@twintag/twintag-form 0.6.0 → 1.0.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.
Files changed (80) hide show
  1. package/.eslintrc.cjs +5 -0
  2. package/.turbo/turbo-build.log +14 -9
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/CHANGELOG.md +6 -0
  5. package/README.md +87 -59
  6. package/dev/index.css +29 -0
  7. package/dev/main.tsx +163 -0
  8. package/dist/common/button.d.ts +137 -0
  9. package/dist/common/checkbox.d.ts +4 -0
  10. package/dist/common/form.d.ts +24 -0
  11. package/dist/common/input.d.ts +4 -0
  12. package/dist/common/label.d.ts +4 -0
  13. package/dist/common/radiogroup.d.ts +5 -0
  14. package/dist/common/switch.d.ts +4 -0
  15. package/dist/common/textarea.d.ts +4 -0
  16. package/dist/components/Input/checkbox.d.ts +2 -6
  17. package/dist/components/Input/file.d.ts +2 -6
  18. package/dist/components/Input/index.d.ts +2 -2
  19. package/dist/components/Input/radiogroup.d.ts +3 -0
  20. package/dist/components/Input/simple.d.ts +2 -6
  21. package/dist/components/Input/submit.d.ts +2 -6
  22. package/dist/components/Input/textarea.d.ts +2 -6
  23. package/dist/components/Input/toggle.d.ts +2 -6
  24. package/dist/components/Render/index.d.ts +7 -0
  25. package/dist/components/Render/useJson.d.ts +2 -0
  26. package/dist/components/{Label/index.d.ts → category.d.ts} +3 -4
  27. package/dist/components/form.d.ts +7 -0
  28. package/dist/components/index.d.ts +8 -4
  29. package/dist/index.d.ts +8 -9
  30. package/dist/provider.d.ts +8 -0
  31. package/dist/twintag-form.react.js +7930 -8119
  32. package/dist/twintag-form.webcomponent.js +2007 -1769
  33. package/dist/types/index.d.ts +33 -0
  34. package/index.html +13 -0
  35. package/lib/common/button.tsx +49 -0
  36. package/lib/common/checkbox.tsx +40 -0
  37. package/lib/common/form.tsx +192 -0
  38. package/lib/common/input.tsx +55 -0
  39. package/lib/common/label.tsx +26 -0
  40. package/lib/common/radiogroup.tsx +56 -0
  41. package/lib/common/switch.tsx +39 -0
  42. package/lib/common/textarea.tsx +53 -0
  43. package/lib/components/Input/checkbox.tsx +55 -42
  44. package/lib/components/Input/file.tsx +64 -72
  45. package/lib/components/Input/index.tsx +15 -15
  46. package/lib/components/Input/radiogroup.tsx +84 -0
  47. package/lib/components/Input/simple.tsx +50 -28
  48. package/lib/components/Input/submit.tsx +4 -13
  49. package/lib/components/Input/textarea.tsx +49 -27
  50. package/lib/components/Input/toggle.tsx +54 -45
  51. package/lib/components/Render/index.tsx +30 -0
  52. package/lib/components/Render/useJson.ts +76 -0
  53. package/lib/components/category.tsx +31 -0
  54. package/lib/components/form.tsx +75 -0
  55. package/lib/components/index.tsx +27 -4
  56. package/lib/index.tsx +24 -48
  57. package/lib/provider.tsx +36 -0
  58. package/lib/types/index.ts +37 -0
  59. package/lib/webcomponent.ts +6 -6
  60. package/package.json +18 -9
  61. package/prettier.config.mjs +26 -0
  62. package/tailwind.config.ts +43 -0
  63. package/tsconfig.json +14 -3
  64. package/twind.config.ts +4 -21
  65. package/vite.config.ts +1 -1
  66. package/dist/components/Category/__styles.d.ts +0 -29
  67. package/dist/components/Category/index.d.ts +0 -8
  68. package/dist/components/Form/index.d.ts +0 -12
  69. package/dist/components/Input/__props.d.ts +0 -10
  70. package/dist/components/Input/__styles.d.ts +0 -460
  71. package/dist/styles.d.ts +0 -487
  72. package/lib/__stories__/Form.stories.tsx +0 -141
  73. package/lib/components/Category/__styles.ts +0 -12
  74. package/lib/components/Category/index.tsx +0 -26
  75. package/lib/components/Form/index.tsx +0 -86
  76. package/lib/components/Input/__props.ts +0 -10
  77. package/lib/components/Input/__styles.ts +0 -132
  78. package/lib/components/Label/index.tsx +0 -24
  79. package/lib/styles.ts +0 -143
  80. package/tailwind.config.cjs +0 -8
