@dhis2-ui/table 10.16.2 → 10.16.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/package.json +5 -4
  2. package/src/data-table/__tests__/data-table-cell.test.js +168 -0
  3. package/src/data-table/__tests__/data-table-column-header/filter-handle.test.js +43 -0
  4. package/src/data-table/__tests__/data-table-column-header/sorter.test.js +41 -0
  5. package/src/data-table/__tests__/data-table-column-header.test.js +227 -0
  6. package/src/data-table/__tests__/data-table-row/expand-handle-cell.js +32 -0
  7. package/src/data-table/__tests__/data-table-row/expanded-row.test.js +57 -0
  8. package/src/data-table/__tests__/data-table-row.test.js +162 -0
  9. package/src/data-table/__tests__/data-table.test.js +85 -0
  10. package/src/data-table/data-table-body.js +3 -0
  11. package/src/data-table/data-table-cell.js +111 -0
  12. package/src/data-table/data-table-column-header/data-table-column-header.js +130 -0
  13. package/src/data-table/data-table-column-header/data-table-column-header.styles.js +30 -0
  14. package/src/data-table/data-table-column-header/filter-handle.js +30 -0
  15. package/src/data-table/data-table-column-header/sorter.js +67 -0
  16. package/src/data-table/data-table-foot.js +3 -0
  17. package/src/data-table/data-table-head.js +3 -0
  18. package/src/data-table/data-table-row/data-table-row.js +103 -0
  19. package/src/data-table/data-table-row/data-table-row.styles.js +20 -0
  20. package/src/data-table/data-table-row/drag-handle-cell.js +9 -0
  21. package/src/data-table/data-table-row/expand-handle-cell.js +28 -0
  22. package/src/data-table/data-table-row/expanded-row.js +51 -0
  23. package/src/data-table/data-table-toolbar.js +3 -0
  24. package/src/data-table/data-table.e2e.stories.js +192 -0
  25. package/src/data-table/data-table.js +75 -0
  26. package/src/data-table/data-table.prod.stories.js +1342 -0
  27. package/src/data-table/features/can_scroll/index.js +48 -0
  28. package/src/data-table/features/can_scroll.feature +31 -0
  29. package/src/data-table/index.js +8 -0
  30. package/src/data-table/table-elements/__tests__/table-body.test.js +40 -0
  31. package/src/data-table/table-elements/__tests__/table-data-cell.test.js +123 -0
  32. package/src/data-table/table-elements/__tests__/table-foot.test.js +40 -0
  33. package/src/data-table/table-elements/__tests__/table-head.test.js +40 -0
  34. package/src/data-table/table-elements/__tests__/table-header-cell-action.test.js +46 -0
  35. package/src/data-table/table-elements/__tests__/table-header-cell.test.js +130 -0
  36. package/src/data-table/table-elements/__tests__/table-row.test.js +52 -0
  37. package/src/data-table/table-elements/__tests__/table-scroll-box.test.js +40 -0
  38. package/src/data-table/table-elements/__tests__/table-toolbar.test.js +44 -0
  39. package/src/data-table/table-elements/__tests__/table.test.js +53 -0
  40. package/src/data-table/table-elements/features/can_scroll/index.js +42 -0
  41. package/src/data-table/table-elements/features/can_scroll.feature +31 -0
  42. package/src/data-table/table-elements/index.js +10 -0
  43. package/src/data-table/table-elements/table-body.js +75 -0
  44. package/src/data-table/table-elements/table-data-cell/table-data-cell.js +126 -0
  45. package/src/data-table/table-elements/table-data-cell/table-data-cell.styles.js +42 -0
  46. package/src/data-table/table-elements/table-foot.js +35 -0
  47. package/src/data-table/table-elements/table-head.js +26 -0
  48. package/src/data-table/table-elements/table-header-cell/table-header-cell.js +121 -0
  49. package/src/data-table/table-elements/table-header-cell/table-header-cell.styles.js +71 -0
  50. package/src/data-table/table-elements/table-header-cell-action.js +62 -0
  51. package/src/data-table/table-elements/table-row.js +52 -0
  52. package/src/data-table/table-elements/table-scroll-box.js +41 -0
  53. package/src/data-table/table-elements/table-toolbar.js +50 -0
  54. package/src/data-table/table-elements/table.e2e.stories.js +190 -0
  55. package/src/data-table/table-elements/table.js +70 -0
  56. package/src/data-table/table-elements/table.stories.internal.js +1144 -0
  57. package/src/index.js +32 -0
  58. package/src/locales/ar/translations.json +4 -0
  59. package/src/locales/cs/translations.json +4 -0
  60. package/src/locales/en/translations.json +4 -0
  61. package/src/locales/es/translations.json +4 -0
  62. package/src/locales/es_419/translations.json +4 -0
  63. package/src/locales/fr/translations.json +4 -0
  64. package/src/locales/index.js +44 -0
  65. package/src/locales/km/translations.json +4 -0
  66. package/src/locales/lo/translations.json +4 -0
  67. package/src/locales/nb/translations.json +4 -0
  68. package/src/locales/nl/translations.json +4 -0
  69. package/src/locales/pt/translations.json +4 -0
  70. package/src/locales/ru/translations.json +4 -0
  71. package/src/locales/uk/translations.json +4 -0
  72. package/src/locales/uz_UZ_Cyrl/translations.json +4 -0
  73. package/src/locales/zh/translations.json +4 -0
  74. package/src/stacked-table/add-col-num-to-children.js +16 -0
  75. package/src/stacked-table/content-with-title.js +40 -0
  76. package/src/stacked-table/extract-header-labels.js +99 -0
  77. package/src/stacked-table/index.js +8 -0
  78. package/src/stacked-table/stacked-table-body.js +23 -0
  79. package/src/stacked-table/stacked-table-cell-head.js +39 -0
  80. package/src/stacked-table/stacked-table-cell.js +60 -0
  81. package/src/stacked-table/stacked-table-foot.js +24 -0
  82. package/src/stacked-table/stacked-table-head.js +23 -0
  83. package/src/stacked-table/stacked-table-row-head.js +19 -0
  84. package/src/stacked-table/stacked-table-row.js +50 -0
  85. package/src/stacked-table/stacked-table.js +33 -0
  86. package/src/stacked-table/stacked-table.prod.stories.js +463 -0
  87. package/src/stacked-table/stacked-table.test.js +127 -0
  88. package/src/stacked-table/supply-header-labels-to-children.js +7 -0
  89. package/src/stacked-table/table-context.js +4 -0
  90. package/src/stacked-table/table.js +28 -0
  91. package/src/table/index.js +8 -0
  92. package/src/table/table-body.js +21 -0
  93. package/src/table/table-cell-head.js +56 -0
  94. package/src/table/table-cell.js +56 -0
  95. package/src/table/table-context.js +7 -0
  96. package/src/table/table-foot.js +21 -0
  97. package/src/table/table-head.js +21 -0
  98. package/src/table/table-row-head.js +30 -0
  99. package/src/table/table-row.js +51 -0
  100. package/src/table/table.js +41 -0
  101. package/src/table/table.prod.stories.js +724 -0
