@transferwise/components 0.0.0-experimental-e94d625 → 0.0.0-experimental-8e1de95

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 (69) hide show
  1. package/build/Snackbar/Snackbar.js +97 -101
  2. package/build/Snackbar/Snackbar.js.map +1 -1
  3. package/build/Snackbar/Snackbar.mjs +98 -102
  4. package/build/Snackbar/Snackbar.mjs.map +1 -1
  5. package/build/types/Carousel/_stories/constants.d.ts +25 -0
  6. package/build/types/Carousel/_stories/constants.d.ts.map +1 -1
  7. package/build/types/ListItem/_stories/variants/helpers.d.ts +38 -1
  8. package/build/types/ListItem/_stories/variants/helpers.d.ts.map +1 -1
  9. package/build/types/Snackbar/Snackbar.d.ts +1 -15
  10. package/build/types/Snackbar/Snackbar.d.ts.map +1 -1
  11. package/package.json +1 -1
  12. package/src/Accordion/_stories/Accordion.test.story.tsx +74 -48
  13. package/src/AvatarLayout/_stories/AvatarLayout.test.story.tsx +46 -30
  14. package/src/Button/LegacyButton/_stories/LegacyButton.test.story.tsx +29 -19
  15. package/src/Calendar/_stories/Calendar.test.story.tsx +34 -21
  16. package/src/Carousel/_stories/Carousel.test.story.tsx +18 -8
  17. package/src/Carousel/_stories/constants.tsx +29 -4
  18. package/src/Checkbox/_stories/Checkbox.test.story.tsx +22 -13
  19. package/src/CheckboxButton/_stories/CheckboxButton.test.story.tsx +23 -14
  20. package/src/Chips/_stories/Chips.test.story.tsx +51 -36
  21. package/src/DateInput/_stories/DateInput.rtl.test.story.tsx +62 -12
  22. package/src/Decision/_stories/Decision.test.story.tsx +74 -58
  23. package/src/DefinitionList/_stories/DefinitionList.test.story.tsx +58 -42
  24. package/src/Drawer/_stories/Drawer.rtl.test.story.tsx +65 -38
  25. package/src/ExpressiveMoneyInput/_stories/ExpressiveMoneyInput.rtl.test.story.tsx +107 -74
  26. package/src/Field/_stories/Field.test.story.tsx +1 -1
  27. package/src/FlowNavigation/_stories/FlowNavigation.rtl.test.story.tsx +81 -51
  28. package/src/Header/_stories/Header.test.story.tsx +30 -18
  29. package/src/Info/_stories/Info.rtl.test.story.tsx +124 -50
  30. package/src/Inputs/InputGroup/_stories/InputGroup.test.story.tsx +4 -2
  31. package/src/Inputs/SelectInput/_stories/SelectInput.rtl.test.story.tsx +106 -77
  32. package/src/InstructionsList/_stories/InstructionsList.test.story.tsx +43 -16
  33. package/src/Link/_stories/Link.test.story.tsx +27 -13
  34. package/src/ListItem/_stories/ListItem.rtl.test.story.tsx +126 -6
  35. package/src/ListItem/_stories/variants/helpers.tsx +174 -126
  36. package/src/Loader/_stories/Loader.test.story.tsx +17 -10
  37. package/src/Modal/_stories/Modal.rtl.test.story.tsx +58 -39
  38. package/src/MoneyInput/_stories/MoneyInput.rtl.test.story.tsx +14 -2
  39. package/src/Nudge/_stories/Nudge.test.story.tsx +70 -21
  40. package/src/Popover/_stories/Popover.rtl.test.story.tsx +92 -49
  41. package/src/PromoCard/_stories/PromoCard.test.story.tsx +53 -29
  42. package/src/PromoCard/_stories/PromoCardGroup.test.story.tsx +60 -36
  43. package/src/Prompt/ActionPrompt/_stories/ActionPrompt.test.story.tsx +74 -38
  44. package/src/Prompt/CriticalBanner/_stories/CriticalBanner.test.story.tsx +68 -31
  45. package/src/Prompt/InfoPrompt/_stories/InfoPrompt.test.story.tsx +52 -22
  46. package/src/Prompt/InlinePrompt/_stories/InlinePrompt.test.story.tsx +36 -21
  47. package/src/Radio/_stories/Radio.test.story.tsx +60 -46
  48. package/src/RadioGroup/_stories/RadioGroup.test.story.tsx +70 -51
  49. package/src/Section/_stories/Section.test.story.tsx +30 -14
  50. package/src/SegmentedControl/_stories/SegmentedControl.test.story.tsx +38 -15
  51. package/src/SlidingPanel/_stories/SlidingPanel.rtl.test.story.tsx +58 -34
  52. package/src/Snackbar/Snackbar.tsx +90 -88
  53. package/src/Snackbar/_stories/Snackbar.rtl.test.story.tsx +24 -12
  54. package/src/Stepper/_stories/Stepper.test.story.tsx +27 -9
  55. package/src/Switch/_stories/Switch.test.story.tsx +20 -12
  56. package/src/Table/_stories/Table.test.story.tsx +107 -86
  57. package/src/Tabs/_stories/Tabs.test.story.tsx +92 -52
  58. package/src/Tag/_stories/Tag.test.story.tsx +27 -16
  59. package/src/Tooltip/_stories/Tooltip.rtl.test.story.tsx +68 -25
  60. package/src/Typeahead/_stories/Typeahead.rtl.test.story.tsx +3 -3
  61. package/src/Upload/_stories/Upload.rtl.test.story.tsx +49 -26
  62. package/src/UploadInput/_stories/UploadInput.test.story.tsx +63 -41
  63. package/src/_deprecated/Alert/_stories/Alert.test.story.tsx +45 -24
  64. package/src/_deprecated/Card/_stories/Card.test.story.tsx +47 -23
  65. package/src/_deprecated/CriticalBanner/_stories/CriticalCommsBanner.test.story.tsx +21 -15
  66. package/src/_deprecated/InlineAlert/_stories/InlineAlert.test.story.tsx +23 -12
  67. package/src/_deprecated/Select/_stories/Select.rtl.test.story.tsx +76 -40
  68. package/src/common/BottomSheet/_stories/BottomSheet.test.story.tsx +38 -20
  69. package/src/common/Panel/_stories/Panel.rtl.test.story.tsx +135 -51
