tailwind-variants 0.0.25 → 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 CHANGED
@@ -18,9 +18,85 @@
18
18
  </p>
19
19
 
20
20
 
21
- # Tailwind Variants
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
- ```sh
36
- yarn add tailwind-variants
37
- #or
38
- npm i tailwind-variants
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!
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var v=["xs","sm","md","lg","xl","2xl"],l={tv:/tv\({[\s\S]*?}\)/g,tvContent:/\({[\s\S]*?}\)/g,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm},u=t=>Array.isArray(t),s=t=>!!(!t||u(t)&&t.length===0||typeof t=="string"&&t.length===0||typeof t=="object"&&Object.keys(t).length===0),y=t=>t.replace(l.comment,"$1").toString().replace(l.blankLine,"").toString().match(l.tv),d=t=>{let n=y(t);if(!s(n))return n.map(e=>new Function(`return ${e.match(l.tvContent).toString()}`)())},p=t=>t.flatMap(n=>n).toString().replaceAll(","," ").split(" "),h=t=>{let n={};for(let[e,r]of Object.entries(t))n[e]={},n[e].original=r,!s(r)&&(n.temp=u(r)?p(r):r.split(" "),v.forEach(i=>{let o="";n.temp.forEach(c=>{o+=`${i}:${c} `;}),n[e][i]=o.trimEnd();}),delete n.temp);return n},b=t=>typeof t=="string"?t.split(" "):u(t)?p(t):t instanceof Object?h(t):t,j=t=>{let{variants:n={}}=t;if(s(n))return;let e={};for(let[r,i]of Object.entries(n))if(e[r]={},!s(i))for(let[o,c]of Object.entries(i)){if(e[r][o]={},e[r][o].original=c,s(c))continue;let f=b(c);if(!s(f)){if(!u(f)){e[r][o]=f;continue}v.forEach(m=>{let g="";f.forEach(C=>{g+=`${m}:${C} `;}),e[r][o][m]=g.trimEnd();});}}return e},a=t=>{try{if(!t.includes("tailwind-variants"))return t;let n=d(t);if(s(n))return t;let e=JSON.stringify(n.map(r=>j(r)),void 0,2);return t.concat(`
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}},S={tsx:t=>a(t),ts:t=>a(t),jsx:t=>a(t),js:t=>a(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.transformer = S;
11
+ exports.tvTransformer = l;
12
+ exports.withTV = T;
@@ -1,8 +1,13 @@
1
- export type TVTransformer = {
2
- tsx(content: string): string;
3
- ts(content: string): string;
4
- jsx(content: string): string;
5
- js(content: string): string;
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 transformer: TVTransformer;
9
+ export declare const withTV: WithTV;
10
+
11
+ export type TVTransformer = {(content: string): string};
12
+
13
+ export declare const tvTransformer: TVTransformer;
@@ -1,9 +1,9 @@
1
- var v=["xs","sm","md","lg","xl","2xl"],l={tv:/tv\({[\s\S]*?}\)/g,tvContent:/\({[\s\S]*?}\)/g,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm},u=t=>Array.isArray(t),s=t=>!!(!t||u(t)&&t.length===0||typeof t=="string"&&t.length===0||typeof t=="object"&&Object.keys(t).length===0),y=t=>t.replace(l.comment,"$1").toString().replace(l.blankLine,"").toString().match(l.tv),d=t=>{let n=y(t);if(!s(n))return n.map(e=>new Function(`return ${e.match(l.tvContent).toString()}`)())},p=t=>t.flatMap(n=>n).toString().replaceAll(","," ").split(" "),h=t=>{let n={};for(let[e,r]of Object.entries(t))n[e]={},n[e].original=r,!s(r)&&(n.temp=u(r)?p(r):r.split(" "),v.forEach(i=>{let o="";n.temp.forEach(c=>{o+=`${i}:${c} `;}),n[e][i]=o.trimEnd();}),delete n.temp);return n},b=t=>typeof t=="string"?t.split(" "):u(t)?p(t):t instanceof Object?h(t):t,j=t=>{let{variants:n={}}=t;if(s(n))return;let e={};for(let[r,i]of Object.entries(n))if(e[r]={},!s(i))for(let[o,c]of Object.entries(i)){if(e[r][o]={},e[r][o].original=c,s(c))continue;let f=b(c);if(!s(f)){if(!u(f)){e[r][o]=f;continue}v.forEach(m=>{let g="";f.forEach(C=>{g+=`${m}:${C} `;}),e[r][o][m]=g.trimEnd();});}}return e},a=t=>{try{if(!t.includes("tailwind-variants"))return t;let n=d(t);if(s(n))return t;let e=JSON.stringify(n.map(r=>j(r)),void 0,2);return t.concat(`
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}},S={tsx:t=>a(t),ts:t=>a(t),jsx:t=>a(t),js:t=>a(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 { S as transformer };
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.25",
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",
@@ -62,12 +62,16 @@
62
62
  "prettier": "^2.2.1",
63
63
  "prettier-eslint": "^12.0.0",
64
64
  "prettier-eslint-cli": "^5.0.1",
65
+ "tailwindcss": "^3.2.4",
65
66
  "ts-node": "^10.9.1",
66
67
  "tslib": "^2.4.1",
67
68
  "tsup": "6.4.0",
68
69
  "typescript": "4.6.2",
69
70
  "webpack": "^5.53.0"
70
71
  },
72
+ "peerDependencies": {
73
+ "tailwindcss": "*"
74
+ },
71
75
  "keywords": [
72
76
  "tailwindcss",
73
77
  "classes",