@lanfermann/ui 0.3.0 → 0.4.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 (74) hide show
  1. package/dist/components/anchor-heading/anchor-heading.d.ts +1 -1
  2. package/dist/components/breadcrumbs/breadcrumbs.js +5 -10
  3. package/dist/components/button/button.d.ts +3 -0
  4. package/dist/components/button/button.js +14 -4
  5. package/dist/components/button-group/button-group-context.js +14 -0
  6. package/dist/components/button-group/button-group-variants.d.ts +14 -0
  7. package/dist/components/button-group/button-group-variants.js +93 -0
  8. package/dist/components/button-group/button-group.d.ts +36 -0
  9. package/dist/components/button-group/button-group.js +46 -0
  10. package/dist/components/code-block/code-block-frame.js +22 -6
  11. package/dist/components/code-block/code-block-live.d.ts +3 -3
  12. package/dist/components/code-block/code-block-live.js +5 -3
  13. package/dist/components/code-block/code-block.d.ts +7 -3
  14. package/dist/components/code-block/code-block.js +9 -3
  15. package/dist/components/code-block/code-keys.d.ts +24 -0
  16. package/dist/components/code-block/code-keys.js +107 -0
  17. package/dist/components/code-block/code-scroll.js +2 -1
  18. package/dist/components/code-block/code-tabs-frame.js +12 -5
  19. package/dist/components/code-block/code-tabs.d.ts +9 -4
  20. package/dist/components/code-block/code-tabs.js +9 -6
  21. package/dist/components/code-block/lines.js +23 -1
  22. package/dist/components/copy-page/copy-page.d.ts +4 -4
  23. package/dist/components/copy-page/copy-page.js +16 -28
  24. package/dist/components/docs-layout/docs-layout.d.ts +1 -1
  25. package/dist/components/docs-layout/docs-layout.js +3 -3
  26. package/dist/components/docs-layout/docs-nav.d.ts +51 -0
  27. package/dist/components/docs-layout/docs-nav.js +60 -0
  28. package/dist/components/grow/grow.d.ts +20 -0
  29. package/dist/components/grow/grow.js +98 -0
  30. package/dist/components/heading/heading.d.ts +4 -0
  31. package/dist/components/heading/heading.js +8 -4
  32. package/dist/components/hover-card/hover-card.d.ts +24 -0
  33. package/dist/components/hover-card/hover-card.js +51 -0
  34. package/dist/components/pager/pager.js +19 -24
  35. package/dist/components/scroll-fade/scroll-fade.d.ts +29 -0
  36. package/dist/components/scroll-fade/scroll-fade.js +40 -0
  37. package/dist/components/scroll-fade/use-scroll-edges.d.ts +13 -0
  38. package/dist/{internal/scroll-edges.js → components/scroll-fade/use-scroll-edges.js} +10 -7
  39. package/dist/components/section/section.d.ts +2 -1
  40. package/dist/components/section/section.js +2 -1
  41. package/dist/components/segmented-control/segmented-control.d.ts +7 -1
  42. package/dist/components/segmented-control/segmented-control.js +22 -11
  43. package/dist/components/select/select.d.ts +4 -1
  44. package/dist/components/select/select.js +15 -3
  45. package/dist/components/shimmer/shimmer.d.ts +21 -0
  46. package/dist/components/shimmer/shimmer.js +24 -0
  47. package/dist/components/side-nav/side-nav.js +11 -20
  48. package/dist/components/site-header/site-header.d.ts +1 -1
  49. package/dist/components/site-header/site-header.js +6 -3
  50. package/dist/components/slider/slider.d.ts +3 -1
  51. package/dist/components/slider/slider.js +45 -19
  52. package/dist/components/table/table.js +2 -1
  53. package/dist/components/tabs/tabs.js +3 -2
  54. package/dist/components/theme-switch/theme-switch.d.ts +47 -0
  55. package/dist/components/theme-switch/theme-switch.js +102 -0
  56. package/dist/components/trace/trace.d.ts +71 -0
  57. package/dist/components/trace/trace.js +201 -0
  58. package/dist/index.d.ts +11 -2
  59. package/dist/index.js +10 -2
  60. package/dist/internal/render-as.js +24 -0
  61. package/dist/internal/rule.js +5 -4
  62. package/package.json +1 -1
  63. package/src/styles/button-group.css +57 -0
  64. package/src/styles/code.css +13 -37
  65. package/src/styles/marks.css +10 -0
  66. package/src/styles/motion.css +4 -3
  67. package/src/styles/scroll-fade.css +26 -20
  68. package/src/styles/shimmer.css +68 -0
  69. package/src/styles/slider.css +57 -19
  70. package/src/styles.css +2 -1
  71. package/dist/components/page-header/page-header.d.ts +0 -30
  72. package/dist/components/page-header/page-header.js +0 -49
  73. package/dist/internal/scroll-fade.js +0 -24
  74. package/src/styles/tabs.css +0 -39
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { cn } from "../../lib/cn.js";
3
- import { CodeCopy } from "./code-copy.js";
3
+ import { CodeKeys } from "./code-keys.js";
4
4
  import { CodeScroll } from "./code-scroll.js";
