ui realigning & refactoring by jina bolton

133
Refactoring Web User Interfaces JINA BOLTON CODEMOTION BERLIN // 2013 (CC BY-NC-SA 3.0)

Upload: codemotion

Post on 27-Jan-2015

109 views

Category:

Technology


2 download

DESCRIPTION

Often designers and developers see Markup and CSS Refactoring as a dreaded, monolithic task. Organization, architecture, clean up, optimization, documentation all seem tedious and overwhelming. However, if you’re armed with the right tools and a solid foundation, you may find refactoring to be actually quite fun. Learn some Sass, markup, and documentation tips & tricks from a product designer’s perspective. Start making refactoring a regular part of your design process and development workflows.

TRANSCRIPT

Page 1: UI Realigning & Refactoring by Jina Bolton

Refactoring Web User InterfacesJINA BOLTON

CODEMOTION BERLIN // 2013

(CC BY-NC-SA 3.0)

Page 2: UI Realigning & Refactoring by Jina Bolton

PRODUCT DESIGNER

Page 3: UI Realigning & Refactoring by Jina Bolton

“It used to be that designers made an object and walked away. Today the emphasis must shift to designing the entire life cycle.”

—PAUL SAFFO

Page 4: UI Realigning & Refactoring by Jina Bolton

Creating pages

Page 5: UI Realigning & Refactoring by Jina Bolton

Creating pages

Page 6: UI Realigning & Refactoring by Jina Bolton

Creating systems

Page 7: UI Realigning & Refactoring by Jina Bolton

“I always write code perfectly the first time.”

—NO ONE EVER

Page 8: UI Realigning & Refactoring by Jina Bolton

Refactoring:CHANGE THE STRUCTURE OF EXISTING CODE WITHOUT

CHANGING THE BEHAVIOR OF THAT CODE

Page 9: UI Realigning & Refactoring by Jina Bolton

Lack of clarity ➤ Confusion

Page 10: UI Realigning & Refactoring by Jina Bolton

No maintainability ➤ Inefficiency

Page 11: UI Realigning & Refactoring by Jina Bolton

Duplication ➤ Bloat

Page 12: UI Realigning & Refactoring by Jina Bolton

Messy UI & CSS ➤ Messy UX

Page 13: UI Realigning & Refactoring by Jina Bolton

Get rid of code smells

Page 14: UI Realigning & Refactoring by Jina Bolton

Smell bad!

Page 15: UI Realigning & Refactoring by Jina Bolton

Refactoring is not just code clean up.

Page 16: UI Realigning & Refactoring by Jina Bolton

Clarity

Maintainability

Efficiency

DRY

Quality

Page 17: UI Realigning & Refactoring by Jina Bolton

Refactoring & Style Guides go together perfectly.

Page 19: UI Realigning & Refactoring by Jina Bolton

Style guides for writing, design, & code

Page 21: UI Realigning & Refactoring by Jina Bolton

ENGINE YARD APP CLOUD, EARLY 2011

Page 22: UI Realigning & Refactoring by Jina Bolton

“A fractured process makes for a fractured user experience.”

—NATE FORTIN

Page 23: UI Realigning & Refactoring by Jina Bolton

Make Refactoring & Documentation a regular part of your review process.

01 //

Page 24: UI Realigning & Refactoring by Jina Bolton

Don’t try to document everything at once.

You’ll likely give up.

Page 25: UI Realigning & Refactoring by Jina Bolton

Do document going forward.

Page 26: UI Realigning & Refactoring by Jina Bolton

CSS Gatekeeper

Page 27: UI Realigning & Refactoring by Jina Bolton

Making something new? Document it.

Page 28: UI Realigning & Refactoring by Jina Bolton

Revising something? Refactor it.Then document it.

Page 29: UI Realigning & Refactoring by Jina Bolton

When code style preferences come up in code reviews, document it for reference in later code reviews.

Page 30: UI Realigning & Refactoring by Jina Bolton

smacss.com

Page 31: UI Realigning & Refactoring by Jina Bolton

sass-lang.com

Page 32: UI Realigning & Refactoring by Jina Bolton

NestingUSE (CAREFULLY) TO AVOID REPETITION

Page 33: UI Realigning & Refactoring by Jina Bolton

