diff --git a/src/App.js b/src/App.js
index 00c7ea9d..c2695b2b 100644
--- a/src/App.js
+++ b/src/App.js
@@ -5,10 +5,10 @@ import Counters from "./components/counters";
class App extends Component {
state = {
counters: [
- { id: 1, value: 0 },
- { id: 2, value: 0 },
- { id: 3, value: 0 },
- { id: 4, value: 0 }
+ { id: 1, value: 0, description: '' },
+ { id: 2, value: 0, description: '' },
+ { id: 3, value: 0, description: '' },
+ { id: 4, value: 0, description: '' }
]
};
@@ -45,6 +45,15 @@ class App extends Component {
window.location.reload();
};
+ handleDescriptionChange = (counter, desc) => {
+ const counters = [...this.state.counters];
+ const index = counters.indexOf(counter);
+ counters[index] = { ...counters[index] };
+ counters[index].description = desc;
+ this.setState({ counters });
+ };
+
+
render() {
return (
@@ -59,6 +68,7 @@ class App extends Component {
onDecrement={this.handleDecrement}
onDelete={this.handleDelete}
onRestart={this.handleRestart}
+ onDescriptionChange={this.handleDescriptionChange}
/>
diff --git a/src/components/counter.jsx b/src/components/counter.jsx
index 862ab509..ead8a271 100644
--- a/src/components/counter.jsx
+++ b/src/components/counter.jsx
@@ -1,6 +1,25 @@
import React, { Component } from "react";
class Counter extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {disabled: true, description: props.description};
+
+ this.handleDescriptionChange = this.handleDescriptionChange.bind(this)
+ }
+
+ // Handle Description change
+ handleDescriptionChange(event) {
+ let prevDescription = this.props.description,
+ currentDescription = event.target.value;
+
+ if( prevDescription !== currentDescription ){
+ this.setState({...this.state, disabled: false});
+ }
+
+ this.props.handleDescriptionChange(this.props.counter, currentDescription)
+ }
+
render() {
return (
@@ -10,7 +29,7 @@ class Counter extends Component {
{this.formatCount()}
-
@@ -46,6 +80,7 @@ class Counter extends Component {
const { value } = this.props.counter;
return value === 0 ? "Zero" : value;
};
+
}
export default Counter;
diff --git a/src/components/counters.jsx b/src/components/counters.jsx
index edaccf3b..b16bba00 100644
--- a/src/components/counters.jsx
+++ b/src/components/counters.jsx
@@ -9,7 +9,8 @@ class Counters extends Component {
onDelete,
onDecrement,
counters,
- onRestart
+ onRestart,
+ onDescriptionChange
} = this.props;
return (
@@ -34,6 +35,7 @@ class Counters extends Component {
onIncrement={onIncrement}
onDecrement={onDecrement}
onDelete={onDelete}
+ handleDescriptionChange={onDescriptionChange}
/>
))}
diff --git a/src/index.css b/src/index.css
index cee5f348..eec2c1d1 100644
--- a/src/index.css
+++ b/src/index.css
@@ -12,3 +12,14 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
+
+/* Counter */
+.description{
+ width: 40%;
+ background: #F1F2F3!important;
+ border-radius: 6px;
+
+ font-size: 16px;
+ line-height: 19px;
+ color: #787F85;
+}
\ No newline at end of file