@@ -1,86 +0,0 @@
1
- import type { Ref } from 'react';
2
- import type { FieldValues } from 'react-hook-form';
3
- import type { WithChildren } from 'twintag-types/dom';
4
-
5
- import { useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
6
- import { useForm, FormProvider } from 'react-hook-form';
7
-
8
- type FormRef = Ref<{
9
- validate?: () => void;
10
- } | null>;
11
-
12
- type Props = {
13
- options?: {
14
- resetOnSubmit?: boolean;
15
- };
16
- } & WithChildren;
17
-
18
- const Form = forwardRef(({ options, children }: Props, ref: FormRef) => {
19
- const { formState, reset, ...methods } = useForm();
20
-
21
- const formRef = useRef<HTMLFormElement>(null);
22
-
23
- useImperativeHandle(ref, () => ({
24
- validate: () => onValidate(),
25
- }));
26
-
27
- useEffect(() => {
28
- if (formState.isSubmitSuccessful && options?.resetOnSubmit) {
29
- reset();
30
- }
31
- }, [formState, reset]);
32
-
33
- const onValid = (data: FieldValues) => {
34
- const customSubmit = new CustomEvent('twintag-form-valid', {
35
- detail: data,
36
- bubbles: true,
37
- cancelable: false,
38
- composed: true,
39
- });
40
-
41
- formRef.current?.dispatchEvent(customSubmit);
42
- };
43
-
44
- const onInvalid = (__errors: FieldValues) => {
45
- const customSubmit = new CustomEvent('twintag-form-invalid', {
46
- detail: __errors,
47
- bubbles: true,
48
- cancelable: false,
49
- composed: true,
50
- });
51
-
52
- formRef.current?.dispatchEvent(customSubmit);
53
- };
54
-
55
- const onValidate = () => {
56
- methods.handleSubmit(onValid, onInvalid)();
57
- };
58
-
59
- useEffect(() => {
60
- const form = formRef.current;
61
-
62
- if (form) {
63
- form.addEventListener('twintag-form-validate', onValidate);
64
- }
65
-
66
- return () => {
67
- if (form) {
68
- form.removeEventListener('twintag-form-validate', onValidate);
69
- }
70
- };
71
- }, []);
72
-
73
- return (
74
- <FormProvider {...{ formState, reset, ...methods }}>
75
- <form
76
- ref={formRef}
77
- className='font-ff-text relative'
78
- onSubmit={methods.handleSubmit(onValid, onInvalid)}
79
- >
80
- <div className='w-full space-y-4'>{children}</div>
81
- </form>
82
- </FormProvider>
83
- );
84
- });
85
-
86
- export default Form;
@@ -1,10 +0,0 @@
1
- export type CommonProps<TVariant> = {
2
- label: string;
3
- bind: string;
4
- checked?: boolean;
5
- options?: {
6
- variant?: TVariant;
7
- placeholder?: string;
8
- optionalField?: boolean;
9
- };
10
- };
@@ -1,132 +0,0 @@
1
- import { tv } from 'tailwind-variants';
2
-
3
- export const labelStyle = tv({
4
- base: 'text-label',
5
- });
6
-
7
- export const containerStyle = tv({
8
- base: '',
9
- });
10
-
11
- export const checkboxStyle = tv({
12
- slots: {
13
- container: containerStyle({
14
- className: 'flex w-full items-center gap-4',
15
- }),
16
- checkbox:
17
- 'border-primary focus:border-accent flex appearance-none items-center justify-center border-2 bg-white outline-none ring-0 focus:ring-0',
18
- },
19
- variants: {
20
- variant: {
21
- alpha: {
22
- checkbox: 'h-5 w-5 rounded',
23
- },
24
- beta: {
25
- checkbox: 'h-5 w-5',
26
- },
27
- },
28
- },
29
- defaultVariants: {
30
- variant: 'alpha',
31
- },
32
- });
33
-
34
- export const fileStyle = tv({
35
- slots: {
36
- container: containerStyle({
37
- className: 'block w-full',
38
- }),
39
- span: '',
40
- input:
41
- 'w-full cursor-pointer border-2 border-transparent ring-0 focus:ring-0',
42
- },
43
- variants: {
44
- variant: {
45
- alpha: {
46
- container: 'grid gap-1.5',
47
- input:
48
- 'peer-focus:border-accent flex items-center justify-between gap-4 rounded-md border-slate-700/10 px-3 py-2',
49
- },
50
- beta: {
51
- container: 'grid gap-0',
52
- input:
53
- 'peer-focus:border-b-accent flex items-center justify-between gap-4 border-b-slate-700/10 py-2',
54
- },
55
- },
56
- },
57
- defaultVariants: {
58
- variant: 'alpha',
59
- },
60
- });
61
-
62
- export const simpleStyle = tv({
63
- slots: {
64
- container: containerStyle({
65
- className: 'w-full',
66
- }),
67
- span: '',
68
- input:
69
- 'placeholder:text-placeholder text-input w-full border-2 border-transparent ring-0 focus:ring-0',
70
- },
71
- variants: {
72
- variant: {
73
- alpha: {
74
- container: 'grid gap-1.5',
75
- input: 'focus:border-accent rounded-md border-slate-700/10',
76
- },
77
- beta: {
78
- container: 'grid gap-0',
79
- input:
80
- 'focus:border-b-accent border-b-slate-700/10 px-0 focus:border-transparent',
81
- },
82
- },
83
- },
84
- defaultVariants: {
85
- variant: 'alpha',
86
- },
87
- });
88
-
89
- export const toggleStyle = tv({
90
- slots: {
91
- container: containerStyle({
92
- className: 'w-full cursor-pointer',
93
- }),
94
- span: '',
95
- input: 'relative outline-none ring-2 ring-transparent',
96
- thumb: 'block transition-transform duration-100 will-change-transform',
97
- },
98
- variants: {
99
- variant: {
100
- alpha: {
101
- container: 'flex justify-between',
102
- input:
103
- 'bg-primary focus:ring-accent h-6 w-9 rounded-full border border-black ring-2 focus:border-transparent data-[state=checked]:bg-white',
104
- thumb:
105
- 'data-[state=checked]:bg-primary h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4',
106
- },
107
- beta: {
108
- container: 'flex justify-between',
109
- input:
110
- 'bg-primary focus:ring-accent h-6 w-9 rounded-full border border-black ring-2 focus:border-transparent data-[state=checked]:bg-white',
111
- thumb:
112
- 'data-[state=checked]:bg-primary h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4',
113
- },
114
- },
115
- },
116
- defaultVariants: {
117
- variant: 'alpha',
118
- },
119
- });
120
-
121
- export const submitStyle = tv({
122
- base: 'mt-2 w-max max-w-full',
123
- variants: {
124
- variant: {
125
- alpha: 'bg-primary rounded-md px-4 py-2 text-white',
126
- beta: 'bg-primary px-4 py-2 text-white',
127
- },
128
- },
129
- defaultVariants: {
130
- variant: 'alpha',
131
- },
132
- });
@@ -1,24 +0,0 @@
1
- import type { FC } from 'react';
2
- import type { WithChildren } from 'twintag-types/dom';
3
-
4
- import { labelStyle } from '@twintag/twintag-form/styles';
5
-
6
- type Props = {
7
- required?: boolean;
8
- className?: string;
9
- } & WithChildren;
10
-
11
- const Label: FC<Props> = ({ className, required, children }) => {
12
- const style = labelStyle({
13
- className,
14
- });
15
-
16
- return (
17
- <span className={style}>
18
- {children}{' '}
19
- {required ? <span className='text-xs text-red-500'>*</span> : <></>}
20
- </span>
21
- );
22
- };
23
-
24
- export default Label;
package/lib/styles.ts DELETED
@@ -1,143 +0,0 @@
1
- import { tv } from 'tailwind-variants';
2
-
3
- export const labelStyle = tv({
4
- base: 'text-label',
5
- });
6
-
7
- export const containerStyle = tv({
8
- base: 'my-2',
9
- });
10
-
11
- export const categoryStyle = tv({
12
- slots: {
13
- container: 'mt-4 grid w-full first:mt-0',
14
- span: 'text-category-label',
15
- items: 'mb-4 mt-2 grid empty:mb-0',
16
- },
17
- variants: {
18
- variant: {},
19
- },
20
- });
21
-
22
- export const checkboxStyle = tv({
23
- slots: {
24
- container: containerStyle({
25
- className: 'flex w-full items-center gap-4',
26
- }),
27
- checkbox:
28
- 'border-primary focus:border-accent flex appearance-none items-center justify-center border-2 bg-white outline-none ring-0 focus:ring-0',
29
- },
30
- variants: {
31
- variant: {
32
- alpha: {
33
- checkbox: 'h-5 w-5 rounded',
34
- },
35
- beta: {
36
- checkbox: 'h-5 w-5',
37
- },
38
- },
39
- },
40
- defaultVariants: {
41
- variant: 'alpha',
42
- },
43
- });
44
-
45
- export const fileStyle = tv({
46
- slots: {
47
- container: containerStyle({
48
- className: 'block w-full',
49
- }),
50
- span: '',
51
- input:
52
- 'w-full cursor-pointer border-2 border-transparent ring-0 focus:ring-0',
53
- },
54
- variants: {
55
- variant: {
56
- alpha: {
57
- container: 'grid gap-1.5',
58
- input:
59
- 'peer-focus:border-accent flex items-center justify-between gap-4 rounded-md border-slate-700/10 px-3 py-2',
60
- },
61
- beta: {
62
- container: 'grid gap-0',
63
- input:
64
- 'peer-focus:border-b-accent flex items-center justify-between gap-4 border-b-slate-700/10 py-2',
65
- },
66
- },
67
- },
68
- defaultVariants: {
69
- variant: 'alpha',
70
- },
71
- });
72
-
73
- export const simpleStyle = tv({
74
- slots: {
75
- container: containerStyle({
76
- className: 'w-full',
77
- }),
78
- span: '',
79
- input:
80
- 'placeholder:text-placeholder text-input w-full border-2 border-transparent ring-0 focus:ring-0',
81
- },
82
- variants: {
83
- variant: {
84
- alpha: {
85
- container: 'grid gap-1.5',
86
- input: 'focus:border-accent rounded-md border-slate-700/10',
87
- },
88
- beta: {
89
- container: 'grid gap-0',
90
- input:
91
- 'focus:border-b-accent border-b-slate-700/10 px-0 focus:border-transparent',
92
- },
93
- },
94
- },
95
- defaultVariants: {
96
- variant: 'alpha',
97
- },
98
- });
99
-
100
- export const toggleStyle = tv({
101
- slots: {
102
- container: containerStyle({
103
- className: 'w-full cursor-pointer',
104
- }),
105
- span: '',
106
- input: 'relative outline-none ring-2 ring-transparent',
107
- thumb: 'block transition-transform duration-100 will-change-transform',
108
- },
109
- variants: {
110
- variant: {
111
- alpha: {
112
- container: 'flex justify-between',
113
- input:
114
- 'bg-primary focus:ring-accent h-6 w-9 rounded-full border border-black ring-2 focus:border-transparent data-[state=checked]:bg-white',
115
- thumb:
116
- 'data-[state=checked]:bg-primary h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4',
117
- },
118
- beta: {
119
- container: 'flex justify-between',
120
- input:
121
- 'bg-primary focus:ring-accent h-6 w-9 rounded-full border border-black ring-2 focus:border-transparent data-[state=checked]:bg-white',
122
- thumb:
123
- 'data-[state=checked]:bg-primary h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4',
124
- },
125
- },
126
- },
127
- defaultVariants: {
128
- variant: 'alpha',
129
- },
130
- });
131
-
132
- export const submitStyle = tv({
133
- base: 'mt-2 w-max max-w-full',
134
- variants: {
135
- variant: {
136
- alpha: 'bg-primary rounded-md px-4 py-2 text-white',
137
- beta: 'bg-primary px-4 py-2 text-white',
138
- },
139
- },
140
- defaultVariants: {
141
- variant: 'alpha',
142
- },
143
- });
@@ -1,8 +0,0 @@
1
- // Added to get Tailwind CSS IntelliSense working
2
- const sharedConfig = require('tailwind-config/tailwind.config.js');
3
-
4
- module.exports = {
5
- ...sharedConfig,
6
- content: ['./lib/**/*.{ts,tsx}', './index.html'],
7
- plugins: [require('@tailwindcss/typography'), require('@tailwindcss/forms')],
8
- };