@boriaui/react 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/components/alert-dialog.d.ts +29 -0
- package/dist/components/alert-dialog.js +62 -0
- package/dist/components/alert.d.ts +12 -0
- package/dist/components/alert.js +35 -0
- package/dist/components/autosize-textarea.d.ts +26 -0
- package/dist/components/autosize-textarea.js +66 -0
- package/dist/components/avatar.d.ts +9 -0
- package/dist/components/avatar.js +30 -0
- package/dist/components/badge.d.ts +16 -0
- package/dist/components/badge.js +24 -0
- package/dist/components/breadcrumb.d.ts +29 -0
- package/dist/components/breadcrumb.js +64 -0
- package/dist/components/button.d.ts +15 -0
- package/dist/components/button.js +45 -0
- package/dist/components/calendar.d.ts +25 -0
- package/dist/components/calendar.js +109 -0
- package/dist/components/card.d.ts +11 -0
- package/dist/components/card.js +44 -0
- package/dist/components/checkbox.d.ts +20 -0
- package/dist/components/checkbox.js +29 -0
- package/dist/components/collapsible.d.ts +9 -0
- package/dist/components/collapsible.js +12 -0
- package/dist/components/command.d.ts +89 -0
- package/dist/components/command.js +79 -0
- package/dist/components/context-menu.d.ts +36 -0
- package/dist/components/context-menu.js +136 -0
- package/dist/components/dialog.d.ts +31 -0
- package/dist/components/dialog.js +58 -0
- package/dist/components/dropdown-menu.d.ts +33 -0
- package/dist/components/dropdown-menu.js +85 -0
- package/dist/components/empty.d.ts +35 -0
- package/dist/components/empty.js +61 -0
- package/dist/components/field.d.ts +64 -0
- package/dist/components/field.js +121 -0
- package/dist/components/hover-card.d.ts +9 -0
- package/dist/components/hover-card.js +25 -0
- package/dist/components/input-group.d.ts +42 -0
- package/dist/components/input-group.js +83 -0
- package/dist/components/input.d.ts +6 -0
- package/dist/components/input.js +17 -0
- package/dist/components/item.d.ts +61 -0
- package/dist/components/item.js +118 -0
- package/dist/components/kbd.d.ts +13 -0
- package/dist/components/kbd.js +21 -0
- package/dist/components/label.d.ts +7 -0
- package/dist/components/label.js +18 -0
- package/dist/components/popover.d.ts +10 -0
- package/dist/components/popover.js +23 -0
- package/dist/components/radio-group.d.ts +14 -0
- package/dist/components/radio-group.js +39 -0
- package/dist/components/resizable.d.ts +34 -0
- package/dist/components/resizable.js +25 -0
- package/dist/components/scroll-area.d.ts +11 -0
- package/dist/components/scroll-area.js +35 -0
- package/dist/components/select.d.ts +16 -0
- package/dist/components/select.js +77 -0
- package/dist/components/separator.d.ts +7 -0
- package/dist/components/separator.js +20 -0
- package/dist/components/sheet.d.ts +34 -0
- package/dist/components/sheet.js +68 -0
- package/dist/components/sidebar.d.ts +72 -0
- package/dist/components/sidebar.js +382 -0
- package/dist/components/skeleton.d.ts +9 -0
- package/dist/components/skeleton.js +13 -0
- package/dist/components/spinner.d.ts +9 -0
- package/dist/components/spinner.js +16 -0
- package/dist/components/switch.d.ts +28 -0
- package/dist/components/switch.js +31 -0
- package/dist/components/tabs.d.ts +10 -0
- package/dist/components/tabs.js +31 -0
- package/dist/components/textarea.d.ts +6 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/toaster.d.ts +10 -0
- package/dist/components/toaster.js +19 -0
- package/dist/components/toggle-group.d.ts +16 -0
- package/dist/components/toggle-group.js +43 -0
- package/dist/components/toggle.d.ts +16 -0
- package/dist/components/toggle.js +40 -0
- package/dist/components/tooltip.d.ts +10 -0
- package/dist/components/tooltip.js +22 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/use-media-query.d.ts +8 -0
- package/dist/hooks/use-media-query.js +20 -0
- package/dist/hooks/use-mobile.d.ts +4 -0
- package/dist/hooks/use-mobile.js +20 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/keyboard-guards.d.ts +11 -0
- package/dist/lib/keyboard-guards.js +21 -0
- package/dist/lib/utils.d.ts +6 -0
- package/dist/lib/utils.js +10 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +4 -0
- package/dist/theme/theme-options.d.ts +16 -0
- package/dist/theme/theme-options.js +25 -0
- package/dist/theme/theme-provider.d.ts +50 -0
- package/dist/theme/theme-provider.js +94 -0
- package/package.json +124 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
8
|
+
|
|
9
|
+
//#region src/components/tabs.tsx
|
|
10
|
+
const Tabs = TabsPrimitive.Root;
|
|
11
|
+
const TabsList = React.forwardRef(({ className,...props }, ref) => /* @__PURE__ */ jsx(TabsPrimitive.List, {
|
|
12
|
+
ref,
|
|
13
|
+
className: cn("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground", className),
|
|
14
|
+
...props
|
|
15
|
+
}));
|
|
16
|
+
TabsList.displayName = TabsPrimitive.List.displayName;
|
|
17
|
+
const TabsTrigger = React.forwardRef(({ className,...props }, ref) => /* @__PURE__ */ jsx(TabsPrimitive.Trigger, {
|
|
18
|
+
ref,
|
|
19
|
+
className: cn("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm", className),
|
|
20
|
+
...props
|
|
21
|
+
}));
|
|
22
|
+
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
|
|
23
|
+
const TabsContent = React.forwardRef(({ className,...props }, ref) => /* @__PURE__ */ jsx(TabsPrimitive.Content, {
|
|
24
|
+
ref,
|
|
25
|
+
className: cn("mt-2 ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", className),
|
|
26
|
+
...props
|
|
27
|
+
}));
|
|
28
|
+
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Tabs, TabsContent, TabsList, TabsTrigger };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/components/textarea.d.ts
|
|
4
|
+
declare const Textarea: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { Textarea };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cn } from "../lib/utils.js";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/components/textarea.tsx
|
|
6
|
+
const Textarea = React.forwardRef(({ className,...props }, ref) => {
|
|
7
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
8
|
+
className: cn("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", className),
|
|
9
|
+
ref,
|
|
10
|
+
...props
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
Textarea.displayName = "Textarea";
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Textarea };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as react29 from "react";
|
|
2
|
+
import { Toaster as Toaster$1 } from "sonner";
|
|
3
|
+
|
|
4
|
+
//#region src/components/toaster.d.ts
|
|
5
|
+
type ToasterProps = React.ComponentProps<typeof Toaster$1>;
|
|
6
|
+
declare const Toaster: ({
|
|
7
|
+
...props
|
|
8
|
+
}: ToasterProps) => react29.JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Toaster };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Toaster as Toaster$1 } from "sonner";
|
|
3
|
+
|
|
4
|
+
//#region src/components/toaster.tsx
|
|
5
|
+
const Toaster = ({ ...props }) => {
|
|
6
|
+
return /* @__PURE__ */ jsx(Toaster$1, {
|
|
7
|
+
className: "toaster group",
|
|
8
|
+
toastOptions: { classNames: {
|
|
9
|
+
toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
|
10
|
+
description: "group-[.toast]:text-muted-foreground",
|
|
11
|
+
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
|
12
|
+
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"
|
|
13
|
+
} },
|
|
14
|
+
...props
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Toaster };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { VariantProps } from "class-variance-authority";
|
|
3
|
+
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
|
4
|
+
import * as class_variance_authority_types8 from "class-variance-authority/types";
|
|
5
|
+
|
|
6
|
+
//#region src/components/toggle-group.d.ts
|
|
7
|
+
declare const ToggleGroup: React.ForwardRefExoticComponent<((Omit<ToggleGroupPrimitive.ToggleGroupSingleProps & React.RefAttributes<HTMLDivElement>, "ref"> | Omit<ToggleGroupPrimitive.ToggleGroupMultipleProps & React.RefAttributes<HTMLDivElement>, "ref">) & VariantProps<(props?: ({
|
|
8
|
+
variant?: "default" | "outline" | null | undefined;
|
|
9
|
+
size?: "default" | "sm" | "lg" | null | undefined;
|
|
10
|
+
} & class_variance_authority_types8.ClassProp) | undefined) => string>) & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
declare const ToggleGroupItem: React.ForwardRefExoticComponent<Omit<ToggleGroupPrimitive.ToggleGroupItemProps & React.RefAttributes<HTMLButtonElement>, "ref"> & VariantProps<(props?: ({
|
|
12
|
+
variant?: "default" | "outline" | null | undefined;
|
|
13
|
+
size?: "default" | "sm" | "lg" | null | undefined;
|
|
14
|
+
} & class_variance_authority_types8.ClassProp) | undefined) => string> & React.RefAttributes<HTMLButtonElement>>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ToggleGroup, ToggleGroupItem };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import { toggleVariants } from "./toggle.js";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
|
9
|
+
|
|
10
|
+
//#region src/components/toggle-group.tsx
|
|
11
|
+
const ToggleGroupContext = React.createContext({
|
|
12
|
+
size: "default",
|
|
13
|
+
variant: "default"
|
|
14
|
+
});
|
|
15
|
+
const ToggleGroup = React.forwardRef(({ className, variant, size, children,...props }, ref) => /* @__PURE__ */ jsx(ToggleGroupPrimitive.Root, {
|
|
16
|
+
ref,
|
|
17
|
+
className: cn("flex items-center justify-center gap-1", className),
|
|
18
|
+
...props,
|
|
19
|
+
children: /* @__PURE__ */ jsx(ToggleGroupContext.Provider, {
|
|
20
|
+
value: {
|
|
21
|
+
variant,
|
|
22
|
+
size
|
|
23
|
+
},
|
|
24
|
+
children
|
|
25
|
+
})
|
|
26
|
+
}));
|
|
27
|
+
ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName;
|
|
28
|
+
const ToggleGroupItem = React.forwardRef(({ className, children, variant, size,...props }, ref) => {
|
|
29
|
+
const context = React.useContext(ToggleGroupContext);
|
|
30
|
+
return /* @__PURE__ */ jsx(ToggleGroupPrimitive.Item, {
|
|
31
|
+
ref,
|
|
32
|
+
className: cn(toggleVariants({
|
|
33
|
+
variant: context.variant || variant,
|
|
34
|
+
size: context.size || size
|
|
35
|
+
}), className),
|
|
36
|
+
...props,
|
|
37
|
+
children
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ToggleGroup, ToggleGroupItem };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { VariantProps } from "class-variance-authority";
|
|
3
|
+
import * as TogglePrimitive from "@radix-ui/react-toggle";
|
|
4
|
+
import * as class_variance_authority_types12 from "class-variance-authority/types";
|
|
5
|
+
|
|
6
|
+
//#region src/components/toggle.d.ts
|
|
7
|
+
declare const toggleVariants: (props?: ({
|
|
8
|
+
variant?: "default" | "outline" | null | undefined;
|
|
9
|
+
size?: "default" | "sm" | "lg" | null | undefined;
|
|
10
|
+
} & class_variance_authority_types12.ClassProp) | undefined) => string;
|
|
11
|
+
declare const Toggle: React.ForwardRefExoticComponent<Omit<TogglePrimitive.ToggleProps & React.RefAttributes<HTMLButtonElement>, "ref"> & VariantProps<(props?: ({
|
|
12
|
+
variant?: "default" | "outline" | null | undefined;
|
|
13
|
+
size?: "default" | "sm" | "lg" | null | undefined;
|
|
14
|
+
} & class_variance_authority_types12.ClassProp) | undefined) => string> & React.RefAttributes<HTMLButtonElement>>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Toggle, toggleVariants };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cva } from "class-variance-authority";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import * as TogglePrimitive from "@radix-ui/react-toggle";
|
|
9
|
+
|
|
10
|
+
//#region src/components/toggle.tsx
|
|
11
|
+
const toggleVariants = cva("inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", {
|
|
12
|
+
variants: {
|
|
13
|
+
variant: {
|
|
14
|
+
default: "bg-transparent",
|
|
15
|
+
outline: "border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground"
|
|
16
|
+
},
|
|
17
|
+
size: {
|
|
18
|
+
default: "h-9 px-2 min-w-9",
|
|
19
|
+
sm: "h-8 px-1.5 min-w-8",
|
|
20
|
+
lg: "h-10 px-2.5 min-w-10"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
variant: "default",
|
|
25
|
+
size: "default"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const Toggle = React.forwardRef(({ className, variant, size,...props }, ref) => /* @__PURE__ */ jsx(TogglePrimitive.Root, {
|
|
29
|
+
ref,
|
|
30
|
+
className: cn(toggleVariants({
|
|
31
|
+
variant,
|
|
32
|
+
size,
|
|
33
|
+
className
|
|
34
|
+
})),
|
|
35
|
+
...props
|
|
36
|
+
}));
|
|
37
|
+
Toggle.displayName = TogglePrimitive.Root.displayName;
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { Toggle, toggleVariants };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
3
|
+
|
|
4
|
+
//#region src/components/tooltip.d.ts
|
|
5
|
+
declare const TooltipProvider: React.FC<TooltipPrimitive.TooltipProviderProps>;
|
|
6
|
+
declare const Tooltip: React.FC<TooltipPrimitive.TooltipProps>;
|
|
7
|
+
declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipPrimitive.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
8
|
+
declare const TooltipContent: React.ForwardRefExoticComponent<Omit<TooltipPrimitive.TooltipContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
8
|
+
|
|
9
|
+
//#region src/components/tooltip.tsx
|
|
10
|
+
const TooltipProvider = TooltipPrimitive.Provider;
|
|
11
|
+
const Tooltip = TooltipPrimitive.Root;
|
|
12
|
+
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
13
|
+
const TooltipContent = React.forwardRef(({ className, sideOffset = 4,...props }, ref) => /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsx(TooltipPrimitive.Content, {
|
|
14
|
+
ref,
|
|
15
|
+
sideOffset,
|
|
16
|
+
className: cn("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-tooltip-content-transform-origin)", className),
|
|
17
|
+
...props
|
|
18
|
+
}) }));
|
|
19
|
+
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/hooks/use-media-query.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Live `window.matchMedia(query).matches`. False where matchMedia is missing
|
|
4
|
+
* (jsdom, very old webviews), so layouts fall back to their wide form.
|
|
5
|
+
*/
|
|
6
|
+
declare function useMediaQuery(query: string): boolean;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { useMediaQuery };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-media-query.ts
|
|
4
|
+
/**
|
|
5
|
+
* Live `window.matchMedia(query).matches`. False where matchMedia is missing
|
|
6
|
+
* (jsdom, very old webviews), so layouts fall back to their wide form.
|
|
7
|
+
*/
|
|
8
|
+
function useMediaQuery(query) {
|
|
9
|
+
const subscribe = React.useCallback((onChange) => {
|
|
10
|
+
if (typeof window.matchMedia !== "function") return () => {};
|
|
11
|
+
const mql = window.matchMedia(query);
|
|
12
|
+
mql.addEventListener("change", onChange);
|
|
13
|
+
return () => mql.removeEventListener("change", onChange);
|
|
14
|
+
}, [query]);
|
|
15
|
+
const getSnapshot = () => typeof window.matchMedia === "function" && window.matchMedia(query).matches;
|
|
16
|
+
return React.useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useMediaQuery };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-mobile.ts
|
|
4
|
+
const MOBILE_BREAKPOINT = 768;
|
|
5
|
+
function useIsMobile() {
|
|
6
|
+
const [isMobile, setIsMobile] = React.useState(void 0);
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
9
|
+
const onChange = () => {
|
|
10
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
11
|
+
};
|
|
12
|
+
mql.addEventListener("change", onChange);
|
|
13
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
14
|
+
return () => mql.removeEventListener("change", onChange);
|
|
15
|
+
}, []);
|
|
16
|
+
return !!isMobile;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useIsMobile };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/lib/keyboard-guards.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Guards for window-level shortcut handlers: a global binding must not fire
|
|
4
|
+
* while the user types or while a modal dialog is stacked on top.
|
|
5
|
+
*/
|
|
6
|
+
/** True while the event target is an editable/typing surface (inputs, editors). */
|
|
7
|
+
declare function isTypingTarget(target: EventTarget | null): boolean;
|
|
8
|
+
/** True when any modal dialog is currently mounted. */
|
|
9
|
+
declare function isDialogOpen(): boolean;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { isDialogOpen, isTypingTarget };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/lib/keyboard-guards.ts
|
|
2
|
+
/**
|
|
3
|
+
* Guards for window-level shortcut handlers: a global binding must not fire
|
|
4
|
+
* while the user types or while a modal dialog is stacked on top.
|
|
5
|
+
*/
|
|
6
|
+
/** True while the event target is an editable/typing surface (inputs, editors). */
|
|
7
|
+
function isTypingTarget(target) {
|
|
8
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
9
|
+
return target.isContentEditable || [
|
|
10
|
+
"INPUT",
|
|
11
|
+
"TEXTAREA",
|
|
12
|
+
"SELECT"
|
|
13
|
+
].includes(target.tagName);
|
|
14
|
+
}
|
|
15
|
+
/** True when any modal dialog is currently mounted. */
|
|
16
|
+
function isDialogOpen() {
|
|
17
|
+
return Boolean(document.querySelector("[role=\"dialog\"], [role=\"alertdialog\"]"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { isDialogOpen, isTypingTarget };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Theme } from "./theme-provider.js";
|
|
2
|
+
import { LucideIcon } from "lucide-react";
|
|
3
|
+
|
|
4
|
+
//#region src/theme/theme-options.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The theme choices, in display order. Every theme picker (menu, settings, ...)
|
|
8
|
+
* can render from this list so the value set and icons cannot
|
|
9
|
+
* drift; each surface supplies its own label copy.
|
|
10
|
+
*/
|
|
11
|
+
declare const THEME_OPTIONS: readonly {
|
|
12
|
+
value: Theme;
|
|
13
|
+
icon: LucideIcon;
|
|
14
|
+
}[];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { THEME_OPTIONS };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Monitor, Moon, Sun } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/theme-options.ts
|
|
4
|
+
/**
|
|
5
|
+
* The theme choices, in display order. Every theme picker (menu, settings, ...)
|
|
6
|
+
* can render from this list so the value set and icons cannot
|
|
7
|
+
* drift; each surface supplies its own label copy.
|
|
8
|
+
*/
|
|
9
|
+
const THEME_OPTIONS = [
|
|
10
|
+
{
|
|
11
|
+
value: "light",
|
|
12
|
+
icon: Sun
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
value: "dark",
|
|
16
|
+
icon: Moon
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
value: "system",
|
|
20
|
+
icon: Monitor
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { THEME_OPTIONS };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/theme/theme-provider.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lightweight theme provider for the shared design system (shadcn/next-themes
|
|
7
|
+
* pattern, ~1 file). Every host (web or native) shares this single source of truth:
|
|
8
|
+
* the provider reads a saved preference, toggles `.dark` (and `.light`) on
|
|
9
|
+
* `document.documentElement`, and persists changes. Tailwind v4 restyles the
|
|
10
|
+
* app from the `.dark`/`.light` class via the `@custom-variant dark` rule in
|
|
11
|
+
* `@boriaui/tokens`.
|
|
12
|
+
*
|
|
13
|
+
* The provider is platform-free: persistence is injected through a `ThemeStorage`
|
|
14
|
+
* (defaults to `localStorage`), and the "system" theme is resolved via
|
|
15
|
+
* `prefers-color-scheme` unless a `systemTheme` is supplied — a native host can
|
|
16
|
+
* feed its window theme through that prop.
|
|
17
|
+
*/
|
|
18
|
+
type Theme = "light" | "dark" | "system";
|
|
19
|
+
type ResolvedTheme = "light" | "dark";
|
|
20
|
+
interface ThemeStorage {
|
|
21
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
22
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
interface ThemeProviderState {
|
|
25
|
+
/** The user-facing mode: explicit `light`/`dark`, or `system` (follow OS). */
|
|
26
|
+
theme: Theme;
|
|
27
|
+
/** The theme actually applied to the document. */
|
|
28
|
+
resolvedTheme: ResolvedTheme;
|
|
29
|
+
setTheme: (theme: Theme) => void;
|
|
30
|
+
}
|
|
31
|
+
interface ThemeProviderProps {
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
defaultTheme?: Theme;
|
|
34
|
+
storageKey?: string;
|
|
35
|
+
storage?: ThemeStorage;
|
|
36
|
+
/** Native/system override used when `theme === "system"` (e.g. a native window theme). */
|
|
37
|
+
systemTheme?: ResolvedTheme | null;
|
|
38
|
+
disableTransitionOnChange?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function ThemeProvider({
|
|
41
|
+
children,
|
|
42
|
+
defaultTheme,
|
|
43
|
+
storageKey,
|
|
44
|
+
storage,
|
|
45
|
+
systemTheme,
|
|
46
|
+
disableTransitionOnChange
|
|
47
|
+
}: ThemeProviderProps): React.JSX.Element;
|
|
48
|
+
declare function useTheme(): ThemeProviderState;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ResolvedTheme, Theme, ThemeProvider, ThemeStorage, useTheme };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/theme/theme-provider.tsx
|
|
8
|
+
const DEFAULT_STORAGE_KEY = "theme";
|
|
9
|
+
const ThemeProviderContext = React.createContext(void 0);
|
|
10
|
+
function defaultStorage() {
|
|
11
|
+
return {
|
|
12
|
+
getItem: (key) => {
|
|
13
|
+
try {
|
|
14
|
+
return window.localStorage.getItem(key);
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
setItem: (key, value) => {
|
|
20
|
+
try {
|
|
21
|
+
window.localStorage.setItem(key, value);
|
|
22
|
+
} catch {}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getMediaTheme() {
|
|
27
|
+
if (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches) return "dark";
|
|
28
|
+
return "light";
|
|
29
|
+
}
|
|
30
|
+
function ThemeProvider({ children, defaultTheme = "system", storageKey = DEFAULT_STORAGE_KEY, storage, systemTheme, disableTransitionOnChange = false }) {
|
|
31
|
+
const [store] = React.useState(() => storage ?? defaultStorage());
|
|
32
|
+
const [theme, setThemeState] = React.useState(defaultTheme);
|
|
33
|
+
const [mediaTheme, setMediaTheme] = React.useState(() => getMediaTheme());
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
let active = true;
|
|
36
|
+
Promise.resolve(store.getItem(storageKey)).then((saved) => {
|
|
37
|
+
if (!active) return;
|
|
38
|
+
if (saved === "light" || saved === "dark" || saved === "system") setThemeState(saved);
|
|
39
|
+
}).catch(() => {});
|
|
40
|
+
return () => {
|
|
41
|
+
active = false;
|
|
42
|
+
};
|
|
43
|
+
}, [store, storageKey]);
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (theme !== "system" || systemTheme) return;
|
|
46
|
+
const mql = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
47
|
+
if (!mql) return;
|
|
48
|
+
const onChange = () => setMediaTheme(mql.matches ? "dark" : "light");
|
|
49
|
+
mql.addEventListener("change", onChange);
|
|
50
|
+
return () => mql.removeEventListener("change", onChange);
|
|
51
|
+
}, [theme, systemTheme]);
|
|
52
|
+
const resolvedTheme = theme === "system" ? systemTheme ?? mediaTheme : theme;
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
const root = window.document.documentElement;
|
|
55
|
+
if (disableTransitionOnChange) root.classList.add("theme-transition-disabled");
|
|
56
|
+
root.classList.remove("light", "dark");
|
|
57
|
+
root.classList.add(resolvedTheme);
|
|
58
|
+
root.style.backgroundColor = "";
|
|
59
|
+
if (disableTransitionOnChange) {
|
|
60
|
+
const timer = window.setTimeout(() => {
|
|
61
|
+
root.classList.remove("theme-transition-disabled");
|
|
62
|
+
}, 0);
|
|
63
|
+
return () => {
|
|
64
|
+
window.clearTimeout(timer);
|
|
65
|
+
root.classList.remove("theme-transition-disabled");
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}, [disableTransitionOnChange, resolvedTheme]);
|
|
69
|
+
const setTheme = React.useCallback((next) => {
|
|
70
|
+
setThemeState(next);
|
|
71
|
+
Promise.resolve(store.setItem(storageKey, next)).catch(() => {});
|
|
72
|
+
}, [store, storageKey]);
|
|
73
|
+
const value = React.useMemo(() => ({
|
|
74
|
+
theme,
|
|
75
|
+
resolvedTheme,
|
|
76
|
+
setTheme
|
|
77
|
+
}), [
|
|
78
|
+
theme,
|
|
79
|
+
resolvedTheme,
|
|
80
|
+
setTheme
|
|
81
|
+
]);
|
|
82
|
+
return /* @__PURE__ */ jsx(ThemeProviderContext.Provider, {
|
|
83
|
+
value,
|
|
84
|
+
children
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function useTheme() {
|
|
88
|
+
const context = React.useContext(ThemeProviderContext);
|
|
89
|
+
if (context === void 0) throw new Error("useTheme must be used within a ThemeProvider");
|
|
90
|
+
return context;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { ThemeProvider, useTheme };
|