@transferwise/components 46.165.0 → 46.165.2
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.
- package/build/Snackbar/Snackbar.js +98 -101
- package/build/Snackbar/Snackbar.js.map +1 -1
- package/build/Snackbar/Snackbar.mjs +99 -102
- package/build/Snackbar/Snackbar.mjs.map +1 -1
- package/build/Snackbar/SnackbarProvider.js +2 -6
- package/build/Snackbar/SnackbarProvider.js.map +1 -1
- package/build/Snackbar/SnackbarProvider.mjs +2 -6
- package/build/Snackbar/SnackbarProvider.mjs.map +1 -1
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/index.mjs +0 -1
- package/build/index.mjs.map +1 -1
- package/build/types/Body/Body.d.ts +2 -2
- package/build/types/Carousel/_stories/constants.d.ts +25 -0
- package/build/types/Carousel/_stories/constants.d.ts.map +1 -1
- package/build/types/IconButton/IconButton.d.ts +1 -1
- package/build/types/ListItem/_stories/variants/helpers.d.ts +38 -1
- package/build/types/ListItem/_stories/variants/helpers.d.ts.map +1 -1
- package/build/types/MoneyInput/MoneyInput.d.ts +1 -1
- package/build/types/MoneyInput/MoneyInput.d.ts.map +1 -1
- package/build/types/Snackbar/Snackbar.d.ts +2 -16
- package/build/types/Snackbar/Snackbar.d.ts.map +1 -1
- package/build/types/Snackbar/SnackbarProvider.d.ts.map +1 -1
- package/build/types/Title/Title.d.ts +2 -2
- package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
- package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
- package/build/types/index.d.ts +0 -1
- package/build/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Accordion/_stories/Accordion.test.story.tsx +74 -48
- package/src/AvatarLayout/_stories/AvatarLayout.test.story.tsx +46 -30
- package/src/Button/LegacyButton/_stories/LegacyButton.test.story.tsx +29 -19
- package/src/Button/_stories/Button.test.story.tsx +96 -62
- package/src/Calendar/_stories/Calendar.test.story.tsx +34 -21
- package/src/Carousel/_stories/Carousel.test.story.tsx +18 -8
- package/src/Carousel/_stories/constants.tsx +29 -4
- package/src/Checkbox/_stories/Checkbox.test.story.tsx +22 -13
- package/src/CheckboxButton/_stories/CheckboxButton.test.story.tsx +23 -14
- package/src/Chips/_stories/Chips.test.story.tsx +51 -36
- package/src/DateInput/_stories/DateInput.rtl.test.story.tsx +62 -12
- package/src/DateLookup/_stories/DateLookup.rtl.test.story.tsx +2 -2
- package/src/Decision/_stories/Decision.test.story.tsx +74 -58
- package/src/DefinitionList/_stories/DefinitionList.test.story.tsx +58 -42
- package/src/Drawer/_stories/Drawer.rtl.test.story.tsx +65 -38
- package/src/ExpressiveMoneyInput/_stories/ExpressiveMoneyInput.rtl.test.story.tsx +107 -74
- package/src/Field/_stories/Field.test.story.tsx +18 -18
- package/src/FlowNavigation/_stories/FlowNavigation.rtl.test.story.tsx +81 -51
- package/src/Header/_stories/Header.test.story.tsx +30 -18
- package/src/Info/_stories/Info.rtl.test.story.tsx +124 -50
- package/src/InputWithDisplayFormat/_stories/InputWithDisplayFormat.test.story.tsx +4 -4
- package/src/Inputs/InputGroup/_stories/InputGroup.test.story.tsx +9 -8
- package/src/Inputs/SearchInput/_stories/SearchInput.test.story.tsx +5 -3
- package/src/Inputs/SelectInput/_stories/SelectInput.rtl.test.story.tsx +108 -79
- package/src/Inputs/TextArea/_stories/TextArea.test.story.tsx +10 -10
- package/src/InstructionsList/_stories/InstructionsList.test.story.tsx +43 -16
- package/src/Label/_stories/Label.test.story.tsx +7 -7
- package/src/Link/_stories/Link.test.story.tsx +27 -13
- package/src/ListItem/_stories/ListItem.rtl.test.story.tsx +126 -6
- package/src/ListItem/_stories/variants/helpers.tsx +174 -126
- package/src/Loader/_stories/Loader.test.story.tsx +17 -10
- package/src/Modal/_stories/Modal.rtl.test.story.tsx +58 -39
- package/src/MoneyInput/_stories/MoneyInput.rtl.test.story.tsx +21 -3
- package/src/Nudge/_stories/Nudge.test.story.tsx +70 -21
- package/src/PhoneNumberInput/_stories/PhoneNumberInput.rtl.test.story.tsx +1 -1
- package/src/Popover/_stories/Popover.rtl.test.story.tsx +92 -49
- package/src/ProgressBar/_stories/ProgressBar.test.story.tsx +6 -6
- package/src/PromoCard/_stories/PromoCard.test.story.tsx +53 -29
- package/src/PromoCard/_stories/PromoCardGroup.test.story.tsx +60 -36
- package/src/Prompt/ActionPrompt/_stories/ActionPrompt.test.story.tsx +74 -38
- package/src/Prompt/CriticalBanner/_stories/CriticalBanner.test.story.tsx +68 -31
- package/src/Prompt/InfoPrompt/_stories/InfoPrompt.test.story.tsx +52 -22
- package/src/Prompt/InlinePrompt/_stories/InlinePrompt.test.story.tsx +36 -21
- package/src/Radio/_stories/Radio.test.story.tsx +60 -46
- package/src/RadioGroup/_stories/RadioGroup.test.story.tsx +70 -51
- package/src/Section/_stories/Section.test.story.tsx +30 -14
- package/src/SegmentedControl/_stories/SegmentedControl.test.story.tsx +38 -15
- package/src/SlidingPanel/_stories/SlidingPanel.rtl.test.story.tsx +58 -34
- package/src/Snackbar/Snackbar.test.tsx +16 -0
- package/src/Snackbar/Snackbar.tsx +93 -90
- package/src/Snackbar/SnackbarProvider.tsx +4 -10
- package/src/Snackbar/_stories/Snackbar.rtl.test.story.tsx +24 -12
- package/src/Stepper/_stories/Stepper.test.story.tsx +27 -9
- package/src/Switch/_stories/Switch.test.story.tsx +20 -12
- package/src/Table/_stories/Table.test.story.tsx +107 -86
- package/src/Tabs/_stories/Tabs.test.story.tsx +92 -52
- package/src/Tag/_stories/Tag.test.story.tsx +27 -16
- package/src/TextareaWithDisplayFormat/_stories/TextareaWithDisplayFormat.test.story.tsx +4 -4
- package/src/Tooltip/_stories/Tooltip.rtl.test.story.tsx +68 -25
- package/src/Typeahead/_stories/Typeahead.rtl.test.story.tsx +4 -4
- package/src/Upload/_stories/Upload.rtl.test.story.tsx +49 -26
- package/src/UploadInput/_stories/UploadInput.test.story.tsx +63 -41
- package/src/_deprecated/Alert/_stories/Alert.test.story.tsx +45 -24
- package/src/_deprecated/Card/_stories/Card.test.story.tsx +47 -23
- package/src/_deprecated/CriticalBanner/_stories/CriticalCommsBanner.test.story.tsx +21 -15
- package/src/_deprecated/InlineAlert/_stories/InlineAlert.test.story.tsx +23 -12
- package/src/_deprecated/Select/_stories/Select.rtl.test.story.tsx +78 -42
- package/src/common/BottomSheet/_stories/BottomSheet.test.story.tsx +38 -20
- package/src/common/Panel/_stories/Panel.rtl.test.story.tsx +135 -51
- package/src/index.ts +0 -1
|
@@ -6,124 +6,121 @@ var React = require('react');
|
|
|
6
6
|
var reactTransitionGroup = require('react-transition-group');
|
|
7
7
|
var Button_resolver = require('../Button/Button.resolver.js');
|
|
8
8
|
var Body = require('../Body/Body.js');
|
|
9
|
-
var DirectionProvider = require('../Provider/Direction/DirectionProvider.js');
|
|
10
9
|
var WithNextPortal = require('../WithNextPortal/WithNextPortal.js');
|
|
11
10
|
var jsxRuntime = require('react/jsx-runtime');
|
|
12
11
|
|
|
13
12
|
const CSS_TRANSITION_DURATION = 400;
|
|
14
|
-
|
|
15
|
-
bodyRef =
|
|
16
|
-
|
|
17
|
-
transitionTimeout = 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
window.clearTimeout(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
setLeaveTimeout = () => {
|
|
39
|
-
const {
|
|
40
|
-
timeout
|
|
41
|
-
} = this.props;
|
|
42
|
-
this.timeout = window.setTimeout(() => {
|
|
43
|
-
this.setState({
|
|
44
|
-
visible: false
|
|
45
|
-
});
|
|
46
|
-
}, timeout);
|
|
47
|
-
};
|
|
48
|
-
componentDidUpdate(previousProps) {
|
|
13
|
+
const Snackbar = props => {
|
|
14
|
+
const bodyRef = React.useRef(null);
|
|
15
|
+
const leaveTimeout = React.useRef(0);
|
|
16
|
+
const transitionTimeout = React.useRef(0);
|
|
17
|
+
/** The props of the last committed render, as `this.props` was in the class component. */
|
|
18
|
+
const committedProps = React.useRef(props);
|
|
19
|
+
const [state, setState] = React.useState({
|
|
20
|
+
visible: false,
|
|
21
|
+
text: ''
|
|
22
|
+
});
|
|
23
|
+
React.useEffect(() => () => {
|
|
24
|
+
window.clearTimeout(leaveTimeout.current);
|
|
25
|
+
window.clearTimeout(transitionTimeout.current);
|
|
26
|
+
}, []);
|
|
27
|
+
// Runs after every render to mirror the componentDidUpdate lifecycle this component previously
|
|
28
|
+
// relied on, including the shouldComponentUpdate guard that ignored every update without text.
|
|
29
|
+
// Layout, not passive, so a notification is shown or replaced before the browser paints, as
|
|
30
|
+
// componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect
|
|
31
|
+
// and its synchronous state updates are what keep this conversion behaviour-identical.
|
|
32
|
+
/* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
|
|
33
|
+
React.useLayoutEffect(() => {
|
|
34
|
+
const previousProps = committedProps.current;
|
|
35
|
+
committedProps.current = props;
|
|
49
36
|
const {
|
|
50
37
|
action,
|
|
51
38
|
text,
|
|
52
39
|
timestamp
|
|
53
|
-
} =
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
} = props;
|
|
41
|
+
// shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
|
|
42
|
+
// updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
|
|
43
|
+
// given text again. Preserved here deliberately to keep this refactor behaviour-identical.
|
|
44
|
+
const updateWhileTextIsPresent = update => {
|
|
45
|
+
if (committedProps.current.text) {
|
|
46
|
+
update();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const setLeaveTimeout = () => {
|
|
50
|
+
leaveTimeout.current = window.setTimeout(() => {
|
|
51
|
+
updateWhileTextIsPresent(() => setState(current => ({
|
|
52
|
+
...current,
|
|
53
|
+
visible: false
|
|
54
|
+
})));
|
|
55
|
+
}, committedProps.current.timeout);
|
|
56
|
+
};
|
|
57
|
+
const show = () => {
|
|
58
|
+
setState(current => ({
|
|
59
|
+
...current,
|
|
56
60
|
visible: true,
|
|
57
61
|
action,
|
|
58
62
|
text
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
}));
|
|
64
|
+
setLeaveTimeout();
|
|
65
|
+
};
|
|
66
|
+
if (!text) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!previousProps.text) {
|
|
70
|
+
show();
|
|
62
71
|
} else if (previousProps.timestamp !== timestamp) {
|
|
63
|
-
window.clearTimeout(
|
|
64
|
-
if (
|
|
65
|
-
|
|
72
|
+
window.clearTimeout(leaveTimeout.current);
|
|
73
|
+
if (state.visible) {
|
|
74
|
+
setState(current => ({
|
|
75
|
+
...current,
|
|
66
76
|
visible: false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
action,
|
|
72
|
-
text
|
|
73
|
-
});
|
|
74
|
-
this.setLeaveTimeout();
|
|
75
|
-
}, CSS_TRANSITION_DURATION);
|
|
76
|
-
});
|
|
77
|
+
}));
|
|
78
|
+
transitionTimeout.current = window.setTimeout(() => {
|
|
79
|
+
updateWhileTextIsPresent(show);
|
|
80
|
+
}, CSS_TRANSITION_DURATION);
|
|
77
81
|
} else {
|
|
78
|
-
|
|
79
|
-
visible: true,
|
|
80
|
-
action,
|
|
81
|
-
text
|
|
82
|
-
});
|
|
83
|
-
this.setLeaveTimeout();
|
|
82
|
+
show();
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
85
|
+
});
|
|
86
|
+
/* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
|
|
87
|
+
const {
|
|
88
|
+
action,
|
|
89
|
+
text,
|
|
90
|
+
visible
|
|
91
|
+
} = state;
|
|
92
|
+
const {
|
|
93
|
+
timeout
|
|
94
|
+
} = props;
|
|
95
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
96
|
+
className: "snackbar",
|
|
97
|
+
"aria-live": "assertive",
|
|
98
|
+
role: "alert",
|
|
99
|
+
children: /*#__PURE__*/jsxRuntime.jsx(reactTransitionGroup.CSSTransition, {
|
|
100
|
+
nodeRef: bodyRef,
|
|
101
|
+
in: visible,
|
|
102
|
+
classNames: "snackbar__text-container",
|
|
103
|
+
timeout: {
|
|
104
|
+
appear: 0,
|
|
105
|
+
enter: timeout,
|
|
106
|
+
exit: CSS_TRANSITION_DURATION
|
|
107
|
+
},
|
|
108
|
+
unmountOnExit: true,
|
|
109
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(Body.default, {
|
|
110
|
+
ref: bodyRef,
|
|
111
|
+
as: "span",
|
|
112
|
+
className: "snackbar__text",
|
|
113
|
+
children: [text, action ? /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
|
|
114
|
+
className: "snackbar__text__action",
|
|
115
|
+
v2: true,
|
|
116
|
+
size: "sm",
|
|
117
|
+
onClick: action.onClick,
|
|
118
|
+
children: action.label
|
|
119
|
+
}) : null]
|
|
122
120
|
})
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
Snackbar.contextType = DirectionProvider.DirectionContext;
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
};
|
|
127
124
|
var SnackbarPortal = WithNextPortal.default(Snackbar);
|
|
128
125
|
|
|
129
126
|
exports.Snackbar = Snackbar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snackbar.js","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Snackbar.js","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { CSSTransition } from 'react-transition-group';\n\nimport Button from '../Button';\nimport Body from '../Body';\nimport type { ThemeDark, ThemeLight } from '../common';\nimport withNextPortal from '../WithNextPortal/WithNextPortal';\n\nconst CSS_TRANSITION_DURATION = 400;\n\nexport interface SnackbarProps {\n action?: {\n label: string;\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n };\n text: React.ReactNode;\n /** @deprecated Has no effect. Snackbar theming is based on ThemeProvider. */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text'> {\n visible: boolean;\n}\n\nexport const Snackbar = (props: SnackbarProps) => {\n const bodyRef = useRef<HTMLSpanElement>(null);\n const leaveTimeout = useRef(0);\n const transitionTimeout = useRef(0);\n /** The props of the last committed render, as `this.props` was in the class component. */\n const committedProps = useRef(props);\n\n const [state, setState] = useState<SnackbarState>({\n visible: false,\n text: '',\n });\n\n useEffect(\n () => () => {\n window.clearTimeout(leaveTimeout.current);\n window.clearTimeout(transitionTimeout.current);\n },\n [],\n );\n\n // Runs after every render to mirror the componentDidUpdate lifecycle this component previously\n // relied on, including the shouldComponentUpdate guard that ignored every update without text.\n // Layout, not passive, so a notification is shown or replaced before the browser paints, as\n // componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect\n // and its synchronous state updates are what keep this conversion behaviour-identical.\n /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n useLayoutEffect(() => {\n const previousProps = committedProps.current;\n committedProps.current = props;\n\n const { action, text, timestamp } = props;\n\n // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the\n // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is\n // given text again. Preserved here deliberately to keep this refactor behaviour-identical.\n const updateWhileTextIsPresent = (update: () => void) => {\n if (committedProps.current.text) {\n update();\n }\n };\n\n const setLeaveTimeout = () => {\n leaveTimeout.current = window.setTimeout(() => {\n updateWhileTextIsPresent(() => setState((current) => ({ ...current, visible: false })));\n }, committedProps.current.timeout);\n };\n\n const show = () => {\n setState((current) => ({ ...current, visible: true, action, text }));\n setLeaveTimeout();\n };\n\n if (!text) {\n return;\n }\n\n if (!previousProps.text) {\n show();\n } else if (previousProps.timestamp !== timestamp) {\n window.clearTimeout(leaveTimeout.current);\n\n if (state.visible) {\n setState((current) => ({ ...current, visible: false }));\n transitionTimeout.current = window.setTimeout(() => {\n updateWhileTextIsPresent(show);\n }, CSS_TRANSITION_DURATION);\n } else {\n show();\n }\n }\n });\n /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n\n const { action, text, visible } = state;\n const { timeout } = props;\n\n return (\n <div className=\"snackbar\" aria-live=\"assertive\" role=\"alert\">\n <CSSTransition\n nodeRef={bodyRef}\n in={visible}\n classNames=\"snackbar__text-container\"\n timeout={{\n appear: 0,\n enter: timeout,\n exit: CSS_TRANSITION_DURATION,\n }}\n unmountOnExit\n >\n <Body ref={bodyRef} as=\"span\" className=\"snackbar__text\">\n {text}\n {action ? (\n <Button className=\"snackbar__text__action\" v2 size=\"sm\" onClick={action.onClick}>\n {action.label}\n </Button>\n ) : null}\n </Body>\n </CSSTransition>\n </div>\n );\n};\n\nexport default withNextPortal(Snackbar);\n"],"names":["CSS_TRANSITION_DURATION","Snackbar","props","bodyRef","useRef","leaveTimeout","transitionTimeout","committedProps","state","setState","useState","visible","text","useEffect","window","clearTimeout","current","useLayoutEffect","previousProps","action","timestamp","updateWhileTextIsPresent","update","setLeaveTimeout","setTimeout","timeout","show","_jsx","className","role","children","CSSTransition","nodeRef","in","classNames","appear","enter","exit","unmountOnExit","_jsxs","Body","ref","as","Button","v2","size","onClick","label","withNextPortal"],"mappings":";;;;;;;;;;;AAQA,MAAMA,uBAAuB,GAAG,GAAG;AAkB5B,MAAMC,QAAQ,GAAIC,KAAoB,IAAI;AAC/C,EAAA,MAAMC,OAAO,GAAGC,YAAM,CAAkB,IAAI,CAAC;AAC7C,EAAA,MAAMC,YAAY,GAAGD,YAAM,CAAC,CAAC,CAAC;AAC9B,EAAA,MAAME,iBAAiB,GAAGF,YAAM,CAAC,CAAC,CAAC;AACnC;AACA,EAAA,MAAMG,cAAc,GAAGH,YAAM,CAACF,KAAK,CAAC;AAEpC,EAAA,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAQ,CAAgB;AAChDC,IAAAA,OAAO,EAAE,KAAK;AACdC,IAAAA,IAAI,EAAE;AACP,GAAA,CAAC;EAEFC,eAAS,CACP,MAAM,MAAK;AACTC,IAAAA,MAAM,CAACC,YAAY,CAACV,YAAY,CAACW,OAAO,CAAC;AACzCF,IAAAA,MAAM,CAACC,YAAY,CAACT,iBAAiB,CAACU,OAAO,CAAC;EAChD,CAAC,EACD,EAAE,CACH;AAED;AACA;AACA;AACA;AACA;AACA;AACAC,EAAAA,qBAAe,CAAC,MAAK;AACnB,IAAA,MAAMC,aAAa,GAAGX,cAAc,CAACS,OAAO;IAC5CT,cAAc,CAACS,OAAO,GAAGd,KAAK;IAE9B,MAAM;MAAEiB,MAAM;MAAEP,IAAI;AAAEQ,MAAAA;AAAS,KAAE,GAAGlB,KAAK;AAEzC;AACA;AACA;IACA,MAAMmB,wBAAwB,GAAIC,MAAkB,IAAI;AACtD,MAAA,IAAIf,cAAc,CAACS,OAAO,CAACJ,IAAI,EAAE;AAC/BU,QAAAA,MA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AM;IAAEP,IAAI;AAAED,IAAAA;AAAO,GAAE,GAAGH,KAAK;EACvC,MAAM;AAAEiB,IAAAA;AAAO,GAAE,GAAGvB,KAAK;AAEzB,EAAA,oBACEyB,cAAA,CAAA,KAAA,EAAA;AAAKC,IAAAA,SAAS,EAAC,UAAU;AAAC,IAAA,WAAA,EAAU,WAAW;AAACC,IAAAA,IAAI,EAAC,OAAO;IAAAC,QAAA,eAC1DH,cAAA,CAACI,kCAAa,EAAA;AACZC,MAAAA,OAAO,EAAE7B,OAAQ;AACjB8B,MAAAA,EAAE,EAAEtB,OAAQ;AACZuB,MAAAA,UAAU,EAAC,0BAA0B;AACrCT,MAAAA,OAAO,EAAE;AACPU,QAAAA,MAAM,EAAE,CAAC;AACTC,QAAAA,KAAK,EAAEX,OAAO;AACdY,QAAAA,IAAI,EAAErC;OACN;MACFsC,aAAa,EAAA,IAAA;MAAAR,QAAA,eAEbS,eAAA,CAACC,YAAI,EAAA;AAACC,QAAAA,GAAG,EAAEtC,OAAQ;AAACuC,QAAAA,EAAE,EAAC,MAAM;AAACd,QAAAA,SAAS,EAAC,gBAAgB;AAAAE,QAAAA,QAAA,GACrDlB,IAAI,EACJO,MAAM,gBACLQ,cAAA,CAACgB,uBAAM,EAAA;AAACf,UAAAA,SAAS,EAAC,wBAAwB;UAACgB,EAAE,EAAA,IAAA;AAACC,UAAAA,IAAI,EAAC,IAAI;UAACC,OAAO,EAAE3B,MAAM,CAAC2B,OAAQ;UAAAhB,QAAA,EAC7EX,MAAM,CAAC4B;SACF,CAAC,GACP,IAAI;OACJ;KACO;AACjB,GAAK,CAAC;AAEV;AAEA,qBAAeC,sBAAc,CAAC/C,QAAQ,CAAC;;;"}
|
|
@@ -1,125 +1,122 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef, useState, useEffect, useLayoutEffect } from 'react';
|
|
2
2
|
import { CSSTransition } from 'react-transition-group';
|
|
3
3
|
import Button from '../Button/Button.resolver.mjs';
|
|
4
4
|
import Body from '../Body/Body.mjs';
|
|
5
|
-
import { DirectionContext } from '../Provider/Direction/DirectionProvider.mjs';
|
|
6
5
|
import withNextPortalWrapper from '../WithNextPortal/WithNextPortal.mjs';
|
|
7
6
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
8
7
|
|
|
9
8
|
const CSS_TRANSITION_DURATION = 400;
|
|
10
|
-
|
|
11
|
-
bodyRef =
|
|
12
|
-
|
|
13
|
-
transitionTimeout = 0;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
window.clearTimeout(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
setLeaveTimeout = () => {
|
|
35
|
-
const {
|
|
36
|
-
timeout
|
|
37
|
-
} = this.props;
|
|
38
|
-
this.timeout = window.setTimeout(() => {
|
|
39
|
-
this.setState({
|
|
40
|
-
visible: false
|
|
41
|
-
});
|
|
42
|
-
}, timeout);
|
|
43
|
-
};
|
|
44
|
-
componentDidUpdate(previousProps) {
|
|
9
|
+
const Snackbar = props => {
|
|
10
|
+
const bodyRef = useRef(null);
|
|
11
|
+
const leaveTimeout = useRef(0);
|
|
12
|
+
const transitionTimeout = useRef(0);
|
|
13
|
+
/** The props of the last committed render, as `this.props` was in the class component. */
|
|
14
|
+
const committedProps = useRef(props);
|
|
15
|
+
const [state, setState] = useState({
|
|
16
|
+
visible: false,
|
|
17
|
+
text: ''
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => () => {
|
|
20
|
+
window.clearTimeout(leaveTimeout.current);
|
|
21
|
+
window.clearTimeout(transitionTimeout.current);
|
|
22
|
+
}, []);
|
|
23
|
+
// Runs after every render to mirror the componentDidUpdate lifecycle this component previously
|
|
24
|
+
// relied on, including the shouldComponentUpdate guard that ignored every update without text.
|
|
25
|
+
// Layout, not passive, so a notification is shown or replaced before the browser paints, as
|
|
26
|
+
// componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect
|
|
27
|
+
// and its synchronous state updates are what keep this conversion behaviour-identical.
|
|
28
|
+
/* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
const previousProps = committedProps.current;
|
|
31
|
+
committedProps.current = props;
|
|
45
32
|
const {
|
|
46
33
|
action,
|
|
47
34
|
text,
|
|
48
35
|
timestamp
|
|
49
|
-
} =
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
} = props;
|
|
37
|
+
// shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
|
|
38
|
+
// updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
|
|
39
|
+
// given text again. Preserved here deliberately to keep this refactor behaviour-identical.
|
|
40
|
+
const updateWhileTextIsPresent = update => {
|
|
41
|
+
if (committedProps.current.text) {
|
|
42
|
+
update();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const setLeaveTimeout = () => {
|
|
46
|
+
leaveTimeout.current = window.setTimeout(() => {
|
|
47
|
+
updateWhileTextIsPresent(() => setState(current => ({
|
|
48
|
+
...current,
|
|
49
|
+
visible: false
|
|
50
|
+
})));
|
|
51
|
+
}, committedProps.current.timeout);
|
|
52
|
+
};
|
|
53
|
+
const show = () => {
|
|
54
|
+
setState(current => ({
|
|
55
|
+
...current,
|
|
52
56
|
visible: true,
|
|
53
57
|
action,
|
|
54
58
|
text
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
}));
|
|
60
|
+
setLeaveTimeout();
|
|
61
|
+
};
|
|
62
|
+
if (!text) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!previousProps.text) {
|
|
66
|
+
show();
|
|
58
67
|
} else if (previousProps.timestamp !== timestamp) {
|
|
59
|
-
window.clearTimeout(
|
|
60
|
-
if (
|
|
61
|
-
|
|
68
|
+
window.clearTimeout(leaveTimeout.current);
|
|
69
|
+
if (state.visible) {
|
|
70
|
+
setState(current => ({
|
|
71
|
+
...current,
|
|
62
72
|
visible: false
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
action,
|
|
68
|
-
text
|
|
69
|
-
});
|
|
70
|
-
this.setLeaveTimeout();
|
|
71
|
-
}, CSS_TRANSITION_DURATION);
|
|
72
|
-
});
|
|
73
|
+
}));
|
|
74
|
+
transitionTimeout.current = window.setTimeout(() => {
|
|
75
|
+
updateWhileTextIsPresent(show);
|
|
76
|
+
}, CSS_TRANSITION_DURATION);
|
|
73
77
|
} else {
|
|
74
|
-
|
|
75
|
-
visible: true,
|
|
76
|
-
action,
|
|
77
|
-
text
|
|
78
|
-
});
|
|
79
|
-
this.setLeaveTimeout();
|
|
78
|
+
show();
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
81
|
+
});
|
|
82
|
+
/* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
|
|
83
|
+
const {
|
|
84
|
+
action,
|
|
85
|
+
text,
|
|
86
|
+
visible
|
|
87
|
+
} = state;
|
|
88
|
+
const {
|
|
89
|
+
timeout
|
|
90
|
+
} = props;
|
|
91
|
+
return /*#__PURE__*/jsx("div", {
|
|
92
|
+
className: "snackbar",
|
|
93
|
+
"aria-live": "assertive",
|
|
94
|
+
role: "alert",
|
|
95
|
+
children: /*#__PURE__*/jsx(CSSTransition, {
|
|
96
|
+
nodeRef: bodyRef,
|
|
97
|
+
in: visible,
|
|
98
|
+
classNames: "snackbar__text-container",
|
|
99
|
+
timeout: {
|
|
100
|
+
appear: 0,
|
|
101
|
+
enter: timeout,
|
|
102
|
+
exit: CSS_TRANSITION_DURATION
|
|
103
|
+
},
|
|
104
|
+
unmountOnExit: true,
|
|
105
|
+
children: /*#__PURE__*/jsxs(Body, {
|
|
106
|
+
ref: bodyRef,
|
|
107
|
+
as: "span",
|
|
108
|
+
className: "snackbar__text",
|
|
109
|
+
children: [text, action ? /*#__PURE__*/jsx(Button, {
|
|
110
|
+
className: "snackbar__text__action",
|
|
111
|
+
v2: true,
|
|
112
|
+
size: "sm",
|
|
113
|
+
onClick: action.onClick,
|
|
114
|
+
children: action.label
|
|
115
|
+
}) : null]
|
|
118
116
|
})
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
Snackbar.contextType = DirectionContext;
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
};
|
|
123
120
|
var SnackbarPortal = withNextPortalWrapper(Snackbar);
|
|
124
121
|
|
|
125
122
|
export { Snackbar, SnackbarPortal as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snackbar.mjs","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Snackbar.mjs","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { CSSTransition } from 'react-transition-group';\n\nimport Button from '../Button';\nimport Body from '../Body';\nimport type { ThemeDark, ThemeLight } from '../common';\nimport withNextPortal from '../WithNextPortal/WithNextPortal';\n\nconst CSS_TRANSITION_DURATION = 400;\n\nexport interface SnackbarProps {\n action?: {\n label: string;\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n };\n text: React.ReactNode;\n /** @deprecated Has no effect. Snackbar theming is based on ThemeProvider. */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text'> {\n visible: boolean;\n}\n\nexport const Snackbar = (props: SnackbarProps) => {\n const bodyRef = useRef<HTMLSpanElement>(null);\n const leaveTimeout = useRef(0);\n const transitionTimeout = useRef(0);\n /** The props of the last committed render, as `this.props` was in the class component. */\n const committedProps = useRef(props);\n\n const [state, setState] = useState<SnackbarState>({\n visible: false,\n text: '',\n });\n\n useEffect(\n () => () => {\n window.clearTimeout(leaveTimeout.current);\n window.clearTimeout(transitionTimeout.current);\n },\n [],\n );\n\n // Runs after every render to mirror the componentDidUpdate lifecycle this component previously\n // relied on, including the shouldComponentUpdate guard that ignored every update without text.\n // Layout, not passive, so a notification is shown or replaced before the browser paints, as\n // componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect\n // and its synchronous state updates are what keep this conversion behaviour-identical.\n /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n useLayoutEffect(() => {\n const previousProps = committedProps.current;\n committedProps.current = props;\n\n const { action, text, timestamp } = props;\n\n // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the\n // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is\n // given text again. Preserved here deliberately to keep this refactor behaviour-identical.\n const updateWhileTextIsPresent = (update: () => void) => {\n if (committedProps.current.text) {\n update();\n }\n };\n\n const setLeaveTimeout = () => {\n leaveTimeout.current = window.setTimeout(() => {\n updateWhileTextIsPresent(() => setState((current) => ({ ...current, visible: false })));\n }, committedProps.current.timeout);\n };\n\n const show = () => {\n setState((current) => ({ ...current, visible: true, action, text }));\n setLeaveTimeout();\n };\n\n if (!text) {\n return;\n }\n\n if (!previousProps.text) {\n show();\n } else if (previousProps.timestamp !== timestamp) {\n window.clearTimeout(leaveTimeout.current);\n\n if (state.visible) {\n setState((current) => ({ ...current, visible: false }));\n transitionTimeout.current = window.setTimeout(() => {\n updateWhileTextIsPresent(show);\n }, CSS_TRANSITION_DURATION);\n } else {\n show();\n }\n }\n });\n /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n\n const { action, text, visible } = state;\n const { timeout } = props;\n\n return (\n <div className=\"snackbar\" aria-live=\"assertive\" role=\"alert\">\n <CSSTransition\n nodeRef={bodyRef}\n in={visible}\n classNames=\"snackbar__text-container\"\n timeout={{\n appear: 0,\n enter: timeout,\n exit: CSS_TRANSITION_DURATION,\n }}\n unmountOnExit\n >\n <Body ref={bodyRef} as=\"span\" className=\"snackbar__text\">\n {text}\n {action ? (\n <Button className=\"snackbar__text__action\" v2 size=\"sm\" onClick={action.onClick}>\n {action.label}\n </Button>\n ) : null}\n </Body>\n </CSSTransition>\n </div>\n );\n};\n\nexport default withNextPortal(Snackbar);\n"],"names":["CSS_TRANSITION_DURATION","Snackbar","props","bodyRef","useRef","leaveTimeout","transitionTimeout","committedProps","state","setState","useState","visible","text","useEffect","window","clearTimeout","current","useLayoutEffect","previousProps","action","timestamp","updateWhileTextIsPresent","update","setLeaveTimeout","setTimeout","timeout","show","_jsx","className","role","children","CSSTransition","nodeRef","in","classNames","appear","enter","exit","unmountOnExit","_jsxs","Body","ref","as","Button","v2","size","onClick","label","withNextPortal"],"mappings":";;;;;;;AAQA,MAAMA,uBAAuB,GAAG,GAAG;AAkB5B,MAAMC,QAAQ,GAAIC,KAAoB,IAAI;AAC/C,EAAA,MAAMC,OAAO,GAAGC,MAAM,CAAkB,IAAI,CAAC;AAC7C,EAAA,MAAMC,YAAY,GAAGD,MAAM,CAAC,CAAC,CAAC;AAC9B,EAAA,MAAME,iBAAiB,GAAGF,MAAM,CAAC,CAAC,CAAC;AACnC;AACA,EAAA,MAAMG,cAAc,GAAGH,MAAM,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ErC;OACN;MACFsC,aAAa,EAAA,IAAA;MAAAR,QAAA,eAEbS,IAAA,CAACC,IAAI,EAAA;AAACC,QAAAA,GAAG,EAAEtC,OAAQ;AAACuC,QAAAA,EAAE,EAAC,MAAM;AAACd,QAAAA,SAAS,EAAC,gBAAgB;AAAAE,QAAAA,QAAA,GACrDlB,IAAI,EACJO,MAAM,gBACLQ,GAAA,CAACgB,MAAM,EAAA;AAACf,UAAAA,SAAS,EAAC,wBAAwB;UAACgB,EAAE,EAAA,IAAA;AAACC,UAAAA,IAAI,EAAC,IAAI;UAACC,OAAO,EAAE3B,MAAM,CAAC2B,OAAQ;UAAAhB,QAAA,EAC7EX,MAAM,CAAC4B;SACF,CAAC,GACP,IAAI;OACJ;KACO;AACjB,GAAK,CAAC;AAEV;AAEA,qBAAeC,qBAAc,CAAC/C,QAAQ,CAAC;;"}
|
|
@@ -18,20 +18,17 @@ function SnackbarProvider({
|
|
|
18
18
|
const {
|
|
19
19
|
action,
|
|
20
20
|
text,
|
|
21
|
-
theme,
|
|
22
21
|
timestamp
|
|
23
22
|
} = state;
|
|
24
23
|
return /*#__PURE__*/jsxRuntime.jsxs(SnackbarContext.SnackbarContext.Provider, {
|
|
25
24
|
value: React.useMemo(() => ({
|
|
26
25
|
createSnackbar: ({
|
|
27
26
|
action,
|
|
28
|
-
text
|
|
29
|
-
theme
|
|
27
|
+
text
|
|
30
28
|
}) => {
|
|
31
29
|
setState({
|
|
32
30
|
action,
|
|
33
31
|
text,
|
|
34
|
-
theme,
|
|
35
32
|
timestamp: Date.now()
|
|
36
33
|
});
|
|
37
34
|
}
|
|
@@ -40,8 +37,7 @@ function SnackbarProvider({
|
|
|
40
37
|
action: action,
|
|
41
38
|
text: text,
|
|
42
39
|
timestamp: timestamp,
|
|
43
|
-
timeout: timeout
|
|
44
|
-
theme: theme
|
|
40
|
+
timeout: timeout
|
|
45
41
|
}), children]
|
|
46
42
|
});
|
|
47
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnackbarProvider.js","sources":["../../src/Snackbar/SnackbarProvider.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\n\nimport SnackbarPortal, { SnackbarProps } from './Snackbar';\nimport { SnackbarContext } from './SnackbarContext';\n\nexport interface SnackbarProviderProps {\n timeout?: number;\n children?: React.ReactNode;\n}\n\nexport default function SnackbarProvider({ timeout = 4500, children }: SnackbarProviderProps) {\n const [state, setState] = useState<Omit<SnackbarProps, 'timeout'>>({\n text: '',\n timestamp: 0,\n });\n const { action, text,
|
|
1
|
+
{"version":3,"file":"SnackbarProvider.js","sources":["../../src/Snackbar/SnackbarProvider.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\n\nimport SnackbarPortal, { SnackbarProps } from './Snackbar';\nimport { SnackbarContext } from './SnackbarContext';\n\nexport interface SnackbarProviderProps {\n timeout?: number;\n children?: React.ReactNode;\n}\n\nexport default function SnackbarProvider({ timeout = 4500, children }: SnackbarProviderProps) {\n const [state, setState] = useState<Omit<SnackbarProps, 'timeout'>>({\n text: '',\n timestamp: 0,\n });\n const { action, text, timestamp } = state;\n\n return (\n <SnackbarContext.Provider\n value={useMemo(\n () => ({\n createSnackbar: ({ action, text }) => {\n setState({ action, text, timestamp: Date.now() });\n },\n }),\n [],\n )}\n >\n <SnackbarPortal action={action} text={text} timestamp={timestamp} timeout={timeout} />\n {children}\n </SnackbarContext.Provider>\n );\n}\n"],"names":["SnackbarProvider","timeout","children","state","setState","useState","text","timestamp","action","_jsxs","SnackbarContext","Provider","value","useMemo","createSnackbar","Date","now","_jsx","SnackbarPortal"],"mappings":";;;;;;;;;AAUc,SAAUA,gBAAgBA,CAAC;AAAEC,EAAAA,OAAO,GAAG,IAAI;AAAEC,EAAAA;AAAQ,CAAyB,EAAA;AAC1F,EAAA,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAQ,CAAiC;AACjEC,IAAAA,IAAI,EAAE,EAAE;AACRC,IAAAA,SAAS,EAAE;AACZ,GAAA,CAAC;EACF,MAAM;IAAEC,MAAM;IAAEF,IAAI;AAAEC,IAAAA;AAAS,GAAE,GAAGJ,KAAK;AAEzC,EAAA,oBACEM,eAAA,CAACC,+BAAe,CAACC,QAAQ,EAAA;IACvBC,KAAK,EAAEC,aAAO,CACZ,OAAO;AACLC,MAAAA,cAAc,EAAEA,CAAC;QAAEN,MAAM;AAAEF,QAAAA;AAAI,OAAE,KAAI;AACnCF,QAAAA,QAAQ,CAAC;UAAEI,MAAM;UAAEF,IAAI;AAAEC,UAAAA,SAAS,EAAEQ,IAAI,CAACC,GAAG;AAAE,SAAE,CAAC;AACnD,MAAA;KACD,CAAC,EACF,EAAE,CACF;IAAAd,QAAA,EAAA,cAEFe,cAAA,CAACC,gBAAc,EAAA;AAACV,MAAAA,MAAM,EAAEA,MAAO;AAACF,MAAAA,IAAI,EAAEA,IAAK;AAACC,MAAAA,SAAS,EAAEA,SAAU;AAACN,MAAAA,OAAO,EAAEA;KAAQ,CACnF,EAACC,QAAQ;AAAA,GACe,CAAC;AAE/B;;"}
|
|
@@ -14,20 +14,17 @@ function SnackbarProvider({
|
|
|
14
14
|
const {
|
|
15
15
|
action,
|
|
16
16
|
text,
|
|
17
|
-
theme,
|
|
18
17
|
timestamp
|
|
19
18
|
} = state;
|
|
20
19
|
return /*#__PURE__*/jsxs(SnackbarContext.Provider, {
|
|
21
20
|
value: useMemo(() => ({
|
|
22
21
|
createSnackbar: ({
|
|
23
22
|
action,
|
|
24
|
-
text
|
|
25
|
-
theme
|
|
23
|
+
text
|
|
26
24
|
}) => {
|
|
27
25
|
setState({
|
|
28
26
|
action,
|
|
29
27
|
text,
|
|
30
|
-
theme,
|
|
31
28
|
timestamp: Date.now()
|
|
32
29
|
});
|
|
33
30
|
}
|
|
@@ -36,8 +33,7 @@ function SnackbarProvider({
|
|
|
36
33
|
action: action,
|
|
37
34
|
text: text,
|
|
38
35
|
timestamp: timestamp,
|
|
39
|
-
timeout: timeout
|
|
40
|
-
theme: theme
|
|
36
|
+
timeout: timeout
|
|
41
37
|
}), children]
|
|
42
38
|
});
|
|
43
39
|
}
|