@lanfermann/ui 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/dist/components/accordion/accordion.d.ts +11 -3
  2. package/dist/components/accordion/accordion.js +15 -10
  3. package/dist/components/action-bar/action-bar.d.ts +60 -0
  4. package/dist/components/action-bar/action-bar.js +117 -0
  5. package/dist/components/alert/alert.d.ts +1 -1
  6. package/dist/components/alert/alert.js +3 -17
  7. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  8. package/dist/components/app-shell/app-shell.d.ts +33 -0
  9. package/dist/components/app-shell/app-shell.js +93 -0
  10. package/dist/components/attachment/attachment.d.ts +51 -0
  11. package/dist/components/attachment/attachment.js +255 -0
  12. package/dist/components/attachment/kinds.d.ts +7 -0
  13. package/dist/components/attachment/kinds.js +142 -0
  14. package/dist/components/avatar/avatar.d.ts +14 -4
  15. package/dist/components/avatar/avatar.js +57 -13
  16. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  17. package/dist/components/avatar-group/avatar-group.js +110 -0
  18. package/dist/components/avatar-group/people.d.ts +12 -0
  19. package/dist/components/avatar-group/people.js +24 -0
  20. package/dist/components/badge/badge.d.ts +9 -3
  21. package/dist/components/badge/badge.js +21 -6
  22. package/dist/components/banner/banner.d.ts +39 -0
  23. package/dist/components/banner/banner.js +149 -0
  24. package/dist/components/button-group/button-group-variants.d.ts +4 -3
  25. package/dist/components/button-group/button-group-variants.js +13 -12
  26. package/dist/components/button-group/button-group.d.ts +3 -3
  27. package/dist/components/button-group/button-group.js +3 -3
  28. package/dist/components/card/card.d.ts +20 -4
  29. package/dist/components/card/card.js +32 -6
  30. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  31. package/dist/components/checkbox-card/checkbox-card.js +50 -0
  32. package/dist/components/chip/chip-group.d.ts +15 -0
  33. package/dist/components/chip/chip-group.js +44 -0
  34. package/dist/components/chip/chip-variants.d.ts +6 -0
  35. package/dist/components/chip/chip-variants.js +28 -0
  36. package/dist/components/chip/chip.d.ts +39 -0
  37. package/dist/components/chip/chip.js +71 -0
  38. package/dist/components/code-block/code-copy.d.ts +3 -11
  39. package/dist/components/code-block/code-copy.js +15 -62
  40. package/dist/components/code-block/code-keys.js +10 -22
  41. package/dist/components/collapsible/collapsible.js +7 -3
  42. package/dist/components/combobox/combobox.d.ts +53 -3
  43. package/dist/components/combobox/combobox.js +204 -20
  44. package/dist/components/command/command.d.ts +131 -0
  45. package/dist/components/command/command.js +335 -0
  46. package/dist/components/consent/consent-card.js +365 -0
  47. package/dist/components/consent/consent-embed.d.ts +21 -0
  48. package/dist/components/consent/consent-embed.js +111 -0
  49. package/dist/components/consent/consent-labels.d.ts +70 -0
  50. package/dist/components/consent/consent-labels.js +61 -0
  51. package/dist/components/consent/consent-record.d.ts +95 -0
  52. package/dist/components/consent/consent-record.js +112 -0
  53. package/dist/components/consent/consent-store.d.ts +26 -0
  54. package/dist/components/consent/consent-store.js +240 -0
  55. package/dist/components/consent/consent.d.ts +86 -0
  56. package/dist/components/consent/consent.js +306 -0
  57. package/dist/components/container/container.d.ts +1 -1
  58. package/dist/components/context-menu/context-menu.d.ts +23 -0
  59. package/dist/components/context-menu/context-menu.js +50 -0
  60. package/dist/components/conversation/conversation.d.ts +45 -0
  61. package/dist/components/conversation/conversation.js +295 -0
  62. package/dist/components/conversation/stick.js +23 -0
  63. package/dist/components/copy-button/copy-button.d.ts +50 -0
  64. package/dist/components/copy-button/copy-button.js +65 -0
  65. package/dist/components/copy-page/copy-page.d.ts +4 -4
  66. package/dist/components/copy-page/copy-page.js +16 -36
  67. package/dist/components/copy-pill/copy-pill.js +1 -1
  68. package/dist/components/description-list/description-list.d.ts +32 -0
  69. package/dist/components/description-list/description-list.js +51 -0
  70. package/dist/components/empty/empty.d.ts +38 -0
  71. package/dist/components/empty/empty.js +57 -0
  72. package/dist/components/field/field.js +1 -1
  73. package/dist/components/file-upload/file-upload.d.ts +96 -0
  74. package/dist/components/file-upload/file-upload.js +347 -0
  75. package/dist/components/file-upload/files.d.ts +39 -0
  76. package/dist/components/file-upload/files.js +74 -0
  77. package/dist/components/grow/grow.d.ts +15 -3
  78. package/dist/components/grow/grow.js +24 -9
  79. package/dist/components/heading/heading.d.ts +1 -1
  80. package/dist/components/icon/icon.d.ts +1 -1
  81. package/dist/components/input/input.js +1 -1
  82. package/dist/components/menu/menu.d.ts +20 -8
  83. package/dist/components/menu/menu.js +51 -29
  84. package/dist/components/message/message.d.ts +81 -0
  85. package/dist/components/message/message.js +208 -0
  86. package/dist/components/navigation-menu/navigation-menu.d.ts +7 -1
  87. package/dist/components/navigation-menu/navigation-menu.js +11 -4
  88. package/dist/components/otp-field/otp-field.d.ts +37 -0
  89. package/dist/components/otp-field/otp-field.js +161 -0
  90. package/dist/components/pagination/pagination.d.ts +50 -0
  91. package/dist/components/pagination/pagination.js +188 -0
  92. package/dist/components/prompt-input/keys.js +15 -0
  93. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  94. package/dist/components/prompt-input/prompt-input.js +331 -0
  95. package/dist/components/radio-card/radio-card.d.ts +23 -0
  96. package/dist/components/radio-card/radio-card.js +49 -0
  97. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  98. package/dist/components/rolling-number/rolling-number.js +149 -0
  99. package/dist/components/seam/seam.d.ts +1 -1
  100. package/dist/components/secret-field/secret-field.d.ts +53 -0
  101. package/dist/components/secret-field/secret-field.js +121 -0
  102. package/dist/components/section/section.d.ts +1 -1
  103. package/dist/components/segmented-control/segmented-control.js +29 -16
  104. package/dist/components/select/select.d.ts +5 -4
  105. package/dist/components/select/select.js +16 -11
  106. package/dist/components/shortcut/shortcut.d.ts +46 -0
  107. package/dist/components/shortcut/shortcut.js +87 -0
  108. package/dist/components/sidebar/sidebar-context.js +16 -0
  109. package/dist/components/sidebar/sidebar.d.ts +161 -0
  110. package/dist/components/sidebar/sidebar.js +588 -0
  111. package/dist/components/site-header/site-header.js +1 -1
  112. package/dist/components/skeleton/loaded.d.ts +21 -0
  113. package/dist/components/skeleton/loaded.js +57 -0
  114. package/dist/components/skeleton/skeleton.d.ts +43 -0
  115. package/dist/components/skeleton/skeleton.js +48 -0
  116. package/dist/components/sources/source-list.d.ts +17 -0
  117. package/dist/components/sources/source-list.js +26 -0
  118. package/dist/components/sources/sources.d.ts +45 -0
  119. package/dist/components/sources/sources.js +167 -0
  120. package/dist/components/stat/stat.d.ts +59 -0
  121. package/dist/components/stat/stat.js +112 -0
  122. package/dist/components/steps/steps.d.ts +57 -0
  123. package/dist/components/steps/steps.js +134 -0
  124. package/dist/components/table/table.d.ts +18 -9
  125. package/dist/components/table/table.js +21 -13
  126. package/dist/components/text/text.d.ts +1 -1
  127. package/dist/components/theme-switch/theme-switch.js +1 -1
  128. package/dist/components/time-field/time-field.js +7 -6
  129. package/dist/components/timeline/timeline.d.ts +45 -0
  130. package/dist/components/timeline/timeline.js +86 -0
  131. package/dist/components/toast/toast.js +10 -26
  132. package/dist/components/toggle/toggle.d.ts +27 -0
  133. package/dist/components/toggle/toggle.js +61 -0
  134. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  135. package/dist/components/toggle-group/toggle-group.js +38 -0
  136. package/dist/components/toolbar/toolbar-context.js +12 -0
  137. package/dist/components/toolbar/toolbar.d.ts +52 -0
  138. package/dist/components/toolbar/toolbar.js +105 -0
  139. package/dist/components/trace/trace.d.ts +2 -1
  140. package/dist/components/trace/trace.js +15 -27
  141. package/dist/index.d.ts +46 -3
  142. package/dist/index.js +44 -3
  143. package/dist/internal/arriving-pieces.js +56 -0
  144. package/dist/internal/arriving.js +171 -0
  145. package/dist/internal/avatar-cut.d.ts +15 -0
  146. package/dist/internal/avatar-cut.js +83 -0
  147. package/dist/internal/choice-card.d.ts +15 -0
  148. package/dist/internal/choice-card.js +81 -0
  149. package/dist/internal/clipboard.js +37 -0
  150. package/dist/internal/copy.js +58 -0
  151. package/dist/internal/disclosure.js +15 -3
  152. package/dist/internal/field.js +24 -4
  153. package/dist/internal/glyphs.js +26 -1
  154. package/dist/internal/key-tip.js +18 -0
  155. package/dist/internal/list-mark.js +39 -0
  156. package/dist/internal/live-list.js +41 -0
  157. package/dist/internal/number-places.js +157 -0
  158. package/dist/internal/picker-sheet.js +1 -1
  159. package/dist/internal/presence-dot.js +24 -0
  160. package/dist/internal/presence.js +104 -0
  161. package/dist/internal/rail-mark.d.ts +3 -0
  162. package/dist/internal/rail-mark.js +33 -0
  163. package/dist/internal/rule.js +2 -1
  164. package/dist/internal/status-icon.js +22 -0
  165. package/dist/internal/tile.js +23 -0
  166. package/dist/internal/travelling-mark.js +204 -0
  167. package/dist/lib/cn.js +10 -0
  168. package/dist/lib/shortcut.d.ts +11 -0
  169. package/dist/lib/shortcut.js +165 -0
  170. package/package.json +1 -1
  171. package/src/styles/accordion.css +176 -0
  172. package/src/styles/action-bar.css +28 -0
  173. package/src/styles/assistant.css +83 -0
  174. package/src/styles/avatar.css +24 -0
  175. package/src/styles/consent.css +65 -0
  176. package/src/styles/copy.css +12 -11
  177. package/src/styles/depth.css +120 -4
  178. package/src/styles/marks.css +20 -2
  179. package/src/styles/motion.css +3 -0
  180. package/src/styles/rail.css +49 -0
  181. package/src/styles/rolling-number.css +94 -0
  182. package/src/styles/segmented.css +14 -7
  183. package/src/styles/steps.css +98 -0
  184. package/src/styles/timeline.css +48 -0
  185. package/src/styles/travel.css +36 -0
  186. package/src/styles.css +10 -0
