styled mixin
1.0.0
เสื้อคลุมที่เรียบง่ายสุด ๆ สำหรับการสร้างส่วนผสมที่มีสไตล์ผสมผสาน อาจจะเป็นไวยากรณ์ที่มนุษย์อ่านได้มากกว่าสำหรับกฎการเขียนทับ
npm i --save styled-mixin import styled from 'styled-component' ;
import createMixin from 'styled-mixin' ;
const tomatoColorMixin = createMixin `
color: tomato;
` ;
const Header = styled . h1 `
color: black;
font-size: 20px;
` ;
const Button = styled . button `
color: black;
border: none;
` ;
const TomatoHeader = tomatoColorMixin ( Header ) ;
const TomatoButton = tomatoColorMixin ( Button ) ;ใช้
import createMixin from 'styled-mixin/native' ;หากคุณต้องการโหมด React-Native
import styled , { keyframes } from 'styled-component' ;
import createMixin from 'styled-mixin' ;
const Header = styled . h1 `
color: black;
` ;
const rotate360Keyframes = keyframes `
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
` ;
const rotate = createMixin `
animation: ${ rotate360Keyframes } 2s linear infinite;
` ;
const Uiiiii = rotate ( Header ) ; import styled from 'styled-component' ;
import createMixin from 'styled-mixin' ;
const blackOrTomatoMixin = createMixin `
color: ${ props => props . tomato ? 'tomato' : 'black' } ;
` ;
const Button = blackOrTomatoMixin ( styled . button `
border: none;
` ) ; < Button tomato > Tomato!!! </ Button > import styled from 'styled-component' ;
import createMixin from 'styled-mixin' ;
const Header = styled . h1 `
color: black;
` ;
const tomatoColorMixin = createMixin `
color: tomato;
` ;
const fontSizeMixin = createMixin `
font-size: 20px;
` ;
const TomatoHeader = tomatoColorMixin ( fontSizeMixin ( Header ) ) ; Dmitry Pavlovsky