Giter VIP home page Giter VIP logo

strclass's Introduction

strclass

A tiny library to apply CSS classes as strings from objects

Build Status Coveralls Coverage Status

Installation

yarn add strclass

Usage

strclass is an Universal Module, and can be used as a global, with AMD, CommonJS or ES Module.

Signature:

strclass({ className: booleanConditionToShowThisClass }, [defaultClass1, defaultclass2, ..., defaultclassN])

Usage:

import strclass from 'strclass'

console.log(strclass({ highlighted: true }))
// 'highlighted'

console.log(strclass({ '-active': true }, 'button'))
// 'button -active'

console.log(strclass({ '-active': true }, 'button', 'button-default'))
// 'button button-default -active'

console.log(strclass({ active: false }))
// ''

You can use with React, VanillaJS or any other lib/framework:

const Button = ({ active, children }) => (
  <button className={strclass({ active }, 'button')}>
    {children}
  </button>
)

<Button active>Click!</Button>
// will render: <button class="button active">Click!</button>

<Button active={false}>Click!</Button>
// will render: <button class="button">Click!</button>

If you are using CSS Modules, or need to pass the class as a dynamic value, just do:

const ac = 'active'
console.log(strclass({ [ac]: true })) // 'active'

Differences from classnames module

Size

strclass has ~200bytes gzipped.

Signature

With classnames, you can pass any argument as String, Object or Array. Otherwise, strclass has a signature that should be respected: Object as a first argument, with the conditionals, and any other argument should be a String.

If you don't need conditionals, you don't need strclass. Just use strings.

That's it =)

License

MIT © Fernando Daciuk

strclass's People

Contributors

fdaciuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

renatobenks-zz

strclass's Issues

[DESIGN] Logo

If you are a designer, and want to suggest a logo for this project, be my guest :)

Uncaught Error: define cannot be used indirect

Ao importar a lib o seguinte erro é apresentado no console:

Uncaught Error: define cannot be used indirect

Stack completa
amd-define.js:2 Uncaught Error: define cannot be used indirect at module.exports (amd-define.js:2) at strclass.min.js:2 at Object.<anonymous> (strclass.min.js:2) at __webpack_require__ (bootstrap 4955f2d…:659) at fn (bootstrap 4955f2d…:85) at Object.defineProperty.value (sidebar-item.js:2) at __webpack_require__ (bootstrap 4955f2d…:659) at fn (bootstrap 4955f2d…:85) at Object.defineProperty.value (index.js:3) at __webpack_require__ (bootstrap 4955f2d…:659)

Alguma configuração que preciso fazer?

[PT-BR] Tradução da documentação

Precisamos traduzir a documentação do strclass para Português do Brasil.

As discussões gerais desse projeto deverão ser em inglês, mas essa issue, especificamente, pode ser discutida em português, já que tem relação com a tradução da documentação para pt-BR.

Se você gostaria de trabalhar nessa issue, sinalize aqui na issue, e vamos discutindo os detalhes de como deve ser feita essa tradução, ok? :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.