@twintag/twintag-form 1.3.0 → 1.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) 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 +233 -210
  5. package/dist/common/button.d.ts +17 -30
  6. package/dist/common/calendar.d.ts +212 -4
  7. package/dist/common/form.d.ts +151 -9
  8. package/dist/common/icon.d.ts +2 -1
  9. package/dist/common/input.d.ts +276 -2
  10. package/dist/common/label.d.ts +39 -1
  11. package/dist/common/slider.d.ts +4 -0
  12. package/dist/common/textarea.d.ts +139 -2
  13. package/dist/components/config.d.ts +4 -2
  14. package/dist/components/containers/accordion.d.ts +3 -2
  15. package/dist/components/containers/category.d.ts +3 -2
  16. package/dist/components/fields/checkbox.d.ts +4 -2
  17. package/dist/components/fields/date-picker.d.ts +3 -1
  18. package/dist/components/fields/file.d.ts +4 -2
  19. package/dist/components/fields/input.d.ts +4 -2
  20. package/dist/components/fields/radiogroup.d.ts +4 -2
  21. package/dist/components/fields/submit.d.ts +3 -2
  22. package/dist/components/fields/textarea.d.ts +4 -2
  23. package/dist/components/fields/toggle.d.ts +4 -2
  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 +5 -3
  29. package/dist/twintag-form.react.js +12868 -12156
  30. package/dist/types/index.d.ts +25 -16
  31. package/dist/utils/data.d.ts +2 -1
  32. package/dist/utils/style.d.ts +2 -1
  33. package/index.html +5 -3
  34. package/lib/common/button.tsx +4 -5
  35. package/lib/common/calendar.tsx +25 -5
  36. package/lib/common/form.tsx +40 -19
  37. package/lib/common/input.tsx +20 -10
  38. package/lib/common/label.tsx +16 -3
  39. package/lib/common/slider.tsx +38 -0
  40. package/lib/common/textarea.tsx +17 -9
  41. package/lib/components/config.tsx +46 -17
  42. package/lib/components/containers/accordion.tsx +24 -7
  43. package/lib/components/containers/category.tsx +16 -7
  44. package/lib/components/fields/checkbox.tsx +12 -6
  45. package/lib/components/fields/date-picker.tsx +54 -18
  46. package/lib/components/fields/file.tsx +83 -76
  47. package/lib/components/fields/input.tsx +15 -6
  48. package/lib/components/fields/radiogroup.tsx +13 -7
  49. package/lib/components/fields/submit.tsx +5 -2
  50. package/lib/components/fields/textarea.tsx +14 -6
  51. package/lib/components/fields/toggle.tsx +12 -6
  52. package/lib/components/fields/tri-toggle.tsx +141 -0
  53. package/lib/components/form.tsx +5 -7
  54. package/lib/components/provider.tsx +159 -0
  55. package/lib/components/{Render/index.tsx → renderer.tsx} +19 -2
  56. package/lib/index.tsx +41 -36
  57. package/lib/types/index.ts +49 -39
  58. package/package.json +5 -7
  59. package/dist/components/Render/index.d.ts +0 -7
  60. package/dist/components/Render/useJson.d.ts +0 -2
  61. package/dist/components/index.d.ts +0 -7
  62. package/dist/provider.d.ts +0 -8
  63. package/lib/components/Render/useJson.ts +0 -76
  64. package/lib/components/index.tsx +0 -24
  65. package/lib/provider.tsx +0 -36
@@ -3,26 +3,35 @@ 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: {
10
- container: 'relative w-full space-y-4',
10
+ container: 'relative w-full space-y-3',
11
11
  heading: 'font-tf-font text-category',
12
- content: 'grid gap-4',
12
+ content: 'grid gap-3',
13
13
  },
14
14
  variants: {
15
15
  variant: {
16
16
  default: {
17
- heading: 'text-base font-medium',
17
+ heading: 'font-medium',
18
18
  },
19
19
  beta: {
20
- heading: 'text-sm font-normal',
20
+ heading: 'font-normal',
21
+ },
22
+ },
23
+ size: {
24
+ sm: {
25
+ heading: 'text-sm',
26
+ },
27
+ base: {
28
+ heading: 'text-base',
21
29
  },
22
30
  },
23
31
  },
