Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tailwind-variants

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tailwind-variants - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

48

dist/index.d.ts
import {TVConfig} from "./config";
import {ClassValue, ClassProp, OmitUndefined, StringToBoolean, AddItemToArray} from "./utils";
import {ClassValue, ClassProp, OmitUndefined, StringToBoolean} from "./utils";
type TVDefaultSlot = "";
type TVBaseName = "base";
type SlotsWithBase<S extends string[]> = AddItemToArray<S, TVBaseName>;
type TVSlots = Record<string, ClassValue> | undefined;
type SlotsClassValue<S extends string[]> = {
[K in SlotsWithBase<S>[number]]: ClassValue;
type SlotsClassValue<S extends TVSlots> = {
[K in keyof S]?: ClassValue;
};
export declare type TVVariants<S extends string[]> = {
export type TVVariants<S extends TVSlots> = {
[key: string]: {
[key: string]: S extends TVDefaultSlot ? ClassValue : SlotsClassValue<S> | ClassValue;
[key: string]: S extends TVSlots ? SlotsClassValue<S> | ClassValue : ClassValue;
};
};
export declare type TVCompoundVariants<V extends TVVariants<S>, S extends string[]> = Array<
export type TVCompoundVariants<V extends TVVariants<S>, S extends TVSlots> = Array<
{
[K in keyof V]?: StringToBoolean<keyof V[K]>;
[K in keyof V]?: StringToBoolean<keyof V[K]> | StringToBoolean<keyof V[K]>[];
} & ClassProp<SlotsClassValue<S> | ClassValue>
>;
export declare type TVDefaultVariants<V extends TVVariants<S>, S extends string[]> = {
export type TVDefaultVariants<V extends TVVariants<S>, S extends TVSlots> = {
[K in keyof V]?: StringToBoolean<keyof V[K]>;
};
export declare type TVProps<V extends TVVariants<S>, S extends string[]> = {
export type TVProps<V extends TVVariants<S>, S extends TVSlots> = {
[K in keyof V]?: StringToBoolean<keyof V[K]>;
} & ClassProp;
export declare type TVReturnType<V extends TVVariants<S>, S extends string> = (
props?: TVProps<V, S[]>,
) => S extends TVDefaultSlot
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = (
props?: TVProps<V, S>,
) => S extends undefined
? string
: {
[K in SlotsWithBase<S[]>[number]]: (props?: ClassProp) => string;
[K in B extends undefined ? keyof S : keyof S | TVBaseName]: (
slotProps?: ClassProp,
) => string;
};
export declare function tv<
V extends TVVariants<S[]>,
DV extends TVDefaultVariants<V, S[]>,
CV extends TVCompoundVariants<V, S[]>,
export function tv<
DV extends TVDefaultVariants<V, S>,
CV extends TVCompoundVariants<V, S>,
C extends TVConfig,
S extends string = TVDefaultSlot,
V extends TVVariants<S>,
B extends ClassValue = undefined,
S extends TVSlots = undefined,
>(
options: {
base?: ClassValue;
slots?: S[];
base?: B;
slots?: S;
variants?: V;

@@ -56,3 +58,3 @@ compoundVariants?: CV;

config?: C,
): TVReturnType<V, S>;
): TVReturnType<V, S, B>;

@@ -59,0 +61,0 @@ export type VariantProps<Component extends (...args: any) => any> = Omit<

import { cx } from 'class-variance-authority';
import { extendTailwindMerge, twMerge } from 'tailwind-merge';
var O=e=>{var i;return (i=e==null?void 0:e.filter)==null?void 0:i.call(e,n=>n&&String(n).match(/^[\w\s]*$/))},o=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,D=e=>e&&Object.keys(e).length>0,f=(...e)=>(i={})=>i.twMerge?(D(i.twMergeConfig)?extendTailwindMerge(i.twMergeConfig):twMerge)(cx(e)):cx(e),S=e=>Array.from(new Set(e));var K=(e,i={twMerge:!0,twMergeConfig:{}})=>n=>{var j,V;if((e==null?void 0:e.variants)==null)return f(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(i);let{slots:d=[],variants:g,defaultVariants:b}=e,w=Array.isArray(d)?S(["base",...d]):[],x=t=>{let r=n==null?void 0:n[t],a=b==null?void 0:b[t];if(r===null)return null;let u=o(r)||o(a);return g[t][u]},h=Object.keys(g).map(x),C=t=>Object.keys(g).map(r=>{let a=x(r);return !a||typeof a!="object"?null:a[t]}),M=n&&Object.entries(n).reduce((t,[r,a])=>(a===void 0||(t[r]=a),t),{}),A=(j=e==null?void 0:e.compoundVariants)==null?void 0:j.reduce((t,{class:r,className:a,...u})=>Object.entries(u).every(([m,c])=>Array.isArray(c)?c.includes({...b,...M}[m]):{...b,...M}[m]===c)?[...t,r,a]:t,[]),B=()=>{let t=O(A);return Array.isArray(t)?t.reduce((r,a)=>(typeof a=="string"&&(r.base=f(r.base,a)(i)),typeof a=="object"&&Object.entries(a).forEach(([u,m])=>{r[u]=f(r[u],m)(i);}),r),{}):t};if(w.length>1){let t=C("base"),r=(V=B())!=null?V:[];return {...w.reduce((u,m)=>(u[m]=c=>f(m==="base"?[e==null?void 0:e.base,t]:[],C(m),r==null?void 0:r[m],c==null?void 0:c.class,c==null?void 0:c.className)(i),u),{})}}return f(e==null?void 0:e.base,h,A,n==null?void 0:n.class,n==null?void 0:n.className)(i)};
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)};
export { K as tv };
export { R as tv };

@@ -9,2 +9,4 @@ import {CxOptions, CxReturn} from "class-variance-authority";

export declare const isNotEmptyObject: (obj: object) => boolean;
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;

@@ -11,0 +13,0 @@

{
"name": "tailwind-variants",
"version": "0.0.8",
"version": "0.0.9",
"description": "🦄 Tailwindcss first-class variant API",

@@ -64,2 +64,3 @@ "author": "Junior Garcia <jrgarciadev@gmail.com>",

"prettier-eslint-cli": "^5.0.1",
"jest": "28.1.1",
"ts-node": "^10.9.1",

@@ -66,0 +67,0 @@ "tslib": "^2.4.1",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc