@twintag/twintag-form 1.4.0-beta.0 → 1.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +121 -62
  4. package/dev/main.tsx +453 -209
  5. package/dist/common/button.d.ts +3 -2
  6. package/dist/common/calendar.d.ts +4 -4
  7. package/dist/common/form.d.ts +11 -11
  8. package/dist/common/icon.d.ts +2 -1
  9. package/dist/common/input.d.ts +3 -2
  10. package/dist/common/label.d.ts +3 -2
  11. package/dist/common/slider.d.ts +4 -0
  12. package/dist/common/textarea.d.ts +3 -2
  13. package/dist/components/config.d.ts +4 -2
  14. package/dist/components/containers/accordion.d.ts +5 -6
  15. package/dist/components/containers/category.d.ts +3 -2
  16. package/dist/components/fields/checkbox.d.ts +5 -3
  17. package/dist/components/fields/date-picker.d.ts +4 -2
  18. package/dist/components/fields/file.d.ts +5 -3
  19. package/dist/components/fields/input.d.ts +5 -3
  20. package/dist/components/fields/radiogroup.d.ts +7 -3
  21. package/dist/components/fields/submit.d.ts +3 -2
  22. package/dist/components/fields/textarea.d.ts +5 -3
  23. package/dist/components/fields/toggle.d.ts +5 -3
  24. package/dist/components/fields/tri-toggle.d.ts +5 -0
  25. package/dist/components/form.d.ts +2 -2
  26. package/dist/components/provider.d.ts +21 -0
  27. package/dist/components/renderer.d.ts +1 -0
  28. package/dist/index.d.ts +4 -3
  29. package/dist/twintag-form.react.js +12880 -12304
  30. package/dist/types/index.d.ts +43 -20
  31. package/dist/utils/data.d.ts +7 -2
  32. package/dist/utils/style.d.ts +2 -1
  33. package/index.html +6 -3
  34. package/lib/common/slider.tsx +38 -0
  35. package/lib/components/config.tsx +46 -17
  36. package/lib/components/containers/accordion.tsx +33 -18
  37. package/lib/components/containers/category.tsx +1 -1
  38. package/lib/components/fields/checkbox.tsx +5 -3
  39. package/lib/components/fields/date-picker.tsx +9 -2
  40. package/lib/components/fields/file.tsx +5 -4
  41. package/lib/components/fields/input.tsx +5 -3
  42. package/lib/components/fields/radiogroup.tsx +9 -3
  43. package/lib/components/fields/submit.tsx +1 -1
  44. package/lib/components/fields/textarea.tsx +5 -3
  45. package/lib/components/fields/toggle.tsx +5 -3
  46. package/lib/components/fields/tri-toggle.tsx +141 -0
  47. package/lib/components/form.tsx +5 -7
  48. package/lib/components/provider.tsx +163 -0
  49. package/lib/components/{Render/index.tsx → renderer.tsx} +19 -2
  50. package/lib/index.tsx +41 -41
  51. package/lib/types/index.ts +69 -29
  52. package/lib/utils/data.ts +5 -2
  53. package/package.json +6 -8
  54. package/dist/components/Render/index.d.ts +0 -7
  55. package/dist/components/Render/useJson.d.ts +0 -2
  56. package/dist/components/index.d.ts +0 -7
  57. package/dist/provider.d.ts +0 -8
  58. package/lib/components/Render/useJson.ts +0 -76
  59. package/lib/components/index.tsx +0 -24
  60. package/lib/provider.tsx +0 -39
