playbook_ui 13.17.0 → 13.18.0.pre.alpha.PBNTR191AdvancedTableFinalFixes2173

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_reset.scss +2 -2
  3. data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +5 -4
  4. data/app/pb_kits/playbook/pb_advanced_table/Components/SubRowHeaderRow.tsx +9 -4
  5. data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +18 -13
  6. data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableBody.tsx +27 -4
  7. data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +18 -4
  8. data/app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx +3 -4
  9. data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +18 -7
  10. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +328 -3
  11. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail.jsx +52 -0
  12. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail.md +1 -0
  13. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +7 -2
  14. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_expanded_control.jsx +59 -0
  15. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_expanded_control.md +18 -0
  16. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_loading.jsx +60 -0
  17. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_loading.md +3 -0
  18. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort.jsx +1 -6
  19. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort.md +5 -0
  20. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_control.jsx +63 -0
  21. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_control.md +3 -0
  22. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_subrow_headers.jsx +57 -0
  23. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_subrow_headers.md +3 -0
  24. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_options.jsx +61 -0
  25. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_options.md +3 -0
  26. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.jsx +55 -0
  27. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.md +1 -0
  28. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +10 -4
  29. data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +7 -0
  30. data/app/pb_kits/playbook/pb_advanced_table/scss_partials/_loading.scss +4 -3
  31. data/app/pb_kits/playbook/pb_collapsible/_collapsible.scss +2 -2
  32. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_flatpickr_styles.scss +1 -1
  33. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.html.erb +5 -7
  34. data/app/pb_kits/playbook/pb_popover/_popover.tsx +12 -14
  35. data/app/pb_kits/playbook/pb_popover/docs/_popover_actionable_content.html.erb +30 -0
  36. data/app/pb_kits/playbook/pb_popover/docs/_popover_actionable_content.jsx +57 -0
  37. data/app/pb_kits/playbook/pb_popover/docs/example.yml +2 -1
  38. data/app/pb_kits/playbook/pb_popover/docs/index.js +1 -0
  39. data/app/pb_kits/playbook/pb_popover/popover.test.js +29 -31
  40. data/app/pb_kits/playbook/pb_table/_table.tsx +3 -0
  41. data/app/pb_kits/playbook/pb_table/docs/_table_striped.html.erb +48 -0
  42. data/app/pb_kits/playbook/pb_table/docs/_table_striped.jsx +58 -0
  43. data/app/pb_kits/playbook/pb_table/docs/_table_striped.md +1 -0
  44. data/app/pb_kits/playbook/pb_table/docs/example.yml +2 -0
  45. data/app/pb_kits/playbook/pb_table/docs/index.js +1 -0
  46. data/app/pb_kits/playbook/pb_table/styles/_all.scss +1 -0
  47. data/app/pb_kits/playbook/pb_table/styles/_striped.scss +19 -0
  48. data/app/pb_kits/playbook/pb_table/table.rb +7 -1
  49. data/app/pb_kits/playbook/pb_table/table.test.js +5 -0
  50. data/dist/menu.yml +102 -3
  51. data/dist/playbook-rails.js +7 -7
  52. data/dist/reset.css +1 -2
  53. data/lib/playbook/version.rb +2 -2
  54. metadata +28 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c288d80cbfc92741e976eda7ca6fd7e4ecbf256b5f5ad9e4e8a23f2b4ddb6ae
4
- data.tar.gz: 675612e33fd9e560aa274763e5de44bfea34fd1af570d03b951a803994fbd4dd
3
+ metadata.gz: c50bdb2d776257482837525dcef9ac706994226966a7acc3041b81f5f9cf89e6
4
+ data.tar.gz: c467ed886607d31ee16abca2bdec30da5880ad8ff58798d74232f7852d6165db
5
5
  SHA512:
6
- metadata.gz: 3d14807433425abbbd0fdf53733c4e2addc7ebb6506d35a89ea7b06f06746c39e815d7e3100a57e54cf4fea14cfb8779693b0140da9d4b4f31eb5867a752b467
7
- data.tar.gz: 916468edea21563fb47710ec9a691e16a0ba1852fc4b4f97637884d560a5ae0b7b55a6a434bfd73fec6d756e68b5af89a5b4b49f2b97f4f19d3b38fa4463df0e
6
+ metadata.gz: cd6efe9805a59dfd26fa143d566f107e6ab5f0435920a6ca5d7985aee7b2859b297734c319a13b1f76ba04732ca8292a24b40811b742bbd9703ae662f48217b4
7
+ data.tar.gz: c60068a9dcb1beebd857868a1fcbf795f9d59697ebce2de88da31fe9a7d50c7e22fd17563417676d0a806ab9e30417223095b9012a8d42e1a594673450e2c41f
@@ -1,5 +1,5 @@
1
- @import "./tokens/typography";
2
- @import "./tokens/colors";
1
+ @import "tokens/typography";
2
+ @import "tokens/colors";
3
3
 
