@slurp-ui/react 1.0.1 → 1.1.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 +25 -0
- package/dist/Card/Card.d.ts +1 -1
- package/dist/Card/Card.js.map +1 -1
- package/dist/Carousel/Carousel.d.ts +36 -0
- package/dist/Carousel/Carousel.js +179 -0
- package/dist/Carousel/Carousel.js.map +1 -0
- package/dist/Carousel/index.d.ts +3 -0
- package/dist/Carousel/index.js +2 -0
- package/dist/Dock/Dock.d.ts +1 -1
- package/dist/Dock/Dock.js.map +1 -1
- package/dist/ListRow/ListRow.d.ts +1 -1
- package/dist/ListRow/ListRow.js.map +1 -1
- package/dist/Pages/Pages.d.ts +45 -0
- package/dist/Pages/Pages.js +128 -0
- package/dist/Pages/Pages.js.map +1 -0
- package/dist/Pages/index.d.ts +3 -0
- package/dist/Pages/index.js +2 -0
- package/dist/Range/Range.d.ts +1 -1
- package/dist/Range/Range.js.map +1 -1
- package/dist/Rating/Rating.d.ts +36 -0
- package/dist/Rating/Rating.js +118 -0
- package/dist/Rating/Rating.js.map +1 -0
- package/dist/Rating/index.d.ts +3 -0
- package/dist/Rating/index.js +2 -0
- package/dist/Search/Search.d.ts +1 -1
- package/dist/Search/Search.js.map +1 -1
- package/dist/Steps/Steps.d.ts +41 -0
- package/dist/Steps/Steps.js +89 -0
- package/dist/Steps/Steps.js.map +1 -0
- package/dist/Steps/index.d.ts +3 -0
- package/dist/Steps/index.js +2 -0
- package/dist/Suggest/Suggest.d.ts +54 -0
- package/dist/Suggest/Suggest.js +257 -0
- package/dist/Suggest/Suggest.js.map +1 -0
- package/dist/Suggest/index.d.ts +3 -0
- package/dist/Suggest/index.js +2 -0
- package/dist/Table/Table.d.ts +52 -0
- package/dist/Table/Table.js +127 -0
- package/dist/Table/Table.js.map +1 -0
- package/dist/Table/index.d.ts +3 -0
- package/dist/Table/index.js +2 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +7 -1
- package/dist/lib/theme.d.ts +30 -0
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +968 -65
- package/dist/tokens.css +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,128 @@
|
|
|
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 { Fragment } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "@slurp-ui/icons";
|
|
9
|
+
// src/Pages/Pages.tsx
|
|
10
|
+
const PAGES_LABELS = {
|
|
11
|
+
label: "Pagine",
|
|
12
|
+
previous: "Pagina precedente",
|
|
13
|
+
next: "Pagina successiva",
|
|
14
|
+
page: (n) => `Pagina ${n}`,
|
|
15
|
+
status: (n, count) => `${n} di ${count}`
|
|
16
|
+
};
|
|
17
|
+
const span = (from, to) => Array.from({ length: Math.max(0, to - from + 1) }, (_, i) => from + i);
|
|
18
|
+
/**
|
|
19
|
+
* The items of a pagination: the ends, a window around the current page and a gap where pages are left out. The length
|
|
20
|
+
* stays the same whatever the page, so the controls never jump; a gap never stands for a single page.
|
|
21
|
+
*/
|
|
22
|
+
function pageItems(page, count, siblings = 1, boundaries = 1) {
|
|
23
|
+
if (count <= 2 * boundaries + 2 * siblings + 3) return span(1, count);
|
|
24
|
+
const lo = Math.min(Math.max(page - siblings, boundaries + 2), count - boundaries - 1 - 2 * siblings);
|
|
25
|
+
const hi = lo + 2 * siblings;
|
|
26
|
+
const left = lo === boundaries + 2 ? span(1, boundaries + 1) : [...span(1, boundaries), "gap"];
|
|
27
|
+
const right = hi === count - boundaries - 1 ? span(count - boundaries, count) : ["gap", ...span(count - boundaries + 1, count)];
|
|
28
|
+
return [
|
|
29
|
+
...left,
|
|
30
|
+
...span(lo, hi),
|
|
31
|
+
...right
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pagination: previous, the page numbers (the current one filled, `aria-current="page"`) and next. On phones only
|
|
36
|
+
* previous, "3 di 12" and next. With `href` every item is a real link.
|
|
37
|
+
*/
|
|
38
|
+
function Pages(props) {
|
|
39
|
+
const { as, css, className, count: countProp, page: pageProp, defaultPage = 1, onPageChange, siblings = 1, boundaries = 1, href, disabled = false, labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Pages", props);
|
|
40
|
+
const labels = {
|
|
41
|
+
...PAGES_LABELS,
|
|
42
|
+
...labelsProp
|
|
43
|
+
};
|
|
44
|
+
const count = Math.max(1, Math.floor(countProp));
|
|
45
|
+
const [raw, setPage] = useControlled({
|
|
46
|
+
value: pageProp,
|
|
47
|
+
defaultValue: defaultPage,
|
|
48
|
+
onChange: onPageChange
|
|
49
|
+
});
|
|
50
|
+
const page = Math.min(count, Math.max(1, raw));
|
|
51
|
+
const Root = as ?? "nav";
|
|
52
|
+
const styled = useCss("Pages", "root", css);
|
|
53
|
+
const { part, style } = useParts("Pages", {
|
|
54
|
+
parts,
|
|
55
|
+
partProps,
|
|
56
|
+
classNames
|
|
57
|
+
});
|
|
58
|
+
const root = useAnimationRoot(rest);
|
|
59
|
+
/** A link or a button that goes to `to`; unavailable (the ends, disabled) it keeps its place but does nothing. */
|
|
60
|
+
const control = (to, off) => {
|
|
61
|
+
const go = (e) => {
|
|
62
|
+
if (off) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (to !== page) setPage(to);
|
|
67
|
+
};
|
|
68
|
+
if (href) return off ? {
|
|
69
|
+
"aria-disabled": true,
|
|
70
|
+
role: "link",
|
|
71
|
+
onClick: go
|
|
72
|
+
} : {
|
|
73
|
+
href: href(to),
|
|
74
|
+
onClick: go
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
type: "button",
|
|
78
|
+
disabled: off,
|
|
79
|
+
onClick: go
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const Tag = href ? "a" : "button";
|
|
83
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
84
|
+
styled.style,
|
|
85
|
+
style,
|
|
86
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
87
|
+
className: cx("slurp-pages", styled.className, className),
|
|
88
|
+
"aria-label": labels.label,
|
|
89
|
+
"data-disabled": disabled ? "" : void 0,
|
|
90
|
+
...root,
|
|
91
|
+
children: [
|
|
92
|
+
part("previous", Tag, {
|
|
93
|
+
...control(page - 1, disabled || page <= 1),
|
|
94
|
+
className: "slurp-pages-step",
|
|
95
|
+
"aria-label": labels.previous,
|
|
96
|
+
children: /* @__PURE__ */ jsx(ChevronLeftIcon, { size: 20 })
|
|
97
|
+
}),
|
|
98
|
+
part("list", "ul", {
|
|
99
|
+
className: "slurp-pages-list",
|
|
100
|
+
children: pageItems(page, count, siblings, boundaries).map((item, i) => /* @__PURE__ */ jsx("li", { children: item === "gap" ? /* @__PURE__ */ jsx("span", {
|
|
101
|
+
className: "slurp-pages-gap",
|
|
102
|
+
"aria-hidden": "true",
|
|
103
|
+
children: "…"
|
|
104
|
+
}) : /* @__PURE__ */ jsx(Fragment, { children: part("item", Tag, {
|
|
105
|
+
...control(item, disabled),
|
|
106
|
+
className: "slurp-pages-item",
|
|
107
|
+
"aria-label": labels.page(item),
|
|
108
|
+
"aria-current": item === page ? "page" : void 0,
|
|
109
|
+
children: item
|
|
110
|
+
}) }) }, item === "gap" ? `gap-${i}` : item))
|
|
111
|
+
}),
|
|
112
|
+
part("status", "span", {
|
|
113
|
+
className: "slurp-pages-status",
|
|
114
|
+
children: labels.status(page, count)
|
|
115
|
+
}),
|
|
116
|
+
part("next", Tag, {
|
|
117
|
+
...control(page + 1, disabled || page >= count),
|
|
118
|
+
className: "slurp-pages-step",
|
|
119
|
+
"aria-label": labels.next,
|
|
120
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, { size: 20 })
|
|
121
|
+
})
|
|
122
|
+
]
|
|
123
|
+
})
|
|
124
|
+
] });
|
|
125
|
+
}
|
|
126
|
+
export { PAGES_LABELS, Pages, pageItems };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=Pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pages.js","names":[],"sources":["../../src/Pages/Pages.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { Fragment, type ElementType, type MouseEvent } 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 PagesLabels {\n /** Name of the navigation landmark. */\n label: string;\n previous: string;\n next: string;\n /** Name of a page link (\"Pagina 3\"). */\n page: (page: number) => string;\n /** Where you are, shown on phones instead of the numbers (\"3 di 12\"). */\n status: (page: number, count: number) => string;\n}\n\nexport const PAGES_LABELS: PagesLabels = {\n label: 'Pagine',\n previous: 'Pagina precedente',\n next: 'Pagina successiva',\n page: (n) => `Pagina ${n}`,\n status: (n, count) => `${n} di ${count}`,\n};\n\nexport interface PagesOwnProps extends PartsProps<\n 'list' | 'item' | 'previous' | 'next' | 'status'\n> {\n /** Number of pages. */\n count: number;\n /** Current page, from 1. */\n page?: number;\n /** Default 1. */\n defaultPage?: number;\n onPageChange?: (page: number) => void;\n /** Pages shown on each side of the current one. Default 1. */\n siblings?: number;\n /** Pages always shown at each end. Default 1. */\n boundaries?: number;\n /** URL of a page: the items become links (crawlable, open in a new tab). */\n href?: (page: number) => string;\n disabled?: boolean;\n labels?: Partial<PagesLabels>;\n}\n\nexport type PagesProps<E extends ElementType = 'nav'> = PolymorphicProps<E, PagesOwnProps>;\n\n/** A page number or a gap (\"…\") standing for the pages left out. */\nexport type PageItem = number | 'gap';\n\nconst span = (from: number, to: number) =>\n Array.from({ length: Math.max(0, to - from + 1) }, (_, i) => from + i);\n\n/**\n * The items of a pagination: the ends, a window around the current page and a gap where pages are left out. The length\n * stays the same whatever the page, so the controls never jump; a gap never stands for a single page.\n */\nexport function pageItems(page: number, count: number, siblings = 1, boundaries = 1): PageItem[] {\n const slots = 2 * boundaries + 2 * siblings + 3;\n if (count <= slots) return span(1, count);\n const lo = Math.min(\n Math.max(page - siblings, boundaries + 2),\n count - boundaries - 1 - 2 * siblings,\n );\n const hi = lo + 2 * siblings;\n const left: PageItem[] =\n lo === boundaries + 2 ? span(1, boundaries + 1) : [...span(1, boundaries), 'gap'];\n const right: PageItem[] =\n hi === count - boundaries - 1\n ? span(count - boundaries, count)\n : ['gap', ...span(count - boundaries + 1, count)];\n return [...left, ...span(lo, hi), ...right];\n}\n\n/**\n * Pagination: previous, the page numbers (the current one filled, `aria-current=\"page\"`) and next. On phones only\n * previous, \"3 di 12\" and next. With `href` every item is a real link.\n */\nexport function Pages<E extends ElementType = 'nav'>(props: PagesProps<E>) {\n const {\n as,\n css,\n className,\n count: countProp,\n page: pageProp,\n defaultPage = 1,\n onPageChange,\n siblings = 1,\n boundaries = 1,\n href,\n disabled = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Pages', props as PagesProps);\n const labels = { ...PAGES_LABELS, ...labelsProp };\n const count = Math.max(1, Math.floor(countProp));\n const [raw, setPage] = useControlled({\n value: pageProp,\n defaultValue: defaultPage,\n onChange: onPageChange,\n });\n const page = Math.min(count, Math.max(1, raw));\n const Root = (as ?? 'nav') as ElementType;\n const styled = useCss('Pages', 'root', css);\n const { part, style } = useParts('Pages', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n /** A link or a button that goes to `to`; unavailable (the ends, disabled) it keeps its place but does nothing. */\n const control = (to: number, off: boolean) => {\n const go = (e: MouseEvent) => {\n if (off) {\n e.preventDefault();\n return;\n }\n if (to !== page) setPage(to);\n };\n if (href) {\n return off\n ? { 'aria-disabled': true, role: 'link', onClick: go }\n : { href: href(to), onClick: go };\n }\n return { type: 'button', disabled: off, onClick: go };\n };\n const Tag = href ? 'a' : 'button';\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-pages', styled.className, className)}\n aria-label={labels.label}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('previous', Tag, {\n ...control(page - 1, disabled || page <= 1),\n className: 'slurp-pages-step',\n 'aria-label': labels.previous,\n children: <ChevronLeftIcon size={20} />,\n })}\n {part('list', 'ul', {\n className: 'slurp-pages-list',\n children: pageItems(page, count, siblings, boundaries).map((item, i) => (\n <li key={item === 'gap' ? `gap-${i}` : item}>\n {item === 'gap' ? (\n <span className=\"slurp-pages-gap\" aria-hidden=\"true\">\n …\n </span>\n ) : (\n <Fragment>\n {part('item', Tag, {\n ...control(item, disabled),\n className: 'slurp-pages-item',\n 'aria-label': labels.page(item),\n 'aria-current': item === page ? 'page' : undefined,\n children: item,\n })}\n </Fragment>\n )}\n </li>\n )),\n })}\n {part('status', 'span', {\n className: 'slurp-pages-status',\n children: labels.status(page, count),\n })}\n {part('next', Tag, {\n ...control(page + 1, disabled || page >= count),\n className: 'slurp-pages-step',\n 'aria-label': labels.next,\n children: <ChevronRightIcon size={20} />,\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAa,eAA4B;CACvC,OAAO;CACP,UAAU;CACV,MAAM;CACN,OAAO,MAAM,UAAU;CACvB,SAAS,GAAG,UAAU,GAAG,EAAE,MAAM;AACnC;AA2BA,MAAM,QAAQ,MAAc,OAC1B,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,KAAK,OAAO,CAAC,EAAE,IAAI,GAAG,MAAM,OAAO,CAAC;;;;;AAMvE,SAAgB,UAAU,MAAc,OAAe,WAAW,GAAG,aAAa,GAAe;CAE/F,IAAI,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AAY,QAAQ,KAAK;KAC9C,WAAW;KACX,cAAc,OAAO;KACrB,UAAU,oBAAC,kBAAD,EAAkB,MAAM,GAAK,CAAA;IACzC,CAAC;GACG;;CACN,EAAA,CAAA;AAEN"}
|
package/dist/Range/Range.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface RangeOwnProps extends PartsProps<'label' | 'value' | 'control'>
|
|
|
13
13
|
max?: number;
|
|
14
14
|
/** Default 1. */
|
|
15
15
|
step?: number;
|
|
16
|
-
/** Text of the value, shown next to the label and read by screen readers ("
|
|
16
|
+
/** Text of the value, shown next to the label and read by screen readers ("75%", "3 di 5"). */
|
|
17
17
|
formatValue?: (value: number) => string;
|
|
18
18
|
/** Shows the value next to the label. Default true. */
|
|
19
19
|
showValue?: boolean;
|
package/dist/Range/Range.js.map
CHANGED
|
@@ -1 +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
|
+
{"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 (\"75%\", \"3 di 5\"). */\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,36 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ControlSize } from "../Button/Button.js";
|
|
4
|
+
import { ElementType } from "react";
|
|
5
|
+
export interface RatingLabels {
|
|
6
|
+
/** The value as words ("4.5 su 5"): the name of a read-only rating, after its label. */
|
|
7
|
+
value: (value: string, max: number) => string;
|
|
8
|
+
/** Name of one star of the input ("3 stelle"). */
|
|
9
|
+
star: (stars: number) => string;
|
|
10
|
+
}
|
|
11
|
+
export declare const RATING_LABELS: RatingLabels;
|
|
12
|
+
export interface RatingOwnProps {
|
|
13
|
+
/** What is rated ("Il tuo voto", "Valutazione media"): the legend of the input, the name of a read-only rating. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Stars chosen; null for none yet. A read-only rating may be fractional (4.5). */
|
|
16
|
+
value?: number | null;
|
|
17
|
+
defaultValue?: number | null;
|
|
18
|
+
onValueChange?: (value: number) => void;
|
|
19
|
+
/** Number of stars. Default 5. */
|
|
20
|
+
max?: number;
|
|
21
|
+
/** Shows a value instead of asking for one: one image named "Valutazione media: 4.5 su 5". */
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
/** Form field name (radio inputs). */
|
|
24
|
+
name?: string;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** Star size: `sm` 20, `md` 28 (default), `lg` 36. Each star of the input stays a 44px target. */
|
|
27
|
+
size?: ControlSize;
|
|
28
|
+
labels?: Partial<RatingLabels>;
|
|
29
|
+
}
|
|
30
|
+
export type RatingProps<E extends ElementType = 'fieldset'> = PolymorphicProps<E, RatingOwnProps>;
|
|
31
|
+
/**
|
|
32
|
+
* Stars. As an input it is a group of native radios (arrow keys move and choose, the legend names it): chosen stars
|
|
33
|
+
* are filled, the others outlined (shape, not only colour). Read-only it is one image with the value in words.
|
|
34
|
+
*/
|
|
35
|
+
export declare function Rating<E extends ElementType = 'fieldset'>(props: RatingProps<E>): import("react").JSX.Element;
|
|
36
|
+
//# sourceMappingURL=Rating.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, useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
6
|
+
import { useId } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { StarIcon } from "@slurp-ui/icons";
|
|
9
|
+
// src/Rating/Rating.tsx
|
|
10
|
+
const RATING_LABELS = {
|
|
11
|
+
value: (v, max) => `${v} su ${max}`,
|
|
12
|
+
star: (n) => n === 1 ? "1 stella" : `${n} stelle`
|
|
13
|
+
};
|
|
14
|
+
const ICON = {
|
|
15
|
+
sm: 20,
|
|
16
|
+
md: 28,
|
|
17
|
+
lg: 36
|
|
18
|
+
};
|
|
19
|
+
/** One decimal, like scores; whole numbers stay whole ("4", "4.5"). */
|
|
20
|
+
const shown = (v) => Number.isInteger(v) ? String(v) : v.toFixed(1);
|
|
21
|
+
/**
|
|
22
|
+
* Stars. As an input it is a group of native radios (arrow keys move and choose, the legend names it): chosen stars
|
|
23
|
+
* are filled, the others outlined (shape, not only colour). Read-only it is one image with the value in words.
|
|
24
|
+
*/
|
|
25
|
+
function Rating(props) {
|
|
26
|
+
const { as, css, className, label, value: valueProp, defaultValue = null, onValueChange, max: maxProp = 5, readOnly = false, name: nameProp, disabled = false, size = "md", labels: labelsProp, style, ...rest } = useThemeProps("Rating", props);
|
|
27
|
+
const labels = {
|
|
28
|
+
...RATING_LABELS,
|
|
29
|
+
...labelsProp
|
|
30
|
+
};
|
|
31
|
+
const max = Math.max(1, Math.round(maxProp));
|
|
32
|
+
const [value, setValue] = useControlled({
|
|
33
|
+
value: valueProp,
|
|
34
|
+
defaultValue,
|
|
35
|
+
onChange: onValueChange
|
|
36
|
+
});
|
|
37
|
+
const auto = useId();
|
|
38
|
+
const name = nameProp ?? auto;
|
|
39
|
+
const styled = useCss("Rating", "root", css);
|
|
40
|
+
const root = useAnimationRoot(rest);
|
|
41
|
+
const stars = Array.from({ length: max }, (_, i) => i + 1);
|
|
42
|
+
const icon = ICON[size];
|
|
43
|
+
const clamped = Math.min(max, Math.max(0, value ?? 0));
|
|
44
|
+
if (readOnly) {
|
|
45
|
+
const Root = as ?? "span";
|
|
46
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
47
|
+
className: cx("slurp-rating", styled.className, className),
|
|
48
|
+
role: "img",
|
|
49
|
+
"aria-label": `${label}: ${labels.value(shown(clamped), max)}`,
|
|
50
|
+
"data-readonly": "",
|
|
51
|
+
"data-size": size,
|
|
52
|
+
style: {
|
|
53
|
+
"--slurp-rating-ratio": clamped / max,
|
|
54
|
+
...style
|
|
55
|
+
},
|
|
56
|
+
...root,
|
|
57
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
58
|
+
className: "slurp-rating-track",
|
|
59
|
+
"aria-hidden": "true",
|
|
60
|
+
children: [stars.map((n) => /* @__PURE__ */ jsx(StarIcon, {
|
|
61
|
+
size: icon,
|
|
62
|
+
className: "slurp-rating-icon"
|
|
63
|
+
}, n)), /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "slurp-rating-fill",
|
|
65
|
+
children: stars.map((n) => /* @__PURE__ */ jsx(StarIcon, {
|
|
66
|
+
size: icon,
|
|
67
|
+
className: "slurp-rating-icon",
|
|
68
|
+
fill: "currentColor"
|
|
69
|
+
}, n))
|
|
70
|
+
})]
|
|
71
|
+
})
|
|
72
|
+
})] });
|
|
73
|
+
}
|
|
74
|
+
const Root = as ?? "fieldset";
|
|
75
|
+
const fieldset = Root === "fieldset";
|
|
76
|
+
const Legend = fieldset ? "legend" : "span";
|
|
77
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
78
|
+
className: cx("slurp-rating", styled.className, className),
|
|
79
|
+
"data-size": size,
|
|
80
|
+
"data-disabled": disabled ? "" : void 0,
|
|
81
|
+
disabled: fieldset ? disabled : void 0,
|
|
82
|
+
role: fieldset ? void 0 : "radiogroup",
|
|
83
|
+
"aria-labelledby": fieldset ? void 0 : `${auto}-label`,
|
|
84
|
+
style,
|
|
85
|
+
...root,
|
|
86
|
+
children: [/* @__PURE__ */ jsx(Legend, {
|
|
87
|
+
id: `${auto}-label`,
|
|
88
|
+
className: "slurp-rating-label",
|
|
89
|
+
children: label
|
|
90
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
91
|
+
className: "slurp-rating-stars",
|
|
92
|
+
children: stars.map((n) => {
|
|
93
|
+
const on = n <= clamped;
|
|
94
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
95
|
+
className: "slurp-rating-star",
|
|
96
|
+
"data-on": on ? "" : void 0,
|
|
97
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
98
|
+
type: "radio",
|
|
99
|
+
className: "slurp-rating-input",
|
|
100
|
+
name,
|
|
101
|
+
value: n,
|
|
102
|
+
checked: value === n,
|
|
103
|
+
disabled,
|
|
104
|
+
"aria-label": labels.star(n),
|
|
105
|
+
onChange: () => setValue(n)
|
|
106
|
+
}), /* @__PURE__ */ jsx(StarIcon, {
|
|
107
|
+
size: icon,
|
|
108
|
+
className: "slurp-rating-icon",
|
|
109
|
+
fill: on ? "currentColor" : "none"
|
|
110
|
+
})]
|
|
111
|
+
}, n);
|
|
112
|
+
})
|
|
113
|
+
})]
|
|
114
|
+
})] });
|
|
115
|
+
}
|
|
116
|
+
export { RATING_LABELS, Rating };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=Rating.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rating.js","names":[],"sources":["../../src/Rating/Rating.tsx"],"sourcesContent":["import { StarIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, type CSSProperties, type ElementType } from 'react';\n\nimport type { ControlSize } from '../Button/Button';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface RatingLabels {\n /** The value as words (\"4.5 su 5\"): the name of a read-only rating, after its label. */\n value: (value: string, max: number) => string;\n /** Name of one star of the input (\"3 stelle\"). */\n star: (stars: number) => string;\n}\n\nexport const RATING_LABELS: RatingLabels = {\n value: (v, max) => `${v} su ${max}`,\n star: (n) => (n === 1 ? '1 stella' : `${n} stelle`),\n};\n\nexport interface RatingOwnProps {\n /** What is rated (\"Il tuo voto\", \"Valutazione media\"): the legend of the input, the name of a read-only rating. */\n label: string;\n /** Stars chosen; null for none yet. A read-only rating may be fractional (4.5). */\n value?: number | null;\n defaultValue?: number | null;\n onValueChange?: (value: number) => void;\n /** Number of stars. Default 5. */\n max?: number;\n /** Shows a value instead of asking for one: one image named \"Valutazione media: 4.5 su 5\". */\n readOnly?: boolean;\n /** Form field name (radio inputs). */\n name?: string;\n disabled?: boolean;\n /** Star size: `sm` 20, `md` 28 (default), `lg` 36. Each star of the input stays a 44px target. */\n size?: ControlSize;\n labels?: Partial<RatingLabels>;\n}\n\nexport type RatingProps<E extends ElementType = 'fieldset'> = PolymorphicProps<E, RatingOwnProps>;\n\nconst ICON: Record<ControlSize, number> = { sm: 20, md: 28, lg: 36 };\n\n/** One decimal, like scores; whole numbers stay whole (\"4\", \"4.5\"). */\nconst shown = (v: number) => (Number.isInteger(v) ? String(v) : v.toFixed(1));\n\n/**\n * Stars. As an input it is a group of native radios (arrow keys move and choose, the legend names it): chosen stars\n * are filled, the others outlined (shape, not only colour). Read-only it is one image with the value in words.\n */\nexport function Rating<E extends ElementType = 'fieldset'>(props: RatingProps<E>) {\n const {\n as,\n css,\n className,\n label,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n max: maxProp = 5,\n readOnly = false,\n name: nameProp,\n disabled = false,\n size = 'md',\n labels: labelsProp,\n style,\n ...rest\n } = useThemeProps('Rating', props as RatingProps);\n const labels = { ...RATING_LABELS, ...labelsProp };\n const max = Math.max(1, Math.round(maxProp));\n const [value, setValue] = useControlled<number | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: number | null) => void) | undefined,\n });\n const auto = useId();\n const name = nameProp ?? auto;\n const styled = useCss('Rating', 'root', css);\n const root = useAnimationRoot(rest);\n const stars = Array.from({ length: max }, (_, i) => i + 1);\n const icon = ICON[size];\n const clamped = Math.min(max, Math.max(0, value ?? 0));\n\n if (readOnly) {\n const Root = (as ?? 'span') as ElementType;\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-rating', styled.className, className)}\n role=\"img\"\n aria-label={`${label}: ${labels.value(shown(clamped), max)}`}\n data-readonly=\"\"\n data-size={size}\n style={{ '--slurp-rating-ratio': clamped / max, ...style } as CSSProperties}\n {...root}\n >\n <span className=\"slurp-rating-track\" aria-hidden=\"true\">\n {stars.map((n) => (\n <StarIcon key={n} size={icon} className=\"slurp-rating-icon\" />\n ))}\n <span className=\"slurp-rating-fill\">\n {stars.map((n) => (\n <StarIcon key={n} size={icon} className=\"slurp-rating-icon\" fill=\"currentColor\" />\n ))}\n </span>\n </span>\n </Root>\n </>\n );\n }\n\n const Root = (as ?? 'fieldset') as ElementType;\n const fieldset = Root === 'fieldset';\n const Legend = fieldset ? 'legend' : 'span';\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-rating', styled.className, className)}\n data-size={size}\n data-disabled={disabled ? '' : undefined}\n disabled={fieldset ? disabled : undefined}\n role={fieldset ? undefined : 'radiogroup'}\n aria-labelledby={fieldset ? undefined : `${auto}-label`}\n style={style}\n {...root}\n >\n <Legend id={`${auto}-label`} className=\"slurp-rating-label\">\n {label}\n </Legend>\n <span className=\"slurp-rating-stars\">\n {stars.map((n) => {\n const on = n <= clamped;\n return (\n <label key={n} className=\"slurp-rating-star\" data-on={on ? '' : undefined}>\n <input\n type=\"radio\"\n className=\"slurp-rating-input\"\n name={name}\n value={n}\n checked={value === n}\n disabled={disabled}\n aria-label={labels.star(n)}\n onChange={() => setValue(n)}\n />\n <StarIcon\n size={icon}\n className=\"slurp-rating-icon\"\n fill={on ? 'currentColor' : 'none'}\n />\n </label>\n );\n })}\n </span>\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAa,gBAA8B;CACzC,QAAQ,GAAG,QAAQ,GAAG,EAAE,MAAM;CAC9B,OAAO,MAAO,MAAM,IAAI,aAAa,GAAG,EAAE;AAC5C;AAuBA,MAAM,OAAoC;CAAE,IAAI;CAAI,IAAI;CAAI,IAAI;AAAG;;AAGnE,MAAM,SAAS,MAAe,OAAO,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;;;;;AAM3E,SAAgB,OAA2C,OAAuB;CAChF,MAAM,EACJ,IACA,KACA,WACA,OACA,OAAO,WACP,eAAe,MACf,eACA,KAAK,UAAU,GACf,WAAW,OACX,MAAM,UACN,WAAW,OACX,OAAO,MACP,QAAQ,YACR,OACA,GAAG,SACD,cAAc,UAAU,KAAoB;CAChD,MAAM,SAAS;EAAE,GAAG;EAAe,GAAG;CAAW;CACjD,MAAM,MAAM,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,CAAC;CAC3C,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,YAAY;CACzB,MAAM,SAAS,OAAO,UAAU,QAAQ,GAA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A,CAUE,oBAAC,QAAD;GAAQ,IAAI,GAAG,KAAK;GAAS,WAAU;GACpC,UAAA;EACK,CAAA,GACR,oBAAC,QAAD;GAAM,WAAU;GACb,UAAA,MAAM,KAAK,MAAM;IAChB,MAAM,KAAK,KAAK;IAChB,OACE,qBAAC,SAAD;KAAe,WAAU;KAAoB,WAAS,KAAK,KAAK,KAAA;KAAhE,UAAA,CACE,oBAAC,SAAD;MACE,MAAK;MACL,WAAU;MACJ;MACN,OAAO;MACP,SAAS,UAAU;MACT;MACV,cAAY,OAAO,KAAK,CAAC;MACzB,gBAAgB,SAAS,CAAC;KAC3B,CAAA,GACD,oBAAC,UAAD;MACE,MAAM;MACN,WAAU;MACV,MAAM,KAAK,iBAAiB;KAC7B,CAAA,CACI;IAhBK,GAAA,CAgBL;GAEX,CAAC;EACG,CAAA,CACF;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
package/dist/Search/Search.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ElementType } from "react";
|
|
|
5
5
|
export interface SearchLabels {
|
|
6
6
|
/** Name of the field (read by screen readers; hidden). */
|
|
7
7
|
label: string;
|
|
8
|
-
/** Says where it looks: "Cerca in
|
|
8
|
+
/** Says where it looks: "Cerca in Archivio…". */
|
|
9
9
|
placeholder: string;
|
|
10
10
|
/** Name of the clear button. */
|
|
11
11
|
clear: string;
|
|
@@ -1 +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
|
|
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 Archivio…\". */\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,UAA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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,41 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface StepItem<V extends string = string> {
|
|
5
|
+
value: V;
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
/** A short line under the label: the choice made in that step ("Grigio siderale"). */
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** Never reachable from the steps, even when done. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface StepsLabels {
|
|
13
|
+
/** Name of the navigation landmark. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Read after the label of a completed step. */
|
|
16
|
+
done: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const STEPS_LABELS: StepsLabels;
|
|
19
|
+
export interface StepsOwnProps<V extends string = string> extends PartsProps<'list' | 'step'> {
|
|
20
|
+
steps: StepItem<V>[];
|
|
21
|
+
/** The current step. */
|
|
22
|
+
value?: V;
|
|
23
|
+
/** Default the first step. */
|
|
24
|
+
defaultValue?: V;
|
|
25
|
+
onValueChange?: (value: V) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Steps you can go to: `done` (default) the completed ones, to change an earlier choice; `all` any step; `none` no
|
|
28
|
+
* step (the flow moves only with its own buttons).
|
|
29
|
+
*/
|
|
30
|
+
navigable?: 'done' | 'all' | 'none';
|
|
31
|
+
/** Default `horizontal`; on phones the labels of the other steps hide. */
|
|
32
|
+
orientation?: 'horizontal' | 'vertical';
|
|
33
|
+
labels?: Partial<StepsLabels>;
|
|
34
|
+
}
|
|
35
|
+
export type StepsProps<V extends string = string, E extends ElementType = 'nav'> = PolymorphicProps<E, StepsOwnProps<V>>;
|
|
36
|
+
/**
|
|
37
|
+
* The steps of a flow of choices: done steps carry a check and can be reopened, the current one is ringed and marked
|
|
38
|
+
* `aria-current="step"`, the next ones wait with their number. State is shape + word, never colour alone.
|
|
39
|
+
*/
|
|
40
|
+
export declare function Steps<V extends string = string, E extends ElementType = 'nav'>(props: StepsProps<V, E>): import("react").JSX.Element;
|
|
41
|
+
//# sourceMappingURL=Steps.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
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 { Fragment } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { CheckIcon } from "@slurp-ui/icons";
|
|
9
|
+
// src/Steps/Steps.tsx
|
|
10
|
+
const STEPS_LABELS = {
|
|
11
|
+
label: "Passaggi",
|
|
12
|
+
done: "completato"
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The steps of a flow of choices: done steps carry a check and can be reopened, the current one is ringed and marked
|
|
16
|
+
* `aria-current="step"`, the next ones wait with their number. State is shape + word, never colour alone.
|
|
17
|
+
*/
|
|
18
|
+
function Steps(props) {
|
|
19
|
+
const { as, css, className, steps, value: valueProp, defaultValue, onValueChange, navigable = "done", orientation = "horizontal", labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Steps", props);
|
|
20
|
+
const labels = {
|
|
21
|
+
...STEPS_LABELS,
|
|
22
|
+
...labelsProp
|
|
23
|
+
};
|
|
24
|
+
const [value, setValue] = useControlled({
|
|
25
|
+
value: valueProp,
|
|
26
|
+
defaultValue: defaultValue ?? steps[0]?.value,
|
|
27
|
+
onChange: onValueChange
|
|
28
|
+
});
|
|
29
|
+
const current = Math.max(0, steps.findIndex((s) => s.value === value));
|
|
30
|
+
const Root = as ?? "nav";
|
|
31
|
+
const styled = useCss("Steps", "root", css);
|
|
32
|
+
const { part, style } = useParts("Steps", {
|
|
33
|
+
parts,
|
|
34
|
+
partProps,
|
|
35
|
+
classNames
|
|
36
|
+
});
|
|
37
|
+
const root = useAnimationRoot(rest);
|
|
38
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
39
|
+
styled.style,
|
|
40
|
+
style,
|
|
41
|
+
/* @__PURE__ */ jsx(Root, {
|
|
42
|
+
className: cx("slurp-steps", styled.className, className),
|
|
43
|
+
"aria-label": labels.label,
|
|
44
|
+
"data-orientation": orientation,
|
|
45
|
+
...root,
|
|
46
|
+
children: part("list", "ol", {
|
|
47
|
+
className: "slurp-steps-list",
|
|
48
|
+
children: steps.map((s, i) => {
|
|
49
|
+
const state = i < current ? "done" : i === current ? "current" : "upcoming";
|
|
50
|
+
const reachable = i !== current && !s.disabled && (navigable === "all" || navigable === "done" && state === "done");
|
|
51
|
+
const body = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
52
|
+
className: "slurp-steps-marker",
|
|
53
|
+
"aria-hidden": "true",
|
|
54
|
+
children: state === "done" ? /* @__PURE__ */ jsx(CheckIcon, { size: 18 }) : i + 1
|
|
55
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
56
|
+
className: "slurp-steps-text",
|
|
57
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
58
|
+
className: "slurp-steps-label",
|
|
59
|
+
children: [s.label, state === "done" && /* @__PURE__ */ jsxs("span", {
|
|
60
|
+
className: "slurp-visually-hidden",
|
|
61
|
+
children: [", ", labels.done]
|
|
62
|
+
})]
|
|
63
|
+
}), s.description != null && /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "slurp-steps-description",
|
|
65
|
+
children: s.description
|
|
66
|
+
})]
|
|
67
|
+
})] });
|
|
68
|
+
return /* @__PURE__ */ jsx(Fragment, { children: part("step", "li", {
|
|
69
|
+
className: "slurp-steps-step",
|
|
70
|
+
"data-state": state,
|
|
71
|
+
"aria-current": state === "current" ? "step" : void 0,
|
|
72
|
+
children: reachable ? /* @__PURE__ */ jsx("button", {
|
|
73
|
+
type: "button",
|
|
74
|
+
className: "slurp-steps-control",
|
|
75
|
+
onClick: () => setValue(s.value),
|
|
76
|
+
children: body
|
|
77
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
78
|
+
className: "slurp-steps-control",
|
|
79
|
+
children: body
|
|
80
|
+
})
|
|
81
|
+
}) }, s.value);
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
] });
|
|
86
|
+
}
|
|
87
|
+
export { STEPS_LABELS, Steps };
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=Steps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Steps.js","names":[],"sources":["../../src/Steps/Steps.tsx"],"sourcesContent":["import { CheckIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { Fragment, type ElementType, type ReactNode } 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 StepItem<V extends string = string> {\n value: V;\n label: ReactNode;\n /** A short line under the label: the choice made in that step (\"Grigio siderale\"). */\n description?: ReactNode;\n /** Never reachable from the steps, even when done. */\n disabled?: boolean;\n}\n\nexport interface StepsLabels {\n /** Name of the navigation landmark. */\n label: string;\n /** Read after the label of a completed step. */\n done: string;\n}\n\nexport const STEPS_LABELS: StepsLabels = { label: 'Passaggi', done: 'completato' };\n\nexport interface StepsOwnProps<V extends string = string> extends PartsProps<'list' | 'step'> {\n steps: StepItem<V>[];\n /** The current step. */\n value?: V;\n /** Default the first step. */\n defaultValue?: V;\n onValueChange?: (value: V) => void;\n /**\n * Steps you can go to: `done` (default) the completed ones, to change an earlier choice; `all` any step; `none` no\n * step (the flow moves only with its own buttons).\n */\n navigable?: 'done' | 'all' | 'none';\n /** Default `horizontal`; on phones the labels of the other steps hide. */\n orientation?: 'horizontal' | 'vertical';\n labels?: Partial<StepsLabels>;\n}\n\nexport type StepsProps<V extends string = string, E extends ElementType = 'nav'> = PolymorphicProps<\n E,\n StepsOwnProps<V>\n>;\n\n/**\n * The steps of a flow of choices: done steps carry a check and can be reopened, the current one is ringed and marked\n * `aria-current=\"step\"`, the next ones wait with their number. State is shape + word, never colour alone.\n */\nexport function Steps<V extends string = string, E extends ElementType = 'nav'>(\n props: StepsProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n steps,\n value: valueProp,\n defaultValue,\n onValueChange,\n navigable = 'done',\n orientation = 'horizontal',\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Steps', props as unknown as StepsProps);\n const labels = { ...STEPS_LABELS, ...labelsProp };\n const [value, setValue] = useControlled<string | undefined>({\n value: valueProp,\n defaultValue: defaultValue ?? steps[0]?.value,\n onChange: onValueChange as ((v: string | undefined) => void) | undefined,\n });\n const current = Math.max(\n 0,\n steps.findIndex((s) => s.value === value),\n );\n const Root = (as ?? 'nav') as ElementType;\n const styled = useCss('Steps', 'root', css);\n const { part, style } = useParts('Steps', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-steps', styled.className, className)}\n aria-label={labels.label}\n data-orientation={orientation}\n {...root}\n >\n {part('list', 'ol', {\n className: 'slurp-steps-list',\n children: steps.map((s, i) => {\n const state = i < current ? 'done' : i === current ? 'current' : 'upcoming';\n const reachable =\n i !== current &&\n !s.disabled &&\n (navigable === 'all' || (navigable === 'done' && state === 'done'));\n const body = (\n <>\n <span className=\"slurp-steps-marker\" aria-hidden=\"true\">\n {state === 'done' ? <CheckIcon size={18} /> : i + 1}\n </span>\n <span className=\"slurp-steps-text\">\n <span className=\"slurp-steps-label\">\n {s.label}\n {state === 'done' && (\n <span className=\"slurp-visually-hidden\">, {labels.done}</span>\n )}\n </span>\n {s.description != null && (\n <span className=\"slurp-steps-description\">{s.description}</span>\n )}\n </span>\n </>\n );\n return (\n <Fragment key={s.value}>\n {part('step', 'li', {\n className: 'slurp-steps-step',\n 'data-state': state,\n 'aria-current': state === 'current' ? 'step' : undefined,\n children: reachable ? (\n <button\n type=\"button\"\n className=\"slurp-steps-control\"\n onClick={() => setValue(s.value)}\n >\n {body}\n </button>\n ) : (\n <span className=\"slurp-steps-control\">{body}</span>\n ),\n })}\n </Fragment>\n );\n }),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAyBA,MAAa,eAA4B;CAAE,OAAO;CAAY,MAAM;AAAa;;;;;AA4BjF,SAAgB,MACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,OAAO,WACP,cACA,eACA,YAAY,QACZ,cAAc,cACd,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,SAAS,KAA8B;CACzD,MAAM,SAAS;EAAE,GAAG;EAAc,GAAG;CAAW;CAChD,MAAM,CAAC,OAAO,YAAY,cAAkC;EAC1D,OAAO;EACP,cAAc,gBAAgB,MAAM,EAAE,EAAE;EACxC,UAAU;CACZ,CAAC;CACD,MAAM,UAAU,KAAK,IACnB,GACA,MAAM,WAAW,MAAM,EAAE,UAAU,KAAK,CAC1C;CACA,MAAM,OAAQ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A;MACK,CAAA,IAER,oBAAC,QAAD;OAAM,WAAU;OAAuB,UAAA;MAAW,CAAA;KAEtD,CAAC,EACO,GAjBK,EAAE,KAiBP;IAEd,CAAC;GACH,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { InputAttributes } from "../Field/Field.js";
|
|
4
|
+
import { ElementType, ReactNode } from "react";
|
|
5
|
+
export interface SuggestOption<V extends string = string> {
|
|
6
|
+
value: V;
|
|
7
|
+
/** Text of the option, written into the field when chosen. */
|
|
8
|
+
label: string;
|
|
9
|
+
/** A second line (a brand, a category); also searched. */
|
|
10
|
+
description?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface SuggestLabels {
|
|
14
|
+
/** Number of suggestions, announced politely while typing. */
|
|
15
|
+
results: (count: number) => string;
|
|
16
|
+
/** Shown in the list, and announced, when nothing matches. */
|
|
17
|
+
empty: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const SUGGEST_LABELS: SuggestLabels;
|
|
20
|
+
export interface SuggestOwnProps<V extends string = string> extends Omit<InputAttributes, 'type'>, PartsProps<'label' | 'control' | 'list' | 'option' | 'hint' | 'error'> {
|
|
21
|
+
/** Visible label. */
|
|
22
|
+
label: ReactNode;
|
|
23
|
+
hint?: ReactNode;
|
|
24
|
+
/** Error message: marks the field invalid. */
|
|
25
|
+
error?: ReactNode;
|
|
26
|
+
options: SuggestOption<V>[];
|
|
27
|
+
/** The chosen option; null while the text matches none. */
|
|
28
|
+
value?: V | null;
|
|
29
|
+
defaultValue?: V | null;
|
|
30
|
+
onValueChange?: (value: V | null) => void;
|
|
31
|
+
/** The text in the field. */
|
|
32
|
+
inputValue?: string;
|
|
33
|
+
/** Default the label of the chosen option, else empty. */
|
|
34
|
+
defaultInputValue?: string;
|
|
35
|
+
onInputValueChange?: (text: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Which options match the text. Default: every word of the text, in any order, ignoring case and accents, in the
|
|
38
|
+
* label or the description. `false` when the app already filters `options` (results from a server).
|
|
39
|
+
*/
|
|
40
|
+
filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;
|
|
41
|
+
/** Most suggestions listed. Default 8. */
|
|
42
|
+
limit?: number;
|
|
43
|
+
/** Lists the suggestions as soon as the field takes focus. Default false (they show while typing). */
|
|
44
|
+
openOnFocus?: boolean;
|
|
45
|
+
labels?: Partial<SuggestLabels>;
|
|
46
|
+
}
|
|
47
|
+
export type SuggestProps<V extends string = string, E extends ElementType = 'div'> = PolymorphicProps<E, SuggestOwnProps<V>>;
|
|
48
|
+
/**
|
|
49
|
+
* Text field with suggestions (combobox): the field **becomes** the list, growing downward on one surface. Focus
|
|
50
|
+
* stays in the field: arrows move through the suggestions, Enter chooses, Escape closes (then clears); matches are
|
|
51
|
+
* marked in the options.
|
|
52
|
+
*/
|
|
53
|
+
export declare function Suggest<V extends string = string, E extends ElementType = 'div'>(props: SuggestProps<V, E>): import("react").JSX.Element;
|
|
54
|
+
//# sourceMappingURL=Suggest.d.ts.map
|