@aglyn/shared-ui-snackstack 1.0.0-beta.143

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.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +7 -0
  3. package/package.json +43 -0
  4. package/src/index.d.ts +17 -0
  5. package/src/index.js +18 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/SnackbarContainer.d.ts +26 -0
  8. package/src/lib/SnackbarContainer.js +130 -0
  9. package/src/lib/SnackbarContainer.js.map +1 -0
  10. package/src/lib/SnackbarContent.d.ts +20 -0
  11. package/src/lib/SnackbarContent.js +42 -0
  12. package/src/lib/SnackbarContent.js.map +1 -0
  13. package/src/lib/SnackbarContext.d.ts +19 -0
  14. package/src/lib/SnackbarContext.js +22 -0
  15. package/src/lib/SnackbarContext.js.map +1 -0
  16. package/src/lib/SnackbarItem/Snackbar.d.ts +29 -0
  17. package/src/lib/SnackbarItem/Snackbar.js +129 -0
  18. package/src/lib/SnackbarItem/Snackbar.js.map +1 -0
  19. package/src/lib/SnackbarItem/SnackbarItem.d.ts +29 -0
  20. package/src/lib/SnackbarItem/SnackbarItem.js +246 -0
  21. package/src/lib/SnackbarItem/SnackbarItem.js.map +1 -0
  22. package/src/lib/SnackbarItem/SnackbarItem.util.d.ts +26 -0
  23. package/src/lib/SnackbarItem/SnackbarItem.util.js +29 -0
  24. package/src/lib/SnackbarItem/SnackbarItem.util.js.map +1 -0
  25. package/src/lib/SnackbarItem/index.d.ts +18 -0
  26. package/src/lib/SnackbarItem/index.js +19 -0
  27. package/src/lib/SnackbarItem/index.js.map +1 -0
  28. package/src/lib/SnackbarProvider.d.ts +80 -0
  29. package/src/lib/SnackbarProvider.js +272 -0
  30. package/src/lib/SnackbarProvider.js.map +1 -0
  31. package/src/lib/types.d.ts +270 -0
  32. package/src/lib/types.js +21 -0
  33. package/src/lib/types.js.map +1 -0
  34. package/src/lib/useSnackbar.d.ts +19 -0
  35. package/src/lib/useSnackbar.js +23 -0
  36. package/src/lib/useSnackbar.js.map +1 -0
  37. package/src/lib/utils/constants.d.ts +68 -0
  38. package/src/lib/utils/constants.js +99 -0
  39. package/src/lib/utils/constants.js.map +1 -0
  40. package/src/lib/utils/defaultIconVariants.d.ts +19 -0
  41. package/src/lib/utils/defaultIconVariants.js +60 -0
  42. package/src/lib/utils/defaultIconVariants.js.map +1 -0
  43. package/src/lib/utils/useEventCallback.d.ts +17 -0
  44. package/src/lib/utils/useEventCallback.js +26 -0
  45. package/src/lib/utils/useEventCallback.js.map +1 -0
  46. package/src/lib/utils/warning.d.ts +18 -0
  47. package/src/lib/utils/warning.js +28 -0
  48. package/src/lib/utils/warning.js.map +1 -0
  49. package/src/lib/withSnackbar.d.ts +19 -0
  50. package/src/lib/withSnackbar.js +37 -0
  51. package/src/lib/withSnackbar.js.map +1 -0
  52. package/src/snackstack.d.ts +21 -0
  53. package/src/snackstack.js +22 -0
  54. package/src/snackstack.js.map +1 -0