@@ -1,35 +1,58 @@
1
- import type { ElementType } from 'react';
2
- export type TwintagFormContext = {
3
- variant?: 'default' | 'beta';
4
- size?: 'base' | 'sm';
5
- components: Map<string, ElementType>;
1
+ import { ElementType } from 'react';
2
+
3
+ export type InputCompConfig = {
4
+ defaultValue?: unknown;
5
+ component: ElementType;
6
6
  };
7
- type RawProps = Partial<{
7
+ type CompType = 'input' | 'item' | 'accordion' | 'category';
8
+ type StringLiteral<T> = T extends string ? string extends T ? never : T : never;
9
+ type RawProps<TType extends string = string, TSubtype extends string = string> = TType extends 'input' | 'item' ? {
10
+ type: TType;
8
11
  bind: string;
9
- subtype: string;
10
- label: string;
11
- icon: string;
12
- options: Partial<{
12
+ label?: string;
13
+ subtype?: string;
14
+ options?: Partial<{
13
15
  description: string;
14
16
  placeholder: string;
15
17
  error: string;
16
18
  optionalField: boolean;
17
19
  }>;
18
- }>;
19
- export type RawJsonComponent = RawProps & Record<string, unknown> & {
20
- type: string;
21
- children?: RawJsonComponent[];
22
- } & {
23
- props?: RawProps;
20
+ } : TType extends 'accordion' ? TSubtype extends 'item' ? {
21
+ type: TType;
22
+ subtype: TSubtype;
23
+ value?: string;
24
+ label: string;
25
+ icon: string;
26
+ } : TSubtype extends 'multiple' | 'single' ? {
27
+ type: TType;
28
+ subtype: TSubtype;
29
+ defaultValue?: string;
30
+ } : never : {
31
+ type: TType;
32
+ label?: string;
33
+ subtype?: string;
24
34
  };
25
- export type ParsedJsonComponent = Props & {
35
+ export type RawJsonComponent = CompType extends infer T ? T extends CompType ? {
36
+ type: StringLiteral<T>;
37
+ props?: Omit<RawProps<StringLiteral<T>>, 'type'>;
38
+ children?: RawJsonComponent[];
39
+ } : never : never;
40
+ export type ParsedJsonComponent<TType extends string = string> = RawProps<TType> & {
26
41
  id: string;
27
42
  type: string;
28
43
  subtype?: string;
29
44
  comp?: ElementType;
30
- };
31
- export type Props = Omit<RawProps, 'subtype'> & {
32
- bind: string;
33
45
  items?: ParsedJsonComponent[];
34
46
  };
47
+ export type Props<TType extends string = string, TSubtype extends string = string> = Omit<RawProps<TType, TSubtype>, 'type'> & {
48
+ items?: (Props<'input'> & ParsedJsonComponent)[];
49
+ };
50
+ export type TwintagFormContext = {
51
+ variant?: 'default' | 'beta';
52
+ size?: 'base' | 'sm';
53
+ inputs: Map<string, InputCompConfig>;
54
+ components: Map<string, ElementType>;
55
+ config: ParsedJsonComponent[] | ParsedJsonComponent;
56
+ resetValues: Record<string, unknown>;
57
+ };
35
58
  export {};
@@ -1,2 +1,7 @@
1
- import type { Props } from '../types';
2
- export declare const getBindSetFromItems: (items: Props[]) => Set<string>;
1
+ import { Props } from '../types';
2
+
3
+ type Items = (Props<'input'> & {
4
+ items?: Items[];
5
+ })[];
6
+ export declare const getBindSetFromItems: (items: Items) => Set<string>;
7
+ export {};
@@ -1,2 +1,3 @@
1
- import type { ClassValue } from 'clsx';
1
+ import { ClassValue } from 'clsx';
2
+
2
3
  export declare function cn(...inputs: ClassValue[]): string;
package/index.html CHANGED
@@ -8,12 +8,15 @@
8
8
  <body>
9
9
  <div
10
10
  style="
11
- display: grid;
12
- grid-template-columns: repeat(2, 1fr);
13
- padding: 2rem;
11
+ display: flex;
12
+ flex-direction: column;
13
+ align-items: center;
14
+ gap: 2rem;
15
+ padding: 1rem;
14
16
  "
15
17
  >
16
18
  <div>
19
+ <button id="set-config">Set config</button>
17
20
  <button id="get-values">Get Values</button>
18
21
  <button id="submit">Submit</button>
19
22
  </div>
@@ -0,0 +1,38 @@
1
+ import * as React from 'react';
2
+ import * as SliderPrimitive from '@radix-ui/react-slider';
3
+ import { tv } from 'tailwind-variants';
4
+
5
+ const sliderVariants = tv({
6
+ slots: {
7
+ root: 'relative flex w-full touch-none select-none items-center',
8
+ track: 'relative h-2 w-full grow overflow-hidden rounded-full bg-muted',
9
+ range: 'absolute h-full bg-accent',
10
+ thumb:
11
+ 'block h-5 w-5 rounded-full border-2 border-accent bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
12
+ },
13
+ });
14
+
15
+ const Slider = React.forwardRef<
16
+ React.ElementRef<typeof SliderPrimitive.Root>,
17
+ React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
18
+ >(({ className, ...props }, ref) => {
19
+ const { root, track, range, thumb } = sliderVariants();
20
+
21
+ return (
22
+ <SliderPrimitive.Root
23
+ ref={ref}
24
+ className={root({
25
+ className,
26
+ })}
27
+ {...props}
28
+ >
29
+ <SliderPrimitive.Track className={track()}>
30
+ <SliderPrimitive.Range className={range()} />
31
+ </SliderPrimitive.Track>
32
+ <SliderPrimitive.Thumb className={thumb()} />
33
+ </SliderPrimitive.Root>
34
+ );
35
+ });
36
+ Slider.displayName = SliderPrimitive.Root.displayName;
37
+
38
+ export { Slider };
@@ -1,25 +1,54 @@
1
1
  import type { ElementType, FC } from 'react';
2
+ import type { InputCompConfig } from '../types';
2
3
 
3
4
  import { Accordion } from './containers/accordion';
4
5
  import { Category } from './containers/category';
5
- import { Checkbox } from './fields/checkbox';
6
- import { DatePicker } from './fields/date-picker';
7
- import { File } from './fields/file';
8
- import { Input as InputField } from './fields/input';
9
- import { RadioGroup } from './fields/radiogroup';
6
+ import { Checkbox, DEFAULT_CHECKBOX_VALUE } from './fields/checkbox';
7
+ import { DatePicker, DEFAULT_DATE_PICKER_VALUE } from './fields/date-picker';
8
+ import { DEFAULT_FILE_VALUE, File } from './fields/file';
9
+ import { DEFAULT_INPUT_VALUE, Input as InputField } from './fields/input';
10
+ import { DEFAULT_RADIOGROUP_VALUE, RadioGroup } from './fields/radiogroup';
10
11
  import { Submit } from './fields/submit';
11
- import { Textarea } from './fields/textarea';
12
- import { Toggle } from './fields/toggle';
12
+ import { DEFAULT_TEXTAREA_VALUE, Textarea } from './fields/textarea';
13
+ import { DEFAULT_TOGGLE_VALUE, Toggle } from './fields/toggle';
14
+ import { DEFAULT_TRI_TOGGLE_VALUE, TriToggle } from './fields/tri-toggle';
13
15
 
14
- export const Inputs = new Map<string, ElementType>()
15
- .set('simple', InputField)
16
- .set('textarea', Textarea)
17
- .set('toggle', Toggle)
18
- .set('file', File)
19
- .set('submit', Submit)
20
- .set('checkbox', Checkbox)
21
- .set('radiogroup', RadioGroup)
22
- .set('datepicker', DatePicker);
16
+ export const Inputs = new Map<string, InputCompConfig>()
17
+ .set('simple', {
18
+ defaultValue: DEFAULT_INPUT_VALUE,
19
+ component: InputField,
20
+ })
21
+ .set('textarea', {
22
+ defaultValue: DEFAULT_TEXTAREA_VALUE,
23
+ component: Textarea,
24
+ })
25
+ .set('toggle', {
26
+ defaultValue: DEFAULT_TOGGLE_VALUE,
27
+ component: Toggle,
28
+ })
29
+ .set('file', {
30
+ defaultValue: DEFAULT_FILE_VALUE,
31
+ component: File,
32
+ })
33
+ .set('submit', {
34
+ component: Submit,
35
+ })
36
+ .set('checkbox', {
37
+ defaultValue: DEFAULT_CHECKBOX_VALUE,
38
+ component: Checkbox,
39
+ })
40
+ .set('radiogroup', {
41
+ defaultValue: DEFAULT_RADIOGROUP_VALUE,
42
+ component: RadioGroup,
43
+ })
44
+ .set('datepicker', {
45
+ defaultValue: DEFAULT_DATE_PICKER_VALUE,
46
+ component: DatePicker,
47
+ })
48
+ .set('tri-toggle', {
49
+ defaultValue: DEFAULT_TRI_TOGGLE_VALUE,
50
+ component: TriToggle,
51
+ });
23
52
 
24
53
  type InputProps = {
25
54
  subtype?: string;
@@ -27,7 +56,7 @@ type InputProps = {
27
56
  bind?: string;
28
57
  };
29
58
  const Input: FC<InputProps> = ({ subtype = 'simple', ...rest }) => {
30
- const Comp = Inputs.get(subtype);
59
+ const Comp = Inputs.get(subtype)?.component;
31
60
 
32
61
  if (!Comp) return <></>;
33
62
 
@@ -11,11 +11,12 @@ import {
11
11
  AccordionTrigger,
12
12
  } from '@twintag/twintag-form/common/accordion';
13
13
  import { Icon } from '@twintag/twintag-form/common/icon';
14
- import { useTwintagForm } from '@twintag/twintag-form/provider';
14
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
15
15
  import { camelize } from '@twintag/twintag-form/utils/string';
16
16
 
17
17
  type AccordionRootProps = {
18
- multiple?: boolean;
18
+ type: 'single' | 'multiple';
19
+ defaultValue?: string;
19
20
  } & WithChildren;
20
21
 
21
22
  const accordionRootVariants = tv({
@@ -30,17 +31,19 @@ const accordionRootVariants = tv({
30
31
  variant: 'default',
31
32
  },
32
33
  });
33
- const AccordionRoot: FC<AccordionRootProps> = ({
34
- multiple = true,
35
- children,
36
- }) => {
34
+ const AccordionRoot: FC<AccordionRootProps> = ({ type, defaultValue, children }) => {
37
35
  const { variant } = useTwintagForm();
38
36
 
37
+ if (type === 'single') {
38
+ return (
39
+ <AccordionPrimitive type='single' defaultValue={defaultValue} collapsible>
40
+ <div className={accordionRootVariants({ variant })}>{children}</div>
41
+ </AccordionPrimitive>
42
+ );
43
+ }
44
+
39
45
  return (
40
- <AccordionPrimitive
41
- type={multiple ? 'multiple' : 'single'}
42
- collapsible={multiple ? undefined : true}
43
- >
46
+ <AccordionPrimitive type='multiple'>
44
47
  <div className={accordionRootVariants({ variant })}>{children}</div>
45
48
  </AccordionPrimitive>
46
49
  );
@@ -80,11 +83,15 @@ const accordionItemVariants = tv({
80
83
  },
81
84
  });
82
85
 
83
- type AccordionItemProps = Omit<Props, 'bind'> & WithChildren;
86
+ type AccordionItemProps = Omit<Props<'accordion', 'item'>, 'subtype'> & {
87
+ value?: string;
88
+ } & WithChildren;
84
89
  const AccordionItem: FC<AccordionItemProps> = ({
85
90
  label = '',
91
+ value = '',
86
92
  icon,
87
93
  children,
94
+ ...rest
88
95
  }) => {
89
96
  const { variant, size } = useTwintagForm();
90
97
 
@@ -96,7 +103,11 @@ const AccordionItem: FC<AccordionItemProps> = ({
96
103
  } = accordionItemVariants({ size, variant });
97
104
 
98
105
  return (
99
- <AccordionItemPrimitive value={camelize(label)} className={item()}>
106
+ <AccordionItemPrimitive
107
+ value={value ?? camelize(label)}
108
+ className={item()}
109
+ {...rest}
110
+ >
100
111
  <AccordionTrigger className='text-category'>
101
112
  <span className={trigger()}>
102
113
  {icon ? <Icon name={icon} className={iconVariants()} /> : <></>}
@@ -109,14 +120,18 @@ const AccordionItem: FC<AccordionItemProps> = ({
109
120
  };
110
121
  AccordionItem.displayName = 'AccordionItem';
111
122
 
112
- type AccordionProps = {
113
- subtype?: 'item' | 'multiple' | 'single';
114
- label?: string;
115
- } & WithChildren;
123
+ type AccordionProps = Props<'accordion', 'item' | 'multiple' | 'single'> &
124
+ WithChildren;
116
125
  const Accordion: FC<AccordionProps> = ({ subtype = 'single', ...rest }) => {
117
- if (subtype === 'item') return <AccordionItem {...rest} />;
126
+ if (subtype === 'item') {
127
+ return (
128
+ <AccordionItem
129
+ {...(rest as Omit<Props<'accordion', 'item'>, 'subtype'>)}
130
+ />
131
+ );
132
+ }
118
133
 
119
- return <AccordionRoot {...rest} />;
134
+ return <AccordionRoot type={subtype} {...rest} />;
120
135
  };
121
136
 
122
137
  export { Accordion };
@@ -3,7 +3,7 @@ import type { WithChildren } from 'twintag-types/dom';
3
3
 
4
4
  import { tv } from 'tailwind-variants';
5
5
 
6
- import { useTwintagForm } from '@twintag/twintag-form/provider';
6
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
7
7
 
8
8
  const categoryStyle = tv({
9
9
  slots: {
@@ -13,9 +13,11 @@ import {
13
13
  FormLabel,
14
14
  FormMessage,
15
15
  } from '@twintag/twintag-form/common/form';
16
- import { useTwintagForm } from '@twintag/twintag-form/provider';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
17
 
18
- export const Checkbox: FC<Props> = ({ label, bind, options }) => {
18
+ export const DEFAULT_CHECKBOX_VALUE = false;
19
+
20
+ export const Checkbox: FC<Props<'input'>> = ({ label, bind, options }) => {
19
21
  const { control } = useFormContext();
20
22
  const { variant, size } = useTwintagForm();
21
23
 
@@ -23,9 +25,9 @@ export const Checkbox: FC<Props> = ({ label, bind, options }) => {
23
25
 
24
26
  return (
25
27
  <FormField
28
+ defaultValue={DEFAULT_CHECKBOX_VALUE}
26
29
  control={control}
27
30
  name={bind}
28
- defaultValue={false}
29
31
  rules={{
30
32
  required: isOptional ? false : options?.error ?? true,
31
33
  }}
@@ -21,7 +21,7 @@ import {
21
21
  PopoverContent,
22
22
  PopoverTrigger,
23
23
  } from '@twintag/twintag-form/common/popover';
24
- import { useTwintagForm } from '@twintag/twintag-form/provider';
24
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
25
25
 
26
26
  const datePickerTriggerVariants = tv({
27
27
  slots: {
@@ -63,7 +63,13 @@ const datePickerTriggerVariants = tv({
63
63
  },
64
64
  });
65
65
 
66
- export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
66
+ export const DEFAULT_DATE_PICKER_VALUE = null;
67
+
68
+ export const DatePicker: React.FC<Props<'input'>> = ({
69
+ label,
70
+ bind,
71
+ options,
72
+ }) => {
67
73
  const { variant, size } = useTwintagForm();
68
74
  const { control } = useFormContext();
69
75
 
@@ -73,6 +79,7 @@ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
73
79
 
74
80
  return (
75
81
  <FormField
82
+ defaultValue={DEFAULT_DATE_PICKER_VALUE}
76
83
  control={control}
77
84
  name={bind}
78
85
  rules={{
@@ -13,9 +13,11 @@ import {
13
13
  FormMessage,
14
14
  } from '@twintag/twintag-form/common/form';
15
15
  import { Input } from '@twintag/twintag-form/common/input';
16
- import { useTwintagForm } from '@twintag/twintag-form/provider';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
17
 
18
- export const File: FC<Props> = ({ label, bind, options }) => {
18
+ export const DEFAULT_FILE_VALUE = '';
19
+
20
+ export const File: FC<Props<'input'>> = ({ label, bind, options }) => {
19
21
  const { control } = useFormContext();
20
22
  const { variant, size } = useTwintagForm();
21
23
 
@@ -23,7 +25,7 @@ export const File: FC<Props> = ({ label, bind, options }) => {
23
25
 
24
26
  return (
25
27
  <FormField
26
- defaultValue=''
28
+ defaultValue={DEFAULT_FILE_VALUE}
27
29
  control={control}
28
30
  name={bind}
29
31
  rules={{
@@ -64,7 +66,6 @@ export const File: FC<Props> = ({ label, bind, options }) => {
64
66
  name={field.name}
65
67
  size={size}
66
68
  variant={variant}
67
- capture='environment'
68
69
  multiple
69
70
  onBlur={field.onBlur}
70
71
  onChange={(e) => {
@@ -13,9 +13,11 @@ import {
13
13
  FormMessage,
14
14
  } from '@twintag/twintag-form/common/form';
15
15
  import { Input as InputPrimitive } from '@twintag/twintag-form/common/input';
16
- import { useTwintagForm } from '@twintag/twintag-form/provider';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
17
 
18
- export const Input: FC<Props> = ({ label, bind, options }) => {
18
+ export const DEFAULT_INPUT_VALUE = '';
19
+
20
+ export const Input: FC<Props<'input'>> = ({ label, bind, options }) => {
19
21
  const { control } = useFormContext();
20
22
 
21
23
  const { variant, size } = useTwintagForm();
@@ -24,7 +26,7 @@ export const Input: FC<Props> = ({ label, bind, options }) => {
24
26
 
25
27
  return (
26
28
  <FormField
27
- defaultValue=''
29
+ defaultValue={DEFAULT_INPUT_VALUE}
28
30
  control={control}
29
31
  name={bind}
30
32
  rules={{
@@ -16,9 +16,15 @@ import {
16
16
  RadioGroup as CommonRadioGroup,
17
17
  RadioGroupItem,
18
18
  } from '@twintag/twintag-form/common/radiogroup';
19
- import { useTwintagForm } from '@twintag/twintag-form/provider';
19
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
20
20
 
21
- export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
21
+ export const DEFAULT_RADIOGROUP_VALUE = '';
22
+
23
+ export const RadioGroup: FC<
24
+ Props<'input'> & {
25
+ items: Props<'input'>[];
26
+ }
27
+ > = ({ label, bind, items, options }) => {
22
28
  const { control } = useFormContext();
23
29
  const { size } = useTwintagForm();
24
30
 
@@ -26,9 +32,9 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
26
32
 
27
33
  return (
28
34
  <FormField
35
+ defaultValue={DEFAULT_RADIOGROUP_VALUE}
29
36
  control={control}
30
37
  name={bind}
31
- defaultValue=''
32
38
  rules={{
33
39
  required: isOptional ? false : options?.error ?? true,
34
40
  }}
@@ -2,7 +2,7 @@ import type { FC } from 'react';
2
2
  import type { Props } from '@twintag/twintag-form/types';
3
3
 
4
4
  import { Button } from '@twintag/twintag-form/common/button';
5
- import { useTwintagForm } from '@twintag/twintag-form/provider';
5
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
6
6
 
7
7
  export const Submit: FC<Props> = ({ label }) => {
8
8
  const { size } = useTwintagForm();
@@ -13,9 +13,11 @@ import {
13
13
  FormMessage,
14
14
  } from '@twintag/twintag-form/common/form';
15
15
  import { Textarea as CommonTextarea } from '@twintag/twintag-form/common/textarea';
16
- import { useTwintagForm } from '@twintag/twintag-form/provider';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
17
 
18
- export const Textarea: FC<Props> = ({ label, bind, options }) => {
18
+ export const DEFAULT_TEXTAREA_VALUE = '';
19
+
20
+ export const Textarea: FC<Props<'input'>> = ({ label, bind, options }) => {
19
21
  const { control } = useFormContext();
20
22
  const { variant, size } = useTwintagForm();
21
23
 
@@ -23,7 +25,7 @@ export const Textarea: FC<Props> = ({ label, bind, options }) => {
23
25
 
24
26
  return (
25
27
  <FormField
26
- defaultValue=''
28
+ defaultValue={DEFAULT_TEXTAREA_VALUE}
27
29
  control={control}
28
30
  name={bind}
29
31
  rules={{
@@ -13,9 +13,11 @@ import {
13
13
  FormMessage,
14
14
  } from '@twintag/twintag-form/common/form';
15
15
  import { Switch } from '@twintag/twintag-form/common/switch';
16
- import { useTwintagForm } from '@twintag/twintag-form/provider';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
17
 
18
- export const Toggle: FC<Props> = ({ label, bind, options }) => {
18
+ export const DEFAULT_TOGGLE_VALUE = false;
19
+
20
+ export const Toggle: FC<Props<'input'>> = ({ label, bind, options }) => {
19
21
  const { control } = useFormContext();
20
22
  const { variant, size } = useTwintagForm();
21
23
 
@@ -23,9 +25,9 @@ export const Toggle: FC<Props> = ({ label, bind, options }) => {
23
25
 
24
26
  return (
25
27
  <FormField
28
+ defaultValue={DEFAULT_TOGGLE_VALUE}
26
29
  control={control}
27
30
  name={bind}
28
- defaultValue={false}
29
31
  rules={{
30
32
  required: isOptional ? false : options?.error ?? true,
31
33
  }}