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 class="app"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Bitter:400,400i,700|Montserrat:300,400,700');
@import url(//fonts.googleapis.com/icon?family=Material+Icons);

.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 1rem; 
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;

  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;

  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;

  /* Support for IE. */
  font-feature-settings: 'liga';
}

$main-font: 'Montserrat', sans-serif;
$second-font: 'Bitter', serif;

$inner-padding: 1rem;

* {box-sizing: border-box;}

html, body {
  font-family: $main-font;
  font-size: 16px;
  font-wieght: 300;
  color: #404040;
}

.container {
  display: flex;
  width: 50rem;
  height: 40rem;
  margin: 2rem auto;
}

.photo {
  position: relative;
  height: 100%;
  overflow: hidden;
  img {
    width: auto;
    height: 100%;
  }
  &-mode {
    display: none;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    background: #0099cc;
    background-image: url('https://images.unsplash.com/photo-1439853949127-fa647821eba0?dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb');
    background-size: auto 100%;
    &--multiply, &--overlay, &--darken, &--lighten, &--exclusion, &--difference, &--screen, &--luminosity {
      display: block;
    }
    &--multiply {
      background-blend-mode: multiply;
    }
    &--overlay {
      background-blend-mode: overlay;
    }
    &--darken {
      background-blend-mode: darken;
    }     
    &--lighten {
      background-blend-mode: lighten;
    }    
    &--exclusion {
      background-blend-mode: exclusion;
    }    
    &--difference {
      background-blend-mode: difference;
    }      
    &--screen {
      background-blend-mode: screen;
    }    
    &--luminosity {
      background-blend-mode: luminosity;
    }      
  }
}

.filter {
  flex: 1;
  padding: $inner-padding;
  background: #f0f8ff;
  &-item {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    height: calc(100% / 8);
    label {
      width: 100%;
      text-transform: uppercase;
      font-size: .75rem;
      color: #404040;
    }
    i {
      width: 1.5rem;
      height: 1.5rem;
      line-height: 1.5rem;
      margin-right: 1.5rem;
      color: #404040;
    }
    input {
      width: calc(100% - 3rem);
      margin: 0;
    }
  }
  .modes {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-right: -1rem;
    &-item {
      cursor: pointer;
      width: 4rem;
      height: 4rem;
      margin: 0 1rem 1rem 0;
      border-radius: 100%;
      background-color: #0099cc;
      background-image: url('https://images.unsplash.com/photo-1439853949127-fa647821eba0?dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb');
      background-size: 100% 100%;
      background-repeat: no-repeat;
      &--multiply {
        background-blend-mode: multiply;
      }
      &--overlay {
        background-blend-mode: overlay;
      }
      &--darken {
        background-blend-mode: darken;
      }     
      &--lighten {
        background-blend-mode: lighten;
      }    
      &--exclusion {
        background-blend-mode: exclusion;
      }    
      &--difference {
        background-blend-mode: difference;
      }      
      &--screen {
        background-blend-mode: screen;
      }    
      &--luminosity {
        background-blend-mode: luminosity;
      }         
    }
  }
}

/* Range Inputs Style */

input[type=range]:invalid {
    box-shadow: none;
}

input[type=range] {
  -webkit-appearance: none;
  background: transparent;
  -webkit-margin: -1rem 0 0 0;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
    cursor: pointer;
  background: #e1e1e1; 
  border-color: transparent;
  color: transparent;
}

input[type=range]:focus {
  outline: none;
}

input[type=range]::-ms-track {
  cursor: pointer;
  background: #e1e1e1; 
  border-color: transparent;
  color: transparent;
}

input[type=range]::-moz-range-track {
  cursor: pointer;
  background: #e1e1e1; 
  border-color: transparent;
  color: transparent;
    border-radius: 1.3px;
}

input[type=range]::-webkit-slider-thumb {
  border-radius: 100%;
  height: 1.5rem;
  width: 1.5rem;
  background: #ffffff;
  cursor: pointer;
  background: #c6e2ff;
  border: 0;
  margin-top: -.75rem;
}

input[type=range]::-webkit-slider-runnable-track {
  height: 2px;
  cursor: pointer;
  background: #e1e1e1; 
  border-radius: 1.3px;
  margin-top: -1rem
}

/* All the same stuff for Firefox */
input[type=range]::-moz-range-thumb {
  border-radius: 100%;
  height: 1.5rem;
  width: 1.5rem;
  background: #ffffff;
  cursor: pointer;
  background: #c6e2ff;
  border: 0;
}

