Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
41 changes: 39 additions & 2 deletions packages/core/system-rsc/__tests__/extend-variants.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ExtendVariantProps} from "../src/extend-variants";
import type {ExtendVariantProps, ExtendVariantWithSlotsProps} from "../src/extend-variants";

import React from "react";
import {render, screen} from "@testing-library/react";
Expand Down Expand Up @@ -37,7 +37,7 @@ const createExtendNoSlotsComponent = (styles: ExtendVariantProps = {}) =>
],
});

const createExtendSlotsComponent = () =>
const createExtendSlotsComponent = (styles: ExtendVariantWithSlotsProps = {}) =>
extendVariants(Card, {
variants: {
shadow: {
Expand Down Expand Up @@ -73,6 +73,13 @@ const createExtendSlotsComponent = () =>
shadow: "xl",
radius: "xl",
},
compoundVariants: styles?.compoundVariants ?? [
{
shadow: "none",
radius: "md",
class: "scale-150",
},
],
});

describe("extendVariants function - no slots", () => {
Expand Down Expand Up @@ -253,4 +260,34 @@ describe("extendVariants function - with slots", () => {
expect(baseEl).toHaveClass("shadow-xs");
expect(headerEl).toHaveClass("rounded-none");
});

test("should include the compound variant styles - original", () => {
const Card2 = createExtendSlotsComponent({
compoundVariants: [
{
shadow: "none",
radius: "md",
class: "scale-150",
},
{
radius: "md",
class: {
header: "rounded-xl",
},
},
],
});

const {getByTestId} = render(
<Card2 radius="md" shadow="none">
Card Content
</Card2>,
);

const baseEl = getByTestId("base");
const headerEl = getByTestId("header");

expect(baseEl).toHaveClass("scale-150");
expect(headerEl).toHaveClass("rounded-xl");
});
});
16 changes: 9 additions & 7 deletions packages/core/system-rsc/src/extend-variants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ type VariantValue<V, SV> = {

type DefaultVariants<V, SV> = VariantValue<V, SV>;

type CompoundVariants<V, SV> = Array<VariantValue<V, SV> & ClassProp<ClassValue>>;
type CompoundVariants<V, SV, S> = Array<
VariantValue<V, SV> & ClassProp<ClassValue | GetSuggestedValues<S>>
>;

type Options = {
/**
Expand Down Expand Up @@ -92,7 +94,7 @@ export type ExtendVariants = {
V extends ComposeVariants<CP, S>,
SV extends SuggestedVariants<CP, S>,
DV extends DefaultVariants<V, SV>,
CV extends CompoundVariants<V, SV>,
CV extends CompoundVariants<V, SV, ComponentSlots<CP>>,
>(
BaseComponent: C,
styles: {
Expand All @@ -103,11 +105,11 @@ export type ExtendVariants = {
},
opts?: Options,
): ForwardRefExoticComponent<
PropsWithoutRef<
CP & {
[key in keyof V]?: StringToBoolean<keyof V[key]>;
}
> &
PropsWithoutRef<{
[key in keyof CP | keyof V]?:
| (key extends keyof CP ? CP[key] : never)
| (key extends keyof V ? StringToBoolean<keyof NonNullable<V[key]>> : never);
}> &
RefAttributes<InferRef<C>>
>;
};
Expand Down
Loading