From 71ead150a206bfeb07fffdebc3454b5cd344bc1b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 18 Aug 2018 23:24:03 +0200 Subject: [PATCH] Added color picker to edit tag modal --- src/tags/helpers/EditTagModal.js | 62 +++++++++++++++++++++++++----- src/tags/helpers/EditTagModal.scss | 3 ++ 2 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 src/tags/helpers/EditTagModal.scss diff --git a/src/tags/helpers/EditTagModal.js b/src/tags/helpers/EditTagModal.js index b7b03f6d..e1c6ca91 100644 --- a/src/tags/helpers/EditTagModal.js +++ b/src/tags/helpers/EditTagModal.js @@ -1,10 +1,20 @@ import React from 'react'; import { connect } from 'react-redux'; -import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; +import { Modal, ModalBody, ModalFooter, ModalHeader, Popover } from 'reactstrap'; import { pick } from 'ramda'; import { editTag, tagEdited } from '../reducers/tagEdit'; +import { ChromePicker } from 'react-color'; +import ColorGenerator from '../../utils/ColorGenerator'; +import './EditTagModal.scss'; + +const defaultProps = { + colorGenerator: ColorGenerator, +}; + export class EditTagModal extends React.Component { + state = { showColorPicker: false }; + saveTag = e => { e.preventDefault(); const { tag: oldName, editTag, toggle } = this.props; @@ -29,8 +39,11 @@ export class EditTagModal extends React.Component { constructor(props) { super(props); + + const { colorGenerator, tag } = props; this.state = { - tag: props.tag, + tag, + color: colorGenerator.getColorForKey(tag) } } @@ -40,20 +53,47 @@ export class EditTagModal extends React.Component { render() { const { isOpen, toggle, tagEdit } = this.props; + const { tag, color } = this.state; + const toggleColorPicker = () => + this.setState({ showColorPicker: !this.state.showColorPicker }); return (
Edit tag - this.setState({ tag: e.target.value })} - placeholder="Tag" - required - className="form-control" - /> + + + + +
+
+
+    +
+
+ this.setState({ tag: e.target.value })} + placeholder="Tag" + required + className="form-control" + /> +
+ {tagEdit.error && (
Something went wrong while editing the tag :( @@ -72,4 +112,6 @@ export class EditTagModal extends React.Component { } } +EditTagModal.defaultProps = defaultProps; + export default connect(pick(['tagEdit']), { editTag, tagEdited })(EditTagModal); diff --git a/src/tags/helpers/EditTagModal.scss b/src/tags/helpers/EditTagModal.scss new file mode 100644 index 00000000..6c774ca0 --- /dev/null +++ b/src/tags/helpers/EditTagModal.scss @@ -0,0 +1,3 @@ +.edit-tag-modal__color-picker-toggle { + cursor: pointer; +}