Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div id="root"></div>
            
          
!

CSS

            
              #todo_widget {
  font-family: sans-serif;
  text-align: center;
  font-size: 1.5em;
}

ul#todo_widget {
  padding: 0;
  margin: 0;
  list-style: none;
  height: 200px;

  -ms-box-orient: horizontal;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -moz-flex;
  display: -webkit-flex;
  display: flex;

  -webkit-justify-content: space-around;
  justify-content: space-around;
  -webkit-flex-flow: row wrap;
  flex-flow: row wrap;
  -webkit-align-items: stretch;
  align-items: stretch;
}

.header,
.footer,
.todo_item {
  flex: 1 100%;
}
.button {
  flex: 1;
}
.new_item {
  flex: 9;
}

#todo_widget li {
  /*background: tomato;*/
  padding: 10px;
  width: 500px;
  // border: 3px solid rgba(0, 0, 0, 0.2);

  /*color: white;*/
  font-weight: bold;
  font-size: 0.8em;
  text-align: right;
}

#todo_widget li.header,#todo_widget li.footer {
  text-align: center;
}

button {
  color: #fff;
  text-transform: uppercase;
  background: #ed3330;
  padding: 0.5vw;
  border-radius: 5px;
  display: inline-block;
  border: none;
  height: 100%;
}
button.remove {
  background-color: green;
  padding: 0.1em;
  height: ;
}

#todo_widget li.new_item input {
  width: 100%;
  height: 100%;
}
#todo_widget li.todo_item {
  font-size: 1.1em;
  line-height: 1.2em;
  display: flex;
  align-items: center;
}

#todo_widget .checkbox {
    height: 1em;
    width: 1em;
    color: green;
    margin-right: 0.2em; 
  }
 
 strike {
  text-decoration: none;
}

input:checked + strike {
  text-decoration: line-through;
  opacity: 0.5;
}

.logo {width:auto;height:5em;}
            
          
!

JS

            
              class ToDoApp extends React.Component {
  constructor(props) {
    super();
    this.state = { list: props.list, change: "false" , doneList:props.doneList };
    this.newItem = React.createRef();
    this.doneList=[...props.doneList];
    this.list=[...this.state.list];
    console.clear();
    console.log(
      "ToDoApp-> Constructor :  list is initialised as..." +
        JSON.stringify(this.list)
    );
  }

componentWillUpdate(nextProps, nextState) {
   console.log('will update');
       this.doneList=[];
    this.list=[...nextState.list];
    console.log(this.list);
}

  render() {
    return (
      <div className="App">
        <ul id="todo_widget">
          <li className="header">
            <img class='logo' src='https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svg'/>
            <h2 className='title'>My to do list </h2></li>
          <li className="new_item add_reset_section">
            <input ref={this.newItem} placeholder="Add a new task..."/>
          </li>
          <li className="button add">
            <button onClick={this._handleAddItem}>Add</button>
          </li>
          <li className="button reset">
            <button onClick={this._handleResetList}>Reset</button>
          </li>
          {this.state.list.map((value, i) => {
            return <ToDoList key={i} i={i} item={value} remove={this._handleRemoveDoneItems} removeItem={this._handleUpdateDoneList}/>;
          })}
          <li className="footer"><button className='remove'  onClick={this._handleRemoveDoneItems}>
          Remove
        </button></li>
        </ul>
      </div>
    );
  }

  _handleAddItem = () => {
    //  let newItem =this.refs.newItem.value;
    let newItem = this.newItem.current["value"];
    if (newItem!=='') {
        this.setState({ list: [...this.state.list, newItem] });
        this.newItem.current["value"]='';
        // this.doneList[this.state.list.length]=false;
        console.log(this.doneList);

        console.log("\n ***Add Button Pressed... **");
        console.log(
          "Add handler will pull value from the input field and set the new state for ToDO app"
        );
        console.log(
          "Tip : You can use React.createRef() to reference Virtual DOM elements.  ");
     }


  };

 _handleResetList = () => {
    //  let newItem =this.refs.newItem.value;
    console.log("\n ***Reset Button Pressed... **");
    console.log(
      "Reset handler will reset list to default values..." +
        JSON.stringify(ToDoApp.defaultProps.list)
    );

    this.setState({ list: [...ToDoApp.defaultProps.list] });
  };

  _handleRemoveDoneItems = e => {


    this.doneList.sort((a, b) => a - b);
    console.log(this.doneList);
    for (var i = this.doneList.length -1; i >= 0; i--)
       this.list.splice(this.doneList[i],1);

    this.setState({ list: [...this.list] });
   
    console.log(this.list);
    this.doneList=[];

  };

  _handleUpdateDoneList = id => {


      let checkIfInDoneList = this.doneList.filter(function (val) {
          return (val === id);
      });

      if (checkIfInDoneList===undefined || checkIfInDoneList.length===0) {
      // add to list
      this.doneList.push(id);
      } else {
      //delete from list
      this.doneList= this.doneList.filter(function (val) {
          return (val !== id);
      });
      }
           console.log('donelist afterremove-->');
           console.log(this.doneList);

  };

}

ToDoApp.propTypes = {
  list: PropTypes.array
};

ToDoApp.defaultProps = {
  list: ["Get up in the morning", "Brush my teeth"],
  doneList: []
};

class ToDoList extends React.Component {
  constructor(props) {
    super();
    this.state = { value: props.item , checked:false};
    console.log(
      "ToDoList->Constructor : item value is initialised as..." +
        JSON.stringify(this.state)
    );
    console.log('-- ToDoList will RENDER..."' + this.state.value + '" to list');
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.item !== this.props.item)
      this.setState({ ...this.state, value: nextProps.item , checked:false});
    console.log(
      'ToDoList -> componentWillReceiveProps : detected property change..."' +
        nextProps.item +
        "--" +
        this.props.item
    );
  }
  _handleCheckBoxClick = (e) => {
    this.setState({
      checked: !this.state.checked
    });
   this.props.removeItem(e.target.id);
  }

  render() {
    /** RENDER  **/
    console.log("-- render");
    
    let text = this.state.checked ? <strike>{this.state.value}</strike> : this.state.value;
    let checked= this.state.checked ? 'checked' : '';
    return (
      <li className="todo_item ">
        <input className='checkbox' type="checkbox" onClick={this._handleCheckBoxClick} id={this.props.i} checked={checked} />{text}
      </li>
    );
  }

  componentWillUnmount() {
    console.log(
      "ToDoList -> componentWillUnmount :  unmount and  delete item .." + this.state.value
    );
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<ToDoApp />, rootElement);

            
          
!
999px

Console