@transferwise/components 0.0.0-experimental-b7402e7 → 0.0.0-experimental-3d4c2d5
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 +105 -2
- package/build/index.esm.js.map +1 -1
- package/build/index.js +105 -1
- package/build/index.js.map +1 -1
- package/build/main.css +101 -0
- package/build/styles/main.css +101 -0
- package/build/styles/segmentedControl/SegmentedControl.css +101 -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 -4
- package/src/index.ts +2 -0
- package/src/main.css +101 -0
- package/src/main.less +1 -0
- package/src/segmentedControl/SegmentedControl.css +101 -0
- package/src/segmentedControl/SegmentedControl.less +101 -0
- package/src/segmentedControl/SegmentedControl.spec.tsx +106 -0
- package/src/segmentedControl/SegmentedControl.story.tsx +55 -0
- package/src/segmentedControl/SegmentedControl.tsx +175 -0
- package/src/segmentedControl/index.ts +2 -0
- package/src/ssr.spec.js +17 -0
- package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
- package/src/withDisplayFormat/WithDisplayFormat.tsx +1 -1
package/build/index.esm.js
CHANGED
|
@@ -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.
|
|
7513
|
+
triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
|
|
7514
7514
|
}
|
|
7515
7515
|
this.setState({
|
|
7516
7516
|
selectionStart: cursorPosition,
|
|
@@ -11042,6 +11042,109 @@ Select.defaultProps = {
|
|
|
11042
11042
|
dropdownProps: {}
|
|
11043
11043
|
};
|
|
11044
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
|
+
|
|
11045
11148
|
const CSS_TRANSITION_DURATION = 400;
|
|
11046
11149
|
class Snackbar extends Component {
|
|
11047
11150
|
bodyRef = /*#__PURE__*/createRef();
|
|
@@ -15416,5 +15519,5 @@ const translations = {
|
|
|
15416
15519
|
'zh-HK': zhHK
|
|
15417
15520
|
};
|
|
15418
15521
|
|
|
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 };
|
|
15522
|
+
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, 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 };
|
|
15420
15523
|
//# sourceMappingURL=index.esm.js.map
|