# @travpro/clsx

> Wraps clsx with automated BEM classname generation

Latest version **1.2.0** (published 2022-05-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @travpro/clsx
pnpm add @travpro/clsx
yarn add @travpro/clsx
bun add @travpro/clsx
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2022-05-20 |
| First published | 2021-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Imre |
| Maintainers | imrevschaijk |

## Links

- npm: https://www.npmjs.com/package/@travpro/clsx
- npm.io page: https://npm.io/package/@travpro/clsx

## Dependencies (1)

- [easy-bem](https://npm.io/package/easy-bem.md) ^1.1.1

## Recent versions

- 1.2.0 (latest) — 2022-05-20
- 1.1.0 — 2021-11-30
- 1.0.4 — 2021-09-15
- 1.0.3 — 2021-09-15
- 1.0.2 — 2021-09-15
- 1.0.1 — 2021-09-15
- 1.0.0 — 2021-06-08

## README

## useClassName

useClassName returns a function that generates correctly formatted class names.

### Benefits

Class names are more consistent and follow standard BEM methodology outlined [here](http://getbem.com/introduction/). Also having this functionality in the form of a hook/function allows easier implementation of dynamic class names

### Example usage (spread)

```jsx
import useClassName from '@travpro/clsx';

const Example = () => {
  const c = useClassName('example');

  return (
    <div {...c()}>
      <h1 {...c('header')}>Lorem Ipsum Dolor Sit</h1>

      <button {...c('button', { green: true })}>Lorem Ipsum</button>

      <p {...c('subtitle', { font: 'large' })}>Lorem Ipsum Dolor Sit Amet Consectetur</p>
    </div>
  );
};
```

**Output**

```html
<div class="example__wrapper">
  <h1 class="example__header">Lorem Ipsum Dolor Sit</h1>

  <button class="example__button--green">Lorem Ipsum</button>

  <p class="example__subtitle example__subtitle--font_large">Lorem Ipsum Dolor Sit Amet Consectetur</p>
</div>
```

### Example usage (prop)

```jsx
import useClassName from '@travpro/clsx/prop';

const Example = () => {
  const c = useClassName('example');

  return (
    <div className={c()}>
      <h1 className={c('header')}>Lorem Ipsum Dolor Sit</h1>

      <button className={c('button', { green: true })}>Lorem Ipsum</button>

      <p className={c('subtitle', { font: 'large' })}>Lorem Ipsum Dolor Sit Amet Consectetur</p>
    </div>
  );
};
```

**Output**

```html
<div class="example__wrapper">
  <h1 class="example__header">Lorem Ipsum Dolor Sit</h1>

  <button class="example__button--green">Lorem Ipsum</button>

  <p class="example__subtitle example__subtitle--font_large">Lorem Ipsum Dolor Sit Amet Consectetur</p>
</div>
```

---
_Source: https://npm.io/package/@travpro/clsx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
