Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Pattern Placeholders
Search
Jaime Caballero
January 21, 2015
Programming
3
65
Pattern Placeholders
Thinking about the ways of using @extend and placeholders.
Jaime Caballero
January 21, 2015
Tweet
Share
Other Decks in Programming
See All in Programming
The Implementations of Advanced LR Parser Algorithm
junk0612
1
390
Memory API : Patterns, Performance et Cas d'Utilisation
josepaumard
0
140
ASP.NETアプリケーションのモダナイゼーションについて
tomokusaba
0
120
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.5k
AIコーディングの理想と現実
tomohisa
30
34k
AI時代の開発者評価について
ayumuu
0
190
AI Coding Agent Enablement - エージェントを自走させよう
yukukotani
14
6.2k
生成AIを使ったQAアプリケーションの作成 - ハンズオン補足資料
oracle4engineer
PRO
3
250
Being an ethical software engineer
xgouchet
PRO
0
210
AWS で実現する安全な AI エージェントの作り方 〜 Bedrock Engineer の実装例を添えて 〜 / how-to-build-secure-ai-agents
gawa
8
860
スモールスタートで始めるためのLambda×モノリス(Lambdalith)
akihisaikeda
2
300
Contribute to Comunities | React Tokyo Meetup #4 LT
sasagar
0
550
Featured
See All Featured
Faster Mobile Websites
deanohume
306
31k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
23
2.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.4k
Statistics for Hackers
jakevdp
798
220k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
The Cult of Friendly URLs
andyhume
78
6.3k
StorybookのUI Testing Handbookを読んだ
zakiyama
29
5.7k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Raft: Consensus for Rubyists
vanstee
137
6.9k
Transcript
%Pattern Placeholders Jaime Caballero - LDN Sass #2 GIF Source:
giphy.com 21/01/2015
None
hi, I’m jaime
jamie james jiame jaime
None
None
• spanish • frontend architect • sass lover
None
None
None
this is me when I’m using Sass
None
this is me when somebody hands me over vanilla CSS
None
me gusta • SMACSS • OOCSS • DRYCSS • BEM
I worry a lot about keeping my CSS scalable and
organised
this is me going through my CSS workflow
None
let’s talk about @extend 1.
@extend combines selectors
.foo
.foo{ color: black; }
.another
.another{ color: black; }
.another{ @extend .foo; }
.another{ @extend .foo; background: white; }
.foo, .another{ color: black; } .another{ background: white; }
combining selectors means no repeating CSS chunks
this is me when I discovered @extend
None
BUT!
we can’t extend without a selector, can we?
.foo{ color: black; }
None
introducing placeholder selectors 2.
if you don’t @extend them, they will not be in
the CSS
.foo
%foo
%foo{ color: black; }
you can have anything in one place, ready to use
BUT!
i’m not here to say @extend FTW
None
all this has its limitations
you can’t extend in a @media query
%foo{ color: black; } @media (min-width: 20em){ .another{ @extend %foo;
} }
you can easily get loads of selectors
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,
that was 46 selectors for 1 property
i like to call this aggressive extending
this is me when i see any of it
None
we are the problem 3.
people are complaining
None
BUT!
we are the ones extending the wrong way
we have to think outside the box
embrace these limitations
you can’t extend in a @media query?
but you can put a media query in a placeholder
%foo{ color: black; } @media (min-width: 20em){ .another{ @extend .foo;
} }
%foo{ }
%foo{ @media (min-width: 20em){ } }
%foo{ @media (min-width: 20em){ color: black; } }
%foo{ @media (min-width: 20em){ color: black; } } .another{ @extend
%foo; }
@media (min-width: 20em){ .another{ color: black; } }
implement placeholder patterns
%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{ @extend %nav-fixed; }
%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{ @extend %nav-offcanvas; }
%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{ @extend %nav-footeranch; }
placeholders for everything
%foo{…} %foo--good{…} %foo--bad{…}
combine them
.Foo.is-good{ @extend %foo; @extend %foo--good; }
separate them
.Foo{ @extend %foo; } .is-good{ @extend %foo--good; }
BEM? SUITCSS? whatever works
None
placeholder patterns add another abstraction layer
you can create naming-agnostic CSS systems
when you only use placeholders
it’s easier to notice a repeated/wrong pattern
.button--action{ @extend %btn; @extend %btn--big; @extend %bg--green; }
BUT!
what about agressive extending ?
agressive extending: fixed 4.
what if we could limit the amount of selectors
?
None
actually, we need to set a selector budget
a warning when we don’t extend properly
a weekend after (last weekend)
this is me after last weekend
None
jaicab.com/ext/
the ext(); mixin sets a selector budget and warns you
(@warn) when you are:
extending too much
extending the same pair (selector, placeholder) more than once
extending twice doesn’t affect your CSS, but it is a
bad organisation practise
this is how it works
&
html, .foo, .another
$selectors: &;
getting started
bower install ext
@import the _ext.scss file into your project
set your selector budget
$ext-budget: ( total: 15 );
it only works with placeholders
use ext(placeholder);
%foo{ color: black; } .another{ @include ext(foo); }
go nuts!
None
None
is @warn not enough?
enable debug mode
add ext-debug(); after all your @imports
None
None
set a targeted budget
$ext-budget: ( total: 15, heading: 12 );
want to see more? change the options
$ext-options: ( warn-over: true, warn-duplicates: true, over-only: true, show-all: true
);
None
there’s much more
but enough for today
None
go to github.com/jaicab/ext/
None
play with it open an issue send me a pull
request fire me a tweet
thank you! jaicab.com/ext/ @jaicab_ Links: http://bit.ly/1JeTmtr