diff --git a/src/containers/Enrolment/Enrolment.jsx b/src/containers/Enrolment/Enrolment.jsx index a756036..ac7a52c 100644 --- a/src/containers/Enrolment/Enrolment.jsx +++ b/src/containers/Enrolment/Enrolment.jsx @@ -11,6 +11,7 @@ import Step3 from "./Function/Step3"; import Done from "./Function/Done"; import { enrolmentRequest } from "../../action/enrolmentAction"; import axios from "axios"; +import { ChromePicker } from 'react-color'; const cx = classNames.bind(styles); @@ -23,6 +24,8 @@ const mapStateToProps = state => { const mapDispatchToProps = { enrolmentRequest }; +let colorTarget = ""; + class Enrolment extends Component { constructor (props){ super(props); @@ -61,13 +64,14 @@ class Enrolment extends Component { doneClose; contents; inputTarget; + colorClose; componentDidMount() { document.addEventListener('DOMContentLoaded', () => { this.selectCup = document.querySelector(".cup-item1").classList[1]; this.selectAlcohol = document.querySelector(".alcohol-item1").classList[1]; this.doneClose = document.querySelector("#done-container").classList[1]; - + this.colorClose = document.querySelector("#color-picker").classList[1]; this.inputTarget = document.querySelectorAll("#recipe-name, #recipe-descripe, #recipe-tag"); }); this.selectStep = document.querySelector(".step-1").classList[1]; @@ -293,6 +297,16 @@ class Enrolment extends Component { }; onAddStuff = () => { + let containerStyle = window.getComputedStyle ? getComputedStyle(document.querySelector("#stuff-container"), null) : document.querySelector("#stuff-container").currentStyle; + let maxHegihtStyle = window.getComputedStyle ? getComputedStyle(document.querySelector("#stuff-container").parentElement, null) : document.querySelector("#stuff-container").parentElement.currentStyle; + + let containerHeight = parseInt(containerStyle.height); + let maxHeight = parseInt(maxHegihtStyle.height); + + if (containerHeight + 62 >= maxHeight) { + document.querySelector("#stuff-container").style.position = 'relative'; + } + let enrolmentData = {...this.state.enrolmentData}; let lastIndexID = this.state.stuffID; @@ -314,35 +328,59 @@ class Enrolment extends Component { }; onDeleteStuff = event => { + let containerStyle = window.getComputedStyle ? getComputedStyle(document.querySelector("#stuff-container"), null) : document.querySelector("#stuff-container").currentStyle; + let maxHegihtStyle = window.getComputedStyle ? getComputedStyle(document.querySelector("#stuff-container").parentElement, null) : document.querySelector("#stuff-container").parentElement.currentStyle; + + let containerHeight = parseInt(containerStyle.height); + let maxHeight = parseInt(maxHegihtStyle.height); + + if (containerHeight - 62 <= maxHeight) { + document.querySelector("#stuff-container").style.position = 'absolute'; + } + let enrolmentData = {...this.state.enrolmentData}; let clickIndex = event.target.parentNode.parentNode.parentNode.getAttribute("stuff"); - enrolmentData.stuff.splice(clickIndex, 1); + enrolmentData.stuff[clickIndex] = {}; this.setState(enrolmentData); - event.target.parentNode.parentNode.parentNode.remove(); + event.target.parentNode.parentNode.remove(); } onSelectColor = event => { - if (event.target.getAttribute("stuff")) { - let colorNumber = event.target.getAttribute("stuff"); - this.setState({color_idx: colorNumber}); + let colorContainer = document.querySelector("#color-picker"); - document.querySelector(`#color-picker_${colorNumber}`).classList.toggle(this.doneClose); - } else { - let colorNumber = this.state.color_idx; - let enrolmentData = {...this.state.enrolmentData}; - let rgb = document.querySelector(`#item-color_${colorNumber}`).style.backgroundColor.replace(/^(rgb|rgba)\(/,'').replace(/\)$/,'').replace(/\s/g,'').split(','); + colorTarget = event.target.id; + colorContainer.classList.remove(this.colorClose); + // console.log(document.querySelector("#color-picker").classList.contains(this.colorClose)); - document.querySelector(`#color-picker_${colorNumber}`).classList.toggle(this.doneClose); - enrolmentData.stuff[colorNumber].color = "#" + ((1 << 24) + (parseInt(rgb[0]) << 16) + (parseInt(rgb[1]) << 8) + parseInt(rgb[2])).toString(16).slice(1); - - this.setState(enrolmentData); - } + // if (event.target.getAttribute("stuff")) { + // let colorNumber = event.target.getAttribute("stuff"); + // this.setState({color_idx: colorNumber}); + + // document.querySelector(`#color-picker_${colorNumber}`).classList.toggle(this.doneClose); + // } else { + + // } }; + onSelectColorClose = () => { + let colorContainer = document.querySelector("#color-picker"); + let target = document.querySelector(`#${colorTarget}`); + let targetNumber = target.getAttribute("stuff"); + let enrolmentData = {...this.state.enrolmentData}; + let rgb = target.style.backgroundColor.replace(/^(rgb|rgba)\(/,'').replace(/\)$/,'').replace(/\s/g,'').split(','); + + + colorContainer.classList.add(this.colorClose); + + enrolmentData.stuff[targetNumber].color = "#" + ((1 << 24) + (parseInt(rgb[0]) << 16) + (parseInt(rgb[1]) << 8) + parseInt(rgb[2])).toString(16).slice(1); + + this.setState(enrolmentData); + } + onSaveImages = images => { this.setState({images: images}); } @@ -356,45 +394,39 @@ class Enrolment extends Component { else cup = 4; // let tag = this.state.enrolmentData.info.tags; + + console.log(this.state); //태그 배열 형태로 나누는거 처리해야 됨 //재료 포멧은 정해야 될듯 + // let data = { + // name: this.state.enrolmentData.info.name, + // glass: cup, + // percent: 50, + // description: this.state.enrolmentData.info.describe, + // tag: [], + // ingredient: this.state.stuff, + // owner: 'fonnie' + // } + let data = { - name: this.state.enrolmentData.info.name, - glass: cup, - percent: 50, - description: this.state.enrolmentData.info.describe, - tag: [], - ingredient: [{ - name : "water", - color : "blue", - ml : 20 + "name": "martini", + "glass" : 4, + "percent" : 50, + "description" : "This is so delicious", + "tag" : ["sweet", "romantic", "johnmat"], + "ingredient" : [{ + "name" : "water", + "color" : "blue", + "ml" : 20 }, { - name : "hongcho", - color : "red", - ml : 10 + "name" : "hongcho", + "color" : "red", + "ml" : 10 }], - owner: '이미지 추가까지 테스트!' + "owner" : "maga40" } - // { - // "name": "martini", - // "glass" : 4, - // "percent" : 50, - // "description" : "This is so delicious", - // "tag" : ["sweet", "romantic", "johnmat"], - // "ingredient" : [{ - // "name" : "water", - // "color" : "blue", - // "ml" : 20 - // }, { - // "name" : "hongcho", - // "color" : "red", - // "ml" : 10 - // }], - // "owner" : "maga40" - // } - // data.tag.push(tag); this.props.enrolmentRequest(data); @@ -423,12 +455,24 @@ class Enrolment extends Component { }); } + handleChange = color => { + let target = document.querySelector(`#${colorTarget}`); + target.style.backgroundColor = color.hex; + } + render() { const { left, middle, step, done } = this.state; return (