Files
cinny/src/app/atoms/text/Text.jsx
T

43 lines
1.2 KiB
React
Raw Normal View History

2021-07-28 18:45:52 +05:30
import React from 'react';
import PropTypes from 'prop-types';
import './Text.scss';
function Text({
2021-12-18 10:10:23 +05:30
className, style, variant, weight,
2021-12-16 17:55:16 +05:30
primary, span, children,
2021-07-28 18:45:52 +05:30
}) {
2021-12-16 17:55:16 +05:30
const classes = [];
if (className) classes.push(className);
classes.push(`text text-${variant} text-${weight}`);
2021-12-17 11:32:21 +05:30
if (primary) classes.push('font-primary');
2021-12-16 17:55:16 +05:30
const textClass = classes.join(' ');
2021-12-18 10:10:23 +05:30
if (span) return <span className={textClass} style={style}>{ children }</span>;
if (variant === 'h1') return <h1 className={textClass} style={style}>{ children }</h1>;
if (variant === 'h2') return <h2 className={textClass} style={style}>{ children }</h2>;
if (variant === 's1') return <h4 className={textClass} style={style}>{ children }</h4>;
return <p className={textClass} style={style}>{ children }</p>;
2021-07-28 18:45:52 +05:30
}
Text.defaultProps = {
2021-12-16 17:55:16 +05:30
className: null,
2021-12-18 10:10:23 +05:30
style: null,
2021-07-28 18:45:52 +05:30
variant: 'b1',
2021-12-16 17:55:16 +05:30
weight: 'normal',
primary: false,
span: false,
2021-07-28 18:45:52 +05:30
};
Text.propTypes = {
className: PropTypes.string,
2021-12-18 10:10:23 +05:30
style: PropTypes.shape({}),
2021-07-28 18:45:52 +05:30
variant: PropTypes.oneOf(['h1', 'h2', 's1', 'b1', 'b2', 'b3']),
2021-12-16 17:55:16 +05:30
weight: PropTypes.oneOf(['light', 'normal', 'medium', 'bold']),
primary: PropTypes.bool,
span: PropTypes.bool,
2021-07-28 18:45:52 +05:30
children: PropTypes.node.isRequired,
};
export default Text;