vademecum.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. 'use strict';
  2. const dom = React.createElement;
  3. const Tag = (label, key, className) => (
  4. <span className={`tag ${className||''}`} key={key}>{label}</span>
  5. );
  6. const Section = (title, paragraph, prepend) => (
  7. <div className="section-container">
  8. <h4 className="section-name">
  9. { title }
  10. </h4>
  11. <p className="section-body">
  12. { prepend }{ paragraph }
  13. </p>
  14. </div>
  15. );
  16. const Product = (product, key) => (
  17. <div className="product-container">
  18. <h3 className="product-name">
  19. {product.name}
  20. </h3>
  21. <div className="product-body">
  22. <p className="product-short-desc">
  23. {product.shortDesc}
  24. </p>
  25. {
  26. Section('Descripción', product.fullDesc)
  27. }
  28. {
  29. product.application && Section('Aplicación', product.application)
  30. }
  31. {
  32. product.actives &&
  33. Section(
  34. 'Activos',
  35. product.actives.join(', '),
  36. product.ph && Tag(`PH ${product.ph}`, null, 'is-ph')
  37. )
  38. }
  39. </div>
  40. </div>
  41. );
  42. const Category = (category, products) => (
  43. <table className="category-container table is-fullwidth">
  44. <thead className="category" id={category[TAG]}>
  45. <tr>
  46. <th>
  47. <h2 className="category-name">{category[LABEL]}</h2>
  48. </th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. {
  53. products.map((p, i) => (
  54. <tr><td>
  55. { Product(p, i) }
  56. </td></tr>
  57. ))
  58. }
  59. </tbody>
  60. <tfoot><tr><td>
  61. <div class="footer-space" height="20px">&nbsp;</div>
  62. </td></tr></tfoot>
  63. </table>
  64. );
  65. const ToC = (categories, products) => (
  66. <table className='toc-table table is-fullwidth'>
  67. <thead>
  68. <tr><th><h2>Indice</h2></th></tr>
  69. </thead>
  70. <tbody>
  71. {
  72. categories.map((category, i) => (
  73. <tr><td>
  74. <div className='toc-section'>
  75. <div>
  76. <a href={`#${category[TAG]}`} className='toc-title'>{category[LABEL]}
  77. <img src="images/arrow.png" className="toc-goto"/>
  78. </a>
  79. </div>
  80. {
  81. products[category[LABEL]].map(product => (
  82. <div className='toc-content'>
  83. { product.name }
  84. </div>
  85. ))
  86. }
  87. </div>
  88. </td></tr>
  89. ))
  90. }
  91. </tbody>
  92. </table>
  93. )
  94. const Vademecum = (categories, products) => {
  95. return categories.map((categoryName, i) => (
  96. <div key={i}>
  97. {
  98. Category(categoryName, products[categoryName[LABEL]])
  99. }
  100. </div>
  101. ))
  102. }
  103. const domContainer = document.querySelector('#vademecum');
  104. const LABEL = 0,
  105. TAG = 1;
  106. class VademecumData extends React.Component {
  107. constructor(props) {
  108. super(props);
  109. this.state = {
  110. categories: [
  111. [ "Higiene", "higiene" ],
  112. [ "Máscaras", "mascaras" ],
  113. [ "Ácido Hialurónico", "acido-hialuronico" ],
  114. [ "Peeling", "peeling" ],
  115. [ "Corporales", "corporales" ],
  116. [ "Hombres", "hombres" ],
  117. [ "Protección Intensiva", "proteccion-intensiva" ],
  118. [ "Monodosis", "monodosis" ],
  119. [ "Activos Concentrados", "activos-concentrados" ],
  120. [ "Protección Solar", "proteccion-solar" ]
  121. ],
  122. products: null,
  123. }
  124. }
  125. componentDidMount() {
  126. fetch('data/products-by-category.json')
  127. .then(response => response.json())
  128. .then(data => {
  129. this.setState({
  130. products: data,
  131. })
  132. })
  133. }
  134. render() {
  135. const { categories, products } = this.state;
  136. if (products) {
  137. return (
  138. <div>
  139. { ToC(categories, products) }
  140. { Vademecum(categories, products) }
  141. </div>
  142. )
  143. } else {
  144. return (<div></div>);
  145. }
  146. }
  147. }
  148. ReactDOM.render(dom(VademecumData), domContainer);