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>
<footer>
  <p>Made by <a href="https://hadaclay.com">@hadaclay</a>.</p>
  <p>© 2019</p>
</footer>
              
            
!

CSS

              
                body {
  background-size: cover;
}

.recipe-well {
  margin-top: 2vh;
}

.panel-title {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  text-color: #000;
  text-align: center;
}

footer p {
  color: #eee;
  text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
  font-size: 2rem;
  font-weight: 300;
}

footer a {
  text-decoration: none;
  text-shadow: 1px 1px 2px #222;
}

              
            
!

JS

              
                const Grid = ReactBootstrap.Grid,
  Row = ReactBootstrap.Row,
  Col = ReactBootstrap.Col,
  Well = ReactBootstrap.Well,
  Accordion = ReactBootstrap.Accordion,
  Panel = ReactBootstrap.Panel,
  Button = ReactBootstrap.Button,
  ButtonToolbar = ReactBootstrap.ButtonToolbar,
  Modal = ReactBootstrap.Modal,
  ListGroup = ReactBootstrap.ListGroup,
  ListGroupItem = ReactBootstrap.ListGroupItem,
  FormControl = ReactBootstrap.FormControl,
  ControlLabel = ReactBootstrap.ControlLabel;

class RecipeContainer extends React.Component {
  constructor(props) {
    super(props);
    if (localStorage.getItem('_hadaclay_recipes') === null) {
      let recipes = [
        {
          name: 'Peanut Brittle',
          ingredients: 'Peanuts, butter, water, sugar, salt'
        },
        {
          name: 'Cheesecake',
          ingredients: 'Graham cracker crumbs, sugar, butter or margerine, cream cheese, sugar, eggs'
        }
      ];
      localStorage.setItem('_hadaclay_recipes', JSON.stringify(recipes));
      this.state = {recipes};
    } else {
      // Get Recipes from LocalStorage
      let recipes = JSON.parse(localStorage.getItem('_hadaclay_recipes'));
      this.state = {recipes};
    }
    
    this.handleNew = this.handleNew.bind(this);
    this.handleUpdate = this.handleUpdate.bind(this);
    this.handleDelete = this.handleDelete.bind(this);
  }
  
  handleNew(recipe) {
    let newState = {};
    newState.recipes = this.state.recipes;
    newState.recipes.push(recipe);
    this.setState(newState);
    localStorage.setItem(
      '_hadaclay_recipes',
      JSON.stringify(this.state.recipes)
    );
  }

  handleUpdate(event, key) {
    let newState = {};
    newState = this.state.recipes[key];
    switch (event.target.id) {
      case 'recipe-name':
        newState.name = event.target.value;
        this.setState(newState);
        localStorage.setItem(
          '_hadaclay_recipes',
          JSON.stringify(this.state.recipes)
        );
        break;
      case 'ingredients':
        newState.ingredients = event.target.value;
        this.setState(newState);
        localStorage.setItem(
          '_hadaclay_recipes',
          JSON.stringify(this.state.recipes)
        );
        break;
      default:
        break;
    }
  }

  handleDelete(key) {
    let newState = {};
    newState.recipes = this.state.recipes;
    newState.recipes.splice(key, 1);
    this.setState(newState);
    localStorage.setItem(
      '_hadaclay_recipes',
      JSON.stringify(this.state.recipes)
    );
  }

  render() {
    return (
      <Well className="recipe-well">
        {this.state.recipes.map((recipe, i) => {
          return (
            <RecipePanel
              eventKey={i}
              key={i}
              header={recipe.name}
              onUpdate={this.handleUpdate}
              onDelete={this.handleDelete}
            >
              {recipe.ingredients}
            </RecipePanel>
          );
        })}
        <AddRecipeModal onNew={this.handleNew} />
      </Well>
    );
  }
};

class RecipePanel extends React.Component {
  constructor(props) {
    super(props);
    this.state = {showModal: false};
    
    this.closeEditModal = this.closeEditModal.bind(this);
    this.openEditModal = this.openEditModal.bind(this);
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
    this.handleDelete = this.handleDelete.bind(this);
  }

  closeEditModal() {
    this.setState({
      showModal: false
    });
  }

  openEditModal() {
    this.setState({
      showModal: true
    });
  }

  handleChange(event, key) {
    this.props.handleUpdate(event, key);
  }

  handleSubmit(event) {
    event.preventDefault();
  }

