css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>

<div class="header">
  <div class="logo">Colo <span class="small-text">Color Recipes</span></div>
</div>

<div id="container"></div>
<div class="test-output"></div>
<!-- 
<div class="palette">
  <div class="name name-small">AQUA</div>
  <div class="swatch swatch-small">
    <ul class="swatch-list">
      <li id="c1"></li>
      <li id="c2"></li>
      <li id="c3"></li>
      <li id="c4"></li>
      <li id="c5"></li>
    </ul>
  </div>
</div>

<div class="palette">

  <div class="name name-small">BOILERROOM</div>

  <div class="swatch swatch-small">
    <ul class="swatch-list">
      <li id="c1"></li>
      <li id="c5"></li>
      <li id="c3"></li>
      <li id="c4"></li>
      <li id="c2"></li>
    </ul>
  </div>
</div>



<div class="palette">
    <div class="title-block">
  <div class="name">CINCO</div>
  <i class="fa fa-trash fa-lg"></i>
    </div>
  <div class="swatch">
    <ul class="swatch-list">
      <li id="c4"></li>
      <li id="c3"></li>
      <li id="c1"></li>
      <li id="c2"></li>
      <li id="c5"></li>
    </ul>
    <div class="codes hidden">
    #7e8c68, #7e8c68, #7e8c68, #7e8c68, #7e8c68
  </div>
  </div>
  
</div>

<div class="palette">
<div class="name new name-small">+ NEW</div>
</div> -->
            
          
!
            
              $boxsize: 80px;

/* * {
  border: 1px white solid;
}
 */
body {
  background: #262626;
  font-family: 'Montserrat', sans-serif;
}

.header {
  height: 50px;
  background: black;
  color: white;
  font-size: 28pt;
  padding: 10px 0 0 20px;
}

.small-text {
  font-size: 10pt;
  margin-left: 20px;
}

.palette {
  width: $boxsize * 5;
  margin: 0 auto;
  margin-top: 10px;
  padding: 10px;
/*   box-shadow: 4px 4px 4px 4px rgba(0,0,0,0.5); */
}

.title-block {
  display: flex;
  justify-content: space-between;
}

.title-edit {
  height: 50px;
}

.name {
  color: white;
  font-size: 18pt;
}

ul {
  list-style: none;
}

.swatch ul {
  display: flex;
  padding-left: 0;
  cursor: pointer;
}

.swatch-list li {
  width: $boxsize;
  height: $boxsize;
  transition: all .2s ease-in-out;
}

@for $item from 1 through 5{
  .swatch-list li:nth-child(#{$item}){ 
    transition-delay: $item*.05s; 
  }
} 

i {
  color: grey;
  height: 20px;
  width: 20px;
  padding: 5px;
  margin-left: 10px;
  line-height: 18px;
  cursor: pointer;
}

.swatch-large ul li {
  width: $boxsize + 10px;
  height: $boxsize + 10px;
  margin: 5px;
  margin-bottom: -2px;
  
}

.codes, textarea {
  color: #f0f2f0;
  font-style: italic;
  border-bottom: 5px white solid;
  padding: 5px;
  background: grey;
  opacity: 1;
  height: 40px;
  overflow: hidden;
  margin-top: 20px;
  width: 100%;
  transition: opacity .15s ease .25s;
  transition: height .15s ease;
}

textarea {
  border: none;
}

.name.new {
  color: grey;
  background: black;
  padding: 5px;
  box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.5);
}

.name-small {
  font-size: 10pt;
}

.hidden {
  height: 0px;
  width: 0px;
  // overflow: hidden;
  // padding: 0;
  // border: 0;
  opacity: 0;
}

button {
  border: none;
}
            
          
!
            
              const initJSON = [{
  id: lil.uuid(),
  title: "Aqua",
  ingredients: "#7e8c68, #f0f2f0, #0b0d0c, #3d3b34, #8c7e65"
}, {
  id: lil.uuid(),
  title: "Boilerroom",
  ingredients: "#0b0d0c, #3d3b34, #8c7e65, #7e8c68, #f0f2f0"
}];

