@transferwise/components 0.0.0-experimental-cc11279 → 0.0.0-experimental-b300585
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 +69 -66
- package/build/index.js.map +1 -1
- package/build/index.mjs +69 -66
- package/build/index.mjs.map +1 -1
- package/build/types/inputs/_BottomSheet.d.ts.map +1 -1
- package/build/types/inputs/_Popover.d.ts.map +1 -1
- package/build/types/segmentedControl/SegmentedControl.d.ts +2 -2
- package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/inputs/_BottomSheet.tsx +33 -28
- package/src/inputs/_Popover.tsx +23 -20
- package/src/segmentedControl/SegmentedControl.spec.tsx +39 -1
- package/src/segmentedControl/SegmentedControl.story.tsx +54 -16
- package/src/segmentedControl/SegmentedControl.tsx +11 -18
package/build/index.mjs
CHANGED
|
@@ -13,11 +13,11 @@ import { Transition, Listbox } from '@headlessui/react';
|
|
|
13
13
|
import mergeProps from 'merge-props';
|
|
14
14
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
15
15
|
import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, offset, flip, shift, size, autoUpdate } from '@floating-ui/react';
|
|
16
|
+
import { FocusScope } from '@react-aria/focus';
|
|
16
17
|
import { usePreventScroll } from '@react-aria/overlays';
|
|
17
18
|
import { CSSTransition } from 'react-transition-group';
|
|
18
19
|
import { isUndefined, isNumber, isEmpty, isNull } from '@transferwise/neptune-validation';
|
|
19
20
|
import { createPortal } from 'react-dom';
|
|
20
|
-
import { FocusScope } from '@react-aria/focus';
|
|
21
21
|
import { usePopper } from 'react-popper';
|
|
22
22
|
import throttle from 'lodash.throttle';
|
|
23
23
|
import { Flag, Illustration } from '@wise/art';
|
|
@@ -5490,35 +5490,37 @@ function BottomSheet({
|
|
|
5490
5490
|
enterFrom: "np-bottom-sheet-v2-content--enter-from",
|
|
5491
5491
|
leave: "np-bottom-sheet-v2-content--leave",
|
|
5492
5492
|
leaveTo: "np-bottom-sheet-v2-content--leave-to",
|
|
5493
|
-
children: /*#__PURE__*/jsx(
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
'np-bottom-sheet-v2-content-inner
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5493
|
+
children: /*#__PURE__*/jsx(FocusScope, {
|
|
5494
|
+
children: /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
5495
|
+
context: context,
|
|
5496
|
+
initialFocus: initialFocusRef,
|
|
5497
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
5498
|
+
// Force inner state invalidation on open
|
|
5499
|
+
ref: refs.setFloating,
|
|
5500
|
+
className: "np-bottom-sheet-v2-content-inner-container",
|
|
5501
|
+
...getFloatingProps(),
|
|
5502
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
5503
|
+
className: "np-bottom-sheet-v2-header",
|
|
5504
|
+
children: /*#__PURE__*/jsx(CloseButton, {
|
|
5505
|
+
size: Size.SMALL,
|
|
5506
|
+
onClick: () => {
|
|
5507
|
+
onClose?.();
|
|
5508
|
+
}
|
|
5509
|
+
})
|
|
5510
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
5511
|
+
className: classNames('np-bottom-sheet-v2-content-inner', title && 'np-bottom-sheet-v2-content-inner--has-title', {
|
|
5512
|
+
'np-bottom-sheet-v2-content-inner--padding-md': padding === 'md'
|
|
5513
|
+
}),
|
|
5514
|
+
children: [title ? /*#__PURE__*/jsx("h2", {
|
|
5515
|
+
className: "np-bottom-sheet-v2-title np-text-title-body",
|
|
5516
|
+
children: title
|
|
5517
|
+
}) : null, /*#__PURE__*/jsx("div", {
|
|
5518
|
+
className: "np-bottom-sheet-v2-body np-text-body-default",
|
|
5519
|
+
children: children
|
|
5520
|
+
})]
|
|
5519
5521
|
})]
|
|
5520
|
-
})
|
|
5521
|
-
}
|
|
5522
|
+
}, floatingKey)
|
|
5523
|
+
})
|
|
5522
5524
|
})
|
|
5523
5525
|
})
|
|
5524
5526
|
})]
|
|
@@ -5619,32 +5621,34 @@ function Popover({
|
|
|
5619
5621
|
setFloatingKey(prev => prev + 1);
|
|
5620
5622
|
},
|
|
5621
5623
|
afterLeave: onCloseEnd,
|
|
5622
|
-
children: /*#__PURE__*/jsx(
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
'np-popover-v2-container
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
'np-popover-v2
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5624
|
+
children: /*#__PURE__*/jsx(FocusScope, {
|
|
5625
|
+
children: /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
5626
|
+
context: context,
|
|
5627
|
+
children: /*#__PURE__*/jsx("div", {
|
|
5628
|
+
// Force inner state invalidation on open
|
|
5629
|
+
ref: refs.setFloating,
|
|
5630
|
+
className: classNames('np-popover-v2-container', {
|
|
5631
|
+
'np-popover-v2-container--size-md': size$1 === 'md',
|
|
5632
|
+
'np-popover-v2-container--size-lg': size$1 === 'lg'
|
|
5633
|
+
})
|
|
5634
|
+
// eslint-disable-next-line react/forbid-dom-props
|
|
5635
|
+
,
|
|
5636
|
+
style: floatingStyles,
|
|
5637
|
+
...getFloatingProps(),
|
|
5638
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
5639
|
+
className: classNames('np-popover-v2', title && 'np-popover-v2--has-title', {
|
|
5640
|
+
'np-popover-v2--padding-md': padding === 'md'
|
|
5641
|
+
}),
|
|
5642
|
+
children: [title ? /*#__PURE__*/jsx("h2", {
|
|
5643
|
+
className: "np-popover-v2-title np-text-title-body",
|
|
5644
|
+
children: title
|
|
5645
|
+
}) : null, /*#__PURE__*/jsx("div", {
|
|
5646
|
+
className: "np-popover-v2-content np-text-body-default",
|
|
5647
|
+
children: children
|
|
5648
|
+
})]
|
|
5649
|
+
})
|
|
5650
|
+
}, floatingKey)
|
|
5651
|
+
})
|
|
5648
5652
|
})
|
|
5649
5653
|
})
|
|
5650
5654
|
})
|
|
@@ -9942,12 +9946,11 @@ Select.defaultProps = {
|
|
|
9942
9946
|
|
|
9943
9947
|
const SegmentedControl = ({
|
|
9944
9948
|
name,
|
|
9945
|
-
|
|
9949
|
+
value,
|
|
9946
9950
|
mode = 'input',
|
|
9947
9951
|
segments,
|
|
9948
9952
|
onChange
|
|
9949
9953
|
}) => {
|
|
9950
|
-
const [selectedValue, setSelectedValue] = useState(defaultValue || segments[0].value);
|
|
9951
9954
|
const [animate, setAnimate] = useState(false);
|
|
9952
9955
|
const segmentsRef = useRef(null);
|
|
9953
9956
|
if (segments.length > 3) {
|
|
@@ -9958,7 +9961,7 @@ const SegmentedControl = ({
|
|
|
9958
9961
|
ref: /*#__PURE__*/createRef()
|
|
9959
9962
|
}));
|
|
9960
9963
|
const updateSegmentPosition = () => {
|
|
9961
|
-
const selectedSegmentRef = segmentsWithRefs.find(segment => segment.value ===
|
|
9964
|
+
const selectedSegmentRef = segmentsWithRefs.find(segment => segment.value === value)?.ref;
|
|
9962
9965
|
// We grab the active segments style object from the ref
|
|
9963
9966
|
// and set the css variables to the selected segments width and x position.
|
|
9964
9967
|
// This is so we can animate the highlight to the selected segment
|
|
@@ -9971,6 +9974,7 @@ const SegmentedControl = ({
|
|
|
9971
9974
|
}
|
|
9972
9975
|
};
|
|
9973
9976
|
useEffect(() => {
|
|
9977
|
+
setAnimate(true);
|
|
9974
9978
|
updateSegmentPosition();
|
|
9975
9979
|
const handleWindowSizeChange = () => {
|
|
9976
9980
|
setAnimate(false);
|
|
@@ -9981,7 +9985,7 @@ const SegmentedControl = ({
|
|
|
9981
9985
|
window.removeEventListener('resize', handleWindowSizeChange);
|
|
9982
9986
|
};
|
|
9983
9987
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9984
|
-
}, [segmentsWithRefs,
|
|
9988
|
+
}, [segmentsWithRefs, value]);
|
|
9985
9989
|
return /*#__PURE__*/jsx("div", {
|
|
9986
9990
|
ref: segmentsRef,
|
|
9987
9991
|
"data-testid": "segmented-control",
|
|
@@ -9996,14 +10000,13 @@ const SegmentedControl = ({
|
|
|
9996
10000
|
children: segmentsWithRefs.map(segment => {
|
|
9997
10001
|
const onSelect = () => {
|
|
9998
10002
|
setAnimate(true);
|
|
9999
|
-
setSelectedValue(segment.value);
|
|
10000
10003
|
onChange(segment.value);
|
|
10001
10004
|
};
|
|
10002
10005
|
return mode === 'input' ? /*#__PURE__*/jsxs("label", {
|
|
10003
10006
|
ref: segment.ref,
|
|
10004
10007
|
htmlFor: segment.id,
|
|
10005
10008
|
className: classNames('segmented-control__segment', {
|
|
10006
|
-
'segmented-control__selected-segment':
|
|
10009
|
+
'segmented-control__selected-segment': value === segment.value
|
|
10007
10010
|
}),
|
|
10008
10011
|
children: [/*#__PURE__*/jsx("input", {
|
|
10009
10012
|
type: "radio",
|
|
@@ -10011,12 +10014,12 @@ const SegmentedControl = ({
|
|
|
10011
10014
|
id: segment.id,
|
|
10012
10015
|
name: name,
|
|
10013
10016
|
value: segment.value,
|
|
10014
|
-
checked:
|
|
10017
|
+
checked: value === segment.value,
|
|
10015
10018
|
onChange: onSelect
|
|
10016
10019
|
}), /*#__PURE__*/jsx(Body, {
|
|
10017
10020
|
className: "segmented-control__text",
|
|
10018
10021
|
as: "span",
|
|
10019
|
-
type:
|
|
10022
|
+
type: value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
|
|
10020
10023
|
children: segment.label
|
|
10021
10024
|
})]
|
|
10022
10025
|
}, segment.id) : /*#__PURE__*/jsx("button", {
|
|
@@ -10025,15 +10028,15 @@ const SegmentedControl = ({
|
|
|
10025
10028
|
role: "tab",
|
|
10026
10029
|
id: segment.id,
|
|
10027
10030
|
"aria-controls": segment.controls,
|
|
10028
|
-
"aria-selected":
|
|
10031
|
+
"aria-selected": value === segment.value,
|
|
10029
10032
|
className: classNames('segmented-control__segment', 'segmented-control__button', {
|
|
10030
|
-
'segmented-control__selected-segment':
|
|
10033
|
+
'segmented-control__selected-segment': value === segment.value
|
|
10031
10034
|
}),
|
|
10032
10035
|
onClick: onSelect,
|
|
10033
10036
|
children: /*#__PURE__*/jsx(Body, {
|
|
10034
10037
|
as: "span",
|
|
10035
10038
|
className: "segmented-control__text",
|
|
10036
|
-
type:
|
|
10039
|
+
type: value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
|
|
10037
10040
|
children: segment.label
|
|
10038
10041
|
})
|
|
10039
10042
|
}, segment.id);
|