|
1 | 1 | /** @jsx jsx */
|
2 | 2 | import { jsx } from "theme-ui"
|
3 |
| -import React from "react" |
4 |
| - |
| 3 | +import { Component } from "react" |
5 | 4 | import SectionTitle from "./evaluation-table-section-title"
|
6 | 5 | import SectionHeaderTop from "./evaluation-table-section-header-top"
|
7 | 6 | import { renderCell } from "./evaluation-cell"
|
| 7 | +import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org" |
8 | 8 |
|
9 |
| -const SimpleEvaluationTable = ({ title, headers, data }) => ( |
10 |
| - <React.Fragment> |
11 |
| - {title && <SectionTitle text={title} />} |
12 |
| - <table> |
13 |
| - <tbody> |
14 |
| - <SectionHeaderTop columnHeaders={headers.map(h => h.display)} /> |
15 |
| - {data.map((node, idx) => ( |
16 |
| - <tr key={`feature-row-${idx}`}> |
17 |
| - {headers.map((header, i) => ( |
| 9 | +class SimpleEvaluationTable extends Component { |
| 10 | + constructor() { |
| 11 | + super() |
| 12 | + this.state = {} |
| 13 | + } |
| 14 | + render() { |
| 15 | + const showTooltip = (row) => this.state[`feature-cell-${row}`] |
| 16 | + const { title, headers, data } = this.props |
| 17 | + return ( |
| 18 | + <div> |
| 19 | + {title && <SectionTitle text={title} />} |
| 20 | + <table> |
| 21 | + <tbody> |
| 22 | + <SectionHeaderTop columnHeaders={headers.map(h => h.display)} /> |
| 23 | + {data.map((node, idx) => |
| 24 | + [].concat([ |
| 25 | + <tr key={`feature-first-row-${idx}`}> |
| 26 | + {headers.map((header, i) => ( |
| 27 | + <td |
| 28 | + key={`feature-cell-${idx}-${i}`} |
| 29 | + sx={{ |
| 30 | + display: `table-cell`, |
| 31 | + "&:hover": { |
| 32 | + cursor: `pointer`, |
| 33 | + }, |
| 34 | + borderBottom: t => |
| 35 | + !showTooltip(idx) |
| 36 | + ? `1px solid ${t.colors.ui.border}` |
| 37 | + : `none`, |
| 38 | + minWidth: 40, |
| 39 | + paddingRight: 0, |
| 40 | + paddingLeft: 0, |
| 41 | + textAlign: `left`, |
| 42 | + verticalAlign: `middle`, |
| 43 | + fontSize: 1, |
| 44 | + lineHeight: `solid`, |
| 45 | + }} |
| 46 | + onClick={() => { |
| 47 | + this.setState({ |
| 48 | + [`feature-cell-${idx}`]: !showTooltip(idx), |
| 49 | + }) |
| 50 | + }} |
| 51 | + > |
| 52 | + {renderCell(node[header.nodeFieldProperty], i)} |
| 53 | + </td> |
| 54 | + ))} |
| 55 | + </tr>, |
| 56 | + // table row containing details of each feature |
| 57 | + <tr |
| 58 | + style={{ |
| 59 | + display: showTooltip(idx) ? `table-row` : `none`, |
| 60 | + }} |
| 61 | + key={`feature-second-row-${idx}`} |
| 62 | + > |
18 | 63 | <td
|
19 |
| - key={`feature-cell-${idx}-${i}`} |
20 | 64 | sx={{
|
21 |
| - display: `table-cell`, |
22 |
| - "&:hover": { |
23 |
| - cursor: `pointer`, |
| 65 | + paddingBottom: t => `calc(${t.space[5]} - 1px)`, |
| 66 | + "&&": { |
| 67 | + [mediaQueries.xs]: { |
| 68 | + px: 3, |
| 69 | + }, |
24 | 70 | },
|
25 |
| - borderBottom: t => `1px solid ${t.colors.ui.border}`, |
26 |
| - minWidth: 40, |
27 |
| - px: 0, |
28 |
| - textAlign: `left`, |
29 |
| - verticalAlign: `middle`, |
30 |
| - fontSize: 1, |
31 |
| - lineHeight: `solid`, |
32 | 71 | }}
|
| 72 | + colSpan="5" |
33 | 73 | >
|
34 |
| - {renderCell(node[header.nodeFieldProperty], i)} |
| 74 | + { |
| 75 | + <span |
| 76 | + dangerouslySetInnerHTML={{ |
| 77 | + __html: node.Description, |
| 78 | + }} |
| 79 | + /> |
| 80 | + } |
35 | 81 | </td>
|
36 |
| - ))} |
37 |
| - </tr> |
38 |
| - ))} |
39 |
| - </tbody> |
40 |
| - </table> |
41 |
| - </React.Fragment> |
42 |
| -) |
| 82 | + </tr>, |
| 83 | + ]))} |
| 84 | + </tbody> |
| 85 | + </table> |
| 86 | + </div> |
| 87 | + ) |
| 88 | + } |
| 89 | +} |
43 | 90 |
|
44 | 91 | export default SimpleEvaluationTable
|
| 92 | + |
0 commit comments