@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Lightbox.js","names":[],"sources":["../../src/Lightbox/Lightbox.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport type { ElementType, KeyboardEvent } from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { Dialog } from '../Dialog/Dialog';\nimport { useLabels } from '../internal/labels';\nimport { useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface LightboxImage {\n src: string;\n alt: string;\n caption?: string;\n}\n\nexport interface LightboxLabels {\n previous: string;\n next: string;\n /** \"2 di 5\", read when the picture changes. */\n position: (index: number, count: number) => string;\n}\n\nexport const LIGHTBOX_LABELS: LightboxLabels = {\n previous: 'Immagine precedente',\n next: 'Immagine successiva',\n position: (i, n) => `${i} di ${n}`,\n};\n\nexport interface LightboxOwnProps {\n images: LightboxImage[];\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** The picture shown. */\n index?: number;\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n labels?: Partial<LightboxLabels>;\n}\n\nexport type LightboxProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, LightboxOwnProps>;\n\n/** A picture at full size in a modal (Dialog underneath): arrows or the buttons move through the set, Escape closes. */\nexport function Lightbox<E extends ElementType = 'dialog'>(props: LightboxProps<E>) {\n const {\n className,\n images,\n index: indexProp,\n defaultIndex = 0,\n onIndexChange,\n labels: labelsProp,\n ...rest\n } = useThemeProps('Lightbox', props as LightboxProps);\n const labels = { ...LIGHTBOX_LABELS, ...useLabels('Lightbox'), ...labelsProp };\n const [index, setIndex] = useControlled({\n value: indexProp,\n defaultValue: defaultIndex,\n onChange: onIndexChange,\n });\n const n = images.length;\n const at = Math.min(Math.max(index, 0), Math.max(n - 1, 0));\n const image = images[at];\n const go = (step: number) => setIndex((at + step + n) % n);\n const keys = (e: KeyboardEvent) => {\n if (n < 2) return;\n const rtl = getComputedStyle(e.currentTarget).direction === 'rtl';\n if (e.key === 'ArrowRight') go(rtl ? -1 : 1);\n else if (e.key === 'ArrowLeft') go(rtl ? 1 : -1);\n else return;\n e.preventDefault();\n };\n if (!image) return null;\n return (\n <Dialog\n {...(rest as object)}\n className={cx('slurp-lightbox', className)}\n title={image.caption ?? image.alt}\n description={n > 1 ? labels.position(at + 1, n) : undefined}\n onKeyDown={keys}\n >\n <div className=\"slurp-lightbox-stage\">\n {n > 1 && (\n <Bubble label={labels.previous} onClick={() => go(-1)} className=\"slurp-lightbox-prev\">\n <ChevronLeftIcon />\n </Bubble>\n )}\n <img src={image.src} alt={image.alt} className=\"slurp-lightbox-image\" />\n {n > 1 && (\n <Bubble label={labels.next} onClick={() => go(1)} className=\"slurp-lightbox-next\">\n <ChevronRightIcon />\n </Bubble>\n )}\n </div>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAa,kBAAkC;CAC7C,UAAU;CACV,MAAM;CACN,WAAW,GAAG,MAAM,GAAG,EAAE,MAAM;AACjC;;AAiBA,SAAgB,SAA2C,OAAyB;CAClF,MAAM,EACJ,WACA,QACA,OAAO,WACP,eAAe,GACf,eACA,QAAQ,YACR,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,CAAC,OAAO,YAAY,cAAc;EACtC,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,IAAI,OAAO;CACjB,MAAM,KAAK,KAAK,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC;CAC1D,MAAM,QAAQ,OAAO;CACrB,MAAM,MAAM,SAAiB,UAAU,KAAK,OAAO,KAAK,CAAC;CACzD,MAAM,QAAQ,MAAqB;EACjC,IAAI,IAAI,GAAG;EACX,MAAM,MAAM,iBAAiB,EAAE,aAAa,CAAC,CAAC,cAAc;EAC5D,IAAI,EAAE,QAAQ,cAAc,GAAG,MAAM,KAAK,CAAC;OACtC,IAAI,EAAE,QAAQ,aAAa,GAAG,MAAM,IAAI,EAAE;OAC1C;EACL,EAAE,eAAe;CACnB;CACA,IAAI,CAAC,OAAO,OAAO;CACnB,OACE,oBAAC,QAAD;EACE,GAAK;EACL,WAAW,GAAG,kBAAkB,SAAS;EACzC,OAAO,MAAM,WAAW,MAAM;EAC9B,aAAa,IAAI,IAAI,OAAO,SAAS,KAAK,GAAG,CAAC,IAAI,KAAA;EAClD,WAAW;EAEX,UAAA,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACG,IAAI,KACH,oBAAC,QAAD;KAAQ,OAAO,OAAO;KAAU,eAAe,GAAG,EAAE;KAAG,WAAU;KAC/D,UAAA,oBAAC,iBAAD,CAAkB,CAAA;IACZ,CAAA;IAEV,oBAAC,OAAD;KAAK,KAAK,MAAM;KAAK,KAAK,MAAM;KAAK,WAAU;IAAwB,CAAA;IACtE,IAAI,KACH,oBAAC,QAAD;KAAQ,OAAO,OAAO;KAAM,eAAe,GAAG,CAAC;KAAG,WAAU;KAC1D,UAAA,oBAAC,kBAAD,CAAmB,CAAA;IACb,CAAA;GAEP;;CACC,CAAA;AAEZ"}
@@ -0,0 +1,3 @@
1
+
2
+ import { LIGHTBOX_LABELS, Lightbox, LightboxImage, LightboxLabels, LightboxProps } from "./Lightbox.js";
3
+ export { LIGHTBOX_LABELS, Lightbox, type LightboxImage, type LightboxLabels, type LightboxProps, Lightbox as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { LIGHTBOX_LABELS, Lightbox, Lightbox as default } from "./Lightbox.js";
@@ -13,11 +13,15 @@ export type MenuProps<E extends ElementType = 'div'> = PolymorphicProps<E, Omit<
13
13
  export declare function Menu<E extends ElementType = 'div'>(props: MenuProps<E>): import("react").JSX.Element;
14
14
  export declare namespace Menu {
15
15
  var Item: typeof MenuItem;
16
+ var Group: typeof MenuGroup;
17
+ var Separator: typeof MenuSeparator;
16
18
  }
17
19
  export interface MenuItemOwnProps {
18
20
  /** Runs the action; the menu closes afterwards (unless the handler calls preventDefault). */
19
21
  onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;
20
22
  icon?: ReactNode;
23
+ /** The key combination that runs it elsewhere, shown at the end (`⌘K`): a hint, not a binding. */
24
+ shortcut?: string;
21
25
  disabled?: boolean;
22
26
  /** `danger` for destructive actions (the text says so too). */
23
27
  tone?: 'neutral' | 'danger';
@@ -26,4 +30,13 @@ export interface MenuItemOwnProps {
26
30
  export type MenuItemProps<E extends ElementType = 'button'> = PolymorphicProps<E, MenuItemOwnProps>;
27
31
  /** One action of a Menu. */
28
32
  export declare function MenuItem<E extends ElementType = 'button'>(props: MenuItemProps<E>): import("react").JSX.Element;
33
+ export interface MenuGroupProps {
34
+ /** Names the group (shown above it and read by screen readers). */
35
+ label: string;
36
+ children?: ReactNode;
37
+ }
38
+ /** A named set of items inside a Menu. */
39
+ export declare function MenuGroup({ label, children }: MenuGroupProps): import("react").JSX.Element;
40
+ /** A line between two sets of items. */
41
+ export declare function MenuSeparator(): import("react").JSX.Element;
29
42
  //# sourceMappingURL=Menu.d.ts.map
package/dist/Menu/Menu.js CHANGED
@@ -3,7 +3,7 @@ import { cx } from "../utils/src/index.js";
3
3
  import { useThemeProps } from "../internal/styled.js";
4
4
  import { moveFocus } from "../utils/focus.js";
5
5
  import { Bloom } from "../Bloom/Bloom.js";
6
- import { createContext, useContext, useRef } from "react";
6
+ import { createContext, useContext, useId, useRef } from "react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  // src/Menu/Menu.tsx
9
9
  const MenuContext = createContext(null);
@@ -32,7 +32,7 @@ function Menu(props) {
32
32
  }
33
33
  /** One action of a Menu. */
34
34
  function MenuItem(props) {
35
- const { as, css: _css, className, onSelect, icon, disabled, tone = "neutral", children, ...rest } = props;
35
+ const { as, css: _css, className, onSelect, icon, shortcut, disabled, tone = "neutral", children, ...rest } = props;
36
36
  const close = useContext(MenuContext);
37
37
  const Root = as ?? "button";
38
38
  return /* @__PURE__ */ jsxs(Root, {
@@ -48,17 +48,49 @@ function MenuItem(props) {
48
48
  if (!e.defaultPrevented) close?.(true);
49
49
  },
50
50
  ...rest,
51
- children: [icon != null && /* @__PURE__ */ jsx("span", {
52
- className: "slurp-bloom-item-icon",
53
- "aria-hidden": "true",
54
- children: icon
55
- }), /* @__PURE__ */ jsx("span", {
56
- className: "slurp-bloom-item-label",
57
- children
58
- })]
51
+ children: [
52
+ icon != null && /* @__PURE__ */ jsx("span", {
53
+ className: "slurp-bloom-item-icon",
54
+ "aria-hidden": "true",
55
+ children: icon
56
+ }),
57
+ /* @__PURE__ */ jsx("span", {
58
+ className: "slurp-bloom-item-label",
59
+ children
60
+ }),
61
+ shortcut != null && /* @__PURE__ */ jsx("kbd", {
62
+ className: "slurp-menu-shortcut",
63
+ "aria-keyshortcuts": shortcut,
64
+ children: shortcut
65
+ })
66
+ ]
67
+ });
68
+ }
69
+ /** A named set of items inside a Menu. */
70
+ function MenuGroup({ label, children }) {
71
+ const id = useId();
72
+ return /* @__PURE__ */ jsxs("div", {
73
+ role: "group",
74
+ "aria-labelledby": id,
75
+ className: "slurp-menu-group",
76
+ children: [/* @__PURE__ */ jsx("div", {
77
+ id,
78
+ className: "slurp-menu-group-label",
79
+ role: "presentation",
80
+ children: label
81
+ }), children]
82
+ });
83
+ }
84
+ /** A line between two sets of items. */
85
+ function MenuSeparator() {
86
+ return /* @__PURE__ */ jsx("div", {
87
+ role: "separator",
88
+ className: "slurp-menu-separator"
59
89
  });
60
90
  }
61
91
  Menu.Item = MenuItem;
62
- export { Menu, MenuItem };
92
+ Menu.Group = MenuGroup;
93
+ Menu.Separator = MenuSeparator;
94
+ export { Menu, MenuGroup, MenuItem, MenuSeparator };
63
95
 
64
96
  //# sourceMappingURL=Menu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.js","names":[],"sources":["../../src/Menu/Menu.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useContext,\n useRef,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { Bloom, type BloomOwnProps } from '../Bloom/Bloom';\nimport { useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { moveFocus } from '../utils/focus';\n\nconst MenuContext = createContext<((restoreFocus?: boolean) => void) | null>(null);\n\nexport type MenuProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n Omit<BloomOwnProps, 'role' | 'children'> & {\n /** MenuItem elements (other content, like a heading, is allowed too). */\n children?: ReactNode;\n }\n>;\n\n/**\n * A list of actions on Bloom: the trigger becomes the menu. Arrow keys move (looping), Home / End go to the ends,\n * Enter or Space run the item, which closes the menu and gives focus back to the trigger.\n */\nexport function Menu<E extends ElementType = 'div'>(props: MenuProps<E>) {\n const { children, width = 260, className, ...rest } = useThemeProps('Menu', props as MenuProps);\n const list = useRef<HTMLDivElement>(null);\n return (\n <Bloom {...rest} role=\"menu\" width={width} className={cx('slurp-menu', className)}>\n {(close) => (\n <MenuContext value={close}>\n <div\n ref={list}\n className=\"slurp-menu-list\"\n onKeyDown={(e) => moveFocus(e, list.current, '[role=\"menuitem\"]', { loop: true })}\n >\n {children}\n </div>\n </MenuContext>\n )}\n </Bloom>\n );\n}\n\nexport interface MenuItemOwnProps {\n /** Runs the action; the menu closes afterwards (unless the handler calls preventDefault). */\n onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;\n icon?: ReactNode;\n disabled?: boolean;\n /** `danger` for destructive actions (the text says so too). */\n tone?: 'neutral' | 'danger';\n children?: ReactNode;\n}\n\nexport type MenuItemProps<E extends ElementType = 'button'> = PolymorphicProps<E, MenuItemOwnProps>;\n\n/** One action of a Menu. */\nexport function MenuItem<E extends ElementType = 'button'>(props: MenuItemProps<E>) {\n const {\n as,\n css: _css,\n className,\n onSelect,\n icon,\n disabled,\n tone = 'neutral',\n children,\n ...rest\n } = props as MenuItemProps;\n const close = useContext(MenuContext);\n const Root = (as ?? 'button') as ElementType;\n return (\n <Root\n role=\"menuitem\"\n tabIndex={-1}\n className={cx('slurp-bloom-item', className)}\n aria-disabled={disabled || undefined}\n data-tone={tone}\n {...(Root === 'button' ? { type: 'button' } : null)}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n if (disabled) return;\n onSelect?.(e);\n if (!e.defaultPrevented) close?.(true);\n }}\n {...rest}\n >\n {icon != null && (\n <span className=\"slurp-bloom-item-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n <span className=\"slurp-bloom-item-label\">{children}</span>\n </Root>\n );\n}\n\nMenu.Item = MenuItem;\n"],"mappings":";;;;;;;;AAeA,MAAM,cAAc,cAAyD,IAAI;;;;;AAcjF,SAAgB,KAAoC,OAAqB;CACvE,MAAM,EAAE,UAAU,QAAQ,KAAK,WAAW,GAAG,SAAS,cAAc,QAAQ,KAAkB;CAC9F,MAAM,OAAO,OAAuB,IAAI;CACxC,OACE,oBAAC,OAAD;EAAO,GAAI;EAAM,MAAK;EAAc;EAAO,WAAW,GAAG,cAAc,SAAS;EAC5E,WAAA,UACA,oBAAC,aAAD;GAAa,OAAO;GAClB,UAAA,oBAAC,OAAD;IACE,KAAK;IACL,WAAU;IACV,YAAY,MAAM,UAAU,GAAG,KAAK,SAAS,uBAAqB,EAAE,MAAM,KAAK,CAAC;IAE/E;GACE,CAAA;EACM,CAAA;CAEV,CAAA;AAEX;;AAeA,SAAgB,SAA2C,OAAyB;CAClF,MAAM,EACJ,IACA,KAAK,MACL,WACA,UACA,MACA,UACA,OAAO,WACP,UACA,GAAG,SACD;CACJ,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,OAAQ,MAAM;CACpB,OACE,qBAAC,MAAD;EACE,MAAK;EACL,UAAU;EACV,WAAW,GAAG,oBAAoB,SAAS;EAC3C,iBAAe,YAAY,KAAA;EAC3B,aAAW;EACX,GAAK,SAAS,WAAW,EAAE,MAAM,SAAS,IAAI;EAC9C,UAAU,MAAqC;GAC7C,IAAI,UAAU;GACd,WAAW,CAAC;GACZ,IAAI,CAAC,EAAE,kBAAkB,QAAQ,IAAI;EACvC;EACA,GAAI;EAZN,UAAA,CAcG,QAAQ,QACP,oBAAC,QAAD;GAAM,WAAU;GAAwB,eAAY;GACjD,UAAA;EACG,CAAA,GAER,oBAAC,QAAD;GAAM,WAAU;GAA0B;EAAe,CAAA,CACrD;;AAEV;AAEA,KAAK,OAAO"}
1
+ {"version":3,"file":"Menu.js","names":[],"sources":["../../src/Menu/Menu.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useContext,\n useId,\n useRef,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { Bloom, type BloomOwnProps } from '../Bloom/Bloom';\nimport { useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { moveFocus } from '../utils/focus';\n\nconst MenuContext = createContext<((restoreFocus?: boolean) => void) | null>(null);\n\nexport type MenuProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n Omit<BloomOwnProps, 'role' | 'children'> & {\n /** MenuItem elements (other content, like a heading, is allowed too). */\n children?: ReactNode;\n }\n>;\n\n/**\n * A list of actions on Bloom: the trigger becomes the menu. Arrow keys move (looping), Home / End go to the ends,\n * Enter or Space run the item, which closes the menu and gives focus back to the trigger.\n */\nexport function Menu<E extends ElementType = 'div'>(props: MenuProps<E>) {\n const { children, width = 260, className, ...rest } = useThemeProps('Menu', props as MenuProps);\n const list = useRef<HTMLDivElement>(null);\n return (\n <Bloom {...rest} role=\"menu\" width={width} className={cx('slurp-menu', className)}>\n {(close) => (\n <MenuContext value={close}>\n <div\n ref={list}\n className=\"slurp-menu-list\"\n onKeyDown={(e) => moveFocus(e, list.current, '[role=\"menuitem\"]', { loop: true })}\n >\n {children}\n </div>\n </MenuContext>\n )}\n </Bloom>\n );\n}\n\nexport interface MenuItemOwnProps {\n /** Runs the action; the menu closes afterwards (unless the handler calls preventDefault). */\n onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;\n icon?: ReactNode;\n /** The key combination that runs it elsewhere, shown at the end (`⌘K`): a hint, not a binding. */\n shortcut?: string;\n disabled?: boolean;\n /** `danger` for destructive actions (the text says so too). */\n tone?: 'neutral' | 'danger';\n children?: ReactNode;\n}\n\nexport type MenuItemProps<E extends ElementType = 'button'> = PolymorphicProps<E, MenuItemOwnProps>;\n\n/** One action of a Menu. */\nexport function MenuItem<E extends ElementType = 'button'>(props: MenuItemProps<E>) {\n const {\n as,\n css: _css,\n className,\n onSelect,\n icon,\n shortcut,\n disabled,\n tone = 'neutral',\n children,\n ...rest\n } = props as MenuItemProps;\n const close = useContext(MenuContext);\n const Root = (as ?? 'button') as ElementType;\n return (\n <Root\n role=\"menuitem\"\n tabIndex={-1}\n className={cx('slurp-bloom-item', className)}\n aria-disabled={disabled || undefined}\n data-tone={tone}\n {...(Root === 'button' ? { type: 'button' } : null)}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n if (disabled) return;\n onSelect?.(e);\n if (!e.defaultPrevented) close?.(true);\n }}\n {...rest}\n >\n {icon != null && (\n <span className=\"slurp-bloom-item-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n <span className=\"slurp-bloom-item-label\">{children}</span>\n {shortcut != null && (\n <kbd className=\"slurp-menu-shortcut\" aria-keyshortcuts={shortcut}>\n {shortcut}\n </kbd>\n )}\n </Root>\n );\n}\n\nexport interface MenuGroupProps {\n /** Names the group (shown above it and read by screen readers). */\n label: string;\n children?: ReactNode;\n}\n\n/** A named set of items inside a Menu. */\nexport function MenuGroup({ label, children }: MenuGroupProps) {\n const id = useId();\n return (\n <div role=\"group\" aria-labelledby={id} className=\"slurp-menu-group\">\n <div id={id} className=\"slurp-menu-group-label\" role=\"presentation\">\n {label}\n </div>\n {children}\n </div>\n );\n}\n\n/** A line between two sets of items. */\nexport function MenuSeparator() {\n return <div role=\"separator\" className=\"slurp-menu-separator\" />;\n}\n\nMenu.Item = MenuItem;\nMenu.Group = MenuGroup;\nMenu.Separator = MenuSeparator;\n"],"mappings":";;;;;;;;AAgBA,MAAM,cAAc,cAAyD,IAAI;;;;;AAcjF,SAAgB,KAAoC,OAAqB;CACvE,MAAM,EAAE,UAAU,QAAQ,KAAK,WAAW,GAAG,SAAS,cAAc,QAAQ,KAAkB;CAC9F,MAAM,OAAO,OAAuB,IAAI;CACxC,OACE,oBAAC,OAAD;EAAO,GAAI;EAAM,MAAK;EAAc;EAAO,W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CAAA;AACjE;AAEA,KAAK,OAAO;AACZ,KAAK,QAAQ;AACb,KAAK,YAAY"}
@@ -1,3 +1,3 @@
1
1
 
2
- import { Menu, MenuItem, MenuItemProps, MenuProps } from "./Menu.js";
3
- export { Menu, MenuItem, type MenuItemProps, type MenuProps, Menu as default };
2
+ import { Menu, MenuGroup, MenuGroupProps, MenuItem, MenuItemProps, MenuProps, MenuSeparator } from "./Menu.js";
3
+ export { Menu, MenuGroup, type MenuGroupProps, MenuItem, type MenuItemProps, type MenuProps, MenuSeparator, Menu as default };
@@ -1,2 +1,2 @@
1
1
 
2
- export { Menu, MenuItem, Menu as default } from "./Menu.js";
2
+ export { Menu, MenuGroup, MenuItem, MenuSeparator, Menu as default } from "./Menu.js";
@@ -0,0 +1,39 @@
1
+
2
+ import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { InputAttributes } from "../Field/Field.js";
4
+ import { SuggestOption } from "../Suggest/Suggest.js";
5
+ import { ElementType, ReactNode } from "react";
6
+ export interface MultiSuggestLabels {
7
+ /** Number of suggestions, announced politely while typing. */
8
+ results: (count: number) => string;
9
+ /** Shown in the list, and announced, when nothing matches. */
10
+ empty: string;
11
+ /** Names the button that removes a chosen option: `remove('Rosso')`. */
12
+ remove: (label: string) => string;
13
+ /** Names the list of chosen options. */
14
+ chosen: string;
15
+ }
16
+ export declare const MULTI_SUGGEST_LABELS: MultiSuggestLabels;
17
+ export interface MultiSuggestOwnProps<V extends string = string> extends Omit<InputAttributes, 'type'>, PartsProps<'label' | 'control' | 'list' | 'option' | 'tags' | 'tag' | 'hint' | 'error'> {
18
+ label: ReactNode;
19
+ hint?: ReactNode;
20
+ /** Error message: marks the field invalid. */
21
+ error?: ReactNode;
22
+ options: SuggestOption<V>[];
23
+ /** The chosen values, in the order they were chosen. */
24
+ value?: V[];
25
+ defaultValue?: V[];
26
+ onValueChange?: (value: V[]) => void;
27
+ /** Which options match the text (default: every word, any order, ignoring case and accents). */
28
+ filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;
29
+ /** Most suggestions listed. Default 8. */
30
+ limit?: number;
31
+ labels?: Partial<MultiSuggestLabels>;
32
+ }
33
+ export type MultiSuggestProps<V extends string = string, E extends ElementType = 'div'> = PolymorphicProps<E, MultiSuggestOwnProps<V>>;
34
+ /**
35
+ * Suggest for several choices: the list stays open while you pick, each pick becomes a removable tag under the field,
36
+ * Backspace in an empty field removes the last one. Submits one hidden input per value when it has a `name`.
37
+ */
38
+ export declare function MultiSuggest<V extends string = string, E extends ElementType = 'div'>(props: MultiSuggestProps<V, E>): import("react").JSX.Element;
39
+ //# sourceMappingURL=MultiSuggest.d.ts.map
@@ -0,0 +1,267 @@
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, useParts, useThemeProps } from "../internal/styled.js";
6
+ import { useControlled } from "../utils/useControlled.js";
7
+ import { splitInputProps } from "../Field/Field.js";
8
+ import { useDismiss } from "../utils/useDismiss.js";
9
+ import { matchesAll } from "../lib/layout.js";
10
+ import { Mark } from "../Mark/Mark.js";
11
+ import { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
12
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
+ import { CheckIcon, CloseIcon, ErrorIcon } from "@slurp-ui/icons";
14
+ // src/MultiSuggest/MultiSuggest.tsx
15
+ const MULTI_SUGGEST_LABELS = {
16
+ results: (n) => n === 1 ? "1 suggerimento" : `${n} suggerimenti`,
17
+ empty: "Nessun suggerimento",
18
+ remove: (label) => `Rimuovi ${label}`,
19
+ chosen: "Scelte"
20
+ };
21
+ const matches = (o, text) => matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);
22
+ /**
23
+ * Suggest for several choices: the list stays open while you pick, each pick becomes a removable tag under the field,
24
+ * Backspace in an empty field removes the last one. Submits one hidden input per value when it has a `name`.
25
+ */
26
+ function MultiSuggest(props) {
27
+ const { as, css, className, label, hint, error, options, value: valueProp, defaultValue = [], onValueChange, filter, limit = 8, labels: labelsProp, parts, partProps, classNames, ...others } = useThemeProps("MultiSuggest", props);
28
+ const labels = {
29
+ ...MULTI_SUGGEST_LABELS,
30
+ ...useLabels("MultiSuggest"),
31
+ ...labelsProp
32
+ };
33
+ const { input, root: rest } = splitInputProps(others);
34
+ const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input;
35
+ const [value, setValue] = useControlled({
36
+ value: valueProp,
37
+ defaultValue,
38
+ onChange: onValueChange
39
+ });
40
+ const [text, setText] = useState("");
41
+ const [open, setOpen] = useState(false);
42
+ const [active, setActive] = useState(-1);
43
+ const box = useRef(null);
44
+ const id = useId();
45
+ const inputId = `${id}-input`;
46
+ const listId = `${id}-list`;
47
+ const hintId = hint != null ? `${id}-hint` : void 0;
48
+ const errorId = error != null && error !== false ? `${id}-error` : void 0;
49
+ const Root = as ?? "div";
50
+ const styled = useCss("MultiSuggest", "root", css);
51
+ const { part, style } = useParts("MultiSuggest", {
52
+ parts,
53
+ partProps,
54
+ classNames
55
+ });
56
+ const root = useAnimationRoot(rest);
57
+ const query = text.trim();
58
+ const found = useMemo(() => {
59
+ return (filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query))).slice(0, Math.max(0, limit));
60
+ }, [
61
+ options,
62
+ filter,
63
+ query,
64
+ limit
65
+ ]);
66
+ const close = () => {
67
+ setOpen(false);
68
+ setActive(-1);
69
+ };
70
+ const dismiss = useDismiss({
71
+ ref: box,
72
+ open,
73
+ onDismiss: close
74
+ });
75
+ useEffect(() => {
76
+ if (open && active >= 0) document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: "nearest" });
77
+ }, [
78
+ open,
79
+ active,
80
+ listId
81
+ ]);
82
+ const next = (from, step) => {
83
+ const n = found.length;
84
+ for (let k = 1; k <= n; k++) {
85
+ const i = ((from + step * k) % n + n) % n;
86
+ if (!found[i]?.disabled) return i;
87
+ }
88
+ return -1;
89
+ };
90
+ const toggle = (o) => {
91
+ if (o.disabled) return;
92
+ setValue(value.includes(o.value) ? value.filter((v) => v !== o.value) : [...value, o.value]);
93
+ setText("");
94
+ };
95
+ const remove = (v) => {
96
+ setValue(value.filter((x) => x !== v));
97
+ document.getElementById(inputId)?.focus();
98
+ };
99
+ const keys = (e) => {
100
+ onKeyDown?.(e);
101
+ if (e.defaultPrevented) return;
102
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
103
+ e.preventDefault();
104
+ const step = e.key === "ArrowDown" ? 1 : -1;
105
+ if (!open) {
106
+ setOpen(true);
107
+ setActive(next(step === 1 ? -1 : 0, step));
108
+ } else setActive(next(active < 0 && step === -1 ? 0 : active, step));
109
+ } else if (e.key === "Enter" && open && active >= 0) {
110
+ e.preventDefault();
111
+ const o = found[active];
112
+ if (o) toggle(o);
113
+ } else if (e.key === "Escape" && open) {
114
+ e.preventDefault();
115
+ e.stopPropagation();
116
+ close();
117
+ } else if (e.key === "Backspace" && !text && value.length) setValue(value.slice(0, -1));
118
+ };
119
+ const showing = open && !disabled;
120
+ const status = showing && query ? found.length ? labels.results(found.length) : labels.empty : "";
121
+ const byValue = new Map(options.map((o) => [o.value, o]));
122
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
123
+ styled.style,
124
+ style,
125
+ /* @__PURE__ */ jsxs(Root, {
126
+ className: cx("slurp-suggest slurp-multisuggest", styled.className, className),
127
+ "data-open": showing ? "" : void 0,
128
+ "data-invalid": errorId ? "" : void 0,
129
+ "data-disabled": disabled ? "" : void 0,
130
+ ...root,
131
+ children: [
132
+ part("label", "label", {
133
+ id: `${id}-label`,
134
+ htmlFor: inputId,
135
+ className: "slurp-suggest-label",
136
+ children: label
137
+ }),
138
+ /* @__PURE__ */ jsx("div", {
139
+ ref: box,
140
+ className: "slurp-suggest-box",
141
+ onBlur: dismiss.containerProps.onBlur,
142
+ children: /* @__PURE__ */ jsxs("div", {
143
+ className: "slurp-suggest-surface",
144
+ children: [part("control", "input", {
145
+ ...inputRest,
146
+ id: inputId,
147
+ type: "text",
148
+ role: "combobox",
149
+ className: "slurp-suggest-control",
150
+ disabled,
151
+ autoComplete: inputRest.autoComplete ?? "off",
152
+ "aria-expanded": showing,
153
+ "aria-controls": listId,
154
+ "aria-autocomplete": "list",
155
+ "aria-activedescendant": showing && active >= 0 ? `${listId}-${active}` : void 0,
156
+ "aria-invalid": errorId ? true : void 0,
157
+ "aria-describedby": cx(errorId, hintId) || void 0,
158
+ value: text,
159
+ onChange: (e) => {
160
+ setText(e.target.value);
161
+ setOpen(true);
162
+ setActive(-1);
163
+ },
164
+ onKeyDown: keys,
165
+ onFocus,
166
+ onBlur,
167
+ onClick: () => {
168
+ if (!open) setOpen(true);
169
+ }
170
+ }), /* @__PURE__ */ jsx("div", {
171
+ className: "slurp-suggest-clip",
172
+ children: found.length > 0 ? part("list", "ul", {
173
+ id: listId,
174
+ role: "listbox",
175
+ "aria-multiselectable": true,
176
+ "aria-labelledby": `${id}-label`,
177
+ className: "slurp-suggest-list",
178
+ children: found.map((o, i) => {
179
+ const on = value.includes(o.value);
180
+ return /* @__PURE__ */ jsx(Fragment, { children: part("option", "li", {
181
+ id: `${listId}-${i}`,
182
+ role: "option",
183
+ className: "slurp-suggest-option",
184
+ "aria-selected": on,
185
+ "aria-disabled": o.disabled || void 0,
186
+ "data-active": showing && i === active ? "" : void 0,
187
+ "data-chosen": on ? "" : void 0,
188
+ onMouseDown: (e) => e.preventDefault(),
189
+ onPointerMove: () => {
190
+ if (!o.disabled && i !== active) setActive(i);
191
+ },
192
+ onClick: () => toggle(o),
193
+ children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
194
+ className: "slurp-suggest-option-text",
195
+ children: [/* @__PURE__ */ jsx("span", {
196
+ className: "slurp-suggest-option-label",
197
+ children: /* @__PURE__ */ jsx(Mark, {
198
+ text: o.label,
199
+ query
200
+ })
201
+ }), o.description && /* @__PURE__ */ jsx("span", {
202
+ className: "slurp-suggest-option-description",
203
+ children: /* @__PURE__ */ jsx(Mark, {
204
+ text: o.description,
205
+ query
206
+ })
207
+ })]
208
+ }), on && /* @__PURE__ */ jsx("span", {
209
+ className: "slurp-suggest-option-check",
210
+ "aria-hidden": "true",
211
+ children: /* @__PURE__ */ jsx(CheckIcon, { size: 18 })
212
+ })] })
213
+ }) }, o.value);
214
+ })
215
+ }) : /* @__PURE__ */ jsx("p", {
216
+ id: listId,
217
+ className: "slurp-suggest-empty",
218
+ children: labels.empty
219
+ })
220
+ })]
221
+ })
222
+ }),
223
+ value.length > 0 && part("tags", "ul", {
224
+ "aria-label": labels.chosen,
225
+ className: "slurp-multisuggest-tags",
226
+ children: value.map((v) => {
227
+ const text = byValue.get(v)?.label ?? v;
228
+ return /* @__PURE__ */ jsx("li", { children: part("tag", "button", {
229
+ type: "button",
230
+ className: "slurp-multisuggest-tag",
231
+ disabled,
232
+ "aria-label": labels.remove(text),
233
+ onClick: () => remove(v),
234
+ children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", { children: text }), /* @__PURE__ */ jsx(CloseIcon, {
235
+ size: 14,
236
+ "aria-hidden": "true"
237
+ })] })
238
+ }) }, v);
239
+ })
240
+ }),
241
+ hintId && part("hint", "p", {
242
+ id: hintId,
243
+ className: "slurp-suggest-hint",
244
+ children: hint
245
+ }),
246
+ errorId && part("error", "p", {
247
+ id: errorId,
248
+ className: "slurp-suggest-error",
249
+ children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ErrorIcon, { size: 16 }), /* @__PURE__ */ jsx("span", { children: error })] })
250
+ }),
251
+ /* @__PURE__ */ jsx("span", {
252
+ className: "slurp-visually-hidden",
253
+ role: "status",
254
+ children: status
255
+ }),
256
+ name && value.map((v) => /* @__PURE__ */ jsx("input", {
257
+ type: "hidden",
258
+ name,
259
+ value: v
260
+ }, v))
261
+ ]
262
+ })
263
+ ] });
264
+ }
265
+ export { MULTI_SUGGEST_LABELS, MultiSuggest };
266
+
267
+ //# sourceMappingURL=MultiSuggest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultiSuggest.js","names":[],"sources":["../../src/MultiSuggest/MultiSuggest.tsx"],"sourcesContent":["import { CheckIcon, CloseIcon, ErrorIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Fragment,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type ElementType,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { splitInputProps, type InputAttributes } from '../Field/Field';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { matchesAll } from '../lib/layout';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { Mark } from '../Mark/Mark';\nimport type { SuggestOption } from '../Suggest/Suggest';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\n\nexport interface MultiSuggestLabels {\n /** Number of suggestions, announced politely while typing. */\n results: (count: number) => string;\n /** Shown in the list, and announced, when nothing matches. */\n empty: string;\n /** Names the button that removes a chosen option: `remove('Rosso')`. */\n remove: (label: string) => string;\n /** Names the list of chosen options. */\n chosen: string;\n}\n\nexport const MULTI_SUGGEST_LABELS: MultiSuggestLabels = {\n results: (n) => (n === 1 ? '1 suggerimento' : `${n} suggerimenti`),\n empty: 'Nessun suggerimento',\n remove: (label) => `Rimuovi ${label}`,\n chosen: 'Scelte',\n};\n\nexport interface MultiSuggestOwnProps<V extends string = string>\n extends\n Omit<InputAttributes, 'type'>,\n PartsProps<'label' | 'control' | 'list' | 'option' | 'tags' | 'tag' | 'hint' | 'error'> {\n label: ReactNode;\n hint?: ReactNode;\n /** Error message: marks the field invalid. */\n error?: ReactNode;\n options: SuggestOption<V>[];\n /** The chosen values, in the order they were chosen. */\n value?: V[];\n defaultValue?: V[];\n onValueChange?: (value: V[]) => void;\n /** Which options match the text (default: every word, any order, ignoring case and accents). */\n filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;\n /** Most suggestions listed. Default 8. */\n limit?: number;\n labels?: Partial<MultiSuggestLabels>;\n}\n\nexport type MultiSuggestProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, MultiSuggestOwnProps<V>>;\n\nconst matches = (o: SuggestOption, text: string) =>\n matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);\n\n/**\n * Suggest for several choices: the list stays open while you pick, each pick becomes a removable tag under the field,\n * Backspace in an empty field removes the last one. Submits one hidden input per value when it has a `name`.\n */\nexport function MultiSuggest<V extends string = string, E extends ElementType = 'div'>(\n props: MultiSuggestProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n hint,\n error,\n options,\n value: valueProp,\n defaultValue = [],\n onValueChange,\n filter,\n limit = 8,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('MultiSuggest', props as unknown as MultiSuggestProps);\n const labels = { ...MULTI_SUGGEST_LABELS, ...useLabels('MultiSuggest'), ...labelsProp };\n const { input, root: rest } = splitInputProps(others);\n const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input as InputAttributes;\n const [value, setValue] = useControlled<string[]>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string[]) => void) | undefined,\n });\n const [text, setText] = useState('');\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const box = useRef<HTMLDivElement>(null);\n const id = useId();\n const inputId = `${id}-input`;\n const listId = `${id}-list`;\n const hintId = hint != null ? `${id}-hint` : undefined;\n const errorId = error != null && error !== false ? `${id}-error` : undefined;\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('MultiSuggest', 'root', css);\n const { part, style } = useParts('MultiSuggest', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const query = text.trim();\n const found = useMemo(() => {\n const all =\n filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query));\n return all.slice(0, Math.max(0, limit));\n }, [options, filter, query, limit]);\n\n const close = () => {\n setOpen(false);\n setActive(-1);\n };\n const dismiss = useDismiss({ ref: box, open, onDismiss: close });\n\n useEffect(() => {\n if (open && active >= 0)\n document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: 'nearest' });\n }, [open, active, listId]);\n\n const next = (from: number, step: 1 | -1) => {\n const n = found.length;\n for (let k = 1; k <= n; k++) {\n const i = (((from + step * k) % n) + n) % n;\n if (!found[i]?.disabled) return i;\n }\n return -1;\n };\n\n const toggle = (o: SuggestOption) => {\n if (o.disabled) return;\n setValue(value.includes(o.value) ? value.filter((v) => v !== o.value) : [...value, o.value]);\n setText('');\n };\n const remove = (v: string) => {\n setValue(value.filter((x) => x !== v));\n document.getElementById(inputId)?.focus();\n };\n\n const keys = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n const step = e.key === 'ArrowDown' ? 1 : -1;\n if (!open) {\n setOpen(true);\n setActive(next(step === 1 ? -1 : 0, step));\n } else setActive(next(active < 0 && step === -1 ? 0 : active, step));\n } else if (e.key === 'Enter' && open && active >= 0) {\n e.preventDefault();\n const o = found[active];\n if (o) toggle(o);\n } else if (e.key === 'Escape' && open) {\n e.preventDefault();\n e.stopPropagation();\n close();\n } else if (e.key === 'Backspace' && !text && value.length) {\n setValue(value.slice(0, -1));\n }\n };\n\n const showing = open && !disabled;\n const status =\n showing && query ? (found.length ? labels.results(found.length) : labels.empty) : '';\n const byValue = new Map(options.map((o) => [o.value as string, o]));\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-suggest slurp-multisuggest', styled.className, className)}\n data-open={showing ? '' : undefined}\n data-invalid={errorId ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('label', 'label', {\n id: `${id}-label`,\n htmlFor: inputId,\n className: 'slurp-suggest-label',\n children: label,\n })}\n <div ref={box} className=\"slurp-suggest-box\" onBlur={dismiss.containerProps.onBlur}>\n <div className=\"slurp-suggest-surface\">\n {part('control', 'input', {\n ...inputRest,\n id: inputId,\n type: 'text',\n role: 'combobox',\n className: 'slurp-suggest-control',\n disabled,\n autoComplete: inputRest.autoComplete ?? 'off',\n 'aria-expanded': showing,\n 'aria-controls': listId,\n 'aria-autocomplete': 'list',\n 'aria-activedescendant': showing && active >= 0 ? `${listId}-${active}` : undefined,\n 'aria-invalid': errorId ? true : undefined,\n 'aria-describedby': cx(errorId, hintId) || undefined,\n value: text,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n setText(e.target.value);\n setOpen(true);\n setActive(-1);\n },\n onKeyDown: keys,\n onFocus,\n onBlur,\n onClick: () => {\n if (!open) setOpen(true);\n },\n })}\n <div className=\"slurp-suggest-clip\">\n {found.length > 0 ? (\n part('list', 'ul', {\n id: listId,\n role: 'listbox',\n 'aria-multiselectable': true,\n 'aria-labelledby': `${id}-label`,\n className: 'slurp-suggest-list',\n children: found.map((o, i) => {\n const on = value.includes(o.value);\n return (\n <Fragment key={o.value}>\n {part('option', 'li', {\n id: `${listId}-${i}`,\n role: 'option',\n className: 'slurp-suggest-option',\n 'aria-selected': on,\n 'aria-disabled': o.disabled || undefined,\n 'data-active': showing && i === active ? '' : undefined,\n 'data-chosen': on ? '' : undefined,\n onMouseDown: (e: MouseEvent) => e.preventDefault(),\n onPointerMove: () => {\n if (!o.disabled && i !== active) setActive(i);\n },\n onClick: () => toggle(o),\n children: (\n <>\n <span className=\"slurp-suggest-option-text\">\n <span className=\"slurp-suggest-option-label\">\n <Mark text={o.label} query={query} />\n </span>\n {o.description && (\n <span className=\"slurp-suggest-option-description\">\n <Mark text={o.description} query={query} />\n </span>\n )}\n </span>\n {on && (\n <span className=\"slurp-suggest-option-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </>\n ),\n })}\n </Fragment>\n );\n }),\n })\n ) : (\n <p id={listId} className=\"slurp-suggest-empty\">\n {labels.empty}\n </p>\n )}\n </div>\n </div>\n </div>\n {value.length > 0 &&\n part('tags', 'ul', {\n 'aria-label': labels.chosen,\n className: 'slurp-multisuggest-tags',\n children: value.map((v) => {\n const text = byValue.get(v)?.label ?? v;\n return (\n <li key={v}>\n {part('tag', 'button', {\n type: 'button',\n className: 'slurp-multisuggest-tag',\n disabled,\n 'aria-label': labels.remove(text),\n onClick: () => remove(v),\n children: (\n <>\n <span>{text}</span>\n <CloseIcon size={14} aria-hidden=\"true\" />\n </>\n ),\n })}\n </li>\n );\n }),\n })}\n {hintId &&\n part('hint', 'p', { id: hintId, className: 'slurp-suggest-hint', children: hint })}\n {errorId &&\n part('error', 'p', {\n id: errorId,\n className: 'slurp-suggest-error',\n children: (\n <>\n <ErrorIcon size={16} />\n <span>{error}</span>\n </>\n ),\n })}\n <span className=\"slurp-visually-hidden\" role=\"status\">\n {status}\n </span>\n {name && value.map((v) => <input key={v} type=\"hidden\" name={name} value={v} />)}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAsCA,MAAa,uBAA2C;CACtD,UAAU,MAAO,MAAM,IAAI,mBAAmB,GAAG,EAAE;CACnD,OAAO;CACP,SAAS,UAAU,WAAW;CAC9B,QAAQ;AACV;AA2BA,MAAM,WAAW,GAAkB,SACjC,WAAW,EAAE,cAAc,GAAG,EAAE,MAAM,GAAG,EAAE,gBAAgB,EAAE,OAAO,IAAI;;;;;AAM1E,SAAgB,aACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,MACA,OACA,SACA,OAAO,WACP,eAAe,CAAC,GAChB,eACA,QACA,QAAQ,GACR,QAAQ,YACR,OACA,WACA,YACA,GAAG,WACD,cAAc,gBAAgB,KAAqC;CACvE,MAAM,SAAS;EAAE,GAAG;EAAsB,GAAG,UAAU,cAAc;EAAG,GAAG;CAAW;CACtF,MAAM,EAAE,OAAO,MAAM,SAAS,gBA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,IAAI,CAAC,CAAC,EAAE,SAAS;MACtC,OACE,oBAAC,MAAD,EAAA,UACG,KAAK,OAAO,UAAU;OACrB,MAAM;OACN,WAAW;OACX;OACA,cAAc,OAAO,OAAO,IAAI;OAChC,eAAe,OAAO,CAAC;OACvB,UACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,KAAW,CAAA,GAClB,oBAAC,WAAD;QAAW,MAAM;QAAI,eAAY;OAAQ,CAAA,CACzC,EAAA,CAAA;MAEN,CAAC,EACC,GAdK,CAcL;KAER,CAAC;IACH,CAAC;IACF,UACC,KAAK,QAAQ,KAAK;KAAE,IAAI;KAAQ,WAAW;KAAsB,UAAU;IAAK,CAAC;IAClF,WACC,KAAK,SAAS,KAAK;KACjB,IAAI;KACJ,WAAW;KACX,UACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,GACtB,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA,CACnB,EAAA,CAAA;IAEN,CAAC;IACH,oBAAC,QAAD;KAAM,WAAU;KAAwB,MAAK;KAC1C,UAAA;IACG,CAAA;IACL,QAAQ,MAAM,KAAK,MAAM,oBAAC,SAAD;KAAe,MAAK;KAAe;KAAM,OAAO;IAAI,GAAxC,CAAwC,CAAC;GAC3E;;CACN,EAAA,CAAA;AAEN"}
@@ -0,0 +1,3 @@
1
+
2
+ import { MULTI_SUGGEST_LABELS, MultiSuggest, MultiSuggestLabels, MultiSuggestProps } from "./MultiSuggest.js";
3
+ export { MULTI_SUGGEST_LABELS, MultiSuggest, type MultiSuggestLabels, type MultiSuggestProps, MultiSuggest as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { MULTI_SUGGEST_LABELS, MultiSuggest, MultiSuggest as default } from "./MultiSuggest.js";
@@ -0,0 +1,16 @@
1
+
2
+ import { PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { ElementType } from "react";
4
+ export interface RevealOwnProps {
5
+ /** The sentence: plain text, at least two lines at 680px. The line breaks are chosen by the browser. */
6
+ children: string;
7
+ }
8
+ export type RevealProps<E extends ElementType = 'p'> = PolymorphicProps<E, RevealOwnProps>;
9
+ /**
10
+ * A large sentence whose words go from the secondary colour to the full one, one at a time, as they cross a line at
11
+ * 65% of the viewport height while the page scrolls. Colour only: nothing moves. Once lit a word stays lit; at the
12
+ * end of the page whatever is still dim lights up, so no word stays dim for good. Reduced motion, no script and no
13
+ * `IntersectionObserver`: the sentence is simply lit.
14
+ */
15
+ export declare function Reveal<E extends ElementType = 'p'>(props: RevealProps<E>): import("react").JSX.Element;
16
+ //# sourceMappingURL=Reveal.d.ts.map
@@ -0,0 +1,77 @@
1
+ "use client";
2
+ import { cx } from "../utils/src/index.js";
3
+ import { useForkRef } from "../utils/useForkRef.js";
4
+ import { useAnimationRoot } from "../internal/animation.js";
5
+ import { useCss, useThemeProps } from "../internal/styled.js";
6
+ import { Fragment, useEffect, useRef } from "react";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
+ // src/Reveal/Reveal.tsx
9
+ /** Milliseconds between words that light up together, and the most the whole batch waits. */
10
+ const STEP = 30;
11
+ const CAP = 400;
12
+ /**
13
+ * A large sentence whose words go from the secondary colour to the full one, one at a time, as they cross a line at
14
+ * 65% of the viewport height while the page scrolls. Colour only: nothing moves. Once lit a word stays lit; at the
15
+ * end of the page whatever is still dim lights up, so no word stays dim for good. Reduced motion, no script and no
16
+ * `IntersectionObserver`: the sentence is simply lit.
17
+ */
18
+ function Reveal(props) {
19
+ const { as, css, className, children, ref, ...rest } = useThemeProps("Reveal", props);
20
+ const Root = as ?? "p";
21
+ const styled = useCss("Reveal", "root", css);
22
+ const own = useRef(null);
23
+ const root = useAnimationRoot({
24
+ ...rest,
25
+ ref: useForkRef(ref, own)
26
+ });
27
+ useEffect(() => {
28
+ const el = own.current;
29
+ if (!el || typeof IntersectionObserver === "undefined") return;
30
+ if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) return;
31
+ const words = [...el.querySelectorAll(".slurp-reveal-word")];
32
+ const dim = () => words.filter((w) => !w.hasAttribute("data-lit"));
33
+ const light = (list) => list.forEach((w, i) => {
34
+ w.style.transitionDelay = `${Math.min(i * STEP, CAP)}ms`;
35
+ w.setAttribute("data-lit", "");
36
+ });
37
+ el.setAttribute("data-armed", "");
38
+ const crossed = new IntersectionObserver((entries) => {
39
+ const batch = entries.filter((e) => e.isIntersecting || e.rootBounds != null && e.boundingClientRect.top < e.rootBounds.top).map((e) => e.target).sort((a, b) => words.indexOf(a) - words.indexOf(b));
40
+ light(batch);
41
+ batch.forEach((w) => crossed.unobserve(w));
42
+ }, { rootMargin: "0px 0px -35% 0px" });
43
+ words.forEach((w) => crossed.observe(w));
44
+ let frame = 0;
45
+ const atEnd = () => {
46
+ frame = 0;
47
+ const doc = document.documentElement;
48
+ if (window.scrollY + window.innerHeight >= doc.scrollHeight - 2) light(dim());
49
+ };
50
+ const onScroll = () => {
51
+ if (!frame && dim().length) frame = requestAnimationFrame(atEnd);
52
+ };
53
+ window.addEventListener("scroll", onScroll, { passive: true });
54
+ onScroll();
55
+ return () => {
56
+ crossed.disconnect();
57
+ window.removeEventListener("scroll", onScroll);
58
+ if (frame) cancelAnimationFrame(frame);
59
+ el.removeAttribute("data-armed");
60
+ words.forEach((w) => {
61
+ w.removeAttribute("data-lit");
62
+ w.style.transitionDelay = "";
63
+ });
64
+ };
65
+ }, [children]);
66
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsx(Root, {
67
+ className: cx("slurp-reveal", styled.className, className),
68
+ ...root,
69
+ children: children.split(" ").map((word, i) => /* @__PURE__ */ jsxs(Fragment, { children: [i > 0 && " ", /* @__PURE__ */ jsx("span", {
70
+ className: "slurp-reveal-word",
71
+ children: word
72
+ })] }, i))
73
+ })] });
74
+ }
75
+ export { Reveal };
76
+
77
+ //# sourceMappingURL=Reveal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Reveal.js","names":[],"sources":["../../src/Reveal/Reveal.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport { Fragment, useEffect, useRef, type ElementType } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { useForkRef } from '../utils/useForkRef';\n\nexport interface RevealOwnProps {\n /** The sentence: plain text, at least two lines at 680px. The line breaks are chosen by the browser. */\n children: string;\n}\n\nexport type RevealProps<E extends ElementType = 'p'> = PolymorphicProps<E, RevealOwnProps>;\n\n/** Milliseconds between words that light up together, and the most the whole batch waits. */\nconst STEP = 30;\nconst CAP = 400;\n\n/**\n * A large sentence whose words go from the secondary colour to the full one, one at a time, as they cross a line at\n * 65% of the viewport height while the page scrolls. Colour only: nothing moves. Once lit a word stays lit; at the\n * end of the page whatever is still dim lights up, so no word stays dim for good. Reduced motion, no script and no\n * `IntersectionObserver`: the sentence is simply lit.\n */\nexport function Reveal<E extends ElementType = 'p'>(props: RevealProps<E>) {\n const { as, css, className, children, ref, ...rest } = useThemeProps(\n 'Reveal',\n props as RevealProps,\n );\n const Root = (as ?? 'p') as ElementType;\n const styled = useCss('Reveal', 'root', css);\n const own = useRef<HTMLElement>(null);\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, own as never) });\n\n useEffect(() => {\n const el = own.current;\n if (!el || typeof IntersectionObserver === 'undefined') return;\n if (typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches)\n return;\n const words = [...el.querySelectorAll<HTMLElement>('.slurp-reveal-word')];\n const dim = () => words.filter((w) => !w.hasAttribute('data-lit'));\n const light = (list: HTMLElement[]) =>\n list.forEach((w, i) => {\n w.style.transitionDelay = `${Math.min(i * STEP, CAP)}ms`;\n w.setAttribute('data-lit', '');\n });\n el.setAttribute('data-armed', '');\n\n const crossed = new IntersectionObserver(\n (entries) => {\n const batch = entries\n .filter(\n (e) =>\n e.isIntersecting ||\n (e.rootBounds != null && e.boundingClientRect.top < e.rootBounds.top),\n )\n .map((e) => e.target as HTMLElement)\n .sort((a, b) => words.indexOf(a) - words.indexOf(b));\n light(batch);\n batch.forEach((w) => crossed.unobserve(w));\n },\n { rootMargin: '0px 0px -35% 0px' },\n );\n words.forEach((w) => crossed.observe(w));\n\n // The page cannot scroll further: whatever is still dim lights up (checked once per frame, only while dim).\n let frame = 0;\n const atEnd = () => {\n frame = 0;\n const doc = document.documentElement;\n if (window.scrollY + window.innerHeight >= doc.scrollHeight - 2) light(dim());\n };\n const onScroll = () => {\n if (!frame && dim().length) frame = requestAnimationFrame(atEnd);\n };\n window.addEventListener('scroll', onScroll, { passive: true });\n onScroll();\n\n return () => {\n crossed.disconnect();\n window.removeEventListener('scroll', onScroll);\n if (frame) cancelAnimationFrame(frame);\n el.removeAttribute('data-armed');\n words.forEach((w) => {\n w.removeAttribute('data-lit');\n w.style.transitionDelay = '';\n });\n };\n }, [children]);\n\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-reveal', styled.className, className)} {...root}>\n {children.split(' ').map((word, i) => (\n <Fragment key={i}>\n {i > 0 && ' '}\n <span className=\"slurp-reveal-word\">{word}</span>\n </Fragment>\n ))}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAgBA,MAAM,OAAO;AACb,MAAM,MAAM;;;;;;;AAQZ,SAAgB,OAAoC,OAAuB;CACzE,MAAM,EAAE,IAAI,KAAK,WAAW,UAAU,KAAK,GAAG,SAAS,cACrD,UACA,KACF;CACA,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,UAAU,QAAQ,GAAG;CAC3C,MAAM,MAAM,OAAoB,IAAI;CACpC,MAAM,OAAO,iBAAiB;EAAE,GAAG;EAAM,KAAK,WAAW,KAAc,GAAY;CAAE,CAAC;CAEtF,gBAAgB;EACd,MAAM,KAAK,IAAI;EACf,IAAI,CAAC,MAAM,OAAO,yBAAyB,aAAa;EACxD,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