@slurp-ui/react 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/Bloom/Bloom.js +3 -2
  3. package/dist/Bloom/Bloom.js.map +1 -1
  4. package/dist/Calendar/Calendar.d.ts +42 -0
  5. package/dist/Calendar/Calendar.js +178 -0
  6. package/dist/Calendar/Calendar.js.map +1 -0
  7. package/dist/Calendar/dates.d.ts +3 -0
  8. package/dist/Calendar/dates.js +46 -0
  9. package/dist/Calendar/dates.js.map +1 -0
  10. package/dist/Calendar/index.d.ts +3 -0
  11. package/dist/Calendar/index.js +2 -0
  12. package/dist/Card/Card.d.ts +1 -1
  13. package/dist/Card/Card.js.map +1 -1
  14. package/dist/Carousel/Carousel.js +2 -0
  15. package/dist/Carousel/Carousel.js.map +1 -1
  16. package/dist/Choice/Choice.js +2 -0
  17. package/dist/Choice/Choice.js.map +1 -1
  18. package/dist/Code/Code.d.ts +38 -0
  19. package/dist/Code/Code.js +82 -0
  20. package/dist/Code/Code.js.map +1 -0
  21. package/dist/Code/index.d.ts +3 -0
  22. package/dist/Code/index.js +2 -0
  23. package/dist/Contents/Contents.d.ts +35 -0
  24. package/dist/Contents/Contents.js +63 -0
  25. package/dist/Contents/Contents.js.map +1 -0
  26. package/dist/Contents/index.d.ts +3 -0
  27. package/dist/Contents/index.js +2 -0
  28. package/dist/DateField/DateField.d.ts +29 -0
  29. package/dist/DateField/DateField.js +118 -0
  30. package/dist/DateField/DateField.js.map +1 -0
  31. package/dist/DateField/index.d.ts +3 -0
  32. package/dist/DateField/index.js +2 -0
  33. package/dist/Dialog/Dialog.js +73 -25
  34. package/dist/Dialog/Dialog.js.map +1 -1
  35. package/dist/Dock/Dock.d.ts +6 -1
  36. package/dist/Dock/Dock.js +13 -2
  37. package/dist/Dock/Dock.js.map +1 -1
  38. package/dist/ErrorSummary/ErrorSummary.d.ts +26 -0
  39. package/dist/ErrorSummary/ErrorSummary.js +68 -0
  40. package/dist/ErrorSummary/ErrorSummary.js.map +1 -0
  41. package/dist/ErrorSummary/index.d.ts +3 -0
  42. package/dist/ErrorSummary/index.js +2 -0
  43. package/dist/FileDrop/FileDrop.d.ts +34 -0
  44. package/dist/FileDrop/FileDrop.js +145 -0
  45. package/dist/FileDrop/FileDrop.js.map +1 -0
  46. package/dist/FileDrop/index.d.ts +3 -0
  47. package/dist/FileDrop/index.js +2 -0
  48. package/dist/Filters/Filters.js +2 -0
  49. package/dist/Filters/Filters.js.map +1 -1
  50. package/dist/Footer/Footer.d.ts +37 -0
  51. package/dist/Footer/Footer.js +63 -0
  52. package/dist/Footer/Footer.js.map +1 -0
  53. package/dist/Footer/index.d.ts +3 -0
  54. package/dist/Footer/index.js +2 -0
  55. package/dist/Hairline/Hairline.d.ts +16 -0
  56. package/dist/Hairline/Hairline.js +23 -0
  57. package/dist/Hairline/Hairline.js.map +1 -0
  58. package/dist/Hairline/index.d.ts +3 -0
  59. package/dist/Hairline/index.js +2 -0
  60. package/dist/Hint/Hint.js +20 -1
  61. package/dist/Hint/Hint.js.map +1 -1
  62. package/dist/Kbd/Kbd.d.ts +7 -0
  63. package/dist/Kbd/Kbd.js +20 -0
  64. package/dist/Kbd/Kbd.js.map +1 -0
  65. package/dist/Kbd/index.d.ts +3 -0
  66. package/dist/Kbd/index.js +2 -0
  67. package/dist/ListRow/ListRow.d.ts +6 -2
  68. package/dist/ListRow/ListRow.js +5 -1
  69. package/dist/ListRow/ListRow.js.map +1 -1
  70. package/dist/Media/Media.d.ts +28 -0
  71. package/dist/Media/Media.js +65 -0
  72. package/dist/Media/Media.js.map +1 -0
  73. package/dist/Media/index.d.ts +3 -0
  74. package/dist/Media/index.js +2 -0
  75. package/dist/Notice/Notice.js +2 -0
  76. package/dist/Notice/Notice.js.map +1 -1
  77. package/dist/NumberField/NumberField.d.ts +32 -0
  78. package/dist/NumberField/NumberField.js +126 -0
  79. package/dist/NumberField/NumberField.js.map +1 -0
  80. package/dist/NumberField/index.d.ts +3 -0
  81. package/dist/NumberField/index.js +2 -0
  82. package/dist/PageNav/PageNav.d.ts +25 -0
  83. package/dist/PageNav/PageNav.js +57 -0
  84. package/dist/PageNav/PageNav.js.map +1 -0
  85. package/dist/PageNav/index.d.ts +3 -0
  86. package/dist/PageNav/index.js +2 -0
  87. package/dist/Pages/Pages.js +2 -0
  88. package/dist/Pages/Pages.js.map +1 -1
  89. package/dist/PinField/PinField.d.ts +26 -0
  90. package/dist/PinField/PinField.js +73 -0
  91. package/dist/PinField/PinField.js.map +1 -0
  92. package/dist/PinField/index.d.ts +3 -0
  93. package/dist/PinField/index.js +2 -0
  94. package/dist/Prose/Prose.d.ts +15 -0
  95. package/dist/Prose/Prose.js +25 -0
  96. package/dist/Prose/Prose.js.map +1 -0
  97. package/dist/Prose/index.d.ts +3 -0
  98. package/dist/Prose/index.js +2 -0
  99. package/dist/Quote/Quote.d.ts +19 -0
  100. package/dist/Quote/Quote.js +52 -0
  101. package/dist/Quote/Quote.js.map +1 -0
  102. package/dist/Quote/index.d.ts +3 -0
  103. package/dist/Quote/index.js +2 -0
  104. package/dist/Rail/Rail.d.ts +37 -0
  105. package/dist/Rail/Rail.js +61 -0
  106. package/dist/Rail/Rail.js.map +1 -0
  107. package/dist/Rail/index.d.ts +3 -0
  108. package/dist/Rail/index.js +2 -0
  109. package/dist/Range/Range.d.ts +1 -1
  110. package/dist/Range/Range.js.map +1 -1
  111. package/dist/Rating/Rating.js +2 -0
  112. package/dist/Rating/Rating.js.map +1 -1
  113. package/dist/Search/Search.d.ts +1 -1
  114. package/dist/Search/Search.js +2 -0
  115. package/dist/Search/Search.js.map +1 -1
  116. package/dist/SecretField/SecretField.d.ts +17 -0
  117. package/dist/SecretField/SecretField.js +59 -0
  118. package/dist/SecretField/SecretField.js.map +1 -0
  119. package/dist/SecretField/index.d.ts +3 -0
  120. package/dist/SecretField/index.js +2 -0
  121. package/dist/Settings/Settings.js +2 -0
  122. package/dist/Settings/Settings.js.map +1 -1
  123. package/dist/SkipLink/SkipLink.d.ts +22 -0
  124. package/dist/SkipLink/SkipLink.js +32 -0
  125. package/dist/SkipLink/SkipLink.js.map +1 -0
  126. package/dist/SkipLink/index.d.ts +3 -0
  127. package/dist/SkipLink/index.js +2 -0
  128. package/dist/SlurpProvider/SlurpProvider.d.ts +7 -1
  129. package/dist/SlurpProvider/SlurpProvider.js +14 -6
  130. package/dist/SlurpProvider/SlurpProvider.js.map +1 -1
  131. package/dist/Steps/Steps.js +2 -0
  132. package/dist/Steps/Steps.js.map +1 -1
  133. package/dist/Suggest/Suggest.js +2 -0
  134. package/dist/Suggest/Suggest.js.map +1 -1
  135. package/dist/Table/Table.js +2 -0
  136. package/dist/Table/Table.js.map +1 -1
  137. package/dist/Tag/Tag.d.ts +14 -0
  138. package/dist/Tag/Tag.js +26 -0
  139. package/dist/Tag/Tag.js.map +1 -0
  140. package/dist/Tag/index.d.ts +3 -0
  141. package/dist/Tag/index.js +2 -0
  142. package/dist/Toast/Toast.js +31 -7
  143. package/dist/Toast/Toast.js.map +1 -1
  144. package/dist/index.d.ts +45 -4
  145. package/dist/index.js +23 -1
  146. package/dist/internal/labels.js +12 -0
  147. package/dist/internal/labels.js.map +1 -0
  148. package/dist/lib/labels.d.ts +175 -0
  149. package/dist/lib/labels.js +116 -0
  150. package/dist/lib/labels.js.map +1 -0
  151. package/dist/lib/theme.d.ts +98 -3
  152. package/dist/lib/theme.js.map +1 -1
  153. package/dist/styles.css +1435 -127
  154. package/dist/tokens.css +10 -0
  155. package/dist/utils/focus.d.ts +1 -1
  156. package/dist/utils/focus.js +2 -2
  157. package/dist/utils/focus.js.map +1 -1
  158. package/dist/utils/index.d.ts +3 -1
  159. package/dist/utils/index.js +3 -1
  160. package/dist/utils/useClipboard.d.ts +14 -0
  161. package/dist/utils/useClipboard.js +30 -0
  162. package/dist/utils/useClipboard.js.map +1 -0
  163. package/dist/utils/useScrollSpy.d.ts +14 -0
  164. package/dist/utils/useScrollSpy.js +27 -0
  165. package/dist/utils/useScrollSpy.js.map +1 -0
  166. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # @slurp-ui/react
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f6b705d: New components for content and navigation, for any site:
8
+
9
+ - `Prose`: typography for long text that arrives as HTML (Markdown, MDX, a CMS), on the design system's scale.
10
+ - `Code`: a code block with an optional file name and a copy button that confirms; takes plain text or HTML from any highlighter (`--slurp-code-*` colours, shiki variables mapped).
11
+ - `Contents`: "on this page" links that follow the section being read.
12
+ - `Rail` (`Rail.Group`, `Rail.Link`): vertical navigation in groups for wide screens, the current page highlighted.
13
+ - `PageNav`: previous and next page at the end of a sequence, with your router's link.
14
+ - `SkipLink`: "skip to content", visible on keyboard focus.
15
+ - `Hairline`: a 1px separator, decorative by default.
16
+ - Hooks `useClipboard` and `useScrollSpy`. English texts for the new components in `labelsEn`.
17
+
18
+ - feeffe9: New components: `Calendar` and `DateField` (a day or a period, in the theme's language), `NumberField`, `SecretField`, `PinField`, `FileDrop`, `ErrorSummary`, `Media`, `Footer`, `Tag`, `Quote` and `Kbd`. English texts in `labelsEn`. A panel element marked `data-autofocus` takes focus first when a Bloom opens.
19
+ - a5cdf08: Texts in other languages and components that hold up in narrow spaces:
20
+
21
+ - `SlurpProvider` takes `labels`: `'en'` switches every component's texts to English, `'it'` keeps the Italian defaults, or pass your own texts by component (`{ Dialog: { close: 'Dismiss' } }`). The string presets can be passed from a server component. A component's own `labels` prop still wins. `labelsEn` and `labelsIt` are exported to build on.
22
+ - Dock: on phones, a bar with only the search shows it as a pill with its placeholder instead of a lone round icon (`Dock.Action` takes `text`).
23
+ - Steps: below 480px of its own width (not only on phones) the other steps keep only their marker, so labels never collide in a narrow card.
24
+ - Tile: long titles break with a hyphen where the page language allows it, instead of anywhere.
25
+
26
+ - b3a055b: - `ListRow` with `href` and no `actionLabel` is a link as a whole: its title becomes the link and covers the row (one target, one focus stop, no extra "Open" button). A router link goes in `parts={{ link: … }}`.
27
+ - `Code`: the scrollable block is a named group instead of a region, so a page with many code blocks keeps unique landmarks.
28
+ - Dock: the phone search pill's accessible name includes its visible placeholder (WCAG 2.5.3).
29
+
30
+ ### Patch Changes
31
+
32
+ - 6557e10: Finish the motion of panels and notifications:
33
+
34
+ - Dialog and Sheet now play their way out (200ms: back toward the control that opened them, a sheet back down) before closing; reopening during the exit keeps them open. Dialog grows from its opener with a uniform scale, so its text no longer stretches. Reduced motion: a 150ms fade in and out.
35
+ - Toast leaves with a short exit and the stack closes the gap instead of jumping; its entrance is now a transition, so a toast dismissed while it appears turns back from where it is.
36
+ - Hint: after one hint closes, the next one within 300ms shows at once and without its entrance, so moving along a row of icons only waits once.
37
+ - Reduced motion keeps colour, opacity and shadow transitions in every component and drops only movement and size changes.
38
+
39
+ - fc030e1: Take every transition curve and duration from the new motion tokens (`--slurp-ease-settle`, `--slurp-duration-*`), in the stylesheets and in Dialog and Bloom. Timings are unchanged except where they snap to the scale (for example 0.3s → 350ms, 0.4s and 0.5s → 450ms, 0.7s → 600ms).
40
+ - Updated dependencies [f6b705d]
41
+ - Updated dependencies [fc030e1]
42
+ - @slurp-ui/icons@1.2.0
43
+ - @slurp-ui/tokens@1.2.0
44
+
45
+ ## 1.1.1
46
+
47
+ ### Patch Changes
48
+
49
+ - 75167a1: Use context-neutral examples in the props documentation (no prices or product names).
50
+ - 239f077: Fix motion on touch screens and on narrow Docks:
51
+
52
+ - Button, Chip, Tile, Card and Rating lift, grow or tilt on hover only with a fine pointer (`(hover: hover) and (pointer: fine)`), so they no longer stay raised after a tap. Colour changes on hover are unchanged.
53
+ - Button, Tile and Card press in 120ms and release more softly (240ms for Button and Chip, 300ms for Tile and Card) instead of using one slow transition both ways.
54
+ - On phones, Dock crumbs before the current one shrink first (to a 44px target), so the current page keeps its name instead of collapsing to a letter.
55
+
56
+ - Updated dependencies [f3d9909]
57
+ - @slurp-ui/tokens@1.1.0
58
+
3
59
  ## 1.1.0
4
60
 
5
61
  ### Minor Changes
@@ -7,10 +7,11 @@ import { useControlled } from "../utils/useControlled.js";
7
7
  import { focusFirst } from "../utils/focus.js";
8
8
  import { useDismiss } from "../utils/useDismiss.js";
9
9
  import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
10
+ import { duration } from "@slurp-ui/tokens";
10
11
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
12
  // src/Bloom/Bloom.tsx
12
- /** The Dock's motion: 0.6s, cubic-bezier(0.2, 0.8, 0.2, 1). */
13
- const DURATION = 600;
13
+ /** The Dock's motion: the surface duration (600ms) on the settle curve, as in Bloom.css. */
14
+ const DURATION = Number.parseFloat(duration.surface);
14
15
  const VIEWPORT_MARGIN = 16;
15
16
  const reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
16
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Bloom.js","names":[],"sources":["../../src/Bloom/Bloom.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { focusFirst } from '../utils/focus';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\nimport { useForkRef } from '../utils/useForkRef';\n\nexport type BloomPlacement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';\n\nexport interface BloomOwnProps extends PartsProps<'surface' | 'trigger' | 'panel'> {\n /** Content of the trigger button (text, icon, both). */\n trigger: ReactNode;\n /**\n * Name of the trigger when it shows only an icon. An icon trigger stays in its corner when open, 44px and inset by\n * space-2 like the Dock's actions; the panel's first row (its title) sits beside it.\n */\n label?: string;\n /** Trigger content while open (an icon trigger usually becomes a close icon). */\n openTrigger?: ReactNode;\n /** Name of an icon trigger while open (\"Chiudi impostazioni\"). */\n closeLabel?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * Corner the surface grows from: `bottom-start` (default) grows right and down. It flips by itself when the panel\n * would leave the viewport.\n */\n placement?: BloomPlacement;\n /** Open width in px (never wider than the viewport minus 32px). Default 300. */\n width?: number;\n /** Role of the panel: a non-modal `dialog` (default), a `menu` or a `listbox`. */\n role?: 'dialog' | 'menu' | 'listbox';\n /** Name of the panel; default the trigger. */\n panelLabel?: string;\n disabled?: boolean;\n /** The panel. A function gets `close(restoreFocus = true)`. */\n children?: ReactNode | ((close: (restoreFocus?: boolean) => void) => ReactNode);\n}\n\nexport type BloomProps<E extends ElementType = 'div'> = PolymorphicProps<E, BloomOwnProps>;\n\n/** The Dock's motion: 0.6s, cubic-bezier(0.2, 0.8, 0.2, 1). */\nconst DURATION = 600;\nconst VIEWPORT_MARGIN = 16;\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/**\n * The design system's rule for floating panels: **the button becomes the panel**. One surface grows from the trigger\n * (width, height through grid rows, radius) and shrinks back into it. Closes on a press outside, Escape or Tab out;\n * opening moves focus into the panel; Escape gives it back to the trigger.\n */\nexport function Bloom<E extends ElementType = 'div'>(props: BloomProps<E>) {\n const {\n as,\n css,\n className,\n trigger: triggerContent,\n label,\n openTrigger,\n closeLabel,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n placement = 'bottom-start',\n width = 300,\n role = 'dialog',\n panelLabel,\n disabled,\n children,\n style,\n parts,\n partProps,\n classNames,\n ref,\n ...rest\n } = useThemeProps('Bloom', props as BloomProps);\n const [open, setOpen] = useControlled({\n value: openProp,\n defaultValue: defaultOpen,\n onChange: onOpenChange,\n });\n const [closing, setClosing] = useState(false);\n const [side, setSide] = useState<BloomPlacement>(placement);\n const [box, setBox] = useState<{ w: number; h: number; panel: number } | null>(null);\n const rootRef = useRef<HTMLElement>(null);\n const surface = useRef<HTMLDivElement>(null);\n const trigger = useRef<HTMLButtonElement>(null);\n const panel = useRef<HTMLDivElement>(null);\n const wasOpen = useRef(open);\n const boxRef = useRef(box);\n const id = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Bloom', 'root', css);\n const { part, style: partsStyle } = useParts('Bloom', { parts, partProps, classNames });\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, rootRef) });\n\n const popover = useDismiss({\n ref: rootRef,\n open,\n onDismiss: () => setOpen(false),\n fallbackFocus: () => trigger.current,\n });\n\n // Opening: lock the trigger's box in the layout, pick the side with room, grow from the trigger size.\n useLayoutEffect(() => {\n const s = surface.current;\n const t = trigger.current;\n if (!open || !s || !t) return;\n const r = t.getBoundingClientRect();\n const w = r.width + 2;\n const h = r.height + 2;\n const target = Math.min(width, innerWidth - 2 * VIEWPORT_MARGIN);\n const at = rootRef.current?.getBoundingClientRect() ?? r;\n const panelHeight = panel.current?.scrollHeight ?? 0;\n let [v, x] = placement.split('-') as ['top' | 'bottom', 'start' | 'end'];\n if (x === 'start' && at.left + target > innerWidth - VIEWPORT_MARGIN) x = 'end';\n else if (x === 'end' && at.right - target < VIEWPORT_MARGIN) x = 'start';\n if (\n v === 'bottom' &&\n at.top + h + panelHeight > innerHeight - VIEWPORT_MARGIN &&\n at.top - panelHeight > VIEWPORT_MARGIN\n )\n v = 'top';\n else if (v === 'top' && at.top - panelHeight < VIEWPORT_MARGIN) v = 'bottom';\n setSide(`${v}-${x}`);\n boxRef.current = { w, h, panel: target };\n setBox(boxRef.current);\n // Start exactly from the trigger's box (no transition into the start values), then grow.\n s.style.transition = 'none';\n s.style.width = `${w}px`;\n s.style.borderRadius = `${h / 2}px`;\n void s.offsetWidth;\n s.style.transition = '';\n s.style.width = `${target}px`;\n s.style.borderRadius = '';\n }, [open, placement, width]);\n\n // Closing: shrink back into the trigger, then return to the flow.\n useLayoutEffect(() => {\n const s = surface.current;\n if (open || !wasOpen.current) {\n wasOpen.current = open;\n return;\n }\n wasOpen.current = open;\n const last = boxRef.current;\n // The trigger's label may have changed while open (a Choice shows the new value): shrink to its size now.\n const t = trigger.current;\n const w = last && !label && t ? t.getBoundingClientRect().width + 2 : last?.w;\n if (s && last && w) {\n boxRef.current = { ...last, w };\n setBox(boxRef.current);\n s.style.width = `${w}px`;\n s.style.borderRadius = `${last.h / 2}px`;\n }\n setClosing(true);\n const timer = setTimeout(\n () => {\n setClosing(false);\n if (s) {\n s.style.width = '';\n s.style.borderRadius = '';\n }\n },\n reduced() ? 0 : DURATION,\n );\n return () => clearTimeout(timer);\n }, [open, label]);\n\n useEffect(() => {\n if (open) focusFirst(panel.current);\n }, [open]);\n\n const phase = open ? 'open' : closing ? 'closing' : 'closed';\n const floating = phase !== 'closed' && box;\n const [v, x] = side.split('-');\n const close = (restoreFocus = true) => popover.dismiss(restoreFocus);\n\n return (\n <>\n {styled.style}\n {partsStyle}\n <Root\n className={cx('slurp-bloom', styled.className, className)}\n data-phase={phase}\n data-icon={label ? '' : undefined}\n data-side={v}\n data-align={x}\n style={\n {\n ...(floating ? { width: box.w, height: box.h } : null),\n ...style,\n } as CSSProperties\n }\n onKeyDown={popover.containerProps.onKeyDown}\n onBlur={popover.containerProps.onBlur}\n {...root}\n >\n {part('surface', 'div', {\n ref: surface,\n className: 'slurp-bloom-surface',\n children: (\n <>\n {part('trigger', 'button', {\n ref: trigger,\n type: 'button',\n id: `${id}-trigger`,\n className: 'slurp-bloom-trigger',\n 'aria-label': open && closeLabel ? closeLabel : label,\n 'aria-haspopup': role === 'dialog' ? 'dialog' : role,\n 'aria-expanded': open,\n 'aria-controls': `${id}-panel`,\n disabled,\n onClick: (e: MouseEvent<HTMLButtonElement>) => {\n if (open) return popover.dismiss(false);\n popover.opened(e.currentTarget);\n setOpen(true);\n },\n children: open && openTrigger !== undefined ? openTrigger : triggerContent,\n })}\n <div className=\"slurp-bloom-clip\">\n {part('panel', 'div', {\n ref: panel,\n id: `${id}-panel`,\n role,\n 'aria-label': panelLabel,\n 'aria-labelledby': panelLabel ? undefined : `${id}-trigger`,\n className: 'slurp-bloom-panel',\n inert: !open,\n style: box ? { width: box.panel - 2 } : undefined,\n children: typeof children === 'function' ? children(close) : children,\n })}\n </div>\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAyDA,MAAM,WAAW;AACjB,MAAM,kBAAkB;AAExB,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;;;;;AAOrF,SAAgB,MAAqC,OAAsB;CACzE,MAAM,EACJ,IACA,KACA,WACA,SAAS,gBACT,OACA,aACA,YACA,MAAM,UACN,cAAc,OACd,cACA,YAAY,gBACZ,QAAQ,KACR,OAAO,UACP,YACA,UACA,UACA,OACA,OACA,WACA,YACA,KACA,GAAG,SACD,cAAc,SAAS,KAAmB;CAC9C,MAAM,CAAC,MAAM,WAAW,cAAc;EACpC,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,MAAM,WAAW,SAAyB,SAAS;CAC1D,MAAM,CAAC,KAAK,UAAU,SAAyD,IAAI;CACnF,MAAM,UAAU,OAAoB,IAAI;CACxC,MAAM,UAAU,OAAuB,IAAI;CAC3C,MAAM,UAAU,OAA0B,IAAI;CAC9C,MAAM,QAAQ,OAAuB,IAAI;CACzC,MAAM,UAAU,OAAO,IAAI;CAC3B,MAAM,SAAS,OAAO,GAAG;CACzB,MAAM,KAAK,MAAM;CACjB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG;CAC1C,MAAM,EAAE,MAAM,OAAO,eAAe,SAAS,SAAS;EAAE;EAAO;EAAW;CAAW,CAAC;CACtF,MAAM,OAAO,iBAAiB;EAAE,GAAG;E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B,KAAK;IACL,WAAW;IACX,UACE,qBAAA,YAAA,EAAA,UAAA,CACG,KAAK,WAAW,UAAU;KACzB,KAAK;KACL,MAAM;KACN,IAAI,GAAG,GAAG;KACV,WAAW;KACX,cAAc,QAAQ,aAAa,aAAa;KAChD,iBAAiB,SAAS,WAAW,WAAW;KAChD,iBAAiB;KACjB,iBAAiB,GAAG,GAAG;KACvB;KACA,UAAU,MAAqC;MAC7C,IAAI,MAAM,OAAO,QAAQ,QAAQ,KAAK;MACtC,QAAQ,OAAO,EAAE,aAAa;MAC9B,QAAQ,IAAI;KACd;KACA,UAAU,QAAQ,gBAAgB,KAAA,IAAY,cAAc;IAC9D,CAAC,GACD,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,KAAK,SAAS,OAAO;MACpB,KAAK;MACL,IAAI,GAAG,GAAG;MACV;MACA,cAAc;MACd,mBAAmB,aAAa,KAAA,IAAY,GAAG,GAAG;MAClD,WAAW;MACX,OAAO,CAAC;MACR,OAAO,MAAM,EAAE,OAAO,IAAI,QAAQ,EAAE,IAAI,KAAA;MACxC,UAAU,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;KAC/D,CAAC;IACE,CAAA,CACL,EAAA,CAAA;GAEN,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"Bloom.js","names":[],"sources":["../../src/Bloom/Bloom.tsx"],"sourcesContent":["import { duration } from '@slurp-ui/tokens';\nimport { cx } from '@slurp-ui/utils';\nimport {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { focusFirst } from '../utils/focus';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\nimport { useForkRef } from '../utils/useForkRef';\n\nexport type BloomPlacement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';\n\nexport interface BloomOwnProps extends PartsProps<'surface' | 'trigger' | 'panel'> {\n /** Content of the trigger button (text, icon, both). */\n trigger: ReactNode;\n /**\n * Name of the trigger when it shows only an icon. An icon trigger stays in its corner when open, 44px and inset by\n * space-2 like the Dock's actions; the panel's first row (its title) sits beside it.\n */\n label?: string;\n /** Trigger content while open (an icon trigger usually becomes a close icon). */\n openTrigger?: ReactNode;\n /** Name of an icon trigger while open (\"Chiudi impostazioni\"). */\n closeLabel?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * Corner the surface grows from: `bottom-start` (default) grows right and down. It flips by itself when the panel\n * would leave the viewport.\n */\n placement?: BloomPlacement;\n /** Open width in px (never wider than the viewport minus 32px). Default 300. */\n width?: number;\n /** Role of the panel: a non-modal `dialog` (default), a `menu` or a `listbox`. */\n role?: 'dialog' | 'menu' | 'listbox';\n /** Name of the panel; default the trigger. */\n panelLabel?: string;\n disabled?: boolean;\n /** The panel. A function gets `close(restoreFocus = true)`. */\n children?: ReactNode | ((close: (restoreFocus?: boolean) => void) => ReactNode);\n}\n\nexport type BloomProps<E extends ElementType = 'div'> = PolymorphicProps<E, BloomOwnProps>;\n\n/** The Dock's motion: the surface duration (600ms) on the settle curve, as in Bloom.css. */\nconst DURATION = Number.parseFloat(duration.surface);\nconst VIEWPORT_MARGIN = 16;\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/**\n * The design system's rule for floating panels: **the button becomes the panel**. One surface grows from the trigger\n * (width, height through grid rows, radius) and shrinks back into it. Closes on a press outside, Escape or Tab out;\n * opening moves focus into the panel; Escape gives it back to the trigger.\n */\nexport function Bloom<E extends ElementType = 'div'>(props: BloomProps<E>) {\n const {\n as,\n css,\n className,\n trigger: triggerContent,\n label,\n openTrigger,\n closeLabel,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n placement = 'bottom-start',\n width = 300,\n role = 'dialog',\n panelLabel,\n disabled,\n children,\n style,\n parts,\n partProps,\n classNames,\n ref,\n ...rest\n } = useThemeProps('Bloom', props as BloomProps);\n const [open, setOpen] = useControlled({\n value: openProp,\n defaultValue: defaultOpen,\n onChange: onOpenChange,\n });\n const [closing, setClosing] = useState(false);\n const [side, setSide] = useState<BloomPlacement>(placement);\n const [box, setBox] = useState<{ w: number; h: number; panel: number } | null>(null);\n const rootRef = useRef<HTMLElement>(null);\n const surface = useRef<HTMLDivElement>(null);\n const trigger = useRef<HTMLButtonElement>(null);\n const panel = useRef<HTMLDivElement>(null);\n const wasOpen = useRef(open);\n const boxRef = useRef(box);\n const id = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Bloom', 'root', css);\n const { part, style: partsStyle } = useParts('Bloom', { parts, partProps, classNames });\n const root = useAnimationRoot({ ...rest, ref: useForkRef(ref as never, rootRef) });\n\n const popover = useDismiss({\n ref: rootRef,\n open,\n onDismiss: () => setOpen(false),\n fallbackFocus: () => trigger.current,\n });\n\n // Opening: lock the trigger's box in the layout, pick the side with room, grow from the trigger size.\n useLayoutEffect(() => {\n const s = surface.current;\n const t = trigger.current;\n if (!open || !s || !t) return;\n const r = t.getBoundingClientRect();\n const w = r.width + 2;\n const h = r.height + 2;\n const target = Math.min(width, innerWidth - 2 * VIEWPORT_MARGIN);\n const at = rootRef.current?.getBoundingClientRect() ?? r;\n const panelHeight = panel.current?.scrollHeight ?? 0;\n let [v, x] = placement.split('-') as ['top' | 'bottom', 'start' | 'end'];\n if (x === 'start' && at.left + target > innerWidth - VIEWPORT_MARGIN) x = 'end';\n else if (x === 'end' && at.right - target < VIEWPORT_MARGIN) x = 'start';\n if (\n v === 'bottom' &&\n at.top + h + panelHeight > innerHeight - VIEWPORT_MARGIN &&\n at.top - panelHeight > VIEWPORT_MARGIN\n )\n v = 'top';\n else if (v === 'top' && at.top - panelHeight < VIEWPORT_MARGIN) v = 'bottom';\n setSide(`${v}-${x}`);\n boxRef.current = { w, h, panel: target };\n setBox(boxRef.current);\n // Start exactly from the trigger's box (no transition into the start values), then grow.\n s.style.transition = 'none';\n s.style.width = `${w}px`;\n s.style.borderRadius = `${h / 2}px`;\n void s.offsetWidth;\n s.style.transition = '';\n s.style.width = `${target}px`;\n s.style.borderRadius = '';\n }, [open, placement, width]);\n\n // Closing: shrink back into the trigger, then return to the flow.\n useLayoutEffect(() => {\n const s = surface.current;\n if (open || !wasOpen.current) {\n wasOpen.current = open;\n return;\n }\n wasOpen.current = open;\n const last = boxRef.current;\n // The trigger's label may have changed while open (a Choice shows the new value): shrink to its size now.\n const t = trigger.current;\n const w = last && !label && t ? t.getBoundingClientRect().width + 2 : last?.w;\n if (s && last && w) {\n boxRef.current = { ...last, w };\n setBox(boxRef.current);\n s.style.width = `${w}px`;\n s.style.borderRadius = `${last.h / 2}px`;\n }\n setClosing(true);\n const timer = setTimeout(\n () => {\n setClosing(false);\n if (s) {\n s.style.width = '';\n s.style.borderRadius = '';\n }\n },\n reduced() ? 0 : DURATION,\n );\n return () => clearTimeout(timer);\n }, [open, label]);\n\n useEffect(() => {\n if (open) focusFirst(panel.current);\n }, [open]);\n\n const phase = open ? 'open' : closing ? 'closing' : 'closed';\n const floating = phase !== 'closed' && box;\n const [v, x] = side.split('-');\n const close = (restoreFocus = true) => popover.dismiss(restoreFocus);\n\n return (\n <>\n {styled.style}\n {partsStyle}\n <Root\n className={cx('slurp-bloom', styled.className, className)}\n data-phase={phase}\n data-icon={label ? '' : undefined}\n data-side={v}\n data-align={x}\n style={\n {\n ...(floating ? { width: box.w, height: box.h } : null),\n ...style,\n } as CSSProperties\n }\n onKeyDown={popover.containerProps.onKeyDown}\n onBlur={popover.containerProps.onBlur}\n {...root}\n >\n {part('surface', 'div', {\n ref: surface,\n className: 'slurp-bloom-surface',\n children: (\n <>\n {part('trigger', 'button', {\n ref: trigger,\n type: 'button',\n id: `${id}-trigger`,\n className: 'slurp-bloom-trigger',\n 'aria-label': open && closeLabel ? closeLabel : label,\n 'aria-haspopup': role === 'dialog' ? 'dialog' : role,\n 'aria-expanded': open,\n 'aria-controls': `${id}-panel`,\n disabled,\n onClick: (e: MouseEvent<HTMLButtonElement>) => {\n if (open) return popover.dismiss(false);\n popover.opened(e.currentTarget);\n setOpen(true);\n },\n children: open && openTrigger !== undefined ? openTrigger : triggerContent,\n })}\n <div className=\"slurp-bloom-clip\">\n {part('panel', 'div', {\n ref: panel,\n id: `${id}-panel`,\n role,\n 'aria-label': panelLabel,\n 'aria-labelledby': panelLabel ? undefined : `${id}-trigger`,\n className: 'slurp-bloom-panel',\n inert: !open,\n style: box ? { width: box.panel - 2 } : undefined,\n children: typeof children === 'function' ? children(close) : children,\n })}\n </div>\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA0DA,MAAM,WAAW,OAAO,WAAW,SAAS,OAAO;AACnD,MAAM,kBAAkB;AAExB,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;;;;;AAOrF,SAAgB,MAAqC,OAAsB;CACzE,MAAM,EACJ,IACA,KACA,WACA,SAAS,gBACT,OACA,aACA,YACA,MAAM,UACN,cAAc,OACd,cACA,YAAY,gBACZ,QAAQ,KACR,OAAO,UACP,YACA,UACA,UACA,OACA,OACA,WACA,YACA,KACA,GAAG,SACD,cAAc,SAAS,KAAmB;CAC9C,MAAM,CAAC,MAAM,WAAW,cAAc;EACpC,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,MAAM,WAAW,SAAyB,SAAS;CAC1D,MAAM,CAAC,KAAK,UAAU,SAAyD,IAAI;CACnF,MAAM,UAAU,OAAoB,IAAI;CACxC,MAAM,UAAU,OAAuB,IAAI;CAC3C,MAAM,UAAU,OAA0B,IAAI;CAC9C,MAAM,QAAQ,OAAuB,IAAI;CACzC,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W,SAAS;GACxD,cAAY;GACZ,aAAW,QAAQ,KAAK,KAAA;GACxB,aAAW;GACX,cAAY;GACZ,OACE;IACE,GAAI,WAAW;KAAE,OAAO,IAAI;KAAG,QAAQ,IAAI;IAAE,IAAI;IACjD,GAAG;GACL;GAEF,WAAW,QAAQ,eAAe;GAClC,QAAQ,QAAQ,eAAe;GAC/B,GAAI;GAEH,UAAA,KAAK,WAAW,OAAO;IACtB,KAAK;IACL,WAAW;IACX,UACE,qBAAA,YAAA,EAAA,UAAA,CACG,KAAK,WAAW,UAAU;KACzB,KAAK;KACL,MAAM;KACN,IAAI,GAAG,GAAG;KACV,WAAW;KACX,cAAc,QAAQ,aAAa,aAAa;KAChD,iBAAiB,SAAS,WAAW,WAAW;KAChD,iBAAiB;KACjB,iBAAiB,GAAG,GAAG;KACvB;KACA,UAAU,MAAqC;MAC7C,IAAI,MAAM,OAAO,QAAQ,QAAQ,KAAK;MACtC,QAAQ,OAAO,EAAE,aAAa;MAC9B,QAAQ,IAAI;KACd;KACA,UAAU,QAAQ,gBAAgB,KAAA,IAAY,cAAc;IAC9D,CAAC,GACD,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,KAAK,SAAS,OAAO;MACpB,KAAK;MACL,IAAI,GAAG,GAAG;MACV;MACA,cAAc;MACd,mBAAmB,aAAa,KAAA,IAAY,GAAG,GAAG;MAClD,WAAW;MACX,OAAO,CAAC;MACR,OAAO,MAAM,EAAE,OAAO,IAAI,QAAQ,EAAE,IAAI,KAAA;MACxC,UAAU,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;KAC/D,CAAC;IACE,CAAA,CACL,EAAA,CAAA;GAEN,CAAC;EACG,CAAA;CACN,EAAA,CAAA;AAEN"}
@@ -0,0 +1,42 @@
1
+
2
+ import { PolymorphicProps } from "../lib/polymorphic.js";
3
+ import { IsoDay } from "./dates.js";
4
+ import { ElementType } from "react";
5
+ export interface CalendarLabels {
6
+ previous: string;
7
+ next: string;
8
+ }
9
+ export declare const CALENDAR_LABELS: CalendarLabels;
10
+ /** A period: `end` is null while only the start has been picked. */
11
+ export interface DateRange {
12
+ start: IsoDay;
13
+ end: IsoDay | null;
14
+ }
15
+ export type CalendarValue = IsoDay | DateRange | null;
16
+ export interface CalendarOwnProps {
17
+ /** One day (`'2026-12-08'`), or a period with `range`. */
18
+ value?: CalendarValue;
19
+ defaultValue?: CalendarValue;
20
+ onValueChange?: (value: CalendarValue) => void;
21
+ /** Pick a period: the first press is the start, the second the end. */
22
+ range?: boolean;
23
+ /** Earliest and latest day that can be picked. */
24
+ min?: IsoDay;
25
+ max?: IsoDay;
26
+ /** Days that cannot be picked (closed days, sold out…). */
27
+ isDateDisabled?: (day: IsoDay) => boolean;
28
+ /** First day of the week: 0 Sunday … 6 Saturday. Default 1 (Monday). */
29
+ weekStartsOn?: number;
30
+ /** The month shown first. Default the value's month, or today's. */
31
+ defaultMonth?: IsoDay;
32
+ /** Move focus to the day (when it opens in a panel). */
33
+ autoFocus?: boolean;
34
+ labels?: Partial<CalendarLabels>;
35
+ }
36
+ export type CalendarProps<E extends ElementType = 'div'> = PolymorphicProps<E, CalendarOwnProps>;
37
+ /**
38
+ * A month to pick a day or a period from. A grid you move through with the arrow keys (Page Up / Down: months,
39
+ * Home / End: the week's ends); day names and the month come from the theme's `locale`.
40
+ */
41
+ export declare function Calendar<E extends ElementType = 'div'>(props: CalendarProps<E>): import("react").JSX.Element;
42
+ //# sourceMappingURL=Calendar.d.ts.map
@@ -0,0 +1,178 @@
1
+ "use client";
2
+ import { useTheme } from "../internal/context.js";
3
+ import { useLabels } from "../internal/labels.js";
4
+ import { cx } from "../utils/src/index.js";
5
+ import { useAnimationRoot } from "../internal/animation.js";
6
+ import { useCss, useThemeProps } from "../internal/styled.js";
7
+ import { Bubble } from "../Bubble/Bubble.js";
8
+ import { useControlled } from "../utils/useControlled.js";
9
+ import { addDays, addMonths, monthGrid, monthOf, toDate, today } from "./dates.js";
10
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
11
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
+ import { ChevronLeftIcon, ChevronRightIcon } from "@slurp-ui/icons";
13
+ // src/Calendar/Calendar.tsx
14
+ const CALENDAR_LABELS = {
15
+ previous: "Mese precedente",
16
+ next: "Mese successivo"
17
+ };
18
+ const startOf = (v) => v == null ? null : typeof v === "string" ? v : v.start;
19
+ /**
20
+ * A month to pick a day or a period from. A grid you move through with the arrow keys (Page Up / Down: months,
21
+ * Home / End: the week's ends); day names and the month come from the theme's `locale`.
22
+ */
23
+ function Calendar(props) {
24
+ const { as, css, className, value: valueProp, defaultValue = null, onValueChange, range = false, min, max, isDateDisabled, weekStartsOn = 1, defaultMonth, autoFocus = false, labels: labelsProp, ...rest } = useThemeProps("Calendar", props);
25
+ const labels = {
26
+ ...CALENDAR_LABELS,
27
+ ...useLabels("Calendar"),
28
+ ...labelsProp
29
+ };
30
+ const { locale } = useTheme();
31
+ const [value, setValue] = useControlled({
32
+ value: valueProp,
33
+ defaultValue,
34
+ onChange: onValueChange
35
+ });
36
+ const now = today();
37
+ const [focused, setFocused] = useState(() => defaultMonth ?? startOf(value) ?? now);
38
+ const focusNext = useRef(autoFocus);
39
+ const id = useId();
40
+ const Root = as ?? "div";
41
+ const styled = useCss("Calendar", "root", css);
42
+ const root = useAnimationRoot(rest);
43
+ const month = monthOf(focused);
44
+ const weeks = useMemo(() => monthGrid(month, weekStartsOn), [month, weekStartsOn]);
45
+ const fmt = useMemo(() => ({
46
+ month: new Intl.DateTimeFormat(locale, {
47
+ month: "long",
48
+ year: "numeric"
49
+ }),
50
+ day: new Intl.DateTimeFormat(locale, {
51
+ weekday: "long",
52
+ day: "numeric",
53
+ month: "long",
54
+ year: "numeric"
55
+ }),
56
+ weekday: new Intl.DateTimeFormat(locale, { weekday: "short" }),
57
+ weekdayLong: new Intl.DateTimeFormat(locale, { weekday: "long" })
58
+ }), [locale]);
59
+ const disabled = (day) => min != null && day < min || max != null && day > max || !!isDateDisabled?.(day);
60
+ const clampDay = (day) => min && day < min ? min : max && day > max ? max : day;
61
+ useEffect(() => {
62
+ if (!focusNext.current) return;
63
+ focusNext.current = false;
64
+ document.getElementById(`${id}-${focused}`)?.focus();
65
+ }, [focused, id]);
66
+ const move = (day) => {
67
+ focusNext.current = true;
68
+ setFocused(clampDay(day));
69
+ };
70
+ const pick = (day) => {
71
+ if (disabled(day)) return;
72
+ setFocused(day);
73
+ if (!range) return setValue(day);
74
+ const current = value != null && typeof value === "object" ? value : null;
75
+ if (!current || current.end !== null) return setValue({
76
+ start: day,
77
+ end: null
78
+ });
79
+ setValue(day < current.start ? {
80
+ start: day,
81
+ end: current.start
82
+ } : {
83
+ start: current.start,
84
+ end: day
85
+ });
86
+ };
87
+ const onKeyDown = (e) => {
88
+ const weekday = (toDate(focused).getDay() - weekStartsOn + 7) % 7;
89
+ const next = {
90
+ ArrowLeft: addDays(focused, -1),
91
+ ArrowRight: addDays(focused, 1),
92
+ ArrowUp: addDays(focused, -7),
93
+ ArrowDown: addDays(focused, 7),
94
+ Home: addDays(focused, -weekday),
95
+ End: addDays(focused, 6 - weekday),
96
+ PageUp: addMonths(focused, e.shiftKey ? -12 : -1),
97
+ PageDown: addMonths(focused, e.shiftKey ? 12 : 1)
98
+ }[e.key];
99
+ if (next) {
100
+ e.preventDefault();
101
+ move(next);
102
+ }
103
+ };
104
+ const selected = (day) => value == null ? false : typeof value === "string" ? value === day : value.start === day || value.end === day;
105
+ const inRange = (day) => value != null && typeof value === "object" && value.end !== null && day > value.start && day < value.end;
106
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
107
+ className: cx("slurp-calendar", styled.className, className),
108
+ "data-range": range || void 0,
109
+ ...root,
110
+ children: [/* @__PURE__ */ jsxs("div", {
111
+ className: "slurp-calendar-head",
112
+ children: [
113
+ /* @__PURE__ */ jsx(Bubble, {
114
+ appearance: "plain",
115
+ tone: "neutral",
116
+ size: "sm",
117
+ label: labels.previous,
118
+ disabled: min != null && monthOf(min) >= month,
119
+ onClick: () => setFocused(clampDay(addMonths(focused, -1))),
120
+ children: /* @__PURE__ */ jsx(ChevronLeftIcon, { size: 18 })
121
+ }),
122
+ /* @__PURE__ */ jsx("p", {
123
+ className: "slurp-calendar-month",
124
+ id: `${id}-month`,
125
+ "aria-live": "polite",
126
+ children: fmt.month.format(toDate(month))
127
+ }),
128
+ /* @__PURE__ */ jsx(Bubble, {
129
+ appearance: "plain",
130
+ tone: "neutral",
131
+ size: "sm",
132
+ label: labels.next,
133
+ disabled: max != null && monthOf(max) <= month,
134
+ onClick: () => setFocused(clampDay(addMonths(focused, 1))),
135
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, { size: 18 })
136
+ })
137
+ ]
138
+ }), /* @__PURE__ */ jsxs("table", {
139
+ className: "slurp-calendar-grid",
140
+ role: "grid",
141
+ "aria-labelledby": `${id}-month`,
142
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: weeks[0]?.map((day) => /* @__PURE__ */ jsx("th", {
143
+ scope: "col",
144
+ abbr: fmt.weekdayLong.format(toDate(day)),
145
+ children: fmt.weekday.format(toDate(day)).slice(0, 2)
146
+ }, day)) }) }), /* @__PURE__ */ jsx("tbody", {
147
+ onKeyDown,
148
+ children: weeks.map((week) => /* @__PURE__ */ jsx("tr", { children: week.map((day) => {
149
+ const off = disabled(day);
150
+ const on = selected(day);
151
+ return /* @__PURE__ */ jsx("td", {
152
+ role: "gridcell",
153
+ "aria-selected": on,
154
+ "data-outside": monthOf(day) !== month || void 0,
155
+ "data-in-range": inRange(day) || void 0,
156
+ "data-edge": range && on || void 0,
157
+ children: /* @__PURE__ */ jsx("button", {
158
+ type: "button",
159
+ id: `${id}-${day}`,
160
+ className: "slurp-calendar-day",
161
+ tabIndex: day === focused ? 0 : -1,
162
+ "aria-label": fmt.day.format(toDate(day)),
163
+ "aria-current": day === now ? "date" : void 0,
164
+ "aria-disabled": off || void 0,
165
+ "data-selected": on || void 0,
166
+ "data-autofocus": autoFocus && day === focused || void 0,
167
+ onClick: () => pick(day),
168
+ children: Number(day.slice(8))
169
+ })
170
+ }, day);
171
+ }) }, week[0]))
172
+ })]
173
+ })]
174
+ })] });
175
+ }
176
+ export { CALENDAR_LABELS, Calendar };
177
+
178
+ //# sourceMappingURL=Calendar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Calendar.js","names":["todayIso"],"sources":["../../src/Calendar/Calendar.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ElementType,\n type KeyboardEvent,\n} from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { useTheme } from '../internal/context';\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';\nimport {\n addDays,\n addMonths,\n monthGrid,\n monthOf,\n toDate,\n today as todayIso,\n type IsoDay,\n} from './dates';\n\nexport interface CalendarLabels {\n previous: string;\n next: string;\n}\n\nexport const CALENDAR_LABELS: CalendarLabels = {\n previous: 'Mese precedente',\n next: 'Mese successivo',\n};\n\n/** A period: `end` is null while only the start has been picked. */\nexport interface DateRange {\n start: IsoDay;\n end: IsoDay | null;\n}\n\nexport type CalendarValue = IsoDay | DateRange | null;\n\nexport interface CalendarOwnProps {\n /** One day (`'2026-12-08'`), or a period with `range`. */\n value?: CalendarValue;\n defaultValue?: CalendarValue;\n onValueChange?: (value: CalendarValue) => void;\n /** Pick a period: the first press is the start, the second the end. */\n range?: boolean;\n /** Earliest and latest day that can be picked. */\n min?: IsoDay;\n max?: IsoDay;\n /** Days that cannot be picked (closed days, sold out…). */\n isDateDisabled?: (day: IsoDay) => boolean;\n /** First day of the week: 0 Sunday … 6 Saturday. Default 1 (Monday). */\n weekStartsOn?: number;\n /** The month shown first. Default the value's month, or today's. */\n defaultMonth?: IsoDay;\n /** Move focus to the day (when it opens in a panel). */\n autoFocus?: boolean;\n labels?: Partial<CalendarLabels>;\n}\n\nexport type CalendarProps<E extends ElementType = 'div'> = PolymorphicProps<E, CalendarOwnProps>;\n\nconst startOf = (v: CalendarValue): IsoDay | null =>\n v == null ? null : typeof v === 'string' ? v : v.start;\n\n/**\n * A month to pick a day or a period from. A grid you move through with the arrow keys (Page Up / Down: months,\n * Home / End: the week's ends); day names and the month come from the theme's `locale`.\n */\nexport function Calendar<E extends ElementType = 'div'>(props: CalendarProps<E>) {\n const {\n as,\n css,\n className,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n range = false,\n min,\n max,\n isDateDisabled,\n weekStartsOn = 1,\n defaultMonth,\n autoFocus = false,\n labels: labelsProp,\n ...rest\n } = useThemeProps('Calendar', props as CalendarProps);\n const labels = { ...CALENDAR_LABELS, ...useLabels('Calendar'), ...labelsProp };\n const { locale } = useTheme();\n const [value, setValue] = useControlled<CalendarValue>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange,\n });\n const now = todayIso();\n const [focused, setFocused] = useState<IsoDay>(() => defaultMonth ?? startOf(value) ?? now);\n // A keyboard move asks focus to follow the roving day once it is rendered (also in another month).\n const focusNext = useRef(autoFocus);\n const id = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Calendar', 'root', css);\n const root = useAnimationRoot(rest);\n\n const month = monthOf(focused);\n const weeks = useMemo(() => monthGrid(month, weekStartsOn), [month, weekStartsOn]);\n const fmt = useMemo(\n () => ({\n month: new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }),\n day: new Intl.DateTimeFormat(locale, {\n weekday: 'long',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n }),\n weekday: new Intl.DateTimeFormat(locale, { weekday: 'short' }),\n weekdayLong: new Intl.DateTimeFormat(locale, { weekday: 'long' }),\n }),\n [locale],\n );\n\n const disabled = (day: IsoDay) =>\n (min != null && day < min) || (max != null && day > max) || !!isDateDisabled?.(day);\n const clampDay = (day: IsoDay) => (min && day < min ? min : max && day > max ? max : day);\n\n useEffect(() => {\n if (!focusNext.current) return;\n focusNext.current = false;\n document.getElementById(`${id}-${focused}`)?.focus();\n }, [focused, id]);\n\n const move = (day: IsoDay) => {\n focusNext.current = true;\n setFocused(clampDay(day));\n };\n\n const pick = (day: IsoDay) => {\n if (disabled(day)) return;\n setFocused(day);\n if (!range) return setValue(day);\n const current = value != null && typeof value === 'object' ? value : null;\n if (!current || current.end !== null) return setValue({ start: day, end: null });\n setValue(\n day < current.start ? { start: day, end: current.start } : { start: current.start, end: day },\n );\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const weekday = (toDate(focused).getDay() - weekStartsOn + 7) % 7;\n const keys: Record<string, IsoDay | undefined> = {\n ArrowLeft: addDays(focused, -1),\n ArrowRight: addDays(focused, 1),\n ArrowUp: addDays(focused, -7),\n ArrowDown: addDays(focused, 7),\n Home: addDays(focused, -weekday),\n End: addDays(focused, 6 - weekday),\n PageUp: addMonths(focused, e.shiftKey ? -12 : -1),\n PageDown: addMonths(focused, e.shiftKey ? 12 : 1),\n };\n const next = keys[e.key];\n if (next) {\n e.preventDefault();\n move(next);\n }\n };\n\n const selected = (day: IsoDay) =>\n value == null\n ? false\n : typeof value === 'string'\n ? value === day\n : value.start === day || value.end === day;\n const inRange = (day: IsoDay) =>\n value != null &&\n typeof value === 'object' &&\n value.end !== null &&\n day > value.start &&\n day < value.end;\n\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-calendar', styled.className, className)}\n data-range={range || undefined}\n {...root}\n >\n <div className=\"slurp-calendar-head\">\n <Bubble\n appearance=\"plain\"\n tone=\"neutral\"\n size=\"sm\"\n label={labels.previous}\n disabled={min != null && monthOf(min) >= month}\n onClick={() => setFocused(clampDay(addMonths(focused, -1)))}\n >\n <ChevronLeftIcon size={18} />\n </Bubble>\n <p className=\"slurp-calendar-month\" id={`${id}-month`} aria-live=\"polite\">\n {fmt.month.format(toDate(month))}\n </p>\n <Bubble\n appearance=\"plain\"\n tone=\"neutral\"\n size=\"sm\"\n label={labels.next}\n disabled={max != null && monthOf(max) <= month}\n onClick={() => setFocused(clampDay(addMonths(focused, 1)))}\n >\n <ChevronRightIcon size={18} />\n </Bubble>\n </div>\n <table className=\"slurp-calendar-grid\" role=\"grid\" aria-labelledby={`${id}-month`}>\n <thead>\n <tr>\n {weeks[0]?.map((day) => (\n <th key={day} scope=\"col\" abbr={fmt.weekdayLong.format(toDate(day))}>\n {fmt.weekday.format(toDate(day)).slice(0, 2)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody onKeyDown={onKeyDown}>\n {weeks.map((week) => (\n <tr key={week[0]}>\n {week.map((day) => {\n const off = disabled(day);\n const on = selected(day);\n return (\n <td\n key={day}\n role=\"gridcell\"\n aria-selected={on}\n data-outside={monthOf(day) !== month || undefined}\n data-in-range={inRange(day) || undefined}\n data-edge={(range && on) || undefined}\n >\n <button\n type=\"button\"\n id={`${id}-${day}`}\n className=\"slurp-calendar-day\"\n tabIndex={day === focused ? 0 : -1}\n aria-label={fmt.day.format(toDate(day))}\n aria-current={day === now ? 'date' : undefined}\n aria-disabled={off || undefined}\n data-selected={on || undefined}\n data-autofocus={(autoFocus && day === focused) || undefined}\n onClick={() => pick(day)}\n >\n {Number(day.slice(8))}\n </button>\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n </table>\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAkCA,MAAa,kBAAkC;CAC7C,UAAU;CACV,MAAM;AACR;AAiCA,MAAM,WAAW,MACf,KAAK,OAAO,OAAO,OAAO,MAAM,WAAW,IAAI,EAAE;;;;;AAMnD,SAAgB,SAAwC,OAAyB;CAC/E,MAAM,EACJ,IACA,KACA,WACA,OAAO,WACP,eAAe,MACf,eACA,QAAQ,OACR,KACA,KACA,gBACA,eAAe,GACf,cACA,YA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QAAQ;KACjB,MAAM,MAAM,SAAS,GAAG;KACxB,MAAM,KAAK,SAAS,GAAG;KACvB,OACE,oBAAC,MAAD;MAEE,MAAK;MACL,iBAAe;MACf,gBAAc,QAAQ,GAAG,MAAM,SAAS,KAAA;MACxC,iBAAe,QAAQ,GAAG,KAAK,KAAA;MAC/B,aAAY,SAAS,MAAO,KAAA;MAE5B,UAAA,oBAAC,UAAD;OACE,MAAK;OACL,IAAI,GAAG,GAAG,GAAG;OACb,WAAU;OACV,UAAU,QAAQ,UAAU,IAAI;OAChC,cAAY,IAAI,IAAI,OAAO,OAAO,GAAG,CAAC;OACtC,gBAAc,QAAQ,MAAM,SAAS,KAAA;OACrC,iBAAe,OAAO,KAAA;OACtB,iBAAe,MAAM,KAAA;OACrB,kBAAiB,aAAa,QAAQ,WAAY,KAAA;OAClD,eAAe,KAAK,GAAG;OAEtB,UAAA,OAAO,IAAI,MAAM,CAAC,CAAC;MACd,CAAA;KACN,GArBG,GAqBH;IAER,CAAC,EACC,GA9BK,KAAK,EA8BV,CACL;GACI,CAAA,CACF;EACH,CAAA,CAAA;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
@@ -0,0 +1,3 @@
1
+
2
+ export type IsoDay = string;
3
+ //# sourceMappingURL=dates.d.ts.map
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ // src/Calendar/dates.ts
3
+ const toDate = (iso) => {
4
+ const [y = 1970, m = 1, d = 1] = iso.split("-").map(Number);
5
+ return new Date(y, m - 1, d);
6
+ };
7
+ const pad = (n) => String(n).padStart(2, "0");
8
+ const toIso = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
9
+ const addDays = (iso, n) => {
10
+ const d = toDate(iso);
11
+ d.setDate(d.getDate() + n);
12
+ return toIso(d);
13
+ };
14
+ /** Same day of another month, clamped to its length (31 Jan + 1 month → 28/29 Feb). */
15
+ const addMonths = (iso, n) => {
16
+ const d = toDate(iso);
17
+ const day = d.getDate();
18
+ d.setDate(1);
19
+ d.setMonth(d.getMonth() + n);
20
+ const last = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
21
+ d.setDate(Math.min(day, last));
22
+ return toIso(d);
23
+ };
24
+ const monthOf = (iso) => `${iso.slice(0, 7)}-01`;
25
+ const today = () => toIso(/* @__PURE__ */ new Date());
26
+ /** The weeks shown for a month: whole weeks from `weekStart` (0 Sunday … 6 Saturday). */
27
+ function monthGrid(month, weekStart) {
28
+ const first = toDate(monthOf(month));
29
+ const offset = (first.getDay() - weekStart + 7) % 7;
30
+ let day = addDays(toIso(first), -offset);
31
+ const end = new Date(first.getFullYear(), first.getMonth() + 1, 0);
32
+ const weeks = [];
33
+ while (weeks.length < 6) {
34
+ const week = [];
35
+ for (let i = 0; i < 7; i++) {
36
+ week.push(day);
37
+ day = addDays(day, 1);
38
+ }
39
+ weeks.push(week);
40
+ if (toDate(day) > end) break;
41
+ }
42
+ return weeks;
43
+ }
44
+ export { addDays, addMonths, monthGrid, monthOf, toDate, toIso, today };
45
+
46
+ //# sourceMappingURL=dates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.js","names":[],"sources":["../../src/Calendar/dates.ts"],"sourcesContent":["// Calendar dates as ISO day strings ('2026-12-08'): serialisable and free of time zones. Local-time arithmetic only.\n\nexport type IsoDay = string;\n\nexport const toDate = (iso: IsoDay): Date => {\n const [y = 1970, m = 1, d = 1] = iso.split('-').map(Number);\n return new Date(y, m - 1, d);\n};\n\nconst pad = (n: number) => String(n).padStart(2, '0');\nexport const toIso = (d: Date): IsoDay =>\n `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;\n\nexport const addDays = (iso: IsoDay, n: number): IsoDay => {\n const d = toDate(iso);\n d.setDate(d.getDate() + n);\n return toIso(d);\n};\n\n/** Same day of another month, clamped to its length (31 Jan + 1 month → 28/29 Feb). */\nexport const addMonths = (iso: IsoDay, n: number): IsoDay => {\n const d = toDate(iso);\n const day = d.getDate();\n d.setDate(1);\n d.setMonth(d.getMonth() + n);\n const last = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();\n d.setDate(Math.min(day, last));\n return toIso(d);\n};\n\nexport const monthOf = (iso: IsoDay): IsoDay => `${iso.slice(0, 7)}-01`;\nexport const today = (): IsoDay => toIso(new Date());\n\n/** The weeks shown for a month: whole weeks from `weekStart` (0 Sunday … 6 Saturday). */\nexport function monthGrid(month: IsoDay, weekStart: number): IsoDay[][] {\n const first = toDate(monthOf(month));\n const offset = (first.getDay() - weekStart + 7) % 7;\n let day = addDays(toIso(first), -offset);\n const end = new Date(first.getFullYear(), first.getMonth() + 1, 0);\n const weeks: IsoDay[][] = [];\n while (weeks.length < 6) {\n const week: IsoDay[] = [];\n for (let i = 0; i < 7; i++) {\n week.push(day);\n day = addDays(day, 1);\n }\n weeks.push(week);\n if (toDate(day) > end) break;\n }\n return weeks;\n}\n"],"mappings":";;AAIA,MAAa,UAAU,QAAsB;CAC3C,MAAM,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC1D,OAAO,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC;AAC7B;AAEA,MAAM,OAAO,MAAc,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;AACpD,MAAa,SAAS,MACpB,GAAG,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,SAAS,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,CAAC;AAEhE,MAAa,WAAW,KAAa,MAAsB;CACzD,MAAM,IAAI,OAAO,GAAG;CACpB,EAAE,QAAQ,EAAE,QAAQ,IAAI,CAAC;CACzB,OAAO,MAAM,CAAC;AAChB;;AAGA,MAAa,aAAa,KAAa,MAAsB;CAC3D,MAAM,IAAI,OAAO,GAAG;CACpB,MAAM,MAAM,EAAE,QAAQ;CACtB,EAAE,QAAQ,CAAC;CACX,EAAE,SAAS,EAAE,SAAS,IAAI,CAAC;CAC3B,MAAM,OAAO,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ;CACpE,EAAE,QAAQ,KAAK,IAAI,KAAK,IAAI,CAAC;CAC7B,OAAO,MAAM,CAAC;AAChB;AAEA,MAAa,WAAW,QAAwB,GAAG,IAAI,MAAM,GAAG,CAAC,EAAE;AACnE,MAAa,cAAsB,sBAAM,IAAI,KAAK,CAAC;;AAGnD,SAAgB,UAAU,OAAe,WAA+B;CACtE,MAAM,QAAQ,OAAO,QAAQ,KAAK,CAAC;CACnC,MAAM,UAAU,MAAM,OAAO,IAAI,YAAY,KAAK;CAClD,IAAI,MAAM,QAAQ,MAAM,KAAK,GAAG,CAAC,MAAM;CACvC,MAAM,MAAM,IAAI,KAAK,MAAM,YAAY,GAAG,MAAM,SAAS,IAAI,GAAG,CAAC;CACjE,MAAM,QAAoB,CAAC;CAC3B,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,OAAiB,CAAC;EACxB,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GAC1B,KAAK,KAAK,GAAG;GACb,MAAM,QAAQ,KAAK,CAAC;EACtB;EACA,MAAM,KAAK,IAAI;EACf,IAAI,OAAO,GAAG,IAAI,KAAK;CACzB;CACA,OAAO;AACT"}
@@ -0,0 +1,3 @@
1
+
2
+ import { CALENDAR_LABELS, Calendar, CalendarLabels, CalendarProps, CalendarValue, DateRange } from "./Calendar.js";
3
+ export { CALENDAR_LABELS, Calendar, type CalendarLabels, type CalendarProps, type CalendarValue, type DateRange, Calendar as default };
@@ -0,0 +1,2 @@
1
+
2
+ export { CALENDAR_LABELS, Calendar, Calendar as default } from "./Calendar.js";
@@ -4,7 +4,7 @@ import { ElementType, ReactNode } from "react";
4
4
  export interface CardOwnProps extends PartsProps<'media' | 'badge' | 'title' | 'description'> {
5
5
  title: ReactNode;
6
6
  description?: ReactNode;
7
- /** A value shown strong in the description pill ("1.239 €"). */
7
+ /** A value shown strong in the description pill ("9.1", "24"). */
8
8
  value?: ReactNode;
9
9
  /** Before the value ("da"). */
10
10
  valuePrefix?: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"Card.js","names":[],"sources":["../../src/Card/Card.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { CSSProperties, ElementType, ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { onColor } from '../lib/color';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\n\nexport interface CardOwnProps extends PartsProps<'media' | 'badge' | 'title' | 'description'> {\n title: ReactNode;\n description?: ReactNode;\n /** A value shown strong in the description pill (\"1.239 €\"). */\n value?: ReactNode;\n /** Before the value (\"da\"). */\n valuePrefix?: ReactNode;\n /** Pill at the top right (\"−15%\"). */\n badge?: ReactNode;\n /** Tint (any hex); default the accent. */\n color?: string;\n /** The media in the middle (illustration, photo), decorative. */\n media?: ReactNode;\n /** Renders a link. */\n href?: string;\n}\n\nexport type CardProps<E extends ElementType = 'a'> = PolymorphicProps<E, CardOwnProps>;\n\n/**\n * One tinted rounded surface (like a Tile): the media in the middle, the title and description pills inside at the\n * bottom left, never covering it. A link with `href`, a button with `onClick`.\n */\nexport function Card<E extends ElementType = 'a'>(props: CardProps<E>) {\n const {\n as,\n css,\n className,\n title,\n description,\n value,\n valuePrefix,\n badge,\n color,\n media,\n href,\n style,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Card', props as CardProps);\n const Root = (as ?? (href ? 'a' : rest.onClick ? 'button' : 'div')) as ElementType;\n const styled = useCss('Card', 'root', css);\n const { part, style: partsStyle } = useParts('Card', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const vars = {\n ...(color\n ? {\n '--slurp-card-color': color,\n '--slurp-card-on': /^#[0-9a-f]{6}$/i.test(color) ? onColor(color) : 'var(--slurp-fg)',\n '--slurp-animation-tint': color,\n }\n : null),\n ...style,\n } as CSSProperties;\n return (\n <>\n {styled.style}\n {partsStyle}\n <Root\n className={cx('slurp-card', styled.className, className)}\n href={href}\n style={vars}\n {...(Root === 'button' ? { type: 'button' } : null)}\n {...root}\n >\n {part('media', 'span', {\n className: 'slurp-card-media',\n 'aria-hidden': true,\n children: (\n <>\n <span className=\"slurp-stage-glow\" />\n <span className=\"slurp-stage-ring\" />\n {media != null && <span className=\"slurp-card-art\">{media}</span>}\n </>\n ),\n })}\n {badge != null && part('badge', 'span', { className: 'slurp-card-badge', children: badge })}\n {part('title', 'span', { className: 'slurp-card-title', children: title })}\n {(description != null || value != null) &&\n part('description', 'span', {\n className: 'slurp-card-description',\n children: (\n <>\n {description != null && <span>{description}</span>}\n {value != null && (\n <strong>\n {valuePrefix != null && <>{valuePrefix} </>}\n {value}\n </strong>\n )}\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,KAAkC,OAAqB;CACrE,MAAM,EACJ,IACA,KACA,WACA,OACA,aACA,OACA,aACA,OACA,OACA,OACA,MACA,OACA,OACA,WACA,YACA,GAAG,SACD,cAAc,QAAQ,KAAkB;CAC5C,MAAM,OAAQ,OAAO,OAAO,MAAM,KAAK,UAAU,WAAW;CAC5D,MAAM,SAAS,OAAO,QAAQ,QAAQ,GAAG;CACzC,MAAM,EAAE,MAAM,OAAO,eAAe,SAAS,QAAQ;EAAE;EAAO;EAAW;CAAW,CAAC;CACrF,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,OAAO;EACX,GAAI,QACA;GACE,sBAAsB;GACtB,mBAAmB,kBAAkB,KAAK,KAAK,IAAI,QAAQ,KAAK,IAAI;GACpE,0BAA0B;EAC5B,IACA;EACJ,GAAG;CACL;CACA,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,WAAW,GAAG,cAAc,OAAO,WAAW,SAAS;GACjD;GACN,OAAO;GACP,GAAK,SAAS,WAAW,EAAE,MAAM,SAAS,IAAI;GAC9C,GAAI;GALN,UAAA;IAOG,KAAK,SAAS,QAAQ;KACrB,WAAW;KACX,eAAe;KACf,UACE,qBAAA,UAAA,EAAA,UAAA;MACE,oBAAC,QAAD,EAAM,WAAU,mBAAoB,CAAA;MACpC,oBAAC,QAAD,EAAM,WAAU,mBAAoB,CAAA;MACnC,SAAS,QAAQ,oBAAC,QAAD;OAAM,WAAU;OAAkB,UAAA;MAAY,CAAA;KAChE,EAAA,CAAA;IAEN,CAAC;IACA,SAAS,QAAQ,KAAK,SAAS,QAAQ;KAAE,WAAW;KAAoB,UAAU;IAAM,CAAC;IACzF,KAAK,SAAS,QAAQ;KAAE,WAAW;KAAoB,UAAU;IAAM,CAAC;KACvE,eAAe,QAAQ,SAAS,SAChC,KAAK,eAAe,QAAQ;KAC1B,WAAW;KACX,UACE,qBAAA,UAAA,EAAA,UAAA,CACG,eAAe,QAAQ,oBAAC,QAAD,EAAA,UAAO,YAAkB,CAAA,GAChD,SAAS,QACR,qBAAC,UAAD,EAAA,UAAA,CACG,eAAe,QAAQ,qBAAA,UAAA,EAAA,UAAA,CAAG,aAAY,GAAG,EAAA,CAAA,GACzC,KACK,EAAA,CAAA,CAEV,EAAA,CAAA;IAEN,CAAC;GACC;;CACN,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"Card.js","names":[],"sources":["../../src/Card/Card.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { CSSProperties, ElementType, ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { onColor } from '../lib/color';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\n\nexport interface CardOwnProps extends PartsProps<'media' | 'badge' | 'title' | 'description'> {\n title: ReactNode;\n description?: ReactNode;\n /** A value shown strong in the description pill (\"9.1\", \"24\"). */\n value?: ReactNode;\n /** Before the value (\"da\"). */\n valuePrefix?: ReactNode;\n /** Pill at the top right (\"−15%\"). */\n badge?: ReactNode;\n /** Tint (any hex); default the accent. */\n color?: string;\n /** The media in the middle (illustration, photo), decorative. */\n media?: ReactNode;\n /** Renders a link. */\n href?: string;\n}\n\nexport type CardProps<E extends ElementType = 'a'> = PolymorphicProps<E, CardOwnProps>;\n\n/**\n * One tinted rounded surface (like a Tile): the media in the middle, the title and description pills inside at the\n * bottom left, never covering it. A link with `href`, a button with `onClick`.\n */\nexport function Card<E extends ElementType = 'a'>(props: CardProps<E>) {\n const {\n as,\n css,\n className,\n title,\n description,\n value,\n valuePrefix,\n badge,\n color,\n media,\n href,\n style,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Card', props as CardProps);\n const Root = (as ?? (href ? 'a' : rest.onClick ? 'button' : 'div')) as ElementType;\n const styled = useCss('Card', 'root', css);\n const { part, style: partsStyle } = useParts('Card', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const vars = {\n ...(color\n ? {\n '--slurp-card-color': color,\n '--slurp-card-on': /^#[0-9a-f]{6}$/i.test(color) ? onColor(color) : 'var(--slurp-fg)',\n '--slurp-animation-tint': color,\n }\n : null),\n ...style,\n } as CSSProperties;\n return (\n <>\n {styled.style}\n {partsStyle}\n <Root\n className={cx('slurp-card', styled.className, className)}\n href={href}\n style={vars}\n {...(Root === 'button' ? { type: 'button' } : null)}\n {...root}\n >\n {part('media', 'span', {\n className: 'slurp-card-media',\n 'aria-hidden': true,\n children: (\n <>\n <span className=\"slurp-stage-glow\" />\n <span className=\"slurp-stage-ring\" />\n {media != null && <span className=\"slurp-card-art\">{media}</span>}\n </>\n ),\n })}\n {badge != null && part('badge', 'span', { className: 'slurp-card-badge', children: badge })}\n {part('title', 'span', { className: 'slurp-card-title', children: title })}\n {(description != null || value != null) &&\n part('description', 'span', {\n className: 'slurp-card-description',\n children: (\n <>\n {description != null && <span>{description}</span>}\n {value != null && (\n <strong>\n {valuePrefix != null && <>{valuePrefix} </>}\n {value}\n </strong>\n )}\n </>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,WAAW;KACX,UACE,qBAAA,UAAA,EAAA,UAAA,CACG,eAAe,QAAQ,oBAAC,QAAD,EAAA,UAAO,YAAkB,CAAA,GAChD,SAAS,QACR,qBAAC,UAAD,EAAA,UAAA,CACG,eAAe,QAAQ,qBAAA,UAAA,EAAA,UAAA,CAAG,aAAY,GAAG,EAAA,CAAA,GACzC,KACK,EAAA,CAAA,CAEV,EAAA,CAAA;IAEN,CAAC;GACC;;CACN,EAAA,CAAA;AAEN"}
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import { useLabels } from "../internal/labels.js";
2
3
  import { cx } from "../utils/src/index.js";
3
4
  import { useAnimationRoot } from "../internal/animation.js";
4
5
  import { useCss, useParts, useThemeProps } from "../internal/styled.js";
@@ -30,6 +31,7 @@ function Carousel(props) {
30
31
  const { as, css, className, label, children, index: indexProp, defaultIndex = 0, onIndexChange, maxDots = 5, labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Carousel", props);
31
32
  const labels = {
32
33
  ...CAROUSEL_LABELS,
34
+ ...useLabels("Carousel"),
33
35
  ...labelsProp
34
36
  };
35
37
  const slides = Children.toArray(children);
@@ -1 +1 @@
1
- {"version":3,"file":"Carousel.js","names":[],"sources":["../../src/Carousel/Carousel.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Children,\n Fragment,\n useEffect,\n useId,\n useRef,\n type ElementType,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\n\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';\n\nexport interface CarouselLabels {\n previous: string;\n next: string;\n /** Name of a slide (\"2 di 5\"). */\n slide: (index: number, count: number) => string;\n /** Name of the button of a slide (\"Mostra 2 di 5\"). */\n show: (index: number, count: number) => string;\n /** Name of the group of slide buttons. */\n picker: string;\n}\n\nexport const CAROUSEL_LABELS: CarouselLabels = {\n previous: 'Precedente',\n next: 'Successiva',\n slide: (i, n) => `${i} di ${n}`,\n show: (i, n) => `Mostra ${i} di ${n}`,\n picker: 'Scegli cosa mostrare',\n};\n\nexport interface CarouselOwnProps extends PartsProps<\n 'track' | 'slide' | 'controls' | 'previous' | 'next' | 'dot'\n> {\n /** What it shows (\"Foto del prodotto\"): the name of the carousel. */\n label: string;\n /** The slides: one per child (a Stage, an image…). */\n children: ReactNode;\n /** Slide shown, from 0. */\n index?: number;\n /** Default 0. */\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n /** Above this many slides the dots (44px targets each) become a \"2 / 12\" counter. Default 5, which fits a phone. */\n maxDots?: number;\n labels?: Partial<CarouselLabels>;\n}\n\nexport type CarouselProps<E extends ElementType = 'section'> = PolymorphicProps<\n E,\n CarouselOwnProps\n>;\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/** Slide nearest to the track's scroll position (-1 when the track has no layout). */\nfunction visible(track: HTMLElement): number {\n const width = track.clientWidth;\n return width ? Math.round(Math.abs(track.scrollLeft) / width) : -1;\n}\n\n/**\n * Media carousel: one slide at a time on a scroll-snap track (swipe on touch, arrow keys on the focused track), with\n * previous / next and a dot per slide (the current one is a longer pill). It never moves by itself; hidden slides are\n * inert, the shown one is announced politely.\n */\nexport function Carousel<E extends ElementType = 'section'>(props: CarouselProps<E>) {\n const {\n as,\n css,\n className,\n label,\n children,\n index: indexProp,\n defaultIndex = 0,\n onIndexChange,\n maxDots = 5,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Carousel', props as CarouselProps);\n const labels = { ...CAROUSEL_LABELS, ...labelsProp };\n const slides = Children.toArray(children);\n const count = slides.length;\n const [raw, setIndex] = useControlled({\n value: indexProp,\n defaultValue: defaultIndex,\n onChange: onIndexChange,\n });\n const index = Math.min(Math.max(0, count - 1), Math.max(0, raw));\n const trackId = `${useId()}-track`;\n /** Slide a programmatic scroll is heading to: the scroll events on the way do not change the index. */\n const heading = useRef<{ to: number; until: number } | null>(null);\n const Root = (as ?? 'section') as ElementType;\n const styled = useCss('Carousel', 'root', css);\n const { part, style } = useParts('Carousel', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n // The index changed (buttons, keys, a controlled value): bring that slide into view.\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t || visible(t) === index) return;\n const slide = t.children[index] as HTMLElement | undefined;\n if (!slide) return;\n heading.current = { to: index, until: performance.now() + 1000 };\n t.scrollTo?.({ left: slide.offsetLeft, behavior: reduced() ? 'auto' : 'smooth' });\n }, [index, trackId]);\n\n const go = (to: number) => {\n const next = Math.min(count - 1, Math.max(0, to));\n if (next !== index) setIndex(next);\n };\n\n // Swipes and scrolling: the slide that snapped into view becomes the current one.\n const latest = useRef({ index, count, setIndex });\n useEffect(() => {\n latest.current = { index, count, setIndex };\n });\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t) return;\n const onScroll = (e: Event) => {\n const at = visible(t);\n const h = heading.current;\n if (h) {\n if (at === h.to || e.timeStamp > h.until) heading.current = null;\n else return;\n }\n const { index: now, count: n, setIndex: set } = latest.current;\n if (at >= 0 && at < n && at !== now) set(at);\n };\n t.addEventListener('scroll', onScroll, { passive: true });\n return () => t.removeEventListener('scroll', onScroll);\n }, [trackId]);\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.target !== e.currentTarget) return;\n const rtl = getComputedStyle(e.currentTarget).direction === 'rtl';\n const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;\n if (step) go(index + (rtl ? -step : step));\n else if (e.key === 'Home') go(0);\n else if (e.key === 'End') go(count - 1);\n else return;\n e.preventDefault();\n };\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-carousel', styled.className, className)}\n aria-roledescription=\"carousel\"\n aria-label={label}\n {...root}\n >\n {part('track', 'div', {\n id: trackId,\n className: 'slurp-carousel-track',\n tabIndex: 0,\n 'aria-live': 'polite',\n onKeyDown,\n children: slides.map((s, i) => (\n <Fragment key={i}>\n {part('slide', 'div', {\n role: 'group',\n 'aria-roledescription': 'slide',\n 'aria-label': labels.slide(i + 1, count),\n className: 'slurp-carousel-slide',\n 'data-current': i === index ? '' : undefined,\n inert: i !== index,\n children: s,\n })}\n </Fragment>\n )),\n })}\n {count > 1 &&\n part('controls', 'div', {\n className: 'slurp-carousel-controls',\n children: (\n <>\n {part('previous', Bubble, {\n className: 'slurp-carousel-previous',\n label: labels.previous,\n appearance: 'soft',\n disabled: index === 0,\n onClick: () => go(index - 1),\n children: <ChevronLeftIcon size={20} />,\n })}\n {count <= maxDots ? (\n <div className=\"slurp-carousel-dots\" role=\"group\" aria-label={labels.picker}>\n {slides.map((_, i) => (\n <Fragment key={i}>\n {part('dot', 'button', {\n type: 'button',\n className: 'slurp-carousel-dot',\n 'aria-label': labels.show(i + 1, count),\n 'aria-current': i === index ? 'true' : undefined,\n onClick: () => go(i),\n })}\n </Fragment>\n ))}\n </div>\n ) : (\n <span className=\"slurp-carousel-status\" aria-hidden=\"true\">\n {index + 1} / {count}\n </span>\n )}\n {part('next', Bubble, {\n className: 'slurp-carousel-next',\n label: labels.next,\n appearance: 'soft',\n disabled: index === count - 1,\n onClick: () => go(index + 1),\n children: <ChevronRightIcon size={20} />,\n })}\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AA8BA,MAAa,kBAAkC;CAC7C,UAAU;CACV,MAAM;CACN,QAAQ,GAAG,MAAM,GAAG,EAAE,MAAM;CAC5B,OAAO,GAAG,MAAM,UAAU,EAAE,MAAM;CAClC,QAAQ;AACV;AAwBA,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;AAGrF,SAAS,QAAQ,OAA4B;CAC3C,MAAM,QAAQ,MAAM;CACp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"Carousel.js","names":[],"sources":["../../src/Carousel/Carousel.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Children,\n Fragment,\n useEffect,\n useId,\n useRef,\n type ElementType,\n type KeyboardEvent,\n type ReactNode,\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';\n\nexport interface CarouselLabels {\n previous: string;\n next: string;\n /** Name of a slide (\"2 di 5\"). */\n slide: (index: number, count: number) => string;\n /** Name of the button of a slide (\"Mostra 2 di 5\"). */\n show: (index: number, count: number) => string;\n /** Name of the group of slide buttons. */\n picker: string;\n}\n\nexport const CAROUSEL_LABELS: CarouselLabels = {\n previous: 'Precedente',\n next: 'Successiva',\n slide: (i, n) => `${i} di ${n}`,\n show: (i, n) => `Mostra ${i} di ${n}`,\n picker: 'Scegli cosa mostrare',\n};\n\nexport interface CarouselOwnProps extends PartsProps<\n 'track' | 'slide' | 'controls' | 'previous' | 'next' | 'dot'\n> {\n /** What it shows (\"Foto del prodotto\"): the name of the carousel. */\n label: string;\n /** The slides: one per child (a Stage, an image…). */\n children: ReactNode;\n /** Slide shown, from 0. */\n index?: number;\n /** Default 0. */\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n /** Above this many slides the dots (44px targets each) become a \"2 / 12\" counter. Default 5, which fits a phone. */\n maxDots?: number;\n labels?: Partial<CarouselLabels>;\n}\n\nexport type CarouselProps<E extends ElementType = 'section'> = PolymorphicProps<\n E,\n CarouselOwnProps\n>;\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/** Slide nearest to the track's scroll position (-1 when the track has no layout). */\nfunction visible(track: HTMLElement): number {\n const width = track.clientWidth;\n return width ? Math.round(Math.abs(track.scrollLeft) / width) : -1;\n}\n\n/**\n * Media carousel: one slide at a time on a scroll-snap track (swipe on touch, arrow keys on the focused track), with\n * previous / next and a dot per slide (the current one is a longer pill). It never moves by itself; hidden slides are\n * inert, the shown one is announced politely.\n */\nexport function Carousel<E extends ElementType = 'section'>(props: CarouselProps<E>) {\n const {\n as,\n css,\n className,\n label,\n children,\n index: indexProp,\n defaultIndex = 0,\n onIndexChange,\n maxDots = 5,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Carousel', props as CarouselProps);\n const labels = { ...CAROUSEL_LABELS, ...useLabels('Carousel'), ...labelsProp };\n const slides = Children.toArray(children);\n const count = slides.length;\n const [raw, setIndex] = useControlled({\n value: indexProp,\n defaultValue: defaultIndex,\n onChange: onIndexChange,\n });\n const index = Math.min(Math.max(0, count - 1), Math.max(0, raw));\n const trackId = `${useId()}-track`;\n /** Slide a programmatic scroll is heading to: the scroll events on the way do not change the index. */\n const heading = useRef<{ to: number; until: number } | null>(null);\n const Root = (as ?? 'section') as ElementType;\n const styled = useCss('Carousel', 'root', css);\n const { part, style } = useParts('Carousel', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n // The index changed (buttons, keys, a controlled value): bring that slide into view.\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t || visible(t) === index) return;\n const slide = t.children[index] as HTMLElement | undefined;\n if (!slide) return;\n heading.current = { to: index, until: performance.now() + 1000 };\n t.scrollTo?.({ left: slide.offsetLeft, behavior: reduced() ? 'auto' : 'smooth' });\n }, [index, trackId]);\n\n const go = (to: number) => {\n const next = Math.min(count - 1, Math.max(0, to));\n if (next !== index) setIndex(next);\n };\n\n // Swipes and scrolling: the slide that snapped into view becomes the current one.\n const latest = useRef({ index, count, setIndex });\n useEffect(() => {\n latest.current = { index, count, setIndex };\n });\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t) return;\n const onScroll = (e: Event) => {\n const at = visible(t);\n const h = heading.current;\n if (h) {\n if (at === h.to || e.timeStamp > h.until) heading.current = null;\n else return;\n }\n const { index: now, count: n, setIndex: set } = latest.current;\n if (at >= 0 && at < n && at !== now) set(at);\n };\n t.addEventListener('scroll', onScroll, { passive: true });\n return () => t.removeEventListener('scroll', onScroll);\n }, [trackId]);\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.target !== e.currentTarget) return;\n const rtl = getComputedStyle(e.currentTarget).direction === 'rtl';\n const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;\n if (step) go(index + (rtl ? -step : step));\n else if (e.key === 'Home') go(0);\n else if (e.key === 'End') go(count - 1);\n else return;\n e.preventDefault();\n };\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-carousel', styled.className, className)}\n aria-roledescription=\"carousel\"\n aria-label={label}\n {...root}\n >\n {part('track', 'div', {\n id: trackId,\n className: 'slurp-carousel-track',\n tabIndex: 0,\n 'aria-live': 'polite',\n onKeyDown,\n children: slides.map((s, i) => (\n <Fragment key={i}>\n {part('slide', 'div', {\n role: 'group',\n 'aria-roledescription': 'slide',\n 'aria-label': labels.slide(i + 1, count),\n className: 'slurp-carousel-slide',\n 'data-current': i === index ? '' : undefined,\n inert: i !== index,\n children: s,\n })}\n </Fragment>\n )),\n })}\n {count > 1 &&\n part('controls', 'div', {\n className: 'slurp-carousel-controls',\n children: (\n <>\n {part('previous', Bubble, {\n className: 'slurp-carousel-previous',\n label: labels.previous,\n appearance: 'soft',\n disabled: index === 0,\n onClick: () => go(index - 1),\n children: <ChevronLeftIcon size={20} />,\n })}\n {count <= maxDots ? (\n <div className=\"slurp-carousel-dots\" role=\"group\" aria-label={labels.picker}>\n {slides.map((_, i) => (\n <Fragment key={i}>\n {part('dot', 'button', {\n type: 'button',\n className: 'slurp-carousel-dot',\n 'aria-label': labels.show(i + 1, count),\n 'aria-current': i === index ? 'true' : undefined,\n onClick: () => go(i),\n })}\n </Fragment>\n ))}\n </div>\n ) : (\n <span className=\"slurp-carousel-status\" aria-hidden=\"true\">\n {index + 1} / {count}\n </span>\n )}\n {part('next', Bubble, {\n className: 'slurp-carousel-next',\n label: labels.next,\n appearance: 'soft',\n disabled: index === count - 1,\n onClick: () => go(index + 1),\n children: <ChevronRightIcon size={20} />,\n })}\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAa,kBAAkC;CAC7C,UAAU;CACV,MAAM;CACN,QAAQ,GAAG,MAAM,GAAG,EAAE,MAAM;CAC5B,OAAO,GAAG,MAAM,UAAU,EAAE,MAAM;CAClC,QAAQ;AACV;AAwBA,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;AAGrF,SAAS,QAAQ,OAA4B;CAC3C,MAAM,QAAQ,MAAM;CACpB,OAAO,QAAQ,KAAK,MAAM,KAAK,IAAI,MAAM,UAAU,IAAI,KAAK,IAAI;AAClE;;;;;;AAOA,SAAgB,SAA4C,OAAyB;CACnF,MAAM,EACJ,IACA,KACA,WACA,OACA,UACA,OAAO,WACP,eAAe,GACf,eACA,UAAU,GACV,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,SAAS,SAAS,QAAQ,QAAQ;CACxC,MAAM,QAAQ,OAAO;CACrB,MAAM,CAAC,KAAK,YAAY,cAAc;EACpC,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,QAAQ,CAAC,GAAG,KAAK,IAAI,GAAG,GAAG,CAAC;CAC/D,MAAM,UAAU,GAAG,MAAM,EAAE;;CAE3B,MAAM,UAAU,OAA6C,IAAI;CACjE,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,YAAY,QAAQ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AAC,UAAD,EAAA,UACG,KAAK,OAAO,UAAU;OACrB,MAAM;OACN,WAAW;OACX,cAAc,OAAO,KAAK,IAAI,GAAG,KAAK;OACtC,gBAAgB,MAAM,QAAQ,SAAS,KAAA;OACvC,eAAe,GAAG,CAAC;MACrB,CAAC,EACO,GARK,CAQL,CACX;KACE,CAAA,IAEL,qBAAC,QAAD;MAAM,WAAU;MAAwB,eAAY;MAApD,UAAA;OACG,QAAQ;OAAE;OAAI;MACX;;KAEP,KAAK,QAAQ,QAAQ;MACpB,WAAW;MACX,OAAO,OAAO;MACd,YAAY;MACZ,UAAU,UAAU,QAAQ;MAC5B,eAAe,GAAG,QAAQ,CAAC;MAC3B,UAAU,oBAAC,kBAAD,EAAkB,MAAM,GAAK,CAAA;KACzC,CAAC;IACD,EAAA,CAAA;GAEN,CAAC,CACC;;CACN,EAAA,CAAA;AAEN"}
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import { useLabels } from "../internal/labels.js";
2
3
  import { cx } from "../utils/src/index.js";
3
4
  import { useAnimationRoot } from "../internal/animation.js";
4
5
  import { useCss, useThemeProps } from "../internal/styled.js";
@@ -18,6 +19,7 @@ function Choice(props) {
18
19
  const { as, css, className, label, options, value: valueProp, defaultValue = null, onValueChange, name, disabled, width = 280, placement, labels: labelsProp, ...rest } = useThemeProps("Choice", props);
19
20
  const labels = {
20
21
  ...CHOICE_LABELS,
22
+ ...useLabels("Choice"),
21
23
  ...labelsProp
22
24
  };
23
25
  const [value, setValue] = useControlled({