@@ -0,0 +1,129 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ /**
5
+ * @license
6
+ * Copyright 2022 Aglyn LLC
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */ import { ClickAwayListener } from "@mui/material";
20
+ import { forwardRef, useCallback, useEffect, useRef } from "react";
21
+ import { REASONS } from "../utils/constants.js";
22
+ import useEventCallback from "../utils/useEventCallback.js";
23
+ const Snackbar = /*#__PURE__*/ forwardRef((props, ref)=>{
24
+ const { children, autoHideDuration, ClickAwayListenerProps, disableWindowBlurListener = false, onClose, onMouseEnter, onMouseLeave, open, resumeHideDuration } = props, rest = _object_without_properties_loose(props, [
25
+ "children",
26
+ "autoHideDuration",
27
+ "ClickAwayListenerProps",
28
+ "disableWindowBlurListener",
29
+ "onClose",
30
+ "onMouseEnter",
31
+ "onMouseLeave",
32
+ "open",
33
+ "resumeHideDuration"
34
+ ]);
35
+ const timerAutoHide = useRef(undefined);
36
+ const handleClose = useEventCallback((...args)=>{
37
+ if (onClose) {
38
+ onClose(...args);
39
+ }
40
+ });
41
+ const setAutoHideTimer = useEventCallback((autoHideDurationParam)=>{
42
+ if (!onClose || autoHideDurationParam == null) {
43
+ return;
44
+ }
45
+ clearTimeout(timerAutoHide.current);
46
+ timerAutoHide.current = setTimeout(()=>{
47
+ handleClose(null, REASONS.TIMEOUT);
48
+ }, autoHideDurationParam);
49
+ });
50
+ useEffect(()=>{
51
+ if (open) {
52
+ setAutoHideTimer(autoHideDuration);
53
+ }
54
+ return ()=>{
55
+ clearTimeout(timerAutoHide.current);
56
+ };
57
+ }, [
58
+ open,
59
+ autoHideDuration,
60
+ setAutoHideTimer
61
+ ]);
62
+ /**
63
+ * Pause the timer when the user is interacting with the Snackbar
64
+ * or when the user hide the window.
65
+ */ const handlePause = ()=>{
66
+ clearTimeout(timerAutoHide.current);
67
+ };
68
+ /**
69
+ * Restart the timer when the user is no longer interacting with the
70
+ * Snackbar or when the window is shown back.
71
+ */ const handleResume = useCallback(()=>{
72
+ if (autoHideDuration != null) {
73
+ setAutoHideTimer(resumeHideDuration != null ? resumeHideDuration : autoHideDuration * 0.5);
74
+ }
75
+ }, [
76
+ autoHideDuration,
77
+ resumeHideDuration,
78
+ setAutoHideTimer
79
+ ]);
80
+ const handleMouseEnter = (event)=>{
81
+ if (onMouseEnter) {
82
+ onMouseEnter(event);
83
+ }
84
+ handlePause();
85
+ };
86
+ const handleMouseLeave = (event)=>{
87
+ if (onMouseLeave) {
88
+ onMouseLeave(event);
89
+ }
90
+ handleResume();
91
+ };
92
+ const handleClickAway = (event)=>{
93
+ if (onClose) {
94
+ onClose(event, REASONS.CLICKAWAY);
95
+ }
96
+ };
97
+ useEffect(()=>{
98
+ if (!disableWindowBlurListener && open) {
99
+ window.addEventListener('focus', handleResume);
100
+ window.addEventListener('blur', handlePause);
101
+ return ()=>{
102
+ window.removeEventListener('focus', handleResume);
103
+ window.removeEventListener('blur', handlePause);
104
+ };
105
+ }
106
+ return undefined;
107
+ }, [
108
+ disableWindowBlurListener,
109
+ handleResume,
110
+ open
111
+ ]);
112
+ return /*#__PURE__*/ _jsx(ClickAwayListener, _extends({
113
+ onClickAway: handleClickAway
114
+ }, ClickAwayListenerProps, {
115
+ children: /*#__PURE__*/ _jsx("div", _extends({
116
+ ref: ref,
117
+ onMouseEnter: handleMouseEnter,
118
+ onMouseLeave: handleMouseLeave
119
+ }, rest, {
120
+ children: children
121
+ }))
122
+ }));
123
+ });
124
+ Snackbar.displayName = 'Snackbar';
125
+ Snackbar.aglyn = true;
126
+ export { Snackbar };
127
+ export default Snackbar;
128
+
129
+ //# sourceMappingURL=Snackbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/snackstack/src/lib/SnackbarItem/Snackbar.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ClickAwayListener, type ClickAwayListenerProps } from '@mui/material'\nimport {\n type MouseEvent as ReactMouseEvent,\n forwardRef,\n type HTMLAttributes,\n useCallback,\n useEffect,\n useRef,\n} from 'react'\nimport { REASONS } from '../utils/constants'\nimport useEventCallback from '../utils/useEventCallback'\n\nexport interface SnackbarProps extends HTMLAttributes<HTMLDivElement> {\n autoHideDuration?: number | null\n ClickAwayListenerProps?: Partial<ClickAwayListenerProps>\n disableWindowBlurListener?: boolean\n resumeHideDuration?: number\n open?: boolean\n onClose?: (...args: any[]) => void\n}\n\nconst Snackbar = forwardRef<any, SnackbarProps>((props, ref) => {\n const {\n children,\n autoHideDuration,\n ClickAwayListenerProps,\n disableWindowBlurListener = false,\n onClose,\n onMouseEnter,\n onMouseLeave,\n open,\n resumeHideDuration,\n ...rest\n } = props\n\n const timerAutoHide = useRef<ReturnType<typeof setTimeout>>(undefined)\n\n const handleClose = useEventCallback((...args: any[]) => {\n if (onClose) {\n onClose(...args)\n }\n })\n\n const setAutoHideTimer = useEventCallback((autoHideDurationParam: number) => {\n if (!onClose || autoHideDurationParam == null) {\n return\n }\n\n clearTimeout(timerAutoHide.current)\n timerAutoHide.current = setTimeout(() => {\n handleClose(null, REASONS.TIMEOUT)\n }, autoHideDurationParam)\n })\n\n useEffect(() => {\n if (open) {\n setAutoHideTimer(autoHideDuration)\n }\n\n return () => {\n clearTimeout(timerAutoHide.current)\n }\n }, [open, autoHideDuration, setAutoHideTimer])\n\n /**\n * Pause the timer when the user is interacting with the Snackbar\n * or when the user hide the window.\n */\n const handlePause = () => {\n clearTimeout(timerAutoHide.current)\n }\n\n /**\n * Restart the timer when the user is no longer interacting with the\n * Snackbar or when the window is shown back.\n */\n const handleResume = useCallback(() => {\n if (autoHideDuration != null) {\n setAutoHideTimer(\n resumeHideDuration != null\n ? resumeHideDuration\n : autoHideDuration * 0.5,\n )\n }\n }, [autoHideDuration, resumeHideDuration, setAutoHideTimer])\n\n const handleMouseEnter = (event: ReactMouseEvent<HTMLDivElement>) => {\n if (onMouseEnter) {\n onMouseEnter(event)\n }\n handlePause()\n }\n\n const handleMouseLeave = (event: ReactMouseEvent<HTMLDivElement>) => {\n if (onMouseLeave) {\n onMouseLeave(event)\n }\n handleResume()\n }\n\n const handleClickAway = (event: MouseEvent | TouchEvent) => {\n if (onClose) {\n onClose(event, REASONS.CLICKAWAY)\n }\n }\n\n useEffect(() => {\n if (!disableWindowBlurListener && open) {\n window.addEventListener('focus', handleResume)\n window.addEventListener('blur', handlePause)\n\n return () => {\n window.removeEventListener('focus', handleResume)\n window.removeEventListener('blur', handlePause)\n }\n }\n\n return undefined\n }, [disableWindowBlurListener, handleResume, open])\n\n return (\n <ClickAwayListener\n onClickAway={handleClickAway}\n {...ClickAwayListenerProps}\n >\n <div\n ref={ref}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n {...rest}\n >\n {children}\n </div>\n </ClickAwayListener>\n )\n})\nSnackbar.displayName = 'Snackbar'\nSnackbar.aglyn = true\n\nexport { Snackbar }\nexport default Snackbar\n"],"names":["ClickAwayListener","forwardRef","useCallback","useEffect","useRef","REASONS","useEventCallback","Snackbar","props","ref","children","autoHideDuration","ClickAwayListenerProps","disableWindowBlurListener","onClose","onMouseEnter","onMouseLeave","open","resumeHideDuration","rest","timerAutoHide","undefined","handleClose","args","setAutoHideTimer","autoHideDurationParam","clearTimeout","current","setTimeout","TIMEOUT","handlePause","handleResume","handleMouseEnter","event","handleMouseLeave","handleClickAway","CLICKAWAY","window","addEventListener","removeEventListener","onClickAway","div","displayName","aglyn"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAqC,gBAAe;AAC9E,SAEEC,UAAU,EAEVC,WAAW,EACXC,SAAS,EACTC,MAAM,QACD,QAAO;AACd,SAASC,OAAO,QAAQ,wBAAoB;AAC5C,OAAOC,sBAAsB,+BAA2B;AAWxD,MAAMC,yBAAWN,WAA+B,CAACO,OAAOC;IACtD,MAAM,EACJC,QAAQ,EACRC,gBAAgB,EAChBC,sBAAsB,EACtBC,4BAA4B,KAAK,EACjCC,OAAO,EACPC,YA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CAAC,QAAQT;YACrC;QACF;QAEA,OAAOT;IACT,GAAG;QAACR;QAA2BkB;QAAcd;KAAK;IAElD,qBACE,KAACjB;QACCwC,aAAaL;OACTvB;kBAEJ,cAAA,KAAC6B;YACChC,KAAKA;YACLM,cAAciB;YACdhB,cAAckB;WACVf;sBAEHT;;;AAIT;AACAH,SAASmC,WAAW,GAAG;AACvBnC,SAASoC,KAAK,GAAG;AAEjB,SAASpC,QAAQ,GAAE;AACnB,eAAeA,SAAQ"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type SnackbarClassKey } from '@mui/material';
18
+ import { type Snack } from '../SnackbarProvider';
19
+ import { type ClassNameMap, type RequiredBy, type SharedProps, type SnackbarProviderProps as ProviderProps } from '../types';
20
+ type RemovedProps = 'variant' | 'anchorOrigin' | 'autoHideDuration' | 'preventDuplicate';
21
+ export interface SnackbarItemProps extends RequiredBy<Omit<SharedProps, RemovedProps>, 'onEntered' | 'onExited' | 'onClose'> {
22
+ snack: Snack;
23
+ dense: ProviderProps['dense'];
24
+ iconVariant: ProviderProps['iconVariant'];
25
+ hideIconVariant: ProviderProps['hideIconVariant'];
26
+ classes: Partial<ClassNameMap<SnackbarClassKey>>;
27
+ }
28
+ declare const SnackbarItem: import("react").ForwardRefExoticComponent<Omit<SnackbarItemProps, "ref"> & import("react").RefAttributes<any>>;
29
+ export default SnackbarItem;
@@ -0,0 +1,246 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ /**
5
+ * @license
6
+ * Copyright 2022 Aglyn LLC
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */ // eslint-disable-next-line @nx/enforce-module-boundaries
20
+ import { createChainedFunction } from "@aglyn/shared-util-tools";
21
+ import { Collapse, emphasize, styled } from "@mui/material";
22
+ import clsx from "clsx";
23
+ import { forwardRef, useEffect, useRef, useState } from "react";
24
+ import SnackbarContent from "../SnackbarContent.js";
25
+ import { DEFAULTS, objectMerge, REASONS, transformer } from "../utils/constants.js";
26
+ import defaultIconVariants from "../utils/defaultIconVariants.js";
27
+ import Snackbar from "./Snackbar.js";
28
+ import { getTransitionDirection } from "./SnackbarItem.util.js";
29
+ const componentName = 'SnackbarItem';
30
+ const classes = {
31
+ contentRoot: `${componentName}-contentRoot`,
32
+ lessPadding: `${componentName}-lessPadding`,
33
+ variantSuccess: `${componentName}-variantSuccess`,
34
+ variantError: `${componentName}-variantError`,
35
+ variantInfo: `${componentName}-variantInfo`,
36
+ variantWarning: `${componentName}-variantWarning`,
37
+ message: `${componentName}-message`,
38
+ action: `${componentName}-action`,
39
+ wrappedRoot: `${componentName}-wrappedRoot`
40
+ };
41
+ const StyledSnackbar = styled(Snackbar)(({ theme })=>{
42
+ const mode = theme.palette.mode;
43
+ const backgroundColor = emphasize(theme.palette.background.default, mode === 'light' ? 0.8 : 0.98);
44
+ return {
45
+ [`&.${classes.wrappedRoot}`]: {
46
+ position: 'relative',
47
+ transform: 'translateX(0)',
48
+ top: 0,
49
+ right: 0,
50
+ bottom: 0,
51
+ left: 0
52
+ },
53
+ [`.${classes.contentRoot}`]: _extends({}, theme.typography.body2, {
54
+ backgroundColor,
55
+ color: theme.palette.getContrastText(backgroundColor),
56
+ alignItems: 'center',
57
+ padding: '6px 16px',
58
+ borderRadius: '4px',
59
+ boxShadow: '0px 3px 5px -1px rgba(0,0,0,0.2),0px 6px 10px 0px rgba(0,0,0,0.14),0px 1px 18px 0px rgba(0,0,0,0.12)'
60
+ }),
61
+ [`.${classes.lessPadding}`]: {
62
+ paddingLeft: 8 * 2.5
63
+ },
64
+ [`.${classes.variantSuccess}`]: {
65
+ backgroundColor: '#43a047',
66
+ color: '#fff'
67
+ },
68
+ [`.${classes.variantError}`]: {
69
+ backgroundColor: '#d32f2f',
70
+ color: '#fff'
71
+ },
72
+ [`.${classes.variantInfo}`]: {
73
+ backgroundColor: '#2196f3',
74
+ color: '#fff'
75
+ },
76
+ [`.${classes.variantWarning}`]: {
77
+ backgroundColor: '#ff9800',
78
+ color: '#fff'
79
+ },
80
+ [`.${classes.message}`]: {
81
+ display: 'flex',
82
+ alignItems: 'center',
83
+ padding: '8px 0'
84
+ },
85
+ [`.${classes.action}`]: {
86
+ display: 'flex',
87
+ alignItems: 'center',
88
+ marginLeft: 'auto',
89
+ paddingLeft: 16,
90
+ marginRight: -8
91
+ }
92
+ };
93
+ });
94
+ const SnackbarItem = /*#__PURE__*/ forwardRef((props, ref)=>{
95
+ const { classes: propClasses } = props, rest = _object_without_properties_loose(props, [
96
+ "classes"
97
+ ]);
98
+ const timeout = useRef(undefined);
99
+ const [collapsed, setCollapsed] = useState(true);
100
+ useEffect(()=>()=>{
101
+ if (timeout.current) {
102
+ clearTimeout(timeout.current);
103
+ }
104
+ }, []);
105
+ const handleClose = createChainedFunction([
106
+ rest.snack.onClose,
107
+ rest.onClose
108
+ ], null, rest.snack.snackbarId);
109
+ const handleEntered = ()=>{
110
+ if (rest.snack.requestClose) {
111
+ handleClose(null, REASONS.INSTRUCTED);
112
+ }
113
+ };
114
+ const handleExitedScreen = ()=>{
115
+ timeout.current = setTimeout(()=>{
116
+ setCollapsed(!collapsed);
117
+ }, 125);
118
+ };
119
+ const { style, dense, ariaAttributes: otherAriaAttributes, className: otherClassName, hideIconVariant, iconVariant, snack, action: otherAction, content: otherContent, TransitionComponent: otherTranComponent, TransitionProps: otherTranProps, transitionDuration: otherTranDuration, onEnter: ignoredOnEnter, onEntered: ignoredOnEntered, onEntering: ignoredOnEntering, onExit: ignoredOnExit, onExited: ignoredOnExited, onExiting: ignoredOnExiting } = rest, other = _object_without_properties_loose(rest, [
120
+ "style",
121
+ "dense",
122
+ "ariaAttributes",
123
+ "className",
124
+ "hideIconVariant",
125
+ "iconVariant",
126
+ "snack",
127
+ "action",
128
+ "content",
129
+ "TransitionComponent",
130
+ "TransitionProps",
131
+ "transitionDuration",
132
+ "onEnter",
133
+ "onEntered",
134
+ "onEntering",
135
+ "onExit",
136
+ "onExited",
137
+ "onExiting"
138
+ ]);
139
+ const { persist, snackbarId, open, entered, requestClose, className: singleClassName, variant, content: singleContent, action: singleAction, ariaAttributes: singleAriaAttributes, anchorOrigin, message: snackMessage, TransitionComponent: singleTranComponent, TransitionProps: singleTranProps, transitionDuration: singleTranDuration, onEnter, onEntered, onEntering, onExit, onExited, onExiting } = snack, singleSnackProps = _object_without_properties_loose(snack, [
140
+ "persist",
141
+ "snackbarId",
142
+ "open",
143
+ "entered",
144
+ "requestClose",
145
+ "className",
146
+ "variant",
147
+ "content",
148
+ "action",
149
+ "ariaAttributes",
150
+ "anchorOrigin",
151
+ "message",
152
+ "TransitionComponent",
153
+ "TransitionProps",
154
+ "transitionDuration",
155
+ "onEnter",
156
+ "onEntered",
157
+ "onEntering",
158
+ "onExit",
159
+ "onExited",
160
+ "onExiting"
161
+ ]);
162
+ const icon = _extends({}, defaultIconVariants, iconVariant)[variant];
163
+ const ariaAttributes = _extends({
164
+ 'aria-describedby': 'notistack-snackbar'
165
+ }, objectMerge(singleAriaAttributes, otherAriaAttributes));
166
+ const TransitionComponent = singleTranComponent || otherTranComponent || DEFAULTS.TransitionComponent;
167
+ const transitionDuration = objectMerge(singleTranDuration, otherTranDuration, DEFAULTS.transitionDuration);
168
+ const transitionProps = _extends({
169
+ direction: getTransitionDirection(anchorOrigin)
170
+ }, objectMerge(singleTranProps, otherTranProps));
171
+ let action = singleAction || otherAction;
172
+ if (typeof action === 'function') {
173
+ action = action(snackbarId);
174
+ }
175
+ let content = singleContent || otherContent;
176
+ if (typeof content === 'function') {
177
+ content = content(snackbarId, snack.message);
178
+ }
179
+ // eslint-disable-next-line operator-linebreak
180
+ const callbacks = [
181
+ 'onEnter',
182
+ 'onEntering',
183
+ 'onEntered',
184
+ 'onExit',
185
+ 'onExiting',
186
+ 'onExited'
187
+ ].reduce((acc, callbackName)=>_extends({}, acc, {
188
+ [callbackName]: createChainedFunction([
189
+ rest.snack[callbackName],
190
+ rest[callbackName]
191
+ ], null, rest.snack.snackbarId)
192
+ }), {});
193
+ return /*#__PURE__*/ _jsx(Collapse, {
194
+ ref: ref,
195
+ unmountOnExit: true,
196
+ timeout: 175,
197
+ in: collapsed,
198
+ onExited: callbacks.onExited,
199
+ children: /*#__PURE__*/ _jsx(StyledSnackbar, _extends({}, other, singleSnackProps, {
200
+ open: open,
201
+ className: clsx(propClasses.root, classes.wrappedRoot, propClasses[transformer.toAnchorOrigin(anchorOrigin)]),
202
+ onClose: handleClose,
203
+ children: /*#__PURE__*/ _jsx(TransitionComponent, _extends({
204
+ appear: true,
205
+ in: open,
206
+ timeout: transitionDuration
207
+ }, transitionProps, {
208
+ onExit: callbacks.onExit,
209
+ onExiting: callbacks.onExiting,
210
+ onExited: handleExitedScreen,
211
+ onEnter: callbacks.onEnter,
212
+ onEntering: callbacks.onEntering,
213
+ // order matters. first callbacks.onEntered to set entered: true,
214
+ // then handleEntered to check if there's a request for closing
215
+ onEntered: createChainedFunction([
216
+ callbacks.onEntered,
217
+ handleEntered
218
+ ]),
219
+ children: content || /*#__PURE__*/ _jsxs(SnackbarContent, _extends({}, ariaAttributes, {
220
+ role: "alert",
221
+ style: style,
222
+ className: clsx(classes.contentRoot, {
223
+ [classes.lessPadding]: !hideIconVariant && icon
224
+ }, classes[transformer.toVariant(variant)], propClasses[transformer.toVariant(variant)], otherClassName, singleClassName),
225
+ children: [
226
+ /*#__PURE__*/ _jsxs("div", {
227
+ id: ariaAttributes['aria-describedby'],
228
+ className: classes.message,
229
+ children: [
230
+ !hideIconVariant ? icon : null,
231
+ snackMessage
232
+ ]
233
+ }),
234
+ action && /*#__PURE__*/ _jsx("div", {
235
+ className: classes.action,
236
+ children: action
237
+ })
238
+ ]
239
+ }))
240
+ }))
241
+ }))
242
+ });
243
+ });
244
+ export default SnackbarItem;
245
+
246
+ //# sourceMappingURL=SnackbarItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/snackstack/src/lib/SnackbarItem/SnackbarItem.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// eslint-disable-next-line @nx/enforce-module-boundaries\nimport { createChainedFunction } from '@aglyn/shared-util-tools'\nimport {\n Collapse,\n emphasize,\n type SnackbarClassKey,\n styled,\n} from '@mui/material'\nimport clsx from 'clsx'\nimport { forwardRef, useEffect, useRef, useState } from 'react'\nimport SnackbarContent from '../SnackbarContent'\nimport { type Snack } from '../SnackbarProvider'\nimport {\n type ClassNameMap,\n type RequiredBy,\n type SharedProps,\n type SnackbarProviderProps as ProviderProps,\n type TransitionHandlerProps,\n} from '../types'\nimport { DEFAULTS, objectMerge, REASONS, transformer } from '../utils/constants'\nimport defaultIconVariants from '../utils/defaultIconVariants'\nimport Snackbar from './Snackbar'\nimport { getTransitionDirection } from './SnackbarItem.util'\n\nconst componentName = 'SnackbarItem'\n\nconst classes = {\n contentRoot: `${componentName}-contentRoot`,\n lessPadding: `${componentName}-lessPadding`,\n variantSuccess: `${componentName}-variantSuccess`,\n variantError: `${componentName}-variantError`,\n variantInfo: `${componentName}-variantInfo`,\n variantWarning: `${componentName}-variantWarning`,\n message: `${componentName}-message`,\n action: `${componentName}-action`,\n wrappedRoot: `${componentName}-wrappedRoot`,\n}\n\nconst StyledSnackbar = styled(Snackbar)(({ theme }) => {\n const mode = theme.palette.mode\n const backgroundColor = emphasize(\n theme.palette.background.default,\n mode === 'light' ? 0.8 : 0.98,\n )\n\n return {\n [`&.${classes.wrappedRoot}`]: {\n position: 'relative',\n transform: 'translateX(0)',\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n },\n [`.${classes.contentRoot}`]: {\n ...theme.typography.body2,\n backgroundColor,\n color: theme.palette.getContrastText(backgroundColor),\n alignItems: 'center',\n padding: '6px 16px',\n borderRadius: '4px',\n boxShadow:\n '0px 3px 5px -1px rgba(0,0,0,0.2),0px 6px 10px 0px rgba(0,0,0,0.14),0px 1px 18px 0px rgba(0,0,0,0.12)',\n },\n [`.${classes.lessPadding}`]: {\n paddingLeft: 8 * 2.5,\n },\n [`.${classes.variantSuccess}`]: {\n backgroundColor: '#43a047', // green\n color: '#fff',\n },\n [`.${classes.variantError}`]: {\n backgroundColor: '#d32f2f', // dark red\n color: '#fff',\n },\n [`.${classes.variantInfo}`]: {\n backgroundColor: '#2196f3', // nice blue\n color: '#fff',\n },\n [`.${classes.variantWarning}`]: {\n backgroundColor: '#ff9800', // amber\n color: '#fff',\n },\n [`.${classes.message}`]: {\n display: 'flex',\n alignItems: 'center',\n padding: '8px 0',\n },\n [`.${classes.action}`]: {\n display: 'flex',\n alignItems: 'center',\n marginLeft: 'auto',\n paddingLeft: 16,\n marginRight: -8,\n },\n }\n})\n\ntype RemovedProps =\n | 'variant' // the one received from Provider is processed and passed to snack prop\n | 'anchorOrigin' // same as above\n | 'autoHideDuration' // same as above\n | 'preventDuplicate' // the one recevied from enqueueSnackbar is processed in provider, therefore\n// shouldn't be passed to SnackbarItem */\n\nexport interface SnackbarItemProps\n extends RequiredBy<\n Omit<SharedProps, RemovedProps>,\n 'onEntered' | 'onExited' | 'onClose'\n > {\n snack: Snack\n dense: ProviderProps['dense']\n iconVariant: ProviderProps['iconVariant']\n hideIconVariant: ProviderProps['hideIconVariant']\n classes: Partial<ClassNameMap<SnackbarClassKey>>\n}\n\nconst SnackbarItem = forwardRef<any, SnackbarItemProps>((props, ref) => {\n const { classes: propClasses, ...rest } = props\n const timeout = useRef<ReturnType<typeof setTimeout>>(undefined)\n const [collapsed, setCollapsed] = useState(true)\n\n useEffect(\n () => (): void => {\n if (timeout.current) {\n clearTimeout(timeout.current)\n }\n },\n [],\n )\n\n const handleClose = createChainedFunction(\n [rest.snack.onClose, rest.onClose],\n null,\n rest.snack.snackbarId,\n )\n\n const handleEntered: TransitionHandlerProps['onEntered'] = () => {\n if (rest.snack.requestClose) {\n handleClose(null, REASONS.INSTRUCTED)\n }\n }\n\n const handleExitedScreen = (): void => {\n timeout.current = setTimeout(() => {\n setCollapsed(!collapsed)\n }, 125)\n }\n\n const {\n style,\n dense,\n ariaAttributes: otherAriaAttributes,\n className: otherClassName,\n hideIconVariant,\n iconVariant,\n snack,\n action: otherAction,\n content: otherContent,\n TransitionComponent: otherTranComponent,\n TransitionProps: otherTranProps,\n transitionDuration: otherTranDuration,\n onEnter: ignoredOnEnter,\n onEntered: ignoredOnEntered,\n onEntering: ignoredOnEntering,\n onExit: ignoredOnExit,\n onExited: ignoredOnExited,\n onExiting: ignoredOnExiting,\n ...other\n } = rest\n\n const {\n persist,\n snackbarId,\n open,\n entered,\n requestClose,\n className: singleClassName,\n variant,\n content: singleContent,\n action: singleAction,\n ariaAttributes: singleAriaAttributes,\n anchorOrigin,\n message: snackMessage,\n TransitionComponent: singleTranComponent,\n TransitionProps: singleTranProps,\n transitionDuration: singleTranDuration,\n onEnter,\n onEntered,\n onEntering,\n onExit,\n onExited,\n onExiting,\n ...singleSnackProps\n } = snack\n\n const icon = {\n ...defaultIconVariants,\n ...iconVariant,\n }[variant]\n\n const ariaAttributes = {\n 'aria-describedby': 'notistack-snackbar',\n ...objectMerge(singleAriaAttributes, otherAriaAttributes),\n }\n\n const TransitionComponent =\n singleTranComponent || otherTranComponent || DEFAULTS.TransitionComponent\n const transitionDuration = objectMerge(\n singleTranDuration,\n otherTranDuration,\n DEFAULTS.transitionDuration,\n )\n const transitionProps = {\n direction: getTransitionDirection(anchorOrigin),\n ...objectMerge(singleTranProps, otherTranProps),\n }\n\n let action = singleAction || otherAction\n if (typeof action === 'function') {\n action = action(snackbarId)\n }\n\n let content = singleContent || otherContent\n if (typeof content === 'function') {\n content = content(snackbarId, snack.message)\n }\n\n // eslint-disable-next-line operator-linebreak\n const callbacks: { [key in keyof TransitionHandlerProps]?: any } = [\n 'onEnter',\n 'onEntering',\n 'onEntered',\n 'onExit',\n 'onExiting',\n 'onExited',\n ].reduce(\n (acc, callbackName) => ({\n ...acc,\n [callbackName]: createChainedFunction(\n [\n rest.snack[callbackName as keyof Snack],\n rest[callbackName as keyof SnackbarItemProps],\n ],\n null,\n rest.snack.snackbarId,\n ),\n }),\n {},\n )\n\n return (\n <Collapse\n ref={ref}\n unmountOnExit\n timeout={175}\n in={collapsed}\n onExited={callbacks.onExited}\n >\n <StyledSnackbar\n {...other}\n {...singleSnackProps}\n open={open}\n className={clsx(\n propClasses.root,\n classes.wrappedRoot,\n propClasses[transformer.toAnchorOrigin(anchorOrigin)],\n )}\n onClose={handleClose}\n >\n <TransitionComponent\n appear\n in={open}\n timeout={transitionDuration}\n {...transitionProps}\n onExit={callbacks.onExit}\n onExiting={callbacks.onExiting}\n onExited={handleExitedScreen}\n onEnter={callbacks.onEnter}\n onEntering={callbacks.onEntering}\n // order matters. first callbacks.onEntered to set entered: true,\n // then handleEntered to check if there's a request for closing\n onEntered={createChainedFunction([\n callbacks.onEntered,\n handleEntered,\n ])}\n >\n {/* @ts-expect-error — SnackbarContent children typing is overly strict */}\n {content || (\n <SnackbarContent\n {...ariaAttributes}\n role=\"alert\"\n style={style}\n className={clsx(\n classes.contentRoot,\n { [classes.lessPadding]: !hideIconVariant && icon },\n classes[transformer.toVariant(variant)],\n propClasses[transformer.toVariant(variant)],\n otherClassName,\n singleClassName,\n )}\n >\n <div\n id={ariaAttributes['aria-describedby']}\n className={classes.message}\n >\n {!hideIconVariant ? icon : null}\n {snackMessage}\n </div>\n {action && <div className={classes.action}>{action}</div>}\n </SnackbarContent>\n )}\n </TransitionComponent>\n </StyledSnackbar>\n </Collapse>\n )\n})\n\nexport default SnackbarItem\n"],"names":["createChainedFunction","Collapse","emphasize","styled","clsx","forwardRef","useEffect","useRef","useState","SnackbarContent","DEFAULTS","objectMerge","REASONS","transformer","defaultIconVariants","Snackbar","getTransitionDirection","componentName","classes","contentRoot","lessPadding","variantSuccess","variantError","variantInfo","variantWarning","message","action","wrappedRoot","StyledSnackbar","theme","mode","palette","backgroundColor","background","default","position","transform","top","right","bottom","left","typography","body2","color","getContrastText","alignItems","padding","borderRadius","boxShadow","paddingLeft","display","marginLeft","marginRight","SnackbarItem","props","ref","propClasses","rest","timeout","undefined","collapsed","setCollapsed","current","clearTimeout","handleClose","snack","onClose","snackbarId","handleEntered","requestClose","INSTRUCTED","handleExitedScreen","setTimeout","style","dense","ariaAttributes","otherAriaAttributes","className","otherClassName","hideIconVariant","iconVariant","otherAction","content","otherContent","TransitionComponent","otherTranComponent","TransitionProps","otherTranProps","transitionDuration","otherTranDuration","onEnter","ignoredOnEnter","onEntered","ignoredOnEntered","onEntering","ignoredOnEntering","onExit","ignoredOnExit","onExited","ignoredOnExited","onExiting","ignoredOnExiting","other","persist","open","entered","singleClassName","variant","singleContent","singleAction","singleAriaAttributes","anchorOrigin","snackMessage","singleTranComponent","singleTranProps","singleTranDuration","singleSnackProps","icon","transitionProps","direction","callbacks","reduce","acc","callbackName","unmountOnExit","in","root","toAnchorOrigin","appear","role","toVariant","div","id"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,yDAAyD;AACzD,SAASA,qBAAqB,QAAQ,2BAA0B;AAChE,SACEC,QAAQ,EACRC,SAAS,EAETC,MAAM,QACD,gBAAe;AACtB,OAAOC,UAAU,OAAM;AACvB,SAASC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAC/D,OAAOC,qBAAqB,wBAAoB;AAShD,SAASC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,EAAEC,WAAW,QAAQ,wBAAoB;AAChF,OAAOC,yBAAyB,kCAA8B;AAC9D,OAAOC,cAAc,gBAAY;AACjC,SAASC,sBAAsB,QAAQ,yBAAqB;AAE5D,MAAMC,gBAAgB;AAEtB,MAAMC,UAAU;IACdC,aAAa,GAAGF,cAAc,YAAY,CAAC;IAC3CG,aAAa,GAAGH,cAAc,YAAY,CAAC;IAC3CI,gBAAgB,GAAGJ,cAAc,eAAe,CAAC;IACjDK,cAAc,GAAGL,cAAc,aAAa,CAAC;IAC7CM,aAAa,GAAGN,cAAc,YAAY,CAAC;IAC3CO,gBAAgB,GAAGP,cAAc,eAAe,CAAC;IACjDQ,SAAS,GAAGR,cAAc,QAAQ,CAAC;IACnCS,QAAQ,GAAGT,cAAc,OAAO,CAAC;IACjCU,aAAa,GAAGV,cAAc,YAAY,CAAC;AAC7C;AAEA,MAAMW,iBAAiBzB,OAAOY,UAAU,CAAC,EAAEc,KAAK,EAAE;IAChD,MAAMC,OAAOD,MAAME,OAAO,CAACD,IAAI;IAC/B,MAAME,kBAAkB9B,UACtB2B,MAAME,OAAO,CAACE,UAAU,CAACC,O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ASF;sBAET,cAAA,KAACoB;gBACC4C,MAAM;gBACNH,IAAIrB;gBACJ9C,SAAS8B;eACL8B;gBACJtB,QAAQwB,UAAUxB,MAAM;gBACxBI,WAAWoB,UAAUpB,SAAS;gBAC9BF,UAAU3B;gBACVmB,SAAS8B,UAAU9B,OAAO;gBAC1BI,YAAY0B,UAAU1B,UAAU;gBAChC,iEAAiE;gBACjE,+DAA+D;gBAC/DF,WAAW5F,sBAAsB;oBAC/BwH,UAAU5B,SAAS;oBACnBxB;iBACD;0BAGAc,yBACC,MAACzE,8BACKkE;oBACJsD,MAAK;oBACLxD,OAAOA;oBACPI,WAAWzE,KACTc,QAAQC,WAAW,EACnB;wBAAE,CAACD,QAAQE,WAAW,CAAC,EAAE,CAAC2D,mBAAmBsC;oBAAK,GAClDnG,OAAO,CAACL,YAAYqH,SAAS,CAACvB,SAAS,EACvCnD,WAAW,CAAC3C,YAAYqH,SAAS,CAACvB,SAAS,EAC3C7B,gBACA4B;;sCAGF,MAACyB;4BACCC,IAAIzD,cAAc,CAAC,mBAAmB;4BACtCE,WAAW3D,QAAQO,OAAO;;gCAEzB,CAACsD,kBAAkBsC,OAAO;gCAC1BL;;;wBAEFtF,wBAAU,KAACyG;4BAAItD,WAAW3D,QAAQQ,MAAM;sCAAGA;;;;;;;AAO1D;AAEA,eAAe2B,aAAY"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type Snack } from '../SnackbarProvider';
18
+ declare const DIRECTION: {
19
+ right: string;
20
+ left: string;
21
+ bottom: string;
22
+ top: string;
23
+ };
24
+ export type DirectionType = typeof DIRECTION[keyof typeof DIRECTION];
25
+ export declare const getTransitionDirection: (anchorOrigin: Snack["anchorOrigin"]) => DirectionType;
26
+ export {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ const DIRECTION = {
17
+ right: 'left',
18
+ left: 'right',
19
+ bottom: 'up',
20
+ top: 'down'
21
+ };
22
+ export const getTransitionDirection = (anchorOrigin)=>{
23
+ if (anchorOrigin.horizontal !== 'center') {
24
+ return DIRECTION[anchorOrigin.horizontal];
25
+ }
26
+ return DIRECTION[anchorOrigin.vertical];
27
+ };
28
+
29
+ //# sourceMappingURL=SnackbarItem.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/snackstack/src/lib/SnackbarItem/SnackbarItem.util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {type Snack} from '../SnackbarProvider'\n\n\nconst DIRECTION = {\n right: 'left',\n left: 'right',\n bottom: 'up',\n top: 'down',\n}\n\nexport type DirectionType = typeof DIRECTION[keyof typeof DIRECTION]\n\nexport const getTransitionDirection = (anchorOrigin: Snack['anchorOrigin']): DirectionType => {\n if (anchorOrigin.horizontal !== 'center') {\n return DIRECTION[anchorOrigin.horizontal]\n }\n return DIRECTION[anchorOrigin.vertical]\n}\n"],"names":["DIRECTION","right","left","bottom","top","getTransitionDirection","anchorOrigin","horizontal","vertical"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAKD,MAAMA,YAAY;IAChBC,OAAO;IACPC,MAAM;IACNC,QAAQ;IACRC,KAAK;AACP;AAIA,OAAO,MAAMC,yBAAyB,CAACC;IACrC,IAAIA,aAAaC,UAAU,KAAK,UAAU;QACxC,OAAOP,SAAS,CAACM,aAAaC,UAAU,CAAC;IAC3C;IACA,OAAOP,SAAS,CAACM,aAAaE,QAAQ,CAAC;AACzC,EAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './SnackbarItem';
18
+ export { default } from './SnackbarItem';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export * from "./SnackbarItem.js";
17
+ export { default } from "./SnackbarItem.js";
18
+
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/snackstack/src/lib/SnackbarItem/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './SnackbarItem'\nexport {default} from './SnackbarItem'\n"],"names":["default"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,oBAAgB;AAC9B,SAAQA,OAAO,QAAO,oBAAgB"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Component } from 'react';
18
+ import type { OptionsObject, ProviderContext, RequiredBy, SnackbarId, SnackbarMessage, SnackbarProviderProps } from './types';
19
+ export interface Snack extends RequiredBy<OptionsObject, 'snackbarId' | 'variant' | 'anchorOrigin'> {
20
+ message: SnackbarMessage;
21
+ open: boolean;
22
+ entered: boolean;
23
+ requestClose: boolean;
24
+ }
25
+ interface State {
26
+ snacks: Snack[];
27
+ queue: Snack[];
28
+ contextValue: ProviderContext;
29
+ }
30
+ declare class SnackbarProvider extends Component<SnackbarProviderProps, State> {
31
+ get maxSnack(): number;
32
+ constructor(props: SnackbarProviderProps);
33
+ /**
34
+ * Adds a new snackbar to the queue to be presented. Returns generated or user
35
+ * defined snackbarId referencing the new snackbar or null
36
+ */
37
+ enqueueSnackbar: (message: SnackbarMessage, opts?: OptionsObject) => SnackbarId;
38
+ /**
39
+ * Close snackbar with the given snackbarId
40
+ */
41
+ closeSnackbar: ProviderContext['closeSnackbar'];
42
+ render(): JSX.Element;
43
+ /**
44
+ * Reducer: Display snack if there's space for it. Otherwise, immediately
45
+ * begin dismissing the oldest message to start showing the new one.
46
+ */
47
+ private handleDisplaySnack;
48
+ /**
49
+ * Reducer: Display items (notifications) in the queue if there's space for them.
50
+ */
51
+ private processQueue;
52
+ /**
53
+ * Reducer: Hide oldest snackbar on the screen because there exists a new one which we have to
54
+ * display.
55
+ * (ignoring the one with 'persist' flag. i.e. explicitly told by user not to get dismissed).
56
+ *
57
+ * Note 1: If there is already a message leaving the screen, no new messages are dismissed.
58
+ * Note 2: If the oldest message has not yet entered the screen, only a request to close the
59
+ * snackbar is made. Once it entered the screen, it will be immediately dismissed.
60
+ */
61
+ private handleDismissOldest;
62
+ /**
63
+ * Set the entered state of the snackbar with the given snackbarId.
64
+ */
65
+ private handleEnteredSnack;
66
+ /**
67
+ * Hide a snackbar after its timeout.
68
+ */
69
+ private handleCloseSnack;
70
+ /**
71
+ * When we set open attribute of a snackbar to false (i.e. after we hide a snackbar),
72
+ * it leaves the screen and immediately after leaving animation is done, this method
73
+ * gets called. We remove the hidden snackbar from state and then display notifications
74
+ * waiting in the queue (if any). If after this process the queue is not empty, the
75
+ * oldest message is dismissed.
76
+ */
77
+ private handleExitedSnack;
78
+ }
79
+ export { SnackbarProvider };
80
+ export default SnackbarProvider;