@@ -0,0 +1,121 @@
1
+ "use client";
2
+ import { Icon } from "../icon/icon.js";
3
+ import { Input } from "../input/input.js";
4
+ import { InputGroup, InputGroupButton } from "../input-group/input-group.js";
5
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip/tooltip.js";
6
+ import { CopyMarks, useCopy } from "../../internal/copy.js";
7
+ import { cn } from "../../lib/cn.js";
8
+ import { mergeRefs } from "../../lib/merge-refs.js";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import { useEffect, useRef, useState } from "react";
11
+ import { ViewIcon, ViewOffSlashIcon } from "@hugeicons/core-free-icons";
12
+ import { flushSync } from "react-dom";
13
+ // src/components/secret-field/secret-field.tsx
14
+ /** How many discs stand for a hidden value at most: its length is nobody's business. */
15
+ const MASK_LENGTH = 24;
16
+ const symbolSize = {
17
+ sm: 14,
18
+ md: 16,
19
+ lg: 16
20
+ };
21
+ /**
22
+ * A value that is read by machines and must not be read over a shoulder: an API key, the
23
+ * secret of a webhook. It stands in a field in mono, hidden behind discs until the key with
24
+ * the eye is pressed, and a second key copies it. The copy always takes the real value,
25
+ * hidden or not, and confirms with the drawn tick.
26
+ *
27
+ * The field cannot be typed into. Label it with a `FieldLabel` ("Geheimer Schlüssel") and say
28
+ * in a `FieldDescription` what the reader should do with it ("Er wird nur dieses eine Mal
29
+ * angezeigt."). While it is hidden the value is not in the page; when the browser refuses the
30
+ * clipboard, the value is shown and selected instead, so ⌘C still works.
31
+ */
32
+ function SecretField({ value, size = "md", hideable = true, revealed: revealedProp, defaultRevealed = false, onRevealedChange, visibleStart = 0, onCopied, revealLabel = "Anzeigen", hideLabel = "Verbergen", copyLabel = "Kopieren", copiedLabel = "Kopiert", copiedMessage = "In die Zwischenablage kopiert.", failedLabel = "Markiert", failedMessage = "Nicht kopiert. Der Wert ist markiert und kann mit ⌘C kopiert werden.", className, ref, ...props }) {
33
+ const [own, setOwn] = useState(defaultRevealed);
34
+ const revealed = !hideable || (revealedProp ?? own);
35
+ const field = useRef(null);
36
+ const [swapping, setSwapping] = useState(false);
37
+ const settle = useRef(0);
38
+ useEffect(() => () => cancelAnimationFrame(settle.current), []);
39
+ const show = (next) => {
40
+ cancelAnimationFrame(settle.current);
41
+ setSwapping(true);
42
+ setOwn(next);
43
+ onRevealedChange?.(next);
44
+ settle.current = requestAnimationFrame(() => {
45
+ settle.current = requestAnimationFrame(() => setSwapping(false));
46
+ });
47
+ };
48
+ const { state, copy } = useCopy({
49
+ text: value,
50
+ selectTarget: field,
51
+ onCopied,
52
+ onRefused: () => flushSync(() => show(true))
53
+ });
54
+ const shown = revealed ? value : value.slice(0, visibleStart) + "•".repeat(Math.min(Math.max(value.length - visibleStart, 0), MASK_LENGTH));
55
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(InputGroup, {
56
+ "data-slot": "secret-field",
57
+ size,
58
+ className,
59
+ children: [
60
+ /* @__PURE__ */ jsx(Input, {
61
+ ref: mergeRefs(field, ref),
62
+ readOnly: true,
63
+ value: shown,
64
+ spellCheck: false,
65
+ autoComplete: "off",
66
+ "data-revealed": revealed ? "" : void 0,
67
+ "data-swapping": swapping ? "" : void 0,
68
+ onFocus: (event) => {
69
+ const input = event.currentTarget;
70
+ if (revealed) {
71
+ input.select();
72
+ return;
73
+ }
74
+ input.setSelectionRange(0, 0);
75
+ input.scrollLeft = 0;
76
+ },
77
+ className: cn("font-mono text-ellipsis", "transition-[opacity,filter] spring-snap data-swapping:opacity-0 data-swapping:blur-[2px] data-swapping:transition-none motion-reduce:data-swapping:blur-none"),
78
+ ...props
79
+ }),
80
+ hideable && /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
81
+ closeOnClick: false,
82
+ render: /* @__PURE__ */ jsx(InputGroupButton, {
83
+ "aria-label": revealLabel,
84
+ "aria-pressed": revealed,
85
+ "data-secret-key": "reveal",
86
+ onClick: () => show(!revealed),
87
+ children: /* @__PURE__ */ jsxs("span", {
88
+ "data-revealed": revealed ? "" : void 0,
89
+ className: "group/eye grid place-items-center *:col-start-1 *:row-start-1 *:transition-[scale,opacity] *:spring-seat motion-reduce:*:scale-100",
90
+ children: [/* @__PURE__ */ jsx(Icon, {
91
+ icon: ViewIcon,
92
+ size: symbolSize[size],
93
+ className: "group-data-revealed/eye:scale-50 group-data-revealed/eye:opacity-0 group-data-revealed/eye:spring-leave"
94
+ }), /* @__PURE__ */ jsx(Icon, {
95
+ icon: ViewOffSlashIcon,
96
+ size: symbolSize[size],
97
+ className: "scale-50 opacity-0 spring-leave group-data-revealed/eye:scale-100 group-data-revealed/eye:opacity-100 group-data-revealed/eye:spring-seat"
98
+ })]
99
+ })
100
+ })
101
+ }), /* @__PURE__ */ jsx(TooltipContent, { children: revealed ? hideLabel : revealLabel })] }),
102
+ /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
103
+ closeOnClick: false,
104
+ render: /* @__PURE__ */ jsx(InputGroupButton, {
105
+ "aria-label": copyLabel,
106
+ "data-secret-key": "copy",
107
+ onClick: () => void copy(),
108
+ children: /* @__PURE__ */ jsx(CopyMarks, {
109
+ copied: state === "copied",
110
+ size: symbolSize[size]
111
+ })
112
+ })
113
+ }), /* @__PURE__ */ jsx(TooltipContent, { children: state === "idle" ? copyLabel : state === "failed" ? failedLabel : copiedLabel })] })
114
+ ]
115
+ }), /* @__PURE__ */ jsx("span", {
116
+ role: "status",
117
+ className: "sr-only",
118
+ children: state === "copied" ? copiedMessage : state === "failed" ? failedMessage : ""
119
+ })] });
120
+ }
121
+ export { SecretField };
@@ -1,5 +1,5 @@
1
- import { VariantProps } from "class-variance-authority";
2
1
  import { ComponentProps } from "react";
