Skip to content

Commit

Permalink
refactor(snackbar): remove click signal handler
Browse files Browse the repository at this point in the history
Co-authored-by: arashagp <arash.qardashpoor@gmail.com>
  • Loading branch information
njfamirm and arashagp committed Dec 17, 2024
1 parent 76b980a commit f676771
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
7 changes: 3 additions & 4 deletions packages/snackbar/src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>): void {
const actionButtonClickHandler = (event: {id: string}) => {
if (event.id !== options.action!.id) return;
function handleActionButtonClick(closeSnackbar: () => Promise<void>): void {
const actionButtonClickHandler = () => {
logger.logOther?.('Snackbar action button clicked.', event);

return closeSnackbar();
Expand Down Expand Up @@ -84,7 +83,7 @@ async function showSnackbar(options: SnackbarOptions): Promise<void> {
};

if (options.action != null) {
handleActionButtonClick(options, closeSnackbar);
handleActionButtonClick(closeSnackbar);
}

// Close the last snackbar if it exists
Expand Down
15 changes: 3 additions & 12 deletions packages/snackbar/src/lib/signal.ts
Original file line number Diff line number Diff line change
@@ -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',
});

Expand Down
4 changes: 2 additions & 2 deletions packages/snackbar/src/lib/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/snackbar/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit f676771

Please sign in to comment.