playbook_ui 14.5.0.pre.alpha.PBNTR600reactfilterdisplayzeroresults4068 → 14.5.0.pre.alpha.PBNTR614advancedtablepoc4155

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +26 -7
  3. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_custom_cell.jsx +52 -0
  4. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -0
  5. data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +1 -0
  6. data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +20 -4
  7. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.jsx +45 -0
  8. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.md +1 -0
  9. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +1 -0
  10. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +1 -0
  11. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +1 -1
  12. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +2 -2
  13. data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +17 -0
  14. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_reset.html.erb +93 -0
  15. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_reset.md +1 -0
  16. data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +1 -0
  17. data/app/pb_kits/playbook/pb_multiple_users_stacked/_multiple_users_stacked.scss +169 -65
  18. data/app/pb_kits/playbook/pb_multiple_users_stacked/_multiple_users_stacked.test.js +5 -5
  19. data/app/pb_kits/playbook/pb_multiple_users_stacked/_multiple_users_stacked.tsx +15 -9
  20. data/app/pb_kits/playbook/pb_multiple_users_stacked/docs/_multiple_users_stacked_size.html.erb +336 -0
  21. data/app/pb_kits/playbook/pb_multiple_users_stacked/docs/_multiple_users_stacked_size.jsx +97 -0
  22. data/app/pb_kits/playbook/pb_multiple_users_stacked/docs/example.yml +2 -0
  23. data/app/pb_kits/playbook/pb_multiple_users_stacked/docs/index.js +1 -0
  24. data/app/pb_kits/playbook/pb_multiple_users_stacked/multiple_users_stacked.html.erb +28 -6
  25. data/app/pb_kits/playbook/pb_multiple_users_stacked/multiple_users_stacked.rb +31 -1
  26. data/dist/chunks/{_typeahead-CT2ByCBK.js → _typeahead-C9g4qCcE.js} +1 -1
  27. data/dist/chunks/_weekday_stacked-leC2i6B3.js +45 -0
  28. data/dist/chunks/vendor.js +1 -1
  29. data/dist/playbook-doc.js +1 -1
  30. data/dist/playbook-rails-react-bindings.js +1 -1
  31. data/dist/playbook-rails.js +1 -1
  32. data/dist/playbook.css +1 -1
  33. data/lib/playbook/version.rb +1 -1
  34. metadata +11 -4
  35. data/dist/chunks/_weekday_stacked-BFqyoTft.js +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1315703b951ec18c52f143275d8fcce5219cd6cab284b284be92584ffe64adb5
4
- data.tar.gz: a8ec02f07ec4a6e857e855b712f659c539410232cb4d8515ae99566e3c1d39f3
3
+ metadata.gz: ac0cc084fd2f8761eab341ba64c605ed0649798c05aa09b61c04b9824950ff73
4
+ data.tar.gz: 8f4102fe8641b3a4be15ea3af479f6f309e84893634dac8c56c5ab76965ebf3f
5
5
  SHA512:
6
- metadata.gz: 947391921569c72c01d30a6819ab580140bea82df5bc6f83a8e3426ea1561a07e6178574a8c3df62c820818eb98f792aa7eb0cab223ec837f420f44ec1adb29e
7
- data.tar.gz: c33a5d61b41a9fb8c57538234484a37e3bc08c8dbc161f727ec8fa9ba5fcbc0f1e9615bb4c53f844561c89e1ce03a4d64064a6d9e00fb54ba72138dadfc507d8
6
+ metadata.gz: 66f34b87ca5da8ff6934015478199b3c396d3acc09c3468aa20bdf0a362653200ecde7974043c9b09d83183004b7902ea2cf63c76fb01708e5c6d68b51ff7af5
7
+ data.tar.gz: 0eea402c08d96745f4e234da5c8a74cf72a1075c0371912b88e1777604ff64ed7dffcb94e1940e851f0dd0166e36a57a043944864f69f6785921fb72339419bf
@@ -91,7 +91,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
91
91
  const columnHelper = createColumnHelper()
92
92
 
93
93
  //Create cells for first columns
