Skip to content

Commit

Permalink
Add an initial ColorPickerDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Jul 19, 2017
1 parent 9c6166e commit a035b81
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
65 changes: 65 additions & 0 deletions src/common/components/ColorPickerDialog.jsx
@@ -0,0 +1,65 @@
import React, {Component} from "react";
import {connect} from "react-redux";
import {
Modal,
Button,
} from "semantic-ui-react";

import {SketchPicker} from "react-color";

import {closeModal} from "features/modals/modalActions";
import {noop} from "common/utils/clientUtils";

const actions = {closeModal};

export class ColorPickerDialog extends Component {
constructor(props) {
super();
this.state = {
color : props.color
}
}

onSelectClicked = () => {
this.props.colorSelected(this.state.color);

this.props.closeModal();
}

onSelectedColorChanged = (colorEvent) => {
this.setState({color : colorEvent.hex});
}

render() {
const {closeModal} = this.props;

return (
<Modal
closeIcon="close"
open={true}
onClose={closeModal}
size="small"
>
<Modal.Header>Select Color</Modal.Header>
<Modal.Content>
<SketchPicker
color={this.state.color}
onChangeComplete={this.onSelectedColorChanged}
/>
</Modal.Content>
<Modal.Actions>
<Button positive onClick={this.onSelectClicked}>Select</Button>
<Button secondary onClick={closeModal}>Cancel</Button>
</Modal.Actions>
</Modal>
)
}
}

ColorPickerDialog.defaultProps = {
color : "red",
colorSelected : noop
};


export default connect(null, actions)(ColorPickerDialog);
4 changes: 3 additions & 1 deletion src/common/utils/clientUtils.js
Expand Up @@ -16,4 +16,6 @@ export function getValueFromEvent(e) {
}

return newValues;
}
}

export const noop = () => {};
4 changes: 3 additions & 1 deletion src/features/modals/ModalManager.jsx
Expand Up @@ -2,9 +2,11 @@ import React, {Component} from "react";
import {connect} from "react-redux";

import TestModal from "./TestModal";
import ColorPickerDialog from "common/components/ColorPickerDialog";

const modalComponentLookupTable = {
TestModal
ColorPickerDialog,
TestModal,
};

const mapState = (state) => ({currentModals : state.modals});
Expand Down
2 changes: 1 addition & 1 deletion src/features/tools/Tools/Tools.jsx
Expand Up @@ -13,7 +13,7 @@ const actions = {loadUnitData, openModal};
class Tools extends Component {

onOpenModalClicked = () => {
this.props.openModal("TestModal", {counter : 1});
this.props.openModal("ColorPickerDialog");
}

render() {
Expand Down

0 comments on commit a035b81

Please sign in to comment.