diff --git a/src/App.css b/src/App.css
index 529eb03..15a60e2 100644
--- a/src/App.css
+++ b/src/App.css
@@ -33,6 +33,10 @@
overflow: auto;
}
+.selectedDiv {
+ border: 1px solid red;
+}
+
/* .FlexContainer > div {
background-color: #dec58e;
margin: 10px;
diff --git a/src/App.js b/src/App.js
index e17cda0..e7d8cf9 100644
--- a/src/App.js
+++ b/src/App.js
@@ -7,58 +7,48 @@ import Controls from './components/Controls/Control';
import Modal, { CssCodes } from './components/GeneratedCodes/GeneratedCodes';
-// Sample Div used to illustrate children
-const SampleDiv = props => (
-
-
-
-);
-
-// Function for repeating components
-const repeatComp = (comp, number) => {
- let CompArr = [];
- for(let count = 1; count <= number; count++) {
- CompArr.push(comp);
- }
- // console.log(ComDisplay);
- return CompArr.map((comp, index) => (
-
- { comp }
-
- ))
-}
-
class App extends React.Component {
-
- state = {
- //Number of Divs
- nDivs: 3,
- // Handling the state of the styles
- divsWidth: '100px',
- divsHeight: '100px',
- divsMargin: '5px',
- flexWrap: 'nowrap',
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'flex-start',
- alignContent: 'flex-start',
-
- htmlArr: [
- '',
- '',
- ''
- ],
-
- codeModal: false
+ constructor(props) {
+ super(props);
+ this.repeatComp = this.repeatComp.bind(this);
+
+ this.state = {
+ //Number of Divs
+ nDivs: [{
+ divWidth: 100,
+ divHeight: 100,
+ divMargin: 5,
+ }],
+ selectedDiv: null,
+ // Handling the state of the styles
+ flexWrap: 'nowrap',
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ alignItems: 'flex-start',
+ alignContent: 'flex-start',
+
+ htmlArr: [
+ '',
+ '',
+ ''
+ ],
+
+ codeModal: false
+ }
}
- //Adding More Divs
+ //Adding More Divs
addDiv = () => {
let initialN = this.state.nDivs;
+ initialN.push({
+ divWidth: 100,
+ divHeight: 100,
+ divMargin: 5,
+ });
let initialHtmlArr = this.state.htmlArr;
initialHtmlArr.push('')
this.setState({
- nDivs: initialN + 1,
+ nDivs: initialN,
htmlArr: initialHtmlArr
})
}
@@ -66,11 +56,12 @@ class App extends React.Component {
// delete divs
delDiv = () => {
let initialN = this.state.nDivs;
+ initialN.pop();
let initialHtmlArr = this.state.htmlArr;
- if (initialN > 1) {
+ if (initialN.length > 0) {
initialHtmlArr.pop();
this.setState({
- nDivs: initialN - 1,
+ nDivs: initialN,
htmlArr: initialHtmlArr
});
}
@@ -79,26 +70,30 @@ class App extends React.Component {
// Functions that get user inputs and change state
changeDivsWidth = event => {
- let currentValue = event.target.value;
+ let currentValue = parseInt(event.target.value, 10);
+ const divArr = this.state.nDivs;
+ divArr[this.state.selectedDiv].divWidth = currentValue;
this.setState({
- divsWidth: currentValue + 'px'
+ nDivs: divArr
})
}
changeDivsHeight = event => {
- let currentValue = event.target.value;
- // console.log(currentValue);
+ let currentValue = parseInt(event.target.value, 10);
+ const divArr = this.state.nDivs;
+ divArr[this.state.selectedDiv].divHeight = currentValue;
this.setState({
- divsHeight: currentValue + 'px'
+ nDivs: divArr
})
}
// Change Margin
changeDivsMargin = event => {
- let currentValue = event.target.value;
- // console.log(currentValue);
+ let currentValue = parseInt(event.target.value, 10);
+ const divArr = this.state.nDivs;
+ divArr[this.state.selectedDiv].divMargin = currentValue;
this.setState({
- divsMargin: currentValue + 'px'
+ nDivs: divArr
})
}
@@ -149,8 +144,23 @@ class App extends React.Component {
})
}
- render() {
+ onDivSelect(index) {
+ if (this.state.selectedDiv === index) {
+ this.setState({selectedDiv: null});
+ } else {
+ this.setState({selectedDiv: index});
+ }
+ }
+
+ repeatComp(divArr) {
+ let renderDivs = [];
+ for (let i = 0; i < divArr.length; i++) {
+ renderDivs.push();
+ }
+ return renderDivs;
+ }
+ render() {
const cssParentArr = [
'display: flex',
`flex-wrap: ${this.state.flexWrap}`,
@@ -197,22 +207,15 @@ class App extends React.Component {
alignContent: this.state.alignContent
}}
>
-
- {
- repeatComp(
- ,
- this.state.nDivs
- )
- }
-
+ {this.repeatComp(this.state.nDivs)}