24
32
  defaultVariants: {
25
33
  variant: 'default',
34
+ size: 'base',
26
35
  },
27
36
  });
28
37
 
@@ -31,9 +40,9 @@ type Props = {
31
40
  } & WithChildren;
32
41
 
33
42
  const Category: FC<Props> = ({ label, children }) => {
34
- const { variant } = useTwintagForm();
43
+ const { variant, size } = useTwintagForm();
35
44
 
36
- const { container, heading, content } = categoryStyle({ variant });
45
+ const { container, heading, content } = categoryStyle({ size, variant });
37
46
 
38
47
  return (
39
48
  <section className={container()}>
@@ -13,22 +13,26 @@ import {
13
13
  FormLabel,
14
14
  FormMessage,
15
15
  } from '@twintag/twintag-form/common/form';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
+
18
+ export const DEFAULT_CHECKBOX_VALUE = false;
16
19
 
17
20
  export const Checkbox: FC<Props> = ({ label, bind, options }) => {
18
21
  const { control } = useFormContext();
22
+ const { variant, size } = useTwintagForm();
19
23
 
20
24
  const isOptional = options?.optionalField;
21
25
 
22
26
  return (
23
27
  <FormField
28
+ defaultValue={DEFAULT_CHECKBOX_VALUE}
24
29
  control={control}
25
30
  name={bind}
26
- defaultValue={false}
27
31
  rules={{
28
32
  required: isOptional ? false : options?.error ?? true,
29
33
  }}
30
34
  render={({ field }) => (
31
- <FormItem className='pt-1.5'>
35
+ <FormItem variant={variant} className='pt-1.5'>
32
36
  <div className='flex space-x-2'>
33
37
  <FormControl>
34
38
  <CommonCheckbox
@@ -39,8 +43,8 @@ export const Checkbox: FC<Props> = ({ label, bind, options }) => {
39
43
  }}
40
44
  />
41
45
  </FormControl>
42
- <div className='grid gap-1.5'>
43
- <FormLabel>
46
+ <div className='grid gap-1'>
47
+ <FormLabel size={size}>
44
48
  {label}
45
49
  {!isOptional ? (
46
50
  <span className='ml-0.5 inline-block'>
@@ -51,11 +55,13 @@ export const Checkbox: FC<Props> = ({ label, bind, options }) => {
51
55
  )}
52
56
  </FormLabel>
53
57
  {options?.description ? (
54
- <FormDescription>{options.description}</FormDescription>
58
+ <FormDescription size={size}>
59
+ {options.description}
60
+ </FormDescription>
55
61
  ) : (
56
62
  <></>
57
63
  )}
58
- <FormMessage />
64
+ <FormMessage size={size} />
59
65
  </div>
60
66
  </div>
61
67
  </FormItem>
@@ -21,40 +21,73 @@ 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
- const triggerVariants = tv({
27
- base: 'w-full justify-start text-left font-normal',
26
+ const datePickerTriggerVariants = tv({
27
+ slots: {
28
+ button: 'w-full justify-start text-left font-normal',
29
+ icon: 'ml-auto text-muted-foreground opacity-70',
30
+ },
28
31
  variants: {
29
32
  variant: {
30
- default: 'px-3',
31
- beta: 'rounded-none border-x-transparent border-t-transparent px-1 transition-none hover:bg-white hover:text-muted-foreground',
33
+ default: {
34
+ button: 'px-3',
35
+ },
36
+ beta: {
37
+ button:
38
+ 'rounded-none border-x-transparent border-t-transparent px-1 transition-none hover:bg-white hover:text-muted-foreground',
39
+ },
32
40
  },
33
41
  withValue: {
34
- true: 'text-muted-foreground',
35
- false: '',
42
+ true: {
43
+ button: 'text-muted-foreground',
44
+ },
45
+ false: {
46
+ button: '',
47
+ },
48
+ },
49
+ size: {
50
+ sm: {
51
+ button: 'text-sm',
52
+ icon: 'h-4 w-4',
53
+ },
54
+ base: {
55
+ button: 'text-base',
56
+ icon: 'h-5 w-5',
57
+ },
36
58
  },
37
59
  },
60
+ defaultVariants: {
61
+ variant: 'default',
62
+ size: 'base',
63
+ },
38
64
  });
39
65
 
40
- export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
41
- const { variant } = useTwintagForm();
66
+ export const DEFAULT_DATE_PICKER_VALUE = null;
42
67
 
68
+ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
69
+ const { variant, size } = useTwintagForm();
43
70
  const { control } = useFormContext();
44
71
 
72
+ const { button, icon } = datePickerTriggerVariants({ variant, size });
73
+
45
74
  const isOptional = options?.optionalField;
46
75
 
47
76
  return (
48
77
  <FormField
78
+ defaultValue={DEFAULT_DATE_PICKER_VALUE}
49
79
  control={control}
50
80
  name={bind}
51
81
  rules={{
52
82
  required: isOptional ? false : options?.error ?? true,
53
83
  }}
54
84
  render={({ field }) => (
55
- <FormItem className='flex flex-col [&>div[data-radix-popper-content-wrapper]]:!z-50'>
56
- <div className='space-y-0.5'>
57
- <FormLabel>
85
+ <FormItem
86
+ variant={variant}
87
+ className='flex flex-col [&>div[data-radix-popper-content-wrapper]]:!z-50'
88
+ >
89
+ <div className='space-y-1'>
90
+ <FormLabel size={size}>
58
91
  {label}
59
92
  {!isOptional ? (
60
93
  <span className='ml-0.5 inline-block'>
@@ -65,7 +98,9 @@ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
65
98
  )}
66
99
  </FormLabel>
67
100
  {options?.description ? (
68
- <FormDescription>{options.description}</FormDescription>
101
+ <FormDescription size={size}>
102
+ {options.description}
103
+ </FormDescription>
69
104
  ) : (
70
105
  <></>
71
106
  )}
@@ -75,10 +110,10 @@ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
75
110
  <FormControl>
76
111
  <Button
77
112
  variant='outline'
78
- className={triggerVariants({
79
- variant,
113
+ size={size}
114
+ className={button({
80
115
  withValue: !field.value,
81
- className: 'h-10 gap-3',
116
+ className: 'h-10 gap-2',
82
117
  })}
83
118
  >
84
119
  {field.value ? (
@@ -86,7 +121,7 @@ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
86
121
  ) : (
87
122
  <span>{options?.placeholder ?? 'Select a date'}</span>
88
123
  )}
89
- <CalendarIcon className='ml-auto h-4 w-4 opacity-50' />
124
+ <CalendarIcon className={icon()} />
90
125
  </Button>
91
126
  </FormControl>
92
127
  </PopoverTrigger>
@@ -96,6 +131,7 @@ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
96
131
  toYear={2050}
97
132
  captionLayout='dropdown-buttons'
98
133
  mode='single'
134
+ size={size}
99
135
  selected={
100
136
  !isNaN(new Date(field.value as Date).getTime())
101
137
  ? new Date(field.value as Date)
@@ -106,7 +142,7 @@ export const DatePicker: React.FC<Props> = ({ label, bind, options }) => {
106
142
  />
107
143
  </PopoverContent>
108
144
  </Popover>
109
- <FormMessage className='pt-1' />
145
+ <FormMessage size={size} className='pt-1' />
110
146
  </FormItem>
111
147
  )}
112
148
  />
@@ -1,76 +1,83 @@
1
- import type { FC } from 'react';
2
- import type { Props } from '@twintag/twintag-form/types';
3
-
4
- import { AsteriskIcon } from 'lucide-react';
5
- import { useFormContext } from 'react-hook-form';
6
-
7
- import {
8
- FormControl,
9
- FormDescription,
10
- FormField,
11
- FormItem,
12
- FormLabel,
13
- FormMessage,
14
- } from '@twintag/twintag-form/common/form';
15
- import { Input } from '@twintag/twintag-form/common/input';
16
-
17
- export const File: FC<Props> = ({ label, bind, options }) => {
18
- const { control } = useFormContext();
19
-
20
- const isOptional = options?.optionalField;
21
-
22
- return (
23
- <FormField
24
- defaultValue=''
25
- control={control}
26
- name={bind}
27
- rules={{
28
- required: isOptional ? false : options?.error ?? true,
29
- }}
30
- render={({ field, formState }) => (
31
- <FormItem>
32
- <div className='space-y-0.5'>
33
- <FormLabel htmlFor={bind}>
34
- {label}
35
- {!isOptional ? (
36
- <span className='ml-0.5 inline-block'>
37
- <AsteriskIcon className='h-3 w-3 text-destructive' />
38
- </span>
39
- ) : (
40
- <></>
41
- )}
42
- </FormLabel>
43
- {options?.description ? (
44
- <FormDescription>{options.description}</FormDescription>
45
- ) : (
46
- <></>
47
- )}
48
- </div>
49
- <FormControl>
50
- <Input
51
- ref={(el) => {
52
- field.ref(el);
53
-
54
- if (el && formState.isSubmitSuccessful) {
55
- el.value = '';
56
- }
57
- }}
58
- id={bind}
59
- type='file'
60
- name={field.name}
61
- capture='environment'
62
- multiple
63
- onBlur={field.onBlur}
64
- onChange={(e) => {
65
- if (e.target.files) {
66
- field.onChange(e.target.files);
67
- }
68
- }}
69
- />
70
- </FormControl>
71
- <FormMessage className='pt-1.5' />
72
- </FormItem>
73
- )}
74
- />
75
- );
76
- };
1
+ import type { FC } from 'react';
2
+ import type { Props } from '@twintag/twintag-form/types';
3
+
4
+ import { AsteriskIcon } from 'lucide-react';
5
+ import { useFormContext } from 'react-hook-form';
6
+
7
+ import {
8
+ FormControl,
9
+ FormDescription,
10
+ FormField,
11
+ FormItem,
12
+ FormLabel,
13
+ FormMessage,
14
+ } from '@twintag/twintag-form/common/form';
15
+ import { Input } from '@twintag/twintag-form/common/input';
16
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
17
+
18
+ export const DEFAULT_FILE_VALUE = '';
19
+
20
+ export const File: FC<Props> = ({ label, bind, options }) => {
21
+ const { control } = useFormContext();
22
+ const { variant, size } = useTwintagForm();
23
+
24
+ const isOptional = options?.optionalField;
25
+
26
+ return (
27
+ <FormField
28
+ defaultValue={DEFAULT_FILE_VALUE}
29
+ control={control}
30
+ name={bind}
31
+ rules={{
32
+ required: isOptional ? false : options?.error ?? true,
33
+ }}
34
+ render={({ field, formState }) => (
35
+ <FormItem variant={variant}>
36
+ <div className='space-y-1'>
37
+ <FormLabel htmlFor={bind} size={size}>
38
+ {label}
39
+ {!isOptional ? (
40
+ <span className='ml-0.5 inline-block'>
41
+ <AsteriskIcon className='h-3 w-3 text-destructive' />
42
+ </span>
43
+ ) : (
44
+ <></>
45
+ )}
46
+ </FormLabel>
47
+ {options?.description ? (
48
+ <FormDescription size={size}>
49
+ {options.description}
50
+ </FormDescription>
51
+ ) : (
52
+ <></>
53
+ )}
54
+ </div>
55
+ <FormControl>
56
+ <Input
57
+ ref={(el) => {
58
+ field.ref(el);
59
+
60
+ if (el && formState.isSubmitSuccessful) {
61
+ el.value = '';
62
+ }
63
+ }}
64
+ id={bind}
65
+ type='file'
66
+ name={field.name}
67
+ size={size}
68
+ variant={variant}
69
+ multiple
70
+ onBlur={field.onBlur}
71
+ onChange={(e) => {
72
+ if (e.target.files) {
73
+ field.onChange(e.target.files);
74
+ }
75
+ }}
76
+ />
77
+ </FormControl>
78
+ <FormMessage size={size} className='pt-1.5' />
79
+ </FormItem>
80
+ )}
81
+ />
82
+ );
83
+ };
@@ -13,24 +13,29 @@ 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/components/provider';
17
+
18
+ export const DEFAULT_INPUT_VALUE = '';
16
19
 
17
20
  export const Input: FC<Props> = ({ label, bind, options }) => {
18
21
  const { control } = useFormContext();
19
22
 
23
+ const { variant, size } = useTwintagForm();
24
+
20
25
  const isOptional = options?.optionalField;
21
26
 
22
27
  return (
23
28
  <FormField
24
- defaultValue=''
29
+ defaultValue={DEFAULT_INPUT_VALUE}
25
30
  control={control}
26
31
  name={bind}
27
32
  rules={{
28
33
  required: isOptional ? false : options?.error ?? true,
29
34
  }}
30
35
  render={({ field }) => (
31
- <FormItem>
32
- <div className='space-y-0.5'>
33
- <FormLabel>
36
+ <FormItem variant={variant}>
37
+ <div className='space-y-1'>
38
+ <FormLabel size={size}>
34
39
  {label}
35
40
  {!isOptional ? (
36
41
  <span className='ml-0.5 inline-block'>
@@ -41,7 +46,9 @@ export const Input: FC<Props> = ({ label, bind, options }) => {
41
46
  )}
42
47
  </FormLabel>
43
48
  {options?.description ? (
44
- <FormDescription>{options.description}</FormDescription>
49
+ <FormDescription size={size}>
50
+ {options.description}
51
+ </FormDescription>
45
52
  ) : (
46
53
  <></>
47
54
  )}
@@ -49,11 +56,13 @@ export const Input: FC<Props> = ({ label, bind, options }) => {
49
56
  <FormControl>
50
57
  <InputPrimitive
51
58
  type='text'
59
+ size={size}
60
+ variant={variant}
52
61
  placeholder={options?.placeholder ?? 'Write here...'}
53
62
  {...field}
54
63
  />
55
64
  </FormControl>
56
- <FormMessage className='pt-1' />
65
+ <FormMessage size={size} className='pt-1' />
57
66
  </FormItem>
58
67
  )}
59
68
  />
@@ -16,24 +16,28 @@ import {
16
16
  RadioGroup as CommonRadioGroup,
17
17
  RadioGroupItem,
18
18
  } from '@twintag/twintag-form/common/radiogroup';
19
+ import { useTwintagForm } from '@twintag/twintag-form/components/provider';
20
+
21
+ export const DEFAULT_RADIOGROUP_VALUE = '';
19
22
 
20
23
  export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
21
24
  const { control } = useFormContext();
25
+ const { size } = useTwintagForm();
22
26
 
23
27
  const isOptional = options?.optionalField;
24
28
 
25
29
  return (
26
30
  <FormField
31
+ defaultValue={DEFAULT_RADIOGROUP_VALUE}
27
32
  control={control}
28
33
  name={bind}
29
- defaultValue=''
30
34
  rules={{
31
35
  required: isOptional ? false : options?.error ?? true,
32
36
  }}
33
37
  render={({ field }) => (
34
38
  <FormItem className='space-y-3'>
35
- <div className='space-y-0.5'>
36
- <FormLabel>
39
+ <div className='space-y-1'>
40
+ <FormLabel size={size}>
37
41
  {label}
38
42
  {!isOptional ? (
39
43
  <span className='ml-0.5 inline-block'>
@@ -44,7 +48,9 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
44
48
  )}
45
49
  </FormLabel>
46
50
  {options?.description ? (
47
- <FormDescription>{options.description}</FormDescription>
51
+ <FormDescription size={size}>
52
+ {options.description}
53
+ </FormDescription>
48
54
  ) : (
49
55
  <></>
50
56
  )}
@@ -60,12 +66,12 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
60
66
  return (
61
67
  <FormItem
62
68
  key={item.id}
63
- className='flex items-center space-x-3 space-y-0'
69
+ className='flex items-center space-x-2 space-y-0'
64
70
  >
65
71
  <FormControl>
66
72
  <RadioGroupItem value={item.bind} />
67
73
  </FormControl>
68
- <FormLabel className='font-normal'>
74
+ <FormLabel size={size} className='font-normal'>
69
75
  {item.label}
70
76
  </FormLabel>
71
77
  </FormItem>
@@ -76,7 +82,7 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
76
82
  })}
77
83
  </CommonRadioGroup>
78
84
  </FormControl>
79
- <FormMessage />
85
+ <FormMessage size={size} />
80
86
  </FormItem>
81
87
  )}
82
88
  />
@@ -2,11 +2,14 @@ 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/components/provider';
5
6
 
6
7
  export const Submit: FC<Props> = ({ label }) => {
8
+ const { size } = useTwintagForm();
9
+
7
10
  return (
8
- <div className='flex w-full justify-center'>
9
- <Button>{label}</Button>
11
+ <div className='flex w-full justify-center pt-2'>
12
+ <Button size={size}>{label}</Button>
10
13
  </div>
11
14
  );
12
15
  };
@@ -13,24 +13,28 @@ 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/components/provider';
17
+
18
+ export const DEFAULT_TEXTAREA_VALUE = '';
16
19
 
17
20
  export const Textarea: FC<Props> = ({ label, bind, options }) => {
18
21
  const { control } = useFormContext();
22
+ const { variant, size } = useTwintagForm();
19
23
 
20
24
  const isOptional = options?.optionalField;
21
25
 
22
26
  return (
23
27
  <FormField
24
- defaultValue=''
28
+ defaultValue={DEFAULT_TEXTAREA_VALUE}
25
29
  control={control}
26
30
  name={bind}
27
31
  rules={{
28
32
  required: isOptional ? false : options?.error ?? true,
29
33
  }}
30
34
  render={({ field }) => (
31
- <FormItem>
32
- <div className='space-y-0.5'>
33
- <FormLabel>
35
+ <FormItem variant={variant}>
36
+ <div className='space-y-1'>
37
+ <FormLabel size={size}>
34
38
  {label}
35
39
  {!isOptional ? (
36
40
  <span className='ml-0.5 inline-block'>
@@ -41,7 +45,9 @@ export const Textarea: FC<Props> = ({ label, bind, options }) => {
41
45
  )}
42
46
  </FormLabel>
43
47
  {options?.description ? (
44
- <FormDescription>{options.description}</FormDescription>
48
+ <FormDescription size={size}>
49
+ {options.description}
50
+ </FormDescription>
45
51
  ) : (
46
52
  <></>
47
53
  )}
@@ -49,10 +55,12 @@ export const Textarea: FC<Props> = ({ label, bind, options }) => {
49
55
  <FormControl>
50
56
  <CommonTextarea
51
57
  {...field}
58
+ size={size}
59
+ variant={variant}
52
60
  placeholder={options?.placeholder ?? 'Write here...'}
53
61
  />
54
62
  </FormControl>
55
- <FormMessage className='pt-1' />
63
+ <FormMessage size={size} className='pt-1' />
56
64
  </FormItem>
57
65
  )}
58
66
  />
@@ -13,25 +13,29 @@ 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/components/provider';
17
+
18
+ export const DEFAULT_TOGGLE_VALUE = false;
16
19
 
17
20
  export const Toggle: FC<Props> = ({ label, bind, options }) => {
18
21
  const { control } = useFormContext();
22
+ const { variant, size } = useTwintagForm();
19
23
 
20
24
  const isOptional = options?.optionalField;
21
25
 
22
26
  return (
23
27
  <FormField
28
+ defaultValue={DEFAULT_TOGGLE_VALUE}
24
29
  control={control}
25
30
  name={bind}
26
- defaultValue={false}
27
31
  rules={{
28
32
  required: isOptional ? false : options?.error ?? true,
29
33
  }}
30
34
  render={({ field }) => (
31
- <FormItem>
35
+ <FormItem variant={variant}>
32
36
  <div className='flex flex-row items-center justify-between'>
33
- <div className='space-y-0.5'>
34
- <FormLabel htmlFor={bind}>
37
+ <div className='space-y-1'>
38
+ <FormLabel htmlFor={bind} size={size}>
35
39
  {label}
36
40
  {!isOptional ? (
37
41
  <span className='ml-0.5 inline-block'>
@@ -42,7 +46,9 @@ export const Toggle: FC<Props> = ({ label, bind, options }) => {
42
46
  )}
43
47
  </FormLabel>
44
48
  {options?.description ? (
45
- <FormDescription>{options.description}</FormDescription>
49
+ <FormDescription size={size}>
50
+ {options.description}
51
+ </FormDescription>
46
52
  ) : (
47
53
  <></>
48
54
  )}
@@ -57,7 +63,7 @@ export const Toggle: FC<Props> = ({ label, bind, options }) => {
57
63
  />
58
64
  </FormControl>
59
65
  </div>
60
- <FormMessage />
66
+ <FormMessage size={size} />
61
67
  </FormItem>
62
68
  )}
63
69
  />