@slurp-ui/react 0.0.0-stage → 1.0.1
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/CHANGELOG.md +84 -0
- 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 +108 -3
|
@@ -0,0 +1,94 @@
|
|
|
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 { Bubble } from "../Bubble/Bubble.js";
|
|
6
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
7
|
+
import { splitInputProps } from "../Field/Field.js";
|
|
8
|
+
import { useId } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { CloseIcon, SearchIcon } from "@slurp-ui/icons";
|
|
11
|
+
// src/Search/Search.tsx
|
|
12
|
+
const SEARCH_LABELS = {
|
|
13
|
+
label: "Cerca",
|
|
14
|
+
placeholder: "Cerca…",
|
|
15
|
+
clear: "Cancella la ricerca",
|
|
16
|
+
results: (n) => n === 0 ? "Nessun risultato" : n === 1 ? "1 risultato" : `${n} risultati`
|
|
17
|
+
};
|
|
18
|
+
/** Search field: icon, contextual placeholder, result count, clear button. */
|
|
19
|
+
function Search(props) {
|
|
20
|
+
const { as, css, className, value: valueProp, defaultValue = "", onValueChange, onSearch, count, labels: labelsProp, parts, partProps, classNames, ...others } = useThemeProps("Search", props);
|
|
21
|
+
const labels = {
|
|
22
|
+
...SEARCH_LABELS,
|
|
23
|
+
...labelsProp
|
|
24
|
+
};
|
|
25
|
+
const { input, root: rest } = splitInputProps(others);
|
|
26
|
+
const [value, setValue] = useControlled({
|
|
27
|
+
value: valueProp,
|
|
28
|
+
defaultValue,
|
|
29
|
+
onChange: onValueChange
|
|
30
|
+
});
|
|
31
|
+
const statusId = useId();
|
|
32
|
+
const Root = as ?? "div";
|
|
33
|
+
const styled = useCss("Search", "root", css);
|
|
34
|
+
const { part, style } = useParts("Search", {
|
|
35
|
+
parts,
|
|
36
|
+
partProps,
|
|
37
|
+
classNames
|
|
38
|
+
});
|
|
39
|
+
const root = useAnimationRoot(rest);
|
|
40
|
+
const typed = value.trim() !== "";
|
|
41
|
+
const userKeyDown = input.onKeyDown;
|
|
42
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
43
|
+
styled.style,
|
|
44
|
+
style,
|
|
45
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
46
|
+
role: "search",
|
|
47
|
+
className: cx("slurp-search", styled.className, className),
|
|
48
|
+
"data-typed": typed ? "" : void 0,
|
|
49
|
+
...root,
|
|
50
|
+
children: [
|
|
51
|
+
part("icon", "span", {
|
|
52
|
+
className: "slurp-search-icon",
|
|
53
|
+
"aria-hidden": true,
|
|
54
|
+
children: /* @__PURE__ */ jsx(SearchIcon, { size: 18 })
|
|
55
|
+
}),
|
|
56
|
+
part("control", "input", {
|
|
57
|
+
...input,
|
|
58
|
+
type: "search",
|
|
59
|
+
className: "slurp-search-control",
|
|
60
|
+
"aria-label": labels.label,
|
|
61
|
+
"aria-describedby": count != null && typed ? statusId : void 0,
|
|
62
|
+
placeholder: input.placeholder ?? labels.placeholder,
|
|
63
|
+
enterKeyHint: input.enterKeyHint ?? "search",
|
|
64
|
+
autoComplete: input.autoComplete ?? "off",
|
|
65
|
+
value,
|
|
66
|
+
onChange: (e) => setValue(e.target.value),
|
|
67
|
+
onKeyDown: (e) => {
|
|
68
|
+
userKeyDown?.(e);
|
|
69
|
+
if (e.key === "Enter" && !e.defaultPrevented) onSearch?.(value);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
part("status", "span", {
|
|
73
|
+
id: statusId,
|
|
74
|
+
className: "slurp-search-count",
|
|
75
|
+
role: "status",
|
|
76
|
+
children: count != null && typed ? labels.results(count) : ""
|
|
77
|
+
}),
|
|
78
|
+
typed && part("clear", Bubble, {
|
|
79
|
+
className: "slurp-search-clear",
|
|
80
|
+
label: labels.clear,
|
|
81
|
+
size: "sm",
|
|
82
|
+
onClick: (e) => {
|
|
83
|
+
setValue("");
|
|
84
|
+
e.currentTarget.parentElement?.querySelector("input")?.focus();
|
|
85
|
+
},
|
|
86
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { size: 18 })
|
|
87
|
+
})
|
|
88
|
+
]
|
|
89
|
+
})
|
|
90
|
+
] });
|
|
91
|
+
}
|
|
92
|
+
export { SEARCH_LABELS, Search };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=Search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Search.js","names":[],"sources":["../../src/Search/Search.tsx"],"sourcesContent":["import { CloseIcon, SearchIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n useId,\n type ChangeEvent,\n type ElementType,\n type KeyboardEvent,\n type MouseEvent,\n} from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { splitInputProps, type InputAttributes } from '../Field/Field';\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 SearchLabels {\n /** Name of the field (read by screen readers; hidden). */\n label: string;\n /** Says where it looks: \"Cerca in Smartphone…\". */\n placeholder: string;\n /** Name of the clear button. */\n clear: string;\n /** Result count, announced politely while typing. */\n results: (count: number) => string;\n}\n\nexport const SEARCH_LABELS: SearchLabels = {\n label: 'Cerca',\n placeholder: 'Cerca…',\n clear: 'Cancella la ricerca',\n results: (n) => (n === 0 ? 'Nessun risultato' : n === 1 ? '1 risultato' : `${n} risultati`),\n};\n\nexport interface SearchOwnProps\n extends Omit<InputAttributes, 'type'>, PartsProps<'icon' | 'control' | 'clear' | 'status'> {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /** Enter. */\n onSearch?: (value: string) => void;\n /** Number of results: shown at the end of the field and announced (polite live region). */\n count?: number;\n labels?: Partial<SearchLabels>;\n}\n\nexport type SearchProps<E extends ElementType = 'div'> = PolymorphicProps<E, SearchOwnProps>;\n\n/** Search field: icon, contextual placeholder, result count, clear button. */\nexport function Search<E extends ElementType = 'div'>(props: SearchProps<E>) {\n const {\n as,\n css,\n className,\n value: valueProp,\n defaultValue = '',\n onValueChange,\n onSearch,\n count,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('Search', props as SearchProps);\n const labels = { ...SEARCH_LABELS, ...labelsProp };\n const { input, root: rest } = splitInputProps(others);\n const [value, setValue] = useControlled({\n value: valueProp,\n defaultValue,\n onChange: onValueChange,\n });\n const statusId = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Search', 'root', css);\n const { part, style } = useParts('Search', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const typed = value.trim() !== '';\n const userKeyDown = input.onKeyDown as ((e: KeyboardEvent<HTMLInputElement>) => void) | undefined;\n return (\n <>\n {styled.style}\n {style}\n <Root\n role=\"search\"\n className={cx('slurp-search', styled.className, className)}\n data-typed={typed ? '' : undefined}\n {...root}\n >\n {part('icon', 'span', {\n className: 'slurp-search-icon',\n 'aria-hidden': true,\n children: <SearchIcon size={18} />,\n })}\n {part('control', 'input', {\n ...input,\n type: 'search',\n className: 'slurp-search-control',\n 'aria-label': labels.label,\n 'aria-describedby': count != null && typed ? statusId : undefined,\n placeholder: input.placeholder ?? labels.placeholder,\n enterKeyHint: input.enterKeyHint ?? 'search',\n autoComplete: input.autoComplete ?? 'off',\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n onKeyDown: (e: KeyboardEvent<HTMLInputElement>) => {\n userKeyDown?.(e);\n if (e.key === 'Enter' && !e.defaultPrevented) onSearch?.(value);\n },\n })}\n {part('status', 'span', {\n id: statusId,\n className: 'slurp-search-count',\n role: 'status',\n children: count != null && typed ? labels.results(count) : '',\n })}\n {typed &&\n part('clear', Bubble, {\n className: 'slurp-search-clear',\n label: labels.clear,\n size: 'sm',\n onClick: (e: MouseEvent<HTMLElement>) => {\n setValue('');\n e.currentTarget.parentElement?.querySelector('input')?.focus();\n },\n children: <CloseIcon size={18} />,\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAa,gBAA8B;CACzC,OAAO;CACP,aAAa;CACb,OAAO;CACP,UAAU,MAAO,MAAM,IAAI,qBAAqB,MAAM,IAAI,gBAAgB,GAAG,EAAE;AACjF;;AAiBA,SAAgB,OAAsC,OAAuB;CAC3E,MAAM,EACJ,IACA,KACA,WACA,OAAO,WACP,eAAe,IACf,eACA,UACA,OACA,QAAQ,YACR,OACA,WACA,YACA,GAAG,WACD,cAAc,UAAU,KAAoB;CAChD,MAAM,SAAS;EAAE,GAAG;EAAe,GAAG;CAAW;CACjD,MAAM,EAAE,OAAO,MAAM,SAAS,gBAAgB,MAAM;CACpD,MAAM,CAAC,OAAO,YAAY,cAAc;EACtC,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,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,MAAM,QAAQ,MAAM,KAAK,MAAM;CAC/B,MAAM,cAAc,MAAM;CAC1B,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,MAAK;GACL,WAAW,GAAG,gBAAgB,OAAO,WAAW,SAAS;GACzD,cAAY,QAAQ,KAAK,KAAA;GACzB,GAAI;GAJN,UAAA;IAMG,KAAK,QAAQ,QAAQ;KACpB,WAAW;KACX,eAAe;KACf,UAAU,oBAAC,YAAD,EAAY,MAAM,GAAK,CAAA;IACnC,CAAC;IACA,KAAK,WAAW,SAAS;KACxB,GAAG;KACH,MAAM;KACN,WAAW;KACX,cAAc,OAAO;KACrB,oBAAoB,SAAS,QAAQ,QAAQ,WAAW,KAAA;KACxD,aAAa,MAAM,eAAe,OAAO;KACzC,cAAc,MAAM,gBAAgB;KACpC,cAAc,MAAM,gBAAgB;KACpC;KACA,WAAW,MAAqC,SAAS,EAAE,OAAO,KAAK;KACvE,YAAY,MAAuC;MACjD,cAAc,CAAC;MACf,IAAI,EAAE,QAAQ,WAAW,CAAC,EAAE,kBAAkB,WAAW,KAAK;KAChE;IACF,CAAC;IACA,KAAK,UAAU,QAAQ;KACtB,IAAI;KACJ,WAAW;KACX,MAAM;KACN,UAAU,SAAS,QAAQ,QAAQ,OAAO,QAAQ,KAAK,IAAI;IAC7D,CAAC;IACA,SACC,KAAK,SAAS,QAAQ;KACpB,WAAW;KACX,OAAO,OAAO;KACd,MAAM;KACN,UAAU,MAA+B;MACvC,SAAS,EAAE;MACX,EAAE,cAAc,eAAe,cAAc,OAAO,CAAC,EAAE,MAAM;KAC/D;KACA,UAAU,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;IAClC,CAAC;GACC;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ControlSize } from "../Button/Button.js";
|
|
4
|
+
import { ElementType, ReactNode } from "react";
|
|
5
|
+
export interface SegmentedOption<V extends string = string> {
|
|
6
|
+
value: V;
|
|
7
|
+
label: ReactNode;
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface SegmentedOwnProps<V extends string = string> extends PartsProps<'item'> {
|
|
12
|
+
/** Name of the group ("Vista"). */
|
|
13
|
+
label: string;
|
|
14
|
+
options: SegmentedOption<V>[];
|
|
15
|
+
value?: V;
|
|
16
|
+
defaultValue?: V;
|
|
17
|
+
onValueChange?: (value: V) => void;
|
|
18
|
+
/** Default `md`. */
|
|
19
|
+
size?: ControlSize;
|
|
20
|
+
}
|
|
21
|
+
export type SegmentedProps<V extends string = string, E extends ElementType = 'div'> = PolymorphicProps<E, SegmentedOwnProps<V>>;
|
|
22
|
+
/** One choice among a few: the selected segment is filled with the accent and shows a check. */
|
|
23
|
+
export declare function Segmented<V extends string = string, E extends ElementType = 'div'>(props: SegmentedProps<V, E>): import("react").JSX.Element;
|
|
24
|
+
//# sourceMappingURL=Segmented.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
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, useParts, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
7
|
+
import { useRovingFocus } from "../utils/useRovingFocus.js";
|
|
8
|
+
import { Fragment, useRef } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { CheckIcon } from "@slurp-ui/icons";
|
|
11
|
+
// src/Segmented/Segmented.tsx
|
|
12
|
+
/** One choice among a few: the selected segment is filled with the accent and shows a check. */
|
|
13
|
+
function Segmented(props) {
|
|
14
|
+
const { as, css, className, label, options, value: valueProp, defaultValue, onValueChange, size = "md", parts, partProps, classNames, ref, ...rest } = useThemeProps("Segmented", props);
|
|
15
|
+
const [value, setValue] = useControlled({
|
|
16
|
+
value: valueProp,
|
|
17
|
+
defaultValue: defaultValue ?? options[0]?.value,
|
|
18
|
+
onChange: onValueChange
|
|
19
|
+
});
|
|
20
|
+
const own = useRef(null);
|
|
21
|
+
const { onKeyDown } = useRovingFocus(own, {
|
|
22
|
+
selector: "[role=\"radio\"]",
|
|
23
|
+
select: true
|
|
24
|
+
});
|
|
25
|
+
const Root = as ?? "div";
|
|
26
|
+
const styled = useCss("Segmented", "root", css);
|
|
27
|
+
const { part, style } = useParts("Segmented", {
|
|
28
|
+
parts,
|
|
29
|
+
partProps,
|
|
30
|
+
classNames
|
|
31
|
+
});
|
|
32
|
+
const root = useAnimationRoot({
|
|
33
|
+
...rest,
|
|
34
|
+
ref: useForkRef(ref, own)
|
|
35
|
+
});
|
|
36
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
37
|
+
styled.style,
|
|
38
|
+
style,
|
|
39
|
+
/* @__PURE__ */ jsx(Root, {
|
|
40
|
+
className: cx("slurp-segmented", styled.className, className),
|
|
41
|
+
role: "radiogroup",
|
|
42
|
+
"aria-label": label,
|
|
43
|
+
"data-size": size,
|
|
44
|
+
onKeyDown,
|
|
45
|
+
...root,
|
|
46
|
+
children: options.map((o) => {
|
|
47
|
+
const on = o.value === value;
|
|
48
|
+
return /* @__PURE__ */ jsx(Fragment, { children: part("item", "button", {
|
|
49
|
+
type: "button",
|
|
50
|
+
role: "radio",
|
|
51
|
+
"aria-checked": on,
|
|
52
|
+
"data-selected": on || void 0,
|
|
53
|
+
disabled: o.disabled,
|
|
54
|
+
tabIndex: on ? 0 : -1,
|
|
55
|
+
className: "slurp-segmented-item",
|
|
56
|
+
onClick: () => setValue(o.value),
|
|
57
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [(on || o.icon) && /* @__PURE__ */ jsx("span", {
|
|
58
|
+
className: "slurp-segmented-icon",
|
|
59
|
+
"aria-hidden": "true",
|
|
60
|
+
children: on ? /* @__PURE__ */ jsx(CheckIcon, { size: 16 }) : o.icon
|
|
61
|
+
}), /* @__PURE__ */ jsx("span", { children: o.label })] })
|
|
62
|
+
}) }, o.value);
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
] });
|
|
66
|
+
}
|
|
67
|
+
export { Segmented };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=Segmented.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Segmented.js","names":[],"sources":["../../src/Segmented/Segmented.tsx"],"sourcesContent":["import { CheckIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { Fragment, useRef, type ElementType, type ReactNode } from 'react';\n\nimport type { ControlSize } from '../Button/Button';\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 { useForkRef } from '../utils/useForkRef';\nimport { useRovingFocus } from '../utils/useRovingFocus';\n\nexport interface SegmentedOption<V extends string = string> {\n value: V;\n label: ReactNode;\n icon?: ReactNode;\n disabled?: boolean;\n}\n\nexport interface SegmentedOwnProps<V extends string = string> extends PartsProps<'item'> {\n /** Name of the group (\"Vista\"). */\n label: string;\n options: SegmentedOption<V>[];\n value?: V;\n defaultValue?: V;\n onValueChange?: (value: V) => void;\n /** Default `md`. */\n size?: ControlSize;\n}\n\nexport type SegmentedProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, SegmentedOwnProps<V>>;\n\n/** One choice among a few: the selected segment is filled with the accent and shows a check. */\nexport function Segmented<V extends string = string, E extends ElementType = 'div'>(\n props: SegmentedProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n options,\n value: valueProp,\n defaultValue,\n onValueChange,\n size = 'md',\n parts,\n partProps,\n classNames,\n ref,\n ...rest\n } = useThemeProps('Segmented', props as unknown as SegmentedProps);\n const [value, setValue] = useControlled<string | undefined>({\n value: valueProp,\n defaultValue: defaultValue ?? options[0]?.value,\n onChange: onValueChange as ((v: string | undefined) => 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('Segmented', 'root', css);\n const { part, style } = useParts('Segmented', { parts, partProps, classNames });\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, own) });\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-segmented', styled.className, className)}\n role=\"radiogroup\"\n aria-label={label}\n data-size={size}\n onKeyDown={onKeyDown}\n {...root}\n >\n {options.map((o) => {\n const on = o.value === value;\n return (\n <Fragment key={o.value}>\n {part('item', 'button', {\n type: 'button',\n role: 'radio',\n 'aria-checked': on,\n 'data-selected': on || undefined,\n disabled: o.disabled,\n tabIndex: on ? 0 : -1,\n className: 'slurp-segmented-item',\n onClick: () => setValue(o.value),\n children: (\n <>\n {(on || o.icon) && (\n <span className=\"slurp-segmented-icon\" aria-hidden=\"true\">\n {on ? <CheckIcon size={16} /> : o.icon}\n </span>\n )}\n <span>{o.label}</span>\n </>\n ),\n })}\n </Fragment>\n );\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,SAAgB,UACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,SACA,OAAO,WACP,cACA,eACA,OAAO,MACP,OACA,WACA,YACA,KACA,GAAG,SACD,cAAc,aAAa,KAAkC;CACjE,MAAM,CAAC,OAAO,YAAY,cAAkC;EAC1D,OAAO;EACP,cAAc,gBAAgB,QAAQ,EAAE,EAAE;EAC1C,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,aAAa,QAAQ,GAAG;CAC9C,MAAM,EAAE,MAAM,UAAU,SAAS,aAAa;EAAE;EAAO;EAAW;CAAW,CAAC;CAC9E,MAAM,OAAO,iBAAiB;EAAE,GAAG;EAAM,KAAK,WAAW,KAAc,GAAG;CAAE,CAAC;CAC7E,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,oBAAC,MAAD;GACE,WAAW,GAAG,mBAAmB,OAAO,WAAW,SAAS;GAC5D,MAAK;GACL,cAAY;GACZ,aAAW;GACA;GACX,GAAI;GAEH,UAAA,QAAQ,KAAK,MAAM;IAClB,MAAM,KAAK,EAAE,UAAU;IACvB,OACE,oBAAC,UAAD,EAAA,UACG,KAAK,QAAQ,UAAU;KACtB,MAAM;KACN,MAAM;KACN,gBAAgB;KAChB,iBAAiB,MAAM,KAAA;KACvB,UAAU,EAAE;KACZ,UAAU,KAAK,IAAI;KACnB,WAAW;KACX,eAAe,SAAS,EAAE,KAAK;KAC/B,UACE,qBAAA,YAAA,EAAA,UAAA,EACI,MAAM,EAAE,SACR,oBAAC,QAAD;MAAM,WAAU;MAAuB,eAAY;MAChD,UAAA,KAAK,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,IAAI,EAAE;KAC9B,CAAA,GAER,oBAAC,QAAD,EAAA,UAAO,EAAE,MAAY,CAAA,CACrB,EAAA,CAAA;IAEN,CAAC,EACO,GArBK,EAAE,KAqBP;GAEd,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
import { SlurpCss } from "../lib/css.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
export interface SettingsLabels {
|
|
5
|
+
/** Name of the button. */
|
|
6
|
+
open: string;
|
|
7
|
+
/** Name of the button while open. */
|
|
8
|
+
close: string;
|
|
9
|
+
/** Title of the panel. */
|
|
10
|
+
title: string;
|
|
11
|
+
theme: string;
|
|
12
|
+
system: string;
|
|
13
|
+
light: string;
|
|
14
|
+
dark: string;
|
|
15
|
+
language: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const SETTINGS_LABELS: SettingsLabels;
|
|
18
|
+
export interface SettingsLanguage {
|
|
19
|
+
value: string;
|
|
20
|
+
/** Written in itself ("Italiano", "English"). */
|
|
21
|
+
label: string;
|
|
22
|
+
/** BCP 47 tag of the label ("it", "en"). */
|
|
23
|
+
lang: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SettingsProps {
|
|
26
|
+
/**
|
|
27
|
+
* Languages: the Lingua choice appears only when they are given (the library has no i18n of its own: apply the
|
|
28
|
+
* choice yourself).
|
|
29
|
+
*/
|
|
30
|
+
languages?: SettingsLanguage[];
|
|
31
|
+
language?: string;
|
|
32
|
+
onLanguageChange?: (value: string) => void;
|
|
33
|
+
/** More preferences (RadioGroup with `appearance="rows"`), or a short note. */
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
/** Panel width. Default 300. */
|
|
36
|
+
width?: number;
|
|
37
|
+
/** In the flow instead of fixed at the top right. */
|
|
38
|
+
inline?: boolean;
|
|
39
|
+
labels?: Partial<SettingsLabels>;
|
|
40
|
+
className?: string;
|
|
41
|
+
css?: SlurpCss;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Site settings: a round button at the top right that grows into its own panel (Bloom) and shrinks back. Tema is
|
|
45
|
+
* always there (Automatico / Chiaro / Scuro, through useColorScheme); Lingua only when `languages` is set.
|
|
46
|
+
* Needs a SlurpProvider.
|
|
47
|
+
*/
|
|
48
|
+
export declare function Settings(props: SettingsProps): import("react").JSX.Element;
|
|
49
|
+
//# sourceMappingURL=Settings.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useColorScheme } from "../internal/context.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { Radio, RadioGroup } from "../Radio/Radio.js";
|
|
6
|
+
import { Bloom } from "../Bloom/Bloom.js";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { AutoIcon, CloseIcon, GearIcon, MoonIcon, SunIcon } from "@slurp-ui/icons";
|
|
10
|
+
// src/Settings/Settings.tsx
|
|
11
|
+
const SETTINGS_LABELS = {
|
|
12
|
+
open: "Impostazioni",
|
|
13
|
+
close: "Chiudi impostazioni",
|
|
14
|
+
title: "Impostazioni",
|
|
15
|
+
theme: "Tema",
|
|
16
|
+
system: "Automatico",
|
|
17
|
+
light: "Chiaro",
|
|
18
|
+
dark: "Scuro",
|
|
19
|
+
language: "Lingua"
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Site settings: a round button at the top right that grows into its own panel (Bloom) and shrinks back. Tema is
|
|
23
|
+
* always there (Automatico / Chiaro / Scuro, through useColorScheme); Lingua only when `languages` is set.
|
|
24
|
+
* Needs a SlurpProvider.
|
|
25
|
+
*/
|
|
26
|
+
function Settings(props) {
|
|
27
|
+
const { languages, language, onLanguageChange, children, width = 300, inline = false, labels: labelsProp, className, css } = useThemeProps("Settings", props);
|
|
28
|
+
const labels = {
|
|
29
|
+
...SETTINGS_LABELS,
|
|
30
|
+
...labelsProp
|
|
31
|
+
};
|
|
32
|
+
const { mode, setMode } = useColorScheme();
|
|
33
|
+
const titleId = useId();
|
|
34
|
+
return /* @__PURE__ */ jsx("div", {
|
|
35
|
+
className: cx("slurp-settings", className),
|
|
36
|
+
"data-inline": inline || void 0,
|
|
37
|
+
children: /* @__PURE__ */ jsxs(Bloom, {
|
|
38
|
+
trigger: /* @__PURE__ */ jsx(GearIcon, { size: 22 }),
|
|
39
|
+
openTrigger: /* @__PURE__ */ jsx(CloseIcon, { size: 22 }),
|
|
40
|
+
label: labels.open,
|
|
41
|
+
closeLabel: labels.close,
|
|
42
|
+
placement: "bottom-end",
|
|
43
|
+
width,
|
|
44
|
+
css,
|
|
45
|
+
partProps: { panel: { "aria-labelledby": titleId } },
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ jsx("h2", {
|
|
48
|
+
id: titleId,
|
|
49
|
+
className: "slurp-settings-title",
|
|
50
|
+
children: labels.title
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ jsxs(RadioGroup, {
|
|
53
|
+
label: labels.theme,
|
|
54
|
+
appearance: "rows",
|
|
55
|
+
value: mode,
|
|
56
|
+
onValueChange: (v) => setMode(v),
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(Radio, {
|
|
59
|
+
value: "system",
|
|
60
|
+
icon: /* @__PURE__ */ jsx(AutoIcon, {}),
|
|
61
|
+
children: labels.system
|
|
62
|
+
}),
|
|
63
|
+
/* @__PURE__ */ jsx(Radio, {
|
|
64
|
+
value: "light",
|
|
65
|
+
icon: /* @__PURE__ */ jsx(SunIcon, {}),
|
|
66
|
+
children: labels.light
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx(Radio, {
|
|
69
|
+
value: "dark",
|
|
70
|
+
icon: /* @__PURE__ */ jsx(MoonIcon, {}),
|
|
71
|
+
children: labels.dark
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
languages?.length ? /* @__PURE__ */ jsx(RadioGroup, {
|
|
76
|
+
label: labels.language,
|
|
77
|
+
appearance: "rows",
|
|
78
|
+
value: language ?? null,
|
|
79
|
+
onValueChange: onLanguageChange,
|
|
80
|
+
children: languages.map((l) => /* @__PURE__ */ jsx(Radio, {
|
|
81
|
+
value: l.value,
|
|
82
|
+
lang: l.lang,
|
|
83
|
+
children: l.label
|
|
84
|
+
}, l.value))
|
|
85
|
+
}) : null,
|
|
86
|
+
children
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export { SETTINGS_LABELS, Settings };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=Settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.js","names":[],"sources":["../../src/Settings/Settings.tsx"],"sourcesContent":["import { AutoIcon, CloseIcon, GearIcon, MoonIcon, SunIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, type ReactNode } from 'react';\n\nimport { Bloom } from '../Bloom/Bloom';\nimport { useColorScheme } from '../internal/context';\nimport { useThemeProps } from '../internal/styled';\nimport type { SlurpCss } from '../lib/css';\nimport type { ColorSchemeMode } from '../lib/theme';\nimport { Radio, RadioGroup } from '../Radio/Radio';\n\nexport interface SettingsLabels {\n /** Name of the button. */\n open: string;\n /** Name of the button while open. */\n close: string;\n /** Title of the panel. */\n title: string;\n theme: string;\n system: string;\n light: string;\n dark: string;\n language: string;\n}\n\nexport const SETTINGS_LABELS: SettingsLabels = {\n open: 'Impostazioni',\n close: 'Chiudi impostazioni',\n title: 'Impostazioni',\n theme: 'Tema',\n system: 'Automatico',\n light: 'Chiaro',\n dark: 'Scuro',\n language: 'Lingua',\n};\n\nexport interface SettingsLanguage {\n value: string;\n /** Written in itself (\"Italiano\", \"English\"). */\n label: string;\n /** BCP 47 tag of the label (\"it\", \"en\"). */\n lang: string;\n}\n\nexport interface SettingsProps {\n /**\n * Languages: the Lingua choice appears only when they are given (the library has no i18n of its own: apply the\n * choice yourself).\n */\n languages?: SettingsLanguage[];\n language?: string;\n onLanguageChange?: (value: string) => void;\n /** More preferences (RadioGroup with `appearance=\"rows\"`), or a short note. */\n children?: ReactNode;\n /** Panel width. Default 300. */\n width?: number;\n /** In the flow instead of fixed at the top right. */\n inline?: boolean;\n labels?: Partial<SettingsLabels>;\n className?: string;\n css?: SlurpCss;\n}\n\n/**\n * Site settings: a round button at the top right that grows into its own panel (Bloom) and shrinks back. Tema is\n * always there (Automatico / Chiaro / Scuro, through useColorScheme); Lingua only when `languages` is set.\n * Needs a SlurpProvider.\n */\nexport function Settings(props: SettingsProps) {\n const {\n languages,\n language,\n onLanguageChange,\n children,\n width = 300,\n inline = false,\n labels: labelsProp,\n className,\n css,\n } = useThemeProps('Settings', props);\n const labels = { ...SETTINGS_LABELS, ...labelsProp };\n const { mode, setMode } = useColorScheme();\n const titleId = useId();\n return (\n <div className={cx('slurp-settings', className)} data-inline={inline || undefined}>\n <Bloom\n trigger={<GearIcon size={22} />}\n openTrigger={<CloseIcon size={22} />}\n label={labels.open}\n closeLabel={labels.close}\n placement=\"bottom-end\"\n width={width}\n css={css}\n partProps={{ panel: { 'aria-labelledby': titleId } }}\n >\n <h2 id={titleId} className=\"slurp-settings-title\">\n {labels.title}\n </h2>\n <RadioGroup\n label={labels.theme}\n appearance=\"rows\"\n value={mode}\n onValueChange={(v) => setMode(v as ColorSchemeMode)}\n >\n <Radio value=\"system\" icon={<AutoIcon />}>\n {labels.system}\n </Radio>\n <Radio value=\"light\" icon={<SunIcon />}>\n {labels.light}\n </Radio>\n <Radio value=\"dark\" icon={<MoonIcon />}>\n {labels.dark}\n </Radio>\n </RadioGroup>\n {languages?.length ? (\n <RadioGroup\n label={labels.language}\n appearance=\"rows\"\n value={language ?? null}\n onValueChange={onLanguageChange}\n >\n {languages.map((l) => (\n <Radio key={l.value} value={l.value} lang={l.lang}>\n {l.label}\n </Radio>\n ))}\n </RadioGroup>\n ) : null}\n {children}\n </Bloom>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAa,kBAAkC;CAC7C,MAAM;CACN,OAAO;CACP,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACN,UAAU;AACZ;;;;;;AAkCA,SAAgB,SAAS,OAAsB;CAC7C,MAAM,EACJ,WACA,UACA,kBACA,UACA,QAAQ,KACR,SAAS,OACT,QAAQ,YACR,WACA,QACE,cAAc,YAAY,KAAK;CACnC,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG;CAAW;CACnD,MAAM,EAAE,MAAM,YAAY,eAAe;CACzC,MAAM,UAAU,MAAM;CACtB,OACE,oBAAC,OAAD;EAAK,WAAW,GAAG,kBAAkB,SAAS;EAAG,eAAa,UAAU,KAAA;EACtE,UAAA,qBAAC,OAAD;GACE,SAAS,oBAAC,UAAD,EAAU,MAAM,GAAK,CAAA;GAC9B,aAAa,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;GACnC,OAAO,OAAO;GACd,YAAY,OAAO;GACnB,WAAU;GACH;GACF;GACL,WAAW,EAAE,OAAO,EAAE,mBAAmB,QAAQ,EAAE;GARrD,UAAA;IAUE,oBAAC,MAAD;KAAI,IAAI;KAAS,WAAU;KACxB,UAAA,OAAO;IACN,CAAA;IACJ,qBAAC,YAAD;KACE,OAAO,OAAO;KACd,YAAW;KACX,OAAO;KACP,gBAAgB,MAAM,QAAQ,CAAoB;KAJpD,UAAA;MAME,oBAAC,OAAD;OAAO,OAAM;OAAS,MAAM,oBAAC,UAAD,CAAW,CAAA;OACpC,UAAA,OAAO;MACH,CAAA;MACP,oBAAC,OAAD;OAAO,OAAM;OAAQ,MAAM,oBAAC,SAAD,CAAU,CAAA;OAClC,UAAA,OAAO;MACH,CAAA;MACP,oBAAC,OAAD;OAAO,OAAM;OAAO,MAAM,oBAAC,UAAD,CAAW,CAAA;OAClC,UAAA,OAAO;MACH,CAAA;KACG;;IACX,WAAW,SACV,oBAAC,YAAD;KACE,OAAO,OAAO;KACd,YAAW;KACX,OAAO,YAAY;KACnB,eAAe;KAEd,UAAA,UAAU,KAAK,MACd,oBAAC,OAAD;MAAqB,OAAO,EAAE;MAAO,MAAM,EAAE;MAC1C,UAAA,EAAE;KACE,GAFK,EAAE,KAEP,CACR;IACS,CAAA,IACV;IACH;GACI;;CACJ,CAAA;AAET"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
import { DialogProps } from "../Dialog/Dialog.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export type SheetProps<E extends ElementType = 'dialog'> = DialogProps<E>;
|
|
5
|
+
/** Modal panel that rises from the bottom edge (full width on phones). Same API as Dialog. */
|
|
6
|
+
export declare function Sheet<E extends ElementType = 'dialog'>(props: SheetProps<E>): import("react").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=Sheet.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useThemeProps } from "../internal/styled.js";
|
|
3
|
+
import { useModal } from "../Dialog/Dialog.js";
|
|
4
|
+
// src/Sheet/Sheet.tsx
|
|
5
|
+
/** Modal panel that rises from the bottom edge (full width on phones). Same API as Dialog. */
|
|
6
|
+
function Sheet(props) {
|
|
7
|
+
return useModal(useThemeProps("Sheet", props), "sheet");
|
|
8
|
+
}
|
|
9
|
+
export { Sheet };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=Sheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sheet.js","names":[],"sources":["../../src/Sheet/Sheet.tsx"],"sourcesContent":["import type { ElementType } from 'react';\n\nimport { useModal, type DialogProps } from '../Dialog/Dialog';\nimport { useThemeProps } from '../internal/styled';\n\nexport type SheetProps<E extends ElementType = 'dialog'> = DialogProps<E>;\n\n/** Modal panel that rises from the bottom edge (full width on phones). Same API as Dialog. */\nexport function Sheet<E extends ElementType = 'dialog'>(props: SheetProps<E>) {\n return useModal(useThemeProps('Sheet', props as DialogProps), 'sheet');\n}\n"],"mappings":";;;;;AAQA,SAAgB,MAAwC,OAAsB;CAC5E,OAAO,SAAS,cAAc,SAAS,KAAoB,GAAG,OAAO;AACvE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export type ShelfProps<E extends ElementType = 'ul'> = PolymorphicProps<E>;
|
|
5
|
+
/** A list of Cards: `repeat(auto-fill, minmax(220px, 1fr))`. Each child becomes a list item. */
|
|
6
|
+
export declare function Shelf<E extends ElementType = 'ul'>(props: ShelfProps<E>): import("react").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=Shelf.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { Children } from "react";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/Shelf/Shelf.tsx
|
|
8
|
+
/** A list of Cards: `repeat(auto-fill, minmax(220px, 1fr))`. Each child becomes a list item. */
|
|
9
|
+
function Shelf(props) {
|
|
10
|
+
const { as, css, className, children, ...rest } = useThemeProps("Shelf", props);
|
|
11
|
+
const Root = as ?? "ul";
|
|
12
|
+
const styled = useCss("Shelf", "root", css);
|
|
13
|
+
const root = useAnimationRoot(rest);
|
|
14
|
+
const list = Root === "ul" || Root === "ol";
|
|
15
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
16
|
+
className: cx("slurp-shelf", styled.className, className),
|
|
17
|
+
...root,
|
|
18
|
+
children: list ? Children.map(children, (child) => child == null ? null : /* @__PURE__ */ jsx("li", { children: child })) : children
|
|
19
|
+
})] });
|
|
20
|
+
}
|
|
21
|
+
export { Shelf };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=Shelf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shelf.js","names":[],"sources":["../../src/Shelf/Shelf.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport { Children, type ElementType } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport type ShelfProps<E extends ElementType = 'ul'> = PolymorphicProps<E>;\n\n/** A list of Cards: `repeat(auto-fill, minmax(220px, 1fr))`. Each child becomes a list item. */\nexport function Shelf<E extends ElementType = 'ul'>(props: ShelfProps<E>) {\n const { as, css, className, children, ...rest } = useThemeProps('Shelf', props as ShelfProps);\n const Root = (as ?? 'ul') as ElementType;\n const styled = useCss('Shelf', 'root', css);\n const root = useAnimationRoot(rest);\n const list = Root === 'ul' || Root === 'ol';\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-shelf', styled.className, className)} {...root}>\n {list\n ? Children.map(children, (child) => (child == null ? null : <li>{child}</li>))\n : children}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,MAAoC,OAAsB;CACxE,MAAM,EAAE,IAAI,KAAK,WAAW,UAAU,GAAG,SAAS,cAAc,SAAS,KAAmB;CAC5F,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,OAAO,SAAS,QAAQ,SAAS;CACvC,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EAAM,WAAW,GAAG,eAAe,OAAO,WAAW,SAAS;EAAG,GAAI;EAClE,UAAA,OACG,SAAS,IAAI,WAAW,UAAW,SAAS,OAAO,OAAO,oBAAC,MAAD,EAAA,UAAK,MAAU,CAAA,CAAE,IAC3E;CACA,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
import { ColorSchemeMode } from "../lib/theme.js";
|
|
3
|
+
export interface ColorSchemeScriptProps {
|
|
4
|
+
/** Same key as SlurpProvider's `storageKey`. */
|
|
5
|
+
storageKey?: string;
|
|
6
|
+
/** Same as the theme's `colorScheme`. */
|
|
7
|
+
defaultMode?: ColorSchemeMode;
|
|
8
|
+
nonce?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Applies the remembered colour scheme before the first paint (no flash of the wrong theme with SSR).
|
|
12
|
+
* Render it in <head>, and put `suppressHydrationWarning` on <html>: the script changes its `data-theme`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ColorSchemeScript({ storageKey, defaultMode, nonce }: ColorSchemeScriptProps): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=ColorSchemeScript.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DEFAULT_STORAGE_KEY } from "../lib/theme.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/SlurpProvider/ColorSchemeScript.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Applies the remembered colour scheme before the first paint (no flash of the wrong theme with SSR).
|
|
7
|
+
* Render it in <head>, and put `suppressHydrationWarning` on <html>: the script changes its `data-theme`.
|
|
8
|
+
*/
|
|
9
|
+
function ColorSchemeScript({ storageKey = DEFAULT_STORAGE_KEY, defaultMode = "system", nonce }) {
|
|
10
|
+
const code = `(function(){var m;try{m=localStorage.getItem(${JSON.stringify(storageKey)})}catch(e){}if(m!=='light'&&m!=='dark'&&m!=='system')m=${JSON.stringify(defaultMode)};var r=document.documentElement;if(m==='system')r.removeAttribute('data-theme');else r.setAttribute('data-theme',m)})()`;
|
|
11
|
+
return /* @__PURE__ */ jsx("script", {
|
|
12
|
+
nonce,
|
|
13
|
+
dangerouslySetInnerHTML: { __html: code }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export { ColorSchemeScript };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=ColorSchemeScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorSchemeScript.js","names":[],"sources":["../../src/SlurpProvider/ColorSchemeScript.tsx"],"sourcesContent":["import { DEFAULT_STORAGE_KEY, type ColorSchemeMode } from '../lib/theme';\n\nexport interface ColorSchemeScriptProps {\n /** Same key as SlurpProvider's `storageKey`. */\n storageKey?: string;\n /** Same as the theme's `colorScheme`. */\n defaultMode?: ColorSchemeMode;\n nonce?: string;\n}\n\n/**\n * Applies the remembered colour scheme before the first paint (no flash of the wrong theme with SSR).\n * Render it in <head>, and put `suppressHydrationWarning` on <html>: the script changes its `data-theme`.\n */\nexport function ColorSchemeScript({\n storageKey = DEFAULT_STORAGE_KEY,\n defaultMode = 'system',\n nonce,\n}: ColorSchemeScriptProps) {\n const code = `(function(){var m;try{m=localStorage.getItem(${JSON.stringify(storageKey)})}catch(e){}if(m!=='light'&&m!=='dark'&&m!=='system')m=${JSON.stringify(defaultMode)};var r=document.documentElement;if(m==='system')r.removeAttribute('data-theme');else r.setAttribute('data-theme',m)})()`;\n return <script nonce={nonce} dangerouslySetInnerHTML={{ __html: code }} />;\n}\n"],"mappings":";;;;;;;;AAcA,SAAgB,kBAAkB,EAChC,aAAa,qBACb,cAAc,UACd,SACyB;CACzB,MAAM,OAAO,gDAAgD,KAAK,UAAU,UAAU,EAAE,yDAAyD,KAAK,UAAU,WAAW,EAAE;CAC7K,OAAO,oBAAC,UAAD;EAAe;EAAO,yBAAyB,EAAE,QAAQ,KAAK;CAAI,CAAA;AAC3E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { Theme } from "../lib/theme.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
export interface SlurpProviderProps {
|
|
5
|
+
/** From `createTheme()`. */
|
|
6
|
+
theme?: Theme;
|
|
7
|
+
/** localStorage key that remembers the chosen scheme; `null` disables persistence. Default `slurp-theme`. */
|
|
8
|
+
storageKey?: string | null;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Theme, colour scheme and runtime styles for everything inside.
|
|
13
|
+
* At the app root it renders no element: the colour scheme goes on <html data-theme>, theme overrides into one
|
|
14
|
+
* hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the
|
|
15
|
+
* colour scheme of the outer provider.
|
|
16
|
+
*/
|
|
17
|
+
export declare function SlurpProvider({ theme, storageKey, children }: SlurpProviderProps): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=SlurpProvider.d.ts.map
|