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 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#content
              
            
!

CSS

              
                html,
body,
#content {
  height: 100%;
}

html {
  font-size: 62.5%;
}

body {
  color: #333;
  font-family: 'Roboto', sans-serif;
  font-size: 1.6rem;
}

h1, h2, h3, h4 {
  margin: 0 0 10px;
}

input[type="checkbox"] {
  float: left;
  opacity: 0.01;
  position: absolute;

  + label {
    display: inline-block;
    line-height: 1.4;
    margin: 0;
    padding-left: 25px;
    position: relative;

    &::before {
      background: no-repeat center center;
      background-color: rgba(#74828d, 0.25);
      border: 1px solid #74828d;
      border-radius: 50%;
      content: "";
      cursor: pointer;
      display: block;
      height: 15px;
      left: 0;
      position: absolute;
      top: 1px;
      width: 15px;
    }
  }

  &:checked + label {
    color: #32a9e1;
    
    &::before {
      background-color: #32a9e1;
      background-image: url(http://www.jerrylow.com/demo/icons/checkmark.svg);
      background-size: 13px 10px;
      border-color: #32a9e1;
    }
  }

  &:focus + label {
    &::before {
      outline: auto 5px -webkit-focus-ring-color;
    }
  }
}

/**
 * App
 **/
.app {
  background: #f7f7f7;
  min-height: 100%;
}

.filters {
  box-shadow: inset -3px 0 1px rgba(0,0,0,.4);
  color: #74828d;
  background: #253447;
  max-height: 100%;
  overflow: auto;
  position: fixed;
  width: 20%;
}

.filters__header {
  background: #1c2939;
  box-shadow: inset -3px 0 1px rgba(0,0,0,.4);
  padding: 20px 40px;
}

.filters__header__title {
  color: white;
  font-size: 2rem;
  font-weight: 500;
  margin: 0;
}

.filters__inner {
  padding: 20px 40px;
}

.filters__filter {
  ul {
    margin: 0 0 30px;
    padding: 0;
    
    li {
      list-style: none;
      margin: 0 0 10px;
    }
  }
}

.filters__filter__title {
  border-bottom: 1px solid rgba(#999, .3);
  color: #567893;
  font-size: 1.2rem;
  font-weight: 100;
  margin-bottom: 15px;
  padding-bottom: 10px;
  text-transform: uppercase; 
}

.filter-bubbles {
  display: flex;
  flex-wrap: wrap;
  margin: 0 0 20px;
  padding: 0;
  
  &:empty {
    margin-bottom: 0;
  }
  
  li {
    background: #aad4ff;
    border-radius: 20px;
    color: #1c2939;
    font-size: 1.2rem;
    list-style: none;
    margin: 0 10px 10px 0;
    padding: 7px 10px;
    
    span {
      text-transform: capitalize;
    }

    button {
      background: #469aef;
      border: none;
      border-radius: 50%;
      color: white;
      cursor: pointer;
      margin: 0 0 0 5px;
      padding: 5px 8px;
      transform: rotate(45deg);
    }
  }
}

li.filters-bubbles__clear-all {
  background: none;
  padding-left: 0;
  padding-right: 0;
  
  button {
    background: none;
    border-radius: 0;
    color: #333;
    margin: 0;
    padding-left: 0;
    padding-right: 0;
    transform: none;
  }
}

.pagination {
  display: flex;
  justify-content: center;
  margin: 40px auto 20px;
  padding: 0;
  
  li {
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #ccc;
    list-style: none;
    padding: 5px 0;
    
    &:first-of-type {
      border: 1px solid #ccc;
      border-radius: 5px 0 0 5px;
      padding-left: 5px;
    }
    
    &:nth-of-type(2) {
      padding-left: 5px;
    }
    
    &:last-of-type {
      border: 1px solid #ccc;
      border-radius: 0 5px 5px 0;
      padding-right: 5px;
    }
    
    &:nth-last-of-type(2) {
      padding-right: 5px;
    }
    
    button {
      background: none;
      border: none;
      border-radius: 3px;
      cursor: pointer;
      font-size: 1.2rem;
      padding: 5px 8px 4px;
      text-align: center;
      
      &.--active {
        background: #469aef;
        color: white;
      }
      
      &:disabled {
        cursor: not-allowed;
      }
    }
  }
}

.body {
  margin-left: 20%;
  padding: 20px 50px;
  
  table {
    border-collapse: collapse;
    margin: 0 -10px;
    width: calc(100% + 20px);
    
    thead th {
      border-bottom: 1px solid #ddd;
      color: #2eacdf;
      font-size: 1.2rem;
      padding: 10px 10px;
      text-align: left;
      text-transform: uppercase;
    }
    
    tbody {
      tr:nth-of-type(2n-2) td {
        background: #ededed;
      }
      
      tr {
        &:hover td {
          background: #dcedff;
        }
  
        td {
          padding: 12px 10px;
        }
      }
    }
  }
}

.body__header__title {
  font-weight: 300;
  margin: 0 0 20px;
}
              
            
!

JS

              
                /**
 * 5000
 * Pre: 1336ms
 * Post : 144ms
 **/
const DATA_ENTRIES = 5000;
const ENTRIES_PER_PAGE = 100;

const { createStore, combineReducers } = Redux;
const { Provider, connect } = ReactRedux;

const entryAttr = {
  name: [
    "Han Solo",
    "Darth Vader",
    "Luke Skywalker",
    "Princess Leia",
    "Chewie",
    "Lando Calrissian",
    "Boba Fett",
    "Yoda",
    "R2D2",
    "Kylo Ren",
    "Rey",
    "Fin",
    "Poe Dameron",
    "Obi-Wan Kenobi"
  ],
  powers: ["Push", "Pull", "Mind Tricks", "Lighning", "Choke", "Drain"],
  color: [
    "Red",
    "Blue",
    "Green",
    "Purple",
    "Yellow",
    "Orange",
    "White",
    "Black"
  ],
  fortune: [100, 200, 300, 400, 500, 600],
  home: [
    "Crait",
    "Tatooine",
    "Hoth",
    "Endor",
    "Jakku",
    "Death Star",
    "Cloud City"
  ],
  transportation: [
    "A-Wing",
    "X-Wing",
    "Y-Wing",
    "Tie Fighter",
    "Star Destroyer",
    "Millenium Falcon"
  ]
};

/**
 * Actions
 **/
const addFilter = (name, value) => {
  return {
    type: "ADD_FILTER",
    name,
    value
  };
};

const removeFilter = (name, value) => {
  return {
    type: "REMOVE_FILTER",
    name,
    value
  };
};

const clearFilters = () => {
  return {
    type: "CLEAR_FILTERS"
  };
};

const setPage = page => {
  return {
    type: "SET_PAGE",
    page
  };
};

const setContent = entries => {
  return {
    type: "SET_CONTENT",
    entries
  };
};

/**
 * Reducers
 **/
const filters = (state = { filters: {} }, action) => {
  switch (action.type) {
    case "ADD_FILTER":
      let currentAddFilter =
        state.filters[action.name] && state.filters[action.name].length
          ? state.filters[action.name]
          : [];
      currentAddFilter.push(action.value);
      const newAddState = Object.assign({}, state.filters, {
        [action.name]: currentAddFilter
      });
      return Object.assign({}, state, { filters: newAddState });
    case "REMOVE_FILTER":
      let currentRemoveFilter =
        state.filters[action.name] && state.filters[action.name].length
          ? state.filters[action.name]
          : [];
      currentRemoveFilter = _.pull(currentRemoveFilter, action.value);

      const newRemoveState = Object.assign({}, state.filters, {
        [action.name]: currentRemoveFilter
      });
      return Object.assign({}, state, { filters: newRemoveState });
    case "CLEAR_FILTERS":
      return Object.assign({}, state, { filters: {} });
    default:
      return state;
  }
};

const pagination = (state = { page: 1 }, action) => {
  switch (action.type) {
    case "SET_PAGE":
      return Object.assign({}, state, { page: action.page });
    default:
      return state;
  }
};

const content = (state = { entries: [] }, action) => {
  switch (action.type) {
    case "SET_CONTENT":
      return Object.assign({}, state, { entries: action.entries });
    default:
      return state;
  }
};

const reducers = combineReducers({
  filters,
  pagination,
  content
});

/**
 * Components - Filters
 **/
const Filters = class Filters extends React.Component {
  updateFilter(name, e) {
    if (e.target.checked) {
      this.props.addFilter(name, e.target.value);
    } else {
      this.props.removeFilter(name, e.target.value);
    }
    
    this.props.resetPage();
  }

  render() {
    return (
      <div className="filters">
        <header className="filters__header">
          <h2 className="filters__header__title">Filters</h2>
        </header>
        <div className="filters__inner">
          {Object.keys(entryAttr)
            .filter(attr => attr !== "name")
            .map((attr, i) => {
              return (
                <div key={`filter-${i}`} className="filters__filter">
                  <h3 className="filters__filter__title">{attr}</h3>
                  <ul>
                    {entryAttr[attr].map((attrValue, attrValueKey) => {
                      const inputId = _.snakeCase(attr + attrValue);
                      const checked = this.props.filters[attr]
                        ? this.props.filters[attr].includes(attrValue.toString())
                        : false;
                      return (
                        <li key={`${attrValue}-${attrValueKey}`}>
                          <input
                            type="checkbox"
                            id={inputId}
                            value={attrValue}
                            name={attrValue}
                            checked={checked}
                            onChange={e => {
                              this.updateFilter(attr, e);
                            }}
                          />
                          <label htmlFor={inputId}>{attrValue}</label>
                        </li>
                      );
                    })}
                  </ul>
                </div>
              );
            })}
        </div>
      </div>
    );
  }
};

const FiltersMapStateToProps = state => {
  return {
    filters: state.filters.filters
  };
};

const FiltersMapDispatchToProps = dispatch => {
  return {
    addFilter: (name, value) => {
      dispatch(addFilter(name, value));
    },
    removeFilter: (name, value) => {
      dispatch(removeFilter(name, value));
    },
    resetPage: () => {
      dispatch(setPage(1));
    }
  };
};

const FiltersContainer = connect(
  FiltersMapStateToProps,
  FiltersMapDispatchToProps
)(Filters);

/**
 * Components - Filter Bubbles
 **/
const FilterBubbles = class FilterBubbles extends React.Component {
  render() {
    const allFilters = Object.keys(
      this.props.filters
    ).reduce((filters, filterKey) => {
      if (this.props.filters[filterKey]) {
        this.props.filters[filterKey].forEach(filter => {
          filters.push({
            name: filterKey,
            value: filter
          });
        });
      }
      return filters;
    }, []);
    return (
      <ul className="filter-bubbles">
        {allFilters.map(filter => {
          const filterId = _.snakeCase(`filter-${filter.name}-${filter.value}`);
          return (
            <li key={filterId}>
              <span>{filter.name}: </span>
              {filter.value}
              <button
                type="button"
                onClick={e => {
                  this.props.removeFilter(filter.name, filter.value);
                }}
              >
                +
              </button>
            </li>
          );
        })}
        {!!allFilters.length && (
          <li className="filters-bubbles__clear-all">
            <button type="button" onClick={this.props.clearFilters}>
              Clear All
            </button>
          </li>
        )}
      </ul>
    );
  }
};

const FilterBubbleMapStateToProps = state => {
  return {
    filters: state.filters.filters
  };
};

const FilterBubbleMapDispatchToProps = dispatch => {
  return {
    removeFilter: (name, value) => {
      dispatch(setPage(1));
      dispatch(removeFilter(name, value));
    },
    clearFilters: () => {
      dispatch(setPage(1));
      dispatch(clearFilters());
    }
  };
};

const FilterBubblesContainer = connect(
  FilterBubbleMapStateToProps,
  FilterBubbleMapDispatchToProps
)(FilterBubbles);

/**
 * Components - Pagination
 **/
const Pagination = class Pagination extends React.Component {
  render() {
    if (this.props.entries.length <= ENTRIES_PER_PAGE) {
      return (null);
    }
    
    const pages = this.props.entries.length / ENTRIES_PER_PAGE + 1;
    const displayPages = pages > 10 ? 10 : pages;
    const displayMin = pages > 10
      ? this.props.page - 5 < 1
        ? 1
        : this.props.page - 5
      : 1;
    const displayMax = pages > 10
      ? this.props.page + 5 > pages
        ? pages
        : this.props.page + 5 < displayMin + 10
          ? displayMin + 10
          : this.props.page + 5
      : displayPages;

    return (
      <ul className="pagination">
        <li>
          <button
            type="button"
            className='--prev'
            onClick={e => {
              this.props.setPage(this.props.page - 1);
            }}
            disabled={this.props.page - 1 <= 0}
            >
            Prev
          </button>
        </li>
        {_.range(
          displayMin,
          displayMax
        ).map((page, i) => {
          return (
            <li>
              <button
                type="button"
                className={`${page === this.props.page ? "--active" : ""}`}
                onClick={e => {
                  this.props.setPage(page);
                }}
              >
                {page}
              </button>
            </li>
          );
        })}
        <li>
          <button
            type="button"
            className='--next'
            onClick={e => {
              this.props.setPage(this.props.page + 1);
            }}
            disabled={this.props.page + 1 >= this.props.entries.length / ENTRIES_PER_PAGE}
            >
            Next
          </button>
        </li>
      </ul>
    );
  }
};

const PaginationMapStateToProps = state => {
  return {
    page: state.pagination.page
  };
};

const PaginationMapDispatchToProps = dispatch => {
  return {
    setPage: page => {
      dispatch(setPage(page));
    }
  };
};

const PaginationContainer = connect(
  PaginationMapStateToProps,
  PaginationMapDispatchToProps
)(Pagination);

/**
 * Components - Body
 **/
const Body = class Body extends React.Component {
  filterEntries() {
    if (_.isEmpty(this.props.filters)) {
      return this.props.entries;
    }

    return this.props.entries.filter(entry => {
      let matchFilters = true;
      Object.keys(this.props.filters).forEach(filterKey => {
        if (this.props.filters[filterKey].length) {
          matchFilters = this.props.filters[filterKey].includes(
            entry[filterKey].toString()
          )
            ? matchFilters
            : false;
        }
      });
      return matchFilters;
    });
  }

  render() {
    const paginationOffset = (this.props.page - 1) * ENTRIES_PER_PAGE;
    const entries = this.filterEntries();
    const paginatedEntries = entries.slice(
      paginationOffset,
      paginationOffset + ENTRIES_PER_PAGE
    );

    return (
      <section className="body">
        <header className="body__header">
          <h2 className="body__header__title">Entries ({paginationOffset + 1}-{paginationOffset + paginatedEntries.length} of {entries.length})</h2>
        </header>
        <FilterBubblesContainer />
        <table>
          <thead>
            <tr>
              {Object.keys(entryAttr).map((attr, i) => (
                <th key={`heading-${i}`}>{attr}</th>
              ))}
            </tr>
          </thead>
          <tbody>
            {paginatedEntries.map(entry => {
              return (
                <tr key={`row-${entry.id}`}>
                  {Object.keys(entryAttr).map((attr, k) => (
                    <td key={`col-${entry.id}-${k}`}>{entry[attr]}</td>
                  ))}
                </tr>
              );
            })}
          </tbody>
        </table>
        <PaginationContainer entries={entries} />
      </section>
    );
  }
};

const BodyMapStateToProp = state => {
  return {
    filters: state.filters.filters,
    page: state.pagination.page,
    entries: state.content.entries
  };
};

const BodyContainer = connect(BodyMapStateToProp)(Body);

/**
 * Components - App
 **/
const App = class App extends React.Component {
  componentWillMount() {
    this.props.setContent(this.getEntries());
  }

  getEntries() {
    const entries = [];
    for (let i = 0; i < DATA_ENTRIES; i++) {
      const entry = { id: i };

      Object.keys(entryAttr).forEach(attr => {
        entry[attr] =
          entryAttr[attr][Math.floor(Math.random() * entryAttr[attr].length)];
      });

      entries.push(entry);
    }
    return entries;
  }

  render() {
    return (
      <main className="app">
        <FiltersContainer />
        <BodyContainer />
      </main>
    );
  }
};

const AppMapStateToProps = state => {
  return {
    entries: state.content.entries
  };
};

const AppMapDispatchToProps = dispatch => {
  return {
    setContent: entries => {
      dispatch(setContent(entries));
    }
  };
};

const AppContainer = connect(AppMapStateToProps, AppMapDispatchToProps)(App);

const store = createStore(reducers);

ReactDOM.render(
  <Provider store={store}>
    <AppContainer />
  </Provider>,
  document.getElementById("content")
);

              
            
!
999px

Console