@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectableOptionEntries.d.ts","sourceRoot":"","sources":["../../src/Selector/selectableOptionEntries.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAGpE,6DAA6D;AAC7D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAAC;IAC7C,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,kBAAkB,EAAE,GAC5B,qBAAqB,EAAE,CAYzB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file selectableOptionEntries.ts
|
|
5
|
+
* @input Selector options, with sections and dividers
|
|
6
|
+
* @output `getSelectableOptionEntries`: each selectable item with the option
|
|
7
|
+
* it was given as
|
|
8
|
+
* @position Internal; the one walk behind utils.ts's `getSelectableOptions`
|
|
9
|
+
* and Selector's rows
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { isOptionData, isSection, normalizeOption } from "./optionShape.js";
|
|
13
|
+
|
|
14
|
+
/** A selectable option as given, and its normalized data. */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Every selectable option (sections flattened, dividers skipped), each with
|
|
18
|
+
* the option it was given as.
|
|
19
|
+
*/
|
|
20
|
+
export function getSelectableOptionEntries(options) {
|
|
21
|
+
const result = [];
|
|
22
|
+
for (const option of options) {
|
|
23
|
+
if (isOptionData(option)) {
|
|
24
|
+
result.push({
|
|
25
|
+
source: option,
|
|
26
|
+
item: normalizeOption(option)
|
|
27
|
+
});
|
|
28
|
+
} else if (isSection(option)) {
|
|
29
|
+
for (const opt of option.options) {
|
|
30
|
+
result.push({
|
|
31
|
+
source: opt,
|
|
32
|
+
item: normalizeOption(opt)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
package/dist/Selector/utils.d.ts
CHANGED
|
@@ -3,23 +3,8 @@
|
|
|
3
3
|
* @output Utility functions for Selector
|
|
4
4
|
* @position Utilities; used by Selector.tsx
|
|
5
5
|
*/
|
|
6
|
-
import type { SelectorOptionType, SelectorOptionData
|
|
7
|
-
|
|
8
|
-
* Type guard: check if option is a selectable option (string or OptionData)
|
|
9
|
-
*/
|
|
10
|
-
export declare function isOptionData(option: SelectorOptionType): option is SelectorOptionData | string;
|
|
11
|
-
/**
|
|
12
|
-
* Type guard: check if option is a divider
|
|
13
|
-
*/
|
|
14
|
-
export declare function isDivider(option: SelectorOptionType): option is SelectorDivider;
|
|
15
|
-
/**
|
|
16
|
-
* Type guard: check if option is a section
|
|
17
|
-
*/
|
|
18
|
-
export declare function isSection(option: SelectorOptionType): option is SelectorSection;
|
|
19
|
-
/**
|
|
20
|
-
* Normalize string or option to consistent shape
|
|
21
|
-
*/
|
|
22
|
-
export declare function normalizeOption(option: string | SelectorOptionData): SelectorOptionData;
|
|
6
|
+
import type { SelectorOptionType, SelectorOptionData } from './types.js';
|
|
7
|
+
export { isOptionData, isDivider, isSection, normalizeOption, } from './optionShape.js';
|
|
23
8
|
/**
|
|
24
9
|
* Get all selectable options (flattening sections)
|
|
25
10
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Selector/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Selector/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAGpE,OAAO,EACL,YAAY,EACZ,SAAS,EACT,SAAS,EACT,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,kBAAkB,EAAE,GAC5B,kBAAkB,EAAE,CAEtB"}
|
package/dist/Selector/utils.js
CHANGED
|
@@ -6,60 +6,12 @@
|
|
|
6
6
|
* @position Utilities; used by Selector.tsx
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export function isOptionData(option) {
|
|
13
|
-
if (typeof option === 'string') {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return !('type' in option);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Type guard: check if option is a divider
|
|
21
|
-
*/
|
|
22
|
-
export function isDivider(option) {
|
|
23
|
-
return typeof option === 'object' && 'type' in option && option.type === 'divider';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Type guard: check if option is a section
|
|
28
|
-
*/
|
|
29
|
-
export function isSection(option) {
|
|
30
|
-
return typeof option === 'object' && 'type' in option && option.type === 'section';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Normalize string or option to consistent shape
|
|
35
|
-
*/
|
|
36
|
-
export function normalizeOption(option) {
|
|
37
|
-
if (typeof option === 'string') {
|
|
38
|
-
return {
|
|
39
|
-
value: option,
|
|
40
|
-
label: option
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
...option,
|
|
45
|
-
label: option.label ?? option.value
|
|
46
|
-
};
|
|
47
|
-
}
|
|
9
|
+
import { getSelectableOptionEntries } from "./selectableOptionEntries.js";
|
|
10
|
+
export { isOptionData, isDivider, isSection, normalizeOption } from "./optionShape.js";
|
|
48
11
|
|
|
49
12
|
/**
|
|
50
13
|
* Get all selectable options (flattening sections)
|
|
51
14
|
*/
|
|
52
15
|
export function getSelectableOptions(options) {
|
|
53
|
-
|
|
54
|
-
for (const option of options) {
|
|
55
|
-
if (isOptionData(option)) {
|
|
56
|
-
result.push(normalizeOption(option));
|
|
57
|
-
} else if (isSection(option)) {
|
|
58
|
-
for (const opt of option.options) {
|
|
59
|
-
result.push(normalizeOption(opt));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Skip dividers
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
16
|
+
return getSelectableOptionEntries(options).map(entry => entry.item);
|
|
65
17
|
}
|
package/dist/Switch/Switch.d.ts
CHANGED
|
@@ -135,7 +135,7 @@ export interface SwitchProps extends Omit<BaseProps, 'onChange'> {
|
|
|
135
135
|
status?: InputStatus;
|
|
136
136
|
/**
|
|
137
137
|
* Size variant controlling track and thumb dimensions.
|
|
138
|
-
* - 'sm':
|
|
138
|
+
* - 'sm': 32x20px (matches sm checkbox/radio vertical rhythm)
|
|
139
139
|
* - 'md': 40x24px (default, matches md checkbox/radio vertical rhythm)
|
|
140
140
|
* @default 'md'
|
|
141
141
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../src/Switch/Switch.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../src/Switch/Switch.tsx"],"names":[],"mappings":"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"}
|
package/dist/Switch/Switch.js
CHANGED
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
* - /apps/storybook/stories/Switch.stories.tsx (storybook stories)
|
|
16
16
|
* - /packages/cli/assets/templates/blocks/components/Switch/ (showcase blocks)
|
|
17
17
|
*/
|
|
18
|
-
import { useId, useOptimistic, useTransition, useEffect, useRef } from 'react';
|
|
18
|
+
import { Fragment, useId, useMemo, useOptimistic, useTransition, useEffect, useRef } from 'react';
|
|
19
19
|
import * as stylex from '@stylexjs/stylex';
|
|
20
20
|
import "../theme/tokens.stylex.js";
|
|
21
|
-
import { colorVars, spacingVars, radiusVars, durationVars, easeVars, typographyVars, typeScaleVars, focusVars } from "../theme/tokens.stylex.js";
|
|
21
|
+
import { colorVars, spacingVars, radiusVars, durationVars, easeVars, typographyVars, typeScaleVars, focusVars, shadowVars } from "../theme/tokens.stylex.js";
|
|
22
22
|
import { FieldLabel } from "../Field/FieldLabel.js";
|
|
23
23
|
import { FieldStatus } from "../FieldStatus/FieldStatus.js";
|
|
24
24
|
import { Spinner } from "../Spinner/index.js";
|
|
@@ -26,7 +26,6 @@ import { useTooltip } from "../Tooltip/index.js";
|
|
|
26
26
|
import { mergeProps, rtlStyles } from "../utils/index.js";
|
|
27
27
|
import "./switch.markers.stylex.js";
|
|
28
28
|
import { switchFocusInput, switchScope } from "./switch.markers.stylex.js";
|
|
29
|
-
import { interactionOverlayStyles } from "../utils/interactionOverlay.stylex.js";
|
|
30
29
|
import { themeProps } from "../utils/themeProps.js";
|
|
31
30
|
import { useAnnounce } from "../hooks/useAnnounce.js";
|
|
32
31
|
import { useResolvedRequired } from "../hooks/useResolvedRequired.js";
|
|
@@ -34,21 +33,54 @@ import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
|
34
33
|
import { usePressFeedback } from "../hooks/usePressFeedback.js";
|
|
35
34
|
import { registerEnglishFallback, useComponentTranslator } from "../i18n/useComponentTranslator.js";
|
|
36
35
|
import english from "../i18n/generated-english/Switch/Switch.generated.js";
|
|
37
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
38
36
|
registerEnglishFallback(english);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
import "../utils/interactionOverlay.stylex.js";
|
|
38
|
+
import { interactionOverlayStyles, pressConsts, pressVars } from "../utils/interactionOverlay.stylex.js";
|
|
39
|
+
import { pressHoldsDragProps } from "../privateAttributes/pressHoldsDrag.stylex.js";
|
|
40
|
+
import { useSwitchTouch } from "./useSwitchTouch.js";
|
|
41
|
+
import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
|
|
42
|
+
import { watchHitArea, writeHitInsets } from "../utils/hitArea.js";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The track box of each size, px (width × height), for the touch
|
|
46
|
+
* presentation's thumb geometry.
|
|
47
|
+
* SYNC: wrapperSizeStyles and trackSizeStyles below.
|
|
48
|
+
*/
|
|
49
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
50
|
+
const TRACK_SIZE = {
|
|
51
|
+
sm: [32, 20],
|
|
52
|
+
md: [40, 24]
|
|
50
53
|
};
|
|
51
|
-
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A finger: utils/touchPresentation.ts's TOUCH_QUERY. The touch presentation
|
|
57
|
+
* is one model on every touch device: the lift, tracking, flip rule and
|
|
58
|
+
* springs sit under it alone.
|
|
59
|
+
* SYNC: utils/touchPresentation.ts TOUCH_QUERY.
|
|
60
|
+
*/
|
|
61
|
+
const TOUCH = '@media (pointer: coarse)';
|
|
62
|
+
|
|
63
|
+
/** The press controller's two states on the row it writes to. */
|
|
64
|
+
const PRESS_ON = '[data-astryx-press="on"]';
|
|
65
|
+
const PRESS_FADING = '[data-astryx-press="fading"]';
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The shared press release, for the press layers the switch fades on the
|
|
69
|
+
* compositor. The clock scales by the theme's tempo, and the curve is the
|
|
70
|
+
* controller's own. Switch.test.tsx compares the two.
|
|
71
|
+
* SYNC: utils/interactionOverlay.stylex.ts PRESS_RELEASE_DURATION,
|
|
72
|
+
* PRESS_RELEASE_DURATION_REDUCED and RELEASE_EASE.
|
|
73
|
+
*/
|
|
74
|
+
const PRESS_RELEASE_DURATION = `calc(${pressConsts.releaseMs}ms * min(var(--_astryx-motion-tempo, 1), 1.5))`;
|
|
75
|
+
const PRESS_RELEASE_DURATION_REDUCED = `min(${pressConsts.releaseMs}ms, calc(${pressConsts.releaseMs}ms * var(--_astryx-motion-tempo, 1)))`;
|
|
76
|
+
const PRESS_RELEASE_EASE = 'cubic-bezier(0, 0, 0.2, 1)';
|
|
77
|
+
|
|
78
|
+
// The measured hit insets (utils/hitArea), 0 until measured.
|
|
79
|
+
const HIT_TOP = 'var(--astryx-hit-inset-top, 0px)';
|
|
80
|
+
const HIT_RIGHT = 'var(--astryx-hit-inset-right, 0px)';
|
|
81
|
+
const HIT_BOTTOM = 'var(--astryx-hit-inset-bottom, 0px)';
|
|
82
|
+
const HIT_LEFT = 'var(--astryx-hit-inset-left, 0px)';
|
|
83
|
+
const wrapperSizeStyles = {
|
|
52
84
|
sm: {
|
|
53
85
|
kzqmXN: "x1td3qas",
|
|
54
86
|
kZKoxP: "x1qx5ct2",
|
|
@@ -60,6 +92,10 @@ const inputSizeStyles = {
|
|
|
60
92
|
$$css: true
|
|
61
93
|
}
|
|
62
94
|
};
|
|
95
|
+
|
|
96
|
+
// Every touch value sits in the same property as the mouse value, as a
|
|
97
|
+
// nested condition, never in a later style. A later style that names a
|
|
98
|
+
// property replaces all of it, mouse value included.
|
|
63
99
|
const trackSizeStyles = {
|
|
64
100
|
sm: {
|
|
65
101
|
kzqmXN: "x1td3qas",
|
|
@@ -74,17 +110,24 @@ const trackSizeStyles = {
|
|
|
74
110
|
$$css: true
|
|
75
111
|
}
|
|
76
112
|
};
|
|
113
|
+
|
|
114
|
+
// The thumb is one circle under any pointer, at each state's size. Under a
|
|
115
|
+
// finger it rests by insets instead of a transform, centered in the track's
|
|
116
|
+
// height at each end. So the compositor moves and lifts it with translate and
|
|
117
|
+
// scale alone; useSwitchTouch measures the box it renders.
|
|
77
118
|
const thumbOffSizeStyles = {
|
|
78
119
|
sm: {
|
|
79
120
|
kzqmXN: "x6jxa94",
|
|
80
121
|
kZKoxP: "x1v9usgg",
|
|
81
|
-
|
|
122
|
+
kLqNvP: "x13kxlb5",
|
|
123
|
+
k3aq6I: "xbryuvx xhyyqqw",
|
|
82
124
|
$$css: true
|
|
83
125
|
},
|
|
84
126
|
md: {
|
|
85
127
|
kzqmXN: "x1kky2od",
|
|
86
128
|
kZKoxP: "xlup9mm",
|
|
87
|
-
|
|
129
|
+
kLqNvP: "xsprn4g",
|
|
130
|
+
k3aq6I: "xbryuvx xhyyqqw",
|
|
88
131
|
$$css: true
|
|
89
132
|
}
|
|
90
133
|
};
|
|
@@ -92,13 +135,17 @@ const thumbOnSizeStyles = {
|
|
|
92
135
|
sm: {
|
|
93
136
|
kzqmXN: "x1kky2od",
|
|
94
137
|
kZKoxP: "xlup9mm",
|
|
95
|
-
|
|
138
|
+
kLqNvP: "xskqmzm",
|
|
139
|
+
kt4wiu: "x1syr3z6",
|
|
140
|
+
k3aq6I: "xv5t66b xi9aj42 x1pxz8w1 xhyyqqw",
|
|
96
141
|
$$css: true
|
|
97
142
|
},
|
|
98
143
|
md: {
|
|
99
144
|
kzqmXN: "xw4jnvo",
|
|
100
145
|
kZKoxP: "x1qx5ct2",
|
|
101
|
-
|
|
146
|
+
kLqNvP: "xskqmzm",
|
|
147
|
+
kt4wiu: "x1syr3z6",
|
|
148
|
+
k3aq6I: "x15481yp x12xz5k6 x1pxz8w1 xhyyqqw",
|
|
102
149
|
$$css: true
|
|
103
150
|
}
|
|
104
151
|
};
|
|
@@ -111,11 +158,22 @@ const thumbOnSizeStyles = {
|
|
|
111
158
|
// hover tint already is: pressing the input, the track or the label all
|
|
112
159
|
// activate the row.
|
|
113
160
|
const pressedImage = `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
161
|
+
|
|
162
|
+
/** The touch press's release on the press layer: opacity 1 → 0. */
|
|
163
|
+
const pressLayerRelease = "x1jn504y-B";
|
|
164
|
+
const PRESS_ALPHA = pressVars['--astryx-press-alpha'];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The shared strength's release, restated so a fine pointer keeps it: the
|
|
168
|
+
* same keyframes, so the same animation.
|
|
169
|
+
*/
|
|
170
|
+
const pressStrengthRelease = "x10jkm1t-B";
|
|
171
|
+
const pressOwnerStyles = {
|
|
172
|
+
pressedAlphaLayered: {
|
|
173
|
+
kKVMdj: "x14e4jsf xxsp3er x6su2wr",
|
|
174
|
+
$$css: true
|
|
175
|
+
}
|
|
176
|
+
};
|
|
119
177
|
const labelWrapperSizeStyles = {
|
|
120
178
|
sm: {
|
|
121
179
|
kAzted: "xisnujt",
|
|
@@ -154,6 +212,10 @@ const styles = {
|
|
|
154
212
|
kHBbk8: "xc8icb0",
|
|
155
213
|
$$css: true
|
|
156
214
|
},
|
|
215
|
+
switchWrapperInteractive: {
|
|
216
|
+
kFalU9: "xge0x1e",
|
|
217
|
+
$$css: true
|
|
218
|
+
},
|
|
157
219
|
input: {
|
|
158
220
|
kVAEAm: "x10l6tqk",
|
|
159
221
|
k87sOh: "xwa60dl",
|
|
@@ -165,8 +227,9 @@ const styles = {
|
|
|
165
227
|
$$css: true
|
|
166
228
|
},
|
|
167
229
|
inputCoarse: {
|
|
168
|
-
|
|
169
|
-
|
|
230
|
+
kzqmXN: "xh8yej3 x1uj43hb",
|
|
231
|
+
kZKoxP: "x5yr21d xgjkl26",
|
|
232
|
+
k3aq6I: "x11lhmoz x1xdvw9q",
|
|
170
233
|
$$css: true
|
|
171
234
|
},
|
|
172
235
|
inputDisabled: {
|
|
@@ -180,15 +243,39 @@ const styles = {
|
|
|
180
243
|
track: {
|
|
181
244
|
k1xSpc: "x78zum5",
|
|
182
245
|
kGNEyG: "x6s0dn4",
|
|
246
|
+
kVAEAm: "xrxqdxo",
|
|
247
|
+
kHBbk8: "xsmms64",
|
|
183
248
|
kaIpWk: "xjspbzw",
|
|
184
249
|
k1ekBW: "x15406qy",
|
|
185
|
-
kIyJzY: "xuedmi6
|
|
250
|
+
kIyJzY: "xuedmi6 xouc37c xzwa1y6 xuh6ohu",
|
|
186
251
|
kAMwcw: "xlr8y92",
|
|
187
252
|
kB7OPa: "x9f619",
|
|
188
253
|
kMzoRj: "xc342km x13rsnn2",
|
|
189
254
|
ksu8eU: "xng3xce xx61lck",
|
|
190
255
|
kVAM5u: "x1w1tqly",
|
|
191
|
-
kKwaWg: "x1xm682w xowtp19
|
|
256
|
+
kKwaWg: "x1xm682w xowtp19",
|
|
257
|
+
kgeoSG: "xpxppvc x15cra4q",
|
|
258
|
+
kEoFBp: "x1hmns74",
|
|
259
|
+
kFcpXp: "xxx281p",
|
|
260
|
+
kxmVGU: "x12maryy",
|
|
261
|
+
kPB484: "xxyica1",
|
|
262
|
+
km8f2m: "xkk1bqk",
|
|
263
|
+
kLkRvE: "x1my3e5g",
|
|
264
|
+
k5QlbN: "x2huugr x1ccaw7f",
|
|
265
|
+
k7EzDT: "xxhzo2e",
|
|
266
|
+
kQZAMR: "xvym4rz xigdn9b",
|
|
267
|
+
kZiNAr: "xgq6fxe",
|
|
268
|
+
k8Tatv: "xq2jpp1",
|
|
269
|
+
k5JduY: "x1s928wv",
|
|
270
|
+
kc3QkE: "x1h1zc6f x1ep27e9",
|
|
271
|
+
kwXMNM: "x1j6awrg",
|
|
272
|
+
kv0HGH: "xarstr8",
|
|
273
|
+
kDVEDD: "x1r0yslu",
|
|
274
|
+
kUfP38: "x1k48kgn",
|
|
275
|
+
kloYau: "x2q1x1w",
|
|
276
|
+
kypkao: "xmf22ne",
|
|
277
|
+
ks3ayO: "x1uc2128",
|
|
278
|
+
kWkaDd: "xqycr0j",
|
|
192
279
|
$$css: true
|
|
193
280
|
},
|
|
194
281
|
trackFocus: {
|
|
@@ -218,10 +305,35 @@ const styles = {
|
|
|
218
305
|
kGNEyG: "x6s0dn4",
|
|
219
306
|
kjj79g: "xl56j7k",
|
|
220
307
|
kaIpWk: "xjspbzw",
|
|
221
|
-
|
|
222
|
-
|
|
308
|
+
kVAEAm: "x8imsj1",
|
|
309
|
+
kYYq5F: "x1s6gw0t",
|
|
310
|
+
kqGvvJ: "xfmjvo4",
|
|
311
|
+
kY2c9j: "x1e8ofxz",
|
|
312
|
+
kfzvcC: "x1bjav06",
|
|
313
|
+
k1ekBW: "xh3q6i0 xiz4dsw",
|
|
314
|
+
kIyJzY: "xuedmi6 xzwa1y6 xuh6ohu",
|
|
223
315
|
kAMwcw: "xlr8y92",
|
|
224
|
-
|
|
316
|
+
kgeoSG: "xpxppvc x15cra4q",
|
|
317
|
+
kEoFBp: "x1hmns74",
|
|
318
|
+
kFcpXp: "xxx281p",
|
|
319
|
+
kPB484: "xxyica1",
|
|
320
|
+
km8f2m: "xkk1bqk",
|
|
321
|
+
kLkRvE: "x1my3e5g",
|
|
322
|
+
k5QlbN: "x2huugr x1ccaw7f",
|
|
323
|
+
k7EzDT: "xxhzo2e",
|
|
324
|
+
kQZAMR: "xvym4rz xigdn9b",
|
|
325
|
+
kZiNAr: "xgq6fxe",
|
|
326
|
+
k8Tatv: "xq2jpp1",
|
|
327
|
+
k5JduY: "x1s928wv",
|
|
328
|
+
kc3QkE: "x1h1zc6f x1ep27e9",
|
|
329
|
+
kwXMNM: "x1j6awrg",
|
|
330
|
+
kv0HGH: "xarstr8",
|
|
331
|
+
kUfP38: "x1k48kgn",
|
|
332
|
+
kloYau: "x2q1x1w",
|
|
333
|
+
kypkao: "xmf22ne",
|
|
334
|
+
kbMawA: "xoca22b",
|
|
335
|
+
kWkaDd: "xqycr0j",
|
|
336
|
+
kKwaWg: "x1xm682w xowtp19",
|
|
225
337
|
$$css: true
|
|
226
338
|
},
|
|
227
339
|
thumbOff: {
|
|
@@ -365,10 +477,49 @@ export function Switch({
|
|
|
365
477
|
describedByParts.push(disabledMessageTooltip.describedBy);
|
|
366
478
|
}
|
|
367
479
|
const ariaDescribedBy = describedByParts.length > 0 ? describedByParts.join(' ') : undefined;
|
|
480
|
+
|
|
481
|
+
// The touch presentation (coarse pointer): its parts are always rendered;
|
|
482
|
+
// CSS shows them under a finger and the hook animates and listens there.
|
|
483
|
+
const surfaceRef = useRef(null);
|
|
484
|
+
const inputRef = useRef(null);
|
|
485
|
+
const thumbRef = useRef(null);
|
|
486
|
+
const trackRef = useRef(null);
|
|
487
|
+
const touchParts = useMemo(() => ({
|
|
488
|
+
surface: surfaceRef,
|
|
489
|
+
input: inputRef,
|
|
490
|
+
thumb: thumbRef,
|
|
491
|
+
track: trackRef
|
|
492
|
+
}), []);
|
|
493
|
+
// The track in a state: its theme target and fill. The other state's, for
|
|
494
|
+
// the fade layer's colour (switchFill.ts).
|
|
495
|
+
const trackPropsFor = on => mergeProps(themeProps('switch', {
|
|
496
|
+
checked: on ? 'checked' : null,
|
|
497
|
+
disabled: isDisabled ? 'disabled' : null,
|
|
498
|
+
size
|
|
499
|
+
}), stylex.props(styles.track, trackSizeStyles[size], on ? styles.trackOn : styles.trackOff, styles.trackFocus, isDisabled && styles.trackDisabled, isDisabled && !on && styles.trackDisabledOff));
|
|
500
|
+
// Syncs the hit area's insets with the layout around the switch, through
|
|
501
|
+
// utils/hitArea's observers. Under a coarse pointer they grow toward 44 px,
|
|
502
|
+
// stopping at half the gap to each neighbouring target. A disabled switch
|
|
503
|
+
// watches nothing.
|
|
504
|
+
useIsomorphicLayoutEffect(() => {
|
|
505
|
+
const surface = surfaceRef.current;
|
|
506
|
+
if (surface == null || isDisabled) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
return watchHitArea(surface, insets => writeHitInsets(surface, insets));
|
|
510
|
+
}, [isDisabled]);
|
|
511
|
+
useSwitchTouch(touchParts, {
|
|
512
|
+
isOn,
|
|
513
|
+
isInteractive: !isDisabled && !isBusy,
|
|
514
|
+
isDisabled,
|
|
515
|
+
trackSize: TRACK_SIZE[size],
|
|
516
|
+
otherTrackProps: trackPropsFor(!isOn)
|
|
517
|
+
});
|
|
368
518
|
const switchElement = /*#__PURE__*/_jsxs("div", {
|
|
369
|
-
|
|
519
|
+
ref: surfaceRef,
|
|
520
|
+
...stylex.props(styles.switchWrapper, wrapperSizeStyles[size], !isDisabled && !isBusy && styles.switchWrapperInteractive),
|
|
370
521
|
children: [/*#__PURE__*/_jsx("input", {
|
|
371
|
-
ref: useMergedRefs(ref, disabledMessageTooltip.positionRef),
|
|
522
|
+
ref: useMergedRefs(ref, disabledMessageTooltip.positionRef, inputRef),
|
|
372
523
|
id: id,
|
|
373
524
|
type: "checkbox",
|
|
374
525
|
role: "switch"
|
|
@@ -409,15 +560,13 @@ export function Switch({
|
|
|
409
560
|
,
|
|
410
561
|
"aria-invalid": status?.type === 'error' ? true : isRequired ? false : undefined,
|
|
411
562
|
"aria-busy": isBusy || undefined,
|
|
412
|
-
...stylex.props(styles.input, rtlStyles.centerInline('-50%'), styles.inputCoarse,
|
|
563
|
+
...stylex.props(styles.input, rtlStyles.centerInline('-50%'), styles.inputCoarse, isDisabled && styles.inputDisabled, isBusy && styles.inputBusy, switchFocusInput)
|
|
413
564
|
}), /*#__PURE__*/_jsx("div", {
|
|
565
|
+
ref: trackRef,
|
|
414
566
|
"aria-hidden": "true",
|
|
415
|
-
...
|
|
416
|
-
checked: isOn ? 'checked' : null,
|
|
417
|
-
disabled: isDisabled ? 'disabled' : null,
|
|
418
|
-
size
|
|
419
|
-
}), stylex.props(styles.track, trackSizeStyles[size], isOn ? styles.trackOn : styles.trackOff, styles.trackFocus, isDisabled && styles.trackDisabled, isDisabled && !isOn && styles.trackDisabledOff)),
|
|
567
|
+
...trackPropsFor(isOn),
|
|
420
568
|
children: /*#__PURE__*/_jsx("div", {
|
|
569
|
+
ref: thumbRef,
|
|
421
570
|
...mergeProps(themeProps('switch-thumb', {
|
|
422
571
|
checked: isOn ? 'checked' : null,
|
|
423
572
|
size
|
|
@@ -470,15 +619,20 @@ export function Switch({
|
|
|
470
619
|
disabledMessageTooltip.interactionRef(el);
|
|
471
620
|
},
|
|
472
621
|
...(isDisabled ? undefined : pressable),
|
|
622
|
+
...pressHoldsDragProps(!isDisabled),
|
|
473
623
|
...stylex.props(styles.container, isLabelHidden && styles.containerLabelHidden, labelSpacing === 'spread' && styles.containerSpread, !isDisabled && switchScope,
|
|
474
624
|
// The touch press's strength and release live on the row the
|
|
475
625
|
// controller writes to; the track and thumb inherit and paint it.
|
|
476
|
-
!isDisabled && interactionOverlayStyles.pressedAlpha),
|
|
477
|
-
children: [' ', labelPosition === 'start' ? /*#__PURE__*/
|
|
478
|
-
children:
|
|
479
|
-
})
|
|
480
|
-
children:
|
|
481
|
-
})]
|
|
626
|
+
!isDisabled && interactionOverlayStyles.pressedAlpha, !isDisabled && pressOwnerStyles.pressedAlphaLayered),
|
|
627
|
+
children: [' ', labelPosition === 'start' ? [/*#__PURE__*/_jsx(Fragment, {
|
|
628
|
+
children: labelElement
|
|
629
|
+
}, "label"), /*#__PURE__*/_jsx(Fragment, {
|
|
630
|
+
children: switchElement
|
|
631
|
+
}, "switch")] : [/*#__PURE__*/_jsx(Fragment, {
|
|
632
|
+
children: switchElement
|
|
633
|
+
}, "switch"), /*#__PURE__*/_jsx(Fragment, {
|
|
634
|
+
children: labelElement
|
|
635
|
+
}, "label")]]
|
|
482
636
|
}), status?.message && /*#__PURE__*/_jsx(FieldStatus, {
|
|
483
637
|
type: status.type,
|
|
484
638
|
message: status.message,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file switchFill.ts
|
|
3
|
+
* @input Switch's track element and the props its other state renders with
|
|
4
|
+
* @output Exports TrackState, sameTrackState, trackStateOf, readInState and
|
|
5
|
+
* readFillOf: an element read in its other state, in place
|
|
6
|
+
* @position Shared by Switch.tsx and useSwitchTouch.ts for the colour fade
|
|
7
|
+
* under a finger
|
|
8
|
+
*
|
|
9
|
+
* The colour fade needs the track's fill in its other state, as the theme
|
|
10
|
+
* paints it. readFillOf swaps the track's class and attributes, reads the
|
|
11
|
+
* colour and swaps back in the same task, so nothing paints in between.
|
|
12
|
+
*
|
|
13
|
+
* SYNC: When modified, update Switch.tsx and useSwitchTouch.ts.
|
|
14
|
+
*/
|
|
15
|
+
/** A track state: its class name and its data attributes. */
|
|
16
|
+
export interface TrackState {
|
|
17
|
+
readonly className: string;
|
|
18
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
19
|
+
}
|
|
20
|
+
/** Whether two track states render alike: the same class and attributes. */
|
|
21
|
+
export declare function sameTrackState(a: TrackState | null, b: TrackState | null): boolean;
|
|
22
|
+
/** The track state of rendered props (`className` and `data-*` props). */
|
|
23
|
+
export declare function trackStateOf(props: object): TrackState;
|
|
24
|
+
/**
|
|
25
|
+
* Reads `element` as it renders in `state` (its class and data attributes),
|
|
26
|
+
* swapping them in and back in the same task, so nothing paints between.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readInState<T>(element: HTMLElement, state: TrackState, read: (element: HTMLElement) => T): T;
|
|
29
|
+
/** The track's computed fill in `state`, read without a paint. */
|
|
30
|
+
export declare function readFillOf(track: HTMLElement, state: TrackState): string;
|
|
31
|
+
//# sourceMappingURL=switchFill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchFill.d.ts","sourceRoot":"","sources":["../../src/Switch/switchFill.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAC5B,CAAC,EAAE,UAAU,GAAG,IAAI,EACpB,CAAC,EAAE,UAAU,GAAG,IAAI,GACnB,OAAO,CAYT;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAYtD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,GAChC,CAAC,CAgCH;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAMxE"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file switchFill.ts
|
|
5
|
+
* @input Switch's track element and the props its other state renders with
|
|
6
|
+
* @output Exports TrackState, sameTrackState, trackStateOf, readInState and
|
|
7
|
+
* readFillOf: an element read in its other state, in place
|
|
8
|
+
* @position Shared by Switch.tsx and useSwitchTouch.ts for the colour fade
|
|
9
|
+
* under a finger
|
|
10
|
+
*
|
|
11
|
+
* The colour fade needs the track's fill in its other state, as the theme
|
|
12
|
+
* paints it. readFillOf swaps the track's class and attributes, reads the
|
|
13
|
+
* colour and swaps back in the same task, so nothing paints in between.
|
|
14
|
+
*
|
|
15
|
+
* SYNC: When modified, update Switch.tsx and useSwitchTouch.ts.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** A track state: its class name and its data attributes. */
|
|
19
|
+
|
|
20
|
+
/** Whether two track states render alike: the same class and attributes. */
|
|
21
|
+
export function sameTrackState(a, b) {
|
|
22
|
+
if (a === b) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (a == null || b == null || a.className !== b.className) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const names = Object.keys(a.attributes);
|
|
29
|
+
return names.length === Object.keys(b.attributes).length && names.every(name => a.attributes[name] === b.attributes[name]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The track state of rendered props (`className` and `data-*` props). */
|
|
33
|
+
export function trackStateOf(props) {
|
|
34
|
+
const attributes = {};
|
|
35
|
+
let className = '';
|
|
36
|
+
for (const [name, value] of Object.entries(props)) {
|
|
37
|
+
if (name === 'className' && typeof value === 'string') {
|
|
38
|
+
className = value;
|
|
39
|
+
} else if (name.startsWith('data-') && value != null) {
|
|
40
|
+
// As React writes a data attribute: every value but null or undefined.
|
|
41
|
+
attributes[name] = String(value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
className,
|
|
46
|
+
attributes
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Reads `element` as it renders in `state` (its class and data attributes),
|
|
52
|
+
* swapping them in and back in the same task, so nothing paints between.
|
|
53
|
+
*/
|
|
54
|
+
export function readInState(element, state, read) {
|
|
55
|
+
const names = new Set(Object.keys(state.attributes));
|
|
56
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
57
|
+
if (attribute.name.startsWith('data-')) {
|
|
58
|
+
names.add(attribute.name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const savedClass = element.className;
|
|
62
|
+
const saved = new Map();
|
|
63
|
+
for (const name of names) {
|
|
64
|
+
saved.set(name, element.getAttribute(name));
|
|
65
|
+
}
|
|
66
|
+
const apply = (className, valueOf) => {
|
|
67
|
+
element.className = className;
|
|
68
|
+
for (const name of names) {
|
|
69
|
+
const value = valueOf(name);
|
|
70
|
+
if (value == null) {
|
|
71
|
+
element.removeAttribute(name);
|
|
72
|
+
} else {
|
|
73
|
+
element.setAttribute(name, value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
apply(state.className, name => state.attributes[name] ?? null);
|
|
78
|
+
try {
|
|
79
|
+
return read(element);
|
|
80
|
+
} finally {
|
|
81
|
+
apply(savedClass, name => saved.get(name) ?? null);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The track's computed fill in `state`, read without a paint. */
|
|
86
|
+
export function readFillOf(track, state) {
|
|
87
|
+
return readInState(track, state, element => getComputedStyle(element).backgroundColor);
|
|
88
|
+
}
|