45
MANAGING COMPLEX PROJECTS WITH DESIGN COMPONENTS Front-end Track - June 4, 2014 JOHN ALBIN WILKINS

Managing Complex Projects with Design Components - Drupalcon Austin 2014

Embed Size (px)

DESCRIPTION

Our CSS sucks. We've been building sites for over a decade using crappy, ornamentation techniques and shoddy selectors. Our styles unintentional bleed across the site. Our stylesheets are fragile and unmaintainable and full of specificity landmines. Pandas wander alone in the wilderness. But there's no need to drown ourselves in beer. New technologies like Web Components and new techniques like OOCSS, SMACSS and BEM show us that planning before building can make our projects maintainable, easier to debug, and smaller with reduced CSS file sizes. This session will introduce the basic techniques for CSS layering and using design components, the heart of any front-end CSS project. We will also discuss CSS/Sass organization and tips to more easily implement these ideas.

Citation preview

Page 1: Managing Complex Projects with Design Components - Drupalcon Austin 2014

MANAGING COMPLEX PROJECTS WITH DESIGN COMPONENTS

Front-end Track - June 4, 2014

J O H N A L B I N W I L K I N S

Page 2: Managing Complex Projects with Design Components - Drupalcon Austin 2014

@ J O H N A L B I N

Senior Front-end Developer PreviousNext

Page 3: Managing Complex Projects with Design Components - Drupalcon Austin 2014

FREE GIFTS FROM ME

Zen Gridszengrids.com"Normalize.css for Sass/Compassgithub.com/JohnAlbin/normalize-scss"Succinct theme for Colloquy (IRC for Mac) github.com/JohnAlbin/succinct-for-colloquy"git-svn-migratejohn.albin.net/git/git-svn-migrate"Zen theme for Drupaldrupal.org/project/zen

Page 4: Managing Complex Projects with Design Components - Drupalcon Austin 2014

“Are you new to front-end web development?

"

 Here’s a secret:  no one else really knows  what they’re doing either.”

— Nicolas Gallagher

WHERE ARE WE HEADED?

Page 5: Managing Complex Projects with Design Components - Drupalcon Austin 2014

www.w3.org/TR/components-intro/"css-tricks.com/modular-future-web-components/

WEB COMPONENTS

WHERE ARE WE HEADED?

Page 6: Managing Complex Projects with Design Components - Drupalcon Austin 2014

www.w3.org/TR/components-intro/"css-tricks.com/modular-future-web-components/

WEB COMPONENTS

“Hey… Web developers really like"templating systems."

We should implement that"natively in HTML.”

WHERE ARE WE HEADED?

Page 7: Managing Complex Projects with Design Components - Drupalcon Austin 2014

<carousel><ohgod-ohgod-why-wont-my-client-listen-to-me-about-carousels>

www.w3.org/TR/components-intro/"css-tricks.com/modular-future-web-components/

WEB COMPONENTS WHERE ARE WE

HEADED?

Page 8: Managing Complex Projects with Design Components - Drupalcon Austin 2014

Reusable and repeatable components"Self-contained design (included CSS only applies to its component)

WHAT CAN WE LEARN FROM THE FUTURE?

Page 9: Managing Complex Projects with Design Components - Drupalcon Austin 2014

CSS SPECIFICITY

WARSCSS

SPECIFICITY WARS

Page 10: Managing Complex Projects with Design Components - Drupalcon Austin 2014

.menu .item a:link {}"

.sidebar .menu .item a:link {}"

.page-37 .sidebar .menu .item a:link {}

CSS SPECIFICITY

WARS

Page 11: Managing Complex Projects with Design Components - Drupalcon Austin 2014

.menu .item a:link {" .sidebar & {" .page-37 & {}" }"}

CSS SPECIFICITY

WARS

Page 12: Managing Complex Projects with Design Components - Drupalcon Austin 2014

OVERLY GENERIC CLASS NAMES

.title { }

.block .title { }

.node .title { }

.views .title { }

.content { }

.block .content { }

.node .content { }

.views .content { }

Page 13: Managing Complex Projects with Design Components - Drupalcon Austin 2014

SEEMED LIKE A GOOD IDEA

AT THE TIME.

Page 14: Managing Complex Projects with Design Components - Drupalcon Austin 2014

WHAT ARE DESIGN COMPONENTS?

“Component” is the same as…"

“Object” in OOCSS"“Module” in SMACSS "“Block” in BEM’s Block-Element-Modifier"“UI Pattern”

Page 15: Managing Complex Projects with Design Components - Drupalcon Austin 2014

GOALS OF DESIGN COMPONENTS

