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

              
                <div id='app'></div>
              
            
!

CSS

              
                @mixin mt {margin-top: 10px}
@mixin hfcolor {background-color: #1e7145;}
@mixin white {color: white}
@mixin center {text-align: center}
@mixin cursor {cursor: pointer}
@mixin mr {margin-right: 10px}
$w70: 70px;

.head{
    @include hfcolor;
    display: center; 
    height: $w70;
}

.maintitle{   
    display: inline-block;
    margin: 17px 0 17px 30px;
    font-size: 25px;
    @include white;
}

.addButtonArea{      
    text-align: right;
    margin-top: -50px;
    margin-right: 30px;
}

.area{
	text-align: center;
}


.title {
	@include cursor;
    background-color: #cbe86b;
   padding-top: 15px;
   padding-bottom: 15px;
    margin-left: 25%;
  color: black;
   width: 50%;
   
}

.list{
    background-color: #f2e9e1;
    padding-top: 12px;
   padding-bottom: 12px;
   margin-left: 25%;
   width: 50%;
   
}

#delBtn{
   @include mt;
   @include mr;
   margin-left: 37%;
}

#myBtn{
    @include mt;
}

.ing, .editarea, .addarea{
	display: none;
}

.tetitle, .teingredients {
	width: 100%;
}

.teingredients{
    margin-bottom: 7px;
}		

.editsave{
    @include mr;
}

.addrecipe, .recip, .ingre{
    text-align: left;
}

/* The Modal (background) */
.modal1 {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    text-align: left;
}

/* Modal Content */
.modal-content1 {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 50%;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s;   
}

/* Add Animation */
@-webkit-keyframes animatetop {
    from {top:-300px; opacity:0} 
    to {top:0; opacity:1}
}

@keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

