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.

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

            
              <main>
    <div id="app"></div>
    <p>
        Check the alternative pen for the <a target="_blank" href="https://codepen.io/IbeVanmeenen/pen/BzzVLJ">non-react demo</a>.
    </p>
</main>



<hr>

<footer>
    <h1>
        &lt;dialog&gt; element as a React component
    </h1>
    <p>
        The HTML <strong>&lt;dialog&gt;</strong> element represents a dialog box or other interactive component, such as an inspector or window. <br>
        For more info, go to <a target="_blank" href="https://developer.mozilla.org/en/docs/Web/HTML/Element/dialog">https://developer.mozilla.org/en/docs/Web/HTML/Element/dialog</a>
    </p>
    <p>
        Currently only works in Chrome and Opera: <a target="_blank" href="http://caniuse.com/#feat=dialog">http://caniuse.com/#feat=dialog</a>.
    </p>
    <p>
        Polyfill (by GoogleChrome): <a target="_blank" href="https://github.com/GoogleChrome/dialog-polyfill">https://github.com/GoogleChrome/dialog-polyfill</a>.
    </p>
</footer>
            
          
!

CSS

            
              /* Base */
* {
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
            font-smoothing: antialiased;
}

html, body {
    margin: 0;
    padding: 1em;
    
    font-family: sans-serif;
    font-size: 100%;
    line-height: 1.6;
}

html {
    -ms-text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

hr {
    margin: 3rem 0 2rem;
    border: 0;
    border-top: 1px solid #E0E4E8;
}

h1 {
    margin: 0 0 1rem;
}

a {
    color: #648ebb;
}


/* Button */
.btn {
    margin: 0;
    padding: 1em 2em;
    
    line-height: 1;
    letter-spacing: .15em;
    text-transform: uppercase;
    color: #fff;
    background: #50AAFF;
    border: 0;
    font-weight: bold;
}

.btn--inline {
    display: inline-block;
    margin-right: .5rem;
}

.btn--close {
    background: #ff8282;
}


/* Dialog */
.dialog {
    width: 90vw;
    max-width: 20rem;
    
    padding: 1em;
    
    background: #fff;
    color: #656e77;
    box-shadow: 0 0 5px rgba(101, 110, 119, .2);
    border: 0;
    text-align: center;
}

.dialog[open] {
    animation: .2s linear slidein;
}

.dialog::backdrop {
    background: rgba(224, 228, 232, .9);
    animation: .4s ease fade;
}

.dialog__title {
    color: #50AAFF;
}

.dialog__txt {}

.dialog__btn {
    display: block;
    width: 100%;
    margin-top: 2rem;
}


@keyframes slidein {
    from {
        transform: translate3d(0, 5px, 0);
    }
    to {
        transfrom: translate3d(0, 0, 0);
    }
}

@keyframes fade {
    from {
        opacity: .3;
    }
    to {
        opacity: 1;
    }
}
            
          
!

JS

            
              // Modal
class Modal extends React.Component {
    constructor () {
        super();

        this.state = {
            isVisible: false
        };
    }
    componentDidMount () {
        if (this.state.isVisible) {
            this.show();
        }
    }
    show () {
        this.state.isVisible = true;
        this.dialog.showModal();
    }
    hide () {
        this.state.isVisible = false;
        this.dialog.close();
    }
    componentWillReceiveProps (nextProps) {
        if (nextProps.visible !== this.state.isVisible) {
            this.state.isVisible = nextProps.visible;

            if (this.state.isVisible) {
                this.show();
            } else {
                this.hide();
            }
        }
    }
    render () {
        this.state.isVisible = this.props.visible;

        return (
            <dialog className="dialog" ref={(ref) => this.dialog = ref}>
                {this.props.children}
            </dialog>
        );
    }
};


Modal.propTypes = {
    visible: React.PropTypes.bool
};




// App
class App extends React.Component {
    constructor () {
        super();

        this.state = {
            visible: false
        }

        this.showModal = this.showModal.bind(this);
        this.hideModal = this.hideModal.bind(this);
    }
    showModal () {
        this.setState({visible: true});
    }
    hideModal () {
        this.setState({visible: false});
    }
    render () {
        return (
            <section>
                <nav role="navigation">
                    <button type="button" onClick={this.showModal} className="btn">
                        Open Modal
                    </button>
                </nav>

                <Modal visible={this.state.visible}>
                    <h3 className="dialog__title">
                        Hello World
                    </h3>
                    <p className="dialog__txt">
                        Nam condimentum quam varius convallis iaculis. Nulla facilisi. Maecenas pretium erat commodo, rhoncus quam quis, laoreet ante. Nunc egestas sapien et magna malesuada faucibus.
                    </p>
                    <button onClick={this.hideModal} type="button" className="btn btn--close dialog__btn">
                        Close
                    </button>
                </Modal>
            </section>
        );
    }
};

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

Console