1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-25 16:19:47 +02:00
planka/client/src/components/Label/Label.jsx

59 lines
1.3 KiB
React
Raw Normal View History

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';
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',
};
const Label = React.memo(({ name, color, size, isDisabled, onClick }) => {
2019-08-31 04:07:25 +05:00
const contentNode = (
<div
title={name}
className={classNames(
styles.wrapper,
!name && styles.wrapperNameless,
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,
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;