@@ -6,124 +6,120 @@ 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
- class Snackbar extends React.Component {
15
- bodyRef = /*#__PURE__*/React.createRef();
16
- timeout = 0;
17
- transitionTimeout = 0;
18
- constructor(props) {
19
- super(props);
20
- this.state = {
21
- visible: false,
22
- text: ''
23
- };
24
- }
25
- componentWillUnmount() {
26
- window.clearTimeout(this.timeout);
27
- window.clearTimeout(this.transitionTimeout);
28
- }
29
- shouldComponentUpdate(nextProps, nextState) {
30
- if (!nextProps.text) {
31
- return false;
32
- }
33
- if (nextProps.timestamp === this.props.timestamp && nextState.visible === this.state.visible && nextState.text === this.state.text) {
34
- return false;
35
- }
36
- return true;
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
+ // Both rules below are disabled on purpose: the dependency-less effect and its synchronous state
30
+ // updates are what keep this conversion behaviour-identical to the class component.
31
+ /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
32
+ React.useEffect(() => {
33
+ const previousProps = committedProps.current;
34
+ committedProps.current = props;
49
35
  const {
50
36
  action,
51
37
  text,
52
38
  timestamp
53
- } = this.props;
54
- if (!previousProps.text) {
55
- this.setState({
39
+ } = props;
40
+ // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
41
+ // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
42
+ // given text again. Preserved here deliberately to keep this refactor behaviour-identical.
43
+ const updateWhileTextIsPresent = update => {
44
+ if (committedProps.current.text) {
45
+ update();
46
+ }
47
+ };
48
+ const setLeaveTimeout = () => {
49
+ leaveTimeout.current = window.setTimeout(() => {
50
+ updateWhileTextIsPresent(() => setState(current => ({
51
+ ...current,
52
+ visible: false
53
+ })));
54
+ }, committedProps.current.timeout);
55
+ };
56
+ const show = () => {
57
+ setState(current => ({
58
+ ...current,
56
59
  visible: true,
57
60
  action,
58
61
  text
59
- }, () => {
60
- this.setLeaveTimeout();
61
- });
62
+ }));
63
+ setLeaveTimeout();
64
+ };
65
+ if (!text) {
66
+ return;
67
+ }
68
+ if (!previousProps.text) {
69
+ show();
62
70
  } else if (previousProps.timestamp !== timestamp) {
63
- window.clearTimeout(this.timeout);
64
- if (this.state.visible) {
65
- this.setState({
71
+ window.clearTimeout(leaveTimeout.current);
72
+ if (state.visible) {
73
+ setState(current => ({
74
+ ...current,
66
75
  visible: false
67
- }, () => {
68
- this.transitionTimeout = window.setTimeout(() => {
69
- this.setState({
70
- visible: true,
71
- action,
72
- text
73
- });
74
- this.setLeaveTimeout();
75
- }, CSS_TRANSITION_DURATION);
76
- });
76
+ }));
77
+ transitionTimeout.current = window.setTimeout(() => {
78
+ updateWhileTextIsPresent(show);
79
+ }, CSS_TRANSITION_DURATION);
77
80
  } else {
78
- this.setState({
79
- visible: true,
80
- action,
81
- text
82
- });
83
- this.setLeaveTimeout();
81
+ show();
84
82
  }
85
83
  }
86
- }
87
- render() {
88
- const {
89
- action,
90
- text,
91
- visible
92
- } = this.state;
93
- const {
94
- timeout
95
- } = this.props;
96
- return /*#__PURE__*/jsxRuntime.jsx("div", {
97
- className: "snackbar",
98
- "aria-live": "assertive",
99
- role: "alert",
100
- children: /*#__PURE__*/jsxRuntime.jsx(reactTransitionGroup.CSSTransition, {
101
- nodeRef: this.bodyRef,
102
- in: visible,
103
- classNames: "snackbar__text-container",
104
- timeout: {
105
- appear: 0,
106
- enter: timeout,
107
- exit: CSS_TRANSITION_DURATION
108
- },
109
- unmountOnExit: true,
110
- children: /*#__PURE__*/jsxRuntime.jsxs(Body.default, {
111
- ref: this.bodyRef,
112
- as: "span",
113
- className: "snackbar__text",
114
- children: [text, action ? /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
115
- className: "snackbar__text__action",
116
- v2: true,
117
- size: "sm",
118
- onClick: action.onClick,
119
- children: action.label
120
- }) : null]
121
- })
84
+ });
85
+ /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
86
+ const {
87
+ action,
88
+ text,
89
+ visible
90
+ } = state;
91
+ const {
92
+ timeout
93
+ } = props;
94
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
95
+ className: "snackbar",
96
+ "aria-live": "assertive",
97
+ role: "alert",
98
+ children: /*#__PURE__*/jsxRuntime.jsx(reactTransitionGroup.CSSTransition, {
99
+ nodeRef: bodyRef,
100
+ in: visible,
101
+ classNames: "snackbar__text-container",
102
+ timeout: {
103
+ appear: 0,
104
+ enter: timeout,
105
+ exit: CSS_TRANSITION_DURATION
106
+ },
107
+ unmountOnExit: true,
108
+ children: /*#__PURE__*/jsxRuntime.jsxs(Body.default, {
109
+ ref: bodyRef,
110
+ as: "span",
111
+ className: "snackbar__text",
112
+ children: [text, action ? /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
113
+ className: "snackbar__text__action",
114
+ v2: true,
115
+ size: "sm",
116
+ onClick: action.onClick,
117
+ children: action.label
118
+ }) : null]
122
119
  })
123
- });
124
- }
125
- }
126
- Snackbar.contextType = DirectionProvider.DirectionContext;
120
+ })
121
+ });
122
+ };
127
123
  var SnackbarPortal = WithNextPortal.default(Snackbar);
