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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

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

CSS

              
                html {
  font-size: 75%;
}
@media screen and (min-width: 768px) {
  html {
    font-size: 87.5%;
  }
}
@media screen and (min-width: 1024px) {
  html {
    font-size: 100%;
  }
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.App {
  background-color: whitesmoke;
  height: 100vh;
  text-align: center;
}

.App-header {
  min-height: 15vh;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: #282c34;
}

.To-do-list-container {
  display: flex;
  flex-wrap: wrap;
}

.To-do-list {
  flex: 1;
}

.Add-item-btn {
  padding: 1rem;
  margin: 0;
  width: 100%;
  text-align: left;
  background: white;
  border-left: solid 10px white;
  border-right: none;
  border-top: none;
  border-bottom: none;
}

.Add-item-btn:before {
  font-weight: bold;
  font-size: 1rem;
  line-height: 1rem;
  content: "+";
  opacity: 0.5;
}

.Add-item-btn:hover {
  background: #fff8e8;
  border-left: solid 10px #ffc06e;
}

.Item-form {
  padding: 0;
  margin: 0;
  resize: none;
  border: none;
  font-size: 1em;
  width: 95%;
  height: 100%;
  background: #fff8e8;
}

.Item-form:focus {
  outline: 0;
}

.Delete-item-btn {
  padding: 0;
  width: 5%;
  background: #fff8e8;
  border: none;
  transform: rotate(45deg);
}

.Delete-item-btn:before {
  font-weight: bold;
  font-size: 1rem;
  line-height: 1rem;
  content: "+";
  opacity: 0.05;
}

.Delete-item-btn:hover:before {
  opacity: 1;
}

              
            
!

JS

              
                const { useState } = React;
const { DragDropContext, Draggable, Droppable } = ReactBeautifulDnd;

const listName = {
  list1: 'todo',
  list2: 'progress',
  list3: 'done'
};

const reorder = (list, startIndex, endIndex) => {
  const result = Array.from(list);
  const [removed] = result.splice(startIndex, 1);
  result.splice(endIndex, 0, removed);
  return result;
};

const deleteItem = (list, index) => {
  const result = Array.from(list);
  result.splice(index, 1);
  return result;
};

const move = (source, destination, droppableSource, droppableDestination) => {
  const sourceClone = Array.from(source);
  const destClone = Array.from(destination);
  const [removed] = sourceClone.splice(droppableSource.index, 1);

  destClone.splice(droppableDestination.index, 0, removed);

  const result = {};
  result[droppableSource.droppableId] = sourceClone;
  result[droppableDestination.droppableId] = destClone;

  return result;
};

const getItemStyle = draggableStyle => ({
  displey: 'flex',
  padding: '1rem',
  marginBottom: '0.5rem',
  background: '#fff8e8',
  borderLeft: 'solid 0.5rem #ffc06e',
  color: '#282c34',

  ...draggableStyle
});

const getListStyle = isDraggingOver => ({
  padding: '1rem',
  margin: '1rem',
  background: 'white',
  minWidth: '150px',
  height: '65vh',
  border: isDraggingOver ? 'solid 5px lightgray' : 'solid 5px white',
  borderRadius: '0.5rem',
  textAlign: 'left',
});

function List(props) {
  const listTitle = {
    list1: 'To do',
    list2: 'In progress',
    list3: 'Done'
  };

  return (
    <div className="To-do-list">
      <Droppable droppableId={props.id}>
        {(provided, snapshot) => (
          <div
            {...provided.droppableProps}
            ref={provided.innerRef}
            style={getListStyle(snapshot.isDraggingOver)}
          >
            <h2>{listTitle[props.id]}</h2>
            {props.list.map((item, index) => (
              <Draggable key={item.id} draggableId={item.id} index={index}>
                {(provided) => (
                  <div
                    ref={provided.innerRef}
                    {...provided.draggableProps}
                    {...provided.dragHandleProps}
                    style={getItemStyle(provided.draggableProps.style)}
                  >
                    <input
                      type="text"
                      className="Item-form"
                      placeholder="Please enter your task"
                      value={item.text}
                      onChange={e => props.onUpdateItems(props.id, index, e)}
                    />
                    <button className="Delete-item-btn" onClick={() => props.onDeleteItemForList(props.id, index)}></button>
                  </div>
                )}
              </Draggable>
            ))}
            {provided.placeholder}
            <button className="Add-item-btn" onClick={() => props.onAddItems(props.id)}></button>
          </div>
        )}
      </Droppable>
    </div>
  );
}


function ToDoListContainer() {
  const [todo, setTodoList] = useState([
    {
      id: 'item-1',
      text: ''
    }
  ]);
  const [progress, setProgressList] = useState([]);
  const [done, setDoneList] = useState([]);
  const [itemCount, setItemCount] = useState(1);

  const getList = id => {
    if (listName[id] === 'todo') {
      return todo;
    } else if (listName[id] === 'progress') {
      return progress;
    } else if (listName[id] === 'done') {
      return done;
    }
  }

  const setItemInList = (id, list) => {
    if (listName[id] === 'todo') {
      setTodoList(list);
    } else if (listName[id] === 'progress') {
      setProgressList(list);
    } else if (listName[id] === 'done') {
      setDoneList(list);
    }
  }

  const onDragEnd = result => {
    const { source, destination } = result;
    if (!result.destination) {
      return;
    }
    if (source.droppableId === destination.droppableId) {
      const update = reorder(
        getList(source.droppableId),
        source.index,
        destination.index
      );
      setItemInList(source.droppableId, update);
    } else {
      const result = move(
        getList(source.droppableId),
        getList(destination.droppableId),
        source,
        destination
      );
      setItemInList(source.droppableId, result[source.droppableId]);
      setItemInList(destination.droppableId, result[destination.droppableId]);
    }
  }

  const addItems = id => {
    setItemInList(
      id,
      getList(id).concat(
        {
          id: `item-${itemCount + 1}`,
          text: ''
        }
      )
    );
    setItemCount(itemCount + 1);
  }

  const updateItems = (id, idx, e) => {
    const list_copy = getList(id).slice();
    list_copy[idx].text = e.target.value;
    setItemInList(id, list_copy);
  }

  const deleteItemForList = (id, idx) => {
    const removed = deleteItem(getList(id),idx);
    setItemInList(id, removed);
  }

  return (
    <DragDropContext onDragEnd={onDragEnd}>
      <div className="To-do-list-container">
        {Object.keys(listName).map(key => 
          <List 
            key={key} 
            id={key} 
            list={getList(key)} 
            onAddItems={addItems} 
            onUpdateItems={updateItems}
            onDeleteItemForList={deleteItemForList}
          />
        )}
      </div>
    </DragDropContext>
  );
}

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <h1>
          To do list
        </h1>
      </header>
      <ToDoListContainer />
    </div>
  );
}

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
              
            
!
999px

Console