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

            
              <header>
  <h1>Composi Todo List</h1>
</header>
<section></section>
            
          
!

CSS

            
              /* Bootstrap 4 Reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -ms-overflow-style: scrollbar;
  -webkit-tap-highlight-color: transparent;
  font-size: 62.5%;
}

@-ms-viewport {
  width: device-width;
}

article, aside, dialog, figcaption, figure, footer, header, hgroup, main, nav, section {
  display: block;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 1.4rem;
  font-weight: normal;
  line-height: 1.5;
  color: #212529;
  text-align: left;
  background-color: #fff;
}

[tabindex="-1"]:focus {
  outline: none !important;
}

hr {
  box-sizing: content-box;
  height: 0;
  overflow: visible;
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: .5rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

abbr[title],
abbr[data-original-title] {
  text-decoration: underline;
  -webkit-text-decoration: underline dotted;
          text-decoration: underline dotted;
  cursor: help;
  border-bottom: 0;
}

address {
  margin-bottom: 1rem;
  font-style: normal;
  line-height: inherit;
}

ol,
ul,
dl {
  margin-top: 0;
  margin-bottom: 1rem;
}

ol ol,
ul ul,
ol ul,
ul ol {
  margin-bottom: 0;
}

dt {
  font-weight: bold;
}

dd {
  margin-bottom: .5rem;
  margin-left: 0;
}

blockquote {
  margin: 0 0 1rem;
}

dfn {
  font-style: italic;
}

b,
strong {
  font-weight: bolder;
}

small {
  font-size: 80%;
}

sub,
sup {
  position: relative;
  font-size: 75%;
  line-height: 0;
  vertical-align: baseline;
}

sub {
  bottom: -.25em;
}

sup {
  top: -.5em;
}

a {
  color: #007bff;
  text-decoration: none;
  background-color: transparent;
  -webkit-text-decoration-skip: objects;
}

a:hover {
  color: #0056b3;
  text-decoration: underline;
}

a:not([href]):not([tabindex]) {
  color: inherit;
  text-decoration: none;
}

a:not([href]):not([tabindex]):focus, a:not([href]):not([tabindex]):hover {
  color: inherit;
  text-decoration: none;
}

a:not([href]):not([tabindex]):focus {
  outline: 0;
}

pre,
code,
kbd,
samp {
  font-family: monospace, monospace;
  font-size: 1em;
}

pre {
  margin-top: 0;
  margin-bottom: 1rem;
  overflow: auto;
  -ms-overflow-style: scrollbar;
}

figure {
  margin: 0 0 1rem;
}

img {
  vertical-align: middle;
  border-style: none;
}

svg:not(:root) {
  overflow: hidden;
}

a,
area,
button,
[role="button"],
input:not([type=range]),
label,
select,
summary,
textarea {
  -ms-touch-action: manipulation;
  touch-action: manipulation;
}

table {
  border-collapse: collapse;
}

caption {
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  color: #868e96;
  text-align: left;
  caption-side: bottom;
}

th {
  text-align: inherit;
}

label {
  display: inline-block;
  margin-bottom: .5rem;
}

button {
  border-radius: 0;
  border: solid 1px #ccc;
  background-color: #ccc;
  overflow: hidden;
}

button:focus {
  outline: 1px dotted;
  outline: 5px auto -webkit-focus-ring-color;
}

input,
button,
select,
optgroup,
textarea {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

button,
input {
  overflow: visible;
  border: solid 1px #ccc;
}

button,
select {
  text-transform: none;
}

button,
html [type="button"],
[type="reset"],
[type="submit"] {
  -webkit-appearance: button;
}

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
  padding: 0;
  border-style: none;
}

input[type="radio"],
input[type="checkbox"] {
  box-sizing: border-box;
  padding: 0;
}

input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  -webkit-appearance: listbox;
}

textarea {
  overflow: auto;
  resize: vertical;
}

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

legend {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin-bottom: .5rem;
  font-size: 1.5rem;
  line-height: inherit;
  color: inherit;
  white-space: normal;
}

progress {
  vertical-align: baseline;
}

[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
  height: auto;
}

[type="search"] {
  outline-offset: -2px;
  -webkit-appearance: none;
}

[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

::-webkit-file-upload-button {
  font: inherit;
  -webkit-appearance: button;
}

output {
  display: inline-block;
}

summary {
  display: list-item;
}

template {
  display: none;
}

[hidden] {
  display: none !important;
}

html, body, h1, h2, h3, h4, h5, h6, p, ol, ul, li, dl,
dt, dd, blockquote, address, table {
  margin: 0;
  padding: 0;
}

* {
  font-weight: 100;
}


/****************/
/* Local Styles */
/****************/

