@transferwise/components 0.0.0-experimental-b2eafa7 → 0.0.0-experimental-b7402e7

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 (48) hide show
  1. package/build/index.esm.js +50 -178
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +50 -179
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +0 -101
  6. package/build/styles/main.css +0 -101
  7. package/build/types/checkboxOption/CheckboxOption.d.ts +2 -2
  8. package/build/types/checkboxOption/CheckboxOption.d.ts.map +1 -1
  9. package/build/types/index.d.ts +2 -2
  10. package/build/types/index.d.ts.map +1 -1
  11. package/build/types/snackbar/Snackbar.d.ts +30 -22
  12. package/build/types/snackbar/Snackbar.d.ts.map +1 -1
  13. package/build/types/snackbar/SnackbarContext.d.ts +7 -2
  14. package/build/types/snackbar/SnackbarContext.d.ts.map +1 -1
  15. package/build/types/snackbar/SnackbarProvider.d.ts +7 -12
  16. package/build/types/snackbar/SnackbarProvider.d.ts.map +1 -1
  17. package/build/types/snackbar/index.d.ts +2 -0
  18. package/build/types/snackbar/index.d.ts.map +1 -0
  19. package/build/types/snackbar/useSnackbar.d.ts +1 -1
  20. package/build/types/snackbar/useSnackbar.d.ts.map +1 -1
  21. package/build/types/withNextPortal/withNextPortal.d.ts +1 -1
  22. package/build/types/withNextPortal/withNextPortal.d.ts.map +1 -1
  23. package/package.json +5 -5
  24. package/src/checkboxOption/CheckboxOption.tsx +2 -2
  25. package/src/index.ts +2 -2
  26. package/src/main.css +0 -101
  27. package/src/main.less +0 -1
  28. package/src/snackbar/{Snackbar.story.js → Snackbar.story.tsx} +2 -1
  29. package/src/snackbar/{Snackbar.js → Snackbar.tsx} +31 -32
  30. package/src/snackbar/SnackbarContext.ts +11 -0
  31. package/src/snackbar/SnackbarProvider.tsx +39 -0
  32. package/src/ssr.spec.js +0 -17
  33. package/src/withNextPortal/withNextPortal.tsx +1 -1
  34. package/build/styles/segmentedControl/SegmentedControl.css +0 -101
  35. package/build/types/segmentedControl/SegmentedControl.d.ts +0 -31
  36. package/build/types/segmentedControl/SegmentedControl.d.ts.map +0 -1
  37. package/build/types/segmentedControl/index.d.ts +0 -3
  38. package/build/types/segmentedControl/index.d.ts.map +0 -1
  39. package/src/segmentedControl/SegmentedControl.css +0 -101
  40. package/src/segmentedControl/SegmentedControl.less +0 -101
  41. package/src/segmentedControl/SegmentedControl.spec.tsx +0 -106
  42. package/src/segmentedControl/SegmentedControl.story.tsx +0 -55
  43. package/src/segmentedControl/SegmentedControl.tsx +0 -175
  44. package/src/segmentedControl/index.ts +0 -2
  45. package/src/snackbar/SnackbarContext.js +0 -4
  46. package/src/snackbar/SnackbarProvider.js +0 -51
  47. /package/src/snackbar/{index.js → index.ts} +0 -0
  48. /package/src/snackbar/{useSnackbar.js → useSnackbar.ts} +0 -0
@@ -2578,7 +2578,7 @@ const CheckboxOption = /*#__PURE__*/forwardRef(({
2578
2578
  button: /*#__PURE__*/jsx(CheckboxButton$1, {
2579
2579
  checked: checked,
2580
2580
  disabled: disabled,
2581
- onChange: () => onChange(!checked)
2581
+ onChange: () => onChange?.(!checked)
2582
2582
  })
2583
2583
  });
2584
2584
  });