128
124
 
129
125
  exports.Snackbar = Snackbar;
@@ -1 +1 @@
1
- {"version":3,"file":"Snackbar.js","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { Component, createRef } from 'react';\nimport { CSSTransition } from 'react-transition-group';\n\nimport Button from '../Button';\nimport Body from '../Body';\nimport type { ThemeDark, ThemeLight } from '../common';\nimport { DirectionContext } from '../Provider/Direction';\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 */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text' | 'theme'> {\n visible: boolean;\n}\n\nexport class Snackbar extends Component<SnackbarProps, SnackbarState> {\n bodyRef = createRef<HTMLSpanElement>();\n timeout = 0;\n transitionTimeout = 0;\n\n constructor(props: SnackbarProps) {\n super(props);\n this.state = {\n visible: false,\n text: '',\n };\n }\n\n componentWillUnmount() {\n window.clearTimeout(this.timeout);\n window.clearTimeout(this.transitionTimeout);\n }\n\n shouldComponentUpdate(nextProps: SnackbarProps, nextState: SnackbarState) {\n if (!nextProps.text) {\n return false;\n }\n if (\n nextProps.timestamp === this.props.timestamp &&\n nextState.visible === this.state.visible &&\n nextState.text === this.state.text\n ) {\n return false;\n }\n\n return true;\n }\n\n setLeaveTimeout = () => {\n const { timeout } = this.props;\n\n this.timeout = window.setTimeout(() => {\n this.setState({ visible: false });\n }, timeout);\n };\n\n componentDidUpdate(previousProps: SnackbarProps) {\n const { action, text, timestamp } = this.props;\n\n if (!previousProps.text) {\n this.setState({ visible: true, action, text }, () => {\n this.setLeaveTimeout();\n });\n } else if (previousProps.timestamp !== timestamp) {\n window.clearTimeout(this.timeout);\n\n if (this.state.visible) {\n this.setState({ visible: false }, () => {\n this.transitionTimeout = window.setTimeout(() => {\n this.setState({ visible: true, action, text });\n this.setLeaveTimeout();\n }, CSS_TRANSITION_DURATION);\n });\n } else {\n this.setState({ visible: true, action, text });\n this.setLeaveTimeout();\n }\n }\n }\n\n render() {\n const { action, text, visible } = this.state;\n const { timeout } = this.props;\n\n return (\n <div className=\"snackbar\" aria-live=\"assertive\" role=\"alert\">\n <CSSTransition\n nodeRef={this.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={this.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}\n\nSnackbar.contextType = DirectionContext;\n\nexport default withNextPortal(Snackbar);\n"],"names":["CSS_TRANSITION_DURATION","Snackbar","Component","bodyRef","createRef","timeout","transitionTimeout","constructor","props","state","visible","text","componentWillUnmount","window","clearTimeout","shouldComponentUpdate","nextProps","nextState","timestamp","setLeaveTimeout","setTimeout","setState","componentDidUpdate","previousProps","action","render","_jsx","className","role","children","CSSTransition","nodeRef","in","classNames","appear","enter","exit","unmountOnExit","_jsxs","Body","ref","as","Button","v2","size","onClick","label","contextType","DirectionContext","withNextPortal"],"mappings":";;;;;;;;;;;;AASA,MAAMA,uBAAuB,GAAG,GAAG;AAkB7B,MAAOC,QAAS,SAAQC,eAAuC,CAAA;EACnEC,OAAO,gBAAGC,eAAS,EAAmB;AACtCC,EAAAA,OAAO,GAAG,CAAC;AACXC,EAAAA,iBAAiB,GAAG,CAAC;EAErBC,WAAAA,CAAYC,KAAoB,EAAA;IAC9B,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,OAAO,EAAE,KAAK;AACdC,MAAAA,IAAI,EAAE;KACP;AACH,EAAA;AAEAC,EAAAA,oBAAoBA,GAAA;AAClBC,IAAAA,MAAM,CAACC,YAAY,CAAC,IAAI,CAACT,OAAO,CAAC;AACjCQ,IAAAA,MAAM,CAACC,YAAY,CAAC,IAAI,CAACR,iBAAiB,CAAC;AAC7C,EAAA;AAEAS,EAAAA,qBAAqBA,CAACC,SAAwB,EAAEC,SAAwB,EAAA;AACtE,IAAA,IAAI,CAACD,SAAS,CAACL,IAAI,EAAE;AACnB,MAAA,OAAO,KAAK;AACd,IAAA;AACA,IAAA,IACEK,SAAS,CAACE,SAAS,KAAK,IAAI,CAACV,KAAK,CAACU,SAAS,IAC5CD,SAAS,CAACP,OAAO,KAAK,IAAI,CAACD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AAErB,MAAM,CAACqB,OAAQ;YAAAhB,QAAA,EAC7EL,MAAM,CAACsB;WACF,CAAC,GACP,IAAI;SACJ;OACO;AACjB,KAAK,CAAC;AAEV,EAAA;AACD;AAED7C,QAAQ,CAAC8C,WAAW,GAAGC,kCAAgB;AAEvC,qBAAeC,sBAAc,CAAChD,QAAQ,CAAC;;;"}
1
+ {"version":3,"file":"Snackbar.js","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { useEffect, 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 */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text' | 'theme'> {\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 // Both rules below are disabled on purpose: the dependency-less effect and its synchronous state\n // updates are what keep this conversion behaviour-identical to the class component.\n /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n useEffect(() => {\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","previousProps","action","timestamp","updateWhileTextIsPresent","update","setLeaveTimeout","setTimeout","timeout","show","_jsx","className","role","children","CSSTransition","nodeRef","in","classNames","appear","enter","exit","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AAKC,IAAAA,SAAS,EAAC,UAAU;AAAC,IAAA,WAAA,EAAU,WAAW;AAACC,IAAAA,IAAI,EAAC,OAAO;IAAAC,QAAA,eAC1DH,cAAA,CAACI,kCAAa,EAAA;AACZC,MAAAA,OAAO,EAAE5B,OAAQ;AACjB6B,MAAAA,EAAE,EAAErB,OAAQ;AACZsB,MAAAA,UAAU,EAAC,0BAA0B;AACrCT,MAAAA,OAAO,EAAE;AACPU,QAAAA,MAAM,EAAE,CAAC;AACTC,QAAAA,KAAK,EAAEX,OAAO;AACdY,QAAAA,IAAI,EAAEpC;OACN;MACFqC,aAAa,EAAA,IAAA;MAAAR,QAAA,eAEbS,eAAA,CAACC,YAAI,EAAA;AAACC,QAAAA,GAAG,EAAErC,OAAQ;AAACsC,QAAAA,EAAE,EAAC,MAAM;AAACd,QAAAA,SAAS,EAAC,gBAAgB;AAAAE,QAAAA,QAAA,GACrDjB,IAAI,EACJM,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,CAAC9C,QAAQ,CAAC;;;"}
@@ -1,125 +1,121 @@
1
- import { Component, createRef } from 'react';
1
+ import { useRef, useState, useEffect } 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
- class Snackbar extends Component {
11
- bodyRef = /*#__PURE__*/createRef();
12
- timeout = 0;
13
- transitionTimeout = 0;
14
- constructor(props) {
15
- super(props);
16
- this.state = {
17
- visible: false,
18
- text: ''
19
- };
20
- }
21
- componentWillUnmount() {
22
- window.clearTimeout(this.timeout);
23
- window.clearTimeout(this.transitionTimeout);
24
- }
25
- shouldComponentUpdate(nextProps, nextState) {
26
- if (!nextProps.text) {
27
- return false;
28
- }
29
- if (nextProps.timestamp === this.props.timestamp && nextState.visible === this.state.visible && nextState.text === this.state.text) {
30
- return false;
31
- }
32
- return true;
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
+ // Both rules below are disabled on purpose: the dependency-less effect and its synchronous state
26
+ // updates are what keep this conversion behaviour-identical to the class component.
27
+ /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
28
+ useEffect(() => {
29
+ const previousProps = committedProps.current;
30
+ committedProps.current = props;
45
31
  const {
46
32
  action,
47
33
  text,
48
34
  timestamp
49
- } = this.props;
50
- if (!previousProps.text) {
51
- this.setState({
35
+ } = props;
36
+ // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
37
+ // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
38
+ // given text again. Preserved here deliberately to keep this refactor behaviour-identical.
39
+ const updateWhileTextIsPresent = update => {
40
+ if (committedProps.current.text) {
41
+ update();
42
+ }
43
+ };
44
+ const setLeaveTimeout = () => {
45
+ leaveTimeout.current = window.setTimeout(() => {
46
+ updateWhileTextIsPresent(() => setState(current => ({
47
+ ...current,
48
+ visible: false
49
+ })));
50
+ }, committedProps.current.timeout);
51
+ };
52
+ const show = () => {
53
+ setState(current => ({
54
+ ...current,
52
55
  visible: true,
53
56
  action,
54
57
  text
55
- }, () => {
56
- this.setLeaveTimeout();
57
- });
58
+ }));
59
+ setLeaveTimeout();
60
+ };
61
+ if (!text) {
62
+ return;
63
+ }
64
+ if (!previousProps.text) {
65
+ show();
58
66
  } else if (previousProps.timestamp !== timestamp) {
59
- window.clearTimeout(this.timeout);
60
- if (this.state.visible) {
61
- this.setState({
67
+ window.clearTimeout(leaveTimeout.current);
68
+ if (state.visible) {
69
+ setState(current => ({
70
+ ...current,
62
71
  visible: false
63
- }, () => {
64
- this.transitionTimeout = window.setTimeout(() => {
65
- this.setState({
66
- visible: true,
67
- action,
68
- text
69
- });
70
- this.setLeaveTimeout();
71
- }, CSS_TRANSITION_DURATION);
72
- });
72
+ }));
73
+ transitionTimeout.current = window.setTimeout(() => {
74
+ updateWhileTextIsPresent(show);
75
+ }, CSS_TRANSITION_DURATION);
73
76
  } else {
74
- this.setState({
75
- visible: true,
76
- action,
77
- text
78
- });
79
- this.setLeaveTimeout();
77
+ show();
80
78
  }
81
79
  }
82
- }
83
- render() {
84
- const {
85
- action,
86
- text,
87
- visible
88
- } = this.state;
89
- const {
90
- timeout
91
- } = this.props;
92
- return /*#__PURE__*/jsx("div", {
93
- className: "snackbar",
94
- "aria-live": "assertive",
95
- role: "alert",
96
- children: /*#__PURE__*/jsx(CSSTransition, {
97
- nodeRef: this.bodyRef,
98
- in: visible,
99
- classNames: "snackbar__text-container",
100
- timeout: {
101
- appear: 0,
102
- enter: timeout,
103
- exit: CSS_TRANSITION_DURATION
104
- },
105
- unmountOnExit: true,
106
- children: /*#__PURE__*/jsxs(Body, {
107
- ref: this.bodyRef,
108
- as: "span",
109
- className: "snackbar__text",
110
- children: [text, action ? /*#__PURE__*/jsx(Button, {
111
- className: "snackbar__text__action",
112
- v2: true,
113
- size: "sm",
114
- onClick: action.onClick,
115
- children: action.label
116
- }) : null]
117
- })
80
+ });
81
+ /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
82
+ const {
83
+ action,
84
+ text,
85
+ visible
86
+ } = state;
87
+ const {
88
+ timeout
89
+ } = props;
90
+ return /*#__PURE__*/jsx("div", {
91
+ className: "snackbar",
92
+ "aria-live": "assertive",
93
+ role: "alert",
94
+ children: /*#__PURE__*/jsx(CSSTransition, {
95
+ nodeRef: bodyRef,
96
+ in: visible,
97
+ classNames: "snackbar__text-container",
98
+ timeout: {
99
+ appear: 0,
100
+ enter: timeout,
101
+ exit: CSS_TRANSITION_DURATION
102
+ },
103
+ unmountOnExit: true,
104
+ children: /*#__PURE__*/jsxs(Body, {
105
+ ref: bodyRef,
106
+ as: "span",
107
+ className: "snackbar__text",
108
+ children: [text, action ? /*#__PURE__*/jsx(Button, {
109
+ className: "snackbar__text__action",
110
+ v2: true,
111
+ size: "sm",
112
+ onClick: action.onClick,
113
+ children: action.label
114
+ }) : null]
118
115
  })
119
- });
120
- }
121
- }
122
- Snackbar.contextType = DirectionContext;
116
+ })
117
+ });
118
+ };
123
119
  var SnackbarPortal = withNextPortalWrapper(Snackbar);
124
120
 
125
121
  export { Snackbar, SnackbarPortal as default };
@@ -1 +1 @@
1
- {"version":3,"file":"Snackbar.mjs","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { Component, createRef } from 'react';\nimport { CSSTransition } from 'react-transition-group';\n\nimport Button from '../Button';\nimport Body from '../Body';\nimport type { ThemeDark, ThemeLight } from '../common';\nimport { DirectionContext } from '../Provider/Direction';\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 */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text' | 'theme'> {\n visible: boolean;\n}\n\nexport class Snackbar extends Component<SnackbarProps, SnackbarState> {\n bodyRef = createRef<HTMLSpanElement>();\n timeout = 0;\n transitionTimeout = 0;\n\n constructor(props: SnackbarProps) {\n super(props);\n this.state = {\n visible: false,\n text: '',\n };\n }\n\n componentWillUnmount() {\n window.clearTimeout(this.timeout);\n window.clearTimeout(this.transitionTimeout);\n }\n\n shouldComponentUpdate(nextProps: SnackbarProps, nextState: SnackbarState) {\n if (!nextProps.text) {\n return false;\n }\n if (\n nextProps.timestamp === this.props.timestamp &&\n nextState.visible === this.state.visible &&\n nextState.text === this.state.text\n ) {\n return false;\n }\n\n return true;\n }\n\n setLeaveTimeout = () => {\n const { timeout } = this.props;\n\n this.timeout = window.setTimeout(() => {\n this.setState({ visible: false });\n }, timeout);\n };\n\n componentDidUpdate(previousProps: SnackbarProps) {\n const { action, text, timestamp } = this.props;\n\n if (!previousProps.text) {\n this.setState({ visible: true, action, text }, () => {\n this.setLeaveTimeout();\n });\n } else if (previousProps.timestamp !== timestamp) {\n window.clearTimeout(this.timeout);\n\n if (this.state.visible) {\n this.setState({ visible: false }, () => {\n this.transitionTimeout = window.setTimeout(() => {\n this.setState({ visible: true, action, text });\n this.setLeaveTimeout();\n }, CSS_TRANSITION_DURATION);\n });\n } else {\n this.setState({ visible: true, action, text });\n this.setLeaveTimeout();\n }\n }\n }\n\n render() {\n const { action, text, visible } = this.state;\n const { timeout } = this.props;\n\n return (\n <div className=\"snackbar\" aria-live=\"assertive\" role=\"alert\">\n <CSSTransition\n nodeRef={this.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={this.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}\n\nSnackbar.contextType = DirectionContext;\n\nexport default withNextPortal(Snackbar);\n"],"names":["CSS_TRANSITION_DURATION","Snackbar","Component","bodyRef","createRef","timeout","transitionTimeout","constructor","props","state","visible","text","componentWillUnmount","window","clearTimeout","shouldComponentUpdate","nextProps","nextState","timestamp","setLeaveTimeout","setTimeout","setState","componentDidUpdate","previousProps","action","render","_jsx","className","role","children","CSSTransition","nodeRef","in","classNames","appear","enter","exit","unmountOnExit","_jsxs","Body","ref","as","Button","v2","size","onClick","label","contextType","DirectionContext","withNextPortal"],"mappings":";;;;;;;;AASA,MAAMA,uBAAuB,GAAG,GAAG;AAkB7B,MAAOC,QAAS,SAAQC,SAAuC,CAAA;EACnEC,OAAO,gBAAGC,SAAS,EAAmB;AACtCC,EAAAA,OAAO,GAAG,CAAC;AACXC,EAAAA,iBAAiB,GAAG,CAAC;EAErBC,WAAAA,CAAYC,KAAoB,EAAA;IAC9B,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,OAAO,EAAE,KAAK;AACdC,MAAAA,IAAI,EAAE;KACP;AACH,EAAA;AAEAC,EAAAA,oBAAoBA,GAAA;AAClBC,IAAAA,MAAM,CAACC,YAAY,CAAC,IAAI,CAACT,OAAO,CAAC;AACjCQ,IAAAA,MAAM,CAACC,YAAY,CAAC,IAAI,CAACR,iBAAiB,CAAC;AAC7C,EAAA;AAEAS,EAAAA,qBAAqBA,CAACC,SAAwB,EAAEC,SAAwB,EAAA;AACtE,IAAA,IAAI,CAACD,SAAS,CAACL,IAAI,EAAE;AACnB,MAAA,OAAO,KAAK;AACd,IAAA;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M,EAAA;AAACf,YAAAA,SAAS,EAAC,wBAAwB;YAACgB,EAAE,EAAA,IAAA;AAACC,YAAAA,IAAI,EAAC,IAAI;YAACC,OAAO,EAAErB,MAAM,CAACqB,OAAQ;YAAAhB,QAAA,EAC7EL,MAAM,CAACsB;WACF,CAAC,GACP,IAAI;SACJ;OACO;AACjB,KAAK,CAAC;AAEV,EAAA;AACD;AAED7C,QAAQ,CAAC8C,WAAW,GAAGC,gBAAgB;AAEvC,qBAAeC,qBAAc,CAAChD,QAAQ,CAAC;;"}
1
+ {"version":3,"file":"Snackbar.mjs","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { useEffect, 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 */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text' | 'theme'> {\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 // Both rules below are disabled on purpose: the dependency-less effect and its synchronous state\n // updates are what keep this conversion behaviour-identical to the class component.\n /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n useEffect(() => {\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","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,CAACF,KAAK,CAAC;AAEpC,EAAA,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGC,QAAQ,CAAgB;AAChDC,IAAAA,OAAO,EAAE,KAAK;AACdC,IAAAA,IAAI,EAAE;AACP,GAAA,CAAC;EAEFC,SAAS,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;AACAH,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,MAAMI,aAAa,GAAGV,cAAc,CAACS,OAAO;IAC5CT,cAAc,CAACS,OAAO,GAAGd,KAAK;IAE9B,MAAM;MAAEgB,MAAM;MAAEN,IAAI;AAAEO,MAAAA;AAAS,KAAE,GAAGjB,KAAK;AAEzC;AACA;AACA;IACA,MAAMkB,wBAAwB,GAAIC,MAAkB,IAAI;AACtD,MAAA,IAAId,cAAc,CAACS,OAAO,CAACJ,IAAI,EAAE;AAC/BS,QAAAA,MAAM,EAAE;AACV,MAAA;IACF,CAAC;IAED,MAAMC,eAA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,KAAK;EACvC,MAAM;AAAEgB,IAAAA;AAAO,GAAE,GAAGtB,KAAK;AAEzB,EAAA,oBACEwB,GAAA,CAAA,KAAA,EAAA;AAAKC,IAAAA,SAAS,EAAC,UAAU;AAAC,IAAA,WAAA,EAAU,WAAW;AAACC,IAAAA,IAAI,EAAC,OAAO;IAAAC,QAAA,eAC1DH,GAAA,CAACI,aAAa,EAAA;AACZC,MAAAA,OAAO,EAAE5B,OAAQ;AACjB6B,MAAAA,EAAE,EAAErB,OAAQ;AACZsB,MAAAA,UAAU,EAAC,0BAA0B;AACrCT,MAAAA,OAAO,EAAE;AACPU,QAAAA,MAAM,EAAE,CAAC;AACTC,QAAAA,KAAK,EAAEX,OAAO;AACdY,QAAAA,IAAI,EAAEpC;OACN;MACFqC,aAAa,EAAA,IAAA;MAAAR,QAAA,eAEbS,IAAA,CAACC,IAAI,EAAA;AAACC,QAAAA,GAAG,EAAErC,OAAQ;AAACsC,QAAAA,EAAE,EAAC,MAAM;AAACd,QAAAA,SAAS,EAAC,gBAAgB;AAAAE,QAAAA,QAAA,GACrDjB,IAAI,EACJM,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,CAAC9C,QAAQ,CAAC;;"}
@@ -1,3 +1,28 @@
1
1
  import type { CarouselCard } from '../Carousel';
2
+ /**
3
+ * Every string the stubbed cards render, shaped as a `withRTLDiff({ i18n })` map so the RTL diff
4
+ * can spread it — that call site is what type-checks the shape against `I18nMap`. The type is not
5
+ * imported here: this file is part of the Rollup build, which cannot emit declarations that
6
+ * reference `.storybook/`. The promo card's `Wise` title is a brand name and stays in Latin script.
7
+ */
8
+ export declare const carouselCardsI18n: {
9
+ globeCardTitle: {
10
+ en: string;
11
+ ar: string;
12
+ };
13
+ promoDescription: {
14
+ en: string;
15
+ ar: string;
16
+ };
17
+ quickPayCardTitle: {
18
+ en: string;
19
+ ar: string;
20
+ };
21
+ };
22
+ /**
23
+ * Takes copy already resolved for one language — exactly what `useRtlDiffI18n()` returns — so the
24
+ * same fixture serves the single-direction stories and the RTL diff.
25
+ */
26
+ export declare const getStubbedCarouselCards: (i18n: Record<string, string>) => CarouselCard[];
2
27
  export declare const stubbedCarouselCards: CarouselCard[];
3
28
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/Carousel/_stories/constants.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,oBAAoB,EAAE,YAAY,EAyC9C,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/Carousel/_stories/constants.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAO7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,YAAY,EAyClF,CAAC;AAMF,eAAO,MAAM,oBAAoB,gBAAuC,CAAC"}
@@ -1,10 +1,47 @@
1
+ import { ReactNode } from 'react';
1
2
  import { StoryObj } from '@storybook/react-webpack5';
3
+ import { type ListItemProps } from '../../ListItem';
2
4
  import { SB_ListItem_ControlType as ControlType } from '../subcomponents';
5
+ type VariantPartial = {
6
+ title: string;
7
+ } & Partial<ListItemProps>;
3
8
  type Variant = 'default' | 'dark' | 'rtl' | 'forest-green' | 'bright-green' | 'mobile' | '400%';
4
- type VariantStoryProps = {
9
+ export type VariantText = {
10
+ title: string;
11
+ subtitle: string;
12
+ valueTitle: string;
13
+ valueSubtitle: string;
14
+ longTitle: string;
15
+ longSubtitle: string;
16
+ longValueTitle: ReactNode;
17
+ };
18
+ /**
19
+ * Every piece of copy and every slot the instance matrix is built from. Extracted so a story can
20
+ * render the same matrix with different content — the RTL diff swaps in localised versions.
21
+ */
22
+ export type VariantContent = {
23
+ text: VariantText;
24
+ media: ReactNode;
25
+ additionalInfo: {
26
+ interactive: ReactNode;
27
+ nonInteractive: ReactNode;
28
+ };
29
+ prompt: {
30
+ interactive: ReactNode;
31
+ nonInteractive: ReactNode;
32
+ };
33
+ };
34
+ export declare const DEFAULT_VARIANT_CONTENT: VariantContent;
35
+ export declare const getVariantInstances: (controlType: ControlType, { text, media, additionalInfo: info, prompt: prompts }: VariantContent) => VariantPartial[];
36
+ export type VariantStoryProps = {
5
37
  controlType: ControlType;
6
38
  variant?: Variant;
7
39
  };
40
+ type VariantListProps = VariantStoryProps & {
41
+ content?: VariantContent;
42
+ controls?: Record<ControlType, ReactNode>;
43
+ };
44
+ export declare const VariantList: ({ controlType, variant, content, controls, }: VariantListProps) => import("react").JSX.Element;
8
45
  type VariantStory = StoryObj<VariantStoryProps>;
9
46
  export declare const VariantStory: VariantStory;
10
47
  export {};