UNPKG

2.61 kBTypeScriptView Raw
1/// <reference types="react" />
2export type SnackbarCloseReason = 'timeout' | 'clickaway' | 'escapeKeyDown';
3export interface UseSnackbarParameters {
4 /**
5 * The number of milliseconds to wait before automatically calling the
6 * `onClose` function. `onClose` should then set the state of the `open`
7 * prop to hide the Snackbar. This behavior is disabled by default with
8 * the `null` value.
9 * @default null
10 */
11 autoHideDuration?: number | null;
12 /**
13 * If `true`, the `autoHideDuration` timer will expire even if the window is not focused.
14 * @default false
15 */
16 disableWindowBlurListener?: boolean;
17 /**
18 * Callback fired when the component requests to be closed.
19 * Typically `onClose` is used to set state in the parent component,
20 * which is used to control the `Snackbar` `open` prop.
21 * The `reason` parameter can optionally be used to control the response to `onClose`,
22 * for example ignoring `clickaway`.
23 *
24 * @param {React.SyntheticEvent<any> | Event} event The event source of the callback.
25 * @param {string} reason Can be: `"timeout"` (`autoHideDuration` expired), `"clickaway"`, or `"escapeKeyDown"`.
26 */
27 onClose?: (event: React.SyntheticEvent<any> | Event | null, reason: SnackbarCloseReason) => void;
28 /**
29 * If `true`, the component is shown.
30 */
31 open?: boolean;
32 /**
33 * The number of milliseconds to wait before dismissing after user interaction.
34 * If `autoHideDuration` prop isn't specified, it does nothing.
35 * If `autoHideDuration` prop is specified but `resumeHideDuration` isn't,
36 * we default to `autoHideDuration / 2` ms.
37 */
38 resumeHideDuration?: number;
39}
40export type UseSnackbarRootSlotProps<ExternalProps = {}> = ExternalProps & UseSnackbarRootSlotOwnProps;
41export interface UseSnackbarRootSlotOwnProps {
42 onBlur: React.FocusEventHandler;
43 onFocus: React.FocusEventHandler;
44 onMouseEnter: React.MouseEventHandler;
45 onMouseLeave: React.MouseEventHandler;
46 ref?: React.RefCallback<Element>;
47 role: React.AriaRole;
48}
49export interface UseSnackbarReturnValue {
50 /**
51 * Resolver for the root slot's props.
52 * @param externalProps props for the root slot
53 * @returns props that should be spread on the root slot
54 */
55 getRootProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSnackbarRootSlotProps<ExternalProps>;
56 /**
57 * Callback fired when a "click away" event is detected.
58 */
59 onClickAway: (event: React.SyntheticEvent<any> | Event) => void;
60}