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. 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

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 id="root"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                class EditableText extends React.Component{
  constructor(props){
    super(props)
    this.state = {
      name: props.name,
      type: props.type||'text',
      value: props.value||'',
      editClassName: props.editClassName,
      edit: false
    }
  }
  edit() {
    this.setState({edit:edit!==false})
  }
  render() {
    return (
      this.state.edit===true&&
      <input 
        name={this.state.name}
        type={this.state.type}
        value={this.state.value}
        className={this.state.editClassName}
        autoFocus
        onFocus={event=>{
          const value = event.target.value
          event.target.value = ''
          event.target.value = value
          this.setState({backup:this.state.value})
        }}
        onChange={event=>{
          this.setState({value:event.target.value})
        }}
        onBlur={event=>{
          this.setState({edit:false})
        }}
        onKeyUp={event=>{
          if(event.key==='Escape') {
            this.setState({edit:false, value:this.state.backup})
          }
          if(event.key==='Enter') {
            this.setState({edit:false})
          }
        }}
      />
      ||
      <span onClick={event=>{
          this.setState({edit:this.state.edit!==true})
        }}>
        {this.state.value}
      </span>
    )
  }
}

class Root extends React.Component{
  constructor(props){
    super(props)
    this.state = {
      name: 'ReactJS: EditableText',
      instructions: [
        'Click text above to edit it.',
        'Press other places to make it loses its focus to persist its changes.',
        'Or press `Enter` to persist its new value and lose focus',
        'Press `Escape` to reset to value before changed.',
        'Hack! All texts in this page are editable.'
      ]
    }
    this.handleClick = this.handleClick.bind(this)
  }
  handleClick(event){
    console.log('handleClick', event.target.name)
    eval(this[event.target.name]).bind(this)(event)
  }
  helloWorld() {
    this.setState({message:'Hello, World!'})
  }
  render(){
    return (
      <div className="container-fluid">
        <h1>
          <EditableText value={this.state.name} editClassName="form-control"/>
        </h1>
        
        <div className="row">
          <div className="col-12">
            
            <EditableText value="Hello word!" editClassName="form-control"/>
            
            <hr/>
            
            <ul className="list-unstyled">
              {
                this.state.instructions.map(entry=>(
                  <li>
                    <EditableText value={entry} editClassName="form-control"/>
                  </li>
                ))
              }
            </ul>
            
          </div>
        </div>
        
      </div>
    )
  }
}

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

Console