@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
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
19
19
|
import * as stylex from '@stylexjs/stylex';
|
|
20
20
|
import { useLayer } from "../Layer/useLayer.js";
|
|
21
|
-
import {
|
|
21
|
+
import { useFocusTrapInternal } from "../hooks/useFocusTrap.js";
|
|
22
22
|
import { LayerDepthProvider } from "../Layer/LayerDepthContext.js";
|
|
23
23
|
import "../theme/tokens.stylex.js";
|
|
24
24
|
import { colorVars, spacingVars, radiusVars, shadowVars } from "../theme/tokens.stylex.js";
|
|
@@ -28,6 +28,7 @@ import { rtlStyles } from "../utils/index.js";
|
|
|
28
28
|
import { useDevWarning } from "../hooks/useDevWarning.js";
|
|
29
29
|
import { focusOutlineProps } from "../utils/focusOutline.stylex.js";
|
|
30
30
|
import { mergeProps } from "../utils/mergeProps.js";
|
|
31
|
+
import { isFocusDetached } from "../utils/focusReturn.js";
|
|
31
32
|
import { themeProps } from "../utils/themeProps.js";
|
|
32
33
|
import { paddingStyles } from "../Layout/padding.stylex.js";
|
|
33
34
|
import { stableClassName } from "../naming.js";
|
|
@@ -161,30 +162,52 @@ function usePopoverImplementation(options = {}) {
|
|
|
161
162
|
|
|
162
163
|
// Track whether to skip auto-focus for the current open event
|
|
163
164
|
const skipAutoFocusRef = useRef(false);
|
|
165
|
+
// Whether `show` focused a content control within the opening event.
|
|
166
|
+
const hasFocusedInGestureRef = useRef(false);
|
|
167
|
+
|
|
168
|
+
// Set when the layer reports it has shown, so `show` can tell a popover
|
|
169
|
+
// that opened within the call from one whose content mounts later.
|
|
170
|
+
const hasShownRef = useRef(false);
|
|
171
|
+
const handleLayerShow = useCallback(() => {
|
|
172
|
+
hasShownRef.current = true;
|
|
173
|
+
onShow?.();
|
|
174
|
+
}, [onShow]);
|
|
164
175
|
|
|
165
176
|
// Core layer for popover positioning
|
|
166
177
|
const layer = useLayer({
|
|
167
178
|
mode: 'context',
|
|
168
179
|
lightDismiss: hasLightDismiss,
|
|
169
|
-
onShow,
|
|
180
|
+
onShow: handleLayerShow,
|
|
170
181
|
onHide
|
|
171
182
|
});
|
|
172
183
|
|
|
173
184
|
// Focus trap for the popover content. Escape stays registered while light
|
|
174
185
|
// dismiss is on (native popover="auto" closes on Escape regardless), so a
|
|
175
186
|
// host Dialog keeps deferring to this trap instead of double-dismissing.
|
|
187
|
+
// The element focused when `show` ran: initial focus may move inside before
|
|
188
|
+
// the trap activates, so the trap restores focus here instead.
|
|
189
|
+
const openerRef = useRef(null);
|
|
190
|
+
const getRestoreTarget = useCallback(() => openerRef.current, []);
|
|
176
191
|
const {
|
|
177
192
|
containerRef: contentRef,
|
|
178
193
|
focusFirst
|
|
179
|
-
} =
|
|
194
|
+
} = useFocusTrapInternal({
|
|
180
195
|
isActive: layer.isOpen,
|
|
181
|
-
onEscape: hasEscapeDismiss || hasLightDismiss ? layer.hide : undefined
|
|
196
|
+
onEscape: hasEscapeDismiss || hasLightDismiss ? layer.hide : undefined,
|
|
197
|
+
getRestoreTarget
|
|
182
198
|
});
|
|
183
199
|
const focusInitialTarget = useCallback(() => {
|
|
184
200
|
const container = contentRef.current;
|
|
185
201
|
if (!container) {
|
|
186
202
|
return;
|
|
187
203
|
}
|
|
204
|
+
// Focus already on a control inside (set in `onShow`, or a press in the
|
|
205
|
+
// content) is where the user or the caller wants it; moving it would
|
|
206
|
+
// undo that.
|
|
207
|
+
const active = container.ownerDocument.activeElement;
|
|
208
|
+
if (active != null && active !== container && container.contains(active)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
188
211
|
if (focusFirstContentControl(container)) {
|
|
189
212
|
return;
|
|
190
213
|
}
|
|
@@ -200,16 +223,23 @@ function usePopoverImplementation(options = {}) {
|
|
|
200
223
|
// Reset the per-open focus preference after the popover closes.
|
|
201
224
|
if (!layer.isOpen) {
|
|
202
225
|
skipAutoFocusRef.current = false;
|
|
226
|
+
hasFocusedInGestureRef.current = false;
|
|
203
227
|
return;
|
|
204
228
|
}
|
|
205
229
|
if (hasAutoFocus && !skipAutoFocusRef.current) {
|
|
206
230
|
// Wait a frame so the content is mounted. A popover that closes or
|
|
207
231
|
// unmounts first cancels it: the frame would otherwise move focus into
|
|
208
232
|
// content that is no longer shown, after the close had left it alone.
|
|
209
|
-
const frame = requestAnimationFrame(
|
|
233
|
+
const frame = requestAnimationFrame(() => {
|
|
234
|
+
const doc = contentRef.current?.ownerDocument ?? document;
|
|
235
|
+
if (hasFocusedInGestureRef.current && !isFocusDetached(doc)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
focusInitialTarget();
|
|
239
|
+
});
|
|
210
240
|
return () => cancelAnimationFrame(frame);
|
|
211
241
|
}
|
|
212
|
-
}, [layer.isOpen, hasAutoFocus, focusInitialTarget]);
|
|
242
|
+
}, [layer.isOpen, hasAutoFocus, focusInitialTarget, contentRef]);
|
|
213
243
|
|
|
214
244
|
// Combined ref for trigger element (layer anchor + our ref). It is keyed on
|
|
215
245
|
// the layer's own ref, not the whole layer: the layer object changes with
|
|
@@ -227,8 +257,27 @@ function usePopoverImplementation(options = {}) {
|
|
|
227
257
|
// Show function with optional focus preservation
|
|
228
258
|
const show = useCallback(showOptions => {
|
|
229
259
|
skipAutoFocusRef.current = showOptions?.skipAutoFocus ?? false;
|
|
260
|
+
hasShownRef.current = false;
|
|
261
|
+
const activeElement = (triggerElementRef.current?.ownerDocument ?? document).activeElement;
|
|
262
|
+
openerRef.current = activeElement != null && !contentRef.current?.contains(activeElement) ? activeElement : null;
|
|
230
263
|
layer.show();
|
|
231
|
-
|
|
264
|
+
// When the content is already mounted, the layer shows it within this
|
|
265
|
+
// call, so initial focus lands within the event that opened it: iOS
|
|
266
|
+
// raises its keyboard only for a focus made while the tap is still
|
|
267
|
+
// being handled. The frame in the effect above stays for content that
|
|
268
|
+
// mounts later.
|
|
269
|
+
// Only a content control already rendered takes focus here; content
|
|
270
|
+
// that renders on open (and the dialog-surface fallback) waits for the
|
|
271
|
+
// effect's frame.
|
|
272
|
+
const container = contentRef.current;
|
|
273
|
+
if (hasShownRef.current && hasAutoFocus && !skipAutoFocusRef.current && container != null && !container.contains(container.ownerDocument.activeElement) && focusFirstContentControl(container)) {
|
|
274
|
+
// Initial focus is done. The effect's frame stays only as a fallback
|
|
275
|
+
// for focus lost to the page (content swapped in the same handler
|
|
276
|
+
// unmounts the control just focused); it must not move focus the user
|
|
277
|
+
// has since moved elsewhere.
|
|
278
|
+
hasFocusedInGestureRef.current = true;
|
|
279
|
+
}
|
|
280
|
+
}, [layer, hasAutoFocus, contentRef]);
|
|
232
281
|
|
|
233
282
|
// Toggle function. Opening delegates to show so every route inherits the
|
|
234
283
|
// same-gesture reopen guard owned by Layer.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PowerSearch.d.ts","sourceRoot":"","sources":["../../src/PowerSearch/PowerSearch.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAGL,KAAK,yBAAyB,EAC/B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"PowerSearch.d.ts","sourceRoot":"","sources":["../../src/PowerSearch/PowerSearch.tsx"],"names":[],"mappings":"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"}
|
|
@@ -17,6 +17,7 @@ import React, { useCallback, useEffect, useImperativeHandle, useMemo, useRef, us
|
|
|
17
17
|
import * as stylex from '@stylexjs/stylex';
|
|
18
18
|
import { Tokenizer } from "../Tokenizer/index.js";
|
|
19
19
|
import { TokenizerClearAllMessageContext } from "../Tokenizer/TokenizerClearAllMessageContext.js";
|
|
20
|
+
import { TokenizerItemRemovableContext } from "../Tokenizer/TokenizerItemRemovableContext.js";
|
|
20
21
|
import { TypeaheadItem } from "../Typeahead/TypeaheadItem.js";
|
|
21
22
|
import { Token } from "../Token/index.js";
|
|
22
23
|
import { Avatar } from "../Avatar/index.js";
|
|
@@ -541,6 +542,10 @@ export function PowerSearch({
|
|
|
541
542
|
}
|
|
542
543
|
}, [config, filters, onChange, setPopoverState]);
|
|
543
544
|
|
|
545
|
+
// Tokenizer's Backspace does not go through renderToken. This predicate
|
|
546
|
+
// locks every token of a read-only field.
|
|
547
|
+
const isItemRemovable = useCallback(() => !isReadOnly, [isReadOnly]);
|
|
548
|
+
|
|
544
549
|
// Handle clicking a token to edit
|
|
545
550
|
const handleTokenClick = useCallback(index => {
|
|
546
551
|
if (isReadOnly || isDisabled) {
|
|
@@ -809,36 +814,39 @@ export function PowerSearch({
|
|
|
809
814
|
...themeProps('power-search'),
|
|
810
815
|
children: /*#__PURE__*/_jsx(TokenizerClearAllMessageContext, {
|
|
811
816
|
value: clearAllMessage,
|
|
812
|
-
children: /*#__PURE__*/_jsx(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
817
|
+
children: /*#__PURE__*/_jsx(TokenizerItemRemovableContext, {
|
|
818
|
+
value: isItemRemovable,
|
|
819
|
+
children: /*#__PURE__*/_jsx(Tokenizer, {
|
|
820
|
+
handleRef: tokenizerRef,
|
|
821
|
+
label: label,
|
|
822
|
+
isLabelHidden: isLabelHidden,
|
|
823
|
+
searchSource: searchSource,
|
|
824
|
+
value: tokenizerValue,
|
|
825
|
+
onChange: handleTokenizerChange,
|
|
826
|
+
renderToken: renderToken,
|
|
827
|
+
renderItem: renderItem,
|
|
828
|
+
maxMenuItems: MAX_BROWSE_MENU_ITEMS,
|
|
829
|
+
menuWidth: menuWidth,
|
|
830
|
+
placeholder: filters.length === 0 ? placeholder : '',
|
|
831
|
+
hasAutoFocus: hasAutoFocus,
|
|
832
|
+
hasClear: hasClear && !isReadOnly,
|
|
833
|
+
startIcon: startIcon,
|
|
834
|
+
endContent: combinedEndContent,
|
|
835
|
+
isDisabled: isDisabled,
|
|
836
|
+
disabledMessage: disabledMessage,
|
|
837
|
+
size: size,
|
|
838
|
+
tokenOverflowBehavior: tokenOverflowBehavior,
|
|
839
|
+
hasEntriesOnFocus: true,
|
|
840
|
+
debounceMs: 0,
|
|
841
|
+
status: status,
|
|
842
|
+
statusVariant: statusVariant,
|
|
843
|
+
onFocus: onFocus,
|
|
844
|
+
onBlur: onBlur,
|
|
845
|
+
containerXstyle: xstyle,
|
|
846
|
+
containerClassName: className,
|
|
847
|
+
containerStyle: style,
|
|
848
|
+
"data-testid": testId
|
|
849
|
+
})
|
|
842
850
|
})
|
|
843
851
|
})
|
|
844
852
|
}), popover.render(popoverContent, {
|
|
@@ -70,7 +70,7 @@ export interface ProgressBarProps extends BaseProps<HTMLDivElement> {
|
|
|
70
70
|
* When true, renders an animated indeterminate progress indicator.
|
|
71
71
|
* Use when the progress amount is unknown (e.g. loading, processing).
|
|
72
72
|
* The `value` and `hasValueLabel` props are ignored in this mode.
|
|
73
|
-
*
|
|
73
|
+
* Under reduced motion it pulses in place instead of sliding.
|
|
74
74
|
* @default false
|
|
75
75
|
*/
|
|
76
76
|
isIndeterminate?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressBar.d.ts","sourceRoot":"","sources":["../../src/ProgressBar/ProgressBar.tsx"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ProgressBar.d.ts","sourceRoot":"","sources":["../../src/ProgressBar/ProgressBar.tsx"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;AAenD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,qBAAqB,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACjE,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1D;;;OAGG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAoZD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAS,EACT,GAAS,EACT,KAAK,EACL,aAAqB,EACrB,aAAqB,EACrB,gBAA0C,EAC1C,OAAkB,EAClB,eAAuB,EACvB,UAAkB,EAClB,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,aAAa,EAAE,UAAU,EACzB,GAAG,EACH,GAAG,IAAI,EACR,EAAE,gBAAgB,+BA6KlB;yBA9Le,WAAW"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file ProgressBar.tsx
|
|
7
|
-
* @input Uses React, useId, stylex, tokens and
|
|
7
|
+
* @input Uses React, useId, stylex, tokens, ProgressBarTouch and resolveMotion
|
|
8
8
|
* @output Exports ProgressBar component, ProgressBarProps, ProgressBarVariant types
|
|
9
9
|
* @position Core implementation; consumed by index.ts
|
|
10
10
|
*
|
|
@@ -25,6 +25,10 @@ import { focusOutlineStyles } from "../utils/focusOutline.stylex.js";
|
|
|
25
25
|
import { themeProps } from "../utils/themeProps.js";
|
|
26
26
|
import { VisuallyHidden } from "../VisuallyHidden/index.js";
|
|
27
27
|
import { useProgressBarTouch } from "./ProgressBarTouch.js";
|
|
28
|
+
import { formatMotionRoleValue } from "../motion/roles.js";
|
|
29
|
+
import { resolveMotion } from "../motion/resolveMotion.js";
|
|
30
|
+
import { progressBar } from "../motion/uikit/progressBar.js";
|
|
31
|
+
import { timing } from "../motion/uikit/timing.js";
|
|
28
32
|
|
|
29
33
|
// Every mark is wrapped in a Tooltip (marks always carry a label), so load it
|
|
30
34
|
// lazily: a ProgressBar with no marks never bundles the Tooltip chunk. While it
|
|
@@ -57,6 +61,12 @@ const indeterminateSlide = "xr3m334-B";
|
|
|
57
61
|
// physically left → right. The magnitudes mirror the LTR keyframe.
|
|
58
62
|
const indeterminateSlideRtl = "x1c2q33o-B";
|
|
59
63
|
|
|
64
|
+
// Under reduced motion the indeterminate fill stops travelling and pulses in
|
|
65
|
+
// place. It goes from full opacity down to the pulse's floor
|
|
66
|
+
// (`--_progress-bar-pulse-floor`, the progress table's) and back. The
|
|
67
|
+
// animation alternates direction each pass.
|
|
68
|
+
const indeterminatePulse = "xml828b-B";
|
|
69
|
+
|
|
60
70
|
// =============================================================================
|
|
61
71
|
// Styles
|
|
62
72
|
// =============================================================================
|
|
@@ -95,11 +105,12 @@ const styles = {
|
|
|
95
105
|
k3XXqK: "x815t2r",
|
|
96
106
|
kjBf7l: "x3teovq",
|
|
97
107
|
kInvED: "xvr1dqx",
|
|
98
|
-
kzqmXN: "xz84dc7",
|
|
108
|
+
kzqmXN: "xz84dc7 xie2s74",
|
|
99
109
|
kaIpWk: "xjspbzw",
|
|
100
|
-
kKVMdj: "xozk8ic xfd3fxj",
|
|
101
|
-
k44tkh: "xmg6eyc
|
|
102
|
-
kyAemX: "x4hg4is",
|
|
110
|
+
kKVMdj: "xozk8ic xfd3fxj x1a94pi7 xfqa98z",
|
|
111
|
+
k44tkh: "xmg6eyc x1p2ibn3",
|
|
112
|
+
kyAemX: "x4hg4is x10xcq22",
|
|
113
|
+
kILWW9: "x4q6aw4",
|
|
103
114
|
ko0y90: "xa4qsjk",
|
|
104
115
|
$$css: true
|
|
105
116
|
},
|
|
@@ -202,10 +213,25 @@ const markOnTrackStyles = {
|
|
|
202
213
|
}
|
|
203
214
|
};
|
|
204
215
|
|
|
216
|
+
// The reduced-motion pulse's variables, from the progress table.
|
|
217
|
+
|
|
205
218
|
// `CSSProperties` has no index signature for custom properties, so the fill's
|
|
206
219
|
// inline style — which publishes the filled share as the private
|
|
207
220
|
// `--_progress-bar-fill` — needs this augmentation to typecheck.
|
|
208
221
|
|
|
222
|
+
/**
|
|
223
|
+
* The reduced-motion pulse plays the `progress.reducedMotionPulseMs` role on
|
|
224
|
+
* the `timing.curves.move` curve, down to the progress table's floor.
|
|
225
|
+
*/
|
|
226
|
+
function pulseStyle(element) {
|
|
227
|
+
const pulseMs = resolveMotion(element, progressBar, 'reducedMotionPulseMs');
|
|
228
|
+
const curve = resolveMotion(element, timing.curves.move);
|
|
229
|
+
return {
|
|
230
|
+
'--_progress-bar-pulse': `${pulseMs}ms`,
|
|
231
|
+
'--_progress-bar-pulse-curve': formatMotionRoleValue('curve', curve),
|
|
232
|
+
'--_progress-bar-pulse-floor': String(progressBar.reducedMotionPulseFloor)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
209
235
|
function defaultFormatValueLabel(value, max) {
|
|
210
236
|
const pct = max > 0 ? Math.round(value / max * 100) : 0;
|
|
211
237
|
return `${pct}%`;
|
|
@@ -371,7 +397,8 @@ export function ProgressBar({
|
|
|
371
397
|
children: isIndeterminate ? /*#__PURE__*/_jsx("div", {
|
|
372
398
|
...mergeProps(themeProps('progress-bar-fill', {
|
|
373
399
|
variant: fillVariant
|
|
374
|
-
}), stylex.props(styles.indeterminateFill, variantStyles[fillVariant]))
|
|
400
|
+
}), stylex.props(styles.indeterminateFill, variantStyles[fillVariant])),
|
|
401
|
+
style: pulseStyle(null)
|
|
375
402
|
}) : /*#__PURE__*/_jsx("div", {
|
|
376
403
|
...mergeProps(themeProps('progress-bar-fill', {
|
|
377
404
|
variant: fillVariant
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file SegmentedControl.tsx
|
|
3
|
-
* @input Uses React, StyleX, SegmentedControlContext, useListFocus,
|
|
3
|
+
* @input Uses React, StyleX, SegmentedControlContext, useListFocus,
|
|
4
|
+
* useKeyboardHint, useTouchPresentation, useSegmentedSelectionMotion
|
|
4
5
|
* @output Exports SegmentedControl component and SegmentedControlProps type
|
|
5
6
|
* @position Container wrapper; provides context to SegmentedControlItem children
|
|
6
7
|
*
|
|
@@ -8,6 +9,7 @@
|
|
|
8
9
|
* - /packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
|
|
9
10
|
* - /packages/core/src/SegmentedControl/index.ts
|
|
10
11
|
* - /packages/core/src/SegmentedControl/SegmentedControl.test.tsx
|
|
12
|
+
* - /packages/core/src/SegmentedControl/useSegmentedSelectionMotion.ts
|
|
11
13
|
* - /packages/cli/assets/templates/blocks/components/SegmentedControl/ (showcase blocks)
|
|
12
14
|
*/
|
|
13
15
|
import React, { type ReactNode } from 'react';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,EAA+B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAQ1E,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AAInC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAO5C,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CACjD,SAAS,CAAC,cAAc,CAAC,EACzB,UAAU,CACX;IACC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAChC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;CACrB;AAqMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EAAE,QAAQ,EACd,MAAc,EACd,UAAkB,EAClB,eAAe,EACf,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAK,EACL,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,kBAAkB,EAAE,mBAAmB,EACvC,GAAG,IAAI,EACR,EAAE,qBAAqB,qBAkLvB;yBApMe,gBAAgB"}
|
|
@@ -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,9 +13,10 @@
|
|
|
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
|
-
import React, { useMemo, useCallback } from 'react';
|
|
19
|
+
import React, { useMemo, useCallback, useRef } from 'react';
|
|
18
20
|
import * as stylex from '@stylexjs/stylex';
|
|
19
21
|
import "../theme/tokens.stylex.js";
|
|
20
22
|
import { colorVars, spacingVars, radiusVars } from "../theme/tokens.stylex.js";
|
|
@@ -28,6 +30,8 @@ import { joinAriaIDs } from "../utils/inputAria.js";
|
|
|
28
30
|
import { useSize } from "../SizeContext/SizeContext.js";
|
|
29
31
|
import { themeProps } from "../utils/themeProps.js";
|
|
30
32
|
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
33
|
+
import { useTouchPresentation } from "../utils/touchPresentation.js";
|
|
34
|
+
import { useSegmentedSelectionMotion } from "./useSegmentedSelectionMotion.js";
|
|
31
35
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
36
|
// =============================================================================
|
|
33
37
|
// Styles
|
|
@@ -35,6 +39,8 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
35
39
|
|
|
36
40
|
const styles = {
|
|
37
41
|
container: {
|
|
42
|
+
kVAEAm: "x1n2onr6",
|
|
43
|
+
kHBbk8: "xc8icb0",
|
|
38
44
|
k1xSpc: "x3nfvp2",
|
|
39
45
|
kGNEyG: "x6s0dn4",
|
|
40
46
|
kzqmXN: "xeq5yr9",
|
|
@@ -54,6 +60,87 @@ const styles = {
|
|
|
54
60
|
disabled: {
|
|
55
61
|
kSiTet: "xbyyjgo",
|
|
56
62
|
$$css: true
|
|
63
|
+
},
|
|
64
|
+
lens: {
|
|
65
|
+
kgeoSG: "x1cpjm7i",
|
|
66
|
+
kEoFBp: "x1hmns74",
|
|
67
|
+
kxmVGU: "xy5mcqj",
|
|
68
|
+
k75S9Q: "x1h6x5ug",
|
|
69
|
+
k96MEf: "x319kzk",
|
|
70
|
+
kOlAkY: "xj84cd",
|
|
71
|
+
kgzTxl: "xlxjeq7",
|
|
72
|
+
kQmYQc: "xtql2tq",
|
|
73
|
+
kEdqc7: "x1xm9zrc",
|
|
74
|
+
km8f2m: "xkk1bqk",
|
|
75
|
+
ktHQil: "x1e91tbo",
|
|
76
|
+
kSdLuy: "xwrs98t",
|
|
77
|
+
ku0W4C: "x13rwrtk",
|
|
78
|
+
kLkRvE: "x1nk0e2p",
|
|
79
|
+
k3DiCg: "x19ph129",
|
|
80
|
+
kuPSpR: "xkyjh71",
|
|
81
|
+
k836YN: "xai7mxl",
|
|
82
|
+
kTP8oX: "xzr6j9d",
|
|
83
|
+
khXQ3S: "x1mz0nwo",
|
|
84
|
+
k2irxo: "xtojb3y",
|
|
85
|
+
ktNmms: "x19rx9s5",
|
|
86
|
+
kGBI9E: "x1gz1ewn",
|
|
87
|
+
ks091d: "xirquxt",
|
|
88
|
+
k9BEaU: "x1rj83xg",
|
|
89
|
+
kLSKZI: "x1gp8cmm",
|
|
90
|
+
kg8CZY: "x267z7u",
|
|
91
|
+
kgb78d: "xu7nluz",
|
|
92
|
+
kTJRYx: "xaki043",
|
|
93
|
+
kUmSqE: "x131tjkd",
|
|
94
|
+
k2L7bE: "x10hoewy",
|
|
95
|
+
krR4Wo: "x1rimih4",
|
|
96
|
+
kjBTDo: "xjmzqq9",
|
|
97
|
+
ktumvE: "xymdich",
|
|
98
|
+
kwknyK: "x1l1ofoh",
|
|
99
|
+
kSMQRv: "x1whvb6r",
|
|
100
|
+
k1cwP5: "xg5vybf",
|
|
101
|
+
k6d8aP: "x1j47n5p",
|
|
102
|
+
klC6Y0: "x11t1reg",
|
|
103
|
+
kFbLEI: "x1icymkt",
|
|
104
|
+
k5JduY: "x1s928wv",
|
|
105
|
+
kwXMNM: "x1j6awrg",
|
|
106
|
+
kDVEDD: "xi4xitw",
|
|
107
|
+
kH8cDV: "x1ggeerv",
|
|
108
|
+
k3foIR: "x3g43gi",
|
|
109
|
+
kkgrvl: "x1l8h5kv",
|
|
110
|
+
k4zj60: "x1fv2pxm",
|
|
111
|
+
kWgvks: "xx38sju",
|
|
112
|
+
k51VwD: "x8ihlwz",
|
|
113
|
+
kloYau: "x2q1x1w",
|
|
114
|
+
kMEsQN: "x1631zco",
|
|
115
|
+
kWkaDd: "x1y8idqa",
|
|
116
|
+
kU8QeM: "xwnwc82",
|
|
117
|
+
ks3ayO: "x1wb6yj0",
|
|
118
|
+
kNctxI: "x10e6nnj",
|
|
119
|
+
kgUb28: "x1d269y",
|
|
120
|
+
kakxe6: "x1pxrrzi",
|
|
121
|
+
kIWj2l: "x19crzk3",
|
|
122
|
+
kJM1pu: "x17as9s2",
|
|
123
|
+
kM2ZXO: "x54l34w",
|
|
124
|
+
kbMawA: "x1tmynux",
|
|
125
|
+
kgFEc0: "x13ob3d2",
|
|
126
|
+
kDH5la: "xbn9yse",
|
|
127
|
+
kBNLoZ: "x1icybqf",
|
|
128
|
+
kskBYc: "xk12vn8",
|
|
129
|
+
k9Mpue: "xsbnptc",
|
|
130
|
+
k6OB6z: "x1n4cxts",
|
|
131
|
+
kHSQhd: "x11at6vl",
|
|
132
|
+
kFO5lE: "x1t5rpqk",
|
|
133
|
+
kRcv9L: "x1ff385h",
|
|
134
|
+
kHi7i2: "x1tili5q",
|
|
135
|
+
kh0EW9: "xe87dmk",
|
|
136
|
+
kjCSS1: "x3sz45y",
|
|
137
|
+
kfzc6R: "x18pjm2d",
|
|
138
|
+
kc1AQg: "xa4st9h",
|
|
139
|
+
kvRJ0G: "x1tqw9ds",
|
|
140
|
+
kcGwG1: "x1pgdhoo",
|
|
141
|
+
kR8tOf: "xc4c6yy",
|
|
142
|
+
kxzRJW: "xt64kwx",
|
|
143
|
+
$$css: true
|
|
57
144
|
}
|
|
58
145
|
};
|
|
59
146
|
const sizeStyles = {
|
|
@@ -107,6 +194,18 @@ export function SegmentedControl({
|
|
|
107
194
|
...rest
|
|
108
195
|
}) {
|
|
109
196
|
const size = useSize(sizeProp, 'md');
|
|
197
|
+
// A touch device (a coarse primary pointer) gets UIKit's motion: the
|
|
198
|
+
// selection slides on a spring. Under a mouse it slides on the theme's
|
|
199
|
+
// duration and easing.
|
|
200
|
+
const isTouchPresentation = useTouchPresentation().isTouch;
|
|
201
|
+
const trackRef = useRef(null);
|
|
202
|
+
// Every pointer's press is tracked. A drag from the selected segment
|
|
203
|
+
// carries the lens, and the lift commits the segment nearest the pointer.
|
|
204
|
+
// A lift outside the control commits nothing.
|
|
205
|
+
const {
|
|
206
|
+
selection,
|
|
207
|
+
attachTrack
|
|
208
|
+
} = useSegmentedSelectionMotion(trackRef, value, isTouchPresentation, !isDisabled);
|
|
110
209
|
|
|
111
210
|
// Disabled-reason tooltip. Applies to the whole-group disabled state. The
|
|
112
211
|
// tooltip listeners attach to the radiogroup container, which keeps pointer
|
|
@@ -145,13 +244,14 @@ export function SegmentedControl({
|
|
|
145
244
|
isEnabled: !isDisabled
|
|
146
245
|
});
|
|
147
246
|
const handleContainerKeyDown = useCallback(e => {
|
|
247
|
+
selection.keyPressed();
|
|
148
248
|
onKeyDownProp?.(e);
|
|
149
249
|
if (e.defaultPrevented) {
|
|
150
250
|
return;
|
|
151
251
|
}
|
|
152
252
|
hint.onKeyDown(e);
|
|
153
253
|
handleKeyDown(e);
|
|
154
|
-
}, [onKeyDownProp, hint, handleKeyDown]);
|
|
254
|
+
}, [selection, onKeyDownProp, hint, handleKeyDown]);
|
|
155
255
|
|
|
156
256
|
// Selection-follows-focus (APG radiogroup): useListFocus only *moves* focus,
|
|
157
257
|
// so whenever it lands focus on a new radio (arrow/Home/End, or a click) we
|
|
@@ -179,6 +279,12 @@ export function SegmentedControl({
|
|
|
179
279
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
180
280
|
return;
|
|
181
281
|
}
|
|
282
|
+
// A mouse or pen press moves focus at pointerdown. A finger moves it
|
|
283
|
+
// after the lift, before the tap's click. The press commits through
|
|
284
|
+
// that click, so this focus move selects nothing.
|
|
285
|
+
if (selection.isPressing()) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
182
288
|
const focused = e.target?.closest('[role="radio"][data-value]');
|
|
183
289
|
if (!focused || focused.getAttribute('aria-disabled') === 'true') {
|
|
184
290
|
return;
|
|
@@ -187,19 +293,20 @@ export function SegmentedControl({
|
|
|
187
293
|
if (nextValue != null && nextValue !== value) {
|
|
188
294
|
onChange(nextValue);
|
|
189
295
|
}
|
|
190
|
-
}, [onFocusProp, hint, handleFocus, isDisabled, onChange, value]);
|
|
296
|
+
}, [onFocusProp, hint, handleFocus, isDisabled, onChange, selection, value]);
|
|
191
297
|
const contextValue = useMemo(() => ({
|
|
192
298
|
value,
|
|
193
299
|
onChange,
|
|
194
300
|
size,
|
|
195
301
|
layout,
|
|
196
302
|
isDisabled,
|
|
197
|
-
disabledReasonID: showsDisabledMessage ? disabledMessageTooltip.describedBy : undefined
|
|
198
|
-
|
|
303
|
+
disabledReasonID: showsDisabledMessage ? disabledMessageTooltip.describedBy : undefined,
|
|
304
|
+
isTouchPresentation
|
|
305
|
+
}), [value, onChange, size, layout, isDisabled, showsDisabledMessage, disabledMessageTooltip.describedBy, isTouchPresentation]);
|
|
199
306
|
return /*#__PURE__*/_jsxs(SegmentedControlContext, {
|
|
200
307
|
value: contextValue,
|
|
201
308
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
202
|
-
ref: useMergedRefs(ref, listRef, disabledMessageTooltip.ref),
|
|
309
|
+
ref: useMergedRefs(ref, listRef, trackRef, attachTrack, disabledMessageTooltip.ref),
|
|
203
310
|
...rest,
|
|
204
311
|
role: "radiogroup",
|
|
205
312
|
"aria-label": label,
|
|
@@ -212,7 +319,7 @@ export function SegmentedControl({
|
|
|
212
319
|
onBlur: composeEventHandlers(onBlurProp, hint.onBlur),
|
|
213
320
|
...mergeProps(themeProps('segmented-control', {
|
|
214
321
|
size
|
|
215
|
-
}), stylex.props(styles.container, sizeStyles[size], layout === 'fill' && styles.fill, isDisabled && styles.disabled, xstyle), className, style),
|
|
322
|
+
}), stylex.props(styles.container, sizeStyles[size], layout === 'fill' && styles.fill, (isTouchPresentation || !isDisabled) && styles.lens, isDisabled && styles.disabled, xstyle), className, style),
|
|
216
323
|
children: [children, hint.hintElement]
|
|
217
324
|
}), showsDisabledMessage && disabledMessageTooltip.renderTooltip(disabledMessage)]
|
|
218
325
|
});
|
|
@@ -12,6 +12,12 @@ export interface SegmentedControlContextValue {
|
|
|
12
12
|
* described by the reason (spec:AST-085 FR5).
|
|
13
13
|
*/
|
|
14
14
|
disabledReasonID?: string;
|
|
15
|
+
/**
|
|
16
|
+
* True in the touch presentation (under a finger, `useTouchPresentation`):
|
|
17
|
+
* the control animates selection changes itself (the surface slides), so
|
|
18
|
+
* segments drop their CSS transitions.
|
|
19
|
+
*/
|
|
20
|
+
isTouchPresentation?: boolean;
|
|
15
21
|
}
|
|
16
22
|
export declare const SegmentedControlContext: import("react").Context<SegmentedControlContextValue | null>;
|
|
17
23
|
export declare function useSegmentedControlContext(): SegmentedControlContextValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControlContext.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControlContext.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,oBAAoB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,UAAU,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"SegmentedControlContext.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControlContext.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,oBAAoB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,UAAU,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,eAAO,MAAM,uBAAuB,8DACsB,CAAC;AAG3D,wBAAgB,0BAA0B,IAAI,4BAA4B,CASzE"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @position Child item; renders as a radio button within the segmented control
|
|
6
6
|
*
|
|
7
7
|
* SYNC: When modified, update:
|
|
8
|
+
* - /packages/core/src/SegmentedControl/useSegmentedSelectionMotion.ts (the title marker)
|
|
8
9
|
* - /packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
|
|
9
10
|
* - /packages/core/src/SegmentedControl/index.ts
|
|
10
11
|
* - /packages/core/src/SegmentedControl/SegmentedControl.test.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControlItem.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControlItem.tsx"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"SegmentedControlItem.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControlItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAkB5C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAO5C,MAAM,WAAW,yBAA0B,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IAC7E,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACnC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAsHD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,GAAG,EACH,KAAK,EACL,KAAK,EACL,aAAqB,EACrB,IAAI,EACJ,UAAkB,EAClB,OAAO,EAAE,WAAW,EACpB,MAAM,EACN,kBAAkB,EAAE,mBAAmB,EACvC,GAAG,IAAI,EACR,EAAE,yBAAyB,qBA8E3B;yBAzFe,oBAAoB"}
|