gab-social/app/javascript/gabsocial/components/text.js

101 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-02-19 23:57:07 +00:00
import classNames from 'classnames/bind'
const cx = classNames.bind(_s)
const COLORS = {
primary: 'primary',
secondary: 'secondary',
brand: 'brand',
error: 'error',
white: 'white',
2020-02-21 00:57:29 +00:00
inherit: 'inherit',
2020-02-19 23:57:07 +00:00
}
const SIZES = {
extraSmall: 'extraSmall',
small: 'small',
normal: 'normal',
medium: 'medium',
large: 'large',
extraLarge: 'extraLarge',
}
const WEIGHTS = {
normal: 'normal',
medium: 'medium',
bold: 'bold',
extraBold: 'extraBold',
}
2020-02-21 00:57:29 +00:00
const ALIGNMENTS = {
center: 'center',
left: 'left',
}
2020-02-19 23:57:07 +00:00
export default class Text extends PureComponent {
static propTypes = {
tagName: PropTypes.string,
className: PropTypes.string,
children: PropTypes.any,
color: PropTypes.oneOf(Object.keys(COLORS)),
size: PropTypes.oneOf(Object.keys(SIZES)),
weight: PropTypes.oneOf(Object.keys(WEIGHTS)),
2020-02-21 00:57:29 +00:00
align: PropTypes.oneOf(Object.keys(ALIGNMENTS)),
2020-02-19 23:57:07 +00:00
underline: PropTypes.bool,
}
static defaultProps = {
tagName: 'span',
color: COLORS.primary,
size: SIZES.normal,
weight: WEIGHTS.normal,
}
render() {
2020-02-21 00:57:29 +00:00
const {
tagName,
className,
children,
color,
size,
weight,
underline,
align
} = this.props
2020-02-19 23:57:07 +00:00
const classes = cx(className, {
default: 1,
text: 1,
colorPrimary: color === COLORS.primary,
colorSecondary: color === COLORS.secondary,
colorBrand: color === COLORS.brand,
colorWhite: color === COLORS.white,
2020-02-21 00:57:29 +00:00
inherit: color === COLORS.inherit,
2020-02-19 23:57:07 +00:00
fontSize19PX: size === SIZES.large,
fontSize15PX: size === SIZES.medium,
fontSize14PX: size === SIZES.normal,
fontSize13PX: size === SIZES.small,
2020-02-21 00:57:29 +00:00
fontSize12PX: size === SIZES.extraSmall,
2020-02-19 23:57:07 +00:00
fontWeightNormal: weight === WEIGHTS.normal,
fontWeightMedium: weight === WEIGHTS.medium,
fontWeightBold: weight === WEIGHTS.bold,
2020-02-21 00:57:29 +00:00
fontWeightExtraBold: weight === WEIGHTS.extraBold,
textAlignLeft: align === ALIGNMENTS.left,
textAlignCenter: align === ALIGNMENTS.center,
2020-02-19 23:57:07 +00:00
underline: underline,
})
return React.createElement(
tagName,
{
className: classes,
},
children,
)
}
}