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

              
                /* Content styling */
/* fonts for the text */
@import url('https://fonts.googleapis.com/css?family=Merriweather:700|Roboto');
@import url('https://fonts.googleapis.com/css?family=Anton|Roboto');


/* Text Color Variables */
$text-color: #444c5c;

/* Color Variables */
$main-bg: #f7f6f4;
$main-grey: #d8d5c4;
$main-green: #78a5a3;
$main-yellow-light: #e1b16a;
$main-yellow: #ffc300;
$main-blue: #444c5c;
$main-dark:rgb(51, 51, 51);
$main-red: #ce5a57;
$main-white: #ffffff;
$main-black: #000a17;
$main-overlay:rgba(0, 0, 0, .3);

/* Lists */
$colors: $main-yellow $main-green $main-blue $main-red $main-dark;
$rainbowColors: $main-yellow $main-grey $main-blue $main-red $main-dark $main-red $main-blue $main-grey $main-yellow;
$fourColors: $main-yellow $main-green $main-blue $main-red;
$pages: "home" "about" "skills" "contact" "blog";

//Themes For Every Route
$theme-colors: (
    'bg': (
        'home': $main-dark,
        'about': $main-green,
        'skills': $main-blue,
        'contact': $main-red,
        'blog': $main-yellow,
    ),

    'text': (
        'home': $main-white,
        'about': $main-white,
        'skills': $main-white,
        'contact': $main-white,
        'blog': $main-white,
    ),
);

@function themeColor($key, $variant) {
    $map: map-get($theme-colors, $key);
    @return map-get($map, $variant);
}

