内容简介:Build a space-separatedDon't want to set up a build step? Import it inside aClasscat takes an array of strings or name-value object and joins all the
Classcat
Build a space-separated class attribute quickly.
- Easily add and remove class names based on a truthy or falsy value.
- Works best when paired with a view framework. which will it be?
- Ridiculously tiny at 260B . No dependencies.
Quickstart
npm i classcat
Don't want to set up a build step? Import it inside a <script>
tag as a module. Don't worry; modules are supported in all evergreen, self-updating desktop, and mobile browsers.
<script type="module"> import cc from "https://unpkg.com/classcat" </script>
Classcat takes an array of strings or name-value object and joins all the truthy values into a space-separated string. Arrays may be nested too. That's really all there is to it. Here's the first example to get you started.
import cc from "classcat" export const ToggleButton = ({ isOn }) => ( <div> <div class={cc({ circle: true, off: !isOn, on: isOn, })} /> <span class={cc({ textOff: !isOn })}>{isOn ? "ON" : "OFF"}</span> </div> )
API
cc(string | number | object | array)
import cc from "classcat" cc("foo") //=> "foo" cc(["foo", "bar", "baz"]) //=> "foo bar baz" cc({ foo: false, bar: null, baz: undefined }) //=> "" cc({ foo: true, bar: false, baz: true }) //=> "foo baz" cc([{ foo: true, bar: false }, "baz"]) //=> "foo baz"
Run the benchmarks
npm run build && npm i -C bench && npm -C bench start
# Strings classcat × 15,927,163 ops/sec classnames × 2,694,533 ops/sec clsx × 8,542,847 ops/sec # Objects classcat × 15,205,051 ops/sec classnames × 2,873,497 ops/sec clsx × 8,806,231 ops/sec # Strings/Objects classcat × 13,834,475 ops/sec classnames × 3,013,424 ops/sec clsx × 5,890,821 ops/sec # Arrays classcat × 3,649,723 ops/sec classnames × 709,177 ops/sec clsx × 2,513,014 ops/sec # Arrays/Objects classcat × 4,290,009 ops/sec classnames × 1,856,967 ops/sec clsx × 3,099,573 ops/sec # Arguments vs Array classcat × 3,089,353 ops/sec classnames × 828,906 ops/sec clsx × 3,057,879 ops/sec
License
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
深入浅出Ext JS
何启伟、徐会生、康爱媛 / 人民邮电出版社 / 2010-5 / 69.00元
以用户为中心的时代,应用的界面外观变得越来越重要。然而,很多程序员都缺乏美术功底,要开发出界面美观的应用实属不易。Ext JS的出现,为广大程序员解决了这一难题。它有丰富多彩的界面和强大的功能,是开发具有炫丽外观的RIA应用的最佳选择。 本书是《深入浅出Ext JS》的升级版,涵盖了最新发布的Ext JS 3.2新特性,并对上一版的内容进行增补,充实了示例代码,同时补充了两个功能强大的实例。......一起来看看 《深入浅出Ext JS》 这本书的介绍吧!