vademecum.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict';
  2. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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); } }
  5. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11. var dom = React.createElement;
  12. var Tag = function Tag(label, key, className) {
  13. return dom("span", {
  14. className: "tag ".concat(className || ''),
  15. key: key
  16. }, label);
  17. };
  18. var Section = function Section(title, paragraph, prepend) {
  19. return dom("div", {
  20. className: "section-container"
  21. }, dom("h4", {
  22. className: "section-name"
  23. }, title), dom("p", {
  24. className: "section-body"
  25. }, prepend, paragraph));
  26. };
  27. var Product = function Product(product, key) {
  28. return dom("div", {
  29. className: "product-container"
  30. }, dom("h3", {
  31. className: "product-name"
  32. }, product.name), dom("div", {
  33. className: "product-body"
  34. }, dom("p", {
  35. className: "product-short-desc"
  36. }, product.shortDesc), Section('Descripción', product.fullDesc), product.application && Section('Aplicación', product.application), product.actives && Section('Activos', product.actives.join(', '), product.ph && Tag("PH ".concat(product.ph), null, 'is-ph'))));
  37. };
  38. var Category = function Category(category, products) {
  39. return dom("table", {
  40. className: "category-container table is-fullwidth"
  41. }, dom("thead", {
  42. className: "category",
  43. id: category[TAG]
  44. }, dom("tr", null, dom("th", null, dom("h2", {
  45. className: "category-name"
  46. }, category[LABEL])))), dom("tbody", null, products.map(function (p, i) {
  47. return dom("tr", null, dom("td", null, Product(p, i)));
  48. })), dom("tfoot", null, dom("tr", null, dom("td", null, dom("div", {
  49. class: "footer-space",
  50. height: "20px"
  51. }, "\xA0")))));
  52. };
  53. var ToC = function ToC(categories, products) {
  54. return dom("table", {
  55. className: "toc-table table is-fullwidth"
  56. }, dom("thead", null, dom("tr", null, dom("th", null, dom("h2", null, "Indice")))), dom("tbody", null, categories.map(function (category, i) {
  57. return dom("tr", null, dom("td", null, dom("div", {
  58. className: "toc-section"
  59. }, dom("div", null, dom("a", {
  60. href: "#".concat(category[TAG]),
  61. className: "toc-title"
  62. }, category[LABEL], dom("img", {
  63. src: "images/arrow.png",
  64. className: "toc-goto"
  65. }))), products[category[LABEL]].map(function (product) {
  66. return dom("div", {
  67. className: "toc-content"
  68. }, product.name);
  69. }))));
  70. })));
  71. };
  72. var Vademecum = function Vademecum(categories, products) {
  73. return categories.map(function (categoryName, i) {
  74. return dom("div", {
  75. key: i
  76. }, Category(categoryName, products[categoryName[LABEL]]));
  77. });
  78. };
  79. var domContainer = document.querySelector('#vademecum');
  80. var LABEL = 0,
  81. TAG = 1;
  82. fetch('data/products-by-category.json').then(function (response) {
  83. return response.json();
  84. }).then(function (data) {
  85. console.log('data', data);
  86. });
  87. var VademecumData =
  88. /*#__PURE__*/
  89. function (_React$Component) {
  90. _inherits(VademecumData, _React$Component);
  91. function VademecumData(props) {
  92. var _this;
  93. _classCallCheck(this, VademecumData);
  94. _this = _possibleConstructorReturn(this, _getPrototypeOf(VademecumData).call(this, props));
  95. _this.state = {
  96. categories: [["Higiene", "higiene"], ["Máscaras", "mascaras"], ["Ácido Hialurónico", "acido-hialuronico"], ["Peeling", "peeling"], ["Corporales", "corporales"], ["Hombres", "hombres"], ["Protección Intensiva", "proteccion-intensiva"], ["Monodosis", "monodosis"], ["Activos Concentrados", "activos-concentrados"], ["Protección Solar", "proteccion-solar"]],
  97. products: null
  98. };
  99. return _this;
  100. }
  101. _createClass(VademecumData, [{
  102. key: "componentDidMount",
  103. value: function componentDidMount() {
  104. var _this2 = this;
  105. fetch('data/products-by-category.json').then(function (response) {
  106. return response.json();
  107. }).then(function (data) {
  108. _this2.setState({
  109. products: data
  110. });
  111. });
  112. }
  113. }, {
  114. key: "render",
  115. value: function render() {
  116. var _this$state = this.state,
  117. categories = _this$state.categories,
  118. products = _this$state.products;
  119. if (products) {
  120. return dom("div", null, ToC(categories, products), Vademecum(categories, products));
  121. } else {
  122. return dom("div", null);
  123. }
  124. }
  125. }]);
  126. return VademecumData;
  127. }(React.Component);
  128. ReactDOM.render(dom(VademecumData), domContainer);