Slide 1

Slide 1 text

%Pattern Placeholders Jaime Caballero - LDN Sass #2 GIF Source: giphy.com 21/01/2015

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

hi, I’m jaime

Slide 4

Slide 4 text

jamie james jiame jaime

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

• spanish • frontend architect • sass lover

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

this is me when I’m using Sass

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

this is me when somebody hands me over vanilla CSS

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

me gusta • SMACSS • OOCSS • DRYCSS • BEM

Slide 16

Slide 16 text

I worry a lot about keeping my CSS scalable and organised

Slide 17

Slide 17 text

this is me going through my CSS workflow

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

let’s talk about @extend 1.

Slide 20

Slide 20 text

@extend combines selectors

Slide 21

Slide 21 text

.foo

Slide 22

Slide 22 text

.foo{ color: black; }

Slide 23

Slide 23 text

.another

Slide 24

Slide 24 text

.another{ color: black; }

Slide 25

Slide 25 text

.another{ @extend .foo; }

Slide 26

Slide 26 text

.another{ @extend .foo; background: white; }

Slide 27

Slide 27 text

.foo, .another{ color: black; } .another{
 background: white;
 }

Slide 28

Slide 28 text

combining selectors means no repeating CSS chunks

Slide 29

Slide 29 text

this is me when I discovered @extend

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

BUT!

Slide 32

Slide 32 text

we can’t extend without a selector, can we?

Slide 33

Slide 33 text

.foo{ color: black; }

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

introducing placeholder selectors 2.

Slide 36

Slide 36 text

if you don’t @extend them, they will not be in the CSS

Slide 37

Slide 37 text

.foo

Slide 38

Slide 38 text

%foo

Slide 39

Slide 39 text

%foo{ color: black; }

Slide 40

Slide 40 text

you can have anything in one place, ready to use

Slide 41

Slide 41 text

BUT!

Slide 42

Slide 42 text

i’m not here to say @extend FTW

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

all this has its limitations

Slide 45

Slide 45 text

you can’t extend in a @media query

Slide 46

Slide 46 text

%foo{ color: black; } @media (min-width: 20em){ .another{ @extend %foo; } }

Slide 47

Slide 47 text

you can easily get 
 loads of selectors

Slide 48

Slide 48 text

a.icon-listen-bl:hover, .event-related .box-title a:hover, .category-related .box-title a:hover, .readmore a:hover, .footer a:hover, .pagination a:hover, .news a:hover, .latest-tweet .date a:hover, .feature .box-header .title a:hover, .caption .title a:hover, .full-agenda-link a:hover,

Slide 49

Slide 49 text

that was 46 selectors for 1 property

Slide 50

Slide 50 text

i like to call this aggressive extending

Slide 51

Slide 51 text

this is me when i see any of it

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

we are the problem 3.

Slide 54

Slide 54 text

people are complaining

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

BUT!

Slide 57

Slide 57 text

we are the ones extending the wrong way

Slide 58

Slide 58 text

we have to think outside the box

Slide 59

Slide 59 text

embrace these limitations

Slide 60

Slide 60 text

you can’t extend in a @media query?

Slide 61

Slide 61 text

but you can put a media query in a placeholder

Slide 62

Slide 62 text

%foo{ color: black; } @media (min-width: 20em){ .another{ @extend .foo; } }

Slide 63

Slide 63 text

%foo{ }

Slide 64

Slide 64 text

%foo{ @media (min-width: 20em){ } }

Slide 65

Slide 65 text

%foo{ @media (min-width: 20em){ color: black; } }

Slide 66

Slide 66 text

%foo{ @media (min-width: 20em){ color: black; } } .another{ @extend %foo; }

Slide 67

Slide 67 text

@media (min-width: 20em){ .another{ color: black; } }

Slide 68

Slide 68 text

implement placeholder patterns

Slide 69

Slide 69 text

%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{
 @extend %nav-fixed;
 }

Slide 70

Slide 70 text

%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{
 @extend %nav-offcanvas;
 }

Slide 71

Slide 71 text

%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{
 @extend %nav-footeranch;
 }

Slide 72

Slide 72 text

placeholders for everything

Slide 73

Slide 73 text

%foo{…} %foo--good{…} %foo--bad{…}

Slide 74

Slide 74 text

combine them

Slide 75

Slide 75 text

.Foo.is-good{
 @extend %foo; @extend %foo--good;
 }

Slide 76

Slide 76 text

separate them

Slide 77

Slide 77 text

.Foo{ @extend %foo; } .is-good{ @extend %foo--good;
 }

Slide 78

Slide 78 text

BEM? SUITCSS?
 whatever works

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

placeholder patterns add another abstraction layer

Slide 81

Slide 81 text

you can create naming-agnostic CSS systems

Slide 82

Slide 82 text

when you only use placeholders

Slide 83

Slide 83 text

it’s easier to notice a repeated/wrong pattern

Slide 84

Slide 84 text

.button--action{
 @extend %btn; @extend %btn--big; @extend %bg--green;
 }

Slide 85

Slide 85 text

BUT!

Slide 86

Slide 86 text

what about agressive extending
 ?

Slide 87

Slide 87 text

agressive extending: fixed 4.

Slide 88

Slide 88 text

what if we could 
 limit the amount of selectors
 ?

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

actually, we need to set a selector budget

Slide 91

Slide 91 text

a warning when we don’t extend properly

Slide 92

Slide 92 text

a weekend after 
 (last weekend)

Slide 93

Slide 93 text

this is me after last weekend

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

jaicab.com/ext/

Slide 96

Slide 96 text

the ext(); mixin sets a selector budget and warns you (@warn) when you are:

Slide 97

Slide 97 text

extending too much

Slide 98

Slide 98 text

extending the same pair (selector, placeholder)
 more than once

Slide 99

Slide 99 text

extending twice doesn’t affect your CSS, but it is a bad organisation practise

Slide 100

Slide 100 text

this is how it works

Slide 101

Slide 101 text

&

Slide 102

Slide 102 text

html, .foo, .another

Slide 103

Slide 103 text

$selectors: &;

Slide 104

Slide 104 text

getting started

Slide 105

Slide 105 text

bower install ext

Slide 106

Slide 106 text

@import the _ext.scss file into your project

Slide 107

Slide 107 text

set your selector budget

Slide 108

Slide 108 text

$ext-budget: ( total: 15 );

Slide 109

Slide 109 text

it only works with placeholders

Slide 110

Slide 110 text

use ext(placeholder);

Slide 111

Slide 111 text

%foo{ color: black; } .another{ @include ext(foo); }

Slide 112

Slide 112 text

go nuts!

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

is @warn not enough?

Slide 116

Slide 116 text

enable debug mode

Slide 117

Slide 117 text

add ext-debug(); after all your
 @imports

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

set a targeted budget

Slide 121

Slide 121 text

$ext-budget: ( total: 15, heading: 12 );

Slide 122

Slide 122 text

want to see more? change the options

Slide 123

Slide 123 text

$ext-options: ( warn-over: true, warn-duplicates: true, over-only: true, show-all: true );

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

there’s much more

Slide 126

Slide 126 text

but enough for today

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

go to 
 github.com/jaicab/ext/

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

play with it open an issue send me a pull request fire me a tweet

Slide 131

Slide 131 text

thank you! jaicab.com/ext/ @jaicab_ Links: http://bit.ly/1JeTmtr