@lanfermann/ui 0.2.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.
- package/dist/components/accordion/accordion.js +2 -1
- package/dist/components/anchor-heading/anchor-heading.d.ts +1 -1
- package/dist/components/breadcrumbs/breadcrumbs.js +5 -10
- package/dist/components/button/button.d.ts +3 -0
- package/dist/components/button/button.js +14 -4
- package/dist/components/button-group/button-group-context.js +14 -0
- package/dist/components/button-group/button-group-variants.d.ts +14 -0
- package/dist/components/button-group/button-group-variants.js +93 -0
- package/dist/components/button-group/button-group.d.ts +36 -0
- package/dist/components/button-group/button-group.js +46 -0
- package/dist/components/code-block/code-block-frame.js +22 -6
- package/dist/components/code-block/code-block-live.d.ts +3 -3
- package/dist/components/code-block/code-block-live.js +5 -3
- package/dist/components/code-block/code-block.d.ts +7 -3
- package/dist/components/code-block/code-block.js +9 -3
- package/dist/components/code-block/code-keys.d.ts +24 -0
- package/dist/components/code-block/code-keys.js +107 -0
- package/dist/components/code-block/code-scroll.js +2 -1
- package/dist/components/code-block/code-tabs-frame.js +12 -5
- package/dist/components/code-block/code-tabs.d.ts +9 -4
- package/dist/components/code-block/code-tabs.js +9 -6
- package/dist/components/code-block/lines.js +23 -1
- package/dist/components/copy-page/copy-page.d.ts +46 -0
- package/dist/components/copy-page/copy-page.js +211 -0
- package/dist/components/docs-layout/docs-layout.d.ts +4 -2
- package/dist/components/docs-layout/docs-layout.js +11 -6
- package/dist/components/docs-layout/docs-nav.d.ts +51 -0
- package/dist/components/docs-layout/docs-nav.js +60 -0
- package/dist/components/grow/grow.d.ts +20 -0
- package/dist/components/grow/grow.js +98 -0
- package/dist/components/heading/heading.d.ts +4 -0
- package/dist/components/heading/heading.js +8 -4
- package/dist/components/hover-card/hover-card.d.ts +24 -0
- package/dist/components/hover-card/hover-card.js +51 -0
- package/dist/components/pager/pager.js +19 -24
- package/dist/components/parameter-list/parameter-list.js +2 -1
- package/dist/components/scroll-fade/scroll-fade.d.ts +29 -0
- package/dist/components/scroll-fade/scroll-fade.js +40 -0
- package/dist/components/scroll-fade/use-scroll-edges.d.ts +13 -0
- package/dist/{internal/scroll-edges.js → components/scroll-fade/use-scroll-edges.js} +10 -7
- package/dist/components/section/section.d.ts +2 -1
- package/dist/components/section/section.js +2 -1
- package/dist/components/segmented-control/segmented-control.d.ts +7 -1
- package/dist/components/segmented-control/segmented-control.js +22 -11
- package/dist/components/select/select.d.ts +4 -1
- package/dist/components/select/select.js +15 -3
- package/dist/components/separator/separator.js +2 -2
- package/dist/components/shimmer/shimmer.d.ts +21 -0
- package/dist/components/shimmer/shimmer.js +24 -0
- package/dist/components/side-nav/side-nav.js +11 -20
- package/dist/components/site-header/site-header.d.ts +1 -1
- package/dist/components/site-header/site-header.js +6 -3
- package/dist/components/slider/slider.d.ts +3 -1
- package/dist/components/slider/slider.js +45 -19
- package/dist/components/table/table.d.ts +6 -6
- package/dist/components/table/table.js +24 -17
- package/dist/components/table-of-contents/table-of-contents.js +11 -6
- package/dist/components/tabs/tabs.js +4 -8
- package/dist/components/theme-switch/theme-switch.d.ts +47 -0
- package/dist/components/theme-switch/theme-switch.js +102 -0
- package/dist/components/trace/trace.d.ts +71 -0
- package/dist/components/trace/trace.js +201 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +11 -2
- package/dist/internal/render-as.js +24 -0
- package/dist/internal/rule.js +16 -0
- package/dist/lib/merge-refs.js +9 -0
- package/package.json +1 -1
- package/src/styles/button-group.css +57 -0
- package/src/styles/code.css +14 -68
- package/src/styles/copy.css +46 -0
- package/src/styles/marks.css +10 -0
- package/src/styles/motion.css +4 -3
- package/src/styles/scroll-fade.css +58 -0
- package/src/styles/shimmer.css +68 -0
- package/src/styles/slider.css +57 -19
- package/src/styles.css +4 -1
- package/dist/components/page-header/page-header.d.ts +0 -30
- package/dist/components/page-header/page-header.js +0 -48
- package/src/styles/tabs.css +0 -39
|
@@ -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 };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import { ActionArrow } from "../../internal/arrow.js";
|
|
2
|
+
import { renderAs } from "../../internal/render-as.js";
|
|
3
3
|
import { cn } from "../../lib/cn.js";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
6
5
|
// src/components/pager/pager.tsx
|
|
7
6
|
/**
|
|
8
7
|
* The way on at the end of a page that is one of a sequence: the page before and the page after,
|
|
@@ -24,28 +23,24 @@ function Pager({ label = "Weitere Seiten", className, children, ...props }) {
|
|
|
24
23
|
*/
|
|
25
24
|
function PagerLink({ direction, title, label = direction === "next" ? "Nächste Seite" : "Vorherige Seite", render, className, ...props }) {
|
|
26
25
|
const next = direction === "next";
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
className: cn("
|
|
36
|
-
children:
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
className: "max-w-full text-lg font-medium text-pretty text-fg",
|
|
46
|
-
children: title
|
|
47
|
-
})] })
|
|
48
|
-
}
|
|
26
|
+
return renderAs("a", render, {
|
|
27
|
+
...props,
|
|
28
|
+
"data-slot": "pager-link",
|
|
29
|
+
"data-direction": direction,
|
|
30
|
+
rel: next ? "next" : "prev",
|
|
31
|
+
className: cn("group/pager -mx-3 flex min-w-0 flex-col gap-1 rounded-lg px-3 py-3 transition-colors duration-150 ease-out hover:bg-hover", "focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-accent", next && "sm:col-start-2 sm:items-end sm:text-right", className),
|
|
32
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("span", {
|
|
33
|
+
"data-slot": "pager-label",
|
|
34
|
+
className: cn("flex items-center gap-1.5 text-sm text-fg-muted", next && "sm:flex-row-reverse"),
|
|
35
|
+
children: [/* @__PURE__ */ jsx(ActionArrow, {
|
|
36
|
+
direction: next ? "right" : "left",
|
|
37
|
+
size: 14
|
|
38
|
+
}), label]
|
|
39
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
40
|
+
"data-slot": "pager-title",
|
|
41
|
+
className: "max-w-full text-lg font-medium text-pretty text-fg",
|
|
42
|
+
children: title
|
|
43
|
+
})] })
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
46
|
export { Pager, PagerLink };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ruleTop } from "../../internal/rule.js";
|
|
1
2
|
import { cn } from "../../lib/cn.js";
|
|
2
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
4
|
import { Fragment as Fragment$1 } from "react";
|
|
@@ -13,7 +14,7 @@ import { Fragment as Fragment$1 } from "react";
|
|
|
13
14
|
function ParameterList({ className, ...props }) {
|
|
14
15
|
return /* @__PURE__ */ jsx("dl", {
|
|
15
16
|
"data-slot": "parameter-list",
|
|
16
|
-
className: cn("flex flex-col
|
|
17
|
+
className: cn("flex flex-col", ruleTop, className),
|
|
17
18
|
...props
|
|
18
19
|
});
|
|
19
20
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
export type ScrollFadeProps = ComponentProps<"div"> & {
|
|
3
|
+
/** The direction the box scrolls in, and so the edges that fade. */
|
|
4
|
+
axis?: "x" | "y";
|
|
5
|
+
/**
|
|
6
|
+
* The edges that may fade: both (the default), or only the one where the content starts or
|
|
7
|
+
* ends. A list under a heading that stays put needs no fade at its start.
|
|
8
|
+
*/
|
|
9
|
+
edges?: "both" | "start" | "end";
|
|
10
|
+
/** How deep the fade is, as a CSS length. 40px unless set. */
|
|
11
|
+
size?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A box that scrolls inside itself and fades at the edge where more waits, instead of being cut
|
|
15
|
+
* hard: a long list in a sheet, a row of chips, the side column of a page. An edge fades only
|
|
16
|
+
* while there is something beyond it, so a box whose content fits looks like any other, and the
|
|
17
|
+
* fade moves in and out on `settle`. It is a mask, not a tinted overlay: it works on every
|
|
18
|
+
* ground and over a picture.
|
|
19
|
+
*
|
|
20
|
+
* Give the box its size (`max-h-64`, `h-full`); it sets its own `overflow`. Its background and
|
|
21
|
+
* border belong on a box around it, since the mask fades everything the box paints, and so does
|
|
22
|
+
* a focus outline. What takes the keyboard focus inside is scrolled clear of the fade. A box
|
|
23
|
+
* that holds nothing focusable must be reachable itself: give it `tabIndex={0}`, a `role` and a
|
|
24
|
+
* name, as a `Table` does.
|
|
25
|
+
*
|
|
26
|
+
* Where the scrolling element belongs to another part, use `useScrollEdges` on it and set
|
|
27
|
+
* `data-scroll-fade` to the axis.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ScrollFade({ axis, edges, size, className, style, ref, ...props }: ScrollFadeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../lib/cn.js";
|
|
3
|
+
import { mergeRefs } from "../../lib/merge-refs.js";
|
|
4
|
+
import { useScrollEdges } from "./use-scroll-edges.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { useRef } from "react";
|
|
7
|
+
// src/components/scroll-fade/scroll-fade.tsx
|
|
8
|
+
/**
|
|
9
|
+
* A box that scrolls inside itself and fades at the edge where more waits, instead of being cut
|
|
10
|
+
* hard: a long list in a sheet, a row of chips, the side column of a page. An edge fades only
|
|
11
|
+
* while there is something beyond it, so a box whose content fits looks like any other, and the
|
|
12
|
+
* fade moves in and out on `settle`. It is a mask, not a tinted overlay: it works on every
|
|
13
|
+
* ground and over a picture.
|
|
14
|
+
*
|
|
15
|
+
* Give the box its size (`max-h-64`, `h-full`); it sets its own `overflow`. Its background and
|
|
16
|
+
* border belong on a box around it, since the mask fades everything the box paints, and so does
|
|
17
|
+
* a focus outline. What takes the keyboard focus inside is scrolled clear of the fade. A box
|
|
18
|
+
* that holds nothing focusable must be reachable itself: give it `tabIndex={0}`, a `role` and a
|
|
19
|
+
* name, as a `Table` does.
|
|
20
|
+
*
|
|
21
|
+
* Where the scrolling element belongs to another part, use `useScrollEdges` on it and set
|
|
22
|
+
* `data-scroll-fade` to the axis.
|
|
23
|
+
*/
|
|
24
|
+
function ScrollFade({ axis = "y", edges = "both", size, className, style, ref, ...props }) {
|
|
25
|
+
const box = useRef(null);
|
|
26
|
+
useScrollEdges(box, axis);
|
|
27
|
+
return /* @__PURE__ */ jsx("div", {
|
|
28
|
+
ref: mergeRefs(box, ref),
|
|
29
|
+
"data-slot": "scroll-fade",
|
|
30
|
+
"data-scroll-fade": axis,
|
|
31
|
+
"data-fade-edges": edges === "both" ? void 0 : edges,
|
|
32
|
+
className: cn(axis === "x" ? "overflow-x-auto" : "overflow-y-auto", className),
|
|
33
|
+
style: size ? {
|
|
34
|
+
"--scroll-fade-size": size,
|
|
35
|
+
...style
|
|
36
|
+
} : style,
|
|
37
|
+
...props
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export { ScrollFade };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Says on a box that scrolls which of its ends has more to show: `data-overflow` holds `start`,
|
|
4
|
+
* `end`, both, or is absent. The stylesheet fades those edges (scroll-fade.css) once the box
|
|
5
|
+
* also carries `data-scroll-fade="x"` or `"y"`. The state is written straight onto the element,
|
|
6
|
+
* so scrolling never renders.
|
|
7
|
+
*
|
|
8
|
+
* Use it where the scrolling box is another part's element and cannot be a `ScrollFade` (a list
|
|
9
|
+
* of tabs, the popup of a menu). `axis` is the direction the box scrolls in. For a box that
|
|
10
|
+
* mounts later than the component (a popup), pass something that changes when it does as
|
|
11
|
+
* `mounted`, so the edges are watched from then on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useScrollEdges(ref: RefObject<HTMLElement | null>, axis?: "x" | "y", mounted?: unknown): void;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
// src/
|
|
3
|
+
// src/components/scroll-fade/use-scroll-edges.ts
|
|
4
4
|
/**
|
|
5
5
|
* Says on a box that scrolls which of its ends has more to show: `data-overflow` holds `start`,
|
|
6
|
-
* `end`, both, or is absent. The stylesheet fades those edges (
|
|
7
|
-
*
|
|
8
|
-
* scrolling never renders.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* `end`, both, or is absent. The stylesheet fades those edges (scroll-fade.css) once the box
|
|
7
|
+
* also carries `data-scroll-fade="x"` or `"y"`. The state is written straight onto the element,
|
|
8
|
+
* so scrolling never renders.
|
|
9
|
+
*
|
|
10
|
+
* Use it where the scrolling box is another part's element and cannot be a `ScrollFade` (a list
|
|
11
|
+
* of tabs, the popup of a menu). `axis` is the direction the box scrolls in. For a box that
|
|
12
|
+
* mounts later than the component (a popup), pass something that changes when it does as
|
|
13
|
+
* `mounted`, so the edges are watched from then on.
|
|
11
14
|
*/
|
|
12
15
|
function useScrollEdges(ref, axis = "x", mounted) {
|
|
13
16
|
useEffect(() => {
|
|
@@ -16,7 +19,7 @@ function useScrollEdges(ref, axis = "x", mounted) {
|
|
|
16
19
|
let frame = 0;
|
|
17
20
|
const update = () => {
|
|
18
21
|
frame = 0;
|
|
19
|
-
const start = axis === "x" ? scroller.scrollLeft : scroller.scrollTop;
|
|
22
|
+
const start = Math.abs(axis === "x" ? scroller.scrollLeft : scroller.scrollTop);
|
|
20
23
|
const visible = axis === "x" ? scroller.clientWidth : scroller.clientHeight;
|
|
21
24
|
const total = axis === "x" ? scroller.scrollWidth : scroller.scrollHeight;
|
|
22
25
|
const overflow = [start > 1 ? "start" : "", start + visible < total - 1 ? "end" : ""].filter(Boolean).join(" ");
|
|
@@ -7,7 +7,8 @@ export type SectionProps = ComponentProps<"section"> & VariantProps<typeof secti
|
|
|
7
7
|
/**
|
|
8
8
|
* One part of a page, with the air above and below it. It is a `<section>`: name it with
|
|
9
9
|
* `aria-labelledby` and the id of its title. Put a `Container` inside, and open it with a
|
|
10
|
-
* `
|
|
10
|
+
* `Heading` (`size="title"`), under a `Separator` rule unless a `Seam` opens the section. A part
|
|
11
|
+
* on another ground stands in a `Ground` with the section inside.
|
|
11
12
|
*/
|
|
12
13
|
export declare function Section({ space, className, ...props }: SectionProps): import("react").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -18,7 +18,8 @@ const sectionVariants = cva("", {
|
|
|
18
18
|
/**
|
|
19
19
|
* One part of a page, with the air above and below it. It is a `<section>`: name it with
|
|
20
20
|
* `aria-labelledby` and the id of its title. Put a `Container` inside, and open it with a
|
|
21
|
-
* `
|
|
21
|
+
* `Heading` (`size="title"`), under a `Separator` rule unless a `Seam` opens the section. A part
|
|
22
|
+
* on another ground stands in a `Ground` with the section inside.
|
|
22
23
|
*/
|
|
23
24
|
function Section({ space, className, ...props }) {
|
|
24
25
|
return /* @__PURE__ */ jsx("section", {
|
|
@@ -13,6 +13,12 @@ export type SegmentedControlProps = Omit<ToggleGroup.Props, "value" | "defaultVa
|
|
|
13
13
|
* `round` is a pill whose thumb rides on the trough's full height, each segment with its mark.
|
|
14
14
|
*/
|
|
15
15
|
shape?: Shape;
|
|
16
|
+
/**
|
|
17
|
+
* The round shape draws the system's mark before every label: a ring, and the disc where the
|
|
18
|
+
* thumb is. `false` leaves it out, for segments that are a symbol each: the symbol is the
|
|
19
|
+
* mark then. The square shape has no marks.
|
|
20
|
+
*/
|
|
21
|
+
marks?: boolean;
|
|
16
22
|
/**
|
|
17
23
|
* The thumb has weight: it can be pulled to another segment, it stretches along its way and
|
|
18
24
|
* squashes as it lands, and it reaches for a mouse that rests over another segment. `false`
|
|
@@ -33,7 +39,7 @@ export type SegmentedControlProps = Omit<ToggleGroup.Props, "value" | "defaultVa
|
|
|
33
39
|
* parents. Its weight is the slider's, decided in src/motion/inertia.ts once per move and drawn
|
|
34
40
|
* by CSS: nothing renders while it moves.
|
|
35
41
|
*/
|
|
36
|
-
export declare function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape, inertia, className, children, ...props }: SegmentedControlProps): import("react").JSX.Element;
|
|
42
|
+
export declare function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape, marks, inertia, className, children, ...props }: SegmentedControlProps): import("react").JSX.Element;
|
|
37
43
|
export type SegmentProps = Omit<Toggle.Props, "value"> & {
|
|
38
44
|
value: string;
|
|
39
45
|
children?: ReactNode;
|
|
@@ -22,7 +22,8 @@ const seatDepth = {
|
|
|
22
22
|
const TrackContext = createContext({
|
|
23
23
|
shape: "square",
|
|
24
24
|
value: void 0,
|
|
25
|
-
lens: false
|
|
25
|
+
lens: false,
|
|
26
|
+
marks: true
|
|
26
27
|
});
|
|
27
28
|
/** How far a press on the thumb must travel before it is a drag and not a click, in px. */
|
|
28
29
|
const DRAG_SLOP = 4;
|
|
@@ -60,7 +61,7 @@ function widthAt(boxes, middle) {
|
|
|
60
61
|
* parents. Its weight is the slider's, decided in src/motion/inertia.ts once per move and drawn
|
|
61
62
|
* by CSS: nothing renders while it moves.
|
|
62
63
|
*/
|
|
63
|
-
function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape = "square", inertia = true, className, children, ...props }) {
|
|
64
|
+
function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape = "square", marks = true, inertia = true, className, children, ...props }) {
|
|
64
65
|
const [inner, setInner] = useState(defaultValue);
|
|
65
66
|
const value = valueProp ?? inner;
|
|
66
67
|
const trackRef = useRef(null);
|
|
@@ -303,13 +304,23 @@ function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape
|
|
|
303
304
|
const track = useMemo(() => ({
|
|
304
305
|
shape,
|
|
305
306
|
value,
|
|
306
|
-
lens: false
|
|
307
|
-
|
|
307
|
+
lens: false,
|
|
308
|
+
marks
|
|
309
|
+
}), [
|
|
310
|
+
shape,
|
|
311
|
+
value,
|
|
312
|
+
marks
|
|
313
|
+
]);
|
|
308
314
|
const lens = useMemo(() => ({
|
|
309
315
|
shape,
|
|
310
316
|
value,
|
|
311
|
-
lens: true
|
|
312
|
-
|
|
317
|
+
lens: true,
|
|
318
|
+
marks
|
|
319
|
+
}), [
|
|
320
|
+
shape,
|
|
321
|
+
value,
|
|
322
|
+
marks
|
|
323
|
+
]);
|
|
313
324
|
return /* @__PURE__ */ jsxs(ToggleGroup, {
|
|
314
325
|
ref: trackRef,
|
|
315
326
|
"data-slot": "segmented-control",
|
|
@@ -368,15 +379,15 @@ const segmentBox = {
|
|
|
368
379
|
const segmentText = "inline-flex items-center justify-center text-control font-medium whitespace-nowrap select-none";
|
|
369
380
|
function Segment({ value, className, children, ...props }) {
|
|
370
381
|
const track = useContext(TrackContext);
|
|
371
|
-
const
|
|
382
|
+
const marked = track.shape === "round" && track.marks;
|
|
372
383
|
if (track.lens) return /* @__PURE__ */ jsx("span", {
|
|
373
384
|
"data-slot": "segment-copy",
|
|
374
385
|
"data-pressed": track.value === value ? "" : void 0,
|
|
375
386
|
className: cn("group", segmentText, segmentBox[track.shape], "text-fg", typeof className === "string" && className),
|
|
376
387
|
children: /* @__PURE__ */ jsxs("span", {
|
|
377
388
|
"data-slot": "segment-label",
|
|
378
|
-
className: cn("inline-flex items-center",
|
|
379
|
-
children: [
|
|
389
|
+
className: cn("inline-flex items-center", marked && "gap-1.5"),
|
|
390
|
+
children: [marked && /* @__PURE__ */ jsx("span", {
|
|
380
391
|
"data-slot": "segment-mark",
|
|
381
392
|
className: "mark group-data-pressed:mark-on group-data-pressed:delay-(--segment-seat)"
|
|
382
393
|
}), children]
|
|
@@ -401,8 +412,8 @@ function Segment({ value, className, children, ...props }) {
|
|
|
401
412
|
...props,
|
|
402
413
|
children: /* @__PURE__ */ jsxs("span", {
|
|
403
414
|
"data-slot": "segment-label",
|
|
404
|
-
className: cn("relative -z-1 inline-flex items-center",
|
|
405
|
-
children: [
|
|
415
|
+
className: cn("relative -z-1 inline-flex items-center", marked && "gap-1.5"),
|
|
416
|
+
children: [marked && /* @__PURE__ */ jsx("span", {
|
|
406
417
|
"data-slot": "segment-mark",
|
|
407
418
|
"aria-hidden": true,
|
|
408
419
|
className: "mark group-hover:[--mark-ring:var(--lf-text-muted)] group-not-data-placed/track:group-data-pressed:mark-on"
|
|
@@ -44,7 +44,10 @@ export type SelectTriggerProps = Omit<Select$1.Trigger.Props, "children"> & Vari
|
|
|
44
44
|
/** Replaces how the chosen value is rendered. By default its label, and icon, from `items`. */
|
|
45
45
|
children?: Select$1.Value.Props["children"];
|
|
46
46
|
};
|
|
47
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Shows the chosen value and opens the list. Give it a name: a `FieldLabel` or `aria-label`.
|
|
49
|
+
* Inside a `ButtonGroup` it is one key of the group's fitting and takes the group's size.
|
|
50
|
+
*/
|
|
48
51
|
export declare function SelectTrigger({ className, size, placeholder, children, ...props }: SelectTriggerProps): import("react").JSX.Element;
|
|
49
52
|
export type SelectContentProps = Select$1.Popup.Props & Pick<Select$1.Positioner.Props, "side" | "align" | "sideOffset" | "alignOffset" | "alignItemWithTrigger">;
|
|
50
53
|
/**
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useButtonGroup } from "../button-group/button-group-context.js";
|
|
3
|
+
import { buttonGroupKeyDisabledLook, buttonGroupKeyVariants } from "../button-group/button-group-variants.js";
|
|
2
4
|
import { useGround } from "../ground/ground.js";
|
|
3
5
|
import { Icon } from "../icon/icon.js";
|
|
4
6
|
import { ChevronDownGlyph } from "../../internal/glyphs.js";
|
|
@@ -88,15 +90,25 @@ const selectTriggerVariants = cva([
|
|
|
88
90
|
} },
|
|
89
91
|
defaultVariants: { size: "md" }
|
|
90
92
|
});
|
|
91
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Shows the chosen value and opens the list. Give it a name: a `FieldLabel` or `aria-label`.
|
|
95
|
+
* Inside a `ButtonGroup` it is one key of the group's fitting and takes the group's size.
|
|
96
|
+
*/
|
|
92
97
|
function SelectTrigger({ className, size, placeholder, children, ...props }) {
|
|
93
98
|
const options = useContext(OptionsContext);
|
|
94
|
-
const
|
|
99
|
+
const group = useButtonGroup();
|
|
100
|
+
const resolvedSize = group?.size ?? size ?? "md";
|
|
95
101
|
const rich = options?.some((option) => option.icon !== void 0 || option.detail !== void 0) === true ? (value) => renderValue(value, options, placeholder, resolvedSize) : void 0;
|
|
96
102
|
return /* @__PURE__ */ jsxs(Select$1.Trigger, {
|
|
97
103
|
"data-slot": "select-trigger",
|
|
104
|
+
"data-group-key": group ? "" : void 0,
|
|
98
105
|
"data-size": resolvedSize,
|
|
99
|
-
|
|
106
|
+
disabled: group?.disabled || void 0,
|
|
107
|
+
className: mergeClassName(group ? [
|
|
108
|
+
buttonGroupKeyVariants({ size: resolvedSize }),
|
|
109
|
+
buttonGroupKeyDisabledLook,
|
|
110
|
+
"min-w-32 justify-between text-left font-normal"
|
|
111
|
+
] : selectTriggerVariants({ size }), className),
|
|
100
112
|
...props,
|
|
101
113
|
children: [/* @__PURE__ */ jsx(Select$1.Value, {
|
|
102
114
|
"data-slot": "select-value",
|
|
@@ -10,8 +10,8 @@ const separatorVariants = cva("shrink-0 data-[orientation=horizontal]:h-(--separ
|
|
|
10
10
|
hairline: "bg-hairline [--separator-size:1px]",
|
|
11
11
|
/** The kit's structural 1px line, visible on its own (3:1). */
|
|
12
12
|
line: "bg-line [--separator-size:1px]",
|
|
13
|
-
/** The 2px rule that opens a block. */
|
|
14
|
-
rule: "bg-rule [--separator-size:2px]"
|
|
13
|
+
/** The 2px rule that opens a block: a line with round ends. */
|
|
14
|
+
rule: "rounded-full bg-rule [--separator-size:2px]"
|
|
15
15
|
} },
|
|
16
16
|
defaultVariants: { variant: "hairline" }
|
|
17
17
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
export type ShimmerProps = ComponentProps<"span"> & {
|
|
3
|
+
/**
|
|
4
|
+
* The work is going on (the default). Set it to `false` when it is done: the same element
|
|
5
|
+
* then is plain text in the colour around it, so the line does not jump.
|
|
6
|
+
*/
|
|
7
|
+
active?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A line of text that names work in progress: a soft light passes through it for as long as the
|
|
11
|
+
* work goes on. Use it where a wait has words ("Zahlungen werden abgeglichen", "Antwort wird
|
|
12
|
+
* geschrieben"), as in the steps of a `Trace`. A wait without words is a `Spinner`; a wait with
|
|
13
|
+
* a known length is a `Progress`.
|
|
14
|
+
*
|
|
15
|
+
* Word it as what is happening, in a few words, and keep it to one line: the light is redrawn
|
|
16
|
+
* on every frame. It is decoration: say that something is busy where assistive tech looks for
|
|
17
|
+
* it (`aria-busy` on the region, a `role="status"` line).
|
|
18
|
+
*
|
|
19
|
+
* The same look is the `shimmer` utility, for text that already has an element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Shimmer({ active, className, ...props }: ShimmerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { cn } from "../../lib/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/components/shimmer/shimmer.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A line of text that names work in progress: a soft light passes through it for as long as the
|
|
6
|
+
* work goes on. Use it where a wait has words ("Zahlungen werden abgeglichen", "Antwort wird
|
|
7
|
+
* geschrieben"), as in the steps of a `Trace`. A wait without words is a `Spinner`; a wait with
|
|
8
|
+
* a known length is a `Progress`.
|
|
9
|
+
*
|
|
10
|
+
* Word it as what is happening, in a few words, and keep it to one line: the light is redrawn
|
|
11
|
+
* on every frame. It is decoration: say that something is busy where assistive tech looks for
|
|
12
|
+
* it (`aria-busy` on the region, a `role="status"` line).
|
|
13
|
+
*
|
|
14
|
+
* The same look is the `shimmer` utility, for text that already has an element.
|
|
15
|
+
*/
|
|
16
|
+
function Shimmer({ active = true, className, ...props }) {
|
|
17
|
+
return /* @__PURE__ */ jsx("span", {
|
|
18
|
+
"data-slot": "shimmer",
|
|
19
|
+
"data-active": active ? "" : void 0,
|
|
20
|
+
className: cn(active && "shimmer", className),
|
|
21
|
+
...props
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { Shimmer };
|