@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,12 @@
|
|
|
1
|
+
import { Radio as Radio$1 } from "@base-ui/react/radio";
|
|
2
|
+
import { RadioGroup as RadioGroup$1 } from "@base-ui/react/radio-group";
|
|
3
|
+
export type RadioGroupProps = RadioGroup$1.Props;
|
|
4
|
+
/** One choice out of a few. Lay the options out as rows; label each with a `<label>`. */
|
|
5
|
+
export declare function RadioGroup({ className, ...props }: RadioGroupProps): import("react").JSX.Element;
|
|
6
|
+
export type RadioProps = Radio$1.Root.Props;
|
|
7
|
+
/**
|
|
8
|
+
* Ring to disc, the system's signature in its plainest form: an open ring is a possibility, the
|
|
9
|
+
* Indigo disc that seats into it is the choice. The previous choice shrinks away; nothing flies
|
|
10
|
+
* between options.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Radio({ className, ...props }: RadioProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { mergeClassName } from "../../lib/cn.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Radio as Radio$1 } from "@base-ui/react/radio";
|
|
5
|
+
import { RadioGroup as RadioGroup$1 } from "@base-ui/react/radio-group";
|
|
6
|
+
// src/components/radio/radio.tsx
|
|
7
|
+
/** One choice out of a few. Lay the options out as rows; label each with a `<label>`. */
|
|
8
|
+
function RadioGroup({ className, ...props }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(RadioGroup$1, {
|
|
10
|
+
"data-slot": "radio-group",
|
|
11
|
+
className: mergeClassName("flex flex-col gap-3", className),
|
|
12
|
+
...props
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ring to disc, the system's signature in its plainest form: an open ring is a possibility, the
|
|
17
|
+
* Indigo disc that seats into it is the choice. The previous choice shrinks away; nothing flies
|
|
18
|
+
* between options.
|
|
19
|
+
*/
|
|
20
|
+
function Radio({ className, ...props }) {
|
|
21
|
+
return /* @__PURE__ */ jsx(Radio$1.Root, {
|
|
22
|
+
"data-slot": "radio",
|
|
23
|
+
className: mergeClassName([
|
|
24
|
+
"group touch-target relative inline-flex size-(--check-size) shrink-0 items-center justify-center rounded-full bg-surface depth-socket",
|
|
25
|
+
"transition-[box-shadow,scale] spring-seat active:scale-[0.92] active:spring-snap",
|
|
26
|
+
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
|
|
27
|
+
"data-disabled:pointer-events-none data-disabled:bg-disabled data-disabled:depth-flat"
|
|
28
|
+
], className),
|
|
29
|
+
...props,
|
|
30
|
+
children: /* @__PURE__ */ jsx(Radio$1.Indicator, {
|
|
31
|
+
"data-slot": "radio-indicator",
|
|
32
|
+
keepMounted: true,
|
|
33
|
+
className: "size-(--radio-dot) scale-0 rounded-full bg-accent transition-[scale] spring-leave group-data-checked:scale-100 group-data-checked:spring-seat group-data-disabled:bg-on-disabled forced-colors:bg-[color:CanvasText]"
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { Radio, RadioGroup };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AnchorHeadingProps } from "../anchor-heading/anchor-heading.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* One entry of a reference: a function, a command, an endpoint, a tool. Entries follow one
|
|
5
|
+
* another under hairlines, without cards: a reference is read down the page and searched with
|
|
6
|
+
* the browser, so every entry is open and can be linked to.
|
|
7
|
+
*
|
|
8
|
+
* Put a `ReferenceEntryHeader` (its name, a title in words, and what kind of thing it is as
|
|
9
|
+
* `Badge`s in a `ReferenceEntryMeta`), then a `ReferenceEntryBody` with the description and a
|
|
10
|
+
* `ParameterList`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ReferenceEntry({ className, ...props }: ComponentProps<"article">): import("react").JSX.Element;
|
|
13
|
+
/** The name, the title and the facts about the entry, at the top. */
|
|
14
|
+
export declare function ReferenceEntryHeader({ className, ...props }: ComponentProps<"header">): import("react").JSX.Element;
|
|
15
|
+
/**
|
|
16
|
+
* The name as it is written in code, as an anchored heading: the address of the entry is
|
|
17
|
+
* `#name`. Give the id the name itself, so links from elsewhere can be written by hand.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ReferenceEntryName({ level, className, ...props }: AnchorHeadingProps): import("react").JSX.Element;
|
|
20
|
+
/** What the entry does, in words: its title for people. */
|
|
21
|
+
export declare function ReferenceEntryTitle({ className, ...props }: ComponentProps<"p">): import("react").JSX.Element;
|
|
22
|
+
/** What kind of thing the entry is: badges for its tier, its traits, its version. */
|
|
23
|
+
export declare function ReferenceEntryMeta({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
|
|
24
|
+
/** The description and the parameters, in the rhythm of running text. */
|
|
25
|
+
export declare function ReferenceEntryBody({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AnchorHeading } from "../anchor-heading/anchor-heading.js";
|
|
2
|
+
import { cn } from "../../lib/cn.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/reference-entry/reference-entry.tsx
|
|
5
|
+
/**
|
|
6
|
+
* One entry of a reference: a function, a command, an endpoint, a tool. Entries follow one
|
|
7
|
+
* another under hairlines, without cards: a reference is read down the page and searched with
|
|
8
|
+
* the browser, so every entry is open and can be linked to.
|
|
9
|
+
*
|
|
10
|
+
* Put a `ReferenceEntryHeader` (its name, a title in words, and what kind of thing it is as
|
|
11
|
+
* `Badge`s in a `ReferenceEntryMeta`), then a `ReferenceEntryBody` with the description and a
|
|
12
|
+
* `ParameterList`.
|
|
13
|
+
*/
|
|
14
|
+
function ReferenceEntry({ className, ...props }) {
|
|
15
|
+
return /* @__PURE__ */ jsx("article", {
|
|
16
|
+
"data-slot": "reference-entry",
|
|
17
|
+
className: cn("flex flex-col gap-5 border-t border-hairline pt-7 pb-2", className),
|
|
18
|
+
...props
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** The name, the title and the facts about the entry, at the top. */
|
|
22
|
+
function ReferenceEntryHeader({ className, ...props }) {
|
|
23
|
+
return /* @__PURE__ */ jsx("header", {
|
|
24
|
+
"data-slot": "reference-entry-header",
|
|
25
|
+
className: cn("flex flex-col items-start gap-2", className),
|
|
26
|
+
...props
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The name as it is written in code, as an anchored heading: the address of the entry is
|
|
31
|
+
* `#name`. Give the id the name itself, so links from elsewhere can be written by hand.
|
|
32
|
+
*/
|
|
33
|
+
function ReferenceEntryName({ level = 3, className, ...props }) {
|
|
34
|
+
return /* @__PURE__ */ jsx(AnchorHeading, {
|
|
35
|
+
"data-slot": "reference-entry-name",
|
|
36
|
+
level,
|
|
37
|
+
size: "label",
|
|
38
|
+
className: cn("font-mono text-[1.0625rem] leading-6 font-medium [overflow-wrap:anywhere] [font-variant-ligatures:none]", className),
|
|
39
|
+
...props
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** What the entry does, in words: its title for people. */
|
|
43
|
+
function ReferenceEntryTitle({ className, ...props }) {
|
|
44
|
+
return /* @__PURE__ */ jsx("p", {
|
|
45
|
+
"data-slot": "reference-entry-title",
|
|
46
|
+
className: cn("text-base font-medium text-pretty text-fg", className),
|
|
47
|
+
...props
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** What kind of thing the entry is: badges for its tier, its traits, its version. */
|
|
51
|
+
function ReferenceEntryMeta({ className, ...props }) {
|
|
52
|
+
return /* @__PURE__ */ jsx("div", {
|
|
53
|
+
"data-slot": "reference-entry-meta",
|
|
54
|
+
className: cn("flex flex-wrap items-center gap-1.5 pt-1", className),
|
|
55
|
+
...props
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** The description and the parameters, in the rhythm of running text. */
|
|
59
|
+
function ReferenceEntryBody({ className, ...props }) {
|
|
60
|
+
return /* @__PURE__ */ jsx("div", {
|
|
61
|
+
"data-slot": "reference-entry-body",
|
|
62
|
+
className: cn("flex min-w-0 flex-col gap-4 text-base text-pretty text-fg-body", className),
|
|
63
|
+
...props
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export { ReferenceEntry, ReferenceEntryBody, ReferenceEntryHeader, ReferenceEntryMeta, ReferenceEntryName, ReferenceEntryTitle };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { VariantProps } from "class-variance-authority";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
declare const sectionVariants: (props?: ({
|
|
4
|
+
space?: "md" | "lg" | null | undefined;
|
|
5
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
|
+
export type SectionProps = ComponentProps<"section"> & VariantProps<typeof sectionVariants>;
|
|
7
|
+
/**
|
|
8
|
+
* One part of a page, with the air above and below it. It is a `<section>`: name it with
|
|
9
|
+
* `aria-labelledby` and the id of its title. Put a `Container` inside, and open it with a
|
|
10
|
+
* `PageHeader`. A part on another ground stands in a `Ground` with the section inside.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Section({ space, className, ...props }: SectionProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cn } from "../../lib/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
// src/components/section/section.tsx
|
|
5
|
+
const sectionVariants = cva("", {
|
|
6
|
+
variants: { space: {
|
|
7
|
+
/** A part that belongs to the one before it. */
|
|
8
|
+
md: "py-10 sm:py-14",
|
|
9
|
+
/**
|
|
10
|
+
* A part of its own: the default between the sections of a page. On a phone two of them
|
|
11
|
+
* stand 96px apart, not 128: the page is read in one long column there, and the air
|
|
12
|
+
* between parts added up to screens (Justin, 2026-11-16).
|
|
13
|
+
*/
|
|
14
|
+
lg: "py-12 sm:py-24"
|
|
15
|
+
} },
|
|
16
|
+
defaultVariants: { space: "lg" }
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* One part of a page, with the air above and below it. It is a `<section>`: name it with
|
|
20
|
+
* `aria-labelledby` and the id of its title. Put a `Container` inside, and open it with a
|
|
21
|
+
* `PageHeader`. A part on another ground stands in a `Ground` with the section inside.
|
|
22
|
+
*/
|
|
23
|
+
function Section({ space, className, ...props }) {
|
|
24
|
+
return /* @__PURE__ */ jsx("section", {
|
|
25
|
+
"data-slot": "section",
|
|
26
|
+
className: cn(sectionVariants({ space }), className),
|
|
27
|
+
...props
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export { Section };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { Toggle } from "@base-ui/react/toggle";
|
|
3
|
+
import { ToggleGroup } from "@base-ui/react/toggle-group";
|
|
4
|
+
type Shape = "square" | "round";
|
|
5
|
+
export type SegmentedControlProps = Omit<ToggleGroup.Props, "value" | "defaultValue" | "onValueChange" | "multiple" | "ref"> & {
|
|
6
|
+
/** The selected segment (controlled). */
|
|
7
|
+
value?: string;
|
|
8
|
+
/** The segment selected at first (uncontrolled). */
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
onValueChange?: (value: string) => void;
|
|
11
|
+
/**
|
|
12
|
+
* `square` sits in the row of controls: corners of a control, the thumb inset in its trough.
|
|
13
|
+
* `round` is a pill whose thumb rides on the trough's full height, each segment with its mark.
|
|
14
|
+
*/
|
|
15
|
+
shape?: Shape;
|
|
16
|
+
/**
|
|
17
|
+
* The thumb has weight: it can be pulled to another segment, it stretches along its way and
|
|
18
|
+
* squashes as it lands, and it reaches for a mouse that rests over another segment. `false`
|
|
19
|
+
* leaves a thumb that only glides.
|
|
20
|
+
*/
|
|
21
|
+
inertia?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A choice between two to five views of the same thing, always with one selected. One raised
|
|
25
|
+
* thumb lives in a sunken trough and TRAVELS to the chosen segment: the mark moves, it does not
|
|
26
|
+
* fade out here and in there. What is chosen is what the thumb covers: the labels are drawn a
|
|
27
|
+
* second time inside it, in the colour of the choice, so a label darkens as the thumb arrives
|
|
28
|
+
* and not before. Keep the labels to plain words and icons: they are rendered twice.
|
|
29
|
+
*
|
|
30
|
+
* The thumb is placed from the pressed segment's measured box and moved with CSS springs
|
|
31
|
+
* (src/styles/segmented.css). That keeps its shadow and corners true (a scale-based layout
|
|
32
|
+
* animation would stretch them) and stays correct under CSS `zoom` and inside transformed
|
|
33
|
+
* parents. Its weight is the slider's, decided in src/motion/inertia.ts once per move and drawn
|
|
34
|
+
* by CSS: nothing renders while it moves.
|
|
35
|
+
*/
|
|
36
|
+
export declare function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape, inertia, className, children, ...props }: SegmentedControlProps): import("react").JSX.Element;
|
|
37
|
+
export type SegmentProps = Omit<Toggle.Props, "value"> & {
|
|
38
|
+
value: string;
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
};
|
|
41
|
+
export declare function Segment({ value, className, children, ...props }: SegmentProps): import("react").JSX.Element;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn, mergeClassName } from "../../lib/cn.js";
|
|
3
|
+
import { leanShape, pillGive, restingMotion, trackMotion, travelStretch, withinRoom } from "../../motion/inertia.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { Toggle } from "@base-ui/react/toggle";
|
|
7
|
+
import { ToggleGroup } from "@base-ui/react/toggle-group";
|
|
8
|
+
// src/components/segmented-control/segmented-control.tsx
|
|
9
|
+
/**
|
|
10
|
+
* The thumb's recipe, by its shape: the raised Fase, toned for the square trough. The thumb
|
|
11
|
+
* wears it, and so does the seat that stands in for the thumb before it is placed (a `::before`
|
|
12
|
+
* on the chosen segment): both written out, so Tailwind finds them.
|
|
13
|
+
*/
|
|
14
|
+
const thumbDepth = {
|
|
15
|
+
square: "depth-raised depth-tone-thumb",
|
|
16
|
+
round: "depth-raised"
|
|
17
|
+
};
|
|
18
|
+
const seatDepth = {
|
|
19
|
+
square: "before:depth-raised before:depth-tone-thumb",
|
|
20
|
+
round: "before:depth-raised"
|
|
21
|
+
};
|
|
22
|
+
const TrackContext = createContext({
|
|
23
|
+
shape: "square",
|
|
24
|
+
value: void 0,
|
|
25
|
+
lens: false
|
|
26
|
+
});
|
|
27
|
+
/** How far a press on the thumb must travel before it is a drag and not a click, in px. */
|
|
28
|
+
const DRAG_SLOP = 4;
|
|
29
|
+
/**
|
|
30
|
+
* How wide a pulled thumb is with its middle at `middle`: over a segment's middle, that
|
|
31
|
+
* segment's width; between two middles, as far between their widths as it is between them. So
|
|
32
|
+
* the width changes only as the hand moves, and never all at once where it crosses a border.
|
|
33
|
+
*/
|
|
34
|
+
function widthAt(boxes, middle) {
|
|
35
|
+
const first = boxes[0];
|
|
36
|
+
if (!first) return 0;
|
|
37
|
+
let before = first;
|
|
38
|
+
for (const box of boxes) {
|
|
39
|
+
const from = before.left + before.width / 2;
|
|
40
|
+
const to = box.left + box.width / 2;
|
|
41
|
+
if (middle <= to) {
|
|
42
|
+
if (to === from) return box.width;
|
|
43
|
+
const share = Math.max(0, (middle - from) / (to - from));
|
|
44
|
+
return before.width + (box.width - before.width) * share;
|
|
45
|
+
}
|
|
46
|
+
before = box;
|
|
47
|
+
}
|
|
48
|
+
return before.width;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A choice between two to five views of the same thing, always with one selected. One raised
|
|
52
|
+
* thumb lives in a sunken trough and TRAVELS to the chosen segment: the mark moves, it does not
|
|
53
|
+
* fade out here and in there. What is chosen is what the thumb covers: the labels are drawn a
|
|
54
|
+
* second time inside it, in the colour of the choice, so a label darkens as the thumb arrives
|
|
55
|
+
* and not before. Keep the labels to plain words and icons: they are rendered twice.
|
|
56
|
+
*
|
|
57
|
+
* The thumb is placed from the pressed segment's measured box and moved with CSS springs
|
|
58
|
+
* (src/styles/segmented.css). That keeps its shadow and corners true (a scale-based layout
|
|
59
|
+
* animation would stretch them) and stays correct under CSS `zoom` and inside transformed
|
|
60
|
+
* parents. Its weight is the slider's, decided in src/motion/inertia.ts once per move and drawn
|
|
61
|
+
* by CSS: nothing renders while it moves.
|
|
62
|
+
*/
|
|
63
|
+
function SegmentedControl({ value: valueProp, defaultValue, onValueChange, shape = "square", inertia = true, className, children, ...props }) {
|
|
64
|
+
const [inner, setInner] = useState(defaultValue);
|
|
65
|
+
const value = valueProp ?? inner;
|
|
66
|
+
const trackRef = useRef(null);
|
|
67
|
+
const [placed, setPlaced] = useState(false);
|
|
68
|
+
const lastLeft = useRef(void 0);
|
|
69
|
+
const release = useRef(void 0);
|
|
70
|
+
const leanFrame = useRef(0);
|
|
71
|
+
/** Until then (ms) the thumb is on its way to a choice and does not lean. */
|
|
72
|
+
const busyUntil = useRef(0);
|
|
73
|
+
/** The choice that follows was made by dropping the thumb: it is not stretched again. */
|
|
74
|
+
const dropped = useRef(false);
|
|
75
|
+
const drag = useRef(null);
|
|
76
|
+
function choose(next) {
|
|
77
|
+
setInner(next);
|
|
78
|
+
onValueChange?.(next);
|
|
79
|
+
}
|
|
80
|
+
useLayoutEffect(() => {
|
|
81
|
+
const track = trackRef.current;
|
|
82
|
+
if (!track) return;
|
|
83
|
+
const pressed = () => track.querySelector("[data-slot=\"segment\"][data-pressed]") ?? void 0;
|
|
84
|
+
const place = () => {
|
|
85
|
+
const segment = pressed();
|
|
86
|
+
const box = segment && {
|
|
87
|
+
left: segment.offsetLeft,
|
|
88
|
+
width: segment.offsetWidth
|
|
89
|
+
};
|
|
90
|
+
const size = {
|
|
91
|
+
width: track.offsetWidth,
|
|
92
|
+
height: track.offsetHeight
|
|
93
|
+
};
|
|
94
|
+
track.style.setProperty("--track-width", `${size.width}px`);
|
|
95
|
+
track.style.setProperty("--track-height", `${size.height}px`);
|
|
96
|
+
if (!box) return void 0;
|
|
97
|
+
track.style.setProperty("--thumb-left", `${box.left}px`);
|
|
98
|
+
track.style.setProperty("--thumb-width", `${box.width}px`);
|
|
99
|
+
return box;
|
|
100
|
+
};
|
|
101
|
+
const before = lastLeft.current;
|
|
102
|
+
const wasDropped = dropped.current;
|
|
103
|
+
dropped.current = false;
|
|
104
|
+
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
105
|
+
if (!wasDropped) delete track.dataset.following;
|
|
106
|
+
const box = place();
|
|
107
|
+
const now = box?.left;
|
|
108
|
+
if (inertia && box && now !== void 0 && before !== void 0 && now !== before && track.hasAttribute("data-placed") && !reduced) {
|
|
109
|
+
track.style.setProperty("--thumb-lean", "0px");
|
|
110
|
+
busyUntil.current = performance.now() + 320;
|
|
111
|
+
if (!wasDropped) {
|
|
112
|
+
track.style.setProperty("--thumb-hold", now > before ? "1" : "-1");
|
|
113
|
+
track.style.setProperty("--thumb-s", travelStretch(now - before, box.width).toFixed(3));
|
|
114
|
+
track.dataset.moving = "";
|
|
115
|
+
track.dataset.travelling = "";
|
|
116
|
+
clearTimeout(release.current);
|
|
117
|
+
release.current = setTimeout(() => {
|
|
118
|
+
delete track.dataset.moving;
|
|
119
|
+
delete track.dataset.travelling;
|
|
120
|
+
track.style.setProperty("--thumb-s", "1");
|
|
121
|
+
}, 120);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
lastLeft.current = now;
|
|
125
|
+
const frame = requestAnimationFrame(() => setPlaced(true));
|
|
126
|
+
let settle = 0;
|
|
127
|
+
const observer = new ResizeObserver(() => {
|
|
128
|
+
const segment = pressed();
|
|
129
|
+
if (!segment || drag.current?.moved) return;
|
|
130
|
+
if (track.style.getPropertyValue("--thumb-left") === `${segment.offsetLeft}px` && track.style.getPropertyValue("--thumb-width") === `${segment.offsetWidth}px` && track.style.getPropertyValue("--track-width") === `${track.offsetWidth}px`) return;
|
|
131
|
+
track.dataset.settling = "";
|
|
132
|
+
lastLeft.current = place()?.left;
|
|
133
|
+
cancelAnimationFrame(settle);
|
|
134
|
+
settle = requestAnimationFrame(() => {
|
|
135
|
+
settle = requestAnimationFrame(() => delete track.dataset.settling);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
observer.observe(track);
|
|
139
|
+
for (const each of track.querySelectorAll("[data-slot=\"segment\"]")) observer.observe(each);
|
|
140
|
+
return () => {
|
|
141
|
+
cancelAnimationFrame(frame);
|
|
142
|
+
cancelAnimationFrame(settle);
|
|
143
|
+
observer.disconnect();
|
|
144
|
+
};
|
|
145
|
+
}, [value, inertia]);
|
|
146
|
+
useEffect(() => () => {
|
|
147
|
+
clearTimeout(release.current);
|
|
148
|
+
cancelAnimationFrame(leanFrame.current);
|
|
149
|
+
}, []);
|
|
150
|
+
const still = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
151
|
+
/** The first and the last place the thumb can stand at, as offsets in the track. */
|
|
152
|
+
function walls(track) {
|
|
153
|
+
const segments = track.querySelectorAll("[data-slot=\"segment\"]");
|
|
154
|
+
const first = segments[0];
|
|
155
|
+
const last = segments[segments.length - 1];
|
|
156
|
+
if (!first || !last) return void 0;
|
|
157
|
+
return {
|
|
158
|
+
start: first.offsetLeft,
|
|
159
|
+
end: last.offsetLeft + last.offsetWidth
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function reach(track, x) {
|
|
163
|
+
const segment = track.querySelector("[data-slot=\"segment\"][data-pressed]");
|
|
164
|
+
const wall = walls(track);
|
|
165
|
+
if (!segment || !wall || performance.now() < busyUntil.current || still()) return;
|
|
166
|
+
const box = segment.getBoundingClientRect();
|
|
167
|
+
const offset = x < box.left ? x - box.left : x > box.right ? x - box.right : 0;
|
|
168
|
+
const room = offset > 0 ? wall.end - segment.offsetLeft - segment.offsetWidth : segment.offsetLeft - wall.start;
|
|
169
|
+
const shape = leanShape(offset, segment.offsetWidth, room);
|
|
170
|
+
track.dataset.following = "";
|
|
171
|
+
track.dataset.moving = "";
|
|
172
|
+
track.style.setProperty("--thumb-lean", `${shape.shift.toFixed(2)}px`);
|
|
173
|
+
track.style.setProperty("--thumb-s", shape.stretch.toFixed(3));
|
|
174
|
+
if (shape.stretch !== 1) track.style.setProperty("--thumb-hold", String(shape.hold));
|
|
175
|
+
}
|
|
176
|
+
function lean(event) {
|
|
177
|
+
if (!inertia || event.pointerType !== "mouse" || drag.current) return;
|
|
178
|
+
const track = event.currentTarget;
|
|
179
|
+
const x = event.clientX;
|
|
180
|
+
cancelAnimationFrame(leanFrame.current);
|
|
181
|
+
leanFrame.current = requestAnimationFrame(() => reach(track, x));
|
|
182
|
+
}
|
|
183
|
+
function stand(event) {
|
|
184
|
+
const track = event.currentTarget;
|
|
185
|
+
cancelAnimationFrame(leanFrame.current);
|
|
186
|
+
if (!inertia || drag.current?.moved || performance.now() < busyUntil.current) return;
|
|
187
|
+
track.style.setProperty("--thumb-lean", "0px");
|
|
188
|
+
track.style.setProperty("--thumb-s", "1");
|
|
189
|
+
}
|
|
190
|
+
function grab(event) {
|
|
191
|
+
if (!inertia || event.button !== 0) return;
|
|
192
|
+
const track = event.currentTarget;
|
|
193
|
+
const segment = event.target.closest("[data-slot=\"segment\"]");
|
|
194
|
+
if (!segment) return;
|
|
195
|
+
if (!segment.hasAttribute("data-pressed")) {
|
|
196
|
+
reach(track, event.clientX);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const segments = [...track.querySelectorAll("[data-slot=\"segment\"]")];
|
|
200
|
+
const left = segment.offsetLeft;
|
|
201
|
+
const width = segment.offsetWidth;
|
|
202
|
+
try {
|
|
203
|
+
track.setPointerCapture(event.pointerId);
|
|
204
|
+
} catch {}
|
|
205
|
+
track.dataset.moving = "";
|
|
206
|
+
delete track.dataset.travelling;
|
|
207
|
+
track.dataset.grabbed = "";
|
|
208
|
+
drag.current = {
|
|
209
|
+
pointer: event.pointerId,
|
|
210
|
+
startX: event.clientX,
|
|
211
|
+
startMiddle: left + width / 2,
|
|
212
|
+
boxes: segments.map((each) => ({
|
|
213
|
+
value: each.getAttribute("data-value"),
|
|
214
|
+
left: each.offsetLeft,
|
|
215
|
+
width: each.offsetWidth
|
|
216
|
+
})),
|
|
217
|
+
left,
|
|
218
|
+
width,
|
|
219
|
+
over: segments.indexOf(segment),
|
|
220
|
+
moved: false,
|
|
221
|
+
motion: restingMotion(left + width / 2, event.timeStamp)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function pull(event) {
|
|
225
|
+
const held = drag.current;
|
|
226
|
+
if (!held || held.pointer !== event.pointerId) return lean(event);
|
|
227
|
+
const track = event.currentTarget;
|
|
228
|
+
if (event.buttons === 0 && !track.hasPointerCapture(event.pointerId)) return drop(event);
|
|
229
|
+
const dx = event.clientX - held.startX;
|
|
230
|
+
if (!held.moved && Math.abs(dx) < DRAG_SLOP) return;
|
|
231
|
+
if (!held.moved) {
|
|
232
|
+
held.moved = true;
|
|
233
|
+
cancelAnimationFrame(leanFrame.current);
|
|
234
|
+
track.style.setProperty("--thumb-lean", "0px");
|
|
235
|
+
track.style.setProperty("--thumb-s", "1");
|
|
236
|
+
track.dataset.following = "";
|
|
237
|
+
track.dataset.dragging = "";
|
|
238
|
+
}
|
|
239
|
+
const first = held.boxes[0];
|
|
240
|
+
const last = held.boxes[held.boxes.length - 1];
|
|
241
|
+
if (!first || !last) return;
|
|
242
|
+
const wish = held.startMiddle + dx;
|
|
243
|
+
const away = (index) => {
|
|
244
|
+
const box = held.boxes[index];
|
|
245
|
+
return box ? Math.abs(box.left + box.width / 2 - wish) : Number.POSITIVE_INFINITY;
|
|
246
|
+
};
|
|
247
|
+
let over = held.over;
|
|
248
|
+
held.boxes.forEach((_, index) => {
|
|
249
|
+
if (away(index) + DRAG_SLOP < away(over)) over = index;
|
|
250
|
+
});
|
|
251
|
+
held.over = over;
|
|
252
|
+
const width = widthAt(held.boxes, wish);
|
|
253
|
+
const left = Math.min(Math.max(wish - width / 2, first.left), last.left + last.width - width);
|
|
254
|
+
held.left = left;
|
|
255
|
+
held.width = width;
|
|
256
|
+
track.style.setProperty("--thumb-width", `${width.toFixed(2)}px`);
|
|
257
|
+
track.style.setProperty("--thumb-left", `${left.toFixed(2)}px`);
|
|
258
|
+
if (still()) return;
|
|
259
|
+
held.motion = trackMotion(held.motion, left + width / 2, event.timeStamp, width, pillGive(width));
|
|
260
|
+
const room = held.motion.direction > 0 ? left - first.left : last.left + last.width - left - width;
|
|
261
|
+
track.dataset.moving = "";
|
|
262
|
+
track.style.setProperty("--thumb-hold", String(held.motion.direction));
|
|
263
|
+
track.style.setProperty("--thumb-s", withinRoom(held.motion.stretch, room, width).toFixed(3));
|
|
264
|
+
clearTimeout(release.current);
|
|
265
|
+
release.current = setTimeout(() => {
|
|
266
|
+
delete track.dataset.moving;
|
|
267
|
+
track.style.setProperty("--thumb-s", "1");
|
|
268
|
+
const now = drag.current;
|
|
269
|
+
if (now) now.motion = restingMotion(now.left + now.width / 2, performance.now());
|
|
270
|
+
}, 90);
|
|
271
|
+
}
|
|
272
|
+
function drop(event) {
|
|
273
|
+
const held = drag.current;
|
|
274
|
+
if (!held || held.pointer !== event.pointerId) {
|
|
275
|
+
if (!held && event.pointerType !== "mouse") stand(event);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
drag.current = null;
|
|
279
|
+
const track = event.currentTarget;
|
|
280
|
+
if (track.hasPointerCapture(event.pointerId)) track.releasePointerCapture(event.pointerId);
|
|
281
|
+
delete track.dataset.grabbed;
|
|
282
|
+
delete track.dataset.moving;
|
|
283
|
+
if (!held.moved) return;
|
|
284
|
+
delete track.dataset.dragging;
|
|
285
|
+
clearTimeout(release.current);
|
|
286
|
+
track.style.setProperty("--thumb-s", "1");
|
|
287
|
+
lastLeft.current = held.left;
|
|
288
|
+
busyUntil.current = performance.now() + 320;
|
|
289
|
+
const next = held.boxes[held.over]?.value ?? void 0;
|
|
290
|
+
if (next && next !== value) {
|
|
291
|
+
dropped.current = true;
|
|
292
|
+
choose(next);
|
|
293
|
+
} else {
|
|
294
|
+
const pressed = track.querySelector("[data-slot=\"segment\"][data-pressed]");
|
|
295
|
+
if (pressed) {
|
|
296
|
+
track.style.setProperty("--thumb-left", `${pressed.offsetLeft}px`);
|
|
297
|
+
track.style.setProperty("--thumb-width", `${pressed.offsetWidth}px`);
|
|
298
|
+
}
|
|
299
|
+
lastLeft.current = pressed?.offsetLeft;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const round = shape === "round";
|
|
303
|
+
const track = useMemo(() => ({
|
|
304
|
+
shape,
|
|
305
|
+
value,
|
|
306
|
+
lens: false
|
|
307
|
+
}), [shape, value]);
|
|
308
|
+
const lens = useMemo(() => ({
|
|
309
|
+
shape,
|
|
310
|
+
value,
|
|
311
|
+
lens: true
|
|
312
|
+
}), [shape, value]);
|
|
313
|
+
return /* @__PURE__ */ jsxs(ToggleGroup, {
|
|
314
|
+
ref: trackRef,
|
|
315
|
+
"data-slot": "segmented-control",
|
|
316
|
+
"data-shape": shape,
|
|
317
|
+
"data-weight": inertia ? "" : void 0,
|
|
318
|
+
"data-placed": placed ? "" : void 0,
|
|
319
|
+
value: value === void 0 ? [] : [value],
|
|
320
|
+
onValueChange: (next) => {
|
|
321
|
+
const picked = next[0];
|
|
322
|
+
if (picked === void 0) return;
|
|
323
|
+
choose(picked);
|
|
324
|
+
},
|
|
325
|
+
onPointerDown: grab,
|
|
326
|
+
onPointerMove: pull,
|
|
327
|
+
onPointerUp: drop,
|
|
328
|
+
onPointerCancel: drop,
|
|
329
|
+
onPointerLeave: stand,
|
|
330
|
+
className: mergeClassName([
|
|
331
|
+
"group/track relative isolate inline-flex h-(--control-md) items-center bg-trough depth-trough",
|
|
332
|
+
round ? "rounded-full" : "gap-0.5 rounded-md p-[3px]",
|
|
333
|
+
inertia && "touch-pan-y data-dragging:cursor-grabbing"
|
|
334
|
+
], className),
|
|
335
|
+
...props,
|
|
336
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
337
|
+
"data-slot": "segment-thumb",
|
|
338
|
+
"aria-hidden": true,
|
|
339
|
+
className: cn("pointer-events-none absolute left-0", round ? "top-0 bottom-0" : "top-[3px] bottom-[3px]", value === void 0 && "hidden"),
|
|
340
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
341
|
+
"data-slot": "segment-thumb-face",
|
|
342
|
+
className: cn("absolute inset-(--thumb-fit) overflow-hidden rounded-(--thumb-radius) bg-raised", thumbDepth[shape], "group-data-grabbed/track:depth-plug"),
|
|
343
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
344
|
+
"data-slot": "segment-lens",
|
|
345
|
+
inert: true,
|
|
346
|
+
className: "absolute inset-0",
|
|
347
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
348
|
+
"data-slot": "segment-lens-labels",
|
|
349
|
+
className: cn("absolute left-[calc(var(--thumb-fit)*-1)] inline-flex h-(--track-height) w-(--track-width) items-center", round ? "top-[calc(var(--thumb-fit)*-1)]" : "top-[calc(-3px-var(--thumb-fit))] gap-0.5 p-[3px]"),
|
|
350
|
+
children: /* @__PURE__ */ jsx(TrackContext, {
|
|
351
|
+
value: lens,
|
|
352
|
+
children
|
|
353
|
+
})
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
}), /* @__PURE__ */ jsx(TrackContext, {
|
|
358
|
+
value: track,
|
|
359
|
+
children
|
|
360
|
+
})]
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
/** A segment's box and text: shared by the button and its copy in the lens, so both lay out alike. */
|
|
364
|
+
const segmentBox = {
|
|
365
|
+
square: "h-[calc(var(--control-md)-6px)] rounded-[calc(var(--radius-md)-3px)] px-(--field-pad-md)",
|
|
366
|
+
round: "h-full rounded-full pr-3.5 pl-3"
|
|
367
|
+
};
|
|
368
|
+
const segmentText = "inline-flex items-center justify-center text-control font-medium whitespace-nowrap select-none";
|
|
369
|
+
function Segment({ value, className, children, ...props }) {
|
|
370
|
+
const track = useContext(TrackContext);
|
|
371
|
+
const round = track.shape === "round";
|
|
372
|
+
if (track.lens) return /* @__PURE__ */ jsx("span", {
|
|
373
|
+
"data-slot": "segment-copy",
|
|
374
|
+
"data-pressed": track.value === value ? "" : void 0,
|
|
375
|
+
className: cn("group", segmentText, segmentBox[track.shape], "text-fg", typeof className === "string" && className),
|
|
376
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
377
|
+
"data-slot": "segment-label",
|
|
378
|
+
className: cn("inline-flex items-center", round && "gap-1.5"),
|
|
379
|
+
children: [round && /* @__PURE__ */ jsx("span", {
|
|
380
|
+
"data-slot": "segment-mark",
|
|
381
|
+
className: "mark group-data-pressed:mark-on group-data-pressed:delay-(--segment-seat)"
|
|
382
|
+
}), children]
|
|
383
|
+
})
|
|
384
|
+
});
|
|
385
|
+
return /* @__PURE__ */ jsx(Toggle, {
|
|
386
|
+
"data-slot": "segment",
|
|
387
|
+
"data-value": value,
|
|
388
|
+
value,
|
|
389
|
+
className: mergeClassName([
|
|
390
|
+
"group touch-target relative",
|
|
391
|
+
segmentText,
|
|
392
|
+
segmentBox[track.shape],
|
|
393
|
+
"text-fg-muted transition-colors duration-150 ease-out",
|
|
394
|
+
"not-data-pressed:hover:text-fg-body not-data-pressed:active:text-fg",
|
|
395
|
+
"group-not-data-placed/track:data-pressed:text-fg",
|
|
396
|
+
"before:absolute before:inset-(--thumb-fit) before:-z-2 before:hidden before:rounded-(--thumb-radius) before:bg-raised",
|
|
397
|
+
"group-not-data-placed/track:data-pressed:before:block",
|
|
398
|
+
seatDepth[track.shape],
|
|
399
|
+
"focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent"
|
|
400
|
+
], className),
|
|
401
|
+
...props,
|
|
402
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
403
|
+
"data-slot": "segment-label",
|
|
404
|
+
className: cn("relative -z-1 inline-flex items-center", round && "gap-1.5"),
|
|
405
|
+
children: [round && /* @__PURE__ */ jsx("span", {
|
|
406
|
+
"data-slot": "segment-mark",
|
|
407
|
+
"aria-hidden": true,
|
|
408
|
+
className: "mark group-hover:[--mark-ring:var(--lf-text-muted)] group-not-data-placed/track:group-data-pressed:mark-on"
|
|
409
|
+
}), children]
|
|
410
|
+
})
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
export { Segment, SegmentedControl };
|