@bloom-housing/ui-components 4.2.2-alpha.1 → 4.2.2-alpha.12

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,43 +1,54 @@
1
1
  import * as React from "react"
2
- import { TableHeaders } from "./StandardTable"
2
+ import { StandardTableData, TableHeaders } from "./StandardTable"
3
3
  import { MinimalTable } from "./MinimalTable"
4
4
 
5
5
  export interface StackedTableRow {
6
+ /** The main text content of the cell */
6
7
  cellText: string
8
+ /** The subtext of the cell, displayed beneath the main text */
7
9
  cellSubText?: string
8
- hideMobile?: boolean
10
+ /** Hides this cell's subtext on mobile views */
11
+ hideSubTextMobile?: boolean
12
+ /** Text content that will replace this cell's header on mobile views */
13
+ mobileReplacement?: string
9
14
  }
10
15
 
11
16
  export interface StackedTableProps {
17
+ /** The headers for the table passed as text content with optional settings */
12
18
  headers: TableHeaders
19
+ /** Headers hidden on desktop views */
13
20
  headersHiddenDesktop?: string[]
21
+ /** The table data passed as records of column name to cell data */
14
22
  stackedData?: Record<string, StackedTableRow>[]
23
+ /** A class name applied to the root of the table */
15
24
  className?: string
16
25
  }
17
26
 
