2.1.2 • Published 3 years ago

getclassname v2.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

getClassName

Simple function for managing css classes. It was made with react in mind. The function returns a string object so if you want the primitive value you have to call toString. You can safely pass the value to className prop in react.

Installation

yarn add getclassname
// or
npm install getclassname

Usage

It is a function that returns a string with a couple more methods. The common use cases are as follows:

import getClassName from 'getclassname';

const common = getClassName({
    "class1": true,
    "not-included": false,
    "class2": () => true
})

// common == "class1 class2"

const interpolation = getClassName({
    base: "base",
    "&--active": true,
})

// interpolation == "base base--active"

const extended = interpolation.extend("&__extended");

// extended == "base__extended"

const extra = interpolation.extend("&__extended").recompute({
    "&--active": false
})

// extra == "base__extended base__extended--active"

const changeInterpolationToken = getClassName({
    base: "base",
    token: "$",
    "$--different": true
})

// changeInterpolationToken == "base base--different"

// BEM Shorthands

const Block = getClassName({ base: "block" })

const Element = Block.element("element");

// Block.element("element") == Block.extend("&__element") == "block__element"

const Modifier = Block.modifier("modifier")

// Block.modifier("modifier") == Block.extend("&--modifier") == "block--modifier"

And that's all there is...

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

6 years ago