tailwind-variants
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -44,30 +44,32 @@ import {TVConfig} from "./config"; | ||
[K in keyof V]?: StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, K>; | ||
} & ClassProp; | ||
} & ClassProp<ClassValue>; | ||
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = ( | ||
props?: TVProps<V, S>, | ||
) => S extends undefined | ||
? string | ||
: { | ||
[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string; | ||
}; | ||
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = { | ||
(props?: TVProps<V, S>): S extends undefined | ||
? string | ||
: {[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string}; | ||
}; | ||
export function tv< | ||
V extends TVVariants<S>, | ||
CV extends TVCompoundVariants<V, S, B>, | ||
DV extends TVDefaultVariants<V, S>, | ||
C extends TVConfig, | ||
B extends ClassValue = undefined, | ||
S extends TVSlots = undefined, | ||
>( | ||
options: { | ||
base?: B; | ||
slots?: S; | ||
variants?: V; | ||
compoundVariants?: CV; | ||
defaultVariants?: DV; | ||
}, | ||
config?: C, | ||
): TVReturnType<V, S, B>; | ||
export type TV = { | ||
< | ||
V extends TVVariants<S> = {}, | ||
CV extends TVCompoundVariants<V, S, B> = [], | ||
DV extends TVDefaultVariants<V, S> = {}, | ||
C extends TVConfig, | ||
B extends ClassValue = undefined, | ||
S extends TVSlots = undefined, | ||
>( | ||
options: { | ||
base?: B; | ||
slots?: S; | ||
variants?: V; | ||
compoundVariants?: CV; | ||
defaultVariants?: DV; | ||
}, | ||
config?: C, | ||
): TVReturnType<V, S, B>; | ||
}; | ||
export declare const tv: TV; | ||
export type VariantProps<Component extends (...args: any) => any> = Omit< | ||
@@ -74,0 +76,0 @@ OmitUndefined<Parameters<Component>[0]>, |
@@ -1,6 +0,5 @@ | ||
import { cx } from 'class-variance-authority'; | ||
import { extendTailwindMerge, twMerge } from 'tailwind-merge'; | ||
var w=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 e={};return typeof t!="object"||typeof u!="object"||Object.keys(t).forEach(s=>{u[s]?e[s]=cx([t[s],u[s]]):e[s]=t[s];}),e},$=t=>!t||typeof t!="string"?t:t.replace(/\s+/g," ").trim();var H=(t,u={twMerge:!0,twMergeConfig:{}})=>e=>{var A;let{slots:s={},variants:y={},compoundVariants:b=[],defaultVariants:d={}}=t;if(y==null&&!g(s))return j(t==null?void 0:t.base,e==null?void 0:e.class,e==null?void 0:e.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,...s},S=(r,n,f=[],i)=>{let a=f;if(typeof n=="string")a.push($(n).split(" ").map(c=>`${r}:${c}`));else if(Array.isArray(n))a.push(n.flatMap(c=>`${r}:${c}`));else if(typeof n=="object"&&typeof i=="string"){let c=n==null?void 0:n[i];if(c&&typeof c=="string"){let l=$(c);a[i]=a[i]?[...a[i],...l.split(" ").map(m=>`${r}:${m}`)]:l.split(" ").map(m=>`${r}:${m}`);}else Array.isArray(c)&&c.length>0&&(a[i]=c.flatMap(l=>`${r}:${l}`));}return a},C=(r,n=null)=>{let f=y==null?void 0:y[r];if(typeof f!="object"||!g(f))return null;let i=e==null?void 0:e[r],a=d==null?void 0:d[r],c=[];if(i===null)return null;let l=w(i);typeof l=="object"&&(c=Object.keys(l).reduce((N,M)=>{let o=l[M],R=f==null?void 0:f[o];return M==="initial"?(a=o,N):S(M,R,N,n)},[]));let m=f[l]||f[w(a)];return typeof c=="object"&&typeof n=="string"&&c[n]?E(c,m):c.length>0?[m,...c]:m},B=y?Object.keys(y).map(C):null,T=r=>!y||typeof y!="object"?null:Object.keys(y).map(n=>{let f=C(n,r);return r==="base"&&typeof f=="string"?f:f&&f[r]}).filter(Boolean),v=e&&Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0)),h=b==null?void 0:b.filter(({class:r,className:n,...f})=>Object.entries(f).every(([i,a])=>{var m;let c=typeof(e==null?void 0:e[i])=="object"?(m=e[i])==null?void 0:m.initial:{},l={...d,...c,...v};return Array.isArray(a)?a.includes(l[i]):l[i]===a})).flatMap(({class:r,className:n})=>[r,n]),F=()=>{let r=h;return Array.isArray(r)?r.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),{}):r};if(g(s)){let r=(A=F())!=null?A:[];return {...typeof x=="object"&&g(x)?Object.keys(x).reduce((f,i)=>(f[i]=a=>j(x[i],T(i),r==null?void 0:r[i],a==null?void 0:a.class,a==null?void 0:a.className)(u),f),{}):{}}}return j(t==null?void 0:t.base,B,h,e==null?void 0:e.class,e==null?void 0:e.className)(u)}; | ||
var O=(...t)=>t.flat(1/0).filter(Boolean).join(" "),w=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,m=t=>t&&Object.keys(t).length>0,j=(...t)=>(u={})=>u.twMerge?(m(u.twMergeConfig)?extendTailwindMerge(u.twMergeConfig):twMerge)(O(t)):O(t),E=(t,u)=>{let e={};return typeof t!="object"||typeof u!="object"||Object.keys(t).forEach(s=>{u[s]?e[s]=O([t[s],u[s]]):e[s]=t[s];}),e},$=t=>!t||typeof t!="string"?t:t.replace(/\s+/g," ").trim();var D=(t,u={twMerge:!0,twMergeConfig:{}})=>e=>{var h;let{slots:s={},variants:b={},compoundVariants:g=[],defaultVariants:d={}}=t;if(b==null&&!m(s))return j(t==null?void 0:t.base,e==null?void 0:e.class,e==null?void 0:e.className)(u);if(g&&!Array.isArray(g))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof g}`);let x={base:t==null?void 0:t.base,...s},S=(r,n,f=[],i)=>{let a=f;if(typeof n=="string")a.push($(n).split(" ").map(c=>`${r}:${c}`));else if(Array.isArray(n))a.push(n.flatMap(c=>`${r}:${c}`));else if(typeof n=="object"&&typeof i=="string"){let c=n==null?void 0:n[i];if(c&&typeof c=="string"){let l=$(c);a[i]=a[i]?[...a[i],...l.split(" ").map(y=>`${r}:${y}`)]:l.split(" ").map(y=>`${r}:${y}`);}else Array.isArray(c)&&c.length>0&&(a[i]=c.flatMap(l=>`${r}:${l}`));}return a},o=(r,n=null)=>{let f=b==null?void 0:b[r];if(typeof f!="object"||!m(f))return null;let i=e==null?void 0:e[r],a=d==null?void 0:d[r],c=[];if(i===null)return null;let l=w(i);typeof l=="object"&&(c=Object.keys(l).reduce((A,M)=>{let N=l[M],I=f==null?void 0:f[N];return M==="initial"?(a=N,A):S(M,I,A,n)},[]));let y=f[l]||f[w(a)];return typeof c=="object"&&typeof n=="string"&&c[n]?E(c,y):c.length>0?[y,...c]:y},B=b?Object.keys(b).map(o):null,T=r=>!b||typeof b!="object"?null:Object.keys(b).map(n=>{let f=o(n,r);return r==="base"&&typeof f=="string"?f:f&&f[r]}).filter(Boolean),v=e&&Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0)),C=g==null?void 0:g.filter(({class:r,className:n,...f})=>Object.entries(f).every(([i,a])=>{var y;let c=typeof(e==null?void 0:e[i])=="object"?(y=e[i])==null?void 0:y.initial:{},l={...d,...c,...v};return Array.isArray(a)?a.includes(l[i]):l[i]===a})).flatMap(({class:r,className:n})=>[r,n]),F=()=>{let r=C;return Array.isArray(r)?r.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),{}):r};if(m(s)){let r=(h=F())!=null?h:[];return {...typeof x=="object"&&m(x)?Object.keys(x).reduce((f,i)=>(f[i]=a=>j(x[i],T(i),r==null?void 0:r[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,e==null?void 0:e.class,e==null?void 0:e.className)(u)}; | ||
export { H as tv }; | ||
export { D as tv }; |
@@ -1,16 +0,3 @@ | ||
import {CxOptions, CxReturn} from "class-variance-authority"; | ||
import {TVConfig} from "./config"; | ||
export declare const falsyToString: <T extends unknown>(value: T) => string | T; | ||
export declare const isNotEmptyObject: (obj: object) => boolean; | ||
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn; | ||
export declare const joinObjects: (obj1: object, obj2: object) => object; | ||
export declare const removeExtraSpaces: (str: string) => string; | ||
export declare type ClassPropKey = "class" | "className"; | ||
export declare type ClassValue = string | string[] | null | undefined; | ||
@@ -30,6 +17,14 @@ | ||
export declare type StringArrayToFunctions<T extends string[], Props = {}> = { | ||
[K in T[number]]: (props?: Props) => string; | ||
}; | ||
export type CxOptions = ClassValue[]; | ||
export declare type AddItemToArray<T extends unknown[], V> = [V, ...T]; | ||
export type CxReturn = string; | ||
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn; | ||
export declare const falsyToString: <T extends unknown>(value: T) => string | T; | ||
export declare const isNotEmptyObject: (obj: object) => boolean; | ||
export declare const joinObjects: (obj1: object, obj2: object) => object; | ||
export declare const removeExtraSpaces: (str: string) => string; |
{ | ||
"name": "tailwind-variants", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "🦄 Tailwindcss first-class variant API", | ||
@@ -37,3 +37,2 @@ "author": "Junior Garcia <jrgarciadev@gmail.com>", | ||
"dependencies": { | ||
"class-variance-authority": "0.4.0", | ||
"tailwind-merge": "^1.8.1" | ||
@@ -40,0 +39,0 @@ }, |
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
1
14820
123
- Removedclass-variance-authority@0.4.0
- Removedclass-variance-authority@0.4.0(transitive)