CSS-in-JS 中的有用插值函数
适用于 styled-components、emotion、JSS 以及其他 CSS-in-JS 库的有用插值函数。
npm: npm i styled-tools 纱线: yarn add styled-tools
import styled, { css } from "styled-components";
import { prop, ifProp, switchProp } from "styled-tools";
const Button = styled.button`
color: ${prop("color", "red")};
font-size: ${ifProp({ size: "large" }, "20px", "14px")};
background-color: ${switchProp("theme", {
dark: "blue",
darker: "mediumblue",
darkest: "darkblue"
})};
`;
// renders with color: blue
// renders with color: red
// renders with font-size: 20px
// renders with background-color: mediumblue
一个更复杂的示例:
…返回 props[path] 或 defaultValue 的值
暂无开放 Issues,或尚未同步最近议题。