vademecum.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. var Tag = function Tag(label, key, className) {
  45. return dom("div", {
  46. className: "chip ".concat(className || ''),
  47. key: key
  48. }, label);
  49. };
  50. var Section = function Section(title, paragraph, prepend) {
  51. return dom("div", {
  52. className: "section-container"
  53. }, dom("h4", {
  54. className: "section-name"
  55. }, title), dom("p", {
  56. className: "section-body",
  57. lang: "es"
  58. }, prepend, paragraph));
  59. };
  60. var Product = function Product(product, key) {
  61. return dom("div", {
  62. className: "product-container"
  63. }, dom("div", {
  64. className: "row valign-wrapper"
  65. }, dom("div", {
  66. class: "col s2"
  67. }, dom("img", {
  68. src: "images/_img/".concat(product.img || product.variants[0].img, ".png"),
  69. className: "responsive-img"
  70. })), dom("div", {
  71. class: "col s10"
  72. }, dom("h4", {
  73. className: "product-name"
  74. }, product.name), dom("div", {
  75. className: "product-body"
  76. }, dom("p", {
  77. className: "product-short-desc",
  78. lang: "es"
  79. }, product.shortDesc)))), dom("div", null, Section('Descripción', product.fullDesc), product.application && Section('Aplicación', product.application), product.actives && Section('', product.actives.map(function (p) {
  80. return Tag(p);
  81. }), product.ph && Tag("PH ".concat(product.ph), null, 'is-ph'))), dom("div", {
  82. className: "divider"
  83. }));
  84. };
  85. var Category = function Category(category, products, prices) {
  86. return dom("section", {
  87. id: category[TAG],
  88. className: "container"
  89. }, dom("h2", {
  90. className: "category-name"
  91. }, category[LABEL]), dom("div", {
  92. className: "collection"
  93. }, products.map(function (p, i) {
  94. return dom("div", {
  95. className: "collection-item"
  96. }, Product(p, i));
  97. })));
  98. };
  99. var ToC = function ToC(categories, products) {
  100. return dom("section", {
  101. id: "eba-toc",
  102. className: "container"
  103. }, dom("h2", {
  104. className: "pagebreak"
  105. }, "Indice"), dom("div", {
  106. class: "col s8"
  107. }, categories.map(function (category, i) {
  108. return dom("div", null, dom("div", null, dom("a", {
  109. href: "#".concat(category[TAG])
  110. }, dom("h5", null, category[LABEL], " ", dom("i", {
  111. className: "material-icons"
  112. }, "chevron_right")))), products[category[LABEL]].map(function (product) {
  113. return dom("div", null, product.name);
  114. }));
  115. })));
  116. };
  117. var Vademecum = function Vademecum(categories, products, prices) {
  118. return categories.map(function (categoryName, i) {
  119. return dom("div", {
  120. key: i
  121. }, Category(categoryName, products[categoryName[LABEL]], prices));
  122. });
  123. };
  124. var domContainer = document.querySelector('#vademecum');
  125. var LABEL = 0,
  126. TAG = 1;
  127. var VademecumData =
  128. /*#__PURE__*/
  129. function (_React$Component) {
  130. _inherits(VademecumData, _React$Component);
  131. function VademecumData(props) {
  132. var _this;
  133. _classCallCheck(this, VademecumData);
  134. _this = _possibleConstructorReturn(this, _getPrototypeOf(VademecumData).call(this, props));
  135. var config = CONFIG["prof-a"];
  136. _this.state = {
  137. config: config,
  138. categories: config.categories,
  139. products: null
  140. };
  141. return _this;
  142. }
  143. _createClass(VademecumData, [{
  144. key: "componentDidMount",
  145. value: function componentDidMount() {
  146. var _this2 = this;
  147. fetch('data/products-by-category.json').then(function (response) {
  148. return response.json();
  149. }).then(this.state.config.productFilter).then(function (data) {
  150. _this2.setState({
  151. products: data
  152. });
  153. });
  154. }
  155. }, {
  156. key: "render",
  157. value: function render() {
  158. var _this$state = this.state,
  159. categories = _this$state.categories,
  160. products = _this$state.products,
  161. config = _this$state.config;
  162. if (products) {
  163. return dom("div", null, ToC(categories, products), Vademecum(categories, products, config.prices));
  164. } else {
  165. return dom("div", null);
  166. }
  167. }
  168. }]);
  169. return VademecumData;
  170. }(React.Component);
  171. ReactDOM.render(dom(VademecumData), domContainer);