@@ -9879,7 +9879,6 @@ const PromoCard = /*#__PURE__*/forwardRef(({
9879
9879
  setChecked(!checked); // Update local state for checkbox
9880
9880
  }
9881
9881
  };
9882
-
9883
9882
  const componentId = `${id || generateRandomId()}`;
9884
9883
  // Set the icon to `'arrow'` if `href` is truthy and `type` is falsy, or
9885
9884
  // `'download'` if `download` is truthy. If neither condition is true, set
@@ -11043,123 +11042,21 @@ Select.defaultProps = {
11043
11042
  dropdownProps: {}
11044
11043
  };
11045
11044
 
11046
- const SegmentedControl = ({
11047
- name,
11048
- defaultValue,
11049
- mode = 'input',
11050
- segments,
11051
- onChange
11052
- }) => {
11053
- const [selectedValue, setSelectedValue] = useState(defaultValue || segments[0].value);
11054
- const [animate, setAnimate] = useState(false);
11055
- const segmentsRef = useRef(null);
11056
- if (segments.length > 3) {
11057
- throw new Error('SegmentedControl only supports up to 3 segments. Please refer to: https://wise.design/components/segmented-control');
11058
- }
11059
- const segmentsWithRefs = segments.map(segment => ({
11060
- ...segment,
11061
- ref: /*#__PURE__*/createRef()
11062
- }));
11063
- const updateSegmentPosition = () => {
11064
- const selectedSegmentRef = segmentsWithRefs.find(segment => segment.value === selectedValue)?.ref;
11065
- // We grab the active segments style object from the ref
11066
- // and set the css variables to the selected segments width and x position.
11067
- // This is so we can animate the highlight to the selected segment
11068
- if (selectedSegmentRef?.current && segmentsRef.current) {
11069
- const {
11070
- style
11071
- } = segmentsRef.current;
11072
- style.setProperty('--segment-highlight-width', `${selectedSegmentRef.current.offsetWidth}px`);
11073
- style.setProperty('--segment-highlight-x', `${selectedSegmentRef.current.offsetLeft}px`);
11074
- }
11075
- };
11076
- useEffect(() => {
11077
- updateSegmentPosition();
11078
- const handleWindowSizeChange = () => {
11079
- setAnimate(false);
11080
- updateSegmentPosition();
11081
- };
11082
- window.addEventListener('resize', handleWindowSizeChange);
11083
- return () => {
11084
- window.removeEventListener('resize', handleWindowSizeChange);
11085
- };
11086
- // eslint-disable-next-line react-hooks/exhaustive-deps
11087
- }, [segmentsWithRefs, selectedValue]);
11088
- useEffect(() => {
11089
- onChange(selectedValue);
11090
- }, [onChange, selectedValue]);
11091
- return /*#__PURE__*/jsx("div", {
11092
- ref: segmentsRef,
11093
- "data-testid": "segmented-control",
11094
- className: classNames('segmented-control', {
11095
- 'segmented-control--input': mode === 'input'
11096
- }),
11097
- children: /*#__PURE__*/jsx("div", {
11098
- className: classNames('segmented-control__segments', {
11099
- 'segmented-control__segments--no-animate': !animate
11100
- }),
11101
- children: segmentsWithRefs.map(segment => mode === 'input' ? /*#__PURE__*/jsxs("label", {
11102
- ref: segment.ref,
11103
- htmlFor: segment.id,
11104
- className: classNames('segmented-control__segment', {
11105
- 'segmented-control__selected-segment': selectedValue === segment.value
11106
- }),
11107
- children: [/*#__PURE__*/jsx("input", {
11108
- type: "radio",
11109
- className: "segmented-control__radio-input",
11110
- id: segment.id,
11111
- name: name,
11112
- value: segment.value,
11113
- checked: selectedValue === segment.value,
11114
- onChange: () => {
11115
- setAnimate(true);
11116
- setSelectedValue(segment.value);
11117
- }
11118
- }), /*#__PURE__*/jsx(Body, {
11119
- className: "segmented-control__text",
11120
- as: "span",
11121
- type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
11122
- children: segment.label
11123
- })]
11124
- }, segment.id) : /*#__PURE__*/jsx("button", {
11125
- ref: segment.ref,
11126
- type: "button",
11127
- role: "tab",
11128
- id: segment.id,
11129
- "aria-controls": segment.controls,
11130
- "aria-selected": selectedValue === segment.value,
11131
- className: classNames('segmented-control__segment', 'segmented-control__button', {
11132
- 'segmented-control__selected-segment': selectedValue === segment.value
11133
- }),
11134
- onClick: () => {
11135
- setAnimate(true);
11136
- setSelectedValue(segment.value);
11137
- },
11138
- children: /*#__PURE__*/jsx(Body, {
11139
- as: "span",
11140
- className: "segmented-control__text",
11141
- type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
11142
- children: segment.label
11143
- })
11144
- }, segment.id))
11145
- })
11146
- });
11147
- };
11148
-
11149
11045
  const CSS_TRANSITION_DURATION = 400;
11150
11046
  class Snackbar extends Component {
11151
- /** @type {RefObject<HTMLSpanElement>} */
11152
11047
  bodyRef = /*#__PURE__*/createRef();
11153
- constructor() {
11154
- super();
11048
+ timeout = 0;
11049
+ transitionTimeout = 0;
11050
+ constructor(props) {
11051
+ super(props);
11155
11052
  this.state = {
11156
11053
  visible: false,
11157
11054
  text: ''
11158
11055
  };
11159
11056
  }
11160
11057
  componentWillUnmount() {
11161
- clearTimeout(this.timeout);
11162
- clearTimeout(this.transitionTimeout);
11058
+ window.clearTimeout(this.timeout);
11059
+ window.clearTimeout(this.transitionTimeout);
11163
11060
  }
11164
11061
  shouldComponentUpdate(nextProps, nextState) {
11165
11062
  if (!nextProps.text) {
@@ -11174,7 +11071,7 @@ class Snackbar extends Component {
11174
11071
  const {
11175
11072
  timeout
11176
11073
  } = this.props;
11177
- this.timeout = setTimeout(() => {
11074
+ this.timeout = window.setTimeout(() => {
11178
11075
  this.setState({
11179
11076
  visible: false
11180
11077
  });
@@ -11197,12 +11094,12 @@ class Snackbar extends Component {
11197
11094
  this.setLeaveTimeout();
11198
11095
  });
11199
11096
  } else if (previousProps.timestamp !== timestamp) {
11200
- clearTimeout(this.timeout);
11097
+ window.clearTimeout(this.timeout);
11201
11098
  if (this.state.visible) {
11202
11099
  this.setState({
11203
11100
  visible: false
11204
11101
  }, () => {
11205
- this.transitionTimeout = setTimeout(() => {
11102
+ this.transitionTimeout = window.setTimeout(() => {
11206
11103
  this.setState({
11207
11104
  visible: true,
11208
11105
  action,
@@ -11227,7 +11124,7 @@ class Snackbar extends Component {
11227
11124
  const {
11228
11125
  action,
11229
11126
  text,
11230
- theme,
11127
+ theme = Theme.LIGHT,
11231
11128
  visible
11232
11129
  } = this.state;
11233
11130
  const {
@@ -11261,74 +11158,51 @@ class Snackbar extends Component {
11261
11158
  }
11262
11159
  }
11263
11160
  Snackbar.contextType = DirectionContext;
11264
- Snackbar.propTypes = {
11265
- action: PropTypes.shape({
11266
- label: PropTypes.string.isRequired,
11267
- onClick: PropTypes.func
11268
- }),
11269
- text: PropTypes.node.isRequired,
11270
- theme: PropTypes.oneOf(['light', 'dark']),
11271
- timeout: PropTypes.number.isRequired,
11272
- timestamp: PropTypes.number.isRequired
11273
- };
11274
- Snackbar.defaultProps = {
11275
- action: null,
11276
- theme: Theme.LIGHT
11277
- };
11278
11161
  var SnackbarPortal = withNextPortalWrapper(Snackbar);
11279
11162
 
11280
- const SnackbarContext = /*#__PURE__*/createContext();
11163
+ const SnackbarContext = /*#__PURE__*/createContext({
11164
+ createSnackbar: () => {}
11165
+ });
11281
11166
  const SnackbarConsumer = SnackbarContext.Consumer;
11282
11167
 
11283
- class SnackbarProvider extends Component {
11284
- constructor() {
11285
- super();
11286
- this.state = {
11287
- text: '',
11288
- timestamp: 0
11289
- };
11290
- }
11291
- create = ({
11168
+ function SnackbarProvider({
11169
+ timeout = 4500,
11170
+ children
11171
+ }) {
11172
+ const [state, setState] = useState({
11173
+ text: '',
11174
+ timestamp: 0
11175
+ });
11176
+ const {
11292
11177
  action,
11293
11178
  text,
11294
- theme
11295
- }) => {
11296
- this.setState({
11297
- action,
11298
- text,
11299
- theme,
11300
- timestamp: Date.now()
11301
- });
11302
- };
11303
- render() {
11304
- const {
11305
- action,
11306
- text,
11307
- theme,
11308
- timestamp
11309
- } = this.state;
11310
- return /*#__PURE__*/jsxs(SnackbarContext.Provider, {
11311
- value: {
11312
- createSnackbar: this.create
11313
- },
11314
- children: [/*#__PURE__*/jsx(SnackbarPortal, {
11315
- action: action,
11316
- text: text,
11317
- timestamp: timestamp,
11318
- timeout: this.props.timeout,
11319
- theme: theme
11320
- }), this.props.children]
11321
- });
11322
- }
11179
+ theme,
11180
+ timestamp
11181
+ } = state;
11182
+ return /*#__PURE__*/jsxs(SnackbarContext.Provider, {
11183
+ value: useMemo(() => ({
11184
+ createSnackbar: ({
11185
+ action,
11186
+ text,
11187
+ theme
11188
+ }) => {
11189
+ setState({
11190
+ action,
11191
+ text,
11192
+ theme,
11193
+ timestamp: Date.now()
11194
+ });
11195
+ }
11196
+ }), []),
11197
+ children: [/*#__PURE__*/jsx(SnackbarPortal, {
11198
+ action: action,
11199
+ text: text,
11200
+ timestamp: timestamp,
11201
+ timeout: timeout,
11202
+ theme: theme
11203
+ }), children]
11204
+ });
11323
11205
  }
11324
- SnackbarProvider.propTypes = {
11325
- children: PropTypes.node.isRequired,
11326
- timeout: PropTypes.number
11327
- };
11328
- SnackbarProvider.defaultProps = {
11329
- timeout: 4500
11330
- };
11331
- var SnackbarProvider$1 = SnackbarProvider;
11332
11206
 
11333
11207
  const Sticky = ({
11334
11208
  open,
@@ -13930,7 +13804,6 @@ const UploadButton = ({
13930
13804
  if (areAllFilesAllowed) {
13931
13805
  return null; //file input by default allows all files
13932
13806
  }
13933
-
13934
13807
  if (Array.isArray(fileTypes)) {
13935
13808
  return {
13936
13809
  accept: fileTypes.join(',')
@@ -14128,7 +14001,6 @@ const UploadItem = ({
14128
14001
  children: processIndicator
14129
14002
  }); // Scale down ProcessIndicator to be 20px*20px to match `icons`
14130
14003
  };
14131
-
14132
14004
  const getErrorMessage = () => typeof error === 'object' && error.message || error || formatMessage(MESSAGES.uploadingFailed);
14133
14005
  const getDescription = () => {
14134
14006
  if (error || status === Status.FAILED) {
@@ -15544,5 +15416,5 @@ const translations = {
15544
15416
  'zh-HK': zhHK
15545
15417
  };
15546
15418
 
15547
- export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, SegmentedControl, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15419
+ export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15548
15420
  //# sourceMappingURL=index.esm.js.map