diff --git a/packages/snackbar/src/lib/handler.ts b/packages/snackbar/src/lib/handler.ts index 629813d..c1c018a 100644 --- a/packages/snackbar/src/lib/handler.ts +++ b/packages/snackbar/src/lib/handler.ts @@ -46,9 +46,8 @@ function createSnackbarElement(options: SnackbarOptions): SnackbarElement { * @param options - Options for configuring the snackbar. * @param closeSnackbar - Function to close the snackbar. */ -function handleActionButtonClick(options: SnackbarOptions, closeSnackbar: () => Promise): void { - const actionButtonClickHandler = (event: {id: string}) => { - if (event.id !== options.action!.id) return; +function handleActionButtonClick(closeSnackbar: () => Promise): void { + const actionButtonClickHandler = () => { logger.logOther?.('Snackbar action button clicked.', event); return closeSnackbar(); @@ -84,7 +83,7 @@ async function showSnackbar(options: SnackbarOptions): Promise { }; if (options.action != null) { - handleActionButtonClick(options, closeSnackbar); + handleActionButtonClick(closeSnackbar); } // Close the last snackbar if it exists diff --git a/packages/snackbar/src/lib/signal.ts b/packages/snackbar/src/lib/signal.ts index d2e3fd3..6d939f9 100644 --- a/packages/snackbar/src/lib/signal.ts +++ b/packages/snackbar/src/lib/signal.ts @@ -1,20 +1,11 @@ -import {AlwatrSignal} from '@alwatr/flux'; +import {AlwatrSignal, AlwatrTrigger} from '@alwatr/flux'; import type {SnackbarOptions} from './type.js'; /** - * Signal triggered when the snackbar action button is clicked. - * - * This signal is used to notify listeners that the action button - * on the snackbar component has been clicked. It can be used to - * perform any necessary actions in response to the button click. - * - * @example - * snackbarActionButtonClickedSignal.addListener(() => { - * console.log('Snackbar action button was clicked!'); - * }); + * Signal triggered when the snackbar action button is clicked to close snackbar. */ -export const snackbarActionButtonClickedSignal = /* @__PURE__ */ new AlwatrSignal<{id: string}>({ +export const snackbarActionButtonClickedSignal = /* @__PURE__ */ new AlwatrTrigger({ name: 'snackbar-action-button-clicked', }); diff --git a/packages/snackbar/src/lib/type.ts b/packages/snackbar/src/lib/type.ts index 35e0a90..f93f200 100644 --- a/packages/snackbar/src/lib/type.ts +++ b/packages/snackbar/src/lib/type.ts @@ -4,14 +4,14 @@ import type {Duration} from '@alwatr/parse-duration'; * @property content - Content to be displayed in the snackbar. * @property [action] - The action button configuration. * @property action.label - The label for the action button. - * @property action.handler - The handler function for the action button. + * @property action.signalId - The signal ID to be emitted when the action button is clicked. * @property duration - Duration for which the snackbar is displayed. `infinite` for infinite duration. * @property addCloseButton - Whether to add a close button to the snackbar. */ export type SnackbarOptions = { content: string; action?: { - id: string; + signalId: string; label: string; }; duration?: Duration | 'infinite'; diff --git a/packages/snackbar/src/main.ts b/packages/snackbar/src/main.ts index 919be66..c9d70e9 100644 --- a/packages/snackbar/src/main.ts +++ b/packages/snackbar/src/main.ts @@ -3,4 +3,4 @@ import {packageTracer} from '@alwatr/package-tracer'; __dev_mode__: packageTracer.add(__package_name__, __package_version__); export * from './lib/element.js'; -export * from './lib/handler.js'; +export {snackbarSignal} from './lib/signal.js';