package/src/index.js ADDED
@@ -0,0 +1,32 @@
1
+ export {
2
+ Table,
3
+ TableFoot,
4
+ TableBody,
5
+ TableHead,
6
+ TableCell,
7
+ TableCellHead,
8
+ TableRow,
9
+ TableRowHead,
10
+ } from './table/index.js'
11
+
12
+ export {
13
+ StackedTable,
14
+ StackedTableHead,
15
+ StackedTableBody,
16
+ StackedTableFoot,
17
+ StackedTableCell,
18
+ StackedTableCellHead,
19
+ StackedTableRow,
20
+ StackedTableRowHead,
21
+ } from './stacked-table/index.js'
22
+
23
+ export {
24
+ DataTable,
25
+ DataTableBody,
26
+ DataTableCell,
27
+ DataTableColumnHeader,
28
+ DataTableFoot,
29
+ DataTableHead,
30
+ DataTableRow,
31
+ DataTableToolbar,
32
+ } from './data-table/index.js'
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "",
3
+ "Sort items": "ترتيب العناصر"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Přepnout filtr",
3
+ "Sort items": "Třídit položky"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Toggle filter",
3
+ "Sort items": "Sort items"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Alternar filtro",
3
+ "Sort items": "Ordena elementos"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Alternar filtro",
3
+ "Sort items": "Clasificar artículos"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Changer de filtre",
3
+ "Sort items": "Trier les éléments"
4
+ }
@@ -0,0 +1,44 @@
1
+ //------------------------------------------------------------------------------
2
+ // <auto-generated>
3
+ // This code was generated by d2-i18n-generate.
4
+ //
5
+ // Changes to this file may cause incorrect behavior and will be lost if
6
+ // the code is regenerated.
7
+ // </auto-generated>
8
+ //------------------------------------------------------------------------------
9
+ import i18n from '@dhis2/d2-i18n'
10
+
11
+ import arTranslations from './ar/translations.json'
12
+ import csTranslations from './cs/translations.json'
13
+ import enTranslations from './en/translations.json'
14
+ import esTranslations from './es/translations.json'
15
+ import es_419Translations from './es_419/translations.json'
16
+ import frTranslations from './fr/translations.json'
17
+ import kmTranslations from './km/translations.json'
18
+ import loTranslations from './lo/translations.json'
19
+ import nbTranslations from './nb/translations.json'
20
+ import nlTranslations from './nl/translations.json'
21
+ import ptTranslations from './pt/translations.json'
22
+ import ruTranslations from './ru/translations.json'
23
+ import ukTranslations from './uk/translations.json'
24
+ import uz_UZ_CyrlTranslations from './uz_UZ_Cyrl/translations.json'
25
+ import zhTranslations from './zh/translations.json'
26
+
27
+ const namespace = 'default'
28
+ i18n.addResources('ar', namespace, arTranslations)
29
+ i18n.addResources('cs', namespace, csTranslations)
30
+ i18n.addResources('en', namespace, enTranslations)
31
+ i18n.addResources('es', namespace, esTranslations)
32
+ i18n.addResources('es_419', namespace, es_419Translations)
33
+ i18n.addResources('fr', namespace, frTranslations)
34
+ i18n.addResources('km', namespace, kmTranslations)
35
+ i18n.addResources('lo', namespace, loTranslations)
36
+ i18n.addResources('nb', namespace, nbTranslations)
37
+ i18n.addResources('nl', namespace, nlTranslations)
38
+ i18n.addResources('pt', namespace, ptTranslations)
39
+ i18n.addResources('ru', namespace, ruTranslations)
40
+ i18n.addResources('uk', namespace, ukTranslations)
41
+ i18n.addResources('uz_UZ_Cyrl', namespace, uz_UZ_CyrlTranslations)
42
+ i18n.addResources('zh', namespace, zhTranslations)
43
+
44
+ export default i18n
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "",
3
+ "Sort items": "តម្រៀប"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "ສະຫຼັບຕົວກອງ",
3
+ "Sort items": "ຈັດຮຽງລາຍການ"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Slå på filter",
3
+ "Sort items": "Sorter elementer"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Schakelfilter",
3
+ "Sort items": "Items sorteren"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Alternar filtro",
3
+ "Sort items": "Ordenar itens"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Переключить фильтр",
3
+ "Sort items": "Сортировать элементы"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Переключити фільтр",
3
+ "Sort items": "Сортувати об'єкти"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "Фильтрни алмаштириш",
3
+ "Sort items": "Элементларни саралаш"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Toggle filter": "切换过滤器",
3
+ "Sort items": "排序项目"
4
+ }
@@ -0,0 +1,16 @@
1
+ import { Children, cloneElement } from 'react'
2
+
3
+ export const addColNumToChildren = (children) => {
4
+ let curCol = 0
5
+
6
+ return Children.map(children, (child) => {
7
+ const column = child.props.column || curCol
8
+ const colSpan = child.props.colSpan
9
+ ? parseInt(child.props.colSpan, 10)
10
+ : 1
11
+
12
+ curCol += colSpan
13
+
14
+ return cloneElement(child, { column })
15
+ })
16
+ }
@@ -0,0 +1,40 @@
1
+ import { colors } from '@dhis2/ui-constants'
2
+ import PropTypes from 'prop-types'
3
+ import React, { Fragment } from 'react'
4
+
5
+ export const ContentWithTitle = ({ title, children }) => (
6
+ <Fragment>
7
+ {title && <span className="title">{title}</span>}
8
+ <span className="content">{children}</span>
9
+
10
+ <style jsx>{`
11
+ .title {
12
+ display: block;
13
+ white-space: normal;
14
+ min-height: 24px;
15
+ font-size: 13px;
16
+ line-height: 16px;
17
+ padding: 8px 0 4px;
18
+ font-weight: normal;
19
+ color: ${colors.grey700};
20
+ }
21
+
22
+ .content {
23
+ display: block;
24
+ padding: 0 0 8px 0;
25
+ font-size: 14px;
26
+ line-height: 18px;
27
+ }
28
+
29
+ .content:first-child {
30
+ padding-top: 8px;
31
+ padding-bottom: 8px;
32
+ }
33
+ `}</style>
34
+ </Fragment>
35
+ )
36
+
37
+ ContentWithTitle.propTypes = {
38
+ children: PropTypes.node.isRequired,
39
+ title: PropTypes.string,
40
+ }
@@ -0,0 +1,99 @@
1
+ import React from 'react'
2
+ import { StackedTableHead } from './stacked-table-head.js'
3
+
4
+ const isChildTableHead = (child) => child.type === StackedTableHead
5
+ const extractChildrenProp = (component) => component.props.children
6
+
7
+ const extractRowsFromTableChildren = (children) =>
8
+ React.Children.toArray(children)
9
+ .filter(isChildTableHead)
10
+
11
+ // extract table head children (rows)
12
+ .map(extractChildrenProp)
13
+
14
+ // when there are multiple header rows,
15
+ // children will come as arrays
16
+ .reduce(
17
+ (flattened, row) =>
18
+ Array.isArray(row)
19
+ ? [...flattened, ...row]
20
+ : [...flattened, row],
21
+ []
22
+ )
23
+
24
+ // extract table row children (cells),
25
+ // will return an array with arrays of cells
26
+ .map(extractChildrenProp)
27
+
28
+ const calculateColumnCount = (row) =>
29
+ Array.isArray(row)
30
+ ? row.reduce(
31
+ (total, col) =>
32
+ // make sure to take col span into account
33
+ col.props.colSpan
34
+ ? total + parseInt(col.props.colSpan, 10)
35
+ : total + 1,
36
+ 0
37
+ )
38
+ : 1
39
+
40
+ const mapCellsToLabels = (rowChildren) => {
41
+ let labels = []
42
+ // in case there's only one cell, the children are not an array
43
+ const row = Array.isArray(rowChildren) ? rowChildren : [rowChildren]
44
+
45
+ // Using a for loop here to be able to increment "i"
46
+ // when a cell has a colspan prop by the colspan number
47
+ for (let i = 0, count = row.length; i < count; ++i) {
48
+ const cell = row[i]
49
+ const colSpan = cell.props.colSpan
50
+ ? parseInt(cell.props.colSpan, 10)
51
+ : 1
52
+
53
+ const label = extractLabelFromCell(cell)
54
+
55
+ // Add a label entry for each column
56
+ labels = [...labels, ...Array(colSpan).fill(label)]
57
+ }
58
+
59
+ return labels
60
+ }
61
+
62
+ const extractLabelFromCell = (cell) =>
63
+ !cell.props.hideResponsiveLabel ? cell.props.children : ''
64
+
65
+ const combineRowLables = (columnCount, rowCount, headerLabels) =>
66
+ // create array with length of column count
67
+ Array(columnCount)
68
+ .fill('')
69
+ .reduce((labels, _, colIndex) => {
70
+ // an array with all labels for a column
71
+ const colLabels =
72
+ // create array with length of rows
73
+ Array(rowCount)
74
+ .fill('')
75
+ // get label for current row & col
76
+ .map((__, rowIndex) => headerLabels[rowIndex][colIndex])
77
+ // remove empty ones
78
+ .filter((val) => val)
79
+
80
+ return [...labels, colLabels.join(' / ')]
81
+ }, [])
82
+
83
+ export const extractHeaderLabels = (children) => {
84
+ if (React.Children.count(children) === 0) {
85
+ return []
86
+ }
87
+
88
+ const rows = extractRowsFromTableChildren(children)
89
+
90
+ if (!rows.length) {
91
+ return []
92
+ }
93
+
94
+ const rowCount = rows.length
95
+ const columnCount = calculateColumnCount(rows[0])
96
+ const headerLabels = rows.map(mapCellsToLabels)
97
+
98
+ return combineRowLables(columnCount, rowCount, headerLabels)
99
+ }
@@ -0,0 +1,8 @@
1
+ export { StackedTable } from './stacked-table.js'
2
+ export { StackedTableHead } from './stacked-table-head.js'
3
+ export { StackedTableBody } from './stacked-table-body.js'
4
+ export { StackedTableFoot } from './stacked-table-foot.js'
5
+ export { StackedTableCell } from './stacked-table-cell.js'
6
+ export { StackedTableCellHead } from './stacked-table-cell-head.js'
7
+ export { StackedTableRow } from './stacked-table-row.js'
8
+ export { StackedTableRowHead } from './stacked-table-row-head.js'
@@ -0,0 +1,23 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+
4
+ export const StackedTableBody = ({
5
+ children,
6
+ className,
7
+ dataTest = 'dhis2-uicore-stackedtablebody',
8
+ }) => (
9
+ <tbody className={className} data-tset={dataTest}>
10
+ {children}
11
+ <style jsx>{`
12
+ tbody {
13
+ display: block;
14
+ }
15
+ `}</style>
16
+ </tbody>
17
+ )
18
+
19
+ StackedTableBody.propTypes = {
20
+ children: PropTypes.node,
21
+ className: PropTypes.string,
22
+ dataTest: PropTypes.string,
23
+ }
@@ -0,0 +1,39 @@
1
+ import { colors } from '@dhis2/ui-constants'
2
+ import PropTypes from 'prop-types'
3
+ import React from 'react'
4
+
5
+ export const StackedTableCellHead = ({
6
+ children = '',
7
+ className,
8
+ colSpan,
9
+ dataTest = 'dhis2-uicore-stackedtablecellhead',
10
+ rowSpan,
11
+ }) => (
12
+ <th
13
+ colSpan={colSpan}
14
+ rowSpan={rowSpan}
15
+ className={className}
16
+ data-test={dataTest}
17
+ >
18
+ {children && <div>{children}</div>}
19
+
20
+ <style jsx>{`
21
+ th {
22
+ border-bottom: 1px solid ${colors.grey300};
23
+ padding: 0 12px;
24
+ }
25
+
26
+ div {
27
+ min-height: 36px;
28
+ }
29
+ `}</style>
30
+ </th>
31
+ )
32
+
33
+ StackedTableCellHead.propTypes = {
34
+ children: PropTypes.string,
35
+ className: PropTypes.string,
36
+ colSpan: PropTypes.string,
37
+ dataTest: PropTypes.string,
38
+ rowSpan: PropTypes.string,
39
+ }
@@ -0,0 +1,60 @@
1
+ import { colors } from '@dhis2/ui-constants'
2
+ import PropTypes from 'prop-types'
3
+ import React from 'react'
4
+ import { ContentWithTitle } from './content-with-title.js'
5
+
6
+ const defaultHeaderLabels = []
7
+ export const StackedTableCell = ({
8
+ children,
9
+ className,
10
+ colSpan,
11
+ column,
12
+ dataTest = 'dhis2-uicore-stackedtablecell',
13
+ headerLabels = defaultHeaderLabels,
14
+ hideTitle,
15
+ rowSpan,
16
+ title,
17
+ }) => {
18
+ const cellTitle = title || headerLabels[column] || ''
19
+ const realTitle = hideTitle ? '' : cellTitle
20
+
21
+ return (
22
+ <td
23
+ colSpan={colSpan}
24
+ rowSpan={rowSpan}
25
+ className={className}
26
+ data-test={dataTest}
27
+ >
28
+ <ContentWithTitle title={realTitle}>{children}</ContentWithTitle>
29
+
30
+ <style jsx>{`
31
+ td {
32
+ border-bottom: 1px solid ${colors.grey300};
33
+ padding: 0 12px;
34
+ font-size: 14px;
35
+ width: 100%;
36
+ display: block;
37
+ }
38
+ td:dir(rtl) {
39
+ text-align: right;
40
+ }
41
+
42
+ td:last-child {
43
+ border-bottom: 0;
44
+ }
45
+ `}</style>
46
+ </td>
47
+ )
48
+ }
49
+
50
+ StackedTableCell.propTypes = {
51
+ children: PropTypes.node,
52
+ className: PropTypes.string,
53
+ colSpan: PropTypes.string,
54
+ column: PropTypes.number,
55
+ dataTest: PropTypes.string,
56
+ headerLabels: PropTypes.arrayOf(PropTypes.string),
57
+ hideTitle: PropTypes.bool,
58
+ rowSpan: PropTypes.string,
59
+ title: PropTypes.string,
60
+ }
@@ -0,0 +1,24 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+
4
+ export const StackedTableFoot = ({
5
+ children,
6
+ className,
7
+ dataTest = 'dhis2-uicore-stackedtablefoot',
8
+ }) => (
9
+ <tfoot className={className} data-test={dataTest}>
10
+ {children}
11
+ <style jsx>{`
12
+ tfoot {
13
+ display: block;
14
+ margin-top: 32px;
15
+ }
16
+ `}</style>
17
+ </tfoot>
18
+ )
19
+
20
+ StackedTableFoot.propTypes = {
21
+ children: PropTypes.node,
22
+ className: PropTypes.string,
23
+ dataTest: PropTypes.string,
24
+ }
@@ -0,0 +1,23 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+
4
+ export const StackedTableHead = ({
5
+ children,
6
+ className,
7
+ dataTest = 'dhis2-uicore-stackedtablehead',
8
+ }) => (
9
+ <thead className={className} data-test={dataTest}>
10
+ {children}
11
+ <style jsx>{`
12
+ thead {
13
+ display: none;
14
+ }
15
+ `}</style>
16
+ </thead>
17
+ )
18
+
19
+ StackedTableHead.propTypes = {
20
+ children: PropTypes.node,
21
+ className: PropTypes.string,
22
+ dataTest: PropTypes.string,
23
+ }
@@ -0,0 +1,19 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+ import { StackedTableRow } from './stacked-table-row.js'
4
+
5
+ export const StackedTableRowHead = ({
6
+ children,
7
+ className,
8
+ dataTest = 'dhis2-uicore-stackedtablerowhead',
9
+ }) => (
10
+ <StackedTableRow className={className} dataTest={dataTest}>
11
+ {children}
12
+ </StackedTableRow>
13
+ )
14
+
15
+ StackedTableRowHead.propTypes = {
16
+ children: PropTypes.node,
17
+ className: PropTypes.string,
18
+ dataTest: PropTypes.string,
19
+ }
@@ -0,0 +1,50 @@
1
+ import { colors } from '@dhis2/ui-constants'
2
+ import PropTypes from 'prop-types'
3
+ import React from 'react'
4
+ import { addColNumToChildren } from './add-col-num-to-children.js'
5
+ import { supplyHeaderLabelsToChildren } from './supply-header-labels-to-children.js'
6
+ import { Consumer } from './table-context.js'
7
+
8
+ export const StackedTableRow = ({
9
+ children,
10
+ className,
11
+ dataTest = 'dhis2-uicore-stackedtablerow',
12
+ }) => (
13
+ <tr className={className} data-test={dataTest}>
14
+ <Consumer>
15
+ {({ headerLabels }) =>
16
+ supplyHeaderLabelsToChildren(
17
+ headerLabels,
18
+ addColNumToChildren(children)
19
+ )
20
+ }
21
+ </Consumer>
22
+
23
+ <style jsx>{`
24
+ tr {
25
+ min-height: 45px;
26
+ display: block;
27
+ border: 1px solid ${colors.grey300};
28
+ }
29
+
30
+ tr:nth-child(even) {
31
+ background: ${colors.white};
32
+ }
33
+
34
+ :global(thead) > tr,
35
+ :global(tbody) > tr {
36
+ min-height: 36px;
37
+ }
38
+
39
+ tr + tr {
40
+ margin-top: 32px;
41
+ }
42
+ `}</style>
43
+ </tr>
44
+ )
45
+
46
+ StackedTableRow.propTypes = {
47
+ children: PropTypes.node,
48
+ className: PropTypes.string,
49
+ dataTest: PropTypes.string,
50
+ }
@@ -0,0 +1,33 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+ import { extractHeaderLabels } from './extract-header-labels.js'
4
+ import { Provider } from './table-context.js'
5
+ import { Table } from './table.js'
6
+
7
+ export const StackedTable = ({
8
+ children,
9
+ className,
10
+ dataTest = 'dhis2-uicore-stackedtable',
11
+ headerLabels,
12
+ }) => {
13
+ const contextHeaderLabels = extractHeaderLabels(children)
14
+ const context = {
15
+ headerLabels: headerLabels || contextHeaderLabels,
16
+ }
17
+
18
+ return (
19
+ <Provider value={context}>
20
+ <Table className={className} dataTest={dataTest}>
21
+ {children}
22
+ </Table>
23
+ </Provider>
24
+ )
25
+ }
26
+
27
+ StackedTable.propTypes = {
28
+ children: PropTypes.node,
29
+ className: PropTypes.string,
30
+ dataTest: PropTypes.string,
31
+ /** Labels for columns. Use an empty string for a column without a header. */
32
+ headerLabels: PropTypes.arrayOf(PropTypes.string),
33
+ }