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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                .container
    .phone
        .camera
        .camera_lens
        .mark
        .speaker
        .screen
            .topbar
                i.fa.fa-wifi
                span 11:41
            #calculator.calculator
             
        .lock
        .volume
    
    
   

              
            
!

CSS

              
                body 
    color: white
    font-family: 'Roboto'
.container
    margin: 2% auto
    width: 235px
 
.phone
    background: #221e1f
    border: 5px solid #4b473f;
    height: 500px
    width: 235px
    border-radius: 30px
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24)
    transition: all 0.3s linear
    &:hover 
        box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22)
	
    .camera
        position: absolute
        background: #585858
        height: 10px
        width: 10px
        border-radius: 10px
        margin-top: 17px
        margin-left: 25px
    .camera_lens
        position: absolute
        background-color: #0d0d0d
        height: 5px
        width: 5px
        border-radius: 5px
        margin-top: 20px
        margin-left: 28px
    .speaker
        position: absolute
        background-color: #574b4d
        height: 5px
        width: 50px
        border-radius: 3px
        margin-top: 17px
        margin-left: 93px
    .mark
        position: absolute
        background-color: #000
        height: 8px
        width: 20px
        border-radius: 10px
        margin-left: 108px
        margin-top: 35px
    .screen
        background: #fff
        position: absolute
        height: 390px
        width: 225px
        margin-left: 0px
        margin-top: 50px
        background-size: 260px 450px
        .topbar
            font-size: 12px
            color: #fff
            text-align: right
            background-color: #00BCD4
            i
                font-size: 12px
                margin-right: 8px
                vertical-align: middle
                width: 10px 
            span
                margin-right: 5px
                margin-bottom: 2px
                font-size: 10px
    .lock
        background-color: #797471
        position: absolute
        height: 35px
        width: 3px
        margin-left: 230px
        margin-top: 100px
        border-top-right-radius: 3px 3px
        border-bottom-right-radius: 3px 3px
    .volume
        background-color: #797471
        position: absolute
        height: 75px
        width: 3px
        margin-top: 180px
        margin-left: 230px
        border-top-right-radius: 3px 3px
        border-bottom-right-radius: 3px 3px


.display
    height: 140px
    overflow: hidden
.input 
    max-width:100%
    box-sizing:border-box
    border:none
    text-align:right
    outline:none
    color:#5e5e5e
    margin-top:5px
    padding:12px
    padding-bottom: 0
    font-size:40px
    overflow:hidden
    
.output
    text-align:right
    color: #7f7f7f
    padding:12px
    padding-top: 0
    font-size:28px
    font-weight:300
    overflow:hidden
.keypad
    background: #434343
    color:white
    float: left
    padding: 10px 0
.key
    border: none
    background: #434343
    font-size: 24px
    font-weight: 300
    width: 55px
    height: 55px
    &:hover, &:active, &:focus
        background: #535353
.operators
    background: #636363
    color: white
    float: left
    padding: 5px 0
    .key
        background: #636363 
        font-size: 16px
        height: 46px
        width: 46px
        min-width: 44px
        display block
        &:hover
            background: #535353
.extendedOperators
    background:#1de9b6
    height: 240px
    width: 14px
    float: left
    
    

              
            
!

JS

              
                class Calculator extends React.Component {
    constructor() {
        super();
        this.enterDigit = this.enterDigit.bind(this);
        this.enterOperator = this.enterOperator.bind(this);
        this.state = {
            input: '',
            output: '',
            operator: null,
            deleteToggle: 'DEL'
        }
    }
    enterDigit(value) {
         if(value === '=') {
            this.setState({
                input: this.state.output,
                output: '',
                operator: null,
                deleteToggle: 'CLR'
            })
        } else if (this.state.operator !== null) {
            var newInput = this.state.input + value;
            var replace = newInput.replace(/x/g, '*').replace(/÷/g, '/');
            var result = eval(replace);
            this.setState({
                input: newInput,
                output: result,
                deleteToggle: 'DEL'
            })
        } else {
            this.setState({
                input: this.state.input + value,
                deleteToggle: 'DEL'
            })
        }
    }
    enterOperator(value) {
        if(value == 'CLR') {
            this.setState({
                input: '',
                output: '',
                operator: null
            })           
        } else if(value == 'DEL') {
            this.setState({
                input: this.state.input.slice(0, -1)
            }) 
        } else {
            this.setState({
                input: this.state.input + value,
                operator: value.replace(/x/g, '*').replace(/÷/g, '/')
            })
            
        }
    }
    render() {
        return(
            <div>
                <Display input={this.state.input} output={this.state.output} />
                <CalcInput  enterDigit={this.enterDigit} enterOperator={this.enterOperator} deleteToggle={this.state.deleteToggle} />
            </div>
        )
    }
}
class Display extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        return(
            <div className="display z-depth-3">
                <div className="input">{this.props.input.toString()}</div>
                <div className="output">{this.props.output}</div>
            </div>
        )
    }
}
class CalcInput extends React.Component {
    render(props) {
        return(
            <div>
                <KeyPad className="keypad" enterDigit={this.props.enterDigit} />
                <Operators  enterOperator={this.props.enterOperator} deleteToggle={this.props.deleteToggle} />
                <ExtendedOperators enterDigit={this.props.enterDigit} />
            </div>
        )
    }
}

class KeyPad extends React.Component {
    constructor(props) {
        super(props);
    }
    mapKeys(arr) {
        return arr.map(a => <Key key={a.toString()} value={a} enterValue={this.props.enterDigit} />);
    }
    render() {
        let rowOne = [7, 8, 9],
            rowTwo = [4, 5, 6],
            rowThree = [1, 2, 3],
            rowFour = [".", 0, '='];
 
        return(
            <div className="keypad">
                <div className="keyRow">{this.mapKeys(rowOne)}</div>
                <div className="keyRow">{this.mapKeys(rowTwo)}</div>
                <div className="keyRow">{this.mapKeys(rowThree)}</div>
                <div className="keyRow">{this.mapKeys(rowFour)}</div>
                
            </div>
        )
    }
}

class Key extends React.Component {
    render() {
        const value = this.props.value;
        return(
            <button className="key waves-effect waves-circle waves-light" onClick={this.props.enterValue.bind(this, value)}>{value}</button>
        ) 
    }
}
class Operators extends React.Component {
    constructor() {
        super();
    }
    
    render() {
        return(
            <div className="operators">
                <Key value={this.props.deleteToggle} enterValue={this.props.enterOperator} />
                <Key value='÷' enterValue={this.props.enterOperator} />
                <Key value='x' enterValue={this.props.enterOperator} />
                <Key value='-' enterValue={this.props.enterOperator} />
                <Key value='+' enterValue={this.props.enterOperator} />
            </div>
        )
    }
}
class ExtendedOperators extends React.Component {
    render() {
        return(
            <div className="extendedOperators"></div>
        )
    }
}
ReactDOM.render(<Calculator />, document.getElementById('calculator'));
              
            
!
999px

Console