ecommerceItem

In this example below you will see how to do a ecommerceItem with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 15chrjef, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 15chrjef ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>ecommerceItem</title>
  
  
  <link rel='stylesheet prefetch' href='https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css'>
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css'>

  
  
</head>

<body>

  <div id='container'/>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/15chrjef/ecommerceitem-BpMeyW */
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ProductImage = function ProductImage(props) {
  var color = props.color,
      src = props.src;

  return React.createElement(
    'div',
    null,
    React.createElement('i', { style: {
        color: color,
        fontSize: '180px',
        paddingLeft: '20px',
        paddingRight: '20px',
        border: '1px solid black'
      },
      className: src })
  );
};

var ColorSelector = function ColorSelector(props) {
  return React.createElement(
    'div',
    { style: { display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center' } },
    React.createElement(
      'div',
      null,
      'Select A Color'
    ),
    React.createElement(
      'div',
      { style: { display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center' } },
      React.createElement('p', {
        onClick: function onClick() {
          return props.changeColor('black');
        },
        style: { height: '20px', width: '20px', backgroundColor: 'black', cursor: 'pointer' }
      }),
      React.createElement('p', {
        onClick: function onClick() {
          return props.changeColor('blue');
        },
        style: { height: '20px', width: '20px', backgroundColor: 'blue', cursor: 'pointer' }
      }),
      React.createElement('p', {
        onClick: function onClick() {
          return props.changeColor('yellow');
        },
        style: { height: '20px', width: '20px', backgroundColor: 'yellow', cursor: 'pointer' }
      }),
      React.createElement('p', {
        onClick: function onClick() {
          return props.changeColor('red');
        },
        style: { height: '20px', width: '20px', backgroundColor: 'red', cursor: 'pointer' }
      })
    )
  );
};

var ProductInfo = function ProductInfo(props) {
  var content;
  if (props.showInfo === 'description') {
    content = React.createElement(
      'div',
      null,
      props.description
    );
  } else {
    var content = props.reviews.map(function (review) {
      return React.createElement(
        'div',
        null,
        review
      );
    });
  }

  return React.createElement(
    'div',
    null,
    React.createElement(
      'h1',
      null,
      props.name
    ),
    React.createElement(
      'h4',
      null,
      'Price: $',
      props.price,
      '.00'
    ),
    React.createElement(
      'button',
      null,
      'Buy it Now'
    ),
    React.createElement(
      'select',
      { onChange: function onChange(e) {
          return props.handleSelect(e);
        } },
      React.createElement(
        'option',
        { value: 'reviews' },
        'Reviews'
      ),
      React.createElement(
        'option',
        { value: 'description' },
        'Description'
      )
    ),
    content
  );
};

var App = function (_React$Component) {
  _inherits(App, _React$Component);

  function App() {
    _classCallCheck(this, App);

    var _this = _possibleConstructorReturn(this, (App.__proto__ || Object.getPrototypeOf(App)).call(this));

    _this.state = {
      name: 'SpinningWidget',
      color: 'black',
      reviews: [],
      description: 'an amazing spinner',
      price: '10',
      showInfo: 'reviews',
      text: ''
    };
    return _this;
  }

  _createClass(App, [{
    key: 'changeColor',
    value: function changeColor(color) {
      this.setState({ color: color });
    }
  }, {
    key: 'handleSelect',
    value: function handleSelect(e) {
      this.setState({ showInfo: e.target.value });
    }
  }, {
    key: 'handleSubmit',
    value: function handleSubmit(e) {
      e.preventDefault();
      var text = this.state.text;
      var arr = this.state.reviews.slice();
      arr.push(text);
      this.setState({
        reviews: arr,
        text: ''
      });
    }
  }, {
    key: 'handleChange',
    value: function handleChange(text) {
      this.setState({ text: text.target.value });
    }
  }, {
    key: 'render',
    value: function render() {
      var _state = this.state,
          name = _state.name,
          reviews = _state.reviews,
          color = _state.color,
          price = _state.price,
          description = _state.description,
          showInfo = _state.showInfo;

      return React.createElement(
        'div',
        { style: { display: 'flex', flexDirection: 'row' } },
        React.createElement(
          'div',
          { style: { marginRight: '80px' } },
          React.createElement(ProductImage, {
            src: 'ion-ios-game-controller-a',
            color: color
          }),
          React.createElement(ColorSelector, { changeColor: this.changeColor.bind(this) })
        ),
        React.createElement(
          'div',
          null,
          React.createElement(ProductInfo, {
            showInfo: showInfo,
            handleSelect: this.handleSelect.bind(this),
            name: name,
            reviews: reviews,
            description: description,
            color: color,
            price: price
          }),
          React.createElement(
            'form',
            { onSubmit: this.handleSubmit.bind(this) },
            React.createElement('input', {
              onChange: this.handleChange.bind(this),
              value: this.state.text,
              type: 'text'
            }),
            React.createElement('input', { onSubmit: this.handleSubmit, type: 'submit' })
          )
        )
      );
    }
  }]);

  return App;
}(React.Component);

ReactDOM.render(React.createElement(App, null), document.getElementById('container'));

Comments