【发布时间】:2020-02-15 03:26:07
【问题描述】:
样式化组件有一个组合实用程序,可以将多个样式化系统功能组合在一个组件中。我想根据默认数组将 lineHeight 和 fontSize 组合在一起。
而不是做:
<Heading type="h1"
fontSize={[ 1, 2, 3 ]}
lineHeight={[1 , 2, 3 ]}
color={theme.colors.heading.tinted}
>
我只想实现一个结合了 fontSize 和 lineHeight 的字体道具。
<Heading type="h1"
font={[ 1, 2, 3 ]}
color={theme.colors.heading.tinted}
>
标题.jsx
const Element = styled('div')(
space,
color,
compose(
fontSize,
lineHeight
)
);
主题.js
const theme = {
fontSizes: [11, 13, 16, 23, 29, 37, 47, 76, 97],
lineHeights: ['12px', '12px', '12px', '32px', '32px', '40px', '48px', '56px', '72px', '80px', '104px']
}
【问题讨论】:
标签: css reactjs components styling styled-components