@blibliki/ui 0.9.2

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.
@@ -0,0 +1,90 @@
1
+ import { Slot } from "@radix-ui/react-slot";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import * as React from "react";
4
+ import { cn } from "@/lib/cn";
5
+
6
+ const stackVariants = cva("ui-stack", {
7
+ variants: {
8
+ direction: {
9
+ row: "ui-stack--row",
10
+ column: "ui-stack--column",
11
+ },
12
+ align: {
13
+ start: "ui-stack--align-start",
14
+ center: "ui-stack--align-center",
15
+ end: "ui-stack--align-end",
16
+ stretch: "ui-stack--align-stretch",
17
+ baseline: "ui-stack--align-baseline",
18
+ },
19
+ justify: {
20
+ start: "ui-stack--justify-start",
21
+ center: "ui-stack--justify-center",
22
+ end: "ui-stack--justify-end",
23
+ between: "ui-stack--justify-between",
24
+ around: "ui-stack--justify-around",
25
+ evenly: "ui-stack--justify-evenly",
26
+ },
27
+ gap: {
28
+ 0: "ui-stack--gap-0",
29
+ 1: "ui-stack--gap-1",
30
+ 2: "ui-stack--gap-2",
31
+ 3: "ui-stack--gap-3",
32
+ 4: "ui-stack--gap-4",
33
+ 5: "ui-stack--gap-5",
34
+ 6: "ui-stack--gap-6",
35
+ },
36
+ wrap: {
37
+ true: "ui-stack--wrap",
38
+ false: "",
39
+ },
40
+ },
41
+ defaultVariants: {
42
+ direction: "column",
43
+ align: "stretch",
44
+ justify: "start",
45
+ gap: 2,
46
+ wrap: false,
47
+ },
48
+ });
49
+
50
+ type StackElement = HTMLDivElement;
51
+
52
+ export interface StackProps
53
+ extends
54
+ React.HTMLAttributes<StackElement>,
55
+ VariantProps<typeof stackVariants> {
56
+ asChild?: boolean;
57
+ }
58
+
59
+ const Stack = React.forwardRef<StackElement, StackProps>(
60
+ (
61
+ {
62
+ className,
63
+ direction,
64
+ align,
65
+ justify,
66
+ gap,
67
+ wrap,
68
+ asChild = false,
69
+ ...props
70
+ },
71
+ ref,
72
+ ) => {
73
+ const Comp = asChild ? Slot : "div";
74
+
75
+ return (
76
+ <Comp
77
+ ref={ref}
78
+ className={cn(
79
+ stackVariants({ direction, align, justify, gap, wrap }),
80
+ className,
81
+ )}
82
+ {...props}
83
+ />
84
+ );
85
+ },
86
+ );
87
+
88
+ Stack.displayName = "Stack";
89
+
90
+ export { Stack, stackVariants };
@@ -0,0 +1,88 @@
1
+ import { Slot } from "@radix-ui/react-slot";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import * as React from "react";
4
+ import { cn } from "@/lib/cn";
5
+
6
+ const surfaceVariants = cva("ui-surface", {
7
+ variants: {
8
+ tone: {
9
+ canvas: "ui-surface--tone-canvas",
10
+ panel: "ui-surface--tone-panel",
11
+ raised: "ui-surface--tone-raised",
12
+ subtle: "ui-surface--tone-subtle",
13
+ },
14
+ border: {
15
+ none: "",
16
+ subtle: "ui-surface--border-subtle",
17
+ },
18
+ radius: {
19
+ none: "ui-surface--radius-none",
20
+ sm: "ui-surface--radius-sm",
21
+ md: "ui-surface--radius-md",
22
+ lg: "ui-surface--radius-lg",
23
+ },
24
+ shadow: {
25
+ none: "",
26
+ sm: "ui-surface--shadow-sm",
27
+ md: "ui-surface--shadow-md",
28
+ lg: "ui-surface--shadow-lg",
29
+ xl: "ui-surface--shadow-xl",
30
+ },
31
+ intent: {
32
+ neutral: "",
33
+ success: "ui-surface--intent-success",
34
+ warning: "ui-surface--intent-warning",
35
+ error: "ui-surface--intent-error",
36
+ info: "ui-surface--intent-info",
37
+ },
38
+ },
39
+ defaultVariants: {
40
+ tone: "raised",
41
+ border: "none",
42
+ radius: "md",
43
+ shadow: "none",
44
+ intent: "neutral",
45
+ },
46
+ });
47
+
48
+ type SurfaceElement = HTMLDivElement;
49
+
50
+ export interface SurfaceProps
51
+ extends
52
+ React.HTMLAttributes<SurfaceElement>,
53
+ VariantProps<typeof surfaceVariants> {
54
+ asChild?: boolean;
55
+ }
56
+
57
+ const Surface = React.forwardRef<SurfaceElement, SurfaceProps>(
58
+ (
59
+ {
60
+ className,
61
+ tone,
62
+ border,
63
+ radius,
64
+ shadow,
65
+ intent,
66
+ asChild = false,
67
+ ...props
68
+ },
69
+ ref,
70
+ ) => {
71
+ const Comp = asChild ? Slot : "div";
72
+
73
+ return (
74
+ <Comp
75
+ ref={ref}
76
+ className={cn(
77
+ surfaceVariants({ tone, border, radius, shadow, intent }),
78
+ className,
79
+ )}
80
+ {...props}
81
+ />
82
+ );
83
+ },
84
+ );
85
+
86
+ Surface.displayName = "Surface";
87
+
88
+ export { Surface, surfaceVariants };
@@ -0,0 +1,72 @@
1
+ import { cva, type VariantProps } from "class-variance-authority";
2
+ import * as React from "react";
3
+ import { cn } from "@/lib/cn";
4
+
5
+ const switchVariants = cva("ui-switch", {
6
+ variants: {
7
+ size: {
8
+ sm: "ui-switch--size-sm",
9
+ md: "ui-switch--size-md",
10
+ },
11
+ color: {
12
+ primary: "ui-switch--color-primary",
13
+ secondary: "ui-switch--color-secondary",
14
+ error: "ui-switch--color-error",
15
+ warning: "ui-switch--color-warning",
16
+ info: "ui-switch--color-info",
17
+ success: "ui-switch--color-success",
18
+ },
19
+ },
20
+ defaultVariants: {
21
+ size: "md",
22
+ color: "primary",
23
+ },
24
+ });
25
+
26
+ export interface SwitchProps
27
+ extends
28
+ Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "color" | "onChange">,
29
+ VariantProps<typeof switchVariants> {
30
+ checked?: boolean;
31
+ onCheckedChange?: (checked: boolean) => void;
32
+ }
33
+
34
+ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
35
+ (
36
+ {
37
+ checked = false,
38
+ onCheckedChange,
39
+ className,
40
+ size,
41
+ color,
42
+ type,
43
+ onClick,
44
+ ...props
45
+ },
46
+ ref,
47
+ ) => {
48
+ return (
49
+ <button
50
+ ref={ref}
51
+ type={type ?? "button"}
52
+ role="switch"
53
+ aria-checked={checked}
54
+ data-state={checked ? "checked" : "unchecked"}
55
+ className={cn(switchVariants({ size, color }), className)}
56
+ onClick={(event) => {
57
+ onClick?.(event);
58
+ if (!event.defaultPrevented) {
59
+ onCheckedChange?.(!checked);
60
+ }
61
+ }}
62
+ {...props}
63
+ >
64
+ <span aria-hidden className="ui-switch__thumb" />
65
+ </button>
66
+ );
67
+ },
68
+ );
69
+
70
+ Switch.displayName = "Switch";
71
+
72
+ export { Switch };
@@ -0,0 +1,59 @@
1
+ import { Slot } from "@radix-ui/react-slot";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import { forwardRef, type HTMLAttributes } from "react";
4
+ import { cn } from "@/lib/cn";
5
+
6
+ const textVariants = cva("ui-text", {
7
+ variants: {
8
+ tone: {
9
+ primary: "ui-text--tone-primary",
10
+ secondary: "ui-text--tone-secondary",
11
+ muted: "ui-text--tone-muted",
12
+ success: "ui-text--tone-success",
13
+ warning: "ui-text--tone-warning",
14
+ error: "ui-text--tone-error",
15
+ info: "ui-text--tone-info",
16
+ },
17
+ size: {
18
+ xs: "ui-text--size-xs",
19
+ sm: "ui-text--size-sm",
20
+ md: "ui-text--size-md",
21
+ lg: "ui-text--size-lg",
22
+ },
23
+ weight: {
24
+ regular: "ui-text--weight-regular",
25
+ medium: "ui-text--weight-medium",
26
+ semibold: "ui-text--weight-semibold",
27
+ },
28
+ },
29
+ defaultVariants: {
30
+ tone: "primary",
31
+ size: "sm",
32
+ weight: "regular",
33
+ },
34
+ });
35
+
36
+ type TextElement = HTMLParagraphElement;
37
+
38
+ export interface TextProps
39
+ extends HTMLAttributes<TextElement>, VariantProps<typeof textVariants> {
40
+ asChild?: boolean;
41
+ }
42
+
43
+ const Text = forwardRef<TextElement, TextProps>(
44
+ ({ className, tone, size, weight, asChild = false, ...props }, ref) => {
45
+ const Comp = asChild ? Slot : "p";
46
+
47
+ return (
48
+ <Comp
49
+ ref={ref}
50
+ className={cn(textVariants({ tone, size, weight }), className)}
51
+ {...props}
52
+ />
53
+ );
54
+ },
55
+ );
56
+
57
+ Text.displayName = "Text";
58
+
59
+ export { Text, textVariants };
@@ -0,0 +1,43 @@
1
+ import { cva, type VariantProps } from "class-variance-authority";
2
+ import { forwardRef, type TextareaHTMLAttributes } from "react";
3
+ import { cn } from "@/lib/cn";
4
+
5
+ const textareaVariants = cva("ui-textarea", {
6
+ variants: {
7
+ size: {
8
+ sm: "ui-textarea--size-sm",
9
+ md: "ui-textarea--size-md",
10
+ },
11
+ resize: {
12
+ none: "ui-textarea--resize-none",
13
+ vertical: "ui-textarea--resize-vertical",
14
+ both: "ui-textarea--resize-both",
15
+ },
16
+ },
17
+ defaultVariants: {
18
+ size: "md",
19
+ resize: "vertical",
20
+ },
21
+ });
22
+
23
+ export interface TextareaProps
24
+ extends
25
+ Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "size">,
26
+ VariantProps<typeof textareaVariants> {}
27
+
28
+ const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
29
+ ({ className, size, resize, ...props }, ref) => {
30
+ return (
31
+ <textarea
32
+ ref={ref}
33
+ data-size={size ?? "md"}
34
+ className={cn(textareaVariants({ size, resize }), className)}
35
+ {...props}
36
+ />
37
+ );
38
+ },
39
+ );
40
+
41
+ Textarea.displayName = "Textarea";
42
+
43
+ export { Textarea, textareaVariants };
package/src/index.ts ADDED
@@ -0,0 +1,120 @@
1
+ export { Button, buttonVariants, type ButtonProps } from "./components/button";
2
+ export {
3
+ Card,
4
+ CardAction,
5
+ CardContent,
6
+ CardDescription,
7
+ CardFooter,
8
+ CardHeader,
9
+ CardTitle,
10
+ } from "./components/card";
11
+ export {
12
+ Surface,
13
+ surfaceVariants,
14
+ type SurfaceProps,
15
+ } from "./components/surface";
16
+ export { Stack, stackVariants, type StackProps } from "./components/stack";
17
+ export {
18
+ Divider,
19
+ dividerVariants,
20
+ type DividerProps,
21
+ } from "./components/divider";
22
+ export { IconButton, type IconButtonProps } from "./components/icon-button";
23
+ export { Input, inputVariants, type InputProps } from "./components/input";
24
+ export {
25
+ Textarea,
26
+ textareaVariants,
27
+ type TextareaProps,
28
+ } from "./components/textarea";
29
+ export { Label } from "./components/label";
30
+ export { Text, textVariants, type TextProps } from "./components/text";
31
+ export { Badge, badgeVariants, type BadgeProps } from "./components/badge";
32
+ export { Switch, type SwitchProps } from "./components/switch";
33
+ export {
34
+ OptionSelect,
35
+ Select,
36
+ SelectContent,
37
+ SelectGroup,
38
+ SelectItem,
39
+ SelectLabel,
40
+ SelectScrollDownButton,
41
+ SelectScrollUpButton,
42
+ SelectSeparator,
43
+ SelectTrigger,
44
+ SelectValue,
45
+ type OptionSelectProps,
46
+ } from "./components/select";
47
+ export {
48
+ Fader,
49
+ type FaderProps,
50
+ type MarkProps,
51
+ type TOrientation,
52
+ } from "./components/fader";
53
+ export { Encoder, type EncoderProps } from "./components/encoder";
54
+ export {
55
+ Dialog,
56
+ DialogPortal,
57
+ DialogOverlay,
58
+ DialogClose,
59
+ DialogTrigger,
60
+ DialogContent,
61
+ DialogHeader,
62
+ DialogFooter,
63
+ DialogTitle,
64
+ DialogDescription,
65
+ type DialogContentProps,
66
+ } from "./components/dialog";
67
+ export {
68
+ ContextMenu,
69
+ ContextMenuPortal,
70
+ ContextMenuTrigger,
71
+ ContextMenuContent,
72
+ ContextMenuGroup,
73
+ ContextMenuLabel,
74
+ ContextMenuItem,
75
+ ContextMenuCheckboxItem,
76
+ ContextMenuRadioGroup,
77
+ ContextMenuRadioItem,
78
+ ContextMenuSeparator,
79
+ ContextMenuShortcut,
80
+ ContextMenuSub,
81
+ ContextMenuSubTrigger,
82
+ ContextMenuSubContent,
83
+ } from "./components/context-menu";
84
+ export {
85
+ DropdownMenu,
86
+ DropdownMenuPortal,
87
+ DropdownMenuTrigger,
88
+ DropdownMenuContent,
89
+ DropdownMenuGroup,
90
+ DropdownMenuLabel,
91
+ DropdownMenuItem,
92
+ DropdownMenuCheckboxItem,
93
+ DropdownMenuRadioGroup,
94
+ DropdownMenuRadioItem,
95
+ DropdownMenuSeparator,
96
+ DropdownMenuShortcut,
97
+ DropdownMenuSub,
98
+ DropdownMenuSubTrigger,
99
+ DropdownMenuSubContent,
100
+ } from "./components/dropdown-menu";
101
+ export { UIProvider, type UIProviderProps } from "./UIProvider";
102
+ export { cn } from "./lib/cn";
103
+ export {
104
+ uiColorMix,
105
+ uiTone,
106
+ uiVars,
107
+ type UIIntentTone,
108
+ type UIIntentToneLevel,
109
+ } from "./semantic";
110
+ export {
111
+ createTheme,
112
+ themeToCssVariables,
113
+ type UIMode,
114
+ type UIResolvedTheme,
115
+ type UITheme,
116
+ type UIColorTokens,
117
+ type UIRadiusTokens,
118
+ } from "./theme";
119
+
120
+ export const UI_MAX_TAILWIND_CLASSES = 12;
package/src/lib/cn.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]): string {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,72 @@
1
+ const uiVars = {
2
+ surface: {
3
+ canvas: "var(--ui-color-surface-0)",
4
+ panel: "var(--ui-color-surface-1)",
5
+ raised: "var(--ui-color-surface-raised)",
6
+ subtle: "var(--ui-color-surface-2)",
7
+ },
8
+ text: {
9
+ primary: "var(--ui-color-text-primary)",
10
+ secondary: "var(--ui-color-text-secondary)",
11
+ muted: "var(--ui-color-text-muted)",
12
+ },
13
+ border: {
14
+ subtle: "var(--ui-color-border-subtle)",
15
+ },
16
+ } as const;
17
+
18
+ const toneVars = {
19
+ primary: {
20
+ "500": "var(--ui-color-primary-500)",
21
+ "600": "var(--ui-color-primary-600)",
22
+ contrast: "var(--ui-color-primary-contrast)",
23
+ },
24
+ secondary: {
25
+ "500": "var(--ui-color-secondary-500)",
26
+ "600": "var(--ui-color-secondary-600)",
27
+ contrast: "var(--ui-color-secondary-contrast)",
28
+ },
29
+ success: {
30
+ "500": "var(--ui-color-success-500)",
31
+ "600": "var(--ui-color-success-600)",
32
+ contrast: "var(--ui-color-success-contrast)",
33
+ },
34
+ warning: {
35
+ "500": "var(--ui-color-warning-500)",
36
+ "600": "var(--ui-color-warning-600)",
37
+ contrast: "var(--ui-color-warning-contrast)",
38
+ },
39
+ error: {
40
+ "500": "var(--ui-color-error-500)",
41
+ "600": "var(--ui-color-error-600)",
42
+ contrast: "var(--ui-color-error-contrast)",
43
+ },
44
+ info: {
45
+ "500": "var(--ui-color-info-500)",
46
+ "600": "var(--ui-color-info-600)",
47
+ contrast: "var(--ui-color-info-contrast)",
48
+ },
49
+ } as const;
50
+
51
+ type UIIntentTone = keyof typeof toneVars;
52
+ type UIIntentToneLevel = keyof (typeof toneVars)[UIIntentTone];
53
+
54
+ function uiTone(tone: UIIntentTone, level: UIIntentToneLevel = "500"): string {
55
+ return toneVars[tone][level];
56
+ }
57
+
58
+ function uiColorMix(
59
+ base: string,
60
+ mixWith: string,
61
+ mixWithPercent: number,
62
+ ): string {
63
+ return `color-mix(in oklab, ${base}, ${mixWith} ${mixWithPercent}%)`;
64
+ }
65
+
66
+ export {
67
+ uiColorMix,
68
+ uiTone,
69
+ uiVars,
70
+ type UIIntentTone,
71
+ type UIIntentToneLevel,
72
+ };