@slurp-ui/react 1.0.1 → 1.1.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.
@@ -0,0 +1,2 @@
1
+
2
+ export { RATING_LABELS, Rating, Rating as default } from "./Rating.js";
@@ -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,MAAM;CACpB,MAAM,SAAS,O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AAD;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,3 @@
1
+
2
+ import { STEPS_LABELS, StepItem, Steps, StepsLabels, StepsProps } from "./Steps.js";
3
+ export { STEPS_LABELS, type StepItem, Steps, type StepsLabels, type StepsProps, Steps as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { STEPS_LABELS, Steps, Steps as default } from "./Steps.js";
@@ -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
@@ -0,0 +1,257 @@
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 { splitInputProps } from "../Field/Field.js";
7
+ import { useDismiss } from "../utils/useDismiss.js";
8
+ import { matchesAll } from "../lib/layout.js";
9
+ import { Mark } from "../Mark/Mark.js";
10
+ import { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
11
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
+ import { CheckIcon, ErrorIcon } from "@slurp-ui/icons";
13
+ // src/Suggest/Suggest.tsx
14
+ const SUGGEST_LABELS = {
15
+ results: (n) => n === 1 ? "1 suggerimento" : `${n} suggerimenti`,
16
+ empty: "Nessun suggerimento"
17
+ };
18
+ const matches = (o, text) => matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);
19
+ /**
20
+ * Text field with suggestions (combobox): the field **becomes** the list, growing downward on one surface. Focus
21
+ * stays in the field: arrows move through the suggestions, Enter chooses, Escape closes (then clears); matches are
22
+ * marked in the options.
23
+ */
24
+ function Suggest(props) {
25
+ const { as, css, className, label, hint, error, options, value: valueProp, defaultValue = null, onValueChange, inputValue, defaultInputValue, onInputValueChange, filter, limit = 8, openOnFocus = false, labels: labelsProp, parts, partProps, classNames, ...others } = useThemeProps("Suggest", props);
26
+ const labels = {
27
+ ...SUGGEST_LABELS,
28
+ ...labelsProp
29
+ };
30
+ const { input, root: rest } = splitInputProps(others);
31
+ const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input;
32
+ const [value, setValue] = useControlled({
33
+ value: valueProp,
34
+ defaultValue,
35
+ onChange: onValueChange
36
+ });
37
+ const [text, setText] = useControlled({
38
+ value: inputValue,
39
+ defaultValue: defaultInputValue ?? options.find((o) => o.value === (valueProp ?? defaultValue))?.label ?? "",
40
+ onChange: onInputValueChange
41
+ });
42
+ const [open, setOpen] = useState(false);
43
+ const [active, setActive] = useState(-1);
44
+ const box = useRef(null);
45
+ const id = useId();
46
+ const inputId = `${id}-input`;
47
+ const listId = `${id}-list`;
48
+ const hintId = hint != null ? `${id}-hint` : void 0;
49
+ const errorId = error != null && error !== false ? `${id}-error` : void 0;
50
+ const Root = as ?? "div";
51
+ const styled = useCss("Suggest", "root", css);
52
+ const { part, style } = useParts("Suggest", {
53
+ parts,
54
+ partProps,
55
+ classNames
56
+ });
57
+ const root = useAnimationRoot(rest);
58
+ const chosen = options.find((o) => o.value === value);
59
+ const query = chosen && text === chosen.label ? "" : text.trim();
60
+ const found = useMemo(() => {
61
+ return (filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query))).slice(0, Math.max(0, limit));
62
+ }, [
63
+ options,
64
+ filter,
65
+ query,
66
+ limit
67
+ ]);
68
+ const [listed, setListed] = useState(found);
69
+ if (open && listed !== found) setListed(found);
70
+ const close = () => {
71
+ setOpen(false);
72
+ setActive(-1);
73
+ };
74
+ const dismiss = useDismiss({
75
+ ref: box,
76
+ open,
77
+ onDismiss: close
78
+ });
79
+ useEffect(() => {
80
+ if (open && active >= 0) document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: "nearest" });
81
+ }, [
82
+ open,
83
+ active,
84
+ listId
85
+ ]);
86
+ /** Next enabled suggestion from `from` in direction `step`, wrapping; -1 when none. */
87
+ const next = (from, step) => {
88
+ const n = found.length;
89
+ for (let k = 1; k <= n; k++) {
90
+ const i = ((from + step * k) % n + n) % n;
91
+ if (!found[i]?.disabled) return i;
92
+ }
93
+ return -1;
94
+ };
95
+ const choose = (o) => {
96
+ if (o.disabled) return;
97
+ if (o.value !== value) setValue(o.value);
98
+ if (o.label !== text) setText(o.label);
99
+ close();
100
+ };
101
+ const keys = (e) => {
102
+ onKeyDown?.(e);
103
+ if (e.defaultPrevented) return;
104
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
105
+ e.preventDefault();
106
+ const step = e.key === "ArrowDown" ? 1 : -1;
107
+ if (!open) {
108
+ setOpen(true);
109
+ const at = found.findIndex((o) => o.value === value);
110
+ setActive(e.altKey ? -1 : at >= 0 ? at : next(step === 1 ? -1 : 0, step));
111
+ } else setActive(next(active < 0 && step === -1 ? 0 : active, step));
112
+ } else if (e.key === "Enter" && open && active >= 0) {
113
+ e.preventDefault();
114
+ const o = found[active];
115
+ if (o) choose(o);
116
+ } else if (e.key === "Escape") {
117
+ if (open) {
118
+ e.preventDefault();
119
+ e.stopPropagation();
120
+ close();
121
+ } else if (text) {
122
+ e.preventDefault();
123
+ setText("");
124
+ if (value != null) setValue(null);
125
+ }
126
+ }
127
+ };
128
+ const showing = open && !disabled;
129
+ const status = showing && query ? found.length ? labels.results(found.length) : labels.empty : "";
130
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
131
+ styled.style,
132
+ style,
133
+ /* @__PURE__ */ jsxs(Root, {
134
+ className: cx("slurp-suggest", styled.className, className),
135
+ "data-open": showing ? "" : void 0,
136
+ "data-invalid": errorId ? "" : void 0,
137
+ "data-disabled": disabled ? "" : void 0,
138
+ ...root,
139
+ children: [
140
+ part("label", "label", {
141
+ id: `${id}-label`,
142
+ htmlFor: inputId,
143
+ className: "slurp-suggest-label",
144
+ children: label
145
+ }),
146
+ /* @__PURE__ */ jsx("div", {
147
+ ref: box,
148
+ className: "slurp-suggest-box",
149
+ onBlur: dismiss.containerProps.onBlur,
150
+ children: /* @__PURE__ */ jsxs("div", {
151
+ className: "slurp-suggest-surface",
152
+ children: [part("control", "input", {
153
+ ...inputRest,
154
+ id: inputId,
155
+ type: "text",
156
+ role: "combobox",
157
+ className: "slurp-suggest-control",
158
+ disabled,
159
+ autoComplete: inputRest.autoComplete ?? "off",
160
+ "aria-expanded": showing,
161
+ "aria-controls": listId,
162
+ "aria-autocomplete": "list",
163
+ "aria-activedescendant": showing && active >= 0 ? `${listId}-${active}` : void 0,
164
+ "aria-invalid": errorId ? true : void 0,
165
+ "aria-describedby": cx(errorId, hintId) || void 0,
166
+ value: text,
167
+ onChange: (e) => {
168
+ const v = e.target.value;
169
+ setText(v);
170
+ if (value != null && v !== chosen?.label) setValue(null);
171
+ setOpen(true);
172
+ setActive(-1);
173
+ },
174
+ onKeyDown: keys,
175
+ onFocus: (e) => {
176
+ onFocus?.(e);
177
+ if (openOnFocus) setOpen(true);
178
+ },
179
+ onBlur,
180
+ onClick: () => {
181
+ if (!open) setOpen(true);
182
+ }
183
+ }), /* @__PURE__ */ jsx("div", {
184
+ className: "slurp-suggest-clip",
185
+ children: listed.length > 0 ? part("list", "ul", {
186
+ id: listId,
187
+ role: "listbox",
188
+ "aria-labelledby": `${id}-label`,
189
+ className: "slurp-suggest-list",
190
+ children: listed.map((o, i) => /* @__PURE__ */ jsx(Fragment, { children: part("option", "li", {
191
+ id: `${listId}-${i}`,
192
+ role: "option",
193
+ className: "slurp-suggest-option",
194
+ "aria-selected": showing && i === active,
195
+ "aria-disabled": o.disabled || void 0,
196
+ "data-chosen": o.value === value ? "" : void 0,
197
+ onMouseDown: (e) => e.preventDefault(),
198
+ onPointerMove: () => {
199
+ if (!o.disabled && i !== active) setActive(i);
200
+ },
201
+ onClick: () => choose(o),
202
+ children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
203
+ className: "slurp-suggest-option-text",
204
+ children: [/* @__PURE__ */ jsx("span", {
205
+ className: "slurp-suggest-option-label",
206
+ children: /* @__PURE__ */ jsx(Mark, {
207
+ text: o.label,
208
+ query
209
+ })
210
+ }), o.description && /* @__PURE__ */ jsx("span", {
211
+ className: "slurp-suggest-option-description",
212
+ children: /* @__PURE__ */ jsx(Mark, {
213
+ text: o.description,
214
+ query
215
+ })
216
+ })]
217
+ }), o.value === value && /* @__PURE__ */ jsx("span", {
218
+ className: "slurp-suggest-option-check",
219
+ "aria-hidden": "true",
220
+ children: /* @__PURE__ */ jsx(CheckIcon, { size: 18 })
221
+ })] })
222
+ }) }, o.value))
223
+ }) : /* @__PURE__ */ jsx("p", {
224
+ id: listId,
225
+ className: "slurp-suggest-empty",
226
+ children: labels.empty
227
+ })
228
+ })]
229
+ })
230
+ }),
231
+ hintId && part("hint", "p", {
232
+ id: hintId,
233
+ className: "slurp-suggest-hint",
234
+ children: hint
235
+ }),
236
+ errorId && part("error", "p", {
237
+ id: errorId,
238
+ className: "slurp-suggest-error",
239
+ children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ErrorIcon, { size: 16 }), /* @__PURE__ */ jsx("span", { children: error })] })
240
+ }),
241
+ /* @__PURE__ */ jsx("span", {
242
+ className: "slurp-visually-hidden",
243
+ role: "status",
244
+ children: status
245
+ }),
246
+ name && /* @__PURE__ */ jsx("input", {
247
+ type: "hidden",
248
+ name,
249
+ value: value ?? ""
250
+ })
251
+ ]
252
+ })
253
+ ] });
254
+ }
255
+ export { SUGGEST_LABELS, Suggest };
256
+
257
+ //# sourceMappingURL=Suggest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Suggest.js","names":[],"sources":["../../src/Suggest/Suggest.tsx"],"sourcesContent":["import { CheckIcon, ErrorIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Fragment,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type ElementType,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { splitInputProps, type InputAttributes } from '../Field/Field';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { matchesAll } from '../lib/layout';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { Mark } from '../Mark/Mark';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\n\nexport interface SuggestOption<V extends string = string> {\n value: V;\n /** Text of the option, written into the field when chosen. */\n label: string;\n /** A second line (a brand, a category); also searched. */\n description?: string;\n disabled?: boolean;\n}\n\nexport interface SuggestLabels {\n /** Number of suggestions, announced politely while typing. */\n results: (count: number) => string;\n /** Shown in the list, and announced, when nothing matches. */\n empty: string;\n}\n\nexport const SUGGEST_LABELS: SuggestLabels = {\n results: (n) => (n === 1 ? '1 suggerimento' : `${n} suggerimenti`),\n empty: 'Nessun suggerimento',\n};\n\nexport interface SuggestOwnProps<V extends string = string>\n extends\n Omit<InputAttributes, 'type'>,\n PartsProps<'label' | 'control' | 'list' | 'option' | 'hint' | 'error'> {\n /** Visible label. */\n label: ReactNode;\n hint?: ReactNode;\n /** Error message: marks the field invalid. */\n error?: ReactNode;\n options: SuggestOption<V>[];\n /** The chosen option; null while the text matches none. */\n value?: V | null;\n defaultValue?: V | null;\n onValueChange?: (value: V | null) => void;\n /** The text in the field. */\n inputValue?: string;\n /** Default the label of the chosen option, else empty. */\n defaultInputValue?: string;\n onInputValueChange?: (text: string) => void;\n /**\n * Which options match the text. Default: every word of the text, in any order, ignoring case and accents, in the\n * label or the description. `false` when the app already filters `options` (results from a server).\n */\n filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;\n /** Most suggestions listed. Default 8. */\n limit?: number;\n /** Lists the suggestions as soon as the field takes focus. Default false (they show while typing). */\n openOnFocus?: boolean;\n labels?: Partial<SuggestLabels>;\n}\n\nexport type SuggestProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, SuggestOwnProps<V>>;\n\nconst matches = (o: SuggestOption, text: string) =>\n matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);\n\n/**\n * Text field with suggestions (combobox): the field **becomes** the list, growing downward on one surface. Focus\n * stays in the field: arrows move through the suggestions, Enter chooses, Escape closes (then clears); matches are\n * marked in the options.\n */\nexport function Suggest<V extends string = string, E extends ElementType = 'div'>(\n props: SuggestProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n hint,\n error,\n options,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n inputValue,\n defaultInputValue,\n onInputValueChange,\n filter,\n limit = 8,\n openOnFocus = false,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('Suggest', props as unknown as SuggestProps);\n const labels = { ...SUGGEST_LABELS, ...labelsProp };\n const { input, root: rest } = splitInputProps(others);\n const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input as InputAttributes;\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const [text, setText] = useControlled({\n value: inputValue,\n defaultValue:\n defaultInputValue ??\n options.find((o) => o.value === (valueProp ?? defaultValue))?.label ??\n '',\n onChange: onInputValueChange,\n });\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const box = useRef<HTMLDivElement>(null);\n const id = useId();\n const inputId = `${id}-input`;\n const listId = `${id}-list`;\n const hintId = hint != null ? `${id}-hint` : undefined;\n const errorId = error != null && error !== false ? `${id}-error` : undefined;\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Suggest', 'root', css);\n const { part, style } = useParts('Suggest', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const chosen = options.find((o) => o.value === value);\n // With the chosen option's own text in the field, every option is offered again.\n const query = chosen && text === chosen.label ? '' : text.trim();\n const found = useMemo(() => {\n const all =\n filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query));\n return all.slice(0, Math.max(0, limit));\n }, [options, filter, query, limit]);\n // While the list closes it keeps the suggestions it showed, so they shrink away instead of changing.\n const [listed, setListed] = useState(found);\n if (open && listed !== found) setListed(found);\n\n const close = () => {\n setOpen(false);\n setActive(-1);\n };\n const dismiss = useDismiss({ ref: box, open, onDismiss: close });\n\n useEffect(() => {\n if (open && active >= 0)\n document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: 'nearest' });\n }, [open, active, listId]);\n\n /** Next enabled suggestion from `from` in direction `step`, wrapping; -1 when none. */\n const next = (from: number, step: 1 | -1) => {\n const n = found.length;\n for (let k = 1; k <= n; k++) {\n const i = (((from + step * k) % n) + n) % n;\n if (!found[i]?.disabled) return i;\n }\n return -1;\n };\n\n const choose = (o: SuggestOption) => {\n if (o.disabled) return;\n if (o.value !== value) setValue(o.value);\n if (o.label !== text) setText(o.label);\n close();\n };\n\n const keys = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n const step = e.key === 'ArrowDown' ? 1 : -1;\n if (!open) {\n setOpen(true);\n const at = found.findIndex((o) => o.value === value);\n setActive(e.altKey ? -1 : at >= 0 ? at : next(step === 1 ? -1 : 0, step));\n } else setActive(next(active < 0 && step === -1 ? 0 : active, step));\n } else if (e.key === 'Enter' && open && active >= 0) {\n e.preventDefault();\n const o = found[active];\n if (o) choose(o);\n } else if (e.key === 'Escape') {\n if (open) {\n e.preventDefault();\n e.stopPropagation();\n close();\n } else if (text) {\n e.preventDefault();\n setText('');\n if (value != null) setValue(null);\n }\n }\n };\n\n const showing = open && !disabled;\n const status =\n showing && query ? (found.length ? labels.results(found.length) : labels.empty) : '';\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-suggest', styled.className, className)}\n data-open={showing ? '' : undefined}\n data-invalid={errorId ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('label', 'label', {\n id: `${id}-label`,\n htmlFor: inputId,\n className: 'slurp-suggest-label',\n children: label,\n })}\n <div ref={box} className=\"slurp-suggest-box\" onBlur={dismiss.containerProps.onBlur}>\n <div className=\"slurp-suggest-surface\">\n {part('control', 'input', {\n ...inputRest,\n id: inputId,\n type: 'text',\n role: 'combobox',\n className: 'slurp-suggest-control',\n disabled,\n autoComplete: inputRest.autoComplete ?? 'off',\n 'aria-expanded': showing,\n 'aria-controls': listId,\n 'aria-autocomplete': 'list',\n 'aria-activedescendant': showing && active >= 0 ? `${listId}-${active}` : undefined,\n 'aria-invalid': errorId ? true : undefined,\n 'aria-describedby': cx(errorId, hintId) || undefined,\n value: text,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n const v = e.target.value;\n setText(v);\n if (value != null && v !== chosen?.label) setValue(null);\n setOpen(true);\n setActive(-1);\n },\n onKeyDown: keys,\n onFocus: (e: FocusEvent<HTMLInputElement>) => {\n onFocus?.(e);\n if (openOnFocus) setOpen(true);\n },\n onBlur,\n onClick: () => {\n if (!open) setOpen(true);\n },\n })}\n <div className=\"slurp-suggest-clip\">\n {listed.length > 0 ? (\n part('list', 'ul', {\n id: listId,\n role: 'listbox',\n 'aria-labelledby': `${id}-label`,\n className: 'slurp-suggest-list',\n children: listed.map((o, i) => (\n <Fragment key={o.value}>\n {part('option', 'li', {\n id: `${listId}-${i}`,\n role: 'option',\n className: 'slurp-suggest-option',\n 'aria-selected': showing && i === active,\n 'aria-disabled': o.disabled || undefined,\n 'data-chosen': o.value === value ? '' : undefined,\n // Keep focus in the field.\n onMouseDown: (e: MouseEvent) => e.preventDefault(),\n onPointerMove: () => {\n if (!o.disabled && i !== active) setActive(i);\n },\n onClick: () => choose(o),\n children: (\n <>\n <span className=\"slurp-suggest-option-text\">\n <span className=\"slurp-suggest-option-label\">\n <Mark text={o.label} query={query} />\n </span>\n {o.description && (\n <span className=\"slurp-suggest-option-description\">\n <Mark text={o.description} query={query} />\n </span>\n )}\n </span>\n {o.value === value && (\n <span className=\"slurp-suggest-option-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </>\n ),\n })}\n </Fragment>\n )),\n })\n ) : (\n <p id={listId} className=\"slurp-suggest-empty\">\n {labels.empty}\n </p>\n )}\n </div>\n </div>\n </div>\n {hintId &&\n part('hint', 'p', { id: hintId, className: 'slurp-suggest-hint', children: hint })}\n {errorId &&\n part('error', 'p', {\n id: errorId,\n className: 'slurp-suggest-error',\n children: (\n <>\n <ErrorIcon size={16} />\n <span>{error}</span>\n </>\n ),\n })}\n <span className=\"slurp-visually-hidden\" role=\"status\">\n {status}\n </span>\n {name && <input type=\"hidden\" name={name} value={value ?? ''} />}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAa,iBAAgC;CAC3C,UAAU,MAAO,MAAM,IAAI,mBAAmB,GAAG,EAAE;CACnD,OAAO;AACT;AAsCA,MAAM,WAAW,GAAkB,SACjC,WAAW,EAAE,cAAc,GAAG,EAAE,MAAM,GAAG,EAAE,gBAAgB,EAAE,OAAO,IAAI;;;;;;AAO1E,SAAgB,QACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,MACA,OACA,SACA,OAAO,WACP,eAAe,MACf,eACA,YACA,mBACA,oBACA,QACA,QAAQ,GACR,cAAc,OACd,QAAQ,YACR,OACA,WACA,YACA,GAAG,WACD,cAAc,WAAW,KAAgC;CAC7D,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG;CAAW;CAClD,MAAM,EAAE,OAAO,MAAM,SAAS,gBAAgB,MAAM;CACpD,MAAM,EAAE,MAAM,UAAU,WAAW,SAAS,QAAQ,GAAG,cAAc;CACrE,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;E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KAAQ,WAAW;KAAsB,UAAU;IAAK,CAAC;IAClF,WACC,KAAK,SAAS,KAAK;KACjB,IAAI;KACJ,WAAW;KACX,UACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,GACtB,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA,CACnB,EAAA,CAAA;IAEN,CAAC;IACH,oBAAC,QAAD;KAAM,WAAU;KAAwB,MAAK;KAC1C,UAAA;IACG,CAAA;IACL,QAAQ,oBAAC,SAAD;KAAO,MAAK;KAAe;KAAM,OAAO,SAAS;IAAK,CAAA;GAC3D;;CACN,EAAA,CAAA;AAEN"}
@@ -0,0 +1,3 @@
1
+
2
+ import { SUGGEST_LABELS, Suggest, SuggestLabels, SuggestOption, SuggestProps } from "./Suggest.js";
3
+ export { SUGGEST_LABELS, Suggest, type SuggestLabels, type SuggestOption, type SuggestProps, Suggest as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { SUGGEST_LABELS, Suggest, Suggest as default } from "./Suggest.js";
@@ -0,0 +1,52 @@
1
+
2
+ import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { ElementType, Key, ReactNode } from "react";
4
+ type Row = object;
5
+ export interface TableColumn<R extends Row = Row> {
6
+ /** Identifies the column; also the field read when there is no `cell` or `sortValue`. */
7
+ key: string;
8
+ header: ReactNode;
9
+ /** Content of a cell. Default the field `key` of the row. */
10
+ cell?: (row: R, index: number) => ReactNode;
11
+ /** `end` for numbers and prices (tabular figures). Default `start`. */
12
+ align?: 'start' | 'center' | 'end';
13
+ sortable?: boolean;
14
+ /** Value compared when sorting. Default the field `key` of the row. */
15
+ sortValue?: (row: R) => string | number | null | undefined;
16
+ /** The cells of this column name their row (`th scope="row"`): usually the first column. */
17
+ rowHeader?: boolean;
18
+ /** CSS width of the column. */
19
+ width?: string | number;
20
+ }
21
+ export interface TableSort {
22
+ key: string;
23
+ direction: 'ascending' | 'descending';
24
+ }
25
+ export interface TableLabels {
26
+ /** Shown in place of the rows when there are none. */
27
+ empty: string;
28
+ }
29
+ export declare const TABLE_LABELS: TableLabels;
30
+ export interface TableOwnProps<R extends Row = Row> extends PartsProps<'table' | 'caption'> {
31
+ /** Title of the table: names it and its scroll region. Hide it with `hideCaption` when a heading already says it. */
32
+ caption: ReactNode;
33
+ hideCaption?: boolean;
34
+ columns: TableColumn<R>[];
35
+ rows: R[];
36
+ /** Stable key of a row. Default its index. */
37
+ rowKey?: (row: R, index: number) => Key;
38
+ sort?: TableSort | null;
39
+ defaultSort?: TableSort | null;
40
+ onSortChange?: (sort: TableSort) => void;
41
+ /** The rows are already sorted (by a server): the table only reports `onSortChange`. */
42
+ manualSort?: boolean;
43
+ labels?: Partial<TableLabels>;
44
+ }
45
+ export type TableProps<R extends Row = Row, E extends ElementType = 'div'> = PolymorphicProps<E, TableOwnProps<R>>;
46
+ /**
47
+ * A plain data table, without a frame: hairlines between rows, numbers aligned at the end. Sortable headers are
48
+ * buttons and the sorted column carries `aria-sort`. Wide tables scroll inside a named, focusable region.
49
+ */
50
+ export declare function Table<R extends Row = Row, E extends ElementType = 'div'>(props: TableProps<R, E>): import("react").JSX.Element;
51
+ export {};
52
+ //# sourceMappingURL=Table.d.ts.map