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="root"></div>
              
            
!

CSS

              
                body {
  height: 100vh;
  width: 100vw;
  background: linear-gradient(to bottom right, #B066FE, #63E2FF); }

#root {
  font-family: 'Indie Flower', cursive;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap; }

recipeSection {
  align-self: center;
  flex-shrink: 0; }

.line-height-50 {
  line-height: 50px; }

.button-primary {
  flex: 0 0 auto;
  background: white;
  height: 50px;
  width: 50px;
  color: black;
  text-align: center;
  line-height: 50px;
  border-radius: 50%;
  transition: all 0.25s ease-in-out; }

.buttonContainer {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  margin-top: 10px;
  margin-bottom: 10px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-content: flex-start; }

.button-primary:hover {
  cursor: pointer;
  background: purple;
  color: white; }

.recipeMaker {
  display: flex;
  justify-content: space-evenly;
  flex-direction: column;
  align-items: stretch;
  flex: 1 0 auto;
  align-self: center;
  min-width: 50vw;
  min-height: 350px;
  height: 60vh;
  background: #69D2E7;
  border-radius: 5%; }

textArea {
  resize: none; }

.center {
  text-align: center; }

.recipeTitle {
  width: 50vw;
  color: white;
  padding-left: 15px;
  padding-right: 15px;
  font-size: 1.5em;
  border-radius: 10px 10px 0 0;
  margin-bottom: 15px;
  background: grey; }

.grow {
  transition: all 0.25s ease-in-out; }

.grow:hover {
  transform: scale(1.02); }

.shrink {
  transition: all 0.25s ease-in-out; }

.shrink:hover {
  color: white; }

.recipeTitle:hover {
  background: blue;
  cursor: pointer; }

.recipeWrapper {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: #20232a;
  border-radius: 10px;
  padding-bottom: 1vh;
  margin-top: 15px;
  margin-bottom: 15px; }

.ingredientName {
  align-self: stretch;
  flex-shrink: 0;
  font-size: 1.2em;
  margin: 10px;
  border-radius: 5px;
  background: white;
  padding: 5px; }

.deleteButton:hover, .backButton:hover {
  background: red; }

.saveButton:hover {
  background: #28A744; }

textArea {
  font-family: 'Indie Flower', cursive;
  font-size: 1.6em;
  border-radius: 10px;
  width: 70%;
  height: 100%; }

h1 {
  text-align: center;
  color: white; }

.textAreaWrapper {
  display: flex;
  justify-content: center;
  align-self: center;
  align-items: center;
  min-width: 100%;
  height: 100px; }

.signature {
  font-family: 'Rajdhani', sans-serif;
  text-align: center;
  align-self: center;
  color: red; }

a {
  color: black;
  text-decoration: none; }

a:visited {
  color: purple; }

a:visited:hover {
  color: blue; }

              
            
!

JS

              
                class RecipeEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      title: props.title,
      ingredients: props.ingredients,
      index: props.index
    };
    this.handleChange = this.handleChange.bind(this);
    this.sanitizeRecipe = this.sanitizeRecipe.bind(this);
    this.saveRecipe = this.saveRecipe.bind(this);
  }

  handleChange(e) {
    this.setState({
      [e.target.id]: e.target.value
    });
  }

  sanitizeRecipe() {
    let trimmedIngredients = this.state.ingredients
      .split(',')
      .map(
        (val, i) => (val.length > 50 ? val.slice(0, 50).trim() : val.trim())
      );

    trimmedIngredients = trimmedIngredients.join(',');
    let trimmedTitle = this.state.title.trim();
    return { title: trimmedTitle, ingredients: trimmedIngredients };
  }

  saveRecipe() {
    let recipe = this.sanitizeRecipe();
    this.props.saveRecipe(this.state.index, recipe);
  }

  render() {
    return (
      <div className="recipeMaker">
        <div className="textAreaWrapper">
          <textArea
            id="title"
            className="titleEditor"
            placeholder="Enter title"
            onChange={this.handleChange}
            value={this.state.title}
          />
        </div>
        <div className="textAreaWrapper">
          <textArea
            id="ingredients"
            className="ingredientEditor"
            placeholder="Enter ingredients seperated by commas eg, Bread,Butter,Fish"
            onChange={this.handleChange}
            value={this.state.ingredients}
          />
        </div>
        <div className="buttonContainer">
          <div className="button-primary saveButton" onClick={this.saveRecipe}>
            <i
              className="fa fa-floppy-o fa-2x line-height-50"
              aria-hidden="true"
            />
          </div>
          <div
            className="button-primary backButton"
            onClick={this.props.discardRecipe}
          >
            <i
              className="fa fa-arrow-left fa-2x line-height-50"
              aria-hidden="true"
            />
          </div>
        </div>
      </div>
    );
  }
}





const RecipeInfo = props => {
  if (!props.isExpanded) {
    return (
      <RecipeTitle
        toggleExpansion={props.toggleExpansion}
        index={props.index}
        title={props.recipe.title}
        class={'recipeTitle grow'}
      />
    );
  } else {
    return (
      <div className="recipeWrapper">
        <RecipeTitle
          toggleExpansion={props.toggleExpansion}
          index={props.index}
          title={props.recipe.title}
          class={'recipeTitle shrink'}
        />
        <Ingredients data={props.recipe.ingredients} />
        <RecipeButtons
          index={props.index}
          editRecipe={props.editRecipe}
          deleteRecipe={props.deleteRecipe}
        />
      </div>
    );
  }
};

const RecipeTitle = props => (
  <div
    className={props.class}
    onClick={() => props.toggleExpansion(props.index)}
  >
    {props.title}
  </div>
);