html, body {
  height: 100%;
  -webkit-font-smoothing: antialiased;
}
body, section {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

header {
  background-color: #0268BF;
  padding: 2rem;
  box-shadow: 0 6px 6px rgba(0,0,0,0.5);
}
header h1 {
  color: #fff;
  margin: 0;
  font-size: 2.5rem
}
section {
  flex: 1;
}
.parent-view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.todo-list {
  list-style: none;
  padding: 0;
  flex: 1;
  border-top: solid 1px #ccc;
  position: relative;
}
.todo-list li {
  display: flex;
  flex-direction: row;
  border-bottom: solid 1px #ccc;
  padding: 10px 2rem;
  background-color: #FAFCFD;
}
.todo-list h3 {
  min-width: 50px;
  margin-right: 10px;
}


nav {
  background-color: #0268BF;
}
nav > h1 {
  color: #fafafa;
  text-align: left;
}
nav button {
  color: #fafafa;
}
nav input {
  border-radius: 0;
}
li.active #checkmark {
  opacity: 0;
}
.todo-list li h3 {
  text-decoration: line-through;
  flex: 1;
}
.todo-list li.active {
  background-color: #fff;
}
.todo-list li.active h3 {
  text-decoration: none;
}
.todo-list li.hidden {
  display: none;
}
button {
  transition: all .25s ease-out;
  cursor: pointer;
}
button.set-state {
  padding: 0;
  height: 30px;
  width: 30px;
  background-color: #fff;
  border: solid 1px #007AFF;
  border-radius: 30px;
  margin-right: 10px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
button.delete {
  padding: 0;
  height: 30px;
  width: 30px;
  border: solid 1px #FF0000;
  border-radius: 30px;
  margin-right: 10px;
  background-color: transparent;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
button.delete > svg {
  transform: scale(.75);
}
button.delete:hover {
  background-color: #ff0000;
}
button.delete:hover #Delete {
  stroke: #ffffff;
}
li.active .set-state {
  border: solid 1px #ccc;
}
button.set-state:hover {
  border: solid 1px #007aff;
  background-color: #007aff;
}
li.active button.set-state:hover #checkmark,
button.set-state:hover #checkmark {
  stroke: #ffffff;
  opacity: 1;
}
footer {
  display: flex;
  flex-direction: row;
  background-color: #fff;
  border-top: solid 1px #ccc;
  padding: 2rem;
}
footer button {
  padding: 2px 10px;
  background-color: #fff;
  border-color: #007AFF;
  border: solid 1px transparent;
  border-radius: 8px;
  margin-left: 10px;
}
footer button:hover {
  background-color: #007AFF;
  color: #fff;
  border: solid 1px #007AFF;
}
footer button.selected {
  border: solid 1px #007AFF;
}
.add-todo {
  padding: 3rem 2rem 2rem;
}
.add-todo input {
  margin-right: 2rem;
}
.addItem {
  border-color: #007AFF;
  color: #007AFF;
  background-color: #fff;
  border-radius: 4px;
}
.addItem:hover {
  background-color: #007AFF;
  color: #fff;
}

#totals-view {
  margin-right: 10px;
}
            
          
!

JS

            
              /** @jsx h */
const { h, render, Component } = composi


// uuid for list items
function uuid() {
  return Math.floor(Math.random() * 100000000 + Math.random() * 1000)
}

// Get items from localStorage:
function loadFromLocalStorage() {
  let todos = localStorage.getItem('todo-list')
  return JSON.parse(todos)
}

// Footer Component:
function Footer({ data, showAll, showActive, showCompleted }) {
  let count = 0
  data.forEach(item => {
    if (item.active === true) {
      count += 1
    }
  })
  return (
    <footer>
      <div id="totals-view"><span>{count} left.</span></div>
      <p>Show: </p>
      <div id="show-todo-state">
        <button onclick={e => showAll(e)} id="show-all" class="selected">All</button>
        <button onclick={e => showActive(e)}  id="show-active" class="">Active</button>
        <button onclick={e => showCompleted(e)}  id="show-completed" class="">Completed</button>
      </div>
    </footer>
  )
}

// List Item Component:
function ListItem({ setActiveState, deleteItem, item }) {
  return (
    <li key={item.id} class={item.active ? 'active' : ''}>
      <button data-id={item.id} class='set-state' onclick={e => setActiveState(e)}>
        <svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="selection-indicator"><path d="M2,13 L9.9294326,16.8406135 L17.1937075,1.90173332" id="checkmark" stroke="#007AFF" stroke-width="2"></path></g></g></svg>
      </button>
      <h3>{item.value}</h3>
      <button onclick={e => deleteItem(e)} data-id={item.id} class="delete">
        <svg width="30px" height="30px" viewBox="0 0 30 30" version="1.1"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Delete" stroke="#FF0000" stroke-width="2" stroke-linecap="square"><path d="M26.5,3.5 L3.5,26.5" id="Line"></path><path d="M3.5,3.5 L26.5,26.5" id="Line"></path></g></g></svg>
      </button>
    </li>
  )
}


class TodoList extends Component {
  constructor(props) {
    super(props)
    this.setActiveState = this.setActiveState.bind(this)
    this.deleteItem = this.deleteItem.bind(this)
    this.showAll = this.showAll.bind(this)
    this.showActive = this.showActive.bind(this)
    this.showCompleted = this.showCompleted.bind(this)
  }
  render(data) {
    return (
      <div class="parent-view">
        <p class="add-todo">
          <input type="text"  />
          <button class='addItem' onclick={() => this.addItem()}>Add Item</button>
        </p>
        <ul class='todo-list'>
          {
            data.map(item => (
              <ListItem deleteItem={this.deleteItem} setActiveState={this.setActiveState} item={item}  />
            ))
          }
        </ul>
        <Footer showAll={this.showAll} showActive={this.showActive} showCompleted={this.showCompleted} data={this.state} />
      </div>
    )
  }
  componentDidMount() {
    this.input = this.element.querySelector('input')
    this.state.forEach(item => {
      if (item.active === true) this.activeItems + 1
    })
  }
  addItem() {
    const value = this.input.value
    if (value) {
      this.setState(prevState => {
        prevState.push({
          active: true,
          value,
          id: uuid()
        })
        this.input.value = ''
        this.input.focus()
        localStorage.setItem('todo-list', JSON.stringify(prevState))
        return prevState
      })
    } else {
      alert('Please provide a value before submitting.')
    }
  }
  deleteItem(e) {
    const id = e.currentTarget.dataset.id
    this.setState(prevState => {
      const index = prevState.findIndex(item => item.id == id)
      prevState.splice(index, 1)
      localStorage.setItem('todo-list', JSON.stringify(prevState))
      return prevState
    })
  }
  setActiveState(e) {
    const id = e.currentTarget.dataset.id
    this.setState(prevState => {
      const index = prevState.findIndex(item => {
        return item.id == id
      })
      prevState[index].active = !prevState[index].active
      localStorage.setItem('todo-list', JSON.stringify(prevState))
      return prevState
    })
  }
  setSelectedStateOfButtons(e) {
    var button = e.currentTarget
    for (let i = 0; i < button.parentNode.children.length; i++) {
      button.parentNode.children[i].className = ''
    }
    button.className = 'selected'
  }
  getAllListItems() {
    return Array.prototype.slice.call(this.element.querySelectorAll('li'))
  }
  showAll(e) {
    this.setSelectedStateOfButtons(e)
    const listItems = this.getAllListItems()
    listItems.map(item => item.classList.remove('hidden'))
  }
  showActive(e) {
    this.setSelectedStateOfButtons(e)
    const listItems = this.getAllListItems()
    this.state.map((item, idx) => {
      if (!item.active) listItems[idx].classList.add('hidden')
      else listItems[idx].classList.remove('hidden')
    })
  }
  showCompleted(e) {
    this.setSelectedStateOfButtons(e)
    const listItems = this.getAllListItems()
    this.state.map((item, idx) => {
      if (item.active) listItems[idx].classList.add('hidden')
      else listItems[idx].classList.remove('hidden')
    })
  }
}


// Instantiate list with default todos:
const list = new TodoList({
  container: 'section',
  state: [
    { active: true, value: 'Take a nap', id: uuid() }, 
    { active: false, value: 'Eat a snack', id: uuid() }, 
    { active: true, value: 'Talk with Mom', id: uuid() }
  ]
})



// When DOM is ready, check for todos stored in localStorage.
// If they exist, use them to render list.
// Otherwise use default list state.
document.addEventListener('DOMContentLoaded', () => {
  setTimeout(() => {
    const data = loadFromLocalStorage()
    if (data && data.length) {
      list.setState(data)
    } else {
      list.update()
    }
  })
})
            
          
!
999px

Console