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

104 lines
2.2 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,
2020-03-26 03:11:32 +00:00
htmlFor: PropTypes.string,
2020-02-19 23:57:07 +00:00
}
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,
2020-03-26 03:11:32 +00:00
align,
htmlFor
2020-02-21 00:57:29 +00:00
} = 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,
{
2020-03-26 03:11:32 +00:00
htmlFor,
2020-02-19 23:57:07 +00:00
className: classes,
},
children,
)
}
}