Comparing version 0.0.3 to 0.1.0
@@ -41,6 +41,6 @@ "use strict"; | ||
} | ||
function cvax(base, config) { | ||
function cvax(config) { | ||
return (props)=>{ | ||
var _config_compoundVariants; | ||
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.className); | ||
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(config === null || config === void 0 ? void 0 : config.base, props === null || props === void 0 ? void 0 : props.className); | ||
const { variants , defaultVariants } = config; | ||
@@ -78,3 +78,3 @@ const getVariantClassNames = Object.keys(variants).map((variant)=>{ | ||
}, []); | ||
return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.className); | ||
return cx(config === null || config === void 0 ? void 0 : config.base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.className); | ||
}; | ||
@@ -85,2 +85,3 @@ } | ||
const new_ = getAbsentKeys(newVariants); | ||
const base = cn(baseVariants.base, newVariants.base); | ||
const variants = getVariants(base_.variants, new_.variants); | ||
@@ -90,2 +91,3 @@ const defaultVariants = getDefaultVariants(base_.defaultVariants, new_.defaultVariants); | ||
return { | ||
base, | ||
variants, | ||
@@ -114,2 +116,3 @@ defaultVariants, | ||
var _obj_variant; | ||
if (!(typeof obj !== "object")) throw new Error(`obj ${obj} is not an Object`); | ||
if (!(variant in obj)) Object.assign(obj, { | ||
@@ -116,0 +119,0 @@ [variant]: newVariants[variant] |
@@ -13,2 +13,3 @@ import type { ClassProp, ClassValue, CxOptions, CxReturn, OmitUndefined, StringToBoolean } from "./types"; | ||
type Config<T> = T extends ConfigSchema ? { | ||
base?: ClassValue; | ||
variants?: T; | ||
@@ -19,4 +20,5 @@ defaultVariants?: ConfigVariants<T>; | ||
type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp; | ||
export declare function cvax<T>(base?: ClassValue, config?: Config<T>): (props?: Props<T>) => string; | ||
export declare function cvax<T>(config: Config<T>): (props?: Props<T>) => string; | ||
export declare function mergeVariants<T, U>(baseVariants: Config<T>, newVariants: Config<U>): { | ||
base: string; | ||
variants: import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<[undefined] extends [import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<T, Function | Iterable<unknown>, object> | import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object>] ? never : import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<T, Function | Iterable<unknown>, object> extends infer T_1 ? T_1 extends import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<T, Function | Iterable<unknown>, object> ? T_1 extends import("type-fest/source/internal").UnknownRecord ? import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object> extends infer T_2 ? T_2 extends import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object> ? T_2 extends import("type-fest/source/internal").UnknownRecord ? import("type-fest/source/merge-deep").MergeDeepRecord<T_1, T_2, { | ||
@@ -23,0 +25,0 @@ arrayMergeMode: "replace"; |
@@ -21,6 +21,6 @@ import { twMerge } from "tailwind-merge"; | ||
} | ||
export function cvax(base, config) { | ||
export function cvax(config) { | ||
return (props)=>{ | ||
var _config_compoundVariants; | ||
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.className); | ||
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(config === null || config === void 0 ? void 0 : config.base, props === null || props === void 0 ? void 0 : props.className); | ||
const { variants , defaultVariants } = config; | ||
@@ -58,3 +58,3 @@ const getVariantClassNames = Object.keys(variants).map((variant)=>{ | ||
}, []); | ||
return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.className); | ||
return cx(config === null || config === void 0 ? void 0 : config.base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.className); | ||
}; | ||
@@ -66,2 +66,3 @@ } | ||
const new_ = getAbsentKeys(newVariants); | ||
const base = cn(baseVariants.base, newVariants.base); | ||
const variants = getVariants(base_.variants, new_.variants); | ||
@@ -71,2 +72,3 @@ const defaultVariants = getDefaultVariants(base_.defaultVariants, new_.defaultVariants); | ||
return { | ||
base, | ||
variants, | ||
@@ -95,2 +97,3 @@ defaultVariants, | ||
var _obj_variant; | ||
if (!(typeof obj !== "object")) throw new Error(`obj ${obj} is not an Object`); | ||
if (!(variant in obj)) Object.assign(obj, { | ||
@@ -97,0 +100,0 @@ [variant]: newVariants[variant] |
{ | ||
"name": "cvax", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Customized CVA. fork 'class-variance-authority'", | ||
@@ -27,3 +27,3 @@ "repository": "https://github.com/alexvyber/cvax.git", | ||
"test:vitest": "vitest", | ||
"test:size": "pnpm build && bundlesize -f 'dist/*.js' -s 1.6KB", | ||
"NO-test:size": "pnpm build && bundlesize -f 'dist/*.js' -s 1.6KB", | ||
"tsc": "tsc --project tsconfig.json --noEmit" | ||
@@ -43,3 +43,2 @@ }, | ||
"@types/react-dom": "18.0.11", | ||
"bundlesize": "0.18.1", | ||
"npm-run-all": "4.1.5", | ||
@@ -46,0 +45,0 @@ "react": "18.2.0", |
17015
12
319
6