tailwind-variants 0.0.12 → 0.0.14
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 +8 -9
- package/dist/index.js +2 -2
- package/dist/utils.d.ts +3 -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 o=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,g=t=>t&&Object.keys(t).length>0,j=(...t)=>(u={})=>u.twMerge?(g(u.twMergeConfig)?tailwindMerge.extendTailwindMerge(u.twMergeConfig):tailwindMerge.twMerge)(classVarianceAuthority.cx(t)):classVarianceAuthority.cx(t),E=(t,u)=>{let r={};return typeof t!="object"||typeof u!="object"||Object.keys(t).forEach(l=>{u[l]?r[l]=classVarianceAuthority.cx([t[l],u[l]]):r[l]=t[l];}),r},w=t=>!t||typeof t!="string"?t:t.replace(/\s+/g," ").trim();var H=(t,u={twMerge:!0,twMergeConfig:{}})=>r=>{var h;let{slots:l={},variants:m={},compoundVariants:b=[],defaultVariants:d={}}=t;if(m==null&&!g(l))return j(t==null?void 0:t.base,r==null?void 0:r.class,r==null?void 0:r.className)(u);if(b&&!Array.isArray(b))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof b}`);let x={base:t==null?void 0:t.base,...l},S=(e,n,f=[],i)=>{let a=f;if(typeof n=="string")a.push(w(n).split(" ").map(c=>`${e}:${c}`));else if(Array.isArray(n))a.push(n.flatMap(c=>`${e}:${c}`));else if(typeof n=="object"&&typeof i=="string"){let c=n==null?void 0:n[i];if(c&&typeof c=="string"){let s=w(c);a[i]=a[i]?[...a[i],...s.split(" ").map(y=>`${e}:${y}`)]:s.split(" ").map(y=>`${e}:${y}`);}else Array.isArray(c)&&c.length>0&&(a[i]=c.flatMap(s=>`${e}:${s}`));}return a},$=(e,n=null)=>{let f=m==null?void 0:m[e];if(typeof f!="object"||!g(f))return null;let i=r==null?void 0:r[e],a=d==null?void 0:d[e],c=[];if(i===null)return null;let s=o(i);typeof s=="object"&&(c=Object.keys(s).reduce((A,M)=>{let N=s[M],R=f==null?void 0:f[N];return M==="initial"?(a=N,A):S(M,R,A,n)},[]));let y=f[s]||f[o(a)];return typeof c=="object"&&typeof n=="string"&&c[n]?E(c,y):c.length>0?[y,...c]:y},B=m?Object.keys(m).map($):null,T=e=>!m||typeof m!="object"?null:Object.keys(m).map(n=>{let f=$(n,e);return e==="base"&&typeof f=="string"?f:f&&f[e]}).filter(Boolean),v=r&&Object.fromEntries(Object.entries(r).filter(([,e])=>e!==void 0)),C=b==null?void 0:b.filter(({class:e,className:n,...f})=>Object.entries(f).every(([i,a])=>{let c=typeof r[i]=="object"?r[i].initial:{},s={...d,...c,...v};return Array.isArray(a)?a.includes(s[i]):s[i]===a})).flatMap(({class:e,className:n})=>[e,n]),F=()=>{let e=C;return Array.isArray(e)?e.reduce((n,f)=>(typeof f=="string"&&(n.base=j(n.base,f)(u)),typeof f=="object"&&Object.entries(f).forEach(([i,a])=>{n[i]=j(n[i],a)(u);}),n),{}):e};if(g(l)){let e=(h=F())!=null?h:[];return {...typeof x=="object"&&g(x)?Object.keys(x).reduce((f,i)=>(f[i]=a=>j(x[i],T(i),e==null?void 0:e[i],a==null?void 0:a.class,a==null?void 0:a.className)(u),f),{}):{}}}return j(t==null?void 0:t.base,B,C,r==null?void 0:r.class,r==null?void 0:r.className)(u)};
|
|
7
7
|
|
|
8
|
-
exports.tv =
|
|
8
|
+
exports.tv = H;
|
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,8 +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 TVScreenPropsValue<V extends TVVariants<S>, K extends keyof V> = {
|
|
39
|
+
[K2 in TVScreens]?: StringToBoolean<keyof V[K]>;
|
|
40
|
+
};
|
|
41
|
+
|
|
36
42
|
export type TVProps<V extends TVVariants<S>, S extends TVSlots> = {
|
|
37
|
-
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
43
|
+
[K in keyof V]?: StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, K>;
|
|
38
44
|
} & ClassProp;
|
|
39
45
|
|
|
40
46
|
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = (
|
|
@@ -45,16 +51,10 @@ export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends C
|
|
|
45
51
|
[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string;
|
|
46
52
|
};
|
|
47
53
|
|
|
48
|
-
export type TVDark<S extends TVSlots, B extends ClassValue> =
|
|
49
|
-
| {
|
|
50
|
-
[K in TVSlotsWithBase<S, B>]?: ClassValue;
|
|
51
|
-
}
|
|
52
|
-
| ClassValue;
|
|
53
|
-
|
|
54
54
|
export function tv<
|
|
55
55
|
V extends TVVariants<S>,
|
|
56
|
-
DV extends TVDefaultVariants<V, S>,
|
|
57
56
|
CV extends TVCompoundVariants<V, S, B>,
|
|
57
|
+
DV extends TVDefaultVariants<V, S>,
|
|
58
58
|
C extends TVConfig,
|
|
59
59
|
B extends ClassValue = undefined,
|
|
60
60
|
S extends TVSlots = undefined,
|
|
@@ -62,7 +62,6 @@ export function tv<
|
|
|
62
62
|
options: {
|
|
63
63
|
base?: B;
|
|
64
64
|
slots?: S;
|
|
65
|
-
dark?: TVDark<S, B>;
|
|
66
65
|
variants?: V;
|
|
67
66
|
compoundVariants?: CV;
|
|
68
67
|
defaultVariants?: DV;
|
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 o=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,g=t=>t&&Object.keys(t).length>0,j=(...t)=>(u={})=>u.twMerge?(g(u.twMergeConfig)?extendTailwindMerge(u.twMergeConfig):twMerge)(cx(t)):cx(t),E=(t,u)=>{let r={};return typeof t!="object"||typeof u!="object"||Object.keys(t).forEach(l=>{u[l]?r[l]=cx([t[l],u[l]]):r[l]=t[l];}),r},w=t=>!t||typeof t!="string"?t:t.replace(/\s+/g," ").trim();var H=(t,u={twMerge:!0,twMergeConfig:{}})=>r=>{var h;let{slots:l={},variants:m={},compoundVariants:b=[],defaultVariants:d={}}=t;if(m==null&&!g(l))return j(t==null?void 0:t.base,r==null?void 0:r.class,r==null?void 0:r.className)(u);if(b&&!Array.isArray(b))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof b}`);let x={base:t==null?void 0:t.base,...l},S=(e,n,f=[],i)=>{let a=f;if(typeof n=="string")a.push(w(n).split(" ").map(c=>`${e}:${c}`));else if(Array.isArray(n))a.push(n.flatMap(c=>`${e}:${c}`));else if(typeof n=="object"&&typeof i=="string"){let c=n==null?void 0:n[i];if(c&&typeof c=="string"){let s=w(c);a[i]=a[i]?[...a[i],...s.split(" ").map(y=>`${e}:${y}`)]:s.split(" ").map(y=>`${e}:${y}`);}else Array.isArray(c)&&c.length>0&&(a[i]=c.flatMap(s=>`${e}:${s}`));}return a},$=(e,n=null)=>{let f=m==null?void 0:m[e];if(typeof f!="object"||!g(f))return null;let i=r==null?void 0:r[e],a=d==null?void 0:d[e],c=[];if(i===null)return null;let s=o(i);typeof s=="object"&&(c=Object.keys(s).reduce((A,M)=>{let N=s[M],R=f==null?void 0:f[N];return M==="initial"?(a=N,A):S(M,R,A,n)},[]));let y=f[s]||f[o(a)];return typeof c=="object"&&typeof n=="string"&&c[n]?E(c,y):c.length>0?[y,...c]:y},B=m?Object.keys(m).map($):null,T=e=>!m||typeof m!="object"?null:Object.keys(m).map(n=>{let f=$(n,e);return e==="base"&&typeof f=="string"?f:f&&f[e]}).filter(Boolean),v=r&&Object.fromEntries(Object.entries(r).filter(([,e])=>e!==void 0)),C=b==null?void 0:b.filter(({class:e,className:n,...f})=>Object.entries(f).every(([i,a])=>{let c=typeof r[i]=="object"?r[i].initial:{},s={...d,...c,...v};return Array.isArray(a)?a.includes(s[i]):s[i]===a})).flatMap(({class:e,className:n})=>[e,n]),F=()=>{let e=C;return Array.isArray(e)?e.reduce((n,f)=>(typeof f=="string"&&(n.base=j(n.base,f)(u)),typeof f=="object"&&Object.entries(f).forEach(([i,a])=>{n[i]=j(n[i],a)(u);}),n),{}):e};if(g(l)){let e=(h=F())!=null?h:[];return {...typeof x=="object"&&g(x)?Object.keys(x).reduce((f,i)=>(f[i]=a=>j(x[i],T(i),e==null?void 0:e[i],a==null?void 0:a.class,a==null?void 0:a.className)(u),f),{}):{}}}return j(t==null?void 0:t.base,B,C,r==null?void 0:r.class,r==null?void 0:r.className)(u)};
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { H as tv };
|
package/dist/utils.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ 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
|
+
|
|
13
|
+
export declare const removeExtraSpaces: (str: string) => string;
|
|
12
14
|
|
|
13
15
|
export declare type ClassPropKey = "class" | "className";
|
|
14
16
|
export declare type ClassValue = string | string[] | null | undefined;
|