const Ingredients = props => (
  <div>
    {props.data.split(',').map((ingred, i) => (
      <div className="ingredientName" key={i}>
        {ingred}
      </div>
    ))}
  </div>
);

const RecipeButtons = props => (
  <div className="buttonContainer">
    <div
      className="button-primary"
      onClick={() => props.editRecipe(props.index)}
    >
      <i
        className="fa fa-pencil-square-o  fa-2x line-height-50"
        aria-hidden="true"
      />
    </div>
    <div
      className="button-primary deleteButton "
      onClick={() => props.deleteRecipe(props.index)}
    >
      <i className="fa fa-trash  fa-2x line-height-50" aria-hidden="true" />
    </div>
  </div>
);




const RecipeSection = props => {
  const { data, toggleExpansion, deleteRecipe, editRecipe } = props;
  return (
    <div className="recipesSection">
      <div className="buttonContainer" onClick={props.makeRecipe}>
        <i
          className="button-primary fa fa-plus-square fa-1.5x line-height-50"
          aria-hidden="true"
        />
      </div>
      <RecipeData
        data={data}
        toggleExpansion={toggleExpansion}
        deleteRecipe={deleteRecipe}
        editRecipe={editRecipe}
      />
    </div>
  );
};

const RecipeData = props => (
  <div>
    {props.data.map((recipe, i) => (
      <RecipeInfo
        key={i}
        isExpanded={recipe.isExpanded}
        toggleExpansion={props.toggleExpansion}
        recipe={recipe}
        deleteRecipe={props.deleteRecipe}
        index={i}
        editRecipe={props.editRecipe}
      />
    ))}
  </div>
);




class RecipesContainer extends React.Component {
  constructor() {
    super();

    this.state = {
      recipes:
        typeof localStorage['recipeMakerTTabhinav'] != 'undefined'
          ? JSON.parse(localStorage['recipeMakerTTabhinav'])
          : [
              {
                title: 'Butter chicken',
                ingredients: 'Butter,chicken',
                isExpanded: true
              },
              {
                title: 'Cake',
                ingredients: 'chocolate,MAGIC!',
                isExpanded: false
              }
            ],
      index: -1,
      makingRecipe: false
    };

    this.saveRecipe = this.saveRecipe.bind(this);
    this.editRecipe = this.editRecipe.bind(this);
    this.deleteRecipe = this.deleteRecipe.bind(this);

    this.discardRecipe = this.discardRecipe.bind(this);
    this.makeRecipe = this.makeRecipe.bind(this);

    this.updateLocalStorage = this.updateLocalStorage.bind(this);
    this.toggleExpansion = this.toggleExpansion.bind(this);
  }

  updateLocalStorage() {
    localStorage.setItem(
      'recipeMakerTTabhinav',
      JSON.stringify(this.state.recipes)
    );
  }

  makeRecipe() {
    this.setState({
      makingRecipe: true,
      index: -1
    });
  }

  saveRecipe(index, recipe) {
    let newRecipes;
    if (index !== -1) {
      newRecipes = this.state.recipes.map((r, i) => (i === index ? recipe : r));
    } else {
      newRecipes = this.state.recipes.concat(recipe);
    }

    this.setState(
      {
        recipes: newRecipes,
        makingRecipe: false,
        index: -1
      },
      () => {
        this.updateLocalStorage();
      }
    );
  }

  editRecipe(index) {
    this.setState({
      index: index,
      makingRecipe: true
    });
  }

  deleteRecipe(index) {
    let newRecipes = this.state.recipes.filter((_, i) => i !== index);
    this.setState(
      {
        recipes: newRecipes
      },
      () => {
        this.updateLocalStorage();
      }
    );
  }

  renderRecipeEditor(index) {
    let title = index === -1 ? '' : this.state.recipes[index].title;
    let ingredients = index === -1 ? '' : this.state.recipes[index].ingredients;

    return (
      <RecipeEditor
        title={title}
        ingredients={ingredients}
        index={index}
        saveRecipe={this.saveRecipe}
        discardRecipe={this.discardRecipe}
      />
    );
  }

  discardRecipe() {
    this.setState({
      makingRecipe: false
    });
  }

  toggleExpansion(index) {
    let changedRecipe = this.state.recipes[index];
    changedRecipe.isExpanded = !changedRecipe.isExpanded;

    let recipes = this.state.recipes.map(
      (r, i) => (index === i ? changedRecipe : r)
    );

    this.setState(
      {
        recipes: recipes
      },
      () => this.updateLocalStorage()
    );
  }

  render() {
    if (this.state.makingRecipe) {
      return this.renderRecipeEditor(this.state.index);
    } else
      return (
        <RecipeSection
          makeRecipe={this.makeRecipe}
          data={this.state.recipes}
          toggleExpansion={this.toggleExpansion}
          deleteRecipe={this.deleteRecipe}
          editRecipe={this.editRecipe}
        />
      );
  }
}

const Signature = props => (
  <div className="signature">
    <p>
      <i className="fa fa-heart" aria-hidden="true" />
    </p>
    <p>
      <a
        href="https://github.com/abhinav-m"
        target="_blank"
        rel="noopener noreferrer"
      >
        Abhinav Mishra
      </a>
    </p>
    <p>
      <a
        href="https://github.com/abhinav-m"
        target="_blank"
        rel="noopener noreferrer"
      >
        अभिनव मिश्रा
      </a>
    </p>
  </div>
);



const App = () => (
  <div className="App">
    <h1>{'Recipe Box'}</h1>
    <RecipesContainer />
    <Signature />
  </div>
);


ReactDOM.render(<App />, document.getElementById('root'));

              
            
!
999px

Console