@me1a/ui 2.1.4 → 2.1.5
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/chunk-6EETNYKI.esm.js +2 -0
- package/dist/chunk-6EETNYKI.esm.js.map +1 -0
- package/dist/chunk-TKRGIWLE.cjs.js +2 -0
- package/dist/chunk-TKRGIWLE.cjs.js.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.esm.js +1 -1
- package/dist/molecules.cjs.js +1 -1
- package/dist/molecules.d.mts +1 -197
- package/dist/molecules.d.ts +1 -197
- package/dist/molecules.esm.js +1 -1
- package/dist/rhf.cjs.js +2 -0
- package/dist/rhf.cjs.js.map +1 -0
- package/dist/rhf.d.mts +199 -0
- package/dist/rhf.d.ts +199 -0
- package/dist/rhf.esm.js +2 -0
- package/dist/rhf.esm.js.map +1 -0
- package/package.json +6 -1
- package/dist/chunk-JQGLWFDR.esm.js +0 -2
- package/dist/chunk-JQGLWFDR.esm.js.map +0 -1
- package/dist/chunk-YVYCVGPC.cjs.js +0 -2
- package/dist/chunk-YVYCVGPC.cjs.js.map +0 -1
package/dist/molecules.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
|
-
import { TextareaHTMLAttributes } from 'react';
|
|
3
2
|
import * as NavigationMenuPrimitive from '@radix-ui/react-navigation-menu';
|
|
4
3
|
import { VariantProps } from 'class-variance-authority';
|
|
5
4
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
6
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
|
-
import * as react_hook_form from 'react-hook-form';
|
|
8
|
-
import { FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
9
|
-
import { I as Input } from './input-Ruz0ZoY6.js';
|
|
10
|
-
import * as _radix_ui_react_slot from '@radix-ui/react-slot';
|
|
11
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
12
|
-
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
13
5
|
|
|
14
6
|
/**
|
|
15
7
|
* Card is a flexible container component that can be used to group related content and actions.
|
|
@@ -177,192 +169,4 @@ declare const NavigationMenuLink: React$1.ForwardRefExoticComponent<NavigationMe
|
|
|
177
169
|
declare const NavigationMenuViewport: React$1.ForwardRefExoticComponent<NavigationMenuViewportProps & React$1.RefAttributes<HTMLDivElement>>;
|
|
178
170
|
declare const NavigationMenuIndicator: React$1.ForwardRefExoticComponent<NavigationMenuIndicatorProps & React$1.RefAttributes<HTMLDivElement>>;
|
|
179
171
|
|
|
180
|
-
|
|
181
|
-
/** The name of the field in the form */
|
|
182
|
-
name: TName;
|
|
183
|
-
/** Optional label for the field */
|
|
184
|
-
label?: string;
|
|
185
|
-
/** Optional description text below the field */
|
|
186
|
-
description?: string;
|
|
187
|
-
/** Optional warning text to display */
|
|
188
|
-
warningText?: string;
|
|
189
|
-
/** Whether the field is required */
|
|
190
|
-
required?: boolean;
|
|
191
|
-
/** Whether the field is disabled */
|
|
192
|
-
disabled?: boolean;
|
|
193
|
-
/** Whether the field is read-only */
|
|
194
|
-
readOnly?: boolean;
|
|
195
|
-
/** The type of input (text, number, email, etc.) */
|
|
196
|
-
type?: React$1.HTMLInputTypeAttribute;
|
|
197
|
-
/** Optional placeholder text */
|
|
198
|
-
placeholder?: string;
|
|
199
|
-
/** Optional aria-label for accessibility */
|
|
200
|
-
"aria-label"?: string;
|
|
201
|
-
/** Optional aria-describedby for accessibility */
|
|
202
|
-
"aria-describedby"?: string;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* A text field component that integrates with React Hook Form.
|
|
207
|
-
* Provides form validation, error handling, and accessibility features.
|
|
208
|
-
*
|
|
209
|
-
* @url https://sergii-melnykov.github.io/ui/?path=/docs/molecules-rhf-rhftextfield--docs
|
|
210
|
-
*
|
|
211
|
-
* * @example
|
|
212
|
-
* ```tsx
|
|
213
|
-
* <Form>
|
|
214
|
-
* <RHFTextField name="name" label="Name" />
|
|
215
|
-
* <RHFTextField name="email" label="Email" />
|
|
216
|
-
* </Form>
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
declare function RHFTextField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, label, description, className, type, warningText, required, disabled, readOnly, placeholder, "aria-label": ariaLabel, "aria-describedby": ariaDescribedby, onBlur, ...other }: RHFTextFieldProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
220
|
-
|
|
221
|
-
interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
222
|
-
/**
|
|
223
|
-
* Whether the textarea should automatically resize
|
|
224
|
-
*/
|
|
225
|
-
autoResize?: boolean;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Textarea component for creating accessible text areas.
|
|
230
|
-
* Built on top of shadcn/ui's Textarea component.
|
|
231
|
-
*
|
|
232
|
-
* @url https://sergii-melnykov.github.io/ui/?path=/docs/atoms-textarea--docs
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* ```tsx
|
|
236
|
-
* <Textarea placeholder="Enter text" />
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
declare const Textarea: React$1.ForwardRefExoticComponent<TextareaProps & React$1.RefAttributes<HTMLTextAreaElement>>;
|
|
240
|
-
|
|
241
|
-
interface RHFTextareaProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<React$1.ComponentProps<typeof Textarea>, "name"> {
|
|
242
|
-
/** The name of the field in the form */
|
|
243
|
-
name: TName;
|
|
244
|
-
/** Optional label for the field */
|
|
245
|
-
label?: string;
|
|
246
|
-
/** Optional description text below the field */
|
|
247
|
-
description?: string;
|
|
248
|
-
/** Optional warning text to display */
|
|
249
|
-
warningText?: string;
|
|
250
|
-
/** Whether the field is required */
|
|
251
|
-
required?: boolean;
|
|
252
|
-
/** Whether the field is disabled */
|
|
253
|
-
disabled?: boolean;
|
|
254
|
-
/** Whether the field is read-only */
|
|
255
|
-
readOnly?: boolean;
|
|
256
|
-
/** Optional placeholder text */
|
|
257
|
-
placeholder?: string;
|
|
258
|
-
/** Optional aria-label for accessibility */
|
|
259
|
-
"aria-label"?: string;
|
|
260
|
-
/** Optional aria-describedby for accessibility */
|
|
261
|
-
"aria-describedby"?: string;
|
|
262
|
-
/** Whether the textarea should automatically resize */
|
|
263
|
-
autoResize?: boolean;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* A textarea component that integrates with React Hook Form.
|
|
268
|
-
* Provides form validation, error handling, and accessibility features.
|
|
269
|
-
*
|
|
270
|
-
* @url https://sergii-melnykov.github.io/ui/?path=/docs/molecules-rhf-rhftextarea--docs
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* ```tsx
|
|
274
|
-
* <Form>
|
|
275
|
-
* <RHFTextarea name="description" label="Description" />
|
|
276
|
-
* </Form>
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
declare function RHFTextarea<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, label, description, className, warningText, required, disabled, readOnly, placeholder, autoResize, "aria-label": ariaLabel, "aria-describedby": ariaDescribedby, onBlur, ...other }: RHFTextareaProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
280
|
-
|
|
281
|
-
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>(props: react_hook_form.FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React$1.JSX.Element;
|
|
282
|
-
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
283
|
-
declare const useFormField: () => {
|
|
284
|
-
invalid: boolean;
|
|
285
|
-
isDirty: boolean;
|
|
286
|
-
isTouched: boolean;
|
|
287
|
-
isValidating: boolean;
|
|
288
|
-
error?: react_hook_form.FieldError;
|
|
289
|
-
id: string;
|
|
290
|
-
name: string;
|
|
291
|
-
formItemId: string;
|
|
292
|
-
formDescriptionId: string;
|
|
293
|
-
formMessageId: string;
|
|
294
|
-
};
|
|
295
|
-
declare const FormItem: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
296
|
-
declare const FormLabel: React$1.ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & React$1.RefAttributes<HTMLLabelElement>, "ref"> & React$1.RefAttributes<HTMLLabelElement>>;
|
|
297
|
-
declare const FormControl: React$1.ForwardRefExoticComponent<Omit<_radix_ui_react_slot.SlotProps & React$1.RefAttributes<HTMLElement>, "ref"> & React$1.RefAttributes<HTMLElement>>;
|
|
298
|
-
declare const FormDescription: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLParagraphElement> & React$1.RefAttributes<HTMLParagraphElement>>;
|
|
299
|
-
declare const FormMessage: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLParagraphElement> & React$1.RefAttributes<HTMLParagraphElement>>;
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Props interface for the Form component.
|
|
303
|
-
* Extends react-hook-form's FormProvider props.
|
|
304
|
-
*/
|
|
305
|
-
interface FormProps<TFieldValues extends FieldValues = FieldValues> {
|
|
306
|
-
/**
|
|
307
|
-
* The form context value
|
|
308
|
-
*/
|
|
309
|
-
context: React$1.Context<TFieldValues>;
|
|
310
|
-
/**
|
|
311
|
-
* The form children
|
|
312
|
-
*/
|
|
313
|
-
children: React$1.ReactNode;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Props interface for the FormField component.
|
|
317
|
-
* Extends react-hook-form's Controller props.
|
|
318
|
-
*/
|
|
319
|
-
interface FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ControllerProps<TFieldValues, TName> {
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Props interface for the FormItem component.
|
|
323
|
-
* Extends HTML div attributes.
|
|
324
|
-
*/
|
|
325
|
-
interface FormItemProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Props interface for the FormLabel component.
|
|
329
|
-
* Extends Radix UI Label props.
|
|
330
|
-
*/
|
|
331
|
-
interface FormLabelProps extends React$1.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> {
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Props interface for the FormControl component.
|
|
335
|
-
* Extends Radix UI Slot props.
|
|
336
|
-
*/
|
|
337
|
-
interface FormControlProps extends React$1.ComponentPropsWithoutRef<typeof Slot> {
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Props interface for the FormDescription component.
|
|
341
|
-
* Extends HTML paragraph attributes.
|
|
342
|
-
*/
|
|
343
|
-
interface FormDescriptionProps extends React$1.HTMLAttributes<HTMLParagraphElement> {
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Props interface for the FormMessage component.
|
|
347
|
-
* Extends HTML paragraph attributes.
|
|
348
|
-
*/
|
|
349
|
-
interface FormMessageProps extends React$1.HTMLAttributes<HTMLParagraphElement> {
|
|
350
|
-
/**
|
|
351
|
-
* The message content
|
|
352
|
-
*/
|
|
353
|
-
children?: React$1.ReactNode;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Context value type for form field context
|
|
357
|
-
*/
|
|
358
|
-
type FormFieldContextValue<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
359
|
-
name: TName;
|
|
360
|
-
};
|
|
361
|
-
/**
|
|
362
|
-
* Context value type for form item context
|
|
363
|
-
*/
|
|
364
|
-
type FormItemContextValue = {
|
|
365
|
-
id: string;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Form, FormControl, type FormControlProps, FormDescription, type FormDescriptionProps, FormField, type FormFieldContextValue, type FormFieldProps, FormItem, type FormItemContextValue, type FormItemProps, FormLabel, type FormLabelProps, FormMessage, type FormMessageProps, type FormProps, NavigationMenu, NavigationMenuContent, type NavigationMenuContentProps, NavigationMenuIndicator, type NavigationMenuIndicatorProps, NavigationMenuItem, type NavigationMenuItemProps, NavigationMenuLink, type NavigationMenuLinkProps, NavigationMenuList, type NavigationMenuListProps, type NavigationMenuProps, NavigationMenuTrigger, type NavigationMenuTriggerProps, NavigationMenuViewport, type NavigationMenuViewportProps, RHFTextField, RHFTextarea, useFormField };
|
|
172
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, NavigationMenu, NavigationMenuContent, type NavigationMenuContentProps, NavigationMenuIndicator, type NavigationMenuIndicatorProps, NavigationMenuItem, type NavigationMenuItemProps, NavigationMenuLink, type NavigationMenuLinkProps, NavigationMenuList, type NavigationMenuListProps, type NavigationMenuProps, NavigationMenuTrigger, type NavigationMenuTriggerProps, NavigationMenuViewport, type NavigationMenuViewportProps };
|
package/dist/molecules.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as Card,e as CardContent,d as CardDescription,f as CardFooter,b as CardHeader,c as CardTitle,
|
|
1
|
+
export{a as Card,e as CardContent,d as CardDescription,f as CardFooter,b as CardHeader,c as CardTitle,g as NavigationMenu,k as NavigationMenuContent,n as NavigationMenuIndicator,i as NavigationMenuItem,l as NavigationMenuLink,h as NavigationMenuList,j as NavigationMenuTrigger,m as NavigationMenuViewport}from'./chunk-6EETNYKI.esm.js';import'./chunk-C26U3FL4.esm.js';//# sourceMappingURL=molecules.esm.js.map
|
|
2
2
|
//# sourceMappingURL=molecules.esm.js.map
|
package/dist/rhf.cjs.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunkUAZIJGWR_cjs_js=require('./chunk-UAZIJGWR.cjs.js'),chunkBR7Z6MCL_cjs_js=require('./chunk-BR7Z6MCL.cjs.js'),chunkSL2ZUI4G_cjs_js=require('./chunk-SL2ZUI4G.cjs.js'),reactHookForm=require('react-hook-form'),l=require('react'),reactSlot=require('@radix-ui/react-slot'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var l__namespace=/*#__PURE__*/_interopNamespace(l);var z=reactHookForm.FormProvider,D=l__namespace.createContext({}),g=({...e})=>jsxRuntime.jsx(D.Provider,{value:{name:e.name},children:jsxRuntime.jsx(reactHookForm.Controller,{...e})}),C=()=>{let e=l__namespace.useContext(D),r=l__namespace.useContext(S),{getFieldState:o,formState:m}=reactHookForm.useFormContext(),a=o(e.name,m);if(!e)throw new Error("useFormField should be used within <FormField>");let{id:t}=r;return {id:t,name:e.name,formItemId:`${t}-form-item`,formDescriptionId:`${t}-form-item-description`,formMessageId:`${t}-form-item-message`,...a}},S=l__namespace.createContext({}),f=l__namespace.forwardRef(({className:e,...r},o)=>{let m=l__namespace.useId();return jsxRuntime.jsx(S.Provider,{value:{id:m},children:jsxRuntime.jsx("div",{ref:o,className:chunkSL2ZUI4G_cjs_js.a("space-y-2",e),...r})})});f.displayName="FormItem";var x=l__namespace.forwardRef(({className:e,...r},o)=>{let{error:m,formItemId:a}=C();return jsxRuntime.jsx(chunkUAZIJGWR_cjs_js.a,{ref:o,className:chunkSL2ZUI4G_cjs_js.a(m&&"text-destructive",e),htmlFor:a,...r})});x.displayName="FormLabel";var b=l__namespace.forwardRef(({...e},r)=>{let{error:o,formItemId:m,formDescriptionId:a,formMessageId:t}=C();return jsxRuntime.jsx(reactSlot.Slot,{ref:r,id:m,"aria-describedby":o?`${a} ${t}`:`${a}`,"aria-invalid":!!o,...e})});b.displayName="FormControl";var T=l__namespace.forwardRef(({className:e,...r},o)=>{let{formDescriptionId:m}=C();return jsxRuntime.jsx("p",{ref:o,id:m,className:chunkSL2ZUI4G_cjs_js.a("text-sm text-muted-foreground",e),...r})});T.displayName="FormDescription";var v=l__namespace.forwardRef(({className:e,children:r,...o},m)=>{let{error:a,formMessageId:t}=C(),i=a?String(a?.message??""):r;return i?jsxRuntime.jsx("p",{ref:m,id:t,className:chunkSL2ZUI4G_cjs_js.a("text-sm font-medium text-destructive",e),...o,children:i}):null});v.displayName="FormMessage";function ae({name:e,label:r,description:o,className:m,type:a="text",warningText:t,required:i,disabled:y,readOnly:P,placeholder:h,"aria-label":V,"aria-describedby":I,onBlur:N,...L}){let{control:M}=reactHookForm.useFormContext();return jsxRuntime.jsx(g,{name:e,control:M,render:({field:s,fieldState:{error:n}})=>jsxRuntime.jsxs(f,{children:[r&&jsxRuntime.jsxs(x,{children:[r,i&&jsxRuntime.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),jsxRuntime.jsx(b,{children:jsxRuntime.jsx(chunkBR7Z6MCL_cjs_js.a,{...s,type:a,value:a==="number"&&s.value===0?"":s.value,onChange:F=>{a==="number"?s.onChange(Number(F.target.value)):s.onChange(F.target.value);},onBlur:F=>{a!=="number"&&typeof s.value=="string"&&s.onChange(s.value.trim()),s.onBlur(),N?.(F);},className:chunkSL2ZUI4G_cjs_js.a(n&&"border-destructive focus-visible:ring-destructive",m),disabled:y,readOnly:P,required:i,placeholder:h,"aria-label":V,"aria-describedby":I,"aria-invalid":!!n,"aria-required":i,...L})}),o&&jsxRuntime.jsx(T,{children:o}),n&&jsxRuntime.jsx(v,{children:n.message}),!n&&t&&jsxRuntime.jsx("p",{className:"text-sm text-yellow-600 dark:text-yellow-500",role:"alert",children:t})]})})}var H=l__namespace.forwardRef(({className:e,autoResize:r=false,...o},m)=>{let a=l__namespace.useRef(null);return l__namespace.useEffect(()=>{if(!r||!a.current)return;let t=a.current,i=()=>{t.style.height="auto",t.style.height=`${t.scrollHeight}px`;};return t.addEventListener("input",i),i(),()=>t.removeEventListener("input",i)},[r]),jsxRuntime.jsx("textarea",{className:chunkSL2ZUI4G_cjs_js.a("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:m,...o})});H.displayName="Textarea";function pe({name:e,label:r,description:o,className:m,warningText:a,required:t,disabled:i,readOnly:y,placeholder:P,autoResize:h,"aria-label":V,"aria-describedby":I,onBlur:N,...L}){let{control:M}=reactHookForm.useFormContext();return jsxRuntime.jsx(g,{name:e,control:M,render:({field:s,fieldState:{error:n}})=>jsxRuntime.jsxs(f,{children:[r&&jsxRuntime.jsxs(x,{children:[r,t&&jsxRuntime.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),jsxRuntime.jsx(b,{children:jsxRuntime.jsx(H,{...s,value:s.value,onChange:F=>{s.onChange(F.target.value);},onBlur:F=>{typeof s.value=="string"&&s.onChange(s.value.trim()),s.onBlur(),N?.(F);},className:chunkSL2ZUI4G_cjs_js.a(n&&"border-destructive focus-visible:ring-destructive",m),disabled:i,readOnly:y,required:t,placeholder:P,"aria-label":V,"aria-describedby":I,"aria-invalid":!!n,"aria-required":t,autoResize:h,...L})}),o&&jsxRuntime.jsx(T,{children:o}),n&&jsxRuntime.jsx(v,{children:n.message}),!n&&a&&jsxRuntime.jsx("p",{className:"text-sm text-yellow-600 dark:text-yellow-500",role:"alert",children:a})]})})}exports.Form=z;exports.FormControl=b;exports.FormDescription=T;exports.FormField=g;exports.FormItem=f;exports.FormLabel=x;exports.FormMessage=v;exports.RHFTextField=ae;exports.RHFTextarea=pe;exports.useFormField=C;//# sourceMappingURL=rhf.cjs.js.map
|
|
2
|
+
//# sourceMappingURL=rhf.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/rhf/form/form.tsx","../src/components/rhf/rhf-text-field/rhf-text-field.tsx","../src/components/atoms/textarea/textarea.tsx","../src/components/rhf/rhf-textarea/rhf-textarea.tsx"],"names":["Form","FormProvider","FormFieldContext","l","FormField","props","jsx","Controller","useFormField","fieldContext","itemContext","FormItemContext","getFieldState","formState","useFormContext","fieldState","id","FormItem","className","ref","cn","FormLabel","error","formItemId","Label","FormControl","formDescriptionId","formMessageId","Slot","FormDescription","FormMessage","children","body","RHFTextField","name","label","description","type","warningText","required","disabled","readOnly","placeholder","ariaLabel","ariaDescribedby","onBlur","other","control","field","jsxs","Input","e","Textarea","R","autoResize","internalRef","textarea","resizeTextarea","RHFTextarea"],"mappings":"6qBAiBA,IAAMA,CAAOC,CAAAA,0BAAAA,CASPC,EAAyBC,YAAqC,CAAA,aAAA,CAAA,EAA2B,CAEzFC,CAAAA,CAAAA,CAAY,CAGhB,CACA,GAAGC,CACL,CAAA,GAEIC,cAACJ,CAAAA,CAAAA,CAAiB,SAAjB,CAA0B,KAAA,CAAO,CAAE,IAAMG,CAAAA,CAAAA,CAAM,IAAK,CACnD,CAAA,QAAA,CAAAC,cAACC,CAAAA,wBAAAA,CAAA,CAAY,GAAGF,EAAO,CACzB,CAAA,CAAA,CAIEG,EAAe,IAAM,CACzB,IAAMC,CAAqB,CAAAN,YAAA,CAAA,UAAA,CAAWD,CAAgB,CAAA,CAChDQ,CAAoB,CAAAP,YAAA,CAAA,UAAA,CAAWQ,CAAe,CAC9C,CAAA,CAAE,cAAAC,CAAe,CAAA,SAAA,CAAAC,CAAU,CAAIC,CAAAA,4BAAAA,EAE/BC,CAAAA,CAAAA,CAAaH,CAAcH,CAAAA,CAAAA,CAAa,KAAMI,CAAS,CAAA,CAE7D,GAAI,CAACJ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AAAA,CAAAA,CAAY,EAC7Cd,CAAShB,EAAAA,cAAAA,CAACwB,EAAA,CAAa,QAAA,CAAAR,CAAM,CAAA,OAAA,CAAQ,CACrC,CAAA,CAACA,GAASgB,CACThC,EAAAA,cAAAA,CAAC,GAAE,CAAA,CAAA,SAAA,CAAU,8CAA+C,CAAA,IAAA,CAAK,QAC9D,QAAAgC,CAAAA,CAAAA,CACH,CAEJ,CAAA,CAAA,CAAA,CAEJ,CAEJ","file":"rhf.cjs.js","sourcesContent":["\"use client\"\n\nimport * as React from \"react\"\nimport * as LabelPrimitive from \"@radix-ui/react-label\"\nimport { Slot } from \"@radix-ui/react-slot\"\nimport {\n Controller,\n FormProvider,\n useFormContext,\n type ControllerProps,\n type FieldPath,\n type FieldValues\n} from \"react-hook-form\"\n\nimport { cn } from \"@/utils/cn\"\nimport { Label } from \"@/components/atoms/label\"\n\nconst Form = 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>({} as FormFieldContextValue)\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>({} as FormItemContextValue)\n\nconst FormItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ 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\nconst FormLabel = React.forwardRef<\n React.ElementRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(({ className, ...props }, ref) => {\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})\nFormLabel.displayName = \"FormLabel\"\n\nconst FormControl = React.forwardRef<\n React.ElementRef<typeof Slot>,\n React.ComponentPropsWithoutRef<typeof Slot>\n>(({ ...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={!!error}\n {...props}\n />\n )\n})\nFormControl.displayName = \"FormControl\"\n\nconst FormDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\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})\nFormDescription.displayName = \"FormDescription\"\n\nconst FormMessage = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\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})\nFormMessage.displayName = \"FormMessage\"\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField\n}\n","import * as React from \"react\"\nimport { useFormContext, type FieldValues, type FieldPath } from \"react-hook-form\"\nimport { Input } from \"@/components/atoms/input\"\nimport { cn } from \"@/utils/cn\"\nimport {\n FormControl,\n FormItem,\n FormMessage,\n FormLabel,\n FormDescription,\n FormField\n} from \"@/components/rhf/form\"\nimport { type RHFTextFieldProps } from \"./rhf-text-field.types\"\n\n// ----------------------------------------------------------------------\n\n/**\n * A text field component that integrates with React Hook Form.\n * Provides form validation, error handling, and accessibility features.\n *\n * @url https://sergii-melnykov.github.io/ui/?path=/docs/molecules-rhf-rhftextfield--docs\n *\n * * @example\n * ```tsx\n * <Form>\n * <RHFTextField name=\"name\" label=\"Name\" />\n * <RHFTextField name=\"email\" label=\"Email\" />\n * </Form>\n * ```\n */\nexport function RHFTextField<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n>({\n name,\n label,\n description,\n className,\n type = \"text\",\n warningText,\n required,\n disabled,\n readOnly,\n placeholder,\n \"aria-label\": ariaLabel,\n \"aria-describedby\": ariaDescribedby,\n onBlur,\n ...other\n}: RHFTextFieldProps<TFieldValues, TName>) {\n const { control } = useFormContext<TFieldValues>()\n\n return (\n <FormField\n name={name}\n control={control}\n render={({ field, fieldState: { error } }) => (\n <FormItem>\n {label && (\n <FormLabel>\n {label}\n {required && <span className=\"text-destructive ml-1\">*</span>}\n </FormLabel>\n )}\n <FormControl>\n <Input\n {...field}\n type={type}\n value={type === \"number\" && field.value === 0 ? \"\" : field.value}\n onChange={(e) => {\n if (type === \"number\") {\n field.onChange(Number(e.target.value))\n } else {\n field.onChange(e.target.value)\n }\n }}\n onBlur={(e) => {\n // trim if a string\n if (type !== \"number\" && typeof field.value === \"string\") {\n field.onChange(field.value.trim())\n }\n field.onBlur() // pass to react-hook-form\n onBlur?.(e) // pass to wrapper\n }}\n className={cn(\n error && \"border-destructive focus-visible:ring-destructive\",\n className\n )}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n placeholder={placeholder}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedby}\n aria-invalid={!!error}\n aria-required={required}\n {...other}\n />\n </FormControl>\n {description && <FormDescription>{description}</FormDescription>}\n {error && <FormMessage>{error.message}</FormMessage>}\n {!error && warningText && (\n <p className=\"text-sm text-yellow-600 dark:text-yellow-500\" role=\"alert\">\n {warningText}\n </p>\n )}\n </FormItem>\n )}\n />\n )\n}\n","import * as React from \"react\"\nimport { cn } from \"@/utils/index\"\nimport { TextareaProps } from \"./textarea.types\"\n\n/**\n * Textarea component for creating accessible text areas.\n * Built on top of shadcn/ui's Textarea component.\n *\n * @url https://sergii-melnykov.github.io/ui/?path=/docs/atoms-textarea--docs\n *\n * @example\n * ```tsx\n * <Textarea placeholder=\"Enter text\" />\n * ```\n */\nconst Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(\n ({ className, autoResize = false, ...props }, ref) => {\n const internalRef = React.useRef<HTMLTextAreaElement>(null)\n\n React.useEffect(() => {\n if (!autoResize || !internalRef.current) return\n\n const textarea = internalRef.current\n const resizeTextarea = () => {\n textarea.style.height = \"auto\"\n textarea.style.height = `${textarea.scrollHeight}px`\n }\n\n textarea.addEventListener(\"input\", resizeTextarea)\n resizeTextarea() // Initial resize\n\n return () => textarea.removeEventListener(\"input\", resizeTextarea)\n }, [autoResize])\n\n return (\n <textarea\n className={cn(\n \"flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm\",\n className\n )}\n ref={ref}\n {...props}\n />\n )\n }\n)\n\nTextarea.displayName = \"Textarea\"\n\nexport { Textarea }\n","import * as React from \"react\"\nimport { useFormContext, type FieldValues, type FieldPath } from \"react-hook-form\"\nimport { Textarea } from \"@/components/atoms/textarea\"\nimport { cn } from \"@/utils/cn\"\nimport {\n FormControl,\n FormItem,\n FormMessage,\n FormLabel,\n FormDescription,\n FormField\n} from \"@/components/rhf/form\"\nimport { type RHFTextareaProps } from \"./rhf-textarea.types\"\n\n// ----------------------------------------------------------------------\n\n/**\n * A textarea component that integrates with React Hook Form.\n * Provides form validation, error handling, and accessibility features.\n *\n * @url https://sergii-melnykov.github.io/ui/?path=/docs/molecules-rhf-rhftextarea--docs\n *\n * @example\n * ```tsx\n * <Form>\n * <RHFTextarea name=\"description\" label=\"Description\" />\n * </Form>\n * ```\n */\nexport function RHFTextarea<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n>({\n name,\n label,\n description,\n className,\n warningText,\n required,\n disabled,\n readOnly,\n placeholder,\n autoResize,\n \"aria-label\": ariaLabel,\n \"aria-describedby\": ariaDescribedby,\n onBlur,\n ...other\n}: RHFTextareaProps<TFieldValues, TName>) {\n const { control } = useFormContext<TFieldValues>()\n\n return (\n <FormField\n name={name}\n control={control}\n render={({ field, fieldState: { error } }) => (\n <FormItem>\n {label && (\n <FormLabel>\n {label}\n {required && <span className=\"text-destructive ml-1\">*</span>}\n </FormLabel>\n )}\n <FormControl>\n <Textarea\n {...field}\n value={field.value}\n onChange={(e) => {\n field.onChange(e.target.value)\n }}\n onBlur={(e) => {\n // trim if a string\n if (typeof field.value === \"string\") {\n field.onChange(field.value.trim())\n }\n field.onBlur() // pass to react-hook-form\n onBlur?.(e) // pass to wrapper\n }}\n className={cn(\n error && \"border-destructive focus-visible:ring-destructive\",\n className\n )}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n placeholder={placeholder}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedby}\n aria-invalid={!!error}\n aria-required={required}\n autoResize={autoResize}\n {...other}\n />\n </FormControl>\n {description && <FormDescription>{description}</FormDescription>}\n {error && <FormMessage>{error.message}</FormMessage>}\n {!error && warningText && (\n <p className=\"text-sm text-yellow-600 dark:text-yellow-500\" role=\"alert\">\n {warningText}\n </p>\n )}\n </FormItem>\n )}\n />\n )\n}\n"]}
|
package/dist/rhf.d.mts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react_hook_form from 'react-hook-form';
|
|
3
|
+
import { FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { TextareaHTMLAttributes } from 'react';
|
|
6
|
+
import { I as Input } from './input-Ruz0ZoY6.mjs';
|
|
7
|
+
import * as _radix_ui_react_slot from '@radix-ui/react-slot';
|
|
8
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
9
|
+
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
10
|
+
|
|
11
|
+
interface RHFTextFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<React.ComponentProps<typeof Input>, "name"> {
|
|
12
|
+
/** The name of the field in the form */
|
|
13
|
+
name: TName;
|
|
14
|
+
/** Optional label for the field */
|
|
15
|
+
label?: string;
|
|
16
|
+
/** Optional description text below the field */
|
|
17
|
+
description?: string;
|
|
18
|
+
/** Optional warning text to display */
|
|
19
|
+
warningText?: string;
|
|
20
|
+
/** Whether the field is required */
|
|
21
|
+
required?: boolean;
|
|
22
|
+
/** Whether the field is disabled */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** Whether the field is read-only */
|
|
25
|
+
readOnly?: boolean;
|
|
26
|
+
/** The type of input (text, number, email, etc.) */
|
|
27
|
+
type?: React.HTMLInputTypeAttribute;
|
|
28
|
+
/** Optional placeholder text */
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
/** Optional aria-label for accessibility */
|
|
31
|
+
"aria-label"?: string;
|
|
32
|
+
/** Optional aria-describedby for accessibility */
|
|
33
|
+
"aria-describedby"?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A text field component that integrates with React Hook Form.
|
|
38
|
+
* Provides form validation, error handling, and accessibility features.
|
|
39
|
+
*
|
|
40
|
+
* @url https://sergii-melnykov.github.io/ui/?path=/docs/molecules-rhf-rhftextfield--docs
|
|
41
|
+
*
|
|
42
|
+
* * @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <Form>
|
|
45
|
+
* <RHFTextField name="name" label="Name" />
|
|
46
|
+
* <RHFTextField name="email" label="Email" />
|
|
47
|
+
* </Form>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare function RHFTextField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, label, description, className, type, warningText, required, disabled, readOnly, placeholder, "aria-label": ariaLabel, "aria-describedby": ariaDescribedby, onBlur, ...other }: RHFTextFieldProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
51
|
+
|
|
52
|
+
interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
53
|
+
/**
|
|
54
|
+
* Whether the textarea should automatically resize
|
|
55
|
+
*/
|
|
56
|
+
autoResize?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Textarea component for creating accessible text areas.
|
|
61
|
+
* Built on top of shadcn/ui's Textarea component.
|
|
62
|
+
*
|
|
63
|
+
* @url https://sergii-melnykov.github.io/ui/?path=/docs/atoms-textarea--docs
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* <Textarea placeholder="Enter text" />
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
71
|
+
|
|
72
|
+
interface RHFTextareaProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<React.ComponentProps<typeof Textarea>, "name"> {
|
|
73
|
+
/** The name of the field in the form */
|
|
74
|
+
name: TName;
|
|
75
|
+
/** Optional label for the field */
|
|
76
|
+
label?: string;
|
|
77
|
+
/** Optional description text below the field */
|
|
78
|
+
description?: string;
|
|
79
|
+
/** Optional warning text to display */
|
|
80
|
+
warningText?: string;
|
|
81
|
+
/** Whether the field is required */
|
|
82
|
+
required?: boolean;
|
|
83
|
+
/** Whether the field is disabled */
|
|
84
|
+
disabled?: boolean;
|
|
85
|
+
/** Whether the field is read-only */
|
|
86
|
+
readOnly?: boolean;
|
|
87
|
+
/** Optional placeholder text */
|
|
88
|
+
placeholder?: string;
|
|
89
|
+
/** Optional aria-label for accessibility */
|
|
90
|
+
"aria-label"?: string;
|
|
91
|
+
/** Optional aria-describedby for accessibility */
|
|
92
|
+
"aria-describedby"?: string;
|
|
93
|
+
/** Whether the textarea should automatically resize */
|
|
94
|
+
autoResize?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A textarea component that integrates with React Hook Form.
|
|
99
|
+
* Provides form validation, error handling, and accessibility features.
|
|
100
|
+
*
|
|
101
|
+
* @url https://sergii-melnykov.github.io/ui/?path=/docs/molecules-rhf-rhftextarea--docs
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```tsx
|
|
105
|
+
* <Form>
|
|
106
|
+
* <RHFTextarea name="description" label="Description" />
|
|
107
|
+
* </Form>
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare function RHFTextarea<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, label, description, className, warningText, required, disabled, readOnly, placeholder, autoResize, "aria-label": ariaLabel, "aria-describedby": ariaDescribedby, onBlur, ...other }: RHFTextareaProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
111
|
+
|
|
112
|
+
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>(props: react_hook_form.FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React.JSX.Element;
|
|
113
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
114
|
+
declare const useFormField: () => {
|
|
115
|
+
invalid: boolean;
|
|
116
|
+
isDirty: boolean;
|
|
117
|
+
isTouched: boolean;
|
|
118
|
+
isValidating: boolean;
|
|
119
|
+
error?: react_hook_form.FieldError;
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
formItemId: string;
|
|
123
|
+
formDescriptionId: string;
|
|
124
|
+
formMessageId: string;
|
|
125
|
+
};
|
|
126
|
+
declare const FormItem: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
127
|
+
declare const FormLabel: React.ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & React.RefAttributes<HTMLLabelElement>, "ref"> & React.RefAttributes<HTMLLabelElement>>;
|
|
128
|
+
declare const FormControl: React.ForwardRefExoticComponent<Omit<_radix_ui_react_slot.SlotProps & React.RefAttributes<HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
129
|
+
declare const FormDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
130
|
+
declare const FormMessage: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Props interface for the Form component.
|
|
134
|
+
* Extends react-hook-form's FormProvider props.
|
|
135
|
+
*/
|
|
136
|
+
interface FormProps<TFieldValues extends FieldValues = FieldValues> {
|
|
137
|
+
/**
|
|
138
|
+
* The form context value
|
|
139
|
+
*/
|
|
140
|
+
context: React.Context<TFieldValues>;
|
|
141
|
+
/**
|
|
142
|
+
* The form children
|
|
143
|
+
*/
|
|
144
|
+
children: React.ReactNode;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Props interface for the FormField component.
|
|
148
|
+
* Extends react-hook-form's Controller props.
|
|
149
|
+
*/
|
|
150
|
+
interface FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ControllerProps<TFieldValues, TName> {
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Props interface for the FormItem component.
|
|
154
|
+
* Extends HTML div attributes.
|
|
155
|
+
*/
|
|
156
|
+
interface FormItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Props interface for the FormLabel component.
|
|
160
|
+
* Extends Radix UI Label props.
|
|
161
|
+
*/
|
|
162
|
+
interface FormLabelProps extends React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> {
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Props interface for the FormControl component.
|
|
166
|
+
* Extends Radix UI Slot props.
|
|
167
|
+
*/
|
|
168
|
+
interface FormControlProps extends React.ComponentPropsWithoutRef<typeof Slot> {
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Props interface for the FormDescription component.
|
|
172
|
+
* Extends HTML paragraph attributes.
|
|
173
|
+
*/
|
|
174
|
+
interface FormDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Props interface for the FormMessage component.
|
|
178
|
+
* Extends HTML paragraph attributes.
|
|
179
|
+
*/
|
|
180
|
+
interface FormMessageProps extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
181
|
+
/**
|
|
182
|
+
* The message content
|
|
183
|
+
*/
|
|
184
|
+
children?: React.ReactNode;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Context value type for form field context
|
|
188
|
+
*/
|
|
189
|
+
type FormFieldContextValue<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
190
|
+
name: TName;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Context value type for form item context
|
|
194
|
+
*/
|
|
195
|
+
type FormItemContextValue = {
|
|
196
|
+
id: string;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { Form, FormControl, type FormControlProps, FormDescription, type FormDescriptionProps, FormField, type FormFieldContextValue, type FormFieldProps, FormItem, type FormItemContextValue, type FormItemProps, FormLabel, type FormLabelProps, FormMessage, type FormMessageProps, type FormProps, RHFTextField, RHFTextarea, useFormField };
|