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

CSS

              
                html,body{
  padding: 20px;
}
h3{
  margin : 40px 0 20px;
}
hr{
  border-color : transparent;
  margin : 10px;
}
.plain-label{
  font-size: 16px;
  background : #f5f5f5;
  border: 1px solid #333;
  padding: 4px 8px;
}
.success-label{
  background : green;
  color : white;
}

.error-label{
  background : red;
  color : white;
}
              
            
!

JS

              
                  'use strict';


class Label1 extends React.Component{
  constructor(props){
    super(props);
    this.className='plain-label';
  }
   render(){
     return <span className={this.className}>
        {this.props.children} 
      </span>
   }
}

class SuccessLabel extends Label1{
  constructor(props){
    super(props);
    this.className = this.className + ' success-label';
  }
}

class SuccessLabelWithIcon extends Label1{
  constructor(props){
    super(props);
    this.className = this.className + ' success-label';
  }
  render(){
    return <div>
          {super.render()}<span>&#9650;</span>
     </div>
  }
}
class ErrorLabel extends Label1{
  constructor(props){
    super(props);
    this.className = this.className + ' error-label';
  }
}






class Label2 extends React.Component{

   render(){
     return <span className={this.props.className + ' plain-label'}>
        {this.props.children} 
      </span>
   }
}

class ComposeSuccessLabel extends React.Component{
  
  render(){
    return <Label2 className='success-label'>{this.props.children}</Label2>;  
  }
}

class ComposeErrorLabel extends React.Component{
  
  render(){
    return <Label2 className='error-label'>{this.props.children}</Label2>;  
  }
}
class ComposeSuccessLabelWithIcon extends React.Component{
 render(){
     return <div>
      <Label2 className='success-label'>{this.props.children}<span>&#9650;</span></Label2>
     </div>
  } 
}




/*
 * A simple React component
 */
class Application extends React.Component {
  render() {
    return <div>
      <h1> Extending React Components </h1>
      <h3> Inheritance </h3>
      <Label1> Plain Label </Label1>
      <hr/>
      <SuccessLabel> Success Label </SuccessLabel>
      <hr/>
      <ErrorLabel> Error Label </ErrorLabel>
      <hr/>
      <SuccessLabelWithIcon> Success Label with Icon </SuccessLabelWithIcon>
      <h3>Composition (Favored)</h3>
      <Label2>Plain Label</Label2>
            <hr/>
      <ComposeSuccessLabel>SuccessLabel</ComposeSuccessLabel>
            <hr/>
       <ComposeErrorLabel>ErrorLabel</ComposeErrorLabel>
      <hr/>
            <ComposeSuccessLabelWithIcon>SuccessLabel With Icon</ComposeSuccessLabelWithIcon>
      

    </div>;
  }
}

/*
 * Render the above component into the div#app
 */
ReactDOM.render(<Application />, document.getElementById('app'));
              
            
!
999px

Console