@lanfermann/ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +17 -2
- package/TRADEMARK.md +10 -0
- package/brand/app-icon.svg +1 -0
- package/brand/avatar.svg +1 -0
- package/brand/favicon.svg +1 -0
- package/dist/components/accordion/accordion.d.ts +26 -0
- package/dist/components/accordion/accordion.js +78 -0
- package/dist/components/alert/alert.d.ts +19 -0
- package/dist/components/alert/alert.js +68 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +20 -0
- package/dist/components/alert-dialog/alert-dialog.js +75 -0
- package/dist/components/anchor-heading/anchor-heading.d.ts +19 -0
- package/dist/components/anchor-heading/anchor-heading.js +39 -0
- package/dist/components/avatar/avatar.d.ts +14 -0
- package/dist/components/avatar/avatar.js +42 -0
- package/dist/components/badge/badge.d.ts +12 -0
- package/dist/components/badge/badge.js +27 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +23 -0
- package/dist/components/breadcrumbs/breadcrumbs.js +63 -0
- package/dist/components/button/button-variants.d.ts +15 -0
- package/dist/components/button/button-variants.js +76 -0
- package/dist/components/button/button.d.ts +25 -0
- package/dist/components/button/button.js +50 -0
- package/dist/components/calendar/calendar-selection.js +216 -0
- package/dist/components/calendar/calendar.d.ts +44 -0
- package/dist/components/calendar/calendar.js +208 -0
- package/dist/components/callout/callout.d.ts +21 -0
- package/dist/components/callout/callout.js +75 -0
- package/dist/components/card/card.d.ts +16 -0
- package/dist/components/card/card.js +53 -0
- package/dist/components/checkbox/checkbox.d.ts +9 -0
- package/dist/components/checkbox/checkbox.js +33 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +18 -0
- package/dist/components/checkbox-group/checkbox-group.js +33 -0
- package/dist/components/code/code.d.ts +7 -0
- package/dist/components/code/code.js +16 -0
- package/dist/components/code-block/code-block-frame.js +146 -0
- package/dist/components/code-block/code-block-live.d.ts +45 -0
- package/dist/components/code-block/code-block-live.js +51 -0
- package/dist/components/code-block/code-block.d.ts +36 -0
- package/dist/components/code-block/code-block.js +51 -0
- package/dist/components/code-block/code-copy.d.ts +12 -0
- package/dist/components/code-block/code-copy.js +71 -0
- package/dist/components/code-block/code-lines-view.d.ts +16 -0
- package/dist/components/code-block/code-lines-view.js +48 -0
- package/dist/components/code-block/code-lines.js +17 -0
- package/dist/components/code-block/code-scroll.js +29 -0
- package/dist/components/code-block/code-surface.js +13 -0
- package/dist/components/code-block/code-tabs-frame.js +85 -0
- package/dist/components/code-block/code-tabs-store.js +25 -0
- package/dist/components/code-block/code-tabs.d.ts +28 -0
- package/dist/components/code-block/code-tabs.js +29 -0
- package/dist/components/code-block/highlight.d.ts +34 -0
- package/dist/components/code-block/highlight.js +258 -0
- package/dist/components/code-block/lines.d.ts +5 -0
- package/dist/components/code-block/lines.js +40 -0
- package/dist/components/collapsible/collapsible.d.ts +19 -0
- package/dist/components/collapsible/collapsible.js +54 -0
- package/dist/components/combobox/combobox.d.ts +84 -0
- package/dist/components/combobox/combobox.js +169 -0
- package/dist/components/container/container.d.ts +16 -0
- package/dist/components/container/container.js +30 -0
- package/dist/components/copy-pill/copy-pill.d.ts +52 -0
- package/dist/components/copy-pill/copy-pill.js +232 -0
- package/dist/components/cta/cta.d.ts +109 -0
- package/dist/components/cta/cta.js +375 -0
- package/dist/components/date-field/date-field.d.ts +40 -0
- package/dist/components/date-field/date-field.js +99 -0
- package/dist/components/date-range-field/date-range-field.d.ts +41 -0
- package/dist/components/date-range-field/date-range-field.js +155 -0
- package/dist/components/dialog/dialog.d.ts +29 -0
- package/dist/components/dialog/dialog.js +96 -0
- package/dist/components/docs-layout/docs-layout.d.ts +17 -0
- package/dist/components/docs-layout/docs-layout.js +46 -0
- package/dist/components/drawer/drawer.d.ts +39 -0
- package/dist/components/drawer/drawer.js +181 -0
- package/dist/components/field/field.d.ts +18 -0
- package/dist/components/field/field.js +77 -0
- package/dist/components/fieldset/fieldset.d.ts +8 -0
- package/dist/components/fieldset/fieldset.js +25 -0
- package/dist/components/figure/figure.d.ts +14 -0
- package/dist/components/figure/figure.js +35 -0
- package/dist/components/form/form.d.ts +31 -0
- package/dist/components/form/form.js +55 -0
- package/dist/components/ground/ground.d.ts +20 -0
- package/dist/components/ground/ground.js +31 -0
- package/dist/components/heading/heading.d.ts +16 -0
- package/dist/components/heading/heading.js +36 -0
- package/dist/components/icon/icon.d.ts +22 -0
- package/dist/components/icon/icon.js +24 -0
- package/dist/components/input/input.d.ts +19 -0
- package/dist/components/input/input.js +46 -0
- package/dist/components/input-group/input-group.d.ts +34 -0
- package/dist/components/input-group/input-group.js +61 -0
- package/dist/components/kbd/kbd.d.ts +6 -0
- package/dist/components/kbd/kbd.js +15 -0
- package/dist/components/link/link-variants.d.ts +13 -0
- package/dist/components/link/link-variants.js +27 -0
- package/dist/components/link/link.d.ts +9 -0
- package/dist/components/link/link.js +18 -0
- package/dist/components/logo/logo-paths.js +22 -0
- package/dist/components/logo/logomark.d.ts +19 -0
- package/dist/components/logo/logomark.js +49 -0
- package/dist/components/logo/wordmark.d.ts +35 -0
- package/dist/components/logo/wordmark.js +48 -0
- package/dist/components/menu/menu.d.ts +26 -0
- package/dist/components/menu/menu.js +132 -0
- package/dist/components/meter/meter.d.ts +29 -0
- package/dist/components/meter/meter.js +68 -0
- package/dist/components/navigation-menu/navigation-menu-variants.d.ts +12 -0
- package/dist/components/navigation-menu/navigation-menu-variants.js +18 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu/navigation-menu.js +128 -0
- package/dist/components/number-field/number-field.d.ts +32 -0
- package/dist/components/number-field/number-field.js +85 -0
- package/dist/components/page-header/page-header.d.ts +27 -0
- package/dist/components/page-header/page-header.js +48 -0
- package/dist/components/pager/pager.d.ts +24 -0
- package/dist/components/pager/pager.js +51 -0
- package/dist/components/parameter-list/parameter-list.d.ts +34 -0
- package/dist/components/parameter-list/parameter-list.js +70 -0
- package/dist/components/popover/popover.d.ts +15 -0
- package/dist/components/popover/popover.js +64 -0
- package/dist/components/progress/progress.d.ts +19 -0
- package/dist/components/progress/progress.js +67 -0
- package/dist/components/prose/prose.d.ts +13 -0
- package/dist/components/prose/prose.js +22 -0
- package/dist/components/quote/quote.d.ts +21 -0
- package/dist/components/quote/quote.js +46 -0
- package/dist/components/radio/radio.d.ts +12 -0
- package/dist/components/radio/radio.js +37 -0
- package/dist/components/reference-entry/reference-entry.d.ts +25 -0
- package/dist/components/reference-entry/reference-entry.js +66 -0
- package/dist/components/section/section.d.ts +13 -0
- package/dist/components/section/section.js +30 -0
- package/dist/components/segmented-control/segmented-control.d.ts +42 -0
- package/dist/components/segmented-control/segmented-control.js +413 -0
- package/dist/components/select/select.d.ts +70 -0
- package/dist/components/select/select.js +189 -0
- package/dist/components/separator/separator.d.ts +12 -0
- package/dist/components/separator/separator.js +29 -0
- package/dist/components/side-nav/side-nav.d.ts +48 -0
- package/dist/components/side-nav/side-nav.js +89 -0
- package/dist/components/site-footer/site-footer-floor.js +48 -0
- package/dist/components/site-footer/site-footer.d.ts +38 -0
- package/dist/components/site-footer/site-footer.js +96 -0
- package/dist/components/site-header/site-header.d.ts +77 -0
- package/dist/components/site-header/site-header.js +214 -0
- package/dist/components/slider/slider.d.ts +42 -0
- package/dist/components/slider/slider.js +279 -0
- package/dist/components/spinner/spinner.d.ts +15 -0
- package/dist/components/spinner/spinner.js +34 -0
- package/dist/components/switch/switch.d.ts +8 -0
- package/dist/components/switch/switch.js +28 -0
- package/dist/components/table/table.d.ts +83 -0
- package/dist/components/table/table.js +123 -0
- package/dist/components/table-of-contents/table-of-contents.d.ts +32 -0
- package/dist/components/table-of-contents/table-of-contents.js +187 -0
- package/dist/components/tabs/tabs.d.ts +28 -0
- package/dist/components/tabs/tabs.js +124 -0
- package/dist/components/text/text.d.ts +16 -0
- package/dist/components/text/text.js +63 -0
- package/dist/components/textarea/textarea.d.ts +19 -0
- package/dist/components/textarea/textarea.js +30 -0
- package/dist/components/time-field/time-field.d.ts +40 -0
- package/dist/components/time-field/time-field.js +123 -0
- package/dist/components/toast/toast.d.ts +55 -0
- package/dist/components/toast/toast.js +129 -0
- package/dist/components/tooltip/tooltip.d.ts +16 -0
- package/dist/components/tooltip/tooltip.js +41 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +77 -0
- package/dist/internal/arrow.js +41 -0
- package/dist/internal/disclosure.js +20 -0
- package/dist/internal/field-context.js +21 -0
- package/dist/internal/field.d.ts +23 -0
- package/dist/internal/field.js +49 -0
- package/dist/internal/glyphs.js +84 -0
- package/dist/internal/iso-date.d.ts +2 -0
- package/dist/internal/iso-date.js +268 -0
- package/dist/internal/overlay.js +40 -0
- package/dist/internal/picker-sheet.js +74 -0
- package/dist/internal/popup.js +37 -0
- package/dist/internal/range-shape.js +295 -0
- package/dist/internal/reduced-motion.js +19 -0
- package/dist/internal/scroll-edges.js +45 -0
- package/dist/internal/trough.js +39 -0
- package/dist/internal/typed-input.d.ts +16 -0
- package/dist/internal/typed-input.js +133 -0
- package/dist/lib/cn.d.ts +11 -0
- package/dist/lib/cn.js +98 -0
- package/dist/motion/inertia.js +111 -0
- package/dist/motion/spring-step.js +35 -0
- package/dist/motion/springs.d.ts +78 -0
- package/dist/motion/springs.js +81 -0
- package/package.json +107 -4
- package/src/styles/base.css +93 -0
- package/src/styles/calendar.css +117 -0
- package/src/styles/code.css +252 -0
- package/src/styles/density.css +53 -0
- package/src/styles/depth.css +501 -0
- package/src/styles/grounds.css +191 -0
- package/src/styles/marks.css +50 -0
- package/src/styles/motion.css +55 -0
- package/src/styles/motion.generated.css +101 -0
- package/src/styles/prose.css +252 -0
- package/src/styles/radius.css +20 -0
- package/src/styles/segmented.css +208 -0
- package/src/styles/slider.css +110 -0
- package/src/styles/status.css +108 -0
- package/src/styles/tabs.css +39 -0
- package/src/styles/toast.css +106 -0
- package/src/styles/touch.css +41 -0
- package/src/styles/type.css +54 -0
- package/src/styles.css +38 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Icon } from "../icon/icon.js";
|
|
2
|
+
import { cn } from "../../lib/cn.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Alert02Icon, AlertCircleIcon, AlertDiamondIcon, Idea01Icon, InformationCircleIcon } from "@hugeicons/core-free-icons";
|
|
5
|
+
// src/components/callout/callout.tsx
|
|
6
|
+
const tones = {
|
|
7
|
+
note: {
|
|
8
|
+
icon: InformationCircleIcon,
|
|
9
|
+
word: "Hinweis",
|
|
10
|
+
edge: "border-line",
|
|
11
|
+
title: "text-fg",
|
|
12
|
+
iconColor: "text-fg-muted"
|
|
13
|
+
},
|
|
14
|
+
tip: {
|
|
15
|
+
icon: Idea01Icon,
|
|
16
|
+
word: "Tipp",
|
|
17
|
+
edge: "border-success",
|
|
18
|
+
title: "text-success",
|
|
19
|
+
iconColor: "text-success"
|
|
20
|
+
},
|
|
21
|
+
important: {
|
|
22
|
+
icon: AlertDiamondIcon,
|
|
23
|
+
word: "Wichtig",
|
|
24
|
+
edge: "border-accent",
|
|
25
|
+
title: "text-fg",
|
|
26
|
+
iconColor: "text-fg"
|
|
27
|
+
},
|
|
28
|
+
warning: {
|
|
29
|
+
icon: Alert02Icon,
|
|
30
|
+
word: "Warnung",
|
|
31
|
+
edge: "border-warning",
|
|
32
|
+
title: "text-warning",
|
|
33
|
+
iconColor: "text-warning"
|
|
34
|
+
},
|
|
35
|
+
caution: {
|
|
36
|
+
icon: AlertCircleIcon,
|
|
37
|
+
word: "Vorsicht",
|
|
38
|
+
edge: "border-danger",
|
|
39
|
+
title: "text-danger",
|
|
40
|
+
iconColor: "text-danger"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A remark set apart from the text it belongs to: a note, a tip, something important, a warning,
|
|
45
|
+
* a caution. It is part of the page and is read in order, so it is a note to assistive tech, not
|
|
46
|
+
* a live message; for what happens now (a form that failed), use `Alert`.
|
|
47
|
+
*
|
|
48
|
+
* It stays text: flat on the page, set apart by a 2px edge in its tone on the left, its kind in
|
|
49
|
+
* words and an icon on the first line. The body is one or a few short paragraphs. Keep it rare:
|
|
50
|
+
* a page where every other block is a callout has none.
|
|
51
|
+
*/
|
|
52
|
+
function Callout({ tone = "note", title, icon, className, children, ...props }) {
|
|
53
|
+
const spec = tones[tone];
|
|
54
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
55
|
+
role: "note",
|
|
56
|
+
"data-slot": "callout",
|
|
57
|
+
"data-tone": tone,
|
|
58
|
+
className: cn("flex flex-col gap-1 border-l-2 py-0.5 pl-4 text-base text-fg-body forced-colors:border-[CanvasText]", spec.edge, className),
|
|
59
|
+
...props,
|
|
60
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
61
|
+
"data-slot": "callout-title",
|
|
62
|
+
className: cn("flex items-center gap-2 font-semibold", spec.title),
|
|
63
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
64
|
+
icon: icon ?? spec.icon,
|
|
65
|
+
size: 18,
|
|
66
|
+
className: cn("shrink-0", spec.iconColor)
|
|
67
|
+
}), title ?? spec.word]
|
|
68
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
69
|
+
"data-slot": "callout-body",
|
|
70
|
+
className: "flex flex-col gap-2 text-pretty",
|
|
71
|
+
children
|
|
72
|
+
})]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export { Callout };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
type DivProps = ComponentProps<"div">;
|
|
3
|
+
/**
|
|
4
|
+
* A container for one object you act on: a form you submit, a plan you choose, an account. It is
|
|
5
|
+
* a softly raised sheet. Do not use it to chop a page into boxes: content that is only read
|
|
6
|
+
* stands on the ground under a rule (`Separator`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function Card({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
9
|
+
export declare function CardHeader({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
10
|
+
/** A sentence, like every title in the kit. */
|
|
11
|
+
export declare function CardTitle({ className, ...props }: ComponentProps<"h3">): import("react").JSX.Element;
|
|
12
|
+
export declare function CardDescription({ className, ...props }: ComponentProps<"p">): import("react").JSX.Element;
|
|
13
|
+
export declare function CardContent({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
14
|
+
/** The quiet strip at the bottom: secondary routes, legal lines, the state of a plan. */
|
|
15
|
+
export declare function CardFooter({ className, ...props }: DivProps): import("react").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { cn } from "../../lib/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/components/card/card.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A container for one object you act on: a form you submit, a plan you choose, an account. It is
|
|
6
|
+
* a softly raised sheet. Do not use it to chop a page into boxes: content that is only read
|
|
7
|
+
* stands on the ground under a rule (`Separator`).
|
|
8
|
+
*/
|
|
9
|
+
function Card({ className, ...props }) {
|
|
10
|
+
return /* @__PURE__ */ jsx("div", {
|
|
11
|
+
"data-slot": "card",
|
|
12
|
+
className: cn("flex flex-col rounded-xl bg-surface depth-card", className),
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function CardHeader({ className, ...props }) {
|
|
17
|
+
return /* @__PURE__ */ jsx("div", {
|
|
18
|
+
"data-slot": "card-header",
|
|
19
|
+
className: cn("flex flex-col gap-1 px-6 pt-6", className),
|
|
20
|
+
...props
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** A sentence, like every title in the kit. */
|
|
24
|
+
function CardTitle({ className, ...props }) {
|
|
25
|
+
return /* @__PURE__ */ jsx("h3", {
|
|
26
|
+
"data-slot": "card-title",
|
|
27
|
+
className: cn("text-lg leading-snug font-semibold text-balance text-fg", className),
|
|
28
|
+
...props
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function CardDescription({ className, ...props }) {
|
|
32
|
+
return /* @__PURE__ */ jsx("p", {
|
|
33
|
+
"data-slot": "card-description",
|
|
34
|
+
className: cn("text-fg-muted", className),
|
|
35
|
+
...props
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function CardContent({ className, ...props }) {
|
|
39
|
+
return /* @__PURE__ */ jsx("div", {
|
|
40
|
+
"data-slot": "card-content",
|
|
41
|
+
className: cn("px-6 py-5", className),
|
|
42
|
+
...props
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The quiet strip at the bottom: secondary routes, legal lines, the state of a plan. */
|
|
46
|
+
function CardFooter({ className, ...props }) {
|
|
47
|
+
return /* @__PURE__ */ jsx("div", {
|
|
48
|
+
"data-slot": "card-footer",
|
|
49
|
+
className: cn("flex items-center gap-3 rounded-b-xl border-t border-hairline bg-well px-6 py-3 text-sm text-fg-muted", className),
|
|
50
|
+
...props
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Checkbox as Checkbox$1 } from "@base-ui/react/checkbox";
|
|
2
|
+
export type CheckboxProps = Checkbox$1.Root.Props;
|
|
3
|
+
/**
|
|
4
|
+
* A socket that takes a plug. Unchecked it is an empty, shaded pocket; checked, an Indigo plug
|
|
5
|
+
* seats into it (`seat`) and the tick draws itself.
|
|
6
|
+
*
|
|
7
|
+
* Wrap it in a `<label>` together with its text, or put it in a `Field` with a `FieldLabel`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Checkbox({ className, ...props }: CheckboxProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DashGlyph, TickGlyph } from "../../internal/glyphs.js";
|
|
3
|
+
import { mergeClassName } from "../../lib/cn.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { Checkbox as Checkbox$1 } from "@base-ui/react/checkbox";
|
|
6
|
+
// src/components/checkbox/checkbox.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A socket that takes a plug. Unchecked it is an empty, shaded pocket; checked, an Indigo plug
|
|
9
|
+
* seats into it (`seat`) and the tick draws itself.
|
|
10
|
+
*
|
|
11
|
+
* Wrap it in a `<label>` together with its text, or put it in a `Field` with a `FieldLabel`.
|
|
12
|
+
*/
|
|
13
|
+
function Checkbox({ className, ...props }) {
|
|
14
|
+
return /* @__PURE__ */ jsx(Checkbox$1.Root, {
|
|
15
|
+
"data-slot": "checkbox",
|
|
16
|
+
className: mergeClassName([
|
|
17
|
+
"group touch-target relative inline-flex size-(--check-size) shrink-0 items-center justify-center rounded-xs bg-surface text-on-accent depth-socket",
|
|
18
|
+
"transition-[box-shadow,background-color,scale] spring-seat active:scale-[0.92] active:spring-snap",
|
|
19
|
+
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
|
|
20
|
+
"data-checked:bg-accent data-checked:depth-plug data-checked:depth-tone-accent",
|
|
21
|
+
"data-indeterminate:bg-accent data-indeterminate:depth-plug data-indeterminate:depth-tone-accent",
|
|
22
|
+
"data-disabled:pointer-events-none data-disabled:bg-disabled data-disabled:depth-flat data-disabled:text-on-disabled"
|
|
23
|
+
], className),
|
|
24
|
+
...props,
|
|
25
|
+
children: /* @__PURE__ */ jsxs(Checkbox$1.Indicator, {
|
|
26
|
+
"data-slot": "checkbox-indicator",
|
|
27
|
+
keepMounted: true,
|
|
28
|
+
className: "flex items-center justify-center",
|
|
29
|
+
children: [/* @__PURE__ */ jsx(TickGlyph, { className: "opacity-0 transition-[stroke-dashoffset,opacity] duration-150 ease-out [stroke-dasharray:1] [stroke-dashoffset:1] group-data-checked:opacity-100 group-data-checked:[stroke-dashoffset:0] group-data-indeterminate:hidden" }), /* @__PURE__ */ jsx(DashGlyph, { className: "hidden group-data-indeterminate:block" })]
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export { Checkbox };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
import { CheckboxGroup as CheckboxGroup$1 } from "@base-ui/react/checkbox-group";
|
|
3
|
+
export type CheckboxGroupProps = CheckboxGroup$1.Props;
|
|
4
|
+
/**
|
|
5
|
+
* Several of a few: the services of a quote, the days a shop is open. The value is the list of
|
|
6
|
+
* the ticked checkboxes' `value`s. Lay the options out as rows, each `Checkbox` in a `<label>`
|
|
7
|
+
* with its text, and name the group with a `FieldsetLegend` or `aria-labelledby`.
|
|
8
|
+
*
|
|
9
|
+
* For "select all", pass every option as `allValues`, control the group, and give the first
|
|
10
|
+
* `Checkbox` the `parent` prop: it shows the dash while some, not all, are ticked. Indent the
|
|
11
|
+
* options under it with `CheckboxGroupItems`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function CheckboxGroup({ className, ...props }: CheckboxGroupProps): import("react").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* The options that a parent checkbox stands for, set in by the width of a box and its gap, so
|
|
16
|
+
* their boxes start where the parent's text does.
|
|
17
|
+
*/
|
|
18
|
+
export declare function CheckboxGroupItems({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn, mergeClassName } from "../../lib/cn.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { CheckboxGroup as CheckboxGroup$1 } from "@base-ui/react/checkbox-group";
|
|
5
|
+
// src/components/checkbox-group/checkbox-group.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Several of a few: the services of a quote, the days a shop is open. The value is the list of
|
|
8
|
+
* the ticked checkboxes' `value`s. Lay the options out as rows, each `Checkbox` in a `<label>`
|
|
9
|
+
* with its text, and name the group with a `FieldsetLegend` or `aria-labelledby`.
|
|
10
|
+
*
|
|
11
|
+
* For "select all", pass every option as `allValues`, control the group, and give the first
|
|
12
|
+
* `Checkbox` the `parent` prop: it shows the dash while some, not all, are ticked. Indent the
|
|
13
|
+
* options under it with `CheckboxGroupItems`.
|
|
14
|
+
*/
|
|
15
|
+
function CheckboxGroup({ className, ...props }) {
|
|
16
|
+
return /* @__PURE__ */ jsx(CheckboxGroup$1, {
|
|
17
|
+
"data-slot": "checkbox-group",
|
|
18
|
+
className: mergeClassName("flex flex-col gap-3", className),
|
|
19
|
+
...props
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The options that a parent checkbox stands for, set in by the width of a box and its gap, so
|
|
24
|
+
* their boxes start where the parent's text does.
|
|
25
|
+
*/
|
|
26
|
+
function CheckboxGroupItems({ className, ...props }) {
|
|
27
|
+
return /* @__PURE__ */ jsx("div", {
|
|
28
|
+
"data-slot": "checkbox-group-items",
|
|
29
|
+
className: cn("flex flex-col gap-3 pl-[calc(var(--check-size)+0.625rem)]", className),
|
|
30
|
+
...props
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export { CheckboxGroup, CheckboxGroupItems };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A word a machine reads, inside running text: a file name, a prop, a command
|
|
4
|
+
* (`bun run dev`). It keeps the size of the sentence around it and breaks with it. For more than
|
|
5
|
+
* a line, use `CodeBlock`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Code({ className, ...props }: ComponentProps<"code">): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cn } from "../../lib/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/components/code/code.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A word a machine reads, inside running text: a file name, a prop, a command
|
|
6
|
+
* (`bun run dev`). It keeps the size of the sentence around it and breaks with it. For more than
|
|
7
|
+
* a line, use `CodeBlock`.
|
|
8
|
+
*/
|
|
9
|
+
function Code({ className, ...props }) {
|
|
10
|
+
return /* @__PURE__ */ jsx("code", {
|
|
11
|
+
"data-slot": "code",
|
|
12
|
+
className: cn("rounded-xs border border-hairline bg-well [box-decoration-break:clone] px-[0.3em] font-mono text-[0.84em] text-fg [font-variant-ligatures:none]", className),
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export { Code };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "../button/button.js";
|
|
3
|
+
import { Icon } from "../icon/icon.js";
|
|
4
|
+
import { ChevronDownGlyph } from "../../internal/glyphs.js";
|
|
5
|
+
import { cn } from "../../lib/cn.js";
|
|
6
|
+
import { CodeCopy } from "./code-copy.js";
|
|
7
|
+
import { CodeScroll } from "./code-scroll.js";
|
|
8
|
+
import { codeHead, codeRoot } from "./code-surface.js";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
11
|
+
// src/components/code-block/code-block-frame.tsx
|
|
12
|
+
/** Inset of the code from the top of its block, and the height of one line. */
|
|
13
|
+
const PAD_Y_REM = .75;
|
|
14
|
+
const LINE_REM = 1.375;
|
|
15
|
+
/**
|
|
16
|
+
* The client half of a CodeBlock: its header, the scrolling region, the copy button and the
|
|
17
|
+
* fold. The code itself arrives finished as `children`.
|
|
18
|
+
*/
|
|
19
|
+
function CodeBlockFrame({ children, copyText, lineCount, title, icon, mark, prompt, label, fold, foldLabel, className, ...labels }) {
|
|
20
|
+
const codeRef = useRef(null);
|
|
21
|
+
const copy = /* @__PURE__ */ jsx(CodeCopy, {
|
|
22
|
+
text: copyText,
|
|
23
|
+
codeRef,
|
|
24
|
+
...labels
|
|
25
|
+
});
|
|
26
|
+
if (prompt) return /* @__PURE__ */ jsxs("div", {
|
|
27
|
+
"data-slot": "code-block",
|
|
28
|
+
className: cn(codeRoot, "flex-row items-center pr-1.5", className),
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ jsx("span", {
|
|
31
|
+
"aria-hidden": true,
|
|
32
|
+
className: "pl-(--code-pad-x) text-fg-muted select-none",
|
|
33
|
+
children: "$"
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ jsx(CodeScroll, {
|
|
36
|
+
label,
|
|
37
|
+
codeRef,
|
|
38
|
+
className: "flex-1 [--code-pad-x:0.625rem]",
|
|
39
|
+
preClassName: "py-[0.5625rem]",
|
|
40
|
+
children
|
|
41
|
+
}),
|
|
42
|
+
copy
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
46
|
+
"data-slot": "code-block",
|
|
47
|
+
className: cn(codeRoot, className),
|
|
48
|
+
children: [title ? /* @__PURE__ */ jsxs("div", {
|
|
49
|
+
"data-slot": "code-block-header",
|
|
50
|
+
className: codeHead,
|
|
51
|
+
children: [
|
|
52
|
+
mark ?? /* @__PURE__ */ jsx(Icon, {
|
|
53
|
+
icon,
|
|
54
|
+
size: 14
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ jsx("span", {
|
|
57
|
+
"data-slot": "code-block-title",
|
|
58
|
+
className: "min-w-0 flex-1 truncate font-mono text-fg-body",
|
|
59
|
+
children: title
|
|
60
|
+
}),
|
|
61
|
+
copy
|
|
62
|
+
]
|
|
63
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
64
|
+
className: "absolute top-1.5 right-1.5 z-10 rounded-md bg-(--code-face)",
|
|
65
|
+
children: copy
|
|
66
|
+
}), /* @__PURE__ */ jsx(CodeFold, {
|
|
67
|
+
lineCount,
|
|
68
|
+
fold,
|
|
69
|
+
label: foldLabel,
|
|
70
|
+
children: /* @__PURE__ */ jsx(CodeScroll, {
|
|
71
|
+
label: title ?? label,
|
|
72
|
+
codeRef,
|
|
73
|
+
preClassName: "py-3",
|
|
74
|
+
children
|
|
75
|
+
})
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Long code shows its first lines and a fade; the trigger below opens the rest. Height is the one
|
|
81
|
+
* layout property animated here, because the page below has to make room (motion.md). It moves
|
|
82
|
+
* on `settle` from the folded height to the measured one and is let go to `auto` when it lands.
|
|
83
|
+
*/
|
|
84
|
+
function CodeFold({ lineCount, fold, label, children }) {
|
|
85
|
+
const folds = fold !== void 0 && lineCount > fold + 1;
|
|
86
|
+
const [open, setOpen] = useState(false);
|
|
87
|
+
const bodyRef = useRef(null);
|
|
88
|
+
const first = useRef(true);
|
|
89
|
+
const id = useId();
|
|
90
|
+
const folded = `${PAD_Y_REM + ((fold ?? 0) + .5) * LINE_REM}rem`;
|
|
91
|
+
useLayoutEffect(() => {
|
|
92
|
+
const body = bodyRef.current;
|
|
93
|
+
if (!body || !folds) return;
|
|
94
|
+
if (first.current) {
|
|
95
|
+
first.current = false;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
99
|
+
if (open) {
|
|
100
|
+
body.style.height = `${body.scrollHeight}px`;
|
|
101
|
+
if (still) {
|
|
102
|
+
body.style.height = "auto";
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const land = (event) => {
|
|
106
|
+
if (event.target !== body || event.propertyName !== "height") return;
|
|
107
|
+
body.style.height = "auto";
|
|
108
|
+
body.removeEventListener("transitionend", land);
|
|
109
|
+
};
|
|
110
|
+
body.addEventListener("transitionend", land);
|
|
111
|
+
return () => body.removeEventListener("transitionend", land);
|
|
112
|
+
}
|
|
113
|
+
body.style.height = `${body.getBoundingClientRect().height}px`;
|
|
114
|
+
body.offsetHeight;
|
|
115
|
+
body.style.height = folded;
|
|
116
|
+
}, [
|
|
117
|
+
open,
|
|
118
|
+
folds,
|
|
119
|
+
folded
|
|
120
|
+
]);
|
|
121
|
+
if (!folds) return children;
|
|
122
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
123
|
+
ref: bodyRef,
|
|
124
|
+
id,
|
|
125
|
+
"data-slot": "code-block-body",
|
|
126
|
+
"data-open": open ? "" : void 0,
|
|
127
|
+
className: "relative overflow-hidden transition-[height] spring-settle motion-reduce:transition-none",
|
|
128
|
+
style: { height: folded },
|
|
129
|
+
children: [children, /* @__PURE__ */ jsx("div", {
|
|
130
|
+
"aria-hidden": true,
|
|
131
|
+
className: cn("pointer-events-none absolute inset-x-0 bottom-0 h-14 bg-linear-to-b from-transparent to-(--code-face)", "transition-opacity spring-settle", open && "opacity-0 spring-leave")
|
|
132
|
+
})]
|
|
133
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
134
|
+
className: "flex justify-center border-t border-hairline px-2 py-1 font-sans",
|
|
135
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
136
|
+
variant: "quiet",
|
|
137
|
+
size: "sm",
|
|
138
|
+
"aria-expanded": open,
|
|
139
|
+
"aria-controls": id,
|
|
140
|
+
onClick: () => setOpen((value) => !value),
|
|
141
|
+
className: "text-fg-muted hover:text-fg",
|
|
142
|
+
children: [label ?? `${lineCount - (fold ?? 0)} weitere Zeilen`, /* @__PURE__ */ jsx(ChevronDownGlyph, { className: cn("transition-[rotate] spring-seat motion-reduce:transition-none", open && "rotate-180") })]
|
|
143
|
+
})
|
|
144
|
+
})] });
|
|
145
|
+
}
|
|
146
|
+
export { CodeBlockFrame };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IconSvgElement } from "../icon/icon.js";
|
|
2
|
+
import { CodeCopyLabels } from "./code-copy.js";
|
|
3
|
+
import { CodeLinesOptions } from "./code-lines-view.js";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* What a run of code is, in the ten roles a block colours: the same ones the highlighter of
|
|
7
|
+
* `CodeBlock` uses, so a live block and a highlighted one look alike on every ground.
|
|
8
|
+
*/
|
|
9
|
+
export type CodeRole = "text" | "comment" | "punct" | "keyword" | "string" | "number" | "function" | "type" | "attribute" | "tag";
|
|
10
|
+
/** One run of a line: its text and what it is. Without a role it is plain text. */
|
|
11
|
+
export type CodePiece = {
|
|
12
|
+
text: string;
|
|
13
|
+
role?: CodeRole;
|
|
14
|
+
};
|
|
15
|
+
export type CodeBlockLiveProps = CodeLinesOptions & CodeCopyLabels & {
|
|
16
|
+
/** The code, line by line, each line as its runs in order. */
|
|
17
|
+
lines: readonly (readonly CodePiece[])[];
|
|
18
|
+
/** The file name or the place the code goes, set in the header. Without it, no header. */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** The symbol in the header. A code file unless said otherwise. */
|
|
21
|
+
icon?: IconSvgElement;
|
|
22
|
+
/** A mark of your own in place of the symbol: the logo of the product the code is for. */
|
|
23
|
+
mark?: ReactNode;
|
|
24
|
+
/** The name of the scrolling region when there is no title. */
|
|
25
|
+
label?: string;
|
|
26
|
+
/** A shell command on one line: a single row with a prompt before it. */
|
|
27
|
+
prompt?: boolean;
|
|
28
|
+
/** Show this many lines and fold the rest behind a trigger that names them. */
|
|
29
|
+
fold?: number;
|
|
30
|
+
foldLabel?: (hidden: number) => string;
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A `CodeBlock` for code that is put together in the browser: a configuration generated from the
|
|
35
|
+
* reader's choices, a command with their own values in it. It looks and behaves like a
|
|
36
|
+
* `CodeBlock` (header, copy with a drawn tick, marked lines, fold), but the app colours the lines
|
|
37
|
+
* itself and hands them over as runs with a role.
|
|
38
|
+
*
|
|
39
|
+
* Why not `CodeBlock`: that one highlights where it renders. On the server that costs the
|
|
40
|
+
* browser nothing; in a client component it would send the highlighter and all its grammars
|
|
41
|
+
* along, about a megabyte for a few lines. So: `CodeBlock` for code that is known when the page
|
|
42
|
+
* is built, `CodeBlockLive` for code that changes under the reader's hand. Mark the lines their
|
|
43
|
+
* choice put there (`marked`), so they see what it changed.
|
|
44
|
+
*/
|
|
45
|
+
export declare function CodeBlockLive({ lines, title, icon, mark, label, prompt, fold, foldLabel, className, lineNumbers, marked, added, removed, wrap, addedLabel, removedLabel, ...copyLabels }: CodeBlockLiveProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CodeBlockFrame } from "./code-block-frame.js";
|
|
2
|
+
import { CodeLinesView } from "./code-lines-view.js";
|
|
3
|
+
import { parseLines } from "./lines.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { FileCodeIcon } from "@hugeicons/core-free-icons";
|
|
6
|
+
// src/components/code-block/code-block-live.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A `CodeBlock` for code that is put together in the browser: a configuration generated from the
|
|
9
|
+
* reader's choices, a command with their own values in it. It looks and behaves like a
|
|
10
|
+
* `CodeBlock` (header, copy with a drawn tick, marked lines, fold), but the app colours the lines
|
|
11
|
+
* itself and hands them over as runs with a role.
|
|
12
|
+
*
|
|
13
|
+
* Why not `CodeBlock`: that one highlights where it renders. On the server that costs the
|
|
14
|
+
* browser nothing; in a client component it would send the highlighter and all its grammars
|
|
15
|
+
* along, about a megabyte for a few lines. So: `CodeBlock` for code that is known when the page
|
|
16
|
+
* is built, `CodeBlockLive` for code that changes under the reader's hand. Mark the lines their
|
|
17
|
+
* choice put there (`marked`), so they see what it changed.
|
|
18
|
+
*/
|
|
19
|
+
function CodeBlockLive({ lines, title, icon = FileCodeIcon, mark, label = "Code", prompt = false, fold, foldLabel = (hidden) => `${hidden} weitere Zeilen`, className, lineNumbers, marked, added, removed, wrap, addedLabel, removedLabel, ...copyLabels }) {
|
|
20
|
+
const coloured = lines.map((line) => line.map((piece) => ({
|
|
21
|
+
content: piece.text,
|
|
22
|
+
color: `var(--lf-code-${piece.role ?? "text"})`,
|
|
23
|
+
italic: piece.role === "comment"
|
|
24
|
+
})));
|
|
25
|
+
const dropped = parseLines(removed);
|
|
26
|
+
const text = lines.filter((_, index) => !dropped.has(index + 1)).map((line) => line.map((piece) => piece.text).join("")).join("\n");
|
|
27
|
+
return /* @__PURE__ */ jsx(CodeBlockFrame, {
|
|
28
|
+
copyText: text,
|
|
29
|
+
lineCount: lines.length,
|
|
30
|
+
title,
|
|
31
|
+
icon,
|
|
32
|
+
mark,
|
|
33
|
+
prompt: prompt && lines.length === 1 && !title,
|
|
34
|
+
label,
|
|
35
|
+
fold,
|
|
36
|
+
foldLabel: fold === void 0 ? void 0 : foldLabel(lines.length - fold),
|
|
37
|
+
className,
|
|
38
|
+
...copyLabels,
|
|
39
|
+
children: /* @__PURE__ */ jsx(CodeLinesView, {
|
|
40
|
+
lines: coloured,
|
|
41
|
+
lineNumbers,
|
|
42
|
+
marked,
|
|
43
|
+
added,
|
|
44
|
+
removed,
|
|
45
|
+
wrap,
|
|
46
|
+
addedLabel,
|
|
47
|
+
removedLabel
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { CodeBlockLive };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IconSvgElement } from "../icon/icon.js";
|
|
2
|
+
import { CodeCopyLabels } from "./code-copy.js";
|
|
3
|
+
import { CodeLinesOptions } from "./code-lines-view.js";
|
|
4
|
+
import { CodeLanguage } from "./highlight.js";
|
|
5
|
+
import { ReactNode } from "react";
|
|
6
|
+
export type CodeBlockProps = CodeLinesOptions & CodeCopyLabels & {
|
|
7
|
+
/** The code, as it is in the file. One trailing line break is ignored. */
|
|
8
|
+
code: string;
|
|
9
|
+
language?: CodeLanguage;
|
|
10
|
+
/** The file name, set in the header with its symbol. Without it the block has no header. */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** A symbol other than the language's own. */
|
|
13
|
+
icon?: IconSvgElement;
|
|
14
|
+
/** A mark of your own in place of the symbol: the logo of the product the code is for. */
|
|
15
|
+
mark?: ReactNode;
|
|
16
|
+
/** The name of the scrolling region when there is no title. */
|
|
17
|
+
label?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Show this many lines and fold the rest behind a trigger that names them. A fold that would
|
|
20
|
+
* hide a single line is not made.
|
|
21
|
+
*/
|
|
22
|
+
fold?: number;
|
|
23
|
+
/** The trigger of the fold, named after what it opens. Gets the number of hidden lines. */
|
|
24
|
+
foldLabel?: (hidden: number) => string;
|
|
25
|
+
className?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A block of code as it is read in documentation: coloured like the ground it stands on, with
|
|
29
|
+
* its file name above it and a copy button that confirms with a drawn tick. Long lines scroll
|
|
30
|
+
* inside the block; long code can be folded. A shell command on one line becomes a single row
|
|
31
|
+
* with a prompt.
|
|
32
|
+
*
|
|
33
|
+
* Mark the lines a text talks about (`marked`), show a change with `added` and `removed`, and
|
|
34
|
+
* keep the file name as it is (`quote-form.tsx`). For a word in running text, use `Code`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function CodeBlock({ code, language, title, icon, mark, label, fold, foldLabel, className, lineNumbers, marked, added, removed, wrap, addedLabel, removedLabel, ...copyLabels }: CodeBlockProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CodeBlockFrame } from "./code-block-frame.js";
|
|
2
|
+
import { CodeLines } from "./code-lines.js";
|
|
3
|
+
import { isShell } from "./highlight.js";
|
|
4
|
+
import { copyText, trimCode } from "./lines.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { CommandLineIcon, FileBracesIcon, FileCodeIcon } from "@hugeicons/core-free-icons";
|
|
7
|
+
// src/components/code-block/code-block.tsx
|
|
8
|
+
/** The symbol in a block's header: a prompt for a shell, braces for data, a code file otherwise. */
|
|
9
|
+
function codeSymbol(language) {
|
|
10
|
+
if (isShell(language)) return CommandLineIcon;
|
|
11
|
+
if (language === "json" || language === "yaml" || language === "yml") return FileBracesIcon;
|
|
12
|
+
return FileCodeIcon;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A block of code as it is read in documentation: coloured like the ground it stands on, with
|
|
16
|
+
* its file name above it and a copy button that confirms with a drawn tick. Long lines scroll
|
|
17
|
+
* inside the block; long code can be folded. A shell command on one line becomes a single row
|
|
18
|
+
* with a prompt.
|
|
19
|
+
*
|
|
20
|
+
* Mark the lines a text talks about (`marked`), show a change with `added` and `removed`, and
|
|
21
|
+
* keep the file name as it is (`quote-form.tsx`). For a word in running text, use `Code`.
|
|
22
|
+
*/
|
|
23
|
+
function CodeBlock({ code, language = "text", title, icon, mark, label = "Code", fold, foldLabel = (hidden) => `${hidden} weitere Zeilen`, className, lineNumbers, marked, added, removed, wrap, addedLabel, removedLabel, ...copyLabels }) {
|
|
24
|
+
const lineCount = trimCode(code).split("\n").length;
|
|
25
|
+
const prompt = isShell(language) && lineCount === 1 && !title;
|
|
26
|
+
return /* @__PURE__ */ jsx(CodeBlockFrame, {
|
|
27
|
+
copyText: copyText(code, removed),
|
|
28
|
+
lineCount,
|
|
29
|
+
title,
|
|
30
|
+
icon: icon ?? codeSymbol(language),
|
|
31
|
+
mark,
|
|
32
|
+
prompt,
|
|
33
|
+
label,
|
|
34
|
+
fold,
|
|
35
|
+
foldLabel: fold === void 0 ? void 0 : foldLabel(lineCount - fold),
|
|
36
|
+
className,
|
|
37
|
+
...copyLabels,
|
|
38
|
+
children: /* @__PURE__ */ jsx(CodeLines, {
|
|
39
|
+
code,
|
|
40
|
+
language,
|
|
41
|
+
lineNumbers,
|
|
42
|
+
marked,
|
|
43
|
+
added,
|
|
44
|
+
removed,
|
|
45
|
+
wrap,
|
|
46
|
+
addedLabel,
|
|
47
|
+
removedLabel
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { CodeBlock, codeSymbol };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
export type CodeCopyLabels = {
|
|
3
|
+
/** The button's name and its tooltip: worded like a button. */
|
|
4
|
+
copyLabel?: string;
|
|
5
|
+
/** The tooltip once the code is on the clipboard. */
|
|
6
|
+
copiedLabel?: string;
|
|
7
|
+
/** Read out once the code is on the clipboard: a full sentence. */
|
|
8
|
+
copiedMessage?: string;
|
|
9
|
+
/** Read out and shown when the clipboard refused; the code is then selected instead. */
|
|
10
|
+
failedLabel?: string;
|
|
11
|
+
failedMessage?: string;
|
|
12
|
+
};
|