input[type=range]::-moz-focus-outer {
  border: 0;
}

@-moz-document url-prefix() { 
  input[type=range] {
    position: relative;
    top: .3rem;
  }
}
              
            
!

JS

              
                const filters = [
  {
    label: 'brightness',
    value: 1,
    icon: 'brightness_5'
  },
  {
    label: 'grayscale',
    value: 0,
    icon: 'brightness_1'
  },
  {
    label: 'contrast',
    value: 1,
    icon: 'brightness_6'
  },
  {
    label: 'hue',
    value: 0,
    icon: 'brightness_3'
  },
  {
    label: 'sepia',
    value: 0,
    icon: 'brightness_1'
  },
   {
    label: 'saturate',
    value: 1,
     icon: 'brightness_7'
  }, 
]

const Photo = (props) => {
  return (
    <div className="photo">
      <img style={props.style} src="https://images.unsplash.com/photo-1439853949127-fa647821eba0?dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb" />
      <div className={props.className}></div>
    </div>
  )
}

const Modes = (props) => {
  return (
    <div className="modes">
      <div id="multiply" className="modes-item modes-item--multiply" onClick={props.onClick}></div>
      <div id="overlay" className="modes-item modes-item--overlay" onClick={props.onClick}></div>
      <div id="darken" className="modes-item modes-item--darken" onClick={props.onClick}></div>
      <div id="lighten" className="modes-item modes-item--lighten" onClick={props.onClick}></div>
      <div id="exclusion" className="modes-item modes-item--exclusion" onClick={props.onClick}></div>
      <div id="difference" className="modes-item modes-item--difference" onClick={props.onClick}></div>
      <div id="screen" className="modes-item modes-item--screen" onClick={props.onClick}></div>
      <div id="luminosity" className="modes-item modes-item--luminosity" onClick={props.onClick}></div>      
    </div>
  )
}

const Item = (props) => {
  return (
    <div className="filter-item">
      <label>{props.label}</label>
      <i className="material-icons">{props.icon}</i>
      <input name={props.label} type="range" defaultValue={props.value} id={props.index} onChange={props.onChange}/>
    </div>
  )
}

const Filter = (props) => {
  
  let item = props.filters.map((item, index) => {
    return (
      <Item index={index} label={item.label} icon={item.icon} value={item.value} onChange={props.onChange}/>
    )
  })
  
  return (
    <div className="filter">
      {item}
      <Modes onClick={props.handleModes}/>
    </div>
  )
}

class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      filters: filters,
      mode: false
    }
    this.onChange = this.onChange.bind(this)
    this.handleModes = this.handleModes.bind(this)
  }
  
  render() {
    
    let style = {
      filter: 'grayScale(' + this.state.filters[1].value + ')' +
      'hue-rotate(' + this.state.filters[3].value + 'deg)' +
      'brightness(' + this.state.filters[0].value + ')' +
      'contrast(' + this.state.filters[2].value + ')' +
      'sepia(' + this.state.filters[4].value + ')' +
      'saturate(' + this.state.filters[5].value + ')'
    }
    
    return (
      <div className="container">
        <Photo style={style} className={this.state.mode ? 'photo-mode photo-mode--' + this.state.modeClass : 'photo-mode'}/>        
        <Filter filters={this.state.filters} onChange={this.onChange} handleModes={this.handleModes}/>
      </div>
    )
  }
  
  handleModes(event) {
    let name = event.target.id
    this.setState({
      modeClass: name,
      mode: true
    })
  }
  
  onChange(event) {
    this.setState({
      mode: false
    })
    let filterId = Number(event.target.id),
        filters = this.state.filters,
        value = Number(event.target.value),
        name = event.target.name
    if (name == 'grayscale') {
      filters[filterId].value = value / 100
    } else if (name == 'hue') {
      filters[filterId].value = value * 3.6
    } else if (name == 'brightness') {
      filters[filterId].value = value < 1 ? 1 : (1 + value / 10)
    } else if (name == 'contrast') {
      filters[filterId].value = value < 1 ? 1 : (1 + value / 10)
    } else if (name == 'sepia') {
      filters[filterId].value = value / 100
    } else if (name == 'saturate') {
      filters[filterId].value = value < 1 ? 1 : (1 + value / 10)
    }
    this.setState({
      filters: filters
    })
  }
}

ReactDOM.render(<App/>, document.querySelector('.app'))
              
            
!
999px

Console