Share
Embed
We need a better UI component library - Styled System
2019/8/28
@ 2019 Modern Web
我們開發網站時,可能會使用 UI Library 讓專案開發更有效率,例如:早期的動態網站,透過 Bootstrap 或是 Pure CSS 等 CSS Framework ,幫助我們快速建立網站。
但隨著前端技術的演進,SPA (Single Page Application)架構興起,這些 CSS Framework 已經不太適合在「元件化」的專案裡使用,我們可能需要自己封裝,或是使用已經封裝好的 UI Library。
像是 Material-UI、Ant Design 等元件化的 UI Library,能夠讓我們直接透過 JavaScript 套用 UI Library,可以更方便使用別人撰寫好的樣式,但同時也失去了彈性,如果需要開發客製化的網站,我們不再像以前可以直接的修改 HTML 結構或是 CSS 樣式,使用這些 UI Component Libraries 反而提高專案維護的困難度。
如今我們希望能夠有一套 UI component Library 可以同時具有元件化的方便性,又能夠達成客製化的需求,透過 Styled System 幫助我們建立更有彈性的元件,組裝出屬於自己風格的網站!
Anna Su
August 28, 2019
Transcript
141 slides
-
Your Title Here This is the content area... OK Cancel
Your Title Here This is the content area... OK Cancel Modal -
2011 Bootstrap 2017 Pure CSS Material UI 2018 Ant Design
2016 Blueprint Semantic UI 2014 -
Card title Some quick example text to build on the
card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. -
Card title Some quick example text to build on the
card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Desktop Mobile -
<div class="container custom-gutters!"> <div class="row!"> <div class="col-xs-12 col-lg-4!"> <div class="card!">
<div class="card-body!"> <h5 class="card-title!">Card title!</h5> <p class="card-text!"> Some quick example text to build on the card title and make up the bulk of the card's content. !</p> !</div> !</div> !</div> <div class="col-xs-12 col-lg-4!"> … !</div> <div class="col-xs-12 col-lg-4!"> … !</div> !</div> !</div> Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. -
<div class="container custom-gutters!"> <div class="row!"> <div class="col-xs-12 col-lg-4!"> <div class="card!">
<div class="card-body!"> <h5 class="card-title!">Card title!</h5> <p class="card-text!"> Some quick example text to build on the card title and make up the bulk of the card's content. !</p> !</div> !</div> !</div> <div class="col-xs-12 col-lg-4!"> … !</div> <div class="col-xs-12 col-lg-4!"> … !</div> !</div> !</div> -
.card-title { … color: rgba(0, 0, 0, 0.85); background-color: white;
} .card-text { … color: rgba(0, 0, 0, 0.65); background-color: white; } @media screen and (max-width: 992px) { .card-title { color: white; background-color: rgba(0, 0, 0, 0.7); } .card-text { color: black; background-color: rgba(0, 0, 0, 0.2); } } -
<Row> <Col> <Card title="Card title" style={{ marginBottom: 16 }}> <p>
Some quick example text to build on the card title and make up the bulk of the card's conte nt. !</p> !</Card> !</Col> <Col> … !</Col> <Col> … !</Col> !</Row> Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. -
<Row gutter={16}> <Col> <Card title="Card title!"> <p> Some quick example
text to build on the card title and make up the bulk of the card's conte nt. !</p> !</Card> !</Col> <Col> … !</Col> <Col> … !</Col> !</Row> -
@media screen and (max-width: 768px) { .ant-card { border: none;
} .ant-card-head { background-color: rgba(0, 0, 0, 0.7); color: white; } .ant-card-body { background-color: rgba(0, 0, 0, 0.2); color: black; } } -
@media screen and (max-width: 768px) { .ant-card { border: none;
} .ant-card-head { background-color: rgba(0, 0, 0, 0.7); color: white; } .ant-card-body { background-color: rgba(0, 0, 0, 0.2); color: black; } } -
Button2 Button1 <Button color="white" backgroundColor="blue!">Button1!</Button> const Button = styled.div` color:
${props !=> props.color}; background-color: ${props !=> props.backgroundColor}; border-radius: 10px; cursor: pointer; … `; -
Label2 Label1 <Label fontColor="green" borderColor="green!">Label1!</Label> const Label = styled.div` color:
${props !=> props.fontColor}; border-color: ${props !=> props.borderColor}; border-radius: 10px; … `; -
<ArticleCard marginRight="16px!">!!...!</ArticleCard> <MemberCard mr="8px" >!!...!</MemberCard> Card title Some quick example
text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. [email protected] 935-721-3322 Anna Su Front-End Developer -
Button B U T T O N Button const StyledButton
= styled.button` padding: ${(props) !=> props.padding}; margin-left: ${(props) !=> props.marginLeft}; width: ${(props) !=> props.width}; height: ${(props) !=> props.height}; font-size: ${(props) !=> props.fontSize}; font-family: ${(props) !=> props.fontFamily}; line-height: ${(props) !=> props.lineHeight}; border: ${(props) !=> props.border}; border-radius: ${(props) !=> props.borderRadius}; color: ${(props) !=> props.color}; background-color: ${(props) !=> props.backgroundColor}; cursor: pointer; … `; -
Button B U T T O N Button const StyledButton
= styled.button` padding: ${(props) !=> props.padding}; margin-left: ${(props) !=> props.marginLeft}; width: ${(props) !=> props.width}; height: ${(props) !=> props.height}; font-size: ${(props) !=> props.fontSize}; font-family: ${(props) !=> props.fontFamily}; line-height: ${(props) !=> props.lineHeight}; border: ${(props) !=> props.border}; border-radius: ${(props) !=> props.borderRadius}; color: ${(props) !=> props.color}; background-color: ${(props) !=> props.backgroundColor}; cursor: pointer; … `; -
Button Button Button Default Small Large <SmallButton small>Button!</SmallButton> <SmallButton size="small!">Button!</SmallButton>
<Button>Button!</Button> <Button size="default!">Button!</Button> <LargeButton large>Button!</LargeButton> <LargeButton size="large!">Button!</LargeButton> -
Button Button Button Default Small Large <SmallButton small>Button!</SmallButton> <SmallButton size="small!">Button!</SmallButton>
<Button>Button!</Button> <Button size="default!">Button!</Button> <LargeButton large>Button!</LargeButton> <LargeButton size="large!">Button!</LargeButton> -
const getTheme = obj !=> status !=> obj[status]; const buttonStyles
= { default: { padding: '8px', color: 'white', backgroundColor: 'gray', … }, primary: { padding: '8px', color: 'white', backgroundColor: 'blue', … }, danger: { padding: '8px', color: 'black', backgroundColor: 'tomato', … }, }; const buttonTheme = getTheme(buttonStyles); Danger Primary Default -
<Label style={labelTheme('order-validation')}>order validation!</Label> <Label style={labelTheme('user-payment')}>user payment!</Label> <Label style={labelTheme('shop-approval')}>shop approval!</Label> <Label
style={labelTheme('driver-assignment')}>driver assignment!</Label> user payment order validation shop approval driver assignment -
<Label style={labelTheme('order-validation')}>order validation!</Label> <Label style={labelTheme('user-payment')}>user payment!</Label> <Label style={labelTheme('shop-approval')}>shop approval!</Label> <Label
style={labelTheme('driver-assignment')}>driver assignment!</Label> user payment order validation shop approval driver assignment Danger Primary Default <Button style={buttonTheme('default')}>Button!</Button>; <Button style={buttonTheme('primary')}>Button!</Button>; <Button style={buttonTheme('danger')}>Button!</Button>; -
const Article = styled.div` width: 100%; … @media (min-width: 567px)
{ width: 50%; … } @media (min-width: 768px) { width: 25%; … } `; -
const Article = styled.div` width: 100%; … @media (min-width: 567px)
{ width: 50%; … } @media (min-width: 768px) { width: 25%; … } `; -
Anna Su Front-End Developer [email protected] 935-721-3322 [email protected] 935-721-3322 Anna Su
Front-End Developer const Info = styled.div` display: flex; justify-content: flex-start; margin-bottom: 5px; font-size: 12px; … @media (max-width: 992px) { justify-content: space-between; margin-bottom: 13px; font-size: 14px; … } `; -
Anna Su Front-End Developer [email protected] 935-721-3322 [email protected] 935-721-3322 Anna Su
Front-End Developer const Info = styled.div` display: flex; justify-content: flex-start; margin-bottom: 5px; font-size: 12px; … @media (max-width: 992px) { justify-content: space-between; margin-bottom: 13px; font-size: 14px; … } `; -
1. 傳入 props 命名不⼀一致 2. 客製化樣式需傳入對應的 props,程式碼很繁冗 3. 不同狀狀態顯⽰示不同樣式時,程式碼需要封裝 4.
RWD 元件開發複雜 客製化元件遇到的問題 -
import { color } from 'styled-system'; const Button = styled.div`
${color} … `; <Button color="white" bg="blue!">Button!</Button> -
import { color } from 'styled-system'; const Button = styled.div`
${color} … `; <Button color="white" bg="blue!">Button!</Button> -
<ArticleCard mr="16px!">!!...!</ArticleCard> <MemberCard mr="8px" >!!...!</MemberCard> Card title Some quick example
text to build on the card title and make up the bulk of the card’s content. Card title Some quick example text to build on the card title and make up the bulk of the card’s content. [email protected] 935-721-3322 Anna Su Front-End Developer -
Button B U T T O N Button const StyledButton
= styled.button` padding: ${(props) !=> props.padding}; margin-left: ${(props) !=> props.marginLeft}; width: ${(props) !=> props.width}; height: ${(props) !=> props.height}; font-size: ${(props) !=> props.fontSize}; font-family: ${(props) !=> props.fontFamily}; line-height: ${(props) !=> props.lineHeight}; border: ${(props) !=> props.border}; border-radius: ${(props) !=> props.borderRadius}; color: ${(props) !=> props.color}; background-color: ${(props) !=> props.backgroundColor}; cursor: pointer; … `; -
Button B U T T O N Button const StyledButton
= styled.button` ${space} ${layout} ${typography} ${border} ${color} cursor: pointer; `; -
const StyledButton = styled.button` padding: ${(props) !=> props.padding}; margin-left: ${(props)
!=> props.marginLeft}; width: ${(props) !=> props.width}; height: ${(props) !=> props.height}; font-size: ${(props) !=> props.fontSize}; font-family: ${(props) !=> props.fontFamily}; line-height: ${(props) !=> props.lineHeight}; border: ${(props) !=> props.border}; border-radius: ${(props) !=> props.borderRadius}; color: ${(props) !=> props.color}; background-color: ${(props) !=> props.backgroundColor}; cursor: pointer; … `; const StyledButton = styled.button` ${space} ${layout} ${typography} ${border} ${color} cursor: pointer; `; -
import { space, layout, typography, border, color } from 'styled-system';
const StyledButton = styled.button` ${space} ${layout} ${typography} ${border} ${color} cursor: pointer; `; -
Danger Primary Default import { variant } from 'styled-system' const
Button = styled.div` ${variant({ variants: { default: { p: "8px", color: "white", backgroundColor: "gray" … }, primary: { p: "8px", color: "white", backgroundColor: "blue" }, danger: { p: "8px", color: "black", backgroundColor: "tomato" }, } })} ` -
const getTheme = obj !=> status !=> obj[status]; const buttonStyles
= { default: { padding: '8px', color: 'white', backgroundColor: ‘gray', … }, primary: { padding: '8px', color: 'white', backgroundColor: ‘blue', … }, danger: { padding: '8px', color: 'black', backgroundColor: ‘tomato', … }, }; const buttonTheme = getTheme(buttonStyles); import { variant } from 'styled-system' const Button = styled.div` ${variant({ variants: { default: { p: "8px", color: "white", backgroundColor: "gray" … }, primary: { p: "8px", color: "white", backgroundColor: "blue" }, danger: { p: "8px", color: "black", backgroundColor: "tomato" }, } })} ` -
<Button style={buttonTheme('default')}>Button!</Button>; <Button style={buttonTheme('primary')}>Button!</Button>; <Button style={buttonTheme('danger')}>Button!</Button>; <Button variant='primary'>Button!</Button> <Button>Button!</Button> <Button
variant='danger'>Button!</Button> Button.defaultProps = { variant: 'default', } -
const Article = styled.div` width: 25%; … @media (min-width: 567px)
{ width: 50%; … } @media (min-width: 768px) { width: 100%; … } `; <Article width={[1, 1 / 2, 1 / 4]} !/> const breakpoints = ['576px', '768px']; -
Anna Su Front-End Developer [email protected] 935-721-3322 [email protected] 935-721-3322 Anna Su
Front-End Developer import { flexbox, space, typography } from 'styled-system'; const Info = styled.div` display: flex; ${flexbox} ${space} ${typography} `; <Info justifyContent={['flex-start', 'space-between']} mb={[5, 13]} fontSize={[12, 14]}> !</Info> -
theme.js const theme = { breakpoints: ['992px'], space: [0, 4,
8, 16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } -
import React from 'react'; import { ThemeProvider } from 'styled-components';
import theme from './theme'; const App = props !=> ( <ThemeProvider theme={theme}> {!/* application elements !*/} !</ThemeProvider> ) export default App; -
import React from 'react'; import { ThemeProvider } from 'styled-components';
import theme from './theme'; const App = props !=> ( <ThemeProvider theme={theme}> {!/* application elements !*/} !</ThemeProvider> ) export default App; const theme = { breakpoints: ['992px'], space: [0, 4, 8, 16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } -
<Box m={2} !/> <Box p={[2, 3]} !/> <Box fontSize={[1, 2]}
!/> <Box color="primary" !/> <Box color="blacks.0" !/> -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } <Box m={2} !/> <Box p={[2, 3]} !/> <Box fontSize={[1, 2]} !/> <Box color="primary" !/> <Box color="blacks.0" !/> -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } <Box m={2} !/> <Box p={[2, 3]} !/> <Box fontSize={[1, 2]} !/> <Box color="primary" !/> <Box color="blacks.0" !/> -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } <Box m={2} !/> <Box p={[2, 3]} !/> <Box fontSize={[1, 2]} !/> <Box color="primary" !/> <Box color="blacks.0" !/> -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } <Box m={2} !/> <Box p={[2, 3]} !/> <Box fontSize={[1, 2]} !/> <Box color="primary" !/> <Box color="blacks.0" !/> -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { black: '#000', blacks: ['#ccc', '#999'] white: '#fff', primary: '#456000', }, button: { !!... }, breadcrumb: { !!... } … pagination: { !!... } } <Box m={2} !/> <Box p={[2, 3]} !/> <Box fontSize={[1, 2]} !/> <Box color="primary" !/> <Box color="blacks.0" !/> -
Button B U T T O N Button Default Small
Large Button Button Button Primary Default Danger Button Button Button Other button themes -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { !!... }, buttons: { default: { !!... }, primary: { color: "white", backgroundColor: "blue", … '&:hover': { !!... }, '&:active': { !!... }, '&:disabled': { !!... }, }, danger: { !!... }, size: { default: { !!... }, large: { height: 40, !!... }, small: { !!... }, }, }, … } Button Button Button Button Button Button -
<Button variant="primary" size="large!">Button!</Button> const Button = styled.button` display: inline-flex; align-items:
center; justify-content: center; cursor: pointer; !!... ${buttonStyle} ${buttonSizeStyle} `; const buttonStyle = variant({ key: 'buttons', }); const buttonSizeStyle = variant({ prop: 'size', key: 'buttons.size', }); Button Button Button Primary Default Danger -
const buttonStyle = variant({ key: 'buttons', }); const theme =
{ breakpoints: ['992px'], space: [0, 4, 8, 16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { !!... }, buttons: { default: { !!... }, primary: { color: "white", backgroundColor: "blue", … '&:hover': { !!... }, '&:active': { !!... }, '&:disabled': { !!... }, }, danger: { !!... }, }, … } Button Button Button Primary Default Danger -
<Button variant="primary" size="large!">Button!</Button> const Button = styled.button` display: inline-flex; align-items:
center; justify-content: center; cursor: pointer; !!... ${buttonStyle} ${buttonSizeStyle} `; const buttonStyle = variant({ key: 'buttons', }); const buttonSizeStyle = variant({ prop: 'size', key: 'buttons.size', }); Button Button Button Default Small Large -
Button Button Button Default Small Large const buttonSizeStyle = variant({
prop: 'size', key: 'buttons.size', }); const theme = { breakpoints: ['992px'], space: [0, 4, 8, 16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], colors: { !!... }, buttons: { … size: { default: { !!... }, large: { height: "40px", !!... }, small: { !!... }, }, }, … } -
const theme = { !!... card: { !!... wrapper: {
vertical: { flexDirection: 'column', }, horizontal: { flexDirection: 'row', }, }, } } -
const cardWrapperStyle = variantResponsive({ key: 'card.wrapper', }); const Card =
styled.a` position: relative; display: flex; overflow: hidden; ${cardWrapperStyle} … `; -
6 5 4 3 2 1 6 5 4 3
2 1 6 5 4 3 2 1 6 5 4 3 2 1 -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], !!... pagination: { item: { fontSize: "14px", color: "blue", backgroundColor: "transparent", border: { top: 0, left: 0, right: 0, bottom: "2px", }, borderRadius: 0, !!... }, !!... } … }; 6 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1 -
6 5 4 3 2 1 6 5 4 3
2 1 6 5 4 3 2 1 6 5 4 3 2 1 const PaginationItem = styled.li` display: inline-block; cursor: pointer; user-select: none; !!... font-size: ${themeGet('pagination.item.fontSize')}; color: ${themeGet('pagination.item.color')}; background-color: ${themeGet('pagination.item.backgroundColor')}; border-top: ${themeGet('pagination.item.border.top')}; border-right: ${themeGet('pagination.item.border.right')}; border-bottom: ${themeGet('pagination.item.border.bottom')}; border-left: ${themeGet('pagination.item.border.left')}; border-radius: ${themeGet('pagination.item.borderRadius')}; `; -
const theme = { breakpoints: ['992px'], space: [0, 4, 8,
16, 24, 32, 64], fontSizes: [12, 14, 16, 20, 24, 32], !!... pagination: { item: { fontSize: "14px", color: "blue", backgroundColor: "transparent", border: { top: 0, left: 0, right: 0, bottom: "2px", }, borderRadius: 0, !!... }, !!... } … }; const PaginationItem = styled.li` display: inline-block; cursor: pointer; user-select: none; !!... font-size: ${themeGet('pagination.item.fontSize')}; color: ${themeGet('pagination.item.color')}; background-color: ${themeGet('pagination.item.backgroundColor')}; border-top: ${themeGet('pagination.item.border.top')}; border-right: ${themeGet('pagination.item.border.right')}; border-bottom: ${themeGet('pagination.item.border.bottom')}; border-left: ${themeGet('pagination.item.border.left')}; border-radius: ${themeGet('pagination.item.borderRadius')}; `; -
6 5 4 3 2 1 const theme = {
!!... pagination: { item: { fontSize: "14px", color: "blue", backgroundColor: "transparent", border: { top: 0, left: 0, right: 0, bottom: "2px", }, borderRadius: 0, !!... }, } … }; const theme = { !!... pagination: { item: { fontSize: "14px", color: "orange", backgroundColor: "transparent", border: { top: "1px", left: "1px", right: "1px", bottom: "1px", }, borderRadius: "50%", !!... }, } … }; 6 5 4 3 2 1 -
6 5 4 3 2 1 const theme = {
!!... pagination: { item: { fontSize: "14px", color: "blue", backgroundColor: "transparent", border: { top: 0, left: 0, right: 0, bottom: "2px", }, borderRadius: 0, !!... }, } … }; const theme = { !!... pagination: { item: { fontSize: "14px", color: "orange", backgroundColor: "transparent", border: { top: "1px", left: "1px", right: "1px", bottom: "1px", }, borderRadius: "50%", !!... }, } … }; 6 5 4 3 2 1 -
const theme = { !!... pagination: { item: { fontSize:
"14px", color: "white", backgroundColor: "green", border: { top: 0, left: 0, right: 0, bottom: 0, }, borderRadius: "50%", !!... }, } … }; const theme = { !!... pagination: { item: { fontSize: "14px", color: "white", backgroundColor: "blue", border: { top: 0, left: 0, right: 0, bottom: 0, }, borderRadius: "5px", !!... }, } … }; 6 5 4 3 2 1 6 5 4 3 2 1 -
const theme = { !!... pagination: { item: { fontSize:
"14px", color: "white", backgroundColor: "green", border: { top: 0, left: 0, right: 0, bottom: 0, }, borderRadius: "50%", !!... }, } … }; const theme = { !!... pagination: { item: { fontSize: "14px", color: "white", backgroundColor: "blue", border: { top: 0, left: 0, right: 0, bottom: 0, }, borderRadius: "5px", !!... }, } … }; 6 5 4 3 2 1 6 5 4 3 2 1 -
1. ⼤大幅降低 props 命名或格式不⼀一致的問題 2. 更更好的抽象化樣式,程式碼變得更更少 3. 根據不同狀狀態,更更彈性的修改對應樣式 4. 靈活的處理理
RWD 樣式 5. 透過 theme 快速變更更主題樣式 解決的問題 Styled System