mtrl 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,4 @@ import { BaseComponent, SnackbarComponent, ApiOptions } from "./types";
4
4
  * @param {ApiOptions} options - API configuration
5
5
  * @returns {Function} Higher-order function that adds API methods to component
6
6
  */
7
- export declare const withAPI: ({ lifecycle, queue }: ApiOptions) => (component: BaseComponent) => SnackbarComponent;
7
+ export declare const withAPI: ({ lifecycle, queue, queueBehavior }: ApiOptions) => (component: BaseComponent) => SnackbarComponent;
@@ -48,6 +48,7 @@ export declare const getTextConfig: (config: SnackbarConfig) => {
48
48
  message: string;
49
49
  action?: string;
50
50
  duration?: number;
51
+ queueBehavior?: import("./types").SnackbarQueueBehavior;
51
52
  onAction?: (event: import("./types").SnackbarEvent) => void;
52
53
  onOpen?: (event: import("./types").SnackbarEvent) => void;
53
54
  onClose?: (event: import("./types").SnackbarEvent) => void;
@@ -62,5 +63,5 @@ export declare const getTextConfig: (config: SnackbarConfig) => {
62
63
  * @param {SnackbarQueue} queue - Snackbar queue manager
63
64
  * @returns {ApiOptions} API configuration object
64
65
  */
65
- export declare const getApiConfig: (comp: BaseComponent, queue: any) => ApiOptions;
66
+ export declare const getApiConfig: (comp: BaseComponent, queue: any, config?: SnackbarConfig) => ApiOptions;
66
67
  export default defaultConfig;
@@ -30,6 +30,20 @@ export declare const SNACKBAR_STATES: {
30
30
  /** Snackbar is hidden */
31
31
  readonly HIDDEN: "hidden";
32
32
  };
33
+ /**
34
+ * Snackbar queue behaviors
35
+ *
36
+ * Controls how a newly shown snackbar interacts with the one currently on
37
+ * screen and any still waiting in the queue.
38
+ * @category Components
39
+ */
40
+ export declare const SNACKBAR_QUEUE_BEHAVIORS: {
41
+ /** Wait in line — shown one at a time, in order (default) */
42
+ readonly QUEUE: "queue";
43
+ /** Replace — immediately dismiss the current snackbar, drop any pending
44
+ * ones, and show this snackbar right away (last-wins) */
45
+ readonly REPLACE: "replace";
46
+ };
33
47
  /**
34
48
  * Snackbar event types
35
49
  * @category Components
@@ -55,6 +69,10 @@ export declare const SNACKBAR_DEFAULTS: {
55
69
  readonly POSITION: "center";
56
70
  /** Default display duration in milliseconds (4 seconds) */
57
71
  readonly DURATION: 4000;
72
+ /** Default queue behavior */
73
+ readonly QUEUE_BEHAVIOR: "queue";
74
+ /** Delay in milliseconds between a dismissed snackbar and the next one */
75
+ readonly QUEUE_GAP: 200;
58
76
  /** Default z-index for snackbars */
59
77
  readonly Z_INDEX: 1000;
60
78
  /** Default animation duration in milliseconds */
@@ -1,2 +1,3 @@
1
1
  export { default } from "./snackbar";
2
- export { SnackbarConfig, SnackbarComponent } from "./types";
2
+ export { SnackbarConfig, SnackbarComponent, SnackbarQueueBehavior, } from "./types";
3
+ export { SNACKBAR_QUEUE_BEHAVIORS } from "./constants";
@@ -1,7 +1,15 @@
1
1
  import { SnackbarQueue } from './types';
2
2
  /**
3
3
  * Creates a queue manager for snackbars
4
- * Ensures only one snackbar is visible at a time
4
+ *
5
+ * Ensures only one snackbar is visible at a time. Supports two behaviors when
6
+ * a new snackbar is added (see {@link SnackbarQueueAddOptions}):
7
+ * - `'queue'` (default): the snackbar waits its turn and is shown in order.
8
+ * - `'replace'`: the snackbar evicts whatever is currently on screen, drops any
9
+ * still-pending snackbars, and shows immediately. This keeps rapid, repeated
10
+ * actions snappy instead of serializing a long backlog.
11
+ *
12
+ * @param {number} gap - Delay in ms between a dismissed snackbar and the next
5
13
  * @returns {SnackbarQueue} Queue manager with add/clear methods
6
14
  */
7
- export declare const createSnackbarQueue: () => SnackbarQueue;
15
+ export declare const createSnackbarQueue: (gap?: number) => SnackbarQueue;
@@ -21,6 +21,19 @@ export declare const SNACKBAR_POSITIONS: {
21
21
  readonly START: "start";
22
22
  readonly END: "end";
23
23
  };
24
+ /**
25
+ * Available snackbar queue behaviors
26
+ */
27
+ export type SnackbarQueueBehavior = 'queue' | 'replace';
28
+ /**
29
+ * Snackbar queue behaviors
30
+ */
31
+ export declare const SNACKBAR_QUEUE_BEHAVIORS: {
32
+ /** Shown one at a time, in order (default) */
33
+ readonly QUEUE: "queue";
34
+ /** Replace the current snackbar and drop pending ones (last-wins) */
35
+ readonly REPLACE: "replace";
36
+ };
24
37
  /**
25
38
  * Snackbar visibility states
26
39
  */
@@ -65,6 +78,14 @@ export interface SnackbarConfig {
65
78
  action?: string;
66
79
  /** Duration in milliseconds to show the snackbar (0 for indefinite) */
67
80
  duration?: number;
81
+ /**
82
+ * How this snackbar interacts with the queue when shown.
83
+ * - `'queue'` (default): wait in line and show one at a time, in order.
84
+ * - `'replace'`: immediately dismiss the current snackbar, drop any pending
85
+ * ones, and show this snackbar right away. Useful for rapid, repeated
86
+ * actions where only the latest message matters.
87
+ */
88
+ queueBehavior?: SnackbarQueueBehavior;
68
89
  /** Action button callback function */
69
90
  onAction?: (event: SnackbarEvent) => void;
70
91
  /** Callback function when the snackbar opens */
@@ -144,20 +165,33 @@ export interface BaseComponent {
144
165
  export interface SnackbarTimer {
145
166
  start: () => void;
146
167
  stop: () => void;
168
+ /** Sets the auto-dismiss duration in milliseconds */
169
+ setDuration: (duration: number) => void;
170
+ /** Gets the current auto-dismiss duration in milliseconds */
171
+ getDuration: () => number;
147
172
  }
148
173
  /**
149
174
  * Interface for snackbars managed by the queue
150
175
  */
151
176
  export interface QueuedSnackbar {
152
177
  _show: () => void;
178
+ /** Visually dismisses the snackbar without advancing the queue */
179
+ _hide?: () => void;
153
180
  on: (event: string, handler: () => void) => void;
154
181
  off: (event: string, handler: () => void) => void;
155
182
  }
183
+ /**
184
+ * Options controlling how a snackbar is added to the queue
185
+ */
186
+ export interface SnackbarQueueAddOptions {
187
+ /** Behavior to apply when adding this snackbar (defaults to `'queue'`) */
188
+ behavior?: SnackbarQueueBehavior;
189
+ }
156
190
  /**
157
191
  * Interface for the snackbar queue manager
158
192
  */
159
193
  export interface SnackbarQueue {
160
- add: (snackbar: QueuedSnackbar) => void;
194
+ add: (snackbar: QueuedSnackbar, options?: SnackbarQueueAddOptions) => void;
161
195
  clear: () => void;
162
196
  getLength: () => number;
163
197
  }
@@ -169,4 +203,6 @@ export interface ApiOptions {
169
203
  destroy: () => void;
170
204
  };
171
205
  queue: SnackbarQueue;
206
+ /** Queue behavior applied when the snackbar is shown */
207
+ queueBehavior?: SnackbarQueueBehavior;
172
208
  }