@underpin/ui 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.md +45 -2
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/button-group.d.ts +17 -0
- package/components/button-group.js +27 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +128 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +15 -0
- package/components/pagination.js +63 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/tabs.d.ts +18 -0
- package/components/tabs.js +65 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +23 -0
- package/lib/icons.js +28 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +116 -4
- package/styles.css +619 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { SEGMENTED_INDICATOR_BOX, SEGMENTED_UNMEASURED_KEY, segmentedVariants, useSegmentedIndicator } from "../lib/segmented.js";
|
|
3
|
+
import { cn } from "../lib/variants.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { createContext, isValidElement, memo, use, useState } from "react";
|
|
6
|
+
import { Radio } from "@base-ui/react/radio";
|
|
7
|
+
import { RadioGroup } from "@base-ui/react/radio-group";
|
|
8
|
+
// src/components/segmented-control.tsx
|
|
9
|
+
const SegmentedControlContext = createContext({
|
|
10
|
+
variant: "segmented",
|
|
11
|
+
size: "md"
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* One choice out of a few short options, drawn as a row with a pill behind the chosen one: a
|
|
15
|
+
* theme, a billing interval, the framework a snippet is written for. It is a radio group, so
|
|
16
|
+
* the arrow keys move the choice and a screen reader announces "radio, 2 of 3"; a row whose
|
|
17
|
+
* options each show a panel of their own is `Tabs`.
|
|
18
|
+
*
|
|
19
|
+
* The pill is measured after layout. Until then the checked option paints its own fill, so a
|
|
20
|
+
* server render, or a page before hydration, already shows the choice.
|
|
21
|
+
*/
|
|
22
|
+
function SegmentedControl({ className, children, variant = "segmented", size = "md", value, defaultValue, onValueChange, ...props }) {
|
|
23
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
24
|
+
const ref = useSegmentedIndicator(value ?? uncontrolled);
|
|
25
|
+
const slots = segmentedVariants({
|
|
26
|
+
variant,
|
|
27
|
+
size
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsx(SegmentedControlContext, {
|
|
30
|
+
value: {
|
|
31
|
+
variant,
|
|
32
|
+
size
|
|
33
|
+
},
|
|
34
|
+
children: /* @__PURE__ */ jsxs(RadioGroup, {
|
|
35
|
+
ref,
|
|
36
|
+
value,
|
|
37
|
+
defaultValue,
|
|
38
|
+
className: cn(slots.root(), variant === "segmented" ? SEGMENTED_UNMEASURED_KEY : "[&:not([data-measured])_[data-checked]]:bg-fill", className),
|
|
39
|
+
onValueChange: (next, eventDetails) => {
|
|
40
|
+
setUncontrolled(next);
|
|
41
|
+
onValueChange?.(next, eventDetails);
|
|
42
|
+
},
|
|
43
|
+
...props,
|
|
44
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
45
|
+
"aria-hidden": true,
|
|
46
|
+
className: slots.indicator({ className: SEGMENTED_INDICATOR_BOX })
|
|
47
|
+
}), children]
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One option in a `SegmentedControl`; its children are its label. Memoised, as a row
|
|
53
|
+
* re-renders with its card and its options rarely change with it; `memo` drops the `Value`
|
|
54
|
+
* parameter, so the cast below puts it back.
|
|
55
|
+
*/
|
|
56
|
+
const SegmentedControlItem = memo(function SegmentedControlItem({ className, ...props }) {
|
|
57
|
+
const { variant, size } = use(SegmentedControlContext);
|
|
58
|
+
const icon = Boolean(props["aria-label"]) && isValidElement(props.children);
|
|
59
|
+
return /* @__PURE__ */ jsx(Radio.Root, {
|
|
60
|
+
className: cn(segmentedVariants({
|
|
61
|
+
variant,
|
|
62
|
+
size,
|
|
63
|
+
icon
|
|
64
|
+
}).item(), "not-data-disabled:cursor-pointer data-disabled:opacity-50 data-checked:text-ink", className),
|
|
65
|
+
...props
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
export { SegmentedControl, SegmentedControlItem };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=segmented-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.js","names":["RadioGroupPrimitive","RadioPrimitive"],"sources":["../../src/components/segmented-control.tsx"],"sourcesContent":["\"use client\"\n\nimport { Radio as RadioPrimitive } from \"@base-ui/react/radio\"\nimport { RadioGroup as RadioGroupPrimitive } from \"@base-ui/react/radio-group\"\nimport { createContext, isValidElement, type JSX, memo, use, useState } from \"react\"\nimport {\n SEGMENTED_INDICATOR_BOX,\n SEGMENTED_UNMEASURED_KEY,\n type SegmentedStyle,\n segmentedVariants,\n useSegmentedIndicator,\n} from \"../lib/segmented\"\nimport { cn, type VariantProps } from \"../lib/variants\"\n\n// The parts below merge `className` outside the variants call, unlike everywhere else: Base UI\n// types it as a function of the part's own state too, which `variants` cannot take.\n\nconst SegmentedControlContext = createContext<SegmentedStyle>({\n variant: \"segmented\",\n size: \"md\",\n})\n\nexport type SegmentedControlProps<Value> = RadioGroupPrimitive.Props<Value> &\n VariantProps<typeof segmentedVariants>\n\n/**\n * One choice out of a few short options, drawn as a row with a pill behind the chosen one: a\n * theme, a billing interval, the framework a snippet is written for. It is a radio group, so\n * the arrow keys move the choice and a screen reader announces \"radio, 2 of 3\"; a row whose\n * options each show a panel of their own is `Tabs`.\n *\n * The pill is measured after layout. Until then the checked option paints its own fill, so a\n * server render, or a page before hydration, already shows the choice.\n */\nfunction SegmentedControl<Value>({\n className,\n children,\n variant = \"segmented\",\n size = \"md\",\n value,\n defaultValue,\n onValueChange,\n ...props\n}: SegmentedControlProps<Value>) {\n // Followed here only to know when to measure again; Base UI still owns the value.\n const [uncontrolled, setUncontrolled] = useState(defaultValue)\n const ref = useSegmentedIndicator(value ?? uncontrolled)\n\n const slots = segmentedVariants({ variant, size })\n\n return (\n <SegmentedControlContext value={{ variant, size }}>\n <RadioGroupPrimitive\n ref={ref}\n value={value}\n defaultValue={defaultValue}\n className={cn(\n slots.root(),\n variant === \"segmented\"\n ? SEGMENTED_UNMEASURED_KEY\n : \"[&:not([data-measured])_[data-checked]]:bg-fill\",\n className,\n )}\n onValueChange={(next, eventDetails) => {\n setUncontrolled(next)\n onValueChange?.(next, eventDetails)\n }}\n {...props}\n >\n <span aria-hidden className={slots.indicator({ className: SEGMENTED_INDICATOR_BOX })} />\n {children}\n </RadioGroupPrimitive>\n </SegmentedControlContext>\n )\n}\n\nexport type SegmentedControlItemProps<Value> = RadioPrimitive.Root.Props<Value>\n\n/**\n * One option in a `SegmentedControl`; its children are its label. Memoised, as a row\n * re-renders with its card and its options rarely change with it; `memo` drops the `Value`\n * parameter, so the cast below puts it back.\n */\nconst SegmentedControlItem = memo(function SegmentedControlItem<Value>({\n className,\n ...props\n}: SegmentedControlItemProps<Value>) {\n const { variant, size } = use(SegmentedControlContext)\n // Named by `aria-label` and showing one element: an icon, drawn as a square.\n const icon = Boolean(props[\"aria-label\"]) && isValidElement(props.children)\n\n return (\n <RadioPrimitive.Root\n className={cn(\n segmentedVariants({ variant, size, icon }).item(),\n \"not-data-disabled:cursor-pointer data-disabled:opacity-50 data-checked:text-ink\",\n className,\n )}\n {...props}\n />\n )\n}) as <Value>(props: SegmentedControlItemProps<Value>) => JSX.Element\n\nexport { SegmentedControl, SegmentedControlItem }\n"],"mappings":";;;;;;;;AAiBA,MAAM,0BAA0B,cAA8B;CAC5D,SAAS;CACT,MAAM;AACR,CAAC;;;;;;;;;;AAcD,SAAS,iBAAwB,EAC/B,WACA,UACA,UAAU,aACV,OAAO,MACP,OACA,cACA,eACA,GAAG,SAC4B;CAE/B,MAAM,CAAC,cAAc,mBAAmB,SAAS,YAAY;CAC7D,MAAM,MAAM,sBAAsB,SAAS,YAAY;CAEvD,MAAM,QAAQ,kBAAkB;EAAE;EAAS;CAAK,CAAC;CAEjD,OACE,oBAAC,yBAAD;EAAyB,OAAO;GAAE;GAAS;EAAK;EAC9C,UAAA,qBAACA,YAAD;GACO;GACE;GACO;GACd,WAAW,GACT,MAAM,KAAK,GACX,YAAY,cACR,2BACA,mDACJ,SACF;GACA,gBAAgB,MAAM,iBAAiB;IACrC,gBAAgB,IAAI;IACpB,gBAAgB,MAAM,YAAY;GACpC;GACA,GAAI;GAfN,UAAA,CAiBE,oBAAC,QAAD;IAAM,eAAA;IAAY,WAAW,MAAM,UAAU,EAAE,WAAW,wBAAwB,CAAC;GAAI,CAAA,GACtF,QACkB;;CACE,CAAA;AAE7B;;;;;;AASA,MAAM,uBAAuB,KAAK,SAAS,qBAA4B,EACrE,WACA,GAAG,SACgC;CACnC,MAAM,EAAE,SAAS,SAAS,IAAI,uBAAuB;CAErD,MAAM,OAAO,QAAQ,MAAM,aAAa,KAAK,eAAe,MAAM,QAAQ;CAE1E,OACE,oBAACC,MAAe,MAAhB;EACE,WAAW,GACT,kBAAkB;GAAE;GAAS;GAAM;EAAK,CAAC,CAAC,CAAC,KAAK,GAChD,mFACA,SACF;EACA,GAAI;CACL,CAAA;AAEL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { inputVariants } from "./input.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { Select as Select$1 } from "@base-ui/react/select";
|
|
5
|
+
/** Not modal, as a menu is. Base UI's own default is modal. */
|
|
6
|
+
declare function Select<Value, Multiple extends boolean | undefined = false>(props: Select$1.Root.Props<Value, Multiple>): import("react").JSX.Element;
|
|
7
|
+
declare const SelectGroup: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").SelectGroupProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
8
|
+
declare const SelectValue: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").SelectValueProps, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
|
|
9
|
+
declare function SelectTrigger({ children, className, interactive, size, ...props }: Select$1.Trigger.Props & VariantProps<typeof inputVariants>): import("react").JSX.Element;
|
|
10
|
+
declare function SelectScrollUpButton({ className, ...props }: Select$1.ScrollUpArrow.Props): import("react").JSX.Element;
|
|
11
|
+
declare function SelectScrollDownButton({ className, ...props }: Select$1.ScrollDownArrow.Props): import("react").JSX.Element;
|
|
12
|
+
declare function SelectContent({ className, children, align, side, sideOffset, alignItemWithTrigger, ...props }: Select$1.Popup.Props & Pick<Select$1.Positioner.Props, "align" | "side" | "sideOffset" | "alignItemWithTrigger">): import("react").JSX.Element;
|
|
13
|
+
declare function SelectLabel({ className, ...props }: Select$1.GroupLabel.Props): import("react").JSX.Element;
|
|
14
|
+
interface SelectItemProps extends Omit<Select$1.Item.Props, "prefix"> {
|
|
15
|
+
prefix?: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Why the option cannot be chosen. It stays in the list, disabled but reachable with the arrow
|
|
18
|
+
* keys, and the reason is read with it and shown in a tooltip, which a tap opens too.
|
|
19
|
+
*/
|
|
20
|
+
disabledReason?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One option. The check ends the row in muted ink, as in a menu, so the label keeps the row's
|
|
24
|
+
* inset whether or not the option carries a leading glyph.
|
|
25
|
+
*/
|
|
26
|
+
declare function SelectItem({ className, children, label, prefix, disabled, disabledReason, onPointerUp, ...props }: SelectItemProps): import("react").JSX.Element;
|
|
27
|
+
declare function SelectSeparator({ className, ...props }: Select$1.Separator.Props): import("react").JSX.Element;
|
|
28
|
+
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { popoverAnimationClasses, popupBackdropClasses, popupGroupLabelClasses, popupItemClasses, popupSeparatorClasses, popupSurfaceClasses } from "../lib/classes.js";
|
|
3
|
+
import { CheckIcon, ChevronDownIcon, ChevronUpIcon, ChevronsUpDownIcon } from "../lib/icons.js";
|
|
4
|
+
import { cn, variants } from "../lib/variants.js";
|
|
5
|
+
import { useDisabledReason } from "./disabled-reason.js";
|
|
6
|
+
import { inputVariants } from "./input.js";
|
|
7
|
+
import { Tooltip } from "./tooltip.js";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { Select as Select$1 } from "@base-ui/react/select";
|
|
10
|
+
// src/components/select.tsx
|
|
11
|
+
/** Not modal, as a menu is. Base UI's own default is modal. */
|
|
12
|
+
function Select(props) {
|
|
13
|
+
return /* @__PURE__ */ jsx(Select$1.Root, {
|
|
14
|
+
modal: false,
|
|
15
|
+
...props
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const SelectGroup = Select$1.Group;
|
|
19
|
+
const SelectValue = Select$1.Value;
|
|
20
|
+
function SelectTrigger({ children, className, interactive = true, size, ...props }) {
|
|
21
|
+
return /* @__PURE__ */ jsxs(Select$1.Trigger, {
|
|
22
|
+
className: inputVariants({
|
|
23
|
+
interactive,
|
|
24
|
+
size,
|
|
25
|
+
className: cn("flex items-center justify-between", "data-popup-open:border-edge-solid data-popup-open:bg-fill-subtle", interactive && "active:not-disabled:bg-fill-subtle", className)
|
|
26
|
+
}),
|
|
27
|
+
...props,
|
|
28
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
29
|
+
className: "truncate",
|
|
30
|
+
children
|
|
31
|
+
}), /* @__PURE__ */ jsx(Select$1.Icon, { render: /* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: "ml-1 size-3.5 shrink-0 text-ink-muted" }) })]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function SelectScrollUpButton({ className, ...props }) {
|
|
35
|
+
return /* @__PURE__ */ jsx(Select$1.ScrollUpArrow, {
|
|
36
|
+
className: cn("flex cursor-pointer items-center justify-center py-1", className),
|
|
37
|
+
...props,
|
|
38
|
+
children: /* @__PURE__ */ jsx(ChevronUpIcon, {})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function SelectScrollDownButton({ className, ...props }) {
|
|
42
|
+
return /* @__PURE__ */ jsx(Select$1.ScrollDownArrow, {
|
|
43
|
+
className: cn("flex cursor-pointer items-center justify-center py-1", className),
|
|
44
|
+
...props,
|
|
45
|
+
children: /* @__PURE__ */ jsx(ChevronDownIcon, {})
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const selectScrollButtonVariants = variants({
|
|
49
|
+
base: "absolute inset-x-0 z-10 bg-overlay animate-in fade-in-0 duration-150 ease-out",
|
|
50
|
+
variants: { position: {
|
|
51
|
+
top: "top-0 mask-b-from-0",
|
|
52
|
+
bottom: "bottom-0 mask-t-from-0"
|
|
53
|
+
} }
|
|
54
|
+
});
|
|
55
|
+
function SelectContent({ className, children, align, side, sideOffset = 6, alignItemWithTrigger = false, ...props }) {
|
|
56
|
+
return /* @__PURE__ */ jsxs(Select$1.Portal, { children: [/* @__PURE__ */ jsx(Select$1.Backdrop, { className: popupBackdropClasses }), /* @__PURE__ */ jsx(Select$1.Positioner, {
|
|
57
|
+
sideOffset,
|
|
58
|
+
align,
|
|
59
|
+
side,
|
|
60
|
+
alignItemWithTrigger,
|
|
61
|
+
className: "isolate z-50",
|
|
62
|
+
children: /* @__PURE__ */ jsxs(Select$1.Popup, {
|
|
63
|
+
className: cn(popupSurfaceClasses, "relative z-50 isolate max-h-(--available-height) min-w-(--anchor-width) overflow-hidden outline-none", !alignItemWithTrigger && popoverAnimationClasses, className),
|
|
64
|
+
...props,
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx(SelectScrollUpButton, { className: selectScrollButtonVariants({ position: "top" }) }),
|
|
67
|
+
/* @__PURE__ */ jsx(Select$1.List, {
|
|
68
|
+
className: "max-h-(--available-height) overflow-y-auto overscroll-contain p-1",
|
|
69
|
+
children
|
|
70
|
+
}),
|
|
71
|
+
/* @__PURE__ */ jsx(SelectScrollDownButton, { className: selectScrollButtonVariants({ position: "bottom" }) })
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
})] });
|
|
75
|
+
}
|
|
76
|
+
function SelectLabel({ className, ...props }) {
|
|
77
|
+
return /* @__PURE__ */ jsx(Select$1.GroupLabel, {
|
|
78
|
+
className: cn(popupGroupLabelClasses, className),
|
|
79
|
+
...props
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* One option. The check ends the row in muted ink, as in a menu, so the label keeps the row's
|
|
84
|
+
* inset whether or not the option carries a leading glyph.
|
|
85
|
+
*/
|
|
86
|
+
function SelectItem({ className, children, label, prefix, disabled, disabledReason, onPointerUp, ...props }) {
|
|
87
|
+
const reason = useDisabledReason(disabledReason, props["aria-describedby"]);
|
|
88
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
89
|
+
id: reason.triggerId,
|
|
90
|
+
tooltip: disabledReason,
|
|
91
|
+
side: "left",
|
|
92
|
+
children: /* @__PURE__ */ jsxs(Select$1.Item, {
|
|
93
|
+
...props,
|
|
94
|
+
label: label ?? (typeof children === "string" ? children : void 0),
|
|
95
|
+
disabled: disabled === true || !!disabledReason,
|
|
96
|
+
"aria-describedby": reason.describedBy,
|
|
97
|
+
onPointerUp: (event) => {
|
|
98
|
+
onPointerUp?.(event);
|
|
99
|
+
reason.onPointerUp(event);
|
|
100
|
+
},
|
|
101
|
+
className: cn(popupItemClasses, "group/choice w-full gap-2 px-2 data-selected:text-ink", className),
|
|
102
|
+
children: [
|
|
103
|
+
prefix != null && /* @__PURE__ */ jsx("span", {
|
|
104
|
+
className: "flex shrink-0 text-ink-muted [&>svg]:size-4",
|
|
105
|
+
children: prefix
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ jsx(Select$1.ItemText, {
|
|
108
|
+
className: "truncate",
|
|
109
|
+
children
|
|
110
|
+
}),
|
|
111
|
+
/* @__PURE__ */ jsx("span", {
|
|
112
|
+
"aria-hidden": true,
|
|
113
|
+
className: "ml-auto hidden shrink-0 pl-4 text-ink-muted group-data-selected/choice:flex",
|
|
114
|
+
children: /* @__PURE__ */ jsx(Select$1.ItemIndicator, { children: /* @__PURE__ */ jsx(CheckIcon, { className: "size-4" }) })
|
|
115
|
+
}),
|
|
116
|
+
reason.reasonText
|
|
117
|
+
]
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function SelectSeparator({ className, ...props }) {
|
|
122
|
+
return /* @__PURE__ */ jsx(Select$1.Separator, {
|
|
123
|
+
className: cn(popupSeparatorClasses, className),
|
|
124
|
+
...props
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue };
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","names":["SelectPrimitive"],"sources":["../../src/components/select.tsx"],"sourcesContent":["\"use client\"\n\nimport { Select as SelectPrimitive } from \"@base-ui/react/select\"\nimport type { ReactNode } from \"react\"\nimport {\n POPUP_SIDE_OFFSET,\n popoverAnimationClasses,\n popupBackdropClasses,\n popupGroupLabelClasses,\n popupItemClasses,\n popupSeparatorClasses,\n popupSurfaceClasses,\n} from \"../lib/classes\"\nimport { CheckIcon, ChevronDownIcon, ChevronUpIcon, ChevronsUpDownIcon } from \"../lib/icons\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\nimport { useDisabledReason } from \"./disabled-reason\"\nimport { inputVariants } from \"./input\"\nimport { Tooltip } from \"./tooltip\"\n\n/** Not modal, as a menu is. Base UI's own default is modal. */\nfunction Select<Value, Multiple extends boolean | undefined = false>(\n props: SelectPrimitive.Root.Props<Value, Multiple>,\n) {\n return <SelectPrimitive.Root modal={false} {...props} />\n}\n\nconst SelectGroup = SelectPrimitive.Group\nconst SelectValue = SelectPrimitive.Value\n\nfunction SelectTrigger({\n children,\n className,\n interactive = true,\n size,\n ...props\n}: SelectPrimitive.Trigger.Props & VariantProps<typeof inputVariants>) {\n return (\n <SelectPrimitive.Trigger\n className={inputVariants({\n interactive,\n size,\n className: cn(\n \"flex items-center justify-between\",\n \"data-popup-open:border-edge-solid data-popup-open:bg-fill-subtle\",\n interactive && \"active:not-disabled:bg-fill-subtle\",\n className,\n ),\n })}\n {...props}\n >\n <span className=\"truncate\">{children}</span>\n\n <SelectPrimitive.Icon\n render={<ChevronsUpDownIcon className=\"ml-1 size-3.5 shrink-0 text-ink-muted\" />}\n />\n </SelectPrimitive.Trigger>\n )\n}\n\nfunction SelectScrollUpButton({ className, ...props }: SelectPrimitive.ScrollUpArrow.Props) {\n return (\n <SelectPrimitive.ScrollUpArrow\n className={cn(\"flex cursor-pointer items-center justify-center py-1\", className)}\n {...props}\n >\n <ChevronUpIcon />\n </SelectPrimitive.ScrollUpArrow>\n )\n}\n\nfunction SelectScrollDownButton({ className, ...props }: SelectPrimitive.ScrollDownArrow.Props) {\n return (\n <SelectPrimitive.ScrollDownArrow\n className={cn(\"flex cursor-pointer items-center justify-center py-1\", className)}\n {...props}\n >\n <ChevronDownIcon />\n </SelectPrimitive.ScrollDownArrow>\n )\n}\n\nconst selectScrollButtonVariants = variants({\n base: \"absolute inset-x-0 z-10 bg-overlay animate-in fade-in-0 duration-150 ease-out\",\n variants: {\n position: {\n top: \"top-0 mask-b-from-0\",\n bottom: \"bottom-0 mask-t-from-0\",\n },\n },\n})\n\nfunction SelectContent({\n className,\n children,\n align,\n side,\n sideOffset = POPUP_SIDE_OFFSET,\n alignItemWithTrigger = false,\n ...props\n}: SelectPrimitive.Popup.Props &\n Pick<\n SelectPrimitive.Positioner.Props,\n \"align\" | \"side\" | \"sideOffset\" | \"alignItemWithTrigger\"\n >) {\n return (\n <SelectPrimitive.Portal>\n <SelectPrimitive.Backdrop className={popupBackdropClasses} />\n <SelectPrimitive.Positioner\n sideOffset={sideOffset}\n align={align}\n side={side}\n alignItemWithTrigger={alignItemWithTrigger}\n className=\"isolate z-50\"\n >\n <SelectPrimitive.Popup\n className={cn(\n popupSurfaceClasses,\n \"relative z-50 isolate max-h-(--available-height) min-w-(--anchor-width) overflow-hidden outline-none\",\n !alignItemWithTrigger && popoverAnimationClasses,\n className,\n )}\n {...props}\n >\n <SelectScrollUpButton className={selectScrollButtonVariants({ position: \"top\" })} />\n {/* The list is the scroller (not the popup), so the scroll arrows can overlay it. */}\n <SelectPrimitive.List className=\"max-h-(--available-height) overflow-y-auto overscroll-contain p-1\">\n {children}\n </SelectPrimitive.List>\n <SelectScrollDownButton className={selectScrollButtonVariants({ position: \"bottom\" })} />\n </SelectPrimitive.Popup>\n </SelectPrimitive.Positioner>\n </SelectPrimitive.Portal>\n )\n}\n\nfunction SelectLabel({ className, ...props }: SelectPrimitive.GroupLabel.Props) {\n return <SelectPrimitive.GroupLabel className={cn(popupGroupLabelClasses, className)} {...props} />\n}\n\ninterface SelectItemProps extends Omit<SelectPrimitive.Item.Props, \"prefix\"> {\n prefix?: ReactNode\n /**\n * Why the option cannot be chosen. It stays in the list, disabled but reachable with the arrow\n * keys, and the reason is read with it and shown in a tooltip, which a tap opens too.\n */\n disabledReason?: string\n}\n\n/**\n * One option. The check ends the row in muted ink, as in a menu, so the label keeps the row's\n * inset whether or not the option carries a leading glyph.\n */\nfunction SelectItem({\n className,\n children,\n label,\n prefix,\n disabled,\n disabledReason,\n onPointerUp,\n ...props\n}: SelectItemProps) {\n const reason = useDisabledReason(disabledReason, props[\"aria-describedby\"])\n\n return (\n <Tooltip id={reason.triggerId} tooltip={disabledReason} side=\"left\">\n <SelectPrimitive.Item\n // First, so the caller's description and pointer-up merge with the reason's.\n {...props}\n label={label ?? (typeof children === \"string\" ? children : undefined)}\n disabled={disabled === true || !!disabledReason}\n aria-describedby={reason.describedBy}\n onPointerUp={event => {\n onPointerUp?.(event)\n reason.onPointerUp(event)\n }}\n className={cn(\n popupItemClasses,\n \"group/choice w-full gap-2 px-2 data-selected:text-ink\",\n className,\n )}\n >\n {prefix != null && (\n <span className=\"flex shrink-0 text-ink-muted [&>svg]:size-4\">{prefix}</span>\n )}\n\n <SelectPrimitive.ItemText className=\"truncate\">{children}</SelectPrimitive.ItemText>\n\n {/* Only the selected row carries the check, so the others give its width to the label;\n `pl-4` on top of the row's gap keeps a floor between the label and the check. */}\n <span\n aria-hidden\n className=\"ml-auto hidden shrink-0 pl-4 text-ink-muted group-data-selected/choice:flex\"\n >\n <SelectPrimitive.ItemIndicator>\n <CheckIcon className=\"size-4\" />\n </SelectPrimitive.ItemIndicator>\n </span>\n\n {reason.reasonText}\n </SelectPrimitive.Item>\n </Tooltip>\n )\n}\n\nfunction SelectSeparator({ className, ...props }: SelectPrimitive.Separator.Props) {\n return <SelectPrimitive.Separator className={cn(popupSeparatorClasses, className)} {...props} />\n}\n\nexport {\n Select,\n SelectGroup,\n SelectValue,\n SelectTrigger,\n SelectContent,\n SelectLabel,\n SelectItem,\n SelectSeparator,\n SelectScrollUpButton,\n SelectScrollDownButton,\n}\n"],"mappings":";;;;;;;;;;;AAoBA,SAAS,OACP,OACA;CACA,OAAO,oBAACA,SAAgB,MAAjB;EAAsB,OAAO;EAAO,GAAI;CAAQ,CAAA;AACzD;AAEA,MAAM,cAAcA,SAAgB;AACpC,MAAM,cAAcA,SAAgB;AAEpC,SAAS,cAAc,EACrB,UACA,WACA,cAAc,MACd,MACA,GAAG,SACkE;CACrE,OACE,qBAACA,SAAgB,SAAjB;EACE,WAAW,cAAc;GACvB;GACA;GACA,WAAW,GACT,qCACA,oEACA,eAAe,sCACf,SACF;EACF,CAAC;EACD,GAAI;EAXN,UAAA,CAaE,oBAAC,QAAD;GAAM,WAAU;GAAY;EAAe,CAAA,GAE3C,oBAACA,SAAgB,MAAjB,EACE,QAAQ,oBAAC,oBAAD,EAAoB,WAAU,wCAAyC,CAAA,EAChF,CAAA,CACsB;;AAE7B;AAEA,SAAS,qBAAqB,EAAE,WAAW,GAAG,SAA8C;CAC1F,OACE,oBAACA,SAAgB,eAAjB;EACE,WAAW,GAAG,wDAAwD,SAAS;EAC/E,GAAI;EAEJ,UAAA,oBAAC,eAAD,CAAgB,CAAA;CACa,CAAA;AAEnC;AAEA,SAAS,uBAAuB,EAAE,WAAW,GAAG,SAAgD;CAC9F,OACE,oBAACA,SAAgB,iBAAjB;EACE,WAAW,GAAG,wDAAwD,SAAS;EAC/E,GAAI;EAEJ,UAAA,oBAAC,iBAAD,CAAkB,CAAA;CACa,CAAA;AAErC;AAEA,MAAM,6BAA6B,SAAS;CAC1C,MAAM;CACN,UAAU,EACR,UAAU;EACR,KAAK;EACL,QAAQ;CACV,EACF;AACF,CAAC;AAED,SAAS,cAAc,EACrB,WACA,UACA,OACA,MACA,aAAA,GACA,uBAAuB,OACvB,GAAG,SAKA;CACH,OACE,qBAACA,SAAgB,QAAjB,EAAA,UAAA,CACE,oBAACA,SAAgB,UAAjB,EAA0B,WAAW,qBAAuB,CAAA,GAC5D,oBAACA,SAAgB,YAAjB;EACc;EACL;EACD;EACgB;EACtB,WAAU;EAEV,UAAA,qBAACA,SAAgB,OAAjB;GACE,WAAW,GACT,qBACA,wGACA,CAAC,wBAAwB,yBACzB,SACF;GACA,GAAI;GAPN,UAAA;IASE,oBAAC,sBAAD,EAAsB,WAAW,2BAA2B,EAAE,UAAU,MAAM,CAAC,EAAI,CAAA;IAEnF,oBAACA,SAAgB,MAAjB;KAAsB,WAAU;KAC7B;IACmB,CAAA;IACtB,oBAAC,wBAAD,EAAwB,WAAW,2BAA2B,EAAE,UAAU,SAAS,CAAC,EAAI,CAAA;GACnE;;CACG,CAAA,CACN,EAAA,CAAA;AAE5B;AAEA,SAAS,YAAY,EAAE,WAAW,GAAG,SAA2C;CAC9E,OAAO,oBAACA,SAAgB,YAAjB;EAA4B,WAAW,GAAG,wBAAwB,SAAS;EAAG,GAAI;CAAQ,CAAA;AACnG;;;;;AAeA,SAAS,WAAW,EAClB,WACA,UACA,OACA,QACA,UACA,gBACA,aACA,GAAG,SACe;CAClB,MAAM,SAAS,kBAAkB,gBAAgB,MAAM,mBAAmB;CAE1E,OACE,oBAAC,SAAD;EAAS,IAAI,OAAO;EAAW,SAAS;EAAgB,MAAK;EAC3D,UAAA,qBAACA,SAAgB,MAAjB;GAEE,GAAI;GACJ,OAAO,UAAU,OAAO,aAAa,WAAW,WAAW,KAAA;GAC3D,UAAU,aAAa,QAAQ,CAAC,CAAC;GACjC,oBAAkB,OAAO;GACzB,cAAa,UAAS;IACpB,cAAc,KAAK;IACnB,OAAO,YAAY,KAAK;GAC1B;GACA,WAAW,GACT,kBACA,yDACA,SACF;GAdF,UAAA;IAgBG,UAAU,QACT,oBAAC,QAAD;KAAM,WAAU;KAA+C,UAAA;IAAa,CAAA;IAG9E,oBAACA,SAAgB,UAAjB;KAA0B,WAAU;KAAY;IAAmC,CAAA;IAInF,oBAAC,QAAD;KACE,eAAA;KACA,WAAU;KAEV,UAAA,oBAACA,SAAgB,eAAjB,EAAA,UACE,oBAAC,WAAD,EAAW,WAAU,SAAU,CAAA,EACF,CAAA;IAC3B,CAAA;IAEL,OAAO;GACY;;CACf,CAAA;AAEb;AAEA,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAA0C;CACjF,OAAO,oBAACA,SAAgB,WAAjB;EAA2B,WAAW,GAAG,uBAAuB,SAAS;EAAG,GAAI;CAAQ,CAAA;AACjG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Kbd } from "./kbd.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
interface ShortcutKeysProps extends Pick<ComponentProps<typeof Kbd>, "variant"> {
|
|
4
|
+
keys: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The badge for one key string, a box per part, in the font the platform draws modifiers in.
|
|
9
|
+
* At the end of a menu row it takes `variant="plain"`, the letters alone, as `MenuShortcut` draws.
|
|
10
|
+
* A screen reader hears the keys spelled out ("Command K") instead of the glyphs. The badge
|
|
11
|
+
* names its key in `data-shortcut`, so an open menu picks the row it sits in when it is pressed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ShortcutKeys({ keys, variant, className }: ShortcutKeysProps): import("react").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatKeys, formatSpokenKeys, toHotkey, useIsMac } from "../lib/shortcuts.js";
|
|
3
|
+
import { cn } from "../lib/variants.js";
|
|
4
|
+
import { Kbd } from "./kbd.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/shortcut-keys.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The badge for one key string, a box per part, in the font the platform draws modifiers in.
|
|
9
|
+
* At the end of a menu row it takes `variant="plain"`, the letters alone, as `MenuShortcut` draws.
|
|
10
|
+
* A screen reader hears the keys spelled out ("Command K") instead of the glyphs. The badge
|
|
11
|
+
* names its key in `data-shortcut`, so an open menu picks the row it sits in when it is pressed.
|
|
12
|
+
*/
|
|
13
|
+
function ShortcutKeys({ keys, variant, className }) {
|
|
14
|
+
const mac = useIsMac();
|
|
15
|
+
const parts = formatKeys(keys, mac);
|
|
16
|
+
const spelled = parts.some((part) => part.length > 1);
|
|
17
|
+
return /* @__PURE__ */ jsxs(Kbd, {
|
|
18
|
+
"data-shortcut": toHotkey(keys),
|
|
19
|
+
variant,
|
|
20
|
+
className: cn("shrink-0", spelled && "gap-[0.35em]", className),
|
|
21
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
22
|
+
className: "sr-only",
|
|
23
|
+
children: formatSpokenKeys(keys, mac)
|
|
24
|
+
}), parts.map((part) => /* @__PURE__ */ jsx("span", {
|
|
25
|
+
"aria-hidden": true,
|
|
26
|
+
children: part
|
|
27
|
+
}, part))]
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export { ShortcutKeys };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=shortcut-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcut-keys.js","names":[],"sources":["../../src/components/shortcut-keys.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ComponentProps } from \"react\"\nimport { formatKeys, formatSpokenKeys, toHotkey, useIsMac } from \"../lib/shortcuts\"\nimport { cn } from \"../lib/variants\"\nimport { Kbd } from \"./kbd\"\n\ninterface ShortcutKeysProps extends Pick<ComponentProps<typeof Kbd>, \"variant\"> {\n keys: string\n className?: string\n}\n\n/**\n * The badge for one key string, a box per part, in the font the platform draws modifiers in.\n * At the end of a menu row it takes `variant=\"plain\"`, the letters alone, as `MenuShortcut` draws.\n * A screen reader hears the keys spelled out (\"Command K\") instead of the glyphs. The badge\n * names its key in `data-shortcut`, so an open menu picks the row it sits in when it is pressed.\n */\nexport function ShortcutKeys({ keys, variant, className }: ShortcutKeysProps) {\n const mac = useIsMac()\n const parts = formatKeys(keys, mac)\n // Glyphs read as one cluster on `Kbd`'s own hairline gap (\"⇧X\"); a modifier spelled out in\n // words, which is every modifier off a Mac, runs into its key at that gap and needs air.\n const spelled = parts.some(part => part.length > 1)\n\n return (\n <Kbd\n data-shortcut={toHotkey(keys)}\n variant={variant}\n className={cn(\"shrink-0\", spelled && \"gap-[0.35em]\", className)}\n >\n <span className=\"sr-only\">{formatSpokenKeys(keys, mac)}</span>\n {parts.map(part => (\n <span key={part} aria-hidden>\n {part}\n </span>\n ))}\n </Kbd>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAgB,aAAa,EAAE,MAAM,SAAS,aAAgC;CAC5E,MAAM,MAAM,SAAS;CACrB,MAAM,QAAQ,WAAW,MAAM,GAAG;CAGlC,MAAM,UAAU,MAAM,MAAK,SAAQ,KAAK,SAAS,CAAC;CAElD,OACE,qBAAC,KAAD;EACE,iBAAe,SAAS,IAAI;EACnB;EACT,WAAW,GAAG,YAAY,WAAW,gBAAgB,SAAS;EAHhE,UAAA,CAKE,oBAAC,QAAD;GAAM,WAAU;GAAW,UAAA,iBAAiB,MAAM,GAAG;EAAQ,CAAA,GAC5D,MAAM,KAAI,SACT,oBAAC,QAAD;GAAiB,eAAA;GACd,UAAA;EACG,GAFK,IAEL,CACP,CACE;;AAET"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface ShortcutsDialogProps {
|
|
2
|
+
open: boolean;
|
|
3
|
+
onOpenChange: (open: boolean) => void;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The one reference list of every shortcut mounted right now, read straight off the registry in
|
|
7
|
+
* `lib/shortcuts`. Nothing to wire: whatever a page registers shows up here, grouped.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ShortcutsDialog({ open, onOpenChange }: ShortcutsDialogProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { eyebrowClasses } from "../lib/classes.js";
|
|
3
|
+
import { matchesMedia } from "../lib/media.js";
|
|
4
|
+
import { formatKeys, useShortcutList } from "../lib/shortcuts.js";
|
|
5
|
+
import { cn } from "../lib/variants.js";
|
|
6
|
+
import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from "./dialog.js";
|
|
7
|
+
import { EmptyState } from "./empty-state.js";
|
|
8
|
+
import { SearchInput } from "./search-input.js";
|
|
9
|
+
import { ShortcutKeys } from "./shortcut-keys.js";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useRef, useState } from "react";
|
|
12
|
+
// src/components/shortcuts-dialog.tsx
|
|
13
|
+
/**
|
|
14
|
+
* The one reference list of every shortcut mounted right now, read straight off the registry in
|
|
15
|
+
* `lib/shortcuts`. Nothing to wire: whatever a page registers shows up here, grouped.
|
|
16
|
+
*/
|
|
17
|
+
function ShortcutsDialog({ open, onOpenChange }) {
|
|
18
|
+
const groups = useShortcutList();
|
|
19
|
+
const [search, setSearch] = useState("");
|
|
20
|
+
const searchRef = useRef(null);
|
|
21
|
+
const query = search.trim().toLowerCase();
|
|
22
|
+
const matches = groups.map((group) => ({
|
|
23
|
+
group: group.group,
|
|
24
|
+
shortcuts: group.shortcuts.filter((shortcut) => {
|
|
25
|
+
return [
|
|
26
|
+
shortcut.label,
|
|
27
|
+
group.group,
|
|
28
|
+
...formatKeys(shortcut.keys)
|
|
29
|
+
].join(" ").toLowerCase().includes(query);
|
|
30
|
+
})
|
|
31
|
+
})).filter((group) => group.shortcuts.length > 0);
|
|
32
|
+
function handleOpenChange(next) {
|
|
33
|
+
if (!next) setSearch("");
|
|
34
|
+
onOpenChange(next);
|
|
35
|
+
}
|
|
36
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
37
|
+
open,
|
|
38
|
+
onOpenChange: handleOpenChange,
|
|
39
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
40
|
+
size: "2xl",
|
|
41
|
+
instant: true,
|
|
42
|
+
initialFocus: () => matchesMedia("(pointer: fine)") ? searchRef.current : true,
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx(DialogHeader, {
|
|
45
|
+
bordered: true,
|
|
46
|
+
className: "sticky top-0 z-20 bg-surface",
|
|
47
|
+
title: "Keyboard shortcuts",
|
|
48
|
+
description: "Press ? anywhere to open this list."
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ jsx("div", {
|
|
51
|
+
className: "border-b bg-surface px-6 py-3",
|
|
52
|
+
children: /* @__PURE__ */ jsx(SearchInput, {
|
|
53
|
+
ref: searchRef,
|
|
54
|
+
value: search,
|
|
55
|
+
onValueChange: setSearch,
|
|
56
|
+
placeholder: "Search shortcuts",
|
|
57
|
+
"aria-label": "Search shortcuts"
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx("div", {
|
|
61
|
+
className: "gap-x-10 px-6 py-5 sm:columns-2",
|
|
62
|
+
children: matches.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
|
|
63
|
+
variant: "inline",
|
|
64
|
+
title: "No shortcuts match"
|
|
65
|
+
}) : matches.map((group) => /* @__PURE__ */ jsxs("div", {
|
|
66
|
+
className: "mb-5 break-inside-avoid last:mb-0",
|
|
67
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
68
|
+
className: cn(eyebrowClasses, "mb-1"),
|
|
69
|
+
children: group.group
|
|
70
|
+
}), group.shortcuts.map((shortcut) => /* @__PURE__ */ jsxs("div", {
|
|
71
|
+
className: "flex items-center justify-between gap-6 py-1.5 text-sm",
|
|
72
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
73
|
+
className: "min-w-0 truncate text-ink-secondary",
|
|
74
|
+
children: shortcut.label
|
|
75
|
+
}), /* @__PURE__ */ jsx(ShortcutKeys, { keys: shortcut.keys })]
|
|
76
|
+
}, `${shortcut.keys} ${shortcut.label}`))]
|
|
77
|
+
}, group.group))
|
|
78
|
+
}),
|
|
79
|
+
/* @__PURE__ */ jsx(DialogFooter, {
|
|
80
|
+
className: "sticky bottom-0 z-20 max-sm:hidden",
|
|
81
|
+
children: /* @__PURE__ */ jsx(DialogClose, {
|
|
82
|
+
variant: "primary",
|
|
83
|
+
children: "Done"
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export { ShortcutsDialog };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=shortcuts-dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcuts-dialog.js","names":[],"sources":["../../src/components/shortcuts-dialog.tsx"],"sourcesContent":["\"use client\"\n\nimport { useRef, useState } from \"react\"\nimport { eyebrowClasses } from \"../lib/classes\"\nimport { matchesMedia, POINTER_FINE } from \"../lib/media\"\nimport { formatKeys, useShortcutList } from \"../lib/shortcuts\"\nimport { cn } from \"../lib/variants\"\nimport { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from \"./dialog\"\nimport { EmptyState } from \"./empty-state\"\nimport { SearchInput } from \"./search-input\"\nimport { ShortcutKeys } from \"./shortcut-keys\"\n\ninterface ShortcutsDialogProps {\n open: boolean\n onOpenChange: (open: boolean) => void\n}\n\n/**\n * The one reference list of every shortcut mounted right now, read straight off the registry in\n * `lib/shortcuts`. Nothing to wire: whatever a page registers shows up here, grouped.\n */\nexport function ShortcutsDialog({ open, onOpenChange }: ShortcutsDialogProps) {\n const groups = useShortcutList()\n const [search, setSearch] = useState(\"\")\n const searchRef = useRef<HTMLInputElement>(null)\n\n const query = search.trim().toLowerCase()\n\n const matches = groups\n .map(group => ({\n group: group.group,\n shortcuts: group.shortcuts.filter(shortcut => {\n const haystack = [shortcut.label, group.group, ...formatKeys(shortcut.keys)]\n return haystack.join(\" \").toLowerCase().includes(query)\n }),\n }))\n .filter(group => group.shortcuts.length > 0)\n\n // The search is scoped to one visit: whatever was typed goes when the dialog is dismissed.\n function handleOpenChange(next: boolean) {\n if (!next) setSearch(\"\")\n onOpenChange(next)\n }\n\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <DialogContent\n size=\"2xl\"\n instant\n // The sheet on a phone is a coarse-pointer surface: focusing the field there throws up\n // the on-screen keyboard over the list it is meant to filter.\n initialFocus={() => (matchesMedia(POINTER_FINE) ? searchRef.current : true)}\n >\n {/* Sticky rather than a fixed-height scrolling body: a multi-column box with a capped\n height spills into a THIRD column and scrolls sideways, so the list keeps its natural\n height, the popup does the scrolling, and the header rides along. */}\n <DialogHeader\n bordered\n className=\"sticky top-0 z-20 bg-surface\"\n title=\"Keyboard shortcuts\"\n description=\"Press ? anywhere to open this list.\"\n />\n\n <div className=\"border-b bg-surface px-6 py-3\">\n <SearchInput\n ref={searchRef}\n value={search}\n onValueChange={setSearch}\n placeholder=\"Search shortcuts\"\n aria-label=\"Search shortcuts\"\n />\n </div>\n\n <div className=\"gap-x-10 px-6 py-5 sm:columns-2\">\n {matches.length === 0 ? (\n <EmptyState variant=\"inline\" title=\"No shortcuts match\" />\n ) : (\n matches.map(group => (\n <div key={group.group} className=\"mb-5 break-inside-avoid last:mb-0\">\n <p className={cn(eyebrowClasses, \"mb-1\")}>{group.group}</p>\n\n {group.shortcuts.map(shortcut => (\n <div\n key={`${shortcut.keys} ${shortcut.label}`}\n className=\"flex items-center justify-between gap-6 py-1.5 text-sm\"\n >\n <span className=\"min-w-0 truncate text-ink-secondary\">{shortcut.label}</span>\n\n <ShortcutKeys keys={shortcut.keys} />\n </div>\n ))}\n </div>\n ))\n )}\n </div>\n\n {/* Desktop only: a sheet closes by its X or a swipe, so a band across its foot would\n only take room from the list. Sticky like the header, since the popup itself is\n what scrolls here. */}\n <DialogFooter className=\"sticky bottom-0 z-20 max-sm:hidden\">\n <DialogClose variant=\"primary\">Done</DialogClose>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,SAAgB,gBAAgB,EAAE,MAAM,gBAAsC;CAC5E,MAAM,SAAS,gBAAgB;CAC/B,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,YAAY,OAAyB,IAAI;CAE/C,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY;CAExC,MAAM,UAAU,OACb,KAAI,WAAU;EACb,OAAO,MAAM;EACb,WAAW,MAAM,UAAU,QAAO,aAAY;GAE5C,OAAO;IADW,SAAS;IAAO,MAAM;IAAO,GAAG,WAAW,SAAS,IAAI;GAC5D,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,KAAK;EACxD,CAAC;CACH,EAAE,CAAC,CACF,QAAO,UAAS,MAAM,UAAU,SAAS,CAAC;CAG7C,SAAS,iBAAiB,MAAe;EACvC,IAAI,CAAC,MAAM,UAAU,EAAE;EACvB,aAAa,IAAI;CACnB;CAEA,OACE,oBAAC,QAAD;EAAc;EAAM,cAAc;EAChC,UAAA,qBAAC,eAAD;GACE,MAAK;GACL,SAAA;GAGA,oBAAqB,aAAA,iBAAyB,IAAI,UAAU,UAAU;GALxE,UAAA;IAUE,oBAAC,cAAD;KACE,UAAA;KACA,WAAU;KACV,OAAM;KACN,aAAY;IACb,CAAA;IAED,oBAAC,OAAD;KAAK,WAAU;KACb,UAAA,oBAAC,aAAD;MACE,KAAK;MACL,OAAO;MACP,eAAe;MACf,aAAY;MACZ,cAAW;KACZ,CAAA;IACE,CAAA;IAEL,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,QAAQ,WAAW,IAClB,oBAAC,YAAD;MAAY,SAAQ;MAAS,OAAM;KAAsB,CAAA,IAEzD,QAAQ,KAAI,UACV,qBAAC,OAAD;MAAuB,WAAU;MAAjC,UAAA,CACE,oBAAC,KAAD;OAAG,WAAW,GAAG,gBAAgB,MAAM;OAAI,UAAA,MAAM;MAAS,CAAA,GAEzD,MAAM,UAAU,KAAI,aACnB,qBAAC,OAAD;OAEE,WAAU;OAFZ,UAAA,CAIE,oBAAC,QAAD;QAAM,WAAU;QAAuC,UAAA,SAAS;OAAY,CAAA,GAE5E,oBAAC,cAAD,EAAc,MAAM,SAAS,KAAO,CAAA,CACjC;MANE,GAAA,GAAG,SAAS,KAAK,GAAG,SAAS,OAM/B,CACN,CACE;KAbK,GAAA,MAAM,KAaX,CACN;IAEA,CAAA;IAKL,oBAAC,cAAD;KAAc,WAAU;KACtB,UAAA,oBAAC,aAAD;MAAa,SAAQ;MAAU,UAAA;KAAiB,CAAA;IACpC,CAAA;GACD;;CACT,CAAA;AAEZ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
/**
|
|
3
|
+
* Loading stand-in in the fill, the same colour as a `BarList` bar, so every
|
|
4
|
+
* skeleton across a page reads as one thing. Size it with `className`; pass `render` for a
|
|
5
|
+
* different element, e.g. `render={<span />}` inside a paragraph. Hidden from screen readers:
|
|
6
|
+
* the container it stands in for says it is loading with `aria-busy`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Skeleton({ className, render, ...props }: useRender.ComponentProps<"div">): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { cn } from "../lib/variants.js";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
// src/components/skeleton.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Loading stand-in in the fill, the same colour as a `BarList` bar, so every
|
|
6
|
+
* skeleton across a page reads as one thing. Size it with `className`; pass `render` for a
|
|
7
|
+
* different element, e.g. `render={<span />}` inside a paragraph. Hidden from screen readers:
|
|
8
|
+
* the container it stands in for says it is loading with `aria-busy`.
|
|
9
|
+
*/
|
|
10
|
+
function Skeleton({ className, render, ...props }) {
|
|
11
|
+
return useRender({
|
|
12
|
+
render,
|
|
13
|
+
defaultTagName: "div",
|
|
14
|
+
props: {
|
|
15
|
+
"aria-hidden": true,
|
|
16
|
+
className: cn("animate-pulse rounded-md bg-fill motion-reduce:animate-none", className),
|
|
17
|
+
...props
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { Skeleton };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=skeleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skeleton.js","names":[],"sources":["../../src/components/skeleton.tsx"],"sourcesContent":["import { useRender } from \"@base-ui/react/use-render\"\nimport { cn } from \"../lib/variants\"\n\n/**\n * Loading stand-in in the fill, the same colour as a `BarList` bar, so every\n * skeleton across a page reads as one thing. Size it with `className`; pass `render` for a\n * different element, e.g. `render={<span />}` inside a paragraph. Hidden from screen readers:\n * the container it stands in for says it is loading with `aria-busy`.\n */\nexport function Skeleton({ className, render, ...props }: useRender.ComponentProps<\"div\">) {\n return useRender({\n render,\n defaultTagName: \"div\",\n props: {\n \"aria-hidden\": true,\n className: cn(\"animate-pulse rounded-md bg-fill motion-reduce:animate-none\", className),\n ...props,\n },\n })\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,SAAS,EAAE,WAAW,QAAQ,GAAG,SAA0C;CACzF,OAAO,UAAU;EACf;EACA,gBAAgB;EAChB,OAAO;GACL,eAAe;GACf,WAAW,GAAG,+DAA+D,SAAS;GACtF,GAAG;EACL;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
export type SparklineProps = Omit<ComponentProps<"div">, "children"> & {
|
|
3
|
+
/** One figure per step along the line, in order. */
|
|
4
|
+
data: number[];
|
|
5
|
+
/**
|
|
6
|
+
* Series colour; one of the `--color-chart-*` tokens.
|
|
7
|
+
*/
|
|
8
|
+
color?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Line weight in px.
|
|
11
|
+
*/
|
|
12
|
+
strokeWidth?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the line wipes in when the element enters the page. Off by default: a line on a
|
|
15
|
+
* page people return to all day would redraw on every visit.
|
|
16
|
+
*/
|
|
17
|
+
animated?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A trend at a glance: the smooth gradient area of `TimeSeriesChart` with no axes, grid,
|
|
21
|
+
* tooltip or hover, filling whatever box it is given. Plain SVG rather than a chart, so the
|
|
22
|
+
* pages that list sites never load the chart runtime for it. Purely a picture, so it takes no
|
|
23
|
+
* pointer events and whatever sits under it stays clickable.
|
|
24
|
+
*/
|
|
25
|
+
export declare function Sparkline({ data, color, strokeWidth, animated, className, ...props }: SparklineProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AREA_FADE } from "../lib/time-series.js";
|
|
3
|
+
import { cn } from "../lib/variants.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import { area, curveMonotoneX, line } from "d3-shape";
|
|
7
|
+
// src/components/sparkline.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The drawing box. The SVG stretches it to whatever size its class gives, and the stroke keeps
|
|
10
|
+
* its width through `vectorEffect`, so the box's proportions never show.
|
|
11
|
+
*/
|
|
12
|
+
const WIDTH = 100;
|
|
13
|
+
const HEIGHT = 32;
|
|
14
|
+
const AREA = area().x((point) => point.x).y0(HEIGHT).y1((point) => point.y).curve(curveMonotoneX);
|
|
15
|
+
const LINE = line().x((point) => point.x).y((point) => point.y).curve(curveMonotoneX);
|
|
16
|
+
/**
|
|
17
|
+
* A trend at a glance: the smooth gradient area of `TimeSeriesChart` with no axes, grid,
|
|
18
|
+
* tooltip or hover, filling whatever box it is given. Plain SVG rather than a chart, so the
|
|
19
|
+
* pages that list sites never load the chart runtime for it. Purely a picture, so it takes no
|
|
20
|
+
* pointer events and whatever sits under it stays clickable.
|
|
21
|
+
*/
|
|
22
|
+
function Sparkline({ data, color = "var(--color-chart-1)", strokeWidth = 1.5, animated = false, className, ...props }) {
|
|
23
|
+
const gradientId = useId();
|
|
24
|
+
const max = Math.max(...data, 0);
|
|
25
|
+
const last = Math.max(data.length - 1, 1);
|
|
26
|
+
const plotted = data.map((value, index) => ({
|
|
27
|
+
x: index / last * WIDTH,
|
|
28
|
+
y: 31 - value / (max || 1) * 30
|
|
29
|
+
}));
|
|
30
|
+
return /* @__PURE__ */ jsx("div", {
|
|
31
|
+
"aria-hidden": true,
|
|
32
|
+
className: cn("pointer-events-none h-16 w-full", className),
|
|
33
|
+
...props,
|
|
34
|
+
children: /* @__PURE__ */ jsxs("svg", {
|
|
35
|
+
viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
|
|
36
|
+
preserveAspectRatio: "none",
|
|
37
|
+
className: cn("size-full overflow-visible", animated && "animate-wipe-in motion-reduce:animate-none"),
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("linearGradient", {
|
|
40
|
+
id: gradientId,
|
|
41
|
+
x1: "0",
|
|
42
|
+
y1: "0",
|
|
43
|
+
x2: "0",
|
|
44
|
+
y2: "1",
|
|
45
|
+
children: AREA_FADE.map((stop) => /* @__PURE__ */ jsx("stop", {
|
|
46
|
+
offset: stop.offset,
|
|
47
|
+
stopColor: color,
|
|
48
|
+
stopOpacity: stop.opacity
|
|
49
|
+
}, stop.offset))
|
|
50
|
+
}) }),
|
|
51
|
+
/* @__PURE__ */ jsx("path", {
|
|
52
|
+
d: AREA(plotted) ?? void 0,
|
|
53
|
+
fill: `url(#${gradientId})`
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ jsx("path", {
|
|
56
|
+
d: LINE(plotted) ?? void 0,
|
|
57
|
+
fill: "none",
|
|
58
|
+
stroke: color,
|
|
59
|
+
strokeWidth,
|
|
60
|
+
strokeLinecap: "round",
|
|
61
|
+
strokeLinejoin: "round",
|
|
62
|
+
vectorEffect: "non-scaling-stroke"
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export { Sparkline };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=sparkline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparkline.js","names":[],"sources":["../../src/components/sparkline.tsx"],"sourcesContent":["\"use client\"\n\nimport { area, curveMonotoneX, line } from \"d3-shape\"\nimport { type ComponentProps, useId } from \"react\"\nimport { AREA_FADE } from \"../lib/time-series\"\nimport { cn } from \"../lib/variants\"\n\nexport type SparklineProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n /** One figure per step along the line, in order. */\n data: number[]\n /**\n * Series colour; one of the `--color-chart-*` tokens.\n */\n color?: string\n /**\n * Line weight in px.\n */\n strokeWidth?: number\n /**\n * Whether the line wipes in when the element enters the page. Off by default: a line on a\n * page people return to all day would redraw on every visit.\n */\n animated?: boolean\n}\n\n/**\n * The drawing box. The SVG stretches it to whatever size its class gives, and the stroke keeps\n * its width through `vectorEffect`, so the box's proportions never show.\n */\nconst WIDTH = 100\nconst HEIGHT = 32\n/** Half a stroke at the box's top and bottom, so a line at either end is not cut in half. */\nconst INSET = 1\n\ninterface Plotted {\n x: number\n y: number\n}\n\nconst AREA = area<Plotted>()\n .x(point => point.x)\n .y0(HEIGHT)\n .y1(point => point.y)\n .curve(curveMonotoneX)\nconst LINE = line<Plotted>()\n .x(point => point.x)\n .y(point => point.y)\n .curve(curveMonotoneX)\n\n/**\n * A trend at a glance: the smooth gradient area of `TimeSeriesChart` with no axes, grid,\n * tooltip or hover, filling whatever box it is given. Plain SVG rather than a chart, so the\n * pages that list sites never load the chart runtime for it. Purely a picture, so it takes no\n * pointer events and whatever sits under it stays clickable.\n */\nexport function Sparkline({\n data,\n color = \"var(--color-chart-1)\",\n strokeWidth = 1.5,\n animated = false,\n className,\n ...props\n}: SparklineProps) {\n const gradientId = useId()\n const max = Math.max(...data, 0)\n const last = Math.max(data.length - 1, 1)\n const plotted = data.map((value, index) => ({\n x: (index / last) * WIDTH,\n // `||`: an all-zero series still draws its baseline at the bottom, not mid-box.\n // oxlint-disable-next-line typescript/prefer-nullish-coalescing\n y: HEIGHT - INSET - (value / (max || 1)) * (HEIGHT - INSET * 2),\n }))\n\n return (\n <div\n // Decorative: the figures it sketches are printed beside it.\n aria-hidden\n className={cn(\"pointer-events-none h-16 w-full\", className)}\n {...props}\n >\n <svg\n viewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n preserveAspectRatio=\"none\"\n className={cn(\n \"size-full overflow-visible\",\n animated && \"animate-wipe-in motion-reduce:animate-none\",\n )}\n >\n <defs>\n <linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n {AREA_FADE.map(stop => (\n <stop\n key={stop.offset}\n offset={stop.offset}\n stopColor={color}\n stopOpacity={stop.opacity}\n />\n ))}\n </linearGradient>\n </defs>\n <path d={AREA(plotted) ?? undefined} fill={`url(#${gradientId})`} />\n <path\n d={LINE(plotted) ?? undefined}\n fill=\"none\"\n stroke={color}\n strokeWidth={strokeWidth}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n vectorEffect=\"non-scaling-stroke\"\n />\n </svg>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;AA6BA,MAAM,QAAQ;AACd,MAAM,SAAS;AASf,MAAM,OAAO,KAAc,CAAC,CACzB,GAAE,UAAS,MAAM,CAAC,CAAC,CACnB,GAAG,MAAM,CAAC,CACV,IAAG,UAAS,MAAM,CAAC,CAAC,CACpB,MAAM,cAAc;AACvB,MAAM,OAAO,KAAc,CAAC,CACzB,GAAE,UAAS,MAAM,CAAC,CAAC,CACnB,GAAE,UAAS,MAAM,CAAC,CAAC,CACnB,MAAM,cAAc;;;;;;;AAQvB,SAAgB,UAAU,EACxB,MACA,QAAQ,wBACR,cAAc,KACd,WAAW,OACX,WACA,GAAG,SACc;CACjB,MAAM,aAAa,MAAM;CACzB,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC;CAC/B,MAAM,OAAO,KAAK,IAAI,KAAK,SAAS,GAAG,CAAC;CACxC,MAAM,UAAU,KAAK,KAAK,OAAO,WAAW;EAC1C,GAAI,QAAQ,OAAQ;EAGpB,GAAG,KAAkB,SAAS,OAAO,KAAO;CAC9C,EAAE;CAEF,OACE,oBAAC,OAAD;EAEE,eAAA;EACA,WAAW,GAAG,mCAAmC,SAAS;EAC1D,GAAI;EAEJ,UAAA,qBAAC,OAAD;GACE,SAAS,OAAO,MAAM,GAAG;GACzB,qBAAoB;GACpB,WAAW,GACT,8BACA,YAAY,4CACd;GANF,UAAA;IAQE,oBAAC,QAAD,EAAA,UACE,oBAAC,kBAAD;KAAgB,IAAI;KAAY,IAAG;KAAI,IAAG;KAAI,IAAG;KAAI,IAAG;KACrD,UAAA,UAAU,KAAI,SACb,oBAAC,QAAD;MAEE,QAAQ,KAAK;MACb,WAAW;MACX,aAAa,KAAK;KACnB,GAJM,KAAK,MAIX,CACF;IACa,CAAA,EACZ,CAAA;IACN,oBAAC,QAAD;KAAM,GAAG,KAAK,OAAO,KAAK,KAAA;KAAW,MAAM,QAAQ,WAAW;IAAK,CAAA;IACnE,oBAAC,QAAD;KACE,GAAG,KAAK,OAAO,KAAK,KAAA;KACpB,MAAK;KACL,QAAQ;KACK;KACb,eAAc;KACd,gBAAe;KACf,cAAa;IACd,CAAA;GACE;;CACF,CAAA;AAET"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
declare const stackVariants: import("tailwind-variants").TVReturnType<{
|
|
4
|
+
size: {
|
|
5
|
+
xs: string;
|
|
6
|
+
sm: string;
|
|
7
|
+
md: string;
|
|
8
|
+
lg: string;
|
|
9
|
+
};
|
|
10
|
+
direction: {
|
|
11
|
+
row: string;
|
|
12
|
+
column: string;
|
|
13
|
+
};
|
|
14
|
+
wrap: {
|
|
15
|
+
true: string;
|
|
16
|
+
false: string;
|
|
17
|
+
};
|
|
18
|
+
}, undefined, "flex", undefined, undefined, undefined>;
|
|
19
|
+
type StackProps = useRender.ComponentProps<"div"> & VariantProps<typeof stackVariants>;
|
|
20
|
+
declare function Stack({ className, render, size, direction, wrap, ...props }: StackProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
|
+
export { Stack };
|