Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                #app
              
            
!

CSS

              
                @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;
    }
  }

}
              
            
!

JS

              
                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

Console