import type { EventCallback } from "../../core/state/emitter.js"; import type { ButtonComponent } from "../button/types.js"; import type { IconButtonComponent } from "../icon-button/types.js"; /** * Creates a new Snackbar component * @param config */ declare const createSnackbar: (config: SnackbarConfig) => SnackbarComponent; /** Dismisses the snackbar on screen and drops the ones still waiting. */ declare const clearSnackbars: () => void; /** Where the snackbar sits along the bottom edge */ type SnackbarPosition = 'center' | 'start' | 'end'; /** Duration presets: 4 s, 10 s, or until dismissed */ type SnackbarDurationPreset = 'short' | 'long' | 'indefinite'; /** A preset or a number of milliseconds (0 for indefinite) */ type SnackbarDuration = SnackbarDurationPreset | number; /** Available snackbar queue behaviors */ type SnackbarQueueBehavior = 'queue' | 'replace'; /** Snackbar visibility states */ type SnackbarState = 'visible' | 'queued' | 'hidden'; /** Why a snackbar closed */ type SnackbarCloseReason = 'timeout' | 'action' | 'close-button' | 'escape' | 'api' | 'queue'; /** Available snackbar event types */ type SnackbarEventType = 'open' | 'close' | 'action' | 'dismiss' | 'focus'; /** Snackbar event data */ interface SnackbarEvent { /** The snackbar component that triggered the event */ snackbar: SnackbarComponent; /** Why the snackbar closed (`close` and `dismiss` events) */ reason?: SnackbarCloseReason; /** Original DOM event if there was one */ originalEvent: Event | null; } /** What each snackbar event hands its handler. */ interface SnackbarEvents { /** The snackbar is on screen */ open: (event: SnackbarEvent) => void; /** The snackbar is leaving; the event carries the reason */ close: (event: SnackbarEvent) => void; /** The action button was clicked */ action: (event: SnackbarEvent) => void; /** Fired with `close`; the queue listens to it */ dismiss: (event: SnackbarEvent) => void; /** The keyboard shortcut moved focus to the action button */ focus: (event: SnackbarEvent) => void; } /** Configuration options for the snackbar component */ interface SnackbarConfig { /** Text message to display; up to two lines */ message: string; /** Label of the single text-button action, if any */ action?: string; /** Adds a close icon button */ dismissible?: boolean; /** Accessible name of the close icon (default "Dismiss") */ closeLabel?: string; /** How long the snackbar stays: `'short'` (4 s), `'long'` (10 s), `'indefinite'`, or milliseconds (0 for indefinite). */ duration?: SnackbarDuration; /** Position of the snackbar along the bottom edge */ position?: SnackbarPosition; /** One non-character key that moves focus to the action button while the snackbar is on screen, named as `KeyboardEvent.key` (`"F8"` by default; `"F6"`, `"F9"` and so on). */ focusShortcut?: string | false; /** Callback invoked when the keyboard shortcut moves focus to the action */ onFocus?: (event: SnackbarEvent) => void; /** How this snackbar interacts with the queue when shown. */ queueBehavior?: SnackbarQueueBehavior; /** `"top"` shows the snackbar in the browser's top layer as a `popover="manual"` element: above every z-index, modal dialogs included, at its usual place in viewport coordinates. */ layer?: 'top'; /** Action button callback function */ onAction?: (event: SnackbarEvent) => void; /** Callback function when the snackbar opens */ onOpen?: (event: SnackbarEvent) => void; /** Callback function when the snackbar closes */ onClose?: (event: SnackbarEvent) => void; /** Additional CSS classes */ class?: string; /** Component prefix for CSS classes */ prefix?: string; /** Component name for CSS classes */ componentName?: string; /** Event handlers for snackbar events */ on?: { [key in SnackbarEventType]?: (event: SnackbarEvent) => void; }; } /** Snackbar component public API interface */ interface SnackbarComponent { /** The root element of the snackbar */ element: HTMLElement; /** Current state of the snackbar: `queued` between `show()` and its turn on screen, behind another snackbar; `visible` while it is shown. */ state: SnackbarState; /** The action button element (if present) */ actionButton?: HTMLElement; /** The close icon button element (if present) */ closeButton?: HTMLElement; /** Timer for auto-dismissal */ timer?: SnackbarTimer; /** Displays the snackbar, through the queue. */ show: () => SnackbarComponent; /** Hides the snackbar. */ hide: () => SnackbarComponent; /** Whether the snackbar is on screen: true only while `state` is `visible` */ isOpen: () => boolean; /** Sets the message text */ setMessage: (message: string) => SnackbarComponent; /** Gets the message text */ getMessage: () => string; /** Sets the action button text */ setAction: (text: string) => SnackbarComponent; /** Gets the action button text */ getAction: () => string; /** Sets the display duration: a preset or milliseconds (0 for indefinite) */ setDuration: (duration: SnackbarDuration) => SnackbarComponent; /** Gets the display duration in milliseconds (0 for indefinite) */ getDuration: () => number; /** Sets the snackbar position */ setPosition: (position: SnackbarPosition) => SnackbarComponent; /** Gets the snackbar position */ getPosition: () => SnackbarPosition; /** Adds event listener */ on: (event: K, handler: SnackbarEvents[K]) => SnackbarComponent; /** Removes event listener */ off: (event: K, handler: SnackbarEvents[K]) => SnackbarComponent; /** Destroys the snackbar component and cleans up resources */ destroy: () => void; } interface BaseComponent { element: HTMLElement; emit?: (event: string, data?: unknown) => void; on?: (event: string, handler: EventCallback) => unknown; off?: (event: string, handler: EventCallback) => unknown; getClass?: (name: string) => string; lifecycle?: { destroy?: () => void; }; text?: { setText: (text: string) => unknown; getText: () => string; }; position?: { getPosition: () => SnackbarPosition; setPosition: (position: SnackbarPosition) => unknown; }; action?: ButtonComponent; actionButton?: HTMLElement; close?: IconButtonComponent; closeButton?: HTMLElement; timer?: SnackbarTimer; } /** Timer interface for snackbar auto-dismissal */ interface SnackbarTimer { /** Starts the countdown from the full duration */ start: () => void; /** Cancels the countdown */ stop: () => void; /** Sets the auto-dismiss duration in milliseconds (0 for none) */ setDuration: (duration: number) => void; /** Gets the current auto-dismiss duration in milliseconds */ getDuration: () => number; } interface QueuedSnackbar { _show: () => void; _hide?: () => void; element?: HTMLElement; on: (event: string, handler: () => void) => void; off: (event: string, handler: () => void) => void; } interface SnackbarQueueAddOptions { behavior?: SnackbarQueueBehavior; } interface SnackbarQueue { add: (snackbar: QueuedSnackbar, options?: SnackbarQueueAddOptions) => void; clear: () => void; remove: (snackbar: QueuedSnackbar) => void; getLength: () => number; } interface ApiOptions { lifecycle: { destroy: () => void; }; queue: SnackbarQueue; config: SnackbarConfig; } export type { SnackbarCloseReason, SnackbarComponent, SnackbarConfig, SnackbarDuration, SnackbarEvent, SnackbarEvents, SnackbarPosition, SnackbarQueueBehavior }; export { clearSnackbars, createSnackbar, createSnackbar as default }; export { SNACKBAR_CLOSE_REASONS, SNACKBAR_DURATIONS, SNACKBAR_POSITIONS, SNACKBAR_QUEUE_BEHAVIORS } from "./constants.js";