@slurp-ui/react 1.1.1 → 1.2.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/CHANGELOG.md +42 -0
- package/dist/Bloom/Bloom.js +3 -2
- package/dist/Bloom/Bloom.js.map +1 -1
- package/dist/Calendar/Calendar.d.ts +42 -0
- package/dist/Calendar/Calendar.js +178 -0
- package/dist/Calendar/Calendar.js.map +1 -0
- package/dist/Calendar/dates.d.ts +3 -0
- package/dist/Calendar/dates.js +46 -0
- package/dist/Calendar/dates.js.map +1 -0
- package/dist/Calendar/index.d.ts +3 -0
- package/dist/Calendar/index.js +2 -0
- package/dist/Carousel/Carousel.js +2 -0
- package/dist/Carousel/Carousel.js.map +1 -1
- package/dist/Choice/Choice.js +2 -0
- package/dist/Choice/Choice.js.map +1 -1
- package/dist/Code/Code.d.ts +38 -0
- package/dist/Code/Code.js +82 -0
- package/dist/Code/Code.js.map +1 -0
- package/dist/Code/index.d.ts +3 -0
- package/dist/Code/index.js +2 -0
- package/dist/Contents/Contents.d.ts +35 -0
- package/dist/Contents/Contents.js +63 -0
- package/dist/Contents/Contents.js.map +1 -0
- package/dist/Contents/index.d.ts +3 -0
- package/dist/Contents/index.js +2 -0
- package/dist/DateField/DateField.d.ts +29 -0
- package/dist/DateField/DateField.js +118 -0
- package/dist/DateField/DateField.js.map +1 -0
- package/dist/DateField/index.d.ts +3 -0
- package/dist/DateField/index.js +2 -0
- package/dist/Dialog/Dialog.js +73 -25
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dock/Dock.d.ts +5 -0
- package/dist/Dock/Dock.js +13 -2
- package/dist/Dock/Dock.js.map +1 -1
- package/dist/ErrorSummary/ErrorSummary.d.ts +26 -0
- package/dist/ErrorSummary/ErrorSummary.js +68 -0
- package/dist/ErrorSummary/ErrorSummary.js.map +1 -0
- package/dist/ErrorSummary/index.d.ts +3 -0
- package/dist/ErrorSummary/index.js +2 -0
- package/dist/FileDrop/FileDrop.d.ts +34 -0
- package/dist/FileDrop/FileDrop.js +145 -0
- package/dist/FileDrop/FileDrop.js.map +1 -0
- package/dist/FileDrop/index.d.ts +3 -0
- package/dist/FileDrop/index.js +2 -0
- package/dist/Filters/Filters.js +2 -0
- package/dist/Filters/Filters.js.map +1 -1
- package/dist/Footer/Footer.d.ts +37 -0
- package/dist/Footer/Footer.js +63 -0
- package/dist/Footer/Footer.js.map +1 -0
- package/dist/Footer/index.d.ts +3 -0
- package/dist/Footer/index.js +2 -0
- package/dist/Hairline/Hairline.d.ts +16 -0
- package/dist/Hairline/Hairline.js +23 -0
- package/dist/Hairline/Hairline.js.map +1 -0
- package/dist/Hairline/index.d.ts +3 -0
- package/dist/Hairline/index.js +2 -0
- package/dist/Hint/Hint.js +20 -1
- package/dist/Hint/Hint.js.map +1 -1
- package/dist/Kbd/Kbd.d.ts +7 -0
- package/dist/Kbd/Kbd.js +20 -0
- package/dist/Kbd/Kbd.js.map +1 -0
- package/dist/Kbd/index.d.ts +3 -0
- package/dist/Kbd/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +5 -1
- package/dist/ListRow/ListRow.js +5 -1
- package/dist/ListRow/ListRow.js.map +1 -1
- package/dist/Media/Media.d.ts +28 -0
- package/dist/Media/Media.js +65 -0
- package/dist/Media/Media.js.map +1 -0
- package/dist/Media/index.d.ts +3 -0
- package/dist/Media/index.js +2 -0
- package/dist/Notice/Notice.js +2 -0
- package/dist/Notice/Notice.js.map +1 -1
- package/dist/NumberField/NumberField.d.ts +32 -0
- package/dist/NumberField/NumberField.js +126 -0
- package/dist/NumberField/NumberField.js.map +1 -0
- package/dist/NumberField/index.d.ts +3 -0
- package/dist/NumberField/index.js +2 -0
- package/dist/PageNav/PageNav.d.ts +25 -0
- package/dist/PageNav/PageNav.js +57 -0
- package/dist/PageNav/PageNav.js.map +1 -0
- package/dist/PageNav/index.d.ts +3 -0
- package/dist/PageNav/index.js +2 -0
- package/dist/Pages/Pages.js +2 -0
- package/dist/Pages/Pages.js.map +1 -1
- package/dist/PinField/PinField.d.ts +26 -0
- package/dist/PinField/PinField.js +73 -0
- package/dist/PinField/PinField.js.map +1 -0
- package/dist/PinField/index.d.ts +3 -0
- package/dist/PinField/index.js +2 -0
- package/dist/Prose/Prose.d.ts +15 -0
- package/dist/Prose/Prose.js +25 -0
- package/dist/Prose/Prose.js.map +1 -0
- package/dist/Prose/index.d.ts +3 -0
- package/dist/Prose/index.js +2 -0
- package/dist/Quote/Quote.d.ts +19 -0
- package/dist/Quote/Quote.js +52 -0
- package/dist/Quote/Quote.js.map +1 -0
- package/dist/Quote/index.d.ts +3 -0
- package/dist/Quote/index.js +2 -0
- package/dist/Rail/Rail.d.ts +37 -0
- package/dist/Rail/Rail.js +61 -0
- package/dist/Rail/Rail.js.map +1 -0
- package/dist/Rail/index.d.ts +3 -0
- package/dist/Rail/index.js +2 -0
- package/dist/Rating/Rating.js +2 -0
- package/dist/Rating/Rating.js.map +1 -1
- package/dist/Search/Search.js +2 -0
- package/dist/Search/Search.js.map +1 -1
- package/dist/SecretField/SecretField.d.ts +17 -0
- package/dist/SecretField/SecretField.js +59 -0
- package/dist/SecretField/SecretField.js.map +1 -0
- package/dist/SecretField/index.d.ts +3 -0
- package/dist/SecretField/index.js +2 -0
- package/dist/Settings/Settings.js +2 -0
- package/dist/Settings/Settings.js.map +1 -1
- package/dist/SkipLink/SkipLink.d.ts +22 -0
- package/dist/SkipLink/SkipLink.js +32 -0
- package/dist/SkipLink/SkipLink.js.map +1 -0
- package/dist/SkipLink/index.d.ts +3 -0
- package/dist/SkipLink/index.js +2 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +7 -1
- package/dist/SlurpProvider/SlurpProvider.js +14 -6
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -1
- package/dist/Steps/Steps.js +2 -0
- package/dist/Steps/Steps.js.map +1 -1
- package/dist/Suggest/Suggest.js +2 -0
- package/dist/Suggest/Suggest.js.map +1 -1
- package/dist/Table/Table.js +2 -0
- package/dist/Table/Table.js.map +1 -1
- package/dist/Tag/Tag.d.ts +14 -0
- package/dist/Tag/Tag.js +26 -0
- package/dist/Tag/Tag.js.map +1 -0
- package/dist/Tag/index.d.ts +3 -0
- package/dist/Tag/index.js +2 -0
- package/dist/Toast/Toast.js +31 -7
- package/dist/Toast/Toast.js.map +1 -1
- package/dist/index.d.ts +45 -4
- package/dist/index.js +23 -1
- package/dist/internal/labels.js +12 -0
- package/dist/internal/labels.js.map +1 -0
- package/dist/lib/labels.d.ts +175 -0
- package/dist/lib/labels.js +116 -0
- package/dist/lib/labels.js.map +1 -0
- package/dist/lib/theme.d.ts +98 -3
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +1367 -111
- package/dist/tokens.css +9 -0
- package/dist/utils/focus.d.ts +1 -1
- package/dist/utils/focus.js +2 -2
- package/dist/utils/focus.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/useClipboard.d.ts +14 -0
- package/dist/utils/useClipboard.js +30 -0
- package/dist/utils/useClipboard.js.map +1 -0
- package/dist/utils/useScrollSpy.d.ts +14 -0
- package/dist/utils/useScrollSpy.js +27 -0
- package/dist/utils/useScrollSpy.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,61 @@
|
|
|
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 { useId } from "react";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/Rail/Rail.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Vertical navigation in groups, beside the content on wide screens (the Dock stays the navigation on phones). The
|
|
10
|
+
* current page is highlighted like a ListRow and marked `aria-current="page"`. Put it in a floating Surface.
|
|
11
|
+
*/
|
|
12
|
+
function RailRoot(props) {
|
|
13
|
+
const { as, css, className, label, children, ...rest } = useThemeProps("Rail", props);
|
|
14
|
+
const Root = as ?? "nav";
|
|
15
|
+
const styled = useCss("Rail", "root", css);
|
|
16
|
+
const root = useAnimationRoot(rest);
|
|
17
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
18
|
+
className: cx("slurp-rail", styled.className, className),
|
|
19
|
+
"aria-label": label,
|
|
20
|
+
...root,
|
|
21
|
+
children
|
|
22
|
+
})] });
|
|
23
|
+
}
|
|
24
|
+
/** A group of links under an optional eyebrow title. */
|
|
25
|
+
function RailGroup({ title, children, className }) {
|
|
26
|
+
const id = useId();
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
28
|
+
className: cx("slurp-rail-group", className),
|
|
29
|
+
children: [title != null && /* @__PURE__ */ jsx("p", {
|
|
30
|
+
className: "slurp-rail-group-title",
|
|
31
|
+
id,
|
|
32
|
+
children: title
|
|
33
|
+
}), /* @__PURE__ */ jsx("ul", {
|
|
34
|
+
className: "slurp-rail-list",
|
|
35
|
+
"aria-labelledby": title != null ? id : void 0,
|
|
36
|
+
children
|
|
37
|
+
})]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** One link of the rail; `as` renders your router's link. */
|
|
41
|
+
function RailLink(props) {
|
|
42
|
+
const { as, css: _css, className, current, children, ...rest } = props;
|
|
43
|
+
const Root = as ?? "a";
|
|
44
|
+
const root = useAnimationRoot(rest);
|
|
45
|
+
return /* @__PURE__ */ jsx("li", {
|
|
46
|
+
className: "slurp-rail-item",
|
|
47
|
+
children: /* @__PURE__ */ jsx(Root, {
|
|
48
|
+
className: cx("slurp-rail-link", className),
|
|
49
|
+
"aria-current": current ? "page" : void 0,
|
|
50
|
+
...root,
|
|
51
|
+
children
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const Rail = Object.assign(RailRoot, {
|
|
56
|
+
Group: RailGroup,
|
|
57
|
+
Link: RailLink
|
|
58
|
+
});
|
|
59
|
+
export { Rail, RailGroup, RailLink };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=Rail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rail.js","names":[],"sources":["../../src/Rail/Rail.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport { useId, type ElementType, type ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface RailOwnProps {\n /** Name of the navigation (\"Documentazione\", \"Impostazioni\"). */\n label: string;\n children?: ReactNode;\n}\n\nexport type RailProps<E extends ElementType = 'nav'> = PolymorphicProps<E, RailOwnProps>;\n\n/**\n * Vertical navigation in groups, beside the content on wide screens (the Dock stays the navigation on phones). The\n * current page is highlighted like a ListRow and marked `aria-current=\"page\"`. Put it in a floating Surface.\n */\nfunction RailRoot<E extends ElementType = 'nav'>(props: RailProps<E>) {\n const { as, css, className, label, children, ...rest } = useThemeProps(\n 'Rail',\n props as RailProps,\n );\n const Root = (as ?? 'nav') as ElementType;\n const styled = useCss('Rail', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-rail', styled.className, className)} aria-label={label} {...root}>\n {children}\n </Root>\n </>\n );\n}\n\nexport interface RailGroupProps {\n /** Shown as an eyebrow above the links, and names the list. */\n title?: ReactNode;\n children?: ReactNode;\n className?: string;\n}\n\n/** A group of links under an optional eyebrow title. */\nfunction RailGroup({ title, children, className }: RailGroupProps) {\n const id = useId();\n return (\n <div className={cx('slurp-rail-group', className)}>\n {title != null && (\n <p className=\"slurp-rail-group-title\" id={id}>\n {title}\n </p>\n )}\n <ul className=\"slurp-rail-list\" aria-labelledby={title != null ? id : undefined}>\n {children}\n </ul>\n </div>\n );\n}\n\nexport interface RailLinkOwnProps {\n /** The page you are on (a router's NavLink sets `aria-current` itself). */\n current?: boolean;\n children?: ReactNode;\n}\n\nexport type RailLinkProps<E extends ElementType = 'a'> = PolymorphicProps<E, RailLinkOwnProps>;\n\n/** One link of the rail; `as` renders your router's link. */\nfunction RailLink<E extends ElementType = 'a'>(props: RailLinkProps<E>) {\n const { as, css: _css, className, current, children, ...rest } = props as RailLinkProps;\n const Root = (as ?? 'a') as ElementType;\n const root = useAnimationRoot(rest);\n return (\n <li className=\"slurp-rail-item\">\n <Root\n className={cx('slurp-rail-link', className)}\n aria-current={current ? 'page' : undefined}\n {...root}\n >\n {children}\n </Root>\n </li>\n );\n}\n\ntype RailComponent = typeof RailRoot & { Group: typeof RailGroup; Link: typeof RailLink };\n\nexport const Rail = Object.assign(RailRoot, { Group: RailGroup, Link: RailLink }) as RailComponent;\nexport { RailGroup, RailLink };\n"],"mappings":";;;;;;;;;;;AAmBA,SAAS,SAAwC,OAAqB;CACpE,MAAM,EAAE,IAAI,KAAK,WAAW,OAAO,UAAU,GAAG,SAAS,cACvD,QACA,KACF;CACA,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,QAAQ,QAAQ,GAAG;CACzC,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EAAM,WAAW,GAAG,cAAc,OAAO,WAAW,SAAS;EAAG,cAAY;EAAO,GAAI;EACpF;CACG,CAAA,CACN,EAAA,CAAA;AAEN;;AAUA,SAAS,UAAU,EAAE,OAAO,UAAU,aAA6B;CACjE,MAAM,KAAK,MAAM;CACjB,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,oBAAoB,SAAS;EAAhD,UAAA,CACG,SAAS,QACR,oBAAC,KAAD;GAAG,WAAU;GAA6B;GACvC,UAAA;EACA,CAAA,GAEL,oBAAC,MAAD;GAAI,WAAU;GAAkB,mBAAiB,SAAS,OAAO,KAAK,KAAA;GACnE;EACC,CAAA,CACD;;AAET;;AAWA,SAAS,SAAsC,OAAyB;CACtE,MAAM,EAAE,IAAI,KAAK,MAAM,WAAW,SAAS,UAAU,GAAG,SAAS;CACjE,MAAM,OAAQ,MAAM;CACpB,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,oBAAC,MAAD;EAAI,WAAU;EACZ,UAAA,oBAAC,MAAD;GACE,WAAW,GAAG,mBAAmB,SAAS;GAC1C,gBAAc,UAAU,SAAS,KAAA;GACjC,GAAI;GAEH;EACG,CAAA;CACJ,CAAA;AAER;AAIA,MAAa,OAAO,OAAO,OAAO,UAAU;CAAE,OAAO;CAAW,MAAM;AAAS,CAAC"}
|
package/dist/Rating/Rating.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
2
3
|
import { cx } from "../utils/src/index.js";
|
|
3
4
|
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
5
|
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
@@ -26,6 +27,7 @@ function Rating(props) {
|
|
|
26
27
|
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
28
|
const labels = {
|
|
28
29
|
...RATING_LABELS,
|
|
30
|
+
...useLabels("Rating"),
|
|
29
31
|
...labelsProp
|
|
30
32
|
};
|
|
31
33
|
const max = Math.max(1, Math.round(maxProp));
|
|
@@ -1 +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":"
|
|
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 { useLabels } from '../internal/labels';\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, ...useLabels('Rating'), ...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":";;;;;;;;;;AAkBA,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,UAAU,QAAQ;EAAG,GAAG;CAAW;CACzE,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,GAAG;CAC3C,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,IAAI,IAAI,GAAG,MAAM,IAAI,CAAC;CACzD,MAAM,OAAO,KAAK;CAClB,MAAM,UAAU,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,SAAS,CAAC,CAAC;CAErD,IAAI,UAAU;EACZ,MAAM,OAAQ,MAAM;EACpB,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;GACE,WAAW,GAAG,gBAAgB,OAAO,WAAW,SAAS;GACzD,MAAK;GACL,cAAY,GAAG,MAAM,IAAI,OAAO,MAAM,MAAM,OAAO,GAAG,GAAG;GACzD,iBAAc;GACd,aAAW;GACX,OAAO;IAAE,wBAAwB,UAAU;IAAK,GAAG;GAAM;GACzD,GAAI;GAEJ,UAAA,qBAAC,QAAD;IAAM,WAAU;IAAqB,eAAY;IAAjD,UAAA,CACG,MAAM,KAAK,MACV,oBAAC,UAAD;KAAkB,MAAM;KAAM,WAAU;IAAqB,GAA9C,CAA8C,CAC9D,GACD,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA,MAAM,KAAK,MACV,oBAAC,UAAD;MAAkB,MAAM;MAAM,WAAU;MAAoB,MAAK;KAAgB,GAAlE,CAAkE,CAClF;IACG,CAAA,CACF;;EACF,CAAA,CACN,EAAA,CAAA;CAEN;CAEA,MAAM,OAAQ,MAAM;CACpB,MAAM,WAAW,SAAS;CAC1B,MAAM,SAAS,WAAW,WAAW;CACrC,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,WAAW,GAAG,gBAAgB,OAAO,WAAW,SAAS;EACzD,aAAW;EACX,iBAAe,WAAW,KAAK,KAAA;EAC/B,UAAU,WAAW,WAAW,KAAA;EAChC,MAAM,WAAW,KAAA,IAAY;EAC7B,mBAAiB,WAAW,KAAA,IAAY,GAAG,KAAK;EACzC;EACP,GAAI;EARN,UAAA,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.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
2
3
|
import { cx } from "../utils/src/index.js";
|
|
3
4
|
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
5
|
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
@@ -20,6 +21,7 @@ function Search(props) {
|
|
|
20
21
|
const { as, css, className, value: valueProp, defaultValue = "", onValueChange, onSearch, count, labels: labelsProp, parts, partProps, classNames, ...others } = useThemeProps("Search", props);
|
|
21
22
|
const labels = {
|
|
22
23
|
...SEARCH_LABELS,
|
|
24
|
+
...useLabels("Search"),
|
|
23
25
|
...labelsProp
|
|
24
26
|
};
|
|
25
27
|
const { input, root: rest } = splitInputProps(others);
|
|
@@ -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 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":"
|
|
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 { useLabels } from '../internal/labels';\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, ...useLabels('Search'), ...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":";;;;;;;;;;;;AA6BA,MAAa,gBAA8B;CACzC,OAAO;CACP,aAAa;CACb,OAAO;CACP,UAAU,MAAO,MAAM,IAAI,qBAAqB,MAAM,IAAI,gBAAgB,GAAG,EAAE;AACjF;;AAiBA,SAAgB,OAAsC,OAAuB;CAC3E,MAAM,EACJ,IACA,KACA,WACA,OAAO,WACP,eAAe,IACf,eACA,UACA,OACA,QAAQ,YACR,OACA,WACA,YACA,GAAG,WACD,cAAc,UAAU,KAAoB;CAChD,MAAM,SAAS;EAAE,GAAG;EAAe,GAAG,UAAU,QAAQ;EAAG,GAAG;CAAW;CACzE,MAAM,EAAE,OAAO,MAAM,SAAS,gBAAgB,MAAM;CACpD,MAAM,CAAC,OAAO,YAAY,cAAc;EACtC,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,UAAU,QAAQ,GAAG;CAC3C,MAAM,EAAE,MAAM,UAAU,SAAS,UAAU;EAAE;EAAO;EAAW;CAAW,CAAC;CAC3E,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,MAAM,KAAK,MAAM;CAC/B,MAAM,cAAc,MAAM;CAC1B,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,MAAK;GACL,WAAW,GAAG,gBAAgB,OAAO,WAAW,SAAS;GACzD,cAAY,QAAQ,KAAK,KAAA;GACzB,GAAI;GAJN,UAAA;IAMG,KAAK,QAAQ,QAAQ;KACpB,WAAW;KACX,eAAe;KACf,UAAU,oBAAC,YAAD,EAAY,MAAM,GAAK,CAAA;IACnC,CAAC;IACA,KAAK,WAAW,SAAS;KACxB,GAAG;KACH,MAAM;KACN,WAAW;KACX,cAAc,OAAO;KACrB,oBAAoB,SAAS,QAAQ,QAAQ,WAAW,KAAA;KACxD,aAAa,MAAM,eAAe,OAAO;KACzC,cAAc,MAAM,gBAAgB;KACpC,cAAc,MAAM,gBAAgB;KACpC;KACA,WAAW,MAAqC,SAAS,EAAE,OAAO,KAAK;KACvE,YAAY,MAAuC;MACjD,cAAc,CAAC;MACf,IAAI,EAAE,QAAQ,WAAW,CAAC,EAAE,kBAAkB,WAAW,KAAK;KAChE;IACF,CAAC;IACA,KAAK,UAAU,QAAQ;KACtB,IAAI;KACJ,WAAW;KACX,MAAM;KACN,UAAU,SAAS,QAAQ,QAAQ,OAAO,QAAQ,KAAK,IAAI;IAC7D,CAAC;IACA,SACC,KAAK,SAAS,QAAQ;KACpB,WAAW;KACX,OAAO,OAAO;KACd,MAAM;KACN,UAAU,MAA+B;MACvC,SAAS,EAAE;MACX,EAAE,cAAc,eAAe,cAAc,OAAO,CAAC,EAAE,MAAM;KAC/D;KACA,UAAU,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;IAClC,CAAC;GACC;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import { FieldProps } from "../Field/Field.js";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
export interface SecretFieldLabels {
|
|
5
|
+
/** Name of the toggle (a pressed button shows the secret). */
|
|
6
|
+
show: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const SECRETFIELD_LABELS: SecretFieldLabels;
|
|
9
|
+
export type SecretFieldProps<E extends ElementType = 'div'> = Omit<FieldProps<E>, 'type' | 'multiline' | 'rows'> & {
|
|
10
|
+
labels?: Partial<SecretFieldLabels>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A password field: a Field (label, hint, error) whose secret can be shown with a pressed toggle. Password managers
|
|
14
|
+
* keep working: it stays a real `type="password"` input until shown.
|
|
15
|
+
*/
|
|
16
|
+
export declare function SecretField<E extends ElementType = 'div'>(props: SecretFieldProps<E>): import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=SecretField.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useThemeProps } from "../internal/styled.js";
|
|
5
|
+
import { Bubble } from "../Bubble/Bubble.js";
|
|
6
|
+
import { Field } from "../Field/Field.js";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { EyeIcon, EyeOffIcon } from "@slurp-ui/icons";
|
|
10
|
+
// src/SecretField/SecretField.tsx
|
|
11
|
+
const SECRETFIELD_LABELS = { show: "Mostra la password" };
|
|
12
|
+
/** The input plus the toggle, in place of Field's control. */
|
|
13
|
+
function SecretControl({ shown, onToggle, toggleLabel, className, ...input }) {
|
|
14
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
15
|
+
className: "slurp-secret-field-control",
|
|
16
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
17
|
+
className,
|
|
18
|
+
...input
|
|
19
|
+
}), /* @__PURE__ */ jsx(Bubble, {
|
|
20
|
+
className: "slurp-secret-field-toggle",
|
|
21
|
+
appearance: "plain",
|
|
22
|
+
tone: "neutral",
|
|
23
|
+
size: "sm",
|
|
24
|
+
label: toggleLabel,
|
|
25
|
+
"aria-pressed": shown,
|
|
26
|
+
onClick: onToggle,
|
|
27
|
+
children: shown ? /* @__PURE__ */ jsx(EyeOffIcon, { size: 18 }) : /* @__PURE__ */ jsx(EyeIcon, { size: 18 })
|
|
28
|
+
})]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A password field: a Field (label, hint, error) whose secret can be shown with a pressed toggle. Password managers
|
|
33
|
+
* keep working: it stays a real `type="password"` input until shown.
|
|
34
|
+
*/
|
|
35
|
+
function SecretField(props) {
|
|
36
|
+
const { labels: labelsProp, className, autoComplete = "current-password", ...rest } = useThemeProps("SecretField", props);
|
|
37
|
+
const labels = {
|
|
38
|
+
...SECRETFIELD_LABELS,
|
|
39
|
+
...useLabels("SecretField"),
|
|
40
|
+
...labelsProp
|
|
41
|
+
};
|
|
42
|
+
const [shown, setShown] = useState(false);
|
|
43
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
44
|
+
...rest,
|
|
45
|
+
className: cx("slurp-secret-field", className),
|
|
46
|
+
type: shown ? "text" : "password",
|
|
47
|
+
autoComplete,
|
|
48
|
+
spellCheck: false,
|
|
49
|
+
parts: { control: SecretControl },
|
|
50
|
+
partProps: { control: {
|
|
51
|
+
shown,
|
|
52
|
+
onToggle: () => setShown((s) => !s),
|
|
53
|
+
toggleLabel: labels.show
|
|
54
|
+
} }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export { SECRETFIELD_LABELS, SecretField };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=SecretField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecretField.js","names":[],"sources":["../../src/SecretField/SecretField.tsx"],"sourcesContent":["import { EyeIcon, EyeOffIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useState, type ElementType } from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { Field, type FieldProps } from '../Field/Field';\nimport { useLabels } from '../internal/labels';\nimport { useThemeProps } from '../internal/styled';\n\nexport interface SecretFieldLabels {\n /** Name of the toggle (a pressed button shows the secret). */\n show: string;\n}\n\nexport const SECRETFIELD_LABELS: SecretFieldLabels = { show: 'Mostra la password' };\n\nexport type SecretFieldProps<E extends ElementType = 'div'> = Omit<\n FieldProps<E>,\n 'type' | 'multiline' | 'rows'\n> & {\n labels?: Partial<SecretFieldLabels>;\n};\n\ninterface ControlProps extends Record<string, unknown> {\n shown: boolean;\n onToggle: () => void;\n toggleLabel: string;\n className?: string;\n}\n\n/** The input plus the toggle, in place of Field's control. */\nfunction SecretControl({ shown, onToggle, toggleLabel, className, ...input }: ControlProps) {\n return (\n <span className=\"slurp-secret-field-control\">\n <input className={className} {...input} />\n <Bubble\n className=\"slurp-secret-field-toggle\"\n appearance=\"plain\"\n tone=\"neutral\"\n size=\"sm\"\n label={toggleLabel}\n aria-pressed={shown}\n onClick={onToggle}\n >\n {shown ? <EyeOffIcon size={18} /> : <EyeIcon size={18} />}\n </Bubble>\n </span>\n );\n}\n\n/**\n * A password field: a Field (label, hint, error) whose secret can be shown with a pressed toggle. Password managers\n * keep working: it stays a real `type=\"password\"` input until shown.\n */\nexport function SecretField<E extends ElementType = 'div'>(props: SecretFieldProps<E>) {\n const {\n labels: labelsProp,\n className,\n autoComplete = 'current-password',\n ...rest\n } = useThemeProps('SecretField', props as SecretFieldProps);\n const labels = { ...SECRETFIELD_LABELS, ...useLabels('SecretField'), ...labelsProp };\n const [shown, setShown] = useState(false);\n return (\n <Field\n {...(rest as FieldProps)}\n className={cx('slurp-secret-field', className)}\n type={shown ? 'text' : 'password'}\n autoComplete={autoComplete}\n spellCheck={false}\n parts={{ control: SecretControl }}\n partProps={{\n control: { shown, onToggle: () => setShown((s) => !s), toggleLabel: labels.show },\n }}\n />\n );\n}\n"],"mappings":";;;;;;;;;;AAcA,MAAa,qBAAwC,EAAE,MAAM,qBAAqB;;AAiBlF,SAAS,cAAc,EAAE,OAAO,UAAU,aAAa,WAAW,GAAG,SAAuB;CAC1F,OACE,qBAAC,QAAD;EAAM,WAAU;EAAhB,UAAA,CACE,oBAAC,SAAD;GAAkB;GAAW,GAAI;EAAQ,CAAA,GACzC,oBAAC,QAAD;GACE,WAAU;GACV,YAAW;GACX,MAAK;GACL,MAAK;GACL,OAAO;GACP,gBAAc;GACd,SAAS;GAER,UAAA,QAAQ,oBAAC,YAAD,EAAY,MAAM,GAAK,CAAA,IAAI,oBAAC,SAAD,EAAS,MAAM,GAAK,CAAA;EAClD,CAAA,CACJ;;AAEV;;;;;AAMA,SAAgB,YAA2C,OAA4B;CACrF,MAAM,EACJ,QAAQ,YACR,WACA,eAAe,oBACf,GAAG,SACD,cAAc,eAAe,KAAyB;CAC1D,MAAM,SAAS;EAAE,GAAG;EAAoB,GAAG,UAAU,aAAa;EAAG,GAAG;CAAW;CACnF,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,OACE,oBAAC,OAAD;EACE,GAAK;EACL,WAAW,GAAG,sBAAsB,SAAS;EAC7C,MAAM,QAAQ,SAAS;EACT;EACd,YAAY;EACZ,OAAO,EAAE,SAAS,cAAc;EAChC,WAAW,EACT,SAAS;GAAE;GAAO,gBAAgB,UAAU,MAAM,CAAC,CAAC;GAAG,aAAa,OAAO;EAAK,EAClF;CACD,CAAA;AAEL"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useColorScheme } from "../internal/context.js";
|
|
3
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
4
|
import { cx } from "../utils/src/index.js";
|
|
4
5
|
import { useThemeProps } from "../internal/styled.js";
|
|
5
6
|
import { Radio, RadioGroup } from "../Radio/Radio.js";
|
|
@@ -27,6 +28,7 @@ function Settings(props) {
|
|
|
27
28
|
const { languages, language, onLanguageChange, children, width = 300, inline = false, labels: labelsProp, className, css } = useThemeProps("Settings", props);
|
|
28
29
|
const labels = {
|
|
29
30
|
...SETTINGS_LABELS,
|
|
31
|
+
...useLabels("Settings"),
|
|
30
32
|
...labelsProp
|
|
31
33
|
};
|
|
32
34
|
const { mode, setMode } = useColorScheme();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Settings.js","names":[],"sources":["../../src/Settings/Settings.tsx"],"sourcesContent":["import { AutoIcon, CloseIcon, GearIcon, MoonIcon, SunIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, type ReactNode } from 'react';\n\nimport { Bloom } from '../Bloom/Bloom';\nimport { useColorScheme } from '../internal/context';\nimport { useThemeProps } from '../internal/styled';\nimport type { SlurpCss } from '../lib/css';\nimport type { ColorSchemeMode } from '../lib/theme';\nimport { Radio, RadioGroup } from '../Radio/Radio';\n\nexport interface SettingsLabels {\n /** Name of the button. */\n open: string;\n /** Name of the button while open. */\n close: string;\n /** Title of the panel. */\n title: string;\n theme: string;\n system: string;\n light: string;\n dark: string;\n language: string;\n}\n\nexport const SETTINGS_LABELS: SettingsLabels = {\n open: 'Impostazioni',\n close: 'Chiudi impostazioni',\n title: 'Impostazioni',\n theme: 'Tema',\n system: 'Automatico',\n light: 'Chiaro',\n dark: 'Scuro',\n language: 'Lingua',\n};\n\nexport interface SettingsLanguage {\n value: string;\n /** Written in itself (\"Italiano\", \"English\"). */\n label: string;\n /** BCP 47 tag of the label (\"it\", \"en\"). */\n lang: string;\n}\n\nexport interface SettingsProps {\n /**\n * Languages: the Lingua choice appears only when they are given (the library has no i18n of its own: apply the\n * choice yourself).\n */\n languages?: SettingsLanguage[];\n language?: string;\n onLanguageChange?: (value: string) => void;\n /** More preferences (RadioGroup with `appearance=\"rows\"`), or a short note. */\n children?: ReactNode;\n /** Panel width. Default 300. */\n width?: number;\n /** In the flow instead of fixed at the top right. */\n inline?: boolean;\n labels?: Partial<SettingsLabels>;\n className?: string;\n css?: SlurpCss;\n}\n\n/**\n * Site settings: a round button at the top right that grows into its own panel (Bloom) and shrinks back. Tema is\n * always there (Automatico / Chiaro / Scuro, through useColorScheme); Lingua only when `languages` is set.\n * Needs a SlurpProvider.\n */\nexport function Settings(props: SettingsProps) {\n const {\n languages,\n language,\n onLanguageChange,\n children,\n width = 300,\n inline = false,\n labels: labelsProp,\n className,\n css,\n } = useThemeProps('Settings', props);\n const labels = { ...SETTINGS_LABELS, ...labelsProp };\n const { mode, setMode } = useColorScheme();\n const titleId = useId();\n return (\n <div className={cx('slurp-settings', className)} data-inline={inline || undefined}>\n <Bloom\n trigger={<GearIcon size={22} />}\n openTrigger={<CloseIcon size={22} />}\n label={labels.open}\n closeLabel={labels.close}\n placement=\"bottom-end\"\n width={width}\n css={css}\n partProps={{ panel: { 'aria-labelledby': titleId } }}\n >\n <h2 id={titleId} className=\"slurp-settings-title\">\n {labels.title}\n </h2>\n <RadioGroup\n label={labels.theme}\n appearance=\"rows\"\n value={mode}\n onValueChange={(v) => setMode(v as ColorSchemeMode)}\n >\n <Radio value=\"system\" icon={<AutoIcon />}>\n {labels.system}\n </Radio>\n <Radio value=\"light\" icon={<SunIcon />}>\n {labels.light}\n </Radio>\n <Radio value=\"dark\" icon={<MoonIcon />}>\n {labels.dark}\n </Radio>\n </RadioGroup>\n {languages?.length ? (\n <RadioGroup\n label={labels.language}\n appearance=\"rows\"\n value={language ?? null}\n onValueChange={onLanguageChange}\n >\n {languages.map((l) => (\n <Radio key={l.value} value={l.value} lang={l.lang}>\n {l.label}\n </Radio>\n ))}\n </RadioGroup>\n ) : null}\n {children}\n </Bloom>\n </div>\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Settings.js","names":[],"sources":["../../src/Settings/Settings.tsx"],"sourcesContent":["import { AutoIcon, CloseIcon, GearIcon, MoonIcon, SunIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, type ReactNode } from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { Bloom } from '../Bloom/Bloom';\nimport { useColorScheme } from '../internal/context';\nimport { useThemeProps } from '../internal/styled';\nimport type { SlurpCss } from '../lib/css';\nimport type { ColorSchemeMode } from '../lib/theme';\nimport { Radio, RadioGroup } from '../Radio/Radio';\n\nexport interface SettingsLabels {\n /** Name of the button. */\n open: string;\n /** Name of the button while open. */\n close: string;\n /** Title of the panel. */\n title: string;\n theme: string;\n system: string;\n light: string;\n dark: string;\n language: string;\n}\n\nexport const SETTINGS_LABELS: SettingsLabels = {\n open: 'Impostazioni',\n close: 'Chiudi impostazioni',\n title: 'Impostazioni',\n theme: 'Tema',\n system: 'Automatico',\n light: 'Chiaro',\n dark: 'Scuro',\n language: 'Lingua',\n};\n\nexport interface SettingsLanguage {\n value: string;\n /** Written in itself (\"Italiano\", \"English\"). */\n label: string;\n /** BCP 47 tag of the label (\"it\", \"en\"). */\n lang: string;\n}\n\nexport interface SettingsProps {\n /**\n * Languages: the Lingua choice appears only when they are given (the library has no i18n of its own: apply the\n * choice yourself).\n */\n languages?: SettingsLanguage[];\n language?: string;\n onLanguageChange?: (value: string) => void;\n /** More preferences (RadioGroup with `appearance=\"rows\"`), or a short note. */\n children?: ReactNode;\n /** Panel width. Default 300. */\n width?: number;\n /** In the flow instead of fixed at the top right. */\n inline?: boolean;\n labels?: Partial<SettingsLabels>;\n className?: string;\n css?: SlurpCss;\n}\n\n/**\n * Site settings: a round button at the top right that grows into its own panel (Bloom) and shrinks back. Tema is\n * always there (Automatico / Chiaro / Scuro, through useColorScheme); Lingua only when `languages` is set.\n * Needs a SlurpProvider.\n */\nexport function Settings(props: SettingsProps) {\n const {\n languages,\n language,\n onLanguageChange,\n children,\n width = 300,\n inline = false,\n labels: labelsProp,\n className,\n css,\n } = useThemeProps('Settings', props);\n const labels = { ...SETTINGS_LABELS, ...useLabels('Settings'), ...labelsProp };\n const { mode, setMode } = useColorScheme();\n const titleId = useId();\n return (\n <div className={cx('slurp-settings', className)} data-inline={inline || undefined}>\n <Bloom\n trigger={<GearIcon size={22} />}\n openTrigger={<CloseIcon size={22} />}\n label={labels.open}\n closeLabel={labels.close}\n placement=\"bottom-end\"\n width={width}\n css={css}\n partProps={{ panel: { 'aria-labelledby': titleId } }}\n >\n <h2 id={titleId} className=\"slurp-settings-title\">\n {labels.title}\n </h2>\n <RadioGroup\n label={labels.theme}\n appearance=\"rows\"\n value={mode}\n onValueChange={(v) => setMode(v as ColorSchemeMode)}\n >\n <Radio value=\"system\" icon={<AutoIcon />}>\n {labels.system}\n </Radio>\n <Radio value=\"light\" icon={<SunIcon />}>\n {labels.light}\n </Radio>\n <Radio value=\"dark\" icon={<MoonIcon />}>\n {labels.dark}\n </Radio>\n </RadioGroup>\n {languages?.length ? (\n <RadioGroup\n label={labels.language}\n appearance=\"rows\"\n value={language ?? null}\n onValueChange={onLanguageChange}\n >\n {languages.map((l) => (\n <Radio key={l.value} value={l.value} lang={l.lang}>\n {l.label}\n </Radio>\n ))}\n </RadioGroup>\n ) : null}\n {children}\n </Bloom>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AA0BA,MAAa,kBAAkC;CAC7C,MAAM;CACN,OAAO;CACP,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACN,UAAU;AACZ;;;;;;AAkCA,SAAgB,SAAS,OAAsB;CAC7C,MAAM,EACJ,WACA,UACA,kBACA,UACA,QAAQ,KACR,SAAS,OACT,QAAQ,YACR,WACA,QACE,cAAc,YAAY,KAAK;CACnC,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,EAAE,MAAM,YAAY,eAAe;CACzC,MAAM,UAAU,MAAM;CACtB,OACE,oBAAC,OAAD;EAAK,WAAW,GAAG,kBAAkB,SAAS;EAAG,eAAa,UAAU,KAAA;EACtE,UAAA,qBAAC,OAAD;GACE,SAAS,oBAAC,UAAD,EAAU,MAAM,GAAK,CAAA;GAC9B,aAAa,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;GACnC,OAAO,OAAO;GACd,YAAY,OAAO;GACnB,WAAU;GACH;GACF;GACL,WAAW,EAAE,OAAO,EAAE,mBAAmB,QAAQ,EAAE;GARrD,UAAA;IAUE,oBAAC,MAAD;KAAI,IAAI;KAAS,WAAU;KACxB,UAAA,OAAO;IACN,CAAA;IACJ,qBAAC,YAAD;KACE,OAAO,OAAO;KACd,YAAW;KACX,OAAO;KACP,gBAAgB,MAAM,QAAQ,CAAoB;KAJpD,UAAA;MAME,oBAAC,OAAD;OAAO,OAAM;OAAS,MAAM,oBAAC,UAAD,CAAW,CAAA;OACpC,UAAA,OAAO;MACH,CAAA;MACP,oBAAC,OAAD;OAAO,OAAM;OAAQ,MAAM,oBAAC,SAAD,CAAU,CAAA;OAClC,UAAA,OAAO;MACH,CAAA;MACP,oBAAC,OAAD;OAAO,OAAM;OAAO,MAAM,oBAAC,UAAD,CAAW,CAAA;OAClC,UAAA,OAAO;MACH,CAAA;KACG;;IACX,WAAW,SACV,oBAAC,YAAD;KACE,OAAO,OAAO;KACd,YAAW;KACX,OAAO,YAAY;KACnB,eAAe;KAEd,UAAA,UAAU,KAAK,MACd,oBAAC,OAAD;MAAqB,OAAO,EAAE;MAAO,MAAM,EAAE;MAC1C,UAAA,EAAE;KACE,GAFK,EAAE,KAEP,CACR;IACS,CAAA,IACV;IACH;GACI;;CACJ,CAAA;AAET"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface SkipLinkLabels {
|
|
5
|
+
/** The link's text. */
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const SKIPLINK_LABELS: SkipLinkLabels;
|
|
9
|
+
export interface SkipLinkOwnProps {
|
|
10
|
+
/** Where it jumps: the id of the main content, with `#`. Default `#content`. */
|
|
11
|
+
href?: string;
|
|
12
|
+
/** Default `labels.label`. */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
labels?: Partial<SkipLinkLabels>;
|
|
15
|
+
}
|
|
16
|
+
export type SkipLinkProps<E extends ElementType = 'a'> = PolymorphicProps<E, SkipLinkOwnProps>;
|
|
17
|
+
/**
|
|
18
|
+
* "Skip to content": the first thing Tab reaches on a page. Out of sight until focused, then a pill at the top left.
|
|
19
|
+
* Give the target an id and `tabIndex={-1}` so focus lands on it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function SkipLink<E extends ElementType = 'a'>(props: SkipLinkProps<E>): import("react").JSX.Element;
|
|
22
|
+
//# sourceMappingURL=SkipLink.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/SkipLink/SkipLink.tsx
|
|
8
|
+
const SKIPLINK_LABELS = { label: "Vai al contenuto" };
|
|
9
|
+
/**
|
|
10
|
+
* "Skip to content": the first thing Tab reaches on a page. Out of sight until focused, then a pill at the top left.
|
|
11
|
+
* Give the target an id and `tabIndex={-1}` so focus lands on it.
|
|
12
|
+
*/
|
|
13
|
+
function SkipLink(props) {
|
|
14
|
+
const { as, css, className, href = "#content", children, labels: labelsProp, ...rest } = useThemeProps("SkipLink", props);
|
|
15
|
+
const labels = {
|
|
16
|
+
...SKIPLINK_LABELS,
|
|
17
|
+
...useLabels("SkipLink"),
|
|
18
|
+
...labelsProp
|
|
19
|
+
};
|
|
20
|
+
const Root = as ?? "a";
|
|
21
|
+
const styled = useCss("SkipLink", "root", css);
|
|
22
|
+
const root = useAnimationRoot(rest);
|
|
23
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
|
|
24
|
+
className: cx("slurp-skip-link", styled.className, className),
|
|
25
|
+
href,
|
|
26
|
+
...root,
|
|
27
|
+
children: children ?? labels.label
|
|
28
|
+
})] });
|
|
29
|
+
}
|
|
30
|
+
export { SKIPLINK_LABELS, SkipLink };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=SkipLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SkipLink.js","names":[],"sources":["../../src/SkipLink/SkipLink.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType, ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface SkipLinkLabels {\n /** The link's text. */\n label: string;\n}\n\nexport const SKIPLINK_LABELS: SkipLinkLabels = { label: 'Vai al contenuto' };\n\nexport interface SkipLinkOwnProps {\n /** Where it jumps: the id of the main content, with `#`. Default `#content`. */\n href?: string;\n /** Default `labels.label`. */\n children?: ReactNode;\n labels?: Partial<SkipLinkLabels>;\n}\n\nexport type SkipLinkProps<E extends ElementType = 'a'> = PolymorphicProps<E, SkipLinkOwnProps>;\n\n/**\n * \"Skip to content\": the first thing Tab reaches on a page. Out of sight until focused, then a pill at the top left.\n * Give the target an id and `tabIndex={-1}` so focus lands on it.\n */\nexport function SkipLink<E extends ElementType = 'a'>(props: SkipLinkProps<E>) {\n const {\n as,\n css,\n className,\n href = '#content',\n children,\n labels: labelsProp,\n ...rest\n } = useThemeProps('SkipLink', props as SkipLinkProps);\n const labels = { ...SKIPLINK_LABELS, ...useLabels('SkipLink'), ...labelsProp };\n const Root = (as ?? 'a') as ElementType;\n const styled = useCss('SkipLink', 'root', css);\n const root = useAnimationRoot(rest);\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-skip-link', styled.className, className)} href={href} {...root}>\n {children ?? labels.label}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;AAaA,MAAa,kBAAkC,EAAE,OAAO,mBAAmB;;;;;AAgB3E,SAAgB,SAAsC,OAAyB;CAC7E,MAAM,EACJ,IACA,KACA,WACA,OAAO,YACP,UACA,QAAQ,YACR,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,YAAY,QAAQ,GAAG;CAC7C,MAAM,OAAO,iBAAiB,IAAI;CAClC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,oBAAC,MAAD;EAAM,WAAW,GAAG,mBAAmB,OAAO,WAAW,SAAS;EAAS;EAAM,GAAI;EAClF,UAAA,YAAY,OAAO;CAChB,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import { LabelsInput } from "../lib/labels.js";
|
|
2
3
|
import { Theme } from "../lib/theme.js";
|
|
3
4
|
import { ReactNode } from "react";
|
|
4
5
|
export interface SlurpProviderProps {
|
|
@@ -6,6 +7,11 @@ export interface SlurpProviderProps {
|
|
|
6
7
|
theme?: Theme;
|
|
7
8
|
/** localStorage key that remembers the chosen scheme; `null` disables persistence. Default `slurp-theme`. */
|
|
8
9
|
storageKey?: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Texts of every component inside: `'en'`, `'it'` (the default) or your own texts by component, e.g.
|
|
12
|
+
* `{ Dialog: { close: 'Dismiss' } }`. A component's own `labels` prop still wins.
|
|
13
|
+
*/
|
|
14
|
+
labels?: LabelsInput;
|
|
9
15
|
children?: ReactNode;
|
|
10
16
|
}
|
|
11
17
|
/**
|
|
@@ -14,5 +20,5 @@ export interface SlurpProviderProps {
|
|
|
14
20
|
* hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the
|
|
15
21
|
* colour scheme of the outer provider.
|
|
16
22
|
*/
|
|
17
|
-
export declare function SlurpProvider({ theme, storageKey, children }: SlurpProviderProps): import("react").JSX.Element;
|
|
23
|
+
export declare function SlurpProvider({ theme, storageKey, labels: labelsProp, children }: SlurpProviderProps): import("react").JSX.Element;
|
|
18
24
|
//# sourceMappingURL=SlurpProvider.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { DEFAULT_STORAGE_KEY, defaultTheme, styleId, themeCss } from "../lib/theme.js";
|
|
3
3
|
import { SlurpContext } from "../internal/context.js";
|
|
4
|
+
import { LabelsContext } from "../internal/labels.js";
|
|
5
|
+
import { resolveLabels } from "../lib/labels.js";
|
|
4
6
|
import { useCallback, useContext, useEffect, useId, useMemo, useState, useSyncExternalStore } from "react";
|
|
5
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
// src/SlurpProvider/SlurpProvider.tsx
|
|
@@ -42,7 +44,8 @@ function applyMode(mode) {
|
|
|
42
44
|
* hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the
|
|
43
45
|
* colour scheme of the outer provider.
|
|
44
46
|
*/
|
|
45
|
-
function SlurpProvider({ theme = defaultTheme, storageKey = DEFAULT_STORAGE_KEY, children }) {
|
|
47
|
+
function SlurpProvider({ theme = defaultTheme, storageKey = DEFAULT_STORAGE_KEY, labels: labelsProp, children }) {
|
|
48
|
+
const outerLabels = useContext(LabelsContext);
|
|
46
49
|
const outer = useContext(SlurpContext).colorScheme;
|
|
47
50
|
const scope = useId();
|
|
48
51
|
const stored = useSyncExternalStore(subscribeStorage, () => readStored(storageKey), () => null);
|
|
@@ -92,13 +95,18 @@ function SlurpProvider({ theme = defaultTheme, storageKey = DEFAULT_STORAGE_KEY,
|
|
|
92
95
|
precedence: "slurp",
|
|
93
96
|
children: css
|
|
94
97
|
});
|
|
98
|
+
const labels = useMemo(() => resolveLabels(labelsProp), [labelsProp]);
|
|
99
|
+
const content = outer ? /* @__PURE__ */ jsx("div", {
|
|
100
|
+
"data-slurp-theme": scope,
|
|
101
|
+
style: { display: "contents" },
|
|
102
|
+
children
|
|
103
|
+
}) : children;
|
|
95
104
|
return /* @__PURE__ */ jsxs(SlurpContext, {
|
|
96
105
|
value,
|
|
97
|
-
children: [style,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}) : children]
|
|
106
|
+
children: [style, labels && labels !== outerLabels ? /* @__PURE__ */ jsx(LabelsContext, {
|
|
107
|
+
value: labels,
|
|
108
|
+
children: content
|
|
109
|
+
}) : content]
|
|
102
110
|
});
|
|
103
111
|
}
|
|
104
112
|
export { SlurpProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlurpProvider.js","names":[],"sources":["../../src/SlurpProvider/SlurpProvider.tsx"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from 'react';\n\nimport { SlurpContext, type ColorSchemeState } from '../internal/context';\nimport {\n DEFAULT_STORAGE_KEY,\n defaultTheme,\n styleId,\n themeCss,\n type ColorSchemeMode,\n type Theme,\n} from '../lib/theme';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\nexport interface SlurpProviderProps {\n /** From `createTheme()`. */\n theme?: Theme;\n /** localStorage key that remembers the chosen scheme; `null` disables persistence. Default `slurp-theme`. */\n storageKey?: string | null;\n children?: ReactNode;\n}\n\nconst isMode = (v: unknown): v is ColorSchemeMode =>\n v === 'light' || v === 'dark' || v === 'system';\n\n// Storage can throw (private mode, blocked site data): every access is guarded and simply falls back.\nfunction readStored(key: string | null): ColorSchemeMode | null {\n if (!key) return null;\n try {\n const v = window.localStorage.getItem(key);\n return isMode(v) ? v : null;\n } catch {\n return null;\n }\n}\n\nconst listeners = new Set<() => void>();\nfunction subscribeStorage(onChange: () => void) {\n listeners.add(onChange);\n window.addEventListener('storage', onChange);\n return () => {\n listeners.delete(onChange);\n window.removeEventListener('storage', onChange);\n };\n}\n\nfunction subscribeSystem(onChange: () => void) {\n const query = window.matchMedia?.(DARK_QUERY);\n query?.addEventListener('change', onChange);\n return () => query?.removeEventListener('change', onChange);\n}\nconst systemSnapshot = () => (window.matchMedia?.(DARK_QUERY).matches ? 'dark' : 'light');\n\n/** Writes `data-theme` on <html>: `light` / `dark`, or no attribute for `system` (prefers-color-scheme decides). */\nfunction applyMode(mode: ColorSchemeMode) {\n const root = document.documentElement;\n if (mode === 'system') root.removeAttribute('data-theme');\n else root.setAttribute('data-theme', mode);\n}\n\n/**\n * Theme, colour scheme and runtime styles for everything inside.\n * At the app root it renders no element: the colour scheme goes on <html data-theme>, theme overrides into one\n * hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the\n * colour scheme of the outer provider.\n */\nexport function SlurpProvider({\n theme = defaultTheme,\n storageKey = DEFAULT_STORAGE_KEY,\n children,\n}: SlurpProviderProps) {\n const outer = useContext(SlurpContext).colorScheme;\n const scope = useId();\n const stored = useSyncExternalStore(\n subscribeStorage,\n () => readStored(storageKey),\n () => null,\n );\n // A choice that could not be stored (or storage disabled) lives in state and wins over the stored one.\n const [local, setLocal] = useState<ColorSchemeMode | null>(null);\n const mode = local ?? stored ?? theme.colorScheme;\n const system = useSyncExternalStore(subscribeSystem, systemSnapshot, () => 'light' as const);\n\n // Reads storage again: during hydration `stored` is still the server snapshot (null) for one render.\n useEffect(() => {\n if (!outer) applyMode(local ?? readStored(storageKey) ?? theme.colorScheme);\n }, [outer, mode, local, storageKey, theme.colorScheme]);\n\n const setMode = useCallback(\n (next: ColorSchemeMode) => {\n if (!storageKey) return setLocal(next);\n try {\n window.localStorage.setItem(storageKey, next);\n setLocal(null);\n } catch {\n setLocal(next);\n }\n for (const notify of listeners) notify();\n },\n [storageKey],\n );\n\n const own = useMemo<ColorSchemeState>(\n () => ({ mode, setMode, resolved: mode === 'system' ? system : mode }),\n [mode, setMode, system],\n );\n const colorScheme = outer ?? own;\n const value = useMemo(() => ({ theme, colorScheme }), [theme, colorScheme]);\n const css = useMemo(() => themeCss(theme, outer ? scope : undefined), [theme, outer, scope]);\n\n const style = css && (\n <style href={styleId('theme', css)} precedence=\"slurp\">\n {css}\n </style>\n );\n
|
|
1
|
+
{"version":3,"file":"SlurpProvider.js","names":[],"sources":["../../src/SlurpProvider/SlurpProvider.tsx"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from 'react';\n\nimport { SlurpContext, type ColorSchemeState } from '../internal/context';\nimport { LabelsContext } from '../internal/labels';\nimport { resolveLabels, type LabelsInput } from '../lib/labels';\nimport {\n DEFAULT_STORAGE_KEY,\n defaultTheme,\n styleId,\n themeCss,\n type ColorSchemeMode,\n type Theme,\n} from '../lib/theme';\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\nexport interface SlurpProviderProps {\n /** From `createTheme()`. */\n theme?: Theme;\n /** localStorage key that remembers the chosen scheme; `null` disables persistence. Default `slurp-theme`. */\n storageKey?: string | null;\n /**\n * Texts of every component inside: `'en'`, `'it'` (the default) or your own texts by component, e.g.\n * `{ Dialog: { close: 'Dismiss' } }`. A component's own `labels` prop still wins.\n */\n labels?: LabelsInput;\n children?: ReactNode;\n}\n\nconst isMode = (v: unknown): v is ColorSchemeMode =>\n v === 'light' || v === 'dark' || v === 'system';\n\n// Storage can throw (private mode, blocked site data): every access is guarded and simply falls back.\nfunction readStored(key: string | null): ColorSchemeMode | null {\n if (!key) return null;\n try {\n const v = window.localStorage.getItem(key);\n return isMode(v) ? v : null;\n } catch {\n return null;\n }\n}\n\nconst listeners = new Set<() => void>();\nfunction subscribeStorage(onChange: () => void) {\n listeners.add(onChange);\n window.addEventListener('storage', onChange);\n return () => {\n listeners.delete(onChange);\n window.removeEventListener('storage', onChange);\n };\n}\n\nfunction subscribeSystem(onChange: () => void) {\n const query = window.matchMedia?.(DARK_QUERY);\n query?.addEventListener('change', onChange);\n return () => query?.removeEventListener('change', onChange);\n}\nconst systemSnapshot = () => (window.matchMedia?.(DARK_QUERY).matches ? 'dark' : 'light');\n\n/** Writes `data-theme` on <html>: `light` / `dark`, or no attribute for `system` (prefers-color-scheme decides). */\nfunction applyMode(mode: ColorSchemeMode) {\n const root = document.documentElement;\n if (mode === 'system') root.removeAttribute('data-theme');\n else root.setAttribute('data-theme', mode);\n}\n\n/**\n * Theme, colour scheme and runtime styles for everything inside.\n * At the app root it renders no element: the colour scheme goes on <html data-theme>, theme overrides into one\n * hoisted <style>. Nested, it themes only its subtree (through a `display: contents` wrapper) and shares the\n * colour scheme of the outer provider.\n */\nexport function SlurpProvider({\n theme = defaultTheme,\n storageKey = DEFAULT_STORAGE_KEY,\n labels: labelsProp,\n children,\n}: SlurpProviderProps) {\n const outerLabels = useContext(LabelsContext);\n const outer = useContext(SlurpContext).colorScheme;\n const scope = useId();\n const stored = useSyncExternalStore(\n subscribeStorage,\n () => readStored(storageKey),\n () => null,\n );\n // A choice that could not be stored (or storage disabled) lives in state and wins over the stored one.\n const [local, setLocal] = useState<ColorSchemeMode | null>(null);\n const mode = local ?? stored ?? theme.colorScheme;\n const system = useSyncExternalStore(subscribeSystem, systemSnapshot, () => 'light' as const);\n\n // Reads storage again: during hydration `stored` is still the server snapshot (null) for one render.\n useEffect(() => {\n if (!outer) applyMode(local ?? readStored(storageKey) ?? theme.colorScheme);\n }, [outer, mode, local, storageKey, theme.colorScheme]);\n\n const setMode = useCallback(\n (next: ColorSchemeMode) => {\n if (!storageKey) return setLocal(next);\n try {\n window.localStorage.setItem(storageKey, next);\n setLocal(null);\n } catch {\n setLocal(next);\n }\n for (const notify of listeners) notify();\n },\n [storageKey],\n );\n\n const own = useMemo<ColorSchemeState>(\n () => ({ mode, setMode, resolved: mode === 'system' ? system : mode }),\n [mode, setMode, system],\n );\n const colorScheme = outer ?? own;\n const value = useMemo(() => ({ theme, colorScheme }), [theme, colorScheme]);\n const css = useMemo(() => themeCss(theme, outer ? scope : undefined), [theme, outer, scope]);\n\n const style = css && (\n <style href={styleId('theme', css)} precedence=\"slurp\">\n {css}\n </style>\n );\n const labels = useMemo(() => resolveLabels(labelsProp), [labelsProp]);\n const content = outer ? (\n <div data-slurp-theme={scope} style={{ display: 'contents' }}>\n {children}\n </div>\n ) : (\n children\n );\n return (\n <SlurpContext value={value}>\n {style}\n {labels && labels !== outerLabels ? (\n <LabelsContext value={labels}>{content}</LabelsContext>\n ) : (\n content\n )}\n </SlurpContext>\n );\n}\n"],"mappings":";;;;;;;;AAuBA,MAAM,aAAa;AAenB,MAAM,UAAU,MACd,MAAM,WAAW,MAAM,UAAU,MAAM;AAGzC,SAAS,WAAW,KAA4C;CAC9D,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI;EACF,MAAM,IAAI,OAAO,aAAa,QAAQ,GAAG;EACzC,OAAO,OAAO,CAAC,IAAI,IAAI;CACzB,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,4BAAY,IAAI,IAAgB;AACtC,SAAS,iBAAiB,UAAsB;CAC9C,UAAU,IAAI,QAAQ;CACtB,OAAO,iBAAiB,WAAW,QAAQ;CAC3C,aAAa;EACX,UAAU,OAAO,QAAQ;EACzB,OAAO,oBAAoB,WAAW,QAAQ;CAChD;AACF;AAEA,SAAS,gBAAgB,UAAsB;CAC7C,MAAM,QAAQ,OAAO,aAAa,UAAU;CAC5C,OAAO,iBAAiB,UAAU,QAAQ;CAC1C,aAAa,OAAO,oBAAoB,UAAU,QAAQ;AAC5D;AACA,MAAM,uBAAwB,OAAO,aAAa,UAAU,CAAC,CAAC,UAAU,SAAS;;AAGjF,SAAS,UAAU,MAAuB;CACxC,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,UAAU,KAAK,gBAAgB,YAAY;MACnD,KAAK,aAAa,cAAc,IAAI;AAC3C;;;;;;;AAQA,SAAgB,cAAc,EAC5B,QAAQ,cACR,aAAa,qBACb,QAAQ,YACR,YACqB;CACrB,MAAM,cAAc,WAAW,aAAa;CAC5C,MAAM,QAAQ,WAAW,YAAY,CAAC,CAAC;CACvC,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,qBACb,wBACM,WAAW,UAAU,SACrB,IACR;CAEA,MAAM,CAAC,OAAO,YAAY,SAAiC,IAAI;CAC/D,MAAM,OAAO,SAAS,UAAU,MAAM;CACtC,MAAM,SAAS,qBAAqB,iBAAiB,sBAAsB,OAAgB;CAG3F,gBAAgB;EACd,IAAI,CAAC,OAAO,UAAU,SAAS,WAAW,UAAU,KAAK,MAAM,WAAW;CAC5E,GAAG;EAAC;EAAO;EAAM;EAAO;EAAY,MAAM;CAAW,CAAC;CAEtD,MAAM,UAAU,aACb,SAA0B;EACzB,IAAI,CAAC,YAAY,OAAO,SAAS,IAAI;EACrC,IAAI;GACF,OAAO,aAAa,QAAQ,YAAY,IAAI;GAC5C,SAAS,IAAI;EACf,QAAQ;GACN,SAAS,IAAI;EACf;EACA,KAAK,MAAM,UAAU,WAAW,OAAO;CACzC,GACA,CAAC,UAAU,CACb;CAEA,MAAM,MAAM,eACH;EAAE;EAAM;EAAS,UAAU,SAAS,WAAW,SAAS;CAAK,IACpE;EAAC;EAAM;EAAS;CAAM,CACxB;CACA,MAAM,cAAc,SAAS;CAC7B,MAAM,QAAQ,eAAe;EAAE;EAAO;CAAY,IAAI,CAAC,OAAO,WAAW,CAAC;CAC1E,MAAM,MAAM,cAAc,SAAS,OAAO,QAAQ,QAAQ,KAAA,CAAS,GAAG;EAAC;EAAO;EAAO;CAAK,CAAC;CAE3F,MAAM,QAAQ,OACZ,oBAAC,SAAD;EAAO,MAAM,QAAQ,SAAS,GAAG;EAAG,YAAW;EAC5C,UAAA;CACI,CAAA;CAET,MAAM,SAAS,cAAc,cAAc,UAAU,GAAG,CAAC,UAAU,CAAC;CACpE,MAAM,UAAU,QACd,oBAAC,OAAD;EAAK,oBAAkB;EAAO,OAAO,EAAE,SAAS,WAAW;EACxD;CACE,CAAA,IAEL;CAEF,OACE,qBAAC,cAAD;EAAqB;EAArB,UAAA,CACG,OACA,UAAU,WAAW,cACpB,oBAAC,eAAD;GAAe,OAAO;GAAS,UAAA;EAAuB,CAAA,IAEtD,OAEU;;AAElB"}
|
package/dist/Steps/Steps.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
2
3
|
import { cx } from "../utils/src/index.js";
|
|
3
4
|
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
5
|
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
@@ -19,6 +20,7 @@ function Steps(props) {
|
|
|
19
20
|
const { as, css, className, steps, value: valueProp, defaultValue, onValueChange, navigable = "done", orientation = "horizontal", labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Steps", props);
|
|
20
21
|
const labels = {
|
|
21
22
|
...STEPS_LABELS,
|
|
23
|
+
...useLabels("Steps"),
|
|
22
24
|
...labelsProp
|
|
23
25
|
};
|
|
24
26
|
const [value, setValue] = useControlled({
|
package/dist/Steps/Steps.js.map
CHANGED
|
@@ -1 +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":"
|
|
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 { useLabels } from '../internal/labels';\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, ...useLabels('Steps'), ...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":";;;;;;;;;;AA0BA,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,UAAU,OAAO;EAAG,GAAG;CAAW;CACvE,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,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,EAAE,MAAM,UAAU,SAAS,SAAS;EAAE;EAAO;EAAW;CAAW,CAAC;CAC1E,MAAM,OAAO,iBAAiB,IAAI;CAElC,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,oBAAC,MAAD;GACE,WAAW,GAAG,eAAe,OAAO,WAAW,SAAS;GACxD,cAAY,OAAO;GACnB,oBAAkB;GAClB,GAAI;GAEH,UAAA,KAAK,QAAQ,MAAM;IAClB,WAAW;IACX,UAAU,MAAM,KAAK,GAAG,MAAM;KAC5B,MAAM,QAAQ,IAAI,UAAU,SAAS,MAAM,UAAU,YAAY;KACjE,MAAM,YACJ,MAAM,WACN,CAAC,EAAE,aACF,cAAc,SAAU,cAAc,UAAU,UAAU;KAC7D,MAAM,OACJ,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,QAAD;MAAM,WAAU;MAAqB,eAAY;MAC9C,UAAA,UAAU,SAAS,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,IAAI,IAAI;KAC9C,CAAA,GACN,qBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,qBAAC,QAAD;OAAM,WAAU;OAAhB,UAAA,CACG,EAAE,OACF,UAAU,UACT,qBAAC,QAAD;QAAM,WAAU;QAAhB,UAAA,CAAwC,MAAG,OAAO,IAAW;OAE3D,CAAA,CAAA;MACL,CAAA,GAAA,EAAE,eAAe,QAChB,oBAAC,QAAD;OAAM,WAAU;OAA2B,UAAA,EAAE;MAAkB,CAAA,CAE7D;KACN,CAAA,CAAA,EAAA,CAAA;KAEJ,OACE,oBAAC,UAAD,EAAA,UACG,KAAK,QAAQ,MAAM;MAClB,WAAW;MACX,cAAc;MACd,gBAAgB,UAAU,YAAY,SAAS,KAAA;MAC/C,UAAU,YACR,oBAAC,UAAD;OACE,MAAK;OACL,WAAU;OACV,eAAe,SAAS,EAAE,KAAK;OAE9B,UAAA;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"}
|
package/dist/Suggest/Suggest.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
2
3
|
import { cx } from "../utils/src/index.js";
|
|
3
4
|
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
5
|
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
@@ -25,6 +26,7 @@ function Suggest(props) {
|
|
|
25
26
|
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
27
|
const labels = {
|
|
27
28
|
...SUGGEST_LABELS,
|
|
29
|
+
...useLabels("Suggest"),
|
|
28
30
|
...labelsProp
|
|
29
31
|
};
|
|
30
32
|
const { input, root: rest } = splitInputProps(others);
|