@slurp-ui/react 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/dist/AvatarGroup/AvatarGroup.d.ts +26 -0
- package/dist/AvatarGroup/AvatarGroup.js +46 -0
- package/dist/AvatarGroup/AvatarGroup.js.map +1 -0
- package/dist/AvatarGroup/index.d.ts +3 -0
- package/dist/AvatarGroup/index.js +2 -0
- package/dist/Bloom/Bloom.js +3 -2
- package/dist/Bloom/Bloom.js.map +1 -1
- package/dist/Calendar/Calendar.d.ts +42 -0
- package/dist/Calendar/Calendar.js +178 -0
- package/dist/Calendar/Calendar.js.map +1 -0
- package/dist/Calendar/dates.d.ts +3 -0
- package/dist/Calendar/dates.js +46 -0
- package/dist/Calendar/dates.js.map +1 -0
- package/dist/Calendar/index.d.ts +3 -0
- package/dist/Calendar/index.js +2 -0
- package/dist/Carousel/Carousel.js +2 -0
- package/dist/Carousel/Carousel.js.map +1 -1
- package/dist/Choice/Choice.js +2 -0
- package/dist/Choice/Choice.js.map +1 -1
- package/dist/Code/Code.d.ts +38 -0
- package/dist/Code/Code.js +82 -0
- package/dist/Code/Code.js.map +1 -0
- package/dist/Code/index.d.ts +3 -0
- package/dist/Code/index.js +2 -0
- package/dist/Compare/Compare.d.ts +23 -0
- package/dist/Compare/Compare.js +61 -0
- package/dist/Compare/Compare.js.map +1 -0
- package/dist/Compare/index.d.ts +3 -0
- package/dist/Compare/index.js +2 -0
- package/dist/Consent/Consent.d.ts +30 -0
- package/dist/Consent/Consent.js +70 -0
- package/dist/Consent/Consent.js.map +1 -0
- package/dist/Consent/index.d.ts +3 -0
- package/dist/Consent/index.js +2 -0
- package/dist/Contents/Contents.d.ts +35 -0
- package/dist/Contents/Contents.js +63 -0
- package/dist/Contents/Contents.js.map +1 -0
- package/dist/Contents/index.d.ts +3 -0
- package/dist/Contents/index.js +2 -0
- package/dist/DateField/DateField.d.ts +29 -0
- package/dist/DateField/DateField.js +118 -0
- package/dist/DateField/DateField.js.map +1 -0
- package/dist/DateField/index.d.ts +3 -0
- package/dist/DateField/index.js +2 -0
- package/dist/Dialog/Dialog.d.ts +2 -0
- package/dist/Dialog/Dialog.js +89 -30
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dock/Dock.d.ts +5 -0
- package/dist/Dock/Dock.js +13 -2
- package/dist/Dock/Dock.js.map +1 -1
- package/dist/ErrorSummary/ErrorSummary.d.ts +26 -0
- package/dist/ErrorSummary/ErrorSummary.js +68 -0
- package/dist/ErrorSummary/ErrorSummary.js.map +1 -0
- package/dist/ErrorSummary/index.d.ts +3 -0
- package/dist/ErrorSummary/index.js +2 -0
- package/dist/FileDrop/FileDrop.d.ts +34 -0
- package/dist/FileDrop/FileDrop.js +145 -0
- package/dist/FileDrop/FileDrop.js.map +1 -0
- package/dist/FileDrop/index.d.ts +3 -0
- package/dist/FileDrop/index.js +2 -0
- package/dist/Filters/Filters.js +2 -0
- package/dist/Filters/Filters.js.map +1 -1
- package/dist/Footer/Footer.d.ts +37 -0
- package/dist/Footer/Footer.js +63 -0
- package/dist/Footer/Footer.js.map +1 -0
- package/dist/Footer/index.d.ts +3 -0
- package/dist/Footer/index.js +2 -0
- package/dist/Hairline/Hairline.d.ts +16 -0
- package/dist/Hairline/Hairline.js +23 -0
- package/dist/Hairline/Hairline.js.map +1 -0
- package/dist/Hairline/index.d.ts +3 -0
- package/dist/Hairline/index.js +2 -0
- package/dist/Hint/Hint.js +20 -1
- package/dist/Hint/Hint.js.map +1 -1
- package/dist/Kbd/Kbd.d.ts +7 -0
- package/dist/Kbd/Kbd.js +20 -0
- package/dist/Kbd/Kbd.js.map +1 -0
- package/dist/Kbd/index.d.ts +3 -0
- package/dist/Kbd/index.js +2 -0
- package/dist/Lightbox/Lightbox.d.ts +30 -0
- package/dist/Lightbox/Lightbox.js +74 -0
- package/dist/Lightbox/Lightbox.js.map +1 -0
- package/dist/Lightbox/index.d.ts +3 -0
- package/dist/Lightbox/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +5 -1
- package/dist/ListRow/ListRow.js +5 -1
- package/dist/ListRow/ListRow.js.map +1 -1
- package/dist/Media/Media.d.ts +28 -0
- package/dist/Media/Media.js +65 -0
- package/dist/Media/Media.js.map +1 -0
- package/dist/Media/index.d.ts +3 -0
- package/dist/Media/index.js +2 -0
- package/dist/Menu/Menu.d.ts +13 -0
- package/dist/Menu/Menu.js +43 -11
- package/dist/Menu/Menu.js.map +1 -1
- package/dist/Menu/index.d.ts +2 -2
- package/dist/Menu/index.js +1 -1
- package/dist/MultiSuggest/MultiSuggest.d.ts +39 -0
- package/dist/MultiSuggest/MultiSuggest.js +267 -0
- package/dist/MultiSuggest/MultiSuggest.js.map +1 -0
- package/dist/MultiSuggest/index.d.ts +3 -0
- package/dist/MultiSuggest/index.js +2 -0
- package/dist/Notice/Notice.js +2 -0
- package/dist/Notice/Notice.js.map +1 -1
- package/dist/NumberField/NumberField.d.ts +32 -0
- package/dist/NumberField/NumberField.js +126 -0
- package/dist/NumberField/NumberField.js.map +1 -0
- package/dist/NumberField/index.d.ts +3 -0
- package/dist/NumberField/index.js +2 -0
- package/dist/PageNav/PageNav.d.ts +25 -0
- package/dist/PageNav/PageNav.js +57 -0
- package/dist/PageNav/PageNav.js.map +1 -0
- package/dist/PageNav/index.d.ts +3 -0
- package/dist/PageNav/index.js +2 -0
- package/dist/Pages/Pages.js +2 -0
- package/dist/Pages/Pages.js.map +1 -1
- package/dist/PinField/PinField.d.ts +26 -0
- package/dist/PinField/PinField.js +73 -0
- package/dist/PinField/PinField.js.map +1 -0
- package/dist/PinField/index.d.ts +3 -0
- package/dist/PinField/index.js +2 -0
- package/dist/Prose/Prose.d.ts +15 -0
- package/dist/Prose/Prose.js +25 -0
- package/dist/Prose/Prose.js.map +1 -0
- package/dist/Prose/index.d.ts +3 -0
- package/dist/Prose/index.js +2 -0
- package/dist/Quote/Quote.d.ts +19 -0
- package/dist/Quote/Quote.js +52 -0
- package/dist/Quote/Quote.js.map +1 -0
- package/dist/Quote/index.d.ts +3 -0
- package/dist/Quote/index.js +2 -0
- package/dist/Rail/Rail.d.ts +37 -0
- package/dist/Rail/Rail.js +61 -0
- package/dist/Rail/Rail.js.map +1 -0
- package/dist/Rail/index.d.ts +3 -0
- package/dist/Rail/index.js +2 -0
- package/dist/Rating/Rating.js +2 -0
- package/dist/Rating/Rating.js.map +1 -1
- package/dist/Search/Search.js +2 -0
- package/dist/Search/Search.js.map +1 -1
- package/dist/SecretField/SecretField.d.ts +17 -0
- package/dist/SecretField/SecretField.js +59 -0
- package/dist/SecretField/SecretField.js.map +1 -0
- package/dist/SecretField/index.d.ts +3 -0
- package/dist/SecretField/index.js +2 -0
- package/dist/Settings/Settings.js +2 -0
- package/dist/Settings/Settings.js.map +1 -1
- package/dist/Sheet/Sheet.d.ts +8 -3
- package/dist/Sheet/Sheet.js +1 -1
- package/dist/Sheet/Sheet.js.map +1 -1
- package/dist/Sheet/index.d.ts +2 -2
- package/dist/SkipLink/SkipLink.d.ts +22 -0
- package/dist/SkipLink/SkipLink.js +32 -0
- package/dist/SkipLink/SkipLink.js.map +1 -0
- package/dist/SkipLink/index.d.ts +3 -0
- package/dist/SkipLink/index.js +2 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +7 -1
- package/dist/SlurpProvider/SlurpProvider.js +14 -6
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -1
- package/dist/Steps/Steps.js +2 -0
- package/dist/Steps/Steps.js.map +1 -1
- package/dist/Suggest/Suggest.js +2 -0
- package/dist/Suggest/Suggest.js.map +1 -1
- package/dist/Table/Table.d.ts +12 -0
- package/dist/Table/Table.js +56 -10
- package/dist/Table/Table.js.map +1 -1
- package/dist/Tag/Tag.d.ts +14 -0
- package/dist/Tag/Tag.js +26 -0
- package/dist/Tag/Tag.js.map +1 -0
- package/dist/Tag/index.d.ts +3 -0
- package/dist/Tag/index.js +2 -0
- package/dist/Timeline/Timeline.d.ts +23 -0
- package/dist/Timeline/Timeline.js +49 -0
- package/dist/Timeline/Timeline.js.map +1 -0
- package/dist/Timeline/index.d.ts +3 -0
- package/dist/Timeline/index.js +2 -0
- package/dist/Toast/Toast.js +31 -7
- package/dist/Toast/Toast.js.map +1 -1
- package/dist/Tree/Tree.d.ts +24 -0
- package/dist/Tree/Tree.js +113 -0
- package/dist/Tree/Tree.js.map +1 -0
- package/dist/Tree/index.d.ts +3 -0
- package/dist/Tree/index.js +2 -0
- package/dist/index.d.ts +63 -8
- package/dist/index.js +31 -2
- package/dist/internal/labels.js +12 -0
- package/dist/internal/labels.js.map +1 -0
- package/dist/lib/labels.d.ts +210 -0
- package/dist/lib/labels.js +139 -0
- package/dist/lib/labels.js.map +1 -0
- package/dist/lib/theme.d.ts +134 -4
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +1912 -138
- package/dist/tokens.css +9 -0
- package/dist/utils/focus.d.ts +1 -1
- package/dist/utils/focus.js +2 -2
- package/dist/utils/focus.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/useClipboard.d.ts +14 -0
- package/dist/utils/useClipboard.js +30 -0
- package/dist/utils/useClipboard.js.map +1 -0
- package/dist/utils/useScrollSpy.d.ts +14 -0
- package/dist/utils/useScrollSpy.js +27 -0
- package/dist/utils/useScrollSpy.js.map +1 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @slurp-ui/react
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 82f0410: New components: `MultiSuggest` (Suggest with several choices and removable tags), `Timeline`, `AvatarGroup` and `Consent` (a banner where refusing is as easy as accepting). `Table` gains row selection (`selectable`) and a fixed header (`maxHeight`). `Menu` gains `Menu.Group`, `Menu.Separator` and a `shortcut` on each item. `Sheet` can slide in from a side with `side="end"` or `"start"`.
|
|
8
|
+
- a38bda7: New components: `Tree` (nested list with full keyboard support), `Compare` (before and after slider) and `Lightbox` (pictures at full size in a modal). Right-to-left: every component stylesheet now uses logical properties (start/end instead of left/right), and the Switch, Toast and Lightbox movements mirror.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 56a8957: The last `Fold` of a group no longer draws a line under itself, so it does not meet the corners of a rounded container.
|
|
13
|
+
- 04c84d6: `Prose` paragraphs and list items use `text-wrap: pretty`, so a line never ends on a single word.
|
|
14
|
+
- Updated dependencies [efe26ec]
|
|
15
|
+
- @slurp-ui/icons@1.3.0
|
|
16
|
+
|
|
17
|
+
## 1.2.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- f6b705d: New components for content and navigation, for any site:
|
|
22
|
+
|
|
23
|
+
- `Prose`: typography for long text that arrives as HTML (Markdown, MDX, a CMS), on the design system's scale.
|
|
24
|
+
- `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).
|
|
25
|
+
- `Contents`: "on this page" links that follow the section being read.
|
|
26
|
+
- `Rail` (`Rail.Group`, `Rail.Link`): vertical navigation in groups for wide screens, the current page highlighted.
|
|
27
|
+
- `PageNav`: previous and next page at the end of a sequence, with your router's link.
|
|
28
|
+
- `SkipLink`: "skip to content", visible on keyboard focus.
|
|
29
|
+
- `Hairline`: a 1px separator, decorative by default.
|
|
30
|
+
- Hooks `useClipboard` and `useScrollSpy`. English texts for the new components in `labelsEn`.
|
|
31
|
+
|
|
32
|
+
- 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.
|
|
33
|
+
- a5cdf08: Texts in other languages and components that hold up in narrow spaces:
|
|
34
|
+
|
|
35
|
+
- `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.
|
|
36
|
+
- 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`).
|
|
37
|
+
- 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.
|
|
38
|
+
- Tile: long titles break with a hyphen where the page language allows it, instead of anywhere.
|
|
39
|
+
|
|
40
|
+
- 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: … }}`.
|
|
41
|
+
- `Code`: the scrollable block is a named group instead of a region, so a page with many code blocks keeps unique landmarks.
|
|
42
|
+
- Dock: the phone search pill's accessible name includes its visible placeholder (WCAG 2.5.3).
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 6557e10: Finish the motion of panels and notifications:
|
|
47
|
+
|
|
48
|
+
- 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.
|
|
49
|
+
- 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.
|
|
50
|
+
- 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.
|
|
51
|
+
- Reduced motion keeps colour, opacity and shadow transitions in every component and drops only movement and size changes.
|
|
52
|
+
|
|
53
|
+
- 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).
|
|
54
|
+
- Updated dependencies [f6b705d]
|
|
55
|
+
- Updated dependencies [fc030e1]
|
|
56
|
+
- @slurp-ui/icons@1.2.0
|
|
57
|
+
- @slurp-ui/tokens@1.2.0
|
|
58
|
+
|
|
3
59
|
## 1.1.1
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { AvatarOwnProps } from "../Avatar/Avatar.js";
|
|
4
|
+
import { ElementType } from "react";
|
|
5
|
+
export interface AvatarGroupLabels {
|
|
6
|
+
/** Names the "+N" counter: `more(3)` → "altre 3 persone". */
|
|
7
|
+
more: (count: number) => string;
|
|
8
|
+
}
|
|
9
|
+
export declare const AVATAR_GROUP_LABELS: AvatarGroupLabels;
|
|
10
|
+
export interface AvatarGroupOwnProps {
|
|
11
|
+
/** The people: a name each, a photo when there is one. */
|
|
12
|
+
people: {
|
|
13
|
+
name: string;
|
|
14
|
+
src?: string;
|
|
15
|
+
}[];
|
|
16
|
+
/** Most avatars shown before the "+N" counter. Default 4. */
|
|
17
|
+
max?: number;
|
|
18
|
+
size?: AvatarOwnProps['size'];
|
|
19
|
+
/** Names the group (who they are: "Partecipanti"). */
|
|
20
|
+
label?: string;
|
|
21
|
+
labels?: Partial<AvatarGroupLabels>;
|
|
22
|
+
}
|
|
23
|
+
export type AvatarGroupProps<E extends ElementType = 'div'> = PolymorphicProps<E, AvatarGroupOwnProps>;
|
|
24
|
+
/** Overlapping avatars of the people in a group, with a "+N" counter for the rest. */
|
|
25
|
+
export declare function AvatarGroup<E extends ElementType = 'div'>(props: AvatarGroupProps<E>): import("react").JSX.Element;
|
|
26
|
+
//# sourceMappingURL=AvatarGroup.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { Avatar } from "../Avatar/Avatar.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/AvatarGroup/AvatarGroup.tsx
|
|
9
|
+
const AVATAR_GROUP_LABELS = { more: (n) => n === 1 ? "un’altra persona" : `altre ${n} persone` };
|
|
10
|
+
/** Overlapping avatars of the people in a group, with a "+N" counter for the rest. */
|
|
11
|
+
function AvatarGroup(props) {
|
|
12
|
+
const { as, css, className, people, max = 4, size = "md", label, labels: labelsProp, ...rest } = useThemeProps("AvatarGroup", props);
|
|
13
|
+
const labels = {
|
|
14
|
+
...AVATAR_GROUP_LABELS,
|
|
15
|
+
...useLabels("AvatarGroup"),
|
|
16
|
+
...labelsProp
|
|
17
|
+
};
|
|
18
|
+
const Root = as ?? "div";
|
|
19
|
+
const styled = useCss("AvatarGroup", "root", css);
|
|
20
|
+
const root = useAnimationRoot(rest);
|
|
21
|
+
const shown = people.slice(0, Math.max(1, max));
|
|
22
|
+
const hidden = people.length - shown.length;
|
|
23
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
24
|
+
role: "group",
|
|
25
|
+
"aria-label": label,
|
|
26
|
+
className: cx("slurp-avatargroup", styled.className, className),
|
|
27
|
+
"data-size": size,
|
|
28
|
+
...root,
|
|
29
|
+
children: [shown.map((p) => /* @__PURE__ */ jsx(Avatar, {
|
|
30
|
+
name: p.name,
|
|
31
|
+
src: p.src,
|
|
32
|
+
size
|
|
33
|
+
}, p.name)), hidden > 0 && /* @__PURE__ */ jsx("span", {
|
|
34
|
+
className: "slurp-avatargroup-more",
|
|
35
|
+
role: "img",
|
|
36
|
+
"aria-label": labels.more(hidden),
|
|
37
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
children: ["+", hidden]
|
|
40
|
+
})
|
|
41
|
+
})]
|
|
42
|
+
})] });
|
|
43
|
+
}
|
|
44
|
+
export { AVATAR_GROUP_LABELS, AvatarGroup };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=AvatarGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AvatarGroup.js","names":[],"sources":["../../src/AvatarGroup/AvatarGroup.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType } from 'react';\n\nimport { Avatar, type AvatarOwnProps } from '../Avatar/Avatar';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface AvatarGroupLabels {\n /** Names the \"+N\" counter: `more(3)` → \"altre 3 persone\". */\n more: (count: number) => string;\n}\n\nexport const AVATAR_GROUP_LABELS: AvatarGroupLabels = {\n more: (n) => (n === 1 ? 'un’altra persona' : `altre ${n} persone`),\n};\n\nexport interface AvatarGroupOwnProps {\n /** The people: a name each, a photo when there is one. */\n people: { name: string; src?: string }[];\n /** Most avatars shown before the \"+N\" counter. Default 4. */\n max?: number;\n size?: AvatarOwnProps['size'];\n /** Names the group (who they are: \"Partecipanti\"). */\n label?: string;\n labels?: Partial<AvatarGroupLabels>;\n}\n\nexport type AvatarGroupProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n AvatarGroupOwnProps\n>;\n\n/** Overlapping avatars of the people in a group, with a \"+N\" counter for the rest. */\nexport function AvatarGroup<E extends ElementType = 'div'>(props: AvatarGroupProps<E>) {\n const {\n as,\n css,\n className,\n people,\n max = 4,\n size = 'md',\n label,\n labels: labelsProp,\n ...rest\n } = useThemeProps('AvatarGroup', props as AvatarGroupProps);\n const labels = { ...AVATAR_GROUP_LABELS, ...useLabels('AvatarGroup'), ...labelsProp };\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('AvatarGroup', 'root', css);\n const root = useAnimationRoot(rest);\n const shown = people.slice(0, Math.max(1, max));\n const hidden = people.length - shown.length;\n return (\n <>\n {styled.style}\n <Root\n role=\"group\"\n aria-label={label}\n className={cx('slurp-avatargroup', styled.className, className)}\n data-size={size}\n {...root}\n >\n {shown.map((p) => (\n <Avatar key={p.name} name={p.name} src={p.src} size={size} />\n ))}\n {hidden > 0 && (\n <span className=\"slurp-avatargroup-more\" role=\"img\" aria-label={labels.more(hidden)}>\n <span aria-hidden=\"true\">+{hidden}</span>\n </span>\n )}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,sBAAyC,EACpD,OAAO,MAAO,MAAM,IAAI,qBAAqB,SAAS,EAAE,UAC1D;;AAmBA,SAAgB,YAA2C,OAA4B;CACrF,MAAM,EACJ,IACA,KACA,WACA,QACA,MAAM,GACN,OAAO,MACP,OACA,QAAQ,YACR,GAAG,SACD,cAAc,eAAe,KAAyB;CAC1D,MAAM,SAAS;EAAE,GAAG;EAAqB,GAAG,UAAU,aAAa;EAAG,GAAG;CAAW;CACpF,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,eAAe,QAAQ,GAAG;CAChD,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,OAAO,MAAM,GAAG,KAAK,IAAI,GAAG,GAAG,CAAC;CAC9C,MAAM,SAAS,OAAO,SAAS,MAAM;CACrC,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,MAAK;EACL,cAAY;EACZ,WAAW,GAAG,qBAAqB,OAAO,WAAW,SAAS;EAC9D,aAAW;EACX,GAAI;EALN,UAAA,CAOG,MAAM,KAAK,MACV,oBAAC,QAAD;GAAqB,MAAM,EAAE;GAAM,KAAK,EAAE;GAAW;EAAO,GAA/C,EAAE,IAA6C,CAC7D,GACA,SAAS,KACR,oBAAC,QAAD;GAAM,WAAU;GAAyB,MAAK;GAAM,cAAY,OAAO,KAAK,MAAM;GAChF,UAAA,qBAAC,QAAD;IAAM,eAAY;IAAlB,UAAA,CAAyB,KAAE,MAAa;;EACpC,CAAA,CAEJ;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
package/dist/Bloom/Bloom.js
CHANGED
|
@@ -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:
|
|
13
|
-
const DURATION =
|
|
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
|
/**
|
package/dist/Bloom/Bloom.js.map
CHANGED
|
@@ -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;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,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"}
|
|
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,WAA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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,YAAY,OACZ,QAAQ,YACR,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,EAAE,WAAW,SAAS;CAC5B,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,MAAMA,MAAS;CACrB,MAAM,CAAC,SAAS,cAAc,eAAuB,gBAAgB,QAAQ,KAAK,KAAK,GAAG;CAE1F,MAAM,YAAY,OAAO,SAAS;CAClC,MAAM,KAAK,MAAM;CACjB,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,YAAY,QAAQ,GAAG;CAC7C,MAAM,OAAO,iBAAiB,IAAI;CAElC,MAAM,QAAQ,QAAQ,OAAO;CAC7B,MAAM,QAAQ,cAAc,UAAU,OAAO,YAAY,GAAG,CAAC,OAAO,YAAY,CAAC;CACjF,MAAM,MAAM,eACH;EACL,OAAO,IAAI,KAAK,eAAe,QAAQ;GA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AAA,CACF;EACH,CAAA,CAAA;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -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"}
|
|
@@ -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);
|