62
ATOMIC CSS @LUCASMOURELLE #BAFrontend

Atomic CSS - Lucas Mourelle

Embed Size (px)

DESCRIPTION

Charla en el marco del a tercera Buenos Aires Front-end Meetup. Miles de líneas de código CSS pueden significar la locura en proyectos grandes. Mostraremos una metodología para lograr código fácil de mantener: CSS Atómico con la ayuda de OOCSS y SASS.

Citation preview

Page 1: Atomic CSS - Lucas Mourelle

ATOMIC CSS@ L U C A S M O U R E L L E

# B A F r o n t e n d

Page 2: Atomic CSS - Lucas Mourelle

Lucas Mourelle

@ l u c a s m o u r e l l e

* Líder de diseño en OmbuLabs

* Profesor en FADU/UBA y Fundación Gutenberg

d i s e ñ a d o r · f r o n t e n d e r · p r o f e s o r

Page 3: Atomic CSS - Lucas Mourelle

PROBLEMA

Page 4: Atomic CSS - Lucas Mourelle
Page 5: Atomic CSS - Lucas Mourelle
Page 6: Atomic CSS - Lucas Mourelle
Page 7: Atomic CSS - Lucas Mourelle

?

Page 8: Atomic CSS - Lucas Mourelle

FILOSOFÍA TECNOLOGÍA ESTRUCTURA

Page 9: Atomic CSS - Lucas Mourelle

FILOSOFÍA

OOCSSObject Oriented CSS

Page 10: Atomic CSS - Lucas Mourelle

DISEÑAR SISTEMAS, NO PÁGINAS

Design systems, not pages

Page 11: Atomic CSS - Lucas Mourelle

ESTRUCTURA COSMÉTICA

Page 12: Atomic CSS - Lucas Mourelle

.default-button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; text-decoration: none; background: #0f0; color: #000;}.button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; text-decoration: none; background: #ddd; color: #000;}

Page 13: Atomic CSS - Lucas Mourelle

.default-button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; text-decoration: none; background: #0f0; color: #000;}.button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; text-decoration: none; background: #ddd; color: #000;}

Page 14: Atomic CSS - Lucas Mourelle

.button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; text-decoration: none; background: #ddd; color: #000;}

