@twintag/twintag-form 1.6.2-beta.1 → 1.7.0
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 +16 -16
- package/CHANGELOG.md +241 -221
- package/README.md +407 -407
- package/dev/index.css +32 -32
- package/dev/main.tsx +461 -460
- package/dist/common/button.d.ts +0 -1
- package/dist/common/form.d.ts +0 -1
- package/dist/common/icon.d.ts +0 -1
- package/dist/common/input.d.ts +0 -1
- package/dist/common/label.d.ts +0 -1
- package/dist/common/textarea.d.ts +0 -1
- package/dist/components/config.d.ts +0 -1
- package/dist/components/containers/accordion.d.ts +1 -2
- package/dist/components/containers/category.d.ts +0 -1
- package/dist/components/fields/checkbox.d.ts +0 -1
- package/dist/components/fields/file.d.ts +0 -1
- package/dist/components/fields/input.d.ts +0 -1
- package/dist/components/fields/radiogroup.d.ts +0 -1
- package/dist/components/fields/submit.d.ts +0 -1
- package/dist/components/fields/textarea.d.ts +0 -1
- package/dist/components/fields/toggle.d.ts +0 -1
- package/dist/components/fields/tri-toggle.d.ts +0 -1
- package/dist/components/form.d.ts +0 -1
- package/dist/components/input.d.ts +0 -1
- package/dist/components/label.d.ts +0 -1
- package/dist/components/provider.d.ts +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1437 -1601
- package/dist/types/index.d.ts +0 -1
- package/dist/utils/data.d.ts +0 -1
- package/dist/utils/style.d.ts +0 -1
- package/dist/webcomponent.cjs +1 -1
- package/dist/webcomponent.js +1118 -1104
- package/lib/common/icon.tsx +2 -1
- package/lib/components/config.tsx +1 -0
- package/lib/components/containers/accordion.tsx +3 -2
- package/lib/components/containers/category.tsx +1 -1
- package/lib/components/fields/checkbox.tsx +3 -6
- package/lib/components/fields/date-picker.tsx +151 -154
- package/lib/components/fields/file.tsx +81 -84
- package/lib/components/fields/input.tsx +67 -70
- package/lib/components/fields/radiogroup.tsx +3 -6
- package/lib/components/fields/submit.tsx +1 -0
- package/lib/components/fields/textarea.tsx +69 -72
- package/lib/components/fields/toggle.tsx +3 -6
- package/lib/components/fields/tri-toggle.tsx +3 -4
- package/lib/components/input.tsx +2 -1
- package/lib/components/label.tsx +1 -0
- package/lib/components/provider.tsx +163 -162
- package/lib/components/renderer.tsx +2 -1
- package/lib/index.tsx +46 -45
- package/lib/types/index.ts +102 -102
- package/lib/webcomponent.ts +1 -2
- package/package.json +9 -10
- package/prettier.config.mjs +1 -17
- package/vite.config.ts +2 -1
package/lib/common/icon.tsx
CHANGED
|
@@ -19,9 +19,10 @@ export const Icon: FC<Props> = ({ name, className, ...props }) => {
|
|
|
19
19
|
[name],
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
+
// biome-ignore lint/performance/noDynamicNamespaceImportAccess: ignore for now
|
|
22
23
|
const Comp = icons[camel];
|
|
23
24
|
|
|
24
|
-
if (!Comp) return
|
|
25
|
+
if (!Comp) return null;
|
|
25
26
|
|
|
26
27
|
return (
|
|
27
28
|
<Comp
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
|
-
import type { Props } from '@twintag/twintag-form/types';
|
|
3
2
|
import type { WithChildren } from 'twintag-types/dom';
|
|
4
3
|
|
|
4
|
+
import type { Props } from '@twintag/twintag-form/types';
|
|
5
|
+
|
|
5
6
|
import { tv } from 'tailwind-variants';
|
|
6
7
|
|
|
7
8
|
import {
|
|
@@ -114,7 +115,7 @@ const AccordionItem: FC<AccordionItemProps> = ({
|
|
|
114
115
|
>
|
|
115
116
|
<AccordionTrigger className='text-category'>
|
|
116
117
|
<span className={trigger()}>
|
|
117
|
-
{icon ? <Icon name={icon} className={iconVariants()} /> :
|
|
118
|
+
{icon ? <Icon name={icon} className={iconVariants()} /> : null}
|
|
118
119
|
{label}
|
|
119
120
|
</span>
|
|
120
121
|
</AccordionTrigger>
|
|
@@ -46,7 +46,7 @@ const Category: FC<Props> = ({ label, children }) => {
|
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<section className={container()}>
|
|
49
|
-
{label ? <h3 className={heading()}>{label}</h3> :
|
|
49
|
+
{label ? <h3 className={heading()}>{label}</h3> : null}
|
|
50
50
|
|
|
51
51
|
<div className={content()}>{children}</div>
|
|
52
52
|
</section>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
|
+
|
|
2
3
|
import type { Props } from '@twintag/twintag-form/types';
|
|
3
4
|
|
|
4
5
|
import { AsteriskIcon } from 'lucide-react';
|
|
@@ -50,17 +51,13 @@ export const Checkbox: FC<Props<'input'>> = ({ label, bind, options }) => {
|
|
|
50
51
|
<span className='ml-0.5 inline-block'>
|
|
51
52
|
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
52
53
|
</span>
|
|
53
|
-
) :
|
|
54
|
-
<></>
|
|
55
|
-
)}
|
|
54
|
+
) : null}
|
|
56
55
|
</FormLabel>
|
|
57
56
|
{options?.description ? (
|
|
58
57
|
<FormDescription size={size}>
|
|
59
58
|
{options.description}
|
|
60
59
|
</FormDescription>
|
|
61
|
-
) :
|
|
62
|
-
<></>
|
|
63
|
-
)}
|
|
60
|
+
) : null}
|
|
64
61
|
<FormMessage size={size} />
|
|
65
62
|
</div>
|
|
66
63
|
</div>
|
|
@@ -1,154 +1,151 @@
|
|
|
1
|
-
import type * as React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
const {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/>
|
|
153
|
-
);
|
|
154
|
-
};
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Props } from '@twintag/twintag-form/types';
|
|
4
|
+
|
|
5
|
+
import { format } from 'date-fns';
|
|
6
|
+
import { AsteriskIcon, Calendar as CalendarIcon } from 'lucide-react';
|
|
7
|
+
import { useFormContext } from 'react-hook-form';
|
|
8
|
+
import { tv } from 'tailwind-variants';
|
|
9
|
+
|
|
10
|
+
import { Button } from '@twintag/twintag-form/common/button';
|
|
11
|
+
import { Calendar } from '@twintag/twintag-form/common/calendar';
|
|
12
|
+
import {
|
|
13
|
+
FormControl,
|
|
14
|
+
FormDescription,
|
|
15
|
+
FormField,
|
|
16
|
+
FormItem,
|
|
17
|
+
FormLabel,
|
|
18
|
+
FormMessage,
|
|
19
|
+
} from '@twintag/twintag-form/common/form';
|
|
20
|
+
import {
|
|
21
|
+
Popover,
|
|
22
|
+
PopoverContent,
|
|
23
|
+
PopoverTrigger,
|
|
24
|
+
} from '@twintag/twintag-form/common/popover';
|
|
25
|
+
import { useTwintagForm } from '@twintag/twintag-form/components/provider';
|
|
26
|
+
|
|
27
|
+
const datePickerTriggerVariants = tv({
|
|
28
|
+
slots: {
|
|
29
|
+
button: 'w-full justify-start text-left font-normal',
|
|
30
|
+
icon: 'ml-auto text-tf-muted-foreground opacity-70',
|
|
31
|
+
},
|
|
32
|
+
variants: {
|
|
33
|
+
variant: {
|
|
34
|
+
default: {
|
|
35
|
+
button: 'px-3',
|
|
36
|
+
},
|
|
37
|
+
outline: {
|
|
38
|
+
button:
|
|
39
|
+
'rounded-none border-x-transparent border-t-transparent px-1 transition-none hover:bg-white hover:text-tf-muted-foreground',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
withValue: {
|
|
43
|
+
true: {
|
|
44
|
+
button: 'text-tf-muted-foreground',
|
|
45
|
+
},
|
|
46
|
+
false: {
|
|
47
|
+
button: '',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
size: {
|
|
51
|
+
sm: {
|
|
52
|
+
button: 'text-sm',
|
|
53
|
+
icon: 'h-4 w-4',
|
|
54
|
+
},
|
|
55
|
+
base: {
|
|
56
|
+
button: 'text-base',
|
|
57
|
+
icon: 'h-5 w-5',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: {
|
|
62
|
+
variant: 'default',
|
|
63
|
+
size: 'base',
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const DEFAULT_DATE_PICKER_VALUE = null;
|
|
68
|
+
|
|
69
|
+
export const DatePicker: React.FC<Props<'input', 'datepicker'>> = ({
|
|
70
|
+
label,
|
|
71
|
+
bind,
|
|
72
|
+
options,
|
|
73
|
+
}) => {
|
|
74
|
+
const { variant, size } = useTwintagForm();
|
|
75
|
+
const { control } = useFormContext();
|
|
76
|
+
|
|
77
|
+
const { button, icon } = datePickerTriggerVariants({ variant, size });
|
|
78
|
+
|
|
79
|
+
const isOptional = options?.optionalField;
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<FormField
|
|
83
|
+
defaultValue={DEFAULT_DATE_PICKER_VALUE}
|
|
84
|
+
control={control}
|
|
85
|
+
name={bind}
|
|
86
|
+
rules={{
|
|
87
|
+
required: isOptional ? false : (options?.error ?? true),
|
|
88
|
+
}}
|
|
89
|
+
render={({ field }) => (
|
|
90
|
+
<FormItem
|
|
91
|
+
variant={variant}
|
|
92
|
+
className='flex flex-col [&>div[data-radix-popper-content-wrapper]]:!z-50'
|
|
93
|
+
>
|
|
94
|
+
<div className='space-y-1'>
|
|
95
|
+
<FormLabel size={size}>
|
|
96
|
+
{label}
|
|
97
|
+
{!isOptional ? (
|
|
98
|
+
<span className='ml-0.5 inline-block'>
|
|
99
|
+
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
100
|
+
</span>
|
|
101
|
+
) : null}
|
|
102
|
+
</FormLabel>
|
|
103
|
+
{options?.description ? (
|
|
104
|
+
<FormDescription size={size}>
|
|
105
|
+
{options.description}
|
|
106
|
+
</FormDescription>
|
|
107
|
+
) : null}
|
|
108
|
+
</div>
|
|
109
|
+
<Popover>
|
|
110
|
+
<PopoverTrigger asChild>
|
|
111
|
+
<FormControl>
|
|
112
|
+
<Button
|
|
113
|
+
variant='outline'
|
|
114
|
+
size={size}
|
|
115
|
+
className={button({
|
|
116
|
+
withValue: !field.value,
|
|
117
|
+
className: 'h-10 gap-2',
|
|
118
|
+
})}
|
|
119
|
+
>
|
|
120
|
+
{field.value ? (
|
|
121
|
+
format(field.value, 'PPP')
|
|
122
|
+
) : (
|
|
123
|
+
<span>{options?.placeholder ?? 'Select a date'}</span>
|
|
124
|
+
)}
|
|
125
|
+
<CalendarIcon className={icon()} />
|
|
126
|
+
</Button>
|
|
127
|
+
</FormControl>
|
|
128
|
+
</PopoverTrigger>
|
|
129
|
+
<PopoverContent className='w-auto p-0' align='start'>
|
|
130
|
+
<Calendar
|
|
131
|
+
fromYear={1970}
|
|
132
|
+
toYear={2050}
|
|
133
|
+
captionLayout='dropdown-buttons'
|
|
134
|
+
mode='single'
|
|
135
|
+
size={size}
|
|
136
|
+
selected={
|
|
137
|
+
!Number.isNaN(new Date(field.value as Date).getTime())
|
|
138
|
+
? new Date(field.value as Date)
|
|
139
|
+
: undefined
|
|
140
|
+
}
|
|
141
|
+
onSelect={field.onChange}
|
|
142
|
+
initialFocus
|
|
143
|
+
/>
|
|
144
|
+
</PopoverContent>
|
|
145
|
+
</Popover>
|
|
146
|
+
<FormMessage size={size} className='pt-1' />
|
|
147
|
+
</FormItem>
|
|
148
|
+
)}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
};
|
|
@@ -1,84 +1,81 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const {
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/>
|
|
83
|
-
);
|
|
84
|
-
};
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Props } from '@twintag/twintag-form/types';
|
|
4
|
+
|
|
5
|
+
import { AsteriskIcon } from 'lucide-react';
|
|
6
|
+
import { useFormContext } from 'react-hook-form';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
FormControl,
|
|
10
|
+
FormDescription,
|
|
11
|
+
FormField,
|
|
12
|
+
FormItem,
|
|
13
|
+
FormLabel,
|
|
14
|
+
FormMessage,
|
|
15
|
+
} from '@twintag/twintag-form/common/form';
|
|
16
|
+
import { Input } from '@twintag/twintag-form/common/input';
|
|
17
|
+
import { useTwintagForm } from '@twintag/twintag-form/components/provider';
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_FILE_VALUE = '';
|
|
20
|
+
|
|
21
|
+
export const File: FC<Props<'input', 'file'>> = ({ label, bind, options }) => {
|
|
22
|
+
const { control } = useFormContext();
|
|
23
|
+
const { variant, size, acceptFileType } = useTwintagForm();
|
|
24
|
+
|
|
25
|
+
const isOptional = options?.optionalField;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<FormField
|
|
29
|
+
defaultValue={DEFAULT_FILE_VALUE}
|
|
30
|
+
control={control}
|
|
31
|
+
name={bind}
|
|
32
|
+
rules={{
|
|
33
|
+
required: isOptional ? false : (options?.error ?? true),
|
|
34
|
+
}}
|
|
35
|
+
render={({ field, formState }) => (
|
|
36
|
+
<FormItem variant={variant}>
|
|
37
|
+
<div className='space-y-1'>
|
|
38
|
+
<FormLabel htmlFor={bind} size={size}>
|
|
39
|
+
{label}
|
|
40
|
+
{!isOptional ? (
|
|
41
|
+
<span className='ml-0.5 inline-block'>
|
|
42
|
+
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
43
|
+
</span>
|
|
44
|
+
) : null}
|
|
45
|
+
</FormLabel>
|
|
46
|
+
{options?.description ? (
|
|
47
|
+
<FormDescription size={size}>
|
|
48
|
+
{options.description}
|
|
49
|
+
</FormDescription>
|
|
50
|
+
) : null}
|
|
51
|
+
</div>
|
|
52
|
+
<FormControl>
|
|
53
|
+
<Input
|
|
54
|
+
ref={(el) => {
|
|
55
|
+
field.ref(el);
|
|
56
|
+
|
|
57
|
+
if (el && formState.isSubmitSuccessful) {
|
|
58
|
+
el.value = '';
|
|
59
|
+
}
|
|
60
|
+
}}
|
|
61
|
+
id={bind}
|
|
62
|
+
type='file'
|
|
63
|
+
accept={options?.accept ?? acceptFileType}
|
|
64
|
+
name={field.name}
|
|
65
|
+
size={size}
|
|
66
|
+
variant={variant}
|
|
67
|
+
multiple
|
|
68
|
+
onBlur={field.onBlur}
|
|
69
|
+
onChange={(e) => {
|
|
70
|
+
if (e.target.files) {
|
|
71
|
+
field.onChange(e.target.files);
|
|
72
|
+
}
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
</FormControl>
|
|
76
|
+
<FormMessage size={size} className='pt-1.5' />
|
|
77
|
+
</FormItem>
|
|
78
|
+
)}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
};
|