cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              @import url(https://fonts.googleapis.com/css?family=Roboto:100);

h2 {
  font-family: 'Roboto', sans-serif;
  font-weight: 100;
  margin: 10px;
}

.usercard {
  height: 170px;
  width: 300px;
  border: 1px solid #bdbdbd;
  border-radius: 15px;
}

.circle {
  height: 100px;
  width: 100px;
  border-radius: 50%;
  margin: 10px;
}
            
          
!
            
              class User extends React.Component {
  // getChildContext serves as the initializer for our context values
  getChildContext() {
    return {
      favColor: '#f8c483',
      userName: 'James Ipsum'
    }
  }
  
  render() {
    return(
      <div>
        <Usercard />
      </div>
    );
  }
}

// childContextTypes is defined on the context-provider, giving the context values their corresponding type and passing them down the tree 
User.childContextTypes = {
  favColor: React.PropTypes.string,
  userName: React.PropTypes.string
};

class Usercard extends React.Component {
  // Note that the Usercard component makes no use of context
  render() {
    return(
      <div className='usercard'>
        <UserIcon />
        <UserInfo />
      </div>
    );
  }
}

class UserInfo extends React.Component {
  // We can make use of these context values...
  render() {
    return(
      <h2>{this.context.userName}</h2>
    );
  }
}

// By defining corresponding contextTypes on child components down the tree that wish to access them
UserInfo.contextTypes = {
  userName: React.PropTypes.string
};

class UserIcon extends React.Component {
  // Same as above
  render() {
    return(
      <div 
        className='circle' 
        style={{
          backgroundColor: this.context.favColor
        }}></div>
    );
  }
}

// But accessing favColor instead.
UserIcon.contextTypes = {
  favColor: React.PropTypes.string
};

ReactDOM.render(<User />, document.getElementById('app'));
            
          
!
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