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

              
                #app
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato');
body{
  background-color:#BEDAFF;
}

.profile-box {
  font-family: Lato;
  margin: auto;
  width: 60%;
  }

h1{
  margin-top:80px;
  color:#455059;
}

.change,
.delete {
  cursor:pointer;
  color: #07A3C3;
}


.row {
  display: flex;
  flex-direction: row;
  margin-bottom: 15px;
}

.title,
a {
  flex: 0 0 30%;
  }

.row a{
  margin-left:50px;
}


form {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  height: 0;
  overflow: hidden;
  transition: height 0.5s;
}

input {
  display: block;
  margin-bottom: 3px;
  width: 240px;
  padding: 10px 3px;
  font-size: 14px;
  color: #555;
  background-color: #fff;
  border: 1px solid white;
}

button {
  padding: 2px 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.42857143;
  color: #333;
  background-color: #fff;
  border: 1px solid #ccc;
  margin-left: 5px;
}

.green {
  color: #fff;
  background-color: #91C789;
  border-color: #91C789;
}

.open {
  height: 130px;
}

.error {
  color: #d95350;
}

.type {
  display: flex;
  flex-direction: row;
}

.typeTitle {
  flex: 0 0 30%;
  }

.type button {
  width: 100px;
  background-color: #fff;
  border-color: #ccc;
  margin-right:5px;
  margin-left:0;
}

.type button:last-child:before {
  content: "Premium";
}

.type button:first-child:hover {
  color: white;
  background-color: #91C789;
}

.type button:last-child:hover {
  background-color: #FF9A16;
  color: white;
}

.type button:last-child:hover:before {
  content: "Upgrade";
}
              
            
!

JS

              
                class ProfileBox extends React.Component {
   constructor() {
    super();
    this.post = this.post.bind(this);
  }
  
   post(path, encodedFields) {
    let data = "csrf_token=12345" + encodedFields;
    let xhr = new XMLHttpRequest();
    xhr.addEventListener("readystatechange", function () {
      if (this.readyState === 4 && this.status === 200) {
        console.log(this.responseText);
      }
    });
    xhr.open("POST", path);
    xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    // xhr.send(data);
    console.log(data);
  }
    
  
  
  render() {
    return (
      <div className="profile-box">
       <h1>Manage your Profile</h1>
         <div className="profile-list">
            <Row title="Email" current="your email" post={ this.post } />
            <Row  title="Name" current="User Li" post={ this.post }/>
            <Row  title="Password" current="******" post={ this.post }/>
            <div className="type">
            <div className="typeTitle">
               Account Type
             </div>
             <div>
              <button>free</button><button></button>
             </div>
           </div>
           
          </div>
            <a className="delete" onClick={this.post.bind(this, "/account/delete","" )}>Delete Account</a>
       </div>
    )
  }
}

class Row extends React.Component {
  constructor() {
    super();
     this.state = {
    isOpen: false
    };
  }

  handleClick() {
    this.setState({
     isOpen: !this.state.isOpen,
    });
  }

  render() {
    let title = this.props.title;
    let form = <Form title={ title } classes={ this.state.isOpen ? 'open' : '' } cancel={this.handleClick.bind(this)} post={ this.props.post }/>;
    let current = this.state.isOpen ? '' : <div>{ this.props.current }</div>;
    if (title == "Name") form = <NameForm name={ this.props.current } classes={ this.state.isOpen ? 'open' : '' } cancel={this.handleClick.bind(this)} post={ this.props.post }/>;
   
    return (
      <div className="row">
        <div className="title">{title}</div>
        <div>{current}{form}</div>
        <a className="change"  onClick={this.handleClick.bind(this)}>Change {title}</a>
    </div>
    )
  }
}

class Form extends React.Component {
  constructor() {
    super();
    this.state = {
      error: false
    };

    this.change = this.change.bind(this);
    this.submit = this.submit.bind(this);
    this.cancel = this.cancel.bind(this);
  }
  
  change() {
    let error = !(this.new.value == this.confirm.value);
    this.setState({
      error
    });
  }
  
   submit(e) {
    e.preventDefault();
    if (!this.new.value || this.state.error) return;
    if (this.title == 'Password') {
      let fields = '&new=' + this.new.value;
      this.props.post('/account/update/password', encodeURI(fields));
    } else {
      let fields = `&email=${this.new.value}`;
      this.props.post('/account/update', encodeURI(fields));
    }
    e.target.reset();
  }
  
  cancel(){
    this.setState({
      error:false
    });
    this.props.cancel();
  }
  
  render() {
    let error = this.state.error ? <span className="error"> { this.props.title} not match </span> : "";
    let title = this.props.title;
    return (
      <form className={this.props.classes } onSubmit={ this.submit }>
        <div>
        <input  type={title.toLowerCase()} placeholder={`New ${title}`} ref={ input => this.new = input} onChange={ this.change }/>
        <input  type={ title.toLowerCase() } placeholder={`Confirm ${title}`} ref={ input => this.confirm = input} onChange={ this.change }/>
          {error}
        </div>
        <div>
          <button  type="reset" onClick={this.cancel } >cancel </button>  
          <button className="green" type="submit"> submit</button>
        </div>
       </form>
    )
  }
}

class NameForm extends React.Component {
   constructor(props) {
    super(props);
    this.submit = this.submit.bind(this);
    [ this.first, this.last ] = this.props.name.split(' ');
  }
  submit(e) {
    e.preventDefault();
    console.log(this.f.value, this.l.value);
  }
  render() {
   
    return (
      <form className={this.props.classes} onSubmit={ this.submit }>
        <input type='text' defaultValue={ this.first } ref={ first => this.f = first }/>
        <input type='text' defaultValue={ this.last } ref={ last => this.l = last } />
        <div>
          <button  type="reset" onClick={ this.props.cancel } >cancel </button>  
          <button className="green" type="submit"> submit</button>
        </div>
      </form>
    );
  }
}

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

Console