vademecum.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  12. var dom = React.createElement;
  13. var CONFIG = _defineProperty({
  14. "prof-a": {
  15. contactInformation: true,
  16. productFilter: function productFilter(products) {
  17. return products;
  18. },
  19. prices: false,
  20. 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"]]
  21. },
  22. "prof-b": {
  23. contactInformation: false,
  24. productFilter: function productFilter(products) {
  25. return products;
  26. },
  27. prices: false,
  28. 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"]]
  29. },
  30. "dom-a": {
  31. contactInformation: false,
  32. productFilter: function productFilter(products) {
  33. return products;
  34. },
  35. prices: true
  36. }
  37. }, "dom-a", {
  38. contactInformation: false,
  39. productFilter: function productFilter(products) {
  40. return products;
  41. },
  42. prices: false
  43. });
  44. console.log("prof-b", CONFIG["prof-b"]);
  45. var Tag = function Tag(label, key, className) {
  46. return dom("span", {
  47. className: "tag ".concat(className || ''),
  48. key: key
  49. }, label);
  50. };
  51. var Section = function Section(title, paragraph, prepend) {
  52. return dom("div", {
  53. className: "section-container"
  54. }, dom("h4", {
  55. className: "section-name"
  56. }, title), dom("p", {
  57. className: "section-body"
  58. }, prepend, paragraph));
  59. };
  60. var Product = function Product(product, key) {
  61. return dom("div", {
  62. className: "product-container"
  63. }, dom("h3", {
  64. className: "product-name"
  65. }, product.name), dom("div", {
  66. className: "product-body"
  67. }, dom("p", {
  68. className: "product-short-desc"
  69. }, 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'))));
  70. };
  71. var Category = function Category(category, products) {
  72. return dom("table", {
  73. className: "category-container table is-fullwidth"
  74. }, dom("thead", {
  75. className: "category",
  76. id: category[TAG]
  77. }, dom("tr", null, dom("th", null, dom("h2", {
  78. className: "category-name"
  79. }, category[LABEL])))), dom("tbody", null, products.map(function (p, i) {
  80. return dom("tr", null, dom("td", null, Product(p, i)));
  81. })), dom("tfoot", null, dom("tr", null, dom("td", null, dom("div", {
  82. class: "footer-space",
  83. height: "20px"
  84. }, "\xA0")))));
  85. };
  86. var ToC = function ToC(categories, products) {
  87. return dom("table", {
  88. className: "toc-table table is-fullwidth"
  89. }, dom("thead", null, dom("tr", null, dom("th", null, dom("h2", null, "Indice")))), dom("tbody", null, categories.map(function (category, i) {
  90. return dom("tr", null, dom("td", null, dom("div", {
  91. className: "toc-section"
  92. }, dom("div", null, dom("a", {
  93. href: "#".concat(category[TAG]),
  94. className: "toc-title"
  95. }, category[LABEL], dom("img", {
  96. src: "images/arrow.png",
  97. className: "toc-goto"
  98. }))), products[category[LABEL]].map(function (product) {
  99. return dom("div", {
  100. className: "toc-content"
  101. }, product.name);
  102. }))));
  103. })));
  104. };
  105. var Vademecum = function Vademecum(categories, products, prices) {
  106. console.log(prices);
  107. return categories.map(function (categoryName, i) {
  108. return dom("div", {
  109. key: i
  110. }, Category(categoryName, products[categoryName[LABEL]]));
  111. });
  112. };
  113. var domContainer = document.querySelector('#vademecum');
  114. var LABEL = 0,
  115. TAG = 1;
  116. var VademecumData =
  117. /*#__PURE__*/
  118. function (_React$Component) {
  119. _inherits(VademecumData, _React$Component);
  120. function VademecumData(props) {
  121. var _this;
  122. _classCallCheck(this, VademecumData);
  123. _this = _possibleConstructorReturn(this, _getPrototypeOf(VademecumData).call(this, props));
  124. var config = CONFIG["prof-b"];
  125. _this.state = {
  126. config: config,
  127. categories: config.categories,
  128. products: null
  129. };
  130. return _this;
  131. }
  132. _createClass(VademecumData, [{
  133. key: "componentDidMount",
  134. value: function componentDidMount() {
  135. var _this2 = this;
  136. fetch('data/products-by-category.json').then(function (response) {
  137. return response.json();
  138. }).then(this.state.config.productFilter).then(function (data) {
  139. _this2.setState({
  140. products: data
  141. });
  142. });
  143. }
  144. }, {
  145. key: "render",
  146. value: function render() {
  147. var _this$state = this.state,
  148. categories = _this$state.categories,
  149. products = _this$state.products,
  150. config = _this$state.config;
  151. if (products) {
  152. return dom("div", null, ToC(categories, products), Vademecum(categories, products, config.prices));
  153. } else {
  154. return dom("div", null);
  155. }
  156. }
  157. }]);
  158. return VademecumData;
  159. }(React.Component);
  160. ReactDOM.render(dom(VademecumData), domContainer);