@repraze/kernelkit 0.1.0-alpha.4 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/alert-dialog.d.ts.map +1 -1
- package/dist/components/alert-dialog.js +4 -1
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/alert.js +3 -3
- package/dist/components/alert.js.map +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/button.js +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.d.ts +8 -1
- package/dist/components/calendar.d.ts.map +1 -1
- package/dist/components/calendar.js +33 -11
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.js +2 -2
- package/dist/components/callout.js.map +1 -1
- package/dist/components/combobox.js +1 -1
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/date-picker.d.ts +11 -5
- package/dist/components/date-picker.d.ts.map +1 -1
- package/dist/components/date-picker.js +29 -7
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/description-list.d.ts +26 -0
- package/dist/components/description-list.d.ts.map +1 -0
- package/dist/components/description-list.js +59 -0
- package/dist/components/description-list.js.map +1 -0
- package/dist/components/locale.d.ts +19 -0
- package/dist/components/locale.d.ts.map +1 -0
- package/dist/components/locale.js +54 -0
- package/dist/components/locale.js.map +1 -0
- package/dist/components/pager.d.ts +1 -1
- package/dist/components/pager.d.ts.map +1 -1
- package/dist/components/pager.js +4 -4
- package/dist/components/pager.js.map +1 -1
- package/dist/components/popover.d.ts +1 -1
- package/dist/components/popover.d.ts.map +1 -1
- package/dist/components/popover.js +2 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/progress.d.ts +19 -6
- package/dist/components/progress.d.ts.map +1 -1
- package/dist/components/progress.js +18 -3
- package/dist/components/progress.js.map +1 -1
- package/dist/components/search-trigger.d.ts +14 -4
- package/dist/components/search-trigger.d.ts.map +1 -1
- package/dist/components/search-trigger.js +25 -4
- package/dist/components/search-trigger.js.map +1 -1
- package/dist/components/shimmer.d.ts +13 -0
- package/dist/components/shimmer.d.ts.map +1 -0
- package/dist/components/shimmer.js +21 -0
- package/dist/components/shimmer.js.map +1 -0
- package/dist/components/spinner.d.ts +28 -6
- package/dist/components/spinner.d.ts.map +1 -1
- package/dist/components/spinner.js +66 -14
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/stepper.d.ts +64 -0
- package/dist/components/stepper.d.ts.map +1 -0
- package/dist/components/stepper.js +167 -0
- package/dist/components/stepper.js.map +1 -0
- package/dist/components/tag-input.d.ts +47 -0
- package/dist/components/tag-input.d.ts.map +1 -0
- package/dist/components/tag-input.js +211 -0
- package/dist/components/tag-input.js.map +1 -0
- package/dist/components/time-input.d.ts +75 -0
- package/dist/components/time-input.d.ts.map +1 -0
- package/dist/components/time-input.js +341 -0
- package/dist/components/time-input.js.map +1 -0
- package/dist/components/time-select.d.ts +49 -0
- package/dist/components/time-select.d.ts.map +1 -0
- package/dist/components/time-select.js +178 -0
- package/dist/components/time-select.js.map +1 -0
- package/dist/components/timeline.d.ts +41 -0
- package/dist/components/timeline.d.ts.map +1 -0
- package/dist/components/timeline.js +83 -0
- package/dist/components/timeline.js.map +1 -0
- package/dist/components/toast.d.ts.map +1 -1
- package/dist/components/toast.js +4 -2
- package/dist/components/toast.js.map +1 -1
- package/dist/components/tree.d.ts +87 -0
- package/dist/components/tree.d.ts.map +1 -0
- package/dist/components/tree.js +516 -0
- package/dist/components/tree.js.map +1 -0
- package/dist/hooks/use-time-format.d.ts +23 -0
- package/dist/hooks/use-time-format.d.ts.map +1 -0
- package/dist/hooks/use-time-format.js +52 -0
- package/dist/hooks/use-time-format.js.map +1 -0
- package/dist/lib/color.d.ts +5 -1
- package/dist/lib/color.d.ts.map +1 -1
- package/dist/lib/color.js +14 -2
- package/dist/lib/color.js.map +1 -1
- package/dist/lib/recipes.d.ts +11 -6
- package/dist/lib/recipes.d.ts.map +1 -1
- package/dist/lib/recipes.js +13 -7
- package/dist/lib/recipes.js.map +1 -1
- package/dist/site/suite-header.d.ts +4 -1
- package/dist/site/suite-header.d.ts.map +1 -1
- package/dist/site/suite-header.js +7 -2
- package/dist/site/suite-header.js.map +1 -1
- package/package.json +1 -1
- package/src/components/alert-dialog.tsx +4 -1
- package/src/components/alert.tsx +3 -3
- package/src/components/badge.tsx +1 -1
- package/src/components/button.tsx +1 -1
- package/src/components/calendar.tsx +48 -4
- package/src/components/callout.tsx +2 -2
- package/src/components/combobox.tsx +1 -1
- package/src/components/date-picker.tsx +43 -9
- package/src/components/description-list.tsx +107 -0
- package/src/components/locale.tsx +67 -0
- package/src/components/pager.tsx +8 -8
- package/src/components/popover.tsx +3 -1
- package/src/components/progress.tsx +70 -4
- package/src/components/search-trigger.tsx +40 -7
- package/src/components/shimmer.tsx +36 -0
- package/src/components/spinner.tsx +126 -23
- package/src/components/stepper.tsx +346 -0
- package/src/components/tag-input.tsx +345 -0
- package/src/components/time-input.tsx +578 -0
- package/src/components/time-select.tsx +291 -0
- package/src/components/timeline.tsx +190 -0
- package/src/components/toast.tsx +4 -4
- package/src/components/tree.tsx +832 -0
- package/src/hooks/use-time-format.ts +72 -0
- package/src/lib/color.ts +19 -2
- package/src/lib/recipes.ts +13 -7
- package/src/site/suite-header.tsx +25 -4
- package/src/styles/kernelkit.css +56 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {cva} from "class-variance-authority";
|
|
4
|
+
import {cn} from "cn";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
|
|
7
|
+
type DescriptionListOrientation = "horizontal" | "vertical";
|
|
8
|
+
|
|
9
|
+
const DescriptionListContext = React.createContext<{orientation: DescriptionListOrientation; divided: boolean}>({
|
|
10
|
+
orientation: "horizontal",
|
|
11
|
+
divided: false,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const descriptionListVariants = cva("text-sm", {
|
|
15
|
+
variants: {
|
|
16
|
+
orientation: {
|
|
17
|
+
// one shared term column: every item is a subgrid row, so terms line up across rows
|
|
18
|
+
horizontal: "grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-6",
|
|
19
|
+
vertical: "flex flex-col",
|
|
20
|
+
},
|
|
21
|
+
divided: {
|
|
22
|
+
true: "",
|
|
23
|
+
false: "",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
compoundVariants: [
|
|
27
|
+
{orientation: "horizontal", divided: false, class: "gap-y-2.5"},
|
|
28
|
+
{orientation: "vertical", divided: false, class: "gap-4"},
|
|
29
|
+
],
|
|
30
|
+
defaultVariants: {orientation: "horizontal", divided: false},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
interface DescriptionListProps extends React.ComponentProps<"dl"> {
|
|
34
|
+
/** `horizontal`: terms in a column beside their details. `vertical`: each term above its details. */
|
|
35
|
+
orientation?: DescriptionListOrientation;
|
|
36
|
+
/** Rule between items. */
|
|
37
|
+
divided?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Key / value pairs: properties of a server, an order, a file. Terms in the label face, details in the body face. */
|
|
41
|
+
function DescriptionList({orientation = "horizontal", divided = false, className, ...props}: DescriptionListProps) {
|
|
42
|
+
const ctx = React.useMemo(() => ({orientation, divided}), [orientation, divided]);
|
|
43
|
+
return (
|
|
44
|
+
<DescriptionListContext.Provider value={ctx}>
|
|
45
|
+
<dl
|
|
46
|
+
data-slot="description-list"
|
|
47
|
+
data-orientation={orientation}
|
|
48
|
+
data-divided={divided ? "" : undefined}
|
|
49
|
+
className={cn(descriptionListVariants({orientation, divided}), className)}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
</DescriptionListContext.Provider>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const descriptionItemVariants = cva("min-w-0", {
|
|
57
|
+
variants: {
|
|
58
|
+
orientation: {
|
|
59
|
+
horizontal: "col-span-2 grid grid-cols-subgrid items-baseline",
|
|
60
|
+
vertical: "flex flex-col gap-1",
|
|
61
|
+
},
|
|
62
|
+
divided: {
|
|
63
|
+
true: "border-b border-border py-2.5 first:pt-0 last:border-b-0 last:pb-0",
|
|
64
|
+
false: "",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
defaultVariants: {orientation: "horizontal", divided: false},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** One term with its details (a `<div>`, which `<dl>` allows around each group). */
|
|
71
|
+
function DescriptionItem({className, ...props}: React.ComponentProps<"div">) {
|
|
72
|
+
const {orientation, divided} = React.useContext(DescriptionListContext);
|
|
73
|
+
return (
|
|
74
|
+
<div
|
|
75
|
+
data-slot="description-item"
|
|
76
|
+
data-orientation={orientation}
|
|
77
|
+
data-divided={divided ? "" : undefined}
|
|
78
|
+
className={cn(descriptionItemVariants({orientation, divided}), className)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function DescriptionTerm({className, ...props}: React.ComponentProps<"dt">) {
|
|
85
|
+
return (
|
|
86
|
+
<dt
|
|
87
|
+
data-slot="description-term"
|
|
88
|
+
className={cn("min-w-0 font-alt text-xs text-muted-foreground", className)}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The value. Inline content (a status dot, a copy button) sits on one row with `flex items-center gap-2`. */
|
|
95
|
+
function DescriptionDetails({className, ...props}: React.ComponentProps<"dd">) {
|
|
96
|
+
return <dd data-slot="description-details" className={cn("min-w-0 text-foreground", className)} {...props} />;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
DescriptionDetails,
|
|
101
|
+
DescriptionItem,
|
|
102
|
+
descriptionItemVariants,
|
|
103
|
+
DescriptionList,
|
|
104
|
+
descriptionListVariants,
|
|
105
|
+
DescriptionTerm,
|
|
106
|
+
};
|
|
107
|
+
export type {DescriptionListOrientation, DescriptionListProps};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Locale for the kit's dates and times (Calendar, DatePicker, TimeInput, TimeSelect), all formatted with
|
|
7
|
+
* `Intl`. Resolution: a component's own `locale` prop › the nearest `LocaleProvider` › the browser's
|
|
8
|
+
* language. Hydration-safe: the server render and the hydration pass use `FALLBACK_LOCALE` (the browser's
|
|
9
|
+
* language is unknown on the server), then the client re-renders with the browser's. To get it right from
|
|
10
|
+
* the first paint in SSR, pass the request's locale (Accept-Language, user setting) to `LocaleProvider`.
|
|
11
|
+
*/
|
|
12
|
+
const FALLBACK_LOCALE = "en-US";
|
|
13
|
+
|
|
14
|
+
const LocaleContext = React.createContext<string | undefined>(undefined);
|
|
15
|
+
|
|
16
|
+
function LocaleProvider({locale, children}: {locale?: string; children: React.ReactNode}) {
|
|
17
|
+
return <LocaleContext.Provider value={locale}>{children}</LocaleContext.Provider>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function browserLocale(): string | null {
|
|
21
|
+
try {
|
|
22
|
+
const tag = navigator.languages?.[0] ?? navigator.language;
|
|
23
|
+
return tag && Intl.DateTimeFormat.supportedLocalesOf(tag).length ? tag : null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function subscribe(onChange: () => void) {
|
|
30
|
+
window.addEventListener("languagechange", onChange);
|
|
31
|
+
return () => window.removeEventListener("languagechange", onChange);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The locale to format with: `explicit` › LocaleProvider › browser (after hydration) › `FALLBACK_LOCALE`. */
|
|
35
|
+
function useLocale(explicit?: string): string {
|
|
36
|
+
const provided = React.useContext(LocaleContext);
|
|
37
|
+
const browser = React.useSyncExternalStore(subscribe, browserLocale, () => null);
|
|
38
|
+
return explicit ?? provided ?? browser ?? FALLBACK_LOCALE;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Regions whose week starts on Sunday or Saturday (CLDR), for engines without Intl.Locale#getWeekInfo.
|
|
42
|
+
const SUNDAY = new Set(
|
|
43
|
+
"AG AS AU BD BR BS BT BW BZ CA CN CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW".split(
|
|
44
|
+
" ",
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const SATURDAY = new Set("AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY".split(" "));
|
|
48
|
+
|
|
49
|
+
/** First day of the week for a locale: 0 Sunday … 6 Saturday. */
|
|
50
|
+
function weekStart(locale: string): 0 | 1 | 6 {
|
|
51
|
+
try {
|
|
52
|
+
const loc = new Intl.Locale(locale) as Intl.Locale & {
|
|
53
|
+
getWeekInfo?: () => {firstDay: number};
|
|
54
|
+
weekInfo?: {firstDay: number};
|
|
55
|
+
};
|
|
56
|
+
const info = loc.getWeekInfo?.() ?? loc.weekInfo;
|
|
57
|
+
if (info) {
|
|
58
|
+
return (info.firstDay % 7) as 0 | 1 | 6;
|
|
59
|
+
}
|
|
60
|
+
const region = loc.maximize().region ?? "";
|
|
61
|
+
return SUNDAY.has(region) ? 0 : SATURDAY.has(region) ? 6 : 1;
|
|
62
|
+
} catch {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export {FALLBACK_LOCALE, LocaleProvider, useLocale, weekStart};
|
package/src/components/pager.tsx
CHANGED
|
@@ -7,14 +7,14 @@ import {cn} from "cn";
|
|
|
7
7
|
import {ArrowLeftIcon, ArrowRightIcon} from "lucide-react";
|
|
8
8
|
import type * as React from "react";
|
|
9
9
|
|
|
10
|
-
/** Previous / next page links at the end of a page
|
|
10
|
+
/** Previous / next page links at the end of a page: stacked on phones, side by side from `sm`. */
|
|
11
11
|
function Pager({className, render, ...props}: useRender.ComponentProps<"nav">) {
|
|
12
12
|
return useRender({
|
|
13
13
|
defaultTagName: "nav",
|
|
14
14
|
props: mergeProps<"nav">(
|
|
15
15
|
{
|
|
16
16
|
"aria-label": "Pages",
|
|
17
|
-
className: cn("grid
|
|
17
|
+
className: cn("grid gap-3 border-t border-border pt-6 sm:grid-cols-2 sm:gap-4", className),
|
|
18
18
|
},
|
|
19
19
|
props,
|
|
20
20
|
),
|
|
@@ -39,21 +39,21 @@ function PagerLink({className, render, direction, label, children, ...props}: Pa
|
|
|
39
39
|
{
|
|
40
40
|
rel: next ? "next" : "prev",
|
|
41
41
|
className: cn(
|
|
42
|
-
"group/pager flex flex-col gap-1 rounded-lg border border-border px-4 py-3 transition-colors hover:border-primary-text hover:bg-hover",
|
|
42
|
+
"group/pager flex min-w-0 flex-col gap-1 rounded-lg border border-border px-4 py-3 transition-colors hover:border-primary-text hover:bg-hover",
|
|
43
43
|
focusRing,
|
|
44
|
-
next ? "
|
|
44
|
+
next ? "items-end text-end sm:col-start-2" : "items-start sm:col-start-1",
|
|
45
45
|
className,
|
|
46
46
|
),
|
|
47
47
|
children: (
|
|
48
48
|
<>
|
|
49
49
|
<span className="text-xs text-muted-foreground">{label ?? (next ? "Next" : "Previous")}</span>
|
|
50
|
-
<span className="flex items-center gap-1.5 font-medium">
|
|
50
|
+
<span className="flex max-w-full items-center gap-1.5 font-medium">
|
|
51
51
|
{!next && (
|
|
52
|
-
<Arrow className="size-4 transition-transform group-hover/pager:-translate-x-0.5" />
|
|
52
|
+
<Arrow className="size-4 shrink-0 transition-transform group-hover/pager:-translate-x-0.5" />
|
|
53
53
|
)}
|
|
54
|
-
{children}
|
|
54
|
+
<span className="min-w-0 wrap-break-word">{children}</span>
|
|
55
55
|
{next && (
|
|
56
|
-
<Arrow className="size-4 transition-transform group-hover/pager:translate-x-0.5" />
|
|
56
|
+
<Arrow className="size-4 shrink-0 transition-transform group-hover/pager:translate-x-0.5" />
|
|
57
57
|
)}
|
|
58
58
|
</span>
|
|
59
59
|
</>
|
|
@@ -20,9 +20,10 @@ function PopoverContent({
|
|
|
20
20
|
alignOffset = 0,
|
|
21
21
|
side = "bottom",
|
|
22
22
|
sideOffset = 4,
|
|
23
|
+
anchor,
|
|
23
24
|
...props
|
|
24
25
|
}: PopoverPrimitive.Popup.Props &
|
|
25
|
-
Pick<PopoverPrimitive.Positioner.Props, "align" | "alignOffset" | "side" | "sideOffset">) {
|
|
26
|
+
Pick<PopoverPrimitive.Positioner.Props, "align" | "alignOffset" | "side" | "sideOffset" | "anchor">) {
|
|
26
27
|
return (
|
|
27
28
|
<PopoverPrimitive.Portal container={usePortalContainer()}>
|
|
28
29
|
<PopoverPrimitive.Positioner
|
|
@@ -30,6 +31,7 @@ function PopoverContent({
|
|
|
30
31
|
alignOffset={alignOffset}
|
|
31
32
|
side={side}
|
|
32
33
|
sideOffset={sideOffset}
|
|
34
|
+
anchor={anchor}
|
|
33
35
|
className="isolate z-50"
|
|
34
36
|
>
|
|
35
37
|
<PopoverPrimitive.Popup
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import {Progress as ProgressPrimitive} from "@base-ui/react/progress";
|
|
4
4
|
import {type Color, colorVariants} from "@repraze/kernelkit/lib/color";
|
|
5
|
+
import {placeholderFill} from "@repraze/kernelkit/lib/recipes";
|
|
5
6
|
import {cva} from "class-variance-authority";
|
|
6
7
|
import {cn} from "cn";
|
|
8
|
+
import type * as React from "react";
|
|
7
9
|
|
|
8
10
|
/** Root of a progress or meter: label + value on one row, track below. Sets the color vars. */
|
|
9
11
|
const progressVariants = cva("group/progress flex w-full flex-wrap items-center gap-x-3 gap-y-1.5", {
|
|
@@ -29,24 +31,44 @@ interface ProgressProps extends Omit<ProgressPrimitive.Root.Props, "color"> {
|
|
|
29
31
|
color?: Color | null;
|
|
30
32
|
/** Track height: sm `h-1`, default `h-1.5`, lg `h-2`. */
|
|
31
33
|
size?: ProgressSize | null;
|
|
34
|
+
/** `bar`: one pill track. `segmented`: a row of cells, lit in order; a wave runs through them while indeterminate. */
|
|
35
|
+
variant?: "bar" | "segmented";
|
|
36
|
+
/** `segmented` only: number of cells. */
|
|
37
|
+
segments?: number;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
function Progress({
|
|
40
|
+
function Progress({
|
|
41
|
+
className,
|
|
42
|
+
children,
|
|
43
|
+
value,
|
|
44
|
+
color,
|
|
45
|
+
size,
|
|
46
|
+
variant = "bar",
|
|
47
|
+
segments = 12,
|
|
48
|
+
max = 100,
|
|
49
|
+
...props
|
|
50
|
+
}: ProgressProps) {
|
|
35
51
|
const resolvedColor = color ?? "primary";
|
|
36
52
|
const resolvedSize = size ?? "default";
|
|
37
53
|
return (
|
|
38
54
|
<ProgressPrimitive.Root
|
|
39
55
|
value={value}
|
|
56
|
+
max={max}
|
|
40
57
|
data-slot="progress"
|
|
58
|
+
data-variant={variant}
|
|
41
59
|
data-color={resolvedColor}
|
|
42
60
|
data-size={resolvedSize}
|
|
43
61
|
className={cn(progressVariants({color: resolvedColor, size: resolvedSize}), className)}
|
|
44
62
|
{...props}
|
|
45
63
|
>
|
|
46
64
|
{children}
|
|
47
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
65
|
+
{variant === "segmented" ? (
|
|
66
|
+
<ProgressSegments segments={segments} lit={value == null ? null : (value / max) * segments} />
|
|
67
|
+
) : (
|
|
68
|
+
<ProgressTrack>
|
|
69
|
+
<ProgressIndicator />
|
|
70
|
+
</ProgressTrack>
|
|
71
|
+
)}
|
|
50
72
|
</ProgressPrimitive.Root>
|
|
51
73
|
);
|
|
52
74
|
}
|
|
@@ -72,6 +94,49 @@ function ProgressIndicator({className, ...props}: ProgressPrimitive.Indicator.Pr
|
|
|
72
94
|
);
|
|
73
95
|
}
|
|
74
96
|
|
|
97
|
+
/** Negative delays so every cell is mid-cycle on the first frame (no dead start). */
|
|
98
|
+
const cellDelay = (i: number, n: number) => ({animationDelay: `${-((n - i) * 1.2) / n}s`});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The `segmented` track: cells in the fill tier, unlit ones on the placeholder fill (§4). `lit` is how many
|
|
102
|
+
* cells are on (fractional rounds), `null` runs the indeterminate wave. Reduced motion slows the wave down.
|
|
103
|
+
*/
|
|
104
|
+
function ProgressSegments({
|
|
105
|
+
segments,
|
|
106
|
+
lit,
|
|
107
|
+
className,
|
|
108
|
+
...props
|
|
109
|
+
}: React.ComponentProps<"div"> & {segments: number; lit: number | null}) {
|
|
110
|
+
const on = lit === null ? -1 : Math.round(Math.min(segments, Math.max(0, lit)));
|
|
111
|
+
return (
|
|
112
|
+
<div
|
|
113
|
+
data-slot="progress-segments"
|
|
114
|
+
aria-hidden
|
|
115
|
+
className={cn(
|
|
116
|
+
"flex h-1.5 w-full gap-0.5 group-data-[size=lg]/progress:h-2 group-data-[size=sm]/progress:h-1",
|
|
117
|
+
className,
|
|
118
|
+
)}
|
|
119
|
+
{...props}
|
|
120
|
+
>
|
|
121
|
+
{Array.from({length: segments}, (_, i) => (
|
|
122
|
+
<span
|
|
123
|
+
key={i}
|
|
124
|
+
data-lit={on < 0 || i < on ? "" : undefined}
|
|
125
|
+
className={cn(
|
|
126
|
+
"h-full flex-1 rounded-xs transition-colors duration-300 motion-reduce:transition-none",
|
|
127
|
+
on < 0
|
|
128
|
+
? "animate-loader-cell bg-(--c-fill) motion-reduce:[animation-duration:3s]"
|
|
129
|
+
: i < on
|
|
130
|
+
? "bg-(--c-fill)"
|
|
131
|
+
: placeholderFill,
|
|
132
|
+
)}
|
|
133
|
+
style={on < 0 ? cellDelay(i, segments) : undefined}
|
|
134
|
+
/>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
75
140
|
function ProgressLabel({className, ...props}: ProgressPrimitive.Label.Props) {
|
|
76
141
|
return (
|
|
77
142
|
<ProgressPrimitive.Label
|
|
@@ -97,6 +162,7 @@ export {
|
|
|
97
162
|
ProgressIndicator,
|
|
98
163
|
progressIndicatorClass,
|
|
99
164
|
ProgressLabel,
|
|
165
|
+
ProgressSegments,
|
|
100
166
|
ProgressTrack,
|
|
101
167
|
progressTrackClass,
|
|
102
168
|
ProgressValue,
|
|
@@ -49,25 +49,58 @@ function useSearchHotkeys(onOpen: (toggle: boolean) => void, {enabled = true}: {
|
|
|
49
49
|
interface SearchTriggerProps extends React.ComponentProps<typeof Button> {
|
|
50
50
|
/** Placeholder text. */
|
|
51
51
|
children?: React.ReactNode;
|
|
52
|
+
/** Full width with its placeholder at every size (a phone menu); otherwise an icon below `sm`. */
|
|
53
|
+
expanded?: boolean;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
type SearchHandler = React.MouseEventHandler<HTMLButtonElement>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Lets a shell open the page's search from another place (SuiteHeader's phone menu) without a second
|
|
60
|
+
* dialog: a SearchTrigger inside `SearchRelay` hands its `onClick` to the relay's ref.
|
|
61
|
+
*/
|
|
62
|
+
const SearchRelayContext = React.createContext<React.RefObject<SearchHandler | null> | null>(null);
|
|
63
|
+
|
|
64
|
+
function SearchRelay({handler, children}: {handler: React.RefObject<SearchHandler | null>; children: React.ReactNode}) {
|
|
65
|
+
return <SearchRelayContext.Provider value={handler}>{children}</SearchRelayContext.Provider>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Header search button: icon, placeholder, OS-aware shortcut. Same 32px height as the header's icon buttons. Open your dialog in `onClick`.
|
|
70
|
+
* The keycap gets the same inset on the right as top/bottom (32 - 20 = 6px each side, border included).
|
|
71
|
+
*/
|
|
72
|
+
function SearchTrigger({children = "Search…", expanded = false, className, onClick, ...props}: SearchTriggerProps) {
|
|
56
73
|
const mod = useModKey();
|
|
74
|
+
const relay = React.useContext(SearchRelayContext);
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
if (!relay) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
relay.current = onClick ?? null;
|
|
80
|
+
return () => {
|
|
81
|
+
relay.current = null;
|
|
82
|
+
};
|
|
83
|
+
}, [relay, onClick]);
|
|
57
84
|
return (
|
|
58
85
|
<Button
|
|
59
86
|
variant="outline"
|
|
60
87
|
aria-label="Search"
|
|
61
88
|
data-slot="search-trigger"
|
|
62
|
-
|
|
89
|
+
data-expanded={expanded || undefined}
|
|
90
|
+
className={cn(
|
|
91
|
+
"justify-start text-muted-foreground",
|
|
92
|
+
expanded ? "w-full pr-1.25 pl-2.5" : "w-8 px-0 sm:w-40 sm:pr-1.25 sm:pl-2.5 lg:w-56",
|
|
93
|
+
className,
|
|
94
|
+
)}
|
|
95
|
+
onClick={onClick}
|
|
63
96
|
{...props}
|
|
64
97
|
>
|
|
65
|
-
<SearchIcon data-icon="inline-start" className="mx-auto sm:mx-0" />
|
|
66
|
-
<span className="
|
|
98
|
+
<SearchIcon data-icon="inline-start" className={expanded ? undefined : "mx-auto sm:mx-0"} />
|
|
99
|
+
<span className={cn("flex-1 truncate text-start", !expanded && "hidden sm:inline")}>{children}</span>
|
|
67
100
|
<Kbd className="hidden sm:inline-flex">{mod} K</Kbd>
|
|
68
101
|
</Button>
|
|
69
102
|
);
|
|
70
103
|
}
|
|
71
104
|
|
|
72
|
-
export {SearchTrigger, useModKey, useSearchHotkeys};
|
|
73
|
-
export type {SearchTriggerProps};
|
|
105
|
+
export {SearchRelay, SearchTrigger, useModKey, useSearchHotkeys};
|
|
106
|
+
export type {SearchHandler, SearchTriggerProps};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {mergeProps} from "@base-ui/react/merge-props";
|
|
4
|
+
import {useRender} from "@base-ui/react/use-render";
|
|
5
|
+
import {cn} from "cn";
|
|
6
|
+
|
|
7
|
+
interface ShimmerProps extends useRender.ComponentProps<"span"> {
|
|
8
|
+
/** Seconds per sweep. */
|
|
9
|
+
duration?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Text with a highlight band sweeping across it ("Thinking…", "Indexing files…"). Muted text, foreground
|
|
14
|
+
* band. Reduced motion: plain muted text.
|
|
15
|
+
*/
|
|
16
|
+
function Shimmer({render, duration, className, style, ...props}: ShimmerProps) {
|
|
17
|
+
return useRender({
|
|
18
|
+
defaultTagName: "span",
|
|
19
|
+
props: mergeProps<"span">(
|
|
20
|
+
{
|
|
21
|
+
className: cn(
|
|
22
|
+
"inline-block animate-shimmer bg-linear-to-r from-muted-foreground from-40% via-foreground via-50% to-muted-foreground to-60% bg-size-[250%_100%] bg-clip-text text-transparent",
|
|
23
|
+
"motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-muted-foreground",
|
|
24
|
+
className,
|
|
25
|
+
),
|
|
26
|
+
style: duration ? {animationDuration: `${duration}s`, ...style} : style,
|
|
27
|
+
},
|
|
28
|
+
props,
|
|
29
|
+
),
|
|
30
|
+
render,
|
|
31
|
+
state: {slot: "shimmer"},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {Shimmer};
|
|
36
|
+
export type {ShimmerProps};
|
|
@@ -1,42 +1,145 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import {type Color, colorVariants} from "@repraze/kernelkit/lib/color";
|
|
4
|
+
import {placeholderFill} from "@repraze/kernelkit/lib/recipes";
|
|
3
5
|
import {cva, type VariantProps} from "class-variance-authority";
|
|
4
6
|
import {cn} from "cn";
|
|
5
7
|
import {Loader2Icon} from "lucide-react";
|
|
8
|
+
import * as React from "react";
|
|
6
9
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Sizes follow the icon column of §4 so a spinner can replace an icon in place. Each size also sets the
|
|
12
|
+
* vars the techy variants draw with: `--ls` (box), `--lc`/`--lg` (dot cell and gap, whole pixels so cells
|
|
13
|
+
* stay crisp) and `--lb` (bar width).
|
|
14
|
+
*/
|
|
15
|
+
const spinnerVariants = cva("relative inline-flex shrink-0 items-center justify-center align-middle text-current", {
|
|
16
|
+
variants: {
|
|
17
|
+
variant: {
|
|
18
|
+
// reduced motion: slow the spin down rather than freeze it, a frozen spinner reads as a glyph
|
|
19
|
+
ring: "size-(--ls) animate-spin motion-reduce:[animation-duration:2.5s]",
|
|
20
|
+
dots: "size-(--ls)",
|
|
21
|
+
braille: "h-(--ls) w-(--ls) items-start overflow-hidden font-mono text-(length:--ls) leading-none",
|
|
22
|
+
// hc: the placeholder fill is the dark border colour there, so the box becomes an outline instead
|
|
23
|
+
scan: `size-(--ls) overflow-hidden rounded-box ${placeholderFill} hc:bg-transparent hc:shadow-[inset_0_0_0_1px_var(--border)]`,
|
|
24
|
+
blink: "h-(--ls) w-[calc(var(--ls)/2)]",
|
|
25
|
+
bars: "size-(--ls) justify-between",
|
|
26
|
+
},
|
|
27
|
+
size: {
|
|
28
|
+
xs: "[--lb:2px] [--lc:3px] [--lg:1px] [--ls:0.75rem]",
|
|
29
|
+
sm: "[--lb:2px] [--lc:4px] [--lg:1px] [--ls:0.875rem]",
|
|
30
|
+
default: "[--lb:3px] [--lc:4px] [--lg:2px] [--ls:1rem]",
|
|
31
|
+
lg: "[--lb:3px] [--lc:6px] [--lg:1px] [--ls:1.25rem]",
|
|
32
|
+
xl: "[--lb:4px] [--lc:6px] [--lg:3px] [--ls:1.5rem]",
|
|
20
33
|
},
|
|
21
|
-
defaultVariants: {size: "default"},
|
|
22
34
|
},
|
|
23
|
-
|
|
35
|
+
defaultVariants: {variant: "ring", size: "default"},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
type SpinnerVariant = NonNullable<VariantProps<typeof spinnerVariants>["variant"]>;
|
|
39
|
+
|
|
40
|
+
/** Every animated part: slower, not frozen, under reduced motion. */
|
|
41
|
+
const slow = "motion-reduce:[animation-duration:3s]";
|
|
24
42
|
|
|
25
|
-
|
|
43
|
+
const BRAILLE = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
|
|
44
|
+
|
|
45
|
+
/** Negative delays so every cell is mid-cycle on the first frame (no dead start). */
|
|
46
|
+
const delay = (i: number, n: number, duration: number) => ({animationDelay: `${-((n - i) * duration) / n}s`});
|
|
47
|
+
|
|
48
|
+
function SpinnerParts({variant}: {variant: SpinnerVariant}) {
|
|
49
|
+
switch (variant) {
|
|
50
|
+
case "ring":
|
|
51
|
+
return <Loader2Icon aria-hidden className="size-full" />;
|
|
52
|
+
case "dots":
|
|
53
|
+
return (
|
|
54
|
+
<span
|
|
55
|
+
data-slot="spinner-grid"
|
|
56
|
+
className="grid grid-cols-[repeat(3,var(--lc))] grid-rows-[repeat(3,var(--lc))] gap-(--lg)"
|
|
57
|
+
>
|
|
58
|
+
{Array.from({length: 9}, (_, i) => (
|
|
59
|
+
<span
|
|
60
|
+
key={i}
|
|
61
|
+
className={cn("animate-loader-cell rounded-pill bg-current", slow)}
|
|
62
|
+
// diagonal wave from the top-left corner
|
|
63
|
+
style={delay(4 - (Math.floor(i / 3) + (i % 3)), 5, 1.2)}
|
|
64
|
+
/>
|
|
65
|
+
))}
|
|
66
|
+
</span>
|
|
67
|
+
);
|
|
68
|
+
case "braille":
|
|
69
|
+
return (
|
|
70
|
+
<span aria-hidden className={cn("flex animate-loader-braille flex-col", slow)}>
|
|
71
|
+
{[...BRAILLE].map((g) => (
|
|
72
|
+
<span key={g} className="h-(--ls) leading-(--ls)">
|
|
73
|
+
{g}
|
|
74
|
+
</span>
|
|
75
|
+
))}
|
|
76
|
+
</span>
|
|
77
|
+
);
|
|
78
|
+
case "scan":
|
|
79
|
+
return (
|
|
80
|
+
<span
|
|
81
|
+
className={cn(
|
|
82
|
+
"absolute inset-0 animate-loader-scan border-e-2 border-current bg-linear-to-r from-transparent to-current/40",
|
|
83
|
+
slow,
|
|
84
|
+
)}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
case "blink":
|
|
88
|
+
return <span className={cn("size-full animate-loader-blink bg-current", slow)} />;
|
|
89
|
+
case "bars":
|
|
90
|
+
return Array.from({length: 4}, (_, i) => (
|
|
91
|
+
<span
|
|
92
|
+
key={i}
|
|
93
|
+
className={cn("h-full w-(--lb) origin-bottom animate-loader-bars rounded-box bg-current", slow)}
|
|
94
|
+
style={delay((i * 2 + Math.floor(i / 2)) % 4, 4, 0.9)}
|
|
95
|
+
/>
|
|
96
|
+
));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const SpinnerContext = React.createContext<SpinnerVariant>("ring");
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Sets the default `variant` of every Spinner below it, including the ones the kit renders itself
|
|
104
|
+
* (tree lazy rows, stepper, file upload, toasts): one switch for the whole app's loading look.
|
|
105
|
+
*/
|
|
106
|
+
function SpinnerProvider({variant, children}: {variant: SpinnerVariant; children: React.ReactNode}) {
|
|
107
|
+
return <SpinnerContext.Provider value={variant}>{children}</SpinnerContext.Provider>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface SpinnerProps
|
|
111
|
+
extends Omit<React.ComponentProps<"span">, "color" | "children">, VariantProps<typeof spinnerVariants> {
|
|
112
|
+
/** Color from the §2 axis; defaults to `currentColor`. */
|
|
113
|
+
color?: Color;
|
|
114
|
+
}
|
|
26
115
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Indeterminate loading indicator at icon size: a spinning ring, or a techy variant (dot matrix, braille,
|
|
118
|
+
* scan line, block cursor, equalizer bars). Inherits `currentColor`; announces itself as a status. The
|
|
119
|
+
* default variant comes from the nearest `SpinnerProvider`.
|
|
120
|
+
*/
|
|
121
|
+
function Spinner({variant, size, color, className, ...props}: SpinnerProps) {
|
|
122
|
+
const fallback = React.useContext(SpinnerContext);
|
|
123
|
+
const resolved = variant ?? fallback;
|
|
29
124
|
return (
|
|
30
|
-
<
|
|
125
|
+
<span
|
|
31
126
|
data-slot="spinner"
|
|
127
|
+
data-variant={resolved}
|
|
32
128
|
data-size={size ?? "default"}
|
|
129
|
+
data-color={color}
|
|
33
130
|
role="status"
|
|
34
131
|
aria-label="Loading"
|
|
35
|
-
className={cn(
|
|
132
|
+
className={cn(
|
|
133
|
+
spinnerVariants({variant: resolved, size}),
|
|
134
|
+
color && cn(colorVariants[color], "text-(--c)"),
|
|
135
|
+
className,
|
|
136
|
+
)}
|
|
36
137
|
{...props}
|
|
37
|
-
|
|
138
|
+
>
|
|
139
|
+
<SpinnerParts variant={resolved} />
|
|
140
|
+
</span>
|
|
38
141
|
);
|
|
39
142
|
}
|
|
40
143
|
|
|
41
|
-
export {Spinner, spinnerVariants};
|
|
42
|
-
export type {SpinnerProps};
|
|
144
|
+
export {Spinner, SpinnerProvider, spinnerVariants};
|
|
145
|
+
export type {SpinnerProps, SpinnerVariant};
|