@alpic-ai/ui 0.0.0 → 1.112.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/dist/components/alert.d.mts +1 -1
- package/dist/components/avatar.d.mts +1 -1
- package/dist/components/badge.d.mts +1 -1
- package/dist/components/button.d.mts +2 -2
- package/dist/components/combobox.mjs +1 -1
- package/dist/components/dialog.mjs +2 -2
- package/dist/components/form.d.mts +119 -0
- package/dist/components/form.mjs +192 -0
- package/dist/components/input.d.mts +2 -0
- package/dist/components/input.mjs +19 -10
- package/dist/components/select-trigger-variants.mjs +1 -0
- package/dist/components/select.d.mts +1 -9
- package/dist/components/select.mjs +8 -28
- package/dist/components/sidebar.d.mts +1 -1
- package/dist/components/sidebar.mjs +6 -6
- package/dist/components/spinner.d.mts +1 -1
- package/dist/components/status-dot.d.mts +1 -1
- package/dist/components/tabs.d.mts +1 -1
- package/dist/components/textarea.d.mts +2 -0
- package/dist/components/textarea.mjs +19 -10
- package/dist/components/toggle-group.d.mts +1 -1
- package/dist/components/typography.d.mts +34 -0
- package/dist/components/typography.mjs +29 -0
- package/package.json +31 -40
- package/src/components/combobox.tsx +1 -1
- package/src/components/dialog.tsx +2 -2
- package/src/components/form.tsx +343 -0
- package/src/components/input.tsx +12 -0
- package/src/components/select-trigger-variants.ts +1 -0
- package/src/components/select.tsx +2 -35
- package/src/components/sidebar.tsx +8 -10
- package/src/components/textarea.tsx +12 -1
- package/src/components/typography.tsx +19 -0
- package/src/stories/accordion-card.stories.tsx +53 -0
- package/src/stories/accordion.stories.tsx +65 -0
- package/src/stories/alert.stories.tsx +58 -0
- package/src/stories/attachment-tile.stories.tsx +37 -0
- package/src/stories/avatar.stories.tsx +54 -0
- package/src/stories/badge.stories.tsx +50 -0
- package/src/stories/breadcrumb.stories.tsx +107 -0
- package/src/stories/button.stories.tsx +342 -0
- package/src/stories/card.stories.tsx +89 -0
- package/src/stories/checkbox.stories.tsx +56 -0
- package/src/stories/collapsible.stories.tsx +69 -0
- package/src/stories/combobox.stories.tsx +214 -0
- package/src/stories/command.stories.tsx +95 -0
- package/src/stories/copyable.stories.tsx +29 -0
- package/src/stories/description-list.stories.tsx +71 -0
- package/src/stories/dialog.stories.tsx +135 -0
- package/src/stories/dropdown-menu.stories.tsx +191 -0
- package/src/stories/form.stories.tsx +91 -0
- package/src/stories/input-group.stories.tsx +63 -0
- package/src/stories/input.stories.tsx +72 -0
- package/src/stories/label.stories.tsx +26 -0
- package/src/stories/ladle.css +3 -0
- package/src/stories/pagination.stories.tsx +35 -0
- package/src/stories/popover.stories.tsx +34 -0
- package/src/stories/radio-group.stories.tsx +59 -0
- package/src/stories/scroll-area.stories.tsx +43 -0
- package/src/stories/select.stories.tsx +95 -0
- package/src/stories/separator.stories.tsx +36 -0
- package/src/stories/sheet.stories.tsx +76 -0
- package/src/stories/sidebar.stories.tsx +255 -0
- package/src/stories/skeleton.stories.tsx +47 -0
- package/src/stories/sonner.stories.tsx +91 -0
- package/src/stories/spinner.stories.tsx +66 -0
- package/src/stories/status-dot.stories.tsx +27 -0
- package/src/stories/switch.stories.tsx +46 -0
- package/src/stories/table.stories.tsx +242 -0
- package/src/stories/tabs.stories.tsx +169 -0
- package/src/stories/tag.stories.tsx +82 -0
- package/src/stories/textarea.stories.tsx +60 -0
- package/src/stories/toggle-group.stories.tsx +142 -0
- package/src/stories/tooltip-icon-button.stories.tsx +59 -0
- package/src/stories/tooltip.stories.tsx +54 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../lib/cn.mjs";
|
|
3
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.mjs";
|
|
3
4
|
import { Label } from "./label.mjs";
|
|
5
|
+
import { Info } from "lucide-react";
|
|
4
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
7
|
import * as React from "react";
|
|
6
8
|
//#region src/components/textarea.tsx
|
|
7
|
-
function Textarea({ className, id, label, required, hint, error, ...props }) {
|
|
9
|
+
function Textarea({ className, id, label, required, hint, error, tooltip, ...props }) {
|
|
8
10
|
const generatedId = React.useId();
|
|
9
11
|
const fieldId = id ?? generatedId;
|
|
10
12
|
const textarea = /* @__PURE__ */ jsx("textarea", {
|
|
@@ -21,15 +23,22 @@ function Textarea({ className, id, label, required, hint, error, ...props }) {
|
|
|
21
23
|
children: [
|
|
22
24
|
label && /* @__PURE__ */ jsxs("div", {
|
|
23
25
|
className: "flex items-center gap-0.5",
|
|
24
|
-
children: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
children: [
|
|
27
|
+
/* @__PURE__ */ jsx(Label, {
|
|
28
|
+
htmlFor: fieldId,
|
|
29
|
+
className: "type-text-sm font-medium text-muted-foreground",
|
|
30
|
+
children: label
|
|
31
|
+
}),
|
|
32
|
+
required && /* @__PURE__ */ jsx("span", {
|
|
33
|
+
"aria-hidden": true,
|
|
34
|
+
className: "type-text-sm font-medium text-required",
|
|
35
|
+
children: "*"
|
|
36
|
+
}),
|
|
37
|
+
tooltip && /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
38
|
+
asChild: true,
|
|
39
|
+
children: /* @__PURE__ */ jsx(Info, { className: "size-4 text-muted-foreground" })
|
|
40
|
+
}), /* @__PURE__ */ jsx(TooltipContent, { children: tooltip })] })
|
|
41
|
+
]
|
|
33
42
|
}),
|
|
34
43
|
textarea,
|
|
35
44
|
(hint || error) && /* @__PURE__ */ jsx("p", {
|
|
@@ -7,7 +7,7 @@ import * as _$class_variance_authority_types0 from "class-variance-authority/typ
|
|
|
7
7
|
//#region src/components/toggle-group.d.ts
|
|
8
8
|
declare const toggleGroupItemVariants: (props?: ({
|
|
9
9
|
variant?: "default" | "outline" | null | undefined;
|
|
10
|
-
size?: "
|
|
10
|
+
size?: "default" | "sm" | null | undefined;
|
|
11
11
|
} & _$class_variance_authority_types0.ClassProp) | undefined) => string;
|
|
12
12
|
type ToggleGroupContextValue = VariantProps<typeof toggleGroupItemVariants>;
|
|
13
13
|
declare function ToggleGroup({
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/typography.d.ts
|
|
5
|
+
declare function H1({
|
|
6
|
+
children,
|
|
7
|
+
className
|
|
8
|
+
}: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
className?: string;
|
|
11
|
+
}): _$react_jsx_runtime0.JSX.Element;
|
|
12
|
+
declare function H2({
|
|
13
|
+
children,
|
|
14
|
+
className
|
|
15
|
+
}: {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
className?: string;
|
|
18
|
+
}): _$react_jsx_runtime0.JSX.Element;
|
|
19
|
+
declare function H3({
|
|
20
|
+
children,
|
|
21
|
+
className
|
|
22
|
+
}: {
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
className?: string;
|
|
25
|
+
}): _$react_jsx_runtime0.JSX.Element;
|
|
26
|
+
declare function H4({
|
|
27
|
+
children,
|
|
28
|
+
className
|
|
29
|
+
}: {
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
className?: string;
|
|
32
|
+
}): _$react_jsx_runtime0.JSX.Element;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { H1, H2, H3, H4 };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.mjs";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/components/typography.tsx
|
|
4
|
+
function H1({ children, className }) {
|
|
5
|
+
return /* @__PURE__ */ jsx("h1", {
|
|
6
|
+
className: cn("scroll-m-20 type-display-sm font-bold", className),
|
|
7
|
+
children
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function H2({ children, className }) {
|
|
11
|
+
return /* @__PURE__ */ jsx("h2", {
|
|
12
|
+
className: cn("scroll-m-20 type-display-xs font-semibold", className),
|
|
13
|
+
children
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function H3({ children, className }) {
|
|
17
|
+
return /* @__PURE__ */ jsx("h3", {
|
|
18
|
+
className: cn("scroll-m-20 type-text-lg font-semibold", className),
|
|
19
|
+
children
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function H4({ children, className }) {
|
|
23
|
+
return /* @__PURE__ */ jsx("h4", {
|
|
24
|
+
className: cn("scroll-m-20 type-text-md font-semibold", className),
|
|
25
|
+
children
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { H1, H2, H3, H4 };
|
package/package.json
CHANGED
|
@@ -1,53 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpic-ai/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.112.0",
|
|
4
4
|
"description": "Alpic design system — shared UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
-
"./components/*":
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
"./components/*": {
|
|
8
|
+
"types": "./dist/components/*.d.mts",
|
|
9
|
+
"default": "./dist/components/*.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./hooks/*": {
|
|
12
|
+
"types": "./dist/hooks/*.d.mts",
|
|
13
|
+
"default": "./dist/hooks/*.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./lib/cn": {
|
|
16
|
+
"types": "./dist/lib/cn.d.mts",
|
|
17
|
+
"default": "./dist/lib/cn.mjs"
|
|
18
|
+
},
|
|
10
19
|
"./theme": "./src/styles/tokens.css"
|
|
11
20
|
},
|
|
12
21
|
"files": [
|
|
13
22
|
"dist",
|
|
14
|
-
"src
|
|
15
|
-
"src/hooks",
|
|
16
|
-
"src/lib",
|
|
17
|
-
"src/styles/tokens.css"
|
|
23
|
+
"src"
|
|
18
24
|
],
|
|
19
|
-
"publishConfig": {
|
|
20
|
-
"exports": {
|
|
21
|
-
"./components/*": {
|
|
22
|
-
"types": "./dist/components/*.d.mts",
|
|
23
|
-
"default": "./dist/components/*.mjs"
|
|
24
|
-
},
|
|
25
|
-
"./hooks/*": {
|
|
26
|
-
"types": "./dist/hooks/*.d.mts",
|
|
27
|
-
"default": "./dist/hooks/*.mjs"
|
|
28
|
-
},
|
|
29
|
-
"./lib/cn": {
|
|
30
|
-
"types": "./dist/lib/cn.d.mts",
|
|
31
|
-
"default": "./dist/lib/cn.mjs"
|
|
32
|
-
},
|
|
33
|
-
"./theme": "./src/styles/tokens.css"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build": "shx rm -rf dist && tsdown",
|
|
38
|
-
"format": "biome check --write --error-on-warnings .",
|
|
39
|
-
"test:type": "tsc --noEmit",
|
|
40
|
-
"test:format": "biome check --error-on-warnings .",
|
|
41
|
-
"dev:ui": "ladle serve",
|
|
42
|
-
"publish:npm": "pnpm publish --tag \"${NPM_TAG}\" --access public --no-git-checks"
|
|
43
|
-
},
|
|
44
25
|
"peerDependencies": {
|
|
45
|
-
"lucide-react": "^1.
|
|
46
|
-
"react": "^19.
|
|
47
|
-
"react-dom": "^19.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
26
|
+
"lucide-react": "^1.7.0",
|
|
27
|
+
"react": "^19.2.4",
|
|
28
|
+
"react-dom": "^19.2.4",
|
|
29
|
+
"react-hook-form": "^7.72.1",
|
|
30
|
+
"sonner": "^2.0.7",
|
|
31
|
+
"tailwindcss": "^4.2.2",
|
|
32
|
+
"tw-animate-css": "^1.4.0"
|
|
51
33
|
},
|
|
52
34
|
"dependencies": {
|
|
53
35
|
"@radix-ui/react-accordion": "^1.2.12",
|
|
@@ -78,11 +60,20 @@
|
|
|
78
60
|
"@types/react": "19.2.14",
|
|
79
61
|
"@types/react-dom": "19.2.3",
|
|
80
62
|
"lucide-react": "^1.7.0",
|
|
63
|
+
"react-hook-form": "^7.72.1",
|
|
81
64
|
"shx": "^0.4.0",
|
|
82
65
|
"sonner": "^2.0.7",
|
|
83
66
|
"tailwindcss": "^4.2.2",
|
|
84
67
|
"tsdown": "^0.21.7",
|
|
85
68
|
"tw-animate-css": "^1.4.0",
|
|
86
69
|
"typescript": "^6.0.2"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "shx rm -rf dist && tsdown",
|
|
73
|
+
"format": "biome check --write --error-on-warnings .",
|
|
74
|
+
"test:type": "tsc --noEmit",
|
|
75
|
+
"test:format": "biome check --error-on-warnings .",
|
|
76
|
+
"dev:ui": "ladle serve",
|
|
77
|
+
"publish:npm": "pnpm publish --tag \"${NPM_TAG}\" --access public --no-git-checks"
|
|
87
78
|
}
|
|
88
|
-
}
|
|
79
|
+
}
|
|
@@ -349,7 +349,7 @@ function ComboboxItem({ className, children, itemValue, ...props }: ComboboxItem
|
|
|
349
349
|
data-selected-item={selected || undefined}
|
|
350
350
|
onSelect={() => onSelect(itemValue)}
|
|
351
351
|
className={cn(
|
|
352
|
-
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-
|
|
352
|
+
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 outline-hidden select-none",
|
|
353
353
|
"type-text-md font-medium text-foreground mx-1.5 my-px",
|
|
354
354
|
"data-[selected=true]:bg-background-hover",
|
|
355
355
|
"data-[selected-item]:bg-accent",
|
|
@@ -37,7 +37,7 @@ function DialogOverlay({ className, ...props }: React.ComponentProps<typeof Dial
|
|
|
37
37
|
const dialogContentVariants = cva(
|
|
38
38
|
[
|
|
39
39
|
"bg-background fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2",
|
|
40
|
-
"
|
|
40
|
+
"max-h-[calc(100vh-4rem)] overflow-hidden rounded-2xl px-6 shadow-lg outline-none",
|
|
41
41
|
"data-[state=open]:animate-in data-[state=closed]:animate-out",
|
|
42
42
|
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
43
43
|
"data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
|
@@ -93,7 +93,7 @@ function DialogContent({ className, children, size, showCloseButton = true, ...p
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
96
|
-
return <div data-slot="dialog-header" className={cn("flex flex-col gap-0.5
|
|
96
|
+
return <div data-slot="dialog-header" className={cn("flex flex-col gap-0.5 py-6 pr-10", className)} {...props} />;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
const dialogFooterVariants = cva("pb-6 pt-6", {
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
4
|
+
import { Info } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import {
|
|
7
|
+
Controller,
|
|
8
|
+
type ControllerProps,
|
|
9
|
+
type FieldPath,
|
|
10
|
+
type FieldValues,
|
|
11
|
+
FormProvider,
|
|
12
|
+
useFormContext,
|
|
13
|
+
useFormState,
|
|
14
|
+
} from "react-hook-form";
|
|
15
|
+
|
|
16
|
+
import { cn } from "../lib/cn";
|
|
17
|
+
import { Input, type InputProps } from "./input";
|
|
18
|
+
import { Label } from "./label";
|
|
19
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select";
|
|
20
|
+
import { Textarea, type TextareaProps } from "./textarea";
|
|
21
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
|
|
22
|
+
|
|
23
|
+
const Form = FormProvider;
|
|
24
|
+
|
|
25
|
+
type FormFieldContextValue<
|
|
26
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
27
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
28
|
+
> = {
|
|
29
|
+
name: TName;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const FormFieldContext = React.createContext<FormFieldContextValue>({} as FormFieldContextValue);
|
|
33
|
+
|
|
34
|
+
const FormField = <
|
|
35
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
36
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
37
|
+
>({
|
|
38
|
+
...props
|
|
39
|
+
}: ControllerProps<TFieldValues, TName>) => {
|
|
40
|
+
return (
|
|
41
|
+
<FormFieldContext.Provider value={{ name: props.name }}>
|
|
42
|
+
<Controller {...props} />
|
|
43
|
+
</FormFieldContext.Provider>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const useFormField = () => {
|
|
48
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
49
|
+
const itemContext = React.useContext(FormItemContext);
|
|
50
|
+
|
|
51
|
+
if (!fieldContext.name) {
|
|
52
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { getFieldState } = useFormContext();
|
|
56
|
+
const formState = useFormState({ name: fieldContext.name });
|
|
57
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
58
|
+
|
|
59
|
+
const { id } = itemContext;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
name: fieldContext.name,
|
|
64
|
+
formItemId: `${id}-form-item`,
|
|
65
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
66
|
+
formMessageId: `${id}-form-item-message`,
|
|
67
|
+
...fieldState,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type FormItemContextValue = {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const FormItemContext = React.createContext<FormItemContextValue>({} as FormItemContextValue);
|
|
76
|
+
|
|
77
|
+
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
78
|
+
const id = React.useId();
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<FormItemContext.Provider value={{ id }}>
|
|
82
|
+
<div data-slot="form-item" className={cn("grid gap-2", className)} {...props} />
|
|
83
|
+
</FormItemContext.Provider>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface FormLabelProps extends React.ComponentProps<typeof Label> {
|
|
88
|
+
required?: boolean;
|
|
89
|
+
tooltip?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function FormLabel({ className, required, tooltip, children, ...props }: FormLabelProps) {
|
|
93
|
+
const { error, formItemId } = useFormField();
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className="flex items-center gap-0.5">
|
|
97
|
+
<Label
|
|
98
|
+
data-slot="form-label"
|
|
99
|
+
data-error={!!error}
|
|
100
|
+
className={cn("data-[error=true]:text-destructive", className)}
|
|
101
|
+
htmlFor={formItemId}
|
|
102
|
+
{...props}
|
|
103
|
+
>
|
|
104
|
+
{children}
|
|
105
|
+
</Label>
|
|
106
|
+
{required && (
|
|
107
|
+
<span aria-hidden className="type-text-sm font-medium text-required">
|
|
108
|
+
*
|
|
109
|
+
</span>
|
|
110
|
+
)}
|
|
111
|
+
{tooltip && (
|
|
112
|
+
<Tooltip>
|
|
113
|
+
<TooltipTrigger asChild>
|
|
114
|
+
<Info className="size-4 text-quaternary-foreground" />
|
|
115
|
+
</TooltipTrigger>
|
|
116
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
117
|
+
</Tooltip>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
|
|
124
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<Slot
|
|
128
|
+
data-slot="form-control"
|
|
129
|
+
id={formItemId}
|
|
130
|
+
aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}
|
|
131
|
+
aria-invalid={!!error}
|
|
132
|
+
{...props}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
138
|
+
const { formDescriptionId } = useFormField();
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<p
|
|
142
|
+
data-slot="form-description"
|
|
143
|
+
id={formDescriptionId}
|
|
144
|
+
className={cn("text-muted-foreground text-sm", className)}
|
|
145
|
+
{...props}
|
|
146
|
+
/>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
|
151
|
+
const { error, formMessageId } = useFormField();
|
|
152
|
+
const body = error ? String(error?.message ?? "") : props.children;
|
|
153
|
+
|
|
154
|
+
if (!body) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<p data-slot="form-message" id={formMessageId} className={cn("text-destructive text-sm", className)} {...props}>
|
|
160
|
+
{body}
|
|
161
|
+
</p>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* ── Layout components ───────────────────────────────────────────────────── */
|
|
166
|
+
|
|
167
|
+
interface FormHeaderProps extends React.ComponentProps<"div"> {
|
|
168
|
+
title: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function FormHeader({ title, description, className, ...props }: FormHeaderProps) {
|
|
173
|
+
return (
|
|
174
|
+
<div className={cn("flex flex-col gap-1", className)} {...props}>
|
|
175
|
+
<h2 className="type-display-sm font-semibold text-foreground">{title}</h2>
|
|
176
|
+
{description && <p className="type-text-xl text-subtle-foreground">{description}</p>}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function FormFields({ className, ...props }: React.ComponentProps<"div">) {
|
|
182
|
+
return <div className={cn("flex flex-col gap-6", className)} {...props} />;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* ── Convenience field wrappers ─────────────────────────────────────────── */
|
|
186
|
+
|
|
187
|
+
interface FormFieldBaseProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> {
|
|
188
|
+
control: ControllerProps<TFieldValues, TName>["control"];
|
|
189
|
+
name: TName;
|
|
190
|
+
rules?: ControllerProps<TFieldValues, TName>["rules"];
|
|
191
|
+
required?: boolean;
|
|
192
|
+
label?: string;
|
|
193
|
+
description?: string;
|
|
194
|
+
tooltip?: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface InputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>
|
|
198
|
+
extends FormFieldBaseProps<TFieldValues, TName>,
|
|
199
|
+
Omit<InputProps, "name" | "label"> {}
|
|
200
|
+
|
|
201
|
+
function InputField<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({
|
|
202
|
+
control,
|
|
203
|
+
name,
|
|
204
|
+
rules,
|
|
205
|
+
required,
|
|
206
|
+
label,
|
|
207
|
+
description,
|
|
208
|
+
tooltip,
|
|
209
|
+
...inputProps
|
|
210
|
+
}: InputFieldProps<TFieldValues, TName>) {
|
|
211
|
+
return (
|
|
212
|
+
<FormField
|
|
213
|
+
control={control}
|
|
214
|
+
name={name}
|
|
215
|
+
rules={rules}
|
|
216
|
+
render={({ field }) => (
|
|
217
|
+
<FormItem>
|
|
218
|
+
{label && (
|
|
219
|
+
<FormLabel required={required} tooltip={tooltip}>
|
|
220
|
+
{label}
|
|
221
|
+
</FormLabel>
|
|
222
|
+
)}
|
|
223
|
+
<FormControl>
|
|
224
|
+
<Input {...inputProps} {...field} />
|
|
225
|
+
</FormControl>
|
|
226
|
+
{description && <FormDescription>{description}</FormDescription>}
|
|
227
|
+
<FormMessage />
|
|
228
|
+
</FormItem>
|
|
229
|
+
)}
|
|
230
|
+
/>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
interface TextareaFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>
|
|
235
|
+
extends FormFieldBaseProps<TFieldValues, TName>,
|
|
236
|
+
Omit<TextareaProps, "name" | "label"> {}
|
|
237
|
+
|
|
238
|
+
function TextareaField<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({
|
|
239
|
+
control,
|
|
240
|
+
name,
|
|
241
|
+
rules,
|
|
242
|
+
required,
|
|
243
|
+
label,
|
|
244
|
+
description,
|
|
245
|
+
tooltip,
|
|
246
|
+
...textareaProps
|
|
247
|
+
}: TextareaFieldProps<TFieldValues, TName>) {
|
|
248
|
+
return (
|
|
249
|
+
<FormField
|
|
250
|
+
control={control}
|
|
251
|
+
name={name}
|
|
252
|
+
rules={rules}
|
|
253
|
+
render={({ field }) => (
|
|
254
|
+
<FormItem>
|
|
255
|
+
{label && (
|
|
256
|
+
<FormLabel required={required} tooltip={tooltip}>
|
|
257
|
+
{label}
|
|
258
|
+
</FormLabel>
|
|
259
|
+
)}
|
|
260
|
+
<FormControl>
|
|
261
|
+
<Textarea {...textareaProps} {...field} />
|
|
262
|
+
</FormControl>
|
|
263
|
+
{description && <FormDescription>{description}</FormDescription>}
|
|
264
|
+
<FormMessage />
|
|
265
|
+
</FormItem>
|
|
266
|
+
)}
|
|
267
|
+
/>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface SelectFieldOption {
|
|
272
|
+
value: string;
|
|
273
|
+
label: string;
|
|
274
|
+
disabled?: boolean;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interface SelectFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>
|
|
278
|
+
extends FormFieldBaseProps<TFieldValues, TName> {
|
|
279
|
+
options: SelectFieldOption[];
|
|
280
|
+
placeholder?: string;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function SelectField<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({
|
|
284
|
+
control,
|
|
285
|
+
name,
|
|
286
|
+
rules,
|
|
287
|
+
required,
|
|
288
|
+
label,
|
|
289
|
+
description,
|
|
290
|
+
tooltip,
|
|
291
|
+
options,
|
|
292
|
+
placeholder,
|
|
293
|
+
}: SelectFieldProps<TFieldValues, TName>) {
|
|
294
|
+
return (
|
|
295
|
+
<FormField
|
|
296
|
+
control={control}
|
|
297
|
+
name={name}
|
|
298
|
+
rules={rules}
|
|
299
|
+
render={({ field }) => (
|
|
300
|
+
<FormItem>
|
|
301
|
+
{label && (
|
|
302
|
+
<FormLabel required={required} tooltip={tooltip}>
|
|
303
|
+
{label}
|
|
304
|
+
</FormLabel>
|
|
305
|
+
)}
|
|
306
|
+
<Select value={field.value} onValueChange={field.onChange}>
|
|
307
|
+
<FormControl>
|
|
308
|
+
<SelectTrigger>
|
|
309
|
+
<SelectValue placeholder={placeholder} />
|
|
310
|
+
</SelectTrigger>
|
|
311
|
+
</FormControl>
|
|
312
|
+
<SelectContent>
|
|
313
|
+
{options.map((option) => (
|
|
314
|
+
<SelectItem key={option.value} value={option.value} disabled={option.disabled}>
|
|
315
|
+
{option.label}
|
|
316
|
+
</SelectItem>
|
|
317
|
+
))}
|
|
318
|
+
</SelectContent>
|
|
319
|
+
</Select>
|
|
320
|
+
{description && <FormDescription>{description}</FormDescription>}
|
|
321
|
+
<FormMessage />
|
|
322
|
+
</FormItem>
|
|
323
|
+
)}
|
|
324
|
+
/>
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export type { SelectFieldOption };
|
|
329
|
+
export {
|
|
330
|
+
Form,
|
|
331
|
+
FormControl,
|
|
332
|
+
FormDescription,
|
|
333
|
+
FormField,
|
|
334
|
+
FormFields,
|
|
335
|
+
FormHeader,
|
|
336
|
+
FormItem,
|
|
337
|
+
FormLabel,
|
|
338
|
+
FormMessage,
|
|
339
|
+
InputField,
|
|
340
|
+
SelectField,
|
|
341
|
+
TextareaField,
|
|
342
|
+
useFormField,
|
|
343
|
+
};
|
package/src/components/input.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { Info } from "lucide-react";
|
|
3
4
|
import * as React from "react";
|
|
4
5
|
|
|
5
6
|
import { cn } from "../lib/cn";
|
|
6
7
|
import { Label } from "./label";
|
|
8
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
|
|
7
9
|
|
|
8
10
|
const inputSizeStyles = {
|
|
9
11
|
sm: {
|
|
@@ -29,6 +31,7 @@ interface InputProps extends Omit<React.ComponentProps<"input">, "size"> {
|
|
|
29
31
|
required?: boolean;
|
|
30
32
|
hint?: string;
|
|
31
33
|
error?: string;
|
|
34
|
+
tooltip?: string;
|
|
32
35
|
leadingText?: string;
|
|
33
36
|
leadingIcon?: React.ReactNode;
|
|
34
37
|
size?: "sm" | "md";
|
|
@@ -41,6 +44,7 @@ function Input({
|
|
|
41
44
|
required,
|
|
42
45
|
hint,
|
|
43
46
|
error,
|
|
47
|
+
tooltip,
|
|
44
48
|
leadingText,
|
|
45
49
|
leadingIcon,
|
|
46
50
|
size = "md",
|
|
@@ -126,6 +130,14 @@ function Input({
|
|
|
126
130
|
*
|
|
127
131
|
</span>
|
|
128
132
|
)}
|
|
133
|
+
{tooltip && (
|
|
134
|
+
<Tooltip>
|
|
135
|
+
<TooltipTrigger asChild>
|
|
136
|
+
<Info className="size-4 text-muted-foreground" />
|
|
137
|
+
</TooltipTrigger>
|
|
138
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
139
|
+
</Tooltip>
|
|
140
|
+
)}
|
|
129
141
|
</div>
|
|
130
142
|
)}
|
|
131
143
|
{wrappedInput}
|
|
@@ -12,6 +12,7 @@ export const selectTriggerVariants = cva(
|
|
|
12
12
|
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
13
13
|
"data-[state=open]:ring-2 data-[state=open]:ring-ring data-[state=open]:ring-offset-2 data-[state=open]:ring-offset-background",
|
|
14
14
|
"disabled:pointer-events-none disabled:bg-disabled disabled:text-disabled-foreground disabled:border-disabled",
|
|
15
|
+
"aria-invalid:border-border-error",
|
|
15
16
|
"[&_svg:not([class*='size-'])]:size-5 [&_svg]:shrink-0",
|
|
16
17
|
].join(" "),
|
|
17
18
|
{
|