SlideShare a Scribd company logo
1 of 39
Download to read offline
Start your app the better way with
Styled System
Agenda
● History of CSS and it’s original sin
● The key problems of customizing UI component libraries’ styles
● Styled System
● QnA
● References
Everything in CSS is global.
.list { ... }
.list .item { ... }
Name collisions
.list { ... }
.list .item { ... }
.list { ... }
.list .item { ... }
Reusability
OOCSS
BEM
SMACSS
.card-list
Element
A component of a
block
Modifier
State for a block or
element.
Block
A block component
.card-list__item .card-list__item--highlight
Preprocessor /
Postprocessor
LESS
SASS
SCSS
PostCSS
.search-box-mixin(@scope) {
.@{scope}-search-box {
.search-input {
border: 1px solid @gray;
}
.tooltip {
margin: 8px 0 0 1px;
}
}
}
.search-box-mixin('page');
.page-search-box .search-input {
border: 1px solid #ddd;
}
.page-search-box .tooltip {
margin: 8px 0 0 1px;
}
Components are the building blocks of
modern web applications.
CSS Modules
Scope CSS rules locally by
using tools to transform the
class name with a hash.
.3zyde4l
.card-list__item .card-list__item--highlight
.card-list
.ucdIPRBM
.1Jf-igmQ
CSS in JS
Write CSS in components.
import styled from
'styled-components';
const Button = styled.button`
margin: 0 10px;
padding: 10px;
background: #fefefe;
border-radius: 3px;
border: 1px solid #ccc;
color: #525252;
`
Still have some problems...
● Components with inconsistent props.
● How to efficiently implement multiple themes? Like SMASCC…
● How to efficiently implement responsive styles for different devices?
● How to reduce redundant codes for setting media queries or mapping
props to css properties?
Recap
As an user, I care about...
● Is it easy to custom styles?
● Does it support global theme styles and it is easy to custom?
As an developer, I care about...
● Develop UI with HIE’s design.
Ant Design
Step 1: Find the target element by
using inspector.
Step 2: Extend LESS files to custom
button styles.
@import '~antd/lib/button/style/index.less';
@btn-default-color: blue;
button
button font-color: blue
font-color: black
Custom text color
import styled from 'styled-components';
import { Button as AntdButton } from 'antd';
const CustomButton = styled(AntdButton)`
span {
color: blue;
}
}`;
export default CustomButton;
Ant Design
Step 1: Find the target element by
using inspector.
Step 2: Wrap AntdButton by using
CustomButton.
Could it be easier?
Start your app the better way with
Styled System
Consistency Mobile-First
Why Styled System is good?
More concise
codes
Easy to
custom styles
More Concise Codes
Utility functions make codes short and clear,
expressing styles without unnecessary words
Utility functions (1/2)
<Box color='#000 bg='tomato' />
const Box = styled.div`
margin: 15px 0;
padding: 15px;
color: ${(props) => props.color};
background: ${(props) => props.bg};
border-radius: 10px;
`;
const getStyles = ({ color, bg }) => ({
color,
background: bg,
});
const Box = styled.div`
${getColor};
margin: 15px 0;
padding: 15px;
border-radius: 10px;
`;
Utility functions (2/2)
import { color } from 'styled-system';
const Box = styled.div`
${color}
margin: 15px 0;
padding: 15px;
border-radius: 10px;
`;
const getStyles = ({ color, bg }) => ({
color,
background: bg,
});
const Box = styled.div`
${getColor};
margin: 15px 0;
padding: 15px;
border-radius: 10px;
`;
Styled
System
Consistency
Make components with consistent prop names
Inconsistent props
<Button color='black'>Click</Button> <Label fontColor='white'>$</Label>
<Button color='black'>Click</Button> <Label color='white'>$</Label>
Use color utility
function in
Styled System
Easy to custom styles
● Define global theme by a config object
● Define individual component styles by variants
Theming
Utilizing `<ThemeProvider>` and pass the theme object from root node to provide
global theme.
<ThemeProvider theme={theme}>
<Box color='black' bg='tomato'/>
</ThemeProvider>
const theme = {
color: {
black: '#333',
},
bg: {
tomato: 'tomato',
},
};
Define component styles in theme object
const theme = {
buttons: {
danger: {
color: 'white',
background: '#f25e7a'
},
size: {
default: { height: 50 },
large: { height: 100 }
}
}
};
<Button variant="danger" size="large" />
const buttonStyle = variant({ key:
'buttons'});
const buttonSizeStyle = variant({
prop: 'size', key: 'buttons.size' });
const Button = styled.div`
${buttonStyle}
${buttonSizeStyle}
padding: 15px;
`;
Variants
Use variants to define component styles.
<Box variant='secondary'/>
import { variant } from 'styled-system';
const Box = styled('div')(
variant({
variants: {
primary: {
color: 'black',
bg: 'tomato'
},
secondary: {
color: 'black',
bg: 'yellow'
},
},
}),
);
<Box variant='primary' />
Mobile-First
Create mobile-first responsive layouts with
array syntax
Responsive styles
Create mobile-first responsive layouts with ease by using an array syntax.
.thing {
font-size: 16px;
width: 100%;
}
@media screen and (min-width: 40em) {
font-size: 20px;
width: 50%;
}
@media screen and (min-width: 52em) {
font-size: 24px;
}
<Thing
fontSize={[ 16, 20, 24 ]}
width={[1, 1/2]}
/>Styled
System
Consistency Mobile-First
Styled System is good!
More concise
codes
Easy to
custom styles
Custom
component styles
<Button>Button</Button>
<Button
variantColor='green'
color='#ddd'
>
Button
</Button>
<Button
bg='#41d2f2'
color='fff'
>
Button
</Button>
Theme
Use theme object to define or
extend theme styles
import { theme } from '@chakra-ui/core';
export default {
...theme,
colors: {
...theme.colors,
brand: {
white: '#fefefe',
blue: '#41d2f2',
yellow: '#f2dc6d',
purple: '#7700bb',
},
},
};
<Button bg='#41d2f2' color='brand.white' />
Responsive
styles
Define values to each
breakpoint respectively
.Box {
width: 100%;
}
@media screen and (min-width: 40em) {
width: 50%;
}
@media screen and (min-width: 52em) {
width: 25%;
}
<Box width={['100%', 1 / 2, 1 / 4]} />
Styles overlapping
Props passed by Styled System should put above the original ones.
const Box = styled.div`
margin: 15px 0;
padding: 15px;
border-radius: 10px;
${color}
`;
const Box = styled.div`
${color}
margin: 15px 0;
padding: 15px;
border-radius: 10px;
`;
Avoid css
overlap
Traditional CSS rules feat. Styled Components
#root div { color: red; } /* in site.css, score: 100 + 1 = 101 */
.jqouBD { color: black; } /* in styled component, score: 10 */
#root div { color: red; } /* in site.css, score: 100 + 1 = 101 */
.jqouBD { color: black !important; } /* in styled component, score: 10000 */
source
Class name without a hash for end-to-end testing
Use a chaninable method “attrs” to attach props to the styled component.
<Button>Click me!</Button>
const Button = styled.button.attrs({ className: 'button-submit' })`...`;
<button class="sc-EHOje button-submit">Click me!</button>
View in
browser
inspector
References
● Styled System https://styled-system.com/
● We need a better UI component library - Styled System http://bit.ly/2roJEsg
● 從 Styled System 看下一代 CSS 技術 https://bit.ly/2u0xvLJ
● The Three Tenets of Styled System http://bit.ly/35ygrcV
● Styled System: Pseudo selectors in Variant http://bit.ly/35yqGhy
● How to create responsive UI with styled-components http://bit.ly/34lhxJ3
● CSS 實戰心法 http://bit.ly/2shXUn4

