@lanfermann/ui 0.0.0-stage → 0.1.1

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 (216) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +17 -2
  3. package/TRADEMARK.md +10 -0
  4. package/brand/app-icon.svg +1 -0
  5. package/brand/avatar.svg +1 -0
  6. package/brand/favicon.svg +1 -0
  7. package/dist/components/accordion/accordion.d.ts +26 -0
  8. package/dist/components/accordion/accordion.js +78 -0
  9. package/dist/components/alert/alert.d.ts +19 -0
  10. package/dist/components/alert/alert.js +68 -0
  11. package/dist/components/alert-dialog/alert-dialog.d.ts +20 -0
  12. package/dist/components/alert-dialog/alert-dialog.js +75 -0
  13. package/dist/components/anchor-heading/anchor-heading.d.ts +19 -0
  14. package/dist/components/anchor-heading/anchor-heading.js +39 -0
  15. package/dist/components/avatar/avatar.d.ts +14 -0
  16. package/dist/components/avatar/avatar.js +42 -0
  17. package/dist/components/badge/badge.d.ts +12 -0
  18. package/dist/components/badge/badge.js +27 -0
  19. package/dist/components/breadcrumbs/breadcrumbs.d.ts +23 -0
  20. package/dist/components/breadcrumbs/breadcrumbs.js +63 -0
  21. package/dist/components/button/button-variants.d.ts +15 -0
  22. package/dist/components/button/button-variants.js +76 -0
  23. package/dist/components/button/button.d.ts +25 -0
  24. package/dist/components/button/button.js +50 -0
  25. package/dist/components/calendar/calendar-selection.js +216 -0
  26. package/dist/components/calendar/calendar.d.ts +44 -0
  27. package/dist/components/calendar/calendar.js +208 -0
  28. package/dist/components/callout/callout.d.ts +21 -0
  29. package/dist/components/callout/callout.js +75 -0
  30. package/dist/components/card/card.d.ts +16 -0
  31. package/dist/components/card/card.js +53 -0
  32. package/dist/components/checkbox/checkbox.d.ts +9 -0
  33. package/dist/components/checkbox/checkbox.js +33 -0
  34. package/dist/components/checkbox-group/checkbox-group.d.ts +18 -0
  35. package/dist/components/checkbox-group/checkbox-group.js +33 -0
  36. package/dist/components/code/code.d.ts +7 -0
  37. package/dist/components/code/code.js +16 -0
  38. package/dist/components/code-block/code-block-frame.js +146 -0
  39. package/dist/components/code-block/code-block-live.d.ts +45 -0
  40. package/dist/components/code-block/code-block-live.js +51 -0
  41. package/dist/components/code-block/code-block.d.ts +36 -0
  42. package/dist/components/code-block/code-block.js +51 -0
  43. package/dist/components/code-block/code-copy.d.ts +12 -0
  44. package/dist/components/code-block/code-copy.js +71 -0
  45. package/dist/components/code-block/code-lines-view.d.ts +16 -0
  46. package/dist/components/code-block/code-lines-view.js +48 -0
  47. package/dist/components/code-block/code-lines.js +17 -0
  48. package/dist/components/code-block/code-scroll.js +29 -0
  49. package/dist/components/code-block/code-surface.js +13 -0
  50. package/dist/components/code-block/code-tabs-frame.js +85 -0
  51. package/dist/components/code-block/code-tabs-store.js +25 -0
  52. package/dist/components/code-block/code-tabs.d.ts +28 -0
  53. package/dist/components/code-block/code-tabs.js +29 -0
  54. package/dist/components/code-block/highlight.d.ts +34 -0
  55. package/dist/components/code-block/highlight.js +258 -0
  56. package/dist/components/code-block/lines.d.ts +5 -0
  57. package/dist/components/code-block/lines.js +40 -0
  58. package/dist/components/collapsible/collapsible.d.ts +19 -0
  59. package/dist/components/collapsible/collapsible.js +54 -0
  60. package/dist/components/combobox/combobox.d.ts +84 -0
  61. package/dist/components/combobox/combobox.js +169 -0
  62. package/dist/components/container/container.d.ts +16 -0
  63. package/dist/components/container/container.js +30 -0
  64. package/dist/components/copy-pill/copy-pill.d.ts +52 -0
  65. package/dist/components/copy-pill/copy-pill.js +232 -0
  66. package/dist/components/cta/cta.d.ts +109 -0
  67. package/dist/components/cta/cta.js +375 -0
  68. package/dist/components/date-field/date-field.d.ts +40 -0
  69. package/dist/components/date-field/date-field.js +99 -0
  70. package/dist/components/date-range-field/date-range-field.d.ts +41 -0
  71. package/dist/components/date-range-field/date-range-field.js +155 -0
  72. package/dist/components/dialog/dialog.d.ts +29 -0
  73. package/dist/components/dialog/dialog.js +96 -0
  74. package/dist/components/docs-layout/docs-layout.d.ts +17 -0
  75. package/dist/components/docs-layout/docs-layout.js +46 -0
  76. package/dist/components/drawer/drawer.d.ts +39 -0
  77. package/dist/components/drawer/drawer.js +181 -0
  78. package/dist/components/field/field.d.ts +18 -0
  79. package/dist/components/field/field.js +77 -0
  80. package/dist/components/fieldset/fieldset.d.ts +8 -0
  81. package/dist/components/fieldset/fieldset.js +25 -0
  82. package/dist/components/figure/figure.d.ts +14 -0
  83. package/dist/components/figure/figure.js +35 -0
  84. package/dist/components/form/form.d.ts +31 -0
  85. package/dist/components/form/form.js +55 -0
  86. package/dist/components/ground/ground.d.ts +20 -0
  87. package/dist/components/ground/ground.js +31 -0
  88. package/dist/components/heading/heading.d.ts +16 -0
  89. package/dist/components/heading/heading.js +36 -0
  90. package/dist/components/icon/icon.d.ts +22 -0
  91. package/dist/components/icon/icon.js +24 -0
  92. package/dist/components/input/input.d.ts +19 -0
  93. package/dist/components/input/input.js +46 -0
  94. package/dist/components/input-group/input-group.d.ts +34 -0
  95. package/dist/components/input-group/input-group.js +61 -0
  96. package/dist/components/kbd/kbd.d.ts +6 -0
  97. package/dist/components/kbd/kbd.js +15 -0
  98. package/dist/components/link/link-variants.d.ts +13 -0
  99. package/dist/components/link/link-variants.js +27 -0
  100. package/dist/components/link/link.d.ts +9 -0
  101. package/dist/components/link/link.js +18 -0
  102. package/dist/components/logo/logo-paths.js +22 -0
  103. package/dist/components/logo/logomark.d.ts +19 -0
  104. package/dist/components/logo/logomark.js +49 -0
  105. package/dist/components/logo/wordmark.d.ts +35 -0
  106. package/dist/components/logo/wordmark.js +48 -0
  107. package/dist/components/menu/menu.d.ts +26 -0
  108. package/dist/components/menu/menu.js +132 -0
  109. package/dist/components/meter/meter.d.ts +29 -0
  110. package/dist/components/meter/meter.js +68 -0
  111. package/dist/components/navigation-menu/navigation-menu-variants.d.ts +12 -0
  112. package/dist/components/navigation-menu/navigation-menu-variants.js +18 -0
  113. package/dist/components/navigation-menu/navigation-menu.d.ts +42 -0
  114. package/dist/components/navigation-menu/navigation-menu.js +128 -0
  115. package/dist/components/number-field/number-field.d.ts +32 -0
  116. package/dist/components/number-field/number-field.js +85 -0
  117. package/dist/components/page-header/page-header.d.ts +27 -0
  118. package/dist/components/page-header/page-header.js +48 -0
  119. package/dist/components/pager/pager.d.ts +24 -0
  120. package/dist/components/pager/pager.js +51 -0
  121. package/dist/components/parameter-list/parameter-list.d.ts +34 -0
  122. package/dist/components/parameter-list/parameter-list.js +70 -0
  123. package/dist/components/popover/popover.d.ts +15 -0
  124. package/dist/components/popover/popover.js +64 -0
  125. package/dist/components/progress/progress.d.ts +19 -0
  126. package/dist/components/progress/progress.js +67 -0
  127. package/dist/components/prose/prose.d.ts +13 -0
  128. package/dist/components/prose/prose.js +22 -0
  129. package/dist/components/quote/quote.d.ts +21 -0
  130. package/dist/components/quote/quote.js +46 -0
  131. package/dist/components/radio/radio.d.ts +12 -0
  132. package/dist/components/radio/radio.js +37 -0
  133. package/dist/components/reference-entry/reference-entry.d.ts +25 -0
  134. package/dist/components/reference-entry/reference-entry.js +66 -0
  135. package/dist/components/section/section.d.ts +13 -0
  136. package/dist/components/section/section.js +30 -0
  137. package/dist/components/segmented-control/segmented-control.d.ts +42 -0
  138. package/dist/components/segmented-control/segmented-control.js +413 -0
  139. package/dist/components/select/select.d.ts +70 -0
  140. package/dist/components/select/select.js +189 -0
  141. package/dist/components/separator/separator.d.ts +12 -0
  142. package/dist/components/separator/separator.js +29 -0
  143. package/dist/components/side-nav/side-nav.d.ts +48 -0
  144. package/dist/components/side-nav/side-nav.js +89 -0
  145. package/dist/components/site-footer/site-footer-floor.js +48 -0
  146. package/dist/components/site-footer/site-footer.d.ts +38 -0
  147. package/dist/components/site-footer/site-footer.js +96 -0
  148. package/dist/components/site-header/site-header.d.ts +77 -0
  149. package/dist/components/site-header/site-header.js +214 -0
  150. package/dist/components/slider/slider.d.ts +42 -0
  151. package/dist/components/slider/slider.js +279 -0
  152. package/dist/components/spinner/spinner.d.ts +15 -0
  153. package/dist/components/spinner/spinner.js +34 -0
  154. package/dist/components/switch/switch.d.ts +8 -0
  155. package/dist/components/switch/switch.js +28 -0
  156. package/dist/components/table/table.d.ts +83 -0
  157. package/dist/components/table/table.js +123 -0
  158. package/dist/components/table-of-contents/table-of-contents.d.ts +32 -0
  159. package/dist/components/table-of-contents/table-of-contents.js +187 -0
  160. package/dist/components/tabs/tabs.d.ts +28 -0
  161. package/dist/components/tabs/tabs.js +124 -0
  162. package/dist/components/text/text.d.ts +16 -0
  163. package/dist/components/text/text.js +63 -0
  164. package/dist/components/textarea/textarea.d.ts +19 -0
  165. package/dist/components/textarea/textarea.js +30 -0
  166. package/dist/components/time-field/time-field.d.ts +40 -0
  167. package/dist/components/time-field/time-field.js +123 -0
  168. package/dist/components/toast/toast.d.ts +55 -0
  169. package/dist/components/toast/toast.js +129 -0
  170. package/dist/components/tooltip/tooltip.d.ts +16 -0
  171. package/dist/components/tooltip/tooltip.js +41 -0
  172. package/dist/index.d.ts +79 -0
  173. package/dist/index.js +77 -0
  174. package/dist/internal/arrow.js +41 -0
  175. package/dist/internal/disclosure.js +20 -0
  176. package/dist/internal/field-context.js +21 -0
  177. package/dist/internal/field.d.ts +23 -0
  178. package/dist/internal/field.js +49 -0
  179. package/dist/internal/glyphs.js +84 -0
  180. package/dist/internal/iso-date.d.ts +2 -0
  181. package/dist/internal/iso-date.js +268 -0
  182. package/dist/internal/overlay.js +40 -0
  183. package/dist/internal/picker-sheet.js +74 -0
  184. package/dist/internal/popup.js +37 -0
  185. package/dist/internal/range-shape.js +295 -0
  186. package/dist/internal/reduced-motion.js +19 -0
  187. package/dist/internal/scroll-edges.js +45 -0
  188. package/dist/internal/trough.js +39 -0
  189. package/dist/internal/typed-input.d.ts +16 -0
  190. package/dist/internal/typed-input.js +133 -0
  191. package/dist/lib/cn.d.ts +11 -0
  192. package/dist/lib/cn.js +98 -0
  193. package/dist/motion/inertia.js +111 -0
  194. package/dist/motion/spring-step.js +35 -0
  195. package/dist/motion/springs.d.ts +78 -0
  196. package/dist/motion/springs.js +81 -0
  197. package/package.json +107 -4
  198. package/src/styles/base.css +93 -0
  199. package/src/styles/calendar.css +117 -0
  200. package/src/styles/code.css +252 -0
  201. package/src/styles/density.css +53 -0
  202. package/src/styles/depth.css +501 -0
  203. package/src/styles/grounds.css +191 -0
  204. package/src/styles/marks.css +50 -0
  205. package/src/styles/motion.css +55 -0
  206. package/src/styles/motion.generated.css +101 -0
  207. package/src/styles/prose.css +252 -0
  208. package/src/styles/radius.css +20 -0
  209. package/src/styles/segmented.css +208 -0
  210. package/src/styles/slider.css +110 -0
  211. package/src/styles/status.css +108 -0
  212. package/src/styles/tabs.css +39 -0
  213. package/src/styles/toast.css +106 -0
  214. package/src/styles/touch.css +41 -0
  215. package/src/styles/type.css +54 -0
  216. package/src/styles.css +38 -0
