tailwind-variants 0.0.24 → 0.0.26
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/README.md +86 -8
- package/dist/transformer.cjs +5 -4
- package/dist/transformer.d.ts +11 -6
- package/dist/transformer.js +4 -4
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -18,9 +18,85 @@
|
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- Zero runtime
|
|
24
|
+
- First-class variant API
|
|
25
|
+
- Responsive variants
|
|
26
|
+
- Slots support
|
|
27
|
+
- Composition support
|
|
28
|
+
- Fully typed
|
|
29
|
+
- Framework agnostic
|
|
30
|
+
- Automatic conflict resolution
|
|
31
|
+
|
|
32
|
+
## Documentation
|
|
33
|
+
|
|
34
|
+
For full documentation, visit [tailwind-variants.org](https://tailwind-variants.org)
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
1. Installation:
|
|
39
|
+
To use Tailwind Variants in your project, you can install it as a dependency:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
yarn add tailwind-variants
|
|
43
|
+
# or
|
|
44
|
+
npm i tailwind-variants
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
2. Usage:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { tv } from 'tailwind-variants';
|
|
51
|
+
|
|
52
|
+
const button = tv({
|
|
53
|
+
base: "font-medium bg-blue-500 text-white rounded-full active:opacity-80",
|
|
54
|
+
variants: {
|
|
55
|
+
color: {
|
|
56
|
+
primary: "bg-blue-500 text-white",
|
|
57
|
+
secondary: "bg-purple-500 text-white",
|
|
58
|
+
},
|
|
59
|
+
size: {
|
|
60
|
+
sm: "text-sm",
|
|
61
|
+
md: "text-base",
|
|
62
|
+
lg: "px-4 py-3 text-lg",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
compoundVariants: [
|
|
66
|
+
{
|
|
67
|
+
size: ["sm", "md"],
|
|
68
|
+
class: "px-3 py-1",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
defaultVariants: {
|
|
72
|
+
size: "md",
|
|
73
|
+
color: "primary",
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<button className={button({ size: 'sm', color: 'secondary' })}>Click me</button>
|
|
79
|
+
)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
3. Responsive variants configuration (optional): If you want to use responsive variants
|
|
83
|
+
you need to add the Tailwind Variants `wrapper` to your TailwindCSS config file `tailwind.config.js`.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
// tailwind.config.js
|
|
87
|
+
|
|
88
|
+
const { withTV } = require('tailwind-variants/transformer')
|
|
89
|
+
|
|
90
|
+
/** @type {import('tailwindcss').Config} */
|
|
91
|
+
module.exports = withTV({
|
|
92
|
+
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
|
93
|
+
theme: {
|
|
94
|
+
extend: {},
|
|
95
|
+
},
|
|
96
|
+
plugins: [],
|
|
97
|
+
})
|
|
98
|
+
```
|
|
22
99
|
|
|
23
|
-
🚧 Under construction - please check back later
|
|
24
100
|
|
|
25
101
|
## Acknowledgements
|
|
26
102
|
|
|
@@ -30,13 +106,15 @@
|
|
|
30
106
|
- [**Stitches**](https://stitches.dev/) ([Modulz](https://modulz.app))
|
|
31
107
|
The pioneers of the `variants` API movement. Inmense thanks to [Modulz](https://modulz.app) for their work on Stitches and the community around it. 🙏
|
|
32
108
|
|
|
33
|
-
## Installation
|
|
34
109
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
110
|
+
## Community
|
|
111
|
+
|
|
112
|
+
We're excited to see the community adopt NextUI, raise issues, and provide feedback. Whether it's a feature request, bug report, or a project to showcase, please get involved!
|
|
113
|
+
|
|
114
|
+
- [Discord](https://discord.gg/9b6yyZKmH4)
|
|
115
|
+
- [Twitter](https://twitter.com/getnextui)
|
|
116
|
+
- [GitHub Discussions](https://github.com/nextui-org/tailwind-variants/discussions)
|
|
117
|
+
|
|
40
118
|
## Contributing
|
|
41
119
|
|
|
42
120
|
Contributions are always welcome!
|
package/dist/transformer.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var b=["xs","sm","md","lg","xl","2xl"],a={tv:/tv\({[\s\S]*?}\)/g,tvContent:/\({[\s\S]*?}\)/g,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,ext:/\.\w+/g},u=n=>Array.isArray(n),g=n=>typeof n=="string",m=n=>typeof n=="object",y=n=>typeof n=="function",f=n=>!!(!n||u(n)&&n.length===0||g(n)&&n.length===0||m(n)&&Object.keys(n).length===0),E=(...n)=>t=>n.reduce((e,r)=>r(e),t),O=n=>n.replace(a.comment,"$1").toString().replace(a.blankLine,"").toString().match(a.tv),S=n=>{let t=O(n);if(!f(t))return t.map(e=>new Function(`return ${e.match(a.tvContent).toString()}`)())},h=n=>n.flatMap(t=>t).toString().replaceAll(","," ").split(" "),C=n=>{let t={};for(let[e,r]of Object.entries(n))t[e]={},t[e].original=r,!f(r)&&(t.temp=u(r)?h(r):r.split(" "),b.forEach(o=>{let s="";t.temp.forEach(i=>{s+=`${o}:${i} `;}),t[e][o]=s.trimEnd();}),delete t.temp);return t},$=n=>g(n)?n.split(" "):u(n)?h(n):m(n)?C(n):n,d=n=>{let{variants:t={}}=n;if(f(t))return;let e={};for(let[r,o]of Object.entries(t))if(e[r]={},!f(o))for(let[s,i]of Object.entries(o)){if(e[r][s]={},e[r][s].original=i,f(i))continue;let c=$(i);if(!f(c)){if(!u(c)){e[r][s]=c;continue}b.forEach(v=>{let x="";c.forEach(j=>{x+=`${v}:${j} `;}),e[r][s][v]=x.trimEnd();});}}return e},l=n=>{try{if(!n.includes("tailwind-variants"))return n;let t=S(n);if(f(t))return n;let e=JSON.stringify(t.map(r=>d(r)),void 0,2);return n.concat(`
|
|
4
4
|
/*
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${e}
|
|
7
7
|
|
|
8
8
|
*/
|
|
9
|
-
`)}catch{return t}},
|
|
9
|
+
`)}catch{return n}},p=n=>{let t=n.map(e=>{if(m(e)&&e.extension)return e.extension;let r=e.match(a.ext);return r||(r=e.split("{"),r=r.pop().replace("}","").split(",")),r.map(o=>o.replace(".","").split(".")).flat()}).flatMap(e=>e);return Array.from(new Set(t)).filter(e=>e!=="html")},T=n=>{var e,r;let t=Object.assign({},n);if(f(t==null?void 0:t.content)||g(t.content))return t;if(u(t.content)){let s=p(t.content).map(i=>[i,l]);return t.content={},t.content.files=n.content,t.content.transform=Object.fromEntries(s),t}if(m(t.content)){if(f((e=t.content)==null?void 0:e.files)||g(t.content.files))return t;if(f((r=t.content)==null?void 0:r.transform)){let s=p(t.content.files).map(i=>[i,l]);return t.content.transform=Object.fromEntries(s),t}if(y(t.content.transform)){let{transform:o}=n.content,i=p(t.content.files).map(c=>[c,E(l,o)]);return t.content.transform=Object.fromEntries(i),t}if(m(t.content.transform)){let{transform:o}=n.content,i=p(t.content.files).map(c=>[c,E(l,o[c]&&o[c])]);return t.content.transform=Object.fromEntries(i),t}return t}return t};
|
|
10
10
|
|
|
11
|
-
exports.
|
|
11
|
+
exports.tvTransformer = l;
|
|
12
|
+
exports.withTV = T;
|
package/dist/transformer.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {Config} from "tailwindcss/types/config";
|
|
2
|
+
|
|
3
|
+
export type TailwindConfig = Config;
|
|
4
|
+
|
|
5
|
+
export type WithTV = {
|
|
6
|
+
<TC extends TailwindConfig>(tvConfig: TailwindConfig): TC;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const withTV: WithTV;
|
|
10
|
+
|
|
11
|
+
export type TVTransformer = {(content: string): string};
|
|
12
|
+
|
|
13
|
+
export declare const tvTransformer: TVTransformer;
|
package/dist/transformer.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var b=["xs","sm","md","lg","xl","2xl"],a={tv:/tv\({[\s\S]*?}\)/g,tvContent:/\({[\s\S]*?}\)/g,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,ext:/\.\w+/g},u=n=>Array.isArray(n),g=n=>typeof n=="string",m=n=>typeof n=="object",y=n=>typeof n=="function",f=n=>!!(!n||u(n)&&n.length===0||g(n)&&n.length===0||m(n)&&Object.keys(n).length===0),E=(...n)=>t=>n.reduce((e,r)=>r(e),t),O=n=>n.replace(a.comment,"$1").toString().replace(a.blankLine,"").toString().match(a.tv),S=n=>{let t=O(n);if(!f(t))return t.map(e=>new Function(`return ${e.match(a.tvContent).toString()}`)())},h=n=>n.flatMap(t=>t).toString().replaceAll(","," ").split(" "),C=n=>{let t={};for(let[e,r]of Object.entries(n))t[e]={},t[e].original=r,!f(r)&&(t.temp=u(r)?h(r):r.split(" "),b.forEach(o=>{let s="";t.temp.forEach(i=>{s+=`${o}:${i} `;}),t[e][o]=s.trimEnd();}),delete t.temp);return t},$=n=>g(n)?n.split(" "):u(n)?h(n):m(n)?C(n):n,d=n=>{let{variants:t={}}=n;if(f(t))return;let e={};for(let[r,o]of Object.entries(t))if(e[r]={},!f(o))for(let[s,i]of Object.entries(o)){if(e[r][s]={},e[r][s].original=i,f(i))continue;let c=$(i);if(!f(c)){if(!u(c)){e[r][s]=c;continue}b.forEach(v=>{let x="";c.forEach(j=>{x+=`${v}:${j} `;}),e[r][s][v]=x.trimEnd();});}}return e},l=n=>{try{if(!n.includes("tailwind-variants"))return n;let t=S(n);if(f(t))return n;let e=JSON.stringify(t.map(r=>d(r)),void 0,2);return n.concat(`
|
|
2
2
|
/*
|
|
3
3
|
|
|
4
|
-
${
|
|
4
|
+
${e}
|
|
5
5
|
|
|
6
6
|
*/
|
|
7
|
-
`)}catch{return t}},
|
|
7
|
+
`)}catch{return n}},p=n=>{let t=n.map(e=>{if(m(e)&&e.extension)return e.extension;let r=e.match(a.ext);return r||(r=e.split("{"),r=r.pop().replace("}","").split(",")),r.map(o=>o.replace(".","").split(".")).flat()}).flatMap(e=>e);return Array.from(new Set(t)).filter(e=>e!=="html")},T=n=>{var e,r;let t=Object.assign({},n);if(f(t==null?void 0:t.content)||g(t.content))return t;if(u(t.content)){let s=p(t.content).map(i=>[i,l]);return t.content={},t.content.files=n.content,t.content.transform=Object.fromEntries(s),t}if(m(t.content)){if(f((e=t.content)==null?void 0:e.files)||g(t.content.files))return t;if(f((r=t.content)==null?void 0:r.transform)){let s=p(t.content.files).map(i=>[i,l]);return t.content.transform=Object.fromEntries(s),t}if(y(t.content.transform)){let{transform:o}=n.content,i=p(t.content.files).map(c=>[c,E(l,o)]);return t.content.transform=Object.fromEntries(i),t}if(m(t.content.transform)){let{transform:o}=n.content,i=p(t.content.files).map(c=>[c,E(l,o[c]&&o[c])]);return t.content.transform=Object.fromEntries(i),t}return t}return t};
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export { l as tvTransformer, T as withTV };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-variants",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "🦄 Tailwindcss first-class variant API",
|
|
5
5
|
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,10 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsup && node copy-types.cjs",
|
|
30
|
-
"dev": "pnpm build:fast -- --watch",
|
|
31
|
-
"clean": "rimraf dist .turbo",
|
|
32
30
|
"typecheck": "tsc --noEmit",
|
|
33
|
-
"dry-run": "node ./scripts/dry-run.js",
|
|
34
31
|
"prepack": "clean-package",
|
|
35
32
|
"postpack": "clean-package restore",
|
|
36
33
|
"lint": "eslint -c .eslintrc.json ./src/**/*.{ts,tsx}",
|
|
@@ -61,16 +58,20 @@
|
|
|
61
58
|
"eslint-plugin-node": "^11.1.0",
|
|
62
59
|
"eslint-plugin-prettier": "^4.0.0",
|
|
63
60
|
"eslint-plugin-promise": "^6.0.0",
|
|
61
|
+
"jest": "28.1.1",
|
|
64
62
|
"prettier": "^2.2.1",
|
|
65
63
|
"prettier-eslint": "^12.0.0",
|
|
66
64
|
"prettier-eslint-cli": "^5.0.1",
|
|
67
|
-
"
|
|
65
|
+
"tailwindcss": "^3.2.4",
|
|
68
66
|
"ts-node": "^10.9.1",
|
|
69
67
|
"tslib": "^2.4.1",
|
|
70
68
|
"tsup": "6.4.0",
|
|
71
69
|
"typescript": "4.6.2",
|
|
72
70
|
"webpack": "^5.53.0"
|
|
73
71
|
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"tailwindcss": "*"
|
|
74
|
+
},
|
|
74
75
|
"keywords": [
|
|
75
76
|
"tailwindcss",
|
|
76
77
|
"classes",
|