@transferwise/components 0.0.0-experimental-13a4d91 → 0.0.0-experimental-0dd9635

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.
@@ -11199,6 +11199,102 @@ Select.defaultProps = {
11199
11199
  dropdownProps: {}
11200
11200
  };
11201
11201
 
11202
+ const SegmentedControl = ({
11203
+ name,
11204
+ defaultValue,
11205
+ mode = 'input',
11206
+ segments,
11207
+ onChange
11208
+ }) => {
11209
+ const [selectedValue, setSelectedValue] = useState(defaultValue || segments[0].value);
11210
+ const [animate, setAnimate] = useState(false);
11211
+ const segmentsRef = useRef(null);
11212
+ if (segments.length > 3) {
11213
+ throw new Error('SegmentedControl only supports up to 3 segments');
11214
+ }
11215
+ const segmentsWithRefs = segments.map(segment => ({
11216
+ ...segment,
11217
+ ref: /*#__PURE__*/createRef()
11218
+ }));
11219
+ const updateSegmentPosition = () => {
11220
+ const selectedSegmentRef = segmentsWithRefs.find(segment => segment.value === selectedValue)?.ref;
11221
+ // We grab the active segments style object from the ref
11222
+ // and set the css variables to the selected segments width and x position.
11223
+ // This is so we can animate the highlight to the selected segment
11224
+ if (selectedSegmentRef?.current && segmentsRef.current) {
11225
+ const {
11226
+ style
11227
+ } = segmentsRef.current;
11228
+ style.setProperty('--segment-highlight-width', `${selectedSegmentRef.current.offsetWidth}px`);
11229
+ style.setProperty('--segment-highlight-x', `${selectedSegmentRef.current.offsetLeft}px`);
11230
+ }
11231
+ };
11232
+ useEffect(() => {
11233
+ updateSegmentPosition();
11234
+ const handleWindowSizeChange = () => {
11235
+ setAnimate(false);
11236
+ updateSegmentPosition();
11237
+ };
11238
+ window.addEventListener('resize', handleWindowSizeChange);
11239
+ return () => {
11240
+ window.removeEventListener('resize', handleWindowSizeChange);
11241
+ };
11242
+ // eslint-disable-next-line react-hooks/exhaustive-deps
11243
+ }, [segmentsWithRefs, selectedValue]);
11244
+ useEffect(() => {
11245
+ onChange(selectedValue);
11246
+ }, [onChange, selectedValue]);
11247
+ return /*#__PURE__*/jsx("div", {
11248
+ ref: segmentsRef,
11249
+ "data-testid": "segmented-control",
11250
+ className: classNames('segmented-control', {
11251
+ 'segmented-control--input': mode === 'input'
11252
+ }),
11253
+ children: /*#__PURE__*/jsx("div", {
11254
+ className: classNames('segmented-control__segments', {
11255
+ 'segmented-control__segments--no-animate': !animate
11256
+ }),
11257
+ children: segmentsWithRefs.map(segment => mode === 'input' ? /*#__PURE__*/jsxs("label", {
11258
+ ref: segment.ref,
11259
+ htmlFor: segment.id,
11260
+ className: classNames('segmented-control__segment', {
11261
+ 'segmented-control__selected-segment': selectedValue === segment.value
11262
+ }),
11263
+ children: [/*#__PURE__*/jsx("input", {
11264
+ type: "radio",
11265
+ className: "segmented-control__radio-input",
11266
+ id: segment.id,
11267
+ name: name,
11268
+ value: segment.value,
11269
+ checked: selectedValue === segment.value,
11270
+ onChange: () => {
11271
+ setAnimate(true);
11272
+ setSelectedValue(segment.value);
11273
+ }
11274
+ }), /*#__PURE__*/jsx("div", {
11275
+ className: "segmented-control__label-text",
11276
+ children: segment.label
11277
+ })]
11278
+ }, segment.id) : /*#__PURE__*/jsx("button", {
11279
+ ref: segment.ref,
11280
+ type: "button",
11281
+ role: "tab",
11282
+ id: segment.id,
11283
+ "aria-controls": segment.controls,
11284
+ "aria-selected": selectedValue === segment.value,
11285
+ className: classNames('segmented-control__segment', 'segmented-control__button', {
11286
+ 'segmented-control__selected-segment': selectedValue === segment.value
11287
+ }),
11288
+ onClick: () => {
11289
+ setAnimate(true);
11290
+ setSelectedValue(segment.value);
11291
+ },
11292
+ children: segment.label
11293
+ }, segment.id))
11294
+ })
11295
+ });
11296
+ };
11297
+
11202
11298
  const CSS_TRANSITION_DURATION = 400;
11203
11299
  class Snackbar extends Component {
11204
11300
  /** @type {RefObject<HTMLSpanElement>} */
@@ -15597,5 +15693,5 @@ const translations = {
15597
15693
  'zh-HK': zhHK
15598
15694
  };
15599
15695
 
15600
- 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$1 as 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 };
15696
+ 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$1 as 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 };
15601
15697
  //# sourceMappingURL=index.esm.js.map