94
- const createCellFunction = (cellAccessors: string[]) => {
94
+ const createCellFunction = (cellAccessors: string[], customRenderer?: (row: Row<GenericObject>, value: any) => JSX.Element) => {
95
95
  const columnCells = ({
96
96
  row,
97
97
  getValue,
@@ -101,6 +101,12 @@ const AdvancedTable = (props: AdvancedTableProps) => {
101
101
  }) => {
102
102
  const rowData = row.original
103
103
 
104
+ // Use customRenderer if provided, otherwise default rendering
105
+ if (customRenderer) {
106
+ // console.log(row.original, getValue())
107
+ return customRenderer(row, getValue())
108
+ }
109
+
104
110
  switch (row.depth) {
105
111
  case 0: {
106
112
  return (
@@ -134,18 +140,31 @@ const AdvancedTable = (props: AdvancedTableProps) => {
134
140
  //Create column array in format needed by Tanstack
135
141
  const columns =
136
142
  columnDefinitions &&
137
- columnDefinitions.map((column) => {
143
+ columnDefinitions.map((column, index) => {
138
144
  // Define the base column structure
139
145
  const columnStructure = {
140
146
  ...columnHelper.accessor(column.accessor, {
141
147
  header: column.label,
142
148
  }),
143
149
  }
144
- if (column.cellAccessors) {
145
- columnStructure.cell = createCellFunction(column.cellAccessors)
146
- }
147
- return columnStructure
148
- })
150
+
151
+ // Use the custom renderer if provided, EXCEPT for the first column
152
+ if (index !== 0) {
153
+ if (column.cellAccessors || column.customRenderer) {
154
+ columnStructure.cell = createCellFunction(
155
+ column.cellAccessors,
156
+ column.customRenderer
157
+ )
158
+ }
159
+ } else {
160
+ // For the first column, apply createCellFunction without customRenderer
161
+ if (column.cellAccessors) {
162
+ columnStructure.cell = createCellFunction(column.cellAccessors)
163
+ }
164
+ }
165
+
166
+ return columnStructure
167
+ })
149
168
 
150
169
  //Syntax for sorting Array if we want to manage state ourselves
151
170
  const sorting = [
@@ -0,0 +1,52 @@
1
+ import React from "react"
2
+ import { AdvancedTable, Pill, Body } from "playbook-ui"
3
+ import MOCK_DATA from "./advanced_table_mock_data.json"
4
+
5
+ const AdvancedTableCustomCell = (props) => {
6
+ const columnDefinitions = [
7
+ {
8
+ accessor: "year",
9
+ label: "Year",
10
+ cellAccessors: ["quarter", "month", "day"],
11
+
12
+ },
13
+ {
14
+ accessor: "newEnrollments",
15
+ label: "New Enrollments",
16
+ customRenderer: (row, value) => <Pill text={value} />,
17
+ },
18
+ {
19
+ accessor: "scheduledMeetings",
20
+ label: "Scheduled Meetings",
21
+ customRenderer: (row, value) => <Body><a href="#">{value}</a></Body>,
22
+ },
23
+ {
24
+ accessor: "attendanceRate",
25
+ label: "Attendance Rate",
26
+ },
27
+ {
28
+ accessor: "completedClasses",
29
+ label: "Completed Classes",
30
+ },
31
+ {
32
+ accessor: "classCompletionRate",
33
+ label: "Class Completion Rate",
34
+ },
35
+ {
36
+ accessor: "graduatedStudents",
37
+ label: "Graduated Students",
38
+ },
39
+ ]
40
+
41
+ return (
42
+ <div>
43
+ <AdvancedTable
44
+ columnDefinitions={columnDefinitions}
45
+ tableData={MOCK_DATA}
46
+ {...props}
47
+ />
48
+ </div>
49
+ )
50
+ }
51
+
52
+ export default AdvancedTableCustomCell
@@ -3,6 +3,7 @@ examples:
3
3
  - advanced_table_beta: Default (Required Props)
4
4
  - advanced_table_beta_subrow_headers: SubRow Headers
5
5
  - advanced_table_beta_sort: Enable Sorting
6
+
6
7
  react:
7
8
  - advanced_table_default: Default (Required Props)
8
9
  - advanced_table_loading: Loading State
@@ -15,3 +16,4 @@ examples:
15
16
  - advanced_table_table_props: Table Props
16
17
  - advanced_table_inline_row_loading: Inline Row Loading
17
18
  - advanced_table_responsive: Responsive Tables
19
+ - advanced_table_custom_cell: Custom Components for Cells
@@ -9,3 +9,4 @@ export { default as AdvancedTableTableOptions } from './_advanced_table_table_op
9
9
  export { default as AdvancedTableTableProps } from './_advanced_table_table_props.jsx'
10
10
  export { default as AdvancedTableInlineRowLoading } from './_advanced_table_inline_row_loading.jsx'
11
11
  export { default as AdvancedTableResponsive } from './_advanced_table_responsive.jsx'
12
+ export { default as AdvancedTableCustomCell } from './_advanced_table_custom_cell.jsx'
@@ -1,4 +1,4 @@
1
- import React, { useState, useRef, useEffect } from "react";
1
+ import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from "react";
2
2
  import classnames from "classnames";
3
3
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props";
4
4
  import { globalProps } from "../utilities/globalProps";
@@ -38,7 +38,14 @@ type DropdownProps = {
38
38
  triggerRef?: any;
39
39
  };
40
40
 
41
- const Dropdown = (props: DropdownProps) => {
41
+ interface DropdownComponent
42
+ extends React.ForwardRefExoticComponent<DropdownProps & React.RefAttributes<unknown>> {
43
+ Option: typeof DropdownOption;
44
+ Trigger: typeof DropdownTrigger;
45
+ Container: typeof DropdownContainer;
46
+ }
47
+
48
+ const Dropdown = forwardRef((props: DropdownProps, ref: any) => {
42
49
  const {
43
50
  aria = {},
44
51
  autocomplete = false,
@@ -125,7 +132,7 @@ const Dropdown = (props: DropdownProps) => {
125
132
  const filteredOptions = optionsWithBlankSelection?.filter((option: GenericObject) => {
126
133
  const label = typeof option.label === 'string' ? option.label.toLowerCase() : option.label;
127
134
  return String(label).toLowerCase().includes(filterItem.toLowerCase());
128
- });
135
+ });
129
136
 
130
137
  // For keyboard accessibility: Set focus within dropdown to selected item if it exists
131
138
  useEffect(() => {
@@ -175,6 +182,14 @@ const Dropdown = (props: DropdownProps) => {
175
182
  dark
176
183
  });
177
184
 
185
+ useImperativeHandle(ref, () => ({
186
+ clearSelected: () => {
187
+ setSelected({});
188
+ setFilterItem("");
189
+ setIsDropDownClosed(true);
190
+ onSelect && onSelect(null);
191
+ },
192
+ }));
178
193
 
179
194
  return (
180
195
  <div {...ariaProps}
@@ -258,8 +273,9 @@ const Dropdown = (props: DropdownProps) => {
258
273
  </DropdownContext.Provider>
259
274
  </div>
260
275
  )
261
- };
276
+ }) as DropdownComponent
262
277
 
278
+ Dropdown.displayName = "Dropdown";
263
279
  Dropdown.Option = DropdownOption;
264
280
  Dropdown.Trigger = DropdownTrigger;
265
281
  Dropdown.Container = DropdownContainer;
@@ -0,0 +1,45 @@
1
+ import React, { useRef } from 'react'
2
+ import { Button, Dropdown } from 'playbook-ui'
3
+
4
+ const options = [
5
+ {
6
+ label: "United States",
7
+ value: "United States",
8
+ },
9
+ {
10
+ label: "Canada",
11
+ value: "Canada",
12
+ },
13
+ {
14
+ label: "Pakistan",
15
+ value: "Pakistan",
16
+ }
17
+ ]
18
+
19
+ const DropdownClearSelection = (props) => {
20
+ const dropdownRef = useRef(null)
21
+
22
+ const handleReset = () => {
23
+ if (dropdownRef.current) {
24
+ dropdownRef.current.clearSelected()
25
+ }
26
+ }
27
+
28
+ return (
29
+ <>
30
+ <Dropdown
31
+ defaultValue={options[2]}
32
+ options={options}
33
+ ref={dropdownRef}
34
+ {...props}
35
+ />
36
+ <Button
37
+ marginTop="md"
38
+ onClick={handleReset}
39
+ text="Reset"
40
+ />
41
+ </>
42
+ )
43
+ }
44
+
45
+ export default DropdownClearSelection
@@ -0,0 +1 @@
1
+ To use an external control (like a reset button) to clear Dropdown selection, you can make use of the `useRef` hook. You must pass a ref to the Dropdown component and use that ref within the onClick for the external control in the way shown in the code snippet below.
@@ -22,6 +22,7 @@ examples:
22
22
  - dropdown_error: Dropdown with Error
23
23
  - dropdown_default_value: Default Value
24
24
  - dropdown_blank_selection: Blank Selection
25
+ - dropdown_clear_selection: Clear Selection
25
26
  # - dropdown_with_autocomplete: Autocomplete
26
27
  # - dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
27
28
  # - dropdown_with_external_control: useDropdown Hook
@@ -12,3 +12,4 @@ export { default as DropdownSubcomponentStructure } from './_dropdown_subcompone
12
12
  export { default as DropdownError } from './_dropdown_error.jsx'
13
13
  export { default as DropdownDefaultValue } from './_dropdown_default_value.jsx'
14
14
  export { default as DropdownBlankSelection } from './_dropdown_blank_selection.jsx'
15
+ export { default as DropdownClearSelection } from './_dropdown_clear_selection.jsx'
@@ -62,7 +62,7 @@ const DropdownOption = (props: DropdownOptionProps) => {
62
62
  const focusedClass = isFocused && "focused";
63
63
 
64
64
  const selectedClass = `${
65
- selected.label === option.label
65
+ selected?.label === option.label
66
66
  ? "selected"
67
67
  : "list"
68
68
  }`;
@@ -73,7 +73,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
73
73
  !autocomplete && "select_only"
74
74
  );
75
75
 
76
- const customDisplayPlaceholder = selected.label ? (
76
+ const customDisplayPlaceholder = selected?.label ? (
77
77
  <b>{selected.label}</b>
78
78
  ) : autocomplete ? (
79
79
  ""
@@ -83,7 +83,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
83
83
  "Select..."
84
84
  );
85
85
 
86
- const defaultDisplayPlaceholder = selected.label
86
+ const defaultDisplayPlaceholder = selected?.label
87
87
  ? selected.label
88
88
  : autocomplete
89
89
  ? ""
@@ -202,6 +202,23 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
202
202
  };
203
203
  }, []);
204
204
 
205
+ useEffect(() => {
206
+ if (id) {
207
+ // Attach the clear function to the window, scoped by the id
208
+ (window as any)[`clearMultiLevelSelect_${id}`] = () => {
209
+ const resetData = modifyRecursive(formattedData, false);
210
+ setFormattedData(resetData);
211
+ setReturnedArray([]);
212
+ setDefaultReturn([]);
213
+ setSingleSelectedItem({ id: [], value: "", item: [] });
214
+ onSelect([]);
215
+ };
216
+ return () => {
217
+ delete (window as any)[`clearMultiLevelSelect_${id}`];
218
+ };
219
+ }
220
+ }, [formattedData, id, onSelect]);
221
+
205
222
  // Iterate over tree, find item and set checked or unchecked
206
223
  const modifyValue = (
207
224
  id: string,
@@ -0,0 +1,93 @@
1
+ <% treeData = [{
2
+ label: "Power Home Remodeling",
3
+ value: "Power Home Remodeling",
4
+ id: "100",
5
+ expanded: true,
6
+ children: [
7
+ {
8
+ label: "People",
9
+ value: "People",
10
+ id: "101",
11
+ expanded: true,
12
+ children: [
13
+ {
14
+ label: "Talent Acquisition",
15
+ value: "Talent Acquisition",
16
+ id: "102",
17
+ },
18
+ {
19
+ label: "Business Affairs",
20
+ value: "Business Affairs",
21
+ id: "103",
22
+ children: [
23
+ {
24
+ label: "Initiatives",
25
+ value: "Initiatives",
26
+ id: "104",
27
+ },
28
+ {
29
+ label: "Learning & Development",
30
+ value: "Learning & Development",
31
+ id: "105",
32
+ },
33
+ ],
34
+ },
35
+ {
36
+ label: "People Experience",
37
+ value: "People Experience",
38
+ id: "106",
39
+ },
40
+ ],
41
+ },
42
+ {
43
+ label: "Contact Center",
44
+ value: "Contact Center",
45
+ id: "107",
46
+ children: [
47
+ {
48
+ label: "Appointment Management",
49
+ value: "Appointment Management",
50
+ id: "108",
51
+ },
52
+ {
53
+ label: "Customer Service",
54
+ value: "Customer Service",
55
+ id: "109",
56
+ },
57
+ {
58
+ label: "Energy",
59
+ value: "Energy",
60
+ id: "110",
61
+ },
62
+ ],
63
+ },
64
+ ],
65
+ }] %>
66
+
67
+ <%= pb_rails("multi_level_select", props: {
68
+ id: "multi-level-select-reset-example",
69
+ name: "my_array",
70
+ tree_data: treeData,
71
+ return_all_selected: true
72
+ }) %>
73
+
74
+ <%= pb_rails("button", props: { text: "Reset", margin_top: "lg", id:"multilevelselect-reset-button" }) %>
75
+
76
+
77
+ <script>
78
+ window.addEventListener('DOMContentLoaded', () => {
79
+ const exampleResetButton = document.querySelector("#multilevelselect-reset-button");
80
+
81
+ exampleResetButton.addEventListener("click", () => {
82
+ clearMultiLevelSelectById('multi-level-select-reset-example');
83
+ });
84
+ function clearMultiLevelSelectById(id) {
85
+ const clearFunction = window[`clearMultiLevelSelect_${id}`];
86
+ if (clearFunction) {
87
+ clearFunction();
88
+ } else {
89
+ console.warn(`No clear function found for MultiLevelSelect with id: ${id}`);
90
+ }
91
+ }
92
+ })
93
+ </script>
@@ -0,0 +1 @@
1
+ In order to clear the multilevelselect selection using an external trigger (like a reset button), the `clearMultiLevelSelect` function can be used. See the code snippet below to see this in action. The function is scoped by id so an id MUST be used on the multilevelselect kit and passed to the function as shown for it to work.
@@ -7,6 +7,7 @@ examples:
7
7
  - multi_level_select_selected_ids: Selected Ids
8
8
  - multi_level_select_with_form: With Form
9
9
  - multi_level_select_color: With Pills (Custom Color)
10
+ - multi_level_select_reset: Reset Selection
10
11
 
11
12
  react:
12
13
  - multi_level_select_default: Default