Skip to content

Commit b4625f1

Browse files
njfamirmarashagp
andcommitted
refactor(snackbar): remove click signal handler
Co-authored-by: arashagp <[email protected]>
1 parent 99057ca commit b4625f1

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

packages/snackbar/src/lib/handler.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ function createSnackbarElement(options: SnackbarOptions): SnackbarElement {
4646
* @param options - Options for configuring the snackbar.
4747
* @param closeSnackbar - Function to close the snackbar.
4848
*/
49-
function handleActionButtonClick(options: SnackbarOptions, closeSnackbar: () => Promise<void>): void {
50-
const actionButtonClickHandler = (event: {id: string}) => {
51-
if (event.id !== options.action!.id) return;
49+
function handleActionButtonClick(closeSnackbar: () => Promise<void>): void {
50+
const actionButtonClickHandler = () => {
5251
logger.logOther?.('Snackbar action button clicked.', event);
5352

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

8685
if (options.action != null) {
87-
handleActionButtonClick(options, closeSnackbar);
86+
handleActionButtonClick(closeSnackbar);
8887
}
8988

9089
// Close the last snackbar if it exists

packages/snackbar/src/lib/signal.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import {AlwatrSignal} from '@alwatr/flux';
1+
import {AlwatrSignal, AlwatrTrigger} from '@alwatr/flux';
22

33
import type {SnackbarOptions} from './type.js';
44

55
/**
6-
* Signal triggered when the snackbar action button is clicked.
7-
*
8-
* This signal is used to notify listeners that the action button
9-
* on the snackbar component has been clicked. It can be used to
10-
* perform any necessary actions in response to the button click.
11-
*
12-
* @example
13-
* snackbarActionButtonClickedSignal.addListener(() => {
14-
* console.log('Snackbar action button was clicked!');
15-
* });
6+
* Signal triggered when the snackbar action button is clicked to close snackbar.
167
*/
17-
export const snackbarActionButtonClickedSignal = /* @__PURE__ */ new AlwatrSignal<{id: string}>({
8+
export const snackbarActionButtonClickedSignal = /* @__PURE__ */ new AlwatrTrigger({
189
name: 'snackbar-action-button-clicked',
1910
});
2011

packages/snackbar/src/lib/type.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import type {Duration} from '@alwatr/parse-duration';
44
* @property content - Content to be displayed in the snackbar.
55
* @property [action] - The action button configuration.
66
* @property action.label - The label for the action button.
7-
* @property action.handler - The handler function for the action button.
7+
* @property action.signalId - The signal ID to be emitted when the action button is clicked.
88
* @property duration - Duration for which the snackbar is displayed. `infinite` for infinite duration.
99
* @property addCloseButton - Whether to add a close button to the snackbar.
1010
*/
1111
export type SnackbarOptions = {
1212
content: string;
1313
action?: {
14-
id: string;
14+
signalId: string;
1515
label: string;
1616
};
1717
duration?: Duration | 'infinite';

packages/snackbar/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import {packageTracer} from '@alwatr/package-tracer';
33
__dev_mode__: packageTracer.add(__package_name__, __package_version__);
44

55
export * from './lib/element.js';
6-
export * from './lib/handler.js';
6+
export {snackbarSignal} from './lib/signal.js';

0 commit comments

Comments
 (0)