@codefast/ui 0.0.39 → 0.0.40
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/plugin/animate.plugin.d.mts +9 -0
- package/dist/plugin/animate.plugin.d.ts +9 -0
- package/dist/plugin/base.plugin.d.mts +8 -0
- package/dist/plugin/base.plugin.d.ts +8 -0
- package/dist/plugin/perspective.plugin.d.mts +8 -0
- package/dist/plugin/perspective.plugin.d.ts +8 -0
- package/dist/react/form.js +1 -1
- package/dist/react/form.js.map +1 -1
- package/dist/react/form.mjs +1 -1
- package/dist/react/form.mjs.map +1 -1
- package/dist/tailwind.config.d.mts +5 -0
- package/dist/tailwind.config.d.ts +5 -0
- package/package.json +1 -1
- package/src/react/form.tsx +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as tailwindcss_types_config from 'tailwindcss/types/config';
|
|
2
|
+
import { Config } from 'tailwindcss/types/config';
|
|
3
|
+
|
|
4
|
+
declare const animate: {
|
|
5
|
+
handler: tailwindcss_types_config.PluginCreator;
|
|
6
|
+
config?: Partial<Config> | undefined;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { animate as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as tailwindcss_types_config from 'tailwindcss/types/config';
|
|
2
|
+
import { Config } from 'tailwindcss/types/config';
|
|
3
|
+
|
|
4
|
+
declare const animate: {
|
|
5
|
+
handler: tailwindcss_types_config.PluginCreator;
|
|
6
|
+
config?: Partial<Config> | undefined;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { animate as default };
|
package/dist/react/form.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }"use client";var _chunkFEE6PNWVjs = require('../chunk-FEE6PNWV.js');var _chunkUJJZZCACjs = require('../chunk-UJJZZCAC.js');var _react = require('react'); var t = _interopRequireWildcard(_react);var _reactslot = require('@radix-ui/react-slot');var _reacthookform = require('react-hook-form');var _jsxruntime = require('react/jsx-runtime');var p=t.createContext(null),c=t.createContext(null),n= exports.useFormField =()=>{let e=t.useContext(p),o=t.useContext(c),{getFieldState:r,formState:m}=_reacthookform.useFormContext.call(void 0, );if(!e||!o)throw new Error("useFormField should be used within <FormField>");let s=r(e.name,m),{id:a}=o;return{id:a,name:e.name,formItemId:`form-item-${a}`,formDescriptionId:`form-item-description-${a}`,formMessageId:`form-item-message-${a}`,...s}},M= exports.Form =_reacthookform.FormProvider;function h({...e}){return _jsxruntime.jsx.call(void 0, p.Provider,{value:{name:e.name},children:_jsxruntime.jsx.call(void 0, _reacthookform.Controller,{...e})})}var R=t.forwardRef(({className:e,...o},r)=>{let m=t.useId();return _jsxruntime.jsx.call(void 0, c.Provider,{value:{id:m},children:_jsxruntime.jsx.call(void 0, "div",{ref:r,className:_chunkUJJZZCACjs.b.call(void 0, "space-y-2",e),...o})})});R.displayName="FormItem";var x=t.forwardRef(({className:e,...o},r)=>{let{error:m,formItemId:s}=n();return _jsxruntime.jsx.call(void 0, _chunkFEE6PNWVjs.a,{ref:r,className:_chunkUJJZZCACjs.b.call(void 0, m&&"text-destructive",e),htmlFor:s,...o})});x.displayName="FormLabel";var C=t.forwardRef(({...e},o)=>{let{error:r,formItemId:m,formDescriptionId:s,formMessageId:a}=n();return _jsxruntime.jsx.call(void 0, _reactslot.Slot,{ref:o,id:m,"aria-describedby":r?`${s} ${a}`:s,"aria-invalid":!!r,...e})});C.displayName="FormControl";var I=t.forwardRef(({className:e,...o},r)=>{let{formDescriptionId:m}=n();return _jsxruntime.jsx.call(void 0, "p",{ref:r,id:m,className:_chunkUJJZZCACjs.b.call(void 0, "text-muted-foreground text-xs",e),...o})});I.displayName="FormDescription";var g=t.forwardRef(({children:e,className:o,...r},m)=>{let{error:s,formMessageId:a}=n(),d=s?
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";var _chunkFEE6PNWVjs = require('../chunk-FEE6PNWV.js');var _chunkUJJZZCACjs = require('../chunk-UJJZZCAC.js');var _react = require('react'); var t = _interopRequireWildcard(_react);var _reactslot = require('@radix-ui/react-slot');var _reacthookform = require('react-hook-form');var _jsxruntime = require('react/jsx-runtime');var p=t.createContext(null),c=t.createContext(null),n= exports.useFormField =()=>{let e=t.useContext(p),o=t.useContext(c),{getFieldState:r,formState:m}=_reacthookform.useFormContext.call(void 0, );if(!e||!o)throw new Error("useFormField should be used within <FormField>");let s=r(e.name,m),{id:a}=o;return{id:a,name:e.name,formItemId:`form-item-${a}`,formDescriptionId:`form-item-description-${a}`,formMessageId:`form-item-message-${a}`,...s}},M= exports.Form =_reacthookform.FormProvider;function h({...e}){return _jsxruntime.jsx.call(void 0, p.Provider,{value:{name:e.name},children:_jsxruntime.jsx.call(void 0, _reacthookform.Controller,{...e})})}var R=t.forwardRef(({className:e,...o},r)=>{let m=t.useId();return _jsxruntime.jsx.call(void 0, c.Provider,{value:{id:m},children:_jsxruntime.jsx.call(void 0, "div",{ref:r,className:_chunkUJJZZCACjs.b.call(void 0, "space-y-2",e),...o})})});R.displayName="FormItem";var x=t.forwardRef(({className:e,...o},r)=>{let{error:m,formItemId:s}=n();return _jsxruntime.jsx.call(void 0, _chunkFEE6PNWVjs.a,{ref:r,className:_chunkUJJZZCACjs.b.call(void 0, m&&"text-destructive",e),htmlFor:s,...o})});x.displayName="FormLabel";var C=t.forwardRef(({...e},o)=>{let{error:r,formItemId:m,formDescriptionId:s,formMessageId:a}=n();return _jsxruntime.jsx.call(void 0, _reactslot.Slot,{ref:o,id:m,"aria-describedby":r?`${s} ${a}`:s,"aria-invalid":!!r,...e})});C.displayName="FormControl";var I=t.forwardRef(({className:e,...o},r)=>{let{formDescriptionId:m}=n();return _jsxruntime.jsx.call(void 0, "p",{ref:r,id:m,className:_chunkUJJZZCACjs.b.call(void 0, "text-muted-foreground text-xs",e),...o})});I.displayName="FormDescription";var g=t.forwardRef(({children:e,className:o,...r},m)=>{let{error:s,formMessageId:a}=n(),d=_optionalChain([s, 'optionalAccess', _ => _.message])?s.message:e;return d?_jsxruntime.jsx.call(void 0, "p",{ref:m,id:a,className:_chunkUJJZZCACjs.b.call(void 0, "text-destructive text-xs font-medium",o),...r,children:d}):null});g.displayName="FormMessage";exports.Form = M; exports.FormControl = C; exports.FormDescription = I; exports.FormField = h; exports.FormItem = R; exports.FormLabel = x; exports.FormMessage = g; exports.useFormField = n;
|
|
2
2
|
//# sourceMappingURL=form.js.map
|
package/dist/react/form.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/form.tsx"],"names":["React","Slot","Controller","FormProvider","useFormContext","jsx","FormFieldContext","FormItemContext","useFormField","fieldContext","itemContext","getFieldState","formState","fieldState","id","Form","FormField","props","FormItem","className","ref","cn","FormLabel","error","formItemId","Label","FormControl","formDescriptionId","formMessageId","FormDescription","FormMessage","children","body"],"mappings":"+FAEA,UAAYA,MAAW,QAEvB,OAAS,QAAAC,MAAY,uBACrB,OACE,cAAAC,EAKA,gBAAAC,EACA,kBAAAC,MACK,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G,QAASK,EAAa,GAAGP,EAAO,CACjH,CAAC,EAEDK,EAAU,YAAc,YASxB,IAAMI,EAAoB,aAAiD,CAAC,CAAE,GAAGT,CAAM,EAAGG,IAAQ,CAChG,GAAM,CAAE,MAAAG,EAAO,WAAAC,EAAY,kBAAAG,EAAmB,cAAAC,CAAc,EAAIpB,EAAa,EAE7E,OACEH,EAACJ,EAAA,CACC,IAAKmB,EACL,GAAII,EACJ,mBAAmBD,EAA4B,GAAGI,CAAiB,IAAIC,CAAa,GAAzDD,EAC3B,eAAc,EAAQJ,EACrB,GAAGN,EACN,CAEJ,CAAC,EAEDS,EAAY,YAAc,cAS1B,IAAMG,EAAwB,aAC5B,CAAC,CAAE,UAAAV,EAAW,GAAGF,CAAM,EAAGG,IAAQ,CAChC,GAAM,CAAE,kBAAAO,CAAkB,EAAInB,EAAa,EAE3C,OAAOH,EAAC,KAAE,IAAKe,EAAK,GAAIO,EAAmB,UAAWN,EAAG,gCAAiCF,CAAS,EAAI,GAAGF,EAAO,CACnH,CACF,EAEAY,EAAgB,YAAc,kBAS9B,IAAMC,EAAoB,aAAiD,CAAC,CAAE,SAAAC,EAAU,UAAAZ,EAAW,GAAGF,CAAM,EAAGG,IAAQ,CACrH,GAAM,CAAE,MAAAG,EAAO,cAAAK,CAAc,EAAIpB,EAAa,EACxCwB,EAAOT,
|
|
1
|
+
{"version":3,"sources":["../../src/react/form.tsx"],"names":["React","Slot","Controller","FormProvider","useFormContext","jsx","FormFieldContext","FormItemContext","useFormField","fieldContext","itemContext","getFieldState","formState","fieldState","id","Form","FormField","props","FormItem","className","ref","cn","FormLabel","error","formItemId","Label","FormControl","formDescriptionId","formMessageId","FormDescription","FormMessage","children","body"],"mappings":"+FAEA,UAAYA,MAAW,QAEvB,OAAS,QAAAC,MAAY,uBACrB,OACE,cAAAC,EAKA,gBAAAC,EACA,kBAAAC,MACK,kBA+ED,cAAAC,MAAA,oBA5DN,IAAMC,EAAyB,gBAA4C,IAAI,EAEzEC,EAAw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EAAoB,aAAiD,CAAC,CAAE,GAAGT,CAAM,EAAGG,IAAQ,CAChG,GAAM,CAAE,MAAAG,EAAO,WAAAC,EAAY,kBAAAG,EAAmB,cAAAC,CAAc,EAAIpB,EAAa,EAE7E,OACEH,EAACJ,EAAA,CACC,IAAKmB,EACL,GAAII,EACJ,mBAAmBD,EAA4B,GAAGI,CAAiB,IAAIC,CAAa,GAAzDD,EAC3B,eAAc,EAAQJ,EACrB,GAAGN,EACN,CAEJ,CAAC,EAEDS,EAAY,YAAc,cAS1B,IAAMG,EAAwB,aAC5B,CAAC,CAAE,UAAAV,EAAW,GAAGF,CAAM,EAAGG,IAAQ,CAChC,GAAM,CAAE,kBAAAO,CAAkB,EAAInB,EAAa,EAE3C,OAAOH,EAAC,KAAE,IAAKe,EAAK,GAAIO,EAAmB,UAAWN,EAAG,gCAAiCF,CAAS,EAAI,GAAGF,EAAO,CACnH,CACF,EAEAY,EAAgB,YAAc,kBAS9B,IAAMC,EAAoB,aAAiD,CAAC,CAAE,SAAAC,EAAU,UAAAZ,EAAW,GAAGF,CAAM,EAAGG,IAAQ,CACrH,GAAM,CAAE,MAAAG,EAAO,cAAAK,CAAc,EAAIpB,EAAa,EACxCwB,EAAOT,GAAO,QAAUA,EAAM,QAAUQ,EAE9C,OAAKC,EAKH3B,EAAC,KAAE,IAAKe,EAAK,GAAIQ,EAAe,UAAWP,EAAG,uCAAwCF,CAAS,EAAI,GAAGF,EACnG,SAAAe,EACH,EANO,IAQX,CAAC,EAEDF,EAAY,YAAc","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport type * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n Controller,\n type ControllerProps,\n type FieldError,\n type FieldPath,\n type FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\";\nimport { cn } from \"../lib/utils\";\nimport { Label } from \"./label\";\n\n/* -----------------------------------------------------------------------------\n * Context: Form\n * -------------------------------------------------------------------------- */\n\ninterface FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> {\n name: TName;\n}\n\ninterface FormItemContextValue {\n id: string;\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue | null>(null);\n\nconst FormItemContext = React.createContext<FormItemContextValue | null>(null);\n\nconst useFormField = (): {\n invalid: boolean;\n isDirty: boolean;\n isTouched: boolean;\n isValidating: boolean;\n error?: FieldError | undefined;\n id: string;\n name: string;\n formItemId: string;\n formDescriptionId: string;\n formMessageId: string;\n} => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n if (!fieldContext || !itemContext) {\n throw new Error(\"useFormField should be used within <FormField>\");\n }\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `form-item-${id}`,\n formDescriptionId: `form-item-description-${id}`,\n formMessageId: `form-item-message-${id}`,\n ...fieldState,\n };\n};\n\n/* -----------------------------------------------------------------------------\n * Component: Form\n * -------------------------------------------------------------------------- */\n\ntype FormProps = React.ComponentProps<typeof FormProvider>;\nconst Form = FormProvider;\n\n/* -----------------------------------------------------------------------------\n * Component: FormField\n * -------------------------------------------------------------------------- */\n\ntype FormFieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = ControllerProps<TFieldValues, TName>;\n\nfunction FormField<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({ ...props }: FormFieldProps<TFieldValues, TName>): React.JSX.Element {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n}\n\n/* -----------------------------------------------------------------------------\n * Component: FormItem\n * -------------------------------------------------------------------------- */\n\ntype FormItemElement = HTMLDivElement;\ntype FormItemProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst FormItem = React.forwardRef<FormItemElement, FormItemProps>(({ className, ...props }, ref) => {\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\nFormItem.displayName = \"FormItem\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormLabel\n * -------------------------------------------------------------------------- */\n\ntype FormFieldElement = React.ElementRef<typeof LabelPrimitive.Root>;\ntype FormLabelProps = React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>;\n\nconst FormLabel = React.forwardRef<FormFieldElement, FormLabelProps>(({ className, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return <Label ref={ref} className={cn(error && \"text-destructive\", className)} htmlFor={formItemId} {...props} />;\n});\n\nFormLabel.displayName = \"FormLabel\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormControl\n * -------------------------------------------------------------------------- */\n\ntype FormControlElement = React.ElementRef<typeof Slot>;\ntype FormControlProps = React.ComponentPropsWithoutRef<typeof Slot>;\n\nconst FormControl = React.forwardRef<FormControlElement, FormControlProps>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={!error ? formDescriptionId : `${formDescriptionId} ${formMessageId}`}\n aria-invalid={Boolean(error)}\n {...props}\n />\n );\n});\n\nFormControl.displayName = \"FormControl\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormDescription\n * -------------------------------------------------------------------------- */\n\ntype FormDescriptionElement = HTMLParagraphElement;\ntype FormDescriptionProps = React.HTMLAttributes<HTMLParagraphElement>;\n\nconst FormDescription = React.forwardRef<FormDescriptionElement, FormDescriptionProps>(\n ({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return <p ref={ref} id={formDescriptionId} className={cn(\"text-muted-foreground text-xs\", className)} {...props} />;\n },\n);\n\nFormDescription.displayName = \"FormDescription\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormMessage\n * -------------------------------------------------------------------------- */\n\ntype FormMessageElement = HTMLParagraphElement;\ntype FormMessageProps = React.HTMLAttributes<HTMLParagraphElement>;\n\nconst FormMessage = React.forwardRef<FormMessageElement, FormMessageProps>(({ children, className, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error?.message ? error.message : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p ref={ref} id={formMessageId} className={cn(\"text-destructive text-xs font-medium\", className)} {...props}>\n {body}\n </p>\n );\n});\n\nFormMessage.displayName = \"FormMessage\";\n\n/* -----------------------------------------------------------------------------\n * Exports\n * -------------------------------------------------------------------------- */\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n type FormProps,\n type FormItemProps,\n type FormLabelProps,\n type FormControlProps,\n type FormDescriptionProps,\n type FormMessageProps,\n type FormFieldProps,\n};\n"]}
|
package/dist/react/form.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{a as F}from"../chunk-KJ77RPJ4.mjs";import{b as l}from"../chunk-466PAJCA.mjs";import*as t from"react";import{Slot as u}from"@radix-ui/react-slot";import{Controller as f,FormProvider as P,useFormContext as y}from"react-hook-form";import{jsx as i}from"react/jsx-runtime";var p=t.createContext(null),c=t.createContext(null),n=()=>{let e=t.useContext(p),o=t.useContext(c),{getFieldState:r,formState:m}=y();if(!e||!o)throw new Error("useFormField should be used within <FormField>");let s=r(e.name,m),{id:a}=o;return{id:a,name:e.name,formItemId:`form-item-${a}`,formDescriptionId:`form-item-description-${a}`,formMessageId:`form-item-message-${a}`,...s}},M=P;function h({...e}){return i(p.Provider,{value:{name:e.name},children:i(f,{...e})})}var R=t.forwardRef(({className:e,...o},r)=>{let m=t.useId();return i(c.Provider,{value:{id:m},children:i("div",{ref:r,className:l("space-y-2",e),...o})})});R.displayName="FormItem";var x=t.forwardRef(({className:e,...o},r)=>{let{error:m,formItemId:s}=n();return i(F,{ref:r,className:l(m&&"text-destructive",e),htmlFor:s,...o})});x.displayName="FormLabel";var C=t.forwardRef(({...e},o)=>{let{error:r,formItemId:m,formDescriptionId:s,formMessageId:a}=n();return i(u,{ref:o,id:m,"aria-describedby":r?`${s} ${a}`:s,"aria-invalid":!!r,...e})});C.displayName="FormControl";var I=t.forwardRef(({className:e,...o},r)=>{let{formDescriptionId:m}=n();return i("p",{ref:r,id:m,className:l("text-muted-foreground text-xs",e),...o})});I.displayName="FormDescription";var g=t.forwardRef(({children:e,className:o,...r},m)=>{let{error:s,formMessageId:a}=n(),d=s?
|
|
1
|
+
"use client";import{a as F}from"../chunk-KJ77RPJ4.mjs";import{b as l}from"../chunk-466PAJCA.mjs";import*as t from"react";import{Slot as u}from"@radix-ui/react-slot";import{Controller as f,FormProvider as P,useFormContext as y}from"react-hook-form";import{jsx as i}from"react/jsx-runtime";var p=t.createContext(null),c=t.createContext(null),n=()=>{let e=t.useContext(p),o=t.useContext(c),{getFieldState:r,formState:m}=y();if(!e||!o)throw new Error("useFormField should be used within <FormField>");let s=r(e.name,m),{id:a}=o;return{id:a,name:e.name,formItemId:`form-item-${a}`,formDescriptionId:`form-item-description-${a}`,formMessageId:`form-item-message-${a}`,...s}},M=P;function h({...e}){return i(p.Provider,{value:{name:e.name},children:i(f,{...e})})}var R=t.forwardRef(({className:e,...o},r)=>{let m=t.useId();return i(c.Provider,{value:{id:m},children:i("div",{ref:r,className:l("space-y-2",e),...o})})});R.displayName="FormItem";var x=t.forwardRef(({className:e,...o},r)=>{let{error:m,formItemId:s}=n();return i(F,{ref:r,className:l(m&&"text-destructive",e),htmlFor:s,...o})});x.displayName="FormLabel";var C=t.forwardRef(({...e},o)=>{let{error:r,formItemId:m,formDescriptionId:s,formMessageId:a}=n();return i(u,{ref:o,id:m,"aria-describedby":r?`${s} ${a}`:s,"aria-invalid":!!r,...e})});C.displayName="FormControl";var I=t.forwardRef(({className:e,...o},r)=>{let{formDescriptionId:m}=n();return i("p",{ref:r,id:m,className:l("text-muted-foreground text-xs",e),...o})});I.displayName="FormDescription";var g=t.forwardRef(({children:e,className:o,...r},m)=>{let{error:s,formMessageId:a}=n(),d=s?.message?s.message:e;return d?i("p",{ref:m,id:a,className:l("text-destructive text-xs font-medium",o),...r,children:d}):null});g.displayName="FormMessage";export{M as Form,C as FormControl,I as FormDescription,h as FormField,R as FormItem,x as FormLabel,g as FormMessage,n as useFormField};
|
|
2
2
|
//# sourceMappingURL=form.mjs.map
|
package/dist/react/form.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/form.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport type * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n Controller,\n type ControllerProps,\n type FieldError,\n type FieldPath,\n type FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\";\nimport { cn } from \"../lib/utils\";\nimport { Label } from \"./label\";\n\n/* -----------------------------------------------------------------------------\n * Context: Form\n * -------------------------------------------------------------------------- */\n\ninterface FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> {\n name: TName;\n}\n\ninterface FormItemContextValue {\n id: string;\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue | null>(null);\n\nconst FormItemContext = React.createContext<FormItemContextValue | null>(null);\n\nconst useFormField = (): {\n invalid: boolean;\n isDirty: boolean;\n isTouched: boolean;\n isValidating: boolean;\n error?: FieldError | undefined;\n id: string;\n name: string;\n formItemId: string;\n formDescriptionId: string;\n formMessageId: string;\n} => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n if (!fieldContext || !itemContext) {\n throw new Error(\"useFormField should be used within <FormField>\");\n }\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `form-item-${id}`,\n formDescriptionId: `form-item-description-${id}`,\n formMessageId: `form-item-message-${id}`,\n ...fieldState,\n };\n};\n\n/* -----------------------------------------------------------------------------\n * Component: Form\n * -------------------------------------------------------------------------- */\n\ntype FormProps = React.ComponentProps<typeof FormProvider>;\nconst Form = FormProvider;\n\n/* -----------------------------------------------------------------------------\n * Component: FormField\n * -------------------------------------------------------------------------- */\n\ntype FormFieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = ControllerProps<TFieldValues, TName>;\n\nfunction FormField<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({ ...props }: FormFieldProps<TFieldValues, TName>): React.JSX.Element {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n}\n\n/* -----------------------------------------------------------------------------\n * Component: FormItem\n * -------------------------------------------------------------------------- */\n\ntype FormItemElement = HTMLDivElement;\ntype FormItemProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst FormItem = React.forwardRef<FormItemElement, FormItemProps>(({ className, ...props }, ref) => {\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\nFormItem.displayName = \"FormItem\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormLabel\n * -------------------------------------------------------------------------- */\n\ntype FormFieldElement = React.ElementRef<typeof LabelPrimitive.Root>;\ntype FormLabelProps = React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>;\n\nconst FormLabel = React.forwardRef<FormFieldElement, FormLabelProps>(({ className, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return <Label ref={ref} className={cn(error && \"text-destructive\", className)} htmlFor={formItemId} {...props} />;\n});\n\nFormLabel.displayName = \"FormLabel\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormControl\n * -------------------------------------------------------------------------- */\n\ntype FormControlElement = React.ElementRef<typeof Slot>;\ntype FormControlProps = React.ComponentPropsWithoutRef<typeof Slot>;\n\nconst FormControl = React.forwardRef<FormControlElement, FormControlProps>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={!error ? formDescriptionId : `${formDescriptionId} ${formMessageId}`}\n aria-invalid={Boolean(error)}\n {...props}\n />\n );\n});\n\nFormControl.displayName = \"FormControl\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormDescription\n * -------------------------------------------------------------------------- */\n\ntype FormDescriptionElement = HTMLParagraphElement;\ntype FormDescriptionProps = React.HTMLAttributes<HTMLParagraphElement>;\n\nconst FormDescription = React.forwardRef<FormDescriptionElement, FormDescriptionProps>(\n ({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return <p ref={ref} id={formDescriptionId} className={cn(\"text-muted-foreground text-xs\", className)} {...props} />;\n },\n);\n\nFormDescription.displayName = \"FormDescription\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormMessage\n * -------------------------------------------------------------------------- */\n\ntype FormMessageElement = HTMLParagraphElement;\ntype FormMessageProps = React.HTMLAttributes<HTMLParagraphElement>;\n\nconst FormMessage = React.forwardRef<FormMessageElement, FormMessageProps>(({ children, className, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error ?
|
|
1
|
+
{"version":3,"sources":["../../src/react/form.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport type * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n Controller,\n type ControllerProps,\n type FieldError,\n type FieldPath,\n type FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\";\nimport { cn } from \"../lib/utils\";\nimport { Label } from \"./label\";\n\n/* -----------------------------------------------------------------------------\n * Context: Form\n * -------------------------------------------------------------------------- */\n\ninterface FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> {\n name: TName;\n}\n\ninterface FormItemContextValue {\n id: string;\n}\n\nconst FormFieldContext = React.createContext<FormFieldContextValue | null>(null);\n\nconst FormItemContext = React.createContext<FormItemContextValue | null>(null);\n\nconst useFormField = (): {\n invalid: boolean;\n isDirty: boolean;\n isTouched: boolean;\n isValidating: boolean;\n error?: FieldError | undefined;\n id: string;\n name: string;\n formItemId: string;\n formDescriptionId: string;\n formMessageId: string;\n} => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n if (!fieldContext || !itemContext) {\n throw new Error(\"useFormField should be used within <FormField>\");\n }\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `form-item-${id}`,\n formDescriptionId: `form-item-description-${id}`,\n formMessageId: `form-item-message-${id}`,\n ...fieldState,\n };\n};\n\n/* -----------------------------------------------------------------------------\n * Component: Form\n * -------------------------------------------------------------------------- */\n\ntype FormProps = React.ComponentProps<typeof FormProvider>;\nconst Form = FormProvider;\n\n/* -----------------------------------------------------------------------------\n * Component: FormField\n * -------------------------------------------------------------------------- */\n\ntype FormFieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = ControllerProps<TFieldValues, TName>;\n\nfunction FormField<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({ ...props }: FormFieldProps<TFieldValues, TName>): React.JSX.Element {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n}\n\n/* -----------------------------------------------------------------------------\n * Component: FormItem\n * -------------------------------------------------------------------------- */\n\ntype FormItemElement = HTMLDivElement;\ntype FormItemProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst FormItem = React.forwardRef<FormItemElement, FormItemProps>(({ className, ...props }, ref) => {\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\nFormItem.displayName = \"FormItem\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormLabel\n * -------------------------------------------------------------------------- */\n\ntype FormFieldElement = React.ElementRef<typeof LabelPrimitive.Root>;\ntype FormLabelProps = React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>;\n\nconst FormLabel = React.forwardRef<FormFieldElement, FormLabelProps>(({ className, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return <Label ref={ref} className={cn(error && \"text-destructive\", className)} htmlFor={formItemId} {...props} />;\n});\n\nFormLabel.displayName = \"FormLabel\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormControl\n * -------------------------------------------------------------------------- */\n\ntype FormControlElement = React.ElementRef<typeof Slot>;\ntype FormControlProps = React.ComponentPropsWithoutRef<typeof Slot>;\n\nconst FormControl = React.forwardRef<FormControlElement, FormControlProps>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={!error ? formDescriptionId : `${formDescriptionId} ${formMessageId}`}\n aria-invalid={Boolean(error)}\n {...props}\n />\n );\n});\n\nFormControl.displayName = \"FormControl\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormDescription\n * -------------------------------------------------------------------------- */\n\ntype FormDescriptionElement = HTMLParagraphElement;\ntype FormDescriptionProps = React.HTMLAttributes<HTMLParagraphElement>;\n\nconst FormDescription = React.forwardRef<FormDescriptionElement, FormDescriptionProps>(\n ({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return <p ref={ref} id={formDescriptionId} className={cn(\"text-muted-foreground text-xs\", className)} {...props} />;\n },\n);\n\nFormDescription.displayName = \"FormDescription\";\n\n/* -----------------------------------------------------------------------------\n * Component: FormMessage\n * -------------------------------------------------------------------------- */\n\ntype FormMessageElement = HTMLParagraphElement;\ntype FormMessageProps = React.HTMLAttributes<HTMLParagraphElement>;\n\nconst FormMessage = React.forwardRef<FormMessageElement, FormMessageProps>(({ children, className, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error?.message ? error.message : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p ref={ref} id={formMessageId} className={cn(\"text-destructive text-xs font-medium\", className)} {...props}>\n {body}\n </p>\n );\n});\n\nFormMessage.displayName = \"FormMessage\";\n\n/* -----------------------------------------------------------------------------\n * Exports\n * -------------------------------------------------------------------------- */\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n type FormProps,\n type FormItemProps,\n type FormLabelProps,\n type FormControlProps,\n type FormDescriptionProps,\n type FormMessageProps,\n type FormFieldProps,\n};\n"],"mappings":"iGAEA,UAAYA,MAAW,QAEvB,OAAS,QAAAC,MAAY,uBACrB,OACE,cAAAC,EAKA,gBAAAC,EACA,kBAAAC,MACK,kBA+ED,cAAAC,MAAA,oBA5DN,IAAMC,EAAyB,gBAA4C,IAAI,EAEzEC,EAAwB,gBAA2C,IAAI,EAEvEC,EAAe,IAWhB,CACH,IAAMC,EAAqB,aAAWH,CAAgB,EAChDI,EAAoB,aAAWH,CAAe,EAC9C,CAAE,cAAAI,EAAe,UAAAC,CAAU,EAAIC,EAAe,EAEpD,GAAI,CAACJ,GAAgB,CAACC,EACpB,MAAM,IAAI,MAAM,gDAAgD,EAGlE,IAAMI,EAAaH,EAAcF,EAAa,KAAMG,CAAS,EAEvD,CAAE,GAAAG,CAAG,EAAIL,EAEf,MAAO,CACL,GAAAK,EACA,KAAMN,EAAa,KACnB,WAAY,aAAaM,CAAE,GAC3B,kBAAmB,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CAAM,EAAGI,IAAQ,CAChC,GAAM,CAAE,kBAAAO,CAAkB,EAAItB,EAAa,EAE3C,OAAOH,EAAC,KAAE,IAAKkB,EAAK,GAAIO,EAAmB,UAAWN,EAAG,gCAAiCF,CAAS,EAAI,GAAGH,EAAO,CACnH,CACF,EAEAc,EAAgB,YAAc,kBAS9B,IAAMC,EAAoB,aAAiD,CAAC,CAAE,SAAAC,EAAU,UAAAb,EAAW,GAAGH,CAAM,EAAGI,IAAQ,CACrH,GAAM,CAAE,MAAAG,EAAO,cAAAK,CAAc,EAAIvB,EAAa,EACxC4B,EAAOV,GAAO,QAAUA,EAAM,QAAUS,EAE9C,OAAKC,EAKH/B,EAAC,KAAE,IAAKkB,EAAK,GAAIQ,EAAe,UAAWP,EAAG,uCAAwCF,CAAS,EAAI,GAAGH,EACnG,SAAAiB,EACH,EANO,IAQX,CAAC,EAEDF,EAAY,YAAc","names":["React","Slot","Controller","FormProvider","useFormContext","jsx","FormFieldContext","FormItemContext","useFormField","fieldContext","itemContext","getFieldState","formState","useFormContext","fieldState","id","Form","FormProvider","FormField","props","Controller","FormItem","className","ref","cn","FormLabel","error","formItemId","Label","FormControl","formDescriptionId","formMessageId","Slot","FormDescription","FormMessage","children","body"]}
|
package/package.json
CHANGED
package/src/react/form.tsx
CHANGED
|
@@ -178,7 +178,7 @@ type FormMessageProps = React.HTMLAttributes<HTMLParagraphElement>;
|
|
|
178
178
|
|
|
179
179
|
const FormMessage = React.forwardRef<FormMessageElement, FormMessageProps>(({ children, className, ...props }, ref) => {
|
|
180
180
|
const { error, formMessageId } = useFormField();
|
|
181
|
-
const body = error ?
|
|
181
|
+
const body = error?.message ? error.message : children;
|
|
182
182
|
|
|
183
183
|
if (!body) {
|
|
184
184
|
return null;
|