@transferwise/components 46.165.0 → 46.165.1

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 (86) hide show
  1. package/build/Snackbar/Snackbar.js +98 -101
  2. package/build/Snackbar/Snackbar.js.map +1 -1
  3. package/build/Snackbar/Snackbar.mjs +99 -102
  4. package/build/Snackbar/Snackbar.mjs.map +1 -1
  5. package/build/types/Body/Body.d.ts +2 -2
  6. package/build/types/Carousel/_stories/constants.d.ts +25 -0
  7. package/build/types/Carousel/_stories/constants.d.ts.map +1 -1
  8. package/build/types/IconButton/IconButton.d.ts +1 -1
  9. package/build/types/ListItem/_stories/variants/helpers.d.ts +38 -1
  10. package/build/types/ListItem/_stories/variants/helpers.d.ts.map +1 -1
  11. package/build/types/MoneyInput/MoneyInput.d.ts +1 -1
  12. package/build/types/MoneyInput/MoneyInput.d.ts.map +1 -1
  13. package/build/types/Snackbar/Snackbar.d.ts +1 -15
  14. package/build/types/Snackbar/Snackbar.d.ts.map +1 -1
  15. package/build/types/Title/Title.d.ts +2 -2
  16. package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
  17. package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
  18. package/package.json +1 -1
  19. package/src/Accordion/_stories/Accordion.test.story.tsx +74 -48
  20. package/src/AvatarLayout/_stories/AvatarLayout.test.story.tsx +46 -30
  21. package/src/Button/LegacyButton/_stories/LegacyButton.test.story.tsx +29 -19
  22. package/src/Button/_stories/Button.test.story.tsx +96 -62
  23. package/src/Calendar/_stories/Calendar.test.story.tsx +34 -21
  24. package/src/Carousel/_stories/Carousel.test.story.tsx +18 -8
  25. package/src/Carousel/_stories/constants.tsx +29 -4
  26. package/src/Checkbox/_stories/Checkbox.test.story.tsx +22 -13
  27. package/src/CheckboxButton/_stories/CheckboxButton.test.story.tsx +23 -14
  28. package/src/Chips/_stories/Chips.test.story.tsx +51 -36
  29. package/src/DateInput/_stories/DateInput.rtl.test.story.tsx +62 -12
  30. package/src/DateLookup/_stories/DateLookup.rtl.test.story.tsx +2 -2
  31. package/src/Decision/_stories/Decision.test.story.tsx +74 -58
  32. package/src/DefinitionList/_stories/DefinitionList.test.story.tsx +58 -42
  33. package/src/Drawer/_stories/Drawer.rtl.test.story.tsx +65 -38
  34. package/src/ExpressiveMoneyInput/_stories/ExpressiveMoneyInput.rtl.test.story.tsx +107 -74
  35. package/src/Field/_stories/Field.test.story.tsx +18 -18
  36. package/src/FlowNavigation/_stories/FlowNavigation.rtl.test.story.tsx +81 -51
  37. package/src/Header/_stories/Header.test.story.tsx +30 -18
  38. package/src/Info/_stories/Info.rtl.test.story.tsx +124 -50
  39. package/src/InputWithDisplayFormat/_stories/InputWithDisplayFormat.test.story.tsx +4 -4
  40. package/src/Inputs/InputGroup/_stories/InputGroup.test.story.tsx +9 -8
  41. package/src/Inputs/SearchInput/_stories/SearchInput.test.story.tsx +5 -3
  42. package/src/Inputs/SelectInput/_stories/SelectInput.rtl.test.story.tsx +108 -79
  43. package/src/Inputs/TextArea/_stories/TextArea.test.story.tsx +10 -10
  44. package/src/InstructionsList/_stories/InstructionsList.test.story.tsx +43 -16
  45. package/src/Label/_stories/Label.test.story.tsx +7 -7
  46. package/src/Link/_stories/Link.test.story.tsx +27 -13
  47. package/src/ListItem/_stories/ListItem.rtl.test.story.tsx +126 -6
  48. package/src/ListItem/_stories/variants/helpers.tsx +174 -126
  49. package/src/Loader/_stories/Loader.test.story.tsx +17 -10
  50. package/src/Modal/_stories/Modal.rtl.test.story.tsx +58 -39
  51. package/src/MoneyInput/_stories/MoneyInput.rtl.test.story.tsx +21 -3
  52. package/src/Nudge/_stories/Nudge.test.story.tsx +70 -21
  53. package/src/PhoneNumberInput/_stories/PhoneNumberInput.rtl.test.story.tsx +1 -1
  54. package/src/Popover/_stories/Popover.rtl.test.story.tsx +92 -49
  55. package/src/ProgressBar/_stories/ProgressBar.test.story.tsx +6 -6
  56. package/src/PromoCard/_stories/PromoCard.test.story.tsx +53 -29
  57. package/src/PromoCard/_stories/PromoCardGroup.test.story.tsx +60 -36
  58. package/src/Prompt/ActionPrompt/_stories/ActionPrompt.test.story.tsx +74 -38
  59. package/src/Prompt/CriticalBanner/_stories/CriticalBanner.test.story.tsx +68 -31
  60. package/src/Prompt/InfoPrompt/_stories/InfoPrompt.test.story.tsx +52 -22
  61. package/src/Prompt/InlinePrompt/_stories/InlinePrompt.test.story.tsx +36 -21
  62. package/src/Radio/_stories/Radio.test.story.tsx +60 -46
  63. package/src/RadioGroup/_stories/RadioGroup.test.story.tsx +70 -51
  64. package/src/Section/_stories/Section.test.story.tsx +30 -14
  65. package/src/SegmentedControl/_stories/SegmentedControl.test.story.tsx +38 -15
  66. package/src/SlidingPanel/_stories/SlidingPanel.rtl.test.story.tsx +58 -34
  67. package/src/Snackbar/Snackbar.test.tsx +16 -0
  68. package/src/Snackbar/Snackbar.tsx +91 -88
  69. package/src/Snackbar/_stories/Snackbar.rtl.test.story.tsx +24 -12
  70. package/src/Stepper/_stories/Stepper.test.story.tsx +27 -9
  71. package/src/Switch/_stories/Switch.test.story.tsx +20 -12
  72. package/src/Table/_stories/Table.test.story.tsx +107 -86
  73. package/src/Tabs/_stories/Tabs.test.story.tsx +92 -52
  74. package/src/Tag/_stories/Tag.test.story.tsx +27 -16
  75. package/src/TextareaWithDisplayFormat/_stories/TextareaWithDisplayFormat.test.story.tsx +4 -4
  76. package/src/Tooltip/_stories/Tooltip.rtl.test.story.tsx +68 -25
  77. package/src/Typeahead/_stories/Typeahead.rtl.test.story.tsx +4 -4
  78. package/src/Upload/_stories/Upload.rtl.test.story.tsx +49 -26
  79. package/src/UploadInput/_stories/UploadInput.test.story.tsx +63 -41
  80. package/src/_deprecated/Alert/_stories/Alert.test.story.tsx +45 -24
  81. package/src/_deprecated/Card/_stories/Card.test.story.tsx +47 -23
  82. package/src/_deprecated/CriticalBanner/_stories/CriticalCommsBanner.test.story.tsx +21 -15
  83. package/src/_deprecated/InlineAlert/_stories/InlineAlert.test.story.tsx +23 -12
  84. package/src/_deprecated/Select/_stories/Select.rtl.test.story.tsx +78 -42
  85. package/src/common/BottomSheet/_stories/BottomSheet.test.story.tsx +38 -20
  86. package/src/common/Panel/_stories/Panel.rtl.test.story.tsx +135 -51
