@twintag/twintag-form 0.5.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.
- package/.eslintrc.cjs +6 -1
- package/.turbo/turbo-build.log +15 -10
- package/.turbo/turbo-lint.log +4 -0
- package/CHANGELOG.md +17 -0
- package/README.md +87 -59
- package/dev/index.css +29 -0
- package/dev/main.tsx +163 -0
- package/dist/common/button.d.ts +137 -0
- package/dist/common/checkbox.d.ts +4 -0
- package/dist/common/form.d.ts +24 -0
- package/dist/common/input.d.ts +4 -0
- package/dist/common/label.d.ts +4 -0
- package/dist/common/radiogroup.d.ts +5 -0
- package/dist/common/switch.d.ts +4 -0
- package/dist/common/textarea.d.ts +4 -0
- package/dist/components/Input/checkbox.d.ts +2 -6
- package/dist/components/Input/file.d.ts +2 -6
- package/dist/components/Input/index.d.ts +2 -2
- package/dist/components/Input/radiogroup.d.ts +3 -0
- package/dist/components/Input/simple.d.ts +2 -6
- package/dist/components/Input/submit.d.ts +2 -6
- package/dist/components/Input/textarea.d.ts +2 -6
- package/dist/components/Input/toggle.d.ts +2 -6
- package/dist/components/Render/index.d.ts +7 -0
- package/dist/components/Render/useJson.d.ts +2 -0
- package/dist/components/{Label/index.d.ts → category.d.ts} +3 -4
- package/dist/components/form.d.ts +7 -0
- package/dist/components/index.d.ts +8 -4
- package/dist/index.d.ts +8 -9
- package/dist/provider.d.ts +8 -0
- package/dist/twintag-form.react.js +7961 -8082
- package/dist/twintag-form.webcomponent.js +2003 -1765
- package/dist/types/index.d.ts +33 -0
- package/index.html +13 -0
- package/lib/common/button.tsx +49 -0
- package/lib/common/checkbox.tsx +40 -0
- package/lib/common/form.tsx +192 -0
- package/lib/common/input.tsx +55 -0
- package/lib/common/label.tsx +26 -0
- package/lib/common/radiogroup.tsx +56 -0
- package/lib/common/switch.tsx +39 -0
- package/lib/common/textarea.tsx +53 -0
- package/lib/components/Input/checkbox.tsx +55 -42
- package/lib/components/Input/file.tsx +64 -72
- package/lib/components/Input/index.tsx +15 -15
- package/lib/components/Input/radiogroup.tsx +84 -0
- package/lib/components/Input/simple.tsx +50 -28
- package/lib/components/Input/submit.tsx +4 -13
- package/lib/components/Input/textarea.tsx +49 -27
- package/lib/components/Input/toggle.tsx +54 -45
- package/lib/components/Render/index.tsx +30 -0
- package/lib/components/Render/useJson.ts +76 -0
- package/lib/components/category.tsx +31 -0
- package/lib/components/form.tsx +75 -0
- package/lib/components/index.tsx +27 -4
- package/lib/index.tsx +24 -48
- package/lib/provider.tsx +36 -0
- package/lib/types/index.ts +37 -0
- package/lib/webcomponent.ts +4 -4
- package/package.json +21 -12
- package/prettier.config.mjs +26 -0
- package/tailwind.config.ts +43 -0
- package/tsconfig.json +25 -6
- package/twind.config.ts +4 -21
- package/vite.config.ts +2 -2
- package/dist/components/Category/__styles.d.ts +0 -19
- package/dist/components/Category/index.d.ts +0 -8
- package/dist/components/Form/index.d.ts +0 -12
- package/dist/components/Input/__props.d.ts +0 -10
- package/dist/components/Input/__styles.d.ts +0 -245
- package/dist/styles.d.ts +0 -262
- package/lib/__stories__/Form.stories.tsx +0 -141
- package/lib/components/Category/__styles.ts +0 -12
- package/lib/components/Category/index.tsx +0 -26
- package/lib/components/Form/index.tsx +0 -86
- package/lib/components/Input/__props.ts +0 -10
- package/lib/components/Input/__styles.ts +0 -132
- package/lib/components/Label/index.tsx +0 -24
- package/lib/styles.ts +0 -143
- 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,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 gap-4 items-center w-full',
|
|
15
|
-
}),
|
|
16
|
-
checkbox:
|
|
17
|
-
'flex appearance-none items-center justify-center bg-white outline-none ring-0 border-2 border-primary focus:ring-0 focus:border-accent',
|
|
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: 'w-full block',
|
|
38
|
-
}),
|
|
39
|
-
span: '',
|
|
40
|
-
input:
|
|
41
|
-
'w-full cursor-pointer ring-0 focus:ring-0 border-2 border-transparent',
|
|
42
|
-
},
|
|
43
|
-
variants: {
|
|
44
|
-
variant: {
|
|
45
|
-
alpha: {
|
|
46
|
-
container: 'grid gap-1.5',
|
|
47
|
-
input:
|
|
48
|
-
'flex items-center justify-between gap-4 rounded-md px-3 py-2 border-slate-700/10 peer-focus:border-accent',
|
|
49
|
-
},
|
|
50
|
-
beta: {
|
|
51
|
-
container: 'grid gap-0',
|
|
52
|
-
input:
|
|
53
|
-
'flex items-center justify-between gap-4 py-2 border-b-slate-700/10 peer-focus:border-b-accent',
|
|
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
|
-
'w-full ring-0 placeholder:text-placeholder focus:ring-0 border-2 border-transparent text-input',
|
|
70
|
-
},
|
|
71
|
-
variants: {
|
|
72
|
-
variant: {
|
|
73
|
-
alpha: {
|
|
74
|
-
container: 'grid gap-1.5',
|
|
75
|
-
input: 'rounded-md border-slate-700/10 focus:border-accent',
|
|
76
|
-
},
|
|
77
|
-
beta: {
|
|
78
|
-
container: 'grid gap-0',
|
|
79
|
-
input:
|
|
80
|
-
'px-0 focus:border-transparent focus:border-b-accent border-b-slate-700/10',
|
|
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
|
-
'h-6 w-9 rounded-full bg-primary border border-black ring-2 focus:border-transparent focus:ring-accent data-[state=checked]:bg-white',
|
|
104
|
-
thumb:
|
|
105
|
-
'h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4 data-[state=checked]:bg-primary',
|
|
106
|
-
},
|
|
107
|
-
beta: {
|
|
108
|
-
container: 'flex justify-between',
|
|
109
|
-
input:
|
|
110
|
-
'h-6 w-9 rounded-full bg-primary border border-black ring-2 focus:border-transparent focus:ring-accent data-[state=checked]:bg-white',
|
|
111
|
-
thumb:
|
|
112
|
-
'h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4 data-[state=checked]:bg-primary',
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
defaultVariants: {
|
|
117
|
-
variant: 'alpha',
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
export const submitStyle = tv({
|
|
122
|
-
base: 'w-max max-w-full mt-2',
|
|
123
|
-
variants: {
|
|
124
|
-
variant: {
|
|
125
|
-
alpha: 'bg-primary text-white px-4 py-2 rounded-md',
|
|
126
|
-
beta: 'bg-primary text-white px-4 py-2',
|
|
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-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: 'w-full grid mt-4 first:mt-0',
|
|
14
|
-
span: 'text-category-label',
|
|
15
|
-
items: 'grid mt-2 mb-4 empty:mb-0',
|
|
16
|
-
},
|
|
17
|
-
variants: {
|
|
18
|
-
variant: {},
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
export const checkboxStyle = tv({
|
|
23
|
-
slots: {
|
|
24
|
-
container: containerStyle({
|
|
25
|
-
className: 'flex gap-4 items-center w-full',
|
|
26
|
-
}),
|
|
27
|
-
checkbox:
|
|
28
|
-
'flex appearance-none items-center justify-center bg-white outline-none ring-0 border-2 border-primary focus:ring-0 focus:border-accent',
|
|
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: 'w-full block',
|
|
49
|
-
}),
|
|
50
|
-
span: '',
|
|
51
|
-
input:
|
|
52
|
-
'w-full cursor-pointer ring-0 focus:ring-0 border-2 border-transparent',
|
|
53
|
-
},
|
|
54
|
-
variants: {
|
|
55
|
-
variant: {
|
|
56
|
-
alpha: {
|
|
57
|
-
container: 'grid gap-1.5',
|
|
58
|
-
input:
|
|
59
|
-
'flex items-center justify-between gap-4 rounded-md px-3 py-2 border-slate-700/10 peer-focus:border-accent',
|
|
60
|
-
},
|
|
61
|
-
beta: {
|
|
62
|
-
container: 'grid gap-0',
|
|
63
|
-
input:
|
|
64
|
-
'flex items-center justify-between gap-4 py-2 border-b-slate-700/10 peer-focus:border-b-accent',
|
|
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
|
-
'w-full ring-0 placeholder:text-placeholder focus:ring-0 border-2 border-transparent text-input',
|
|
81
|
-
},
|
|
82
|
-
variants: {
|
|
83
|
-
variant: {
|
|
84
|
-
alpha: {
|
|
85
|
-
container: 'grid gap-1.5',
|
|
86
|
-
input: 'rounded-md border-slate-700/10 focus:border-accent',
|
|
87
|
-
},
|
|
88
|
-
beta: {
|
|
89
|
-
container: 'grid gap-0',
|
|
90
|
-
input:
|
|
91
|
-
'px-0 focus:border-transparent focus:border-b-accent border-b-slate-700/10',
|
|
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
|
-
'h-6 w-9 rounded-full bg-primary border border-black ring-2 focus:border-transparent focus:ring-accent data-[state=checked]:bg-white',
|
|
115
|
-
thumb:
|
|
116
|
-
'h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4 data-[state=checked]:bg-primary',
|
|
117
|
-
},
|
|
118
|
-
beta: {
|
|
119
|
-
container: 'flex justify-between',
|
|
120
|
-
input:
|
|
121
|
-
'h-6 w-9 rounded-full bg-primary border border-black ring-2 focus:border-transparent focus:ring-accent data-[state=checked]:bg-white',
|
|
122
|
-
thumb:
|
|
123
|
-
'h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4 data-[state=checked]:bg-primary',
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
defaultVariants: {
|
|
128
|
-
variant: 'alpha',
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
export const submitStyle = tv({
|
|
133
|
-
base: 'w-max max-w-full mt-2',
|
|
134
|
-
variants: {
|
|
135
|
-
variant: {
|
|
136
|
-
alpha: 'bg-primary text-white px-4 py-2 rounded-md',
|
|
137
|
-
beta: 'bg-primary text-white px-4 py-2',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
defaultVariants: {
|
|
141
|
-
variant: 'alpha',
|
|
142
|
-
},
|
|
143
|
-
});
|
package/tailwind.config.cjs
DELETED
|
@@ -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
|
-
};
|