  handleDelete() {
    this.props.onDelete(this.props.eventKey);
  }

  render() {
    return (
      <div>
        <Panel
          header={this.props.header}
          eventKey={this.props.eventKey}
          collapsible="true"
        >
          <h4 className="text-center">Ingredients</h4><hr />
          <ListGroup>
            {this.props.children.split(',').map((ingredient, i) => {
              return <ListGroupItem key={i}> {ingredient}</ListGroupItem>;
            })}
          </ListGroup>
          <ButtonToolbar>
            <Button onClick={this.handleDelete} bsStyle="danger">Delete</Button>
            <Button onClick={this.openEditModal}>Edit Recipe</Button>
          </ButtonToolbar>
        </Panel>

        <Modal show={this.state.showModal} onHide={this.closeEditModal}>
          <Modal.Header closeButton>
            <Modal.Title>Edit Recipe</Modal.Title>
          </Modal.Header>
          <Modal.Body>
            <form onSubmit={this.handleSubmit}>
              <ControlLabel>Recipe</ControlLabel>
              <FormControl
                id="recipe-name"
                value={this.props.header}
                onChange={event =>
                  this.props.onUpdate(event, this.props.eventKey)}
              />
              <ControlLabel>Ingredients</ControlLabel>
              <FormControl
                id="ingredients"
                componentClass="textarea"
                value={this.props.children}
                onChange={event =>
                  this.props.onUpdate(event, this.props.eventKey)}
              />
            </form>
          </Modal.Body>
          <Modal.Footer>
            <ButtonToolbar className="pull-right">
              <Button bsStyle="primary" onClick={this.closeEditModal}>
                Finish
              </Button>
            </ButtonToolbar>
          </Modal.Footer>
        </Modal>
      </div>
    );
  }
}

class AddRecipeModal extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      showModal: false,
      name: '',
      ingredients: ''
    };
    
    this.close = this.close.bind(this);
    this.open = this.open.bind(this);
    this.onChange = this.onChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  close() {
    this.setState({
      showModal: false
    });
  }

  open() {
    this.setState({
      showModal: true
    });
  }

  onChange(event) {
    switch (event.target.id) {
      case 'recipe-name':
        this.setState({name: event.target.value});
        break;
      case 'ingredients':
        this.setState({ingredients: event.target.value});
        break;
      default:
        break;
    }
  }

  handleSubmit(event) {
    event.preventDefault();
    // Build object from state
    const newRecipe = {
      name: this.state.name,
      ingredients: this.state.ingredients
    };
    this.props.onNew(newRecipe);
    // Clear state after passed to RecipeContainer
    this.setState({name: '', ingredients: ''});
    this.close();
  }

  render() {
    return (
      <div>
        <Button
          className="add-button"
          bsSize="large"
          bsStyle="primary"
          block
          onClick={this.open}
        >
          Add Recipe
        </Button>
        <Modal show={this.state.showModal} onHide={this.close}>
          <Modal.Header closeButton>
            <Modal.Title>Add a Recipe</Modal.Title>
          </Modal.Header>
          <Modal.Body>
            <form onSubmit={this.handleSubmit}>
              <ControlLabel>Recipe</ControlLabel>
              <FormControl
                id="recipe-name"
                placeholder="Recipe Name"
                value={this.state.name}
                onChange={this.onChange}
              />
              <ControlLabel>Ingredients</ControlLabel>
              <FormControl
                id="ingredients"
                componentClass="textarea"
                placeholder="Enter, ingredients, separated, by, commas"
                value={this.state.ingredients}
                onChange={this.onChange}
              />
            </form>
          </Modal.Body>
          <Modal.Footer>
            <ButtonToolbar className="pull-right">
              <Button onClick={this.handleSubmit} bsStyle="primary">
                Add Recipe
              </Button>
              <Button onClick={this.close}>Close</Button>
            </ButtonToolbar>
          </Modal.Footer>
        </Modal>
      </div>
    );
  }
}

function App() {
  return (
    <Grid>
      <Row>
        <Col xs={12}>
          <RecipeContainer />
        </Col>
      </Row>
    </Grid>  
  );
}

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

// Set background of page
const deviceHeight =  document.documentElement.clientHeight;
const deviceWidth = document.documentElement.clientWidth;
document.body.style.backgroundImage = `url(https://source.unsplash.com/collection/197345/${deviceWidth}x${deviceHeight})`;

              
            
!
999px

Console