@@ -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
- 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
+ // 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
- } = this.props;
54
- if (!previousProps.text) {
55
- this.setState({
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
- this.setLeaveTimeout();
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(this.timeout);
64
- if (this.state.visible) {
65
- this.setState({
72
+ window.clearTimeout(leaveTimeout.current);
73
+ if (state.visible) {
74
+ setState(current => ({
75
+ ...current,
66
76
  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
- });
77
+ }));
78
+ transitionTimeout.current = window.setTimeout(() => {
79
+ updateWhileTextIsPresent(show);
80
+ }, CSS_TRANSITION_DURATION);
77
81
  } else {
78
- this.setState({
79
- visible: true,
80
- action,
81
- text
82
- });
83
- this.setLeaveTimeout();
82
+ show();
84
83
  }
85
84
  }
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
- })
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 { 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":";;;;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B,IAAA,oBACEkB,cAAA,CAAA,KAAA,EAAA;AAAKC,MAAAA,SAAS,EAAC,UAAU;AAAC,MAAA,WAAA,EAAU,WAAW;AAACC,MAAAA,IAAI,EAAC,OAAO;MAAAC,QAAA,eAC1DH,cAAA,CAACI,kCAAa,EAAA;QACZC,OAAO,EAAE,IAAI,CAAC5B,OAAQ;AACtB6B,QAAAA,EAAE,EAAEtB,OAAQ;AACZuB,QAAAA,UAAU,EAAC,0BAA0B;AACrC5B,QAAAA,OAAO,EAAE;AACP6B,UAAAA,MAAM,EAAE,CAAC;AACTC,UAAAA,KAAK,EAAE9B,OAAO;AACd+B,UAAAA,IAAI,EAAEpC;SACN;QACFqC,aAAa,EAAA,IAAA;QAAAR,QAAA,eAEbS,eAAA,CAACC,YAAI,EAAA;UAACC,GAAG,EAAE,IAAI,CAACrC,OAAQ;AAACsC,UAAAA,EAAE,EAAC,MAAM;AAACd,UAAAA,SAAS,EAAC,gBAAgB;AAAAE,UAAAA,QAAA,GAC1DlB,IAAI,EACJa,MAAM,gBACLE,cAAA,CAACgB,uBAAM,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,kCAAgB;AAEvC,qBAAeC,sBAAc,CAAChD,QAAQ,CAAC;;;"}
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 */\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 // 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,C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FsC,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 { Component, createRef } from 'react';
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
- 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
+ // 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
- } = this.props;
50
- if (!previousProps.text) {
51
- this.setState({
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
- this.setLeaveTimeout();
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(this.timeout);
60
- if (this.state.visible) {
61
- this.setState({
68
+ window.clearTimeout(leaveTimeout.current);
69
+ if (state.visible) {
70
+ setState(current => ({
71
+ ...current,
62
72
  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
- });
73
+ }));
74
+ transitionTimeout.current = window.setTimeout(() => {
75
+ updateWhileTextIsPresent(show);
76
+ }, CSS_TRANSITION_DURATION);
73
77
  } else {
74
- this.setState({
75
- visible: true,
76
- action,
77
- text
78
- });
79
- this.setLeaveTimeout();
78
+ show();
80
79
  }
81
80
  }
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
- })
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 { 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;AACA,IAAA,IACEK,SAAS,CAACE,SAAS,KAAK,IAAI,CAACV,KAAK,CAACU,SAAS,IAC5CD,SAAS,CAACP,OAAO,KAAK,IAAI,CAACD,KAAK,CAACC,OAAO,IACxCO,SAAS,CAACN,IAAI,KAAK,IAAI,CAACF,KAAK,CAACE,IAAI,EAClC;AACA,MAAA,OAAO,KAAK;AACd,IAAA;AAEA,IAAA,OAAO,IAAI;AACb,EAAA;EAEAQ,eAAe,GAAGA,MAAK;IACrB,MAA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c,CAAChD,QAAQ,CAAC;;"}
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 */\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 // 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,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,CAACI,aAAa,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,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;;"}
@@ -11,7 +11,7 @@ export type BodyProps = HTMLAttributes<HTMLSpanElement | HTMLParagraphElement> &
11
11
  */
12
12
  preserveNewlines?: boolean;
13
13
  };
14
- declare const Body: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLSpanElement | HTMLParagraphElement> & {
14
+ declare const Body: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLParagraphElement | HTMLSpanElement> & {
15
15
  /** @default 'body-default' */
16
16
  type?: BodyTypes;
17
17
  /** @default 'div' */
@@ -21,6 +21,6 @@ declare const Body: import("react").ForwardRefExoticComponent<HTMLAttributes<HTM
21
21
  * @default false
22
22
  */
23
23
  preserveNewlines?: boolean;
24
- } & import("react").RefAttributes<HTMLDivElement | HTMLSpanElement | HTMLParagraphElement | null>>;
24
+ } & import("react").RefAttributes<HTMLDivElement | HTMLParagraphElement | HTMLSpanElement | null>>;
25
25
  export default Body;
26
26
  //# sourceMappingURL=Body.d.ts.map
@@ -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"}
@@ -16,6 +16,6 @@ declare const IconButton: import("react").ForwardRefExoticComponent<{
16
16
  /** @default 'default' */
17
17
  type?: "default" | "negative";
18
18
  'data-testid'?: string;
19
- } & Pick<AnchorHTMLAttributes<HTMLAnchorElement>, "onClick" | "target" | "href"> & Pick<ButtonHTMLAttributes<HTMLButtonElement>, "disabled" | "onClick"> & Pick<HTMLAttributes<HTMLDivElement>, "children" | "className" | "id" | "tabIndex" | "role" | "aria-label"> & import("react").RefAttributes<unknown>>;
19
+ } & Pick<AnchorHTMLAttributes<HTMLAnchorElement>, "onClick" | "target" | "href"> & Pick<ButtonHTMLAttributes<HTMLButtonElement>, "disabled" | "onClick"> & Pick<HTMLAttributes<HTMLDivElement>, "id" | "className" | "tabIndex" | "role" | "aria-label" | "children"> & import("react").RefAttributes<unknown>>;
20
20
  export default IconButton;
21
21
  //# sourceMappingURL=IconButton.d.ts.map