diff --git a/apps/ui.immich.app/src/lib/constants.ts b/apps/ui.immich.app/src/lib/constants.ts index 938e8403..1ae98ed1 100644 --- a/apps/ui.immich.app/src/lib/constants.ts +++ b/apps/ui.immich.app/src/lib/constants.ts @@ -208,7 +208,7 @@ export const components: ComponentItem[] = [ { name: 'Tooltip', icon: mdiInformationSlabCircleOutline, activeIcon: mdiInformationSlabCircle }, ]; -const onAction: ActionItemHandler = (item) => { +const onAction: ActionItemHandler = ({ action: item }) => { toastManager.show({ title: `Clicked ${item.title}`, color: item.color ?? 'primary', diff --git a/apps/ui.immich.app/src/routes/(docs)/components/action-button/BasicExample.svelte b/apps/ui.immich.app/src/routes/(docs)/components/action-button/BasicExample.svelte index e07ce897..83641380 100644 --- a/apps/ui.immich.app/src/routes/(docs)/components/action-button/BasicExample.svelte +++ b/apps/ui.immich.app/src/routes/(docs)/components/action-button/BasicExample.svelte @@ -1,6 +1,43 @@ Icon buttons @@ -20,3 +57,13 @@ + + + +Event info +
+ Use the mouse or keyboard shortcuts Del or Ctrl Del +
+ +
+
diff --git a/apps/ui.immich.app/src/routes/(docs)/components/command-palette/+page.svelte b/apps/ui.immich.app/src/routes/(docs)/components/command-palette/+page.svelte index 25283dc5..34f4b51d 100644 --- a/apps/ui.immich.app/src/routes/(docs)/components/command-palette/+page.svelte +++ b/apps/ui.immich.app/src/routes/(docs)/components/command-palette/+page.svelte @@ -5,6 +5,8 @@ import { Markdown, Text } from '@immich/ui'; import BasicExample from './BasicExample.svelte'; import basicExample from './BasicExample.svelte?raw'; + import EventExample from './EventExample.svelte'; + import eventExample from './EventExample.svelte?raw'; @@ -12,4 +14,5 @@ See for a dedicated button to open the component + diff --git a/apps/ui.immich.app/src/routes/(docs)/components/command-palette/EventExample.svelte b/apps/ui.immich.app/src/routes/(docs)/components/command-palette/EventExample.svelte new file mode 100644 index 00000000..5ca8fa47 --- /dev/null +++ b/apps/ui.immich.app/src/routes/(docs)/components/command-palette/EventExample.svelte @@ -0,0 +1,31 @@ + + + + +Get the event that triggered the action + diff --git a/apps/ui.immich.app/src/routes/(docs)/components/context-menu/BasicExample.svelte b/apps/ui.immich.app/src/routes/(docs)/components/context-menu/BasicExample.svelte index 9aeb7600..b8d85b0f 100644 --- a/apps/ui.immich.app/src/routes/(docs)/components/context-menu/BasicExample.svelte +++ b/apps/ui.immich.app/src/routes/(docs)/components/context-menu/BasicExample.svelte @@ -11,7 +11,7 @@ mdiTrashCanOutline, } from '@mdi/js'; - const onAction: ActionItemHandler = (item) => { + const onAction: ActionItemHandler = ({ action: item }) => { toastManager.show({ title: `Clicked ${item.title}`, color: item.color ?? 'primary', diff --git a/packages/ui/src/lib/components/ActionButton/ActionButton.svelte b/packages/ui/src/lib/components/ActionButton/ActionButton.svelte index 392c5c67..cabfa071 100644 --- a/packages/ui/src/lib/components/ActionButton/ActionButton.svelte +++ b/packages/ui/src/lib/components/ActionButton/ActionButton.svelte @@ -19,7 +19,7 @@ const common = $derived({ variant: variantOverride ?? 'ghost', color: colorOverride ?? action.color ?? 'secondary', - onclick: () => onAction(action), + onclick: (event: MouseEvent) => onAction({ action, event }), }); diff --git a/packages/ui/src/lib/components/CommandPalette/CommandPaletteItem.svelte b/packages/ui/src/lib/components/CommandPalette/CommandPaletteItem.svelte index 3046a1dd..8ded7b8b 100644 --- a/packages/ui/src/lib/components/CommandPalette/CommandPaletteItem.svelte +++ b/packages/ui/src/lib/components/CommandPalette/CommandPaletteItem.svelte @@ -11,7 +11,7 @@ type Props = { item: ActionItem; selected: boolean; - onSelect: () => void; + onSelect: (event: MouseEvent) => void; }; const { item, selected, onSelect }: Props = $props(); @@ -37,7 +37,7 @@
diff --git a/packages/ui/src/lib/services/command-palette-manager.svelte.ts b/packages/ui/src/lib/services/command-palette-manager.svelte.ts index 00bd18aa..1e663da3 100644 --- a/packages/ui/src/lib/services/command-palette-manager.svelte.ts +++ b/packages/ui/src/lib/services/command-palette-manager.svelte.ts @@ -2,7 +2,7 @@ import { matchesShortcut, shortcuts, shouldIgnoreEvent } from '$lib/actions/shor import CommandPaletteModal from '$lib/internal/CommandPaletteModal.svelte'; import { modalManager } from '$lib/services/modal-manager.svelte.js'; import { isModalOpen } from '$lib/state/modal-state.svelte.js'; -import type { ActionItem, MaybePromise, TranslationProps } from '$lib/types.js'; +import type { ActionEvent, ActionItem, MaybePromise, TranslationProps } from '$lib/types.js'; import { isEnabled } from '$lib/utilities/common.js'; import { asArray, generateId } from '$lib/utilities/internal.js'; import Fuse, { type FuseResult, type FuseResultMatch, type IFuseOptions } from 'fuse.js'; @@ -220,13 +220,13 @@ class CommandPaletteManager { event.preventDefault(); } - action?.onAction(action); + action?.onAction({ action, event }); return; } } - async #onClose(action?: ActionItem) { - await action?.onAction(action); + async #onClose(actionEvent?: ActionEvent) { + await actionEvent?.action.onAction(actionEvent); this.#isOpen = false; this.#results = []; } diff --git a/packages/ui/src/lib/types.ts b/packages/ui/src/lib/types.ts index a7306afc..3dabf3cc 100644 --- a/packages/ui/src/lib/types.ts +++ b/packages/ui/src/lib/types.ts @@ -370,7 +370,17 @@ export type DatePickerProps = { export type IfLike = { $if?: () => boolean }; -export type ActionItemHandler = (item: T) => unknown | Promise; +/** + * The event will be a `KeyboardEvent | MouseEvent` for actions triggered via + * normal (icon) buttons and the command palette (including shortcuts), and + * a custom event type for actions triggered via bits-ui components like the + * context menu. + */ +export type ActionEvent = { action: T; event: Event }; + +export type ActionItemHandler = ( + actionEvent: ActionEvent, +) => unknown | Promise; export type LinkItem = { title: string;