@twintag/twintag-form 1.2.1 → 1.4.0-beta.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.
@@ -13,9 +13,11 @@ import {
13
13
  FormMessage,
14
14
  } from '@twintag/twintag-form/common/form';
15
15
  import { Input } from '@twintag/twintag-form/common/input';
16
+ import { useTwintagForm } from '@twintag/twintag-form/provider';
16
17
 
17
18
  export const File: FC<Props> = ({ label, bind, options }) => {
18
19
  const { control } = useFormContext();
20
+ const { variant, size } = useTwintagForm();
19
21
 
20
22
  const isOptional = options?.optionalField;
21
23
 
@@ -28,9 +30,9 @@ export const File: FC<Props> = ({ label, bind, options }) => {
28
30
  required: isOptional ? false : options?.error ?? true,
29
31
  }}
30
32
  render={({ field, formState }) => (
31
- <FormItem>
32
- <div className='space-y-0.5'>
33
- <FormLabel htmlFor={bind}>
33
+ <FormItem variant={variant}>
34
+ <div className='space-y-1'>
35
+ <FormLabel htmlFor={bind} size={size}>
34
36
  {label}
35
37
  {!isOptional ? (
36
38
  <span className='ml-0.5 inline-block'>
@@ -41,7 +43,9 @@ export const File: FC<Props> = ({ label, bind, options }) => {
41
43
  )}
42
44
  </FormLabel>
43
45
  {options?.description ? (
44
- <FormDescription>{options.description}</FormDescription>
46
+ <FormDescription size={size}>
47
+ {options.description}
48
+ </FormDescription>
45
49
  ) : (
46
50
  <></>
47
51
  )}
@@ -58,6 +62,8 @@ export const File: FC<Props> = ({ label, bind, options }) => {
58
62
  id={bind}
59
63
  type='file'
60
64
  name={field.name}
65
+ size={size}
66
+ variant={variant}
61
67
  capture='environment'
62
68
  multiple
63
69
  onBlur={field.onBlur}
@@ -68,7 +74,7 @@ export const File: FC<Props> = ({ label, bind, options }) => {
68
74
  }}
69
75
  />
70
76
  </FormControl>
71
- <FormMessage className='pt-1.5' />
77
+ <FormMessage size={size} className='pt-1.5' />
72
78
  </FormItem>
73
79
  )}
74
80
  />
@@ -13,10 +13,13 @@ 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/provider';
16
17
 
17
18
  export const Input: FC<Props> = ({ label, bind, options }) => {
18
19
  const { control } = useFormContext();
19
20
 
21
+ const { variant, size } = useTwintagForm();
22
+
20
23
  const isOptional = options?.optionalField;
21
24
 
22
25
  return (
@@ -28,9 +31,9 @@ export const Input: FC<Props> = ({ label, bind, options }) => {
28
31
  required: isOptional ? false : options?.error ?? true,
29
32
  }}
30
33
  render={({ field }) => (
31
- <FormItem>
32
- <div className='space-y-0.5'>
33
- <FormLabel>
34
+ <FormItem variant={variant}>
35
+ <div className='space-y-1'>
36
+ <FormLabel size={size}>
34
37
  {label}
35
38
  {!isOptional ? (
36
39
  <span className='ml-0.5 inline-block'>
@@ -41,7 +44,9 @@ export const Input: FC<Props> = ({ label, bind, options }) => {
41
44
  )}
42
45
  </FormLabel>
43
46
  {options?.description ? (
44
- <FormDescription>{options.description}</FormDescription>
47
+ <FormDescription size={size}>
48
+ {options.description}
49
+ </FormDescription>
45
50
  ) : (
46
51
  <></>
47
52
  )}
@@ -49,11 +54,13 @@ export const Input: FC<Props> = ({ label, bind, options }) => {
49
54
  <FormControl>
50
55
  <InputPrimitive
51
56
  type='text'
57
+ size={size}
58
+ variant={variant}
52
59
  placeholder={options?.placeholder ?? 'Write here...'}
53
60
  {...field}
54
61
  />
55
62
  </FormControl>
56
- <FormMessage className='pt-1' />
63
+ <FormMessage size={size} className='pt-1' />
57
64
  </FormItem>
58
65
  )}
59
66
  />
@@ -16,9 +16,11 @@ import {
16
16
  RadioGroup as CommonRadioGroup,
17
17
  RadioGroupItem,
18
18
  } from '@twintag/twintag-form/common/radiogroup';
19
+ import { useTwintagForm } from '@twintag/twintag-form/provider';
19
20
 
20
21
  export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
21
22
  const { control } = useFormContext();
23
+ const { size } = useTwintagForm();
22
24
 
23
25
  const isOptional = options?.optionalField;
24
26
 
@@ -32,8 +34,8 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
32
34
  }}
33
35
  render={({ field }) => (
34
36
  <FormItem className='space-y-3'>
35
- <div className='space-y-0.5'>
36
- <FormLabel>
37
+ <div className='space-y-1'>
38
+ <FormLabel size={size}>
37
39
  {label}
38
40
  {!isOptional ? (
39
41
  <span className='ml-0.5 inline-block'>
@@ -44,7 +46,9 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
44
46
  )}
45
47
  </FormLabel>
46
48
  {options?.description ? (
47
- <FormDescription>{options.description}</FormDescription>
49
+ <FormDescription size={size}>
50
+ {options.description}
51
+ </FormDescription>
48
52
  ) : (
49
53
  <></>
50
54
  )}
@@ -60,12 +64,12 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
60
64
  return (
61
65
  <FormItem
62
66
  key={item.id}
63
- className='flex items-center space-x-3 space-y-0'
67
+ className='flex items-center space-x-2 space-y-0'
64
68
  >
65
69
  <FormControl>
66
70
  <RadioGroupItem value={item.bind} />
67
71
  </FormControl>
68
- <FormLabel className='font-normal'>
72
+ <FormLabel size={size} className='font-normal'>
69
73
  {item.label}
70
74
  </FormLabel>
71
75
  </FormItem>
@@ -76,7 +80,7 @@ export const RadioGroup: FC<Props> = ({ label, bind, items, options }) => {
76
80
  })}
77
81
  </CommonRadioGroup>
78
82
  </FormControl>
79
- <FormMessage />
83
+ <FormMessage size={size} />
80
84
  </FormItem>
81
85
  )}
82
86
  />
@@ -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/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,9 +13,11 @@ 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/provider';
16
17
 
17
18
  export const Textarea: FC<Props> = ({ label, bind, options }) => {
18
19
  const { control } = useFormContext();
20
+ const { variant, size } = useTwintagForm();
19
21
 
20
22
  const isOptional = options?.optionalField;
21
23
 
@@ -28,9 +30,9 @@ export const Textarea: FC<Props> = ({ label, bind, options }) => {
28
30
  required: isOptional ? false : options?.error ?? true,
29
31
  }}
30
32
  render={({ field }) => (
31
- <FormItem>
32
- <div className='space-y-0.5'>
33
- <FormLabel>
33
+ <FormItem variant={variant}>
34
+ <div className='space-y-1'>
35
+ <FormLabel size={size}>
34
36
  {label}
35
37
  {!isOptional ? (
36
38
  <span className='ml-0.5 inline-block'>
@@ -41,7 +43,9 @@ export const Textarea: FC<Props> = ({ label, bind, options }) => {
41
43
  )}
42
44
  </FormLabel>
43
45
  {options?.description ? (
44
- <FormDescription>{options.description}</FormDescription>
46
+ <FormDescription size={size}>
47
+ {options.description}
48
+ </FormDescription>
45
49
  ) : (
46
50
  <></>
47
51
  )}
@@ -49,10 +53,12 @@ export const Textarea: FC<Props> = ({ label, bind, options }) => {
49
53
  <FormControl>
50
54
  <CommonTextarea
51
55
  {...field}
56
+ size={size}
57
+ variant={variant}
52
58
  placeholder={options?.placeholder ?? 'Write here...'}
53
59
  />
54
60
  </FormControl>
55
- <FormMessage className='pt-1' />
61
+ <FormMessage size={size} className='pt-1' />
56
62
  </FormItem>
57
63
  )}
58
64
  />
@@ -13,9 +13,11 @@ 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/provider';
16
17
 
17
18
  export const Toggle: FC<Props> = ({ label, bind, options }) => {
18
19
  const { control } = useFormContext();
20
+ const { variant, size } = useTwintagForm();
19
21
 
20
22
  const isOptional = options?.optionalField;
21
23
 
@@ -28,10 +30,10 @@ export const Toggle: FC<Props> = ({ label, bind, options }) => {
28
30
  required: isOptional ? false : options?.error ?? true,
29
31
  }}
30
32
  render={({ field }) => (
31
- <FormItem>
33
+ <FormItem variant={variant}>
32
34
  <div className='flex flex-row items-center justify-between'>
33
- <div className='space-y-0.5'>
34
- <FormLabel htmlFor={bind}>
35
+ <div className='space-y-1'>
36
+ <FormLabel htmlFor={bind} size={size}>
35
37
  {label}
36
38
  {!isOptional ? (
37
39
  <span className='ml-0.5 inline-block'>
@@ -42,7 +44,9 @@ export const Toggle: FC<Props> = ({ label, bind, options }) => {
42
44
  )}
43
45
  </FormLabel>
44
46
  {options?.description ? (
45
- <FormDescription>{options.description}</FormDescription>
47
+ <FormDescription size={size}>
48
+ {options.description}
49
+ </FormDescription>
46
50
  ) : (
47
51
  <></>
48
52
  )}
@@ -57,7 +61,7 @@ export const Toggle: FC<Props> = ({ label, bind, options }) => {
57
61
  />
58
62
  </FormControl>
59
63
  </div>
60
- <FormMessage />
64
+ <FormMessage size={size} />
61
65
  </FormItem>
62
66
  )}
63
67
  />
package/lib/index.tsx CHANGED
@@ -13,15 +13,21 @@ type Props = {
13
13
  options?: Partial<{
14
14
  defaultValues?: ComponentProps<typeof TwintagForm>['defaultValues'];
15
15
  variant?: ComponentProps<typeof TwintagFormProvider>['variant'];
16
+ size?: ComponentProps<typeof TwintagFormProvider>['size'];
16
17
  resetOnSubmit?: boolean;
17
18
  }>;
18
19
  };
19
20
 
20
21
  export const Form = forwardRef<HTMLFormElement, Props>(
21
- ({ config, options }) => {
22
+ ({ config, options }, ref) => {
22
23
  return (
23
- <TwintagFormProvider variant={options?.variant} components={components}>
24
+ <TwintagFormProvider
25
+ components={components}
26
+ variant={options?.variant}
27
+ size={options?.size}
28
+ >
24
29
  <TwintagForm
30
+ ref={ref}
25
31
  defaultValues={options?.defaultValues}
26
32
  resetOnSubmit={options?.resetOnSubmit}
27
33
  >
package/lib/provider.tsx CHANGED
@@ -5,6 +5,7 @@ import { createContext, useContext } from 'react';
5
5
 
6
6
  export const twintagFormContext = createContext<TwintagFormContext>({
7
7
  variant: 'default',
8
+ size: 'base',
8
9
  components: new Map(),
9
10
  });
10
11
 
@@ -21,12 +22,14 @@ export const useTwintagForm = () => {
21
22
  export const TwintagFormProvider = ({
22
23
  children,
23
24
  variant,
25
+ size,
24
26
  components,
25
27
  }: TwintagFormContext & WithChildren) => {
26
28
  return (
27
29
  <twintagFormContext.Provider
28
30
  value={{
29
31
  variant,
32
+ size,
30
33
  components,
31
34
  }}
32
35
  >
@@ -2,6 +2,7 @@ import type { ElementType } from 'react';
2
2
 
3
3
  export type TwintagFormContext = {
4
4
  variant?: 'default' | 'beta';
5
+ size?: 'base' | 'sm';
5
6
  components: Map<string, ElementType>;
6
7
  };
7
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twintag/twintag-form",
3
- "version": "1.2.1",
3
+ "version": "1.4.0-beta.0",
4
4
  "author": "Twintag",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,9 +51,9 @@
51
51
  "tailwindcss": "^3.3.6",
52
52
  "vite": "^4.4.9",
53
53
  "vite-plugin-dts": "^3.0.3",
54
- "eslint-config-custom": "1.0.0",
54
+ "twintag-types": "0.2.0",
55
55
  "tsconfig": "0.0.0",
56
- "twintag-types": "0.2.0"
56
+ "eslint-config-custom": "1.0.0"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public"