More Related Content

What's hot

jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017Codemotion
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSSChris Coyier
 
Workshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effectsWorkshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effectsVisual Engineering
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...Sencha
 
[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle
[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle
[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tleFuture Processing
 
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSencha
 
A Tour to MySQL Commands
A Tour to MySQL CommandsA Tour to MySQL Commands
A Tour to MySQL CommandsHikmat Dhamee
 
GQL CheatSheet 1.1
GQL CheatSheet 1.1GQL CheatSheet 1.1
GQL CheatSheet 1.1sones GmbH
 
GQL cheat sheet latest
GQL cheat sheet latestGQL cheat sheet latest
GQL cheat sheet latestsones GmbH
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsRachael L Moore
 
GWT.create 2013: Introduction to GXT
GWT.create 2013: Introduction to GXTGWT.create 2013: Introduction to GXT
GWT.create 2013: Introduction to GXTniloc132
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片cfc
 
GWT.create 2013: Themeing GWT Applications with the Appearance Pattern
GWT.create 2013: Themeing GWT Applications with the Appearance PatternGWT.create 2013: Themeing GWT Applications with the Appearance Pattern
GWT.create 2013: Themeing GWT Applications with the Appearance Patternniloc132
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsRachael L Moore
 
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventHTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventRobert Nyman
 

What's hot (20)

jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
 
The Customizer
The CustomizerThe Customizer
The Customizer
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
 
Polymer 1.0
Polymer 1.0Polymer 1.0
Polymer 1.0
 
Workshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effectsWorkshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effects
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
 
[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle
[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle
[Quality Meetup] M. Górski, M. Boś - Testy UI w Espresso z farmą w tle
 
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
 
[ HackFest.pl 2012] Testing - what for and how
[ HackFest.pl 2012] Testing - what for and how[ HackFest.pl 2012] Testing - what for and how
[ HackFest.pl 2012] Testing - what for and how
 
A Tour to MySQL Commands
A Tour to MySQL CommandsA Tour to MySQL Commands
A Tour to MySQL Commands
 
GQL CheatSheet 1.1
GQL CheatSheet 1.1GQL CheatSheet 1.1
GQL CheatSheet 1.1
 
GQL cheat sheet latest
GQL cheat sheet latestGQL cheat sheet latest
GQL cheat sheet latest
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web Components
 
GWT.create 2013: Introduction to GXT
GWT.create 2013: Introduction to GXTGWT.create 2013: Introduction to GXT
GWT.create 2013: Introduction to GXT
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
 
GWT.create 2013: Themeing GWT Applications with the Appearance Pattern
GWT.create 2013: Themeing GWT Applications with the Appearance PatternGWT.create 2013: Themeing GWT Applications with the Appearance Pattern
GWT.create 2013: Themeing GWT Applications with the Appearance Pattern
 
jQuery
jQueryjQuery
jQuery
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web Components
 
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventHTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
 

Similar to Start your app the better way with Styled System

CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule皮馬 頑
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End MethodologiesArash Manteghi
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with AngularAna Cidre
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Codemotion
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Hatem Mahmoud
 
Lect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptxLect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptxzainm7032
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angularDavid Amend
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & CompassRob Davarnia
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & AnimationNguyen Tuan
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptraghavanp4
 
Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013Paris Android User Group
 
SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant
SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant   SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant
SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant Sencha
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for DevelopersNascenia IT
 

Similar to Start your app the better way with Styled System (20)

CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with Angular
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
 
Css3
Css3Css3
Css3
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Lect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptxLect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptx
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angular
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013
 
WPF - An introduction
WPF - An introductionWPF - An introduction
WPF - An introduction
 
SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant
SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant   SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant
SenchaCon 2016: Theming the Modern Toolkit - Phil Guerrant
 
Webtech File.docx
Webtech File.docxWebtech File.docx
Webtech File.docx
 
Accessibility and css - Lisa Seeman
Accessibility and css - Lisa SeemanAccessibility and css - Lisa Seeman
Accessibility and css - Lisa Seeman
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for Developers
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Start your app the better way with Styled System

  • 1. Start your app the better way with Styled System
  • 2. Agenda ● History of CSS and it’s original sin ● The key problems of customizing UI component libraries’ styles ● Styled System ● QnA ● References
  • 3. Everything in CSS is global.
  • 4. .list { ... } .list .item { ... } Name collisions .list { ... } .list .item { ... } .list { ... } .list .item { ... }
  • 6. OOCSS BEM SMACSS .card-list Element A component of a block Modifier State for a block or element. Block A block component .card-list__item .card-list__item--highlight
  • 7. Preprocessor / Postprocessor LESS SASS SCSS PostCSS .search-box-mixin(@scope) { .@{scope}-search-box { .search-input { border: 1px solid @gray; } .tooltip { margin: 8px 0 0 1px; } } } .search-box-mixin('page'); .page-search-box .search-input { border: 1px solid #ddd; } .page-search-box .tooltip { margin: 8px 0 0 1px; }
  • 8. Components are the building blocks of modern web applications.
  • 9. CSS Modules Scope CSS rules locally by using tools to transform the class name with a hash. .3zyde4l .card-list__item .card-list__item--highlight .card-list .ucdIPRBM .1Jf-igmQ
  • 10. CSS in JS Write CSS in components. import styled from 'styled-components'; const Button = styled.button` margin: 0 10px; padding: 10px; background: #fefefe; border-radius: 3px; border: 1px solid #ccc; color: #525252; `
  • 11. Still have some problems... ● Components with inconsistent props. ● How to efficiently implement multiple themes? Like SMASCC… ● How to efficiently implement responsive styles for different devices? ● How to reduce redundant codes for setting media queries or mapping props to css properties?
  • 12. Recap As an user, I care about... ● Is it easy to custom styles? ● Does it support global theme styles and it is easy to custom? As an developer, I care about... ● Develop UI with HIE’s design.
  • 13. Ant Design Step 1: Find the target element by using inspector. Step 2: Extend LESS files to custom button styles. @import '~antd/lib/button/style/index.less'; @btn-default-color: blue; button button font-color: blue font-color: black Custom text color
  • 14. import styled from 'styled-components'; import { Button as AntdButton } from 'antd'; const CustomButton = styled(AntdButton)` span { color: blue; } }`; export default CustomButton; Ant Design Step 1: Find the target element by using inspector. Step 2: Wrap AntdButton by using CustomButton.
  • 15. Could it be easier?
  • 16. Start your app the better way with Styled System
  • 17. Consistency Mobile-First Why Styled System is good? More concise codes Easy to custom styles
  • 18. More Concise Codes Utility functions make codes short and clear, expressing styles without unnecessary words
  • 19. Utility functions (1/2) <Box color='#000 bg='tomato' /> const Box = styled.div` margin: 15px 0; padding: 15px; color: ${(props) => props.color}; background: ${(props) => props.bg}; border-radius: 10px; `; const getStyles = ({ color, bg }) => ({ color, background: bg, }); const Box = styled.div` ${getColor}; margin: 15px 0; padding: 15px; border-radius: 10px; `;
  • 20. Utility functions (2/2) import { color } from 'styled-system'; const Box = styled.div` ${color} margin: 15px 0; padding: 15px; border-radius: 10px; `; const getStyles = ({ color, bg }) => ({ color, background: bg, }); const Box = styled.div` ${getColor}; margin: 15px 0; padding: 15px; border-radius: 10px; `; Styled System
  • 21. Consistency Make components with consistent prop names
  • 22. Inconsistent props <Button color='black'>Click</Button> <Label fontColor='white'>$</Label> <Button color='black'>Click</Button> <Label color='white'>$</Label> Use color utility function in Styled System
  • 23. Easy to custom styles ● Define global theme by a config object ● Define individual component styles by variants
  • 24. Theming Utilizing `<ThemeProvider>` and pass the theme object from root node to provide global theme. <ThemeProvider theme={theme}> <Box color='black' bg='tomato'/> </ThemeProvider> const theme = { color: { black: '#333', }, bg: { tomato: 'tomato', }, };
  • 25. Define component styles in theme object const theme = { buttons: { danger: { color: 'white', background: '#f25e7a' }, size: { default: { height: 50 }, large: { height: 100 } } } }; <Button variant="danger" size="large" /> const buttonStyle = variant({ key: 'buttons'}); const buttonSizeStyle = variant({ prop: 'size', key: 'buttons.size' }); const Button = styled.div` ${buttonStyle} ${buttonSizeStyle} padding: 15px; `;
  • 26. Variants Use variants to define component styles. <Box variant='secondary'/> import { variant } from 'styled-system'; const Box = styled('div')( variant({ variants: { primary: { color: 'black', bg: 'tomato' }, secondary: { color: 'black', bg: 'yellow' }, }, }), ); <Box variant='primary' />
  • 27. Mobile-First Create mobile-first responsive layouts with array syntax
  • 28. Responsive styles Create mobile-first responsive layouts with ease by using an array syntax. .thing { font-size: 16px; width: 100%; } @media screen and (min-width: 40em) { font-size: 20px; width: 50%; } @media screen and (min-width: 52em) { font-size: 24px; } <Thing fontSize={[ 16, 20, 24 ]} width={[1, 1/2]} />Styled System
  • 29. Consistency Mobile-First Styled System is good! More concise codes Easy to custom styles
  • 30.
  • 31.
  • 33. Theme Use theme object to define or extend theme styles import { theme } from '@chakra-ui/core'; export default { ...theme, colors: { ...theme.colors, brand: { white: '#fefefe', blue: '#41d2f2', yellow: '#f2dc6d', purple: '#7700bb', }, }, }; <Button bg='#41d2f2' color='brand.white' />
  • 34. Responsive styles Define values to each breakpoint respectively .Box { width: 100%; } @media screen and (min-width: 40em) { width: 50%; } @media screen and (min-width: 52em) { width: 25%; } <Box width={['100%', 1 / 2, 1 / 4]} />
  • 35.
  • 36. Styles overlapping Props passed by Styled System should put above the original ones. const Box = styled.div` margin: 15px 0; padding: 15px; border-radius: 10px; ${color} `; const Box = styled.div` ${color} margin: 15px 0; padding: 15px; border-radius: 10px; `; Avoid css overlap
  • 37. Traditional CSS rules feat. Styled Components #root div { color: red; } /* in site.css, score: 100 + 1 = 101 */ .jqouBD { color: black; } /* in styled component, score: 10 */ #root div { color: red; } /* in site.css, score: 100 + 1 = 101 */ .jqouBD { color: black !important; } /* in styled component, score: 10000 */ source
  • 38. Class name without a hash for end-to-end testing Use a chaninable method “attrs” to attach props to the styled component. <Button>Click me!</Button> const Button = styled.button.attrs({ className: 'button-submit' })`...`; <button class="sc-EHOje button-submit">Click me!</button> View in browser inspector
  • 39. References ● Styled System https://styled-system.com/ ● We need a better UI component library - Styled System http://bit.ly/2roJEsg ● 從 Styled System 看下一代 CSS 技術 https://bit.ly/2u0xvLJ ● The Three Tenets of Styled System http://bit.ly/35ygrcV ● Styled System: Pseudo selectors in Variant http://bit.ly/35yqGhy ● How to create responsive UI with styled-components http://bit.ly/34lhxJ3 ● CSS 實戰心法 http://bit.ly/2shXUn4