2
+ import { VariantProps } from "class-variance-authority";
3
3
  declare const sectionVariants: (props?: ({
4
4
  space?: "md" | "lg" | null | undefined;
5
5
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
@@ -92,11 +92,11 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
92
92
  width: track.offsetWidth,
93
93
  height: track.offsetHeight
94
94
  };
95
- track.style.setProperty("--track-width", `${size.width}px`);
96
- track.style.setProperty("--track-height", `${size.height}px`);
95
+ track.style.setProperty("--track-width", String(size.width));
96
+ track.style.setProperty("--track-height", String(size.height));
97
97
  if (!box) return void 0;
98
- track.style.setProperty("--thumb-left", `${box.left}px`);
99
- track.style.setProperty("--thumb-width", `${box.width}px`);
98
+ track.style.setProperty("--thumb-left", String(box.left));
99
+ track.style.setProperty("--thumb-width", String(box.width));
100
100
  return box;
101
101
  };
102
102
  const before = lastLeft.current;
@@ -106,8 +106,11 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
106
106
  if (!wasDropped) delete track.dataset.following;
107
107
  const box = place();
108
108
  const now = box?.left;
109
+ cancelAnimationFrame(leanFrame.current);
110
+ track.style.setProperty("--thumb-lean", "0");
111
+ track.style.setProperty("--thumb-s", "1");
112
+ delete track.dataset.moving;
109
113
  if (inertia && box && now !== void 0 && before !== void 0 && now !== before && track.hasAttribute("data-placed") && !reduced) {
110
- track.style.setProperty("--thumb-lean", "0px");
111
114
  busyUntil.current = performance.now() + 320;
112
115
  if (!wasDropped) {
113
116
  track.style.setProperty("--thumb-hold", now > before ? "1" : "-1");
@@ -128,7 +131,7 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
128
131
  const observer = new ResizeObserver(() => {
129
132
  const segment = pressed();
130
133
  if (!segment || drag.current?.moved) return;
131
- if (track.style.getPropertyValue("--thumb-left") === `${segment.offsetLeft}px` && track.style.getPropertyValue("--thumb-width") === `${segment.offsetWidth}px` && track.style.getPropertyValue("--track-width") === `${track.offsetWidth}px`) return;
134
+ if (track.style.getPropertyValue("--thumb-left") === String(segment.offsetLeft) && track.style.getPropertyValue("--thumb-width") === String(segment.offsetWidth) && track.style.getPropertyValue("--track-width") === String(track.offsetWidth)) return;
132
135
  track.dataset.settling = "";
133
136
  lastLeft.current = place()?.left;
134
137
  cancelAnimationFrame(settle);
@@ -149,6 +152,15 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
149
152
  cancelAnimationFrame(leanFrame.current);
150
153
  }, []);
151
154
  const still = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
155
+ /**
156
+ * How many viewport pixels one of the track's layout pixels takes: more than 1 under a zoomed
157
+ * ancestor or a scaled one. Pointer positions are viewport pixels and the places written onto
158
+ * the track are layout pixels, so a pointer's way is divided by this before it is used.
159
+ */
160
+ function zoomOf(track) {
161
+ const drawn = track.getBoundingClientRect().width;
162
+ return drawn > 0 && track.offsetWidth > 0 ? drawn / track.offsetWidth : 1;
163
+ }
152
164
  /** The first and the last place the thumb can stand at, as offsets in the track. */
153
165
  function walls(track) {
154
166
  const segments = track.querySelectorAll("[data-slot=\"segment\"]");
@@ -165,12 +177,12 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
165
177
  const wall = walls(track);
166
178
  if (!segment || !wall || performance.now() < busyUntil.current || still()) return;
167
179
  const box = segment.getBoundingClientRect();
168
- const offset = x < box.left ? x - box.left : x > box.right ? x - box.right : 0;
180
+ const offset = (x < box.left ? x - box.left : x > box.right ? x - box.right : 0) / zoomOf(track);
169
181
  const room = offset > 0 ? wall.end - segment.offsetLeft - segment.offsetWidth : segment.offsetLeft - wall.start;
170
182
  const shape = leanShape(offset, segment.offsetWidth, room);
171
183
  track.dataset.following = "";
172
184
  track.dataset.moving = "";
173
- track.style.setProperty("--thumb-lean", `${shape.shift.toFixed(2)}px`);
185
+ track.style.setProperty("--thumb-lean", shape.shift.toFixed(2));
174
186
  track.style.setProperty("--thumb-s", shape.stretch.toFixed(3));
175
187
  if (shape.stretch !== 1) track.style.setProperty("--thumb-hold", String(shape.hold));
176
188
  }
@@ -185,7 +197,7 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
185
197
  const track = event.currentTarget;
186
198
  cancelAnimationFrame(leanFrame.current);
187
199
  if (!inertia || drag.current?.moved || performance.now() < busyUntil.current) return;
188
- track.style.setProperty("--thumb-lean", "0px");
200
+ track.style.setProperty("--thumb-lean", "0");
189
201
  track.style.setProperty("--thumb-s", "1");
190
202
  }
191
203
  function grab(event) {
@@ -210,6 +222,7 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
210
222
  pointer: event.pointerId,
211
223
  startX: event.clientX,
212
224
  startMiddle: left + width / 2,
225
+ zoom: zoomOf(track),
213
226
  boxes: segments.map((each) => ({
214
227
  value: each.getAttribute("data-value"),
215
228
  left: each.offsetLeft,
@@ -227,12 +240,12 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
227
240
  if (!held || held.pointer !== event.pointerId) return lean(event);
228
241
  const track = event.currentTarget;
229
242
  if (event.buttons === 0 && !track.hasPointerCapture(event.pointerId)) return drop(event);
230
- const dx = event.clientX - held.startX;
243
+ const dx = (event.clientX - held.startX) / held.zoom;
231
244
  if (!held.moved && Math.abs(dx) < DRAG_SLOP) return;
232
245
  if (!held.moved) {
233
246
  held.moved = true;
234
247
  cancelAnimationFrame(leanFrame.current);
235
- track.style.setProperty("--thumb-lean", "0px");
248
+ track.style.setProperty("--thumb-lean", "0");
236
249
  track.style.setProperty("--thumb-s", "1");
237
250
  track.dataset.following = "";
238
251
  track.dataset.dragging = "";
@@ -254,8 +267,8 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
254
267
  const left = Math.min(Math.max(wish - width / 2, first.left), last.left + last.width - width);
255
268
  held.left = left;
256
269
  held.width = width;
257
- track.style.setProperty("--thumb-width", `${width.toFixed(2)}px`);
258
- track.style.setProperty("--thumb-left", `${left.toFixed(2)}px`);
270
+ track.style.setProperty("--thumb-width", width.toFixed(2));
271
+ track.style.setProperty("--thumb-left", left.toFixed(2));
259
272
  if (still()) return;
260
273
  held.motion = trackMotion(held.motion, left + width / 2, event.timeStamp, width, pillGive(width));
261
274
  const room = held.motion.direction > 0 ? left - first.left : last.left + last.width - left - width;
@@ -294,8 +307,8 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
294
307
  } else {
295
308
  const pressed = track.querySelector("[data-slot=\"segment\"][data-pressed]");
296
309
  if (pressed) {
297
- track.style.setProperty("--thumb-left", `${pressed.offsetLeft}px`);
298
- track.style.setProperty("--thumb-width", `${pressed.offsetWidth}px`);
310
+ track.style.setProperty("--thumb-left", String(pressed.offsetLeft));
311
+ track.style.setProperty("--thumb-width", String(pressed.offsetWidth));
299
312
  }
300
313
  lastLeft.current = pressed?.offsetLeft;
301
314
  }
@@ -357,7 +370,7 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
357
370
  className: "absolute inset-0",
358
371
  children: /* @__PURE__ */ jsx("span", {
359
372
  "data-slot": "segment-lens-labels",
360
- className: cn("absolute left-[calc(var(--thumb-fit)*-1)] inline-flex h-(--track-height) w-(--track-width) items-center", round ? "top-[calc(var(--thumb-fit)*-1)]" : "top-[calc(-3px-var(--thumb-fit))] gap-0.5 p-[3px]"),
373
+ className: cn("absolute left-[calc(var(--thumb-fit)*-1)] inline-flex h-[calc(var(--track-height)*1px)] w-[calc(var(--track-width)*1px)] items-center", round ? "top-[calc(var(--thumb-fit)*-1)]" : "top-[calc(-3px-var(--thumb-fit))] gap-0.5 p-[3px]"),
361
374
  children: /* @__PURE__ */ jsx(TrackContext, {
362
375
  value: lens,
363
376
  children
@@ -1,6 +1,6 @@
1
1
  import { IconSvgElement } from "../icon/icon.js";
2
- import { VariantProps } from "class-variance-authority";
3
2
  import { ReactNode } from "react";
3
+ import { VariantProps } from "class-variance-authority";
4
4
  import { Select as Select$1 } from "@base-ui/react/select";
5
5
  /** One entry of a select's `items`. */
6
6
  export type SelectOption<Value = string> = {
@@ -62,9 +62,10 @@ export type SelectItemProps = Select$1.Item.Props & {
62
62
  detail?: ReactNode;
63
63
  };
64
64
  /**
65
- * One option. The chosen one carries the mark: a disc, where the others have nothing (ring to
66
- * disc, with the ring left out to keep a long list calm). An icon, if the option has one, stands
67
- * between the mark and the label; a detail stands at the right edge. Both are muted.
65
+ * One option. Its label starts at the row's left edge, where the group's label does. An icon,
66
+ * if the option has one, stands before the label; a detail stands at the right edge. Both are
67
+ * muted. The chosen one carries the disc at the right end; where the options have a detail, it
68
+ * stands on the tint instead (`listTint`).
68
69
  */
69
70
  export declare function SelectItem({ className, children, icon, detail, ...props }: SelectItemProps): import("react").JSX.Element;
70
71
  export declare const SelectGroup: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").SelectGroupProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -4,11 +4,12 @@ import { buttonGroupKeyDisabledLook, buttonGroupKeyVariants } from "../button-gr
4
4
  import { useGround } from "../ground/ground.js";
5
5
  import { Icon } from "../icon/icon.js";
6
6
  import { ChevronDownGlyph } from "../../internal/glyphs.js";
7
+ import { ListMark, listTint } from "../../internal/list-mark.js";
7
8
  import { listGroupLabel, listItem, listSeparator, listSheet, popupMotion } from "../../internal/popup.js";
8
9
  import { mergeClassName } from "../../lib/cn.js";
9
10
  import { jsx, jsxs } from "react/jsx-runtime";
10
- import { cva } from "class-variance-authority";
11
11
  import { createContext, useContext, useMemo } from "react";
12
+ import { cva } from "class-variance-authority";
12
13
  import { Select as Select$1 } from "@base-ui/react/select";
13
14
  // src/components/select/select.tsx
14
15
  const OptionsContext = createContext(void 0);
@@ -150,36 +151,40 @@ function SelectContent({ className, side = "bottom", align = "start", sideOffset
150
151
  }) });
151
152
  }
152
153
  /**
153
- * One option. The chosen one carries the mark: a disc, where the others have nothing (ring to
154
- * disc, with the ring left out to keep a long list calm). An icon, if the option has one, stands
155
- * between the mark and the label; a detail stands at the right edge. Both are muted.
154
+ * One option. Its label starts at the row's left edge, where the group's label does. An icon,
155
+ * if the option has one, stands before the label; a detail stands at the right edge. Both are
156
+ * muted. The chosen one carries the disc at the right end; where the options have a detail, it
157
+ * stands on the tint instead (`listTint`).
156
158
  */
157
159
  function SelectItem({ className, children, icon, detail, ...props }) {
158
160
  const option = useContext(OptionsContext)?.find((candidate) => Object.is(candidate.value, props.value));
159
161
  const resolvedIcon = icon ?? option?.icon;
160
162
  const resolvedDetail = detail ?? option?.detail;
163
+ const tinted = resolvedDetail !== void 0;
161
164
  return /* @__PURE__ */ jsxs(Select$1.Item, {
162
165
  "data-slot": "select-item",
163
- className: mergeClassName(["group", listItem], className),
166
+ className: mergeClassName([
167
+ "group",
168
+ listItem,
169
+ tinted && listTint
170
+ ], className),
164
171
  ...props,
165
172
  children: [
166
- /* @__PURE__ */ jsx("span", {
167
- "aria-hidden": true,
168
- className: "mark mark-quiet group-data-selected:mark-on"
169
- }),
170
173
  resolvedIcon && /* @__PURE__ */ jsx(Icon, {
171
174
  icon: resolvedIcon,
172
- className: "text-fg-muted"
175
+ className: "text-fg-muted group-data-highlighted:text-fg"
173
176
  }),
174
177
  /* @__PURE__ */ jsx(Select$1.ItemText, {
175
178
  "data-slot": "select-item-text",
179
+ className: "min-w-0 truncate",
176
180
  children
177
181
  }),
178
182
  resolvedDetail !== void 0 && /* @__PURE__ */ jsx("span", {
179
183
  "data-slot": "select-item-detail",
180
184
  className: "ml-auto shrink-0 pl-3 whitespace-nowrap text-fg-muted tabular-nums",
181
185
  children: resolvedDetail
182
- })
186
+ }),
187
+ !tinted && /* @__PURE__ */ jsx(ListMark, { className: "ml-auto" })
183
188
  ]
184
189
  });
185
190
  }
@@ -0,0 +1,46 @@
1
+ import { Platform } from "../../lib/shortcut.js";
2
+ import { ComponentProps, ReactNode } from "react";
3
+ export type ShortcutProviderProps = {
4
+ /** The kind of keyboard the reader has, as the server knows it. */
5
+ platform: Platform;
6
+ children: ReactNode;
7
+ };
8
+ /**
9
+ * Tells every `Shortcut` below which keyboard to draw, for an app whose server knows it (from
10
+ * the `Sec-CH-UA-Platform` header, or a cookie set on the first visit). The page then arrives
11
+ * with the right keys. Without it a shortcut finds out in the browser.
12
+ */
13
+ export declare function ShortcutProvider({ platform, children }: ShortcutProviderProps): import("react").JSX.Element;
14
+ /** The kind of keyboard the reader has: `apple` or `other`. On the server it is `other`. */
15
+ export declare function usePlatform(): Platform;
16
+ export type ShortcutProps = Omit<ComponentProps<"kbd">, "children"> & {
17
+ /**
18
+ * The shortcut, as its keys joined by a plus: `mod+k`, `mod+shift+p`, `esc`, `/`. `mod` is
19
+ * ⌘ on an Apple device and Strg elsewhere.
20
+ */
21
+ keys: string;
22
+ /** Draw it for this keyboard, whatever the reader has: for a page that documents both. */
23
+ platform?: Platform;
24
+ };
25
+ /**
26
+ * A keyboard shortcut in the keys of the reader's own keyboard: ⌘ K on a Mac, Strg K on
27
+ * Windows. Put it at the end of the menu entry, the button or the tooltip that the shortcut
28
+ * stands for. It only shows the keys; `useShortcut` listens for them.
29
+ *
30
+ * A page that comes from a server cannot know the keyboard. A shortcut that differs between
31
+ * keyboards therefore keeps its place but stays unseen until the browser has looked, rather
32
+ * than showing the wrong key first. A `ShortcutProvider` spares it the wait.
33
+ */
34
+ export declare function Shortcut({ keys, platform: fixed, className, ...props }: ShortcutProps): import("react").JSX.Element;
35
+ export type UseShortcutOptions = {
36
+ /** Set to `false` while the shortcut should not answer (a dialog is open over its page). */
37
+ enabled?: boolean;
38
+ };
39
+ /**
40
+ * Calls `onPress` when the shortcut is pressed anywhere in the window, written like the `keys`
41
+ * of a `Shortcut`. The browser's own action for those keys is stopped.
42
+ *
43
+ * A shortcut without ⌘, Strg or Alt (`/`, `g`) does not answer while the reader types into a
44
+ * field. A press that is held down counts once.
45
+ */
46
+ export declare function useShortcut(keys: string, onPress: (event: KeyboardEvent) => void, { enabled }?: UseShortcutOptions): void;
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ import { Kbd } from "../kbd/kbd.js";
3
+ import { cn } from "../../lib/cn.js";
4
+ import { dependsOnPlatform, detectPlatform, hasCommandKey, isTypingTarget, matchesShortcut, shortcutKeys } from "../../lib/shortcut.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { createContext, useContext, useEffect, useEffectEvent, useSyncExternalStore } from "react";
7
+ // src/components/shortcut/shortcut.tsx
8
+ const PlatformContext = createContext(void 0);
9
+ /**
10
+ * Tells every `Shortcut` below which keyboard to draw, for an app whose server knows it (from
11
+ * the `Sec-CH-UA-Platform` header, or a cookie set on the first visit). The page then arrives
12
+ * with the right keys. Without it a shortcut finds out in the browser.
13
+ */
14
+ function ShortcutProvider({ platform, children }) {
15
+ return /* @__PURE__ */ jsx(PlatformContext, {
16
+ value: platform,
17
+ children
18
+ });
19
+ }
20
+ const never = () => () => {};
21
+ const unknown = () => void 0;
22
+ /** The reader's keyboard, or `undefined` for as long as only the browser could say. */
23
+ function useKnownPlatform() {
24
+ const given = useContext(PlatformContext);
25
+ const detected = useSyncExternalStore(never, detectPlatform, unknown);
26
+ return given ?? detected;
27
+ }
28
+ /** The kind of keyboard the reader has: `apple` or `other`. On the server it is `other`. */
29
+ function usePlatform() {
30
+ return useKnownPlatform() ?? "other";
31
+ }
32
+ /**
33
+ * A keyboard shortcut in the keys of the reader's own keyboard: ⌘ K on a Mac, Strg K on
34
+ * Windows. Put it at the end of the menu entry, the button or the tooltip that the shortcut
35
+ * stands for. It only shows the keys; `useShortcut` listens for them.
36
+ *
37
+ * A page that comes from a server cannot know the keyboard. A shortcut that differs between
38
+ * keyboards therefore keeps its place but stays unseen until the browser has looked, rather
39
+ * than showing the wrong key first. A `ShortcutProvider` spares it the wait.
40
+ */
41
+ function Shortcut({ keys, platform: fixed, className, ...props }) {
42
+ const known = useKnownPlatform();
43
+ const platform = fixed ?? known ?? "other";
44
+ const waits = fixed === void 0 && known === void 0 && dependsOnPlatform(keys);
45
+ const caps = shortcutKeys(keys, platform);
46
+ return /* @__PURE__ */ jsxs("kbd", {
47
+ "data-slot": "shortcut",
48
+ "data-platform": waits ? void 0 : platform,
49
+ className: cn("inline-flex shrink-0 items-center gap-1", waits && "invisible", className),
50
+ ...props,
51
+ children: [/* @__PURE__ */ jsx("span", {
52
+ className: "sr-only",
53
+ children: caps.map((cap) => cap.name).join(" ")
54
+ }), caps.map((cap, index) => /* @__PURE__ */ jsx(Kbd, {
55
+ "aria-hidden": true,
56
+ children: cap.label
57
+ }, index))]
58
+ });
59
+ }
60
+ /**
61
+ * Calls `onPress` when the shortcut is pressed anywhere in the window, written like the `keys`
62
+ * of a `Shortcut`. The browser's own action for those keys is stopped.
63
+ *
64
+ * A shortcut without ⌘, Strg or Alt (`/`, `g`) does not answer while the reader types into a
65
+ * field. A press that is held down counts once.
66
+ */
67
+ function useShortcut(keys, onPress, { enabled = true } = {}) {
68
+ const platform = usePlatform();
69
+ const pressed = useEffectEvent(onPress);
70
+ useEffect(() => {
71
+ if (!enabled) return;
72
+ const onKeyDown = (event) => {
73
+ if (event.defaultPrevented || event.repeat) return;
74
+ if (!matchesShortcut(event, keys, platform)) return;
75
+ if (!hasCommandKey(keys) && isTypingTarget(event.target)) return;
76
+ event.preventDefault();
77
+ pressed(event);
78
+ };
79
+ window.addEventListener("keydown", onKeyDown);
80
+ return () => window.removeEventListener("keydown", onKeyDown);
81
+ }, [
82
+ keys,
83
+ platform,
84
+ enabled
85
+ ]);
86
+ }
87
+ export { Shortcut, ShortcutProvider, usePlatform, useShortcut };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { createContext, useSyncExternalStore } from "react";
3
+ // src/components/sidebar/sidebar-context.ts
4
+ const SidebarStateContext = createContext(null);
5
+ /** From this width on the sidebar stands beside the page (Tailwind's `md`). */
6
+ const SIDEBAR_WIDE = "(min-width: 48rem)";
7
+ function subscribe(notify) {
8
+ const query = window.matchMedia(SIDEBAR_WIDE);
9
+ query.addEventListener("change", notify);
10
+ return () => query.removeEventListener("change", notify);
11
+ }
12
+ /** Whether the window is wide enough for the sidebar to stand beside the page. Yes on the server. */
13
+ function useWideWindow() {
14
+ return useSyncExternalStore(subscribe, () => window.matchMedia(SIDEBAR_WIDE).matches, () => true);
15
+ }
16
+ export { SIDEBAR_WIDE, SidebarStateContext, useWideWindow };