@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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DEFAULT_STORAGE_KEY, defaultTheme, styleId, themeCss } from "../lib/theme.js";
|
|
3
|
+
import { SlurpContext } from "../internal/context.js";
|
|
4
|
+
import { useCallback, useContext, useEffect, useId, useMemo, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/SlurpProvider/SlurpProvider.tsx
|
|
7
|
+
const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
8
|
+
const isMode = (v) => v === "light" || v === "dark" || v === "system";
|
|
9
|
+
function readStored(key) {
|
|
10
|
+
if (!key) return null;
|
|
11
|
+
try {
|
|
12
|
+
const v = window.localStorage.getItem(key);
|
|
13
|
+
return isMode(v) ? v : null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
19
|
+
function subscribeStorage(onChange) {
|
|
20
|
+
listeners.add(onChange);
|
|
21
|
+
window.addEventListener("storage", onChange);
|
|
22
|
+
return () => {
|
|
23
|
+
listeners.delete(onChange);
|
|
24
|
+
window.removeEventListener("storage", onChange);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function subscribeSystem(onChange) {
|
|
28
|
+
const query = window.matchMedia?.(DARK_QUERY);
|
|
29
|
+
query?.addEventListener("change", onChange);
|
|
30
|
+
return () => query?.removeEventListener("change", onChange);
|
|
31
|
+
}
|
|
32
|
+
const systemSnapshot = () => window.matchMedia?.(DARK_QUERY).matches ? "dark" : "light";
|
|
33
|
+
/** Writes `data-theme` on <html>: `light` / `dark`, or no attribute for `system` (prefers-color-scheme decides). */
|
|
34
|
+
function applyMode(mode) {
|
|
35
|
+
const root = document.documentElement;
|
|
36
|
+
if (mode === "system") root.removeAttribute("data-theme");
|
|
37
|
+
else root.setAttribute("data-theme", mode);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Theme, colour scheme and runtime styles for everything inside.
|
|
41
|
+
* At the app root it renders no element: the colour scheme goes on <html data-theme>, theme overrides into one
|
|
42
|
+
* hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the
|
|
43
|
+
* colour scheme of the outer provider.
|
|
44
|
+
*/
|
|
45
|
+
function SlurpProvider({ theme = defaultTheme, storageKey = DEFAULT_STORAGE_KEY, children }) {
|
|
46
|
+
const outer = useContext(SlurpContext).colorScheme;
|
|
47
|
+
const scope = useId();
|
|
48
|
+
const stored = useSyncExternalStore(subscribeStorage, () => readStored(storageKey), () => null);
|
|
49
|
+
const [local, setLocal] = useState(null);
|
|
50
|
+
const mode = local ?? stored ?? theme.colorScheme;
|
|
51
|
+
const system = useSyncExternalStore(subscribeSystem, systemSnapshot, () => "light");
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!outer) applyMode(local ?? readStored(storageKey) ?? theme.colorScheme);
|
|
54
|
+
}, [
|
|
55
|
+
outer,
|
|
56
|
+
mode,
|
|
57
|
+
local,
|
|
58
|
+
storageKey,
|
|
59
|
+
theme.colorScheme
|
|
60
|
+
]);
|
|
61
|
+
const setMode = useCallback((next) => {
|
|
62
|
+
if (!storageKey) return setLocal(next);
|
|
63
|
+
try {
|
|
64
|
+
window.localStorage.setItem(storageKey, next);
|
|
65
|
+
setLocal(null);
|
|
66
|
+
} catch {
|
|
67
|
+
setLocal(next);
|
|
68
|
+
}
|
|
69
|
+
for (const notify of listeners) notify();
|
|
70
|
+
}, [storageKey]);
|
|
71
|
+
const own = useMemo(() => ({
|
|
72
|
+
mode,
|
|
73
|
+
setMode,
|
|
74
|
+
resolved: mode === "system" ? system : mode
|
|
75
|
+
}), [
|
|
76
|
+
mode,
|
|
77
|
+
setMode,
|
|
78
|
+
system
|
|
79
|
+
]);
|
|
80
|
+
const colorScheme = outer ?? own;
|
|
81
|
+
const value = useMemo(() => ({
|
|
82
|
+
theme,
|
|
83
|
+
colorScheme
|
|
84
|
+
}), [theme, colorScheme]);
|
|
85
|
+
const css = useMemo(() => themeCss(theme, outer ? scope : void 0), [
|
|
86
|
+
theme,
|
|
87
|
+
outer,
|
|
88
|
+
scope
|
|
89
|
+
]);
|
|
90
|
+
const style = css && /* @__PURE__ */ jsx("style", {
|
|
91
|
+
href: styleId("theme", css),
|
|
92
|
+
precedence: "slurp",
|
|
93
|
+
children: css
|
|
94
|
+
});
|
|
95
|
+
return /* @__PURE__ */ jsxs(SlurpContext, {
|
|
96
|
+
value,
|
|
97
|
+
children: [style, outer ? /* @__PURE__ */ jsx("div", {
|
|
98
|
+
"data-slurp-theme": scope,
|
|
99
|
+
style: { display: "contents" },
|
|
100
|
+
children
|
|
101
|
+
}) : children]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export { SlurpProvider };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=SlurpProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlurpProvider.js","names":[],"sources":["../../src/SlurpProvider/SlurpProvider.tsx"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from 'react';\n\nimport { SlurpContext, type ColorSchemeState } from '../internal/context';\nimport {\n DEFAULT_STORAGE_KEY,\n defaultTheme,\n styleId,\n themeCss,\n type ColorSchemeMode,\n type Theme,\n} from '../lib/theme';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\nexport interface SlurpProviderProps {\n /** From `createTheme()`. */\n theme?: Theme;\n /** localStorage key that remembers the chosen scheme; `null` disables persistence. Default `slurp-theme`. */\n storageKey?: string | null;\n children?: ReactNode;\n}\n\nconst isMode = (v: unknown): v is ColorSchemeMode =>\n v === 'light' || v === 'dark' || v === 'system';\n\n// Storage can throw (private mode, blocked site data): every access is guarded and simply falls back.\nfunction readStored(key: string | null): ColorSchemeMode | null {\n if (!key) return null;\n try {\n const v = window.localStorage.getItem(key);\n return isMode(v) ? v : null;\n } catch {\n return null;\n }\n}\n\nconst listeners = new Set<() => void>();\nfunction subscribeStorage(onChange: () => void) {\n listeners.add(onChange);\n window.addEventListener('storage', onChange);\n return () => {\n listeners.delete(onChange);\n window.removeEventListener('storage', onChange);\n };\n}\n\nfunction subscribeSystem(onChange: () => void) {\n const query = window.matchMedia?.(DARK_QUERY);\n query?.addEventListener('change', onChange);\n return () => query?.removeEventListener('change', onChange);\n}\nconst systemSnapshot = () => (window.matchMedia?.(DARK_QUERY).matches ? 'dark' : 'light');\n\n/** Writes `data-theme` on <html>: `light` / `dark`, or no attribute for `system` (prefers-color-scheme decides). */\nfunction applyMode(mode: ColorSchemeMode) {\n const root = document.documentElement;\n if (mode === 'system') root.removeAttribute('data-theme');\n else root.setAttribute('data-theme', mode);\n}\n\n/**\n * Theme, colour scheme and runtime styles for everything inside.\n * At the app root it renders no element: the colour scheme goes on <html data-theme>, theme overrides into one\n * hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the\n * colour scheme of the outer provider.\n */\nexport function SlurpProvider({\n theme = defaultTheme,\n storageKey = DEFAULT_STORAGE_KEY,\n children,\n}: SlurpProviderProps) {\n const outer = useContext(SlurpContext).colorScheme;\n const scope = useId();\n const stored = useSyncExternalStore(\n subscribeStorage,\n () => readStored(storageKey),\n () => null,\n );\n // A choice that could not be stored (or storage disabled) lives in state and wins over the stored one.\n const [local, setLocal] = useState<ColorSchemeMode | null>(null);\n const mode = local ?? stored ?? theme.colorScheme;\n const system = useSyncExternalStore(subscribeSystem, systemSnapshot, () => 'light' as const);\n\n // Reads storage again: during hydration `stored` is still the server snapshot (null) for one render.\n useEffect(() => {\n if (!outer) applyMode(local ?? readStored(storageKey) ?? theme.colorScheme);\n }, [outer, mode, local, storageKey, theme.colorScheme]);\n\n const setMode = useCallback(\n (next: ColorSchemeMode) => {\n if (!storageKey) return setLocal(next);\n try {\n window.localStorage.setItem(storageKey, next);\n setLocal(null);\n } catch {\n setLocal(next);\n }\n for (const notify of listeners) notify();\n },\n [storageKey],\n );\n\n const own = useMemo<ColorSchemeState>(\n () => ({ mode, setMode, resolved: mode === 'system' ? system : mode }),\n [mode, setMode, system],\n );\n const colorScheme = outer ?? own;\n const value = useMemo(() => ({ theme, colorScheme }), [theme, colorScheme]);\n const css = useMemo(() => themeCss(theme, outer ? scope : undefined), [theme, outer, scope]);\n\n const style = css && (\n <style href={styleId('theme', css)} precedence=\"slurp\">\n {css}\n </style>\n );\n return (\n <SlurpContext value={value}>\n {style}\n {outer ? (\n <div data-slurp-theme={scope} style={{ display: 'contents' }}>\n {children}\n </div>\n ) : (\n children\n )}\n </SlurpContext>\n );\n}\n"],"mappings":";;;;;;AAqBA,MAAM,aAAa;AAUnB,MAAM,UAAU,MACd,MAAM,WAAW,MAAM,UAAU,MAAM;AAGzC,SAAS,WAAW,KAA4C;CAC9D,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI;EACF,MAAM,IAAI,OAAO,aAAa,QAAQ,GAAG;EACzC,OAAO,OAAO,CAAC,IAAI,IAAI;CACzB,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,4BAAY,IAAI,IAAgB;AACtC,SAAS,iBAAiB,UAAsB;CAC9C,UAAU,IAAI,QAAQ;CACtB,OAAO,iBAAiB,WAAW,QAAQ;CAC3C,aAAa;EACX,UAAU,OAAO,QAAQ;EACzB,OAAO,oBAAoB,WAAW,QAAQ;CAChD;AACF;AAEA,SAAS,gBAAgB,UAAsB;CAC7C,MAAM,QAAQ,OAAO,aAAa,UAAU;CAC5C,OAAO,iBAAiB,UAAU,QAAQ;CAC1C,aAAa,OAAO,oBAAoB,UAAU,QAAQ;AAC5D;AACA,MAAM,uBAAwB,OAAO,aAAa,UAAU,CAAC,CAAC,UAAU,SAAS;;AAGjF,SAAS,UAAU,MAAuB;CACxC,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,UAAU,KAAK,gBAAgB,YAAY;MACnD,KAAK,aAAa,cAAc,IAAI;AAC3C;;;;;;;AAQA,SAAgB,cAAc,EAC5B,QAAQ,cACR,aAAa,qBACb,YACqB;CACrB,MAAM,QAAQ,WAAW,YAAY,CAAC,CAAC;CACvC,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,qBACb,wBACM,WAAW,UAAU,SACrB,IACR;CAEA,MAAM,CAAC,OAAO,YAAY,SAAiC,IAAI;CAC/D,MAAM,OAAO,SAAS,UAAU,MAAM;CACtC,MAAM,SAAS,qBAAqB,iBAAiB,sBAAsB,OAAgB;CAG3F,gBAAgB;EACd,IAAI,CAAC,OAAO,UAAU,SAAS,WAAW,UAAU,KAAK,MAAM,WAAW;CAC5E,GAAG;EAAC;EAAO;EAAM;EAAO;EAAY,MAAM;CAAW,CAAC;CAEtD,MAAM,UAAU,aACb,SAA0B;EACzB,IAAI,CAAC,YAAY,OAAO,SAAS,IAAI;EACrC,IAAI;GACF,OAAO,aAAa,QAAQ,YAAY,IAAI;GAC5C,SAAS,IAAI;EACf,QAAQ;GACN,SAAS,IAAI;EACf;EACA,KAAK,MAAM,UAAU,WAAW,OAAO;CACzC,GACA,CAAC,UAAU,CACb;CAEA,MAAM,MAAM,eACH;EAAE;EAAM;EAAS,UAAU,SAAS,WAAW,SAAS;CAAK,IACpE;EAAC;EAAM;EAAS;CAAM,CACxB;CACA,MAAM,cAAc,SAAS;CAC7B,MAAM,QAAQ,eAAe;EAAE;EAAO;CAAY,IAAI,CAAC,OAAO,WAAW,CAAC;CAC1E,MAAM,MAAM,cAAc,SAAS,OAAO,QAAQ,QAAQ,KAAA,CAAS,GAAG;EAAC;EAAO;EAAO;CAAK,CAAC;CAE3F,MAAM,QAAQ,OACZ,oBAAC,SAAD;EAAO,MAAM,QAAQ,SAAS,GAAG;EAAG,YAAW;EAC5C,UAAA;CACI,CAAA;CAET,OACE,qBAAC,cAAD;EAAqB;EAArB,UAAA,CACG,OACA,QACC,oBAAC,OAAD;GAAK,oBAAkB;GAAO,OAAO,EAAE,SAAS,WAAW;GACxD;EACE,CAAA,IAEL,QAEU;;AAElB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
import { SlurpProvider, SlurpProviderProps } from "./SlurpProvider.js";
|
|
3
|
+
import { ColorSchemeScript, ColorSchemeScriptProps } from "./ColorSchemeScript.js";
|
|
4
|
+
import { ColorSchemeState, useColorScheme, useTheme } from "../internal/context.js";
|
|
5
|
+
export { ColorSchemeScript, type ColorSchemeScriptProps, type ColorSchemeState, SlurpProvider, type SlurpProviderProps, SlurpProvider as default, useColorScheme, useTheme };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
import { useColorScheme, useTheme } from "../internal/context.js";
|
|
3
|
+
import { SlurpProvider } from "./SlurpProvider.js";
|
|
4
|
+
import { ColorSchemeScript } from "./ColorSchemeScript.js";
|
|
5
|
+
export { ColorSchemeScript, SlurpProvider, SlurpProvider as default, useColorScheme, useTheme };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export interface StageOwnProps {
|
|
5
|
+
/** Tint of the stage; default the accent. */
|
|
6
|
+
color?: string;
|
|
7
|
+
}
|
|
8
|
+
export type StageProps<E extends ElementType = 'div'> = PolymorphicProps<E, StageOwnProps>;
|
|
9
|
+
/**
|
|
10
|
+
* Stage for any media: a tinted surface with one soft round glow (breathing slowly) and one smooth ring. Photos and
|
|
11
|
+
* placeholder shapes sit on it; round geometry only.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Stage<E extends ElementType = 'div'>(props: StageProps<E>): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=Stage.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../utils/src/index.js";
|
|
3
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/Stage/Stage.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Stage for any media: a tinted surface with one soft round glow (breathing slowly) and one smooth ring. Photos and
|
|
9
|
+
* placeholder shapes sit on it; round geometry only.
|
|
10
|
+
*/
|
|
11
|
+
function Stage(props) {
|
|
12
|
+
const { as, css, className, color, style, children, ...rest } = useThemeProps("Stage", props);
|
|
13
|
+
const Root = as ?? "div";
|
|
14
|
+
const styled = useCss("Stage", "root", css);
|
|
15
|
+
const root = useAnimationRoot(rest);
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
17
|
+
className: cx("slurp-stage", styled.className, className),
|
|
18
|
+
style: {
|
|
19
|
+
...color ? { "--slurp-stage-color": color } : null,
|
|
20
|
+
...style
|
|
21
|
+
},
|
|
22
|
+
...root,
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ jsx("span", {
|
|
25
|
+
className: "slurp-stage-glow",
|
|
26
|
+
"aria-hidden": "true"
|
|
27
|
+
}),
|
|
28
|
+
/* @__PURE__ */ jsx("span", {
|
|
29
|
+
className: "slurp-stage-ring",
|
|
30
|
+
"aria-hidden": "true"
|
|
31
|
+
}),
|
|
32
|
+
children
|
|
33
|
+
]
|
|
34
|
+
})] });
|
|
35
|
+
}
|
|
36
|
+
export { Stage };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=Stage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Stage.js","names":[],"sources":["../../src/Stage/Stage.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { CSSProperties, ElementType } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface StageOwnProps {\n /** Tint of the stage; default the accent. */\n color?: string;\n}\n\nexport type StageProps<E extends ElementType = 'div'> = PolymorphicProps<E, StageOwnProps>;\n\n/**\n * Stage for any media: a tinted surface with one soft round glow (breathing slowly) and one smooth ring. Photos and\n * placeholder shapes sit on it; round geometry only.\n */\nexport function Stage<E extends ElementType = 'div'>(props: StageProps<E>) {\n const { as, css, className, color, style, children, ...rest } = useThemeProps(\n 'Stage',\n props as StageProps,\n );\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Stage', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-stage', styled.className, className)}\n style={{ ...(color ? { '--slurp-stage-color': color } : null), ...style } as CSSProperties}\n {...root}\n >\n <span className=\"slurp-stage-glow\" aria-hidden=\"true\" />\n <span className=\"slurp-stage-ring\" aria-hidden=\"true\" />\n {children}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,MAAqC,OAAsB;CACzE,MAAM,EAAE,IAAI,KAAK,WAAW,OAAO,OAAO,UAAU,GAAG,SAAS,cAC9D,SACA,KACF;CACA,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,WAAW,GAAG,eAAe,OAAO,WAAW,SAAS;EACxD,OAAO;GAAE,GAAI,QAAQ,EAAE,uBAAuB,MAAM,IAAI;GAAO,GAAG;EAAM;EACxE,GAAI;EAHN,UAAA;GAKE,oBAAC,QAAD;IAAM,WAAU;IAAmB,eAAY;GAAQ,CAAA;GACvD,oBAAC,QAAD;IAAM,WAAU;IAAmB,eAAY;GAAQ,CAAA;GACtD;EACG;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export interface SurfaceOwnProps {
|
|
5
|
+
/** `surface` translucent (default) · `dock` near-opaque · `solid` opaque `surface-2`, no blur. */
|
|
6
|
+
level?: 'surface' | 'dock' | 'solid';
|
|
7
|
+
/** Radius token: `card` for cards and small panels (default), `panel` for large ones, `full` for bars. */
|
|
8
|
+
radius?: 'sm' | 'md' | 'lg' | 'card' | 'panel' | 'full';
|
|
9
|
+
}
|
|
10
|
+
export type SurfaceProps<E extends ElementType = 'div'> = PolymorphicProps<E, SurfaceOwnProps>;
|
|
11
|
+
/**
|
|
12
|
+
* Floating surface: fill, `blur-surface`, decorative `line` hairline, `shadow-float`.
|
|
13
|
+
* Do not nest a Surface directly in another: inside, use flat tints.
|
|
14
|
+
*/
|
|
15
|
+
export declare function Surface<E extends ElementType = 'div'>(props: SurfaceProps<E>): import("react").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=Surface.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../utils/src/index.js";
|
|
3
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/Surface/Surface.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Floating surface: fill, `blur-surface`, decorative `line` hairline, `shadow-float`.
|
|
9
|
+
* Do not nest a Surface directly in another: inside, use flat tints.
|
|
10
|
+
*/
|
|
11
|
+
function Surface(props) {
|
|
12
|
+
const { as, css, className, level = "surface", radius = "card", ...rest } = useThemeProps("Surface", props);
|
|
13
|
+
const Root = as ?? "div";
|
|
14
|
+
const styled = useCss("Surface", "root", css);
|
|
15
|
+
const root = useAnimationRoot(rest);
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
17
|
+
className: cx("slurp-surface", styled.className, className),
|
|
18
|
+
"data-level": level,
|
|
19
|
+
"data-radius": radius,
|
|
20
|
+
...root
|
|
21
|
+
})] });
|
|
22
|
+
}
|
|
23
|
+
export { Surface };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=Surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Surface.js","names":[],"sources":["../../src/Surface/Surface.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface SurfaceOwnProps {\n /** `surface` translucent (default) · `dock` near-opaque · `solid` opaque `surface-2`, no blur. */\n level?: 'surface' | 'dock' | 'solid';\n /** Radius token: `card` for cards and small panels (default), `panel` for large ones, `full` for bars. */\n radius?: 'sm' | 'md' | 'lg' | 'card' | 'panel' | 'full';\n}\n\nexport type SurfaceProps<E extends ElementType = 'div'> = PolymorphicProps<E, SurfaceOwnProps>;\n\n/**\n * Floating surface: fill, `blur-surface`, decorative `line` hairline, `shadow-float`.\n * Do not nest a Surface directly in another: inside, use flat tints.\n */\nexport function Surface<E extends ElementType = 'div'>(props: SurfaceProps<E>) {\n const {\n as,\n css,\n className,\n level = 'surface',\n radius = 'card',\n ...rest\n } = useThemeProps('Surface', props as SurfaceProps);\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Surface', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-surface', styled.className, className)}\n data-level={level}\n data-radius={radius}\n {...root}\n />\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAoBA,SAAgB,QAAuC,OAAwB;CAC7E,MAAM,EACJ,IACA,KACA,WACA,QAAQ,WACR,SAAS,QACT,GAAG,SACD,cAAc,WAAW,KAAqB;CAClD,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG;CAC5C,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EACE,WAAW,GAAG,iBAAiB,OAAO,WAAW,SAAS;EAC1D,cAAY;EACZ,eAAa;EACb,GAAI;CACL,CAAA,CACD,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export interface SwatchOwnProps {
|
|
5
|
+
/** Any CSS colour. */
|
|
6
|
+
color: string;
|
|
7
|
+
/** Name of the colour: the accessible name ("Blu notte"). */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Selected = a ring around it (never colour alone). */
|
|
10
|
+
selected?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type SwatchProps<E extends ElementType = 'button'> = PolymorphicProps<E, SwatchOwnProps>;
|
|
13
|
+
/** One colour choice: a 44px circle; selected shows an accent-ink ring. Use it inside a SwatchGroup. */
|
|
14
|
+
export declare function Swatch<E extends ElementType = 'button'>(props: SwatchProps<E>): import("react").JSX.Element;
|
|
15
|
+
export interface SwatchOption {
|
|
16
|
+
value: string;
|
|
17
|
+
color: string;
|
|
18
|
+
label: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SwatchGroupOwnProps {
|
|
21
|
+
/** Name of the group ("Colore"). */
|
|
22
|
+
label: string;
|
|
23
|
+
options: SwatchOption[];
|
|
24
|
+
value?: string | null;
|
|
25
|
+
defaultValue?: string | null;
|
|
26
|
+
onValueChange?: (value: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export type SwatchGroupProps<E extends ElementType = 'div'> = PolymorphicProps<E, SwatchGroupOwnProps>;
|
|
29
|
+
/** Single colour choice: a radio group of swatches, one tab stop, arrow keys move and select. */
|
|
30
|
+
export declare function SwatchGroup<E extends ElementType = 'div'>(props: SwatchGroupProps<E>): import("react").JSX.Element;
|
|
31
|
+
//# sourceMappingURL=Swatch.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../utils/src/index.js";
|
|
3
|
+
import { useForkRef } from "../utils/useForkRef.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
7
|
+
import { useRovingFocus } from "../utils/useRovingFocus.js";
|
|
8
|
+
import { useRef } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/Swatch/Swatch.tsx
|
|
11
|
+
/** One colour choice: a 44px circle; selected shows an accent-ink ring. Use it inside a SwatchGroup. */
|
|
12
|
+
function Swatch(props) {
|
|
13
|
+
const { as, css, className, color, label, selected = false, ...rest } = useThemeProps("Swatch", props);
|
|
14
|
+
const Root = as ?? "button";
|
|
15
|
+
const styled = useCss("Swatch", "root", css);
|
|
16
|
+
const root = useAnimationRoot(rest);
|
|
17
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
18
|
+
className: cx("slurp-swatch", styled.className, className),
|
|
19
|
+
role: "radio",
|
|
20
|
+
"aria-checked": selected,
|
|
21
|
+
"aria-label": label,
|
|
22
|
+
title: label,
|
|
23
|
+
"data-selected": selected || void 0,
|
|
24
|
+
...Root === "button" ? { type: "button" } : null,
|
|
25
|
+
...root,
|
|
26
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
27
|
+
className: "slurp-swatch-fill",
|
|
28
|
+
style: { background: color }
|
|
29
|
+
})
|
|
30
|
+
})] });
|
|
31
|
+
}
|
|
32
|
+
/** Single colour choice: a radio group of swatches, one tab stop, arrow keys move and select. */
|
|
33
|
+
function SwatchGroup(props) {
|
|
34
|
+
const { as, css, className, label, options, value: valueProp, defaultValue = null, onValueChange, ref, ...rest } = useThemeProps("SwatchGroup", props);
|
|
35
|
+
const [value, setValue] = useControlled({
|
|
36
|
+
value: valueProp,
|
|
37
|
+
defaultValue,
|
|
38
|
+
onChange: onValueChange
|
|
39
|
+
});
|
|
40
|
+
const own = useRef(null);
|
|
41
|
+
const { onKeyDown } = useRovingFocus(own, {
|
|
42
|
+
selector: "[role=\"radio\"]",
|
|
43
|
+
select: true
|
|
44
|
+
});
|
|
45
|
+
const Root = as ?? "div";
|
|
46
|
+
const styled = useCss("SwatchGroup", "root", css);
|
|
47
|
+
const root = useAnimationRoot({
|
|
48
|
+
...rest,
|
|
49
|
+
ref: useForkRef(ref, own)
|
|
50
|
+
});
|
|
51
|
+
const active = options.some((o) => o.value === value) ? value : options[0]?.value;
|
|
52
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
53
|
+
className: cx("slurp-swatch-group", styled.className, className),
|
|
54
|
+
role: "radiogroup",
|
|
55
|
+
"aria-label": label,
|
|
56
|
+
onKeyDown,
|
|
57
|
+
...root,
|
|
58
|
+
children: options.map((o) => /* @__PURE__ */ jsx(Swatch, {
|
|
59
|
+
color: o.color,
|
|
60
|
+
label: o.label,
|
|
61
|
+
selected: o.value === value,
|
|
62
|
+
tabIndex: o.value === active ? 0 : -1,
|
|
63
|
+
onClick: (e) => {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
setValue(o.value);
|
|
66
|
+
}
|
|
67
|
+
}, o.value))
|
|
68
|
+
})] });
|
|
69
|
+
}
|
|
70
|
+
export { Swatch, SwatchGroup };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=Swatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Swatch.js","names":[],"sources":["../../src/Swatch/Swatch.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport { useRef, type ElementType, type MouseEvent } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\nimport { useForkRef } from '../utils/useForkRef';\nimport { useRovingFocus } from '../utils/useRovingFocus';\n\nexport interface SwatchOwnProps {\n /** Any CSS colour. */\n color: string;\n /** Name of the colour: the accessible name (\"Blu notte\"). */\n label: string;\n /** Selected = a ring around it (never colour alone). */\n selected?: boolean;\n}\n\nexport type SwatchProps<E extends ElementType = 'button'> = PolymorphicProps<E, SwatchOwnProps>;\n\n/** One colour choice: a 44px circle; selected shows an accent-ink ring. Use it inside a SwatchGroup. */\nexport function Swatch<E extends ElementType = 'button'>(props: SwatchProps<E>) {\n const {\n as,\n css,\n className,\n color,\n label,\n selected = false,\n ...rest\n } = useThemeProps('Swatch', props as SwatchProps);\n const Root = (as ?? 'button') as ElementType;\n const styled = useCss('Swatch', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-swatch', styled.className, className)}\n role=\"radio\"\n aria-checked={selected}\n aria-label={label}\n title={label}\n data-selected={selected || undefined}\n {...(Root === 'button' ? { type: 'button' } : null)}\n {...root}\n >\n <span className=\"slurp-swatch-fill\" style={{ background: color }} />\n </Root>\n </>\n );\n}\n\nexport interface SwatchOption {\n value: string;\n color: string;\n label: string;\n}\n\nexport interface SwatchGroupOwnProps {\n /** Name of the group (\"Colore\"). */\n label: string;\n options: SwatchOption[];\n value?: string | null;\n defaultValue?: string | null;\n onValueChange?: (value: string) => void;\n}\n\nexport type SwatchGroupProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n SwatchGroupOwnProps\n>;\n\n/** Single colour choice: a radio group of swatches, one tab stop, arrow keys move and select. */\nexport function SwatchGroup<E extends ElementType = 'div'>(props: SwatchGroupProps<E>) {\n const {\n as,\n css,\n className,\n label,\n options,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n ref,\n ...rest\n } = useThemeProps('SwatchGroup', props as SwatchGroupProps);\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const own = useRef<HTMLElement>(null);\n const { onKeyDown } = useRovingFocus(own, { selector: '[role=\"radio\"]', select: true });\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('SwatchGroup', 'root', css);\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, own) });\n const active = options.some((o) => o.value === value) ? value : options[0]?.value;\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-swatch-group', styled.className, className)}\n role=\"radiogroup\"\n aria-label={label}\n onKeyDown={onKeyDown}\n {...root}\n >\n {options.map((o) => (\n <Swatch\n key={o.value}\n color={o.color}\n label={o.label}\n selected={o.value === value}\n tabIndex={o.value === active ? 0 : -1}\n onClick={(e: MouseEvent) => {\n e.preventDefault();\n setValue(o.value);\n }}\n />\n ))}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAgB,OAAyC,OAAuB;CAC9E,MAAM,EACJ,IACA,KACA,WACA,OACA,OACA,WAAW,OACX,GAAG,SACD,cAAc,UAAU,KAAoB;CAChD,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,UAAU,QAAQ,GAAG;CAC3C,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EACE,WAAW,GAAG,gBAAgB,OAAO,WAAW,SAAS;EACzD,MAAK;EACL,gBAAc;EACd,cAAY;EACZ,OAAO;EACP,iBAAe,YAAY,KAAA;EAC3B,GAAK,SAAS,WAAW,EAAE,MAAM,SAAS,IAAI;EAC9C,GAAI;EAEJ,UAAA,oBAAC,QAAD;GAAM,WAAU;GAAoB,OAAO,EAAE,YAAY,MAAM;EAAI,CAAA;CAC/D,CAAA,CACN,EAAA,CAAA;AAEN;;AAuBA,SAAgB,YAA2C,OAA4B;CACrF,MAAM,EACJ,IACA,KACA,WACA,OACA,SACA,OAAO,WACP,eAAe,MACf,eACA,KACA,GAAG,SACD,cAAc,eAAe,KAAyB;CAC1D,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,MAAM,OAAoB,IAAI;CACpC,MAAM,EAAE,cAAc,eAAe,KAAK;EAAE,UAAU;EAAkB,QAAQ;CAAK,CAAC;CACtF,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,eAAe,QAAQ,GAAG;CAChD,MAAM,OAAO,iBAAiB;EAAE,GAAG;EAAM,KAAK,WAAW,KAAc,GAAG;CAAE,CAAC;CAC7E,MAAM,SAAS,QAAQ,MAAM,MAAM,EAAE,UAAU,KAAK,IAAI,QAAQ,QAAQ,EAAE,EAAE;CAC5E,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EACE,WAAW,GAAG,sBAAsB,OAAO,WAAW,SAAS;EAC/D,MAAK;EACL,cAAY;EACD;EACX,GAAI;EAEH,UAAA,QAAQ,KAAK,MACZ,oBAAC,QAAD;GAEE,OAAO,EAAE;GACT,OAAO,EAAE;GACT,UAAU,EAAE,UAAU;GACtB,UAAU,EAAE,UAAU,SAAS,IAAI;GACnC,UAAU,MAAkB;IAC1B,EAAE,eAAe;IACjB,SAAS,EAAE,KAAK;GAClB;EACD,GATM,EAAE,KASR,CACF;CACG,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ToggleInputAttributes } from "../Checkbox/Checkbox.js";
|
|
4
|
+
import { ElementType, ReactNode } from "react";
|
|
5
|
+
export interface SwitchOwnProps extends ToggleInputAttributes, PartsProps<'input' | 'track' | 'thumb' | 'label'> {
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
defaultChecked?: boolean;
|
|
8
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
9
|
+
/** The label: what is switched on. */
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export type SwitchProps<E extends ElementType = 'label'> = PolymorphicProps<E, SwitchOwnProps>;
|
|
13
|
+
/** On / off setting that applies at once (`role="switch"`). On = thumb at the end with a check, accent track. */
|
|
14
|
+
export declare function Switch<E extends ElementType = 'label'>(props: SwitchProps<E>): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=Switch.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../utils/src/index.js";
|
|
3
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
|
+
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
6
|
+
import { splitToggleProps } from "../Checkbox/Checkbox.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { CheckIcon } from "@slurp-ui/icons";
|
|
9
|
+
// src/Switch/Switch.tsx
|
|
10
|
+
/** On / off setting that applies at once (`role="switch"`). On = thumb at the end with a check, accent track. */
|
|
11
|
+
function Switch(props) {
|
|
12
|
+
const { as, css, className, checked: checkedProp, defaultChecked = false, onCheckedChange, children, parts, partProps, classNames, ...others } = useThemeProps("Switch", props);
|
|
13
|
+
const { input, root: rest } = splitToggleProps(others);
|
|
14
|
+
const [checked, setChecked] = useControlled({
|
|
15
|
+
value: checkedProp,
|
|
16
|
+
defaultValue: defaultChecked,
|
|
17
|
+
onChange: onCheckedChange
|
|
18
|
+
});
|
|
19
|
+
const Root = as ?? "label";
|
|
20
|
+
const styled = useCss("Switch", "root", css);
|
|
21
|
+
const { part, style } = useParts("Switch", {
|
|
22
|
+
parts,
|
|
23
|
+
partProps,
|
|
24
|
+
classNames
|
|
25
|
+
});
|
|
26
|
+
const root = useAnimationRoot(rest);
|
|
27
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
28
|
+
styled.style,
|
|
29
|
+
style,
|
|
30
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
31
|
+
className: cx("slurp-toggle", "slurp-switch", styled.className, className),
|
|
32
|
+
"data-state": checked ? "on" : "off",
|
|
33
|
+
"data-disabled": input.disabled ? "" : void 0,
|
|
34
|
+
...root,
|
|
35
|
+
children: [
|
|
36
|
+
part("input", "input", {
|
|
37
|
+
...input,
|
|
38
|
+
type: "checkbox",
|
|
39
|
+
role: "switch",
|
|
40
|
+
className: "slurp-toggle-input slurp-switch-input",
|
|
41
|
+
checked,
|
|
42
|
+
onChange: (e) => setChecked(e.target.checked)
|
|
43
|
+
}),
|
|
44
|
+
part("track", "span", {
|
|
45
|
+
className: "slurp-switch-track",
|
|
46
|
+
"aria-hidden": true,
|
|
47
|
+
children: part("thumb", "span", {
|
|
48
|
+
className: "slurp-switch-thumb",
|
|
49
|
+
children: checked ? /* @__PURE__ */ jsx(CheckIcon, { size: 14 }) : null
|
|
50
|
+
})
|
|
51
|
+
}),
|
|
52
|
+
children != null && part("label", "span", {
|
|
53
|
+
className: "slurp-toggle-label",
|
|
54
|
+
children
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
})
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
export { Switch };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=Switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Switch.js","names":[],"sources":["../../src/Switch/Switch.tsx"],"sourcesContent":["import { CheckIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport type { ChangeEvent, ElementType, ReactNode } from 'react';\n\nimport { splitToggleProps, type ToggleInputAttributes } from '../Checkbox/Checkbox';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface SwitchOwnProps\n extends ToggleInputAttributes, PartsProps<'input' | 'track' | 'thumb' | 'label'> {\n checked?: boolean;\n defaultChecked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n /** The label: what is switched on. */\n children?: ReactNode;\n}\n\nexport type SwitchProps<E extends ElementType = 'label'> = PolymorphicProps<E, SwitchOwnProps>;\n\n/** On / off setting that applies at once (`role=\"switch\"`). On = thumb at the end with a check, accent track. */\nexport function Switch<E extends ElementType = 'label'>(props: SwitchProps<E>) {\n const {\n as,\n css,\n className,\n checked: checkedProp,\n defaultChecked = false,\n onCheckedChange,\n children,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('Switch', props as SwitchProps);\n const { input, root: rest } = splitToggleProps(others);\n const [checked, setChecked] = useControlled({\n value: checkedProp,\n defaultValue: defaultChecked,\n onChange: onCheckedChange,\n });\n const Root = (as ?? 'label') as ElementType;\n const styled = useCss('Switch', 'root', css);\n const { part, style } = useParts('Switch', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-toggle', 'slurp-switch', styled.className, className)}\n data-state={checked ? 'on' : 'off'}\n data-disabled={input.disabled ? '' : undefined}\n {...root}\n >\n {part('input', 'input', {\n ...input,\n type: 'checkbox',\n role: 'switch',\n className: 'slurp-toggle-input slurp-switch-input',\n checked,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setChecked(e.target.checked),\n })}\n {part('track', 'span', {\n className: 'slurp-switch-track',\n 'aria-hidden': true,\n children: part('thumb', 'span', {\n className: 'slurp-switch-thumb',\n children: checked ? <CheckIcon size={14} /> : null,\n }),\n })}\n {children != null && part('label', 'span', { className: 'slurp-toggle-label', children })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,OAAwC,OAAuB;CAC7E,MAAM,EACJ,IACA,KACA,WACA,SAAS,aACT,iBAAiB,OACjB,iBACA,UACA,OACA,WACA,YACA,GAAG,WACD,cAAc,UAAU,KAAoB;CAChD,MAAM,EAAE,OAAO,MAAM,SAAS,iBAAiB,MAAM;CACrD,MAAM,CAAC,SAAS,cAAc,cAAc;EAC1C,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,UAAU,QAAQ,GAAG;CAC3C,MAAM,EAAE,MAAM,UAAU,SAAS,UAAU;EAAE;EAAO;EAAW;CAAW,CAAC;CAC3E,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,WAAW,GAAG,gBAAgB,gBAAgB,OAAO,WAAW,SAAS;GACzE,cAAY,UAAU,OAAO;GAC7B,iBAAe,MAAM,WAAW,KAAK,KAAA;GACrC,GAAI;GAJN,UAAA;IAMG,KAAK,SAAS,SAAS;KACtB,GAAG;KACH,MAAM;KACN,MAAM;KACN,WAAW;KACX;KACA,WAAW,MAAqC,WAAW,EAAE,OAAO,OAAO;IAC7E,CAAC;IACA,KAAK,SAAS,QAAQ;KACrB,WAAW;KACX,eAAe;KACf,UAAU,KAAK,SAAS,QAAQ;MAC9B,WAAW;MACX,UAAU,UAAU,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,IAAI;KAChD,CAAC;IACH,CAAC;IACA,YAAY,QAAQ,KAAK,SAAS,QAAQ;KAAE,WAAW;KAAsB;IAAS,CAAC;GACpF;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface TabItem<V extends string = string> {
|
|
5
|
+
value: V;
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
content?: ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface TabsOwnProps<V extends string = string> extends PartsProps<'list' | 'tab' | 'indicator' | 'panel'> {
|
|
11
|
+
/** Name of the tab list ("Dettagli prodotto"). */
|
|
12
|
+
label: string;
|
|
13
|
+
items: TabItem<V>[];
|
|
14
|
+
value?: V;
|
|
15
|
+
defaultValue?: V;
|
|
16
|
+
onValueChange?: (value: V) => void;
|
|
17
|
+
}
|
|
18
|
+
export type TabsProps<V extends string = string, E extends ElementType = 'div'> = PolymorphicProps<E, TabsOwnProps<V>>;
|
|
19
|
+
/** Tabs: a pill indicator under the selected tab; arrow keys move and select, Home / End go to the ends. */
|
|
20
|
+
export declare function Tabs<V extends string = string, E extends ElementType = 'div'>(props: TabsProps<V, E>): import("react").JSX.Element;
|
|
21
|
+
//# sourceMappingURL=Tabs.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../utils/src/index.js";
|
|
3
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
|
+
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
6
|
+
import { useRovingFocus } from "../utils/useRovingFocus.js";
|
|
7
|
+
import { Fragment, useId, useLayoutEffect, useRef } from "react";
|
|
8
|
+
import { spring } from "@slurp-ui/motion";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/Tabs/Tabs.tsx
|
|
11
|
+
/** The pill indicator travels on a spring (stiffness 200, damping 22): a CSS linear() easing, no JS per frame. */
|
|
12
|
+
const INDICATOR = spring({
|
|
13
|
+
stiffness: 200,
|
|
14
|
+
damping: 22
|
|
15
|
+
});
|
|
16
|
+
/** Tabs: a pill indicator under the selected tab; arrow keys move and select, Home / End go to the ends. */
|
|
17
|
+
function Tabs(props) {
|
|
18
|
+
const { as, css, className, label, items, value: valueProp, defaultValue, onValueChange, parts, partProps, classNames, ...rest } = useThemeProps("Tabs", props);
|
|
19
|
+
const first = items.find((i) => !i.disabled)?.value;
|
|
20
|
+
const [value, setValue] = useControlled({
|
|
21
|
+
value: valueProp,
|
|
22
|
+
defaultValue: defaultValue ?? first,
|
|
23
|
+
onChange: onValueChange
|
|
24
|
+
});
|
|
25
|
+
const list = useRef(null);
|
|
26
|
+
const { onKeyDown } = useRovingFocus(list, {
|
|
27
|
+
selector: "[role=\"tab\"]",
|
|
28
|
+
select: true
|
|
29
|
+
});
|
|
30
|
+
const id = useId();
|
|
31
|
+
const Root = as ?? "div";
|
|
32
|
+
const styled = useCss("Tabs", "root", css);
|
|
33
|
+
const { part, style } = useParts("Tabs", {
|
|
34
|
+
parts,
|
|
35
|
+
partProps,
|
|
36
|
+
classNames
|
|
37
|
+
});
|
|
38
|
+
const root = useAnimationRoot(rest);
|
|
39
|
+
const active = items.find((i) => i.value === value);
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
const el = list.current;
|
|
42
|
+
const tab = el?.querySelector("[aria-selected=\"true\"]");
|
|
43
|
+
if (!el || !tab) return;
|
|
44
|
+
const place = () => {
|
|
45
|
+
el.style.setProperty("--slurp-tabs-x", `${tab.offsetLeft}px`);
|
|
46
|
+
el.style.setProperty("--slurp-tabs-w", `${tab.offsetWidth}px`);
|
|
47
|
+
};
|
|
48
|
+
place();
|
|
49
|
+
const ready = requestAnimationFrame(() => el.dataset.ready = "");
|
|
50
|
+
if (typeof ResizeObserver === "undefined") return () => cancelAnimationFrame(ready);
|
|
51
|
+
const ro = new ResizeObserver(place);
|
|
52
|
+
ro.observe(el);
|
|
53
|
+
return () => {
|
|
54
|
+
cancelAnimationFrame(ready);
|
|
55
|
+
ro.disconnect();
|
|
56
|
+
};
|
|
57
|
+
}, [value]);
|
|
58
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
59
|
+
styled.style,
|
|
60
|
+
style,
|
|
61
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
62
|
+
className: cx("slurp-tabs", styled.className, className),
|
|
63
|
+
...root,
|
|
64
|
+
children: [part("list", "div", {
|
|
65
|
+
ref: list,
|
|
66
|
+
role: "tablist",
|
|
67
|
+
"aria-label": label,
|
|
68
|
+
className: "slurp-tabs-list",
|
|
69
|
+
onKeyDown,
|
|
70
|
+
style: {
|
|
71
|
+
"--slurp-tabs-easing": INDICATOR.easing,
|
|
72
|
+
"--slurp-tabs-duration": `${INDICATOR.duration}ms`
|
|
73
|
+
},
|
|
74
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [part("indicator", "span", {
|
|
75
|
+
className: "slurp-tabs-indicator",
|
|
76
|
+
"aria-hidden": true
|
|
77
|
+
}), items.map((item) => {
|
|
78
|
+
const on = item.value === value;
|
|
79
|
+
return /* @__PURE__ */ jsx(Fragment, { children: part("tab", "button", {
|
|
80
|
+
type: "button",
|
|
81
|
+
role: "tab",
|
|
82
|
+
id: `${id}-tab-${item.value}`,
|
|
83
|
+
"aria-selected": on,
|
|
84
|
+
"aria-controls": `${id}-panel-${item.value}`,
|
|
85
|
+
tabIndex: on ? 0 : -1,
|
|
86
|
+
disabled: item.disabled,
|
|
87
|
+
className: "slurp-tabs-tab",
|
|
88
|
+
onClick: () => setValue(item.value),
|
|
89
|
+
children: item.label
|
|
90
|
+
}) }, item.value);
|
|
91
|
+
})] })
|
|
92
|
+
}), active && active.content !== void 0 && part("panel", "div", {
|
|
93
|
+
role: "tabpanel",
|
|
94
|
+
id: `${id}-panel-${active.value}`,
|
|
95
|
+
"aria-labelledby": `${id}-tab-${active.value}`,
|
|
96
|
+
tabIndex: 0,
|
|
97
|
+
className: "slurp-tabs-panel",
|
|
98
|
+
children: active.content
|
|
99
|
+
})]
|
|
100
|
+
})
|
|
101
|
+
] });
|
|
102
|
+
}
|
|
103
|
+
export { Tabs };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=Tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tabs.js","names":[],"sources":["../../src/Tabs/Tabs.tsx"],"sourcesContent":["import { spring } from '@slurp-ui/motion';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Fragment,\n useId,\n useLayoutEffect,\n useRef,\n type CSSProperties,\n type ElementType,\n type ReactNode,\n} from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\nimport { useRovingFocus } from '../utils/useRovingFocus';\n\nexport interface TabItem<V extends string = string> {\n value: V;\n label: ReactNode;\n content?: ReactNode;\n disabled?: boolean;\n}\n\nexport interface TabsOwnProps<V extends string = string> extends PartsProps<\n 'list' | 'tab' | 'indicator' | 'panel'\n> {\n /** Name of the tab list (\"Dettagli prodotto\"). */\n label: string;\n items: TabItem<V>[];\n value?: V;\n defaultValue?: V;\n onValueChange?: (value: V) => void;\n}\n\nexport type TabsProps<V extends string = string, E extends ElementType = 'div'> = PolymorphicProps<\n E,\n TabsOwnProps<V>\n>;\n\n/** The pill indicator travels on a spring (stiffness 200, damping 22): a CSS linear() easing, no JS per frame. */\nconst INDICATOR = spring({ stiffness: 200, damping: 22 });\n\n/** Tabs: a pill indicator under the selected tab; arrow keys move and select, Home / End go to the ends. */\nexport function Tabs<V extends string = string, E extends ElementType = 'div'>(\n props: TabsProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n items,\n value: valueProp,\n defaultValue,\n onValueChange,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Tabs', props as unknown as TabsProps);\n const first = items.find((i) => !i.disabled)?.value;\n const [value, setValue] = useControlled<string | undefined>({\n value: valueProp,\n defaultValue: defaultValue ?? first,\n onChange: onValueChange as ((v: string | undefined) => void) | undefined,\n });\n const list = useRef<HTMLDivElement>(null);\n const { onKeyDown } = useRovingFocus(list, { selector: '[role=\"tab\"]', select: true });\n const id = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Tabs', 'root', css);\n const { part, style } = useParts('Tabs', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const active = items.find((i) => i.value === value);\n\n // The indicator follows the selected tab: its box is written as CSS variables on the list (no re-render).\n useLayoutEffect(() => {\n const el = list.current;\n const tab = el?.querySelector<HTMLElement>('[aria-selected=\"true\"]');\n if (!el || !tab) return;\n const place = () => {\n el.style.setProperty('--slurp-tabs-x', `${tab.offsetLeft}px`);\n el.style.setProperty('--slurp-tabs-w', `${tab.offsetWidth}px`);\n };\n place();\n // The first placement does not travel: the spring starts from the next frame on.\n const ready = requestAnimationFrame(() => (el.dataset.ready = ''));\n if (typeof ResizeObserver === 'undefined') return () => cancelAnimationFrame(ready);\n const ro = new ResizeObserver(place);\n ro.observe(el);\n return () => {\n cancelAnimationFrame(ready);\n ro.disconnect();\n };\n }, [value]);\n\n return (\n <>\n {styled.style}\n {style}\n <Root className={cx('slurp-tabs', styled.className, className)} {...root}>\n {part('list', 'div', {\n ref: list,\n role: 'tablist',\n 'aria-label': label,\n className: 'slurp-tabs-list',\n onKeyDown,\n style: {\n '--slurp-tabs-easing': INDICATOR.easing,\n '--slurp-tabs-duration': `${INDICATOR.duration}ms`,\n } as CSSProperties,\n children: (\n <>\n {part('indicator', 'span', {\n className: 'slurp-tabs-indicator',\n 'aria-hidden': true,\n })}\n {items.map((item) => {\n const on = item.value === value;\n return (\n <Fragment key={item.value}>\n {part('tab', 'button', {\n type: 'button',\n role: 'tab',\n id: `${id}-tab-${item.value}`,\n 'aria-selected': on,\n 'aria-controls': `${id}-panel-${item.value}`,\n tabIndex: on ? 0 : -1,\n disabled: item.disabled,\n className: 'slurp-tabs-tab',\n onClick: () => setValue(item.value),\n children: item.label,\n })}\n </Fragment>\n );\n })}\n </>\n ),\n })}\n {active &&\n active.content !== undefined &&\n part('panel', 'div', {\n role: 'tabpanel',\n id: `${id}-panel-${active.value}`,\n 'aria-labelledby': `${id}-tab-${active.value}`,\n tabIndex: 0,\n className: 'slurp-tabs-panel',\n children: active.content,\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AA0CA,MAAM,YAAY,OAAO;CAAE,WAAW;CAAK,SAAS;AAAG,CAAC;;AAGxD,SAAgB,KACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,OACA,OAAO,WACP,cACA,eACA,OACA,WACA,YACA,GAAG,SACD,cAAc,QAAQ,KAA6B;CACvD,MAAM,QAAQ,MAAM,MAAM,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE;CAC9C,MAAM,CAAC,OAAO,YAAY,cAAkC;EAC1D,OAAO;EACP,cAAc,gBAAgB;EAC9B,UAAU;CACZ,CAAC;CACD,MAAM,OAAO,OAAuB,IAAI;CACxC,MAAM,EAAE,cAAc,eAAe,MAAM;EAAE,UAAU;EAAgB,QAAQ;CAAK,CAAC;CACrF,MAAM,KAAK,MAAM;CACjB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,QAAQ,QAAQ,GAAG;CACzC,MAAM,EAAE,MAAM,UAAU,SAAS,QAAQ;EAAE;EAAO;EAAW;CAAW,CAAC;CACzE,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,SAAS,MAAM,MAAM,MAAM,EAAE,UAAU,KAAK;CAGlD,sBAAsB;EACpB,MAAM,KAAK,KAAK;EAChB,MAAM,MAAM,IAAI,cAA2B,0BAAwB;EACnE,IAAI,CAAC,MAAM,CAAC,KAAK;EACjB,MAAM,cAAc;GAClB,GAAG,MAAM,YAAY,kBAAkB,GAAG,IAAI,WAAW,GAAG;GAC5D,GAAG,MAAM,YAAY,kBAAkB,GAAG,IAAI,YAAY,GAAG;EAC/D;EACA,MAAM;EAEN,MAAM,QAAQ,4BAA6B,GAAG,QAAQ,QAAQ,EAAG;EACjE,IAAI,OAAO,mBAAmB,aAAa,aAAa,qBAAqB,KAAK;EAClF,MAAM,KAAK,IAAI,eAAe,KAAK;EACnC,GAAG,QAAQ,EAAE;EACb,aAAa;GACX,qBAAqB,KAAK;GAC1B,GAAG,WAAW;EAChB;CACF,GAAG,CAAC,KAAK,CAAC;CAEV,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GAAM,WAAW,GAAG,cAAc,OAAO,WAAW,SAAS;GAAG,GAAI;GAApE,UAAA,CACG,KAAK,QAAQ,OAAO;IACnB,KAAK;IACL,MAAM;IACN,cAAc;IACd,WAAW;IACX;IACA,OAAO;KACL,uBAAuB,UAAU;KACjC,yBAAyB,GAAG,UAAU,SAAS;IACjD;IACA,UACE,qBAAA,YAAA,EAAA,UAAA,CACG,KAAK,aAAa,QAAQ;KACzB,WAAW;KACX,eAAe;IACjB,CAAC,GACA,MAAM,KAAK,SAAS;KACnB,MAAM,KAAK,KAAK,UAAU;KAC1B,OACE,oBAAC,UAAD,EAAA,UACG,KAAK,OAAO,UAAU;MACrB,MAAM;MACN,MAAM;MACN,IAAI,GAAG,GAAG,OAAO,KAAK;MACtB,iBAAiB;MACjB,iBAAiB,GAAG,GAAG,SAAS,KAAK;MACrC,UAAU,KAAK,IAAI;MACnB,UAAU,KAAK;MACf,WAAW;MACX,eAAe,SAAS,KAAK,KAAK;MAClC,UAAU,KAAK;KACjB,CAAC,EACO,GAbK,KAAK,KAaV;IAEd,CAAC,CACD,EAAA,CAAA;GAEN,CAAC,GACA,UACC,OAAO,YAAY,KAAA,KACnB,KAAK,SAAS,OAAO;IACnB,MAAM;IACN,IAAI,GAAG,GAAG,SAAS,OAAO;IAC1B,mBAAmB,GAAG,GAAG,OAAO,OAAO;IACvC,UAAU;IACV,WAAW;IACX,UAAU,OAAO;GACnB,CAAC,CACC;;CACN,EAAA,CAAA;AAEN"}
|