1.3.0 • Published 10 months ago

cssmem v1.3.0

Weekly downloads
141
License
MIT
Repository
github
Last release
10 months ago

CSSMEM (CSS Module, Element, Modifier)

CSSMEM is like BEM but with CSS Module instead of Block.

It works like classnames/bind but with CSSMEM methodology.

Install

npm i --save-dev cssmem

Usage

import cssmem from 'cssmem';

const styles = {
  foo: 'abc',
  foo_bar: 'def',
  foo_baz_qwe: 'ghi',
};

const em = cssmem(styles);
const foo = em('foo');

foo(); // abc
foo({ bar: true }); //abc def
foo({ baz: 'qwe' }); //abc ghi
foo({ bar: true, baz: 'qwe' }); //abc def ghi

More plausible example

// components/MyButton/MyButton.css
.button {
  border: 1px solid #000;

  &_wide {
    width: 100%;
  }

  &_size {
    &_s {
      height: 28px;
    }
    &_m {
      height: 36px;
    }
  }
}
// components/MyButton/index.js
import React from 'react';
import cssmem from 'cssmem';
import styles from 'MyButton.css';

const em = cssmem(styles);
const button = em('button');

const MyButton = ({
  onClick,
  text,
  wide,
  size,
}) => {
  return (
    <div className={button({ wide, size })} onClick={onClick}>
      {text}
    </div>
  );
};

export default MyButton;

Mixes

You can mix other classnames by passing second argument to last call (after modifiers).

const MyButton = ({
  onClick,
  text,
  wide,
  size,
  className,
}) => {
  return (
    <div className={button({ wide, size }, className)} onClick={onClick}>
      {text}
    </div>
  );
};

If you don't need modifiers you can skip it with {} or null.

Configuration

If you need custom delimiters, you can change defaults:

// Somewhere in the root of your app
cssmem.config.elemDelimiter = '--'; // Default is '_'
cssmem.config.modDelimiter = '-'; // Default is '_' too
1.3.0

10 months ago

1.2.5

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago