@transferwise/components 46.7.0 → 46.8.0

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.
@@ -7510,7 +7510,7 @@ class WithDisplayFormat extends Component {
7510
7510
  const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
7511
7511
  setTimeout(() => {
7512
7512
  if (triggerEvent) {
7513
- triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7513
+ triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
7514
7514
  }
7515
7515
  this.setState({
7516
7516
  selectionStart: cursorPosition,
@@ -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,6 +11042,109 @@ Select.defaultProps = {
11043
11042
  dropdownProps: {}
11044
11043
  };
11045
11044
 
11045
+ const SegmentedControl = ({
11046
+ name,
11047
+ defaultValue,
11048
+ mode = 'input',
11049
+ segments,
11050
+ onChange
11051
+ }) => {
11052
+ const [selectedValue, setSelectedValue] = useState(defaultValue || segments[0].value);
11053
+ const [animate, setAnimate] = useState(false);
11054
+ const segmentsRef = useRef(null);
11055
+ if (segments.length > 3) {
11056
+ throw new Error('SegmentedControl only supports up to 3 segments. Please refer to: https://wise.design/components/segmented-control');
11057
+ }
11058
+ const segmentsWithRefs = segments.map(segment => ({
11059
+ ...segment,
11060
+ ref: /*#__PURE__*/createRef()
11061
+ }));
11062
+ const updateSegmentPosition = () => {
11063
+ const selectedSegmentRef = segmentsWithRefs.find(segment => segment.value === selectedValue)?.ref;
11064
+ // We grab the active segments style object from the ref
11065
+ // and set the css variables to the selected segments width and x position.
11066
+ // This is so we can animate the highlight to the selected segment
11067
+ if (selectedSegmentRef?.current && segmentsRef.current) {
11068
+ const {
11069
+ style
11070
+ } = segmentsRef.current;
11071
+ style.setProperty('--segment-highlight-width', `${selectedSegmentRef.current.offsetWidth}px`);
11072
+ style.setProperty('--segment-highlight-x', `${selectedSegmentRef.current.offsetLeft}px`);
11073
+ }
11074
+ };
11075
+ useEffect(() => {
11076
+ updateSegmentPosition();
11077
+ const handleWindowSizeChange = () => {
11078
+ setAnimate(false);
11079
+ updateSegmentPosition();
11080
+ };
11081
+ window.addEventListener('resize', handleWindowSizeChange);
11082
+ return () => {
11083
+ window.removeEventListener('resize', handleWindowSizeChange);
11084
+ };
11085
+ // eslint-disable-next-line react-hooks/exhaustive-deps
11086
+ }, [segmentsWithRefs, selectedValue]);
11087
+ useEffect(() => {
11088
+ onChange(selectedValue);
11089
+ }, [onChange, selectedValue]);
11090
+ return /*#__PURE__*/jsx("div", {
11091
+ ref: segmentsRef,
11092
+ "data-testid": "segmented-control",
11093
+ className: classNames('segmented-control', {
11094
+ 'segmented-control--input': mode === 'input'
11095
+ }),
11096
+ children: /*#__PURE__*/jsx("div", {
11097
+ className: classNames('segmented-control__segments', {
11098
+ 'segmented-control__segments--no-animate': !animate
11099
+ }),
11100
+ children: segmentsWithRefs.map(segment => mode === 'input' ? /*#__PURE__*/jsxs("label", {
11101
+ ref: segment.ref,
11102
+ htmlFor: segment.id,
11103
+ className: classNames('segmented-control__segment', {
11104
+ 'segmented-control__selected-segment': selectedValue === segment.value
11105
+ }),
11106
+ children: [/*#__PURE__*/jsx("input", {
11107
+ type: "radio",
11108
+ className: "segmented-control__radio-input",
11109
+ id: segment.id,
11110
+ name: name,
11111
+ value: segment.value,
11112
+ checked: selectedValue === segment.value,
11113
+ onChange: () => {
11114
+ setAnimate(true);
11115
+ setSelectedValue(segment.value);
11116
+ }
11117
+ }), /*#__PURE__*/jsx(Body, {
11118
+ className: "segmented-control__text",
11119
+ as: "span",
11120
+ type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
11121
+ children: segment.label
11122
+ })]
11123
+ }, segment.id) : /*#__PURE__*/jsx("button", {
11124
+ ref: segment.ref,
11125
+ type: "button",
11126
+ role: "tab",
11127
+ id: segment.id,
11128
+ "aria-controls": segment.controls,
11129
+ "aria-selected": selectedValue === segment.value,
11130
+ className: classNames('segmented-control__segment', 'segmented-control__button', {
11131
+ 'segmented-control__selected-segment': selectedValue === segment.value
11132
+ }),
11133
+ onClick: () => {
11134
+ setAnimate(true);
11135
+ setSelectedValue(segment.value);
11136
+ },
11137
+ children: /*#__PURE__*/jsx(Body, {
11138
+ as: "span",
11139
+ className: "segmented-control__text",
11140
+ type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
11141
+ children: segment.label
11142
+ })
11143
+ }, segment.id))
11144
+ })
11145
+ });
11146
+ };
11147
+
11046
11148
  const CSS_TRANSITION_DURATION = 400;
11047
11149
  class Snackbar extends Component {
11048
11150
  /** @type {RefObject<HTMLSpanElement>} */
@@ -13827,7 +13929,6 @@ const UploadButton = ({
13827
13929
  if (areAllFilesAllowed) {
13828
13930
  return null; //file input by default allows all files
13829
13931
  }
13830
-
13831
13932
  if (Array.isArray(fileTypes)) {
13832
13933
  return {
13833
13934
  accept: fileTypes.join(',')
@@ -14025,7 +14126,6 @@ const UploadItem = ({
14025
14126
  children: processIndicator
14026
14127
  }); // Scale down ProcessIndicator to be 20px*20px to match `icons`
14027
14128
  };
14028
-
14029
14129
  const getErrorMessage = () => typeof error === 'object' && error.message || error || formatMessage(MESSAGES.uploadingFailed);
14030
14130
  const getDescription = () => {
14031
14131
  if (error || status === Status.FAILED) {
@@ -15441,5 +15541,5 @@ const translations = {
15441
15541
  'zh-HK': zhHK
15442
15542
  };
15443
15543
 
15444
- 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$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 };
15544
+ 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 };
15445
15545
  //# sourceMappingURL=index.esm.js.map