@slurp-ui/react 1.2.0 → 1.4.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/AvatarGroup/AvatarGroup.d.ts +26 -0
  3. package/dist/AvatarGroup/AvatarGroup.js +46 -0
  4. package/dist/AvatarGroup/AvatarGroup.js.map +1 -0
  5. package/dist/AvatarGroup/index.d.ts +3 -0
  6. package/dist/AvatarGroup/index.js +2 -0
  7. package/dist/Compare/Compare.d.ts +23 -0
  8. package/dist/Compare/Compare.js +61 -0
  9. package/dist/Compare/Compare.js.map +1 -0
  10. package/dist/Compare/index.d.ts +3 -0
  11. package/dist/Compare/index.js +2 -0
  12. package/dist/Consent/Consent.d.ts +30 -0
  13. package/dist/Consent/Consent.js +70 -0
  14. package/dist/Consent/Consent.js.map +1 -0
  15. package/dist/Consent/index.d.ts +3 -0
  16. package/dist/Consent/index.js +2 -0
  17. package/dist/Dialog/Dialog.d.ts +2 -0
  18. package/dist/Dialog/Dialog.js +19 -8
  19. package/dist/Dialog/Dialog.js.map +1 -1
  20. package/dist/Lightbox/Lightbox.d.ts +30 -0
  21. package/dist/Lightbox/Lightbox.js +74 -0
  22. package/dist/Lightbox/Lightbox.js.map +1 -0
  23. package/dist/Lightbox/index.d.ts +3 -0
  24. package/dist/Lightbox/index.js +2 -0
  25. package/dist/Menu/Menu.d.ts +13 -0
  26. package/dist/Menu/Menu.js +43 -11
  27. package/dist/Menu/Menu.js.map +1 -1
  28. package/dist/Menu/index.d.ts +2 -2
  29. package/dist/Menu/index.js +1 -1
  30. package/dist/MultiSuggest/MultiSuggest.d.ts +39 -0
  31. package/dist/MultiSuggest/MultiSuggest.js +267 -0
  32. package/dist/MultiSuggest/MultiSuggest.js.map +1 -0
  33. package/dist/MultiSuggest/index.d.ts +3 -0
  34. package/dist/MultiSuggest/index.js +2 -0
  35. package/dist/Reveal/Reveal.d.ts +16 -0
  36. package/dist/Reveal/Reveal.js +77 -0
  37. package/dist/Reveal/Reveal.js.map +1 -0
  38. package/dist/Reveal/index.d.ts +3 -0
  39. package/dist/Reveal/index.js +2 -0
  40. package/dist/Sheet/Sheet.d.ts +8 -3
  41. package/dist/Sheet/Sheet.js +1 -1
  42. package/dist/Sheet/Sheet.js.map +1 -1
  43. package/dist/Sheet/index.d.ts +2 -2
  44. package/dist/Table/Table.d.ts +12 -0
  45. package/dist/Table/Table.js +54 -10
  46. package/dist/Table/Table.js.map +1 -1
  47. package/dist/Timeline/Timeline.d.ts +23 -0
  48. package/dist/Timeline/Timeline.js +49 -0
  49. package/dist/Timeline/Timeline.js.map +1 -0
  50. package/dist/Timeline/index.d.ts +3 -0
  51. package/dist/Timeline/index.js +2 -0
  52. package/dist/Tree/Tree.d.ts +24 -0
  53. package/dist/Tree/Tree.js +113 -0
  54. package/dist/Tree/Tree.js.map +1 -0
  55. package/dist/Tree/index.d.ts +3 -0
  56. package/dist/Tree/index.js +2 -0
  57. package/dist/index.d.ts +21 -5
  58. package/dist/index.js +10 -2
  59. package/dist/lib/labels.d.ts +36 -1
  60. package/dist/lib/labels.js +24 -1
  61. package/dist/lib/labels.js.map +1 -1
  62. package/dist/lib/theme.d.ts +41 -1
  63. package/dist/lib/theme.js.map +1 -1
  64. package/dist/styles.css +576 -37
  65. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @slurp-ui/react
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b386d97: New component: `Reveal`, a large sentence whose words go from the secondary colour to the full one as the page scrolls. Colour only, lit with reduced motion and without script.
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 82f0410: New components: `MultiSuggest` (Suggest with several choices and removable tags), `Timeline`, `AvatarGroup` and `Consent` (a banner where refusing is as easy as accepting). `Table` gains row selection (`selectable`) and a fixed header (`maxHeight`). `Menu` gains `Menu.Group`, `Menu.Separator` and a `shortcut` on each item. `Sheet` can slide in from a side with `side="end"` or `"start"`.
14
+ - a38bda7: New components: `Tree` (nested list with full keyboard support), `Compare` (before and after slider) and `Lightbox` (pictures at full size in a modal). Right-to-left: every component stylesheet now uses logical properties (start/end instead of left/right), and the Switch, Toast and Lightbox movements mirror.
15
+
16
+ ### Patch Changes
17
+
18
+ - 56a8957: The last `Fold` of a group no longer draws a line under itself, so it does not meet the corners of a rounded container.
19
+ - 04c84d6: `Prose` paragraphs and list items use `text-wrap: pretty`, so a line never ends on a single word.
20
+ - Updated dependencies [efe26ec]
21
+ - @slurp-ui/icons@1.3.0
22
+
3
23
  ## 1.2.0
4
24
 
5
25
  ### Minor Changes
@@ -0,0 +1,26 @@
1
+
2
+ import { PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { AvatarOwnProps } from "../Avatar/Avatar.js";
4
+ import { ElementType } from "react";
5
+ export interface AvatarGroupLabels {
6
+ /** Names the "+N" counter: `more(3)` → "altre 3 persone". */
7
+ more: (count: number) => string;
8
+ }
9
+ export declare const AVATAR_GROUP_LABELS: AvatarGroupLabels;
10
+ export interface AvatarGroupOwnProps {
11
+ /** The people: a name each, a photo when there is one. */
12
+ people: {
13
+ name: string;
14
+ src?: string;
15
+ }[];
16
+ /** Most avatars shown before the "+N" counter. Default 4. */
17
+ max?: number;
18
+ size?: AvatarOwnProps['size'];
19
+ /** Names the group (who they are: "Partecipanti"). */
20
+ label?: string;
21
+ labels?: Partial<AvatarGroupLabels>;
22
+ }
23
+ export type AvatarGroupProps<E extends ElementType = 'div'> = PolymorphicProps<E, AvatarGroupOwnProps>;
24
+ /** Overlapping avatars of the people in a group, with a "+N" counter for the rest. */
25
+ export declare function AvatarGroup<E extends ElementType = 'div'>(props: AvatarGroupProps<E>): import("react").JSX.Element;
26
+ //# sourceMappingURL=AvatarGroup.d.ts.map
@@ -0,0 +1,46 @@
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 { Avatar } from "../Avatar/Avatar.js";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ // src/AvatarGroup/AvatarGroup.tsx
9
+ const AVATAR_GROUP_LABELS = { more: (n) => n === 1 ? "un’altra persona" : `altre ${n} persone` };
10
+ /** Overlapping avatars of the people in a group, with a "+N" counter for the rest. */
11
+ function AvatarGroup(props) {
12
+ const { as, css, className, people, max = 4, size = "md", label, labels: labelsProp, ...rest } = useThemeProps("AvatarGroup", props);
13
+ const labels = {
14
+ ...AVATAR_GROUP_LABELS,
15
+ ...useLabels("AvatarGroup"),
16
+ ...labelsProp
17
+ };
18
+ const Root = as ?? "div";
19
+ const styled = useCss("AvatarGroup", "root", css);
20
+ const root = useAnimationRoot(rest);
21
+ const shown = people.slice(0, Math.max(1, max));
22
+ const hidden = people.length - shown.length;
23
+ return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
24
+ role: "group",
25
+ "aria-label": label,
26
+ className: cx("slurp-avatargroup", styled.className, className),
27
+ "data-size": size,
28
+ ...root,
29
+ children: [shown.map((p) => /* @__PURE__ */ jsx(Avatar, {
30
+ name: p.name,
31
+ src: p.src,
32
+ size
33
+ }, p.name)), hidden > 0 && /* @__PURE__ */ jsx("span", {
34
+ className: "slurp-avatargroup-more",
35
+ role: "img",
36
+ "aria-label": labels.more(hidden),
37
+ children: /* @__PURE__ */ jsxs("span", {
38
+ "aria-hidden": "true",
39
+ children: ["+", hidden]
40
+ })
41
+ })]
42
+ })] });
43
+ }
44
+ export { AVATAR_GROUP_LABELS, AvatarGroup };
45
+
46
+ //# sourceMappingURL=AvatarGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AvatarGroup.js","names":[],"sources":["../../src/AvatarGroup/AvatarGroup.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType } from 'react';\n\nimport { Avatar, type AvatarOwnProps } from '../Avatar/Avatar';\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 AvatarGroupLabels {\n /** Names the \"+N\" counter: `more(3)` → \"altre 3 persone\". */\n more: (count: number) => string;\n}\n\nexport const AVATAR_GROUP_LABELS: AvatarGroupLabels = {\n more: (n) => (n === 1 ? 'un’altra persona' : `altre ${n} persone`),\n};\n\nexport interface AvatarGroupOwnProps {\n /** The people: a name each, a photo when there is one. */\n people: { name: string; src?: string }[];\n /** Most avatars shown before the \"+N\" counter. Default 4. */\n max?: number;\n size?: AvatarOwnProps['size'];\n /** Names the group (who they are: \"Partecipanti\"). */\n label?: string;\n labels?: Partial<AvatarGroupLabels>;\n}\n\nexport type AvatarGroupProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n AvatarGroupOwnProps\n>;\n\n/** Overlapping avatars of the people in a group, with a \"+N\" counter for the rest. */\nexport function AvatarGroup<E extends ElementType = 'div'>(props: AvatarGroupProps<E>) {\n const {\n as,\n css,\n className,\n people,\n max = 4,\n size = 'md',\n label,\n labels: labelsProp,\n ...rest\n } = useThemeProps('AvatarGroup', props as AvatarGroupProps);\n const labels = { ...AVATAR_GROUP_LABELS, ...useLabels('AvatarGroup'), ...labelsProp };\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('AvatarGroup', 'root', css);\n const root = useAnimationRoot(rest);\n const shown = people.slice(0, Math.max(1, max));\n const hidden = people.length - shown.length;\n return (\n <>\n {styled.style}\n <Root\n role=\"group\"\n aria-label={label}\n className={cx('slurp-avatargroup', styled.className, className)}\n data-size={size}\n {...root}\n >\n {shown.map((p) => (\n <Avatar key={p.name} name={p.name} src={p.src} size={size} />\n ))}\n {hidden > 0 && (\n <span className=\"slurp-avatargroup-more\" role=\"img\" aria-label={labels.more(hidden)}>\n <span aria-hidden=\"true\">+{hidden}</span>\n </span>\n )}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,sBAAyC,EACpD,OAAO,MAAO,MAAM,IAAI,qBAAqB,SAAS,EAAE,UAC1D;;AAmBA,SAAgB,YAA2C,OAA4B;CACrF,MAAM,EACJ,IACA,KACA,WACA,QACA,MAAM,GACN,OAAO,MACP,OACA,QAAQ,YACR,GAAG,SACD,cAAc,eAAe,KAAyB;CAC1D,MAAM,SAAS;EAAE,GAAG;EAAqB,GAAG,UAAU,aAAa;EAAG,GAAG;CAAW;CACpF,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,eAAe,QAAQ,GAAG;CAChD,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,OAAO,MAAM,GAAG,KAAK,IAAI,GAAG,GAAG,CAAC;CAC9C,MAAM,SAAS,OAAO,SAAS,MAAM;CACrC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,MAAK;EACL,cAAY;EACZ,WAAW,GAAG,qBAAqB,OAAO,WAAW,SAAS;EAC9D,aAAW;EACX,GAAI;EALN,UAAA,CAOG,MAAM,KAAK,MACV,oBAAC,QAAD;GAAqB,MAAM,EAAE;GAAM,KAAK,EAAE;GAAW;EAAO,GAA/C,EAAE,IAA6C,CAC7D,GACA,SAAS,KACR,oBAAC,QAAD;GAAM,WAAU;GAAyB,MAAK;GAAM,cAAY,OAAO,KAAK,MAAM;GAChF,UAAA,qBAAC,QAAD;IAAM,eAAY;IAAlB,UAAA,CAAyB,KAAE,MAAa;;EACpC,CAAA,CAEJ;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
@@ -0,0 +1,3 @@
1
+
2
+ import { AVATAR_GROUP_LABELS, AvatarGroup, AvatarGroupLabels, AvatarGroupProps } from "./AvatarGroup.js";
3
+ export { AVATAR_GROUP_LABELS, AvatarGroup, type AvatarGroupLabels, type AvatarGroupProps, AvatarGroup as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { AVATAR_GROUP_LABELS, AvatarGroup, AvatarGroup as default } from "./AvatarGroup.js";
@@ -0,0 +1,23 @@
1
+
2
+ import { PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { ElementType, ReactNode } from "react";
4
+ export interface CompareLabels {
5
+ /** Names the slider: how much of the "after" shows. */
6
+ handle: string;
7
+ }
8
+ export declare const COMPARE_LABELS: CompareLabels;
9
+ export interface CompareOwnProps {
10
+ /** The "before" content (usually an image), on the start side. */
11
+ before: ReactNode;
12
+ /** The "after" content, same size as `before`. */
13
+ after: ReactNode;
14
+ /** Share of the width given to `before`, 0–100. Default 50. */
15
+ value?: number;
16
+ defaultValue?: number;
17
+ onValueChange?: (value: number) => void;
18
+ labels?: Partial<CompareLabels>;
19
+ }
20
+ export type CompareProps<E extends ElementType = 'div'> = PolymorphicProps<E, CompareOwnProps>;
21
+ /** Two pictures in one frame with a divider that sweeps between them: a range input, so keys and touch just work. */
22
+ export declare function Compare<E extends ElementType = 'div'>(props: CompareProps<E>): import("react").JSX.Element;
23
+ //# sourceMappingURL=Compare.d.ts.map
@@ -0,0 +1,61 @@
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 { useControlled } from "../utils/useControlled.js";
7
+ import { useId } from "react";
8
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
+ // src/Compare/Compare.tsx
10
+ const COMPARE_LABELS = { handle: "Confronta prima e dopo" };
11
+ /** Two pictures in one frame with a divider that sweeps between them: a range input, so keys and touch just work. */
12
+ function Compare(props) {
13
+ const { as, css, className, before, after, value: valueProp, defaultValue = 50, onValueChange, labels: labelsProp, ...rest } = useThemeProps("Compare", props);
14
+ const labels = {
15
+ ...COMPARE_LABELS,
16
+ ...useLabels("Compare"),
17
+ ...labelsProp
18
+ };
19
+ const [value, setValue] = useControlled({
20
+ value: valueProp,
21
+ defaultValue,
22
+ onChange: onValueChange
23
+ });
24
+ const Root = as ?? "div";
25
+ const styled = useCss("Compare", "root", css);
26
+ const root = useAnimationRoot(rest);
27
+ const id = useId();
28
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
29
+ className: cx("slurp-compare", styled.className, className),
30
+ style: { "--slurp-compare": `${value}%` },
31
+ ...root,
32
+ children: [
33
+ /* @__PURE__ */ jsx("div", {
34
+ className: "slurp-compare-after",
35
+ children: after
36
+ }),
37
+ /* @__PURE__ */ jsx("div", {
38
+ className: "slurp-compare-before",
39
+ children: before
40
+ }),
41
+ /* @__PURE__ */ jsx("span", {
42
+ className: "slurp-compare-line",
43
+ "aria-hidden": "true"
44
+ }),
45
+ /* @__PURE__ */ jsx("input", {
46
+ id,
47
+ type: "range",
48
+ min: 0,
49
+ max: 100,
50
+ value,
51
+ "aria-label": labels.handle,
52
+ "aria-valuetext": `${Math.round(value)}%`,
53
+ className: "slurp-compare-range",
54
+ onChange: (e) => setValue(Number(e.target.value))
55
+ })
56
+ ]
57
+ })] });
58
+ }
59
+ export { COMPARE_LABELS, Compare };
60
+
61
+ //# sourceMappingURL=Compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Compare.js","names":[],"sources":["../../src/Compare/Compare.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n useId,\n type ChangeEvent,\n type CSSProperties,\n type ElementType,\n type ReactNode,\n} from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface CompareLabels {\n /** Names the slider: how much of the \"after\" shows. */\n handle: string;\n}\n\nexport const COMPARE_LABELS: CompareLabels = { handle: 'Confronta prima e dopo' };\n\nexport interface CompareOwnProps {\n /** The \"before\" content (usually an image), on the start side. */\n before: ReactNode;\n /** The \"after\" content, same size as `before`. */\n after: ReactNode;\n /** Share of the width given to `before`, 0–100. Default 50. */\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n labels?: Partial<CompareLabels>;\n}\n\nexport type CompareProps<E extends ElementType = 'div'> = PolymorphicProps<E, CompareOwnProps>;\n\n/** Two pictures in one frame with a divider that sweeps between them: a range input, so keys and touch just work. */\nexport function Compare<E extends ElementType = 'div'>(props: CompareProps<E>) {\n const {\n as,\n css,\n className,\n before,\n after,\n value: valueProp,\n defaultValue = 50,\n onValueChange,\n labels: labelsProp,\n ...rest\n } = useThemeProps('Compare', props as CompareProps);\n const labels = { ...COMPARE_LABELS, ...useLabels('Compare'), ...labelsProp };\n const [value, setValue] = useControlled({\n value: valueProp,\n defaultValue,\n onChange: onValueChange,\n });\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Compare', 'root', css);\n const root = useAnimationRoot(rest);\n const id = useId();\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-compare', styled.className, className)}\n style={{ '--slurp-compare': `${value}%` } as CSSProperties}\n {...root}\n >\n <div className=\"slurp-compare-after\">{after}</div>\n <div className=\"slurp-compare-before\">{before}</div>\n <span className=\"slurp-compare-line\" aria-hidden=\"true\" />\n <input\n id={id}\n type=\"range\"\n min={0}\n max={100}\n value={value}\n aria-label={labels.handle}\n aria-valuetext={`${Math.round(value)}%`}\n className=\"slurp-compare-range\"\n onChange={(e: ChangeEvent<HTMLInputElement>) => setValue(Number(e.target.value))}\n />\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAa,iBAAgC,EAAE,QAAQ,yBAAyB;;AAiBhF,SAAgB,QAAuC,OAAwB;CAC7E,MAAM,EACJ,IACA,KACA,WACA,QACA,OACA,OAAO,WACP,eAAe,IACf,eACA,QAAQ,YACR,GAAG,SACD,cAAc,WAAW,KAAqB;CAClD,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG,UAAU,SAAS;EAAG,GAAG;CAAW;CAC3E,MAAM,CAAC,OAAO,YAAY,cAAc;EACtC,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG;CAC5C,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,KAAK,MAAM;CACjB,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,WAAW,GAAG,iBAAiB,OAAO,WAAW,SAAS;EAC1D,OAAO,EAAE,mBAAmB,GAAG,MAAM,GAAG;EACxC,GAAI;EAHN,UAAA;GAKE,oBAAC,OAAD;IAAK,WAAU;IAAuB,UAAA;GAAW,CAAA;GACjD,oBAAC,OAAD;IAAK,WAAU;IAAwB,UAAA;GAAY,CAAA;GACnD,oBAAC,QAAD;IAAM,WAAU;IAAqB,eAAY;GAAQ,CAAA;GACzD,oBAAC,SAAD;IACM;IACJ,MAAK;IACL,KAAK;IACL,KAAK;IACE;IACP,cAAY,OAAO;IACnB,kBAAgB,GAAG,KAAK,MAAM,KAAK,EAAE;IACrC,WAAU;IACV,WAAW,MAAqC,SAAS,OAAO,EAAE,OAAO,KAAK,CAAC;GAChF,CAAA;EACG;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
@@ -0,0 +1,3 @@
1
+
2
+ import { COMPARE_LABELS, Compare, CompareLabels, CompareProps } from "./Compare.js";
3
+ export { COMPARE_LABELS, Compare, type CompareLabels, type CompareProps, Compare as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { COMPARE_LABELS, Compare, Compare as default } from "./Compare.js";
@@ -0,0 +1,30 @@
1
+
2
+ import { PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { ElementType, ReactNode } from "react";
4
+ export interface ConsentLabels {
5
+ /** Names the banner's region. */
6
+ region: string;
7
+ accept: string;
8
+ reject: string;
9
+ customize: string;
10
+ }
11
+ export declare const CONSENT_LABELS: ConsentLabels;
12
+ export interface ConsentOwnProps {
13
+ /** Shown or not: the app keeps the choice (and decides when to ask again). Default true. */
14
+ open?: boolean;
15
+ title?: ReactNode;
16
+ onAccept?: () => void;
17
+ onReject?: () => void;
18
+ /** Adds a "Personalizza" button, for a settings dialog. */
19
+ onCustomize?: () => void;
20
+ labels?: Partial<ConsentLabels>;
21
+ /** What is asked and why: link the policy here. */
22
+ children?: ReactNode;
23
+ }
24
+ export type ConsentProps<E extends ElementType = 'section'> = PolymorphicProps<E, ConsentOwnProps>;
25
+ /**
26
+ * A consent banner fixed to the bottom of the page. Accepting and rejecting are the same size and weight: refusing
27
+ * is as easy as agreeing. It does not trap focus or block the page; the app stores the answer.
28
+ */
29
+ export declare function Consent<E extends ElementType = 'section'>(props: ConsentProps<E>): import("react").JSX.Element | null;
30
+ //# sourceMappingURL=Consent.d.ts.map
@@ -0,0 +1,70 @@
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 { Button } from "../Button/Button.js";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ // src/Consent/Consent.tsx
9
+ const CONSENT_LABELS = {
10
+ region: "Preferenze sui cookie",
11
+ accept: "Accetta",
12
+ reject: "Rifiuta",
13
+ customize: "Personalizza"
14
+ };
15
+ /**
16
+ * A consent banner fixed to the bottom of the page. Accepting and rejecting are the same size and weight: refusing
17
+ * is as easy as agreeing. It does not trap focus or block the page; the app stores the answer.
18
+ */
19
+ function Consent(props) {
20
+ const { as, css, className, open = true, title, onAccept, onReject, onCustomize, labels: labelsProp, children, ...rest } = useThemeProps("Consent", props);
21
+ const labels = {
22
+ ...CONSENT_LABELS,
23
+ ...useLabels("Consent"),
24
+ ...labelsProp
25
+ };
26
+ const Root = as ?? "section";
27
+ const styled = useCss("Consent", "root", css);
28
+ const root = useAnimationRoot(rest);
29
+ if (!open) return null;
30
+ return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
31
+ "aria-label": labels.region,
32
+ className: cx("slurp-consent", styled.className, className),
33
+ ...root,
34
+ children: [/* @__PURE__ */ jsxs("div", {
35
+ className: "slurp-consent-text",
36
+ children: [title != null && /* @__PURE__ */ jsx("p", {
37
+ className: "slurp-consent-title",
38
+ children: title
39
+ }), children != null && /* @__PURE__ */ jsx("div", {
40
+ className: "slurp-consent-body",
41
+ children
42
+ })]
43
+ }), /* @__PURE__ */ jsxs("div", {
44
+ className: "slurp-consent-actions",
45
+ children: [
46
+ /* @__PURE__ */ jsx(Button, {
47
+ tone: "neutral",
48
+ size: "sm",
49
+ onClick: onReject,
50
+ children: labels.reject
51
+ }),
52
+ onCustomize && /* @__PURE__ */ jsx(Button, {
53
+ tone: "neutral",
54
+ size: "sm",
55
+ onClick: onCustomize,
56
+ children: labels.customize
57
+ }),
58
+ /* @__PURE__ */ jsx(Button, {
59
+ tone: "accent",
60
+ size: "sm",
61
+ onClick: onAccept,
62
+ children: labels.accept
63
+ })
64
+ ]
65
+ })]
66
+ })] });
67
+ }
68
+ export { CONSENT_LABELS, Consent };
69
+
70
+ //# sourceMappingURL=Consent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Consent.js","names":[],"sources":["../../src/Consent/Consent.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType, ReactNode } from 'react';\n\nimport { Button } from '../Button/Button';\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 ConsentLabels {\n /** Names the banner's region. */\n region: string;\n accept: string;\n reject: string;\n customize: string;\n}\n\nexport const CONSENT_LABELS: ConsentLabels = {\n region: 'Preferenze sui cookie',\n accept: 'Accetta',\n reject: 'Rifiuta',\n customize: 'Personalizza',\n};\n\nexport interface ConsentOwnProps {\n /** Shown or not: the app keeps the choice (and decides when to ask again). Default true. */\n open?: boolean;\n title?: ReactNode;\n onAccept?: () => void;\n onReject?: () => void;\n /** Adds a \"Personalizza\" button, for a settings dialog. */\n onCustomize?: () => void;\n labels?: Partial<ConsentLabels>;\n /** What is asked and why: link the policy here. */\n children?: ReactNode;\n}\n\nexport type ConsentProps<E extends ElementType = 'section'> = PolymorphicProps<E, ConsentOwnProps>;\n\n/**\n * A consent banner fixed to the bottom of the page. Accepting and rejecting are the same size and weight: refusing\n * is as easy as agreeing. It does not trap focus or block the page; the app stores the answer.\n */\nexport function Consent<E extends ElementType = 'section'>(props: ConsentProps<E>) {\n const {\n as,\n css,\n className,\n open = true,\n title,\n onAccept,\n onReject,\n onCustomize,\n labels: labelsProp,\n children,\n ...rest\n } = useThemeProps('Consent', props as ConsentProps);\n const labels = { ...CONSENT_LABELS, ...useLabels('Consent'), ...labelsProp };\n const Root = (as ?? 'section') as ElementType;\n const styled = useCss('Consent', 'root', css);\n const root = useAnimationRoot(rest);\n if (!open) return null;\n return (\n <>\n {styled.style}\n <Root\n aria-label={labels.region}\n className={cx('slurp-consent', styled.className, className)}\n {...root}\n >\n <div className=\"slurp-consent-text\">\n {title != null && <p className=\"slurp-consent-title\">{title}</p>}\n {children != null && <div className=\"slurp-consent-body\">{children}</div>}\n </div>\n <div className=\"slurp-consent-actions\">\n <Button tone=\"neutral\" size=\"sm\" onClick={onReject}>\n {labels.reject}\n </Button>\n {onCustomize && (\n <Button tone=\"neutral\" size=\"sm\" onClick={onCustomize}>\n {labels.customize}\n </Button>\n )}\n <Button tone=\"accent\" size=\"sm\" onClick={onAccept}>\n {labels.accept}\n </Button>\n </div>\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;AAiBA,MAAa,iBAAgC;CAC3C,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,WAAW;AACb;;;;;AAqBA,SAAgB,QAA2C,OAAwB;CACjF,MAAM,EACJ,IACA,KACA,WACA,OAAO,MACP,OACA,UACA,UACA,aACA,QAAQ,YACR,UACA,GAAG,SACD,cAAc,WAAW,KAAqB;CAClD,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG,UAAU,SAAS;EAAG,GAAG;CAAW;CAC3E,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG;CAC5C,MAAM,OAAO,iBAAiB,IAAI;CAClC,IAAI,CAAC,MAAM,OAAO;CAClB,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,cAAY,OAAO;EACnB,WAAW,GAAG,iBAAiB,OAAO,WAAW,SAAS;EAC1D,GAAI;EAHN,UAAA,CAKE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,SAAS,QAAQ,oBAAC,KAAD;IAAG,WAAU;IAAuB,UAAA;GAAS,CAAA,GAC9D,YAAY,QAAQ,oBAAC,OAAD;IAAK,WAAU;IAAsB;GAAc,CAAA,CACrE;EACL,CAAA,GAAA,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,oBAAC,QAAD;KAAQ,MAAK;KAAU,MAAK;KAAK,SAAS;KACvC,UAAA,OAAO;IACF,CAAA;IACP,eACC,oBAAC,QAAD;KAAQ,MAAK;KAAU,MAAK;KAAK,SAAS;KACvC,UAAA,OAAO;IACF,CAAA;IAEV,oBAAC,QAAD;KAAQ,MAAK;KAAS,MAAK;KAAK,SAAS;KACtC,UAAA,OAAO;IACF,CAAA;GACL;EACD,CAAA,CAAA;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
@@ -0,0 +1,3 @@
1
+
2
+ import { CONSENT_LABELS, Consent, ConsentLabels, ConsentProps } from "./Consent.js";
3
+ export { CONSENT_LABELS, Consent, type ConsentLabels, type ConsentProps, Consent as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { CONSENT_LABELS, Consent, Consent as default } from "./Consent.js";
@@ -21,6 +21,8 @@ export interface DialogOwnProps extends PartsProps<'header' | 'title' | 'descrip
21
21
  children?: ReactNode;
22
22
  }
