mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 23:07:26 +03:00
Added color picker to edit tag modal
This commit is contained in:
parent
d541543ab3
commit
71ead150a2
2 changed files with 55 additions and 10 deletions
|
@ -1,10 +1,20 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
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 { pick } from 'ramda';
|
||||||
import { editTag, tagEdited } from '../reducers/tagEdit';
|
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 {
|
export class EditTagModal extends React.Component {
|
||||||
|
state = { showColorPicker: false };
|
||||||
|
|
||||||
saveTag = e => {
|
saveTag = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const { tag: oldName, editTag, toggle } = this.props;
|
const { tag: oldName, editTag, toggle } = this.props;
|
||||||
|
@ -29,8 +39,11 @@ export class EditTagModal extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
const { colorGenerator, tag } = props;
|
||||||
this.state = {
|
this.state = {
|
||||||
tag: props.tag,
|
tag,
|
||||||
|
color: colorGenerator.getColorForKey(tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,20 +53,47 @@ export class EditTagModal extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isOpen, toggle, tagEdit } = this.props;
|
const { isOpen, toggle, tagEdit } = this.props;
|
||||||
|
const { tag, color } = this.state;
|
||||||
|
const toggleColorPicker = () =>
|
||||||
|
this.setState({ showColorPicker: !this.state.showColorPicker });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} toggle={toggle} centered onClosed={this.onClosed}>
|
<Modal isOpen={isOpen} toggle={toggle} centered onClosed={this.onClosed}>
|
||||||
<form onSubmit={this.saveTag}>
|
<form onSubmit={this.saveTag}>
|
||||||
<ModalHeader toggle={toggle}>Edit tag</ModalHeader>
|
<ModalHeader toggle={toggle}>Edit tag</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<input
|
<Popover
|
||||||
type="text"
|
isOpen={this.state.showColorPicker}
|
||||||
value={this.state.tag}
|
toggle={toggleColorPicker}
|
||||||
onChange={e => this.setState({ tag: e.target.value })}
|
target="colorPickerBtn"
|
||||||
placeholder="Tag"
|
placement="right"
|
||||||
required
|
>
|
||||||
className="form-control"
|
<ChromePicker color={color} />
|
||||||
/>
|
</Popover>
|
||||||
|
|
||||||
|
<div className="input-group">
|
||||||
|
<div
|
||||||
|
className="input-group-prepend"
|
||||||
|
id="colorPickerBtn"
|
||||||
|
onClick={toggleColorPicker}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="input-group-text edit-tag-modal__color-picker-toggle"
|
||||||
|
style={{backgroundColor: color}}
|
||||||
|
>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={tag}
|
||||||
|
onChange={e => this.setState({ tag: e.target.value })}
|
||||||
|
placeholder="Tag"
|
||||||
|
required
|
||||||
|
className="form-control"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{tagEdit.error && (
|
{tagEdit.error && (
|
||||||
<div className="p-2 mt-2 bg-danger text-white text-center">
|
<div className="p-2 mt-2 bg-danger text-white text-center">
|
||||||
Something went wrong while editing the tag :(
|
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);
|
export default connect(pick(['tagEdit']), { editTag, tagEdited })(EditTagModal);
|
||||||
|
|
3
src/tags/helpers/EditTagModal.scss
Normal file
3
src/tags/helpers/EditTagModal.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.edit-tag-modal__color-picker-toggle {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
Loading…
Reference in a new issue