@lanfermann/ui 0.5.0 → 0.6.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 (165) hide show
  1. package/dist/components/action-bar/action-bar.d.ts +59 -0
  2. package/dist/components/action-bar/action-bar.js +116 -0
  3. package/dist/components/alert/alert.d.ts +1 -1
  4. package/dist/components/alert/alert.js +3 -17
  5. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  6. package/dist/components/app-shell/app-shell.d.ts +33 -0
  7. package/dist/components/app-shell/app-shell.js +93 -0
  8. package/dist/components/attachment/attachment.d.ts +46 -0
  9. package/dist/components/attachment/attachment.js +222 -0
  10. package/dist/components/attachment/kinds.d.ts +7 -0
  11. package/dist/components/attachment/kinds.js +100 -0
  12. package/dist/components/avatar/avatar.d.ts +14 -4
  13. package/dist/components/avatar/avatar.js +57 -13
  14. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  15. package/dist/components/avatar-group/avatar-group.js +110 -0
  16. package/dist/components/avatar-group/people.d.ts +12 -0
  17. package/dist/components/avatar-group/people.js +24 -0
  18. package/dist/components/badge/badge.d.ts +9 -3
  19. package/dist/components/badge/badge.js +21 -6
  20. package/dist/components/banner/banner.d.ts +39 -0
  21. package/dist/components/banner/banner.js +149 -0
  22. package/dist/components/card/card.d.ts +11 -3
  23. package/dist/components/card/card.js +18 -4
  24. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  25. package/dist/components/checkbox-card/checkbox-card.js +49 -0
  26. package/dist/components/chip/chip-group.d.ts +15 -0
  27. package/dist/components/chip/chip-group.js +44 -0
  28. package/dist/components/chip/chip-variants.d.ts +6 -0
  29. package/dist/components/chip/chip-variants.js +28 -0
  30. package/dist/components/chip/chip.d.ts +39 -0
  31. package/dist/components/chip/chip.js +71 -0
  32. package/dist/components/code-block/code-copy.d.ts +3 -11
  33. package/dist/components/code-block/code-copy.js +15 -62
  34. package/dist/components/code-block/code-keys.js +10 -22
  35. package/dist/components/combobox/combobox.d.ts +50 -2
  36. package/dist/components/combobox/combobox.js +178 -9
  37. package/dist/components/command/command.d.ts +131 -0
  38. package/dist/components/command/command.js +335 -0
  39. package/dist/components/consent/consent-card.js +365 -0
  40. package/dist/components/consent/consent-embed.d.ts +21 -0
  41. package/dist/components/consent/consent-embed.js +111 -0
  42. package/dist/components/consent/consent-labels.d.ts +70 -0
  43. package/dist/components/consent/consent-labels.js +61 -0
  44. package/dist/components/consent/consent-record.d.ts +95 -0
  45. package/dist/components/consent/consent-record.js +112 -0
  46. package/dist/components/consent/consent-store.d.ts +26 -0
  47. package/dist/components/consent/consent-store.js +240 -0
  48. package/dist/components/consent/consent.d.ts +86 -0
  49. package/dist/components/consent/consent.js +306 -0
  50. package/dist/components/container/container.d.ts +1 -1
  51. package/dist/components/context-menu/context-menu.d.ts +23 -0
  52. package/dist/components/context-menu/context-menu.js +50 -0
  53. package/dist/components/conversation/conversation.d.ts +45 -0
  54. package/dist/components/conversation/conversation.js +295 -0
  55. package/dist/components/conversation/stick.js +23 -0
  56. package/dist/components/copy-button/copy-button.d.ts +50 -0
  57. package/dist/components/copy-button/copy-button.js +65 -0
  58. package/dist/components/copy-page/copy-page.js +7 -17
  59. package/dist/components/copy-pill/copy-pill.js +1 -1
  60. package/dist/components/description-list/description-list.d.ts +32 -0
  61. package/dist/components/description-list/description-list.js +51 -0
  62. package/dist/components/empty/empty.d.ts +38 -0
  63. package/dist/components/empty/empty.js +57 -0
  64. package/dist/components/field/field.js +1 -1
  65. package/dist/components/file-upload/file-upload.d.ts +96 -0
  66. package/dist/components/file-upload/file-upload.js +347 -0
  67. package/dist/components/file-upload/files.d.ts +39 -0
  68. package/dist/components/file-upload/files.js +74 -0
  69. package/dist/components/grow/grow.d.ts +15 -3
  70. package/dist/components/grow/grow.js +24 -9
  71. package/dist/components/heading/heading.d.ts +1 -1
  72. package/dist/components/icon/icon.d.ts +1 -1
  73. package/dist/components/input/input.js +1 -1
  74. package/dist/components/message/message.d.ts +73 -0
  75. package/dist/components/message/message.js +196 -0
  76. package/dist/components/otp-field/otp-field.d.ts +37 -0
  77. package/dist/components/otp-field/otp-field.js +126 -0
  78. package/dist/components/pagination/pagination.d.ts +50 -0
  79. package/dist/components/pagination/pagination.js +188 -0
  80. package/dist/components/prompt-input/keys.js +15 -0
  81. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  82. package/dist/components/prompt-input/prompt-input.js +331 -0
  83. package/dist/components/radio-card/radio-card.d.ts +23 -0
  84. package/dist/components/radio-card/radio-card.js +48 -0
  85. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  86. package/dist/components/rolling-number/rolling-number.js +149 -0
  87. package/dist/components/seam/seam.d.ts +1 -1
  88. package/dist/components/secret-field/secret-field.d.ts +53 -0
  89. package/dist/components/secret-field/secret-field.js +121 -0
  90. package/dist/components/section/section.d.ts +1 -1
  91. package/dist/components/select/select.d.ts +1 -1
  92. package/dist/components/select/select.js +1 -1
  93. package/dist/components/shortcut/shortcut.d.ts +46 -0
  94. package/dist/components/shortcut/shortcut.js +87 -0
  95. package/dist/components/sidebar/sidebar-context.js +16 -0
  96. package/dist/components/sidebar/sidebar.d.ts +161 -0
  97. package/dist/components/sidebar/sidebar.js +588 -0
  98. package/dist/components/site-header/site-header.js +1 -1
  99. package/dist/components/skeleton/loaded.d.ts +21 -0
  100. package/dist/components/skeleton/loaded.js +57 -0
  101. package/dist/components/skeleton/skeleton.d.ts +43 -0
  102. package/dist/components/skeleton/skeleton.js +48 -0
  103. package/dist/components/sources/source-list.d.ts +17 -0
  104. package/dist/components/sources/source-list.js +26 -0
  105. package/dist/components/sources/sources.d.ts +45 -0
  106. package/dist/components/sources/sources.js +167 -0
  107. package/dist/components/stat/stat.d.ts +57 -0
  108. package/dist/components/stat/stat.js +110 -0
  109. package/dist/components/steps/steps.d.ts +57 -0
  110. package/dist/components/steps/steps.js +131 -0
  111. package/dist/components/table/table.d.ts +18 -9
  112. package/dist/components/table/table.js +21 -13
  113. package/dist/components/text/text.d.ts +1 -1
  114. package/dist/components/theme-switch/theme-switch.js +1 -1
  115. package/dist/components/time-field/time-field.js +1 -1
  116. package/dist/components/timeline/timeline.d.ts +45 -0
  117. package/dist/components/timeline/timeline.js +86 -0
  118. package/dist/components/toast/toast.js +10 -26
  119. package/dist/components/toggle/toggle.d.ts +24 -0
  120. package/dist/components/toggle/toggle.js +53 -0
  121. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  122. package/dist/components/toggle-group/toggle-group.js +38 -0
  123. package/dist/components/toolbar/toolbar-context.js +12 -0
  124. package/dist/components/toolbar/toolbar.d.ts +45 -0
  125. package/dist/components/toolbar/toolbar.js +92 -0
  126. package/dist/components/trace/trace.d.ts +2 -1
  127. package/dist/components/trace/trace.js +14 -26
  128. package/dist/index.d.ts +46 -3
  129. package/dist/index.js +44 -3
  130. package/dist/internal/arriving-pieces.js +56 -0
  131. package/dist/internal/arriving.js +171 -0
  132. package/dist/internal/avatar-cut.d.ts +15 -0
  133. package/dist/internal/avatar-cut.js +83 -0
  134. package/dist/internal/choice-card.d.ts +15 -0
  135. package/dist/internal/choice-card.js +65 -0
  136. package/dist/internal/clipboard.js +37 -0
  137. package/dist/internal/copy.js +58 -0
  138. package/dist/internal/field.js +24 -4
  139. package/dist/internal/glyphs.js +26 -1
  140. package/dist/internal/live-list.js +41 -0
  141. package/dist/internal/number-places.js +156 -0
  142. package/dist/internal/picker-sheet.js +1 -1
  143. package/dist/internal/presence-dot.js +24 -0
  144. package/dist/internal/presence.js +104 -0
  145. package/dist/internal/rail-mark.d.ts +3 -0
  146. package/dist/internal/rail-mark.js +33 -0
  147. package/dist/internal/status-icon.js +22 -0
  148. package/dist/internal/travelling-mark.js +204 -0
  149. package/dist/lib/cn.js +4 -0
  150. package/dist/lib/shortcut.d.ts +11 -0
  151. package/dist/lib/shortcut.js +165 -0
  152. package/package.json +1 -1
  153. package/src/styles/action-bar.css +28 -0
  154. package/src/styles/assistant.css +83 -0
  155. package/src/styles/avatar.css +24 -0
  156. package/src/styles/consent.css +65 -0
  157. package/src/styles/copy.css +12 -11
  158. package/src/styles/depth.css +46 -2
  159. package/src/styles/marks.css +20 -2
  160. package/src/styles/rail.css +49 -0
  161. package/src/styles/rolling-number.css +94 -0
  162. package/src/styles/steps.css +98 -0
  163. package/src/styles/timeline.css +48 -0
  164. package/src/styles/travel.css +36 -0
  165. package/src/styles.css +9 -0
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import { ChoiceCardBody, choiceCard, choiceControl } from "../../internal/choice-card.js";
3
+ import { cn } from "../../lib/cn.js";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { useId } from "react";
6
+ import { Radio } from "@base-ui/react/radio";
7
+ // src/components/radio-card/radio-card.tsx
8
+ /**
9
+ * One choice out of a few whose options need a sentence each: a plan, an answer in a set-up.
10
+ * The whole card is the control and the target. It is a softly raised sheet that stands still:
11
+ * a press anywhere on it dips its radio. Chosen, it takes the accent as its edge and the disc
12
+ * seats into its radio's socket, as in a plain `Radio`.
13
+ *
14
+ * Put the cards into a `RadioGroup` and lay them out with a class on it (`grid sm:grid-cols-3`
15
+ * with `gap-3`). The title names the choice, the sentence says what it means; keep both the
16
+ * same length from card to card. For options that are a word each, plain `Radio`s in rows are
17
+ * calmer.
18
+ */
19
+ function RadioCard({ title, description, detail, icon, chosen = "edge", className, children, ...props }) {
20
+ const titleId = useId();
21
+ const descriptionId = useId();
22
+ return /* @__PURE__ */ jsxs("label", {
23
+ "data-slot": "radio-card",
24
+ className: cn(choiceCard, chosen === "edge" && "has-[[data-slot=choice-control][data-checked]]:depth-card-chosen", className),
25
+ children: [/* @__PURE__ */ jsx(Radio.Root, {
26
+ "data-slot": "choice-control",
27
+ "aria-labelledby": titleId,
28
+ "aria-describedby": description === void 0 ? void 0 : descriptionId,
29
+ className: cn(choiceControl, "rounded-full bg-surface depth-socket transition-[box-shadow,scale]", "data-disabled:bg-disabled data-disabled:depth-flat"),
30
+ ...props,
31
+ children: /* @__PURE__ */ jsx(Radio.Indicator, {
32
+ keepMounted: true,
33
+ "data-slot": "radio-card-indicator",
34
+ className: "size-(--radio-dot) scale-0 rounded-full bg-accent transition-[scale] spring-leave group-data-checked/control:scale-100 group-data-checked/control:spring-seat group-data-disabled/control:bg-on-disabled forced-colors:bg-[color:CanvasText]"
35
+ })
36
+ }), /* @__PURE__ */ jsx(ChoiceCardBody, {
37
+ slot: "radio-card",
38
+ titleId,
39
+ descriptionId,
40
+ title,
41
+ description,
42
+ detail,
43
+ icon,
44
+ children
45
+ })]
46
+ });
47
+ }
48
+ export { RadioCard };
@@ -0,0 +1,30 @@
1
+ import { ComponentProps } from "react";
2
+ export type RollingNumberProps = Omit<ComponentProps<"span">, "children"> & {
3
+ value: number;
4
+ /** The language the number is written in. German by default: „1.234,50 €“. */
5
+ locale?: Intl.LocalesArgument;
6
+ /**
7
+ * How it is written: `{ style: "currency", currency: "EUR" }`, `{ style: "percent" }`,
8
+ * `{ notation: "compact" }`, a number of decimals. A value that rounds to zero never shows a
9
+ * minus. To keep decimals from coming and going, give `minimumFractionDigits`.
10
+ */
11
+ format?: Intl.NumberFormatOptions;
12
+ };
13
+ /**
14
+ * A number whose digits roll to a new value instead of being swapped: a total, a count, a price
15
+ * that changes while it is on screen. Each digit is a column of the ten digits moved by
16
+ * `translate`, and every column rolls the way the number moves (9 rolls forward into 0, as on an
17
+ * odometer). Tabular digits keep every column the same width. Grouping dots, the decimal comma,
18
+ * the currency sign and the percent sign stand still between the columns; a place that joins
19
+ * opens and fades in, one that leaves fades and closes, so what stands beside the number slides
20
+ * aside instead of jumping. A change that arrives while the digits still move takes them on
21
+ * from where they are.
22
+ *
23
+ * It does not count up on page load: what shows first is the plain number, and it rolls only
24
+ * when the value changes afterwards. Assistive tech reads the formatted value, not the columns;
25
+ * announce a change with a live region around it where the change is the news. Under reduced
26
+ * motion the digits change at once.
27
+ *
28
+ * German by default; `format` takes `Intl.NumberFormat` options.
29
+ */
30
+ export declare function RollingNumber({ value, locale, format, className, style, ref, ...props }: RollingNumberProps): import("react").JSX.Element;
@@ -0,0 +1,149 @@
1
+ "use client";
2
+ import { mergePlaces, nextRolls, numberFormat, toPlaces } from "../../internal/number-places.js";
3
+ import { useLive } from "../../internal/presence.js";
4
+ import { cn } from "../../lib/cn.js";
5
+ import { mergeRefs } from "../../lib/merge-refs.js";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ import { useEffect, useRef, useState } from "react";
8
+ // src/components/rolling-number/rolling-number.tsx
9
+ /** Formats are cached by what they are, so a `format` written inline costs nothing per render. */
10
+ const formats = /* @__PURE__ */ new Map();
11
+ function formatFor(locale, options) {
12
+ const key = JSON.stringify([locale, options]);
13
+ let format = formats.get(key);
14
+ if (!format) {
15
+ format = numberFormat(locale, options);
16
+ formats.set(key, format);
17
+ }
18
+ return format;
19
+ }
20
+ /** The ten digits of a format's numbering system, for the columns, when they are not 0 to 9. */
21
+ function digitsOf(format) {
22
+ const zero = format.formatToParts(0).find((part) => part.type === "integer")?.value ?? "0";
23
+ if (zero === "0") return void 0;
24
+ const code = zero.codePointAt(0) ?? 48;
25
+ return `"${[...Array.from({ length: 10 }, (_, digit) => digit), 0].map((digit) => String.fromCodePoint(code + digit)).join("\\A ")}"`;
26
+ }
27
+ /**
28
+ * A number whose digits roll to a new value instead of being swapped: a total, a count, a price
29
+ * that changes while it is on screen. Each digit is a column of the ten digits moved by
30
+ * `translate`, and every column rolls the way the number moves (9 rolls forward into 0, as on an
31
+ * odometer). Tabular digits keep every column the same width. Grouping dots, the decimal comma,
32
+ * the currency sign and the percent sign stand still between the columns; a place that joins
33
+ * opens and fades in, one that leaves fades and closes, so what stands beside the number slides
34
+ * aside instead of jumping. A change that arrives while the digits still move takes them on
35
+ * from where they are.
36
+ *
37
+ * It does not count up on page load: what shows first is the plain number, and it rolls only
38
+ * when the value changes afterwards. Assistive tech reads the formatted value, not the columns;
39
+ * announce a change with a live region around it where the change is the news. Under reduced
40
+ * motion the digits change at once.
41
+ *
42
+ * German by default; `format` takes `Intl.NumberFormat` options.
43
+ */
44
+ function RollingNumber({ value, locale = "de-DE", format, className, style, ref, ...props }) {
45
+ const formatter = formatFor(locale, format);
46
+ const parts = toPlaces(formatter, value);
47
+ const [model, setModel] = useState(() => ({
48
+ value,
49
+ text: parts.text,
50
+ unit: parts.unit,
51
+ shown: mergePlaces([], parts.places),
52
+ rolls: nextRolls({}, parts.places, 0),
53
+ swaps: 0
54
+ }));
55
+ if (model.value !== value || model.text !== parts.text) {
56
+ const swap = model.unit !== parts.unit;
57
+ setModel({
58
+ value,
59
+ text: parts.text,
60
+ unit: parts.unit,
61
+ shown: mergePlaces(swap ? [] : model.shown, parts.places),
62
+ rolls: swap ? nextRolls({}, parts.places, 0) : {
63
+ ...model.rolls,
64
+ ...nextRolls(model.rolls, parts.places, Math.sign(value - model.value))
65
+ },
66
+ swaps: swap ? model.swaps + 1 : model.swaps
67
+ });
68
+ }
69
+ const columns = useLive();
70
+ const [live, setLive] = useState(false);
71
+ useEffect(() => {
72
+ if (!columns) return;
73
+ const frame = requestAnimationFrame(() => setLive(true));
74
+ return () => cancelAnimationFrame(frame);
75
+ }, [columns]);
76
+ const root = useRef(null);
77
+ useEffect(() => {
78
+ if (!model.shown.some((place) => place.leaving)) return;
79
+ const frame = requestAnimationFrame(() => {
80
+ const still = [...root.current?.querySelectorAll("[data-leaving]") ?? []].filter((element) => element.getAnimations().length === 0).map((element) => element.dataset.key);
81
+ if (still.length > 0) setModel((current) => drop(current, (place) => still.includes(place.key)));
82
+ });
83
+ return () => cancelAnimationFrame(frame);
84
+ }, [model.shown]);
85
+ const settled = (event, key) => {
86
+ if (event.target !== event.currentTarget) return;
87
+ if (event.currentTarget.getAnimations().length > 0) return;
88
+ setModel((current) => drop(current, (place) => place.key === key));
89
+ };
90
+ const digits = digitsOf(formatter);
91
+ return /* @__PURE__ */ jsxs("span", {
92
+ ref: mergeRefs(root, ref),
93
+ "data-slot": "rolling-number",
94
+ "data-live": live ? "" : void 0,
95
+ className: cn("inline-flex tabular-nums", className),
96
+ style: digits ? {
97
+ "--rolling-digits": digits,
98
+ ...style
99
+ } : style,
100
+ ...props,
101
+ children: [/* @__PURE__ */ jsx("span", {
102
+ className: "sr-only",
103
+ suppressHydrationWarning: true,
104
+ children: model.text
105
+ }), columns ? /* @__PURE__ */ jsx("span", {
106
+ "aria-hidden": true,
107
+ className: "inline-flex select-none",
108
+ children: model.shown.map((place) => /* @__PURE__ */ jsx("span", {
109
+ "data-slot": "rolling-number-place",
110
+ "data-key": place.key,
111
+ "data-leaving": place.leaving ? "" : void 0,
112
+ onTransitionEnd: (event) => {
113
+ if (place.leaving) settled(event, place.key);
114
+ },
115
+ onTransitionCancel: (event) => {
116
+ if (place.leaving) settled(event, place.key);
117
+ },
118
+ children: place.kind === "digit" ? /* @__PURE__ */ jsx("span", {
119
+ "data-slot": "rolling-number-window",
120
+ children: /* @__PURE__ */ jsx("span", {
121
+ "data-slot": "rolling-number-column",
122
+ style: { "--roll": model.rolls[place.key] ?? place.digit }
123
+ })
124
+ }) : /* @__PURE__ */ jsx("span", {
125
+ "data-slot": "rolling-number-symbol",
126
+ children: place.text
127
+ })
128
+ }, place.key))
129
+ }, model.swaps) : /* @__PURE__ */ jsx("span", {
130
+ "aria-hidden": true,
131
+ suppressHydrationWarning: true,
132
+ className: "whitespace-pre",
133
+ children: model.text
134
+ })]
135
+ });
136
+ }
137
+ /** The model without the leaving places that `which` names, and without their columns. */
138
+ function drop(model, which) {
139
+ const gone = model.shown.filter((place) => place.leaving && which(place));
140
+ if (gone.length === 0) return model;
141
+ const rolls = { ...model.rolls };
142
+ for (const place of gone) delete rolls[place.key];
143
+ return {
144
+ ...model,
145
+ shown: model.shown.filter((place) => !gone.includes(place)),
146
+ rolls
147
+ };
148
+ }
149
+ export { RollingNumber };
@@ -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 seamVariants: (props?: ({
4
4
  direction?: "down" | "up" | null | undefined;
5
5
  above?: "ground" | "well" | "surface" | null | undefined;
@@ -0,0 +1,53 @@
1
+ import { InputProps } from "../input/input.js";
2
+ import { FieldSize } from "../../internal/field.js";
3
+ export type SecretFieldProps = Omit<InputProps, "value" | "defaultValue" | "onChange" | "readOnly" | "type" | "size"> & {
4
+ /** The value: an API key, a webhook's secret, an invitation link. */
5
+ value: string;
6
+ /** The size of the field, from the density. */
7
+ size?: FieldSize;
8
+ /**
9
+ * Whether the value can be hidden at all. `false` for something that is not a secret (an
10
+ * address, a link): the field then only shows and copies it.
11
+ */
12
+ hideable?: boolean;
13
+ /** Whether the value is shown (controlled). Hidden unless said otherwise. */
14
+ revealed?: boolean;
15
+ /** Whether the value is shown at first. */
16
+ defaultRevealed?: boolean;
17
+ onRevealedChange?: (revealed: boolean) => void;
18
+ /**
19
+ * How many characters at the start stay readable while the value is hidden: the prefix that
20
+ * says what kind of key it is (`lf_live_`).
21
+ */
22
+ visibleStart?: number;
23
+ /** Called once the value has reached the clipboard. */
24
+ onCopied?: () => void;
25
+ /** The name of the key that shows the value; it is a toggle. Also its tooltip while hidden. */
26
+ revealLabel?: string;
27
+ /** The tooltip of that key while the value is shown. */
28
+ hideLabel?: string;
29
+ /** The name of the copy key and its tooltip. */
30
+ copyLabel?: string;
31
+ /** The tooltip once the value is on the clipboard. */
32
+ copiedLabel?: string;
33
+ /** Read out once the value is on the clipboard: a full sentence. */
34
+ copiedMessage?: string;
35
+ /** The tooltip when the clipboard refused; the value is then shown and selected. */
36
+ failedLabel?: string;
37
+ /** Read out when the clipboard refused. */
38
+ failedMessage?: string;
39
+ /** Classes for the field as a whole, e.g. its width. */
40
+ className?: string;
41
+ };
42
+ /**
43
+ * A value that is read by machines and must not be read over a shoulder: an API key, the
44
+ * secret of a webhook. It stands in a field in mono, hidden behind discs until the key with
45
+ * the eye is pressed, and a second key copies it. The copy always takes the real value,
46
+ * hidden or not, and confirms with the drawn tick.
47
+ *
48
+ * The field cannot be typed into. Label it with a `FieldLabel` ("Geheimer Schlüssel") and say
49
+ * in a `FieldDescription` what the reader should do with it ("Er wird nur dieses eine Mal
50
+ * angezeigt."). While it is hidden the value is not in the page; when the browser refuses the
51
+ * clipboard, the value is shown and selected instead, so ⌘C still works.
52
+ */
53
+ export declare function SecretField({ value, size, hideable, revealed: revealedProp, defaultRevealed, onRevealedChange, visibleStart, onCopied, revealLabel, hideLabel, copyLabel, copiedLabel, copiedMessage, failedLabel, failedMessage, className, ref, ...props }: SecretFieldProps): import("react").JSX.Element;
@@ -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;
@@ -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> = {
@@ -7,8 +7,8 @@ import { ChevronDownGlyph } from "../../internal/glyphs.js";
7
7
  import { listGroupLabel, listItem, listSeparator, listSheet, popupMotion } from "../../internal/popup.js";
8
8
  import { mergeClassName } from "../../lib/cn.js";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
- import { cva } from "class-variance-authority";
11
10
  import { createContext, useContext, useMemo } from "react";
11
+ import { cva } from "class-variance-authority";
12
12
  import { Select as Select$1 } from "@base-ui/react/select";
13
13
  // src/components/select/select.tsx
14
14
  const OptionsContext = createContext(void 0);
@@ -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 };