23
23
  export type DialogProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, DialogOwnProps>;
24
+ /** The edge a sheet is attached to: `bottom` (default), or the `start` / `end` side (flipped in RTL). */
25
+ export type SheetSide = 'bottom' | 'start' | 'end';
24
26
  /** Modal dialog, centred, opened from a trigger: title, description, content and one primary action. */
25
27
  export declare function Dialog<E extends ElementType = 'dialog'>(props: DialogProps<E>): import("react").JSX.Element;
26
28
  //# sourceMappingURL=Dialog.d.ts.map
@@ -15,7 +15,7 @@ const DIALOG_LABELS = { close: "Chiudi" };
15
15
  const reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
16
16
  /** Shared by Dialog and Sheet: a native modal <dialog> (top layer, focus contained, Escape, inert page). */
17
17
  function useModal(props, variant) {
18
- const { as, css, className, title, description, open: openProp, defaultOpen = false, onOpenChange, actions, dismissible = true, labels: labelsProp, children, parts, partProps, classNames, ref, ...rest } = props;
18
+ const { side = "bottom", as, css, className, title, description, open: openProp, defaultOpen = false, onOpenChange, actions, dismissible = true, labels: labelsProp, children, parts, partProps, classNames, ref, ...rest } = props;
19
19
  const labels = {
20
20
  ...DIALOG_LABELS,
21
21
  ...useLabels("Dialog"),
@@ -53,7 +53,7 @@ function useModal(props, variant) {
53
53
  opener.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
54
54
  if (typeof el.showModal === "function") el.showModal();
55
55
  else el.setAttribute("open", "");
56
- grow(el, opener.current, variant);
56
+ grow(el, opener.current, variant, side);
57
57
  } else if (!open && el.open && !leaving.current) {
58
58
  const close = () => {
59
59
  leaving.current = null;
@@ -62,7 +62,7 @@ function useModal(props, variant) {
62
62
  opener.current?.focus();
63
63
  opener.current = null;
64
64
  };
65
- const exit = shrink(el, opener.current, variant);
65
+ const exit = shrink(el, opener.current, variant, side);
66
66
  if (!exit) return close();
67
67
  leaving.current = exit;
68
68
  exit.finished.then(() => {
@@ -72,7 +72,11 @@ function useModal(props, variant) {
72
72
  }
73
73
  }, () => {});
74
74
  }
75
- }, [open, variant]);
75
+ }, [
76
+ open,
77
+ variant,
78
+ side
79
+ ]);
76
80
  useEffect(() => () => opener.current?.focus(), []);
