5.0.5 • Published 1 year ago

classcat v5.0.5

Weekly downloads
31,510
License
MIT
Repository
github
Last release
1 year ago

Classcat

Build a class attribute string quickly.

  • Framework agnostic, reusable, plain vanilla JavaScript.
  • Up to 2.5x faster than alternatives.
  • 217 B (minified+gzipped). 👌

This module makes it easy to build a space-delimited class attribute string from an object or array of CSS class names. Just pair each class with a boolean value to add or remove them conditionally.

import cc from "classcat"

export const ToggleButton = ({ isOn, toggle }) => (
  <div className="btn" onClick={() => toggle(!isOn)}>
    <div
      className={cc({
        circle: true,
        off: !isOn,
        on: isOn,
      })}
    />
    <span className={cc({ textOff: !isOn })}>{isOn ? "ON" : "OFF"}</span>
  </div>
)

Try with React, lit-html, Mithril, Superfine

Installation

npm install classcat

Or without a build step—import it right in your browser.

<script type="module">
  import cc from "https://unpkg.com/classcat"
</script>

API

cc(names)

cc(names: string | number | object | array): string
import cc from "classcat"

cc("elf") //=> "elf"

cc(["elf", "orc", "gnome"]) //=> "elf orc gnome"

cc({
  elf: false,
  orc: null,
  gnome: undefined,
}) //=> ""

cc({
  elf: true,
  orc: false,
  gnome: true,
}) //=> "elf gnome"

cc([
  {
    elf: true,
    orc: false,
  },
  "gnome",
]) //=> "elf gnome"

Benchmarks

npm --prefix bench start

License

MIT

democensafractures-uigray-react-tools@appist/app-btn@appist/app-iconreact-flow-dnd@walkme/wm-ui@stellaris/lynxmodalo@sec-ant/react-flow-renderercensapackagedesignsystemindesigndocumentabcdesignabcsystempackagestorypackagedesign@everything-registry/sub-chunk-1332week-scheduleweek-scheduler-reactsunshine-react-flow@dmn-arc-core-components/feature_article-body@copart/core-components@namehash/react@ambroseus/react-flow-renderer@apitable/react-flow@arc-core-components/feature_article-body@antender/thisisfine@bharatpatil/background@bharatpatil/controls@bharatpatil/core@bharatpatil/minimap@bharatpatil/node-resizer@bharatpatil/node-toolbar@cbinsights/fds@easyv/react-flow-renderer@havlasme/react-cookie-consent@forabi/react-week-scheduler@indexnetwork/ui@mpen/jsxhtml@matejmazur/react-table-form@namehash/nameguard-react@namehash/namekit-react@narmi/design_system@nodeject/ui-components@matthewgapp/solidjs-flow@mo-fang/materials@kinark/react-flow-renderer@kiroboio/minimap@kiroboio/node-resizer@kiroboio/node-toolbar@kiroboio/background@kiroboio/controls@kiroboio/core@jhqn/react-flow-renderer@moretall/react-flow-nns@ohmunity/verification-code@rctflw/background@rctflw/controls@rctflw/core@rctflw/minimap@product-hackers/feature_article-body@r-4bb1t/rabbit-ui@saravntbe/react-flow-renderer-umd@reactflow/controls@reactflow/core@reactflow/minimap@reactflow/node-resizer@reactflow/node-toolbar@reactflowfork/background@reactflowfork/controls@reactflowfork/core@reactflowfork/minimap@reactflow/background@reactflowfork/node-resizer@reactflowfork/node-toolbar@openfn/workflow-diagram@remotelock/react-week-scheduler@revityactive/react-week-schedulermoppium-react-flow-rendereropsportal-corereact-cosmos-diagramreact-awesome-daterdf-rendererreact-flow-nnsreact-flow-rendererreact-flow-renderer-gdreact-flow-renderer-nnsreact-flow-renderer-pathfinderreact-flow-rendererv10react-flow-vunet-newreact-flowyreact-flow-renderer-silvacppreact-flow-renderer2network-policy-viewerrewire-gridrewire-uireact-revised-week-schedulerreact-sample-component-by-yshrknreactflow-velocity
5.0.5

1 year ago

5.0.4

3 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.1.0

5 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.2.5

6 years ago

3.2.4

6 years ago

3.2.3

7 years ago

3.2.2

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago