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

              
                <div id="root"></div>
 <a target="_blank" title="instagram/web__addict" href="https://www.instagram.com/web__addict/"><i class="fab fa-instagram"></i></a>
              
            
!

CSS

              
                body{
  font-family: 'Libre Franklin', sans-serif;
  color: #3d2f71;
}
#root{
  width: fit-content;
  margin: 0 auto;
}
.card{
  margin: 40px;
  box-shadow: 7px 13px 49px -5px rgba(86, 63, 130, 0.78);
  border-radius: 30px;
  padding: 10px 40px;
}
.wrap{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  margin: 20px;
}
.left{
  margin-right: 20px;
}
form{
  display: flex;
  align-items: baseline;
  margin-top: 30px;
  margin-bottom: 30px;
}
.form-label{
  margin: 0 10px;
  font-size: 24px;
}
img{
  transform: scale(-1, 1);
}
input {
  border-radius: 10px;
  border: 2px solid #8c78cc;
  font-weight: 600;
  color: #3d2f71;
  padding-left: 15px;
  font-size: 18px;
  padding: 3px 3px 3px 10px;
}
input:focus{
  outline: none;
}
ul{
  list-style: none;
  padding: 0;
}
h2{
  font-size: 32px;
  margin-bottom: 50px;
  text-align: center;
}
.price__items{
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.price__descr{
  width: 300px;
  text-align: left;
}
.price-collapse .price__item{
  margin-bottom: 5px;
}
.collapse{
  margin-bottom: 20px;
  margin-left: 32px;
  cursor: pointer;
}
.price__add{
  font-weight: 600;
  color: #292929;
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  cursor: pointer;
  width: 450px;
}
.price{
  font-size: 17px;
  font-weight: 700;
  width: 70px;
}
.day-price{
  color: #3d2f71;
}
.icon{
  transition: all .4s linear;
  font-size: 20px;
  width: 22px;
}

.icon-add{
  color: #96d2ff;
}
.icon-add:hover{
  color: #319cec;
}
.icon-delete{
  color: #92da8a;
}
.icon-delete:hover{
  color: #f37490;
}
.icon-delete:hover::before {
  content: "\f057";
 }
.collapse__button{
  display: flex;
}
.collapse__switch{
  width: 60px;
}
.switch__icon{
  color: #808080;
}
.show {
  margin-top: 10px;
  font-size: 16px;
  max-width: 420px;
}
.price__summe{
  display: flex;
  align-items: center;
}
.summe-span{
  transition: all .4s linear;
}
h3{
  margin-right: 20px;
  text-transform: uppercase;
  font-weight: 600;
}
.price__summe{
  display: flex;
  justify-content: flex-end;
}
.summe-span{
  font-weight: 700;
  font-size: 32px;
}
@media screen and (max-width: 1100px) {
  .wrap {
    display: block; ;
  }
}

.fa-instagram{
  position: absolute;
  top: 3%;
  right: 2%;
  font-size: 38px;
}

.fa-instagram:hover{
  font-size: 42px;
  color: #dca118;
  transition: all .1s linear;
  cursor: pointer;
}
              
            
!

JS

              
                const products = [
  {name: 'General cleaning', price: 55, add: true },
  {name: 'Laundry package (for 2 pers.)', price: 13, add: false, dayPrice: false },
  {name: 'Highchair (per day)', price: 3, add: false, dayPrice: true},
  {name: 'Cot (per day)', price: 3, add: false, dayPrice: true },
  {name: 'Deposit', price: 100, add: false, dayPrice: false },
  {name: 'Laundry package (for 3rd and 4th pers.)', price: 19, add: false, dayPrice: false },
  {name: 'Booking', price: 15, add: false, dayPrice: false },
];

const Input = ({ 
    value, 
    onChange,
    onSubmit, 
  })=>{
    return(
      <form onSubmit={onSubmit}>
        <input
          className="input"
          type = "number"
          min="1"
          max="90"
          value = {value}
          onChange = {onChange}
        />
      </form>
    );
  }

class Price extends React.Component{
 state = {
   products,
   sum : 55,
   stayDays : 7,
 };

  onInputChange = e => {
    let stayDays = e.target.value;
    this.setState({ stayDays });
    this.updateSum(stayDays);
  };

  onInputSubmit = e => {
    e.preventDefault();
  };

  changeAdd = index => {
    const { products } = this.state;
    products[index].add = !products[index].add;
    this.setState({
      products
    });
  };

  updateSum = stayDays => {
    const { products } = this.state;
    let allItemsSum = 0;
    let addPrice;

    {
      products.map(product => {
        addPrice = product.price * (product.dayPrice ? stayDays : 1);
        product.add ? (allItemsSum += addPrice) : 0;
      });
    }

    this.setState({
      sum: allItemsSum
    });
  };

  handleClick = e => {
    const { index } = e.currentTarget.dataset;
    const { stayDays } = this.state;

    this.changeAdd(index);
    this.updateSum(stayDays);
  };

  render(){
    const {products, sum, stayDays} = this.state;
    return(
      <div className="card">
        <h2>Additional services</h2>
      <div className="wrap">
        <div className="left">
          <img src="https://github.com/OlgaKoplik/CodePen/blob/master/bg1.png?raw=true"/>
          <form>
            <label className="prev__input form-label" htmlFor="days">Stay time:</label>
            <Input 
              value = {stayDays}
              onChange = {this.onInputChange}
              onSubmit={this.onInputSubmit}
              id="days"
              />
            <label className="after__input form-label" htmlFor="days">Days</label>
          </form>
        </div>
        <div className="right">
          <ul>
            {products.map((product, index)=>(
              <li 
                data-index={index} 
                onClick={this.handleClick} 
                className="product price__add" >
                
                { product.add? (
                  <i className="fas fa-check-circle icon icon-delete delete"></i>
                ) : (
                  <i className="fas fa-plus-circle icon icon-add add"></i>
                )}
                <div className="price__descr">
                  <div className={"price__item" + (product.dayPrice ?' day-price':'')}>{product.name}</div>
                </div>
                
                <div className={"price" + (product.dayPrice ?' day-price':'')}>€ {product.price}.<sup>00</sup></div>
                
              </li>
            ))}
          </ul>
          <div className="price__summe">
            <h3>total:</h3><span className="summe-span">
            € {sum}.<sup>00</sup>
            </span>
          </div>
        </div>
      </div>
    </div>
    );
  }
}


ReactDOM.render(
  <Price />,
  document.getElementById('root')
);
              
            
!
999px

Console