@astryxdesign/core 0.7.7-canary.550ff21 → 0.7.7-canary.559b005
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/dist/Avatar/Avatar.d.ts.map +1 -1
- package/dist/Avatar/Avatar.js +1 -1
- package/dist/Breadcrumbs/BreadcrumbItem.d.ts.map +1 -1
- package/dist/Breadcrumbs/BreadcrumbItem.js +2 -1
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +3 -2
- package/dist/DateInput/Wheel.d.ts +17 -1
- package/dist/DateInput/Wheel.d.ts.map +1 -1
- package/dist/DateInput/Wheel.js +179 -19
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +63 -49
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +49 -12
- package/dist/Drawer/Drawer.d.ts.map +1 -1
- package/dist/Drawer/Drawer.js +15 -10
- package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
- package/dist/Drawer/useDrawerDialogPresence.js +4 -0
- package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenu.js +20 -4
- package/dist/InfoTip/InfoTip.d.ts +63 -0
- package/dist/InfoTip/InfoTip.d.ts.map +1 -0
- package/dist/InfoTip/InfoTip.js +126 -0
- package/dist/InfoTip/index.d.ts +10 -0
- package/dist/InfoTip/index.d.ts.map +1 -0
- package/dist/InfoTip/index.js +12 -0
- package/dist/Layer/layerClickBoundary.d.ts +7 -1
- package/dist/Layer/layerClickBoundary.d.ts.map +1 -1
- package/dist/Layer/layerClickBoundary.js +2 -2
- package/dist/Layer/useBackdropPress.d.ts +27 -0
- package/dist/Layer/useBackdropPress.d.ts.map +1 -0
- package/dist/Layer/useBackdropPress.js +53 -0
- package/dist/Layer/usePressPin.d.ts +95 -0
- package/dist/Layer/usePressPin.d.ts.map +1 -0
- package/dist/Layer/usePressPin.js +365 -0
- package/dist/Layer/useTouchTrigger.d.ts +23 -1
- package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
- package/dist/Layer/useTouchTrigger.js +45 -7
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +2 -1
- package/dist/Popover/usePopover.d.ts.map +1 -1
- package/dist/Popover/usePopover.js +56 -7
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearch.js +38 -30
- package/dist/ProgressBar/ProgressBar.d.ts +1 -1
- package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
- package/dist/ProgressBar/ProgressBar.js +33 -6
- package/dist/SegmentedControl/SegmentedControl.d.ts +3 -1
- package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControl.js +115 -8
- package/dist/SegmentedControl/SegmentedControlContext.d.ts +6 -0
- package/dist/SegmentedControl/SegmentedControlContext.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControlItem.d.ts +1 -0
- package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControlItem.js +10 -2
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts +357 -0
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -0
- package/dist/SegmentedControl/useSegmentedSelectionMotion.js +1349 -0
- package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts +70 -0
- package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -0
- package/dist/SegmentedControl/useSegmentedTouchTracking.js +264 -0
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +96 -67
- package/dist/Selector/optionShape.d.ts +24 -0
- package/dist/Selector/optionShape.d.ts.map +1 -0
- package/dist/Selector/optionShape.js +48 -0
- package/dist/Selector/selectableOptionEntries.d.ts +20 -0
- package/dist/Selector/selectableOptionEntries.d.ts.map +1 -0
- package/dist/Selector/selectableOptionEntries.js +38 -0
- package/dist/Selector/utils.d.ts +2 -17
- package/dist/Selector/utils.d.ts.map +1 -1
- package/dist/Selector/utils.js +3 -51
- package/dist/Switch/Switch.d.ts +1 -1
- package/dist/Switch/Switch.d.ts.map +1 -1
- package/dist/Switch/Switch.js +200 -46
- package/dist/Switch/switchFill.d.ts +31 -0
- package/dist/Switch/switchFill.d.ts.map +1 -0
- package/dist/Switch/switchFill.js +88 -0
- package/dist/Switch/switchTouch.d.ts +74 -0
- package/dist/Switch/switchTouch.d.ts.map +1 -0
- package/dist/Switch/switchTouch.js +125 -0
- package/dist/Switch/useSwitchTouch.d.ts +276 -0
- package/dist/Switch/useSwitchTouch.d.ts.map +1 -0
- package/dist/Switch/useSwitchTouch.js +939 -0
- package/dist/TabList/Tab.d.ts.map +1 -1
- package/dist/TabList/Tab.js +4 -3
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +5 -0
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +1 -0
- package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
- package/dist/Tokenizer/Tokenizer.js +12 -5
- package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts +3 -0
- package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts.map +1 -0
- package/dist/Tokenizer/TokenizerItemRemovableContext.js +17 -0
- package/dist/Tooltip/Tooltip.d.ts +30 -6
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +5 -0
- package/dist/Tooltip/index.d.ts +1 -1
- package/dist/Tooltip/index.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.d.ts +31 -5
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +59 -18
- package/dist/Typeahead/Typeahead.d.ts.map +1 -1
- package/dist/Typeahead/Typeahead.js +26 -15
- package/dist/astryx.css +125 -2
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +71 -14
- package/dist/gestures/PressTracker.d.ts +6 -0
- package/dist/gestures/PressTracker.d.ts.map +1 -1
- package/dist/gestures/PressTracker.js +3 -0
- package/dist/gestures/types.d.ts +6 -0
- package/dist/gestures/types.d.ts.map +1 -1
- package/dist/gestures/usePressTracker.d.ts.map +1 -1
- package/dist/gestures/usePressTracker.js +1 -0
- package/dist/gestures/wheelSegmenter.d.ts +14 -3
- package/dist/gestures/wheelSegmenter.d.ts.map +1 -1
- package/dist/gestures/wheelSegmenter.js +32 -8
- package/dist/hooks/actionGroupTracker.d.ts +3 -3
- package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
- package/dist/hooks/actionGroupTracker.js +6 -53
- package/dist/hooks/useAttachment.d.ts +16 -8
- package/dist/hooks/useAttachment.d.ts.map +1 -1
- package/dist/hooks/useAttachment.js +35 -15
- package/dist/hooks/useFocusTrap.d.ts +15 -0
- package/dist/hooks/useFocusTrap.d.ts.map +1 -1
- package/dist/hooks/useFocusTrap.js +13 -2
- package/dist/hooks/useHighlightedOptionScroll.d.ts.map +1 -1
- package/dist/hooks/useHighlightedOptionScroll.js +14 -11
- package/dist/hooks/useMediaQuery.d.ts +2 -1
- package/dist/hooks/useMediaQuery.d.ts.map +1 -1
- package/dist/hooks/useMediaQuery.js +7 -4
- package/dist/hooks/usePager.d.ts +261 -0
- package/dist/hooks/usePager.d.ts.map +1 -0
- package/dist/hooks/usePager.js +1169 -0
- package/dist/i18n/generated-english/InfoTip/InfoTip.generated.d.ts +8 -0
- package/dist/i18n/generated-english/InfoTip/InfoTip.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/InfoTip/InfoTip.generated.js +12 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +2 -1
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/motion/paging.d.ts +16 -5
- package/dist/motion/paging.d.ts.map +1 -1
- package/dist/motion/paging.js +34 -14
- package/dist/motion/roles.d.ts +7 -1
- package/dist/motion/roles.d.ts.map +1 -1
- package/dist/motion/roles.js +20 -1
- package/dist/motion/uikit/index.d.ts +7 -4
- package/dist/motion/uikit/index.d.ts.map +1 -1
- package/dist/motion/uikit/index.js +7 -4
- package/dist/motion/uikit/paging.d.ts +31 -20
- package/dist/motion/uikit/paging.d.ts.map +1 -1
- package/dist/motion/uikit/paging.js +41 -11
- package/dist/motion/uikit/progressBar.d.ts +27 -7
- package/dist/motion/uikit/progressBar.d.ts.map +1 -1
- package/dist/motion/uikit/progressBar.js +31 -11
- package/dist/motion/uikit/segmented.d.ts +55 -0
- package/dist/motion/uikit/segmented.d.ts.map +1 -0
- package/dist/motion/uikit/segmented.js +77 -0
- package/dist/motion/uikit/springs.d.ts +8 -42
- package/dist/motion/uikit/springs.d.ts.map +1 -1
- package/dist/motion/uikit/springs.js +12 -42
- package/dist/motion/uikit/switch.d.ts +166 -0
- package/dist/motion/uikit/switch.d.ts.map +1 -0
- package/dist/motion/uikit/switch.js +186 -0
- package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts +18 -0
- package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/pressHoldsDrag.stylex.js +28 -0
- package/dist/privateAttributes/segmentTitle.stylex.d.ts +5 -0
- package/dist/privateAttributes/segmentTitle.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/segmentTitle.stylex.js +22 -0
- package/dist/utils/browserClickWait.d.ts +35 -0
- package/dist/utils/browserClickWait.d.ts.map +1 -0
- package/dist/utils/browserClickWait.js +123 -0
- package/dist/utils/clickGuard.d.ts +7 -1
- package/dist/utils/clickGuard.d.ts.map +1 -1
- package/dist/utils/clickGuard.js +23 -1
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +5 -0
- package/locales/en.json +4 -0
- package/locales/pseudo.json +3 -0
- package/package.json +9 -4
- package/src/Avatar/Avatar.tsx +3 -1
- package/src/Breadcrumbs/BreadcrumbItem.tsx +4 -1
- package/src/Button/Button.tsx +3 -2
- package/src/DateInput/Wheel.tsx +174 -14
- package/src/DateRangeInput/DateRangeInput.doc.mjs +3 -2
- package/src/DateRangeInput/DateRangeInput.tsx +117 -71
- package/src/Dialog/Dialog.tsx +62 -11
- package/src/Drawer/Drawer.tsx +27 -10
- package/src/Drawer/useDrawerDialogPresence.ts +4 -0
- package/src/DropdownMenu/DropdownMenu.tsx +28 -6
- package/src/InfoTip/InfoTip.doc.mjs +192 -0
- package/src/InfoTip/InfoTip.tsx +186 -0
- package/src/InfoTip/index.ts +14 -0
- package/src/Layer/layerClickBoundary.ts +2 -2
- package/src/Layer/useBackdropPress.ts +81 -0
- package/src/Layer/usePressPin.ts +516 -0
- package/src/Layer/useTouchTrigger.ts +56 -6
- package/src/Lightbox/Lightbox.tsx +2 -1
- package/src/Popover/usePopover.tsx +71 -9
- package/src/PowerSearch/PowerSearch.tsx +38 -31
- package/src/ProgressBar/ProgressBar.doc.mjs +4 -2
- package/src/ProgressBar/ProgressBar.tsx +67 -7
- package/src/SegmentedControl/SegmentedControl.doc.mjs +3 -3
- package/src/SegmentedControl/SegmentedControl.tsx +179 -5
- package/src/SegmentedControl/SegmentedControlContext.ts +6 -0
- package/src/SegmentedControl/SegmentedControlItem.tsx +14 -2
- package/src/SegmentedControl/useSegmentedSelectionMotion.ts +1637 -0
- package/src/SegmentedControl/useSegmentedTouchTracking.ts +308 -0
- package/src/Selector/Selector.tsx +136 -89
- package/src/Selector/optionShape.ts +64 -0
- package/src/Selector/selectableOptionEntries.ts +39 -0
- package/src/Selector/utils.ts +9 -68
- package/src/Switch/Switch.doc.mjs +3 -3
- package/src/Switch/Switch.tsx +412 -86
- package/src/Switch/switchFill.ts +106 -0
- package/src/Switch/switchTouch.ts +186 -0
- package/src/Switch/useSwitchTouch.ts +1051 -0
- package/src/TabList/Tab.tsx +5 -3
- package/src/Toast/Toast.tsx +5 -0
- package/src/Token/Token.tsx +2 -0
- package/src/Tokenizer/Tokenizer.tsx +15 -5
- package/src/Tokenizer/TokenizerItemRemovableContext.ts +22 -0
- package/src/Tooltip/Tooltip.doc.mjs +21 -6
- package/src/Tooltip/Tooltip.tsx +42 -5
- package/src/Tooltip/index.ts +1 -0
- package/src/Tooltip/useTooltip.doc.mjs +4 -2
- package/src/Tooltip/useTooltip.tsx +84 -21
- package/src/Typeahead/Typeahead.tsx +29 -15
- package/src/gestures/GestureHost.ts +100 -11
- package/src/gestures/PressTracker.ts +10 -0
- package/src/gestures/types.ts +6 -0
- package/src/gestures/usePressTracker.ts +2 -0
- package/src/gestures/wheelSegmenter.ts +36 -7
- package/src/hooks/actionGroupTracker.ts +12 -56
- package/src/hooks/useAttachment.ts +56 -14
- package/src/hooks/useFocusTrap.ts +26 -2
- package/src/hooks/useHighlightedOptionScroll.ts +15 -11
- package/src/hooks/useMediaQuery.doc.mjs +2 -2
- package/src/hooks/useMediaQuery.ts +13 -4
- package/src/hooks/usePager.ts +1446 -0
- package/src/i18n/generated-english/InfoTip/InfoTip.generated.ts +13 -0
- package/src/i18n/generated-locales/en.generated.ts +1 -0
- package/src/i18n/generated-locales/pseudo.generated.ts +1 -0
- package/src/index.ts +1 -0
- package/src/motion/MEASUREMENTS.md +36 -27
- package/src/motion/README.md +3 -1
- package/src/motion/paging.ts +37 -14
- package/src/motion/roles.ts +20 -1
- package/src/motion/uikit/index.ts +6 -5
- package/src/motion/uikit/paging.ts +41 -10
- package/src/motion/uikit/progressBar.ts +31 -11
- package/src/motion/uikit/segmented.ts +74 -0
- package/src/motion/uikit/springs.ts +12 -42
- package/src/motion/uikit/switch.ts +174 -0
- package/src/privateAttributes/pressHoldsDrag.stylex.ts +28 -0
- package/src/privateAttributes/segmentTitle.stylex.ts +22 -0
- package/src/utils/browserClickWait.ts +133 -0
- package/src/utils/clickGuard.ts +28 -1
- package/src/utils/pressFeedback.ts +5 -0
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file SegmentedControl.tsx
|
|
7
|
-
* @input Uses React, StyleX, SegmentedControlContext, useListFocus,
|
|
7
|
+
* @input Uses React, StyleX, SegmentedControlContext, useListFocus,
|
|
8
|
+
* useKeyboardHint, useTouchPresentation, useSegmentedSelectionMotion
|
|
8
9
|
* @output Exports SegmentedControl component and SegmentedControlProps type
|
|
9
10
|
* @position Container wrapper; provides context to SegmentedControlItem children
|
|
10
11
|
*
|
|
@@ -12,10 +13,11 @@
|
|
|
12
13
|
* - /packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
|
|
13
14
|
* - /packages/core/src/SegmentedControl/index.ts
|
|
14
15
|
* - /packages/core/src/SegmentedControl/SegmentedControl.test.tsx
|
|
16
|
+
* - /packages/core/src/SegmentedControl/useSegmentedSelectionMotion.ts
|
|
15
17
|
* - /packages/cli/assets/templates/blocks/components/SegmentedControl/ (showcase blocks)
|
|
16
18
|
*/
|
|
17
19
|
|
|
18
|
-
import React, {useMemo, useCallback, type ReactNode} from 'react';
|
|
20
|
+
import React, {useMemo, useCallback, useRef, type ReactNode} from 'react';
|
|
19
21
|
import * as stylex from '@stylexjs/stylex';
|
|
20
22
|
import {colorVars, spacingVars, radiusVars} from '../theme/tokens.stylex';
|
|
21
23
|
import {SegmentedControlContext} from './SegmentedControlContext';
|
|
@@ -34,6 +36,9 @@ import type {BaseProps} from '../BaseProps';
|
|
|
34
36
|
import {themeProps} from '../utils/themeProps';
|
|
35
37
|
|
|
36
38
|
import {useMergedRefs} from '../hooks/useMergedRefs';
|
|
39
|
+
import {useTouchPresentation} from '../utils/touchPresentation';
|
|
40
|
+
import {useSegmentedSelectionMotion} from './useSegmentedSelectionMotion';
|
|
41
|
+
|
|
37
42
|
export interface SegmentedControlProps extends Omit<
|
|
38
43
|
BaseProps<HTMLDivElement>,
|
|
39
44
|
'onChange'
|
|
@@ -94,6 +99,11 @@ export interface SegmentedControlProps extends Omit<
|
|
|
94
99
|
|
|
95
100
|
const styles = stylex.create({
|
|
96
101
|
container: {
|
|
102
|
+
// The lens's containing block and stacking context. The lens sits at
|
|
103
|
+
// z-index -1 inside it: above the track's own background, below every
|
|
104
|
+
// segment.
|
|
105
|
+
position: 'relative',
|
|
106
|
+
isolation: 'isolate',
|
|
97
107
|
display: 'inline-flex',
|
|
98
108
|
alignItems: 'center',
|
|
99
109
|
width: 'fit-content',
|
|
@@ -127,6 +137,140 @@ const styles = stylex.create({
|
|
|
127
137
|
disabled: {
|
|
128
138
|
opacity: 0.5,
|
|
129
139
|
},
|
|
140
|
+
// The lens uses the radiogroup's own pseudo-elements, so it adds no
|
|
141
|
+
// element. ::before carries the selected surface. Under Reduced Motion,
|
|
142
|
+
// ::after is the old surface that fades out in place. Both are hidden at
|
|
143
|
+
// rest. A negative z-index keeps them under every segment's content, inside
|
|
144
|
+
// the stacking context the container's isolation makes. Above the segments,
|
|
145
|
+
// a moving lens could paint over their titles. WebKit's overlap test can
|
|
146
|
+
// miss what a moving layer covers.
|
|
147
|
+
lens: {
|
|
148
|
+
'::before': {
|
|
149
|
+
content: '""',
|
|
150
|
+
position: 'absolute',
|
|
151
|
+
zIndex: -1,
|
|
152
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: laid out on a segment's box measured from client rects (useSegmentedSelectionMotion), in both directions.
|
|
153
|
+
left: 'var(--_segmented-lens-left, 0px)',
|
|
154
|
+
top: 'var(--_segmented-lens-top, 0px)',
|
|
155
|
+
width: 'var(--_segmented-lens-width, 0px)',
|
|
156
|
+
height: 'var(--_segmented-lens-height, 0px)',
|
|
157
|
+
boxSizing: 'border-box',
|
|
158
|
+
// Scales around its center: the lens's position and size are separate.
|
|
159
|
+
transformOrigin: '50% 50%',
|
|
160
|
+
pointerEvents: 'none',
|
|
161
|
+
visibility: 'var(--_segmented-lens-visibility, hidden)',
|
|
162
|
+
willChange: 'var(--astryx-motion-will-change-before, auto)',
|
|
163
|
+
// It carries a copy of an already resolved surface, forced colors
|
|
164
|
+
// included (Highlight), so the UA must not remap it again.
|
|
165
|
+
forcedColorAdjust: 'none',
|
|
166
|
+
backgroundColor: 'var(--_segmented-lens-background-color, transparent)',
|
|
167
|
+
backgroundImage: 'var(--_segmented-lens-background-image, none)',
|
|
168
|
+
backgroundPosition: 'var(--_segmented-lens-background-position, 0% 0%)',
|
|
169
|
+
backgroundSize: 'var(--_segmented-lens-background-size, auto)',
|
|
170
|
+
backgroundRepeat: 'var(--_segmented-lens-background-repeat, repeat)',
|
|
171
|
+
backgroundOrigin: 'var(--_segmented-lens-background-origin, padding-box)',
|
|
172
|
+
backgroundClip: 'var(--_segmented-lens-background-clip, border-box)',
|
|
173
|
+
boxShadow: 'var(--_segmented-lens-box-shadow, none)',
|
|
174
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
175
|
+
borderTopLeftRadius: 'var(--_segmented-lens-border-top-left-radius, 0px)',
|
|
176
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
177
|
+
borderTopRightRadius:
|
|
178
|
+
'var(--_segmented-lens-border-top-right-radius, 0px)',
|
|
179
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
180
|
+
borderBottomRightRadius:
|
|
181
|
+
'var(--_segmented-lens-border-bottom-right-radius, 0px)',
|
|
182
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
183
|
+
borderBottomLeftRadius:
|
|
184
|
+
'var(--_segmented-lens-border-bottom-left-radius, 0px)',
|
|
185
|
+
borderTopWidth: 'var(--_segmented-lens-border-top-width, 0px)',
|
|
186
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
187
|
+
borderRightWidth: 'var(--_segmented-lens-border-right-width, 0px)',
|
|
188
|
+
borderBottomWidth: 'var(--_segmented-lens-border-bottom-width, 0px)',
|
|
189
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
190
|
+
borderLeftWidth: 'var(--_segmented-lens-border-left-width, 0px)',
|
|
191
|
+
borderTopStyle: 'var(--_segmented-lens-border-top-style, none)',
|
|
192
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
193
|
+
borderRightStyle: 'var(--_segmented-lens-border-right-style, none)',
|
|
194
|
+
borderBottomStyle: 'var(--_segmented-lens-border-bottom-style, none)',
|
|
195
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
196
|
+
borderLeftStyle: 'var(--_segmented-lens-border-left-style, none)',
|
|
197
|
+
borderTopColor: 'var(--_segmented-lens-border-top-color, currentcolor)',
|
|
198
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
199
|
+
borderRightColor:
|
|
200
|
+
'var(--_segmented-lens-border-right-color, currentcolor)',
|
|
201
|
+
borderBottomColor:
|
|
202
|
+
'var(--_segmented-lens-border-bottom-color, currentcolor)',
|
|
203
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
204
|
+
borderLeftColor: 'var(--_segmented-lens-border-left-color, currentcolor)',
|
|
205
|
+
backdropFilter: 'var(--_segmented-lens-backdrop-filter, none)',
|
|
206
|
+
WebkitBackdropFilter:
|
|
207
|
+
'var(--_segmented-lens-webkit-backdrop-filter, none)',
|
|
208
|
+
},
|
|
209
|
+
'::after': {
|
|
210
|
+
content: '""',
|
|
211
|
+
position: 'absolute',
|
|
212
|
+
zIndex: -1,
|
|
213
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: laid out on a segment's box measured from client rects (useSegmentedSelectionMotion), in both directions.
|
|
214
|
+
left: 'var(--_segmented-after-left, 0px)',
|
|
215
|
+
top: 'var(--_segmented-after-top, 0px)',
|
|
216
|
+
width: 'var(--_segmented-after-width, 0px)',
|
|
217
|
+
height: 'var(--_segmented-after-height, 0px)',
|
|
218
|
+
boxSizing: 'border-box',
|
|
219
|
+
// Scales around its center: the lens's position and size are separate.
|
|
220
|
+
transformOrigin: '50% 50%',
|
|
221
|
+
pointerEvents: 'none',
|
|
222
|
+
visibility: 'var(--_segmented-after-visibility, hidden)',
|
|
223
|
+
willChange: 'var(--astryx-motion-will-change-after, auto)',
|
|
224
|
+
// It carries a copy of an already resolved surface, forced colors
|
|
225
|
+
// included (Highlight), so the UA must not remap it again.
|
|
226
|
+
forcedColorAdjust: 'none',
|
|
227
|
+
backgroundColor: 'var(--_segmented-after-background-color, transparent)',
|
|
228
|
+
backgroundImage: 'var(--_segmented-after-background-image, none)',
|
|
229
|
+
backgroundPosition: 'var(--_segmented-after-background-position, 0% 0%)',
|
|
230
|
+
backgroundSize: 'var(--_segmented-after-background-size, auto)',
|
|
231
|
+
backgroundRepeat: 'var(--_segmented-after-background-repeat, repeat)',
|
|
232
|
+
backgroundOrigin:
|
|
233
|
+
'var(--_segmented-after-background-origin, padding-box)',
|
|
234
|
+
backgroundClip: 'var(--_segmented-after-background-clip, border-box)',
|
|
235
|
+
boxShadow: 'var(--_segmented-after-box-shadow, none)',
|
|
236
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
237
|
+
borderTopLeftRadius:
|
|
238
|
+
'var(--_segmented-after-border-top-left-radius, 0px)',
|
|
239
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
240
|
+
borderTopRightRadius:
|
|
241
|
+
'var(--_segmented-after-border-top-right-radius, 0px)',
|
|
242
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
243
|
+
borderBottomRightRadius:
|
|
244
|
+
'var(--_segmented-after-border-bottom-right-radius, 0px)',
|
|
245
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
246
|
+
borderBottomLeftRadius:
|
|
247
|
+
'var(--_segmented-after-border-bottom-left-radius, 0px)',
|
|
248
|
+
borderTopWidth: 'var(--_segmented-after-border-top-width, 0px)',
|
|
249
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
250
|
+
borderRightWidth: 'var(--_segmented-after-border-right-width, 0px)',
|
|
251
|
+
borderBottomWidth: 'var(--_segmented-after-border-bottom-width, 0px)',
|
|
252
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
253
|
+
borderLeftWidth: 'var(--_segmented-after-border-left-width, 0px)',
|
|
254
|
+
borderTopStyle: 'var(--_segmented-after-border-top-style, none)',
|
|
255
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
256
|
+
borderRightStyle: 'var(--_segmented-after-border-right-style, none)',
|
|
257
|
+
borderBottomStyle: 'var(--_segmented-after-border-bottom-style, none)',
|
|
258
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
259
|
+
borderLeftStyle: 'var(--_segmented-after-border-left-style, none)',
|
|
260
|
+
borderTopColor: 'var(--_segmented-after-border-top-color, currentcolor)',
|
|
261
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
262
|
+
borderRightColor:
|
|
263
|
+
'var(--_segmented-after-border-right-color, currentcolor)',
|
|
264
|
+
borderBottomColor:
|
|
265
|
+
'var(--_segmented-after-border-bottom-color, currentcolor)',
|
|
266
|
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: a copy of the segment's computed (physical) surface.
|
|
267
|
+
borderLeftColor:
|
|
268
|
+
'var(--_segmented-after-border-left-color, currentcolor)',
|
|
269
|
+
backdropFilter: 'var(--_segmented-after-backdrop-filter, none)',
|
|
270
|
+
WebkitBackdropFilter:
|
|
271
|
+
'var(--_segmented-after-webkit-backdrop-filter, none)',
|
|
272
|
+
},
|
|
273
|
+
},
|
|
130
274
|
});
|
|
131
275
|
|
|
132
276
|
const sizeStyles = stylex.create({
|
|
@@ -177,6 +321,20 @@ export function SegmentedControl({
|
|
|
177
321
|
...rest
|
|
178
322
|
}: SegmentedControlProps) {
|
|
179
323
|
const size = useSize(sizeProp, 'md');
|
|
324
|
+
// A touch device (a coarse primary pointer) gets UIKit's motion: the
|
|
325
|
+
// selection slides on a spring. Under a mouse it slides on the theme's
|
|
326
|
+
// duration and easing.
|
|
327
|
+
const isTouchPresentation = useTouchPresentation().isTouch;
|
|
328
|
+
const trackRef = useRef<HTMLDivElement | null>(null);
|
|
329
|
+
// Every pointer's press is tracked. A drag from the selected segment
|
|
330
|
+
// carries the lens, and the lift commits the segment nearest the pointer.
|
|
331
|
+
// A lift outside the control commits nothing.
|
|
332
|
+
const {selection, attachTrack} = useSegmentedSelectionMotion(
|
|
333
|
+
trackRef,
|
|
334
|
+
value,
|
|
335
|
+
isTouchPresentation,
|
|
336
|
+
!isDisabled,
|
|
337
|
+
);
|
|
180
338
|
|
|
181
339
|
// Disabled-reason tooltip. Applies to the whole-group disabled state. The
|
|
182
340
|
// tooltip listeners attach to the radiogroup container, which keeps pointer
|
|
@@ -215,6 +373,7 @@ export function SegmentedControl({
|
|
|
215
373
|
|
|
216
374
|
const handleContainerKeyDown = useCallback(
|
|
217
375
|
(e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
376
|
+
selection.keyPressed();
|
|
218
377
|
onKeyDownProp?.(e);
|
|
219
378
|
if (e.defaultPrevented) {
|
|
220
379
|
return;
|
|
@@ -222,7 +381,7 @@ export function SegmentedControl({
|
|
|
222
381
|
hint.onKeyDown(e);
|
|
223
382
|
handleKeyDown(e);
|
|
224
383
|
},
|
|
225
|
-
[onKeyDownProp, hint, handleKeyDown],
|
|
384
|
+
[selection, onKeyDownProp, hint, handleKeyDown],
|
|
226
385
|
);
|
|
227
386
|
|
|
228
387
|
// Selection-follows-focus (APG radiogroup): useListFocus only *moves* focus,
|
|
@@ -252,6 +411,12 @@ export function SegmentedControl({
|
|
|
252
411
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
253
412
|
return;
|
|
254
413
|
}
|
|
414
|
+
// A mouse or pen press moves focus at pointerdown. A finger moves it
|
|
415
|
+
// after the lift, before the tap's click. The press commits through
|
|
416
|
+
// that click, so this focus move selects nothing.
|
|
417
|
+
if (selection.isPressing()) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
255
420
|
const focused = (e.target as HTMLElement | null)?.closest<HTMLElement>(
|
|
256
421
|
'[role="radio"][data-value]',
|
|
257
422
|
);
|
|
@@ -263,7 +428,7 @@ export function SegmentedControl({
|
|
|
263
428
|
onChange(nextValue);
|
|
264
429
|
}
|
|
265
430
|
},
|
|
266
|
-
[onFocusProp, hint, handleFocus, isDisabled, onChange, value],
|
|
431
|
+
[onFocusProp, hint, handleFocus, isDisabled, onChange, selection, value],
|
|
267
432
|
);
|
|
268
433
|
|
|
269
434
|
const contextValue = useMemo(
|
|
@@ -276,6 +441,7 @@ export function SegmentedControl({
|
|
|
276
441
|
disabledReasonID: showsDisabledMessage
|
|
277
442
|
? disabledMessageTooltip.describedBy
|
|
278
443
|
: undefined,
|
|
444
|
+
isTouchPresentation,
|
|
279
445
|
}),
|
|
280
446
|
[
|
|
281
447
|
value,
|
|
@@ -285,13 +451,20 @@ export function SegmentedControl({
|
|
|
285
451
|
isDisabled,
|
|
286
452
|
showsDisabledMessage,
|
|
287
453
|
disabledMessageTooltip.describedBy,
|
|
454
|
+
isTouchPresentation,
|
|
288
455
|
],
|
|
289
456
|
);
|
|
290
457
|
|
|
291
458
|
return (
|
|
292
459
|
<SegmentedControlContext value={contextValue}>
|
|
293
460
|
<div
|
|
294
|
-
ref={useMergedRefs(
|
|
461
|
+
ref={useMergedRefs(
|
|
462
|
+
ref,
|
|
463
|
+
listRef,
|
|
464
|
+
trackRef,
|
|
465
|
+
attachTrack,
|
|
466
|
+
disabledMessageTooltip.ref,
|
|
467
|
+
)}
|
|
295
468
|
{...rest}
|
|
296
469
|
role="radiogroup"
|
|
297
470
|
aria-label={label}
|
|
@@ -310,6 +483,7 @@ export function SegmentedControl({
|
|
|
310
483
|
styles.container,
|
|
311
484
|
sizeStyles[size],
|
|
312
485
|
layout === 'fill' && styles.fill,
|
|
486
|
+
(isTouchPresentation || !isDisabled) && styles.lens,
|
|
313
487
|
isDisabled && styles.disabled,
|
|
314
488
|
xstyle,
|
|
315
489
|
),
|
|
@@ -29,6 +29,12 @@ export interface SegmentedControlContextValue {
|
|
|
29
29
|
* described by the reason (spec:AST-085 FR5).
|
|
30
30
|
*/
|
|
31
31
|
disabledReasonID?: string;
|
|
32
|
+
/**
|
|
33
|
+
* True in the touch presentation (under a finger, `useTouchPresentation`):
|
|
34
|
+
* the control animates selection changes itself (the surface slides), so
|
|
35
|
+
* segments drop their CSS transitions.
|
|
36
|
+
*/
|
|
37
|
+
isTouchPresentation?: boolean;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export const SegmentedControlContext =
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @position Child item; renders as a radio button within the segmented control
|
|
10
10
|
*
|
|
11
11
|
* SYNC: When modified, update:
|
|
12
|
+
* - /packages/core/src/SegmentedControl/useSegmentedSelectionMotion.ts (the title marker)
|
|
12
13
|
* - /packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
|
|
13
14
|
* - /packages/core/src/SegmentedControl/index.ts
|
|
14
15
|
* - /packages/core/src/SegmentedControl/SegmentedControl.test.tsx
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
import React, {type ReactNode} from 'react';
|
|
19
20
|
import {joinAriaIDs} from '../utils/inputAria';
|
|
20
21
|
import {segmentDisabledProps} from '../privateAttributes/segmentDisabled.stylex';
|
|
22
|
+
import {segmentTitleProps} from '../privateAttributes/segmentTitle.stylex';
|
|
21
23
|
import * as stylex from '@stylexjs/stylex';
|
|
22
24
|
import {
|
|
23
25
|
colorVars,
|
|
@@ -37,6 +39,7 @@ import {themeProps} from '../utils/themeProps';
|
|
|
37
39
|
import {focusOutlineProps} from '../utils/focusOutline.stylex';
|
|
38
40
|
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
|
|
39
41
|
import {usePressFeedback} from '../hooks/usePressFeedback';
|
|
42
|
+
import {isRenderable} from '../utils/isRenderable';
|
|
40
43
|
|
|
41
44
|
export interface SegmentedControlItemProps extends BaseProps<HTMLButtonElement> {
|
|
42
45
|
ref?: React.Ref<HTMLButtonElement>;
|
|
@@ -146,6 +149,12 @@ const styles = stylex.create({
|
|
|
146
149
|
textOverflow: 'ellipsis',
|
|
147
150
|
minWidth: 0,
|
|
148
151
|
},
|
|
152
|
+
// Under a finger, script animates the selection change, because the surface
|
|
153
|
+
// slides. A CSS transition would run a second, main-thread version of the
|
|
154
|
+
// same change.
|
|
155
|
+
touchPresentation: {
|
|
156
|
+
transitionProperty: 'none',
|
|
157
|
+
},
|
|
149
158
|
});
|
|
150
159
|
|
|
151
160
|
const CONCENTRIC_RADIUS =
|
|
@@ -219,7 +228,7 @@ export function SegmentedControlItem({
|
|
|
219
228
|
},
|
|
220
229
|
);
|
|
221
230
|
|
|
222
|
-
const iconElement = icon ? (
|
|
231
|
+
const iconElement = isRenderable(icon) ? (
|
|
223
232
|
<span {...stylex.props(styles.icon, iconSizeStyles[size])}>{icon}</span>
|
|
224
233
|
) : null;
|
|
225
234
|
|
|
@@ -262,12 +271,15 @@ export function SegmentedControlItem({
|
|
|
262
271
|
!isItemDisabled &&
|
|
263
272
|
interactionOverlayStyles.backgroundColor,
|
|
264
273
|
isItemDisabled && styles.disabled,
|
|
274
|
+
ctx.isTouchPresentation === true && styles.touchPresentation,
|
|
265
275
|
xstyle,
|
|
266
276
|
),
|
|
267
277
|
)}>
|
|
268
278
|
{iconElement}
|
|
269
279
|
{!isLabelHidden && (
|
|
270
|
-
<span {...stylex.props(styles.labelText)}>
|
|
280
|
+
<span {...segmentTitleProps} {...stylex.props(styles.labelText)}>
|
|
281
|
+
{label}
|
|
282
|
+
</span>
|
|
271
283
|
)}
|
|
272
284
|
</button>
|
|
273
285
|
);
|