playbook_ui 14.16.0.pre.rc.6 → 14.17.0.pre.alpha.play1499backgroundkitoverlay7105
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/Utilities/types.ts +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +104 -2
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +168 -85
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +2 -2
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.rb +10 -0
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +20 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_fullscreen.jsx +90 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_fullscreen.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_pagination.jsx +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows.html.erb +39 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_no_subrows.html.erb +33 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_no_subrows_rails.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_rails.md +6 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +4 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_advanced_table/index.js +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/table_body.rb +4 -2
- data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +19 -9
- data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +38 -1
- data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +49 -37
- data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +39 -0
- data/app/pb_kits/playbook/pb_background/_background.scss +26 -0
- data/app/pb_kits/playbook/pb_background/_background.tsx +8 -4
- data/app/pb_kits/playbook/pb_background/docs/_background_overlay.jsx +36 -0
- data/app/pb_kits/playbook/pb_background/docs/_background_overlay.md +1 -0
- data/app/pb_kits/playbook/pb_background/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_background/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +1 -1
- data/app/pb_kits/playbook/pb_button/_button.scss +5 -5
- data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +1 -1
- data/app/pb_kits/playbook/pb_collapsible/__snapshots__/collapsible.test.js.snap +14 -7
- data/app/pb_kits/playbook/pb_contact/contact.test.js +7 -7
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.tsx +34 -34
- data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +2 -2
- data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.ts +16 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_inline.html.erb +0 -11
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_inline.jsx +0 -7
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_inline_styles.scss +28 -24
- data/app/pb_kits/playbook/pb_date_range_inline/date_range_inline.test.js +2 -2
- data/app/pb_kits/playbook/pb_date_range_stacked/date_range_stacked.test.js +1 -1
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +115 -5
- data/app/pb_kits/playbook/pb_draggable/_draggable.tsx +6 -4
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +91 -24
- data/app/pb_kits/playbook/pb_draggable/context/types.ts +35 -28
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones.jsx +184 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones.md +5 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones_colors.jsx +97 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones_colors.md +1 -0
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +3 -3
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableContainer.tsx +11 -2
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +65 -6
- data/app/pb_kits/playbook/pb_drawer/docs/_drawer_breakpoints.html.erb +3 -0
- data/app/pb_kits/playbook/pb_drawer/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.jsx +6 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.jsx +6 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +6 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display_rails.html.erb +8 -8
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +3 -3
- data/app/pb_kits/playbook/pb_filter/Filter/CurrentFilters.tsx +3 -4
- data/app/pb_kits/playbook/pb_filter/Filter/SortMenu.tsx +2 -2
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/_fixed_confirmation_toast.scss +2 -2
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with.html.erb +67 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +67 -0
- data/app/pb_kits/playbook/pb_form/pb_form_validation.js +1 -1
- data/app/pb_kits/playbook/pb_form_group/_form_group.scss +22 -0
- data/app/pb_kits/playbook/pb_gauge/_gauge.tsx +1 -1
- data/app/pb_kits/playbook/pb_icon/_icon.scss +8 -1
- data/app/pb_kits/playbook/pb_icon/docs/_icon_color.html.erb +10 -4
- data/app/pb_kits/playbook/pb_icon/docs/_icon_color.jsx +49 -24
- data/app/pb_kits/playbook/pb_icon/icon.test.js +9 -9
- data/app/pb_kits/playbook/pb_icon_button/_icon_button.tsx +4 -1
- data/app/pb_kits/playbook/pb_icon_button/docs/_icon_button_click.jsx +13 -0
- data/app/pb_kits/playbook/pb_icon_button/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_icon_button/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_icon_circle/icon_circle.test.js +1 -1
- data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.test.js +1 -1
- data/app/pb_kits/playbook/pb_icon_value/icon_value.test.js +1 -1
- data/app/pb_kits/playbook/pb_label_value/label_value.test.js +1 -1
- data/app/pb_kits/playbook/pb_layout/_layout.scss +58 -0
- data/app/pb_kits/playbook/pb_layout/_layout.tsx +20 -7
- data/app/pb_kits/playbook/pb_layout/docs/_layout_bracket.jsx +190 -0
- data/app/pb_kits/playbook/pb_layout/docs/_layout_bracket.md +5 -0
- data/app/pb_kits/playbook/pb_layout/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_layout/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_layout/layout.test.js +4 -0
- data/app/pb_kits/playbook/pb_layout/subcomponents/_game.tsx +90 -0
- data/app/pb_kits/playbook/pb_layout/subcomponents/_round.tsx +57 -0
- data/app/pb_kits/playbook/pb_lightbox/Carousel/Slide.tsx +1 -1
- data/app/pb_kits/playbook/pb_lightbox/Carousel/Slides.tsx +1 -1
- data/app/pb_kits/playbook/pb_lightbox/Carousel/Thumbnails.tsx +1 -1
- data/app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js +1 -1
- data/app/pb_kits/playbook/pb_line_graph/_line_graph.tsx +1 -1
- data/app/pb_kits/playbook/pb_link/link.test.jsx +2 -2
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.scss +23 -0
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +28 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_error.html.erb +72 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_error.jsx +97 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_label.html.erb +71 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_label.jsx +91 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +4 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/index.js +3 -1
- data/app/pb_kits/playbook/pb_multi_level_select/index.js +105 -0
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +10 -0
- data/app/pb_kits/playbook/pb_nav/_nav.scss +5 -0
- data/app/pb_kits/playbook/pb_nav/_nav_item.test.js +5 -3
- data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.tsx +29 -11
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_default.html.erb +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.html.erb +4 -4
- data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.rb +2 -0
- data/app/pb_kits/playbook/pb_section_separator/docs/_section_separator_vertical.md +1 -0
- data/app/pb_kits/playbook/pb_stat_change/stat_change.test.js +8 -4
- data/app/pb_kits/playbook/pb_table/_table.tsx +4 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_borderless.jsx +50 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_borderless_react.md +1 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_floating.jsx +59 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_floating_react.md +1 -0
- data/app/pb_kits/playbook/pb_table/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_table/docs/index.js +2 -0
- data/app/pb_kits/playbook/pb_table/styles/_headers.scss +76 -0
- data/app/pb_kits/playbook/pb_table/styles/_striped.scss +3 -3
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_head.tsx +11 -1
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_header.tsx +11 -1
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_row.tsx +5 -0
- data/app/pb_kits/playbook/pb_table/table.test.js +17 -0
- data/app/pb_kits/playbook/pb_tooltip/index.js +183 -56
- data/app/pb_kits/playbook/pb_tooltip/tooltip.html.erb +2 -5
- data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.tsx +1 -1
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.scss +4 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +3 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_disabled.html.erb +19 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_disabled.jsx +23 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_highlight.jsx +4 -4
- data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_typeahead/index.ts +2 -2
- data/app/pb_kits/playbook/pb_typeahead/typeahead.html.erb +2 -5
- data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +3 -0
- data/app/pb_kits/playbook/pb_user/_user.tsx +78 -13
- data/app/pb_kits/playbook/pb_user/docs/_user_font_options.html.erb +22 -0
- data/app/pb_kits/playbook/pb_user/docs/_user_font_options.jsx +40 -0
- data/app/pb_kits/playbook/pb_user/docs/_user_font_options_rails.md +5 -0
- data/app/pb_kits/playbook/pb_user/docs/_user_font_options_react.md +5 -0
- data/app/pb_kits/playbook/pb_user/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_user/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_user/user.html.erb +28 -12
- data/app/pb_kits/playbook/pb_user/user.rb +17 -1
- data/app/pb_kits/playbook/pb_user/user.test.js +182 -1
- data/app/pb_kits/playbook/pb_user_badge/user_badge.html.erb +1 -6
- data/app/pb_kits/playbook/tokens/_colors.scss +1 -4
- data/app/pb_kits/playbook/utilities/globalProps.ts +1 -1
- data/app/pb_kits/playbook/utilities/object.test.js +287 -1
- data/app/pb_kits/playbook/utilities/object.ts +171 -3
- data/app/pb_kits/playbook/utilities/text.ts +1 -1
- data/dist/chunks/_typeahead-ySWHB-7p.js +22 -0
- data/dist/chunks/_weekday_stacked-36N8xzXL.js +45 -0
- data/dist/chunks/lib-BGzBzFZX.js +29 -0
- data/dist/chunks/{pb_form_validation-BvDxpfs-.js → pb_form_validation-BvNy9Bd6.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/forms/builder/multi_level_select_field.rb +2 -0
- data/lib/playbook/kit_base.rb +4 -4
- data/lib/playbook/version.rb +2 -2
- metadata +41 -9
- data/app/pb_kits/playbook/pb_tooltip/floating_ui.js +0 -282
- data/dist/chunks/_typeahead-CRAPc8k-.js +0 -22
- data/dist/chunks/_weekday_stacked-T0kFfioG.js +0 -45
- data/dist/chunks/lib-BeKPJYlk.js +0 -29
- /data/app/pb_kits/playbook/pb_advanced_table/docs/{_advanced_table_selectable_rows_no_subrows.md → _advanced_table_selectable_rows_no_subrows_react.md} +0 -0
- /data/app/pb_kits/playbook/pb_advanced_table/docs/{_advanced_table_selectable_rows.md → _advanced_table_selectable_rows_react.md} +0 -0
@@ -1,11 +1,11 @@
|
|
1
|
-
import React, { createContext, useReducer, useContext, useEffect, useMemo } from "react";
|
1
|
+
import React, { createContext, useReducer, useContext, useEffect, useMemo, useRef, useState } 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,9 +31,23 @@ 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
|
34
|
+
const targetItem = newItems.find(item => item.id === targetId);
|
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);
|
35
45
|
const targetIndex = newItems.findIndex(item => item.id === targetId);
|
36
46
|
|
47
|
+
if (draggedIndex === -1 || targetIndex === -1) {
|
48
|
+
return state;
|
49
|
+
}
|
50
|
+
|
37
51
|
newItems.splice(draggedIndex, 1);
|
38
52
|
newItems.splice(targetIndex, 0, draggedItem);
|
39
53
|
|
@@ -48,77 +62,130 @@ const reducer = (state: InitialStateType, action: ActionType) => {
|
|
48
62
|
const DragContext = createContext<any>({});
|
49
63
|
|
50
64
|
export const DraggableContext = () => {
|
51
|
-
|
65
|
+
const context = useContext(DragContext);
|
66
|
+
if (context === undefined) {
|
67
|
+
throw new Error('DraggableContext must be used within a DraggableProvider');
|
68
|
+
}
|
69
|
+
return context;
|
52
70
|
};
|
53
71
|
|
54
|
-
export const DraggableProvider = ({
|
55
|
-
children,
|
56
|
-
initialItems,
|
72
|
+
export const DraggableProvider = ({
|
73
|
+
children,
|
74
|
+
initialItems,
|
57
75
|
onReorder,
|
58
|
-
onDragStart,
|
59
|
-
onDragEnter,
|
60
|
-
onDragEnd,
|
61
|
-
onDrop,
|
62
|
-
onDragOver
|
76
|
+
onDragStart,
|
77
|
+
onDragEnter,
|
78
|
+
onDragEnd,
|
79
|
+
onDrop,
|
80
|
+
onDragOver,
|
81
|
+
dropZone = { type: 'ghost', color: 'neutral', direction: 'vertical' }
|
63
82
|
}: DraggableProviderType) => {
|
64
83
|
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
|
+
|
89
|
+
// Parse dropZone prop - handle both string format (backward compatibility) and object format
|
90
|
+
let dropZoneType = 'ghost';
|
91
|
+
let dropZoneColor = 'neutral';
|
92
|
+
let dropZoneDirection = 'vertical';
|
93
|
+
|
94
|
+
if (typeof dropZone === 'string') {
|
95
|
+
// Legacy format - just the type is provided as a string
|
96
|
+
dropZoneType = dropZone;
|
97
|
+
} else {
|
98
|
+
// New object format
|
99
|
+
dropZoneType = dropZone.type || 'ghost';
|
100
|
+
// Line default is set to primary. Other types default to neutral.
|
101
|
+
dropZoneColor = dropZone.type === 'line' ? (dropZone.color || 'primary') : (dropZone.color || 'neutral');
|
102
|
+
|
103
|
+
// Only use direction if the type is 'line'
|
104
|
+
if (dropZoneType === 'line') {
|
105
|
+
dropZoneDirection = dropZone.direction || 'vertical';
|
106
|
+
}
|
107
|
+
}
|
65
108
|
|
66
109
|
useEffect(() => {
|
67
110
|
dispatch({ type: 'SET_ITEMS', payload: initialItems });
|
111
|
+
initialItemsRef.current = initialItems;
|
68
112
|
}, [initialItems]);
|
69
113
|
|
70
114
|
useEffect(() => {
|
71
|
-
onReorder
|
72
|
-
|
115
|
+
if (onReorder) {
|
116
|
+
onReorder(state.items);
|
117
|
+
}
|
118
|
+
}, [state.items, onReorder]);
|
73
119
|
|
74
120
|
const handleDragStart = (id: string, container: string) => {
|
75
|
-
|
121
|
+
setIsDragging(true);
|
122
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id, initialGroup: container } });
|
76
123
|
dispatch({ type: 'SET_IS_DRAGGING', payload: id });
|
124
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
77
125
|
if (onDragStart) onDragStart(id, container);
|
78
126
|
};
|
79
127
|
|
80
128
|
const handleDragEnter = (id: string, container: string) => {
|
81
|
-
if (
|
82
|
-
|
83
|
-
|
129
|
+
if (!isDragging || container !== state.activeContainer) return;
|
130
|
+
|
131
|
+
if (state.dragData.id === id) return;
|
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;
|
84
138
|
}
|
139
|
+
|
140
|
+
dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
|
141
|
+
|
85
142
|
if (onDragEnter) onDragEnter(id, container);
|
86
143
|
};
|
87
144
|
|
88
145
|
const handleDragEnd = () => {
|
146
|
+
setIsDragging(false);
|
89
147
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
90
148
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
91
149
|
if (onDragEnd) onDragEnd();
|
92
150
|
};
|
93
151
|
|
94
|
-
const changeCategory = (itemId: string, container: string) => {
|
95
|
-
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId, container } });
|
96
|
-
};
|
97
|
-
|
98
152
|
const handleDrop = (container: string) => {
|
153
|
+
const draggedItem = state.items.find(item => item.id === state.dragData.id);
|
154
|
+
|
155
|
+
if (draggedItem && draggedItem.container !== container) {
|
156
|
+
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId: state.dragData.id, container } });
|
157
|
+
}
|
158
|
+
|
99
159
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
100
160
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
101
|
-
|
161
|
+
|
162
|
+
setIsDragging(false);
|
102
163
|
if (onDrop) onDrop(container);
|
103
164
|
};
|
104
165
|
|
105
166
|
const handleDragOver = (e: Event, container: string) => {
|
106
167
|
e.preventDefault();
|
168
|
+
e.stopPropagation();
|
107
169
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
108
170
|
if (onDragOver) onDragOver(e, container);
|
109
171
|
};
|
110
172
|
|
173
|
+
// Include direction in contextValue only if type is 'line'
|
111
174
|
const contextValue = useMemo(() => ({
|
112
175
|
items: state.items,
|
113
176
|
dragData: state.dragData,
|
114
177
|
isDragging: state.isDragging,
|
115
178
|
activeContainer: state.activeContainer,
|
179
|
+
dropZone: dropZoneType,
|
180
|
+
dropZoneColor,
|
181
|
+
// Only include direction when type is 'line'
|
182
|
+
...(dropZoneType === 'line' ? { direction: dropZoneDirection } : {}),
|
116
183
|
handleDragStart,
|
117
184
|
handleDragEnter,
|
118
185
|
handleDragEnd,
|
119
186
|
handleDrop,
|
120
187
|
handleDragOver
|
121
|
-
}), [state]);
|
188
|
+
}), [state, dropZoneType, dropZoneColor, dropZoneDirection, handleDragStart, handleDragEnter, handleDragEnd, handleDrop, handleDragOver]);
|
122
189
|
|
123
190
|
return (
|
124
191
|
<DragContext.Provider value={contextValue}>{children}</DragContext.Provider>
|
@@ -1,31 +1,38 @@
|
|
1
1
|
export interface ItemType {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
id: string;
|
3
|
+
container: string;
|
4
|
+
[key: string]: any;
|
5
|
+
}
|
6
|
+
|
7
|
+
export interface InitialStateType {
|
8
|
+
items: ItemType[];
|
9
|
+
dragData: { id: string; initialGroup: string };
|
10
|
+
isDragging: string;
|
11
|
+
activeContainer: string;
|
12
|
+
}
|
13
|
+
|
14
|
+
export type ActionType =
|
15
|
+
| { type: 'SET_ITEMS'; payload: ItemType[] }
|
16
|
+
| { type: 'SET_DRAG_DATA'; payload: { id: string; initialGroup: string } }
|
17
|
+
| { type: 'SET_IS_DRAGGING'; payload: string }
|
18
|
+
| { type: 'SET_ACTIVE_CONTAINER'; payload: string }
|
19
|
+
| { type: 'CHANGE_CATEGORY'; payload: { itemId: string; container: string } }
|
20
|
+
| { type: 'REORDER_ITEMS'; payload: { dragId: string; targetId: string } };
|
21
|
+
|
22
|
+
export interface DropZoneConfig {
|
23
|
+
type?: 'ghost' | 'outline' | 'shadow' | 'line';
|
24
|
+
color?: 'primary' | 'neutral' | 'purple';
|
25
|
+
direction?: 'horizontal' | 'vertical';
|
12
26
|
}
|
13
|
-
|
14
|
-
export type ActionType =
|
15
|
-
| { type: 'SET_ITEMS'; payload: ItemType[] }
|
16
|
-
| { type: 'SET_DRAG_DATA'; payload: { id: string; initialGroup: string } }
|
17
|
-
| { type: 'SET_IS_DRAGGING'; payload: string }
|
18
|
-
| { type: 'SET_ACTIVE_CONTAINER'; payload: string }
|
19
|
-
| { type: 'CHANGE_CATEGORY'; payload: { itemId: string; container: string } }
|
20
|
-
| { type: 'REORDER_ITEMS'; payload: { dragId: string; targetId: string } };
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
export interface DraggableProviderType {
|
29
|
+
children: React.ReactNode;
|
30
|
+
initialItems: ItemType[];
|
31
|
+
onReorder: (items: ItemType[]) => void;
|
32
|
+
onDragStart?: (id: string, container: string) => void;
|
33
|
+
onDragEnter?: (id: string, container: string) => void;
|
34
|
+
onDragEnd?: () => void;
|
35
|
+
onDrop?: (container: string) => void;
|
36
|
+
onDragOver?: (e: Event, container: string) => void;
|
37
|
+
dropZone?: DropZoneConfig | string; // Can accept string for backward compatibility
|
38
|
+
}
|
@@ -0,0 +1,184 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import Body from '../../pb_body/_body'
|
3
|
+
import Flex from '../../pb_flex/_flex'
|
4
|
+
import FlexItem from '../../pb_flex/_flex_item'
|
5
|
+
import Card from '../../pb_card/_card'
|
6
|
+
import Caption from '../../pb_caption/_caption'
|
7
|
+
import Draggable from '../../pb_draggable/_draggable'
|
8
|
+
import { DraggableProvider } from '../../pb_draggable/context'
|
9
|
+
|
10
|
+
// Initial items to be dragged
|
11
|
+
const dataShadow = [
|
12
|
+
{
|
13
|
+
id: "51",
|
14
|
+
text: "Task 1",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
id: "52",
|
18
|
+
text: "Task 2",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
id: "53",
|
22
|
+
text: "Task 3",
|
23
|
+
},
|
24
|
+
];
|
25
|
+
|
26
|
+
const dataOutline = [
|
27
|
+
{
|
28
|
+
id: "61",
|
29
|
+
text: "Task 1",
|
30
|
+
},
|
31
|
+
{
|
32
|
+
id: "62",
|
33
|
+
text: "Task 2",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
id: "63",
|
37
|
+
text: "Task 3",
|
38
|
+
},
|
39
|
+
];
|
40
|
+
|
41
|
+
const dataLine = [
|
42
|
+
{
|
43
|
+
id: "71",
|
44
|
+
text: "Task 1",
|
45
|
+
},
|
46
|
+
{
|
47
|
+
id: "72",
|
48
|
+
text: "Task 2",
|
49
|
+
},
|
50
|
+
{
|
51
|
+
id: "73",
|
52
|
+
text: "Task 3",
|
53
|
+
},
|
54
|
+
];
|
55
|
+
|
56
|
+
const DraggableDropZones = (props) => {
|
57
|
+
const [initialShadowState, setInitialShadowState] = useState(dataShadow);
|
58
|
+
const [initialOutlineState, setInitialOutlineState] = useState(dataOutline);
|
59
|
+
const [initialLineState, setInitialLineState] = useState(dataLine);
|
60
|
+
|
61
|
+
return (
|
62
|
+
<>
|
63
|
+
<Flex justify="between"
|
64
|
+
{...props}
|
65
|
+
>
|
66
|
+
<FlexItem marginRight="xl">
|
67
|
+
<DraggableProvider
|
68
|
+
dropZone={{type: "shadow"}}
|
69
|
+
initialItems={dataShadow}
|
70
|
+
onReorder={(items) => setInitialShadowState(items)}
|
71
|
+
>
|
72
|
+
<Caption
|
73
|
+
marginBottom="xs"
|
74
|
+
textAlign="center"
|
75
|
+
>
|
76
|
+
{"Shadow"}
|
77
|
+
</Caption>
|
78
|
+
<Draggable.Container
|
79
|
+
htmlOptions={{style:{ width: "200px"}}}
|
80
|
+
{...props}
|
81
|
+
>
|
82
|
+
{initialShadowState.map(({ id, text }) => (
|
83
|
+
<Card dragId={id}
|
84
|
+
draggableItem
|
85
|
+
key={id}
|
86
|
+
marginBottom="xs"
|
87
|
+
padding="xs"
|
88
|
+
{...props}
|
89
|
+
>
|
90
|
+
<Flex alignItems="stretch"
|
91
|
+
flexDirection="column"
|
92
|
+
>
|
93
|
+
<Body
|
94
|
+
text={text}
|
95
|
+
{...props}
|
96
|
+
/>
|
97
|
+
</Flex>
|
98
|
+
</Card>
|
99
|
+
))}
|
100
|
+
</Draggable.Container>
|
101
|
+
</DraggableProvider>
|
102
|
+
</FlexItem>
|
103
|
+
<FlexItem marginRight="xl">
|
104
|
+
<DraggableProvider
|
105
|
+
dropZone={{type: "outline"}}
|
106
|
+
initialItems={dataOutline}
|
107
|
+
onReorder={(items) => setInitialOutlineState(items)}
|
108
|
+
>
|
109
|
+
<Caption
|
110
|
+
marginBottom="xs"
|
111
|
+
textAlign="center"
|
112
|
+
>
|
113
|
+
{"Outline"}
|
114
|
+
</Caption>
|
115
|
+
<Draggable.Container
|
116
|
+
htmlOptions={{style:{ width: "200px"}}}
|
117
|
+
{...props}
|
118
|
+
>
|
119
|
+
{initialOutlineState.map(({ id, text }) => (
|
120
|
+
<Card
|
121
|
+
dragId={id}
|
122
|
+
draggableItem
|
123
|
+
key={id}
|
124
|
+
marginBottom="xs"
|
125
|
+
padding="xs"
|
126
|
+
{...props}
|
127
|
+
>
|
128
|
+
<Flex
|
129
|
+
alignItems="stretch"
|
130
|
+
flexDirection="column"
|
131
|
+
>
|
132
|
+
<Body
|
133
|
+
text={text}
|
134
|
+
{...props}
|
135
|
+
/>
|
136
|
+
</Flex>
|
137
|
+
</Card>
|
138
|
+
))}
|
139
|
+
</Draggable.Container>
|
140
|
+
</DraggableProvider>
|
141
|
+
</FlexItem>
|
142
|
+
<FlexItem>
|
143
|
+
<DraggableProvider
|
144
|
+
dropZone={{type: "line"}}
|
145
|
+
initialItems={dataLine}
|
146
|
+
onReorder={(items) => setInitialLineState(items)}
|
147
|
+
>
|
148
|
+
<Caption
|
149
|
+
marginBottom="xs"
|
150
|
+
textAlign="center"
|
151
|
+
>
|
152
|
+
{"Line"}
|
153
|
+
</Caption>
|
154
|
+
<Draggable.Container
|
155
|
+
htmlOptions={{style:{ width: "200px"}}}
|
156
|
+
{...props}
|
157
|
+
>
|
158
|
+
{initialLineState.map(({ id, text }) => (
|
159
|
+
<Card dragId={id}
|
160
|
+
draggableItem
|
161
|
+
key={id}
|
162
|
+
marginBottom="xs"
|
163
|
+
padding="xs"
|
164
|
+
{...props}
|
165
|
+
>
|
166
|
+
<Flex alignItems="stretch"
|
167
|
+
flexDirection="column"
|
168
|
+
>
|
169
|
+
<Body
|
170
|
+
text={text}
|
171
|
+
{...props}
|
172
|
+
/>
|
173
|
+
</Flex>
|
174
|
+
</Card>
|
175
|
+
))}
|
176
|
+
</Draggable.Container>
|
177
|
+
</DraggableProvider>
|
178
|
+
</FlexItem>
|
179
|
+
</Flex>
|
180
|
+
</>
|
181
|
+
);
|
182
|
+
};
|
183
|
+
|
184
|
+
export default DraggableDropZones;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
The Draggable kit allows you to choose the style of drop zones that appear when dragging an item.
|
2
|
+
|
3
|
+
By default, the Draggable kit utilizes the "ghost" style for drop zones, but you can also choose between "shadow", "outline", and "line".
|
4
|
+
|
5
|
+
Additionally, when using the "line" style, be sure to set the proper `direction` attribute within the `dropZone` prop depending on the orentation of your draggable view. By default, this attribute is set to "vertical", but can also be used with a "horizontal" direction. The `direction` attribute only applies to the "line" style and will not affect other drop zone styles.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
|
3
|
+
import Flex from '../../pb_flex/_flex'
|
4
|
+
import Image from '../../pb_image/_image'
|
5
|
+
import Caption from '../../pb_caption/_caption'
|
6
|
+
import Draggable from '../../pb_draggable/_draggable'
|
7
|
+
import { DraggableProvider } from '../../pb_draggable/context'
|
8
|
+
|
9
|
+
// Initial items to be dragged
|
10
|
+
const dataPrimary = [
|
11
|
+
{
|
12
|
+
id: "81",
|
13
|
+
url: "https://unsplash.it/500/400/?image=633",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
id: "82",
|
17
|
+
url: "https://unsplash.it/500/400/?image=634",
|
18
|
+
},
|
19
|
+
{
|
20
|
+
id: "83",
|
21
|
+
url: "https://unsplash.it/500/400/?image=637",
|
22
|
+
},
|
23
|
+
];
|
24
|
+
const dataPurple = [
|
25
|
+
{
|
26
|
+
id: "91",
|
27
|
+
url: "https://unsplash.it/500/400/?image=633",
|
28
|
+
},
|
29
|
+
{
|
30
|
+
id: "92",
|
31
|
+
url: "https://unsplash.it/500/400/?image=634",
|
32
|
+
},
|
33
|
+
{
|
34
|
+
id: "93",
|
35
|
+
url: "https://unsplash.it/500/400/?image=637",
|
36
|
+
},
|
37
|
+
];
|
38
|
+
|
39
|
+
const DraggableDropZonesColors = (props) => {
|
40
|
+
const [initialPrimaryState, setInitialPrimaryState] = useState(dataPrimary);
|
41
|
+
const [initialPurpleState, setInitialPurpleState] = useState(dataPurple);
|
42
|
+
|
43
|
+
return (
|
44
|
+
<>
|
45
|
+
<Caption marginBottom="xs">
|
46
|
+
Primary
|
47
|
+
</Caption>
|
48
|
+
<DraggableProvider
|
49
|
+
dropZone={{type: "shadow", color: "primary"}}
|
50
|
+
initialItems={dataPrimary}
|
51
|
+
onReorder={(items) => setInitialPrimaryState(items)}
|
52
|
+
>
|
53
|
+
<Draggable.Container {...props}>
|
54
|
+
<Flex>
|
55
|
+
{initialPrimaryState.map(({ id, url }) => (
|
56
|
+
<Draggable.Item dragId={id}
|
57
|
+
key={id}
|
58
|
+
marginRight="sm"
|
59
|
+
>
|
60
|
+
<Image alt={id}
|
61
|
+
size="md"
|
62
|
+
url={url}
|
63
|
+
/>
|
64
|
+
</Draggable.Item>
|
65
|
+
))}
|
66
|
+
</Flex>
|
67
|
+
</Draggable.Container>
|
68
|
+
</DraggableProvider>
|
69
|
+
<Caption marginBottom="xs">
|
70
|
+
Purple
|
71
|
+
</Caption>
|
72
|
+
<DraggableProvider
|
73
|
+
dropZone={{type: "outline", color: "purple"}}
|
74
|
+
initialItems={dataPurple}
|
75
|
+
onReorder={(items) => setInitialPurpleState(items)}
|
76
|
+
>
|
77
|
+
<Draggable.Container {...props}>
|
78
|
+
<Flex>
|
79
|
+
{initialPurpleState.map(({ id, url }) => (
|
80
|
+
<Draggable.Item dragId={id}
|
81
|
+
key={id}
|
82
|
+
marginRight="sm"
|
83
|
+
>
|
84
|
+
<Image alt={id}
|
85
|
+
size="md"
|
86
|
+
url={url}
|
87
|
+
/>
|
88
|
+
</Draggable.Item>
|
89
|
+
))}
|
90
|
+
</Flex>
|
91
|
+
</Draggable.Container>
|
92
|
+
</DraggableProvider>
|
93
|
+
</>
|
94
|
+
);
|
95
|
+
};
|
96
|
+
|
97
|
+
export default DraggableDropZonesColors;
|
@@ -0,0 +1 @@
|
|
1
|
+
By default, the Draggable kit sets the default color of drop zones to "neutral" (or "primary" if using the "line" style.)
|
@@ -165,7 +165,7 @@ test("generated dragHandle with List", () => {
|
|
165
165
|
|
166
166
|
const list = kit.querySelector(".pb_list_kit");
|
167
167
|
expect(list).toBeInTheDocument();
|
168
|
-
const dragHandle = list.querySelector(".
|
168
|
+
const dragHandle = list.querySelector(".pb_custom_icon");
|
169
169
|
expect(dragHandle).toBeInTheDocument();
|
170
170
|
});
|
171
171
|
|
@@ -175,7 +175,7 @@ test("generated dragHandle with SelectableList", () => {
|
|
175
175
|
|
176
176
|
const selectabellist = kit.querySelector(".pb_selectable_list_kit");
|
177
177
|
expect(selectabellist).toBeInTheDocument();
|
178
|
-
const dragHandle = selectabellist.querySelector(".
|
178
|
+
const dragHandle = selectabellist.querySelector(".pb_custom_icon");
|
179
179
|
expect(dragHandle).toBeInTheDocument();
|
180
180
|
});
|
181
181
|
|
@@ -185,6 +185,6 @@ test("generated dragHandle with Card", () => {
|
|
185
185
|
|
186
186
|
const card = kit.querySelector(".pb_card_kit_deselected_border_radius_md");
|
187
187
|
expect(card).toBeInTheDocument();
|
188
|
-
const dragHandle = card.querySelector(".
|
188
|
+
const dragHandle = card.querySelector(".pb_custom_icon");
|
189
189
|
expect(dragHandle).toBeInTheDocument();
|
190
190
|
});
|
@@ -22,18 +22,27 @@ type DraggableContainerProps = {
|
|
22
22
|
|
23
23
|
const DraggableContainer = (props: DraggableContainerProps) => {
|
24
24
|
const { aria = {}, children, className, container, data = {}, htmlOptions = {}, id, tag="div" } = props;
|
25
|
+
const contextValues = DraggableContext();
|
26
|
+
const {
|
27
|
+
handleDragOver,
|
28
|
+
handleDrop,
|
29
|
+
activeContainer,
|
30
|
+
dropZone
|
31
|
+
} = contextValues;
|
25
32
|
|
26
|
-
|
33
|
+
// Only get direction if dropZone is 'line'
|
34
|
+
const direction = dropZone === 'line' ? (contextValues.direction || 'vertical') : 'vertical';
|
27
35
|
|
28
36
|
const ariaProps = buildAriaProps(aria);
|
29
37
|
const dataProps = buildDataProps(data);
|
30
38
|
const htmlProps = buildHtmlProps(htmlOptions);
|
31
|
-
|
32
39
|
const Tag: React.ReactElement | any = `${tag}`;
|
33
40
|
|
34
41
|
const classes = classnames(
|
35
42
|
buildCss("pb_draggable_container"),
|
36
43
|
`${activeContainer === container ? "active" : ""}`,
|
44
|
+
// Only add vertical class if dropZone is 'line' and direction is 'vertical'
|
45
|
+
(dropZone === 'line' && direction === 'vertical') ? 'vertical' : '',
|
37
46
|
globalProps(props),
|
38
47
|
className
|
39
48
|
);
|