Reduce specificity"Reduce applicability / control the cascade"Improve maintainability

Page 16: Managing Complex Projects with Design Components - Drupalcon Austin 2014

DESIGN COMPONENT

One class == one consistent style

Page 17: Managing Complex Projects with Design Components - Drupalcon Austin 2014

DESIGN COMPONENT

One class == one consistent style

.button.navbar

.side-nav.bio

.watermark.tabs

.more-link

.teaser

.pager

.breaking-news

Page 18: Managing Complex Projects with Design Components - Drupalcon Austin 2014

ON THE MEANING OF SEMANTICS

Page 19: Managing Complex Projects with Design Components - Drupalcon Austin 2014

ON THE MEANING OF SEMANTICS

.omnomnomnom

"

is more semantic then!

"

.blaaagh

Page 20: Managing Complex Projects with Design Components - Drupalcon Austin 2014

ON THE MEANING OF SEMANTICS

Don’t name your class .blubadu-blubadu-blubadu-pphhffft

Page 21: Managing Complex Projects with Design Components - Drupalcon Austin 2014

ON THE MEANING OF SEMANTICS

Content semantics is handled by HTML5 elements"

Let’s make our class names use Design semantics"

Make the class names meaningful to the developers and designers

Page 22: Managing Complex Projects with Design Components - Drupalcon Austin 2014

1.BASE 2.LAYOUT 3.MODULE 4.STATE 5.THEME

SMACSS

Page 23: Managing Complex Projects with Design Components - Drupalcon Austin 2014

1.BASE 2.LAYOUT 3.MODULE 4.STATE 5.THEME

1.BASE 2.LAYOUT 3.COMPONENTS 4.STATE 5.SKIN

SMACSS

Page 24: Managing Complex Projects with Design Components - Drupalcon Austin 2014

1.BASE 2.LAYOUT 3.COMPONENTS

3.1.STATE 3.2.SKINS

MA

CS

S

Page 25: Managing Complex Projects with Design Components - Drupalcon Austin 2014

1.BASE 2.LAYOUT 3.COMPONENTS

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

SM

AC

SS

BE

M}

Page 26: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower

Page 27: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower__petals

.flower__face

Page 28: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower__stem

.flower__leaves

Page 29: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower__stem

.flower__leaves

.flower__stem__leavesNO!

Page 30: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower__bed

Page 31: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower--rose

Page 32: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower:hover

Page 33: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

.flower.is-pollinating

Page 34: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

@media (min-width: 48em) {! .flower!}

Page 35: Managing Complex Projects with Design Components - Drupalcon Austin 2014

"

"

"

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

@media “print” {! .flower!}

Page 36: Managing Complex Projects with Design Components - Drupalcon Austin 2014

DECONSTRUCTING A DESIGN COMPONENT

.the%component%%modifier/

.the%component__an%element/

.the%component.is%state/

/ .the%component:hover/

/ @media/all/{/.the%component/{}/}/

.the%skin/.the%component

Page 37: Managing Complex Projects with Design Components - Drupalcon Austin 2014

1.BASE 2.LAYOUT 3.COMPONENTS

3.1.COMPONENT 3.2.ELEMENT 3.3.MODIFIER 3.4.STATE 3.5.SKIN

SM

AC

SS

BE

M}

Page 38: Managing Complex Projects with Design Components - Drupalcon Austin 2014

FILE ORGANIZATION = FIRST 3 SMACSS

CATEGORIES

Page 39: Managing Complex Projects with Design Components - Drupalcon Austin 2014

SIMPLE FOLDER STRUCTURE

Page 40: Managing Complex Projects with Design Components - Drupalcon Austin 2014

EASY TO FIND YOUR COMPONENTS.

Inspect the DOM."Find the class on the design component."Look for a file with that name in the components folder.

Page 41: Managing Complex Projects with Design Components - Drupalcon Austin 2014

STYLES.SCSS

Page 42: Managing Complex Projects with Design Components - Drupalcon Austin 2014

AUTOMATED STYLEGUIDE

kss-node github.com/hughsk/kss-node

Page 43: Managing Complex Projects with Design Components - Drupalcon Austin 2014

THE “FUGLY” SELECTOR HACK

Page 44: Managing Complex Projects with Design Components - Drupalcon Austin 2014

THE “FUGLY” SELECTOR HACK

Selector in DOMI couldn’t change

Class name I wish I could use in DOM

Page 45: Managing Complex Projects with Design Components - Drupalcon Austin 2014

WHAT DID YOU THINK?E V A L U A T E T H I S S E S S I O N :

A U S T I N 2 0 1 4 . D R U P A L . O R G / S C H E D U L E

Thank you!