playbook_ui 14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4380 → 14.6.2.pre.alpha.PBNTR666advancedtablefirstcolumn4406
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +8 -1
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +22 -28
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +37 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_custom_cell.jsx +13 -2
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +7 -8
- data/dist/chunks/_weekday_stacked-C5GUey9h.js +45 -0
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +3 -3
- data/dist/chunks/_weekday_stacked-DJWwxF-6.js +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dba166f4d1d79b3c8a653c6cbd2f651b2d45ff4433ddd0eeee0372e3f6b38eca
|
4
|
+
data.tar.gz: f5e0af7845810066fe7c8562b3ff17806aad72e02eaae9e5e2b22394f1cc54b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f82455bc51c6223115c2436793824a3c602ca7ec81b88c328a3e92f82992781b81cbeb81d53057a7af3588b814d4daa672e5c69f9a4a1861e7722dd051b676ab
|
7
|
+
data.tar.gz: 5c81b68981cdc6611fcb3e4c0ce8091ef4d2b627f5982e73a826f94e15e74d037b34812c7439dcd1769714b3b34f5bf10bfbfb4135e920dbefa34b3fcc0e70ec
|
@@ -16,6 +16,7 @@ interface CustomCellProps {
|
|
16
16
|
onRowToggleClick?: (arg: Row<GenericObject>) => void
|
17
17
|
row: Row<GenericObject>
|
18
18
|
value?: string
|
19
|
+
customRenderer?: (row: Row<GenericObject>, value: string | undefined) => React.ReactNode
|
19
20
|
}
|
20
21
|
|
21
22
|
export const CustomCell = ({
|
@@ -23,6 +24,7 @@ export const CustomCell = ({
|
|
23
24
|
onRowToggleClick,
|
24
25
|
row,
|
25
26
|
value,
|
27
|
+
customRenderer,
|
26
28
|
}: CustomCellProps & GlobalProps) => {
|
27
29
|
const { setExpanded, expanded, expandedControl, inlineRowLoading } = useContext(AdvancedTableContext);
|
28
30
|
|
@@ -61,7 +63,12 @@ export const CustomCell = ({
|
|
61
63
|
</button>
|
62
64
|
) : null}
|
63
65
|
<FlexItem paddingLeft={renderButton? "none" : "xs"}>
|
64
|
-
{row.depth === 0 ?
|
66
|
+
{row.depth === 0 ? (
|
67
|
+
customRenderer ? customRenderer(row, getValue()) : getValue()
|
68
|
+
) :(
|
69
|
+
customRenderer ? customRenderer(row, value) : value
|
70
|
+
)
|
71
|
+
}
|
65
72
|
</FlexItem>
|
66
73
|
</Flex>
|
67
74
|
</div>
|
@@ -90,8 +90,8 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
90
90
|
|
91
91
|
const columnHelper = createColumnHelper()
|
92
92
|
|
93
|
-
//Create cells for first
|
94
|
-
const createCellFunction = (cellAccessors: string[], customRenderer?: (row: Row<GenericObject>, value: any) => JSX.Element) => {
|
93
|
+
//Create cells for columns, with customization for first column
|
94
|
+
const createCellFunction = (cellAccessors: string[], customRenderer?: (row: Row<GenericObject>, value: any) => JSX.Element, index?: number) => {
|
95
95
|
const columnCells = ({
|
96
96
|
row,
|
97
97
|
getValue,
|
@@ -101,19 +101,16 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
101
101
|
}) => {
|
102
102
|
const rowData = row.original
|
103
103
|
|
104
|
-
|
105
|
-
if (customRenderer) {
|
106
|
-
return customRenderer(row, getValue())
|
107
|
-
}
|
108
|
-
|
104
|
+
if (index === 0) {
|
109
105
|
switch (row.depth) {
|
110
106
|
case 0: {
|
111
107
|
return (
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
108
|
+
<CustomCell
|
109
|
+
customRenderer={customRenderer}
|
110
|
+
getValue={getValue}
|
111
|
+
onRowToggleClick={onRowToggleClick}
|
112
|
+
row={row}
|
113
|
+
/>
|
117
114
|
)
|
118
115
|
}
|
119
116
|
default: {
|
@@ -122,6 +119,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
122
119
|
const accessorValue = rowData[depthAccessor]
|
123
120
|
return accessorValue ? (
|
124
121
|
<CustomCell
|
122
|
+
customRenderer={customRenderer}
|
125
123
|
onRowToggleClick={onRowToggleClick}
|
126
124
|
row={row}
|
127
125
|
value={accessorValue}
|
@@ -132,11 +130,14 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
132
130
|
}
|
133
131
|
}
|
134
132
|
}
|
135
|
-
|
133
|
+
return customRenderer
|
134
|
+
? customRenderer(row, getValue())
|
135
|
+
: getValue()
|
136
|
+
}
|
136
137
|
return columnCells
|
137
138
|
}
|
138
|
-
|
139
|
-
|
139
|
+
|
140
|
+
// //Create column array in format needed by Tanstack
|
140
141
|
const columns =
|
141
142
|
columnDefinitions &&
|
142
143
|
columnDefinitions.map((column, index) => {
|
@@ -147,19 +148,12 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
147
148
|
}),
|
148
149
|
}
|
149
150
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
)
|
157
|
-
}
|
158
|
-
} else {
|
159
|
-
// For the first column, apply createCellFunction without customRenderer
|
160
|
-
if (column.cellAccessors) {
|
161
|
-
columnStructure.cell = createCellFunction(column.cellAccessors)
|
162
|
-
}
|
151
|
+
if (column.cellAccessors || column.customRenderer) {
|
152
|
+
columnStructure.cell = createCellFunction(
|
153
|
+
column.cellAccessors,
|
154
|
+
column.customRenderer,
|
155
|
+
index
|
156
|
+
)
|
163
157
|
}
|
164
158
|
|
165
159
|
return columnStructure
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React, {useState} from "react"
|
2
2
|
import { render, screen, waitFor } from "../utilities/test-utils"
|
3
3
|
|
4
|
-
import { AdvancedTable } from "playbook-ui"
|
4
|
+
import { AdvancedTable, Pill } from "playbook-ui"
|
5
5
|
|
6
6
|
const MOCK_DATA = [
|
7
7
|
{
|
@@ -88,6 +88,28 @@ const columnDefinitions = [
|
|
88
88
|
},
|
89
89
|
]
|
90
90
|
|
91
|
+
const columnDefinitionsCustomRenderer = [
|
92
|
+
{
|
93
|
+
accessor: "year",
|
94
|
+
label: "Year",
|
95
|
+
cellAccessors: ["quarter", "month", "day"],
|
96
|
+
},
|
97
|
+
{
|
98
|
+
accessor: "newEnrollments",
|
99
|
+
label: "New Enrollments",
|
100
|
+
customRenderer: (row, value) => (
|
101
|
+
<Pill text={value}
|
102
|
+
variant="success"
|
103
|
+
/>
|
104
|
+
),
|
105
|
+
},
|
106
|
+
{
|
107
|
+
accessor: "scheduledMeetings",
|
108
|
+
label: "Scheduled Meetings",
|
109
|
+
},
|
110
|
+
]
|
111
|
+
|
112
|
+
|
91
113
|
const subRowHeaders = ["Quarter"]
|
92
114
|
|
93
115
|
const testId = "advanced_table"
|
@@ -463,3 +485,17 @@ test("responsive none prop functions as expected", () => {
|
|
463
485
|
const kit = screen.getByTestId(testId)
|
464
486
|
expect(kit).toHaveClass("pb_advanced_table table-responsive-none")
|
465
487
|
})
|
488
|
+
|
489
|
+
test("customRenderer prop functions as expected", () => {
|
490
|
+
render(
|
491
|
+
<AdvancedTable
|
492
|
+
columnDefinitions={columnDefinitionsCustomRenderer}
|
493
|
+
data={{ testid: testId }}
|
494
|
+
tableData={MOCK_DATA}
|
495
|
+
/>
|
496
|
+
)
|
497
|
+
|
498
|
+
const kit = screen.getByTestId(testId)
|
499
|
+
const pill = kit.querySelector(".pb_pill_kit_success_lowercase")
|
500
|
+
expect(pill).toBeInTheDocument()
|
501
|
+
})
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from "react"
|
2
|
-
import { AdvancedTable, Pill, Body, Flex, Detail, Caption } from "playbook-ui"
|
2
|
+
import { AdvancedTable, Pill, Body, Flex, Detail, Caption, Badge, Title } from "playbook-ui"
|
3
3
|
import MOCK_DATA from "./advanced_table_mock_data.json"
|
4
4
|
|
5
5
|
const AdvancedTableCustomCell = (props) => {
|
@@ -8,7 +8,18 @@ const AdvancedTableCustomCell = (props) => {
|
|
8
8
|
accessor: "year",
|
9
9
|
label: "Year",
|
10
10
|
cellAccessors: ["quarter", "month", "day"],
|
11
|
-
|
11
|
+
customRenderer: (row, value) => (
|
12
|
+
<Flex>
|
13
|
+
<Title size={4}
|
14
|
+
text={value}
|
15
|
+
/>
|
16
|
+
<Badge
|
17
|
+
marginLeft="sm"
|
18
|
+
text={row.original.newEnrollments > 20 ? "High" : "Low"}
|
19
|
+
variant="neutral"
|
20
|
+
/>
|
21
|
+
</Flex>
|
22
|
+
),
|
12
23
|
},
|
13
24
|
{
|
14
25
|
accessor: "newEnrollments",
|
@@ -47,7 +47,7 @@ interface DropdownComponent
|
|
47
47
|
Container: typeof DropdownContainer;
|
48
48
|
}
|
49
49
|
|
50
|
-
|
50
|
+
const Dropdown = forwardRef((props: DropdownProps, ref: any) => {
|
51
51
|
const {
|
52
52
|
aria = {},
|
53
53
|
autocomplete = false,
|
@@ -260,7 +260,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
260
260
|
<DropdownContainer>
|
261
261
|
{optionsWithBlankSelection &&
|
262
262
|
optionsWithBlankSelection?.map((option: GenericObject) => (
|
263
|
-
<
|
263
|
+
<Dropdown.Option key={option.id}
|
264
264
|
option={option}
|
265
265
|
/>
|
266
266
|
))}
|
@@ -278,12 +278,11 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
278
278
|
</DropdownContext.Provider>
|
279
279
|
</div>
|
280
280
|
)
|
281
|
-
}
|
281
|
+
}) as DropdownComponent
|
282
282
|
|
283
|
-
Dropdown =
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
(Dropdown as DropdownComponent).Container = DropdownContainer;
|
283
|
+
Dropdown.displayName = "Dropdown";
|
284
|
+
Dropdown.Option = DropdownOption;
|
285
|
+
Dropdown.Trigger = DropdownTrigger;
|
286
|
+
Dropdown.Container = DropdownContainer;
|
288
287
|
|
289
288
|
export default Dropdown;
|