77
81
  const Root = as ?? "dialog";
78
82
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -81,6 +85,7 @@ function useModal(props, variant) {
81
85
  /* @__PURE__ */ jsx(Root, {
82
86
  className: cx("slurp-dialog", styled.className, className),
83
87
  "data-variant": variant,
88
+ "data-side": variant === "sheet" ? side : void 0,
84
89
  "aria-labelledby": `${id}-title`,
85
90
  "aria-describedby": description != null ? `${id}-description` : void 0,
86
91
  onCancel: (e) => {
@@ -135,6 +140,12 @@ function fromOpener(el, from) {
135
140
  if (!at || !to.width || !to.height || !at.width) return void 0;
136
141
  return `translate(${at.left + at.width / 2 - (to.left + to.width / 2)}px, ${at.top + at.height / 2 - (to.top + to.height / 2)}px) scale(${Math.min(1, Math.max(.5, Math.min(at.width / to.width, at.height / to.height)))})`;
137
142
  }
143
+ /** The transform that puts a sheet fully off its edge. */
144
+ function offscreen(el, side) {
145
+ if (side === "bottom") return "translateY(100%)";
146
+ const rtl = getComputedStyle(el).direction === "rtl";
147
+ return `translateX(${side === "end" !== rtl ? "" : "-"}100%)`;
148
+ }
138
149
  const EASE = ease.settle;
139
150
  /** Milliseconds of a duration token (`'450ms'` → 450). */
140
151
  const ms = (t) => Number.parseFloat(t);
@@ -142,7 +153,7 @@ const ms = (t) => Number.parseFloat(t);
142
153
  * The dialog grows out of the control that opened it (the Bloom rule applied to a modal): it starts at the opener's
143
154
  * place and settles in the centre. A sheet rises from the bottom edge. Reduced motion: a 150ms fade, as the engine.
144
155
  */
145
- function grow(el, from, variant) {
156
+ function grow(el, from, variant, side) {
146
157
  if (typeof el.animate !== "function") return;
147
158
  if (reduced()) {
148
159
  el.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 150 });
@@ -153,7 +164,7 @@ function grow(el, from, variant) {
153
164
  easing: EASE
154
165
  };
155
166
  if (variant === "sheet") {
156
- el.animate([{ transform: "translateY(100%)" }, { transform: "none" }], timing);
167
+ el.animate([{ transform: offscreen(el, side) }, { transform: "none" }], timing);
157
168
  return;
158
169
  }
159
170
  const start = fromOpener(el, from) ?? "scale(0.96)";
@@ -169,7 +180,7 @@ function grow(el, from, variant) {
169
180
  * The way out, quicker than the way in (200ms): back toward the opener, a sheet back down. Returns the animation to
170
181
  * wait for before closing, or nothing when there is nothing to play.
171
182
  */
172
- function shrink(el, to, variant) {
183
+ function shrink(el, to, variant, side) {
173
184
  if (typeof el.animate !== "function") return void 0;
174
185
  const fill = "forwards";
175
186
  if (reduced()) return el.animate([{ opacity: 1 }, { opacity: 0 }], {
@@ -181,7 +192,7 @@ function shrink(el, to, variant) {
181
192
  easing: EASE,
182
193
  fill
183
194
  };
184
- if (variant === "sheet") return el.animate([{ transform: "none" }, { transform: "translateY(100%)" }], timing);
195
+ if (variant === "sheet") return el.animate([{ transform: "none" }, { transform: offscreen(el, side) }], timing);
185
196
  const end = fromOpener(el, to) ?? "scale(0.96)";
186
197
  return el.animate([{
187
198
  transform: "none",
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.js","names":[],"sources":["../../src/Dialog/Dialog.tsx"],"sourcesContent":["import { CloseIcon } from '@slurp-ui/icons';\nimport { duration, ease } from '@slurp-ui/tokens';\nimport { cx } from '@slurp-ui/utils';\nimport {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n type SyntheticEvent,\n} from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { Bubble } from '../Bubble/Bubble';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\nimport { useForkRef } from '../utils/useForkRef';\n\nexport interface DialogLabels {\n /** Name of the close button. */\n close: string;\n}\n\nexport const DIALOG_LABELS: DialogLabels = { close: 'Chiudi' };\n\nexport interface DialogOwnProps extends PartsProps<\n 'header' | 'title' | 'description' | 'body' | 'footer' | 'close'\n> {\n /** The dialog's name (its heading). */\n title: ReactNode;\n description?: ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** Buttons at the bottom (one primary action). */\n actions?: ReactNode;\n /** A press on the backdrop closes it. Default true. */\n dismissible?: boolean;\n labels?: Partial<DialogLabels>;\n children?: ReactNode;\n}\n\nexport type DialogProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, DialogOwnProps>;\n\n/** Where a modal panel comes from: centred dialog, or a sheet from the bottom. */\ntype Variant = 'dialog' | 'sheet';\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/** Shared by Dialog and Sheet: a native modal <dialog> (top layer, focus contained, Escape, inert page). */\nexport function useModal(props: DialogProps, variant: Variant) {\n const {\n as,\n css,\n className,\n title,\n description,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n actions,\n dismissible = true,\n labels: labelsProp,\n children,\n parts,\n partProps,\n classNames,\n ref,\n ...rest\n } = props;\n const labels = { ...DIALOG_LABELS, ...useLabels('Dialog'), ...labelsProp };\n const [open, setOpen] = useControlled({\n value: openProp,\n defaultValue: defaultOpen,\n onChange: onOpenChange,\n });\n const dialog = useRef<HTMLDialogElement>(null);\n const opener = useRef<HTMLElement | null>(null);\n const id = useId();\n const name = variant === 'sheet' ? 'Sheet' : 'Dialog';\n const styled = useCss(name, 'root', css);\n const { part, style } = useParts(name, { parts, partProps, classNames });\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, dialog) });\n\n const leaving = useRef<Animation | null>(null);\n\n useLayoutEffect(() => {\n const el = dialog.current;\n if (!el) return;\n if (open && leaving.current) {\n // Reopened while it was leaving: stop the exit, it is still open.\n leaving.current.cancel();\n leaving.current = null;\n return;\n }\n if (open && !el.open) {\n opener.current =\n document.activeElement instanceof HTMLElement ? document.activeElement : null;\n if (typeof el.showModal === 'function') el.showModal();\n else el.setAttribute('open', '');\n grow(el, opener.current, variant);\n } else if (!open && el.open && !leaving.current) {\n const close = () => {\n leaving.current = null;\n if (typeof el.close === 'function') el.close();\n else el.removeAttribute('open');\n opener.current?.focus();\n opener.current = null;\n };\n const exit = shrink(el, opener.current, variant);\n if (!exit) return close();\n leaving.current = exit;\n exit.finished.then(\n () => {\n if (leaving.current === exit) {\n close();\n exit.cancel();\n }\n },\n () => {\n /* cancelled: reopened */\n },\n );\n }\n }, [open, variant]);\n\n // Unmounting while open: give focus back.\n useEffect(() => () => opener.current?.focus(), []);\n\n const Root = (as ?? 'dialog') as ElementType;\n const element = (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-dialog', styled.className, className)}\n data-variant={variant}\n aria-labelledby={`${id}-title`}\n aria-describedby={description != null ? `${id}-description` : undefined}\n onCancel={(e: SyntheticEvent) => {\n // Escape: the state decides (controlled dialogs stay open until the parent closes them).\n e.preventDefault();\n setOpen(false);\n }}\n onClick={(e: MouseEvent<HTMLDialogElement>) => {\n if (dismissible && e.target === e.currentTarget) setOpen(false);\n }}\n {...root}\n >\n <div className=\"slurp-dialog-inner\">\n {part('header', 'div', {\n className: 'slurp-dialog-header',\n children: (\n <>\n <div className=\"slurp-dialog-heading\">\n {part('title', 'h2', {\n id: `${id}-title`,\n className: 'slurp-dialog-title',\n children: title,\n })}\n {description != null &&\n part('description', 'p', {\n id: `${id}-description`,\n className: 'slurp-dialog-description',\n children: description,\n })}\n </div>\n {part('close', Bubble, {\n className: 'slurp-dialog-close',\n label: labels.close,\n size: 'sm',\n onClick: () => setOpen(false),\n children: <CloseIcon />,\n })}\n </>\n ),\n })}\n {children != null && part('body', 'div', { className: 'slurp-dialog-body', children })}\n {actions != null &&\n part('footer', 'div', { className: 'slurp-dialog-footer', children: actions })}\n </div>\n </Root>\n </>\n );\n return element;\n}\n\n/** Offset and uniform scale that put `el` on its opener's box (uniform, so the text never stretches). */\nfunction fromOpener(el: HTMLElement, from: HTMLElement | null) {\n const to = el.getBoundingClientRect();\n const at = from?.isConnected ? from.getBoundingClientRect() : undefined;\n if (!at || !to.width || !to.height || !at.width) return undefined;\n const dx = at.left + at.width / 2 - (to.left + to.width / 2);\n const dy = at.top + at.height / 2 - (to.top + to.height / 2);\n const s = Math.min(1, Math.max(0.5, Math.min(at.width / to.width, at.height / to.height)));\n return `translate(${dx}px, ${dy}px) scale(${s})`;\n}\n\nconst EASE = ease.settle;\n/** Milliseconds of a duration token (`'450ms'` → 450). */\nconst ms = (t: string) => Number.parseFloat(t);\n\n/**\n * The dialog grows out of the control that opened it (the Bloom rule applied to a modal): it starts at the opener's\n * place and settles in the centre. A sheet rises from the bottom edge. Reduced motion: a 150ms fade, as the engine.\n */\nfunction grow(el: HTMLElement, from: HTMLElement | null, variant: Variant) {\n if (typeof el.animate !== 'function') return;\n if (reduced()) {\n el.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 150 });\n return;\n }\n const timing = { duration: ms(duration.panel), easing: EASE };\n if (variant === 'sheet') {\n el.animate([{ transform: 'translateY(100%)' }, { transform: 'none' }], timing);\n return;\n }\n const start = fromOpener(el, from) ?? 'scale(0.96)';\n el.animate(\n [\n { transform: start, opacity: 0 },\n { transform: 'none', opacity: 1 },\n ],\n timing,\n );\n}\n\n/**\n * The way out, quicker than the way in (200ms): back toward the opener, a sheet back down. Returns the animation to\n * wait for before closing, or nothing when there is nothing to play.\n */\nfunction shrink(el: HTMLElement, to: HTMLElement | null, variant: Variant): Animation | undefined {\n if (typeof el.animate !== 'function') return undefined;\n const fill = 'forwards' as const;\n if (reduced()) return el.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, fill });\n const timing = { duration: ms(duration.quick), easing: EASE, fill };\n if (variant === 'sheet') {\n return el.animate([{ transform: 'none' }, { transform: 'translateY(100%)' }], timing);\n }\n const end = fromOpener(el, to) ?? 'scale(0.96)';\n return el.animate(\n [\n { transform: 'none', opacity: 1 },\n { transform: end, opacity: 0 },\n ],\n timing,\n );\n}\n\n/** Modal dialog, centred, opened from a trigger: title, description, content and one primary action. */\nexport function Dialog<E extends ElementType = 'dialog'>(props: DialogProps<E>) {\n return useModal(useThemeProps('Dialog', props as DialogProps), 'dialog');\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAa,gBAA8B,EAAE,OAAO,SAAS;AAwB7D,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;AAGrF,SAAgB,SAAS,OAAoB,SAAkB;CAC7D,MAAM,EACJ,IACA,KACA,WACA,OACA,aACA,MAAM,UACN,cAAc,OACd,cACA,SACA,cAAc,MACd,QAAQ,YACR,UACA,OACA,WACA,YACA,KACA,GAAG,SACD;CACJ,MAAM,SAAS;EAAE,GAAG;EAAe,GAAG,UAAU,QAAQ;EAAG,GAAG;CAAW;CACzE,MAAM,CAAC,MAAM,WAAW,cAAc;EACpC,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,SAAS,OAA0B,IAAI;CAC7C,MAAM,SAAS,OAA2B,IAAI;CAC9C,MAAM,KAAK,MAAM;CACjB,MAAM,OAAO,YAAY,UAAU,UAAU;CAC7C,MAAM,SAAS,OAAO,MAAM,QAAQ,GAAG;CACvC,MAAM,EAAE,MAAM,UAAU,SAAS,MAAM;EAAE;EAAO;EAAW;CAAW,CAAC;CACvE,MAAM,OAAO,iBAAiB;EAAE,GAAG;EAAM,KAAK,WAAW,KAAc,MAAM;CAAE,CAAC;CAEhF,MAAM,UAAU,OAAyB,IAAI;CAE7C,sBAAsB;EACpB,MAAM,KAAK,OAAO;EAClB,IAAI,CAAC,IAAI;EACT,IAAI,QAAQ,QAAQ,SAAS;GAE3B,QAAQ,QAAQ,OAAO;GACvB,QAAQ,UAAU;GAClB;EACF;EACA,IAAI,QAAQ,CAAC,GAAG,MAAM;GACpB,OAAO,UACL,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AAC,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,UAAU,IAAI,CAAC;EAC9D;CACF;CACA,MAAM,SAAS;EAAE,UAAU,GAAG,SAAS,KAAK;EAAG,QAAQ;CAAK;CAC5D,IAAI,YAAY,SAAS;EACvB,GAAG,QAAQ,CAAC,EAAE,WAAW,mBAAmB,GAAG,EAAE,WAAW,OAAO,CAAC,GAAG,MAAM;EAC7E;CACF;CACA,MAAM,QAAQ,WAAW,IAAI,IAAI,KAAK;CACtC,GAAG,QACD,CACE;EAAE,WAAW;EAAO,SAAS;CAAE,GAC/B;EAAE,WAAW;EAAQ,SAAS;CAAE,CAClC,GACA,MACF;AACF;;;;;AAMA,SAAS,OAAO,IAAiB,IAAwB,SAAyC;CAChG,IAAI,OAAO,GAAG,YAAY,YAAY,OAAO,KAAA;CAC7C,MAAM,OAAO;CACb,IAAI,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,GAAG;EAAE,UAAU;EAAK;CAAK,CAAC;CAC1F,MAAM,SAAS;EAAE,UAAU,GAAG,SAAS,KAAK;EAAG,QAAQ;EAAM;CAAK;CAClE,IAAI,YAAY,SACd,OAAO,GAAG,QAAQ,CAAC,EAAE,WAAW,OAAO,GAAG,EAAE,WAAW,mBAAmB,CAAC,GAAG,MAAM;CAEtF,MAAM,MAAM,WAAW,IAAI,EAAE,KAAK;CAClC,OAAO,GAAG,QACR,CACE;EAAE,WAAW;EAAQ,SAAS;CAAE,GAChC;EAAE,WAAW;EAAK,SAAS;CAAE,CAC/B,GACA,MACF;AACF;;AAGA,SAAgB,OAAyC,OAAuB;CAC9E,OAAO,SAAS,cAAc,UAAU,KAAoB,GAAG,QAAQ;AACzE"}
1
+ {"version":3,"file":"Dialog.js","names":[],"sources":["../../src/Dialog/Dialog.tsx"],"sourcesContent":["import { CloseIcon } from '@slurp-ui/icons';\nimport { duration, ease } from '@slurp-ui/tokens';\nimport { cx } from '@slurp-ui/utils';\nimport {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n type SyntheticEvent,\n} from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { Bubble } from '../Bubble/Bubble';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\nimport { useForkRef } from '../utils/useForkRef';\n\nexport interface DialogLabels {\n /** Name of the close button. */\n close: string;\n}\n\nexport const DIALOG_LABELS: DialogLabels = { close: 'Chiudi' };\n\nexport interface DialogOwnProps extends PartsProps<\n 'header' | 'title' | 'description' | 'body' | 'footer' | 'close'\n> {\n /** The dialog's name (its heading). */\n title: ReactNode;\n description?: ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** Buttons at the bottom (one primary action). */\n actions?: ReactNode;\n /** A press on the backdrop closes it. Default true. */\n dismissible?: boolean;\n labels?: Partial<DialogLabels>;\n children?: ReactNode;\n}\n\nexport type DialogProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, DialogOwnProps>;\n\n/** Where a modal panel comes from: centred dialog, or a sheet from an edge. */\ntype Variant = 'dialog' | 'sheet';\n\n/** The edge a sheet is attached to: `bottom` (default), or the `start` / `end` side (flipped in RTL). */\nexport type SheetSide = 'bottom' | 'start' | 'end';\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/** Shared by Dialog and Sheet: a native modal <dialog> (top layer, focus contained, Escape, inert page). */\nexport function useModal(props: DialogProps & { side?: SheetSide }, variant: Variant) {\n const {\n side = 'bottom',\n as,\n css,\n className,\n title,\n description,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n actions,\n dismissible = true,\n labels: labelsProp,\n children,\n parts,\n partProps,\n classNames,\n ref,\n ...rest\n } = props;\n const labels = { ...DIALOG_LABELS, ...useLabels('Dialog'), ...labelsProp };\n const [open, setOpen] = useControlled({\n value: openProp,\n defaultValue: defaultOpen,\n onChange: onOpenChange,\n });\n const dialog = useRef<HTMLDialogElement>(null);\n const opener = useRef<HTMLElement | null>(null);\n const id = useId();\n const name = variant === 'sheet' ? 'Sheet' : 'Dialog';\n const styled = useCss(name, 'root', css);\n const { part, style } = useParts(name, { parts, partProps, classNames });\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, dialog) });\n\n const leaving = useRef<Animation | null>(null);\n\n useLayoutEffect(() => {\n const el = dialog.current;\n if (!el) return;\n if (open && leaving.current) {\n // Reopened while it was leaving: stop the exit, it is still open.\n leaving.current.cancel();\n leaving.current = null;\n return;\n }\n if (open && !el.open) {\n opener.current =\n document.activeElement instanceof HTMLElement ? document.activeElement : null;\n if (typeof el.showModal === 'function') el.showModal();\n else el.setAttribute('open', '');\n grow(el, opener.current, variant, side);\n } else if (!open && el.open && !leaving.current) {\n const close = () => {\n leaving.current = null;\n if (typeof el.close === 'function') el.close();\n else el.removeAttribute('open');\n opener.current?.focus();\n opener.current = null;\n };\n const exit = shrink(el, opener.current, variant, side);\n if (!exit) return close();\n leaving.current = exit;\n exit.finished.then(\n () => {\n if (leaving.current === exit) {\n close();\n exit.cancel();\n }\n },\n () => {\n /* cancelled: reopened */\n },\n );\n }\n }, [open, variant, side]);\n\n // Unmounting while open: give focus back.\n useEffect(() => () => opener.current?.focus(), []);\n\n const Root = (as ?? 'dialog') as ElementType;\n const element = (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-dialog', styled.className, className)}\n data-variant={variant}\n data-side={variant === 'sheet' ? side : undefined}\n aria-labelledby={`${id}-title`}\n aria-describedby={description != null ? `${id}-description` : undefined}\n onCancel={(e: SyntheticEvent) => {\n // Escape: the state decides (controlled dialogs stay open until the parent closes them).\n e.preventDefault();\n setOpen(false);\n }}\n onClick={(e: MouseEvent<HTMLDialogElement>) => {\n if (dismissible && e.target === e.currentTarget) setOpen(false);\n }}\n {...root}\n >\n <div className=\"slurp-dialog-inner\">\n {part('header', 'div', {\n className: 'slurp-dialog-header',\n children: (\n <>\n <div className=\"slurp-dialog-heading\">\n {part('title', 'h2', {\n id: `${id}-title`,\n className: 'slurp-dialog-title',\n children: title,\n })}\n {description != null &&\n part('description', 'p', {\n id: `${id}-description`,\n className: 'slurp-dialog-description',\n children: description,\n })}\n </div>\n {part('close', Bubble, {\n className: 'slurp-dialog-close',\n label: labels.close,\n size: 'sm',\n onClick: () => setOpen(false),\n children: <CloseIcon />,\n })}\n </>\n ),\n })}\n {children != null && part('body', 'div', { className: 'slurp-dialog-body', children })}\n {actions != null &&\n part('footer', 'div', { className: 'slurp-dialog-footer', children: actions })}\n </div>\n </Root>\n </>\n );\n return element;\n}\n\n/** Offset and uniform scale that put `el` on its opener's box (uniform, so the text never stretches). */\nfunction fromOpener(el: HTMLElement, from: HTMLElement | null) {\n const to = el.getBoundingClientRect();\n const at = from?.isConnected ? from.getBoundingClientRect() : undefined;\n if (!at || !to.width || !to.height || !at.width) return undefined;\n const dx = at.left + at.width / 2 - (to.left + to.width / 2);\n const dy = at.top + at.height / 2 - (to.top + to.height / 2);\n const s = Math.min(1, Math.max(0.5, Math.min(at.width / to.width, at.height / to.height)));\n return `translate(${dx}px, ${dy}px) scale(${s})`;\n}\n\n/** The transform that puts a sheet fully off its edge. */\nfunction offscreen(el: HTMLElement, side: SheetSide) {\n if (side === 'bottom') return 'translateY(100%)';\n const rtl = getComputedStyle(el).direction === 'rtl';\n return `translateX(${(side === 'end') !== rtl ? '' : '-'}100%)`;\n}\n\nconst EASE = ease.settle;\n/** Milliseconds of a duration token (`'450ms'` → 450). */\nconst ms = (t: string) => Number.parseFloat(t);\n\n/**\n * The dialog grows out of the control that opened it (the Bloom rule applied to a modal): it starts at the opener's\n * place and settles in the centre. A sheet rises from the bottom edge. Reduced motion: a 150ms fade, as the engine.\n */\nfunction grow(el: HTMLElement, from: HTMLElement | null, variant: Variant, side: SheetSide) {\n if (typeof el.animate !== 'function') return;\n if (reduced()) {\n el.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 150 });\n return;\n }\n const timing = { duration: ms(duration.panel), easing: EASE };\n if (variant === 'sheet') {\n el.animate([{ transform: offscreen(el, side) }, { transform: 'none' }], timing);\n return;\n }\n const start = fromOpener(el, from) ?? 'scale(0.96)';\n el.animate(\n [\n { transform: start, opacity: 0 },\n { transform: 'none', opacity: 1 },\n ],\n timing,\n );\n}\n\n/**\n * The way out, quicker than the way in (200ms): back toward the opener, a sheet back down. Returns the animation to\n * wait for before closing, or nothing when there is nothing to play.\n */\nfunction shrink(\n el: HTMLElement,\n to: HTMLElement | null,\n variant: Variant,\n side: SheetSide,\n): Animation | undefined {\n if (typeof el.animate !== 'function') return undefined;\n const fill = 'forwards' as const;\n if (reduced()) return el.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, fill });\n const timing = { duration: ms(duration.quick), easing: EASE, fill };\n if (variant === 'sheet') {\n return el.animate([{ transform: 'none' }, { transform: offscreen(el, side) }], timing);\n }\n const end = fromOpener(el, to) ?? 'scale(0.96)';\n return el.animate(\n [\n { transform: 'none', opacity: 1 },\n { transform: end, opacity: 0 },\n ],\n timing,\n );\n}\n\n/** Modal dialog, centred, opened from a trigger: title, description, content and one primary action. */\nexport function Dialog<E extends ElementType = 'dialog'>(props: DialogProps<E>) {\n return useModal(useThemeProps('Dialog', props as DialogProps), 'dialog');\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAa,gBAA8B,EAAE,OAAO,SAAS;AA2B7D,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;AAGrF,SAAgB,SAAS,OAA2C,SAAkB;CACpF,MAAM,EACJ,OAAO,UACP,IACA,KACA,WACA,OACA,aACA,MAAM,UACN,cAAc,OACd,cACA,SACA,cAAc,MACd,QAAQ,YACR,UACA,OACA,WACA,YACA,KACA,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CAAC,GAAG,MAAM;EAC9E;CACF;CACA,MAAM,QAAQ,WAAW,IAAI,IAAI,KAAK;CACtC,GAAG,QACD,CACE;EAAE,WAAW;EAAO,SAAS;CAAE,GAC/B;EAAE,WAAW;EAAQ,SAAS;CAAE,CAClC,GACA,MACF;AACF;;;;;AAMA,SAAS,OACP,IACA,IACA,SACA,MACuB;CACvB,IAAI,OAAO,GAAG,YAAY,YAAY,OAAO,KAAA;CAC7C,MAAM,OAAO;CACb,IAAI,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,GAAG;EAAE,UAAU;EAAK;CAAK,CAAC;CAC1F,MAAM,SAAS;EAAE,UAAU,GAAG,SAAS,KAAK;EAAG,QAAQ;EAAM;CAAK;CAClE,IAAI,YAAY,SACd,OAAO,GAAG,QAAQ,CAAC,EAAE,WAAW,OAAO,GAAG,EAAE,WAAW,UAAU,IAAI,IAAI,EAAE,CAAC,GAAG,MAAM;CAEvF,MAAM,MAAM,WAAW,IAAI,EAAE,KAAK;CAClC,OAAO,GAAG,QACR,CACE;EAAE,WAAW;EAAQ,SAAS;CAAE,GAChC;EAAE,WAAW;EAAK,SAAS;CAAE,CAC/B,GACA,MACF;AACF;;AAGA,SAAgB,OAAyC,OAAuB;CAC9E,OAAO,SAAS,cAAc,UAAU,KAAoB,GAAG,QAAQ;AACzE"}
@@ -0,0 +1,30 @@
1
+
2
+ import { PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { ElementType } from "react";
4
+ export interface LightboxImage {
5
+ src: string;
6
+ alt: string;
7
+ caption?: string;
8
+ }
9
+ export interface LightboxLabels {
10
+ previous: string;
11
+ next: string;
12
+ /** "2 di 5", read when the picture changes. */
13
+ position: (index: number, count: number) => string;
14
+ }
15
+ export declare const LIGHTBOX_LABELS: LightboxLabels;
16
+ export interface LightboxOwnProps {
17
+ images: LightboxImage[];
18
+ open?: boolean;
19
+ defaultOpen?: boolean;
20
+ onOpenChange?: (open: boolean) => void;
21
+ /** The picture shown. */
22
+ index?: number;
23
+ defaultIndex?: number;
24
+ onIndexChange?: (index: number) => void;
25
+ labels?: Partial<LightboxLabels>;
26
+ }
27
+ export type LightboxProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, LightboxOwnProps>;
28
+ /** A picture at full size in a modal (Dialog underneath): arrows or the buttons move through the set, Escape closes. */
29
+ export declare function Lightbox<E extends ElementType = 'dialog'>(props: LightboxProps<E>): import("react").JSX.Element | null;
30
+ //# sourceMappingURL=Lightbox.d.ts.map
@@ -0,0 +1,74 @@
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 { useControlled } from "../utils/useControlled.js";
7
+ import { Dialog } from "../Dialog/Dialog.js";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { ChevronLeftIcon, ChevronRightIcon } from "@slurp-ui/icons";
10
+ // src/Lightbox/Lightbox.tsx
11
+ const LIGHTBOX_LABELS = {
12
+ previous: "Immagine precedente",
13
+ next: "Immagine successiva",
14
+ position: (i, n) => `${i} di ${n}`
15
+ };
16
+ /** A picture at full size in a modal (Dialog underneath): arrows or the buttons move through the set, Escape closes. */
17
+ function Lightbox(props) {
18
+ const { className, images, index: indexProp, defaultIndex = 0, onIndexChange, labels: labelsProp, ...rest } = useThemeProps("Lightbox", props);
19
+ const labels = {
20
+ ...LIGHTBOX_LABELS,
21
+ ...useLabels("Lightbox"),
22
+ ...labelsProp
23
+ };
24
+ const [index, setIndex] = useControlled({
25
+ value: indexProp,
26
+ defaultValue: defaultIndex,
27
+ onChange: onIndexChange
28
+ });
29
+ const n = images.length;
30
+ const at = Math.min(Math.max(index, 0), Math.max(n - 1, 0));
31
+ const image = images[at];
32
+ const go = (step) => setIndex((at + step + n) % n);
33
+ const keys = (e) => {
34
+ if (n < 2) return;
35
+ const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
36
+ if (e.key === "ArrowRight") go(rtl ? -1 : 1);
37
+ else if (e.key === "ArrowLeft") go(rtl ? 1 : -1);
38
+ else return;
39
+ e.preventDefault();
40
+ };
41
+ if (!image) return null;
42
+ return /* @__PURE__ */ jsx(Dialog, {
43
+ ...rest,
44
+ className: cx("slurp-lightbox", className),
45
+ title: image.caption ?? image.alt,
46
+ description: n > 1 ? labels.position(at + 1, n) : void 0,
47
+ onKeyDown: keys,
48
+ children: /* @__PURE__ */ jsxs("div", {
49
+ className: "slurp-lightbox-stage",
50
+ children: [
51
+ n > 1 && /* @__PURE__ */ jsx(Bubble, {
52
+ label: labels.previous,
53
+ onClick: () => go(-1),
54
+ className: "slurp-lightbox-prev",
55
+ children: /* @__PURE__ */ jsx(ChevronLeftIcon, {})
56
+ }),
57
+ /* @__PURE__ */ jsx("img", {
58
+ src: image.src,
59
+ alt: image.alt,
60
+ className: "slurp-lightbox-image"
61
+ }),
62
+ n > 1 && /* @__PURE__ */ jsx(Bubble, {
63
+ label: labels.next,
64
+ onClick: () => go(1),
65
+ className: "slurp-lightbox-next",
66
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, {})
67
+ })
68
+ ]
69
+ })
70
+ });
71
+ }
72
+ export { LIGHTBOX_LABELS, Lightbox };
73
+
74
+ //# sourceMappingURL=Lightbox.js.map