@slurp-ui/react 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/AccentScope/AccentScope.d.ts +15 -0
- package/dist/AccentScope/AccentScope.js +31 -0
- package/dist/AccentScope/AccentScope.js.map +1 -0
- package/dist/AccentScope/index.d.ts +3 -0
- package/dist/AccentScope/index.js +2 -0
- package/dist/Avatar/Avatar.d.ts +17 -0
- package/dist/Avatar/Avatar.js +42 -0
- package/dist/Avatar/Avatar.js.map +1 -0
- package/dist/Avatar/index.d.ts +3 -0
- package/dist/Avatar/index.js +2 -0
- package/dist/Bento/Bento.d.ts +14 -0
- package/dist/Bento/Bento.js +42 -0
- package/dist/Bento/Bento.js.map +1 -0
- package/dist/Bento/index.d.ts +3 -0
- package/dist/Bento/index.js +2 -0
- package/dist/Bloom/Bloom.d.ts +42 -0
- package/dist/Bloom/Bloom.js +183 -0
- package/dist/Bloom/Bloom.js.map +1 -0
- package/dist/Bloom/index.d.ts +3 -0
- package/dist/Bloom/index.js +2 -0
- package/dist/Bubble/Bubble.d.ts +20 -0
- package/dist/Bubble/Bubble.js +30 -0
- package/dist/Bubble/Bubble.js.map +1 -0
- package/dist/Bubble/index.d.ts +3 -0
- package/dist/Bubble/index.js +2 -0
- package/dist/Button/Button.d.ts +26 -0
- package/dist/Button/Button.js +50 -0
- package/dist/Button/Button.js.map +1 -0
- package/dist/Button/index.d.ts +3 -0
- package/dist/Button/index.js +2 -0
- package/dist/Card/Card.d.ts +26 -0
- package/dist/Card/Card.js +70 -0
- package/dist/Card/Card.js.map +1 -0
- package/dist/Card/index.d.ts +3 -0
- package/dist/Card/index.js +2 -0
- package/dist/Cell/Cell.d.ts +7 -0
- package/dist/Cell/Cell.js +20 -0
- package/dist/Cell/Cell.js.map +1 -0
- package/dist/Cell/index.d.ts +3 -0
- package/dist/Cell/index.js +2 -0
- package/dist/Checkbox/Checkbox.d.ts +27 -0
- package/dist/Checkbox/Checkbox.js +82 -0
- package/dist/Checkbox/Checkbox.js.map +1 -0
- package/dist/Checkbox/index.d.ts +3 -0
- package/dist/Checkbox/index.js +2 -0
- package/dist/Chip/Chip.d.ts +15 -0
- package/dist/Chip/Chip.js +40 -0
- package/dist/Chip/Chip.js.map +1 -0
- package/dist/Chip/index.d.ts +3 -0
- package/dist/Chip/index.js +2 -0
- package/dist/Choice/Choice.d.ts +37 -0
- package/dist/Choice/Choice.js +134 -0
- package/dist/Choice/Choice.js.map +1 -0
- package/dist/Choice/index.d.ts +3 -0
- package/dist/Choice/index.js +2 -0
- package/dist/Count/Count.d.ts +19 -0
- package/dist/Count/Count.js +30 -0
- package/dist/Count/Count.js.map +1 -0
- package/dist/Count/index.d.ts +3 -0
- package/dist/Count/index.js +2 -0
- package/dist/Dialog/Dialog.d.ts +26 -0
- package/dist/Dialog/Dialog.js +152 -0
- package/dist/Dialog/Dialog.js.map +1 -0
- package/dist/Dialog/index.d.ts +3 -0
- package/dist/Dialog/index.js +2 -0
- package/dist/Dock/Dock.d.ts +124 -0
- package/dist/Dock/Dock.js +359 -0
- package/dist/Dock/Dock.js.map +1 -0
- package/dist/Dock/index.d.ts +3 -0
- package/dist/Dock/index.js +2 -0
- package/dist/Empty/Empty.d.ts +17 -0
- package/dist/Empty/Empty.js +40 -0
- package/dist/Empty/Empty.js.map +1 -0
- package/dist/Empty/index.d.ts +3 -0
- package/dist/Empty/index.js +2 -0
- package/dist/Fact/Fact.d.ts +11 -0
- package/dist/Fact/Fact.js +27 -0
- package/dist/Fact/Fact.js.map +1 -0
- package/dist/Fact/index.d.ts +3 -0
- package/dist/Fact/index.js +2 -0
- package/dist/Field/Field.d.ts +44 -0
- package/dist/Field/Field.js +105 -0
- package/dist/Field/Field.js.map +1 -0
- package/dist/Field/index.d.ts +3 -0
- package/dist/Field/index.js +2 -0
- package/dist/Filters/Filters.d.ts +37 -0
- package/dist/Filters/Filters.js +64 -0
- package/dist/Filters/Filters.js.map +1 -0
- package/dist/Filters/index.d.ts +3 -0
- package/dist/Filters/index.js +2 -0
- package/dist/Flow/Flow.d.ts +17 -0
- package/dist/Flow/Flow.js +26 -0
- package/dist/Flow/Flow.js.map +1 -0
- package/dist/Flow/index.d.ts +3 -0
- package/dist/Flow/index.js +2 -0
- package/dist/Fold/Fold.d.ts +17 -0
- package/dist/Fold/Fold.js +64 -0
- package/dist/Fold/Fold.js.map +1 -0
- package/dist/Fold/index.d.ts +3 -0
- package/dist/Fold/index.js +2 -0
- package/dist/Frame/Frame.d.ts +7 -0
- package/dist/Frame/Frame.js +20 -0
- package/dist/Frame/Frame.js.map +1 -0
- package/dist/Frame/index.d.ts +3 -0
- package/dist/Frame/index.js +2 -0
- package/dist/Ground/Ground.d.ts +7 -0
- package/dist/Ground/Ground.js +19 -0
- package/dist/Ground/Ground.js.map +1 -0
- package/dist/Ground/index.d.ts +3 -0
- package/dist/Ground/index.js +2 -0
- package/dist/Hint/Hint.d.ts +21 -0
- package/dist/Hint/Hint.js +104 -0
- package/dist/Hint/Hint.js.map +1 -0
- package/dist/Hint/index.d.ts +3 -0
- package/dist/Hint/index.js +2 -0
- package/dist/Link/Link.d.ts +7 -0
- package/dist/Link/Link.js +20 -0
- package/dist/Link/Link.js.map +1 -0
- package/dist/Link/index.d.ts +3 -0
- package/dist/Link/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +25 -0
- package/dist/ListRow/ListRow.js +80 -0
- package/dist/ListRow/ListRow.js.map +1 -0
- package/dist/ListRow/index.d.ts +3 -0
- package/dist/ListRow/index.js +2 -0
- package/dist/Mark/Mark.d.ts +14 -0
- package/dist/Mark/Mark.js +28 -0
- package/dist/Mark/Mark.js.map +1 -0
- package/dist/Mark/index.d.ts +3 -0
- package/dist/Mark/index.js +2 -0
- package/dist/Menu/Menu.d.ts +29 -0
- package/dist/Menu/Menu.js +64 -0
- package/dist/Menu/Menu.js.map +1 -0
- package/dist/Menu/index.d.ts +3 -0
- package/dist/Menu/index.js +2 -0
- package/dist/Notice/Notice.d.ts +31 -0
- package/dist/Notice/Notice.js +82 -0
- package/dist/Notice/Notice.js.map +1 -0
- package/dist/Notice/index.d.ts +3 -0
- package/dist/Notice/index.js +2 -0
- package/dist/Placeholder/Placeholder.d.ts +15 -0
- package/dist/Placeholder/Placeholder.js +28 -0
- package/dist/Placeholder/Placeholder.js.map +1 -0
- package/dist/Placeholder/index.d.ts +3 -0
- package/dist/Placeholder/index.js +2 -0
- package/dist/Portal/Portal.d.ts +10 -0
- package/dist/Portal/Portal.js +13 -0
- package/dist/Portal/Portal.js.map +1 -0
- package/dist/Portal/index.d.ts +3 -0
- package/dist/Portal/index.js +2 -0
- package/dist/Progress/Progress.d.ts +22 -0
- package/dist/Progress/Progress.js +65 -0
- package/dist/Progress/Progress.js.map +1 -0
- package/dist/Progress/index.d.ts +3 -0
- package/dist/Progress/index.js +2 -0
- package/dist/Radio/Radio.d.ts +39 -0
- package/dist/Radio/Radio.js +118 -0
- package/dist/Radio/Radio.js.map +1 -0
- package/dist/Radio/index.d.ts +3 -0
- package/dist/Radio/index.js +2 -0
- package/dist/Range/Range.d.ts +26 -0
- package/dist/Range/Range.js +68 -0
- package/dist/Range/Range.js.map +1 -0
- package/dist/Range/index.d.ts +3 -0
- package/dist/Range/index.js +2 -0
- package/dist/ResultRow/ResultRow.d.ts +17 -0
- package/dist/ResultRow/ResultRow.js +46 -0
- package/dist/ResultRow/ResultRow.js.map +1 -0
- package/dist/ResultRow/index.d.ts +3 -0
- package/dist/ResultRow/index.js +2 -0
- package/dist/Score/Score.d.ts +16 -0
- package/dist/Score/Score.js +55 -0
- package/dist/Score/Score.js.map +1 -0
- package/dist/Score/index.d.ts +3 -0
- package/dist/Score/index.js +2 -0
- package/dist/Search/Search.d.ts +29 -0
- package/dist/Search/Search.js +94 -0
- package/dist/Search/Search.js.map +1 -0
- package/dist/Search/index.d.ts +3 -0
- package/dist/Search/index.js +2 -0
- package/dist/Segmented/Segmented.d.ts +24 -0
- package/dist/Segmented/Segmented.js +69 -0
- package/dist/Segmented/Segmented.js.map +1 -0
- package/dist/Segmented/index.d.ts +3 -0
- package/dist/Segmented/index.js +2 -0
- package/dist/Settings/Settings.d.ts +49 -0
- package/dist/Settings/Settings.js +93 -0
- package/dist/Settings/Settings.js.map +1 -0
- package/dist/Settings/index.d.ts +3 -0
- package/dist/Settings/index.js +2 -0
- package/dist/Sheet/Sheet.d.ts +7 -0
- package/dist/Sheet/Sheet.js +11 -0
- package/dist/Sheet/Sheet.js.map +1 -0
- package/dist/Sheet/index.d.ts +3 -0
- package/dist/Sheet/index.js +2 -0
- package/dist/Shelf/Shelf.d.ts +7 -0
- package/dist/Shelf/Shelf.js +23 -0
- package/dist/Shelf/Shelf.js.map +1 -0
- package/dist/Shelf/index.d.ts +3 -0
- package/dist/Shelf/index.js +2 -0
- package/dist/SlurpProvider/ColorSchemeScript.d.ts +15 -0
- package/dist/SlurpProvider/ColorSchemeScript.js +18 -0
- package/dist/SlurpProvider/ColorSchemeScript.js.map +1 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +18 -0
- package/dist/SlurpProvider/SlurpProvider.js +106 -0
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -0
- package/dist/SlurpProvider/index.d.ts +5 -0
- package/dist/SlurpProvider/index.js +5 -0
- package/dist/Stage/Stage.d.ts +14 -0
- package/dist/Stage/Stage.js +38 -0
- package/dist/Stage/Stage.js.map +1 -0
- package/dist/Stage/index.d.ts +3 -0
- package/dist/Stage/index.js +2 -0
- package/dist/Surface/Surface.d.ts +16 -0
- package/dist/Surface/Surface.js +25 -0
- package/dist/Surface/Surface.js.map +1 -0
- package/dist/Surface/index.d.ts +3 -0
- package/dist/Surface/index.js +2 -0
- package/dist/Swatch/Swatch.d.ts +31 -0
- package/dist/Swatch/Swatch.js +72 -0
- package/dist/Swatch/Swatch.js.map +1 -0
- package/dist/Swatch/index.d.ts +3 -0
- package/dist/Swatch/index.js +2 -0
- package/dist/Switch/Switch.d.ts +15 -0
- package/dist/Switch/Switch.js +62 -0
- package/dist/Switch/Switch.js.map +1 -0
- package/dist/Switch/index.d.ts +3 -0
- package/dist/Switch/index.js +2 -0
- package/dist/Tabs/Tabs.d.ts +21 -0
- package/dist/Tabs/Tabs.js +105 -0
- package/dist/Tabs/Tabs.js.map +1 -0
- package/dist/Tabs/index.d.ts +3 -0
- package/dist/Tabs/index.js +2 -0
- package/dist/Text/Text.d.ts +17 -0
- package/dist/Text/Text.js +33 -0
- package/dist/Text/Text.js.map +1 -0
- package/dist/Text/index.d.ts +3 -0
- package/dist/Text/index.js +2 -0
- package/dist/Tile/Tile.d.ts +25 -0
- package/dist/Tile/Tile.js +67 -0
- package/dist/Tile/Tile.js.map +1 -0
- package/dist/Tile/index.d.ts +3 -0
- package/dist/Tile/index.js +2 -0
- package/dist/Toast/Toast.d.ts +43 -0
- package/dist/Toast/Toast.js +132 -0
- package/dist/Toast/Toast.js.map +1 -0
- package/dist/Toast/index.d.ts +3 -0
- package/dist/Toast/index.js +2 -0
- package/dist/VisuallyHidden/VisuallyHidden.d.ts +7 -0
- package/dist/VisuallyHidden/VisuallyHidden.js +15 -0
- package/dist/VisuallyHidden/VisuallyHidden.js.map +1 -0
- package/dist/VisuallyHidden/index.d.ts +3 -0
- package/dist/VisuallyHidden/index.js +2 -0
- package/dist/fonts/poppins-latin-400-normal.woff2 +0 -0
- package/dist/fonts/poppins-latin-500-normal.woff2 +0 -0
- package/dist/fonts/poppins-latin-600-normal.woff2 +0 -0
- package/dist/fonts/poppins-latin-700-normal.woff2 +0 -0
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.js +2 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +69 -0
- package/dist/internal/animation.js +26 -0
- package/dist/internal/animation.js.map +1 -0
- package/dist/internal/context.d.ts +14 -0
- package/dist/internal/context.js +21 -0
- package/dist/internal/context.js.map +1 -0
- package/dist/internal/styled.js +79 -0
- package/dist/internal/styled.js.map +1 -0
- package/dist/lib/color.d.ts +21 -0
- package/dist/lib/color.js +151 -0
- package/dist/lib/color.js.map +1 -0
- package/dist/lib/crumb.d.ts +9 -0
- package/dist/lib/crumb.js +69 -0
- package/dist/lib/crumb.js.map +1 -0
- package/dist/lib/css.d.ts +53 -0
- package/dist/lib/css.js +142 -0
- package/dist/lib/css.js.map +1 -0
- package/dist/lib/ground.js +15 -0
- package/dist/lib/ground.js.map +1 -0
- package/dist/lib/layout.d.ts +24 -0
- package/dist/lib/layout.js +88 -0
- package/dist/lib/layout.js.map +1 -0
- package/dist/lib/polymorphic.d.ts +28 -0
- package/dist/lib/theme.d.ts +292 -0
- package/dist/lib/theme.js +90 -0
- package/dist/lib/theme.js.map +1 -0
- package/dist/motion/AnimationGroup.d.ts +10 -0
- package/dist/motion/AnimationGroup.js +14 -0
- package/dist/motion/AnimationGroup.js.map +1 -0
- package/dist/motion/context.js +8 -0
- package/dist/motion/context.js.map +1 -0
- package/dist/motion/index.d.ts +7 -0
- package/dist/motion/index.js +7 -0
- package/dist/motion/navigation.d.ts +51 -0
- package/dist/motion/navigation.js +122 -0
- package/dist/motion/navigation.js.map +1 -0
- package/dist/motion/useAnimationTarget.d.ts +22 -0
- package/dist/motion/useAnimationTarget.js +34 -0
- package/dist/motion/useAnimationTarget.js.map +1 -0
- package/dist/motion/useSlurp.d.ts +18 -0
- package/dist/motion/useSlurp.js +48 -0
- package/dist/motion/useSlurp.js.map +1 -0
- package/dist/styles.css +3439 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +2 -0
- package/dist/tokens.css +178 -0
- package/dist/utils/focus.d.ts +20 -0
- package/dist/utils/focus.js +50 -0
- package/dist/utils/focus.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/src/index.js +9 -0
- package/dist/utils/src/index.js.map +1 -0
- package/dist/utils/useControlled.d.ts +14 -0
- package/dist/utils/useControlled.js +23 -0
- package/dist/utils/useControlled.js.map +1 -0
- package/dist/utils/useDismiss.d.ts +24 -0
- package/dist/utils/useDismiss.js +60 -0
- package/dist/utils/useDismiss.js.map +1 -0
- package/dist/utils/useFindInPage.d.ts +18 -0
- package/dist/utils/useFindInPage.js +51 -0
- package/dist/utils/useFindInPage.js.map +1 -0
- package/dist/utils/useForkRef.d.ts +5 -0
- package/dist/utils/useForkRef.js +33 -0
- package/dist/utils/useForkRef.js.map +1 -0
- package/dist/utils/useMediaQuery.d.ts +11 -0
- package/dist/utils/useMediaQuery.js +21 -0
- package/dist/utils/useMediaQuery.js.map +1 -0
- package/dist/utils/useRovingFocus.d.ts +17 -0
- package/dist/utils/useRovingFocus.js +26 -0
- package/dist/utils/useRovingFocus.js.map +1 -0
- package/package.json +107 -3
package/dist/tokens.css
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/* @slurp-ui/tokens — generated from src/tokens.json (Slurp v4, synced 2026-10-14). Do not edit. */
|
|
2
|
+
@layer slurp.reset, slurp.base, slurp.components, slurp.utilities;
|
|
3
|
+
|
|
4
|
+
@layer slurp.base {
|
|
5
|
+
:where(:root) {
|
|
6
|
+
--slurp-accent: #8b6fff;
|
|
7
|
+
--slurp-on-accent: #111114;
|
|
8
|
+
--slurp-accent-soft: rgba(139, 111, 255, 0.16);
|
|
9
|
+
--slurp-hue-red: #ff223d;
|
|
10
|
+
--slurp-hue-orange: #f96909;
|
|
11
|
+
--slurp-hue-amber: #e29b03;
|
|
12
|
+
--slurp-hue-green: #10a668;
|
|
13
|
+
--slurp-hue-teal: #1aa594;
|
|
14
|
+
--slurp-hue-sky: #14a5e8;
|
|
15
|
+
--slurp-hue-blue: #5882fe;
|
|
16
|
+
--slurp-hue-violet: #8b6fff;
|
|
17
|
+
--slurp-hue-pink: #ef1cac;
|
|
18
|
+
--slurp-space-1: 4px;
|
|
19
|
+
--slurp-space-2: 8px;
|
|
20
|
+
--slurp-space-3: 12px;
|
|
21
|
+
--slurp-space-4: 16px;
|
|
22
|
+
--slurp-space-5: 20px;
|
|
23
|
+
--slurp-space-6: 24px;
|
|
24
|
+
--slurp-space-8: 32px;
|
|
25
|
+
--slurp-space-10: 40px;
|
|
26
|
+
--slurp-space-48: 192px;
|
|
27
|
+
--slurp-radius-sm: 16px;
|
|
28
|
+
--slurp-radius-md: 22px;
|
|
29
|
+
--slurp-radius-lg: 26px;
|
|
30
|
+
--slurp-radius-dock: 32px;
|
|
31
|
+
--slurp-radius-card: 34px;
|
|
32
|
+
--slurp-radius-tile: 36px;
|
|
33
|
+
--slurp-radius-panel: 40px;
|
|
34
|
+
--slurp-radius-full: 9999px;
|
|
35
|
+
--slurp-blur-surface: 24px;
|
|
36
|
+
--slurp-blur-stage: 30px;
|
|
37
|
+
--slurp-blur-ambient: 90px;
|
|
38
|
+
--slurp-blur-goo: 12px;
|
|
39
|
+
--slurp-blob-opacity-light: 0.42;
|
|
40
|
+
--slurp-blob-opacity-dark: 0.3;
|
|
41
|
+
--slurp-font-family-display: Poppins, system-ui, sans-serif;
|
|
42
|
+
--slurp-font-family-sans: Poppins, system-ui, sans-serif;
|
|
43
|
+
--slurp-font-display-xl-size: 52px;
|
|
44
|
+
--slurp-font-display-xl-line-height: 1.1;
|
|
45
|
+
--slurp-font-display-xl-weight: 600;
|
|
46
|
+
--slurp-font-display-xl-tracking: -0.02em;
|
|
47
|
+
--slurp-font-display-xl: var(--slurp-font-display-xl-weight) var(--slurp-font-display-xl-size) / var(--slurp-font-display-xl-line-height) var(--slurp-font-family-display);
|
|
48
|
+
--slurp-font-display-l-size: 48px;
|
|
49
|
+
--slurp-font-display-l-line-height: 1.1;
|
|
50
|
+
--slurp-font-display-l-weight: 600;
|
|
51
|
+
--slurp-font-display-l-tracking: -0.02em;
|
|
52
|
+
--slurp-font-display-l: var(--slurp-font-display-l-weight) var(--slurp-font-display-l-size) / var(--slurp-font-display-l-line-height) var(--slurp-font-family-display);
|
|
53
|
+
--slurp-font-title-xl-size: 40px;
|
|
54
|
+
--slurp-font-title-xl-line-height: 1.15;
|
|
55
|
+
--slurp-font-title-xl-weight: 600;
|
|
56
|
+
--slurp-font-title-xl-tracking: -0.02em;
|
|
57
|
+
--slurp-font-title-xl: var(--slurp-font-title-xl-weight) var(--slurp-font-title-xl-size) / var(--slurp-font-title-xl-line-height) var(--slurp-font-family-display);
|
|
58
|
+
--slurp-font-figure-size: 40px;
|
|
59
|
+
--slurp-font-figure-line-height: 1.1;
|
|
60
|
+
--slurp-font-figure-weight: 700;
|
|
61
|
+
--slurp-font-figure-tracking: -0.02em;
|
|
62
|
+
--slurp-font-figure: var(--slurp-font-figure-weight) var(--slurp-font-figure-size) / var(--slurp-font-figure-line-height) var(--slurp-font-family-display);
|
|
63
|
+
--slurp-font-tile-label-size: 28px;
|
|
64
|
+
--slurp-font-tile-label-line-height: 1.2;
|
|
65
|
+
--slurp-font-tile-label-weight: 600;
|
|
66
|
+
--slurp-font-tile-label-tracking: -0.015em;
|
|
67
|
+
--slurp-font-tile-label: var(--slurp-font-tile-label-weight) var(--slurp-font-tile-label-size) / var(--slurp-font-tile-label-line-height) var(--slurp-font-family-display);
|
|
68
|
+
--slurp-font-title-l-size: 24px;
|
|
69
|
+
--slurp-font-title-l-line-height: 1.25;
|
|
70
|
+
--slurp-font-title-l-weight: 600;
|
|
71
|
+
--slurp-font-title-l-tracking: -0.01em;
|
|
72
|
+
--slurp-font-title-l: var(--slurp-font-title-l-weight) var(--slurp-font-title-l-size) / var(--slurp-font-title-l-line-height) var(--slurp-font-family-display);
|
|
73
|
+
--slurp-font-title-s-size: 20px;
|
|
74
|
+
--slurp-font-title-s-line-height: 1.3;
|
|
75
|
+
--slurp-font-title-s-weight: 600;
|
|
76
|
+
--slurp-font-title-s-tracking: normal;
|
|
77
|
+
--slurp-font-title-s: var(--slurp-font-title-s-weight) var(--slurp-font-title-s-size) / var(--slurp-font-title-s-line-height) var(--slurp-font-family-display);
|
|
78
|
+
--slurp-font-body-l-size: 18px;
|
|
79
|
+
--slurp-font-body-l-line-height: 1.6;
|
|
80
|
+
--slurp-font-body-l-weight: 400;
|
|
81
|
+
--slurp-font-body-l-tracking: normal;
|
|
82
|
+
--slurp-font-body-l: var(--slurp-font-body-l-weight) var(--slurp-font-body-l-size) / var(--slurp-font-body-l-line-height) var(--slurp-font-family-sans);
|
|
83
|
+
--slurp-font-body-size: 16px;
|
|
84
|
+
--slurp-font-body-line-height: 1.6;
|
|
85
|
+
--slurp-font-body-weight: 400;
|
|
86
|
+
--slurp-font-body-tracking: normal;
|
|
87
|
+
--slurp-font-body: var(--slurp-font-body-weight) var(--slurp-font-body-size) / var(--slurp-font-body-line-height) var(--slurp-font-family-sans);
|
|
88
|
+
--slurp-font-body-s-size: 15px;
|
|
89
|
+
--slurp-font-body-s-line-height: 1.5;
|
|
90
|
+
--slurp-font-body-s-weight: 500;
|
|
91
|
+
--slurp-font-body-s-tracking: normal;
|
|
92
|
+
--slurp-font-body-s: var(--slurp-font-body-s-weight) var(--slurp-font-body-s-size) / var(--slurp-font-body-s-line-height) var(--slurp-font-family-sans);
|
|
93
|
+
--slurp-font-label-size: 15px;
|
|
94
|
+
--slurp-font-label-line-height: 1.4;
|
|
95
|
+
--slurp-font-label-weight: 600;
|
|
96
|
+
--slurp-font-label-tracking: normal;
|
|
97
|
+
--slurp-font-label: var(--slurp-font-label-weight) var(--slurp-font-label-size) / var(--slurp-font-label-line-height) var(--slurp-font-family-sans);
|
|
98
|
+
--slurp-font-caption-size: 13px;
|
|
99
|
+
--slurp-font-caption-line-height: 1.5;
|
|
100
|
+
--slurp-font-caption-weight: 500;
|
|
101
|
+
--slurp-font-caption-tracking: normal;
|
|
102
|
+
--slurp-font-caption: var(--slurp-font-caption-weight) var(--slurp-font-caption-size) / var(--slurp-font-caption-line-height) var(--slurp-font-family-sans);
|
|
103
|
+
--slurp-font-eyebrow-size: 12px;
|
|
104
|
+
--slurp-font-eyebrow-line-height: 1.5;
|
|
105
|
+
--slurp-font-eyebrow-weight: 700;
|
|
106
|
+
--slurp-font-eyebrow-tracking: 0.08em;
|
|
107
|
+
--slurp-font-eyebrow: var(--slurp-font-eyebrow-weight) var(--slurp-font-eyebrow-size) / var(--slurp-font-eyebrow-line-height) var(--slurp-font-family-sans);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Themed tokens. data-theme always wins over the system setting, on the root or on any subtree.
|
|
111
|
+
Every selector is wrapped in :where() (zero specificity): theme overrides and AccentScope win whatever
|
|
112
|
+
the stylesheet order, and between these blocks only their order decides. */
|
|
113
|
+
:where(:root, [data-theme='light']) {
|
|
114
|
+
color-scheme: light;
|
|
115
|
+
--slurp-bg: #f7f7fa;
|
|
116
|
+
--slurp-surface: rgba(255, 255, 255, 0.78);
|
|
117
|
+
--slurp-surface-dock: rgba(255, 255, 255, 0.92);
|
|
118
|
+
--slurp-surface-2: #ffffff;
|
|
119
|
+
--slurp-fg: #15131c;
|
|
120
|
+
--slurp-muted: #55526a;
|
|
121
|
+
--slurp-line: rgba(21, 19, 28, 0.08);
|
|
122
|
+
--slurp-border-control: #858299;
|
|
123
|
+
--slurp-accent-ink: #463b79;
|
|
124
|
+
--slurp-focus: var(--slurp-accent-ink);
|
|
125
|
+
--slurp-success: #13734a;
|
|
126
|
+
--slurp-warning: #8a5300;
|
|
127
|
+
--slurp-danger: #c0172f;
|
|
128
|
+
--slurp-shadow-float: 0 24px 60px -24px rgba(70, 59, 121, 0.38);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
:where([data-theme='dark']) {
|
|
132
|
+
color-scheme: dark;
|
|
133
|
+
--slurp-bg: #0f0e14;
|
|
134
|
+
--slurp-surface: rgba(30, 28, 38, 0.78);
|
|
135
|
+
--slurp-surface-dock: rgba(26, 24, 34, 0.94);
|
|
136
|
+
--slurp-surface-2: #1b1a23;
|
|
137
|
+
--slurp-fg: #f4f3f8;
|
|
138
|
+
--slurp-muted: #b3b0c3;
|
|
139
|
+
--slurp-line: rgba(255, 255, 255, 0.1);
|
|
140
|
+
--slurp-border-control: #75728a;
|
|
141
|
+
--slurp-accent-ink: #c1baff;
|
|
142
|
+
--slurp-focus: var(--slurp-accent-ink);
|
|
143
|
+
--slurp-success: #4fd197;
|
|
144
|
+
--slurp-warning: #f2b14b;
|
|
145
|
+
--slurp-danger: #ff7f8f;
|
|
146
|
+
--slurp-shadow-float: 0 24px 60px -24px rgba(0, 0, 0, 0.75);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@media (prefers-color-scheme: dark) {
|
|
150
|
+
:where(:root:not([data-theme='light'])) {
|
|
151
|
+
color-scheme: dark;
|
|
152
|
+
--slurp-bg: #0f0e14;
|
|
153
|
+
--slurp-surface: rgba(30, 28, 38, 0.78);
|
|
154
|
+
--slurp-surface-dock: rgba(26, 24, 34, 0.94);
|
|
155
|
+
--slurp-surface-2: #1b1a23;
|
|
156
|
+
--slurp-fg: #f4f3f8;
|
|
157
|
+
--slurp-muted: #b3b0c3;
|
|
158
|
+
--slurp-line: rgba(255, 255, 255, 0.1);
|
|
159
|
+
--slurp-border-control: #75728a;
|
|
160
|
+
--slurp-accent-ink: #c1baff;
|
|
161
|
+
--slurp-focus: var(--slurp-accent-ink);
|
|
162
|
+
--slurp-success: #4fd197;
|
|
163
|
+
--slurp-warning: #f2b14b;
|
|
164
|
+
--slurp-danger: #ff7f8f;
|
|
165
|
+
--slurp-shadow-float: 0 24px 60px -24px rgba(0, 0, 0, 0.75);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Compact (phone) type scale. */
|
|
170
|
+
@media (max-width: 640px) {
|
|
171
|
+
:where(:root) {
|
|
172
|
+
--slurp-font-display-xl-size: 34px;
|
|
173
|
+
--slurp-font-display-l-size: 36px;
|
|
174
|
+
--slurp-font-title-xl-size: 32px;
|
|
175
|
+
--slurp-font-tile-label-size: 22px;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import { KeyboardEvent as KeyboardEvent$1 } from "react";
|
|
3
|
+
/** Elements that take focus with Tab (enabled controls, links, explicit tab stops). */
|
|
4
|
+
export declare const FOCUSABLE = "button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])";
|
|
5
|
+
/** Focuses the active choice inside root, else its first enabled control (when a panel opens). */
|
|
6
|
+
export declare function focusFirst(root: HTMLElement | null): HTMLElement | null;
|
|
7
|
+
export interface MoveFocusOptions {
|
|
8
|
+
/** `vertical` (default): ArrowUp / ArrowDown. `horizontal`: ArrowLeft / ArrowRight (flipped in RTL). `both`. */
|
|
9
|
+
orientation?: 'vertical' | 'horizontal' | 'both';
|
|
10
|
+
/** From the last item to the first and back. Default false. */
|
|
11
|
+
loop?: boolean;
|
|
12
|
+
/** ArrowUp (or ArrowLeft) from the first item, when not looping: e.g. back to the field above the list. */
|
|
13
|
+
onExitStart?: () => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Arrow keys in a list of controls: to the next / previous `selector` inside root; Home / End to the ends once focus is
|
|
17
|
+
* in the list. Disabled items are skipped. Returns the element focused, or null when the key was not handled.
|
|
18
|
+
*/
|
|
19
|
+
export declare function moveFocus(e: KeyboardEvent$1 | KeyboardEvent, root: HTMLElement | null, selector: string, options?: MoveFocusOptions | (() => void)): HTMLElement | null;
|
|
20
|
+
//# sourceMappingURL=focus.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/utils/focus.ts
|
|
3
|
+
/** Elements that take focus with Tab (enabled controls, links, explicit tab stops). */
|
|
4
|
+
const FOCUSABLE = "button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])";
|
|
5
|
+
/** The active choice of a panel: a pressed chip, a checked radio, a selected option or tab. */
|
|
6
|
+
const ACTIVE_CHOICE = "[aria-pressed=\"true\"], [aria-selected=\"true\"], [aria-checked=\"true\"], input[type=\"radio\"]:checked";
|
|
7
|
+
/** Focuses the active choice inside root, else its first enabled control (when a panel opens). */
|
|
8
|
+
function focusFirst(root) {
|
|
9
|
+
const el = root?.querySelector(ACTIVE_CHOICE) ?? root?.querySelector("button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])");
|
|
10
|
+
el?.focus({ preventScroll: true });
|
|
11
|
+
return el ?? null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Arrow keys in a list of controls: to the next / previous `selector` inside root; Home / End to the ends once focus is
|
|
15
|
+
* in the list. Disabled items are skipped. Returns the element focused, or null when the key was not handled.
|
|
16
|
+
*/
|
|
17
|
+
function moveFocus(e, root, selector, options = {}) {
|
|
18
|
+
const { orientation = "vertical", loop = false, onExitStart } = typeof options === "function" ? { onExitStart: options } : options;
|
|
19
|
+
const items = root ? [...root.querySelectorAll(selector)].filter((el) => !el.matches(":disabled, [aria-disabled=\"true\"]")) : [];
|
|
20
|
+
if (!items.length) return null;
|
|
21
|
+
const rtl = root ? getComputedStyle(root).direction === "rtl" : false;
|
|
22
|
+
const vertical = orientation !== "horizontal";
|
|
23
|
+
const horizontal = orientation !== "vertical";
|
|
24
|
+
const at = items.indexOf(document.activeElement);
|
|
25
|
+
let step = 0;
|
|
26
|
+
if (vertical && e.key === "ArrowDown") step = 1;
|
|
27
|
+
else if (vertical && e.key === "ArrowUp") step = -1;
|
|
28
|
+
else if (horizontal && e.key === "ArrowRight") step = rtl ? -1 : 1;
|
|
29
|
+
else if (horizontal && e.key === "ArrowLeft") step = rtl ? 1 : -1;
|
|
30
|
+
let to;
|
|
31
|
+
if (step) to = at + step;
|
|
32
|
+
else if (e.key === "Home" && at >= 0) to = 0;
|
|
33
|
+
else if (e.key === "End" && at >= 0) to = items.length - 1;
|
|
34
|
+
else return null;
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
if (to < 0) {
|
|
37
|
+
if (!loop) {
|
|
38
|
+
onExitStart?.();
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
to = items.length - 1;
|
|
42
|
+
}
|
|
43
|
+
if (to >= items.length) to = loop ? 0 : items.length - 1;
|
|
44
|
+
const next = items[to] ?? null;
|
|
45
|
+
next?.focus();
|
|
46
|
+
return next;
|
|
47
|
+
}
|
|
48
|
+
export { FOCUSABLE, focusFirst, moveFocus };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus.js","names":[],"sources":["../../src/utils/focus.ts"],"sourcesContent":["import type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n/** Elements that take focus with Tab (enabled controls, links, explicit tab stops). */\nexport const FOCUSABLE =\n 'button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])';\n\n/** The active choice of a panel: a pressed chip, a checked radio, a selected option or tab. */\nconst ACTIVE_CHOICE =\n '[aria-pressed=\"true\"], [aria-selected=\"true\"], [aria-checked=\"true\"], input[type=\"radio\"]:checked';\n\n/** Focuses the active choice inside root, else its first enabled control (when a panel opens). */\nexport function focusFirst(root: HTMLElement | null): HTMLElement | null {\n const el =\n root?.querySelector<HTMLElement>(ACTIVE_CHOICE) ?? root?.querySelector<HTMLElement>(FOCUSABLE);\n el?.focus({ preventScroll: true });\n return el ?? null;\n}\n\nexport interface MoveFocusOptions {\n /** `vertical` (default): ArrowUp / ArrowDown. `horizontal`: ArrowLeft / ArrowRight (flipped in RTL). `both`. */\n orientation?: 'vertical' | 'horizontal' | 'both';\n /** From the last item to the first and back. Default false. */\n loop?: boolean;\n /** ArrowUp (or ArrowLeft) from the first item, when not looping: e.g. back to the field above the list. */\n onExitStart?: () => void;\n}\n\n/**\n * Arrow keys in a list of controls: to the next / previous `selector` inside root; Home / End to the ends once focus is\n * in the list. Disabled items are skipped. Returns the element focused, or null when the key was not handled.\n */\nexport function moveFocus(\n e: ReactKeyboardEvent | KeyboardEvent,\n root: HTMLElement | null,\n selector: string,\n options: MoveFocusOptions | (() => void) = {},\n): HTMLElement | null {\n const {\n orientation = 'vertical',\n loop = false,\n onExitStart,\n } = typeof options === 'function' ? { onExitStart: options } : options;\n const items = root\n ? [...root.querySelectorAll<HTMLElement>(selector)].filter(\n (el) => !el.matches(':disabled, [aria-disabled=\"true\"]'),\n )\n : [];\n if (!items.length) return null;\n const rtl = root ? getComputedStyle(root).direction === 'rtl' : false;\n const vertical = orientation !== 'horizontal';\n const horizontal = orientation !== 'vertical';\n const at = items.indexOf(document.activeElement as HTMLElement);\n let step = 0;\n if (vertical && e.key === 'ArrowDown') step = 1;\n else if (vertical && e.key === 'ArrowUp') step = -1;\n else if (horizontal && e.key === 'ArrowRight') step = rtl ? -1 : 1;\n else if (horizontal && e.key === 'ArrowLeft') step = rtl ? 1 : -1;\n let to: number;\n if (step) to = at + step;\n else if (e.key === 'Home' && at >= 0) to = 0;\n else if (e.key === 'End' && at >= 0) to = items.length - 1;\n else return null;\n e.preventDefault();\n if (to < 0) {\n if (!loop) {\n onExitStart?.();\n return null;\n }\n to = items.length - 1;\n }\n if (to >= items.length) to = loop ? 0 : items.length - 1;\n const next = items[to] ?? null;\n next?.focus();\n return next;\n}\n"],"mappings":";;;AAGA,MAAa,YACX;;AAGF,MAAM,gBACJ;;AAGF,SAAgB,WAAW,MAA8C;CACvE,MAAM,KACJ,MAAM,cAA2B,aAAa,KAAK,MAAM,cAAA,wIAAoC;CAC/F,IAAI,MAAM,EAAE,eAAe,KAAK,CAAC;CACjC,OAAO,MAAM;AACf;;;;;AAeA,SAAgB,UACd,GACA,MACA,UACA,UAA2C,CAAC,GACxB;CACpB,MAAM,EACJ,cAAc,YACd,OAAO,OACP,gBACE,OAAO,YAAY,aAAa,EAAE,aAAa,QAAQ,IAAI;CAC/D,MAAM,QAAQ,OACV,CAAC,GAAG,KAAK,iBAA8B,QAAQ,CAAC,CAAC,CAAC,QAC/C,OAAO,CAAC,GAAG,QAAQ,qCAAmC,CACzD,IACA,CAAC;CACL,IAAI,CAAC,MAAM,QAAQ,OAAO;CAC1B,MAAM,MAAM,OAAO,iBAAiB,IAAI,CAAC,CAAC,cAAc,QAAQ;CAChE,MAAM,WAAW,gBAAgB;CACjC,MAAM,aAAa,gBAAgB;CACnC,MAAM,KAAK,MAAM,QAAQ,SAAS,aAA4B;CAC9D,IAAI,OAAO;CACX,IAAI,YAAY,EAAE,QAAQ,aAAa,OAAO;MACzC,IAAI,YAAY,EAAE,QAAQ,WAAW,OAAO;MAC5C,IAAI,cAAc,EAAE,QAAQ,cAAc,OAAO,MAAM,KAAK;MAC5D,IAAI,cAAc,EAAE,QAAQ,aAAa,OAAO,MAAM,IAAI;CAC/D,IAAI;CACJ,IAAI,MAAM,KAAK,KAAK;MACf,IAAI,EAAE,QAAQ,UAAU,MAAM,GAAG,KAAK;MACtC,IAAI,EAAE,QAAQ,SAAS,MAAM,GAAG,KAAK,MAAM,SAAS;MACpD,OAAO;CACZ,EAAE,eAAe;CACjB,IAAI,KAAK,GAAG;EACV,IAAI,CAAC,MAAM;GACT,cAAc;GACd,OAAO;EACT;EACA,KAAK,MAAM,SAAS;CACtB;CACA,IAAI,MAAM,MAAM,QAAQ,KAAK,OAAO,IAAI,MAAM,SAAS;CACvD,MAAM,OAAO,MAAM,OAAO;CAC1B,MAAM,MAAM;CACZ,OAAO;AACT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
import { matchRanges, matchesAll, normalizeText } from "../lib/layout.js";
|
|
3
|
+
import { FOCUSABLE, MoveFocusOptions, focusFirst, moveFocus } from "./focus.js";
|
|
4
|
+
import { ControlledOptions, useControlled } from "./useControlled.js";
|
|
5
|
+
import { DismissOptions, useDismiss } from "./useDismiss.js";
|
|
6
|
+
import { useForkRef } from "./useForkRef.js";
|
|
7
|
+
import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery.js";
|
|
8
|
+
import { RovingFocusOptions, useRovingFocus } from "./useRovingFocus.js";
|
|
9
|
+
import { FindInPage, focusHit, useFindInPage } from "./useFindInPage.js";
|
|
10
|
+
export { COMPACT_QUERY, type ControlledOptions, type DismissOptions, FOCUSABLE, type FindInPage, type MoveFocusOptions, type RovingFocusOptions, focusFirst, focusHit, matchRanges, matchesAll, moveFocus, normalizeText, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
import { useForkRef } from "./useForkRef.js";
|
|
3
|
+
import { useControlled } from "./useControlled.js";
|
|
4
|
+
import { FOCUSABLE, focusFirst, moveFocus } from "./focus.js";
|
|
5
|
+
import { useRovingFocus } from "./useRovingFocus.js";
|
|
6
|
+
import { useDismiss } from "./useDismiss.js";
|
|
7
|
+
import { matchRanges, matchesAll, normalizeText } from "../lib/layout.js";
|
|
8
|
+
import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery.js";
|
|
9
|
+
import { focusHit, useFindInPage } from "./useFindInPage.js";
|
|
10
|
+
export { COMPACT_QUERY, FOCUSABLE, focusFirst, focusHit, matchRanges, matchesAll, moveFocus, normalizeText, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../utils/src/index.ts"],"sourcesContent":["// Internal helpers shared by the @slurp-ui/* packages; bundled into @slurp-ui/react, never published.\n\n/** Joins truthy class names. */\nexport function cx(...names: (string | false | null | undefined)[]): string {\n return names.filter(Boolean).join(' ');\n}\n"],"mappings":";;;AAGA,SAAgB,GAAG,GAAG,OAAsD;CAC1E,OAAO,MAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
export interface ControlledOptions<T> {
|
|
3
|
+
/** Controlled value: when defined, the component follows it and only reports changes. */
|
|
4
|
+
value: T | undefined;
|
|
5
|
+
/** Initial value when uncontrolled. */
|
|
6
|
+
defaultValue: T;
|
|
7
|
+
onChange?: ((value: T) => void) | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Controlled / uncontrolled state with one API (`value` + `defaultValue` + `on…Change`). Whether it is controlled is
|
|
11
|
+
* decided on mount, like native inputs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useControlled<T>({ value, defaultValue, onChange }: ControlledOptions<T>): [T, (next: T) => void];
|
|
14
|
+
//# sourceMappingURL=useControlled.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
// src/utils/useControlled.ts
|
|
4
|
+
/**
|
|
5
|
+
* Controlled / uncontrolled state with one API (`value` + `defaultValue` + `on…Change`). Whether it is controlled is
|
|
6
|
+
* decided on mount, like native inputs.
|
|
7
|
+
*/
|
|
8
|
+
function useControlled({ value, defaultValue, onChange }) {
|
|
9
|
+
const [controlled] = useState(value !== void 0);
|
|
10
|
+
const [own, setOwn] = useState(defaultValue);
|
|
11
|
+
const latest = useRef(onChange);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
latest.current = onChange;
|
|
14
|
+
});
|
|
15
|
+
const set = useCallback((next) => {
|
|
16
|
+
if (!controlled) setOwn(next);
|
|
17
|
+
latest.current?.(next);
|
|
18
|
+
}, [controlled]);
|
|
19
|
+
return [controlled ? value : own, set];
|
|
20
|
+
}
|
|
21
|
+
export { useControlled };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=useControlled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useControlled.js","names":[],"sources":["../../src/utils/useControlled.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface ControlledOptions<T> {\n /** Controlled value: when defined, the component follows it and only reports changes. */\n value: T | undefined;\n /** Initial value when uncontrolled. */\n defaultValue: T;\n onChange?: ((value: T) => void) | undefined;\n}\n\n/**\n * Controlled / uncontrolled state with one API (`value` + `defaultValue` + `on…Change`). Whether it is controlled is\n * decided on mount, like native inputs.\n */\nexport function useControlled<T>({\n value,\n defaultValue,\n onChange,\n}: ControlledOptions<T>): [T, (next: T) => void] {\n const [controlled] = useState(value !== undefined);\n const [own, setOwn] = useState(defaultValue);\n const latest = useRef(onChange);\n useEffect(() => {\n latest.current = onChange;\n });\n const set = useCallback(\n (next: T) => {\n if (!controlled) setOwn(next);\n latest.current?.(next);\n },\n [controlled],\n );\n return [controlled ? (value as T) : own, set];\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,cAAiB,EAC/B,OACA,cACA,YAC+C;CAC/C,MAAM,CAAC,cAAc,SAAS,UAAU,KAAA,CAAS;CACjD,MAAM,CAAC,KAAK,UAAU,SAAS,YAAY;CAC3C,MAAM,SAAS,OAAO,QAAQ;CAC9B,gBAAgB;EACd,OAAO,UAAU;CACnB,CAAC;CACD,MAAM,MAAM,aACT,SAAY;EACX,IAAI,CAAC,YAAY,OAAO,IAAI;EAC5B,OAAO,UAAU,IAAI;CACvB,GACA,CAAC,UAAU,CACb;CACA,OAAO,CAAC,aAAc,QAAc,KAAK,GAAG;AAC9C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import { FocusEvent, KeyboardEvent, RefObject } from "react";
|
|
3
|
+
export interface DismissOptions {
|
|
4
|
+
/** The container: a press inside it does not close. */
|
|
5
|
+
ref: RefObject<HTMLElement | null>;
|
|
6
|
+
open: boolean;
|
|
7
|
+
onDismiss: () => void;
|
|
8
|
+
/** Where Escape sends focus when no opener was recorded. */
|
|
9
|
+
fallbackFocus?: () => HTMLElement | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The shared rules of floating panels: a press outside, Escape or Tab out close it; Escape gives focus back to the
|
|
13
|
+
* opener (recorded with `opened(el)`) or to `fallbackFocus()`; a press away or Tab leave focus where the person put it.
|
|
14
|
+
* Spread `containerProps` on the container.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useDismiss(options: DismissOptions): {
|
|
17
|
+
opened: (el: HTMLElement | null) => void;
|
|
18
|
+
dismiss: (restoreFocus: boolean) => void;
|
|
19
|
+
containerProps: {
|
|
20
|
+
onKeyDown: (e: KeyboardEvent) => void;
|
|
21
|
+
onBlur: (e: FocusEvent) => void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useDismiss.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
+
// src/utils/useDismiss.ts
|
|
4
|
+
/**
|
|
5
|
+
* The shared rules of floating panels: a press outside, Escape or Tab out close it; Escape gives focus back to the
|
|
6
|
+
* opener (recorded with `opened(el)`) or to `fallbackFocus()`; a press away or Tab leave focus where the person put it.
|
|
7
|
+
* Spread `containerProps` on the container.
|
|
8
|
+
*/
|
|
9
|
+
function useDismiss(options) {
|
|
10
|
+
const opener = useRef(null);
|
|
11
|
+
const latest = useRef(options);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
latest.current = options;
|
|
14
|
+
});
|
|
15
|
+
const dismiss = useCallback((restoreFocus) => {
|
|
16
|
+
const o = latest.current;
|
|
17
|
+
const back = opener.current ?? o.fallbackFocus?.() ?? null;
|
|
18
|
+
opener.current = null;
|
|
19
|
+
latest.current = {
|
|
20
|
+
...o,
|
|
21
|
+
open: false
|
|
22
|
+
};
|
|
23
|
+
o.onDismiss();
|
|
24
|
+
if (restoreFocus) back?.focus();
|
|
25
|
+
}, []);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!options.open) return;
|
|
28
|
+
const onDown = (e) => {
|
|
29
|
+
const root = latest.current.ref.current;
|
|
30
|
+
if (root && e.target instanceof Node && root.contains(e.target)) return;
|
|
31
|
+
opener.current = null;
|
|
32
|
+
latest.current.onDismiss();
|
|
33
|
+
};
|
|
34
|
+
document.addEventListener("pointerdown", onDown);
|
|
35
|
+
return () => document.removeEventListener("pointerdown", onDown);
|
|
36
|
+
}, [options.open]);
|
|
37
|
+
return {
|
|
38
|
+
opened: useCallback((el) => {
|
|
39
|
+
opener.current = el;
|
|
40
|
+
}, []),
|
|
41
|
+
dismiss,
|
|
42
|
+
containerProps: {
|
|
43
|
+
onKeyDown: (e) => {
|
|
44
|
+
if (e.key === "Escape" && latest.current.open) {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
dismiss(true);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
onBlur: (e) => {
|
|
51
|
+
const root = latest.current.ref.current;
|
|
52
|
+
const to = e.relatedTarget;
|
|
53
|
+
if (latest.current.open && to instanceof Node && root && !root.contains(to)) dismiss(false);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export { useDismiss };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=useDismiss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDismiss.js","names":[],"sources":["../../src/utils/useDismiss.ts"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useRef,\n type FocusEvent,\n type KeyboardEvent,\n type RefObject,\n} from 'react';\n\nexport interface DismissOptions {\n /** The container: a press inside it does not close. */\n ref: RefObject<HTMLElement | null>;\n open: boolean;\n onDismiss: () => void;\n /** Where Escape sends focus when no opener was recorded. */\n fallbackFocus?: () => HTMLElement | null;\n}\n\n/**\n * The shared rules of floating panels: a press outside, Escape or Tab out close it; Escape gives focus back to the\n * opener (recorded with `opened(el)`) or to `fallbackFocus()`; a press away or Tab leave focus where the person put it.\n * Spread `containerProps` on the container.\n */\nexport function useDismiss(options: DismissOptions) {\n const opener = useRef<HTMLElement | null>(null);\n const latest = useRef(options);\n useEffect(() => {\n latest.current = options;\n });\n\n const dismiss = useCallback((restoreFocus: boolean) => {\n const o = latest.current;\n const back = opener.current ?? o.fallbackFocus?.() ?? null;\n opener.current = null;\n // Closed from now on, even before the parent re-renders: moving focus out must not close it twice.\n latest.current = { ...o, open: false };\n o.onDismiss();\n if (restoreFocus) back?.focus();\n }, []);\n\n useEffect(() => {\n if (!options.open) return;\n const onDown = (e: PointerEvent) => {\n const root = latest.current.ref.current;\n if (root && e.target instanceof Node && root.contains(e.target)) return;\n opener.current = null;\n latest.current.onDismiss();\n };\n document.addEventListener('pointerdown', onDown);\n return () => document.removeEventListener('pointerdown', onDown);\n }, [options.open]);\n\n const containerProps = {\n onKeyDown: (e: KeyboardEvent) => {\n if (e.key === 'Escape' && latest.current.open) {\n e.preventDefault();\n e.stopPropagation();\n dismiss(true);\n }\n },\n onBlur: (e: FocusEvent) => {\n const root = latest.current.ref.current;\n const to = e.relatedTarget;\n if (latest.current.open && to instanceof Node && root && !root.contains(to)) dismiss(false);\n },\n };\n\n /** Records the element that opened the panel (focus goes back to it on Escape). */\n const opened = useCallback((el: HTMLElement | null) => {\n opener.current = el;\n }, []);\n\n return { opened, dismiss, containerProps };\n}\n"],"mappings":";;;;;;;;AAuBA,SAAgB,WAAW,SAAyB;CAClD,MAAM,SAAS,OAA2B,IAAI;CAC9C,MAAM,SAAS,OAAO,OAAO;CAC7B,gBAAgB;EACd,OAAO,UAAU;CACnB,CAAC;CAED,MAAM,UAAU,aAAa,iBAA0B;EACrD,MAAM,IAAI,OAAO;EACjB,MAAM,OAAO,OAAO,WAAW,EAAE,gBAAgB,KAAK;EACtD,OAAO,UAAU;EAEjB,OAAO,UAAU;GAAE,GAAG;GAAG,MAAM;EAAM;EACrC,EAAE,UAAU;EACZ,IAAI,cAAc,MAAM,MAAM;CAChC,GAAG,CAAC,CAAC;CAEL,gBAAgB;EACd,IAAI,CAAC,QAAQ,MAAM;EACnB,MAAM,UAAU,MAAoB;GAClC,MAAM,OAAO,OAAO,QAAQ,IAAI;GAChC,IAAI,QAAQ,EAAE,kBAAkB,QAAQ,KAAK,SAAS,EAAE,MAAM,GAAG;GACjE,OAAO,UAAU;GACjB,OAAO,QAAQ,UAAU;EAC3B;EACA,SAAS,iBAAiB,eAAe,MAAM;EAC/C,aAAa,SAAS,oBAAoB,eAAe,MAAM;CACjE,GAAG,CAAC,QAAQ,IAAI,CAAC;CAsBjB,OAAO;EAAE,QAJM,aAAa,OAA2B;GACrD,OAAO,UAAU;EACnB,GAAG,CAAC,CAEU;EAAG;EAAS,gBAAA;GAnBxB,YAAY,MAAqB;IAC/B,IAAI,EAAE,QAAQ,YAAY,OAAO,QAAQ,MAAM;KAC7C,EAAE,eAAe;KACjB,EAAE,gBAAgB;KAClB,QAAQ,IAAI;IACd;GACF;GACA,SAAS,MAAkB;IACzB,MAAM,OAAO,OAAO,QAAQ,IAAI;IAChC,MAAM,KAAK,EAAE;IACb,IAAI,OAAO,QAAQ,QAAQ,cAAc,QAAQ,QAAQ,CAAC,KAAK,SAAS,EAAE,GAAG,QAAQ,KAAK;GAC5F;EAQqC;CAAE;AAC3C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { RefObject } from "react";
|
|
3
|
+
/** Marks the active `mark.slurp-mark` inside root and scrolls it to the middle; returns how many there are. */
|
|
4
|
+
export declare function focusHit(root: HTMLElement | null, index: number, smooth?: boolean): number;
|
|
5
|
+
export interface FindInPage {
|
|
6
|
+
/** Matches found in the root (the `Mark`s rendered for the query). */
|
|
7
|
+
count: number;
|
|
8
|
+
/** The active match, 0-based. */
|
|
9
|
+
index: number;
|
|
10
|
+
/** Next (+1) or previous (−1) match, looping: Enter / Shift+Enter, or a tap on the counter. */
|
|
11
|
+
step: (delta: 1 | -1) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Find in page: render the page's text through `<Mark text query />`, pass the same query here. The active match is
|
|
15
|
+
* filled and scrolled to the middle; a new query starts again from the first match.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useFindInPage(root: RefObject<HTMLElement | null>, query: string): FindInPage;
|
|
18
|
+
//# sourceMappingURL=useFindInPage.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useLayoutEffect, useState } from "react";
|
|
3
|
+
// src/utils/useFindInPage.ts
|
|
4
|
+
/** Marks the active `mark.slurp-mark` inside root and scrolls it to the middle; returns how many there are. */
|
|
5
|
+
function focusHit(root, index, smooth = true) {
|
|
6
|
+
const hits = root ? [...root.querySelectorAll("mark.slurp-mark")] : [];
|
|
7
|
+
const current = hits.length ? hits[(index % hits.length + hits.length) % hits.length] : null;
|
|
8
|
+
for (const m of hits) if (m === current) m.dataset.active = "";
|
|
9
|
+
else delete m.dataset.active;
|
|
10
|
+
current?.scrollIntoView?.({
|
|
11
|
+
behavior: smooth ? "smooth" : "auto",
|
|
12
|
+
block: "center"
|
|
13
|
+
});
|
|
14
|
+
return hits.length;
|
|
15
|
+
}
|
|
16
|
+
const reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
17
|
+
/**
|
|
18
|
+
* Find in page: render the page's text through `<Mark text query />`, pass the same query here. The active match is
|
|
19
|
+
* filled and scrolled to the middle; a new query starts again from the first match.
|
|
20
|
+
*/
|
|
21
|
+
function useFindInPage(root, query) {
|
|
22
|
+
const [state, setState] = useState({
|
|
23
|
+
query,
|
|
24
|
+
index: 0
|
|
25
|
+
});
|
|
26
|
+
const [count, setCount] = useState(0);
|
|
27
|
+
const index = state.query === query ? state.index : 0;
|
|
28
|
+
if (state.query !== query) setState({
|
|
29
|
+
query,
|
|
30
|
+
index: 0
|
|
31
|
+
});
|
|
32
|
+
useLayoutEffect(() => {
|
|
33
|
+
setCount(query.trim() ? focusHit(root.current, index, !reduced()) : 0);
|
|
34
|
+
}, [
|
|
35
|
+
root,
|
|
36
|
+
query,
|
|
37
|
+
index
|
|
38
|
+
]);
|
|
39
|
+
const step = useCallback((delta) => setState((s) => ({
|
|
40
|
+
...s,
|
|
41
|
+
index: count ? ((s.index + delta) % count + count) % count : 0
|
|
42
|
+
})), [count]);
|
|
43
|
+
return {
|
|
44
|
+
count,
|
|
45
|
+
index: count ? index : 0,
|
|
46
|
+
step
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { focusHit, useFindInPage };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=useFindInPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFindInPage.js","names":[],"sources":["../../src/utils/useFindInPage.ts"],"sourcesContent":["import { useCallback, useLayoutEffect, useState, type RefObject } from 'react';\n\n/** Marks the active `mark.slurp-mark` inside root and scrolls it to the middle; returns how many there are. */\nexport function focusHit(root: HTMLElement | null, index: number, smooth = true): number {\n const hits = root ? [...root.querySelectorAll<HTMLElement>('mark.slurp-mark')] : [];\n const current = hits.length ? hits[((index % hits.length) + hits.length) % hits.length] : null;\n for (const m of hits) {\n if (m === current) m.dataset.active = '';\n else delete m.dataset.active;\n }\n current?.scrollIntoView?.({ behavior: smooth ? 'smooth' : 'auto', block: 'center' });\n return hits.length;\n}\n\nexport interface FindInPage {\n /** Matches found in the root (the `Mark`s rendered for the query). */\n count: number;\n /** The active match, 0-based. */\n index: number;\n /** Next (+1) or previous (−1) match, looping: Enter / Shift+Enter, or a tap on the counter. */\n step: (delta: 1 | -1) => void;\n}\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/**\n * Find in page: render the page's text through `<Mark text query />`, pass the same query here. The active match is\n * filled and scrolled to the middle; a new query starts again from the first match.\n */\nexport function useFindInPage(root: RefObject<HTMLElement | null>, query: string): FindInPage {\n const [state, setState] = useState({ query, index: 0 });\n const [count, setCount] = useState(0);\n const index = state.query === query ? state.index : 0;\n if (state.query !== query) setState({ query, index: 0 });\n\n useLayoutEffect(() => {\n // The matches are the marks just rendered: they can only be counted from the DOM after the commit.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setCount(query.trim() ? focusHit(root.current, index, !reduced()) : 0);\n }, [root, query, index]);\n\n const step = useCallback(\n (delta: 1 | -1) =>\n setState((s) => ({ ...s, index: count ? (((s.index + delta) % count) + count) % count : 0 })),\n [count],\n );\n return { count, index: count ? index : 0, step };\n}\n"],"mappings":";;;;AAGA,SAAgB,SAAS,MAA0B,OAAe,SAAS,MAAc;CACvF,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,iBAA8B,iBAAiB,CAAC,IAAI,CAAC;CAClF,MAAM,UAAU,KAAK,SAAS,MAAO,QAAQ,KAAK,SAAU,KAAK,UAAU,KAAK,UAAU;CAC1F,KAAK,MAAM,KAAK,MACd,IAAI,MAAM,SAAS,EAAE,QAAQ,SAAS;MACjC,OAAO,EAAE,QAAQ;CAExB,SAAS,iBAAiB;EAAE,UAAU,SAAS,WAAW;EAAQ,OAAO;CAAS,CAAC;CACnF,OAAO,KAAK;AACd;AAWA,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;;;;AAMrF,SAAgB,cAAc,MAAqC,OAA2B;CAC5F,MAAM,CAAC,OAAO,YAAY,SAAS;EAAE;EAAO,OAAO;CAAE,CAAC;CACtD,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,QAAQ,MAAM,UAAU,QAAQ,MAAM,QAAQ;CACpD,IAAI,MAAM,UAAU,OAAO,SAAS;EAAE;EAAO,OAAO;CAAE,CAAC;CAEvD,sBAAsB;EAGpB,SAAS,MAAM,KAAK,IAAI,SAAS,KAAK,SAAS,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;CACvE,GAAG;EAAC;EAAM;EAAO;CAAK,CAAC;CAEvB,MAAM,OAAO,aACV,UACC,UAAU,OAAO;EAAE,GAAG;EAAG,OAAO,UAAW,EAAE,QAAQ,SAAS,QAAS,SAAS,QAAQ;CAAE,EAAE,GAC9F,CAAC,KAAK,CACR;CACA,OAAO;EAAE;EAAO,OAAO,QAAQ,QAAQ;EAAG;CAAK;AACjD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
import { Ref } from "react";
|
|
3
|
+
/** One ref for two: returns the only defined ref as is, so a single ref costs nothing. */
|
|
4
|
+
export declare function useForkRef<T>(a: Ref<T> | undefined, b: Ref<T> | undefined): Ref<T> | undefined;
|
|
5
|
+
//# sourceMappingURL=useForkRef.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
// src/utils/useForkRef.ts
|
|
4
|
+
/** Sets a ref and returns how to clear it (React 19 ref callbacks may return their own cleanup). */
|
|
5
|
+
function assign(ref, value) {
|
|
6
|
+
if (typeof ref === "function") {
|
|
7
|
+
const cleanup = ref(value);
|
|
8
|
+
return typeof cleanup === "function" ? cleanup : () => ref(null);
|
|
9
|
+
}
|
|
10
|
+
if (ref) {
|
|
11
|
+
ref.current = value;
|
|
12
|
+
return () => {
|
|
13
|
+
ref.current = null;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return () => void 0;
|
|
17
|
+
}
|
|
18
|
+
/** One ref for two: returns the only defined ref as is, so a single ref costs nothing. */
|
|
19
|
+
function useForkRef(a, b) {
|
|
20
|
+
return useMemo(() => {
|
|
21
|
+
if (!a || !b) return a ?? b;
|
|
22
|
+
const merged = (value) => {
|
|
23
|
+
const clear = [assign(a, value), assign(b, value)];
|
|
24
|
+
return () => {
|
|
25
|
+
for (const c of clear) c();
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
return merged;
|
|
29
|
+
}, [a, b]);
|
|
30
|
+
}
|
|
31
|
+
export { useForkRef };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=useForkRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useForkRef.js","names":[],"sources":["../../src/utils/useForkRef.ts"],"sourcesContent":["import { useMemo, type Ref, type RefCallback } from 'react';\n\n/** Sets a ref and returns how to clear it (React 19 ref callbacks may return their own cleanup). */\nfunction assign<T>(ref: Ref<T> | undefined, value: T | null): () => void {\n if (typeof ref === 'function') {\n const cleanup = ref(value);\n return typeof cleanup === 'function' ? cleanup : () => ref(null);\n }\n if (ref) {\n ref.current = value as T;\n return () => {\n ref.current = null as T;\n };\n }\n return () => undefined;\n}\n\n/** One ref for two: returns the only defined ref as is, so a single ref costs nothing. */\nexport function useForkRef<T>(a: Ref<T> | undefined, b: Ref<T> | undefined): Ref<T> | undefined {\n return useMemo((): Ref<T> | undefined => {\n if (!a || !b) return a ?? b;\n const merged: RefCallback<T> = (value) => {\n const clear = [assign(a, value), assign(b, value)];\n return () => {\n for (const c of clear) c();\n };\n };\n return merged;\n }, [a, b]);\n}\n"],"mappings":";;;;AAGA,SAAS,OAAU,KAAyB,OAA6B;CACvE,IAAI,OAAO,QAAQ,YAAY;EAC7B,MAAM,UAAU,IAAI,KAAK;EACzB,OAAO,OAAO,YAAY,aAAa,gBAAgB,IAAI,IAAI;CACjE;CACA,IAAI,KAAK;EACP,IAAI,UAAU;EACd,aAAa;GACX,IAAI,UAAU;EAChB;CACF;CACA,aAAa,KAAA;AACf;;AAGA,SAAgB,WAAc,GAAuB,GAA2C;CAC9F,OAAO,cAAkC;EACvC,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,KAAK;EAC1B,MAAM,UAA0B,UAAU;GACxC,MAAM,QAAQ,CAAC,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,KAAK,CAAC;GACjD,aAAa;IACX,KAAK,MAAM,KAAK,OAAO,EAAE;GAC3B;EACF;EACA,OAAO;CACT,GAAG,CAAC,GAAG,CAAC,CAAC;AACX"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
import { COMPACT_QUERY as COMPACT_QUERY$1 } from "@slurp-ui/tokens";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a media query matches, kept in sync. During server rendering (and hydration) it returns `defaultMatches`.
|
|
5
|
+
* `useMediaQuery(COMPACT_QUERY)` is the design system's phone layout.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useMediaQuery(query: string, { defaultMatches }?: {
|
|
8
|
+
defaultMatches?: boolean | undefined;
|
|
9
|
+
}): boolean;
|
|
10
|
+
export { COMPACT_QUERY$1 as COMPACT_QUERY };
|
|
11
|
+
//# sourceMappingURL=useMediaQuery.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
3
|
+
import { COMPACT_QUERY as COMPACT_QUERY$1 } from "@slurp-ui/tokens";
|
|
4
|
+
// src/utils/useMediaQuery.ts
|
|
5
|
+
const canMatch = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
6
|
+
/**
|
|
7
|
+
* Whether a media query matches, kept in sync. During server rendering (and hydration) it returns `defaultMatches`.
|
|
8
|
+
* `useMediaQuery(COMPACT_QUERY)` is the design system's phone layout.
|
|
9
|
+
*/
|
|
10
|
+
function useMediaQuery(query, { defaultMatches = false } = {}) {
|
|
11
|
+
const subscribe = useCallback((onChange) => {
|
|
12
|
+
if (!canMatch()) return () => void 0;
|
|
13
|
+
const mq = window.matchMedia(query);
|
|
14
|
+
mq.addEventListener("change", onChange);
|
|
15
|
+
return () => mq.removeEventListener("change", onChange);
|
|
16
|
+
}, [query]);
|
|
17
|
+
return useSyncExternalStore(subscribe, () => canMatch() ? window.matchMedia(query).matches : defaultMatches, () => defaultMatches);
|
|
18
|
+
}
|
|
19
|
+
export { COMPACT_QUERY$1 as COMPACT_QUERY, useMediaQuery };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=useMediaQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaQuery.js","names":[],"sources":["../../src/utils/useMediaQuery.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\n\nexport { COMPACT_QUERY } from '@slurp-ui/tokens';\n\nconst canMatch = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function';\n\n/**\n * Whether a media query matches, kept in sync. During server rendering (and hydration) it returns `defaultMatches`.\n * `useMediaQuery(COMPACT_QUERY)` is the design system's phone layout.\n */\nexport function useMediaQuery(query: string, { defaultMatches = false } = {}): boolean {\n const subscribe = useCallback(\n (onChange: () => void) => {\n if (!canMatch()) return () => undefined;\n const mq = window.matchMedia(query);\n mq.addEventListener('change', onChange);\n return () => mq.removeEventListener('change', onChange);\n },\n [query],\n );\n return useSyncExternalStore(\n subscribe,\n () => (canMatch() ? window.matchMedia(query).matches : defaultMatches),\n () => defaultMatches,\n );\n}\n"],"mappings":";;;;AAIA,MAAM,iBAAiB,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe;;;;;AAMrF,SAAgB,cAAc,OAAe,EAAE,iBAAiB,UAAU,CAAC,GAAY;CACrF,MAAM,YAAY,aACf,aAAyB;EACxB,IAAI,CAAC,SAAS,GAAG,aAAa,KAAA;EAC9B,MAAM,KAAK,OAAO,WAAW,KAAK;EAClC,GAAG,iBAAiB,UAAU,QAAQ;EACtC,aAAa,GAAG,oBAAoB,UAAU,QAAQ;CACxD,GACA,CAAC,KAAK,CACR;CACA,OAAO,qBACL,iBACO,SAAS,IAAI,OAAO,WAAW,KAAK,CAAC,CAAC,UAAU,sBACjD,cACR;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import { MoveFocusOptions } from "./focus.js";
|
|
3
|
+
import { KeyboardEvent, RefObject } from "react";
|
|
4
|
+
export interface RovingFocusOptions extends Pick<MoveFocusOptions, 'orientation' | 'loop'> {
|
|
5
|
+
/** The items, inside the container. */
|
|
6
|
+
selector: string;
|
|
7
|
+
/** Selection follows focus (tabs, segmented controls): the item reached is also clicked. */
|
|
8
|
+
select?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* One tab stop for a group (tabIndex 0 on the active item, -1 on the others) and arrow keys between the items.
|
|
12
|
+
* Spread the returned onKeyDown on the container.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useRovingFocus(ref: RefObject<HTMLElement | null>, { selector, orientation, loop, select }: RovingFocusOptions): {
|
|
15
|
+
onKeyDown: (e: KeyboardEvent) => void;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=useRovingFocus.d.ts.map
|