@@ -0,0 +1,76 @@
1
+ import { cva } from "class-variance-authority";
2
+ // src/components/button/button-variants.ts
3
+ /**
4
+ * The look of a button as class names. It lives outside the client component so Server Components
5
+ * can call it, e.g. for a link that should look like a button:
6
+ *
7
+ * <a href="/angebot" className={buttonVariants({ variant: "primary" })}>Angebot ansehen</a>
8
+ *
9
+ * (A link keeps its own semantics; do not render one through `Button`.)
10
+ */
11
+ const buttonVariants = cva([
12
+ "touch-target relative inline-flex shrink-0 items-center justify-center font-medium whitespace-nowrap select-none",
13
+ "transition-[box-shadow,background-color,color,scale] spring-seat",
14
+ "hover:spring-snap active:scale-(--motion-press-scale) active:spring-snap",
15
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
16
+ "data-disabled:pointer-events-none"
17
+ ], {
18
+ variants: {
19
+ variant: {
20
+ /** The committed action of a view: the dark key. */
21
+ primary: "bg-key depth-raised text-on-key depth-tone-key hover:bg-key-hover hover:depth-raised-hover active:bg-key-pressed active:depth-pressed",
22
+ /** Everything else that deserves a visible button. The default. */
23
+ secondary: "bg-raised depth-raised text-fg hover:depth-raised-hover active:bg-raised-pressed active:depth-pressed",
24
+ /** An action that should not compete: toolbars, rows, cancel. */
25
+ quiet: "text-fg hover:bg-hover active:bg-hover",
26
+ /** The ask. Indigo, at most once per view. */
27
+ ask: "bg-accent depth-raised text-on-accent depth-tone-accent hover:bg-accent-hover hover:depth-raised-hover active:bg-accent-pressed active:depth-pressed",
28
+ /** Confirms something irreversible. Only where the danger is real. */
29
+ danger: "bg-danger-solid depth-raised text-on-danger depth-tone-danger hover:depth-raised-hover active:depth-pressed"
30
+ },
31
+ size: {
32
+ sm: "h-(--control-sm) gap-1.5 rounded-sm px-(--control-pad-sm) text-sm",
33
+ md: "h-(--control-md) gap-2 rounded-md px-(--control-pad-md) text-control",
34
+ lg: "h-(--control-lg) gap-2 rounded-lg px-(--control-pad-lg) text-control"
35
+ },
36
+ /** A square button that holds one icon. */
37
+ iconOnly: {
38
+ true: "px-0",
39
+ false: ""
40
+ }
41
+ },
42
+ compoundVariants: [
43
+ {
44
+ iconOnly: true,
45
+ size: "sm",
46
+ class: "w-(--control-sm)"
47
+ },
48
+ {
49
+ iconOnly: true,
50
+ size: "md",
51
+ class: "w-(--control-md)"
52
+ },
53
+ {
54
+ iconOnly: true,
55
+ size: "lg",
56
+ class: "w-(--control-lg)"
57
+ }
58
+ ],
59
+ defaultVariants: {
60
+ variant: "secondary",
61
+ size: "md",
62
+ iconOnly: false
63
+ }
64
+ });
65
+ /**
66
+ * What a button looks like when it cannot be used: no gloss, no shadow, muted label. Left out
67
+ * while a button is loading, which is disabled too but should keep its colour.
68
+ */
69
+ const buttonDisabledLook = {
70
+ primary: "data-disabled:bg-disabled data-disabled:text-on-disabled data-disabled:depth-flat",
71
+ secondary: "data-disabled:bg-disabled data-disabled:text-on-disabled data-disabled:depth-flat",
72
+ quiet: "data-disabled:text-on-disabled",
73
+ ask: "data-disabled:bg-disabled data-disabled:text-on-disabled data-disabled:depth-flat",
74
+ danger: "data-disabled:bg-disabled data-disabled:text-on-disabled data-disabled:depth-flat"
75
+ };
76
+ export { buttonDisabledLook, buttonVariants };
@@ -0,0 +1,25 @@
1
+ import { ButtonVariants } from "./button-variants.js";
2
+ import { Button as Button$1 } from "@base-ui/react/button";
3
+ export type ButtonProps = Button$1.Props & Pick<ButtonVariants, "variant" | "size"> & {
4
+ /**
5
+ * The action is under way: a spinner replaces the label, the width stays, and the button
6
+ * cannot be pressed again. It keeps focus and its colour.
7
+ */
8
+ loading?: boolean;
9
+ } & ({
10
+ /** A square button for a single icon. It has no visible label, so it needs a name. */
11
+ iconOnly: true;
12
+ "aria-label": string;
13
+ } | {
14
+ iconOnly?: false;
15
+ });
16
+ /**
17
+ * A fitting: the one thing in the system that is pressed. It sits raised on a soft shadow under a
18
+ * gloss, goes down on pointer-down (`snap`) and seats back with a small bounce on release
19
+ * (`seat`). Heights and paddings come from the density (src/styles/density.css).
20
+ *
21
+ * Label it with what happens ("Angebot senden", not "OK"). Icons go inside as children, before
22
+ * the label: 14px in `sm`, 16px in `md`, 18px in `lg`. For a link that should look like a button,
23
+ * style an `<a>` with `buttonVariants()` instead of rendering one through `Button`.
24
+ */
25
+ export declare function Button({ className, variant, size, iconOnly, loading, disabled, focusableWhenDisabled, children, ...props }: ButtonProps): import("react").JSX.Element;
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { Spinner } from "../spinner/spinner.js";
3
+ import { mergeClassName } from "../../lib/cn.js";
4
+ import { buttonDisabledLook, buttonVariants } from "./button-variants.js";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import { Button as Button$1 } from "@base-ui/react/button";
7
+ // src/components/button/button.tsx
8
+ const spinnerSize = {
9
+ sm: 14,
10
+ md: 16,
11
+ lg: 18
12
+ };
13
+ /**
14
+ * A fitting: the one thing in the system that is pressed. It sits raised on a soft shadow under a
15
+ * gloss, goes down on pointer-down (`snap`) and seats back with a small bounce on release
16
+ * (`seat`). Heights and paddings come from the density (src/styles/density.css).
17
+ *
18
+ * Label it with what happens ("Angebot senden", not "OK"). Icons go inside as children, before
19
+ * the label: 14px in `sm`, 16px in `md`, 18px in `lg`. For a link that should look like a button,
20
+ * style an `<a>` with `buttonVariants()` instead of rendering one through `Button`.
21
+ */
22
+ function Button({ className, variant, size, iconOnly, loading = false, disabled, focusableWhenDisabled, children, ...props }) {
23
+ const resolvedVariant = variant ?? "secondary";
24
+ const resolvedSize = size ?? "md";
25
+ return /* @__PURE__ */ jsx(Button$1, {
26
+ "data-slot": "button",
27
+ "data-variant": resolvedVariant,
28
+ "data-size": resolvedSize,
29
+ "data-loading": loading ? "" : void 0,
30
+ "aria-busy": loading || void 0,
31
+ disabled: disabled || loading,
32
+ focusableWhenDisabled: focusableWhenDisabled ?? loading,
33
+ className: mergeClassName([buttonVariants({
34
+ variant,
35
+ size,
36
+ iconOnly
37
+ }), !loading && buttonDisabledLook[resolvedVariant]], className),
38
+ ...props,
39
+ children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
40
+ "data-slot": "button-label",
41
+ className: "inline-flex items-center gap-[inherit] opacity-0",
42
+ children
43
+ }), /* @__PURE__ */ jsx("span", {
44
+ "data-slot": "button-spinner",
45
+ className: "absolute inset-0 flex items-center justify-center transition-opacity duration-150 ease-out starting:opacity-0",
46
+ children: /* @__PURE__ */ jsx(Spinner, { size: spinnerSize[resolvedSize] })
47
+ })] }) : children
48
+ });
49
+ }
50
+ export { Button };
@@ -0,0 +1,216 @@
1
+ "use client";
2
+ import { toIsoDate } from "../../internal/iso-date.js";
3
+ import { gridDays, pixelPoints, polygonPoints, rangeInGrid, rangeOutline, spanOutline } from "../../internal/range-shape.js";
4
+ import { cn } from "../../lib/cn.js";
5
+ import { atRest, springForce, stepSpring } from "../../motion/spring-step.js";
6
+ import { springs } from "../../motion/springs.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { useLayoutEffect, useRef, useState } from "react";
9
+ // src/components/calendar/calendar-selection.tsx
10
+ /** The room the drawing keeps around the grid, in px: for its edge, and a swing past the grid. */
11
+ const ROOM = 4;
12
+ /** The shape at rest, in the calendar's own units: nothing measured, right on a server too. */
13
+ function atRestDrawing({ top, first, bottom, last }) {
14
+ const rows = bottom - top + 1;
15
+ const outline = rangeOutline(first, last, rows, 0, top);
16
+ return {
17
+ shape: polygonPoints(outline, ROOM),
18
+ edge: polygonPoints(rangeOutline(first, last, rows, 1, top), ROOM),
19
+ start: polygonPoints(outline.slice(0, 1), ROOM)
20
+ };
21
+ }
22
+ /** The shape on its way, in pixels. */
23
+ function movingDrawing(span, sizes) {
24
+ const outline = spanOutline(span, sizes);
25
+ return {
26
+ shape: pixelPoints(outline, ROOM),
27
+ edge: pixelPoints(spanOutline(span, sizes, 1), ROOM),
28
+ start: pixelPoints(outline.slice(0, 1), ROOM)
29
+ };
30
+ }
31
+ function draw(element, drawing) {
32
+ element.style.setProperty("--shape", drawing.shape);
33
+ element.style.setProperty("--shape-edge", drawing.edge);
34
+ element.style.setProperty("--shape-start", drawing.start);
35
+ }
36
+ /** The sizes of the grid as it stands, read once when a motion begins. */
37
+ function measure(element) {
38
+ const day = element.parentElement?.querySelector("[data-slot=\"calendar-day\"]");
39
+ if (!day) return void 0;
40
+ const cell = day.offsetWidth;
41
+ return {
42
+ cell,
43
+ gap: (element.offsetWidth - 8 - 7 * cell) / 6,
44
+ radius: Number.parseFloat(getComputedStyle(day).borderTopLeftRadius) || 0
45
+ };
46
+ }
47
+ const force = springForce(springs.seat);
48
+ const KEYS = [
49
+ "top",
50
+ "first",
51
+ "bottom",
52
+ "last"
53
+ ];
54
+ /**
55
+ * Moves the shape from where it is to a new selection; returns the ref for the shape. The four numbers of the selection each
56
+ * ride the `seat` spring, and the outline is drawn from them frame by frame (`spanOutline`),
57
+ * so it is a proper shape at every instant and takes a new target mid-flight. Only the drawing's
58
+ * custom properties are written: no layout, no React render. When it has arrived, the shape at
59
+ * rest is written back in the calendar's own units.
60
+ *
61
+ * What it does not do: move on the first drawing (a page that loads does not animate), or under
62
+ * reduced motion. A selection made where there was none seats instead: it grows out of its day.
63
+ */
64
+ function useGlide(span) {
65
+ const element = useRef(null);
66
+ const moving = useRef(void 0);
67
+ const drawn = useRef(false);
68
+ const top = span?.top;
69
+ const first = span?.first;
70
+ const bottom = span?.bottom;
71
+ const last = span?.last;
72
+ useLayoutEffect(() => {
73
+ const node = element.current;
74
+ const had = moving.current;
75
+ const before = drawn.current;
76
+ drawn.current = true;
77
+ if (!node) return;
78
+ if (top === void 0 || first === void 0 || bottom === void 0 || last === void 0) {
79
+ moving.current = void 0;
80
+ return;
81
+ }
82
+ const target = {
83
+ top,
84
+ first,
85
+ bottom,
86
+ last
87
+ };
88
+ const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
89
+ const sizes = had && !still ? measure(node) : void 0;
90
+ if (!had || !sizes) {
91
+ moving.current = {
92
+ top: {
93
+ value: top,
94
+ velocity: 0
95
+ },
96
+ first: {
97
+ value: first,
98
+ velocity: 0
99
+ },
100
+ bottom: {
101
+ value: bottom,
102
+ velocity: 0
103
+ },
104
+ last: {
105
+ value: last,
106
+ velocity: 0
107
+ }
108
+ };
109
+ draw(node, atRestDrawing(target));
110
+ if (before && !had && !still) {
111
+ node.style.transition = "none";
112
+ node.style.scale = "0.6";
113
+ node.style.opacity = "0";
114
+ node.offsetWidth;
115
+ node.style.transition = "";
116
+ node.style.scale = "";
117
+ node.style.opacity = "";
118
+ }
119
+ return;
120
+ }
121
+ let frame = 0;
122
+ let then = performance.now();
123
+ const tick = (now) => {
124
+ const seconds = (now - then) / 1e3;
125
+ then = now;
126
+ let arrived = true;
127
+ for (const key of KEYS) {
128
+ had[key] = stepSpring(had[key], target[key], force, seconds);
129
+ arrived &&= atRest(had[key], target[key]);
130
+ }
131
+ if (arrived) {
132
+ for (const key of KEYS) had[key] = {
133
+ value: target[key],
134
+ velocity: 0
135
+ };
136
+ draw(node, atRestDrawing(target));
137
+ return;
138
+ }
139
+ draw(node, movingDrawing({
140
+ top: had.top.value,
141
+ first: had.first.value,
142
+ bottom: had.bottom.value,
143
+ last: had.last.value
144
+ }, sizes));
145
+ frame = requestAnimationFrame(tick);
146
+ };
147
+ frame = requestAnimationFrame(tick);
148
+ return () => cancelAnimationFrame(frame);
149
+ }, [
150
+ top,
151
+ first,
152
+ bottom,
153
+ last
154
+ ]);
155
+ return element;
156
+ }
157
+ /** Today's ring where the day stands on the selection: inside, in the colour that reads there. */
158
+ const ringOnSelection = "after:pointer-events-none after:absolute after:inset-[3px] after:rounded-[calc(var(--radius-md)-3px)] after:inset-ring-[1.5px] after:inset-ring-on-accent/60";
159
+ /**
160
+ * What is chosen, drawn as one raised Indigo shape over the days (`calendar-selection`): one
161
+ * day, or a range from its first day to its last, filled through and with one edge, also where
162
+ * it runs on into the next week.
163
+ *
164
+ * It is one element per month. When the selection changes it is not swapped for another: it
165
+ * glides to its new place and re-forms on the way (`useGlide`). A range grows out of its first
166
+ * day, a new week out of the edge, two weeks join through a neck or let go of each other. The
167
+ * mark travels, here as everywhere.
168
+ *
169
+ * The shape carries the numbers of the days in the colour that reads on it, cut to its outline
170
+ * like the fill. So a number changes colour exactly where the edge passes over it, and never
171
+ * stands in the wrong colour while the shape is still on its way.
172
+ */
173
+ function CalendarSelection({ month, chosen, today }) {
174
+ const place = chosen ? rangeInGrid(month, chosen.from, chosen.to) : void 0;
175
+ const span = place && {
176
+ ...place,
177
+ bottom: place.top + place.rows - 1
178
+ };
179
+ const element = useGlide(span);
180
+ const [initial] = useState(() => span && atRestDrawing(span));
181
+ return /* @__PURE__ */ jsxs("span", {
182
+ ref: element,
183
+ "aria-hidden": true,
184
+ "data-slot": "calendar-selection",
185
+ "data-empty": span ? void 0 : "",
186
+ className: "calendar-selection z-[1] depth-tone-accent",
187
+ style: {
188
+ "--room": `${ROOM}px`,
189
+ ...initial && {
190
+ "--shape": initial.shape,
191
+ "--shape-edge": initial.edge,
192
+ "--shape-start": initial.start
193
+ },
194
+ ...span && { transformOrigin: `calc(${span.first + .5} * var(--u) + ${ROOM}px) calc(${span.top + .5} * var(--u) + ${ROOM}px)` }
195
+ },
196
+ children: [
197
+ /* @__PURE__ */ jsx("span", { "data-layer": "edge" }),
198
+ /* @__PURE__ */ jsx("span", {
199
+ "data-layer": "face",
200
+ children: /* @__PURE__ */ jsx("span", {
201
+ className: "absolute top-(--room) left-(--room) grid grid-cols-[repeat(7,var(--calendar-cell))] gap-(--calendar-gap) text-control text-on-accent select-none forced-colors:text-[HighlightText]",
202
+ children: gridDays(month).map((date) => {
203
+ const iso = toIsoDate(date);
204
+ return /* @__PURE__ */ jsx("span", {
205
+ className: cn("relative flex size-(--calendar-cell) items-center justify-center", date.getMonth() !== month.getMonth() && "opacity-70", iso === today && ["font-semibold", ringOnSelection]),
206
+ children: date.getDate()
207
+ }, iso);
208
+ })
209
+ })
210
+ }),
211
+ /* @__PURE__ */ jsx("span", { "data-layer": "light" }),
212
+ /* @__PURE__ */ jsx("span", { "data-layer": "shade" })
213
+ ]
214
+ });
215
+ }
216
+ export { CalendarSelection };
@@ -0,0 +1,44 @@
1
+ /** A range of days as ISO dates, both ends included. `""` for an end that is not set. */
2
+ export type DateRange = {
3
+ from: string;
4
+ to: string;
5
+ };
6
+ type CalendarCommon = {
7
+ /** The first and the last day that can be chosen, as ISO dates. */
8
+ min?: string;
9
+ max?: string;
10
+ /**
11
+ * The day that counts as today, as an ISO date. The real one unless given; a page rendered on
12
+ * a server only learns the real one in the browser, so its ring appears a moment later.
13
+ */
14
+ today?: string;
15
+ className?: string;
16
+ };
17
+ export type CalendarProps = CalendarCommon & ({
18
+ /** One day. */
19
+ mode?: "single";
20
+ /** The chosen day as an ISO date (`2026-11-14`), or `""` for none (controlled). */
21
+ value?: string;
22
+ /** The day chosen at first (uncontrolled). */
23
+ defaultValue?: string;
24
+ onValueChange?: (value: string) => void;
25
+ } | {
26
+ /** A first and a last day. */
27
+ mode: "range";
28
+ /** The chosen range (controlled). */
29
+ value?: DateRange;
30
+ /** The range chosen at first (uncontrolled). */
31
+ defaultValue?: DateRange;
32
+ /** Called once both ends are chosen, with the earlier one first. */
33
+ onValueChange?: (value: DateRange) => void;
34
+ });
35
+ /**
36
+ * A month to pick from: one day, or with `mode="range"` a first and a last day. German weekdays,
37
+ * Monday first, six rows always, so the sheet it sits in does not change height from month to
38
+ * month. Dates go in and come out as ISO strings.
39
+ *
40
+ * It is the calendar of a `DateField` and a `DateRangeField`; on its own it suits a page that is
41
+ * about one date.
42
+ */
43
+ export declare function Calendar(props: CalendarProps): import("react").JSX.Element;
44
+ export {};
@@ -0,0 +1,208 @@
1
+ "use client";
2
+ import { buttonVariants } from "../button/button-variants.js";
3
+ import { ChevronLeftGlyph, ChevronRightGlyph } from "../../internal/glyphs.js";
4
+ import { parseIsoDate, toIsoDate } from "../../internal/iso-date.js";
5
+ import { cn } from "../../lib/cn.js";
6
+ import { CalendarSelection } from "./calendar-selection.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { createContext, useContext, useState, useSyncExternalStore } from "react";
9
+ import { DayButton, DayPicker } from "react-day-picker";
10
+ import { de } from "react-day-picker/locale";
11
+ // src/components/calendar/calendar.tsx
12
+ /** What is chosen, as a range of days (one day is a range of itself). `undefined` for nothing. */
13
+ const Chosen = createContext(void 0);
14
+ /** The month a grid shows. */
15
+ const ShownMonth = createContext(void 0);
16
+ /** The day that counts as today, as an ISO date. */
17
+ const Today = createContext("");
18
+ /** The month, handing its date to the grid inside it. */
19
+ function Month({ calendarMonth, displayIndex: _, ...props }) {
20
+ return /* @__PURE__ */ jsx(ShownMonth, {
21
+ value: calendarMonth.date,
22
+ children: /* @__PURE__ */ jsx("div", { ...props })
23
+ });
24
+ }
25
+ /** The grid of days, with what is chosen drawn over it (`CalendarSelection`). */
26
+ function MonthGrid(props) {
27
+ const month = useContext(ShownMonth);
28
+ const chosen = useContext(Chosen);
29
+ const today = useContext(Today);
30
+ return /* @__PURE__ */ jsxs("div", {
31
+ className: "relative",
32
+ children: [month && /* @__PURE__ */ jsx(CalendarSelection, {
33
+ month,
34
+ chosen,
35
+ today
36
+ }, toIsoDate(month)), /* @__PURE__ */ jsx("table", { ...props })]
37
+ });
38
+ }
39
+ /**
40
+ * One day of the month. Today wears the ring (open: possible), what is chosen is Indigo
41
+ * (filled: chosen), the same pair a radio and a tab mark use. A press dips the day.
42
+ *
43
+ * A chosen day does not change itself: the selection is drawn once for the whole month, over
44
+ * the days, with their numbers on it (`CalendarSelection`). Only the day that has the keyboard focus
45
+ * comes forward through it, so its outline shows; on the selection the outline is light and
46
+ * lies inside the day, where an Indigo one would not be seen.
47
+ */
48
+ function CalendarDay({ className, modifiers, ...props }) {
49
+ return /* @__PURE__ */ jsx(DayButton, {
50
+ modifiers,
51
+ "data-slot": "calendar-day",
52
+ className: cn("relative inline-flex size-(--calendar-cell) items-center justify-center rounded-md text-control text-fg select-none", "transition-[background-color,scale] spring-seat hover:bg-hover hover:spring-snap active:scale-[0.92] active:spring-snap", "focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent", modifiers.outside && "text-fg-muted", modifiers.today && "font-semibold after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:inset-ring-[1.5px] after:inset-ring-line", modifiers.selected && [
53
+ "focus-visible:text-on-accent focus-visible:-outline-offset-2 focus-visible:outline-on-accent",
54
+ modifiers.today && ["focus-visible:after:inset-ring-0"],
55
+ "forced-colors:focus-visible:text-[HighlightText] forced-colors:focus-visible:[forced-color-adjust:none]"
56
+ ], modifiers.disabled && "pointer-events-none text-on-disabled", className),
57
+ ...props
58
+ });
59
+ }
60
+ const navButton = cn(buttonVariants({
61
+ variant: "quiet",
62
+ size: "sm",
63
+ iconOnly: true
64
+ }), "text-fg-muted hover:text-fg aria-disabled:pointer-events-none aria-disabled:text-on-disabled");
65
+ /**
66
+ * Stands in for today while the day is not known (see `Calendar`). The picker must always be
67
+ * given a day: left without one it reads the clock itself, while rendering.
68
+ */
69
+ const NO_DAY = new Date(1900, 0, 1);
70
+ /**
71
+ * What both kinds of calendar share: the limits, the look, German weekdays from Monday, and the
72
+ * month to open on: the one of what is chosen, else today's.
73
+ */
74
+ function useCalendarProps({ min, max, className }, chosen) {
75
+ const first = parseIsoDate(min);
76
+ const last = parseIsoDate(max);
77
+ const disabled = [...first ? [{ before: first }] : [], ...last ? [{ after: last }] : []];
78
+ const now = parseIsoDate(useContext(Today));
79
+ const blank = !chosen && !now;
80
+ return {
81
+ start: blank ? "blank" : "month",
82
+ props: {
83
+ locale: de,
84
+ dir: "ltr",
85
+ showOutsideDays: true,
86
+ fixedWeeks: true,
87
+ today: now ?? NO_DAY,
88
+ defaultMonth: chosen ?? now,
89
+ startMonth: first,
90
+ endMonth: last,
91
+ disabled,
92
+ components: {
93
+ Month,
94
+ MonthGrid,
95
+ DayButton: CalendarDay,
96
+ Chevron: ({ orientation }) => orientation === "left" ? /* @__PURE__ */ jsx(ChevronLeftGlyph, {}) : /* @__PURE__ */ jsx(ChevronRightGlyph, {})
97
+ },
98
+ "data-slot": "calendar",
99
+ className: cn("relative w-fit text-control text-fg [--calendar-cell:var(--control-md)] [--calendar-gap:2px] [--u:calc(var(--calendar-cell)+var(--calendar-gap))] pointer-coarse:[--calendar-cell:2.5rem]", blank && "invisible", className),
100
+ classNames: {
101
+ months: "flex",
102
+ month: "flex flex-col gap-1.5",
103
+ month_caption: "flex h-(--control-sm) items-center pl-2",
104
+ caption_label: "text-control font-medium text-fg",
105
+ nav: "absolute top-0 right-0 z-10 flex gap-0.5",
106
+ button_previous: navButton,
107
+ button_next: navButton,
108
+ month_grid: "-m-(--calendar-gap) border-separate border-spacing-(--calendar-gap)",
109
+ weekday: "h-(--control-sm) w-(--calendar-cell) text-center text-sm font-normal text-fg-muted",
110
+ day: "p-0 text-center"
111
+ }
112
+ }
113
+ };
114
+ }
115
+ /** Today is today for as long as a calendar is open: there is nothing to listen for. */
116
+ const neverChanges = () => () => {};
117
+ /**
118
+ * A month to pick from: one day, or with `mode="range"` a first and a last day. German weekdays,
119
+ * Monday first, six rows always, so the sheet it sits in does not change height from month to
120
+ * month. Dates go in and come out as ISO strings.
121
+ *
122
+ * It is the calendar of a `DateField` and a `DateRangeField`; on its own it suits a page that is
123
+ * about one date.
124
+ */
125
+ function Calendar(props) {
126
+ const realToday = useSyncExternalStore(neverChanges, () => toIsoDate(/* @__PURE__ */ new Date()), () => "");
127
+ return /* @__PURE__ */ jsx(Today, {
128
+ value: props.today ?? realToday,
129
+ children: props.mode === "range" ? /* @__PURE__ */ jsx(RangeCalendar, { ...props }) : /* @__PURE__ */ jsx(SingleCalendar, { ...props })
130
+ });
131
+ }
132
+ function SingleCalendar({ value, defaultValue, onValueChange, ...common }) {
133
+ const [inner, setInner] = useState(defaultValue ?? "");
134
+ const selected = parseIsoDate(value ?? inner);
135
+ const { start, props } = useCalendarProps(common, selected);
136
+ return /* @__PURE__ */ jsx(Chosen, {
137
+ value: selected && {
138
+ from: selected,
139
+ to: selected
140
+ },
141
+ children: /* @__PURE__ */ jsx(DayPicker, {
142
+ mode: "single",
143
+ required: true,
144
+ selected,
145
+ onSelect: (date) => {
146
+ const next = toIsoDate(date);
147
+ if (value === void 0) setInner(next);
148
+ onValueChange?.(next);
149
+ },
150
+ ...props
151
+ }, start)
152
+ });
153
+ }
154
+ /**
155
+ * The first press sets one end, the second the other; whichever is earlier becomes the start. A
156
+ * third press begins a new range. Between the two presses the range follows the pointer and the
157
+ * arrow keys, so it is seen before it is chosen.
158
+ */
159
+ function RangeCalendar({ value, defaultValue, onValueChange, ...common }) {
160
+ const [inner, setInner] = useState(defaultValue ?? {
161
+ from: "",
162
+ to: ""
163
+ });
164
+ const range = value ?? inner;
165
+ const [anchor, setAnchor] = useState();
166
+ const [aim, setAim] = useState();
167
+ const from = parseIsoDate(range.from);
168
+ const to = parseIsoDate(range.to);
169
+ const { start, props } = useCalendarProps(common, from);
170
+ const other = aim ?? anchor;
171
+ const selected = anchor && other ? {
172
+ from: anchor < other ? anchor : other,
173
+ to: anchor < other ? other : anchor
174
+ } : {
175
+ from,
176
+ to
177
+ };
178
+ return /* @__PURE__ */ jsx(Chosen, {
179
+ value: selected.from && {
180
+ from: selected.from,
181
+ to: selected.to ?? selected.from
182
+ },
183
+ children: /* @__PURE__ */ jsx(DayPicker, {
184
+ mode: "range",
185
+ selected,
186
+ onSelect: (_, day, modifiers) => {
187
+ if (modifiers.disabled) return;
188
+ if (!anchor) {
189
+ setAnchor(day);
190
+ setAim(void 0);
191
+ return;
192
+ }
193
+ const next = {
194
+ from: toIsoDate(day < anchor ? day : anchor),
195
+ to: toIsoDate(day < anchor ? anchor : day)
196
+ };
197
+ setAnchor(void 0);
198
+ setAim(void 0);
199
+ if (value === void 0) setInner(next);
200
+ onValueChange?.(next);
201
+ },
202
+ onDayMouseEnter: (day) => anchor && setAim(day),
203
+ onDayFocus: (day) => anchor && setAim(day),
204
+ ...props
205
+ }, start)
206
+ });
207
+ }
208
+ export { Calendar };
@@ -0,0 +1,21 @@
1
+ import { IconSvgElement } from "../icon/icon.js";
2
+ import { ComponentProps, ReactNode } from "react";
3
+ /** The five kinds of a GitHub alert (`> [!NOTE]` …), which is where most callouts come from. */
4
+ export type CalloutTone = "note" | "tip" | "important" | "warning" | "caution";
5
+ export type CalloutProps = Omit<ComponentProps<"div">, "title"> & {
6
+ tone?: CalloutTone;
7
+ /** Replaces the tone's word ("Hinweis", "Warnung") as the first line. */
8
+ title?: ReactNode;
9
+ /** Replaces the tone's icon. A callout always has one: colour alone never carries its kind. */
10
+ icon?: IconSvgElement;
11
+ };
12
+ /**
13
+ * A remark set apart from the text it belongs to: a note, a tip, something important, a warning,
14
+ * a caution. It is part of the page and is read in order, so it is a note to assistive tech, not
15
+ * a live message; for what happens now (a form that failed), use `Alert`.
16
+ *
17
+ * It stays text: flat on the page, set apart by a 2px edge in its tone on the left, its kind in
18
+ * words and an icon on the first line. The body is one or a few short paragraphs. Keep it rare:
19
+ * a page where every other block is a callout has none.
20
+ */
21
+ export declare function Callout({ tone, title, icon, className, children, ...props }: CalloutProps): import("react").JSX.Element;