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 class="overlay"></div>
<div id="app"></div>
              
            
!

CSS

              
                body {
    font-family: Gill Sans; }

#app {
    min-width: 260px;
    padding: 10px;
    margin: 0 auto;
    max-width: 94%; }

.btn {
    font-weight: 100;
    display: inline-block;
    cursor: pointer;
    border-radius: 5px;
    padding: 4px 6px 0px 6px;
    margin: 10px 10px;
    font-size: 20px; }

.btn:hover {
    position: relative;
    top: -1px;
    box-shadow: 1px 1px 1px 0 #555;
    opacity: 1; }

.btn:active {
    top: 0px;
    box-shadow: 1px 1px 0 0 #555; }

.delete-button {
    color: red; }

.edit-button {
    color: #808080; }

.main-title {
    font-size: 32px;
    text-align: center;
    padding: 5px }

.flex {
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex; 
    flex-wrap: wrap; }

.recipe-title {
    font-size: 16px;
    display: inline;
    padding: 4px;
    margin: 10px 0;
    flex-grow: 2;
    text-align: center;
    background-color: #ccc; 
    color: black;
    border: 1px solid black; }

.recipe-ingredients {
    display: none;
    flex-basis: 100%;
    margin: 0 10px;
    border-radius: 5px;
    font-size: 13px;
    font-family: Andale Mono;
    padding: 20px;
    border: 1px solid #0000ff;
    color: #0000ff;
    background-color: #ccccff; }

.center {
    text-align: center; }

hr {
    color: #6666ff; }

.add-button {
    width: 100%;
    margin: 10px auto;
    padding: 0 0 2px 0;
    font-size: 24px;
    background-color: #ccffcc;
    border: 1px solid green;
    color: green; 
    text-align: center; }

.overlay {
    position: fixed;
    top: 0;
    left: 100%;
    background-color: black;
    width: 100%;
    height: 100%; 
    opacity: 0;
    z-index: 1;
    transition: opacity 400ms ease-out 0ms; }

.form {
    padding: 20px 0 5px 0;
    position: fixed;
    top: 50px;
    left: 100%;
    width: 94%;
    border-radius: 5px;
    opacity: 0;
    z-index: 2;
    min-width: 260px;
    transition: opacity 400ms ease-out 0ms; }

.add-form {
    background-color: #ccffcc;
    border: 1px solid green;
    color: green; }

.edit-form {
    background-color: #ccc;
    border: 1px solid black;
    color: black; }

.textarea-wrap {
    text-align: left;
    width: 40%;
    margin: 0 5%; }

textarea {
    resize: none;
    min-height: 150px;
    width: 100%; 
    max-width: 100%; }

.cancel-button {
    color: red; 
    float: left; }

.save-button {
    color: green;
    float: right; }

.inline {
    display: inline-block; }

.name-wrap {
margin: 25px 0 15px 0; }
              
            
!

JS

              
                function closePopup() {
    $('.overlay').css('left', '100%');
    $('.add-form').css('left', '100%');
    $('.edit-form').css('left', '100%');
    $('.overlay').css('opacity', '0');
    $('.add-form').css('opacity', '0');
    $('.edit-form').css('opacity', '0');
};

function clearValues() {
    $('.nameInput').val('');
    $('.ingredientsInput').val('');
    $('.directionsInput').val('');
};

$('.overlay').click(function () {
    closePopup();       
});

var retrievedObject = JSON.parse(localStorage.getItem('storedRecipes')),
    index;

if (retrievedObject === null) {
    retrievedObject = [];
}

class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            recipes: retrievedObject
        }; //end this.state
    }; //end constructor
    
    add = (e) => {
        clearValues();
        $('.overlay').css('left', '0');
        $('.add-form').css('left', '3%');
        $('.add-form').css('opacity', '1');
        $('.overlay').css('opacity', '0.7'); 
    };
    
    addSave = (e) => {
        var name = $('#addNameInput').val(),
            ingredients = $('#addIngredientsInput').val().split(','),
            directions = $('#addDirectionsInput').val().split(','),
            recipe = { name: name, ingredients: ingredients, directions: directions };
        closePopup();
        retrievedObject.push(recipe);
        localStorage.setItem('storedRecipes', JSON.stringify(retrievedObject));
        clearValues();
        this.setState({
           recipes: retrievedObject 
        });
    }; //end addSave

    cancel = (e) => {
        closePopup();
    };
    
    edit = (e) => { //brings up the edit menu
        $('.overlay').css('left', '0');
        $('.edit-form').css('left', '3%');
        $('.edit-form').css('opacity', '1');
        $('.overlay').css('opacity', '0.7');
        
        index = e.target.id;
        var name = retrievedObject[index].name,
            ingredients = retrievedObject[index].ingredients.join(),
            directions = retrievedObject[index].directions.join();
        
            $('#editNameInput').val(name);
            $('#editIngredientsInput').val(ingredients);
            $('#editDirectionsInput').val(directions);
    }; //end edit

    editSave = (e) => {
            var name = $('#editNameInput').val(),
            ingredients = $('#editIngredientsInput').val().split(','),
            directions = $('#editDirectionsInput').val().split(',');
        
        retrievedObject[index] = { name: name, ingredients: ingredients, directions: directions };

        closePopup();
        localStorage.setItem('storedRecipes', JSON.stringify(retrievedObject));
        clearValues();
        this.setState({
           recipes: retrievedObject 
        });
    }; //end edit

    delete = (e) => { //when one of the delete buttons is clicked
        var index = e.target.id; //get index of clicked
        retrievedObject.splice(index, 1); //remove clicked from array
        localStorage.setItem('storedRecipes', JSON.stringify(retrievedObject)); //set new array to localStorage
        this.setState({ //set new state
            recipes: retrievedObject
        });
    }; //end delete

    slide = (e) => {
        $(e.target).siblings().last().slideToggle();
    }; //end slide

    render() {
        return(
            <div>
                <div className="main-title">My Recipes</div>
                {this.state.recipes.map((obj, index) => 
                    <div className="flex" key={obj[1]}>
                        <div className="delete-button btn" id={index} onClick={this.delete.bind(this)}>✗</div>
                        <div className="recipe-title btn" onClick={this.slide.bind(this)}>{obj.name}</div>
                        <div className="edit-button btn" id={index} onClick={this.edit.bind(this)}>✎</div>                
                        <div className="recipe-ingredients">
                            <div className="center">ingredients<hr /></div>
                            {obj.ingredients.map((ingredient) =>  <div>{ingredient}</div> )}
                            <br /><br />
                            <div className="center">directions<hr /></div>
                            {obj.directions.map((direction) =>  <div>{direction}</div> )}
                        </div>
                    </div>
                )}
                <div className="add-button btn" onClick={this.add.bind(this)}>✙</div>
                
                <div className="form add-form">
                    <div className="center">ADD RECIPE</div>
                    <div className="center name-wrap">
                        <div className="inline">Name:&nbsp;</div>
                        <input type="text" className="nameInput" id="addNameInput"></input>
                    </div>
                    <div className="center">
                        <div className="inline textarea-wrap">
                            <div>Ingredients, separated by commas:</div>
                            <textarea className="ingredientsInput" id="addIngredientsInput" wrap="off"></textarea><br/>
                        </div>
                        <div className="inline textarea-wrap">
                            <div>Directions, separated by commas:</div>
                            <textarea className="directionsInput" id="addDirectionsInput" wrap="off"></textarea><br/>
                        </div>
                    </div>
                    <br/>
                    <div className="cancel-button btn" onClick={this.cancel.bind(this)}>✗</div>
                    <div className="save-button btn" onClick={this.addSave.bind(this)}>✓</div>
                </div>
                    
               <div className="edit-form form">
                    <div className="center">EDIT RECIPE</div>
                    <div className="center name-wrap">
                        <div className="inline">Name:&nbsp;</div>
                        <input type="text" className="nameInput" id="editNameInput"></input>
                    </div>
                    <div className="center">
                        <div className="inline textarea-wrap">
                            <div>Ingredients, separated by commas:</div>
                            <textarea className="ingredientsInput" id="editIngredientsInput" wrap="off"></textarea><br/>
                        </div>
                        <div className="inline textarea-wrap">
                            <div>Directions, separated by commas:</div>
                            <textarea className="directionsInput" id="editDirectionsInput" wrap="off"></textarea><br/>
                        </div>
                    </div>
                    <br/>
                    <div className="cancel-button btn" onClick={this.cancel.bind(this)}>✗</div>
                    <div className="save-button btn" onClick={this.editSave.bind(this)}>✓</div>
                </div>
                    
            </div>
        ); //end return
    } //end render
} //end Main Component


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

Console