1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-08-01 11:35:27 +02:00
planka/client/src/components/LabelsStep/Editor.jsx

62 lines
1.7 KiB
React
Raw Normal View History

import upperFirst from 'lodash/upperFirst';
import camelCase from 'lodash/camelCase';
2019-10-09 18:48:19 +05:00
import React, { useEffect, useRef } from 'react';
2019-08-31 04:07:25 +05:00
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Button } from 'semantic-ui-react';
import { Input } from '../../lib/custom-ui';
import LabelColors from '../../constants/LabelColors';
import styles from './Editor.module.scss';
import globalStyles from '../../styles.module.scss';
2019-08-31 04:07:25 +05:00
2019-10-09 18:48:19 +05:00
const Editor = React.memo(({ data, onFieldChange }) => {
2019-08-31 04:07:25 +05:00
const [t] = useTranslation();
const nameField = useRef(null);
2019-10-09 18:48:19 +05:00
useEffect(() => {
2019-08-31 04:07:25 +05:00
nameField.current.select();
}, []);
return (
<>
<div className={styles.text}>{t('common.title')}</div>
<Input
fluid
ref={nameField}
name="name"
value={data.name}
className={styles.field}
onChange={onFieldChange}
/>
<div className={styles.text}>{t('common.color')}</div>
<div className={styles.colorButtons}>
{LabelColors.map((color) => (
2019-08-31 04:07:25 +05:00
<Button
key={color}
2019-08-31 04:07:25 +05:00
type="button"
name="color"
value={color}
2019-08-31 04:07:25 +05:00
className={classNames(
styles.colorButton,
color === data.color && styles.colorButtonActive,
globalStyles[`background${upperFirst(camelCase(color))}`],
2019-08-31 04:07:25 +05:00
)}
onClick={onFieldChange}
/>
))}
</div>
</>
);
});
Editor.propTypes = {
data: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
onFieldChange: PropTypes.func.isRequired,
};
2019-10-09 18:48:19 +05:00
export default Editor;