.button.default { background: #0f0; color: #000;}

.button.big { font-size: 2em;}

.button.small { font-size: .6em;}

Page 15: Atomic CSS - Lucas Mourelle

C O N T E N E D O R

CONTENIDO

Page 16: Atomic CSS - Lucas Mourelle

.dialog { border-radius: 5px; background: #fff; box-shadow: rgba(0,0,0,0.3) 0px 2px 6px; overflow: hidden; max-width: 760px; margin: 1em auto 1em; padding: 1em;}.dialog header h1 { font-size: 1.5625em; font-weight: 700; color: #fff; text-align: center; padding: 1em;}

Page 17: Atomic CSS - Lucas Mourelle

.dialog { border-radius: 5px; background: #fff; box-shadow: rgba(0,0,0,0.3) 0px 2px 6px; overflow: hidden; max-width: 760px; margin: 1em auto 1em; padding: 1em;}.dialog header h1 { font-size: 1.5625em; font-weight: 700; color: #fff; text-align: center; padding: 1em;}

Page 18: Atomic CSS - Lucas Mourelle

.dialog { border-radius: 5px; background: #fff; box-shadow: rgba(0,0,0,0.3) 0px 2px 6px; overflow: hidden; max-width: 760px; margin: 1em auto 1em; padding: 1em;}.heading { font-size: 1.5625em; font-weight: 700; color: #fff; text-align: center; padding: 1em;}

Page 19: Atomic CSS - Lucas Mourelle

DRYDON’T REPEAT YOURSELFDON’T REPEAT YOURSELFDON’T REPEAT YOURSELFDON’T REPEAT YOURSELFDON’T REPEAT YOURSELFDON’T REPEAT YOURSELFDON’T REPEAT YOURSELFDON’T REPEAT YOURSELF

Page 20: Atomic CSS - Lucas Mourelle

TECNOLOGÍA

SASSSyntactically Awesome Style Sheets

Page 21: Atomic CSS - Lucas Mourelle

SCSS CSS

SASSLESS

Page 22: Atomic CSS - Lucas Mourelle

VARIABLES

Page 23: Atomic CSS - Lucas Mourelle

.button { background: #66ffcc; font-size: 1.2em; margin-right: 20px;}.header { color: #66ffcc; font-weight: 700; margin-bottom: 20px;}

Page 24: Atomic CSS - Lucas Mourelle

.button { background: #66ffcc; font-size: 1.2em; margin-right: 20px;}.header { color: #66ffcc; font-weight: 700; margin-bottom: 20px;}

Page 25: Atomic CSS - Lucas Mourelle

$brand-color: #66ffcc;$module: 20px;!.button { background: $brand-color; font-size: 1.2em; margin-right: $module;}.header { color: $brand-color; font-weight: 700; margin-bottom: $module;}

Page 26: Atomic CSS - Lucas Mourelle

CÁLCULOS

Page 27: Atomic CSS - Lucas Mourelle

$brand-color: #66ffcc;$module: 20px;!.button { background: $brand-color; font-size: 1.2em; margin-right: $module;}.header { color: $brand-color; font-weight: 700; margin-bottom: 40px;}

Page 28: Atomic CSS - Lucas Mourelle

$brand-color: #66ffcc;$module: 20px;!.button { background: $brand-color; font-size: 1.2em; margin-right: $module;}.header { color: $brand-color; font-weight: 700; margin-bottom: $module*2;}

Page 29: Atomic CSS - Lucas Mourelle

NESTING

Page 30: Atomic CSS - Lucas Mourelle

.button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; background: #ddd;}.button:hover { background: #fff;}.button:active { background: #bbb;}

Page 31: Atomic CSS - Lucas Mourelle

.button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; background: #ddd;}.button:hover { background: #fff;}.button:active { background: #bbb;}

Page 32: Atomic CSS - Lucas Mourelle

.button { display: inline-block; border-radius: 3px; padding: .4em .8em; border: none; background: #ddd; &:hover { background: #fff; } &:active { background: #bbb; }}

Page 33: Atomic CSS - Lucas Mourelle

IMPORT PARTIALS

Page 34: Atomic CSS - Lucas Mourelle

.main-content { float: left; width: 65%;}.secondary-content { float: right; width: 30%;}

CSS

_layout.scss style.scss style.css

import "layout";!.button { background: #6f0; font-size: 1.2em; padding: .2em;}

.main-content { float: left; width: 65%;}.secondary-content { float: right; width: 30%;}.button { background: #6f0; font-size: 1.2em; padding: .2em;}

Page 35: Atomic CSS - Lucas Mourelle

MIXINS & HERENCIA

Page 36: Atomic CSS - Lucas Mourelle

@mixin border-radius($radius) { -webkit-border-radius: $radius; border-radius: $radius;}!.button { @include border-radius(5px);}.dialog { @include border-radius(10px);}

.button { -webkit-border-radius: 5px; border-radius: 5px;}.dialog { -webkit-border-radius: 10px; border-radius: 10px;}

CSSSCSS

Page 37: Atomic CSS - Lucas Mourelle

%alert-base { display: inline-block; padding: .3em; text-decoration: none;}!.alert-warning { @extend %alert-base; background: #ffffdf; color: #000;}.alert-error { @extend %alert-base; background: #f00; color: #fff;}

.alert-warning, .alert-error { display: inline-block; padding: .3em; text-decoration: none;}!.alert-warning { background: #ffffdf; color: #000;}.alert-error { background: #f00; color: #fff;}

CSSSCSS

Page 38: Atomic CSS - Lucas Mourelle

COLOR FUNCTIONS

Page 39: Atomic CSS - Lucas Mourelle

CSS

SCSS

$brand-color: #ff0000;!.alert { border: 1px solid $brand-color; color: darken($brand-color, 20%); background: lighten($brand-color, 40%);}

.alert { border: 1px solid #ff0000; color: #990000; background: #ffcccc;}

Page 40: Atomic CSS - Lucas Mourelle

You got me at variables!

Page 41: Atomic CSS - Lucas Mourelle

ESTRUCTURA

ATOMIC

Page 42: Atomic CSS - Lucas Mourelle
Page 43: Atomic CSS - Lucas Mourelle

DIVIDE & CONQUER

Page 44: Atomic CSS - Lucas Mourelle

ATOMIC DESIGNVERSIÓN ORIGINAL

ATOMS MOLECULES ORGANISMS TEMPLATES PAGES

by Brad Frost

Page 45: Atomic CSS - Lucas Mourelle

Brad Frost@brad_frost

bradfrostweb.com

https://vimeo.com/95626309 =PREALLY COOL ATOMIC DESIGN TALK

patternlab.io

Page 46: Atomic CSS - Lucas Mourelle

ATOMIC CSS

ATOMS MOLECULES PAGESQUARKSUTILITIES

VERSIÓN ALTERNATIVARobin Rendle y otros

Page 47: Atomic CSS - Lucas Mourelle

ATOMS MOLECULES PAGESQUARKSUTILITIES

Page 48: Atomic CSS - Lucas Mourelle

ATOMS MOLECULES PAGESQUARKSUTILITIES

Page 49: Atomic CSS - Lucas Mourelle

ATOMS MOLECULES PAGESQUARKSUTILITIES

Page 50: Atomic CSS - Lucas Mourelle

ATOMS MOLECULES PAGESQUARKSUTILITIES

Page 51: Atomic CSS - Lucas Mourelle

ATOMS MOLECULES PAGESQUARKSUTILITIES

Page 52: Atomic CSS - Lucas Mourelle

1-util ities

2-quarks

3-atoms

4-molecules

5-pages

SCSS

style.scss

Page 53: Atomic CSS - Lucas Mourelle

1-util ities

SCSS

style.scss

_variables.scss_mixins.scss_placeholders.scss_grid.scss!_typography.scss_forms.scss!_brand.scss_buttons.scss_errors.scss!_dialog.scss_footer.scss_navbar.scss!_home.scss_features.scss_examples.scss

2-quarks

3-atoms

4-molecules

5-pages

Page 54: Atomic CSS - Lucas Mourelle

// 1-UTILITIES@import "1-utilities/variables";@import "1-utilities/mixins";@import "1-utilities/placeholders";@import "1-utilities/grid";!// 2-QUARKS@import "2-quarks/typography";@import "2-quarks/forms";!// 3-ATOMS@import "3-atoms/brand";@import "3-atoms/buttons";@import "3-atoms/errors";!// 4-MOLECULES@import "4-molecules/dialog";@import "4-molecules/footer";@import "4-molecules/navbar";!// 5-PAGES@import "5-pages/home";@import "5-pages/features";@import "5-pages/examples";

SCSS style.scss

Page 55: Atomic CSS - Lucas Mourelle

// Componente.button { display: inline-block; border-radius: $global-radius; padding: .4em .8em; border: none; text-decoration: none; background: $button-background-color; color: $button-text-color; // Modificadores &.default { background: $button-default—background-color; color: $button-default-text-color; } &.big { font-size: 2em; } &.small { font-size: .6em; }}

SCSS _buttons.scss

3-atoms

Page 56: Atomic CSS - Lucas Mourelle

// Componente.component {!!!!!!! // Modificadores!!!!!!!!!!}

SCSS _component.scss

n-layer

ESTRUCTURAL

COSMÉTICOmodificadores, estados, contextos

Page 57: Atomic CSS - Lucas Mourelle

ATOMIC CSS

ATOMS MOLECULES PAGESQUARKSUTILITIES

VERSIÓN ALTERNATIVA

Page 58: Atomic CSS - Lucas Mourelle

FILOSOFÍA TECNOLOGÍA ESTRUCTURA

OOCSS SASS ATOMIC

Page 59: Atomic CSS - Lucas Mourelle

GRACIAS!L U C A S M O U R E L L E

# B A F r o n t e n d

Page 60: Atomic CSS - Lucas Mourelle

AT O M I C D E S I G N B r a d F r o s t ( @ b r a d _ f r o s t )h t t p : / / p a t t e r n l a b . i o / h t t p : / / b r a d f r o s t w e b . c o m / b l o g / p o s t / a t o m i c - w e b - d e s i g n /

AT O M I C C S S ( w i t h S A S S ) R o b i n R e n d l e ( @ r o b i n r e n d l e )h t t p : / / w w w. s m a s h i n g m a g a z i n e . c o m / 2 0 1 3 / 0 8 / 0 2 / o t h e r - i n t e r f a c e - a t o m i c -d e s i g n - s a s s /

O O C S S N a t i D e v a l l e ( @ t a l y )h t t p : / / e s . s l i d e s h a r e . n e t / n d e v a l l e / a n - i n t r o d u c t i o n - t o - o b j e c t - o r i e n t e d - c s s

C S S AT Ó M I C O O m b u S h o p B l o gh t t p : / / w w w. o m b u s h o p . c o m / b l o g / d i s e n o - w e b / c s s - a t o m i c o . h t m l

Page 61: Atomic CSS - Lucas Mourelle

¿PREGUNTAS?

Page 62: Atomic CSS - Lucas Mourelle

GRACIAS!L U C A S M O U R E L L E

@ l u c a s m o u r e l l e

# B A F r o n t e n d