@transferwise/components 0.0.0-experimental-dd495d2 → 0.0.0-experimental-3776330
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.
- package/build/index.esm.js +97 -1
- package/build/index.esm.js.map +1 -1
- package/build/index.js +97 -0
- package/build/index.js.map +1 -1
- package/build/main.css +103 -0
- package/build/styles/main.css +103 -0
- package/build/styles/segmentedControl/SegmentedControl.css +103 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/segmentedControl/SegmentedControl.d.ts +31 -0
- package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -0
- package/build/types/segmentedControl/index.d.ts +3 -0
- package/build/types/segmentedControl/index.d.ts.map +1 -0
- package/package.json +4 -11
- package/src/index.ts +2 -0
- package/src/main.css +103 -0
- package/src/main.less +1 -0
- package/src/segmentedControl/SegmentedControl.css +103 -0
- package/src/segmentedControl/SegmentedControl.less +103 -0
- package/src/segmentedControl/SegmentedControl.spec.tsx +106 -0
- package/src/segmentedControl/SegmentedControl.story.tsx +55 -0
- package/src/segmentedControl/SegmentedControl.tsx +152 -0
- package/src/segmentedControl/index.ts +2 -0
- package/src/ssr.spec.js +17 -0
package/build/index.esm.js
CHANGED
|
@@ -11043,6 +11043,102 @@ Select.defaultProps = {
|
|
|
11043
11043
|
dropdownProps: {}
|
|
11044
11044
|
};
|
|
11045
11045
|
|
|
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("div", {
|
|
11119
|
+
className: "segmented-control__label-text",
|
|
11120
|
+
children: segment.label
|
|
11121
|
+
})]
|
|
11122
|
+
}, segment.id) : /*#__PURE__*/jsx("button", {
|
|
11123
|
+
ref: segment.ref,
|
|
11124
|
+
type: "button",
|
|
11125
|
+
role: "tab",
|
|
11126
|
+
id: segment.id,
|
|
11127
|
+
"aria-controls": segment.controls,
|
|
11128
|
+
"aria-selected": selectedValue === segment.value,
|
|
11129
|
+
className: classNames('segmented-control__segment', 'segmented-control__button', {
|
|
11130
|
+
'segmented-control__selected-segment': selectedValue === segment.value
|
|
11131
|
+
}),
|
|
11132
|
+
onClick: () => {
|
|
11133
|
+
setAnimate(true);
|
|
11134
|
+
setSelectedValue(segment.value);
|
|
11135
|
+
},
|
|
11136
|
+
children: segment.label
|
|
11137
|
+
}, segment.id))
|
|
11138
|
+
})
|
|
11139
|
+
});
|
|
11140
|
+
};
|
|
11141
|
+
|
|
11046
11142
|
const CSS_TRANSITION_DURATION = 400;
|
|
11047
11143
|
class Snackbar extends Component {
|
|
11048
11144
|
/** @type {RefObject<HTMLSpanElement>} */
|
|
@@ -15441,5 +15537,5 @@ const translations = {
|
|
|
15441
15537
|
'zh-HK': zhHK
|
|
15442
15538
|
};
|
|
15443
15539
|
|
|
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 };
|
|
15540
|
+
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
15541
|
//# sourceMappingURL=index.esm.js.map
|