cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              @import url('https://fonts.googleapis.com/css?family=Open+Sans|Slabo+27px');

body{
  font-family: 'Open Sans', sans-serif;
  background: linear-gradient(45deg, #32ff92 0%,#2bc3ff 83%);
  min-height:100vh;
}

.todo{
  display:flex;
  background: linear-gradient(to right, #e3f2fd 68%,#cce7f9 100%);
  padding:0.5em;
  // border-bottom:1px solid #90CAF9;
  align-items:flex-start;
  margin-bottom: 0.5em;
  box-shadow:2px 2px 2px rgba(0,0,0,0.3);
  max-height:100px;
  overflow:hidden;
  transition: all 300ms ease;
  
  button{
    margin-right:1em;
  }
  
  &.deleted{
    max-height:0px;
    padding:0;
    margin-bottom:0;
    opacity:0;
  }
}

button{
  border:0;
  color:#fff;
  outline:none;
}

.remove{
  color: #F44336;
  background:none;
}

.todo-list{

  max-width:400px;
  margin:3em auto 0;
  background: linear-gradient(to right, #f7f7f7 54%,#e8f4fc 100%);
  padding:1em;
  box-shadow:5px 5px 10px rgba(0,0,0,0.3);

  h1{
    margin-top:0;
    color:#212121;
    font-family: 'Slabo 27px', serif;
    text-align:center;
    
  }

  .controls{
    display:flex;
    margin-top:1em;
    input{
      flex:1;
      padding:0.5em;
      border: 1px solid rgba(#009688,0.5);
      border-right:0px;
      outline:none;
    }
    button{
      background: linear-gradient(to right, #009688 1%,#005e6b 100%);
      color:#fff;
      padding:0.5em;
    }
  }

}
            
          
!
            
              const {React, ReactDOM} = window;

class TodoList extends React.Component{

  constructor(props){
    super(props);
    this.state = JSON.parse(localStorage.getItem('todoapp')) || {
      input: '',
      todos: [{
        value: 'This is a sample TODO!',
        id: this.guid()
      }]
    };
    this.addTodo = this.addTodo.bind(this);
    this.handleInput = this.handleInput.bind(this);
    this.removeTodo = this.removeTodo.bind(this);
  }

  componentDidMount(){
    this.todoInput.focus();
  }

  componentDidUpdate(){
    localStorage.setItem('todoapp', JSON.stringify(this.state));
  }

  addTodo(){
    const newTodo = {
      value: this.state.input,
      id: this.guid()
    };

    this.setState(state => ({
      todos: [ ...state.todos, newTodo],
      input: ''
    }));
  }

  handleInput(evt){
    if(evt.nativeEvent.key === "Enter"){
      this.addTodo();
    }else{
      this.setState({
        input: evt.target.value
      });
    }
  }

  removeTodo(id){

    this.setState(state => {
      return{
        todos: state.todos.map(todo => {
          if(todo.id !== id){
            return todo;
          } else {
            return { ...todo, deleted: true }
          }
        })
      };
    });

    setTimeout(() => {
      this.setState(state => {
        return{
          todos: state.todos.filter(t => t.id !== id)
        }});
    }, 1000);
  }

  guid(){
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
      return v.toString(16);
    });
  }

  render(){
    return(
      <div className="todo-list">
        <h1>Reactjs Todo List</h1>

        { this.state.todos.map(t => <Todo key={t.id} {...t} onClick={()=>this.removeTodo(t.id)}/>)}

        <div className="controls">
          <input type="text" 
            value={this.state.input} 
            onChange={this.handleInput} 
            onKeyDown={this.handleInput}  
            ref={(input) => { this.todoInput = input; }} />
          <button onClick={this.addTodo}>Add</button>
        </div>
      </div>
    )
  }  
}

const Todo = ({value, onClick, deleted}) => (
  <div className={`todo ${deleted? 'deleted' : ''}`} >
    <button className="remove" onClick={onClick}>×</button>
    <div>{value}</div>

  </div>
);

ReactDOM.render(
  <TodoList />,
  document.querySelector('#app')
);
            
          
!
999px
Loading ..................

Console