@twintag/twintag-form 0.1.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 +4 -0
- package/.turbo/turbo-build.log +50 -0
- package/CHANGELOG.md +7 -0
- package/dist/index.es.js +27356 -0
- package/dist/index.umd.js +196 -0
- package/dist/lib/components/Form/index.d.ts +10 -0
- package/dist/lib/components/Form/index.d.ts.map +1 -0
- package/dist/lib/components/Form/register.d.ts +13 -0
- package/dist/lib/components/Form/register.d.ts.map +1 -0
- package/dist/lib/components/Input/checkbox.d.ts +8 -0
- package/dist/lib/components/Input/checkbox.d.ts.map +1 -0
- package/dist/lib/components/Input/file.d.ts +8 -0
- package/dist/lib/components/Input/file.d.ts.map +1 -0
- package/dist/lib/components/Input/index.d.ts +8 -0
- package/dist/lib/components/Input/index.d.ts.map +1 -0
- package/dist/lib/components/Input/simple.d.ts +8 -0
- package/dist/lib/components/Input/simple.d.ts.map +1 -0
- package/dist/lib/components/Input/submit.d.ts +8 -0
- package/dist/lib/components/Input/submit.d.ts.map +1 -0
- package/dist/lib/components/Input/textarea.d.ts +8 -0
- package/dist/lib/components/Input/textarea.d.ts.map +1 -0
- package/dist/lib/components/Input/toggle.d.ts +8 -0
- package/dist/lib/components/Input/toggle.d.ts.map +1 -0
- package/dist/lib/index.d.ts +18 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/styles.d.ts +120 -0
- package/dist/lib/styles.d.ts.map +1 -0
- package/dist/lib/types/index.d.ts +16 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/webcomponent.d.ts +2 -0
- package/dist/lib/webcomponent.d.ts.map +1 -0
- package/dist/twind.config.d.ts +5 -0
- package/dist/twind.config.d.ts.map +1 -0
- package/dist/webcomponent.es.js +31725 -0
- package/dist/webcomponent.umd.js +196 -0
- package/lib/components/Form/index.tsx +86 -0
- package/lib/components/Form/register.tsx +70 -0
- package/lib/components/Input/checkbox.tsx +50 -0
- package/lib/components/Input/file.tsx +76 -0
- package/lib/components/Input/index.tsx +30 -0
- package/lib/components/Input/simple.tsx +41 -0
- package/lib/components/Input/submit.tsx +24 -0
- package/lib/components/Input/textarea.tsx +36 -0
- package/lib/components/Input/toggle.tsx +50 -0
- package/lib/index.tsx +173 -0
- package/lib/styles.ts +116 -0
- package/lib/types/index.ts +16 -0
- package/lib/webcomponent.ts +20 -0
- package/package.json +56 -0
- package/scripts/build.js +55 -0
- package/tailwind.config.cjs +8 -0
- package/tsconfig.json +13 -0
- package/twind.config.ts +22 -0
package/lib/styles.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { tv } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
export const checkboxStyle = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
container: 'flex gap-4 items-center w-full',
|
|
6
|
+
checkbox:
|
|
7
|
+
'flex appearance-none items-center justify-center bg-white outline-none ring-0 border-2 border-primary focus:ring-0 focus:border-accent',
|
|
8
|
+
},
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
alpha: {
|
|
12
|
+
checkbox: 'h-5 w-5 rounded',
|
|
13
|
+
},
|
|
14
|
+
beta: {
|
|
15
|
+
checkbox: 'h-5 w-5',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
variant: 'alpha',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const fileStyle = tv({
|
|
25
|
+
slots: {
|
|
26
|
+
container: 'w-full block',
|
|
27
|
+
span: 'font-semibold',
|
|
28
|
+
input:
|
|
29
|
+
'w-full cursor-pointer ring-0 focus:ring-0 border-2 border-transparent',
|
|
30
|
+
},
|
|
31
|
+
variants: {
|
|
32
|
+
variant: {
|
|
33
|
+
alpha: {
|
|
34
|
+
container: 'grid gap-1.5',
|
|
35
|
+
input:
|
|
36
|
+
'flex items-center justify-between gap-4 rounded-md px-3 py-2 border-slate-700/10 peer-focus:border-accent',
|
|
37
|
+
},
|
|
38
|
+
beta: {
|
|
39
|
+
container: 'grid gap-1.5',
|
|
40
|
+
input:
|
|
41
|
+
'flex items-center justify-between gap-4 py-2 border-b-slate-700/10 peer-focus:border-b-accent',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
defaultVariants: {
|
|
46
|
+
variant: 'alpha',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const simpleStyle = tv({
|
|
51
|
+
slots: {
|
|
52
|
+
container: 'w-full',
|
|
53
|
+
span: 'font-semibold',
|
|
54
|
+
input:
|
|
55
|
+
'w-full ring-0 placeholder:text-slate-400 focus:ring-0 border-2 border-transparent',
|
|
56
|
+
},
|
|
57
|
+
variants: {
|
|
58
|
+
variant: {
|
|
59
|
+
alpha: {
|
|
60
|
+
container: 'grid gap-1.5',
|
|
61
|
+
input: 'rounded-md border-slate-700/10 focus:border-accent',
|
|
62
|
+
},
|
|
63
|
+
beta: {
|
|
64
|
+
container: 'grid gap-1.5',
|
|
65
|
+
input:
|
|
66
|
+
'px-0 focus:border-transparent focus:border-b-accent border-b-slate-700/10',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
defaultVariants: {
|
|
71
|
+
variant: 'alpha',
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export const submitStyle = tv({
|
|
76
|
+
base: 'w-max max-w-full',
|
|
77
|
+
variants: {
|
|
78
|
+
variant: {
|
|
79
|
+
alpha: 'bg-primary text-white px-4 py-2 rounded-md',
|
|
80
|
+
beta: 'bg-primary text-white px-4 py-2',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
defaultVariants: {
|
|
84
|
+
variant: 'alpha',
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const toggleStyle = tv({
|
|
89
|
+
slots: {
|
|
90
|
+
container: 'w-full cursor-pointer',
|
|
91
|
+
span: 'font-semibold',
|
|
92
|
+
input: 'relative outline-none ring-2 ring-transparent',
|
|
93
|
+
thumb: 'block transition-transform duration-100 will-change-transform',
|
|
94
|
+
},
|
|
95
|
+
variants: {
|
|
96
|
+
variant: {
|
|
97
|
+
alpha: {
|
|
98
|
+
container: 'flex justify-between',
|
|
99
|
+
input:
|
|
100
|
+
'h-6 w-9 rounded-full bg-primary border border-black ring-2 focus:ring-accent data-[state=checked]:bg-white',
|
|
101
|
+
thumb:
|
|
102
|
+
'h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4 data-[state=checked]:bg-primary',
|
|
103
|
+
},
|
|
104
|
+
beta: {
|
|
105
|
+
container: 'flex justify-between',
|
|
106
|
+
input:
|
|
107
|
+
'h-6 w-9 rounded-full bg-primary border border-black ring-2 focus:border-transparent focus:ring-accent data-[state=checked]:bg-white',
|
|
108
|
+
thumb:
|
|
109
|
+
'h-4 w-4 translate-x-0.5 rounded-full bg-white data-[state=checked]:translate-x-4 data-[state=checked]:bg-primary',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
defaultVariants: {
|
|
114
|
+
variant: 'alpha',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UseFormRegister, Control } from 'react-hook-form';
|
|
2
|
+
import type { Label } from 'twintag-types/dom';
|
|
3
|
+
|
|
4
|
+
export type CommonProps<TVariant> = {
|
|
5
|
+
label: Label;
|
|
6
|
+
bind?: Label;
|
|
7
|
+
useForm?: {
|
|
8
|
+
register: UseFormRegister<any>;
|
|
9
|
+
control: Control;
|
|
10
|
+
};
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
options?: {
|
|
13
|
+
variant?: TVariant;
|
|
14
|
+
optionalField?: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import install from '@twind/with-web-components';
|
|
2
|
+
import r2wc from '@r2wc/react-to-web-component';
|
|
3
|
+
|
|
4
|
+
import config from '../twind.config';
|
|
5
|
+
|
|
6
|
+
import TwintagForm from './index';
|
|
7
|
+
|
|
8
|
+
const withTwind = install(config);
|
|
9
|
+
|
|
10
|
+
const TwintagFormElement = r2wc(TwintagForm, {
|
|
11
|
+
props: {
|
|
12
|
+
config: 'json',
|
|
13
|
+
options: 'json',
|
|
14
|
+
},
|
|
15
|
+
shadow: 'open',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
class TwindElement extends withTwind(TwintagFormElement) {}
|
|
19
|
+
|
|
20
|
+
customElements.define('twintag-form', TwindElement);
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twintag/twintag-form",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "Twintag",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.es.js",
|
|
9
|
+
"require": "./dist/index.umd.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./webcomponent": {
|
|
13
|
+
"import": "./dist/webcomponent.es.js",
|
|
14
|
+
"require": "./dist/webcomponent.umd.js",
|
|
15
|
+
"types": "./dist/webcomponent.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@heroicons/react": "^2.0.16",
|
|
20
|
+
"@r2wc/react-to-web-component": "^2.0.2",
|
|
21
|
+
"@radix-ui/react-checkbox": "^1.0.4",
|
|
22
|
+
"@radix-ui/react-switch": "^1.0.2",
|
|
23
|
+
"@twind/core": "^1.1.3",
|
|
24
|
+
"@twind/preset-autoprefix": "^1.0.7",
|
|
25
|
+
"@twind/preset-tailwind": "^1.1.4",
|
|
26
|
+
"@twind/preset-tailwind-forms": "^1.1.2",
|
|
27
|
+
"@twind/preset-typography": "^1.0.7",
|
|
28
|
+
"@twind/with-web-components": "^1.1.3",
|
|
29
|
+
"react": "^18.2.0",
|
|
30
|
+
"react-dom": "^18.2.0",
|
|
31
|
+
"react-hook-form": "^7.43.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@rollup/plugin-typescript": "^11.1.1",
|
|
35
|
+
"@types/react": "^18.0.28",
|
|
36
|
+
"@types/react-dom": "^18.0.11",
|
|
37
|
+
"@vitejs/plugin-react-swc": "^3.0.0",
|
|
38
|
+
"eslint": "^8.38.0",
|
|
39
|
+
"rollup": "^3.18.0",
|
|
40
|
+
"typescript": "^5.0.2",
|
|
41
|
+
"vite": "^4.1.0",
|
|
42
|
+
"vite-plugin-dts": "^2.1.0",
|
|
43
|
+
"tsconfig": "0.0.0",
|
|
44
|
+
"tailwind-config": "0.0.0",
|
|
45
|
+
"twintag-types": "0.0.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"dev": "vite",
|
|
52
|
+
"build": "tsc && node ./scripts/build.js",
|
|
53
|
+
"lint": "eslint lib --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
54
|
+
"preview": "vite preview"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/scripts/build.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { resolve, dirname } from "pathe";
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { build, defineConfig } from "vite";
|
|
4
|
+
import react from "@vitejs/plugin-react-swc";
|
|
5
|
+
import typescript from "@rollup/plugin-typescript";
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
const reactComponentLibrary = {
|
|
10
|
+
plugins: [],
|
|
11
|
+
entry: resolve(__dirname, "../lib/index.tsx"),
|
|
12
|
+
fileName: (format) => `index.${format}.js`,
|
|
13
|
+
name: "index",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const webcomponentsLibrary = {
|
|
17
|
+
plugins: [],
|
|
18
|
+
entry: resolve(__dirname, "../lib/webcomponent.ts"),
|
|
19
|
+
fileName: (format) => `webcomponent.${format}.js`,
|
|
20
|
+
name: "webcomponent",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getSharedConfiguration = ({ plugins, ...library }) => {
|
|
24
|
+
return defineConfig({
|
|
25
|
+
plugins: [react(), typescript(), ...plugins],
|
|
26
|
+
build: {
|
|
27
|
+
lib: {
|
|
28
|
+
formats: ["es", "umd"],
|
|
29
|
+
...library,
|
|
30
|
+
},
|
|
31
|
+
rollupOptions: {
|
|
32
|
+
external: ["react"],
|
|
33
|
+
output: {
|
|
34
|
+
globals: {
|
|
35
|
+
react: "react",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const viteBuild = (configFactory) => {
|
|
44
|
+
return build(configFactory);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const buildLibraries = async () => {
|
|
48
|
+
await Promise.all(
|
|
49
|
+
[webcomponentsLibrary, reactComponentLibrary]
|
|
50
|
+
.map(getSharedConfiguration)
|
|
51
|
+
.map(viteBuild)
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
buildLibraries()
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
};
|
package/tsconfig.json
ADDED
package/twind.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from '@twind/core';
|
|
2
|
+
import presetAutoprefix from '@twind/preset-autoprefix';
|
|
3
|
+
import presetTailwind from '@twind/preset-tailwind';
|
|
4
|
+
import presetTypography from '@twind/preset-typography';
|
|
5
|
+
import presetTailwindForms from '@twind/preset-tailwind-forms';
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
theme: {
|
|
9
|
+
extend: {
|
|
10
|
+
colors: {
|
|
11
|
+
primary: 'var(--clr-primary,black)',
|
|
12
|
+
accent: 'var(--clr-accent,blue)',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
presets: [
|
|
17
|
+
presetAutoprefix(),
|
|
18
|
+
presetTailwind(),
|
|
19
|
+
presetTypography(),
|
|
20
|
+
presetTailwindForms(),
|
|
21
|
+
],
|
|
22
|
+
});
|