class RecipeBook extends React.Component {
  constructor(props) {
    super(props);
    if (typeof localStorage.getItem('recipebook') !== 'string') { 
      localStorage.setItem('recipebook', JSON.stringify(this.props.data));
    }
    const recipebook = JSON.parse(localStorage.getItem('recipebook'));
    this.state = {
      recipebook: recipebook
    };
    this.onIngredentsEdit = this.onIngredientsEdit.bind(this);
    this.onAddNote = this.onAddNote.bind(this);
    this.onTitleEdit = this.onTitleEdit.bind(this);
    this.onDelete = this.onDelete.bind(this);
  }
  
  onIngredientsEdit(id, e) {
    const recipebook = this.state.recipebook.map(recipe => {
      if(recipe.id === id && e.target.value) {
        recipe.ingredients = e.target.value;
      }
      return recipe;
    });
    this.setState({recipebook}, this.forceUpdate());
    localStorage.setItem('recipebook', JSON.stringify(recipebook));
  }
  
  onTitleEdit(id, e) {
    // TODO: 'enter' key submits
    const recipebook = this.state.recipebook.map(recipe => {
      if(recipe.id === id && e.target.value) {
        recipe.title = e.target.value;
      }
      return recipe;
    });
    this.setState({recipebook}, this.forceUpdate());
    localStorage.setItem('recipebook', JSON.stringify(recipebook));
  }
  
  onAddNote() {
    this.setState({
      recipebook: this.state.recipebook.concat([{
        id: lil.uuid(),
        title: "New Recipe",
        ingredients: "#0b0d0c, #3d3b34, #8c7e65, #7e8c68, #f0f2f0"
      }])
    });
    localStorage.setItem('recipebook', JSON.stringify(this.state.recipebook));
  }
  
  onDelete(id) {
    console.log("Deleting "+id);
    const recipebook = this.state.recipebook.filter(el => (el.id !== id));
    this.setState({recipebook});
    localStorage.setItem('recipebook', JSON.stringify(recipebook));
  }
  
  render() {
    const recipebook = this.state.recipebook;
    // We use bind on OnIngredientsEdit to pass a reference to the recipe being edited
    return (
      <div className="recipebook">
        <ul>
          {recipebook.map((el) => (<Recipe data={el} key={el.id} onIngredientsEdit={this.onIngredientsEdit.bind(this, el.id)} onDelete={this.onDelete.bind(this, el.id)}  onTitleEdit={this.onTitleEdit.bind(this, el.id)}/>))}
          <li className="palette">
            <button className="name new name-small" onClick={this.onAddNote}>+ NEW</button>
          </li>
        </ul>
      </div>
    );
  }
}

class Recipe extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      edit: false
    };
    this.onEditClick = this.onEditClick.bind(this);
    this.onEditEnter = this.onEditEnter.bind(this);
  }

  onEditClick() {
    this.setState({
      edit: !this.state.edit
    })
  }
  
  onEditEnter(e) {
    if (e.charCode == 13 && this.state.edit) this.setState({edit: false})
  }
  
  render() {
    const title = this.props.data.title;
    const id = this.props.id;
    const ingredients = this.props.data.ingredients;
    return (
      <li className="palette">
        <div className="title-block">
          <div className="title-edit">
            <div className={"name" + (!this.state.edit ? "" : " hidden")}>{this.props.data.title}</div>
            <input type="text" className={this.state.edit ? "" : "hidden"} onChange={this.props.onTitleEdit} onKeyPress={this.onEditEnter} value={this.props.data.title}></input>
          </div>
          <div className="icons">
            <a onClick={this.onEditClick}><i className="fa fa-pencil fa-lg"></i></a>
          <a onClick={this.props.onDelete}><i className="fa fa-trash fa-lg"></i></a>
          </div>
        </div>
        <div onClick={this.onEditClick} className={"swatch" + (this.state.edit ? " swatch-large" : "")}>
          <IngredientList data={ingredients} />
        </div>
        <div className={"codes" + (!this.state.edit ? " hidden" : "")}>
          <textarea name={id} value={ingredients} onChange={this.props.onIngredientsEdit}/>
        </div>
      </li>
    );
  }
}

class IngredientList extends React.Component {
  constructor(props) {
    super(props);
    // var ingredients = [];
  }
  
  render() {
    return (
      <ul className="swatch-list">
        {this.props.data.split(',').map(function(el) {
          let liStyle = {background: el};
          return (<li key={el} style={liStyle}></li>);
        })
      }
      </ul>
    );
  }
}

ReactDOM.render( <RecipeBook data={initJSON} />, document.getElementById('container'));

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console