Top Banner
Chainable BEM Modifiers Jordan Lewis
45

Chainable BEM Modifiers

Apr 14, 2017

Download

Technology

Jordan Lewis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chainable BEM Modifiers

Chainable BEM Modifiers Jordan Lewis

Page 2: Chainable BEM Modifiers

‣ Solved an issue that has been bothering us since adopting BEM

‣ Removed ambiguity from our code

‣ Build a super flexible UI Library

‣ Enabled those less skilled in Frontend practices to be productive

Page 3: Chainable BEM Modifiers

Jordan Lewis @jordanlewiz

Page 4: Chainable BEM Modifiers
Page 5: Chainable BEM Modifiers

‣ Problem with BEM syntax

‣ Finding a better solution

‣ Variations

‣ Modifiers

‣ Recap

What we’ll cover

Page 6: Chainable BEM Modifiers

The problem with BEM syntax

Page 7: Chainable BEM Modifiers

block__element—modifier

BEM

PROBLEMS WITH BEM

Page 8: Chainable BEM Modifiers

PROBLEMS WITH BEM

BEM 101

Page 9: Chainable BEM Modifiers

BEM Modifiers are used in 2 different ways..

PROBLEMS WITH BEM

Page 10: Chainable BEM Modifiers

Having two conventions using identical syntax is a recipe for confusion.

PROBLEMS WITH BEM

Page 11: Chainable BEM Modifiers

Single class

SINGLE CLASS MODIFIERS

Page 12: Chainable BEM Modifiers

‣ Easy to understand at a glance

‣ Pushes all the logic into the CSS

‣ Makes use of Sass’ @extend to make the modifications

‣ Best suited for modules that only need to make one modification at a time

Benefits of a single class modifier

SINGLE CLASS MODIFIERS

Page 13: Chainable BEM Modifiers

SASS CSS

SINGLE CLASS MODIFIERS

Page 14: Chainable BEM Modifiers

Multiple classes (aka chaining)

MULTIPLE CLASSES MODIFIER

Page 15: Chainable BEM Modifiers

‣ Logic kept in the HTML

‣ Configure any given module on the fly

‣ Best suited for modules with multiple modifiers that are designed to be mixed and matched.

Benefits of multiple classes

MULTIPLE CLASSES MODIFIER

Page 16: Chainable BEM Modifiers

SASS CSS

MULTIPLE CLASSES MODIFIER

Page 17: Chainable BEM Modifiers

Finding a better solution

Page 18: Chainable BEM Modifiers

What if told you 'single' and 'multiple' classes

are complete different things?

SOLUTION

Page 19: Chainable BEM Modifiers

SOLUTION

Page 20: Chainable BEM Modifiers

Single class =

variation

SOLUTION

Page 21: Chainable BEM Modifiers

SOLUTION

Multiple classes =

modifiers

Page 22: Chainable BEM Modifiers

SOLUTION

Introducing…

Page 23: Chainable BEM Modifiers

BEVM

SOLUTION

block__element--variation -modifier

Page 24: Chainable BEM Modifiers

Variations

Page 25: Chainable BEM Modifiers

“A different or distinct form or version of something”

VARIATION

Oxford Dictionary

Variation

Page 26: Chainable BEM Modifiers

Variation (aka Single class approach)

VARIATION

Page 27: Chainable BEM Modifiers

‣ Can only apply one 'variation' at a time

‣ No need to repeat base class

‣ Can use Sass @extends to build

‣ Or can write a custom variation (no @extends)

‣ Can combine with Modifiers

Variation rules

VARIATION

Page 28: Chainable BEM Modifiers

Chainable Modifers

Page 29: Chainable BEM Modifiers

CHAINABLE MODIFIERS

“A ... thing that makes partial or minor changes to something”

Oxford Dictionary

Modifier

Page 30: Chainable BEM Modifiers

Chainable Modifiers (aka Multiple class approach)

CHAINABLE MODIFIERS

Page 31: Chainable BEM Modifiers

New modifier syntax

-namespace-descriptor

Leading hyphen Namespace

Descriptor for the modification

CHAINABLE MODIFIERS

Page 32: Chainable BEM Modifiers

GOLDEN RULE:

Chainable modifiers should never modify the same CSS property twice for a given module

CHAINABLE MODIFIERS

Page 33: Chainable BEM Modifiers

btn

btn -color-primary

btn -color-primary -size-l

btn -color-primary -size-l -width-full

CHAINABLE MODIFIERS

Page 34: Chainable BEM Modifiers

CHAINABLE MODIFIERS

Page 35: Chainable BEM Modifiers

‣ See 'Golden rule'

‣ Use a namespace which describe the change e.g. size, color, width etc

‣ Use generic descriptors e.g. large, primary, dark etc

Chainable Modifier rules

CHAINABLE MODIFIERS

Page 36: Chainable BEM Modifiers

Won’t that make things hard to find?

CHAINABLE MODIFIERS

Page 37: Chainable BEM Modifiers

Recap

Page 38: Chainable BEM Modifiers

RECAP

‘variations’ and ‘modifiers’ are different so lets treat them like they are.

block__element--variation -modifier

Page 39: Chainable BEM Modifiers

Modifiers: How we got here?

RECAP

Page 40: Chainable BEM Modifiers

Combining Variations and Modifiers

RECAP

Page 41: Chainable BEM Modifiers

RECAP

‣ State classes ‣ Helper/Utility classes ‣ JS Hooks

Special mentions

Page 42: Chainable BEM Modifiers

RECAP

‣ Build a super flexible UI Library ‣ Configure modules in the HTML ‣ Short, concise syntax ‣ Reducing the amount of CSS that we need to write ‣ Increases development speed ‣ Can still use 'variations' if you want ‣ Works with 'helper' and 'state' classes ‣ Greppable

Benefits of BEVM

Page 43: Chainable BEM Modifiers

RECAP

Live demo

Page 44: Chainable BEM Modifiers

RECAP

‣ Chainable BEM Modifiers http://webuild.envato.com/blog/chainable-bem-modifiers

‣ Sassier (BE)Modifers http://viget.com/extend/bem-sass-modifiers

‣ BEM modifiers: multiple classes vs @extend http://bensmithett.com/bem-modifiers-multiple-classes-vs-extend

Resources