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

              
                <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> -->
              
            
!

CSS

              
                $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;
}
              
            
!

JS

              
                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

Console