4
4
  * {
5
5
  box-sizing: border-box;
@@ -22,13 +22,14 @@ export const CustomCell = ({
22
22
  row,
23
23
  value,
24
24
  }: CustomCellProps & GlobalProps) => {
25
- const { setExpanded, expanded } = useContext(AdvancedTableContext);
26
- const RowWithoutChildren = row.originalSubRows === undefined;
25
+ const { setExpanded, expanded, inlineRowLoading } = useContext(AdvancedTableContext);
27
26
 
28
27
  const handleOnExpand = (row: Row<DataType>) => {
29
28
  onRowToggleClick && onRowToggleClick(row);
30
29
  setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() });
31
30
  };
31
+ const RowHasChildren = row.original.children ? true : false
32
+ const renderButton = inlineRowLoading ? RowHasChildren : row.getCanExpand()
32
33
 
33
34
  return (
34
35
  <div style={{ paddingLeft: `${row.depth * 1.25}em` }}>
@@ -36,7 +37,7 @@ export const CustomCell = ({
36
37
  columnGap="xs"
37
38
  orientation="row"
38
39
  >
39
- {!RowWithoutChildren ? (
40
+ {renderButton ? (
40
41
  <button
41
42
  className="gray-icon expand-toggle-icon"
42
43
  onClick={() => handleOnExpand(row)}
@@ -53,7 +54,7 @@ export const CustomCell = ({
53
54
  )}
54
55
  </button>
55
56
  ) : null}
56
- <FlexItem paddingLeft={!RowWithoutChildren ? "none" : "xs"}>
57
+ <FlexItem paddingLeft={renderButton? "none" : "xs"}>
57
58
  {row.depth === 0 ? getValue() : value}
58
59
  </FlexItem>
59
60
  </Flex>
@@ -1,8 +1,9 @@
1
- import React from "react"
1
+ import React, { useContext } from "react"
2
2
  import Flex from "../../pb_flex/_flex"
3
3
  import Caption from "../../pb_caption/_caption"
4
4
  import { Row, Table } from "@tanstack/react-table"
5
5
 
6
+ import AdvancedTableContext from "../Context/AdvancedTableContext";
6
7
  import { ToggleIconButton } from "./ToggleIconButton"
7
8
  import { renderCollapsibleTrail } from "./CollapsibleTrail"
8
9
 
@@ -12,7 +13,7 @@ import { GlobalProps } from "../../utilities/globalProps"
12
13
 
13
14
  interface SubRowHeaderRowProps {
14
15
  collapsibleTrail?: boolean
15
- enableToggleExpansion?: "all" | "header"
16
+ enableToggleExpansion?: "all" | "header" | "none"
16
17
  onClick: (row: Row<DataType>) => void
17
18
  row: Row<DataType>
18
19
  subRowHeaders?: string[]
@@ -27,7 +28,11 @@ export const SubRowHeaderRow = ({
27
28
  subRowHeaders,
28
29
  table,
29
30
  }: SubRowHeaderRowProps & GlobalProps) => {
31
+ const { inlineRowLoading } = useContext(AdvancedTableContext);
32
+
30
33
  const numberOfColumns = table.getAllFlatColumns().length
34
+ const rowHasChildren = row.original.children ? true : false
35
+ const canExpand = inlineRowLoading ? rowHasChildren : row.getCanExpand()
31
36
 
32
37
  return (
33
38
  <tr className="custom-row bg-silver">
@@ -42,13 +47,13 @@ export const SubRowHeaderRow = ({
42
47
  <Flex align="center"
43
48
  columnGap="xs"
44
49
  >
45
- {enableToggleExpansion === "all" && row.getCanExpand() ? (
50
+ {enableToggleExpansion === "all" && canExpand ? (
46
51
  <ToggleIconButton onClick={onClick}
47
52
  row={row}
48
53
  />
49
54
  ) : null}
50
55
  <Caption
51
- marginLeft={row.getCanExpand() ? "none" : "xs"}
56
+ marginLeft={canExpand ? "none" : "xs"}
52
57
  text={subRowHeaders[row.depth - 1]}
53
58
  />
54
59
  </Flex>
@@ -12,11 +12,10 @@ import { GlobalProps } from "../../utilities/globalProps"
12
12
 
13
13
  type TableHeaderCellProps = {
14
14
  enableSorting?: boolean
15
- enableToggleExpansion?: "all" | "header"
15
+ enableToggleExpansion?: "all" | "header" | "none"
16
16
  handleExpandOrCollapse?: () => void
17
17
  header?: Header<DataType, unknown>
18
18
  headerChildren?: React.ReactNode | React.ReactNode[]
19
- headerId?: string
20
19
  loading?: boolean
21
20
  sortIcon?: string | string[]
22
21
  } & GlobalProps
@@ -27,7 +26,6 @@ export const TableHeaderCell = ({
27
26
  handleExpandOrCollapse,
28
27
  header,
29
28
  headerChildren,
30
- headerId,
31
29
  loading,
32
30
  sortIcon,
33
31
  }: TableHeaderCellProps) => {
@@ -50,10 +48,22 @@ const cellClassName = classnames("table-header-cells",
50
48
  );
51
49
 
52
50
  const cellId = `${loading ?
53
- `loading-${header.id}${headerId ? `-${headerId}` : ""}`
54
- : `${header.id}${headerId ? `-${headerId}` : ""}`
51
+ `loading-${header.id}`
52
+ : `${header.id}`
55
53
  }`;
56
54
 
55
+ const isToggleExpansionEnabledLoading =
56
+ header.index === 0 &&
57
+ loading &&
58
+ (enableToggleExpansion === "all" || "header") &&
59
+ enableToggleExpansion !== "none";
60
+
61
+ const isToggleExpansionEnabled =
62
+ header.index === 0 &&
63
+ !loading &&
64
+ (enableToggleExpansion === "all" || "header") &&
65
+ enableToggleExpansion !== "none";
66
+
57
67
  return (
58
68
  <th
59
69
  align="right"
@@ -72,17 +82,12 @@ const cellId = `${loading ?
72
82
  <Flex
73
83
  alignItems="center"
74
84
  justify={header.index === 0 && enableSorting ? "between" : header.index === 0 && !enableSorting ? "start" : "end"}
75
- paddingLeft={loading ? "sm" : "none"}
76
85
  >
77
- {header.index === 0 &&
78
- !loading &&
79
- (enableToggleExpansion === "all" || "header") && (
86
+ {isToggleExpansionEnabled && (
80
87
  <ToggleIconButton onClick={handleExpandOrCollapse} />
81
88
  )}
82
89
 
83
- {header.index === 0 &&
84
- loading &&
85
- (enableToggleExpansion === "all" || "header") && (
90
+ {isToggleExpansionEnabledLoading &&(
86
91
  <div className="loading-toggle-icon header-toggle-icon" />
87
92
  )}
88
93
 
@@ -114,7 +119,7 @@ const cellId = `${loading ?
114
119
  header.column.getCanSort() &&
115
120
  enableSorting &&
116
121
  (loading ? (
117
- <div className="loading-toggle-icon header-sort-icon" />
122
+ <div className="loading-toggle-icon" />
118
123
  ) : (
119
124
  <SortIconButton header={header}
120
125
  sortIcon={sortIcon}
@@ -1,4 +1,7 @@
1
1
  import React, { useContext } from "react"
2
+ import classnames from "classnames";
3
+ import { buildCss } from "../../utilities/props";
4
+ import { globalProps } from "../../utilities/globalProps";
2
5
  import LoadingInline from "../../pb_loading_inline/_loading_inline"
3
6
  import { flexRender, Row } from "@tanstack/react-table"
4
7
 
@@ -10,28 +13,46 @@ import { isChrome } from "../Utilities/BrowserCheck"
10
13
  import { DataType } from "../Utilities/types"
11
14
 
12
15
  type TableBodyProps = {
16
+ className?: string;
13
17
  collapsibleTrail?: boolean
18
+ id?: string;
14
19
  subRowHeaders?: string[]
15
20
  }
16
21
 
17
22
  export const TableBody = ({
23
+ className,
18
24
  collapsibleTrail = true,
25
+ id,
19
26
  subRowHeaders,
27
+ ...props
20
28
  }: TableBodyProps) => {
29
+
21
30
  const {
31
+ columnDefinitions,
22
32
  enableToggleExpansion,
23
33
  handleExpandOrCollapse,
34
+ inlineRowLoading,
24
35
  loading,
25
36
  table,
26
37
  } = useContext(AdvancedTableContext)
38
+
39
+ const classes = classnames(
40
+ buildCss("pb_advanced_table_body"),
41
+ globalProps(props),
42
+ className
43
+ );
44
+
27
45
  return (
28
46
  <>
29
- <tbody>
47
+ <tbody className={classes}
48
+ id={id}
49
+ >
30
50
  {table.getRowModel().rows.map((row: Row<DataType>) => {
31
51
  const isExpandable = row.getIsExpanded()
32
52
  const isFirstChildofSubrow = row.depth > 0 && row.index === 0
33
- const rowHasNoChildren = !row.original.children?.length
53
+ const rowHasNoChildren = row.original.children && !row.original.children.length ? true : false
34
54
  const numberOfColumns = table.getAllFlatColumns().length
55
+ const isDataLoading = isExpandable && (inlineRowLoading && rowHasNoChildren) && (row.depth < columnDefinitions[0].cellAccessors?.length)
35
56
 
36
57
  return (
37
58
  <React.Fragment key={`${row.index}-${row.id}-${row.depth}-row`}>
@@ -79,9 +100,11 @@ export const TableBody = ({
79
100
  </tr>
80
101
 
81
102
  {/* Display LoadingInline if Row Data is querying and there are no children already */}
82
- {isExpandable && rowHasNoChildren && row.depth === 0 ? (
103
+ {isDataLoading ? (
83
104
  <tr key={`${row.id}-row`}>
84
- <td colSpan={numberOfColumns}>
105
+ <td colSpan={numberOfColumns}
106
+ style={{ paddingLeft: `${row.depth === 0 ? 0.5 : (row.depth * 2)}em` }}
107
+ >
85
108
  <LoadingInline />
86
109
  </td>
87
110
  </tr>
@@ -1,4 +1,7 @@
1
1
  import React, { useContext } from "react"
2
+ import classnames from "classnames";
3
+ import { buildCss } from "../../utilities/props";
4
+ import { globalProps } from "../../utilities/globalProps";
2
5
  import { HeaderGroup } from "@tanstack/react-table"
3
6
  import AdvancedTableContext from "../Context/AdvancedTableContext"
4
7
  import { TableHeaderCell } from "../Components/TableHeaderCell"
@@ -6,16 +9,19 @@ import { DataType } from "../Utilities/types"
6
9
 
7
10
  type TableHeaderProps = {
8
11
  children?: React.ReactNode | React.ReactNode[]
12
+ className?: string
9
13
  enableSorting?: boolean
10
- headerId?: string
14
+ id?: string;
11
15
  sortIcon?: string | string[]
12
16
  }
13
17
 
14
18
  export const TableHeader = ({
15
19
  children,
20
+ className,
16
21
  enableSorting = false,
17
- headerId,
22
+ id,
18
23
  sortIcon = ["arrow-up-short-wide", "arrow-down-short-wide"],
24
+ ...props
19
25
  }: TableHeaderProps) => {
20
26
  const {
21
27
  enableToggleExpansion,
@@ -24,9 +30,18 @@ export const TableHeader = ({
24
30
  table,
25
31
  } = useContext(AdvancedTableContext)
26
32
 
33
+ const classes = classnames(
34
+ buildCss("pb_advanced_table_header"),
35
+ globalProps(props),
36
+ className
37
+ );
38
+
39
+
27
40
  return (
28
41
  <>
29
- <thead>
42
+ <thead className={classes}
43
+ id={id}
44
+ >
30
45
  {/* Get the header groups (only one in this example) */}
31
46
  {table.getHeaderGroups().map((headerGroup: HeaderGroup<DataType>) => (
32
47
  <tr key={`${headerGroup.id}-headerGroup`}>
@@ -37,7 +52,6 @@ export const TableHeader = ({
37
52
  handleExpandOrCollapse={handleExpandOrCollapse}
38
53
  header={header}
39
54
  headerChildren={children}
40
- headerId={headerId}
41
55
  key={`${header.id}-header`}
42
56
  loading={loading}
43
57
  sortIcon={sortIcon}
@@ -24,10 +24,9 @@ export const updateExpandAndCollapseState = (
24
24
  // Update isExpansionConsistent variable
25
25
  for (const row of rows) {
26
26
  if (
27
- row.getCanExpand() &&
28
- (targetParent === undefined
27
+ targetParent === undefined
29
28
  ? row.depth === 0
30
- : targetParent === row.parentId)
29
+ : targetParent === row.parentId
31
30
  ) {
32
31
  areRowsExpanded.add(row.getIsExpanded())
33
32
  if (areRowsExpanded.size > 1) {
@@ -48,7 +47,7 @@ export const updateExpandAndCollapseState = (
48
47
  })
49
48
  } else {
50
49
  for (const row of rows) {
51
- if (row.getCanExpand() && targetParent === row.parentId) {
50
+ if (targetParent === row.parentId) {
52
51
  updateExpandedRows[row.id] = !isExpansionConsistent
53
52
  ? true
54
53
  : !row.getIsExpanded()
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useEffect, useCallback } from "react";
2
2
  import classnames from "classnames";
3
- import { buildAriaProps, buildCss, buildDataProps } from "../utilities/props";
3
+ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props";
4
4
  import { globalProps, GlobalProps } from "../utilities/globalProps";
5
5
  import Table from "../pb_table/_table";
6
6
  import {
@@ -28,10 +28,12 @@ type AdvancedTableProps = {
28
28
  className?: string;
29
29
  columnDefinitions: DataType[];
30
30
  data?: { [key: string]: string };
31
- enableToggleExpansion?: "all" | "header";
31
+ enableToggleExpansion?: "all" | "header" | "none";
32
32
  expandedControl?: DataType;
33
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
33
34
  id?: string;
34
35
  initialLoadingRowsCount?: number;
36
+ inlineRowLoading?: boolean;
35
37
  loading?: boolean | string;
36
38
  onRowToggleClick?: (arg: Row<DataType>) => void;
37
39
  onToggleExpansionClick?: (arg: Row<DataType>) => void;
@@ -51,8 +53,10 @@ const AdvancedTable = (props: AdvancedTableProps) => {
51
53
  data = {},
52
54
  enableToggleExpansion = "header",
53
55
  expandedControl,
56
+ htmlOptions = {},
54
57
  id,
55
58
  initialLoadingRowsCount = 10,
59
+ inlineRowLoading = false,
56
60
  loading,
57
61
  onRowToggleClick,
58
62
  onToggleExpansionClick,
@@ -104,7 +108,9 @@ const AdvancedTable = (props: AdvancedTableProps) => {
104
108
  const depthAccessor = cellAccessors[row.depth - 1]; // Adjust index for depth
105
109
  const accessorValue = rowData[depthAccessor];
106
110
  return accessorValue ? (
107
- <CustomCell row={row}
111
+ <CustomCell
112
+ onRowToggleClick={onRowToggleClick}
113
+ row={row}
108
114
  value={accessorValue}
109
115
  />
110
116
  ) : (
@@ -162,6 +168,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
162
168
  getExpandedRowModel: getExpandedRowModel(),
163
169
  getSortedRowModel: getSortedRowModel(),
164
170
  enableSortingRemoval: false,
171
+ sortDescFirst: true,
165
172
  ...expandAndSortState(),
166
173
  ...tableOptions,
167
174
  });
@@ -194,6 +201,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
194
201
 
195
202
  const ariaProps = buildAriaProps(aria);
196
203
  const dataProps = buildDataProps(data);
204
+ const htmlProps = buildHtmlProps(htmlOptions);
197
205
  const classes = classnames(
198
206
  buildCss("pb_advanced_table"),
199
207
  globalProps(props),
@@ -203,19 +211,22 @@ const AdvancedTable = (props: AdvancedTableProps) => {
203
211
  return (
204
212
  <div {...ariaProps}
205
213
  {...dataProps}
214
+ {...htmlProps}
206
215
  className={classes}
207
216
  id={id}
208
217
  >
209
218
  <AdvancedTableContext.Provider
210
219
  value={{
211
- table,
220
+ columnDefinitions,
221
+ enableToggleExpansion,
222
+ expanded,
212
223
  handleExpandOrCollapse,
224
+ inlineRowLoading,
213
225
  loading,
214
- enableToggleExpansion,
215
- toggleExpansionIcon,
216
226
  setExpanded,
217
- expanded,
218
227
  sortControl,
228
+ table,
229
+ toggleExpansionIcon,
219
230
  }}
220
231
  >
221
232
  <Table