@transferwise/components 0.0.0-experimental-322d55c → 0.0.0-experimental-cb4aafe
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.js +46 -43
- package/build/index.js.map +1 -1
- package/build/index.mjs +46 -43
- package/build/index.mjs.map +1 -1
- package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/segmentedControl/SegmentedControl.spec.tsx +27 -1
- package/src/segmentedControl/SegmentedControl.tsx +14 -13
package/build/index.mjs
CHANGED
|
@@ -10624,7 +10624,9 @@ const SegmentedControl = ({
|
|
|
10624
10624
|
}, [segmentsWithRefs, selectedValue]);
|
|
10625
10625
|
useEffect(() => {
|
|
10626
10626
|
onChange(selectedValue);
|
|
10627
|
-
|
|
10627
|
+
// only call onChange once when the component mounts, to maintain previous behavior
|
|
10628
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10629
|
+
}, []);
|
|
10628
10630
|
return /*#__PURE__*/jsx("div", {
|
|
10629
10631
|
ref: segmentsRef,
|
|
10630
10632
|
"data-testid": "segmented-control",
|
|
@@ -10636,50 +10638,51 @@ const SegmentedControl = ({
|
|
|
10636
10638
|
'segmented-control__segments--no-animate': !animate
|
|
10637
10639
|
}),
|
|
10638
10640
|
role: mode !== 'input' ? 'tablist' : undefined,
|
|
10639
|
-
children: segmentsWithRefs.map(segment =>
|
|
10640
|
-
|
|
10641
|
-
htmlFor: segment.id,
|
|
10642
|
-
className: classNames('segmented-control__segment', {
|
|
10643
|
-
'segmented-control__selected-segment': selectedValue === segment.value
|
|
10644
|
-
}),
|
|
10645
|
-
children: [/*#__PURE__*/jsx("input", {
|
|
10646
|
-
type: "radio",
|
|
10647
|
-
className: "segmented-control__radio-input",
|
|
10648
|
-
id: segment.id,
|
|
10649
|
-
name: name,
|
|
10650
|
-
value: segment.value,
|
|
10651
|
-
checked: selectedValue === segment.value,
|
|
10652
|
-
onChange: () => {
|
|
10653
|
-
setAnimate(true);
|
|
10654
|
-
setSelectedValue(segment.value);
|
|
10655
|
-
}
|
|
10656
|
-
}), /*#__PURE__*/jsx(Body, {
|
|
10657
|
-
className: "segmented-control__text",
|
|
10658
|
-
as: "span",
|
|
10659
|
-
type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
|
|
10660
|
-
children: segment.label
|
|
10661
|
-
})]
|
|
10662
|
-
}, segment.id) : /*#__PURE__*/jsx("button", {
|
|
10663
|
-
ref: segment.ref,
|
|
10664
|
-
type: "button",
|
|
10665
|
-
role: "tab",
|
|
10666
|
-
id: segment.id,
|
|
10667
|
-
"aria-controls": segment.controls,
|
|
10668
|
-
"aria-selected": selectedValue === segment.value,
|
|
10669
|
-
className: classNames('segmented-control__segment', 'segmented-control__button', {
|
|
10670
|
-
'segmented-control__selected-segment': selectedValue === segment.value
|
|
10671
|
-
}),
|
|
10672
|
-
onClick: () => {
|
|
10641
|
+
children: segmentsWithRefs.map(segment => {
|
|
10642
|
+
const onSelect = () => {
|
|
10673
10643
|
setAnimate(true);
|
|
10674
10644
|
setSelectedValue(segment.value);
|
|
10675
|
-
|
|
10676
|
-
|
|
10677
|
-
|
|
10678
|
-
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10645
|
+
onChange(segment.value);
|
|
10646
|
+
};
|
|
10647
|
+
return mode === 'input' ? /*#__PURE__*/jsxs("label", {
|
|
10648
|
+
ref: segment.ref,
|
|
10649
|
+
htmlFor: segment.id,
|
|
10650
|
+
className: classNames('segmented-control__segment', {
|
|
10651
|
+
'segmented-control__selected-segment': selectedValue === segment.value
|
|
10652
|
+
}),
|
|
10653
|
+
children: [/*#__PURE__*/jsx("input", {
|
|
10654
|
+
type: "radio",
|
|
10655
|
+
className: "segmented-control__radio-input",
|
|
10656
|
+
id: segment.id,
|
|
10657
|
+
name: name,
|
|
10658
|
+
value: segment.value,
|
|
10659
|
+
checked: selectedValue === segment.value,
|
|
10660
|
+
onChange: onSelect
|
|
10661
|
+
}), /*#__PURE__*/jsx(Body, {
|
|
10662
|
+
className: "segmented-control__text",
|
|
10663
|
+
as: "span",
|
|
10664
|
+
type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
|
|
10665
|
+
children: segment.label
|
|
10666
|
+
})]
|
|
10667
|
+
}, segment.id) : /*#__PURE__*/jsx("button", {
|
|
10668
|
+
ref: segment.ref,
|
|
10669
|
+
type: "button",
|
|
10670
|
+
role: "tab",
|
|
10671
|
+
id: segment.id,
|
|
10672
|
+
"aria-controls": segment.controls,
|
|
10673
|
+
"aria-selected": selectedValue === segment.value,
|
|
10674
|
+
className: classNames('segmented-control__segment', 'segmented-control__button', {
|
|
10675
|
+
'segmented-control__selected-segment': selectedValue === segment.value
|
|
10676
|
+
}),
|
|
10677
|
+
onClick: onSelect,
|
|
10678
|
+
children: /*#__PURE__*/jsx(Body, {
|
|
10679
|
+
as: "span",
|
|
10680
|
+
className: "segmented-control__text",
|
|
10681
|
+
type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
|
|
10682
|
+
children: segment.label
|
|
10683
|
+
})
|
|
10684
|
+
}, segment.id);
|
|
10685
|
+
})
|
|
10683
10686
|
})
|
|
10684
10687
|
});
|
|
10685
10688
|
};
|