@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
|
@@ -1,70 +1,67 @@
|
|
|
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
|
-
|
|
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
|
-
};
|
|
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 as InputPrimitive } from '@twintag/twintag-form/common/input';
|
|
17
|
+
import { useTwintagForm } from '@twintag/twintag-form/components/provider';
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_INPUT_VALUE = '';
|
|
20
|
+
|
|
21
|
+
export const Input: FC<Props<'input', 'text'>> = ({ label, bind, options }) => {
|
|
22
|
+
const { control } = useFormContext();
|
|
23
|
+
|
|
24
|
+
const { variant, size } = useTwintagForm();
|
|
25
|
+
|
|
26
|
+
const isOptional = options?.optionalField;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<FormField
|
|
30
|
+
defaultValue={DEFAULT_INPUT_VALUE}
|
|
31
|
+
control={control}
|
|
32
|
+
name={bind}
|
|
33
|
+
rules={{
|
|
34
|
+
required: isOptional ? false : (options?.error ?? true),
|
|
35
|
+
}}
|
|
36
|
+
render={({ field }) => (
|
|
37
|
+
<FormItem variant={variant}>
|
|
38
|
+
<div className='space-y-1'>
|
|
39
|
+
<FormLabel size={size}>
|
|
40
|
+
{label}
|
|
41
|
+
{!isOptional ? (
|
|
42
|
+
<span className='ml-0.5 inline-block'>
|
|
43
|
+
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
44
|
+
</span>
|
|
45
|
+
) : null}
|
|
46
|
+
</FormLabel>
|
|
47
|
+
{options?.description ? (
|
|
48
|
+
<FormDescription size={size}>
|
|
49
|
+
{options.description}
|
|
50
|
+
</FormDescription>
|
|
51
|
+
) : null}
|
|
52
|
+
</div>
|
|
53
|
+
<FormControl>
|
|
54
|
+
<InputPrimitive
|
|
55
|
+
type='text'
|
|
56
|
+
size={size}
|
|
57
|
+
variant={variant}
|
|
58
|
+
placeholder={options?.placeholder ?? 'Write here...'}
|
|
59
|
+
{...field}
|
|
60
|
+
/>
|
|
61
|
+
</FormControl>
|
|
62
|
+
<FormMessage size={size} className='pt-1' />
|
|
63
|
+
</FormItem>
|
|
64
|
+
)}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -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';
|
|
@@ -47,17 +48,13 @@ export const RadioGroup: FC<
|
|
|
47
48
|
<span className='ml-0.5 inline-block'>
|
|
48
49
|
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
49
50
|
</span>
|
|
50
|
-
) :
|
|
51
|
-
<></>
|
|
52
|
-
)}
|
|
51
|
+
) : null}
|
|
53
52
|
</FormLabel>
|
|
54
53
|
{options?.description ? (
|
|
55
54
|
<FormDescription size={size}>
|
|
56
55
|
{options.description}
|
|
57
56
|
</FormDescription>
|
|
58
|
-
) :
|
|
59
|
-
<></>
|
|
60
|
-
)}
|
|
57
|
+
) : null}
|
|
61
58
|
</div>
|
|
62
59
|
<FormControl>
|
|
63
60
|
<CommonRadioGroup
|
|
@@ -1,72 +1,69 @@
|
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const {
|
|
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
|
-
};
|
|
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 { Textarea as CommonTextarea } from '@twintag/twintag-form/common/textarea';
|
|
17
|
+
import { useTwintagForm } from '@twintag/twintag-form/components/provider';
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_TEXTAREA_VALUE = '';
|
|
20
|
+
|
|
21
|
+
export const Textarea: FC<Props<'input', 'text'>> = ({
|
|
22
|
+
label,
|
|
23
|
+
bind,
|
|
24
|
+
options,
|
|
25
|
+
}) => {
|
|
26
|
+
const { control } = useFormContext();
|
|
27
|
+
const { variant, size } = useTwintagForm();
|
|
28
|
+
|
|
29
|
+
const isOptional = options?.optionalField;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<FormField
|
|
33
|
+
defaultValue={DEFAULT_TEXTAREA_VALUE}
|
|
34
|
+
control={control}
|
|
35
|
+
name={bind}
|
|
36
|
+
rules={{
|
|
37
|
+
required: isOptional ? false : (options?.error ?? true),
|
|
38
|
+
}}
|
|
39
|
+
render={({ field }) => (
|
|
40
|
+
<FormItem variant={variant}>
|
|
41
|
+
<div className='space-y-1'>
|
|
42
|
+
<FormLabel size={size}>
|
|
43
|
+
{label}
|
|
44
|
+
{!isOptional ? (
|
|
45
|
+
<span className='ml-0.5 inline-block'>
|
|
46
|
+
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
47
|
+
</span>
|
|
48
|
+
) : null}
|
|
49
|
+
</FormLabel>
|
|
50
|
+
{options?.description ? (
|
|
51
|
+
<FormDescription size={size}>
|
|
52
|
+
{options.description}
|
|
53
|
+
</FormDescription>
|
|
54
|
+
) : null}
|
|
55
|
+
</div>
|
|
56
|
+
<FormControl>
|
|
57
|
+
<CommonTextarea
|
|
58
|
+
{...field}
|
|
59
|
+
size={size}
|
|
60
|
+
variant={variant}
|
|
61
|
+
placeholder={options?.placeholder ?? 'Write here...'}
|
|
62
|
+
/>
|
|
63
|
+
</FormControl>
|
|
64
|
+
<FormMessage size={size} className='pt-1' />
|
|
65
|
+
</FormItem>
|
|
66
|
+
)}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -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';
|
|
@@ -41,17 +42,13 @@ export const Toggle: FC<Props<'input'>> = ({ label, bind, options }) => {
|
|
|
41
42
|
<span className='ml-0.5 inline-block'>
|
|
42
43
|
<AsteriskIcon className='h-3 w-3 text-tf-destructive' />
|
|
43
44
|
</span>
|
|
44
|
-
) :
|
|
45
|
-
<></>
|
|
46
|
-
)}
|
|
45
|
+
) : null}
|
|
47
46
|
</FormLabel>
|
|
48
47
|
{options?.description ? (
|
|
49
48
|
<FormDescription size={size}>
|
|
50
49
|
{options.description}
|
|
51
50
|
</FormDescription>
|
|
52
|
-
) :
|
|
53
|
-
<></>
|
|
54
|
-
)}
|
|
51
|
+
) : null}
|
|
55
52
|
</div>
|
|
56
53
|
<FormControl>
|
|
57
54
|
<Switch
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
|
-
import type { Props } from '@twintag/twintag-form/types';
|
|
3
2
|
import type { VariantProps } from 'tailwind-variants';
|
|
4
3
|
|
|
4
|
+
import type { Props } from '@twintag/twintag-form/types';
|
|
5
|
+
|
|
5
6
|
import * as React from 'react';
|
|
6
7
|
import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
7
8
|
import { useFormContext } from 'react-hook-form';
|
|
@@ -111,9 +112,7 @@ export const TriToggle: FC<Props<'input'>> = ({ label, bind, options }) => {
|
|
|
111
112
|
<FormDescription size={size}>
|
|
112
113
|
{options.description}
|
|
113
114
|
</FormDescription>
|
|
114
|
-
) :
|
|
115
|
-
<></>
|
|
116
|
-
)}
|
|
115
|
+
) : null}
|
|
117
116
|
</div>
|
|
118
117
|
<FormControl>
|
|
119
118
|
<Slider
|
package/lib/components/input.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
|
+
|
|
2
3
|
import type { Props } from '../types';
|
|
3
4
|
|
|
4
5
|
import { Inputs } from './config';
|
|
@@ -6,7 +7,7 @@ import { Inputs } from './config';
|
|
|
6
7
|
export const Input: FC<Props<'input'>> = ({ subtype, ...rest }) => {
|
|
7
8
|
const Comp = Inputs.get(subtype!)?.component;
|
|
8
9
|
|
|
9
|
-
if (!Comp) return
|
|
10
|
+
if (!Comp) return null;
|
|
10
11
|
|
|
11
12
|
return <Comp {...rest} />;
|
|
12
13
|
};
|