@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,22 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export interface ProgressOwnProps {
|
|
5
|
+
/** What is in progress ("Caricamento"): the accessible name. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Between 0 and `max`; leave it out while the amount is unknown (indeterminate). */
|
|
8
|
+
value?: number;
|
|
9
|
+
/** Default 100. */
|
|
10
|
+
max?: number;
|
|
11
|
+
/** `bar` (default) or `ring`. */
|
|
12
|
+
shape?: 'bar' | 'ring';
|
|
13
|
+
/** Ring diameter in px. Default 48. */
|
|
14
|
+
size?: number;
|
|
15
|
+
/** Shows the value: the percentage, or what `formatValue` returns. */
|
|
16
|
+
showValue?: boolean;
|
|
17
|
+
formatValue?: (value: number, max: number) => string;
|
|
18
|
+
}
|
|
19
|
+
export type ProgressProps<E extends ElementType = 'div'> = PolymorphicProps<E, ProgressOwnProps>;
|
|
20
|
+
/** Progress as a bar or a ring (the design system's ScoreRing geometry). The filled part is accent-ink (≥ 3:1). */
|
|
21
|
+
export declare function Progress<E extends ElementType = 'div'>(props: ProgressProps<E>): import("react").JSX.Element;
|
|
22
|
+
//# sourceMappingURL=Progress.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
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/Progress/Progress.tsx
|
|
7
|
+
const RING_R = 34;
|
|
8
|
+
const RING_C = 2 * Math.PI * RING_R;
|
|
9
|
+
/** Progress as a bar or a ring (the design system's ScoreRing geometry). The filled part is accent-ink (≥ 3:1). */
|
|
10
|
+
function Progress(props) {
|
|
11
|
+
const { as, css, className, label, value, max = 100, shape = "bar", size = 48, showValue = false, formatValue = (v, m) => `${Math.round(v / m * 100)}%`, style, ...rest } = useThemeProps("Progress", props);
|
|
12
|
+
const Root = as ?? "div";
|
|
13
|
+
const styled = useCss("Progress", "root", css);
|
|
14
|
+
const root = useAnimationRoot(rest);
|
|
15
|
+
const known = typeof value === "number" && Number.isFinite(value);
|
|
16
|
+
const clamped = known ? Math.min(max, Math.max(0, value)) : 0;
|
|
17
|
+
const ratio = max > 0 ? clamped / max : 0;
|
|
18
|
+
const text = known ? formatValue(clamped, max) : void 0;
|
|
19
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
20
|
+
className: cx("slurp-progress", styled.className, className),
|
|
21
|
+
role: "progressbar",
|
|
22
|
+
"aria-label": label,
|
|
23
|
+
"aria-valuemin": 0,
|
|
24
|
+
"aria-valuemax": max,
|
|
25
|
+
"aria-valuenow": known ? clamped : void 0,
|
|
26
|
+
"aria-valuetext": text,
|
|
27
|
+
"data-shape": shape,
|
|
28
|
+
"data-indeterminate": known ? void 0 : "",
|
|
29
|
+
style: {
|
|
30
|
+
"--slurp-progress-ratio": ratio,
|
|
31
|
+
...style
|
|
32
|
+
},
|
|
33
|
+
...root,
|
|
34
|
+
children: [shape === "ring" ? /* @__PURE__ */ jsxs("svg", {
|
|
35
|
+
width: size,
|
|
36
|
+
height: size,
|
|
37
|
+
viewBox: "0 0 80 80",
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
40
|
+
className: "slurp-progress-track",
|
|
41
|
+
cx: "40",
|
|
42
|
+
cy: "40",
|
|
43
|
+
r: RING_R
|
|
44
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
45
|
+
className: "slurp-progress-fill",
|
|
46
|
+
cx: "40",
|
|
47
|
+
cy: "40",
|
|
48
|
+
r: RING_R,
|
|
49
|
+
strokeDasharray: `${(known ? ratio : .25) * RING_C} ${RING_C}`,
|
|
50
|
+
transform: "rotate(-90 40 40)"
|
|
51
|
+
})]
|
|
52
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
53
|
+
className: "slurp-progress-bar",
|
|
54
|
+
"aria-hidden": "true",
|
|
55
|
+
children: /* @__PURE__ */ jsx("span", { className: "slurp-progress-fill" })
|
|
56
|
+
}), showValue && text && /* @__PURE__ */ jsx("span", {
|
|
57
|
+
className: "slurp-progress-value",
|
|
58
|
+
"aria-hidden": "true",
|
|
59
|
+
children: text
|
|
60
|
+
})]
|
|
61
|
+
})] });
|
|
62
|
+
}
|
|
63
|
+
export { Progress };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=Progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Progress.js","names":[],"sources":["../../src/Progress/Progress.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 ProgressOwnProps {\n /** What is in progress (\"Caricamento\"): the accessible name. */\n label: string;\n /** Between 0 and `max`; leave it out while the amount is unknown (indeterminate). */\n value?: number;\n /** Default 100. */\n max?: number;\n /** `bar` (default) or `ring`. */\n shape?: 'bar' | 'ring';\n /** Ring diameter in px. Default 48. */\n size?: number;\n /** Shows the value: the percentage, or what `formatValue` returns. */\n showValue?: boolean;\n formatValue?: (value: number, max: number) => string;\n}\n\nexport type ProgressProps<E extends ElementType = 'div'> = PolymorphicProps<E, ProgressOwnProps>;\n\nconst RING_R = 34;\nconst RING_C = 2 * Math.PI * RING_R;\n\n/** Progress as a bar or a ring (the design system's ScoreRing geometry). The filled part is accent-ink (≥ 3:1). */\nexport function Progress<E extends ElementType = 'div'>(props: ProgressProps<E>) {\n const {\n as,\n css,\n className,\n label,\n value,\n max = 100,\n shape = 'bar',\n size = 48,\n showValue = false,\n formatValue = (v: number, m: number) => `${Math.round((v / m) * 100)}%`,\n style,\n ...rest\n } = useThemeProps('Progress', props as ProgressProps);\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Progress', 'root', css);\n const root = useAnimationRoot(rest);\n const known = typeof value === 'number' && Number.isFinite(value);\n const clamped = known ? Math.min(max, Math.max(0, value)) : 0;\n const ratio = max > 0 ? clamped / max : 0;\n const text = known ? formatValue(clamped, max) : undefined;\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-progress', styled.className, className)}\n role=\"progressbar\"\n aria-label={label}\n aria-valuemin={0}\n aria-valuemax={max}\n aria-valuenow={known ? clamped : undefined}\n aria-valuetext={text}\n data-shape={shape}\n data-indeterminate={known ? undefined : ''}\n style={{ '--slurp-progress-ratio': ratio, ...style } as CSSProperties}\n {...root}\n >\n {shape === 'ring' ? (\n <svg width={size} height={size} viewBox=\"0 0 80 80\" aria-hidden=\"true\">\n <circle className=\"slurp-progress-track\" cx=\"40\" cy=\"40\" r={RING_R} />\n <circle\n className=\"slurp-progress-fill\"\n cx=\"40\"\n cy=\"40\"\n r={RING_R}\n strokeDasharray={`${(known ? ratio : 0.25) * RING_C} ${RING_C}`}\n transform=\"rotate(-90 40 40)\"\n />\n </svg>\n ) : (\n <span className=\"slurp-progress-bar\" aria-hidden=\"true\">\n <span className=\"slurp-progress-fill\" />\n </span>\n )}\n {showValue && text && (\n <span className=\"slurp-progress-value\" aria-hidden=\"true\">\n {text}\n </span>\n )}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;AAyBA,MAAM,SAAS;AACf,MAAM,SAAS,IAAI,KAAK,KAAK;;AAG7B,SAAgB,SAAwC,OAAyB;CAC/E,MAAM,EACJ,IACA,KACA,WACA,OACA,OACA,MAAM,KACN,QAAQ,OACR,OAAO,IACP,YAAY,OACZ,eAAe,GAAW,MAAc,GAAG,KAAK,MAAO,IAAI,IAAK,GAAG,EAAE,IACrE,OACA,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,YAAY,QAAQ,GAAG;CAC7C,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;CAChE,MAAM,UAAU,QAAQ,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI;CAC5D,MAAM,QAAQ,MAAM,IAAI,UAAU,MAAM;CACxC,MAAM,OAAO,QAAQ,YAAY,SAAS,GAAG,IAAI,KAAA;CACjD,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,WAAW,GAAG,kBAAkB,OAAO,WAAW,SAAS;EAC3D,MAAK;EACL,cAAY;EACZ,iBAAe;EACf,iBAAe;EACf,iBAAe,QAAQ,UAAU,KAAA;EACjC,kBAAgB;EAChB,cAAY;EACZ,sBAAoB,QAAQ,KAAA,IAAY;EACxC,OAAO;GAAE,0BAA0B;GAAO,GAAG;EAAM;EACnD,GAAI;EAXN,UAAA,CAaG,UAAU,SACT,qBAAC,OAAD;GAAK,OAAO;GAAM,QAAQ;GAAM,SAAQ;GAAY,eAAY;GAAhE,UAAA,CACE,oBAAC,UAAD;IAAQ,WAAU;IAAuB,IAAG;IAAK,IAAG;IAAK,GAAG;GAAS,CAAA,GACrE,oBAAC,UAAD;IACE,WAAU;IACV,IAAG;IACH,IAAG;IACH,GAAG;IACH,iBAAiB,IAAI,QAAQ,QAAQ,OAAQ,OAAO,GAAG;IACvD,WAAU;GACX,CAAA,CACE;EAEL,CAAA,IAAA,oBAAC,QAAD;GAAM,WAAU;GAAqB,eAAY;GAC/C,UAAA,oBAAC,QAAD,EAAM,WAAU,sBAAuB,CAAA;EACnC,CAAA,GAEP,aAAa,QACZ,oBAAC,QAAD;GAAM,WAAU;GAAuB,eAAY;GAChD,UAAA;EACG,CAAA,CAEJ;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 RadioOwnProps extends Omit<ToggleInputAttributes, 'value'>, PartsProps<'input' | 'dot' | 'label'> {
|
|
6
|
+
/** Submitted value; inside a RadioGroup, the value it selects. */
|
|
7
|
+
value: string;
|
|
8
|
+
/** Standalone use only (inside a RadioGroup the group decides). */
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
11
|
+
/** Leading icon (shown in `rows` groups). */
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export type RadioProps<E extends ElementType = 'label'> = PolymorphicProps<E, RadioOwnProps>;
|
|
16
|
+
/** Native radio: the checked one is an accent ring with a dot (a shape, not only colour). Use it in a RadioGroup. */
|
|
17
|
+
export declare function Radio<E extends ElementType = 'label'>(props: RadioProps<E>): import("react").JSX.Element;
|
|
18
|
+
export interface RadioGroupOwnProps extends PartsProps<'legend'> {
|
|
19
|
+
/** Name of the group (the fieldset's legend). */
|
|
20
|
+
label: ReactNode;
|
|
21
|
+
value?: string | null;
|
|
22
|
+
defaultValue?: string | null;
|
|
23
|
+
onValueChange?: (value: string) => void;
|
|
24
|
+
/** Form name of the radios (generated by default). */
|
|
25
|
+
name?: string;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* `rows` (the settings' choice rows): each option a full-width row with its icon; the chosen one is accent-soft
|
|
29
|
+
* with a check. Default `default`.
|
|
30
|
+
*/
|
|
31
|
+
appearance?: 'default' | 'rows';
|
|
32
|
+
/** Radios side by side. Default `vertical`. */
|
|
33
|
+
orientation?: 'vertical' | 'horizontal';
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export type RadioGroupProps<E extends ElementType = 'fieldset'> = PolymorphicProps<E, RadioGroupOwnProps>;
|
|
37
|
+
/** Single choice: a fieldset of native radios (arrow keys move and select, the legend names the group). */
|
|
38
|
+
export declare function RadioGroup<E extends ElementType = 'fieldset'>(props: RadioGroupProps<E>): import("react").JSX.Element;
|
|
39
|
+
//# sourceMappingURL=Radio.d.ts.map
|
|
@@ -0,0 +1,118 @@
|
|
|
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 { createContext, useContext, useId } from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { CheckIcon } from "@slurp-ui/icons";
|
|
10
|
+
// src/Radio/Radio.tsx
|
|
11
|
+
const RadioGroupContext = createContext(null);
|
|
12
|
+
/** Native radio: the checked one is an accent ring with a dot (a shape, not only colour). Use it in a RadioGroup. */
|
|
13
|
+
function Radio(props) {
|
|
14
|
+
const { as, css, className, checked: checkedProp, onCheckedChange, icon, children, parts, partProps, classNames, ...others } = useThemeProps("Radio", props);
|
|
15
|
+
const { input, root: rest } = splitToggleProps(others);
|
|
16
|
+
const group = useContext(RadioGroupContext);
|
|
17
|
+
const value = input.value;
|
|
18
|
+
const checked = group ? group.value === value : !!checkedProp;
|
|
19
|
+
const disabled = input.disabled ?? group?.disabled;
|
|
20
|
+
const rows = group?.appearance === "rows";
|
|
21
|
+
const Root = as ?? "label";
|
|
22
|
+
const styled = useCss("Radio", "root", css);
|
|
23
|
+
const { part, style } = useParts("Radio", {
|
|
24
|
+
parts,
|
|
25
|
+
partProps,
|
|
26
|
+
classNames
|
|
27
|
+
});
|
|
28
|
+
const root = useAnimationRoot(rest);
|
|
29
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
30
|
+
styled.style,
|
|
31
|
+
style,
|
|
32
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
33
|
+
className: cx("slurp-toggle", "slurp-radio", styled.className, className),
|
|
34
|
+
"data-state": checked ? "on" : "off",
|
|
35
|
+
"data-appearance": rows ? "rows" : void 0,
|
|
36
|
+
"data-disabled": disabled ? "" : void 0,
|
|
37
|
+
...root,
|
|
38
|
+
children: [
|
|
39
|
+
part("input", "input", {
|
|
40
|
+
...input,
|
|
41
|
+
type: "radio",
|
|
42
|
+
name: input.name ?? group?.name,
|
|
43
|
+
disabled,
|
|
44
|
+
className: "slurp-toggle-input",
|
|
45
|
+
checked,
|
|
46
|
+
onChange: (e) => {
|
|
47
|
+
if (!e.target.checked) return;
|
|
48
|
+
if (group) group.setValue(value);
|
|
49
|
+
else onCheckedChange?.(true);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
!rows && part("dot", "span", {
|
|
53
|
+
className: "slurp-radio-dot",
|
|
54
|
+
"aria-hidden": true
|
|
55
|
+
}),
|
|
56
|
+
rows && icon != null && /* @__PURE__ */ jsx("span", {
|
|
57
|
+
className: "slurp-radio-icon",
|
|
58
|
+
"aria-hidden": "true",
|
|
59
|
+
children: icon
|
|
60
|
+
}),
|
|
61
|
+
children != null && part("label", "span", {
|
|
62
|
+
className: "slurp-toggle-label",
|
|
63
|
+
children
|
|
64
|
+
}),
|
|
65
|
+
rows && /* @__PURE__ */ jsx("span", {
|
|
66
|
+
className: "slurp-radio-check",
|
|
67
|
+
"aria-hidden": "true",
|
|
68
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { size: 18 })
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
})
|
|
72
|
+
] });
|
|
73
|
+
}
|
|
74
|
+
/** Single choice: a fieldset of native radios (arrow keys move and select, the legend names the group). */
|
|
75
|
+
function RadioGroup(props) {
|
|
76
|
+
const { as, css, className, label, value: valueProp, defaultValue = null, onValueChange, name: nameProp, disabled, appearance = "default", orientation = "vertical", children, parts, partProps, classNames, ...rest } = useThemeProps("RadioGroup", props);
|
|
77
|
+
const [value, setValue] = useControlled({
|
|
78
|
+
value: valueProp,
|
|
79
|
+
defaultValue,
|
|
80
|
+
onChange: onValueChange
|
|
81
|
+
});
|
|
82
|
+
const auto = useId();
|
|
83
|
+
const Root = as ?? "fieldset";
|
|
84
|
+
const styled = useCss("RadioGroup", "root", css);
|
|
85
|
+
const { part, style } = useParts("RadioGroup", {
|
|
86
|
+
parts,
|
|
87
|
+
partProps,
|
|
88
|
+
classNames
|
|
89
|
+
});
|
|
90
|
+
const root = useAnimationRoot(rest);
|
|
91
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
92
|
+
styled.style,
|
|
93
|
+
style,
|
|
94
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
95
|
+
className: cx("slurp-radio-group", styled.className, className),
|
|
96
|
+
"data-orientation": orientation,
|
|
97
|
+
"data-appearance": appearance,
|
|
98
|
+
disabled,
|
|
99
|
+
...root,
|
|
100
|
+
children: [part("legend", "legend", {
|
|
101
|
+
className: "slurp-radio-group-legend",
|
|
102
|
+
children: label
|
|
103
|
+
}), /* @__PURE__ */ jsx(RadioGroupContext, {
|
|
104
|
+
value: {
|
|
105
|
+
name: nameProp ?? auto,
|
|
106
|
+
value,
|
|
107
|
+
setValue,
|
|
108
|
+
disabled,
|
|
109
|
+
appearance
|
|
110
|
+
},
|
|
111
|
+
children
|
|
112
|
+
})]
|
|
113
|
+
})
|
|
114
|
+
] });
|
|
115
|
+
}
|
|
116
|
+
export { Radio, RadioGroup };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=Radio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Radio.js","names":[],"sources":["../../src/Radio/Radio.tsx"],"sourcesContent":["import { CheckIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useContext,\n useId,\n type ChangeEvent,\n type ElementType,\n type ReactNode,\n} 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\ninterface RadioGroupContextValue {\n name: string;\n value: string | null;\n setValue: (value: string) => void;\n disabled?: boolean;\n appearance: 'default' | 'rows';\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null);\n\nexport interface RadioOwnProps\n extends Omit<ToggleInputAttributes, 'value'>, PartsProps<'input' | 'dot' | 'label'> {\n /** Submitted value; inside a RadioGroup, the value it selects. */\n value: string;\n /** Standalone use only (inside a RadioGroup the group decides). */\n checked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n /** Leading icon (shown in `rows` groups). */\n icon?: ReactNode;\n children?: ReactNode;\n}\n\nexport type RadioProps<E extends ElementType = 'label'> = PolymorphicProps<E, RadioOwnProps>;\n\n/** Native radio: the checked one is an accent ring with a dot (a shape, not only colour). Use it in a RadioGroup. */\nexport function Radio<E extends ElementType = 'label'>(props: RadioProps<E>) {\n const {\n as,\n css,\n className,\n checked: checkedProp,\n onCheckedChange,\n icon,\n children,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('Radio', props as RadioProps);\n const { input, root: rest } = splitToggleProps(others);\n const group = useContext(RadioGroupContext);\n const value = input.value as string;\n const checked = group ? group.value === value : !!checkedProp;\n const disabled = (input.disabled as boolean | undefined) ?? group?.disabled;\n const rows = group?.appearance === 'rows';\n const Root = (as ?? 'label') as ElementType;\n const styled = useCss('Radio', 'root', css);\n const { part, style } = useParts('Radio', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-toggle', 'slurp-radio', styled.className, className)}\n data-state={checked ? 'on' : 'off'}\n data-appearance={rows ? 'rows' : undefined}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('input', 'input', {\n ...input,\n type: 'radio',\n name: (input.name as string | undefined) ?? group?.name,\n disabled,\n className: 'slurp-toggle-input',\n checked,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n if (!e.target.checked) return;\n if (group) group.setValue(value);\n else onCheckedChange?.(true);\n },\n })}\n {!rows && part('dot', 'span', { className: 'slurp-radio-dot', 'aria-hidden': true })}\n {rows && icon != null && (\n <span className=\"slurp-radio-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {children != null && part('label', 'span', { className: 'slurp-toggle-label', children })}\n {rows && (\n <span className=\"slurp-radio-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </Root>\n </>\n );\n}\n\nexport interface RadioGroupOwnProps extends PartsProps<'legend'> {\n /** Name of the group (the fieldset's legend). */\n label: ReactNode;\n value?: string | null;\n defaultValue?: string | null;\n onValueChange?: (value: string) => void;\n /** Form name of the radios (generated by default). */\n name?: string;\n disabled?: boolean;\n /**\n * `rows` (the settings' choice rows): each option a full-width row with its icon; the chosen one is accent-soft\n * with a check. Default `default`.\n */\n appearance?: 'default' | 'rows';\n /** Radios side by side. Default `vertical`. */\n orientation?: 'vertical' | 'horizontal';\n children?: ReactNode;\n}\n\nexport type RadioGroupProps<E extends ElementType = 'fieldset'> = PolymorphicProps<\n E,\n RadioGroupOwnProps\n>;\n\n/** Single choice: a fieldset of native radios (arrow keys move and select, the legend names the group). */\nexport function RadioGroup<E extends ElementType = 'fieldset'>(props: RadioGroupProps<E>) {\n const {\n as,\n css,\n className,\n label,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n name: nameProp,\n disabled,\n appearance = 'default',\n orientation = 'vertical',\n children,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('RadioGroup', props as RadioGroupProps);\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const auto = useId();\n const Root = (as ?? 'fieldset') as ElementType;\n const styled = useCss('RadioGroup', 'root', css);\n const { part, style } = useParts('RadioGroup', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-radio-group', styled.className, className)}\n data-orientation={orientation}\n data-appearance={appearance}\n disabled={disabled}\n {...root}\n >\n {part('legend', 'legend', { className: 'slurp-radio-group-legend', children: label })}\n <RadioGroupContext\n value={{ name: nameProp ?? auto, value, setValue, disabled, appearance }}\n >\n {children}\n </RadioGroupContext>\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,oBAAoB,cAA6C,IAAI;;AAiB3E,SAAgB,MAAuC,OAAsB;CAC3E,MAAM,EACJ,IACA,KACA,WACA,SAAS,aACT,iBACA,MACA,UACA,OACA,WACA,YACA,GAAG,WACD,cAAc,SAAS,KAAmB;CAC9C,MAAM,EAAE,OAAO,MAAM,SAAS,iBAAiB,MAAM;CACrD,MAAM,QAAQ,WAAW,iBAAiB;CAC1C,MAAM,QAAQ,MAAM;CACpB,MAAM,UAAU,QAAQ,MAAM,UAAU,QAAQ,CAAC,CAAC;CAClD,MAAM,WAAY,MAAM,YAAoC,OAAO;CACnE,MAAM,OAAO,OAAO,eAAe;CACnC,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,EAAE,MAAM,UAAU,SAAS,SAAS;EAAE;EAAO;EAAW;CAAW,CAAC;CAC1E,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,WAAW,GAAG,gBAAgB,eAAe,OAAO,WAAW,SAAS;GACxE,cAAY,UAAU,OAAO;GAC7B,mBAAiB,OAAO,SAAS,KAAA;GACjC,iBAAe,WAAW,KAAK,KAAA;GAC/B,GAAI;GALN,UAAA;IAOG,KAAK,SAAS,SAAS;KACtB,GAAG;KACH,MAAM;KACN,MAAO,MAAM,QAA+B,OAAO;KACnD;KACA,WAAW;KACX;KACA,WAAW,MAAqC;MAC9C,IAAI,CAAC,EAAE,OAAO,SAAS;MACvB,IAAI,OAAO,MAAM,SAAS,KAAK;WAC1B,kBAAkB,IAAI;KAC7B;IACF,CAAC;IACA,CAAC,QAAQ,KAAK,OAAO,QAAQ;KAAE,WAAW;KAAmB,eAAe;IAAK,CAAC;IAClF,QAAQ,QAAQ,QACf,oBAAC,QAAD;KAAM,WAAU;KAAmB,eAAY;KAC5C,UAAA;IACG,CAAA;IAEP,YAAY,QAAQ,KAAK,SAAS,QAAQ;KAAE,WAAW;KAAsB;IAAS,CAAC;IACvF,QACC,oBAAC,QAAD;KAAM,WAAU;KAAoB,eAAY;KAC9C,UAAA,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;IAClB,CAAA;GAEJ;;CACN,EAAA,CAAA;AAEN;;AA2BA,SAAgB,WAA+C,OAA2B;CACxF,MAAM,EACJ,IACA,KACA,WACA,OACA,OAAO,WACP,eAAe,MACf,eACA,MAAM,UACN,UACA,aAAa,WACb,cAAc,YACd,UACA,OACA,WACA,YACA,GAAG,SACD,cAAc,cAAc,KAAwB;CACxD,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,OAAO,MAAM;CACnB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,cAAc,QAAQ,GAAG;CAC/C,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;EAAE;EAAO;EAAW;CAAW,CAAC;CAC/E,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,WAAW,GAAG,qBAAqB,OAAO,WAAW,SAAS;GAC9D,oBAAkB;GAClB,mBAAiB;GACP;GACV,GAAI;GALN,UAAA,CAOG,KAAK,UAAU,UAAU;IAAE,WAAW;IAA4B,UAAU;GAAM,CAAC,GACpF,oBAAC,mBAAD;IACE,OAAO;KAAE,MAAM,YAAY;KAAM;KAAO;KAAU;KAAU;IAAW;IAEtE;GACgB,CAAA,CACf;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface RangeOwnProps extends PartsProps<'label' | 'value' | 'control'> {
|
|
5
|
+
/** Visible label. */
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
value?: number;
|
|
8
|
+
defaultValue?: number;
|
|
9
|
+
onValueChange?: (value: number) => void;
|
|
10
|
+
/** Default 0. */
|
|
11
|
+
min?: number;
|
|
12
|
+
/** Default 100. */
|
|
13
|
+
max?: number;
|
|
14
|
+
/** Default 1. */
|
|
15
|
+
step?: number;
|
|
16
|
+
/** Text of the value, shown next to the label and read by screen readers ("1.200 €"). */
|
|
17
|
+
formatValue?: (value: number) => string;
|
|
18
|
+
/** Shows the value next to the label. Default true. */
|
|
19
|
+
showValue?: boolean;
|
|
20
|
+
name?: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type RangeProps<E extends ElementType = 'div'> = PolymorphicProps<E, RangeOwnProps>;
|
|
24
|
+
/** Slider on a native range input: 44px thumb target, accent-ink fill, arrow keys / Page keys / Home / End. */
|
|
25
|
+
export declare function Range<E extends ElementType = 'div'>(props: RangeProps<E>): import("react").JSX.Element;
|
|
26
|
+
//# sourceMappingURL=Range.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { useId } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/Range/Range.tsx
|
|
9
|
+
/** Slider on a native range input: 44px thumb target, accent-ink fill, arrow keys / Page keys / Home / End. */
|
|
10
|
+
function Range(props) {
|
|
11
|
+
const { as, css, className, label, value: valueProp, defaultValue, onValueChange, min = 0, max = 100, step = 1, formatValue = String, showValue = true, name, disabled, style, parts, partProps, classNames, ...rest } = useThemeProps("Range", props);
|
|
12
|
+
const [value, setValue] = useControlled({
|
|
13
|
+
value: valueProp,
|
|
14
|
+
defaultValue: defaultValue ?? min,
|
|
15
|
+
onChange: onValueChange
|
|
16
|
+
});
|
|
17
|
+
const id = useId();
|
|
18
|
+
const Root = as ?? "div";
|
|
19
|
+
const styled = useCss("Range", "root", css);
|
|
20
|
+
const { part, style: partsStyle } = useParts("Range", {
|
|
21
|
+
parts,
|
|
22
|
+
partProps,
|
|
23
|
+
classNames
|
|
24
|
+
});
|
|
25
|
+
const root = useAnimationRoot(rest);
|
|
26
|
+
const ratio = max > min ? (Math.min(max, Math.max(min, value)) - min) / (max - min) : 0;
|
|
27
|
+
const text = formatValue(value);
|
|
28
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
29
|
+
styled.style,
|
|
30
|
+
partsStyle,
|
|
31
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
32
|
+
className: cx("slurp-range", styled.className, className),
|
|
33
|
+
"data-disabled": disabled ? "" : void 0,
|
|
34
|
+
style: {
|
|
35
|
+
"--slurp-range-ratio": ratio,
|
|
36
|
+
...style
|
|
37
|
+
},
|
|
38
|
+
...root,
|
|
39
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
40
|
+
className: "slurp-range-head",
|
|
41
|
+
children: [part("label", "label", {
|
|
42
|
+
htmlFor: id,
|
|
43
|
+
className: "slurp-range-label",
|
|
44
|
+
children: label
|
|
45
|
+
}), showValue && part("value", "output", {
|
|
46
|
+
htmlFor: id,
|
|
47
|
+
className: "slurp-range-value",
|
|
48
|
+
children: text
|
|
49
|
+
})]
|
|
50
|
+
}), part("control", "input", {
|
|
51
|
+
id,
|
|
52
|
+
type: "range",
|
|
53
|
+
className: "slurp-range-control",
|
|
54
|
+
name,
|
|
55
|
+
min,
|
|
56
|
+
max,
|
|
57
|
+
step,
|
|
58
|
+
disabled,
|
|
59
|
+
value,
|
|
60
|
+
"aria-valuetext": text,
|
|
61
|
+
onChange: (e) => setValue(Number(e.target.value))
|
|
62
|
+
})]
|
|
63
|
+
})
|
|
64
|
+
] });
|
|
65
|
+
}
|
|
66
|
+
export { Range };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=Range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Range.js","names":[],"sources":["../../src/Range/Range.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n useId,\n type ChangeEvent,\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';\n\nexport interface RangeOwnProps extends PartsProps<'label' | 'value' | 'control'> {\n /** Visible label. */\n label: ReactNode;\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n /** Default 0. */\n min?: number;\n /** Default 100. */\n max?: number;\n /** Default 1. */\n step?: number;\n /** Text of the value, shown next to the label and read by screen readers (\"1.200 €\"). */\n formatValue?: (value: number) => string;\n /** Shows the value next to the label. Default true. */\n showValue?: boolean;\n name?: string;\n disabled?: boolean;\n}\n\nexport type RangeProps<E extends ElementType = 'div'> = PolymorphicProps<E, RangeOwnProps>;\n\n/** Slider on a native range input: 44px thumb target, accent-ink fill, arrow keys / Page keys / Home / End. */\nexport function Range<E extends ElementType = 'div'>(props: RangeProps<E>) {\n const {\n as,\n css,\n className,\n label,\n value: valueProp,\n defaultValue,\n onValueChange,\n min = 0,\n max = 100,\n step = 1,\n formatValue = String,\n showValue = true,\n name,\n disabled,\n style,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Range', props as RangeProps);\n const [value, setValue] = useControlled({\n value: valueProp,\n defaultValue: defaultValue ?? min,\n onChange: onValueChange,\n });\n const id = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Range', 'root', css);\n const { part, style: partsStyle } = useParts('Range', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const ratio = max > min ? (Math.min(max, Math.max(min, value)) - min) / (max - min) : 0;\n const text = formatValue(value);\n return (\n <>\n {styled.style}\n {partsStyle}\n <Root\n className={cx('slurp-range', styled.className, className)}\n data-disabled={disabled ? '' : undefined}\n style={{ '--slurp-range-ratio': ratio, ...style } as CSSProperties}\n {...root}\n >\n <div className=\"slurp-range-head\">\n {part('label', 'label', { htmlFor: id, className: 'slurp-range-label', children: label })}\n {showValue &&\n part('value', 'output', {\n htmlFor: id,\n className: 'slurp-range-value',\n children: text,\n })}\n </div>\n {part('control', 'input', {\n id,\n type: 'range',\n className: 'slurp-range-control',\n name,\n min,\n max,\n step,\n disabled,\n value,\n 'aria-valuetext': text,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(Number(e.target.value)),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAqCA,SAAgB,MAAqC,OAAsB;CACzE,MAAM,EACJ,IACA,KACA,WACA,OACA,OAAO,WACP,cACA,eACA,MAAM,GACN,MAAM,KACN,OAAO,GACP,cAAc,QACd,YAAY,MACZ,MACA,UACA,OACA,OACA,WACA,YACA,GAAG,SACD,cAAc,SAAS,KAAmB;CAC9C,MAAM,CAAC,OAAO,YAAY,cAAc;EACtC,OAAO;EACP,cAAc,gBAAgB;EAC9B,UAAU;CACZ,CAAC;CACD,MAAM,KAAK,MAAM;CACjB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,EAAE,MAAM,OAAO,eAAe,SAAS,SAAS;EAAE;EAAO;EAAW;CAAW,CAAC;CACtF,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,MAAM,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC,IAAI,QAAQ,MAAM,OAAO;CACtF,MAAM,OAAO,YAAY,KAAK;CAC9B,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,WAAW,GAAG,eAAe,OAAO,WAAW,SAAS;GACxD,iBAAe,WAAW,KAAK,KAAA;GAC/B,OAAO;IAAE,uBAAuB;IAAO,GAAG;GAAM;GAChD,GAAI;GAJN,UAAA,CAME,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACG,KAAK,SAAS,SAAS;KAAE,SAAS;KAAI,WAAW;KAAqB,UAAU;IAAM,CAAC,GACvF,aACC,KAAK,SAAS,UAAU;KACtB,SAAS;KACT,WAAW;KACX,UAAU;IACZ,CAAC,CACA;GACJ,CAAA,GAAA,KAAK,WAAW,SAAS;IACxB;IACA,MAAM;IACN,WAAW;IACX;IACA;IACA;IACA;IACA;IACA;IACA,kBAAkB;IAClB,WAAW,MAAqC,SAAS,OAAO,EAAE,OAAO,KAAK,CAAC;GACjF,CAAC,CACG;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface ResultRowOwnProps {
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
meta?: ReactNode;
|
|
7
|
+
value?: ReactNode;
|
|
8
|
+
/** Small media (44px), decorative. */
|
|
9
|
+
media?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export type ResultRowProps<E extends ElementType = 'button'> = PolymorphicProps<E, ResultRowOwnProps>;
|
|
12
|
+
/**
|
|
13
|
+
* A search result: media, title, meta and a value; the whole row is one control. Rows carry `data-result`, so the
|
|
14
|
+
* results list moves with the arrow keys (`moveFocus(e, root, '[data-result]')`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function ResultRow<E extends ElementType = 'button'>(props: ResultRowProps<E>): import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=ResultRow.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
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/ResultRow/ResultRow.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A search result: media, title, meta and a value; the whole row is one control. Rows carry `data-result`, so the
|
|
9
|
+
* results list moves with the arrow keys (`moveFocus(e, root, '[data-result]')`).
|
|
10
|
+
*/
|
|
11
|
+
function ResultRow(props) {
|
|
12
|
+
const { as, css, className, title, meta, value, media, ...rest } = useThemeProps("ResultRow", props);
|
|
13
|
+
const Root = as ?? "button";
|
|
14
|
+
const styled = useCss("ResultRow", "root", css);
|
|
15
|
+
const root = useAnimationRoot(rest);
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
17
|
+
className: cx("slurp-result-row", styled.className, className),
|
|
18
|
+
"data-result": "",
|
|
19
|
+
...Root === "button" ? { type: "button" } : null,
|
|
20
|
+
...root,
|
|
21
|
+
children: [
|
|
22
|
+
media != null && /* @__PURE__ */ jsx("span", {
|
|
23
|
+
className: "slurp-result-row-media",
|
|
24
|
+
"aria-hidden": "true",
|
|
25
|
+
children: media
|
|
26
|
+
}),
|
|
27
|
+
/* @__PURE__ */ jsxs("span", {
|
|
28
|
+
className: "slurp-result-row-text",
|
|
29
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
30
|
+
className: "slurp-result-row-title",
|
|
31
|
+
children: title
|
|
32
|
+
}), meta != null && /* @__PURE__ */ jsx("span", {
|
|
33
|
+
className: "slurp-result-row-meta",
|
|
34
|
+
children: meta
|
|
35
|
+
})]
|
|
36
|
+
}),
|
|
37
|
+
value != null && /* @__PURE__ */ jsx("span", {
|
|
38
|
+
className: "slurp-result-row-value",
|
|
39
|
+
children: value
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
})] });
|
|
43
|
+
}
|
|
44
|
+
export { ResultRow };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=ResultRow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultRow.js","names":[],"sources":["../../src/ResultRow/ResultRow.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType, ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface ResultRowOwnProps {\n title: ReactNode;\n meta?: ReactNode;\n value?: ReactNode;\n /** Small media (44px), decorative. */\n media?: ReactNode;\n}\n\nexport type ResultRowProps<E extends ElementType = 'button'> = PolymorphicProps<\n E,\n ResultRowOwnProps\n>;\n\n/**\n * A search result: media, title, meta and a value; the whole row is one control. Rows carry `data-result`, so the\n * results list moves with the arrow keys (`moveFocus(e, root, '[data-result]')`).\n */\nexport function ResultRow<E extends ElementType = 'button'>(props: ResultRowProps<E>) {\n const { as, css, className, title, meta, value, media, ...rest } = useThemeProps(\n 'ResultRow',\n props as ResultRowProps,\n );\n const Root = (as ?? 'button') as ElementType;\n const styled = useCss('ResultRow', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-result-row', styled.className, className)}\n data-result=\"\"\n {...(Root === 'button' ? { type: 'button' } : null)}\n {...root}\n >\n {media != null && (\n <span className=\"slurp-result-row-media\" aria-hidden=\"true\">\n {media}\n </span>\n )}\n <span className=\"slurp-result-row-text\">\n <span className=\"slurp-result-row-title\">{title}</span>\n {meta != null && <span className=\"slurp-result-row-meta\">{meta}</span>}\n </span>\n {value != null && <span className=\"slurp-result-row-value\">{value}</span>}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAwBA,SAAgB,UAA4C,OAA0B;CACpF,MAAM,EAAE,IAAI,KAAK,WAAW,OAAO,MAAM,OAAO,OAAO,GAAG,SAAS,cACjE,aACA,KACF;CACA,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,aAAa,QAAQ,GAAG;CAC9C,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,WAAW,GAAG,oBAAoB,OAAO,WAAW,SAAS;EAC7D,eAAY;EACZ,GAAK,SAAS,WAAW,EAAE,MAAM,SAAS,IAAI;EAC9C,GAAI;EAJN,UAAA;GAMG,SAAS,QACR,oBAAC,QAAD;IAAM,WAAU;IAAyB,eAAY;IAClD,UAAA;GACG,CAAA;GAER,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CACE,oBAAC,QAAD;KAAM,WAAU;KAA0B,UAAA;IAAY,CAAA,GACrD,QAAQ,QAAQ,oBAAC,QAAD;KAAM,WAAU;KAAyB,UAAA;IAAW,CAAA,CACjE;;GACL,SAAS,QAAQ,oBAAC,QAAD;IAAM,WAAU;IAA0B,UAAA;GAAY,CAAA;EACpE;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 ScoreOwnProps {
|
|
5
|
+
score: number;
|
|
6
|
+
/** Default 10. */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Diameter in px. Default 96. */
|
|
9
|
+
size?: number;
|
|
10
|
+
/** What is scored, for the accessible name: "Punteggio 9.1 su 10". Default `Punteggio`. */
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
export type ScoreProps<E extends ElementType = 'span'> = PolymorphicProps<E, ScoreOwnProps>;
|
|
14
|
+
/** A score with one decimal in a ring (accent-ink arc, ≥ 3:1). */
|
|
15
|
+
export declare function Score<E extends ElementType = 'span'>(props: ScoreProps<E>): import("react").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=Score.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
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/Score/Score.tsx
|
|
7
|
+
const R = 34;
|
|
8
|
+
const C = 2 * Math.PI * R;
|
|
9
|
+
/** A score with one decimal in a ring (accent-ink arc, ≥ 3:1). */
|
|
10
|
+
function Score(props) {
|
|
11
|
+
const { as, css, className, score, max = 10, size = 96, label = "Punteggio", ...rest } = useThemeProps("Score", props);
|
|
12
|
+
const Root = as ?? "span";
|
|
13
|
+
const styled = useCss("Score", "root", css);
|
|
14
|
+
const root = useAnimationRoot(rest);
|
|
15
|
+
const value = Number(score) || 0;
|
|
16
|
+
const shown = value.toFixed(1);
|
|
17
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
18
|
+
className: cx("slurp-score", styled.className, className),
|
|
19
|
+
role: "img",
|
|
20
|
+
"aria-label": `${label} ${shown} su ${max}`,
|
|
21
|
+
...root,
|
|
22
|
+
children: /* @__PURE__ */ jsxs("svg", {
|
|
23
|
+
width: size,
|
|
24
|
+
height: size,
|
|
25
|
+
viewBox: "0 0 80 80",
|
|
26
|
+
"aria-hidden": "true",
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx("circle", {
|
|
29
|
+
className: "slurp-score-track",
|
|
30
|
+
cx: "40",
|
|
31
|
+
cy: "40",
|
|
32
|
+
r: R
|
|
33
|
+
}),
|
|
34
|
+
/* @__PURE__ */ jsx("circle", {
|
|
35
|
+
className: "slurp-score-arc",
|
|
36
|
+
cx: "40",
|
|
37
|
+
cy: "40",
|
|
38
|
+
r: R,
|
|
39
|
+
strokeDasharray: `${Math.min(max, Math.max(0, value)) / max * C} ${C}`,
|
|
40
|
+
transform: "rotate(-90 40 40)"
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ jsx("text", {
|
|
43
|
+
x: "40",
|
|
44
|
+
y: "47",
|
|
45
|
+
textAnchor: "middle",
|
|
46
|
+
className: "slurp-score-label",
|
|
47
|
+
children: shown
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
})
|
|
51
|
+
})] });
|
|
52
|
+
}
|
|
53
|
+
export { Score };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=Score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Score.js","names":[],"sources":["../../src/Score/Score.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 ScoreOwnProps {\n score: number;\n /** Default 10. */\n max?: number;\n /** Diameter in px. Default 96. */\n size?: number;\n /** What is scored, for the accessible name: \"Punteggio 9.1 su 10\". Default `Punteggio`. */\n label?: string;\n}\n\nexport type ScoreProps<E extends ElementType = 'span'> = PolymorphicProps<E, ScoreOwnProps>;\n\nconst R = 34;\nconst C = 2 * Math.PI * R;\n\n/** A score with one decimal in a ring (accent-ink arc, ≥ 3:1). */\nexport function Score<E extends ElementType = 'span'>(props: ScoreProps<E>) {\n const {\n as,\n css,\n className,\n score,\n max = 10,\n size = 96,\n label = 'Punteggio',\n ...rest\n } = useThemeProps('Score', props as ScoreProps);\n const Root = (as ?? 'span') as ElementType;\n const styled = useCss('Score', 'root', css);\n const root = useAnimationRoot(rest);\n const value = Number(score) || 0;\n const shown = value.toFixed(1);\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-score', styled.className, className)}\n role=\"img\"\n aria-label={`${label} ${shown} su ${max}`}\n {...root}\n >\n <svg width={size} height={size} viewBox=\"0 0 80 80\" aria-hidden=\"true\">\n <circle className=\"slurp-score-track\" cx=\"40\" cy=\"40\" r={R} />\n <circle\n className=\"slurp-score-arc\"\n cx=\"40\"\n cy=\"40\"\n r={R}\n strokeDasharray={`${(Math.min(max, Math.max(0, value)) / max) * C} ${C}`}\n transform=\"rotate(-90 40 40)\"\n />\n <text x=\"40\" y=\"47\" textAnchor=\"middle\" className=\"slurp-score-label\">\n {shown}\n </text>\n </svg>\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;AAmBA,MAAM,IAAI;AACV,MAAM,IAAI,IAAI,KAAK,KAAK;;AAGxB,SAAgB,MAAsC,OAAsB;CAC1E,MAAM,EACJ,IACA,KACA,WACA,OACA,MAAM,IACN,OAAO,IACP,QAAQ,aACR,GAAG,SACD,cAAc,SAAS,KAAmB;CAC9C,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,OAAO,KAAK,KAAK;CAC/B,MAAM,QAAQ,MAAM,QAAQ,CAAC;CAC7B,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EACE,WAAW,GAAG,eAAe,OAAO,WAAW,SAAS;EACxD,MAAK;EACL,cAAY,GAAG,MAAM,GAAG,MAAM,MAAM;EACpC,GAAI;EAEJ,UAAA,qBAAC,OAAD;GAAK,OAAO;GAAM,QAAQ;GAAM,SAAQ;GAAY,eAAY;GAAhE,UAAA;IACE,oBAAC,UAAD;KAAQ,WAAU;KAAoB,IAAG;KAAK,IAAG;KAAK,GAAG;IAAI,CAAA;IAC7D,oBAAC,UAAD;KACE,WAAU;KACV,IAAG;KACH,IAAG;KACH,GAAG;KACH,iBAAiB,GAAI,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,MAAO,EAAE,GAAG;KACrE,WAAU;IACX,CAAA;IACD,oBAAC,QAAD;KAAM,GAAE;KAAK,GAAE;KAAK,YAAW;KAAS,WAAU;KAC/C,UAAA;IACG,CAAA;GACH;;CACD,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { InputAttributes } from "../Field/Field.js";
|
|
4
|
+
import { ElementType } from "react";
|
|
5
|
+
export interface SearchLabels {
|
|
6
|
+
/** Name of the field (read by screen readers; hidden). */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Says where it looks: "Cerca in Smartphone…". */
|
|
9
|
+
placeholder: string;
|
|
10
|
+
/** Name of the clear button. */
|
|
11
|
+
clear: string;
|
|
12
|
+
/** Result count, announced politely while typing. */
|
|
13
|
+
results: (count: number) => string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SEARCH_LABELS: SearchLabels;
|
|
16
|
+
export interface SearchOwnProps extends Omit<InputAttributes, 'type'>, PartsProps<'icon' | 'control' | 'clear' | 'status'> {
|
|
17
|
+
value?: string;
|
|
18
|
+
defaultValue?: string;
|
|
19
|
+
onValueChange?: (value: string) => void;
|
|
20
|
+
/** Enter. */
|
|
21
|
+
onSearch?: (value: string) => void;
|
|
22
|
+
/** Number of results: shown at the end of the field and announced (polite live region). */
|
|
23
|
+
count?: number;
|
|
24
|
+
labels?: Partial<SearchLabels>;
|
|
25
|
+
}
|
|
26
|
+
export type SearchProps<E extends ElementType = 'div'> = PolymorphicProps<E, SearchOwnProps>;
|
|
27
|
+
/** Search field: icon, contextual placeholder, result count, clear button. */
|
|
28
|
+
export declare function Search<E extends ElementType = 'div'>(props: SearchProps<E>): import("react").JSX.Element;
|
|
29
|
+
//# sourceMappingURL=Search.d.ts.map
|