1 | import * as React from 'react';
|
2 | import { SxProps } from '@mui/system';
|
3 | import { ClickAwayListenerProps } from '../ClickAwayListener';
|
4 | import { Theme } from '../styles';
|
5 | import { InternalStandardProps as StandardProps } from '..';
|
6 | import { SnackbarContentProps } from '../SnackbarContent';
|
7 | import { TransitionProps } from '../transitions/transition';
|
8 | import { SnackbarClasses } from './snackbarClasses';
|
9 |
|
10 | export interface SnackbarOrigin {
|
11 | vertical: 'top' | 'bottom';
|
12 | horizontal: 'left' | 'center' | 'right';
|
13 | }
|
14 |
|
15 | export type SnackbarCloseReason = 'timeout' | 'clickaway' | 'escapeKeyDown';
|
16 |
|
17 | export interface SnackbarProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
|
18 | /**
|
19 | * The action to display. It renders after the message, at the end of the snackbar.
|
20 | */
|
21 | action?: SnackbarContentProps['action'];
|
22 | /**
|
23 | * The anchor of the `Snackbar`.
|
24 | * On smaller screens, the component grows to occupy all the available width,
|
25 | * the horizontal alignment is ignored.
|
26 | * @default { vertical: 'bottom', horizontal: 'left' }
|
27 | */
|
28 | anchorOrigin?: SnackbarOrigin;
|
29 | /**
|
30 | * The number of milliseconds to wait before automatically calling the
|
31 | * `onClose` function. `onClose` should then set the state of the `open`
|
32 | * prop to hide the Snackbar. This behavior is disabled by default with
|
33 | * the `null` value.
|
34 | * @default null
|
35 | */
|
36 | autoHideDuration?: number | null;
|
37 | /**
|
38 | * Replace the `SnackbarContent` component.
|
39 | */
|
40 | children?: React.ReactElement<unknown, any>;
|
41 | /**
|
42 | * Override or extend the styles applied to the component.
|
43 | */
|
44 | classes?: Partial<SnackbarClasses>;
|
45 | /**
|
46 | * Props applied to the `ClickAwayListener` element.
|
47 | */
|
48 | ClickAwayListenerProps?: Partial<ClickAwayListenerProps>;
|
49 | /**
|
50 | * Props applied to the [`SnackbarContent`](https://mui.com/material-ui/api/snackbar-content/) element.
|
51 | */
|
52 | ContentProps?: Partial<SnackbarContentProps>;
|
53 | /**
|
54 | * If `true`, the `autoHideDuration` timer will expire even if the window is not focused.
|
55 | * @default false
|
56 | */
|
57 | disableWindowBlurListener?: boolean;
|
58 | /**
|
59 | * When displaying multiple consecutive snackbars using a single parent-rendered
|
60 | * `<Snackbar/>`, add the `key` prop to ensure independent treatment of each message.
|
61 | * For instance, use `<Snackbar key={message} />`. Otherwise, messages might update
|
62 | * in place, and features like `autoHideDuration` could be affected.
|
63 | */
|
64 | key?: any;
|
65 | /**
|
66 | * The message to display.
|
67 | */
|
68 | message?: SnackbarContentProps['message'];
|
69 | /**
|
70 | * Callback fired when the component requests to be closed.
|
71 | * Typically `onClose` is used to set state in the parent component,
|
72 | * which is used to control the `Snackbar` `open` prop.
|
73 | * The `reason` parameter can optionally be used to control the response to `onClose`,
|
74 | * for example ignoring `clickaway`.
|
75 | *
|
76 | * @param {React.SyntheticEvent<any> | Event} event The event source of the callback.
|
77 | * @param {string} reason Can be: `"timeout"` (`autoHideDuration` expired), `"clickaway"`, or `"escapeKeyDown"`.
|
78 | */
|
79 | onClose?: (event: React.SyntheticEvent<any> | Event, reason: SnackbarCloseReason) => void;
|
80 | /**
|
81 | * If `true`, the component is shown.
|
82 | */
|
83 | open?: boolean;
|
84 | /**
|
85 | * The number of milliseconds to wait before dismissing after user interaction.
|
86 | * If `autoHideDuration` prop isn't specified, it does nothing.
|
87 | * If `autoHideDuration` prop is specified but `resumeHideDuration` isn't,
|
88 | * we default to `autoHideDuration / 2` ms.
|
89 | */
|
90 | resumeHideDuration?: number;
|
91 | /**
|
92 | * The system prop that allows defining system overrides as well as additional CSS styles.
|
93 | */
|
94 | sx?: SxProps<Theme>;
|
95 | /**
|
96 | * The component used for the transition.
|
97 | * [Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
|
98 | * @default Grow
|
99 | */
|
100 | TransitionComponent?: React.JSXElementConstructor<
|
101 | TransitionProps & { children: React.ReactElement<unknown, any> }
|
102 | >;
|
103 | /**
|
104 | * The duration for the transition, in milliseconds.
|
105 | * You may specify a single timeout for all transitions, or individually with an object.
|
106 | * @default {
|
107 | * enter: theme.transitions.duration.enteringScreen,
|
108 | * exit: theme.transitions.duration.leavingScreen,
|
109 | * }
|
110 | */
|
111 | transitionDuration?: TransitionProps['timeout'];
|
112 | /**
|
113 | * Props applied to the transition element.
|
114 | * By default, the element is based on this [`Transition`](https://reactcommunity.org/react-transition-group/transition/) component.
|
115 | * @default {}
|
116 | */
|
117 | TransitionProps?: TransitionProps;
|
118 | }
|
119 |
|
120 | /**
|
121 | *
|
122 | * Demos:
|
123 | *
|
124 | * - [Snackbar](https://mui.com/material-ui/react-snackbar/)
|
125 | *
|
126 | * API:
|
127 | *
|
128 | * - [Snackbar API](https://mui.com/material-ui/api/snackbar/)
|
129 | */
|
130 | export default function Snackbar(props: SnackbarProps): React.JSX.Element;
|