Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function isSlotAwareValue(value: unknown): value is SlotAwareObject {
}

function addSlotClasses(
slotParts: Record<string, ClassValue[]>,
slotParts: Record<string, ClassValue[] | undefined>,
slots: Record<string, ClassValue>,
): void {
for (const [slotName, slotClasses] of Object.entries(slots)) {
Expand All @@ -174,7 +174,7 @@ function addSlotClasses(
function processTraits<TTraits extends Record<string, SlotAwareValue>>(
traits: TTraits,
propsTraits?: Props<{}, TTraits>["traits"],
slotParts?: Record<string, ClassValue[]>,
slotParts?: Record<string, ClassValue[] | undefined>,
): ClassValue[] {
if (!propsTraits) return [];

Expand Down Expand Up @@ -268,6 +268,8 @@ export function windctrl<
): (
props?: Props<TVariants, TTraits, TDynamic>,
) => Result<SlotKeys<typeof config.base, TVariants, TTraits>> {
type TSlotKeys = SlotKeys<typeof config.base, TVariants, TTraits>;

const {
base,
variants = {} as TVariants,
Expand All @@ -290,7 +292,7 @@ export function windctrl<
return (props = {} as Props<TVariants, TTraits, TDynamic>) => {
const classNameParts: ClassValue[] = [];
let mergedStyle: CSSProperties = {};
const slotParts: Record<string, ClassValue[]> = {};
const slotParts: Partial<Record<TSlotKeys, ClassValue[]>> = {};

// Priority order: Base < Variants < Traits < Dynamic
// (Higher priority classes are added later, so tailwind-merge will keep them)
Expand Down Expand Up @@ -353,26 +355,32 @@ export function windctrl<

const hasStyle = Object.keys(mergedStyle).length > 0;

let finalSlots: Record<string, string> | undefined;
const slotNames = Object.keys(slotParts);
let finalSlots: Partial<Record<TSlotKeys, string>> | undefined;

const slotNames = Object.keys(slotParts) as TSlotKeys[];
if (slotNames.length > 0) {
finalSlots = {};
const out: Partial<Record<TSlotKeys, string>> = {};

for (const slotName of slotNames) {
const merged = twMerge(clsx(slotParts[slotName]));
const parts = slotParts[slotName];
if (!parts) continue;

const merged = twMerge(clsx(parts));
if (merged) {
finalSlots[slotName] = merged;
out[slotName] = merged;
}
}
if (Object.keys(finalSlots).length === 0) {
finalSlots = undefined;

if (Object.keys(out).length > 0) {
finalSlots = out;
}
}

return {
className: finalClassName,
...(hasStyle && { style: mergedStyle }),
...(finalSlots && { slots: finalSlots }),
} as Result<SlotKeys<typeof config.base, TVariants, TTraits>>;
};
};
}

Expand Down