playbook_ui 14.21.0.pre.rc.1 → 14.21.0
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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/Components/RegularTableView.tsx +116 -49
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/Context/AdvancedTableContext.tsx +58 -2
- data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableActions.ts +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableState.ts +16 -4
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +7 -3
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +32 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +13 -3
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.rb +7 -1
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +61 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_no_subrows.html.erb +33 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_no_subrows.jsx +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_pinned_rows.jsx +57 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_pinned_rows_react.md +5 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_scrollbar_none.html.erb +33 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_scrollbar_none.jsx +53 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +6 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +3 -1
- data/app/pb_kits/playbook/pb_advanced_table/index.js +2 -0
- data/app/pb_kits/playbook/pb_checkbox/checkbox.html.erb +1 -4
- data/app/pb_kits/playbook/pb_checkbox/checkbox.rb +7 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick_date_display.html.erb +13 -0
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +17 -58
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +12 -3
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_close_on_select.jsx +42 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_close_on_select.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +14 -10
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +26 -15
- data/app/pb_kits/playbook/pb_popover/index.ts +9 -4
- data/app/pb_kits/playbook/pb_table/docs/_table_with_selectable_rows.html.erb +3 -51
- data/app/pb_kits/playbook/pb_table/styles/_mobile_collapse.scss +1 -1
- data/dist/chunks/{_typeahead-CRW6dJbW.js → _typeahead-BlPRej0F.js} +2 -2
- data/dist/chunks/_weekday_stacked-DqVFJsbt.js +45 -0
- data/dist/chunks/lazysizes-DHz07jlL.js +1 -0
- data/dist/chunks/lib-D4vXIZF5.js +29 -0
- data/dist/chunks/{pb_form_validation-BZ2AVAi_.js → pb_form_validation-DyvJ8iPe.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +15 -7
- data/dist/chunks/_weekday_stacked-C4d17aYW.js +0 -45
- data/dist/chunks/lazysizes-B7xYodB-.js +0 -1
- data/dist/chunks/lib-D5R1BjUn.js +0 -29
@@ -0,0 +1,33 @@
|
|
1
|
+
<% column_definitions = [
|
2
|
+
{
|
3
|
+
accessor: "year",
|
4
|
+
label: "Year",
|
5
|
+
cellAccessors: ["quarter", "month", "day"],
|
6
|
+
},
|
7
|
+
{
|
8
|
+
accessor: "newEnrollments",
|
9
|
+
label: "New Enrollments",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
accessor: "scheduledMeetings",
|
13
|
+
label: "Scheduled Meetings",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
accessor: "attendanceRate",
|
17
|
+
label: "Attendance Rate",
|
18
|
+
},
|
19
|
+
{
|
20
|
+
accessor: "completedClasses",
|
21
|
+
label: "Completed Classes",
|
22
|
+
},
|
23
|
+
{
|
24
|
+
accessor: "classCompletionRate",
|
25
|
+
label: "Class Completion Rate",
|
26
|
+
},
|
27
|
+
{
|
28
|
+
accessor: "graduatedStudents",
|
29
|
+
label: "Graduated Students",
|
30
|
+
}
|
31
|
+
] %>
|
32
|
+
|
33
|
+
<%= pb_rails("advanced_table", props: { id: "table-no-children", enable_toggle_expansion: "none", table_data: @table_data_no_subrows, column_definitions: column_definitions }) %>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import React, { useState } from "react"
|
2
|
+
import AdvancedTable from '../_advanced_table'
|
3
|
+
import MOCK_DATA from "./advanced_table_mock_data_with_id.json"
|
4
|
+
|
5
|
+
const AdvancedTableRowPinning = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "scheduledMeetings",
|
18
|
+
label: "Scheduled Meetings",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "attendanceRate",
|
22
|
+
label: "Attendance Rate",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "completedClasses",
|
26
|
+
label: "Completed Classes",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "classCompletionRate",
|
30
|
+
label: "Class Completion Rate",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "graduatedStudents",
|
34
|
+
label: "Graduated Students",
|
35
|
+
},
|
36
|
+
]
|
37
|
+
|
38
|
+
const [pinnedRows, setPinnedRows] = useState({top: ["8", "9", "10", "11", "12", "13", "14"]})
|
39
|
+
|
40
|
+
return (
|
41
|
+
<div>
|
42
|
+
<AdvancedTable
|
43
|
+
columnDefinitions={columnDefinitions}
|
44
|
+
maxHeight="xs"
|
45
|
+
pinnedRows={{value: pinnedRows, onChange: setPinnedRows}}
|
46
|
+
tableData={MOCK_DATA}
|
47
|
+
tableProps={{sticky: true}}
|
48
|
+
{...props}
|
49
|
+
>
|
50
|
+
<AdvancedTable.Header enableSorting />
|
51
|
+
<AdvancedTable.Body />
|
52
|
+
</AdvancedTable>
|
53
|
+
</div>
|
54
|
+
)
|
55
|
+
}
|
56
|
+
|
57
|
+
export default AdvancedTableRowPinning
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Use the `pinnedRows` prop to pin specific rows to the top of an Advanced Table. Pinned rows will remain at the top when scrolling through table data and reorganizing via sorting.
|
2
|
+
|
3
|
+
**NOTE:** This prop is in Beta. Current Requirements for V1:
|
4
|
+
- Sticky header required: Pinned rows must be used with `sticky: true` via `tableProps` (works with both responsive and non-responsive tables)
|
5
|
+
- Row ids required: Pass an array of row ids to the `top` property. For expandable rows, both parent and all its child row ids must be included individually
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<% column_definitions = [
|
2
|
+
{
|
3
|
+
accessor: "year",
|
4
|
+
label: "Year",
|
5
|
+
cellAccessors: ["quarter", "month", "day"],
|
6
|
+
},
|
7
|
+
{
|
8
|
+
accessor: "newEnrollments",
|
9
|
+
label: "New Enrollments",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
accessor: "scheduledMeetings",
|
13
|
+
label: "Scheduled Meetings",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
accessor: "attendanceRate",
|
17
|
+
label: "Attendance Rate",
|
18
|
+
},
|
19
|
+
{
|
20
|
+
accessor: "completedClasses",
|
21
|
+
label: "Completed Classes",
|
22
|
+
},
|
23
|
+
{
|
24
|
+
accessor: "classCompletionRate",
|
25
|
+
label: "Class Completion Rate",
|
26
|
+
},
|
27
|
+
{
|
28
|
+
accessor: "graduatedStudents",
|
29
|
+
label: "Graduated Students",
|
30
|
+
}
|
31
|
+
] %>
|
32
|
+
|
33
|
+
<%= pb_rails("advanced_table", props: { id: "beta_table", table_data: @table_data, column_definitions: column_definitions, max_height: "xs", scroll_bar_none: true }) %>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import React from "react"
|
2
|
+
import AdvancedTable from '../../pb_advanced_table/_advanced_table'
|
3
|
+
import MOCK_DATA from "./advanced_table_mock_data.json"
|
4
|
+
|
5
|
+
const AdvancedTableScrollbarNone = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "scheduledMeetings",
|
18
|
+
label: "Scheduled Meetings",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "attendanceRate",
|
22
|
+
label: "Attendance Rate",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "completedClasses",
|
26
|
+
label: "Completed Classes",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "classCompletionRate",
|
30
|
+
label: "Class Completion Rate",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "graduatedStudents",
|
34
|
+
label: "Graduated Students",
|
35
|
+
},
|
36
|
+
]
|
37
|
+
|
38
|
+
return (
|
39
|
+
<div>
|
40
|
+
<AdvancedTable
|
41
|
+
columnDefinitions={columnDefinitions}
|
42
|
+
maxHeight="xs"
|
43
|
+
overflow="auto"
|
44
|
+
responsive="scroll"
|
45
|
+
scrollBarNone
|
46
|
+
tableData={MOCK_DATA}
|
47
|
+
{...props}
|
48
|
+
/>
|
49
|
+
</div>
|
50
|
+
)
|
51
|
+
}
|
52
|
+
|
53
|
+
export default AdvancedTableScrollbarNone
|
@@ -13,10 +13,12 @@ examples:
|
|
13
13
|
- advanced_table_column_headers: Multi-Header Columns
|
14
14
|
- advanced_table_column_headers_multiple: Multi-Header Columns (Multiple Levels)
|
15
15
|
- advanced_table_column_border_color_rails: Column Group Border Color
|
16
|
+
- advanced_table_no_subrows: Table with No Subrows or Expansion
|
16
17
|
- advanced_table_selectable_rows_rails: Selectable Rows
|
17
18
|
- advanced_table_selectable_rows_no_subrows_rails: Selectable Rows (No Subrows)
|
18
19
|
- advanced_table_selectable_rows_actions_rails: Selectable Rows (With Actions)
|
19
20
|
- advanced_table_selectable_rows_header_rails: Selectable Rows (No Actions Bar)
|
21
|
+
- advanced_table_scrollbar_none: Advanced Table Scrollbar None
|
20
22
|
|
21
23
|
react:
|
22
24
|
- advanced_table_default: Default (Required Props)
|
@@ -42,7 +44,7 @@ examples:
|
|
42
44
|
- advanced_table_column_headers_multiple: Multi-Header Columns (Multiple Levels)
|
43
45
|
- advanced_table_column_headers_custom_cell: Multi-Header Columns with Custom Cells
|
44
46
|
- advanced_table_column_border_color: Column Group Border Color
|
45
|
-
|
47
|
+
- advanced_table_no_subrows: Table with No Subrows or Expansion
|
46
48
|
- advanced_table_selectable_rows: Selectable Rows
|
47
49
|
- advanced_table_selectable_rows_no_subrows_react: Selectable Rows (No Subrows)
|
48
50
|
- advanced_table_selectable_rows_actions: Selectable Rows (With Actions)
|
@@ -52,4 +54,6 @@ examples:
|
|
52
54
|
- advanced_table_column_visibility: Column Visibility Control
|
53
55
|
- advanced_table_column_visibility_with_state: Column Visibility Control With State
|
54
56
|
- advanced_table_column_visibility_custom: Column Visibility Control with Custom Dropdown
|
55
|
-
- advanced_table_column_visibility_multi: Column Visibility Control with Multi-Header Columns
|
57
|
+
- advanced_table_column_visibility_multi: Column Visibility Control with Multi-Header Columns
|
58
|
+
- advanced_table_pinned_rows: Pinned Rows
|
59
|
+
- advanced_table_scrollbar_none: Advanced Table Scrollbar None
|
@@ -31,4 +31,6 @@ export { default as AdvancedTableColumnBorderColor} from './_advanced_table_colu
|
|
31
31
|
export { default as AdvancedTableColumnVisibility } from './_advanced_table_column_visibility.jsx'
|
32
32
|
export { default as AdvancedTableColumnVisibilityCustom } from './_advanced_table_column_visibility_custom.jsx'
|
33
33
|
export { default as AdvancedTableColumnVisibilityMulti } from './_advanced_table_column_visibility_multi.jsx'
|
34
|
-
export { default as AdvancedTableColumnVisibilityWithState } from './_advanced_table_column_visibility_with_state.jsx'
|
34
|
+
export { default as AdvancedTableColumnVisibilityWithState } from './_advanced_table_column_visibility_with_state.jsx'
|
35
|
+
export { default as AdvancedTablePinnedRows } from './_advanced_table_pinned_rows.jsx'
|
36
|
+
export { default as AdvancedTableScrollbarNone} from './_advanced_table_scrollbar_none.jsx'
|
@@ -569,6 +569,8 @@ class PbAdvancedTableActionBar {
|
|
569
569
|
actionBar.style.height = 'auto';
|
570
570
|
actionBar.style.overflow = 'visible';
|
571
571
|
actionBar.style.opacity = '1';
|
572
|
+
actionBar.style.transitionProperty = 'all';
|
573
|
+
actionBar.style.transitionTimingFunction = 'ease-in-out';
|
572
574
|
actionBar.classList.remove("p_none");
|
573
575
|
actionBar.classList.add("p_xs", "is-visible", "show-action-card");
|
574
576
|
|
@@ -1,7 +1,4 @@
|
|
1
|
-
<%= pb_content_tag(:label
|
2
|
-
pb_checkbox_indeterminate_main: object.indeterminate_main,
|
3
|
-
pb_checkbox_indeterminate_parent: object.indeterminate_parent,
|
4
|
-
}) do %>
|
1
|
+
<%= pb_content_tag(:label) do %>
|
5
2
|
<%= content.presence || object.input %>
|
6
3
|
<span data-pb-checkbox-icon-span="true" class="pb_checkbox_checkmark">
|
7
4
|
<%= pb_rails("icon", props: { icon: "check", classname: "check_icon", fixed_width: true}) %>
|
@@ -31,6 +31,13 @@ module Playbook
|
|
31
31
|
error ? "negative" : nil
|
32
32
|
end
|
33
33
|
|
34
|
+
def data
|
35
|
+
Hash(prop(:data)).merge(
|
36
|
+
pb_checkbox_indeterminate_main: indeterminate_main,
|
37
|
+
pb_checkbox_indeterminate_parent: indeterminate_parent
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
34
41
|
private
|
35
42
|
|
36
43
|
def error_class
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= pb_rails("date_picker", props: {
|
2
|
+
allow_input: true,
|
3
|
+
date_display: false,
|
4
|
+
end_date_id: "quick-pick-end-date",
|
5
|
+
end_date_name: "quick-pick-end-date",
|
6
|
+
mode: "range",
|
7
|
+
picker_id: "date-picker-quick-pick-date-display",
|
8
|
+
placeholder: "mm/dd/yyyy to mm/dd/yyyy",
|
9
|
+
selection_type: "quickpick",
|
10
|
+
start_date_id: "quick-pick-start-date",
|
11
|
+
start_date_name: "quick-pick-start-date"
|
12
|
+
}) %>
|
13
|
+
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import React, { createContext, useReducer, useContext, useEffect, useMemo
|
1
|
+
import React, { createContext, useReducer, useContext, useEffect, useMemo } from "react";
|
2
2
|
import { InitialStateType, ActionType, DraggableProviderType } from "./types";
|
3
3
|
|
4
4
|
const initialState: InitialStateType = {
|
5
5
|
items: [],
|
6
6
|
dragData: { id: "", initialGroup: "" },
|
7
7
|
isDragging: "",
|
8
|
-
activeContainer: ""
|
8
|
+
activeContainer: ""
|
9
9
|
};
|
10
10
|
|
11
11
|
const reducer = (state: InitialStateType, action: ActionType) => {
|
@@ -31,23 +31,9 @@ const reducer = (state: InitialStateType, action: ActionType) => {
|
|
31
31
|
const { dragId, targetId } = action.payload;
|
32
32
|
const newItems = [...state.items];
|
33
33
|
const draggedItem = newItems.find(item => item.id === dragId);
|
34
|
-
const
|
35
|
-
|
36
|
-
if (!draggedItem || !targetItem || draggedItem.container !== targetItem.container) {
|
37
|
-
return state;
|
38
|
-
}
|
39
|
-
|
40
|
-
if (dragId === targetId) {
|
41
|
-
return state;
|
42
|
-
}
|
43
|
-
|
44
|
-
const draggedIndex = newItems.findIndex(item => item.id === dragId);
|
34
|
+
const draggedIndex = newItems.indexOf(draggedItem);
|
45
35
|
const targetIndex = newItems.findIndex(item => item.id === targetId);
|
46
36
|
|
47
|
-
if (draggedIndex === -1 || targetIndex === -1) {
|
48
|
-
return state;
|
49
|
-
}
|
50
|
-
|
51
37
|
newItems.splice(draggedIndex, 1);
|
52
38
|
newItems.splice(targetIndex, 0, draggedItem);
|
53
39
|
|
@@ -62,11 +48,7 @@ const reducer = (state: InitialStateType, action: ActionType) => {
|
|
62
48
|
const DragContext = createContext<any>({});
|
63
49
|
|
64
50
|
export const DraggableContext = () => {
|
65
|
-
|
66
|
-
if (context === undefined) {
|
67
|
-
throw new Error('DraggableContext must be used within a DraggableProvider');
|
68
|
-
}
|
69
|
-
return context;
|
51
|
+
return useContext(DragContext);
|
70
52
|
};
|
71
53
|
|
72
54
|
export const DraggableProvider = ({
|
@@ -81,11 +63,7 @@ export const DraggableProvider = ({
|
|
81
63
|
dropZone = { type: 'ghost', color: 'neutral', direction: 'vertical' }
|
82
64
|
}: DraggableProviderType) => {
|
83
65
|
const [state, dispatch] = useReducer(reducer, initialState);
|
84
|
-
|
85
|
-
// Store initial items in a ref to use if needed (for consistency when needed in future updates)
|
86
|
-
const initialItemsRef = useRef(initialItems);
|
87
|
-
const [isDragging, setIsDragging] = useState(false);
|
88
|
-
|
66
|
+
|
89
67
|
// Parse dropZone prop - handle both string format (backward compatibility) and object format
|
90
68
|
let dropZoneType = 'ghost';
|
91
69
|
let dropZoneColor = 'neutral';
|
@@ -108,64 +86,45 @@ export const DraggableProvider = ({
|
|
108
86
|
|
109
87
|
useEffect(() => {
|
110
88
|
dispatch({ type: 'SET_ITEMS', payload: initialItems });
|
111
|
-
initialItemsRef.current = initialItems;
|
112
89
|
}, [initialItems]);
|
113
90
|
|
114
91
|
useEffect(() => {
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
}, [state.items, onReorder]);
|
92
|
+
onReorder(state.items);
|
93
|
+
}, [state.items]);
|
119
94
|
|
120
95
|
const handleDragStart = (id: string, container: string) => {
|
121
|
-
|
122
|
-
dispatch({ type: 'SET_DRAG_DATA', payload: { id, initialGroup: container } });
|
96
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: id, initialGroup: container } });
|
123
97
|
dispatch({ type: 'SET_IS_DRAGGING', payload: id });
|
124
|
-
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
125
98
|
if (onDragStart) onDragStart(id, container);
|
126
99
|
};
|
127
100
|
|
128
101
|
const handleDragEnter = (id: string, container: string) => {
|
129
|
-
if (
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
const draggedItem = state.items.find(item => item.id === state.dragData.id);
|
134
|
-
const targetItem = state.items.find(item => item.id === id);
|
135
|
-
|
136
|
-
if (!draggedItem || !targetItem || draggedItem.container !== targetItem.container) {
|
137
|
-
return;
|
102
|
+
if (state.dragData.id !== id) {
|
103
|
+
dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
|
104
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: state.dragData.id, initialGroup: container } });
|
138
105
|
}
|
139
|
-
|
140
|
-
dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
|
141
|
-
|
142
106
|
if (onDragEnter) onDragEnter(id, container);
|
143
107
|
};
|
144
108
|
|
145
109
|
const handleDragEnd = () => {
|
146
|
-
setIsDragging(false);
|
147
110
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
148
111
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
149
112
|
if (onDragEnd) onDragEnd();
|
150
113
|
};
|
151
114
|
|
152
|
-
const
|
153
|
-
|
154
|
-
|
155
|
-
if (draggedItem && draggedItem.container !== container) {
|
156
|
-
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId: state.dragData.id, container } });
|
157
|
-
}
|
115
|
+
const changeCategory = (itemId: string, container: string) => {
|
116
|
+
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId, container } });
|
117
|
+
};
|
158
118
|
|
119
|
+
const handleDrop = (container: string) => {
|
159
120
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
160
121
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
161
|
-
|
162
|
-
setIsDragging(false);
|
122
|
+
changeCategory(state.dragData.id, container);
|
163
123
|
if (onDrop) onDrop(container);
|
164
124
|
};
|
165
125
|
|
166
126
|
const handleDragOver = (e: Event, container: string) => {
|
167
127
|
e.preventDefault();
|
168
|
-
e.stopPropagation();
|
169
128
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
170
129
|
if (onDragOver) onDragOver(e, container);
|
171
130
|
};
|
@@ -185,7 +144,7 @@ export const DraggableProvider = ({
|
|
185
144
|
handleDragEnd,
|
186
145
|
handleDrop,
|
187
146
|
handleDragOver
|
188
|
-
}), [state, dropZoneType, dropZoneColor, dropZoneDirection
|
147
|
+
}), [state, dropZoneType, dropZoneColor, dropZoneDirection]);
|
189
148
|
|
190
149
|
return (
|
191
150
|
<DragContext.Provider value={contextValue}>{children}</DragContext.Provider>
|
@@ -25,6 +25,7 @@ type DropdownProps = {
|
|
25
25
|
blankSelection?: string;
|
26
26
|
children?: React.ReactChild[] | React.ReactChild | React.ReactElement[];
|
27
27
|
className?: string;
|
28
|
+
closeOnSelection?: boolean;
|
28
29
|
formPillProps?: GenericObject;
|
29
30
|
dark?: boolean;
|
30
31
|
data?: { [key: string]: string };
|
@@ -55,6 +56,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
55
56
|
blankSelection = '',
|
56
57
|
children,
|
57
58
|
className,
|
59
|
+
closeOnSelection = true,
|
58
60
|
dark = false,
|
59
61
|
data = {},
|
60
62
|
defaultValue = {},
|
@@ -152,7 +154,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
152
154
|
if (!multiSelect) return optionsWithBlankSelection;
|
153
155
|
return optionsWithBlankSelection.filter((option: GenericObject) => !selectedArray.some((sel) => sel.label === option.label));
|
154
156
|
}, [optionsWithBlankSelection, selectedArray, multiSelect]);
|
155
|
-
|
157
|
+
|
156
158
|
const filteredOptions = useMemo(() => {
|
157
159
|
return availableOptions.filter((opt: GenericObject) =>
|
158
160
|
String(opt.label).toLowerCase().includes(filterItem.toLowerCase())
|
@@ -192,12 +194,18 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
192
194
|
return next;
|
193
195
|
});
|
194
196
|
setFilterItem("");
|
195
|
-
|
197
|
+
// Only close dropdown if closeOnSelection is true
|
198
|
+
if (closeOnSelection) {
|
199
|
+
setIsDropDownClosed(true);
|
200
|
+
}
|
196
201
|
} else {
|
197
202
|
setSelected(clickedItem);
|
198
203
|
setFilterItem("");
|
199
|
-
setIsDropDownClosed(true);
|
200
204
|
onSelect && onSelect(clickedItem);
|
205
|
+
// Only close dropdown if closeOnSelection is true
|
206
|
+
if (closeOnSelection) {
|
207
|
+
setIsDropDownClosed(true);
|
208
|
+
}
|
201
209
|
}
|
202
210
|
};
|
203
211
|
|
@@ -252,6 +260,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
252
260
|
<DropdownContext.Provider
|
253
261
|
value={{
|
254
262
|
autocomplete,
|
263
|
+
closeOnSelection,
|
255
264
|
dropdownContainerRef,
|
256
265
|
filteredOptions,
|
257
266
|
filterItem,
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import Dropdown from '../../pb_dropdown/_dropdown'
|
3
|
+
|
4
|
+
const DropdownCloseOnSelect = (props) => {
|
5
|
+
|
6
|
+
const options = [
|
7
|
+
{
|
8
|
+
label: "United States",
|
9
|
+
value: "United States",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
label: "Canada",
|
13
|
+
value: "Canada",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
label: "Pakistan",
|
17
|
+
value: "Pakistan",
|
18
|
+
}
|
19
|
+
];
|
20
|
+
|
21
|
+
|
22
|
+
return (
|
23
|
+
<div>
|
24
|
+
<Dropdown
|
25
|
+
closeOnSelection={false}
|
26
|
+
label="Default"
|
27
|
+
options={options}
|
28
|
+
{...props}
|
29
|
+
/>
|
30
|
+
<br />
|
31
|
+
<Dropdown
|
32
|
+
closeOnSelection={false}
|
33
|
+
label="Multi Select"
|
34
|
+
multiSelect
|
35
|
+
options={options}
|
36
|
+
{...props}
|
37
|
+
/>
|
38
|
+
</div>
|
39
|
+
)
|
40
|
+
}
|
41
|
+
|
42
|
+
export default DropdownCloseOnSelect
|
@@ -0,0 +1 @@
|
|
1
|
+
By default, the dropdown menu will close when a selection is made. You can prevent this behavior by using the `closeOnSelection` prop, which will leave the menu open after a selection is made when set to 'false'.
|
@@ -19,4 +19,5 @@ export { default as DropdownMultiSelect } from './_dropdown_multi_select.jsx'
|
|
19
19
|
export { default as DropdownMultiSelectDisplay } from './_dropdown_multi_select_display.jsx'
|
20
20
|
export { default as DropdownMultiSelectWithAutocomplete } from './_dropdown_multi_select_with_autocomplete.jsx'
|
21
21
|
export { default as DropdownMultiSelectWithDefault } from './_dropdown_multi_select_with_default.jsx'
|
22
|
-
export { default as DropdownMultiSelectWithCustomOptions } from './_dropdown_multi_select_with_custom_options.jsx'
|
22
|
+
export { default as DropdownMultiSelectWithCustomOptions } from './_dropdown_multi_select_with_custom_options.jsx'
|
23
|
+
export { default as DropdownCloseOnSelect } from './_dropdown_close_on_select.jsx'
|
@@ -25,7 +25,7 @@ type DropdownOptionProps = {
|
|
25
25
|
key?: string | number;
|
26
26
|
option?: GenericObject;
|
27
27
|
padding?: string;
|
28
|
-
}
|
28
|
+
} & GlobalProps;
|
29
29
|
|
30
30
|
const DropdownOption = (props: DropdownOptionProps) => {
|
31
31
|
const {
|
@@ -56,16 +56,17 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
56
56
|
|
57
57
|
// When multiSelect, then if an option is selected, remove from dropdown
|
58
58
|
const isSelected = Array.isArray(selected)
|
59
|
-
|
60
|
-
|
59
|
+
? selected.some((item) => item.label === option?.label)
|
60
|
+
: (selected as GenericObject)?.label === option?.label;
|
61
61
|
|
62
|
-
|
63
62
|
if (!isItemMatchingFilter(option) || (multiSelect && isSelected)) {
|
64
63
|
return null;
|
65
64
|
}
|
65
|
+
|
66
66
|
const isFocused =
|
67
67
|
focusedOptionIndex >= 0 &&
|
68
68
|
filteredOptions[focusedOptionIndex].label === option?.label;
|
69
|
+
|
69
70
|
const focusedClass = isFocused && "focused";
|
70
71
|
|
71
72
|
const selectedClass = isSelected ? "selected" : "list";
|
@@ -91,7 +92,10 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
91
92
|
className={classes}
|
92
93
|
id={id}
|
93
94
|
key={key}
|
94
|
-
onClick=
|
95
|
+
onClick={(e) => {
|
96
|
+
e.stopPropagation();
|
97
|
+
handleOptionClick(option);
|
98
|
+
}}
|
95
99
|
>
|
96
100
|
<ListItem
|
97
101
|
cursor="pointer"
|
@@ -100,12 +104,12 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
100
104
|
key={option?.label}
|
101
105
|
padding="none"
|
102
106
|
>
|
103
|
-
|
107
|
+
{children ?
|
104
108
|
<div className="dropdown_option_wrapper">{children}</div> :
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
+
<Body dark={dark}
|
110
|
+
text={option?.label}
|
111
|
+
/>
|
112
|
+
}
|
109
113
|
</ListItem>
|
110
114
|
</div>
|
111
115
|
);
|