2020-05-29 19:31:19 +05:00
|
|
|
import upperFirst from 'lodash/upperFirst';
|
|
|
|
import camelCase from 'lodash/camelCase';
|
2019-08-31 04:07:25 +05:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import LabelColors from '../../constants/LabelColors';
|
|
|
|
|
2020-05-29 19:31:19 +05:00
|
|
|
import styles from './Label.module.scss';
|
|
|
|
import globalStyles from '../../styles.module.scss';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
const SIZES = {
|
|
|
|
TINY: 'tiny',
|
|
|
|
SMALL: 'small',
|
|
|
|
MEDIUM: 'medium',
|
|
|
|
};
|
|
|
|
|
2020-02-03 18:42:31 +05:00
|
|
|
const Label = React.memo(({ name, color, size, isDisabled, onClick }) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
const contentNode = (
|
|
|
|
<div
|
|
|
|
title={name}
|
2020-05-29 19:31:19 +05:00
|
|
|
className={classNames(
|
|
|
|
styles.wrapper,
|
2021-01-09 18:42:16 +05:00
|
|
|
!name && styles.wrapperNameless,
|
2020-05-29 19:31:19 +05:00
|
|
|
styles[`wrapper${upperFirst(size)}`],
|
|
|
|
onClick && styles.wrapperHoverable,
|
|
|
|
globalStyles[`background${upperFirst(camelCase(color))}`],
|
|
|
|
)}
|
2019-08-31 04:07:25 +05:00
|
|
|
>
|
2019-10-09 18:48:19 +05:00
|
|
|
{name || '\u00A0'}
|
2019-08-31 04:07:25 +05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return onClick ? (
|
|
|
|
<button type="button" disabled={isDisabled} className={styles.button} onClick={onClick}>
|
|
|
|
{contentNode}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
contentNode
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Label.propTypes = {
|
2019-10-09 18:48:19 +05:00
|
|
|
name: PropTypes.string,
|
2020-05-29 19:31:19 +05:00
|
|
|
color: PropTypes.oneOf(LabelColors).isRequired,
|
2019-08-31 04:07:25 +05:00
|
|
|
size: PropTypes.oneOf(Object.values(SIZES)),
|
|
|
|
isDisabled: PropTypes.bool,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
Label.defaultProps = {
|
2019-10-09 18:48:19 +05:00
|
|
|
name: undefined,
|
2019-08-31 04:07:25 +05:00
|
|
|
size: SIZES.MEDIUM,
|
|
|
|
isDisabled: false,
|
|
|
|
onClick: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Label;
|