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