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
CSS Modules, CSS Variables and the Future of Re...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Glen Maddern
May 11, 2016
Technology
1.3k
9
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSS Modules, CSS Variables and the Future of Reusable CSS
Presented at CSSConf Budapest, 2016 <3
Glen Maddern
May 11, 2016
More Decks by Glen Maddern
See All by Glen Maddern
The Road to Styled Components & the Road Ahead
geelen
2
250
The Road to Styled Components
geelen
2
1.5k
Styled Components and the Road to Unification
geelen
2
300
The Future of Reusable CSS
geelen
2
230
Other Decks in Technology
See All in Technology
キャリアLT会#3
beli68
2
240
探索・可視化・自動化を一本化 Amazon Quickでデータ活用スピードを上げる方法
koheiyoshikawa
0
170
AI、CDK と協働する Full TypeScript アプリケーション開発 / Full TypeScript Application with AI and CDK
geekplus_tech
2
480
AI Native なプロダクト組織の立ち上げ方 : 生産性 100 倍への挑戦
mikesorae
0
1.3k
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.5k
生成 AI 時代にいま一度「問い合わせ」について考えてみる
kazzpapa3
1
130
ファミコンでPHPを動かす / PHP on the Famicom
tomzoh
2
610
事業成長とAI活用を止めないデータ基盤アーキテクチャの設計思想
hiracky16
0
520
AI時代のPlaywright活用(システムテストを自動化する ー 実行エンジンにPla ywrightを選んだ理由)
ynisqa1988
2
940
kaonavi Tech Night#1
kaonavi
0
160
AmplifyHostingConstructからSSRフレームワークのためのホスティング設計を考察する/amplify-hosting-construct
fossamagna
1
300
VPCセキュリティ対応の最新事情
nagisa53
1
270
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
160
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
640
Faster Mobile Websites
deanohume
310
32k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Amusing Abliteration
ianozsvald
1
240
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
740
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Producing Creativity
orderedlist
PRO
348
40k
Leo the Paperboy
mayatellez
8
1.9k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Prompt Engineering for Job Search
mfonobong
0
380
Test your architecture with Archunit
thirion
1
2.3k
Transcript
Reusable CSS CSS VARIABLES, CSS MODULES & THE FUTURE OF
@glenmaddern
HELLO BUDAPEST! ♥
Reusable CSS CSS VARIABLES, CSS MODULES & THE FUTURE OF
@glenmaddern
None
WHY IS IT SO HARD TO SHARE CSS?
WHY IS IT SO HARD TO REUSE CSS?
import something from 'somewhere' something.leftPad()
THE HUMAN BRAIN IS A (IN)CONSISTENCY-DETECTING MACHINE
http://semantic-ui.com
http://semantic-ui.com
http://semantic-ui.com
http://www.novolume.co.uk/blog/all-websites-look-the-same/
http://graphicriver.net/
None
WE DON'T NEED MORE TOOLING TO MAKE OUR CURRENT COMPONENTS
THEMEABLE WE NEED TO START BUILDING BETTER COMPONENTS
st ep #1
RESPONSIVE COMPONENTS
A COMPONENT SHOULD RESPOND TO ITS ENVIRONMENT • • RATHER
THAN THE ENVIRONMENT OVERRIDING THE COMPONENT
OUTSIDE-IN OVERRIDES
https://en.wikipedia.org/wiki/Margaret_Hamilton_(scientist)
http://semantic-ui.com
MAKE YOUR COMPONENTS LESS RESPONSIBLE & MORE RESPONSIVE
layout
PADDING CONTENT MARGIN
PADDING CONTENT MARGIN
.component { width: 50%; margin-top: 2rem; flex-grow: 1; } ❌
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } ONE ONE TWO ONE TWO THREE
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } .parent > * + * { margin-left: 1rem; } ONE ONE TWO ONE TWO THREE
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } .parent > * + * { margin-left: 1rem; } .parent > :first-child { flex: 0 0 50%; } ONE TWO ONE TWO THREE ONE TWO THREE FOUR
LAYOUT IS THE CONCERN OF THE p arent
DEMO: CURRENTCOLOR
https://www.youtube.com/watch?v=jPOBVaomzLE
css v ari able s
http://caniuse.com/#feat=css-variables
CSS CUSTOM PROPERTIES CSS VARIABLES =
.component { --size: 2rem; width: calc(2 * var(--size)); height: var(--size);
} .component
.component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:
var(--size); } .component .container .component .container { --spacing: 1rem; }
.component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:
var(--size); } .component .component.large .large { --spacing: 4rem; /* or */ --size: 4rem; }
.component { background: var(--bg, black); color: var(--fg, white); }
.component { background: var(--bg, black); color: var(--fg, white); } (bg,
fg) => <Component style.../>
DEMO: INVERTED BUTTON
INHERITANCE THE CASCADE vs
st ep #2
EXPLICIT COMPONENTS
http://semantic-ui.com/elements/button.html
http://jxnblk.com/rebass/#Button
DEMO: DOCUMENTATION
NAMING MISMATCHES?
.container .container { --grid-size: 1rem; } .component .component .component {
--size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
.component .container .component.fix .container { --grid-size: 1rem; } .fix {
--spacing: var(--grid-size); } .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
st ep #3
RESILIENT COMPONENTS
w arning: re act
import styles from './MediaObject.css' const MediaObject = ({ title, image,
text }) => ( <div className={styles.outer}> <img className={styles.img} src={ image }/> <div className={styles.inner}> <h1 className={styles.h1}>{ title }</h1> <p className={styles.p}>{ text }</p> </div> </div> )
import styles from './MediaObject.css' const MediaObject = ({ title, image,
text, theme=styles }) =>( <div className={theme.outer}> <img className={theme.img} src={ image }/> <div className={theme.inner}> <h1 className={theme.h1}>{ title }</h1> <p className={theme.p}>{ text }</p> </div> </div> ) https://github.com/css-modules/css-modules/issues/147
DEMO: INTERNAL STRUCTURE DOCS
✅ RESPOND TO ENVIRONMENT ✅ USE INTERNAL VARIABLES ✅ EXPOSE
INTERNAL STRUCTURE
t hank you! @glenmaddern