/* The Close Button */
.close1 {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close1:hover,
.close1:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.modal-header1{
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}

.modal-body1 {padding: 2px 16px;}
.modal-footer1{
	text-align: right;
    padding: 12px 16px;
    background-color: #5cb85c;
    color: white;
}
 
              
            
!

JS

              
                let data = (localStorage['_c0d0er_recipes']) ? JSON.parse(localStorage['_c0d0er_recipes']) : [
  {title: "Pumpkin Pie", ingredients: ["Pumpkin Puree", "Sweetened Condensed Milk", "Eggs", "Pumpkin Pie Spice", "Pie Crust"]}, 
  {title: "Spaghetti", ingredients: ["Noodles", "Tomato Sauce", "(Optional) Meatballs"]}, 
  {title: "Onion Pie", ingredients: ["Onion", "Pie Crust", "Sounds Yummy right?"]}
];

const localdata = () => {
  localStorage.setItem('_c0d0er_recipes', JSON.stringify(data));
  return JSON.parse(localStorage['_c0d0er_recipes']);
}

let ti = '';//edit title area value;
let te = '';//edit ingredients area value;
let addTit =''; //title textarea value under add;
let addIng = '';// ingredients textarea value under add;

const Footer = (props) => {
  return (
        <footer>
      <p>Coded by <a className='bill' href='https://codepen.io/c0d0er/'>Bill</a></p>
      </footer>
  );
};

const List = (props) => {

  let lnodes = props.name.map((val, ind) => {
    return (
    <h4 className='list'>{val}</h4>
    );    
  })
  return (
    <div className='ing ing1'>
    {lnodes}
    <button type='button' id='delBtn' className='btn btn-danger' onClick={props.onClickD}>Delete</button>
    <button type='button' id="myBtn" className='btn btn-info' onClick={props.onClickE}>Edit</button> 
    
       
    </div>);
};

const Edit = (props) => {
  return (
    <div className='editarea modal1' id="myModal1">
    <div className="modal-content1">
    <div className="modal-header1">
    <span className="close1" onClick={props.close}>&times;</span>
    <h3>Edit Recipe</h3>
    </div>
    <div className="modal-body1">
    <h5>Recipe</h5>
    <textarea className='tetitle' rows='2' onChange={props.changeTit}>{props.title}</textarea>
    <h5>Ingredients</h5>
    <textarea className='teingredients' rows='2' onChange={props.changeIng}>{props.data}</textarea>
    <br/>
    </div>
    <div className="modal-footer1">
    <button type='button' className='btn btn-primary editsave' onClick={props.save}>Save</button>
    <button type='button' className='btn btn-default editclose' onClick={props.close}>Close</button>
    </div> 
    </div>
    </div>
  );
};

const Add = (props) => {
  return (
    <div className='addButtonArea'>    
    <button type="button" className="btn btn-info" data-toggle="modal" data-target="#myModal" onClick={props.add}>Add Recipe</button>
    <div className="modal fade addarea" id="myModal" role="dialog">
    <div className="modal-dialog">    
    <div className="modal-content">
    <div className="modal-header">
    <button type="button" className="close" data-dismiss="modal" onClick={props.addclose}>&times;</button>
    <h3 className='addrecipe'>Add a Recipe</h3>
    </div>
    <div className="modal-body">
    <h4 className='recip'>Recipe</h4>
    <textarea id='texttitid' className='tetitle' rows='1' cols='50' placeholder="Recipe Name" onChange={props.addtit}></textarea>
    <h5 className='ingre'>Ingredients</h5>
    <textarea id='textingid' className='teingredients' rows='2' cols='50' placeholder="Enter Ingredients,Separated,By Commas"
     onChange={props.adding}></textarea>
    <br/>
    </div>
    <div className="modal-footer">    
    <button type='button' className='btn btn-info' data-dismiss="modal" onClick={props.addsave}>Save</button>
    <button type='button' className='btn btn-default' data-dismiss="modal" onClick={props.addclose}>Close</button>
    </div>
    </div>
    </div>
    </div>
    </div>
  )
}

class Box extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      recipes: localdata()
    };    
  }

  handleClick = (e) => {// click on the recipe title to toggle show and hide;
    let x = e.target.nextSibling;

    $(x).toggleClass('ing');

  };

  handleClickD = (e) => {//click delete button;
    let h3title = $(e.target).parent().prev().text();//get h3 text;   

    let i = $(e.target).parent().prev().attr('id');

    data.splice(i, 1);
    this.setState({recipes: localdata()}); 
    $('.ing1').addClass('ing'); 
  };

  handleClickE = (e) => {//click edit button;
    let z = $(e.target).parent().next();
    $(z).css('display', 'block');
    
  };

  handleTextTitle = (e) => {//get textarea title value under edit;
    ti = e.target.value;
    
  };

  handleTextIng = (e) => {//get textarea ingredients value under edit;
    te = e.target.value;
    
  };

  handleSave = (e) => {//click save button under edit;
    if(!ti&&!te){//user doesnt change anything and click save;
      ti=$(e.target).parent().parent().parent().parent().children().eq(0).text();//h3 text;
    te=$(e.target).parent().prev().children().eq(3).text();//ingredients text area text;
    }
    else if(!te&&ti){te=$(e.target).parent().prev().children().eq(3).text();}//user only changes title and save; ingredients text area text;
    else if(!ti&&te){ti=$(e.target).parent().parent().parent().parent().children().eq(0).text();}//user only changes ingredients and save;//h3 text;
    
    let s = $(e.target).parent().parent().parent().parent().children().eq(0).text();//show title text; user changes both title and ingredients;//h3 text;
    let tearr=te.split(',')//ingredients array;
    let i=5;// title text index;

    data.forEach((val, ind)=>{
      if(val.title===s){i=ind}
    })

    data[i].title=ti;
    data[i].ingredients=tearr;
    $('.editarea').css('display', 'none')
    this.setState({recipes: localdata()})

  };

  handleClose = (e) => {//click close button under edit;
    let c = $(e.target).parent().parent().parent().parent().children().eq(0).text();//get title text from h3 tag;
    let i =5;
    data.forEach((val, ind)=>{
      if(val.title===c){i=ind}
    })
    
    $(e.target).parent().prev().children().eq(1).val(data[i].title);//change textarea title text;
    $(e.target).parent().prev().children().eq(3).val(data[i].ingredients.join(', '));//change textarea ingredients text;
    ti=data[i].title; 
    te=data[i].ingredients.join(',');  
    $('.editarea').css('display', 'none')
  };

  handleAdd = (e) =>{//click add button;
    $('.addarea').css('display', 'block')
  };

  handleAddTitle = (e) =>{//get textarea title text under add button;
    addTit = e.target.value;
  };

  handleAddIng = (e) =>{//get textarea title text under add button;
    addIng = e.target.value;
  };

  handleAddSave = (e) =>{//click save button under add;
    if(!addTit){addTit='Untitled'}
    let addIngArr = addIng.split(',')
    let addObj = {title: addTit, ingredients: addIngArr};
    data.push(addObj);
    this.setState({recipes: localdata()});
    $('.addarea').css('display', 'none');
    $('#textingid').val('');
    $('#texttitid').val('');
    addIng=''; addTit='';
  };

  handleAddClose = (e) =>{
    $('#textingid').val('');
    $('#texttitid').val('');
    addIng=''; addTit='';
    $('.addarea').css('display', 'none');
  };

  render () {
    let nodes = this.state.recipes.map((val, ind)=>{
           
        return (        
          <div className='area'>
          <h3 className='title' id={ind} onClick={this.handleClick}>
            {val.title}
          </h3>        
         <List 
         name={val.ingredients} 
         onClickD={this.handleClickD}
         onClickE={this.handleClickE}/>
         <Edit title={val.title} 
         data={val.ingredients.join(', ')} 
         changeTit={this.handleTextTitle}
         changeIng={this.handleTextIng}
         save={this.handleSave}
         close={this.handleClose}/>
          </div>                                  
        );      
    });

    return (
      <div>
        <div className='head'>
        <div className='maintitle'>Recipe Box</div>        
        <Add add={this.handleAdd}
      addtit={this.handleAddTitle}
      adding={this.handleAddIng}
      addsave={this.handleAddSave}
      addclose={this.handleAddClose}/> 
        </div>       
        {nodes}       
      </div>
    );    
  }
}

ReactDOM.render(<Box />,
  document.getElementById('app'));


              
            
!
999px

Console