vademecum.js 6.8 KB

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