@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.
Files changed (57) hide show
  1. package/.turbo/turbo-build.log +16 -16
  2. package/CHANGELOG.md +241 -221
  3. package/README.md +407 -407
  4. package/dev/index.css +32 -32
  5. package/dev/main.tsx +461 -460
  6. package/dist/common/button.d.ts +0 -1
  7. package/dist/common/form.d.ts +0 -1
  8. package/dist/common/icon.d.ts +0 -1
  9. package/dist/common/input.d.ts +0 -1
  10. package/dist/common/label.d.ts +0 -1
  11. package/dist/common/textarea.d.ts +0 -1
  12. package/dist/components/config.d.ts +0 -1
  13. package/dist/components/containers/accordion.d.ts +1 -2
  14. package/dist/components/containers/category.d.ts +0 -1
  15. package/dist/components/fields/checkbox.d.ts +0 -1
  16. package/dist/components/fields/file.d.ts +0 -1
  17. package/dist/components/fields/input.d.ts +0 -1
  18. package/dist/components/fields/radiogroup.d.ts +0 -1
  19. package/dist/components/fields/submit.d.ts +0 -1
  20. package/dist/components/fields/textarea.d.ts +0 -1
  21. package/dist/components/fields/toggle.d.ts +0 -1
  22. package/dist/components/fields/tri-toggle.d.ts +0 -1
  23. package/dist/components/form.d.ts +0 -1
  24. package/dist/components/input.d.ts +0 -1
  25. package/dist/components/label.d.ts +0 -1
  26. package/dist/components/provider.d.ts +1 -2
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.ts +0 -1
  29. package/dist/index.js +1437 -1601
  30. package/dist/types/index.d.ts +0 -1
  31. package/dist/utils/data.d.ts +0 -1
  32. package/dist/utils/style.d.ts +0 -1
  33. package/dist/webcomponent.cjs +1 -1
  34. package/dist/webcomponent.js +1118 -1104
  35. package/lib/common/icon.tsx +2 -1
  36. package/lib/components/config.tsx +1 -0
  37. package/lib/components/containers/accordion.tsx +3 -2
  38. package/lib/components/containers/category.tsx +1 -1
  39. package/lib/components/fields/checkbox.tsx +3 -6
  40. package/lib/components/fields/date-picker.tsx +151 -154
  41. package/lib/components/fields/file.tsx +81 -84
  42. package/lib/components/fields/input.tsx +67 -70
  43. package/lib/components/fields/radiogroup.tsx +3 -6
  44. package/lib/components/fields/submit.tsx +1 -0
  45. package/lib/components/fields/textarea.tsx +69 -72
  46. package/lib/components/fields/toggle.tsx +3 -6
  47. package/lib/components/fields/tri-toggle.tsx +3 -4
  48. package/lib/components/input.tsx +2 -1
  49. package/lib/components/label.tsx +1 -0
  50. package/lib/components/provider.tsx +163 -162
  51. package/lib/components/renderer.tsx +2 -1
  52. package/lib/index.tsx +46 -45
  53. package/lib/types/index.ts +102 -102
  54. package/lib/webcomponent.ts +1 -2
  55. package/package.json +9 -10
  56. package/prettier.config.mjs +1 -17
  57. package/vite.config.ts +2 -1
@@ -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,4 +1,5 @@
1
1
  import type { ElementType } from 'react';
2
+
2
3
  import type { InputCompConfig } from '../types';
3
4
 
4
5
  import { Accordion } from './containers/accordion';
@@ -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
- 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
+
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
- 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
+
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
+ };