DEV Community

Discussion on: Tips to write elegant and resilient components

Collapse
 
leobm profile image
Felix Wittmann • Edited

e.g. for the modular approach, the ideas of Atomic Design helps me alot.
bradfrost.com/blog/post/atomic-web...

and BEM for styling (CSS) this different building blocks.
css-tricks.com/bem-101/

e.g. a Button Atom

.a-btn {...}
.a-btn__icon {...}

.a-btn--active {...}

Edit:
in my last project I used often the data attribute instead BEM modifiers.

like

<a class="a-btn" data-disabled data-size="small" />
.a-btn[data-disabled] {....}

.a-btn[data-size="small"] {....}

Data attributes are often easier to set/modify with javascript than CSS classes. Additional they are an interesting solution to manage component state in the DOM.

Collapse
 
christopherkade profile image
Christopher Kade

Agreed, depending on the project (especially when it comes to personal projects), I even structure it based on Atomic Design, it really helps !