5
5
  import { codeHead, codeRoot } from "./code-surface.js";
6
6
  import { readChoice, subscribeChoices, writeChoice } from "./code-tabs-store.js";
@@ -11,9 +11,10 @@ import { Tabs } from "@base-ui/react/tabs";
11
11
  /**
12
12
  * The client half of CodeTabs: a row of tabs in the header, each with its mark, and one soft
13
13
  * highlight that glides to the chosen tab (`glide`, placed by Base UI's measure and moved by
14
- * `translate`). The copy button takes the code that is shown.
14
+ * `translate`). The keys at the end of the header take the code that is shown.
15
15
  */
16
- function CodeTabsFrame({ children, tabs, group, defaultValue, label, className, ...labels }) {
16
+ function CodeTabsFrame({ children, tabs, group, defaultValue, label, download, wrap = false, wrapToggle = false, className, ...keyOptions }) {
17
+ const [wrapped, setWrapped] = useState(wrap);
17
18
  const names = tabs.map((tab) => tab.label);
18
19
  const [own, setOwn] = useState(defaultValue ?? names[0]);
19
20
  const shared = useSyncExternalStore(subscribeChoices, () => group ? readChoice(group) : void 0, () => void 0);
@@ -36,6 +37,7 @@ function CodeTabsFrame({ children, tabs, group, defaultValue, label, className,
36
37
  setOwn(next);
37
38
  if (group) writeChoice(group, next);
38
39
  },
40
+ "data-wrap": wrapToggle ? wrapped ? "on" : "off" : void 0,
39
41
  className: cn(codeRoot, className),
40
42
  children: [/* @__PURE__ */ jsxs("div", {
41
43
  "data-slot": "code-tabs-header",
@@ -56,10 +58,15 @@ function CodeTabsFrame({ children, tabs, group, defaultValue, label, className,
56
58
  "data-slot": "code-tabs-indicator",
57
59
  className: cn("absolute top-(--active-tab-top) left-0 -z-10 h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) rounded-sm bg-hover", "forced-colors:outline forced-colors:-outline-offset-1", placed && "transition-[translate,width] spring-glide")
58
60
  })]
59
- }), /* @__PURE__ */ jsx(CodeCopy, {
61
+ }), /* @__PURE__ */ jsx(CodeKeys, {
60
62
  text: tabs[index]?.copyText ?? "",
61
63
  codeRef: activeCode,
62
- ...labels
64
+ fileName: tabs[index]?.fileName,
65
+ download,
66
+ wrapToggle,
67
+ wrapped,
68
+ onWrappedChange: setWrapped,
69
+ ...keyOptions
63
70
  })]
64
71
  }), panels.map((panel, at) => /* @__PURE__ */ jsx(Tabs.Panel, {
65
72
  value: names[at],
@@ -1,4 +1,4 @@
1
- import { CodeCopyLabels } from "./code-copy.js";
1
+ import { CodeKeyOptions } from "./code-keys.js";
2
2
  import { CodeLinesOptions } from "./code-lines-view.js";
3
3
  import { CodeLanguage } from "./highlight.js";
4
4
  export type CodeTab = CodeLinesOptions & {
@@ -6,8 +6,10 @@ export type CodeTab = CodeLinesOptions & {
6
6
  label: string;
7
7
  code: string;
8
8
  language?: CodeLanguage;
9
+ /** The file this version is saved as when the block has a download key. */
10
+ fileName?: string;
9
11
  };
10
- export type CodeTabsProps = CodeCopyLabels & {
12
+ export type CodeTabsProps = Omit<CodeKeyOptions, "download"> & {
11
13
  items: CodeTab[];
12
14
  /**
13
15
  * Blocks with the same group share the reader's choice: picking „bun“ in one shows bun in all
@@ -18,11 +20,14 @@ export type CodeTabsProps = CodeCopyLabels & {
18
20
  defaultValue?: string;
19
21
  /** The name of the tab row, and of each code region after it. */
20
22
  label?: string;
23
+ /** Adds a key that saves the version that is shown, as its tab's `fileName`. */
24
+ download?: boolean;
21
25
  className?: string;
22
26
  };
23
27
  /**
24
28
  * One block, several versions of the same code: the install command for each package manager,
25
29
  * or a component and its stylesheet. The tabs sit in the header with their marks; the copy
26
- * button copies the version that is shown.
30
+ * button copies the version that is shown, and so do the download and the line wrap when the
31
+ * block has them (see `CodeBlock`).
27
32
  */
28
- export declare function CodeTabs({ items, group, defaultValue, label, className, ...copyLabels }: CodeTabsProps): import("react").JSX.Element;
33
+ export declare function CodeTabs({ items, group, defaultValue, label, className, ...keyOptions }: CodeTabsProps): import("react").JSX.Element;
@@ -1,25 +1,28 @@
1
1
  import { CodeLines } from "./code-lines.js";
2
2
  import { CodeTabsFrame } from "./code-tabs-frame.js";
3
- import { copyText } from "./lines.js";
3
+ import { codeFileName, copyText } from "./lines.js";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  // src/components/code-block/code-tabs.tsx
6
6
  /**
7
7
  * One block, several versions of the same code: the install command for each package manager,
8
8
  * or a component and its stylesheet. The tabs sit in the header with their marks; the copy
9
- * button copies the version that is shown.
9
+ * button copies the version that is shown, and so do the download and the line wrap when the
10
+ * block has them (see `CodeBlock`).
10
11
  */
11
- function CodeTabs({ items, group, defaultValue, label = "Code", className, ...copyLabels }) {
12
+ function CodeTabs({ items, group, defaultValue, label = "Code", className, ...keyOptions }) {
12
13
  return /* @__PURE__ */ jsx(CodeTabsFrame, {
13
14
  tabs: items.map((item) => ({
14
15
  label: item.label,
15
- copyText: copyText(item.code, item.removed)
16
+ copyText: copyText(item.code, item.removed),
17
+ fileName: item.fileName ?? codeFileName(void 0, item.language)
16
18
  })),
17
19
  group,
18
20
  defaultValue,
19
21
  label,
22
+ wrap: items.every((item) => item.wrap),
20
23
  className,
21
- ...copyLabels,
22
- children: items.map(({ label: name, code, language = "text", ...lines }) => /* @__PURE__ */ jsx(CodeLines, {
24
+ ...keyOptions,
25
+ children: items.map(({ label: name, code, language = "text", fileName: _, ...lines }) => /* @__PURE__ */ jsx(CodeLines, {
23
26
  code,
24
27
  language,
25
28
  ...lines
@@ -37,4 +37,26 @@ function lineKinds(count, { marked, added, removed }) {
37
37
  ];
38
38
  return Array.from({ length: count }, (_, i) => r.has(i + 1) ? "removed" : a.has(i + 1) ? "added" : m.has(i + 1) ? "marked" : void 0);
39
39
  }
40
- export { copyText, lineKinds, parseLines, trimCode };
40
+ /**
41
+ * The file a block of code is saved as when nothing names it: the last part of its title if that
42
+ * is a file's name ("app/api/route.ts" gives "route.ts"), or `code` with the ending of its
43
+ * language.
44
+ */
45
+ function codeFileName(title, language = "text") {
46
+ const name = title?.split(/[/\\]/).pop();
47
+ if (name && /^\S*\.[A-Za-z0-9]+$/.test(name)) return name;
48
+ return `code.${{
49
+ text: "txt",
50
+ shell: "sh",
51
+ bash: "sh",
52
+ zsh: "sh",
53
+ typescript: "ts",
54
+ javascript: "js",
55
+ markdown: "md",
56
+ python: "py",
57
+ powershell: "ps1",
58
+ dotenv: "env",
59
+ yml: "yaml"
60
+ }[language] ?? language}`;
61
+ }
62
+ export { codeFileName, copyText, lineKinds, parseLines, trimCode };
@@ -1,5 +1,5 @@
1
1
  import { ComponentProps } from "react";
2
- export type CopyPageProps = Omit<ComponentProps<"div">, "children"> & {
2
+ export type CopyPageProps = Omit<ComponentProps<"div">, "children" | "aria-label" | "aria-labelledby"> & {
3
3
  /** The page as Markdown, on this site: what is copied, and what "view" opens. */
4
4
  href: string;
5
5
  /** The button, and the first entry of the menu: the thing, then the action ("Seite kopieren"). */
@@ -24,10 +24,10 @@ export type CopyPageProps = Omit<ComponentProps<"div">, "children"> & {
24
24
  /**
25
25
  * Hands a docs page on as Markdown: one raised fitting split in two, the copy and the menu. The
26
26
  * copy fetches the page's Markdown and puts it on the clipboard, for a model or an agent; the
27
- * menu repeats it with a line on what it is, and opens the Markdown in a new tab. Put it in the
28
- * page header, at the end of the row above the title.
27
+ * menu repeats it with a line on what it is, and opens the Markdown in a new tab. Put it at the
28
+ * end of the row above the page's title.
29
29
  *
30
- * It is one part with two keys, so it moves as one: under the pointer the whole fitting lifts,
30
+ * It is a `ButtonGroup`, named by its `label`: one part with two keys, so it moves as one: under the pointer the whole fitting lifts,
31
31
  * and the key under it takes the hover wash. Pressed, the fitting goes down and drops its
32
32
  * ambient shadow, and only the pressed key takes the inner shade, so it rocks on that key and the
33
33
  * other keeps its gloss. A copy is confirmed in the key, as in a code block: the copy symbol
@@ -1,4 +1,6 @@
1
1
  "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { ButtonGroup } from "../button-group/button-group.js";
2
4
  import { Icon } from "../icon/icon.js";
3
5
  import { MenuContent, MenuItem, MenuLinkItem } from "../menu/menu.js";
4
6
  import { ActionArrow } from "../../internal/arrow.js";
@@ -14,10 +16,10 @@ const CONFIRM_MS = 1600;
14
16
  /**
15
17
  * Hands a docs page on as Markdown: one raised fitting split in two, the copy and the menu. The
16
18
  * copy fetches the page's Markdown and puts it on the clipboard, for a model or an agent; the
17
- * menu repeats it with a line on what it is, and opens the Markdown in a new tab. Put it in the
18
- * page header, at the end of the row above the title.
19
+ * menu repeats it with a line on what it is, and opens the Markdown in a new tab. Put it at the
20
+ * end of the row above the page's title.
19
21
  *
20
- * It is one part with two keys, so it moves as one: under the pointer the whole fitting lifts,
22
+ * It is a `ButtonGroup`, named by its `label`: one part with two keys, so it moves as one: under the pointer the whole fitting lifts,
21
23
  * and the key under it takes the hover wash. Pressed, the fitting goes down and drops its
22
24
  * ambient shadow, and only the pressed key takes the inner shade, so it rocks on that key and the
23
25
  * other keeps its gloss. A copy is confirmed in the key, as in a code block: the copy symbol
@@ -71,9 +73,11 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
71
73
  }
72
74
  }
73
75
  const isCopied = state === "copied";
74
- return /* @__PURE__ */ jsxs("div", {
76
+ return /* @__PURE__ */ jsxs(ButtonGroup, {
77
+ size: "sm",
78
+ "aria-label": label,
75
79
  "data-slot": "copy-page",
76
- className: cn("relative inline-flex h-(--control-sm) shrink-0 items-stretch rounded-md bg-raised depth-raised text-sm font-medium text-fg", "transition-[box-shadow,scale] spring-seat", "has-[button:hover]:spring-snap has-[button:hover:not(:active)]:depth-raised-hover", "has-[button:active]:scale-(--motion-press-scale) has-[button:active]:shadow-pressed has-[button:active]:spring-snap", className),
80
+ className: cn("rounded-md", className),
77
81
  onPointerEnter: (event) => {
78
82
  load().catch(() => {});
79
83
  onPointerEnter?.(event);
@@ -84,12 +88,11 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
84
88
  },
85
89
  ...props,
86
90
  children: [
87
- /* @__PURE__ */ jsxs("button", {
88
- type: "button",
91
+ /* @__PURE__ */ jsxs(Button, {
89
92
  "data-slot": "copy-page-copy",
90
93
  "data-copied": isCopied ? "" : void 0,
91
94
  onClick: () => void copy(),
92
- className: cn(key, "gap-1.5 rounded-l-md pr-2.5 pl-(--control-pad-sm)"),
95
+ className: "pr-2.5",
93
96
  children: [/* @__PURE__ */ jsxs("span", {
94
97
  className: "relative flex size-4 shrink-0 items-center justify-center",
95
98
  children: [/* @__PURE__ */ jsx(Icon, {
@@ -106,18 +109,15 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
106
109
  })]
107
110
  }), label]
108
111
  }),
109
- /* @__PURE__ */ jsx("span", {
110
- "aria-hidden": true,
111
- "data-slot": "copy-page-divider",
112
- className: "w-px bg-hairline"
113
- }),
114
112
  /* @__PURE__ */ jsxs(Menu.Root, {
115
113
  modal: false,
116
114
  defaultOpen,
117
115
  children: [/* @__PURE__ */ jsx(Menu.Trigger, {
118
- "data-slot": "copy-page-more",
119
- "aria-label": moreLabel,
120
- className: cn(key, "group/more justify-center rounded-r-md px-1.5 data-popup-open:bg-hover pointer-coarse:px-2.5"),
116
+ render: /* @__PURE__ */ jsx(Button, {
117
+ "data-slot": "copy-page-more",
118
+ "aria-label": moreLabel,
119
+ className: "group/more px-1.5 pointer-coarse:px-2.5"
120
+ }),
121
121
  children: /* @__PURE__ */ jsx(ChevronDownGlyph, {
122
122
  width: 12,
123
123
  height: 12,
@@ -160,18 +160,6 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
160
160
  ]
161
161
  });
162
162
  }
163
- /**
164
- * One key of the fitting. It has no face of its own: the fitting's gloss shows through, a wash
165
- * marks the key under the pointer, and a press shades only this key. On a touch screen its target
166
- * grows to 44px up and down, never sideways, so the two keys never take each other's taps.
167
- */
168
- const key = [
169
- "relative inline-flex items-center outline-offset-2 select-none",
170
- "transition-[background-color,box-shadow] spring-seat hover:bg-hover hover:spring-snap",
171
- "active:bg-raised-pressed active:inset-shadow-pressed active:spring-snap",
172
- "focus-visible:z-1 focus-visible:rounded-md focus-visible:outline-2 focus-visible:outline-accent",
173
- "pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 pointer-coarse:after:top-1/2 pointer-coarse:after:h-11 pointer-coarse:after:-translate-y-1/2 pointer-coarse:after:content-['']"
174
- ].join(" ");
175
163
  /** A row of the menu: a tile, then two lines. It keeps the list's instant highlight. */
176
164
  const row = "group/row items-center gap-3 px-2 py-2";
177
165
  function Tile({ children }) {
@@ -5,7 +5,7 @@ import { ComponentProps } from "react";
5
5
  * in the middle, the page's sections on the right.
6
6
  *
7
7
  * The side columns stay in view while the text scrolls, below a sticky bar of the height in
8
- * `--docs-top` (4rem: the `SiteHeader`'s bar, 8px off the top and 56px tall). A side column
8
+ * `--docs-top` (3.5rem: the `SiteHeader`'s bar, 8px off the top and 48px tall). A side column
9
9
  * longer than the window scrolls inside itself, and fades at the end that has more. The pages
10
10
  * column shows from `lg`, the sections column from `xl`; below that, the pages go into the
11
11
  * site's menu and the sections fold above the text.
@@ -1,5 +1,5 @@
1
1
  import { containerVariants } from "../container/container.js";
2
- import { ScrollFade } from "../../internal/scroll-fade.js";
2
+ import { ScrollFade } from "../scroll-fade/scroll-fade.js";
3
3
  import { cn } from "../../lib/cn.js";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  // src/components/docs-layout/docs-layout.tsx
@@ -9,7 +9,7 @@ import { jsx } from "react/jsx-runtime";
9
9
  * in the middle, the page's sections on the right.
10
10
  *
11
11
  * The side columns stay in view while the text scrolls, below a sticky bar of the height in
12
- * `--docs-top` (4rem: the `SiteHeader`'s bar, 8px off the top and 56px tall). A side column
12
+ * `--docs-top` (3.5rem: the `SiteHeader`'s bar, 8px off the top and 48px tall). A side column
13
13
  * longer than the window scrolls inside itself, and fades at the end that has more. The pages
14
14
  * column shows from `lg`, the sections column from `xl`; below that, the pages go into the
15
15
  * site's menu and the sections fold above the text.
@@ -17,7 +17,7 @@ import { jsx } from "react/jsx-runtime";
17
17
  function DocsLayout({ className, ...props }) {
18
18
  return /* @__PURE__ */ jsx("div", {
19
19
  "data-slot": "docs-layout",
20
- className: cn(containerVariants(), "grid [--docs-top:4rem] lg:grid-cols-[13.5rem_minmax(0,1fr)] lg:gap-x-10 xl:grid-cols-[13.5rem_minmax(0,1fr)_12rem]", className),
20
+ className: cn(containerVariants(), "grid [--docs-top:3.5rem] lg:grid-cols-[13.5rem_minmax(0,1fr)] lg:gap-x-10 xl:grid-cols-[13.5rem_minmax(0,1fr)_12rem]", className),
21
21
  ...props
22
22
  });
23
23
  }
@@ -0,0 +1,51 @@
1
+ /** One page of the set. A page may have subpages, which are read after it. */
2
+ export type DocsPage = {
3
+ /** The page's name, as it stands in the navigation and above the page. */
4
+ title: string;
5
+ /** Where it is, as the site's router knows it ("/doku/schnellstart"). */
6
+ href: string;
7
+ /** Pages under this one. They show in the navigation while the reader is on it or on them. */
8
+ pages?: readonly DocsPage[];
9
+ };
10
+ /** A part of the set: a noun ("Anleitungen") and the pages under it. */
11
+ export type DocsGroup = {
12
+ title: string;
13
+ pages: readonly DocsPage[];
14
+ };
15
+ /** The whole set, in the order it is read. */
16
+ export type DocsNav = readonly DocsGroup[];
17
+ /** A step of the trail above a page's title. A group is no page and has no `href`. */
18
+ export type DocsCrumb = {
19
+ title: string;
20
+ href?: string;
21
+ };
22
+ /** Where a page stands in its set. */
23
+ export type DocsPlace = {
24
+ page: DocsPage;
25
+ /** The part of the set it belongs to. */
26
+ group: DocsGroup;
27
+ /** The page it lies under, if it is a subpage. */
28
+ parent?: DocsPage;
29
+ /** The page read before it and the one read after it, across groups. None at either end. */
30
+ previous?: DocsPage;
31
+ next?: DocsPage;
32
+ /** What stands above it, from the outside in: its group, then its parent. Not the page. */
33
+ trail: DocsCrumb[];
34
+ };
35
+ /** Whether two addresses lead to the same page ("/doku/start/" and "/doku/start#bevor"). */
36
+ export declare function sameDocsPage(a: string, b: string): boolean;
37
+ /** Every page of the set in reading order: each page, then its subpages, group after group. */
38
+ export declare function docsPages(nav: DocsNav): DocsPage[];
39
+ /**
40
+ * Where the page at `href` stands: its group, its parent, the trail above it and the pages
41
+ * before and after it. `undefined` when the set has no such page.
42
+ */
43
+ export declare function findDocsPage(nav: DocsNav, href: string): DocsPlace | undefined;
44
+ /**
45
+ * Whether a page of the navigation is the one being read, or lies above it: the first wears
46
+ * `current`, the second is `open` so its subpages show.
47
+ */
48
+ export declare function docsPageState(page: DocsPage, href: string): {
49
+ current: boolean;
50
+ open: boolean;
51
+ };
@@ -0,0 +1,60 @@
1
+ // src/components/docs-layout/docs-nav.ts
2
+ /** An address without what does not name a page: its query, its fragment, a closing slash. */
3
+ function pathOf(href) {
4
+ const path = href.replace(/[?#].*$/, "");
5
+ return path.length > 1 ? path.replace(/\/+$/, "") : path;
6
+ }
7
+ /** Whether two addresses lead to the same page ("/doku/start/" and "/doku/start#bevor"). */
8
+ function sameDocsPage(a, b) {
9
+ return pathOf(a) === pathOf(b);
10
+ }
11
+ /** Every page of the set in reading order: each page, then its subpages, group after group. */
12
+ function docsPages(nav) {
13
+ const walk = (pages) => pages.flatMap((page) => [page, ...walk(page.pages ?? [])]);
14
+ return nav.flatMap((group) => walk(group.pages));
15
+ }
16
+ /**
17
+ * Where the page at `href` stands: its group, its parent, the trail above it and the pages
18
+ * before and after it. `undefined` when the set has no such page.
19
+ */
20
+ function findDocsPage(nav, href) {
21
+ const order = docsPages(nav);
22
+ const at = order.findIndex((page) => sameDocsPage(page.href, href));
23
+ const page = order[at];
24
+ if (!page) return void 0;
25
+ const within = (pages, above) => {
26
+ for (const candidate of pages) {
27
+ if (candidate === page) return above;
28
+ const deeper = within(candidate.pages ?? [], [...above, candidate]);
29
+ if (deeper) return deeper;
30
+ }
31
+ };
32
+ for (const group of nav) {
33
+ const above = within(group.pages, []);
34
+ if (!above) continue;
35
+ return {
36
+ page,
37
+ group,
38
+ parent: above[above.length - 1],
39
+ previous: order[at - 1],
40
+ next: order[at + 1],
41
+ trail: [{ title: group.title }, ...above.map((parent) => ({
42
+ title: parent.title,
43
+ href: parent.href
44
+ }))]
45
+ };
46
+ }
47
+ }
48
+ /**
49
+ * Whether a page of the navigation is the one being read, or lies above it: the first wears
50
+ * `current`, the second is `open` so its subpages show.
51
+ */
52
+ function docsPageState(page, href) {
53
+ const current = sameDocsPage(page.href, href);
54
+ const holds = (pages) => pages.some((sub) => sameDocsPage(sub.href, href) || holds(sub.pages ?? []));
55
+ return {
56
+ current,
57
+ open: !current && holds(page.pages ?? [])
58
+ };
59
+ }
60
+ export { docsPageState, docsPages, findDocsPage, sameDocsPage };
@@ -0,0 +1,20 @@
1
+ import { ComponentProps } from "react";
2
+ export type GrowProps = ComponentProps<"div">;
3
+ /**
4
+ * A block whose height follows what it holds. When something joins it (a step of a `Trace`, a
5
+ * paragraph that arrives, the next tab's panel), it eases to its new height on `settle`, and
6
+ * what stands below moves down with it instead of jumping. It shrinks the same way.
7
+ *
8
+ * Put it around the part that changes, not around the page: what stands inside below the change
9
+ * still moves at once. Give each part that grows on its own a `Grow` of its own, side by side;
10
+ * one inside another sets its height in the middle of the other's measuring, and the outer one
11
+ * then learns of it a frame late.
12
+ *
13
+ * At rest it is a plain block of the content's height that clips nothing. It clips only while
14
+ * it moves, so a line that joins at its foot is uncovered as the block opens. From rest it does
15
+ * not animate the first height, a resize of the window, or a height that something inside is
16
+ * already animating (an opening `Collapsible`): then it simply follows.
17
+ * Already on its way, it takes a new height as its goal from where it stands. Under reduced
18
+ * motion it always follows.
19
+ */
20
+ export declare function Grow({ className, children, ref, ...props }: GrowProps): import("react").JSX.Element;
@@ -0,0 +1,98 @@
1
+ "use client";
2
+ import { cn } from "../../lib/cn.js";
3
+ import { mergeRefs } from "../../lib/merge-refs.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { useLayoutEffect, useRef } from "react";
6
+ // src/components/grow/grow.tsx
7
+ /** The transitions of a part inside that already move the content's height by themselves. */
8
+ const heightProperties = /* @__PURE__ */ new Set([
9
+ "height",
10
+ "max-height",
11
+ "grid-template-rows"
12
+ ]);
13
+ /** Whether something inside is moving its own height: a panel opening, another `Grow`. */
14
+ function movingInside(content) {
15
+ return content.getAnimations({ subtree: true }).some((animation) => animation instanceof CSSTransition && heightProperties.has(animation.transitionProperty) && animation.playState !== "finished");
16
+ }
17
+ /**
18
+ * A block whose height follows what it holds. When something joins it (a step of a `Trace`, a
19
+ * paragraph that arrives, the next tab's panel), it eases to its new height on `settle`, and
20
+ * what stands below moves down with it instead of jumping. It shrinks the same way.
21
+ *
22
+ * Put it around the part that changes, not around the page: what stands inside below the change
23
+ * still moves at once. Give each part that grows on its own a `Grow` of its own, side by side;
24
+ * one inside another sets its height in the middle of the other's measuring, and the outer one
25
+ * then learns of it a frame late.
26
+ *
27
+ * At rest it is a plain block of the content's height that clips nothing. It clips only while
28
+ * it moves, so a line that joins at its foot is uncovered as the block opens. From rest it does
29
+ * not animate the first height, a resize of the window, or a height that something inside is
30
+ * already animating (an opening `Collapsible`): then it simply follows.
31
+ * Already on its way, it takes a new height as its goal from where it stands. Under reduced
32
+ * motion it always follows.
33
+ */
34
+ function Grow({ className, children, ref, ...props }) {
35
+ const box = useRef(null);
36
+ const content = useRef(null);
37
+ useLayoutEffect(() => {
38
+ const outer = box.current;
39
+ const inner = content.current;
40
+ if (!outer || !inner) return;
41
+ const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
42
+ /** The content's height when it was last measured, and the window's width then. */
43
+ let height = inner.offsetHeight;
44
+ let width = window.innerWidth;
45
+ const rest = () => {
46
+ delete outer.dataset.moving;
47
+ outer.style.height = "";
48
+ };
49
+ const observer = new ResizeObserver(() => {
50
+ const nextHeight = inner.offsetHeight;
51
+ const nextWidth = window.innerWidth;
52
+ const moving = outer.dataset.moving !== void 0;
53
+ const from = moving ? outer.getBoundingClientRect().height : height;
54
+ const follow = reduced.matches || nextWidth !== width || movingInside(inner);
55
+ height = nextHeight;
56
+ width = nextWidth;
57
+ if (Math.abs(nextHeight - from) < .5) {
58
+ if (moving) rest();
59
+ return;
60
+ }
61
+ if (follow && (!moving || reduced.matches)) {
62
+ if (moving) rest();
63
+ return;
64
+ }
65
+ outer.dataset.moving = "";
66
+ outer.style.transition = "none";
67
+ outer.style.height = `${from}px`;
68
+ outer.offsetHeight;
69
+ outer.style.transition = "";
70
+ outer.style.height = `${nextHeight}px`;
71
+ });
72
+ observer.observe(inner);
73
+ const arrived = (event) => {
74
+ if (event.target === outer && event.propertyName === "height") rest();
75
+ };
76
+ outer.addEventListener("transitionend", arrived);
77
+ outer.addEventListener("transitioncancel", arrived);
78
+ return () => {
79
+ observer.disconnect();
80
+ outer.removeEventListener("transitionend", arrived);
81
+ outer.removeEventListener("transitioncancel", arrived);
82
+ rest();
83
+ };
84
+ }, []);
85
+ return /* @__PURE__ */ jsx("div", {
86
+ ref: mergeRefs(box, ref),
87
+ "data-slot": "grow",
88
+ className: cn("transition-[height] spring-settle data-moving:overflow-clip", className),
89
+ ...props,
90
+ children: /* @__PURE__ */ jsx("div", {
91
+ ref: content,
92
+ "data-slot": "grow-content",
93
+ className: "flow-root",
94
+ children
95
+ })
96
+ });
97
+ }
98
+ export { Grow };
@@ -11,6 +11,10 @@ export type HeadingProps = ComponentProps<"h2"> & VariantProps<typeof headingVar
11
11
  * A title on the type scale. Write it as a sentence with a full stop ("Bei Lanfermann
12
12
  * anmelden."), in sentence case. Pick `level` for the document outline and `size` for the look:
13
13
  * they are independent.
14
+ *
15
+ * What opens a page or a section is this and a `Text` under it, set left, with nothing above the
16
+ * title: `size="display"` once, for the page's opening, `size="title"` for every section. Give
17
+ * the title a measure (`max-w-[44rem]`) and the lead a shorter one (`max-w-[34rem]`).
14
18
  */
15
19
  export declare function Heading({ level, size, className, ...props }: HeadingProps): import("react").JSX.Element;
16
20
  export {};
@@ -3,10 +3,10 @@ import { jsx } from "react/jsx-runtime";
3
3
  import { cva } from "class-variance-authority";
4
4
  // src/components/heading/heading.tsx
5
5
  const headingVariants = cva("text-balance text-fg", { variants: { size: {
6
- /** 54px: one per page at most, on a landing view. */
7
- display: "text-3xl font-medium",
8
- /** 36px: the title of a page. */
9
- title: "text-2xl font-medium",
6
+ /** 54px: one per page at most, on a landing view. 36px on a phone. */
7
+ display: "text-3xl font-medium max-sm:text-2xl",
8
+ /** 36px: the title of a page. 24px on a phone. */
9
+ title: "text-2xl font-medium max-sm:text-xl",
10
10
  /** 24px: a section, usually under a rule. */
11
11
  section: "text-xl font-semibold",
12
12
  /** 20px: a card, a dialog, a group. */
@@ -24,6 +24,10 @@ const sizeForLevel = {
24
24
  * A title on the type scale. Write it as a sentence with a full stop ("Bei Lanfermann
25
25
  * anmelden."), in sentence case. Pick `level` for the document outline and `size` for the look:
26
26
  * they are independent.
27
+ *
28
+ * What opens a page or a section is this and a `Text` under it, set left, with nothing above the
29
+ * title: `size="display"` once, for the page's opening, `size="title"` for every section. Give
30
+ * the title a measure (`max-w-[44rem]`) and the lead a shorter one (`max-w-[34rem]`).
27
31
  */
28
32
  function Heading({ level = 2, size, className, ...props }) {
29
33
  const Tag = `h${level}`;
@@ -0,0 +1,24 @@
1
+ import { LinkVariants } from "../link/link-variants.js";
2
+ import { PreviewCard } from "@base-ui/react/preview-card";
3
+ /**
4
+ * A look at what stands behind a link, before following it: the page a term leads to, the
5
+ * customer behind a name. It opens while the link is pointed at (after a moment, so a pointer
6
+ * passing over does not open it) or has the keyboard, and never on a touch screen.
7
+ *
8
+ * It is a preview and nothing more. Everything in it must also stand where the link leads,
9
+ * because assistive tech does not go through it: there, the link is the whole interface. For
10
+ * something a person has to read or operate, use a `Popover`.
11
+ */
12
+ export declare const HoverCard: <Payload>(props: PreviewCard.Root.Props<Payload>) => React.JSX.Element;
13
+ export type HoverCardTriggerProps = PreviewCard.Trigger.Props & LinkVariants;
14
+ /**
15
+ * The link. It stays a link, with a link's look and its `href`; pass a router's link as `render`.
16
+ * `delay` and `closeDelay` (ms) say how long it waits before the card opens and closes.
17
+ */
18
+ export declare function HoverCardTrigger({ className, variant, ...props }: HoverCardTriggerProps): import("react").JSX.Element;
19
+ export type HoverCardContentProps = PreviewCard.Popup.Props & Pick<PreviewCard.Positioner.Props, "side" | "align" | "sideOffset" | "alignOffset">;
20
+ /**
21
+ * The card: a sheet that grows out of the link and hangs from the start of it, like everything
22
+ * that is set left. A title, a line or two, perhaps a picture; nothing to press.
23
+ */
24
+ export declare function HoverCardContent({ className, side, align, sideOffset, alignOffset, ...props }: HoverCardContentProps): import("react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import { useGround } from "../ground/ground.js";
3
+ import { linkVariants } from "../link/link-variants.js";
4
+ import { popupMotion } from "../../internal/popup.js";
5
+ import { mergeClassName } from "../../lib/cn.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ import { PreviewCard } from "@base-ui/react/preview-card";
8
+ // src/components/hover-card/hover-card.tsx
9
+ /**
10
+ * A look at what stands behind a link, before following it: the page a term leads to, the
11
+ * customer behind a name. It opens while the link is pointed at (after a moment, so a pointer
12
+ * passing over does not open it) or has the keyboard, and never on a touch screen.
13
+ *
14
+ * It is a preview and nothing more. Everything in it must also stand where the link leads,
15
+ * because assistive tech does not go through it: there, the link is the whole interface. For
16
+ * something a person has to read or operate, use a `Popover`.
17
+ */
18
+ const HoverCard = PreviewCard.Root;
19
+ /**
20
+ * The link. It stays a link, with a link's look and its `href`; pass a router's link as `render`.
21
+ * `delay` and `closeDelay` (ms) say how long it waits before the card opens and closes.
22
+ */
23
+ function HoverCardTrigger({ className, variant, ...props }) {
24
+ return /* @__PURE__ */ jsx(PreviewCard.Trigger, {
25
+ "data-slot": "hover-card-trigger",
26
+ className: mergeClassName(linkVariants({ variant }), className),
27
+ ...props
28
+ });
29
+ }
30
+ /**
31
+ * The card: a sheet that grows out of the link and hangs from the start of it, like everything
32
+ * that is set left. A title, a line or two, perhaps a picture; nothing to press.
33
+ */
34
+ function HoverCardContent({ className, side = "bottom", align = "start", sideOffset = 8, alignOffset, ...props }) {
35
+ const ground = useGround();
36
+ return /* @__PURE__ */ jsx(PreviewCard.Portal, { children: /* @__PURE__ */ jsx(PreviewCard.Positioner, {
37
+ "data-slot": "hover-card-positioner",
38
+ side,
39
+ align,
40
+ sideOffset,
41
+ alignOffset,
42
+ className: "z-50 max-w-(--available-width)",
43
+ children: /* @__PURE__ */ jsx(PreviewCard.Popup, {
44
+ "data-slot": "hover-card-content",
45
+ "data-theme": ground,
46
+ className: mergeClassName(["flex w-72 flex-col gap-2 rounded-xl bg-sheet p-4 text-control text-fg-body depth-floating", popupMotion], className),
47
+ ...props
48
+ })
49
+ }) });
50
+ }
51
+ export { HoverCard, HoverCardContent, HoverCardTrigger };