OUTPUT

.menu a {

color: #369;

&:hover {

color: #036;

.note & { color: #fff; }

}

}

.menu a { color: #369; }

.menu a:hover {

color: #036;

}

.note .menu a:hover {

color: #fff;

}

SCSS

Page 34: UI Realigning & Refactoring by Jina Bolton

OUTPUT

.menu a {

color: #369;

@media print {

color: #000;

}

}

.menu a { color: #369; }

@media print {

.menu a { color: #000; }

}

SCSS

Page 35: UI Realigning & Refactoring by Jina Bolton

OUTPUT

.menu {

border: 1px solid #eee {

top-color: #fff;

left: 0;

}

}

.menu {

border: 1px solid #eee;

border-top-color: #fff;

border-left: 0;

}

SCSS

Page 36: UI Realigning & Refactoring by Jina Bolton

If you’re nesting more than three levels deep, you’re probably doing something wrong. Refactor!

Page 37: UI Realigning & Refactoring by Jina Bolton

VariablesSTORE COMMON ATTRIBUTES FOR MAINTAINABILITY

Page 38: UI Realigning & Refactoring by Jina Bolton

OUTPUT

$text: #444;

$bg: $text;

body { color: $text; }

aside { background: $bg; }

body { color: #444; }

aside { background: #444; }

SCSS

Page 39: UI Realigning & Refactoring by Jina Bolton

MixinsSTORE REUSABLE CODE & PASS ARGUMENTS FOR OVERRIDES

Page 40: UI Realigning & Refactoring by Jina Bolton

OUTPUT

@mixin mod($txt: #ccc) {

background: #111;

color: $txt;

}

body { @include mod; }

.box { @include mod(#888); }

body {

background: #111;

color: #ccc;

}

.box {

background: #111;

color: #888;

}

SCSS

Page 41: UI Realigning & Refactoring by Jina Bolton

ExtendCHAIN SELECTORS TOGETHER

Page 42: UI Realigning & Refactoring by Jina Bolton

OUTPUT

.message {

padding: 1em;

.content {

background: #111;

}

}

.error {

@extend .message;

color: #eee;

}

.message,

.error { padding: 1em; }

.message .content,

.error .content {

background: #111;

}

.error { color: #eee; }

SCSS

Page 43: UI Realigning & Refactoring by Jina Bolton

Placeholder SelectorsCREATE SILENT CLASSES THAT DON’T GET OUTPUT

Page 44: UI Realigning & Refactoring by Jina Bolton

OUTPUT

%grid-1 { width: 240px; }

%grid-2 { width: 480px; }

.content {

@extend %grid-1;

background: #111;

}

.main {

@extend %grid-1;

color: #eee;

}

.content,

.main { width: 240px; }

.content {

background: #111;

}

.main { color: #eee; }

SCSS

Page 45: UI Realigning & Refactoring by Jina Bolton

Document your ideal CSS Architecture.

02 //

Page 46: UI Realigning & Refactoring by Jina Bolton

DO’S WEB APPLICATION

Page 47: UI Realigning & Refactoring by Jina Bolton

deathstarDO’S WEB APPLICATION

Page 48: UI Realigning & Refactoring by Jina Bolton

DO’S WEBSITE

Page 49: UI Realigning & Refactoring by Jina Bolton

KenobiDO’S WEBSITE

Page 50: UI Realigning & Refactoring by Jina Bolton

KENOBI.CSS.SASSDEATHSTAR.CSS.SASS

Page 51: UI Realigning & Refactoring by Jina Bolton

KENOBI.CSS.SASSDEATHSTAR.CSS.SASS

Page 52: UI Realigning & Refactoring by Jina Bolton

KENOBI.CSS.SASSDEATHSTAR.CSS.SASS

Page 53: UI Realigning & Refactoring by Jina Bolton

KENOBI.CSS.SASSDEATHSTAR.CSS.SASS

Page 54: UI Realigning & Refactoring by Jina Bolton

VENDOR/_SHARED.SASS

@import compass

@import compass/layout

@import susy

KENOBI.CSS.SASS

@import vendor/shared

DEATHSTAR.CSS.SASS

@import bootstrap/variables

@import bootstrap/mixins

@import vendor/shared

01 // VENDOR LIBRARIES

Page 55: UI Realigning & Refactoring by Jina Bolton

compass-style.org

Page 57: UI Realigning & Refactoring by Jina Bolton

01 //

DEPENDENCIES/_SHARED.SASS

@import metrics

@import typography

@import colors

@import themes

02 // DEPENDENCIESVENDOR LIBRARIES

Globally used variables, mixins, & functions

Page 58: UI Realigning & Refactoring by Jina Bolton

01 //

FOUNDATION/_SHARED.SASS

@include border-box-sizing

@import ../vendor/normalize

@import base

03 // FOUNDATION

VENDOR LIBRARIES

02 // DEPENDENCIES

Plain old semantic HTML

Page 61: UI Realigning & Refactoring by Jina Bolton

01 //

KENOBI.CSS.SASS

@import foundation/shared

@import foundation/kenobi

DEATHSTAR.CSS.SASS

@import foundation/shared

03 // FOUNDATION

VENDOR LIBRARIES

02 // DEPENDENCIES

Kenobi has a different font, so we override them after importing shared styles.

Page 62: UI Realigning & Refactoring by Jina Bolton

01 //

COMPONENTS/_SHARED.SASS

@import icons

@import buttons

@import toggles

@import messages

@import pagination

04 // COMPONENTS

VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

Modular components& their states.

These should be able to be used anywhere.

Page 63: UI Realigning & Refactoring by Jina Bolton

01 //

REGIONS/_SHARED.SASS

@import banner

@import navigation

@import complementary

@import contentinfo

05 // REGIONS

VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

04 // COMPONENTS

Page regions, named after their class and role names.

Page 64: UI Realigning & Refactoring by Jina Bolton

01 //

HELPERS/_SHARED.SASS

@import nonsemantic-classes

@import placeholder-selectors

06 // HELPERS

VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

04 // COMPONENTS

05 // REGIONS

Non-semantic helpers

Page 65: UI Realigning & Refactoring by Jina Bolton

01 //

RESPONSIVE/_SHARED.SASS

@import responsive/mobile

@import responsive/tablet

@import responsive/screen

07 // RESPONSIVE

VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

04 // COMPONENTS

05 // REGIONS

06 // HELPERS

Adjustments to type sizes, grids, and images.

Page 66: UI Realigning & Refactoring by Jina Bolton

01 //

@import tools/show-grid

08 // TOOLS

VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

04 // COMPONENTS

05 // REGIONS

06 // HELPERS

07 // RESPONSIVE

Page 67: UI Realigning & Refactoring by Jina Bolton

01 //

<% if Rails.env.development? && Settings.show_grids %>

@import tools/show-grid

<% end %>

08 // TOOLS

VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

04 // COMPONENTS

05 // REGIONS

06 // HELPERS

07 // RESPONSIVE

Page 68: UI Realigning & Refactoring by Jina Bolton

Don’t try to refactor everything at once.

You’ll likely give up.

Page 69: UI Realigning & Refactoring by Jina Bolton

Do refactor going forward.

Page 70: UI Realigning & Refactoring by Jina Bolton

Refactor when you’re addingsomething new.

Refactor when you’re fixing an issue.

Refactor during code reviews.

Page 71: UI Realigning & Refactoring by Jina Bolton

}01 // VENDOR LIBRARIES

02 // DEPENDENCIES

03 // FOUNDATION

04 // COMPONENTS

05 // REGIONS

06 // HELPERS

07 // RESPONSIVE

08 // TOOLS

Put new CSS in the proper place.

Move old CSS as you come to it in refactors.Have some tech debt time? Move more CSS.

Page 72: UI Realigning & Refactoring by Jina Bolton

Stay organized!

Page 73: UI Realigning & Refactoring by Jina Bolton

app/views/layouts

components/

dependencies/

foundation/

helpers/regions/

_banner.sass

_contentinfo.sass

responsive/tools/

vendor/

deathstar.css.scss

kenobi.css.scss

components/

regions/

_banner.haml

_contentinfo.haml

deathstar.haml

kenobi.haml

app/assets/stylesheets

Page 74: UI Realigning & Refactoring by Jina Bolton

app/assets/javascripts

components/

dependencies/

foundation/

helpers/regions/

responsive/

tools/

vendor/

deathstar.css.scss

kenobi.css.scss

components/

responsive/

tools/

vendor/

jquery.js

modernizr.js

deathstar.js.coffee

kenobi.js.coffee

app/assets/stylesheets

Page 75: UI Realigning & Refactoring by Jina Bolton

app/assets/images

components/

icons/

dependencies/foundation/

helpers/

regions/

responsive/

tools/

vendor/

deathstar.css.scss

kenobi.css.scss

components/

icons/

textures/

logos/

regions/

vendor/

app/assets/stylesheets

Page 76: UI Realigning & Refactoring by Jina Bolton

Make a UI Library03 //

Page 78: UI Realigning & Refactoring by Jina Bolton

Content (text, lists, tables)

Navigation (tabs, pagination, filters, sorters, indexes)

Status (progress, alerts, toasts)

Interaction (forms, pickers, modals, drawers, toggles)

Icons (consider SVG or fonts)

Page 79: UI Realigning & Refactoring by Jina Bolton

Show object &all associated states.

Page 80: UI Realigning & Refactoring by Jina Bolton

GUMBY FRAMEWORK’S UI KIT

Page 81: UI Realigning & Refactoring by Jina Bolton

Keep documentation current & useful.

Page 83: UI Realigning & Refactoring by Jina Bolton

STYLEDOCCO USED ON BOOTSTRAP

Page 84: UI Realigning & Refactoring by Jina Bolton

Get to know the tools you use.

04 //

Page 85: UI Realigning & Refactoring by Jina Bolton

USING CHROME INSPECTOR

Page 86: UI Realigning & Refactoring by Jina Bolton

Start at the element, then work outwards.

Page 87: UI Realigning & Refactoring by Jina Bolton

Use the CSS editor to debug quickly.

Page 88: UI Realigning & Refactoring by Jina Bolton

Don’t accidentally refresh all yourchanges away!

Page 89: UI Realigning & Refactoring by Jina Bolton

USING SUBLIME’S SEARCH TOOLS

Page 90: UI Realigning & Refactoring by Jina Bolton

COMMAND + P

to find things quickly

Page 91: UI Realigning & Refactoring by Jina Bolton

COMMAND + SHIFT + F

to see a full list of results in your project

Page 92: UI Realigning & Refactoring by Jina Bolton

If the selector or image is not used anywhere, it’s probably safe to delete it.

Page 93: UI Realigning & Refactoring by Jina Bolton

Red is a wonderful color to see during pull request reviews!

Page 94: UI Realigning & Refactoring by Jina Bolton

Check how your changes affect the object in the style guide.

If the object you’re refactoring isn’t in the style guide, add it.

Validate & Test.

Page 95: UI Realigning & Refactoring by Jina Bolton

During larger refactors, focus on one area at a time.

05 //

Page 96: UI Realigning & Refactoring by Jina Bolton

Color

Typography

Layout

Page 97: UI Realigning & Refactoring by Jina Bolton

ColorMAINTAINABILITY WITH SASS & STYLE GUIDES

Page 98: UI Realigning & Refactoring by Jina Bolton

Create a simple color palette. Use Sass to make variations.

Page 99: UI Realigning & Refactoring by Jina Bolton

OUTPUT

$x: #369;$y: #fff;

.a { color: lighten($x, 5%);}

.b { color: darken($x, 5%);}

.c { color: saturate($x, 5%);}

.d { color: grayscale($x );}

.e { color: mix($x, $y);}

.a { color: #3973ac; }

.b { color: #2d5986; }

.c { color: #2e669e; }

.d { color: #666666; }

.e { color: #99b2cc; }

SCSS

Page 100: UI Realigning & Refactoring by Jina Bolton

Use your Sass variables to generate a living color palette in your style guide.

Page 101: UI Realigning & Refactoring by Jina Bolton

Make variables for common pairings of colors & Sass color functions, and document it.

Page 102: UI Realigning & Refactoring by Jina Bolton

ENGINE YARD APP CLOUD, EARLY 2011

Page 103: UI Realigning & Refactoring by Jina Bolton

_HEADER.SCSS

// Color palette

$black: #000;

$grey: #eee;

$white: invert($black);

$h-bg-color: $black;

$h-text-color: $grey;

$h-link-color: $white;

.header {

background: $h-bg-color;

color: $h-text-color;

a {

color: $h-link-color;

}

}

_COLORS.SCSS

Page 104: UI Realigning & Refactoring by Jina Bolton

sassme.arc90.com

Page 105: UI Realigning & Refactoring by Jina Bolton

Make mixins for common pairings of background, text,& shadow colors.

Page 106: UI Realigning & Refactoring by Jina Bolton

DO’S POP STRIPE

Page 107: UI Realigning & Refactoring by Jina Bolton

http://codepen.io/jina/pen/iosjp

Page 108: UI Realigning & Refactoring by Jina Bolton

PUKING RAINBOWS

Page 109: UI Realigning & Refactoring by Jina Bolton

TypographyCREATE A SMART SYSTEM

Page 110: UI Realigning & Refactoring by Jina Bolton

Choose a standard base unit.4 is good; it multiplies into 8, 12, 16, etc.

Page 111: UI Realigning & Refactoring by Jina Bolton

DEPENDENCIES/_TYPOGRAPHY.SASS

// For typography, spacing, & grids

$base-unit: 4px

// These are used by both Compass & Susy

$base-font-size: $base-unit * 4

$base-line-height: $base-font-size * 1.5

Page 112: UI Realigning & Refactoring by Jina Bolton

DEPENDENCIES/_TYPOGRAPHY.SASS

$font-size-x-small: $base-font-size * .75

$font-size-small: $base-font-size * .875

$font-size: $base-font-size / 1px

$font-size-large: $base-font-size * 1.125

$font-size-x-large: $base-font-size * 1.375

$font-size-xx-large: $base-font-size * 2.75

$line-height: $base-line-height / $base-font-size

$line-height-reset: 1

Page 113: UI Realigning & Refactoring by Jina Bolton

DEPENDENCIES/_TYPOGRAPHY.SASS

$sans-serif: Helvetica, Arial, sans-serif

$serif: Georgia, serif

$monospace: Menlo, Monaco, Consolas, monospace

Page 114: UI Realigning & Refactoring by Jina Bolton

Create mixins for your various type styles.Small and all caps, big quote styles, etc. Don’t have too many. Document them.

Page 115: UI Realigning & Refactoring by Jina Bolton

LayoutREGIONS & GRID OPTIONS

Page 116: UI Realigning & Refactoring by Jina Bolton

Show layout structures: top-level, category, and detail/edit views.

Page 118: UI Realigning & Refactoring by Jina Bolton

BACKGROUNDS

Page 119: UI Realigning & Refactoring by Jina Bolton

BASELINE GRID

Page 120: UI Realigning & Refactoring by Jina Bolton

BOXES

Page 121: UI Realigning & Refactoring by Jina Bolton

GRID COLUMNS

Page 122: UI Realigning & Refactoring by Jina Bolton

ALL THE TOGGLES!

Page 123: UI Realigning & Refactoring by Jina Bolton

SUSY MAKES IT EASIER TO USE GRIDS

Page 124: UI Realigning & Refactoring by Jina Bolton

Try a responsive iframe sandbox during development.

Page 125: UI Realigning & Refactoring by Jina Bolton

USING IFRAMES TO DEVELOP FOR SMALLER SCREENS FIRST

Page 126: UI Realigning & Refactoring by Jina Bolton

Don’t try to refactor & document everything at once.You’ll likely give up.

Page 127: UI Realigning & Refactoring by Jina Bolton

Do refactor & document going forward, in iterations.

Page 128: UI Realigning & Refactoring by Jina Bolton

“Be regular and orderly in your life so that you may be violent and original in your work.”

—GUSTAVE FLAUBERT

Page 129: UI Realigning & Refactoring by Jina Bolton

@jina

Page 130: UI Realigning & Refactoring by Jina Bolton

jina.me

Page 131: UI Realigning & Refactoring by Jina Bolton

artinmycoffee.com

Page 132: UI Realigning & Refactoring by Jina Bolton

DO.COM

@DOWORKTOGETHER

Page 133: UI Realigning & Refactoring by Jina Bolton

Thank you!