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

              
                <div id="app"></div>


              
            
!

CSS

              
                $background-color: #FFFFFF
$popup: #1F3900
$font-family-1: arial
$text-color: black
$main-color: #509028
$secondary-color: #A1D67E
$danger-color: #AA0000

.c-5
  width: 5%
.c-10
  width: 10%
.c-70
  width: 70%
.c-30
  width: 30%
  
body
  background-color: $background-color
  color: $text-color
  font-size: 20px
  font-family: $font-family-1
  
label
  @extend .white
  font-size: 14px
  margin: 2px
  
#container
  border-radius: 15px
  border: 3px solid black
  margin: auto
  padding: 30px
  margin-top: 25px
  width: 65%
  
/* Button Style */
button
  border: none
  color: white
  padding: 15px
  border-radius: 5px
  margin: 10px 10px 0 0

  
.padding
  padding-left: 10px

.casual-btn
  min-width: 75px
  
.sml-btn
  margin: 0
  padding: 2px
  
.casual-color
  background-color: $main-color
  
.danger
  background-color: $danger-color

.white
  color: white

/* Recipe Head */
.container-recipe
  display: table
  width: 100%
  color: black
  background-color: $secondary-color
  margin: 10px 10px 0 0
  
.recipe-div
  display: table-cell
  padding: 9px
  width: 85%
  font-weight: bold
  color: black
  cursor: default
  
.icon-div
  display: table-cell
  text-align: right
  padding: 10px

/* Drop Window */
.drop-window
  position: relative
  display: none
  background-color: $secondary-color
  opacity: 0.6
  filter: alpha(opacity=60)

.drop-window ul
  margin-top: 0
.drop-window li
  padding: 3px

/* Popup */

.popup-window
  position: absolute
  display: none
  margin-left: 32.5%
  width: 25%
  background-color: $popup
  top: 100px
  border: 2px solid $popup
  z-index: 2
  
.popup-head
  position: relative
  left: 0
  top: 0
  background-color: white
  font-family: $font-family-1
  font-weight: bold
  font-size: 25px
  text-align: center
  padding: 10px

.popup-input
  width: 95%
  font-size: 20px
  margin: 5px

.popup-input-container
  padding: 5px
  
.popup-btn-container
  text-align: center
  margin-left: -20px
  
.popup-btn-container button
  margin: 10px 10px 10px 50px

.note
  font-size: 12px
  color: black
  
  
              
            
!

JS

              
                var popup = false;
var recipeTitle;
var book=[];
var ingredients = [];
var startRecipe = [
                    { "banana split" : ["ice cream", "chocolate sauce", "strawberry sauce", "2 banana"] },
                    { "spagetti devil" : ["chocolate melted", "marshmallow", "spagetti noodle", "cherry sauce"] },
                    { "Pineapple apple pen" : ["Pineapple", "apple", "pen", "bad dancer"]}
                  ];
//Set local storage or fetch it
var recipeJson = JSON.parse(localStorage.getItem("recJson"));
if(recipeJson === null) {
  localStorage.setItem("recJson", JSON.stringify(startRecipe));
  recipeJson = JSON.parse(localStorage.getItem("recJson"));
}


class Buttons extends React.Component{
  render(){
    if(!this.props.deleteHtml) {
     return (
       <div>
         <div>
           <i className="padding fas fa-cog" onClick={this.props.edit}></i>
           <i className="padding fas fa-trash-alt fa-xs" onClick={this.props.iconDelete}></i>
         </div>
       </div>
     );
    } else {
      return (
        <div>
          <button className="sml-btn danger c-70" onClick={this.props.delete}> Delete? </button>
          <button className="sml-btn danger c-30" onClick={this.props.cancelDelete}>x</button>
        </div>
      );
    }
  }
}

class Recipe extends React.Component{
  constructor() {
    super();
    this.state = { 
       iconDrop: "fas fa-plus fa-xs",
       deleteHtml: false
    };
    this.closeIcon = "fas fa-plus fa-xs";
    this.openIcon = "fas fa-minus fa-xs";    
  }
  dropList(id){
    if(this.state.iconDrop == this.closeIcon) {
      this.setState({iconDrop: this.openIcon});
    } else {
      this.setState({iconDrop: this.closeIcon});
    }
    $("#"+id).slideToggle("fast"); 
  }
  iconDeleteRecipe(e) {
    this.setState({deleteHtml: true});
  }
  deleteRecipe(e){
    this.setState({deleteHtml: false});
    this.props.deleteRecipe(this.props.recipeId);
  }
  cancelDeleteRecipe(e){
    this.setState({deleteHtml: false});
  }
  render(){           
   return (
       <div id={"rec-container" + this.props.recipeId} >
         <div className="container-recipe">
           <div className="icon-div c-5"  onClick={()=> this.dropList("window" + this.props.recipeId, this.props.startIconDrop)}><i className={this.state.iconDrop}></i></div>
           <div className="recipe-div" onClick={()=> this.dropList("window" + this.props.recipeId, this.props.startIconDrop)}>
             {this.props.recipeTitle.replace(/.{1}/i, function(x){ return x.toUpperCase()})}
           </div>
           <div className="icon-div c-10">
             <Buttons 
               deleteHtml={this.state.deleteHtml} 
               iconDelete={this.iconDeleteRecipe.bind(this)}
               edit={()=> this.props.editRecipeWindow(this.props.recipeId)}
               delete={this.deleteRecipe.bind(this)}
               cancelDelete={this.cancelDeleteRecipe.bind(this)}
               />
           </div>
         </div>  
         <div id={"window" + this.props.recipeId} className="drop-window">
           <ul>
             {
               this.props.ingredients.map((ing, i) => (
                 <li key={i+ ing}>{ing}</li>
               ))
             }
           </ul>
         </div>  
       </div>
   );
  } 
}

