Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,600,700);

* {
  font-family: 'Open Sans';
}

html, body {
  background: #FAFAFA;
  font-size: 14px;  
}

.main {
  button {
    border: none;
    background: #3ed37d;
    color: #FFF;
    padding: 10px;
    cursor: pointer;
    border-radius: 5px;
    outline: none;
    margin: 5px;
    
    &:hover {
      background: lighten(#3ed37d, 15%);
    }
  }
}

.notification {
  position: fixed;
  top: 5px; right: 5px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: #FFF;
  border-radius: 5px;
  box-shadow: 0 1px 10px rgba(0, 0, 0, 0.2);
  transition: 0.3s all;
  opacity: 0;
  transform: translate(0, 100px);
  max-width: 400px;
  
  &.show {
    opacity: 1;
    transform: translate(0, 0);
  }
}
              
            
!

JS

              
                // Provider
var Provider = ReactRedux.Provider

// Some data
var quotes = [
  'Look deep into nature, and then you will understand everything better.',
  'You can\'t blame gravity for falling in love',
  'Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.',
  'Try not to become a man of success, but rather try to become a man of value.',
  'Health is the greatest gift, contentment the greatest wealth, faithfulness the best relationship.',
  'Three things cannot be long hidden: the sun, the moon, and the truth.',
  'When I was young I thought that money was the most important thing in life; now that I am old I know that it is.',
  'No great artist ever sees things as they really are. If he did, he would cease to be an artist.'
];

// Default state
var notifyDefault = {
  display: false,
  message: ''
}

// Reducer
const notificationReducer = (state = notifyDefault, action) => {
  switch (action.type) {
    case 'SHOW_NOTIFICATION':
      return {
        display: true,
        message: action.message ? action.message : quotes[Math.floor(Math.random()*quotes.length)]
      };
    case 'HIDE_NOTIFICATION':
      return {
        display: false,
        message: state.message
      };
    default:
      return state;
  }
}

// Store
var notificationStore = Redux.createStore(notificationReducer)

/* React component */

class NotificationBox extends React.Component {
  render() {
    var notifyClass = "notification";
    if (this.props.notify.display) {
      notifyClass += " show";
    }
    return (
      <div className={notifyClass}>
      {this.props.notify.message}
      </div>
    )
  } 
}
// Connect NotificationBox component with store
var NotificationBoxComponent = ReactRedux.connect(
  state => ({notify: state})
)(NotificationBox);


class App extends React.Component {
  showNotify() {
    notificationStore.dispatch({
      type: 'SHOW_NOTIFICATION'
    })
    
    setTimeout(function() {
      notificationStore.dispatch({
        type: 'HIDE_NOTIFICATION'
      })
    }, 3000)
  }
  
  showCustomNotify() {
    notificationStore.dispatch({
      type: 'SHOW_NOTIFICATION',
      message: 'This is the custom message notification'
    })
    
    setTimeout(function() {
      notificationStore.dispatch({
        type: 'HIDE_NOTIFICATION'
      })
    }, 3000)
  }
  
  render() {
    return (
      <Provider store={notificationStore}>
        <div className="main">
          <button onClick={this.showNotify}>Show Quotes</button><br/>
          <button onClick={this.showCustomNotify}>Show Custom Message</button>
          <NotificationBoxComponent/>
        </div>
      </Provider>
    )
  }
}

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

Console