@cdc/core 4.25.1 → 4.25.2-25

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.
@@ -1,13 +1,13 @@
1
1
  import { ReactNode } from 'react'
2
2
  import Row from './components/Row'
3
3
  import GroupRow from './components/GroupRow'
4
- import { CellMatrix, GroupCellMatrix } from './types/CellMatrix'
4
+ import { CellMatrix } from './types/CellMatrix'
5
5
  import { RowType } from './types/RowType'
6
6
  import { PreliminaryDataItem } from '@cdc/chart/src/types/ChartConfig'
7
7
  import _ from 'lodash'
8
8
 
9
9
  type TableProps = {
10
- childrenMatrix: CellMatrix | GroupCellMatrix
10
+ childrenMatrix: CellMatrix | Map<string, CellMatrix>
11
11
  noData?: boolean
12
12
  tableName: string
13
13
  caption: string
@@ -24,6 +24,7 @@ type TableProps = {
24
24
  hasRowType?: boolean // if it has row type then the first column is the row type which will explain how to render the row
25
25
  viewport: 'lg' | 'md' | 'sm' | 'xs' | 'xxs'
26
26
  preliminaryData?: PreliminaryDataItem[]
27
+ rightAlignedCols: object
27
28
  }
28
29
 
29
30
  type Position = 'sticky'
@@ -39,7 +40,8 @@ const Table = ({
39
40
  wrapColumns,
40
41
  hasRowType,
41
42
  viewport,
42
- preliminaryData
43
+ preliminaryData,
44
+ rightAlignedCols
43
45
  }: TableProps) => {
44
46
  const headStyle = stickyHeader ? { position: 'sticky' as Position, top: 0, zIndex: 2 } : {}
45
47
  const isGroupedMatrix = !Array.isArray(childrenMatrix)
@@ -56,9 +58,9 @@ const Table = ({
56
58
  <thead style={headStyle}>{headContent}</thead>
57
59
  <tbody>
58
60
  {isGroupedMatrix
59
- ? Object.keys(childrenMatrix).flatMap(groupName => {
61
+ ? Array.from(childrenMatrix.keys()).flatMap(groupName => {
60
62
  let colSpan = 0
61
- const rows = childrenMatrix[groupName].map((row, i) => {
63
+ const rows = childrenMatrix.get(groupName).map((row, i) => {
62
64
  colSpan = row.length
63
65
  const key = `${tableName}-${groupName}-row-${i}`
64
66
  return (
@@ -70,6 +72,7 @@ const Table = ({
70
72
  wrapColumns={wrapColumns}
71
73
  cellMinWidth={tableOptions.cellMinWidth}
72
74
  viewport={viewport}
75
+ rightAlignedCols={rightAlignedCols}
73
76
  />
74
77
  )
75
78
  })
@@ -90,6 +93,7 @@ const Table = ({
90
93
  wrapColumns={wrapColumns}
91
94
  cellMinWidth={tableOptions.cellMinWidth}
92
95
  viewport={viewport}
96
+ rightAlignedCols={rightAlignedCols}
93
97
  />
94
98
  )
95
99
  } else {
@@ -107,6 +111,7 @@ const Table = ({
107
111
  wrapColumns={wrapColumns}
108
112
  cellMinWidth={tableOptions.cellMinWidth}
109
113
  viewport={viewport}
114
+ rightAlignedCols={rightAlignedCols}
110
115
  />
111
116
  )
112
117
  case RowType.row_group_total:
@@ -121,6 +126,7 @@ const Table = ({
121
126
  wrapColumns={wrapColumns}
122
127
  cellMinWidth={tableOptions.cellMinWidth}
123
128
  viewport={viewport}
129
+ rightAlignedCols={rightAlignedCols}
124
130
  />
125
131
  )
126
132
  }
@@ -11,10 +11,20 @@ type RowProps = {
11
11
  viewport: 'lg' | 'md' | 'sm' | 'xs' | 'xxs'
12
12
  style?: object
13
13
  preliminaryData?: PreliminaryDataItem[]
14
+ rightAlignedCols: object
14
15
  }
15
16
 
16
17
  const Row: FC<RowProps> = props => {
17
- const { childRow, rowKey, wrapColumns, cellMinWidth = 0, isTotal, viewport, preliminaryData } = props
18
+ const {
19
+ childRow,
20
+ rowKey,
21
+ wrapColumns,
22
+ cellMinWidth = 0,
23
+ isTotal,
24
+ viewport,
25
+ preliminaryData,
26
+ rightAlignedCols
27
+ } = props
18
28
  const whiteSpace = wrapColumns ? 'unset' : 'nowrap'
19
29
  const minWidth = cellMinWidth + 'px'
20
30
 
@@ -27,11 +37,13 @@ const Row: FC<RowProps> = props => {
27
37
  ) && { color: '#777772' }) ||
28
38
  {}
29
39
 
40
+ const textAlign = rightAlignedCols && rightAlignedCols[i] ? 'right' : ''
41
+
30
42
  return (
31
43
  <Cell
32
44
  ariaLabel={style?.color ? 'suppressed data' : ''}
33
45
  key={rowKey + '__' + i}
34
- style={{ whiteSpace, minWidth, ...style }}
46
+ style={{ whiteSpace, minWidth, textAlign, ...style }}
35
47
  isBold={isTotal}
36
48
  >
37
49
  {child}