@mixin centerer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@mixin centererHorizontal {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

@mixin centererVertical {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}


*, *:before, *:after {
  box-sizing: border-box;
}

$primary: #e14;
$secondary: #124;
$accent: #e72;

body {
  font: 400 16px Roboto, sans-serif;
  padding: 0;
  margin: 0;
  background-color: $main-dark;
}

.container {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}

.card {
  background-color: #fff;
  border-radius: 3px;
  box-shadow: 0 2px 10px rgba($secondary,.06);
  overflow: hidden;
}

.waves {
  height: 80px;
  background: linear-gradient(to bottom left, $primary, $accent);
}

h1 {
  margin: 2rem 2rem 0;
  font-size: 1.62rem;
}

.form {
  padding: 2rem;
}

.button {
  display: block;
  width: 100%;
  background-color: #e14;
  border: none;
  border-radius: 3px;
  padding: 1ch;
  font-size: 1rem;
  color: #fff;
  font-family: inherit;
}

@mixin input {
  display: block;
  width: 100%;
  border: 2px solid #eee;
  padding: 1ch;
  border-radius: 3px;
  transition: 150ms ease;
  outline: none;
  font-size: 1rem;
  font-family: inherit;
}

@mixin input-focus {
  border-color: #e14;
}

@mixin label {
  position: absolute;
  top: 1ch;
  left: 1ch;
  padding: 0 .5ch;
  pointer-events: none;
  transition: 150ms ease;
  color: #888;
}

@mixin label-focus {
  position: absolute;
  top: 0;
  font-size: 0.9em;
  color: #e14;
  font-weight: bold;
  transform: translateY(-50%);
  background-color: #fff;
  font-weight: 600;
}



.text-input {
  position: relative;
  margin-bottom: 1rem;
  label {
    @include label;
  }
  label.label-focus {
    @include label-focus;
  }
  input {
    @include input;
  }
  input.input-focus {
    @include input-focus;
  }
}

.text-area {
  position: relative;
  margin-bottom: 1rem;
  label {
    @include label;
  }
  label.label-focus {
    @include label-focus;
  }
  textarea {
    @include input;
    height: 8em;
  }
  textarea.input-focus {
    @include input-focus;
  }
}
              
            
!

JS

              
                /** ContactForm Component */

// validate empty name input and message input
function validateNameMessage(res) {
    // we are going to store errors for all fields
    // in a signle array
    const errors = [];
    
    if (res.value.length === 0) {
        errors.push(res.name + " can't be empty");
    }
    
    if (res.value.length < 3) {
        console.log(res.name);
        if (res.name == "message") {
            errors.push("Please enter a valid " + res.name + " at lease 20 characters");
        }
        
        if (res.name == "name") {
            errors.push("Please enter a valid " + res.name + " between 3 to 32 characters.");
        }
    }

    return errors;
}

// validate email
function validateEmail(res) {    
    const email = res.value
    const errors = [];
    
    if (email.length < 5 || email.split("").filter(x => x === "@").length !== 1 || email.indexOf(".") === -1) {
        errors.push("Please enter a valide email");
    }
    
    return errors;
}

class Contact extends React.Component {
    constructor() {
        super();
        this.state = {
            name: {
                name: "name",
                label: "Name",
                value: "",
                focus: false,
                errorMessage: ""
            },
            email: {
                name: "email",
                label: "Email",
                value: "",
                focus: false,
                errorMessage: false
            },
            message: {
                name: "message",
                label: "Message",
                value: "",
                focus: false,
                errorMessage: ""
            },
        };
        
        this.handleFocus = this.handleFocus.bind(this);
        this.handleBlur = this.handleBlur.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);
    }

    handleFocus(e) {
        const name = e.target.name;
        const state = Object.assign({}, this.state[name]);
        state.focus = true;
        this.setState({ [name]: state });
    }

    handleBlur(e) {
        const name = e.target.name;
        const state = Object.assign({}, this.state[name]);
        state.focus = false;
        this.setState({ [name]: state });
    }

    handleChange(e) {
        const name = e.target.name;
        const state = Object.assign({}, this.state[name]);
        let errorMessage = "";
        state.value = e.target.value;
        
        if(name == "email") {
            errorMessage = validateEmail(this.state[name]);
        } else {
            errorMessage = validateNameMessage(this.state[name]);
        }
        
        if(errorMessage) {
           state.errorMessage =  errorMessage;
        }  
        
        this.setState({ [name]: state });
    }
    
    handleSubmit(e) {
        const subject = "Mail From" + this.state.name.value,
              email = this.state.email.value,
              message = this.state.message.value; 
        event.preventDefault();
    }

    render() {
        const { name, email, message } = this.state;
        
        return (
            <div className="contact content">
                <div className="container">
                    <ContactInfo>
                        <h1> Conatact Info</h1>
                        <p>Get in touch with me at anytime if you have any question.</p>
                        <p>Ues the form to the righ or my details below and I'll get back to you ASAP.</p>
                        <a href="mailto:liangli.0311@gmail.com" subject="Ciao Liang">liangli.0311@gmail.com</a>                 
                    </ContactInfo>

                    <div className="col-sm-2"></div>

                    <Card>
                        <h1>Ge in touch</h1>
                        <Form onSubmit={this.handleSubmit}>
                            <TextInput
                                {...name}
                                onFocus={this.handleFocus}
                                onBlur={this.handleBlur}
                                onChange={this.handleChange}
                            />
                            <TextInput
                                {...email}
                                onFocus={this.handleFocus}
                                onBlur={this.handleBlur}
                                onChange={this.handleChange}
                            />
                            <TextArea
                                {...message}
                                onFocus={this.handleFocus}
                                onBlur={this.handleBlur}
                                onChange={this.handleChange}
                            />
                            <Button>Send</Button>
                        </Form>
                    </Card>
                </div>
            </div>
        );
    }
}

/** Components */
const Card = props => (
    <div className="card col-sm-7">
        {props.children}
    </div>
);

const Form = props => <form className="form" onSubmit={props.onSubmit}>{props.children}</form>;

const TextInput = props => (
    <div className="text-input">
        <label
            className={props.focus || props.value !== "" ? "label-focus" : ""}
            htmlFor={props.name}
        >
            {props.label}
        </label>
        <input
            className={props.focus || props.value !== "" ? "input-focus" : ""}
            type="text"
            name={props.name}
            value={props.value}
            onChange={props.onChange}
            onInput={props.onInput}
            onFocus={props.onFocus}
            onBlur={props.onBlur}
        />
        
    </div>
);

const TextArea = props => (
    <div className="text-area">
        <label
            className={props.focus || props.value !== "" ? "label-focus" : ""}
            htmlFor={props.name}
        >
            {props.label}
        </label>
        <textarea
            className={props.focus || props.value !== "" ? "input-focus" : ""}
            name={props.name}
            value={props.value}
            onChange={props.onChange}
            onInput={props.onInput}
            onFocus={props.onFocus}
            onBlur={props.onBlur}
        />
    </div>
);

const Button = props => <input type="submit" value="Submit" />;

const ContactInfo = props => <div className="col-sm-5">{props.children}</div>

ReactDOM.render(<Contact />, document.getElementById("root"));

              
            
!
999px

Console