@tw-classed/core
Advanced tools
Comparing version 1.0.0-alpha.3 to 1.0.0
@@ -1,3 +0,4 @@ | ||
import { ClassedProducer, ClassNamesAndVariant, Variants } from "./types"; | ||
export default function classed<V extends Variants = {}>(...classNames: Array<ClassNamesAndVariant<V> | ClassedProducer<V>>): ClassedProducer<V>; | ||
import { ClassedCoreFunctionType } from "./types"; | ||
declare const classed: ClassedCoreFunctionType; | ||
export { classed }; | ||
//# sourceMappingURL=classed.d.ts.map |
@@ -1,4 +0,5 @@ | ||
export { default } from "./classed"; | ||
export * from "./classed"; | ||
export * from "./types"; | ||
export * from "./parser"; | ||
export { TW_VARS } from "./constants"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,1 +1,2 @@ | ||
const TW_VARS = Symbol.for("tw-classed.vars"); | ||
const joinClasses = (classNames) => classNames.join(" "); | ||
@@ -22,6 +23,13 @@ const mergeClass = (c1, c2) => { | ||
} | ||
if (Reflect.has(className, TW_VARS)) { | ||
const record = Reflect.get(className, TW_VARS); | ||
Object.assign(variantObj, record.variants); | ||
Object.assign(defaultVariants, record.defaultVariants); | ||
stringClassNames.push(record.className); | ||
continue; | ||
} | ||
if (className.variants) { | ||
Object.assign(variantObj, className.variants); | ||
} | ||
if (className.defaultVariants) { | ||
if (defaultVariants) { | ||
Object.assign(defaultVariants, className.defaultVariants); | ||
@@ -71,3 +79,3 @@ } | ||
}; | ||
function classed(...classNames) { | ||
const classed = (...classNames) => { | ||
const { className, variants, defaultVariants } = parseClassNames(classNames); | ||
@@ -81,7 +89,12 @@ const producer = (variantProps) => { | ||
}; | ||
producer.variants = variants; | ||
Reflect.set(producer, TW_VARS, { | ||
className, | ||
variants, | ||
defaultVariants | ||
}); | ||
return producer; | ||
} | ||
}; | ||
export { | ||
classed as default, | ||
TW_VARS, | ||
classed, | ||
getVariantSelector, | ||
@@ -88,0 +101,0 @@ mapPropsToVariantClass, |
import { ClassNamesAndVariant, InferVariantProps, VariantConfig, Variants } from "./types"; | ||
export declare const parseClassNames: <TVariants extends Variants>(classNames: ClassNamesAndVariant<TVariants>[]) => { | ||
export declare const parseClassNames: <TVariants extends Variants>(classNames: any[]) => { | ||
className: string; | ||
@@ -4,0 +4,0 @@ variants: TVariants; |
@@ -1,2 +0,2 @@ | ||
export declare type ClassNames = string; | ||
import type * as Util from "./util"; | ||
export declare type Variant = Record<string, string>; | ||
@@ -7,3 +7,3 @@ export declare type Variants = Record<string, Variant>; | ||
variants?: V; | ||
className?: ClassNames; | ||
className?: string; | ||
defaultVariants?: Partial<{ | ||
@@ -15,5 +15,6 @@ [K in keyof V]: keyof V[K]; | ||
export declare type ClassedProducer<V extends Variants = {}> = ((variantProps: InferVariantProps<V>) => any) & { | ||
variants: V; | ||
_def: { | ||
_variants: V; | ||
className?: string; | ||
variants?: V; | ||
defaultVariants?: unknown; | ||
}; | ||
@@ -24,2 +25,38 @@ }; | ||
}> : {}; | ||
interface ClassedCreator<Props extends {} = {}> { | ||
(variantProps?: Props): string; | ||
} | ||
export interface ClassedType<Props extends {} = {}, TComposedVariants extends {} = {}> extends ClassedCreator<Props> { | ||
[$$ClassedProps]: Props; | ||
[$$ClassedVariants]: TComposedVariants; | ||
} | ||
export declare const $$ClassedProps: unique symbol; | ||
export declare type $$ClassedProps = typeof $$ClassedProps; | ||
export declare const $$ClassedVariants: unique symbol; | ||
export declare type $$ClassedVariants = typeof $$ClassedVariants; | ||
export declare type ClassedProps<T extends any[]> = ($$ClassedProps extends keyof T[0] ? T[0][$$ClassedProps] : T[0] extends { | ||
variants: { | ||
[name: string]: unknown; | ||
}; | ||
} ? InferVariantProps<T[0]["variants"]> : {}) & (T extends [lead: any, ...tail: infer V] ? ClassedProps<V> : {}); | ||
export declare type ClassedVariants<T extends any[]> = ($$ClassedVariants extends keyof T[0] ? T[0][$$ClassedVariants] : T[0] extends { | ||
variants: { | ||
[name: string]: unknown; | ||
}; | ||
} ? Pick<T[0], "variants" | "defaultVariants"> : {}) & (T extends [lead: any, ...tail: infer V] ? ClassedVariants<V> : {}); | ||
export interface ClassedCoreFunctionType { | ||
<Composers extends (string | Util.Function | { | ||
variants?: { | ||
[name: string]: unknown; | ||
}; | ||
})[]>(...composers: { | ||
[K in keyof Composers]: string extends Composers[K] ? Composers[K] : Composers[K] extends string | Util.Function ? Composers[K] : { | ||
variants: Variants; | ||
defaultVariants?: "variants" extends keyof Composers[K] ? { | ||
[Name in keyof Composers[K]["variants"]]?: keyof Composers[K]["variants"][Name]; | ||
} : never; | ||
}; | ||
}): ClassedType<ClassedProps<Composers>, ClassedVariants<Composers>>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@tw-classed/core", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0", | ||
"description": "A Stitches & Styled-Components inspired library to create reusable Tailwind react components", | ||
@@ -19,10 +19,2 @@ "type": "module", | ||
}, | ||
"scripts": { | ||
"dev": "vite build --watch", | ||
"build": "rimraf ./dist && vite build", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:ui": "vitest --ui", | ||
"test:coverage": "vitest run --coverage" | ||
}, | ||
"keywords": [], | ||
@@ -47,3 +39,11 @@ "author": "Sanna Jammeh", | ||
"vitest": "^0.25.1" | ||
}, | ||
"scripts": { | ||
"dev": "vite build --watch", | ||
"build": "rimraf ./dist && vite build", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:ui": "vitest --ui", | ||
"test:coverage": "vitest run --coverage" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16871
17
281
0