Skip to content

Commit

Permalink
Roll-your-own unset (#191)
Browse files Browse the repository at this point in the history
feat: roll-your-own unset
  • Loading branch information
joe-bell committed Aug 12, 2023
1 parent a1f7f50 commit 7be180f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
28 changes: 25 additions & 3 deletions packages/cva/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,29 @@ For documentation, visit [cva.style](https://cva.style).
const after = cva({ base: "your-base-class" });
```

2. **Use `"unset"` to disable a variant completely**
2. **Roll-your-own `"unset"` to disable a variant completely**

Previously, passing `null` to a variant would provide the same behaviour – to match Stitches.js – however this caused some [concern and confusion](https://github.com/joe-bell/cva/discussions/97).
Previously, passing `null` to a variant would disable a variant completely – to match Stitches.js – however this caused some [concern and confusion](https://github.com/joe-bell/cva/discussions/97).

Instead, a more explicit `"unset"` option ([similar to the CSS keyword](https://developer.mozilla.org/en-US/docs/Web/CSS/unset)) is now available for use.
Instead, we recommend setting an explicit `"unset"` option ([similar to the CSS keyword](https://developer.mozilla.org/en-US/docs/Web/CSS/unset)) within your variant:

```ts
import { cva } from "cva";

const button = cva({
base: "button",
variants: {
intent: {
unset: null,
primary: "button--primary",
secondary: "button--secondary",
},
},
});

button({ intent: "unset" });
// => "button"
```

3. Utilize `swc` minification to improve bundlesize

Expand All @@ -61,6 +79,8 @@ For documentation, visit [cva.style](https://cva.style).
Builds a `cva` component

```ts
import { cva } from "cva";

const component = cva(options);
```

Expand All @@ -80,6 +100,8 @@ Generate `cx` and `cva` functions based on your preferred configuration.
Store in a `cva.config.ts` file, and import across your project.

```ts
import { cva } from "cva";

// cva.config.ts
export const { cva, cx } = defineConfig(options);
```
Expand Down
Loading

1 comment on commit 7be180f

@vercel
Copy link

@vercel vercel bot commented on 7be180f Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.