@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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +12 -0
- package/README.md +121 -62
- package/dev/main.tsx +233 -210
- package/dist/common/button.d.ts +17 -30
- package/dist/common/calendar.d.ts +212 -4
- package/dist/common/form.d.ts +151 -9
- package/dist/common/icon.d.ts +2 -1
- package/dist/common/input.d.ts +276 -2
- package/dist/common/label.d.ts +39 -1
- package/dist/common/slider.d.ts +4 -0
- package/dist/common/textarea.d.ts +139 -2
- package/dist/components/config.d.ts +4 -2
- package/dist/components/containers/accordion.d.ts +3 -2
- package/dist/components/containers/category.d.ts +3 -2
- package/dist/components/fields/checkbox.d.ts +4 -2
- package/dist/components/fields/date-picker.d.ts +3 -1
- package/dist/components/fields/file.d.ts +4 -2
- package/dist/components/fields/input.d.ts +4 -2
- package/dist/components/fields/radiogroup.d.ts +4 -2
- package/dist/components/fields/submit.d.ts +3 -2
- package/dist/components/fields/textarea.d.ts +4 -2
- package/dist/components/fields/toggle.d.ts +4 -2
- package/dist/components/fields/tri-toggle.d.ts +5 -0
- package/dist/components/form.d.ts +2 -2
- package/dist/components/provider.d.ts +21 -0
- package/dist/components/renderer.d.ts +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/twintag-form.react.js +12868 -12156
- package/dist/types/index.d.ts +25 -16
- package/dist/utils/data.d.ts +2 -1
- package/dist/utils/style.d.ts +2 -1
- package/index.html +5 -3
- package/lib/common/button.tsx +4 -5
- package/lib/common/calendar.tsx +25 -5
- package/lib/common/form.tsx +40 -19
- package/lib/common/input.tsx +20 -10
- package/lib/common/label.tsx +16 -3
- package/lib/common/slider.tsx +38 -0
- package/lib/common/textarea.tsx +17 -9
- package/lib/components/config.tsx +46 -17
- package/lib/components/containers/accordion.tsx +24 -7
- package/lib/components/containers/category.tsx +16 -7
- package/lib/components/fields/checkbox.tsx +12 -6
- package/lib/components/fields/date-picker.tsx +54 -18
- package/lib/components/fields/file.tsx +83 -76
- package/lib/components/fields/input.tsx +15 -6
- package/lib/components/fields/radiogroup.tsx +13 -7
- package/lib/components/fields/submit.tsx +5 -2
- package/lib/components/fields/textarea.tsx +14 -6
- package/lib/components/fields/toggle.tsx +12 -6
- package/lib/components/fields/tri-toggle.tsx +141 -0
- package/lib/components/form.tsx +5 -7
- package/lib/components/provider.tsx +159 -0
- package/lib/components/{Render/index.tsx → renderer.tsx} +19 -2
- package/lib/index.tsx +41 -36
- package/lib/types/index.ts +49 -39
- package/package.json +5 -7
- package/dist/components/Render/index.d.ts +0 -7
- package/dist/components/Render/useJson.d.ts +0 -2
- package/dist/components/index.d.ts +0 -7
- package/dist/provider.d.ts +0 -8
- package/lib/components/Render/useJson.ts +0 -76
- package/lib/components/index.tsx +0 -24
- 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-
|
|
10
|
+
container: 'relative w-full space-y-3',
|
|
11
11
|
heading: 'font-tf-font text-category',
|
|
12
|
-
content: 'grid gap-
|
|
12
|
+
content: 'grid gap-3',
|
|
13
13
|
},
|
|
14
14
|
variants: {
|
|
15
15
|
variant: {
|
|
16
16
|
default: {
|
|
17
|
-
heading: '
|
|
17
|
+
heading: 'font-medium',
|
|
18
18
|
},
|
|
19
19
|
beta: {
|
|
20
|
-
heading: '
|
|
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
|
|
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
|
|
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
|
|
27
|
-
|
|
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:
|
|
31
|
-
|
|
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:
|
|
35
|
-
|
|
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
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
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
|
-
|
|
79
|
-
|
|
113
|
+
size={size}
|
|
114
|
+
className={button({
|
|
80
115
|
withValue: !field.value,
|
|
81
|
-
className: 'h-10 gap-
|
|
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=
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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-
|
|
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
|
|
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-
|
|
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
|
|
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-
|
|
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-
|
|
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
|
|
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-
|
|
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
|
|
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
|
/>
|