Files
planka/client/src/components/LabelsStep/Item.jsx

58 lines
1.4 KiB
React
Raw Normal View History

2019-08-31 04:07:25 +05:00
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Button } from 'semantic-ui-react';
import LabelColors from '../../constants/LabelColors';
import styles from './Item.module.css';
const Item = React.memo(({ name, color, isPersisted, isActive, onSelect, onDeselect, onEdit }) => {
2019-08-31 04:07:25 +05:00
const handleToggleClick = useCallback(() => {
if (isActive) {
onDeselect();
} else {
onSelect();
}
}, [isActive, onSelect, onDeselect]);
return (
<div className={styles.wrapper}>
<Button
fluid
content={name}
active={isActive}
disabled={!isPersisted}
className={classNames(styles.labelButton, isActive && styles.labelButtonActive)}
style={{
background: LabelColors.MAP[color],
}}
onClick={handleToggleClick}
/>
<Button
icon="pencil"
size="small"
disabled={!isPersisted}
className={styles.editButton}
onClick={onEdit}
/>
</div>
);
});
Item.propTypes = {
2019-10-09 18:48:19 +05:00
name: PropTypes.string,
2019-08-31 04:07:25 +05:00
color: PropTypes.string.isRequired,
isPersisted: PropTypes.bool.isRequired,
isActive: PropTypes.bool.isRequired,
onSelect: PropTypes.func.isRequired,
onDeselect: PropTypes.func.isRequired,
onEdit: PropTypes.func.isRequired,
};
2019-10-09 18:48:19 +05:00
Item.defaultProps = {
name: undefined,
};
2019-08-31 04:07:25 +05:00
export default Item;