Skip to content

Commit

Permalink
docs: add class composition section
Browse files Browse the repository at this point in the history
  • Loading branch information
wagerfield committed Aug 7, 2023
1 parent 589425e commit 2f3cdc0
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Workflow Status](https://img.shields.io/github/actions/workflow/status/wagerfield/onno/test.yml?style=flat-square&logo=github&logoColor=FFF&color=4C8)][workflow]
[![License](https://img.shields.io/github/license/wagerfield/onno?style=flat-square&color=4C8)][license]

Tiny ([596B][bundlephobia-onno]) utility for composing class variants using `clsx`
Tiny ([266B][bundlephobia-onno]) utility for composing class variants using `clsx`

pnpm add onno

Expand Down Expand Up @@ -173,7 +173,7 @@ button({ className: "with more" }) // "solid base with more"
button({ className: "with more", size: "sm" }) // "solid base pretty small with more"
```

### Class Order
### Class Composition

Classes are applied in the following order:

Expand All @@ -182,6 +182,42 @@ Classes are applied in the following order:
3. `compound`
4. `className`

Under the hood `onno` uses `clsx` to build the class list.

For convenience `clsx` is exported from `onno` so you can use it to compose classes:

```js
import { onno, clsx } from "onno"

const button = onno({
variants: {
size: {
sm: "pretty small",
lg: "really large",
},
},
})

clsx("foo", ["bar", { baz: true }], button({ size: "sm" })) // "foo bar baz pretty small"
```

Note that onno's `className` option also accepts any `clsx.ClassValue` ([see docs][clsx]) so you can do:

```js
import { onno, clsx } from "onno"

const button = onno({
variants: {
size: {
sm: "pretty small",
lg: "really large",
},
},
})

button({ size: "lg", className: ["foo", ["bar"], { baz: true }] }) // "really large foo bar baz"
```

## TypeScript

Use `OnnoProps` to infer variant props from an `OnnoFunction`
Expand Down Expand Up @@ -241,10 +277,11 @@ Todo

## License

[MIT][license] © [Matthew Wagerfield][wagerfield]
[MIT][license] © [Matthew Wagerfield][github]

[onno]: https://onnojs.com
[wagerfield]: https://github.com/wagerfield
[onno]: https://github.com/wagerfield/onno#readme
[clsx]: https://github.com/lukeed/clsx#readme
[github]: https://github.com/wagerfield
[codecov]: https://codecov.io/gh/wagerfield/onno
[license]: https://github.com/wagerfield/onno/blob/main/license
[workflow]: https://github.com/wagerfield/onno/actions/workflows/test.yml
Expand Down

0 comments on commit 2f3cdc0

Please sign in to comment.