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
Atomic CSS with Fela
Search
Ben Smithett
July 01, 2020
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Atomic CSS with Fela
Ben Smithett
July 01, 2020
More Decks by Ben Smithett
See All by Ben Smithett
Objects in Space: A practical guide to CSS display, position & z-index
bensmithett
0
74
The 12MB Web Page: A tale of perfect PageSpeed scores & developer happiness
bensmithett
1
350
The UI is an Application
bensmithett
0
1.2k
Hands on with the modern front end stack
bensmithett
0
1.3k
The New Front End Stack: A really really really high level introduction
bensmithett
1
550
Smarter Sass/Less Builds with Webpack (MelbJS Edition)
bensmithett
0
350
Smarter Sass builds with Webpack
bensmithett
1
250
Faking Real Time: Optimistic Updates & Eventual Consistency (Decompress 2015)
bensmithett
0
510
Other Decks in Programming
See All in Programming
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
act1-costs.pdf
sumedhbala
0
120
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.3k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
220
Agentic UI
manfredsteyer
PRO
0
200
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
180
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
120
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
810
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.9k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Into the Great Unknown - MozCon
thekraken
41
2.6k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
170
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
240
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
We Have a Design System, Now What?
morganepeng
55
8.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Transcript
Atomic CSS with
What is Atomic CSS? compose styles directly on HTML tags
instead of in abstract CSS classes
Normal: style composition in CSS classes .header { background: black;
padding: 10px; display: flex; } <div class='header'>
Normal: style composition in CSS classes .header { background: black;
padding: 10px; display: flex; } <div class='header'> Not normal: inline styles <div style='background: black; padding: 10px; display: flex;'>
Atomic CSS .bg-black { background: black; } .padding-s { padding:
10px; } .flex { display: flex; } <div class='bg-black padding-s flex'> Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; } <div class='header'> Not normal: inline styles <div style='background: black; padding: 10px; display: flex;'>
why? Atomic CSS .bg-black { background: black; } .padding-s {
padding: 10px; } .flex { display: flex; } <div class='bg-black padding-s flex'> Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; } <div class='header'> Not normal: inline styles <div style='background: black; padding: 10px; display: flex;'> 🚀P🚀E🚀R🚀F🚀O🚀R🚀M🚀A🚀N🚀C🚀E🚀 (among other reasons)
developing new features the normal way:
header.css .header { background: black; padding: 10px; display: flex; }
.header-logo { border: 0; }
header.css .header { background: black; padding: 10px; display: flex; }
.header-logo { border: 0; } footer.css .footer { background: black; padding: 10px; display: grid; } .footer-links { display: flex; flex-direction: column; }
CSS size (kb) Features added over time
CSS size (kb) Features added over time 🐌
CSS size (kb) Features added over time 🐌 code splitting
CSS size (kb) Features added over time 🐌 code splitting
CSS Modules `composes`
CSS size (kb) Features added over time 🐌 code splitting
CSS Modules `composes` lazy-load below-the-fold sections
header.css .header { background: black; padding: 10px; display: flex; }
.header-logo { border: 0; } footer.css .footer { background: black; padding: 10px; display: grid; } .footer-links { display: flex; flex-direction: column; }
developing new features with Atomic CSS:
styles.css .bg-black { background: black; } .padding-s { padding: 10px;
} .flex { display: flex; } .border-0 { border: 0; } header.template <div class='bg-black padding-s flex'> <img class='border-0' /> </div>
styles.css .bg-black { background: black; } .padding-s { padding: 10px;
} .flex { display: flex; } .border-0 { border: 0; } .grid { display: grid; } .flex-col { flex-direction: column; } header.template <div class='bg-black padding-s flex'> <img class='border-0' /> </div> footer.template <div class='bg-black padding-s grid'> <div class='flex flex-col' /> </div>
styles.css .bg-black { background: black; } .padding-s { padding: 10px;
} .flex { display: flex; } .border-0 { border: 0; } .grid { display: grid; } .flex-col { flex-direction: column; } header.template <div class='bg-black padding-s flex'> <img class='border-0' /> </div> footer.template <div class='bg-black padding-s grid'> <div class='flex flex-col' /> </div>
CSS size (kb) Features added over time
yay! but...
Hand-coding Atomic CSS is gross Learning an abstraction bg-black border-xl
flex pad-s instead of just writing the CSS you already know
Hand-coding Atomic CSS is gross bg-black border-xl flex pad-s not
CSS not on MDN
what if we could write dev-friendly not-very-performant-looking real CSS ...but
ship atomic classes?
write the CSS you know generate atomic classes
header.js <div className={css({ background: 'black', padding: 10, display: 'flex' })}>
<img className={css({ border: 0 })} /> </div>
header.js <div className={css({ background: 'black', padding: 10, display: 'flex' })}>
<img className={css({ border: 0 })} /> </div> footer.js <div className={css({ background: 'black', padding: 10, display: 'grid' })}> <div className={css({ display: 'flex',( flexDirection: 'column' })} /> </div>
header.js <div className={css({ background: 'black', a padding: 10, b display:
'flex' c })}> <img className={css({ border: 0 d })} /> </div> footer.js <div className={css({ background: 'black', a padding: 10, b display: 'grid' e })}> <div className={css({ display: 'flex',( c flexDirection: 'column' f })} /> </div>
header.js <div className={css({ background: 'black', a padding: 10, b display:
'flex' c })}> <img className={css({ border: 0 d })} /> </div> footer.js <div className={css({ background: 'black', a padding: 10, b display: 'grid' e })}> <div className={css({ display: 'flex',( c flexDirection: 'column' f })} /> </div> output HTML // header <div class='a b c'> <img class='d' /> </div> // footer <div class='a b e'> <div class='c f' /> </div> output CSS .a { background: black } .b { padding: 10px } .c { display: flex } .d { border: 0 } .e { display: grid } .f { flex-direction: column }
header.js <div className={css({ background: 'black', padding: 10, display: 'flex' })}>
<img className={css({ border: 0 })} /> </div> footer.js <div className={css({ background: 'black', padding: 10, display: 'grid' })}> <div className={css({ display: 'flex',( flexDirection: 'column' })} /> </div> 😱 CSS in JS!
It's the output that matters Authoring style is flexible 🙂
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div>
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div> import from another file import {root, logo} from './header.css.js' <div className={css(root)}> <img className={css(logo)} /> </div>
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div> import from another file import {root, logo} from './header.css.js' <div className={css(root)}> <img className={css(logo)} /> </div> (with enough Webpack tomfoolery)
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div> import from another file import {root, logo} from './header.css.js' <div className={css(root)}> <img className={css(logo)} /> </div> (with enough Webpack tomfoolery) Styled Components const Root = styled.div` background: black; padding: 10px; display: flex; ` const Logo = styled.img` border: 0; ` <Root> <Logo /> </Root>
You choose how you write CSS (IMHO just use JS
objects, ask me why later) Fela gives you optimised output
Unlearn "clever" optimisations
CSS size (kb) Features added over time 🐌 code splitting
CSS Modules `composes` lazy-load below-the-fold sections
CSS Modules `composes` code splitting lazy-load below-the-fold sections 🗑
🗑 📄 📄 📄 CSS files
<html> <head> <style>.a{background:black}.b{padding:10px}.c{display:flex}.d{border:0}</style> </head> <body> <div class='a b c'> <img
class='d' /> </div> <body> </html> just inline the initial render's CSS in <head>
fela.js.org styletron.org sanblas.netlify.app inspect new facebook.com in devtools Show me
more!