tailwind-variants
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -8,16 +8,24 @@ import {TVConfig} from "./config"; | ||
type SlotsClassValue<S extends TVSlots> = { | ||
[K in keyof S]?: ClassValue; | ||
type TVSlotsWithBase<S extends TVSlots, B extends ClassValue> = B extends undefined | ||
? keyof S | ||
: keyof S | TVBaseName; | ||
type SlotsClassValue<S extends TVSlots, B extends ClassValue> = { | ||
[K in TVSlotsWithBase<S, B>]?: ClassValue; | ||
}; | ||
export type TVVariants<S extends TVSlots> = { | ||
export type TVVariants<S extends TVSlots, B extends ClassValue> = { | ||
[key: string]: { | ||
[key: string]: S extends TVSlots ? SlotsClassValue<S> | ClassValue : ClassValue; | ||
[key: string]: S extends TVSlots ? SlotsClassValue<S, B> | ClassValue : ClassValue; | ||
}; | ||
}; | ||
export type TVCompoundVariants<V extends TVVariants<S>, S extends TVSlots> = Array< | ||
export type TVCompoundVariants< | ||
V extends TVVariants<S>, | ||
S extends TVSlots, | ||
B extends ClassValue, | ||
> = Array< | ||
{ | ||
[K in keyof V]?: StringToBoolean<keyof V[K]> | StringToBoolean<keyof V[K]>[]; | ||
} & ClassProp<SlotsClassValue<S> | ClassValue> | ||
} & ClassProp<SlotsClassValue<S, B> | ClassValue> | ||
>; | ||
@@ -38,5 +46,3 @@ | ||
: { | ||
[K in B extends undefined ? keyof S : keyof S | TVBaseName]: ( | ||
slotProps?: ClassProp, | ||
) => string; | ||
[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string; | ||
}; | ||
@@ -46,3 +52,3 @@ | ||
DV extends TVDefaultVariants<V, S>, | ||
CV extends TVCompoundVariants<V, S>, | ||
CV extends TVCompoundVariants<V, S, B>, | ||
C extends TVConfig, | ||
@@ -49,0 +55,0 @@ V extends TVVariants<S>, |
import { cx } from 'class-variance-authority'; | ||
import { extendTailwindMerge, twMerge } from 'tailwind-merge'; | ||
var k=/[\W_]+/g,A=e=>{var u;return !e||!Array.isArray(e)?null:(u=e.filter)==null?void 0:u.call(e,t=>t&&!String(t).match(k)).map(String)},j=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,m=e=>e&&Object.keys(e).length>0,g=(...e)=>(u={})=>u.twMerge?(m(u.twMergeConfig)?extendTailwindMerge(u.twMergeConfig):twMerge)(cx(e)):cx(e);var R=(e,u={twMerge:!0,twMergeConfig:{}})=>t=>{var M,C;let{slots:d={},variants:b,defaultVariants:l}=e;if(b==null&&!m(d))return g(e==null?void 0:e.base,t==null?void 0:t.class,t==null?void 0:t.className)(u);let y={base:e==null?void 0:e.base,...d},x=r=>{let a=t==null?void 0:t[r],n=l==null?void 0:l[r];if(a===null)return null;let c=j(a)||j(n);return b[r][c]},V=b?Object.keys(b).map(x):null,N=r=>!b||typeof b!="object"?null:Object.keys(b).map(a=>{let n=x(a);return r==="base"&&typeof n=="string"?n:!n||typeof n!="object"?null:n[r]}),s=t&&Object.entries(t).reduce((r,[a,n])=>(n===void 0||(r[a]=n),r),{}),w=(M=e==null?void 0:e.compoundVariants)==null?void 0:M.reduce((r,{class:a,className:n,...c})=>Object.entries(c).every(([f,i])=>Array.isArray(i)?i.includes({...l,...s}[f]):{...l,...s}[f]===i)?[...r,a,n]:r,[]),S=()=>{let r=A(w);return Array.isArray(r)?r.reduce((a,n)=>(typeof n=="string"&&(a.base=g(a.base,n)(u)),typeof n=="object"&&Object.entries(n).forEach(([c,f])=>{a[c]=g(a[c],f)(u);}),a),{}):r};if(m(d)){let r=(C=S())!=null?C:[];return {...typeof y=="object"&&m(y)?Object.keys(y).reduce((n,c)=>(n[c]=f=>g(c==="base"?e==null?void 0:e.base:[],y[c],N(c),r==null?void 0:r[c],f==null?void 0:f.class,f==null?void 0:f.className)(u),n),{}):{}}}return g(e==null?void 0:e.base,V,w,t==null?void 0:t.class,t==null?void 0:t.className)(u)}; | ||
var i=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>e&&Object.keys(e).length>0,m=(...e)=>(f={})=>f.twMerge?(g(f.twMergeConfig)?extendTailwindMerge(f.twMergeConfig):twMerge)(cx(e)):cx(e);var F=(e,f={twMerge:!0,twMergeConfig:{}})=>n=>{var C,O;let{slots:l={},variants:b,defaultVariants:y}=e;if(b==null&&!g(l))return m(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(f);let d={base:e==null?void 0:e.base,...l},w=t=>{let a=n==null?void 0:n[t],r=y==null?void 0:y[t];if(a===null)return null;let u=i(a)||i(r);return b[t][u]},s=b?Object.keys(b).map(w):null,N=t=>!b||typeof b!="object"?null:Object.keys(b).map(a=>{let r=w(a);return t==="base"&&typeof r=="string"?r:!r||typeof r!="object"?null:r[t]}),M=n&&Object.entries(n).reduce((t,[a,r])=>(r===void 0||(t[a]=r),t),{}),x=(C=e==null?void 0:e.compoundVariants)==null?void 0:C.reduce((t,{class:a,className:r,...u})=>Object.entries(u).every(([c,j])=>Array.isArray(j)?j.includes({...y,...M}[c]):{...y,...M}[c]===j)?[...t,a,r]:t,[]),A=()=>{let t=x;return Array.isArray(t)?t.reduce((a,r)=>(typeof r=="string"&&(a.base=m(a.base,r)(f)),typeof r=="object"&&Object.entries(r).forEach(([u,c])=>{a[u]=m(a[u],c)(f);}),a),{}):t};if(g(l)){let t=(O=A())!=null?O:[];return {...typeof d=="object"&&g(d)?Object.keys(d).reduce((r,u)=>(r[u]=c=>m(u==="base"?e==null?void 0:e.base:[],d[u],N(u),t==null?void 0:t[u],c==null?void 0:c.class,c==null?void 0:c.className)(f),r),{}):{}}}return m(e==null?void 0:e.base,s,x,n==null?void 0:n.class,n==null?void 0:n.className)(f)}; | ||
export { R as tv }; | ||
export { F as tv }; |
@@ -5,4 +5,2 @@ import {CxOptions, CxReturn} from "class-variance-authority"; | ||
export declare const cleanArray: (array: string[]) => string[] | undefined; | ||
export declare const falsyToString: <T extends unknown>(value: T) => string | T; | ||
@@ -9,0 +7,0 @@ |
{ | ||
"name": "tailwind-variants", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "🦄 Tailwindcss first-class variant API", | ||
@@ -5,0 +5,0 @@ "author": "Junior Garcia <jrgarciadev@gmail.com>", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114
11803