class ConfirmButton extends React.Component{
  
  render(){
    if(this.props.popupState == "add") {
      return (
              <button 
               className="casual-color casual-btn" 
               onClick={this.props.confirm}
               type="submit">
                Add
              </button>
        )
    } else if(this.props.popupState == "edit") {
      return (  
              <button 
                className="casual-color casual-btn" 
                onClick={this.props.confirm}
                type="submit">
                Edit
              </button>
      );
    }
  }
}

class Popup extends React.Component {
  render() {
    return (
      <div className="popup-window" title="New recipe">
        <div className="popup-head">{this.props.popupTitle}</div>
        <div className="popup-input-container">
          <label htmlFor="recipeTitle">Recipe title</label>
          <input id="recipeTitle" className="popup-input" type="text" placeholder="ex:Apple pie" 
            value={this.props.recipeVal} onChange={e => this.props.handleChangeRecipe(e.target.value)}/>
          <label htmlFor="ingredientList">Ingredients list</label>
          <input id="ingredientList" className="popup-input" type="text" placeholder="ex: apple, flour, butter" 
            value={this.props.ingredientVal} onChange={e=> this.props.handleChangeIngredient(e.target.value)}/>
        </div>
        <div className="popup-btn-container">
          <ConfirmButton 
            popupState={this.props.popupState} 
            confirm={() => this.props.confirm($('#recipeTitle').val(),$('#ingredientList').val(), this.props.popupState, this.props.editId)}
          />
          <button className="casual-btn danger" onClick={this.props.cancelHandler}>Cancel</button>
        </div>
      </div>
    );
  }
}

class Layout extends React.Component {
  constructor() {
    super();
    this.state = {
      recipe: recipeJson,
      popupTitle: "",
      editRecipe: "",
      editIngredient: "",
      popupState: "add",
      editId: 0,
      popupHasClicked: false
    };
    this.defaultVal = "";
  }    
  addRecipe(e){
    e.preventDefault;
    this.setState({
      popupTitle: "ADD A RECIPE",
      popupState: "add"
    });
    this.resetInput();
    $(".popup-window").show();
    $("#recipeTitle").focus();
  }
  cancelHandler(e){
    e.preventDefault;
    this.resetInput();
  }
  confirmRecipe(titleVal, listVal, state, id) {
    var obj = {};
    var arr = listVal.split(",");
    obj[titleVal] = arr;
    
    if(state == "add") {
      recipeJson.push(obj);
    } else if(state == "edit") {
      recipeJson[id] = obj;
    }
    
    this.setState({recipe: recipeJson});
    localStorage.setItem("recJson", JSON.stringify(recipeJson));
    this.resetInput(); 
  }
  deleteRecipe(id){
    $("#rec-container" + id).slideUp("default");
    recipeJson.splice(id, 1);
    localStorage.setItem("recJson", JSON.stringify(recipeJson));
  }
  editRecipeWindow(id){
    var recipeTitle = Object.keys(recipeJson[id])[0];
    var ingredients = recipeJson[id][recipeTitle].toString();
    this.setState({
      editRecipe: recipeTitle,
      editIngredient: ingredients,
      popupTitle: "EDIT RECIPE",
      popupState: "edit",
      editId: id
    });
    $(".popup-window").show();
    $("#recipeTitle").focus();
  }
  resetInput(){
    $(".popup-window").hide();
    $("#recipeTitle").blur();
    $("#ingredientList").blur();
    this.setState({
      editRecipe: "",
      editIngredient: "",
      editId: 0
    });
  }
   handleChangeRecipe(val){
    this.setState({editRecipe: val});
  }
  handleChangeIngredient(val){
    this.setState({editIngredient: val});
  }
  render(){
    return (
      <div>
        <Popup 
          recipeVal={this.state.editRecipe} 
          ingredientVal={this.state.editIngredient} 
          popupTitle={this.state.popupTitle}
          cancelHandler={this.cancelHandler.bind(this)} 
          confirm={this.confirmRecipe.bind(this)}
          defaultVal={this.defaultVal}
          handleChangeRecipe={this.handleChangeRecipe.bind(this)}
          handleChangeIngredient={this.handleChangeIngredient.bind(this)}
          popupState={this.state.popupState}
          editId={this.state.editId}
        />
        <div id="container">
          {
            this.state.recipe.map((re, i) =>(
              recipeTitle = String(Object.keys(re)),
              ingredients = re[recipeTitle],
            <Recipe key={i}
              recipeId={i}  
              recipeTitle={recipeTitle}
              ingredients={ingredients} 
              deleteRecipe={this.deleteRecipe.bind(this)}
              editRecipeWindow={this.editRecipeWindow.bind(this)}
            />
            ))}
          <div className="note">*All your recipe will automatically be saved. Enjoy! ^^</div>
          <button id="add-recipe" className="casual-color" onClick={this.addRecipe.bind(this)}>Add Recipe</button>
        </div>
      </div>
    );
  }
}

app = document.getElementById("app");

ReactDOM.render(<Layout/>, app);

              
            
!
999px

Console