styled theme
1.0.0
스타일링 컴포넌트를위한 테마 시스템?
$ npm install --save styled-theme
WebPackbin에서 연주하십시오
import styled from 'styled-components'
import { font , palette } from 'styled-theme'
const Text = styled . span `
font-family: ${ font ( 'primary' ) } ;
background-color: ${ palette ( 1 ) } ;
color: ${ palette ( 'grayscale' , 0 , true ) } ;
`
Text . defaultProps = {
palette : 'primary'
} < Text > Hello </ Text > < Text reverse > Hello </ Text > < Text palette = "secondary" > Hello </ Text > import { ThemeProvider } from 'styled-components'
const xmasTheme = {
fonts : {
primary : 'Georgia, serif'
} ,
palette : {
// red gradient
primary : [ '#D32F2F' , '#F44336' , '#F8877F' , '#FFCDD2' ]
}
}
< ThemeProvider theme = { xmasTheme } >
< Text > Hello </ Text >
< / ThemeProvider> 이것은 src/theme.js 의 내용입니다.
import coolorsToHex from 'coolors-to-hex'
import { reversePalette } from './composer'
const theme = { }
theme . palette = {
primary : coolorsToHex ( 'https://coolors.co/1976d2-2196f3-71bcf7-97cef9-c2e2fb' ) ,
secondary : coolorsToHex ( 'https://coolors.co/c2185b-e91e63-f06292-f48caf-f8bbd0' ) ,
danger : coolorsToHex ( 'https://coolors.co/d32f2f-f44336-f8877f-f9a7a1-ffcdd2' ) ,
alert : coolorsToHex ( 'https://coolors.co/ffa000-ffc107-ffd761-ffecb3-fff2ce' ) ,
success : coolorsToHex ( 'https://coolors.co/388e3c-4caf50-7cc47f-9fd4a1-c8e6c9' ) ,
grayscale : [ '#212121' , '#616161' , '#9e9e9e' , '#bdbdbd' , '#e0e0e0' , '#ffffff' ]
}
theme . reversePalette = reversePalette ( theme . palette )
theme . fonts = {
primary : 'Helvetica Neue, Helvetica, Roboto, sans-serif' ,
pre : 'Consolas, Liberation Mono, Menlo, Courier, monospace' ,
quote : 'Georgia, serif'
}
theme . sizes = {
maxWidth : '1100px'
}
export default theme reversePalette 는 도우미 방법입니다. styled-theme/composer 에서 가져 오십시오.
팔레트를 되돌립니다
매개 변수
palette 팔레트예
reversePalette ( { primary : [ 'red' , 'yellow' , 'green' ] } )
// { primary: ['green', 'yellow', 'red'] }팔레트를 반환합니다
props.theme[path] 또는 styledTheme[path] 의 값을 반환합니다.
매개 변수
path (문자열 | 배열 <문자열>)defaultValue Any예
const Button = styled . button `
font-family: ${ key ( 'fonts.primary' ) } ;
color: ${ key ( [ 'colors' , 'primary' , 0 ] ) } ;
`반환 합니다
key to key(['fonts', path])
매개 변수
path 문자열defaultValue Any예
const Button = styled . button `
font-family: ${ font ( 'primary' ) } ;
`글꼴을 반환합니다
Key to key(['sizes', path])
매개 변수
path 문자열defaultValue Any예
const Button = styled . button `
padding: ${ size ( 'padding' ) } ;
`크기를 반환합니다
props.theme[palette || reversePalette][path][index] 또는 styledTheme[palette || reversePalette][path][index] (기본 테마)
유형을 유지하는 한 인수는 어떤 순서로든 전달 될 수 있습니다.
매개 변수
index 번호 테마 팔레트 톤 어레이의 톤 색인path 문자열? 테마 팔레트 객체의 톤의 키 (선택 사항, 기본 props.palette )exceptions 객체? 키로 경로가있는 객체 및 값으로 인덱스reverse ? reversePalette 또는 palette 에서 톤을 반환하는 플래그defaultValue String? 기본값args ... 누구든지예
// index = 1
// exception = { grayscale: 0 }
// reverse = true
const Button = styled . button `
background-color: ${ palette ( { grayscale : 0 } , 1 , true ) } ;
`
// renders props.theme.reversePalette.grayscale[0]
< Button palette = "grayscale" / >
// renders props.theme.palette.danger[1] (nullify reverse)
< Button palette = "danger" reverse />톤을 반환합니다
유형 : 문자열
유형 : 배열 <톤>
유형 : 문자열
유형 : 문자열
유형: {}
유형: {}
유형: {}
유형 : {팔레트 : 팔레트?, 리버스 폴렛 : 팔레트?, 글꼴 : 글꼴?, 크기 : 크기?}
MIT © Diego Haz