Skip to content

Commit

Permalink
feat: support the className prop
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-bell committed Nov 7, 2022
1 parent bb1bce6 commit b0899b9
Show file tree
Hide file tree
Showing 5 changed files with 642 additions and 31 deletions.
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ const button = cva(["font-semibold", "border", "rounded"], {
medium: ["text-base", "py-2", "px-4"],
},
},
compoundVariants: [{ intent: "primary", size: "medium", class: "uppercase" }],
compoundVariants: [
{
intent: "primary",
size: "medium",
class: "uppercase",
// **or** if you're a React.js user, `className` may feel more consistent:
// className: "uppercase"
},
],
defaultVariants: {
intent: "primary",
size: "medium",
Expand All @@ -151,7 +159,7 @@ button({ intent: "secondary", size: "small" });

### Additional Classes

All `cva` components provide an optional `class` prop, which can be used to pass additional classes to the component.
All `cva` components provide an optional `class` **or** `className` prop, which can be used to pass additional classes to the component.

```ts
// components/button.ts
Expand All @@ -161,6 +169,9 @@ const button = cva(/* … */);

button({ class: "m-4" });
// => "…buttonClasses m-4"

button({ className: "m-4" });
// => "…buttonClasses m-4"
```

### TypeScript
Expand Down Expand Up @@ -510,7 +521,7 @@ const button = cva(base, {
},
},
compoundVariants: [
{ intent: "primary", size: "medium", class: primaryMedium },
{ intent: "primary", size: "medium", className: primaryMedium },
],
defaultVariants: {
intent: "primary",
Expand All @@ -527,9 +538,7 @@ export const Button: React.FC<ButtonProps> = ({
intent,
size,
...props
}) => (
<button className={button({ intent, size, class: className })} {...props} />
);
}) => <button className={button({ intent, size, className })} {...props} />;
```

</details>
Expand Down Expand Up @@ -564,7 +573,9 @@ const button = cva("button", {
medium: ["text-base", "py-2", "px-4"],
},
},
compoundVariants: [{ intent: "primary", size: "medium", class: "uppercase" }],
compoundVariants: [
{ intent: "primary", size: "medium", className: "uppercase" },
],
defaultVariants: {
intent: "primary",
size: "medium",
Expand All @@ -580,9 +591,7 @@ export const Button: React.FC<ButtonProps> = ({
intent,
size,
...props
}) => (
<button className={button({ intent, size, class: className })} {...props} />
);
}) => <button className={button({ intent, size, className })} {...props} />;
```

</details>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b0899b9

Please sign in to comment.