css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <div class="wrapper"></div>
            
          
!
            
              html, body {
  background-image: url('http://i.imgur.com/7Orp3U5.jpg');
  background-size: cover;
  background-position: center;
  color: #fff;
  height: 100%;
}

.wrapper {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  
  .card {
    background-color: #fff;
    color: #333;
    padding: 15px;
    border: 1px solid #e9e9e9;
    border-bottom-color: #d5d5d5;
    border-bottom-width: 2px;
    border-radius: 4px;
    
    h1 {
      text-transform: uppercase;
      font-family: impact;
    }
  }
}

.secret {
  opacity: 0.5;
  transition: opacity 0.3s;
  -webkit-transition: opacity 0.3s;
}

button {
  border-radius: 5px;
  padding: 10px;
  color: #fff;
  background-color: #000;
  width: 100%;
  text-transform: uppercase;
  
  &.pressed {
    opacity: 0.5;
    transition: opacity 0.3s;
    -webkit-transition: opacity 0.3s;
  }
}
            
          
!
            
              class Menu extends React.Component {
  constructor(props) {
    super(props)
    
    this.state = {
      pressed: false,
      secret: 'Super Secret'
    }
  }
  
  // shouldComponentUpdate defaults to true, this is simply here for demonstration
  // purposes. If we decided that the incoming props or state didn't meet whatever
  // check we setup here we could return false to prevent the update.
  shouldComponentUpdate() {
    return true;
  }
  
  // When the component has passed shouldComponentUpdate we can make some checks
  // against the incoming props and state. In this example if the current state
  // doesn't match the incoming state we run a method that plays an animation.
  componentWillUpdate(nextProps, nextState) {
    console.log('Component is about to update!')
    
    if (nextState.pressed != this.state.pressed) {
      this.openMenu();
    } else {
      // State hasn't changed...
    }
  }
  
  // Let's you see when the component has updated.
  componentDidUpdate() {
    console.log('Component updated!');
  }
  
  // We toggle the state when the button is pressed here, this will cause 
  // the update lifecycle to fire, eventually getting to componentWillUpdate
  handleClick(event) {
    let secret = this.state.secret;
    
    if (secret.indexOf('Deal with the Devil') != -1) {
      secret = 'Super Secret'
    } else {
      secret = 'Deal with the Devil'
    }
    
    this.setState({
      pressed: !this.state.pressed,
      secret
    })
  }
  
  // If the current state of the button is false, when it's clicked we play an animation
  // to up the opacity to prepare for the incoming state.
  openMenu() {
    if (!this.state.pressed == true) {
      $(this.refs['secret']).css('opacity', '1')
    } else {
      $(this.refs['secret']).css('opacity', '0.5');
    }
  }
  
  render() {
    return (
      <div className="card">
        <button onClick={this.handleClick.bind(this)}
          className={this.state.pressed ? 'pressed' : ''}>Reveal the Secret Bottle</button>
        <div className="secret" ref="secret"><h1>{this.state.secret}</h1></div>
      </div>
    );
  }
}


ReactDOM.render(<Menu />, document.querySelector(".wrapper"));

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console