|
| 1 | +import React from 'react'; |
| 2 | +import { Typography } from 'antd'; |
| 3 | +import styled from 'styled-components'; |
| 4 | +import { shade as shadeFunc, tint as tintFunc } from 'polished'; |
| 5 | +import PropTypes from 'prop-types'; |
| 6 | + |
| 7 | +const { Title: AntTitle, Text: AntText, Paragraph: AntParagraph } = Typography; |
| 8 | + |
| 9 | +function getColor(color, shadeValue, tintValue) { |
| 10 | + if (shadeValue) { |
| 11 | + return shadeFunc(shadeValue, color); |
| 12 | + } |
| 13 | + if (tintValue) { |
| 14 | + return tintFunc(tintValue, color); |
| 15 | + } |
| 16 | + return tintFunc(0.1, color); |
| 17 | +} |
| 18 | + |
| 19 | +const AntTitleStyled = styled(AntTitle)` |
| 20 | + &&& { |
| 21 | + color: ${props => |
| 22 | + getColor(props.theme[props.color], props.shade, props.tint)}; |
| 23 | + font-family: 'Cera Pro', sans-serif; |
| 24 | + } |
| 25 | +`; |
| 26 | + |
| 27 | +const AntTextStyled = styled(AntText)` |
| 28 | + &&& { |
| 29 | + color: ${props => |
| 30 | + getColor(props.theme[props.color], props.shade, props.tint)}; |
| 31 | + font-family: 'Cera Pro', sans-serif; |
| 32 | + } |
| 33 | +`; |
| 34 | + |
| 35 | +const AntParaStyled = styled(AntParagraph)` |
| 36 | + &&& { |
| 37 | + color: ${props => |
| 38 | + getColor(props.theme[props.color], props.shade, props.tint)}; |
| 39 | + font-family: 'Cera Pro', sans-serif; |
| 40 | + font-size: 1.6rem; |
| 41 | + } |
| 42 | +`; |
| 43 | + |
| 44 | +export function Title({ color = 'primary', shade, tint, ...rest }) { |
| 45 | + return <AntTitleStyled color={color} shade={shade} tint={tint} {...rest} />; |
| 46 | +} |
| 47 | + |
| 48 | +export function Text({ color = 'primary', shade, tint, ...rest }) { |
| 49 | + return <AntTextStyled color={color} shade={shade} tint={tint} {...rest} />; |
| 50 | +} |
| 51 | + |
| 52 | +export function Paragraph({ color = 'primary', shade, tint, ...rest }) { |
| 53 | + return <AntParaStyled color={color} shade={shade} tint={tint} {...rest} />; |
| 54 | +} |
| 55 | + |
| 56 | +Title.propTypes = { |
| 57 | + color: PropTypes.string, |
| 58 | + shade: PropTypes.number, |
| 59 | + tint: PropTypes.number, |
| 60 | +}; |
| 61 | + |
| 62 | +Text.propTypes = { |
| 63 | + color: PropTypes.string, |
| 64 | + shade: PropTypes.number, |
| 65 | + tint: PropTypes.number, |
| 66 | +}; |
| 67 | + |
| 68 | +Paragraph.propTypes = { |
| 69 | + color: PropTypes.string, |
| 70 | + shade: PropTypes.number, |
| 71 | + tint: PropTypes.number, |
| 72 | +}; |
0 commit comments