tailwind-variants 0.0.11 → 0.0.13
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 +20 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +2 -2
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://tailwind-variants.org">
|
|
3
|
+
<img width="20%" src=".github/assets/isotipo.png" alt="tailwind-variants" />
|
|
4
|
+
<h1 align="center">tailwind-variants</h1>
|
|
5
|
+
</a>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
The <em>power</em> of Tailwind combined with a <em>first-class</em> variant API.<br><br>
|
|
9
|
+
<a href="https://www.npmjs.com/package/tailwind-variants">
|
|
10
|
+
<img src="https://img.shields.io/npm/dm/tailwind-variants.svg?style=flat-round" alt="npm downloads">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/tailwind-variants">
|
|
13
|
+
<img alt="NPM Version" src="https://badgen.net/npm/v/tailwind-variants" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://github.com/nextui-org/tailwind-variants/blob/main/LICENSE">
|
|
16
|
+
<img src="https://img.shields.io/npm/l/tailwind-variants?style=flat" alt="License">
|
|
17
|
+
</a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
|
|
1
21
|
# Tailwind Variants
|
|
2
22
|
|
|
3
23
|
🚧 Under construction - please check back later
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
var classVarianceAuthority = require('class-variance-authority');
|
|
4
4
|
var tailwindMerge = require('tailwind-merge');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var $=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,m=e=>e&&Object.keys(e).length>0,j=(...e)=>(s={})=>s.twMerge?(m(s.twMergeConfig)?tailwindMerge.extendTailwindMerge(s.twMergeConfig):tailwindMerge.twMerge)(classVarianceAuthority.cx(e)):classVarianceAuthority.cx(e),B=(e,s)=>{let f={};return typeof e!="object"||typeof s!="object"||Object.keys(e).forEach(u=>{s[u]?f[u]=classVarianceAuthority.cx([e[u],s[u]]):f[u]=e[u];}),f};var J=(e,s={twMerge:!0,twMergeConfig:{}})=>f=>{var x;let{slots:u={},variants:l={},compoundVariants:b=[],defaultVariants:d={},screenVariants:g={initial:{}}}=e;if(l==null&&!m(u))return j(e==null?void 0:e.base,f==null?void 0:f.class,f==null?void 0:f.className)(s);if(b&&!Array.isArray(b))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof b}`);let M={base:e==null?void 0:e.base,...u},S=(t,r,n,a=[])=>{let i=a;if(typeof r=="string")i.push(r.split(" ").map(c=>`${t}:${c}`));else if(Array.isArray(r))i.push(r.flatMap(c=>`${t}:${c}`));else if(typeof r=="object"&&typeof n=="string"){let c=r==null?void 0:r[n];c&&typeof c=="string"?i[n]=i[n]?[...i[n],...c.split(" ").map(y=>`${t}:${y}`)]:c.split(" ").map(y=>`${t}:${y}`):Array.isArray(c)&&c.length>0&&(i[n]=c.flatMap(y=>`${t}:${y}`));}return i},C=(t,r=null)=>{var A;let n=f==null?void 0:f[t],a=l==null?void 0:l[t],i=((A=g==null?void 0:g.initial)==null?void 0:A[t])||(d==null?void 0:d[t]),c=Object.keys(g).reduce((N,O)=>{var E;if(O==="initial")return N;let U=(E=g[O])==null?void 0:E[t],W=a==null?void 0:a[U];return S(O,W,r,N)},[]);if(typeof a!="object"||!m(a)||n===null)return null;let y=$(n)||$(i);return typeof c=="object"&&typeof r=="string"&&c[r]?B(c,a[y]):c.length>0?[a[y],...c]:a[y]},T=l?Object.keys(l).map(C):null,o=t=>!l||typeof l!="object"?null:Object.keys(l).map(r=>{let n=C(r,t);return t==="base"&&typeof n=="string"?n:n&&n[t]}).filter(Boolean),F=f&&Object.fromEntries(Object.entries(f).filter(([,t])=>t!==void 0)),h=b==null?void 0:b.filter(({class:t,className:r,...n})=>Object.entries(n).every(([a,i])=>{let c={...d,...g.initial,...F};return Array.isArray(i)?i.includes(c[a]):c[a]===i})).flatMap(({class:t,className:r})=>[t,r]),R=()=>{let t=h;return Array.isArray(t)?t.reduce((r,n)=>(typeof n=="string"&&(r.base=j(r.base,n)(s)),typeof n=="object"&&Object.entries(n).forEach(([a,i])=>{r[a]=j(r[a],i)(s);}),r),{}):t};if(m(u)){let t=(x=R())!=null?x:[];return {...typeof M=="object"&&m(M)?Object.keys(M).reduce((n,a)=>(n[a]=i=>j(M[a],o(a),t==null?void 0:t[a],i==null?void 0:i.class,i==null?void 0:i.className)(s),n),{}):{}}}return j(e==null?void 0:e.base,T,h,f==null?void 0:f.class,f==null?void 0:f.className)(s)};
|
|
7
7
|
|
|
8
|
-
exports.tv =
|
|
8
|
+
exports.tv = J;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import {ClassValue, ClassProp, OmitUndefined, StringToBoolean} from "./utils";
|
|
|
3
3
|
|
|
4
4
|
type TVBaseName = "base";
|
|
5
5
|
|
|
6
|
+
type TVScreens = "initial" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
7
|
+
|
|
6
8
|
type TVSlots = Record<string, ClassValue> | undefined;
|
|
7
9
|
|
|
8
10
|
type TVSlotsWithBase<S extends TVSlots, B extends ClassValue> = B extends undefined
|
|
@@ -33,6 +35,12 @@ export type TVDefaultVariants<V extends TVVariants<S>, S extends TVSlots> = {
|
|
|
33
35
|
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
34
36
|
};
|
|
35
37
|
|
|
38
|
+
export type TVScreenVariants<V extends TVVariants<S>> = {
|
|
39
|
+
[K in TVScreens]?: {
|
|
40
|
+
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
36
44
|
export type TVProps<V extends TVVariants<S>, S extends TVSlots> = {
|
|
37
45
|
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
38
46
|
} & ClassProp;
|
|
@@ -46,10 +54,11 @@ export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends C
|
|
|
46
54
|
};
|
|
47
55
|
|
|
48
56
|
export function tv<
|
|
49
|
-
|
|
57
|
+
V extends TVVariants<S>,
|
|
50
58
|
CV extends TVCompoundVariants<V, S, B>,
|
|
59
|
+
DV extends TVDefaultVariants<V, S>,
|
|
60
|
+
SV extends TVScreenVariants<V>,
|
|
51
61
|
C extends TVConfig,
|
|
52
|
-
V extends TVVariants<S>,
|
|
53
62
|
B extends ClassValue = undefined,
|
|
54
63
|
S extends TVSlots = undefined,
|
|
55
64
|
>(
|
|
@@ -58,6 +67,7 @@ export function tv<
|
|
|
58
67
|
slots?: S;
|
|
59
68
|
variants?: V;
|
|
60
69
|
compoundVariants?: CV;
|
|
70
|
+
screenVariants?: SV;
|
|
61
71
|
defaultVariants?: DV;
|
|
62
72
|
},
|
|
63
73
|
config?: C,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cx } from 'class-variance-authority';
|
|
2
2
|
import { extendTailwindMerge, twMerge } from 'tailwind-merge';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var $=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,m=e=>e&&Object.keys(e).length>0,j=(...e)=>(s={})=>s.twMerge?(m(s.twMergeConfig)?extendTailwindMerge(s.twMergeConfig):twMerge)(cx(e)):cx(e),B=(e,s)=>{let f={};return typeof e!="object"||typeof s!="object"||Object.keys(e).forEach(u=>{s[u]?f[u]=cx([e[u],s[u]]):f[u]=e[u];}),f};var J=(e,s={twMerge:!0,twMergeConfig:{}})=>f=>{var x;let{slots:u={},variants:l={},compoundVariants:b=[],defaultVariants:d={},screenVariants:g={initial:{}}}=e;if(l==null&&!m(u))return j(e==null?void 0:e.base,f==null?void 0:f.class,f==null?void 0:f.className)(s);if(b&&!Array.isArray(b))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof b}`);let M={base:e==null?void 0:e.base,...u},S=(t,r,n,a=[])=>{let i=a;if(typeof r=="string")i.push(r.split(" ").map(c=>`${t}:${c}`));else if(Array.isArray(r))i.push(r.flatMap(c=>`${t}:${c}`));else if(typeof r=="object"&&typeof n=="string"){let c=r==null?void 0:r[n];c&&typeof c=="string"?i[n]=i[n]?[...i[n],...c.split(" ").map(y=>`${t}:${y}`)]:c.split(" ").map(y=>`${t}:${y}`):Array.isArray(c)&&c.length>0&&(i[n]=c.flatMap(y=>`${t}:${y}`));}return i},C=(t,r=null)=>{var A;let n=f==null?void 0:f[t],a=l==null?void 0:l[t],i=((A=g==null?void 0:g.initial)==null?void 0:A[t])||(d==null?void 0:d[t]),c=Object.keys(g).reduce((N,O)=>{var E;if(O==="initial")return N;let U=(E=g[O])==null?void 0:E[t],W=a==null?void 0:a[U];return S(O,W,r,N)},[]);if(typeof a!="object"||!m(a)||n===null)return null;let y=$(n)||$(i);return typeof c=="object"&&typeof r=="string"&&c[r]?B(c,a[y]):c.length>0?[a[y],...c]:a[y]},T=l?Object.keys(l).map(C):null,o=t=>!l||typeof l!="object"?null:Object.keys(l).map(r=>{let n=C(r,t);return t==="base"&&typeof n=="string"?n:n&&n[t]}).filter(Boolean),F=f&&Object.fromEntries(Object.entries(f).filter(([,t])=>t!==void 0)),h=b==null?void 0:b.filter(({class:t,className:r,...n})=>Object.entries(n).every(([a,i])=>{let c={...d,...g.initial,...F};return Array.isArray(i)?i.includes(c[a]):c[a]===i})).flatMap(({class:t,className:r})=>[t,r]),R=()=>{let t=h;return Array.isArray(t)?t.reduce((r,n)=>(typeof n=="string"&&(r.base=j(r.base,n)(s)),typeof n=="object"&&Object.entries(n).forEach(([a,i])=>{r[a]=j(r[a],i)(s);}),r),{}):t};if(m(u)){let t=(x=R())!=null?x:[];return {...typeof M=="object"&&m(M)?Object.keys(M).reduce((n,a)=>(n[a]=i=>j(M[a],o(a),t==null?void 0:t[a],i==null?void 0:i.class,i==null?void 0:i.className)(s),n),{}):{}}}return j(e==null?void 0:e.base,T,h,f==null?void 0:f.class,f==null?void 0:f.className)(s)};
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { J as tv };
|
package/dist/utils.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const isNotEmptyObject: (obj: object) => boolean;
|
|
|
8
8
|
|
|
9
9
|
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;
|
|
10
10
|
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const joinObjects: (obj1: object, obj2: object) => object;
|
|
12
12
|
|
|
13
13
|
export declare type ClassPropKey = "class" | "className";
|
|
14
14
|
export declare type ClassValue = string | string[] | null | undefined;
|