Comparing version 0.1.4 to 0.1.5
@@ -5,17 +5,9 @@ "use strict"; | ||
}); | ||
function _export(target, all) { | ||
for(var name in all)Object.defineProperty(target, name, { | ||
enumerable: true, | ||
get: all[name] | ||
}); | ||
} | ||
_export(exports, { | ||
cx: ()=>cx, | ||
cn: ()=>cn, | ||
cvax: ()=>cvax, | ||
mergeVariants: ()=>mergeVariants | ||
}); | ||
const _tailwindMerge = require("tailwind-merge"); | ||
const _lodashIsequal = /*#__PURE__*/ _interopRequireDefault(require("lodash.isequal" // FIXME: find the way to not to use lodash | ||
)); | ||
exports.cx = cx; | ||
exports.cn = cn; | ||
exports.cvax = cvax; | ||
exports.mergeVariants = mergeVariants; | ||
var _tailwindMerge = require("tailwind-merge"); | ||
var _lodashIsequal // FIXME: find the way to not to use lodash | ||
= _interopRequireDefault(require("lodash.isequal")); | ||
function _interopRequireDefault(obj) { | ||
@@ -27,3 +19,3 @@ return obj && obj.__esModule ? obj : { | ||
function falsyToString(value) { | ||
return typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value; | ||
return typeof value === "boolean" ? "".concat(value) : value === 0 ? "0" : value; | ||
} | ||
@@ -41,7 +33,7 @@ function cx() { | ||
} | ||
return (0, _tailwindMerge.twMerge)(cx(inputs)); | ||
return (0, _tailwindMerge).twMerge(cx(inputs)); | ||
} | ||
function cvax(config) { | ||
return (props)=>{ | ||
var _config_compoundVariants; | ||
var ref; | ||
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); | ||
@@ -64,4 +56,4 @@ const { variants , defaultVariants } = config; | ||
}, {}); | ||
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param; | ||
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param1; | ||
return Object.entries(compoundVariantOptions).every((param)=>{ | ||
@@ -115,4 +107,4 @@ let [key, value] = param; | ||
return Object.keys(value).map((key)=>{ | ||
var _obj_variant; | ||
if (!(typeof obj !== "object")) throw new Error(`obj ${obj} is not an Object`); | ||
var ref; | ||
if (!(typeof obj !== "object")) throw new Error("obj ".concat(obj, " is not an Object")); | ||
if (!(variant in obj)) Object.assign(obj, { | ||
@@ -122,3 +114,3 @@ [variant]: newVariants[variant] | ||
Object.assign(obj[variant], { | ||
[key]: cn(obj === null || obj === void 0 ? void 0 : (_obj_variant = obj[variant]) === null || _obj_variant === void 0 ? void 0 : _obj_variant[key], value[key]) | ||
[key]: cn(obj === null || obj === void 0 ? void 0 : (ref = obj[variant]) === null || ref === void 0 ? void 0 : ref[key], value[key]) | ||
}); | ||
@@ -148,3 +140,3 @@ }); | ||
const { className , ...ArrRest } = arr[i]; | ||
if ((0, _lodashIsequal.default)(rest, ArrRest)) markArr[i] = null; | ||
if ((0, _lodashIsequal).default(rest, ArrRest)) markArr[i] = null; | ||
} | ||
@@ -155,1 +147,3 @@ } | ||
//# sourceMappingURL=index.cjs.js.map |
import type { ClassProp, ClassValue, CxOptions, CxReturn, OmitUndefined, StringToBoolean } from "./types"; | ||
export type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "className">; | ||
export declare type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "className">; | ||
export declare function cx<T extends CxOptions>(...classes: T): CxReturn; | ||
export declare function cn(...inputs: ClassValue[]): string; | ||
type ConfigSchema = Record<string, Record<string, ClassValue>>; | ||
type ConfigVariants<T extends ConfigSchema> = { | ||
declare type ConfigSchema = Record<string, Record<string, ClassValue>>; | ||
declare type ConfigVariants<T extends ConfigSchema> = { | ||
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null; | ||
}; | ||
type ConfigVariantsMulti<T extends ConfigSchema> = { | ||
declare type ConfigVariantsMulti<T extends ConfigSchema> = { | ||
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[]; | ||
}; | ||
type Config<T> = T extends ConfigSchema ? { | ||
declare type Config<T> = T extends ConfigSchema ? { | ||
base?: ClassValue; | ||
@@ -18,3 +18,3 @@ variants?: T; | ||
} : never; | ||
type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp; | ||
declare type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp; | ||
export declare function cvax<T>(config: Config<T>): (props?: Props<T>) => string; | ||
@@ -21,0 +21,0 @@ export declare function mergeVariants<T, U>(baseVariants: Config<T>, newVariants: Config<U>): { |
import { twMerge } from "tailwind-merge"; | ||
import isEqual from "lodash.isequal"; // FIXME: find the way to not to use lodash | ||
function falsyToString(value) { | ||
return typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value; | ||
return typeof value === "boolean" ? "".concat(value) : value === 0 ? "0" : value; | ||
} | ||
@@ -23,3 +23,3 @@ /* cx | ||
return (props)=>{ | ||
var _config_compoundVariants; | ||
var ref; | ||
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); | ||
@@ -42,4 +42,4 @@ const { variants , defaultVariants } = config; | ||
}, {}); | ||
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param; | ||
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param1; | ||
return Object.entries(compoundVariantOptions).every((param)=>{ | ||
@@ -94,4 +94,4 @@ let [key, value] = param; | ||
return Object.keys(value).map((key)=>{ | ||
var _obj_variant; | ||
if (!(typeof obj !== "object")) throw new Error(`obj ${obj} is not an Object`); | ||
var ref; | ||
if (!(typeof obj !== "object")) throw new Error("obj ".concat(obj, " is not an Object")); | ||
if (!(variant in obj)) Object.assign(obj, { | ||
@@ -101,3 +101,3 @@ [variant]: newVariants[variant] | ||
Object.assign(obj[variant], { | ||
[key]: cn(obj === null || obj === void 0 ? void 0 : (_obj_variant = obj[variant]) === null || _obj_variant === void 0 ? void 0 : _obj_variant[key], value[key]) | ||
[key]: cn(obj === null || obj === void 0 ? void 0 : (ref = obj[variant]) === null || ref === void 0 ? void 0 : ref[key], value[key]) | ||
}); | ||
@@ -133,1 +133,3 @@ }); | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,4 +0,4 @@ | ||
export type ClassPropKey = "className"; | ||
export type ClassValue = string | null | undefined | readonly ClassValue[]; | ||
export type ClassProp = { | ||
export declare type ClassPropKey = "className"; | ||
export declare type ClassValue = string | null | undefined | readonly ClassValue[]; | ||
export declare type ClassProp = { | ||
className: ClassValue; | ||
@@ -8,5 +8,5 @@ } | { | ||
}; | ||
export type OmitUndefined<T> = T extends undefined ? never : T; | ||
export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T; | ||
export type CxOptions = ClassValue[]; | ||
export type CxReturn = string; | ||
export declare type OmitUndefined<T> = T extends undefined ? never : T; | ||
export declare type StringToBoolean<T> = T extends "true" | "false" ? boolean : T; | ||
export declare type CxOptions = ClassValue[]; | ||
export declare type CxReturn = string; |
{ | ||
"name": "cvax", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Customized CVA. fork 'class-variance-authority'", | ||
@@ -12,3 +12,3 @@ "repository": "https://github.com/alexvyber/cvax.git", | ||
"module": "dist/index.esm.js", | ||
"typings": "dist/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
@@ -39,13 +39,14 @@ "dist/*.js", | ||
"devDependencies": { | ||
"@swc/cli": "0.1.62", | ||
"@swc/core": "1.3.36", | ||
"@swc/cli": "0.1.57", | ||
"@swc/core": "1.2.198", | ||
"@types/lodash.isequal": "^4.5.6", | ||
"@types/node": "18.14.1", | ||
"@types/react": "18.0.28", | ||
"@types/react-dom": "18.0.11", | ||
"@types/node": "18.11.18", | ||
"@types/react": "18.0.12", | ||
"@types/react-dom": "18.0.5", | ||
"jest": "28.1.1", | ||
"npm-run-all": "4.1.5", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "^4.9.5", | ||
"ts-node": "10.8.1", | ||
"typescript": "4.7.3", | ||
"vitest": "^0.29.1" | ||
@@ -52,0 +53,0 @@ }, |
16999
13
311