@opencosmos/ui 1.3.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/.claude/CLAUDE.md +239 -0
- package/README.md +161 -0
- package/dist/cli.mjs +151 -0
- package/dist/dates.d.mts +20 -0
- package/dist/dates.d.ts +20 -0
- package/dist/dates.js +240 -0
- package/dist/dates.js.map +1 -0
- package/dist/dates.mjs +203 -0
- package/dist/dates.mjs.map +1 -0
- package/dist/dnd.d.mts +126 -0
- package/dist/dnd.d.ts +126 -0
- package/dist/dnd.js +274 -0
- package/dist/dnd.js.map +1 -0
- package/dist/dnd.mjs +250 -0
- package/dist/dnd.mjs.map +1 -0
- package/dist/fontThemes-Dh8mtXES.d.mts +868 -0
- package/dist/fontThemes-Dh8mtXES.d.ts +868 -0
- package/dist/forms.d.mts +38 -0
- package/dist/forms.d.ts +38 -0
- package/dist/forms.js +198 -0
- package/dist/forms.js.map +1 -0
- package/dist/forms.mjs +159 -0
- package/dist/forms.mjs.map +1 -0
- package/dist/hooks-1b8WaQf1.d.mts +225 -0
- package/dist/hooks-CKW8vE9H.d.ts +225 -0
- package/dist/hooks.d.mts +3 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +971 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hooks.mjs +943 -0
- package/dist/hooks.mjs.map +1 -0
- package/dist/index-DscTIrZ2.d.mts +29 -0
- package/dist/index-DscTIrZ2.d.ts +29 -0
- package/dist/index.d.mts +3382 -0
- package/dist/index.d.ts +3382 -0
- package/dist/index.js +15146 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14802 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers-CXPDMsl7.d.mts +30 -0
- package/dist/providers-Dn_Msjvz.d.ts +30 -0
- package/dist/providers.d.mts +3 -0
- package/dist/providers.d.ts +3 -0
- package/dist/providers.js +1885 -0
- package/dist/providers.js.map +1 -0
- package/dist/providers.mjs +1859 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/tables.d.mts +10 -0
- package/dist/tables.d.ts +10 -0
- package/dist/tables.js +248 -0
- package/dist/tables.js.map +1 -0
- package/dist/tables.mjs +218 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tokens.d.mts +1065 -0
- package/dist/tokens.d.ts +1065 -0
- package/dist/tokens.js +2637 -0
- package/dist/tokens.js.map +1 -0
- package/dist/tokens.mjs +2555 -0
- package/dist/tokens.mjs.map +1 -0
- package/dist/utils-CIIM7dAC.d.ts +986 -0
- package/dist/utils-Cs04sxth.d.mts +986 -0
- package/dist/utils.d.mts +4 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +874 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +806 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/validation-Bj1ye-v_.d.mts +114 -0
- package/dist/validation-Bj1ye-v_.d.ts +114 -0
- package/dist/webgl.d.mts +104 -0
- package/dist/webgl.d.ts +104 -0
- package/dist/webgl.js +226 -0
- package/dist/webgl.js.map +1 -0
- package/dist/webgl.mjs +195 -0
- package/dist/webgl.mjs.map +1 -0
- package/package.json +267 -0
- package/src/cli.ts +206 -0
- package/src/component-registry.ts +183 -0
- package/src/components/actions/Button.test.tsx +61 -0
- package/src/components/actions/Button.tsx +70 -0
- package/src/components/actions/Link.tsx +78 -0
- package/src/components/actions/Magnetic.tsx +68 -0
- package/src/components/actions/Toggle.test.tsx +40 -0
- package/src/components/actions/Toggle.tsx +47 -0
- package/src/components/actions/ToggleGroup.tsx +70 -0
- package/src/components/actions/index.ts +5 -0
- package/src/components/backgrounds/FaultyTerminal.tsx +426 -0
- package/src/components/backgrounds/OrbBackground.tsx +424 -0
- package/src/components/backgrounds/WarpBackground.tsx +358 -0
- package/src/components/backgrounds/index.ts +3 -0
- package/src/components/blocks/Hero.tsx +142 -0
- package/src/components/blocks/social/OpenGraphCard.tsx +243 -0
- package/src/components/cursor/SplashCursor.tsx +1315 -0
- package/src/components/cursor/TargetCursor.tsx +187 -0
- package/src/components/cursor/index.ts +2 -0
- package/src/components/data-display/AspectImage.tsx +73 -0
- package/src/components/data-display/Avatar.test.tsx +35 -0
- package/src/components/data-display/Avatar.tsx +55 -0
- package/src/components/data-display/Badge.test.tsx +43 -0
- package/src/components/data-display/Badge.tsx +84 -0
- package/src/components/data-display/Brand.tsx +123 -0
- package/src/components/data-display/Calendar.tsx +70 -0
- package/src/components/data-display/Card.test.tsx +92 -0
- package/src/components/data-display/Card.tsx +115 -0
- package/src/components/data-display/Code.tsx +210 -0
- package/src/components/data-display/CollapsibleCodeBlock.tsx +238 -0
- package/src/components/data-display/DataTable.tsx +119 -0
- package/src/components/data-display/DescriptionList.tsx +41 -0
- package/src/components/data-display/GitHubIcon.tsx +44 -0
- package/src/components/data-display/Heading.test.tsx +36 -0
- package/src/components/data-display/Heading.tsx +83 -0
- package/src/components/data-display/StatCard.tsx +195 -0
- package/src/components/data-display/Table.tsx +133 -0
- package/src/components/data-display/Text.test.tsx +48 -0
- package/src/components/data-display/Text.tsx +144 -0
- package/src/components/data-display/Timeline.tsx +194 -0
- package/src/components/data-display/TreeView.tsx +226 -0
- package/src/components/data-display/Typewriter.tsx +119 -0
- package/src/components/data-display/VariableWeightText.tsx +130 -0
- package/src/components/data-display/index.ts +19 -0
- package/src/components/feedback/Alert.test.tsx +44 -0
- package/src/components/feedback/Alert.tsx +65 -0
- package/src/components/feedback/EmptyState.tsx +113 -0
- package/src/components/feedback/Progress.test.tsx +60 -0
- package/src/components/feedback/Progress.tsx +30 -0
- package/src/components/feedback/ProgressBar.tsx +158 -0
- package/src/components/feedback/Skeleton.test.tsx +39 -0
- package/src/components/feedback/Skeleton.tsx +45 -0
- package/src/components/feedback/Sonner.tsx +28 -0
- package/src/components/feedback/Spinner.test.tsx +33 -0
- package/src/components/feedback/Spinner.tsx +99 -0
- package/src/components/feedback/Stepper.tsx +307 -0
- package/src/components/feedback/Toast/Toast.tsx +243 -0
- package/src/components/feedback/Toast/index.ts +2 -0
- package/src/components/feedback/index.ts +9 -0
- package/src/components/forms/Checkbox.test.tsx +40 -0
- package/src/components/forms/Checkbox.tsx +31 -0
- package/src/components/forms/ColorPicker.tsx +118 -0
- package/src/components/forms/Combobox.tsx +96 -0
- package/src/components/forms/DragDrop.tsx +440 -0
- package/src/components/forms/FileUpload.tsx +252 -0
- package/src/components/forms/FilterButton.tsx +65 -0
- package/src/components/forms/Form.tsx +197 -0
- package/src/components/forms/Input.test.tsx +46 -0
- package/src/components/forms/Input.tsx +43 -0
- package/src/components/forms/InputOTP.tsx +81 -0
- package/src/components/forms/Label.test.tsx +20 -0
- package/src/components/forms/Label.tsx +25 -0
- package/src/components/forms/RadioGroup.tsx +51 -0
- package/src/components/forms/SearchBar.tsx +215 -0
- package/src/components/forms/Select.test.tsx +118 -0
- package/src/components/forms/Select.tsx +274 -0
- package/src/components/forms/Slider.tsx +29 -0
- package/src/components/forms/Switch.test.tsx +76 -0
- package/src/components/forms/Switch.tsx +30 -0
- package/src/components/forms/TextField.tsx +152 -0
- package/src/components/forms/Textarea.test.tsx +41 -0
- package/src/components/forms/Textarea.tsx +29 -0
- package/src/components/forms/ThemeSwitcher.tsx +290 -0
- package/src/components/forms/ThemeToggle.tsx +151 -0
- package/src/components/forms/index.ts +19 -0
- package/src/components/layout/Accordion.test.tsx +66 -0
- package/src/components/layout/Accordion.tsx +64 -0
- package/src/components/layout/AspectRatio.tsx +7 -0
- package/src/components/layout/Carousel.tsx +277 -0
- package/src/components/layout/Collapsible.test.tsx +40 -0
- package/src/components/layout/Collapsible.tsx +31 -0
- package/src/components/layout/Container.test.tsx +45 -0
- package/src/components/layout/Container.tsx +99 -0
- package/src/components/layout/CustomizerPanel.tsx +400 -0
- package/src/components/layout/DatePicker.tsx +57 -0
- package/src/components/layout/Footer/Footer.tsx +175 -0
- package/src/components/layout/Footer/index.ts +2 -0
- package/src/components/layout/GlassSurface.tsx +82 -0
- package/src/components/layout/Grid.test.tsx +31 -0
- package/src/components/layout/Grid.tsx +130 -0
- package/src/components/layout/Header/Header.tsx +450 -0
- package/src/components/layout/Header/index.ts +2 -0
- package/src/components/layout/PageLayout.tsx +180 -0
- package/src/components/layout/PageTemplate.tsx +158 -0
- package/src/components/layout/Resizable.tsx +48 -0
- package/src/components/layout/ScrollArea.tsx +53 -0
- package/src/components/layout/Separator.test.tsx +28 -0
- package/src/components/layout/Separator.tsx +29 -0
- package/src/components/layout/Sidebar.tsx +171 -0
- package/src/components/layout/Stack.test.tsx +41 -0
- package/src/components/layout/Stack.tsx +89 -0
- package/src/components/layout/glass-surface.css +60 -0
- package/src/components/layout/index.ts +18 -0
- package/src/components/motion/AnimatedBeam.tsx +159 -0
- package/src/components/navigation/Breadcrumb.test.tsx +57 -0
- package/src/components/navigation/Breadcrumb.tsx +119 -0
- package/src/components/navigation/Breadcrumbs.tsx +221 -0
- package/src/components/navigation/Command.tsx +159 -0
- package/src/components/navigation/Menubar.tsx +115 -0
- package/src/components/navigation/NavLink.tsx +55 -0
- package/src/components/navigation/NavigationMenu.tsx +125 -0
- package/src/components/navigation/Pagination.tsx +121 -0
- package/src/components/navigation/SecondaryNav.tsx +100 -0
- package/src/components/navigation/Tabs.test.tsx +47 -0
- package/src/components/navigation/Tabs.tsx +60 -0
- package/src/components/navigation/TertiaryNav.tsx +90 -0
- package/src/components/navigation/index.ts +10 -0
- package/src/components/overlays/AlertDialog.test.tsx +69 -0
- package/src/components/overlays/AlertDialog.tsx +166 -0
- package/src/components/overlays/ContextMenu.tsx +243 -0
- package/src/components/overlays/Dialog.test.tsx +79 -0
- package/src/components/overlays/Dialog.tsx +158 -0
- package/src/components/overlays/Drawer.tsx +128 -0
- package/src/components/overlays/Dropdown.tsx +253 -0
- package/src/components/overlays/DropdownMenu.tsx +242 -0
- package/src/components/overlays/HoverCard.tsx +32 -0
- package/src/components/overlays/Modal.tsx +250 -0
- package/src/components/overlays/NotificationCenter.tsx +364 -0
- package/src/components/overlays/Popover.test.tsx +40 -0
- package/src/components/overlays/Popover.tsx +46 -0
- package/src/components/overlays/Sheet.tsx +163 -0
- package/src/components/overlays/Tooltip.test.tsx +33 -0
- package/src/components/overlays/Tooltip.tsx +32 -0
- package/src/components/overlays/index.ts +12 -0
- package/src/dates.ts +2 -0
- package/src/dnd.ts +1 -0
- package/src/forms.ts +1 -0
- package/src/globals.css +187 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useForm.ts +247 -0
- package/src/hooks/useMotionPreference.test.ts +102 -0
- package/src/hooks/useMotionPreference.ts +78 -0
- package/src/hooks/useTheme.ts +58 -0
- package/src/hooks.ts +9 -0
- package/src/index.ts +168 -0
- package/src/lib/animations.ts +356 -0
- package/src/lib/breadcrumbs.ts +94 -0
- package/src/lib/colors.ts +493 -0
- package/src/lib/store/customizer.ts +482 -0
- package/src/lib/store/index.ts +3 -0
- package/src/lib/store/theme.ts +55 -0
- package/src/lib/syntax-parser/index.ts +50 -0
- package/src/lib/syntax-parser/patterns.ts +64 -0
- package/src/lib/syntax-parser/tokenizer.ts +117 -0
- package/src/lib/syntax-parser/types.ts +27 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validation.ts +204 -0
- package/src/lib/webgl/Color.ts +11 -0
- package/src/lib/webgl/Mesh.ts +41 -0
- package/src/lib/webgl/Program.ts +118 -0
- package/src/lib/webgl/Renderer.ts +51 -0
- package/src/lib/webgl/Triangle.ts +27 -0
- package/src/lib/webgl/Vec3.ts +18 -0
- package/src/lib/webgl/index.ts +13 -0
- package/src/nativewind-env.d.ts +1 -0
- package/src/providers/ThemeProvider.tsx +461 -0
- package/src/providers/index.ts +1 -0
- package/src/providers.ts +7 -0
- package/src/tables.ts +1 -0
- package/src/test/setup.ts +39 -0
- package/src/theme.css +158 -0
- package/src/tokens.ts +7 -0
- package/src/utils.ts +12 -0
- package/src/webgl.ts +1 -0
package/dist/forms.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FormProvider, FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
6
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
7
|
+
|
|
8
|
+
declare const Form: typeof FormProvider;
|
|
9
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare const useFormField: () => {
|
|
11
|
+
invalid: boolean;
|
|
12
|
+
isDirty: boolean;
|
|
13
|
+
isTouched: boolean;
|
|
14
|
+
isValidating: boolean;
|
|
15
|
+
error?: react_hook_form.FieldError;
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
formItemId: string;
|
|
19
|
+
formDescriptionId: string;
|
|
20
|
+
formMessageId: string;
|
|
21
|
+
};
|
|
22
|
+
declare const FormItem: ({ ref, className, ...props }: React.HTMLAttributes<HTMLDivElement> & {
|
|
23
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
24
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
25
|
+
declare const FormLabel: ({ ref, className, ...props }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {
|
|
26
|
+
ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;
|
|
27
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
28
|
+
declare const FormControl: ({ ref, ...props }: React.ComponentPropsWithoutRef<typeof Slot> & {
|
|
29
|
+
ref?: React.Ref<React.ElementRef<typeof Slot>>;
|
|
30
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
31
|
+
declare const FormDescription: ({ ref, className, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
32
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
33
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare const FormMessage: ({ ref, className, children, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
35
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
36
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
37
|
+
|
|
38
|
+
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField };
|
package/dist/forms.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FormProvider, FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
6
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
7
|
+
|
|
8
|
+
declare const Form: typeof FormProvider;
|
|
9
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare const useFormField: () => {
|
|
11
|
+
invalid: boolean;
|
|
12
|
+
isDirty: boolean;
|
|
13
|
+
isTouched: boolean;
|
|
14
|
+
isValidating: boolean;
|
|
15
|
+
error?: react_hook_form.FieldError;
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
formItemId: string;
|
|
19
|
+
formDescriptionId: string;
|
|
20
|
+
formMessageId: string;
|
|
21
|
+
};
|
|
22
|
+
declare const FormItem: ({ ref, className, ...props }: React.HTMLAttributes<HTMLDivElement> & {
|
|
23
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
24
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
25
|
+
declare const FormLabel: ({ ref, className, ...props }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {
|
|
26
|
+
ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;
|
|
27
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
28
|
+
declare const FormControl: ({ ref, ...props }: React.ComponentPropsWithoutRef<typeof Slot> & {
|
|
29
|
+
ref?: React.Ref<React.ElementRef<typeof Slot>>;
|
|
30
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
31
|
+
declare const FormDescription: ({ ref, className, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
32
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
33
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare const FormMessage: ({ ref, className, children, ...props }: React.HTMLAttributes<HTMLParagraphElement> & {
|
|
35
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
36
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
37
|
+
|
|
38
|
+
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField };
|
package/dist/forms.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/forms.ts
|
|
32
|
+
var forms_exports = {};
|
|
33
|
+
__export(forms_exports, {
|
|
34
|
+
Form: () => Form,
|
|
35
|
+
FormControl: () => FormControl,
|
|
36
|
+
FormDescription: () => FormDescription,
|
|
37
|
+
FormField: () => FormField,
|
|
38
|
+
FormItem: () => FormItem,
|
|
39
|
+
FormLabel: () => FormLabel,
|
|
40
|
+
FormMessage: () => FormMessage,
|
|
41
|
+
useFormField: () => useFormField
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(forms_exports);
|
|
44
|
+
|
|
45
|
+
// src/components/forms/Form.tsx
|
|
46
|
+
var React = __toESM(require("react"));
|
|
47
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
|
48
|
+
var import_react_hook_form = require("react-hook-form");
|
|
49
|
+
|
|
50
|
+
// src/lib/utils.ts
|
|
51
|
+
var import_clsx = require("clsx");
|
|
52
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
53
|
+
function cn(...inputs) {
|
|
54
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/components/forms/Label.tsx
|
|
58
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
59
|
+
var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
|
|
60
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
|
+
var labelVariants = (0, import_class_variance_authority.cva)(
|
|
62
|
+
"block mb-1.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
63
|
+
);
|
|
64
|
+
var Label = ({
|
|
65
|
+
ref,
|
|
66
|
+
className,
|
|
67
|
+
...props
|
|
68
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
+
LabelPrimitive.Root,
|
|
70
|
+
{
|
|
71
|
+
ref,
|
|
72
|
+
className: cn(labelVariants(), className),
|
|
73
|
+
...props
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// src/components/forms/Form.tsx
|
|
78
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
79
|
+
var Form = import_react_hook_form.FormProvider;
|
|
80
|
+
var FormFieldContext = React.createContext(
|
|
81
|
+
{}
|
|
82
|
+
);
|
|
83
|
+
var FormField = ({
|
|
84
|
+
...props
|
|
85
|
+
}) => {
|
|
86
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_hook_form.Controller, { ...props }) });
|
|
87
|
+
};
|
|
88
|
+
var useFormField = () => {
|
|
89
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
90
|
+
const itemContext = React.useContext(FormItemContext);
|
|
91
|
+
const { getFieldState, formState } = (0, import_react_hook_form.useFormContext)();
|
|
92
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
93
|
+
if (!fieldContext) {
|
|
94
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
95
|
+
}
|
|
96
|
+
const { id } = itemContext;
|
|
97
|
+
return {
|
|
98
|
+
id,
|
|
99
|
+
name: fieldContext.name,
|
|
100
|
+
formItemId: `${id}-form-item`,
|
|
101
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
102
|
+
formMessageId: `${id}-form-item-message`,
|
|
103
|
+
...fieldState
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
var FormItemContext = React.createContext(
|
|
107
|
+
{}
|
|
108
|
+
);
|
|
109
|
+
var FormItem = ({
|
|
110
|
+
ref,
|
|
111
|
+
className,
|
|
112
|
+
...props
|
|
113
|
+
}) => {
|
|
114
|
+
const id = React.useId();
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
116
|
+
};
|
|
117
|
+
var FormLabel = ({
|
|
118
|
+
ref,
|
|
119
|
+
className,
|
|
120
|
+
...props
|
|
121
|
+
}) => {
|
|
122
|
+
const { error, formItemId } = useFormField();
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
124
|
+
Label,
|
|
125
|
+
{
|
|
126
|
+
ref,
|
|
127
|
+
className: cn(error && "text-destructive", className),
|
|
128
|
+
htmlFor: formItemId,
|
|
129
|
+
...props
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
var FormControl = ({
|
|
134
|
+
ref,
|
|
135
|
+
...props
|
|
136
|
+
}) => {
|
|
137
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
138
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
139
|
+
import_react_slot.Slot,
|
|
140
|
+
{
|
|
141
|
+
ref,
|
|
142
|
+
id: formItemId,
|
|
143
|
+
"aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
|
|
144
|
+
"aria-invalid": !!error,
|
|
145
|
+
...props
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
var FormDescription = ({
|
|
150
|
+
ref,
|
|
151
|
+
className,
|
|
152
|
+
...props
|
|
153
|
+
}) => {
|
|
154
|
+
const { formDescriptionId } = useFormField();
|
|
155
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
156
|
+
"p",
|
|
157
|
+
{
|
|
158
|
+
ref,
|
|
159
|
+
id: formDescriptionId,
|
|
160
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
161
|
+
...props
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
var FormMessage = ({
|
|
166
|
+
ref,
|
|
167
|
+
className,
|
|
168
|
+
children,
|
|
169
|
+
...props
|
|
170
|
+
}) => {
|
|
171
|
+
const { error, formMessageId } = useFormField();
|
|
172
|
+
const body = error ? String(error?.message) : children;
|
|
173
|
+
if (!body) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
177
|
+
"p",
|
|
178
|
+
{
|
|
179
|
+
ref,
|
|
180
|
+
id: formMessageId,
|
|
181
|
+
className: cn("text-sm font-medium text-destructive", className),
|
|
182
|
+
...props,
|
|
183
|
+
children: body
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
Form,
|
|
190
|
+
FormControl,
|
|
191
|
+
FormDescription,
|
|
192
|
+
FormField,
|
|
193
|
+
FormItem,
|
|
194
|
+
FormLabel,
|
|
195
|
+
FormMessage,
|
|
196
|
+
useFormField
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=forms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/forms.ts","../src/components/forms/Form.tsx","../src/lib/utils.ts","../src/components/forms/Label.tsx"],"sourcesContent":["export * from './components/forms/Form';\n","\"use client\";\nimport * as React from \"react\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { Slot } from \"@radix-ui/react-slot\"\nimport {\n Controller,\n ControllerProps,\n FieldPath,\n FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\"\n\nimport { cn } from \"../../lib/utils\"\nimport { Label } from \"./Label\"\n\nconst Form: typeof FormProvider = FormProvider\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = {\n name: TName\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue>(\n {} as FormFieldContextValue\n)\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n )\n}\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext)\n const itemContext = React.useContext(FormItemContext)\n const { getFieldState, formState } = useFormContext()\n\n const fieldState = getFieldState(fieldContext.name, formState)\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\")\n }\n\n const { id } = itemContext\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n }\n}\n\ntype FormItemContextValue = {\n id: string\n}\n\nconst FormItemContext = React.createContext<FormItemContextValue>(\n {} as FormItemContextValue\n)\n\nconst FormItem = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n }\n) => {\n const id = React.useId()\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-2\", className)} {...props} />\n </FormItemContext.Provider>\n )\n}\n\nconst FormLabel = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => {\n const { error, formItemId } = useFormField()\n\n return (\n <Label\n ref={ref}\n className={cn(error && \"text-destructive\", className)}\n htmlFor={formItemId}\n {...props}\n />\n )\n}\n\nconst FormControl = (\n {\n ref,\n ...props\n }: React.ComponentPropsWithoutRef<typeof Slot> & {\n ref?: React.Ref<React.ElementRef<typeof Slot>>;\n }\n) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField()\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={\n !error\n ? `${formDescriptionId}`\n : `${formDescriptionId} ${formMessageId}`\n }\n aria-invalid={!!error}\n {...props}\n />\n )\n}\n\nconst FormDescription = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { formDescriptionId } = useFormField()\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm text-muted-foreground\", className)}\n {...props}\n />\n )\n}\n\nconst FormMessage = (\n {\n ref,\n className,\n children,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { error, formMessageId } = useFormField()\n const body = error ? String(error?.message) : children\n\n if (!body) {\n return null\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n )\n}\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { cn } from \"../../lib/utils\"\n\nconst labelVariants = cva(\n \"block mb-1.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n)\n\nconst Label = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &\n VariantProps<typeof labelVariants> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => (<LabelPrimitive.Root\n ref={ref}\n className={cn(labelVariants(), className)}\n {...props}\n/>)\n\nexport { Label, labelVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,YAAuB;AAEvB,wBAAqB;AACrB,6BAOO;;;ACXP,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AACxC,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC/B;;;ACJA,sCAAuC;AACvC,qBAAgC;AAgB1B;AAbN,IAAM,oBAAgB;AAAA,EAClB;AACJ;AAEA,IAAM,QAAQ,CACV;AAAA,EACI;AAAA,EACA;AAAA,EACA,GAAG;AACP,MAIE;AAAA,EAAgB;AAAA,EAAf;AAAA,IACH;AAAA,IACA,WAAW,GAAG,cAAc,GAAG,SAAS;AAAA,IACvC,GAAG;AAAA;AACR;;;AFeM,IAAAA,sBAAA;AArBN,IAAM,OAA4B;AASlC,IAAM,mBAAyB;AAAA,EAC7B,CAAC;AACH;AAEA,IAAM,YAAY,CAGhB;AAAA,EACA,GAAG;AACL,MAA4C;AAC1C,SACE,6CAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,MAAM,MAAM,KAAK,GACnD,uDAAC,qCAAY,GAAG,OAAO,GACzB;AAEJ;AAEA,IAAM,eAAe,MAAM;AACzB,QAAM,eAAqB,iBAAW,gBAAgB;AACtD,QAAM,cAAoB,iBAAW,eAAe;AACpD,QAAM,EAAE,eAAe,UAAU,QAAI,uCAAe;AAEpD,QAAM,aAA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AGG;AACH,QAAM,EAAE,kBAAkB,IAAI,aAAa;AAE3C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,IAAI;AAAA,MACJ,WAAW,GAAG,iCAAiC,SAAS;AAAA,MACvD,GAAG;AAAA;AAAA,EACN;AAEJ;AAEA,IAAM,cAAc,CAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAGG;AACH,QAAM,EAAE,OAAO,cAAc,IAAI,aAAa;AAC9C,QAAM,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI;AAE9C,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,IAAI;AAAA,MACJ,WAAW,GAAG,wCAAwC,SAAS;AAAA,MAC9D,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":["import_jsx_runtime"]}
|
package/dist/forms.mjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/forms/Form.tsx
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
6
|
+
import {
|
|
7
|
+
Controller,
|
|
8
|
+
FormProvider,
|
|
9
|
+
useFormContext
|
|
10
|
+
} from "react-hook-form";
|
|
11
|
+
|
|
12
|
+
// src/lib/utils.ts
|
|
13
|
+
import { clsx } from "clsx";
|
|
14
|
+
import { twMerge } from "tailwind-merge";
|
|
15
|
+
function cn(...inputs) {
|
|
16
|
+
return twMerge(clsx(inputs));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/components/forms/Label.tsx
|
|
20
|
+
import { cva } from "class-variance-authority";
|
|
21
|
+
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
22
|
+
import { jsx } from "react/jsx-runtime";
|
|
23
|
+
var labelVariants = cva(
|
|
24
|
+
"block mb-1.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
25
|
+
);
|
|
26
|
+
var Label = ({
|
|
27
|
+
ref,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}) => /* @__PURE__ */ jsx(
|
|
31
|
+
LabelPrimitive.Root,
|
|
32
|
+
{
|
|
33
|
+
ref,
|
|
34
|
+
className: cn(labelVariants(), className),
|
|
35
|
+
...props
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// src/components/forms/Form.tsx
|
|
40
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
41
|
+
var Form = FormProvider;
|
|
42
|
+
var FormFieldContext = React.createContext(
|
|
43
|
+
{}
|
|
44
|
+
);
|
|
45
|
+
var FormField = ({
|
|
46
|
+
...props
|
|
47
|
+
}) => {
|
|
48
|
+
return /* @__PURE__ */ jsx2(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx2(Controller, { ...props }) });
|
|
49
|
+
};
|
|
50
|
+
var useFormField = () => {
|
|
51
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
52
|
+
const itemContext = React.useContext(FormItemContext);
|
|
53
|
+
const { getFieldState, formState } = useFormContext();
|
|
54
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
55
|
+
if (!fieldContext) {
|
|
56
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
57
|
+
}
|
|
58
|
+
const { id } = itemContext;
|
|
59
|
+
return {
|
|
60
|
+
id,
|
|
61
|
+
name: fieldContext.name,
|
|
62
|
+
formItemId: `${id}-form-item`,
|
|
63
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
64
|
+
formMessageId: `${id}-form-item-message`,
|
|
65
|
+
...fieldState
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var FormItemContext = React.createContext(
|
|
69
|
+
{}
|
|
70
|
+
);
|
|
71
|
+
var FormItem = ({
|
|
72
|
+
ref,
|
|
73
|
+
className,
|
|
74
|
+
...props
|
|
75
|
+
}) => {
|
|
76
|
+
const id = React.useId();
|
|
77
|
+
return /* @__PURE__ */ jsx2(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx2("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
78
|
+
};
|
|
79
|
+
var FormLabel = ({
|
|
80
|
+
ref,
|
|
81
|
+
className,
|
|
82
|
+
...props
|
|
83
|
+
}) => {
|
|
84
|
+
const { error, formItemId } = useFormField();
|
|
85
|
+
return /* @__PURE__ */ jsx2(
|
|
86
|
+
Label,
|
|
87
|
+
{
|
|
88
|
+
ref,
|
|
89
|
+
className: cn(error && "text-destructive", className),
|
|
90
|
+
htmlFor: formItemId,
|
|
91
|
+
...props
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
var FormControl = ({
|
|
96
|
+
ref,
|
|
97
|
+
...props
|
|
98
|
+
}) => {
|
|
99
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
100
|
+
return /* @__PURE__ */ jsx2(
|
|
101
|
+
Slot,
|
|
102
|
+
{
|
|
103
|
+
ref,
|
|
104
|
+
id: formItemId,
|
|
105
|
+
"aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
|
|
106
|
+
"aria-invalid": !!error,
|
|
107
|
+
...props
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
var FormDescription = ({
|
|
112
|
+
ref,
|
|
113
|
+
className,
|
|
114
|
+
...props
|
|
115
|
+
}) => {
|
|
116
|
+
const { formDescriptionId } = useFormField();
|
|
117
|
+
return /* @__PURE__ */ jsx2(
|
|
118
|
+
"p",
|
|
119
|
+
{
|
|
120
|
+
ref,
|
|
121
|
+
id: formDescriptionId,
|
|
122
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
123
|
+
...props
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
var FormMessage = ({
|
|
128
|
+
ref,
|
|
129
|
+
className,
|
|
130
|
+
children,
|
|
131
|
+
...props
|
|
132
|
+
}) => {
|
|
133
|
+
const { error, formMessageId } = useFormField();
|
|
134
|
+
const body = error ? String(error?.message) : children;
|
|
135
|
+
if (!body) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return /* @__PURE__ */ jsx2(
|
|
139
|
+
"p",
|
|
140
|
+
{
|
|
141
|
+
ref,
|
|
142
|
+
id: formMessageId,
|
|
143
|
+
className: cn("text-sm font-medium text-destructive", className),
|
|
144
|
+
...props,
|
|
145
|
+
children: body
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
export {
|
|
150
|
+
Form,
|
|
151
|
+
FormControl,
|
|
152
|
+
FormDescription,
|
|
153
|
+
FormField,
|
|
154
|
+
FormItem,
|
|
155
|
+
FormLabel,
|
|
156
|
+
FormMessage,
|
|
157
|
+
useFormField
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=forms.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/forms/Form.tsx","../src/lib/utils.ts","../src/components/forms/Label.tsx"],"sourcesContent":["\"use client\";\nimport * as React from \"react\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { Slot } from \"@radix-ui/react-slot\"\nimport {\n Controller,\n ControllerProps,\n FieldPath,\n FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\"\n\nimport { cn } from \"../../lib/utils\"\nimport { Label } from \"./Label\"\n\nconst Form: typeof FormProvider = FormProvider\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = {\n name: TName\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue>(\n {} as FormFieldContextValue\n)\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n )\n}\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext)\n const itemContext = React.useContext(FormItemContext)\n const { getFieldState, formState } = useFormContext()\n\n const fieldState = getFieldState(fieldContext.name, formState)\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\")\n }\n\n const { id } = itemContext\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n }\n}\n\ntype FormItemContextValue = {\n id: string\n}\n\nconst FormItemContext = React.createContext<FormItemContextValue>(\n {} as FormItemContextValue\n)\n\nconst FormItem = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n }\n) => {\n const id = React.useId()\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-2\", className)} {...props} />\n </FormItemContext.Provider>\n )\n}\n\nconst FormLabel = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => {\n const { error, formItemId } = useFormField()\n\n return (\n <Label\n ref={ref}\n className={cn(error && \"text-destructive\", className)}\n htmlFor={formItemId}\n {...props}\n />\n )\n}\n\nconst FormControl = (\n {\n ref,\n ...props\n }: React.ComponentPropsWithoutRef<typeof Slot> & {\n ref?: React.Ref<React.ElementRef<typeof Slot>>;\n }\n) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField()\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={\n !error\n ? `${formDescriptionId}`\n : `${formDescriptionId} ${formMessageId}`\n }\n aria-invalid={!!error}\n {...props}\n />\n )\n}\n\nconst FormDescription = (\n {\n ref,\n className,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { formDescriptionId } = useFormField()\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm text-muted-foreground\", className)}\n {...props}\n />\n )\n}\n\nconst FormMessage = (\n {\n ref,\n className,\n children,\n ...props\n }: React.HTMLAttributes<HTMLParagraphElement> & {\n ref?: React.Ref<HTMLParagraphElement>;\n }\n) => {\n const { error, formMessageId } = useFormField()\n const body = error ? String(error?.message) : children\n\n if (!body) {\n return null\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n )\n}\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { cn } from \"../../lib/utils\"\n\nconst labelVariants = cva(\n \"block mb-1.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n)\n\nconst Label = (\n {\n ref,\n className,\n ...props\n }: React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &\n VariantProps<typeof labelVariants> & {\n ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>;\n }\n) => (<LabelPrimitive.Root\n ref={ref}\n className={cn(labelVariants(), className)}\n {...props}\n/>)\n\nexport { Label, labelVariants }\n"],"mappings":";;;AACA,YAAY,WAAW;AAEvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EAIA;AAAA,EACA;AAAA,OACK;;;ACXP,SAA0B,YAAY;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM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