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