18
27
  const StackedTable = (props: StackedTableProps) => {
19
- const tableClasses = ["base", props.className]
20
- const modifiedData: Record<string, React.ReactNode>[] = []
21
- const cellTextClass = "font-semibold text-gray-750"
22
- const cellSubtextClass = "text-sm text-gray-700"
28
+ const tableClasses = ["base", "stacked-table", props.className]
29
+ const modifiedData: StandardTableData = []
30
+
23
31
  props.stackedData?.forEach((dataRow) => {
24
32
  const dataCell = Object.keys(dataRow).reduce((acc, item) => {
25
- acc[item] = (
26
- <div
27
- className={`md:flex md:flex-col w-1/2 md:w-full ${
28
- props.headersHiddenDesktop?.includes(item) && "md:hidden"
29
- }`}
30
- >
31
- <span className={`${cellTextClass}`}>{dataRow[item].cellText}</span>
32
- <span
33
- className={`pl-1 md:pl-0 ${
34
- dataRow[item].hideMobile && "hidden md:block"
35
- } ${cellSubtextClass}`}
33
+ acc[item] = {
34
+ content: (
35
+ <div
36
+ className={`stacked-table-cell-container ${
37
+ props.headersHiddenDesktop?.includes(item) && "md:hidden"
38
+ }`}
36
39
  >
37
- {dataRow[item].cellSubText}
38
- </span>
39
- </div>
40
- )
40
+ <span className={"stacked-table-cell"}>{dataRow[item].cellText}</span>
41
+ <span
42
+ className={`stacked-table-subtext ${
43
+ dataRow[item].hideSubTextMobile && "hidden md:block"
44
+ } `}
45
+ >
46
+ {dataRow[item].cellSubText}
47
+ </span>
48
+ </div>
49
+ ),
50
+ mobileReplacement: dataRow[item].cellText,
51
+ }
41
52
  return acc
42
53
  }, {})
43
54
  modifiedData.push(dataCell)
@@ -48,14 +59,15 @@ const StackedTable = (props: StackedTableProps) => {
48
59
  if (props.headersHiddenDesktop?.includes(headerKey)) {
49
60
  let headerClasses = "md:hidden"
50
61
  headerClasses = `${tempHeader["className"] && tempHeader["className"]} ${headerClasses}`
51
- tempHeader = { name: tempHeader["name"] ?? tempHeader, className: headerClasses }
62
+ tempHeader = {
63
+ name: tempHeader["name"] ?? tempHeader,
64
+ className: `stacked-table-header ${headerClasses}`,
65
+ }
52
66
  } else {
53
67
  acc[headerKey] = props.headers[headerKey]
54
68
  tempHeader = {
55
69
  name: tempHeader["name"] ?? tempHeader,
56
- className: `${
57
- tempHeader["className"] && tempHeader["className"]
58
- } px-0 text-base text-gray-700 border-b`,
70
+ className: `${tempHeader["className"] && tempHeader["className"]} stacked-table-header`,
59
71
  }
60
72
  }
61
73
  acc[headerKey] = tempHeader
@@ -68,7 +80,7 @@ const StackedTable = (props: StackedTableProps) => {
68
80
  data={modifiedData}
69
81
  className={tableClasses.join(" ")}
70
82
  responsiveCollapse={true}
71
- cellClassName={"py-3 px-0"}
83
+ cellClassName={"b-0"}
72
84
  />
73
85
  )
74
86
  }
@@ -7,6 +7,7 @@ import { t } from "../helpers/translator"
7
7
 
8
8
  export interface TableHeadersOptions {
9
9
  name: string
10
+ mobileReplacement?: string
10
11
  className?: string
11
12
  }
12
13
  export interface TableHeaders {
@@ -28,9 +29,11 @@ export const Cell = (props: {
28
29
  className?: string
29
30
  colSpan?: number
30
31
  children: React.ReactNode
32
+ mobileReplacement?: string | React.ReactNode
31
33
  }) => (
32
34
  <td
33
35
  data-label={props.headerLabel instanceof Object ? props.headerLabel?.name : props.headerLabel}
36
+ data-cell={props.mobileReplacement}
34
37
  className={props.className || "p-5"}
35
38
  colSpan={props.colSpan}
36
39
  >
@@ -42,20 +45,36 @@ export const TableThumbnail = (props: { children: React.ReactNode }) => {
42
45
  return <span className="table__thumbnail">{props.children}</span>
43
46
  }
44
47
 
48
+ export type StandardTableCell = {
49
+ /** The main content of the cell */
50
+ content: React.ReactNode
51
+ /** Text content that will replace this cell's header on mobile views */
52
+ mobileReplacement?: string
53
+ }
54
+
55
+ export type StandardTableData = Record<string, StandardTableCell>[]
56
+
45
57
  export interface StandardTableProps {
58
+ /** If the table should be sortable through dragging */
46
59
  draggable?: boolean
60
+ /** A set state function tied to the table's data, used if the table is draggable */
47
61
  setData?: (data: unknown[]) => void
62
+ /** The headers for the table passed as text content with optional settings */
48
63
  headers: TableHeaders
64
+ /** The table data passed as records of column name to cell data with optional settings */
49
65
  data?: StandardTableData
66
+ /** A class name applied to the root of the table */
50
67
  tableClassName?: string
68
+ /** A class name applied to each cell */
51
69
  cellClassName?: string
70
+ /** If the table should collapse on mobile views to show repeating columns on the left for every row */
52
71
  responsiveCollapse?: boolean
72
+ /** If cell text should be translated or left raw */
53
73
  translateData?: boolean
74
+ /** An id applied to the table */
54
75
  id?: string
55
76
  }
56
77
 
57
- export type StandardTableData = Record<string, React.ReactNode>[] | undefined
58
-
59
78
  const headerName = (header: string | TableHeadersOptions) => {
60
79
  if (typeof header === "string") {
61
80
  return header
@@ -99,16 +118,16 @@ export const StandardTable = (props: StandardTableProps) => {
99
118
  )
100
119
  }
101
120
 
102
- const body = tableData?.map((row: Record<string, React.ReactNode>, dataIndex) => {
121
+ const body = tableData?.map((row, dataIndex) => {
103
122
  const rowKey = row["id"]
104
- ? `row-${row["id"] as string}`
123
+ ? `row-${row["id"].content as string}`
105
124
  : process.env.NODE_ENV === "test"
106
125
  ? `standardrow-${dataIndex}`
107
126
  : nanoid()
108
127
 
109
128
  const cols = Object.keys(headers)?.map((colKey, colIndex) => {
110
129
  const uniqKey = process.env.NODE_ENV === "test" ? `standardcol-${colIndex}` : nanoid()
111
- const cell = row[colKey]
130
+ const cell = row[colKey]?.content
112
131
 
113
132
  const cellClass = [headerClassName(headers[colKey]), cellClassName].join(" ")
114
133
 
@@ -121,6 +140,7 @@ export const StandardTable = (props: StandardTableProps) => {
121
140
  : headers[colKey]
122
141
  }
123
142
  className={cellClass !== " " ? cellClass : undefined}
143
+ mobileReplacement={row[colKey]?.mobileReplacement}
124
144
  >
125
145
  {props.translateData && typeof cell === "string" && cell !== ""
126
146
  ? getTranslationWithArguments(cell)
@@ -176,11 +196,7 @@ export const StandardTable = (props: StandardTableProps) => {
176
196
  tableClasses.push(props.tableClassName)
177
197
  }
178
198
 
179
- const reorder = (
180
- list: Record<string, React.ReactNode>[] | undefined,
181
- startIndex: number,
182
- endIndex: number
183
- ) => {
199
+ const reorder = (list: StandardTableData | undefined, startIndex: number, endIndex: number) => {
184
200
  if (!list) return
185
201
 
186
202
  const result = Array.from(list)