Skip to content

Commit

Permalink
fix(react): allow additional defaultVariant string type
Browse files Browse the repository at this point in the history
Allows any string KV pair in defaultVariants

fixes: #144
  • Loading branch information
sannajammeh committed Jan 27, 2024
1 parent 11b2b77 commit 77d09d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ export interface ClassedFunctionType {
[Name in keyof Composers[K]["variants"]]?: Util.Widen<
keyof Composers[K]["variants"][Name]
>;
}
: {};
} & { [key: string]: string }
: {
[key: string]: string;
};

compoundVariants?: (("variants" extends keyof Composers[K]
? {
Expand Down Expand Up @@ -187,8 +189,8 @@ export interface ClassedProxyFunctionType<
[Name in keyof Composers[K]["variants"]]?: Util.Widen<
keyof Composers[K]["variants"][Name]
>;
}
: {};
} & { [key: string]: string }
: { [key: string]: string };

compoundVariants?: (("variants" extends keyof Composers[K]
? {
Expand Down
33 changes: 33 additions & 0 deletions packages/react/test/types.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,39 @@ test("It Should create a JSX Element", () => {
expectTypeOf(button).toMatchTypeOf<JSX.Element>();
});

test("It should allow for typings of composed variants", () => {
const Button = classed("button", {
defaultVariants: {
size: "default",
variant: "default",
},
variants: {
size: {
default: "...",
sm: "...",
},
variant: {
default: "...",
ghost: "...",
},
},
});

const Toggle = classed("div", Button, {
defaultVariants: {
size: "sm", // <-- ERROR HERE, see below
variant: "ghost",
},
variants: {
variant: {
// additional Toggle styles to be merged with Button styles
default: "...",
ghost: "...",
},
},
});
});

test("DerivedComponentType -> Should successfully infer the type of the component", () => {
const InnerButton = classed("button", {
variants: {
Expand Down

0 comments on commit 77d09d4

Please sign in to comment.