playbook_ui 13.29.0.pre.alpha.testingcollapsibleissue3052 → 13.30.0.pre.alpha.PBNTR353draggablev53136
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/_playbook.scss +1 -0
- data/app/pb_kits/playbook/index.js +1 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.html.erb +58 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.jsx +68 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_card/_card.scss +5 -0
- data/app/pb_kits/playbook/pb_card/_card.tsx +57 -9
- data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +9 -5
- data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +2 -3
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +2 -4
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +70 -50
- data/app/pb_kits/playbook/pb_draggable/context/types.ts +26 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.jsx +3 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.md +2 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.jsx +13 -8
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.md +1 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.jsx +23 -35
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.md +5 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.jsx +7 -7
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.md +7 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.jsx +11 -9
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.md +7 -0
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +143 -18
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +6 -5
- data/app/pb_kits/playbook/pb_list/_list.tsx +4 -4
- data/app/pb_kits/playbook/pb_list/_list_item.tsx +7 -3
- data/app/pb_kits/playbook/pb_overlay/_overlay.scss +72 -0
- data/app/pb_kits/playbook/pb_overlay/_overlay.tsx +78 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.html.erb +24 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.jsx +40 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.md +7 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.html.erb +11 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.jsx +36 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.md +5 -0
- data/app/pb_kits/playbook/pb_overlay/docs/example.yml +8 -0
- data/app/pb_kits/playbook/pb_overlay/docs/index.js +2 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.html.erb +27 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.rb +110 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.test.jsx +66 -0
- data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_percentage.tsx +57 -0
- data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_token.tsx +48 -0
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.scss +43 -25
- data/app/pb_kits/playbook/pb_selectable_list/_item.tsx +7 -3
- data/app/pb_kits/playbook/pb_selectable_list/_selectable_list.tsx +3 -3
- data/app/pb_kits/playbook/pb_table/docs/_table_alignment_column_rails.html.erb +32 -33
- data/app/pb_kits/playbook/pb_table/table_header.html.erb +0 -2
- data/app/pb_kits/playbook/pb_timeline/_item.tsx +11 -10
- data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +8 -6
- data/app/pb_kits/playbook/playbook-doc.js +2 -0
- data/app/pb_kits/playbook/utilities/globalProps.ts +1 -0
- data/dist/menu.yml +5 -1
- data/dist/playbook-rails.js +6 -6
- data/lib/playbook/kit_base.rb +19 -0
- data/lib/playbook/version.rb +2 -2
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d681e69c84f185b628e40d1d517d5cee70c28972186ee4b47b21641a4ca4637
|
4
|
+
data.tar.gz: 0c5933b2d3d51c8d8c891f4604f1f11447f1edcf5227446b68db72a4b169731e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80a03f749ddd4bf241009567ecc83c161a4cbbefc6779d8db7c2b717242ff4ac536afb263715bae97bca4cfb73bbb2c29d11c8747592ea341bed2b4547572ae2
|
7
|
+
data.tar.gz: 9cdc6ecc0caeab5ee99f8846513121233f191f28c3b9dd1b9bf3c631133f707dbde9bec819db905663ca437fd2ba66a43e03a871e055e74874a61de87059ff00
|
@@ -62,6 +62,7 @@
|
|
62
62
|
@import 'pb_multiple_users_stacked/multiple_users_stacked';
|
63
63
|
@import 'pb_nav/nav';
|
64
64
|
@import 'pb_online_status/online_status';
|
65
|
+
@import 'pb_overlay/overlay';
|
65
66
|
@import 'pb_pagination/pagination';
|
66
67
|
@import 'pb_passphrase/passphrase';
|
67
68
|
@import 'pb_person/person';
|
@@ -72,6 +72,7 @@ export { default as MultipleUsersStacked } from './pb_multiple_users_stacked/_mu
|
|
72
72
|
export { default as Nav } from './pb_nav/_nav'
|
73
73
|
export { default as NavItem } from './pb_nav/_item'
|
74
74
|
export { default as OnlineStatus } from './pb_online_status/_online_status'
|
75
|
+
export { default as Overlay} from './pb_overlay/_overlay'
|
75
76
|
export { default as Passphrase } from './pb_passphrase/_passphrase'
|
76
77
|
export { default as PbReactPopover } from './pb_popover/_popover'
|
77
78
|
export { default as Person } from './pb_person/_person'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<% bar_graph_options = {
|
2
|
+
customOptions: {
|
3
|
+
chart: {
|
4
|
+
type: 'bar'
|
5
|
+
},
|
6
|
+
title: {
|
7
|
+
text: 'Historic World Population by Region',
|
8
|
+
align: 'left'
|
9
|
+
},
|
10
|
+
subtitle: {
|
11
|
+
text: 'Source: <a ' +
|
12
|
+
'href="https://en.wikipedia.org/wiki/List_of_continents_and_continental_subregions_by_population"' +
|
13
|
+
'target="_blank">Wikipedia.org</a>',
|
14
|
+
align: 'left'
|
15
|
+
},
|
16
|
+
xAxis: {
|
17
|
+
categories: ['Africa', 'America', 'Asia', 'Europe'],
|
18
|
+
lineWidth: 0
|
19
|
+
},
|
20
|
+
yAxis: {
|
21
|
+
min: 0,
|
22
|
+
title: {
|
23
|
+
text: 'Population (millions)',
|
24
|
+
align: 'high'
|
25
|
+
},
|
26
|
+
labels: {
|
27
|
+
overflow: 'justify'
|
28
|
+
},
|
29
|
+
},
|
30
|
+
tooltip: {
|
31
|
+
valueSuffix: ' millions'
|
32
|
+
},
|
33
|
+
plotOptions: {
|
34
|
+
bar: {
|
35
|
+
dataLabels: {
|
36
|
+
enabled: true
|
37
|
+
},
|
38
|
+
groupPadding: 0.1
|
39
|
+
}
|
40
|
+
},
|
41
|
+
series: [{
|
42
|
+
name: 'Year 1990',
|
43
|
+
data: [631, 727, 3202, 721]
|
44
|
+
}, {
|
45
|
+
name: 'Year 2000',
|
46
|
+
data: [814, 841, 3714, 726]
|
47
|
+
}, {
|
48
|
+
name: 'Year 2018',
|
49
|
+
data: [1276, 1007, 4561, 746]
|
50
|
+
}]
|
51
|
+
}
|
52
|
+
} %>
|
53
|
+
|
54
|
+
<%= pb_rails("bar_graph", props: {
|
55
|
+
id: "bar-horizontal",
|
56
|
+
y_axis_min: 0,
|
57
|
+
custom_options: bar_graph_options,
|
58
|
+
}) %>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
|
3
|
+
import BarGraph from '../_bar_graph'
|
4
|
+
|
5
|
+
|
6
|
+
const barGraphOptions = {
|
7
|
+
chart: {
|
8
|
+
type: 'bar'
|
9
|
+
},
|
10
|
+
title: {
|
11
|
+
text: 'Historic World Population by Region',
|
12
|
+
align: 'left'
|
13
|
+
},
|
14
|
+
subtitle: {
|
15
|
+
text: 'Source: <a ' +
|
16
|
+
'href="https://en.wikipedia.org/wiki/List_of_continents_and_continental_subregions_by_population"' +
|
17
|
+
'target="_blank">Wikipedia.org</a>',
|
18
|
+
align: 'left'
|
19
|
+
},
|
20
|
+
xAxis: {
|
21
|
+
categories: ['Africa', 'America', 'Asia', 'Europe'],
|
22
|
+
lineWidth: 0
|
23
|
+
},
|
24
|
+
yAxis: {
|
25
|
+
min: 0,
|
26
|
+
title: {
|
27
|
+
text: 'Population (millions)',
|
28
|
+
align: 'high'
|
29
|
+
},
|
30
|
+
labels: {
|
31
|
+
overflow: 'justify'
|
32
|
+
},
|
33
|
+
},
|
34
|
+
tooltip: {
|
35
|
+
valueSuffix: ' millions'
|
36
|
+
},
|
37
|
+
plotOptions: {
|
38
|
+
bar: {
|
39
|
+
dataLabels: {
|
40
|
+
enabled: true
|
41
|
+
},
|
42
|
+
groupPadding: 0.1
|
43
|
+
}
|
44
|
+
},
|
45
|
+
series: [{
|
46
|
+
name: 'Year 1990',
|
47
|
+
data: [631, 727, 3202, 721]
|
48
|
+
}, {
|
49
|
+
name: 'Year 2000',
|
50
|
+
data: [814, 841, 3714, 726]
|
51
|
+
}, {
|
52
|
+
name: 'Year 2018',
|
53
|
+
data: [1276, 1007, 4561, 746]
|
54
|
+
}]
|
55
|
+
}
|
56
|
+
|
57
|
+
const BarGraphHorizontal = (props) => (
|
58
|
+
<div>
|
59
|
+
<BarGraph
|
60
|
+
customOptions={barGraphOptions}
|
61
|
+
id="bar-horizontal"
|
62
|
+
yAxisMin={0}
|
63
|
+
{...props}
|
64
|
+
/>
|
65
|
+
</div>
|
66
|
+
)
|
67
|
+
|
68
|
+
export default BarGraphHorizontal
|
@@ -12,6 +12,7 @@ examples:
|
|
12
12
|
- bar_graph_stacked: Stacked
|
13
13
|
- bar_graph_negative_numbers: Negative Numbers
|
14
14
|
- bar_graph_secondary_y_axis: Secondary Y-Axis
|
15
|
+
- bar_graph_horizontal: Custom Options From Highcharts
|
15
16
|
|
16
17
|
|
17
18
|
react:
|
@@ -26,3 +27,4 @@ examples:
|
|
26
27
|
- bar_graph_stacked: Stacked
|
27
28
|
- bar_graph_negative_numbers: Negative Numbers
|
28
29
|
- bar_graph_secondary_y_axis: Secondary Y-Axis
|
30
|
+
- bar_graph_horizontal: Custom Options From Highcharts
|
@@ -9,3 +9,4 @@ export { default as BarGraphCustom } from './_bar_graph_custom.jsx'
|
|
9
9
|
export { default as BarGraphStacked } from './_bar_graph_stacked.jsx'
|
10
10
|
export { default as BarGraphNegativeNumbers } from './_bar_graph_negative_numbers.jsx'
|
11
11
|
export { default as BarGraphSecondaryYAxis } from './_bar_graph_secondary_y_axis.jsx'
|
12
|
+
export { default as BarGraphHorizontal } from './_bar_graph_horizontal.jsx'
|
@@ -8,6 +8,10 @@ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../uti
|
|
8
8
|
import { GlobalProps, globalProps } from '../utilities/globalProps'
|
9
9
|
import type { ProductColors, CategoryColors, BackgroundColors } from '../types/colors'
|
10
10
|
|
11
|
+
import Icon from '../pb_icon/_icon'
|
12
|
+
import Flex from '../pb_flex/_flex'
|
13
|
+
import Draggable from '../pb_draggable/_draggable'
|
14
|
+
|
11
15
|
type CardPropTypes = {
|
12
16
|
aria?: {[key: string]: string},
|
13
17
|
background?: BackgroundColors | ProductColors | "none",
|
@@ -16,11 +20,15 @@ type CardPropTypes = {
|
|
16
20
|
children: React.ReactChild[] | React.ReactChild | number,
|
17
21
|
className?: string,
|
18
22
|
data?: {[key: string]: string},
|
23
|
+
dragId?: string,
|
24
|
+
draggableItem?: boolean,
|
25
|
+
dragHandle?: boolean,
|
19
26
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
20
27
|
highlight?: {
|
21
28
|
position?: "side" | "top",
|
22
29
|
color?: string,
|
23
30
|
},
|
31
|
+
id?: string,
|
24
32
|
length?: number,
|
25
33
|
padding?: string,
|
26
34
|
selected?: boolean,
|
@@ -78,6 +86,9 @@ const Card = (props: CardPropTypes): React.ReactElement => {
|
|
78
86
|
children,
|
79
87
|
className,
|
80
88
|
data = {},
|
89
|
+
dragId,
|
90
|
+
dragHandle = true,
|
91
|
+
draggableItem = false,
|
81
92
|
highlight = {},
|
82
93
|
htmlOptions = {},
|
83
94
|
selected = false,
|
@@ -113,15 +124,52 @@ const Card = (props: CardPropTypes): React.ReactElement => {
|
|
113
124
|
const Tag = tagOptions.includes(tag) ? tag : 'div'
|
114
125
|
|
115
126
|
return (
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
{
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
127
|
+
<>
|
128
|
+
{
|
129
|
+
draggableItem ? (
|
130
|
+
<Draggable.Item dragId={dragId}
|
131
|
+
key={dragId}
|
132
|
+
>
|
133
|
+
<Tag
|
134
|
+
{...ariaProps}
|
135
|
+
{...dataProps}
|
136
|
+
{...htmlProps}
|
137
|
+
className={classnames(cardCss, globalProps(props), className)}
|
138
|
+
>
|
139
|
+
{subComponentTags('Header')}
|
140
|
+
{
|
141
|
+
dragHandle ? (
|
142
|
+
<Flex>
|
143
|
+
<span className="card_draggable_handle">
|
144
|
+
<Icon
|
145
|
+
icon="grip-dots-vertical"
|
146
|
+
paddingRight="xs"
|
147
|
+
verticalAlign="middle"
|
148
|
+
/>
|
149
|
+
</span>
|
150
|
+
<div style={{width: '100%'}}>
|
151
|
+
{nonHeaderChildren}
|
152
|
+
</div>
|
153
|
+
</Flex>
|
154
|
+
) : (
|
155
|
+
nonHeaderChildren
|
156
|
+
)
|
157
|
+
}
|
158
|
+
</Tag>
|
159
|
+
</Draggable.Item>
|
160
|
+
) : (
|
161
|
+
<Tag
|
162
|
+
{...ariaProps}
|
163
|
+
{...dataProps}
|
164
|
+
{...htmlProps}
|
165
|
+
className={classnames(cardCss, globalProps(props), className)}
|
166
|
+
>
|
167
|
+
{subComponentTags('Header')}
|
168
|
+
{nonHeaderChildren}
|
169
|
+
</Tag>
|
170
|
+
)
|
171
|
+
}
|
172
|
+
</>
|
125
173
|
)
|
126
174
|
}
|
127
175
|
|
@@ -46,16 +46,20 @@ type CircleChartProps = {
|
|
46
46
|
borderWidth?: number;
|
47
47
|
};
|
48
48
|
|
49
|
-
|
49
|
+
|
50
|
+
|
50
51
|
const alignBlockElement = (event: any) => {
|
51
|
-
const itemToMove = document.querySelector(
|
52
|
+
const itemToMove = document.querySelector<HTMLElement>(
|
52
53
|
`#wrapper-circle-chart-${event.target.renderTo.id} .pb-circle-chart-block`
|
53
|
-
)
|
54
|
+
);
|
54
55
|
const chartContainer = document.querySelector(`#${event.target.renderTo.id}`);
|
55
|
-
|
56
|
+
|
57
|
+
if (itemToMove !== null && chartContainer !== null) {
|
56
58
|
itemToMove.style.height = `${event.target.chartHeight}px`;
|
57
59
|
itemToMove.style.width = `${event.target.chartWidth}px`;
|
58
|
-
chartContainer.firstChild
|
60
|
+
if (chartContainer.firstChild !== null) {
|
61
|
+
chartContainer.firstChild.before(itemToMove);
|
62
|
+
}
|
59
63
|
}
|
60
64
|
};
|
61
65
|
|
@@ -37,7 +37,6 @@
|
|
37
37
|
</div>
|
38
38
|
|
39
39
|
<%= javascript_tag do %>
|
40
|
-
window.addEventListener("DOMContentLoaded", () =>
|
41
|
-
|
42
|
-
})
|
40
|
+
window.addEventListener("DOMContentLoaded", () => dialogHelper())
|
41
|
+
window.addEventListener("turbo:frame-load", () => dialogHelper())
|
43
42
|
<% end %>
|
@@ -1,90 +1,110 @@
|
|
1
|
-
import React, { createContext,
|
1
|
+
import React, { createContext, useReducer, useContext, useEffect, useMemo } from "react";
|
2
|
+
import { InitialStateType, ActionType, DraggableProviderType } from "./types";
|
3
|
+
|
4
|
+
const initialState: InitialStateType = {
|
5
|
+
items: [],
|
6
|
+
dragData: { id: "", initialGroup: "" },
|
7
|
+
isDragging: "",
|
8
|
+
activeContainer: ""
|
9
|
+
};
|
10
|
+
|
11
|
+
const reducer = (state: InitialStateType, action: ActionType) => {
|
12
|
+
switch (action.type) {
|
13
|
+
case 'SET_ITEMS':
|
14
|
+
return { ...state, items: action.payload };
|
15
|
+
case 'SET_DRAG_DATA':
|
16
|
+
return { ...state, dragData: action.payload };
|
17
|
+
case 'SET_IS_DRAGGING':
|
18
|
+
return { ...state, isDragging: action.payload };
|
19
|
+
case 'SET_ACTIVE_CONTAINER':
|
20
|
+
return { ...state, activeContainer: action.payload };
|
21
|
+
case 'CHANGE_CATEGORY':
|
22
|
+
return {
|
23
|
+
...state,
|
24
|
+
items: state.items.map(item =>
|
25
|
+
item.id === action.payload.itemId
|
26
|
+
? { ...item, container: action.payload.container }
|
27
|
+
: item
|
28
|
+
)
|
29
|
+
};
|
30
|
+
case 'REORDER_ITEMS': {
|
31
|
+
const { dragId, targetId } = action.payload;
|
32
|
+
const newItems = [...state.items];
|
33
|
+
const draggedItem = newItems.find(item => item.id === dragId);
|
34
|
+
const draggedIndex = newItems.indexOf(draggedItem);
|
35
|
+
const targetIndex = newItems.findIndex(item => item.id === targetId);
|
36
|
+
|
37
|
+
newItems.splice(draggedIndex, 1);
|
38
|
+
newItems.splice(targetIndex, 0, draggedItem);
|
2
39
|
|
40
|
+
return { ...state, items: newItems };
|
41
|
+
}
|
42
|
+
default:
|
43
|
+
return state;
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
// Context and Provider
|
3
48
|
const DragContext = createContext<any>({});
|
4
49
|
|
5
50
|
export const DraggableContext = () => {
|
6
51
|
return useContext(DragContext);
|
7
52
|
};
|
8
53
|
|
9
|
-
export const DraggableProvider = ({ children, initialItems,
|
10
|
-
const [
|
11
|
-
const [dragData, setDragData] = useState<{ [key: string]: any }>({});
|
12
|
-
const [isDragging, setIsDragging] = useState("");
|
13
|
-
const [activeContainer, setActiveContainer] = useState("");
|
54
|
+
export const DraggableProvider = ({ children, initialItems, onReorder }: DraggableProviderType) => {
|
55
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
14
56
|
|
15
57
|
useEffect(() => {
|
16
|
-
|
58
|
+
dispatch({ type: 'SET_ITEMS', payload: initialItems });
|
17
59
|
}, [initialItems]);
|
18
60
|
|
19
61
|
useEffect(() => {
|
20
|
-
|
21
|
-
}, [items]);
|
62
|
+
onReorder(state.items);
|
63
|
+
}, [state.items]);
|
22
64
|
|
23
65
|
const handleDragStart = (id: string, container: string) => {
|
24
|
-
|
25
|
-
|
66
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: id, initialGroup: container } });
|
67
|
+
dispatch({ type: 'SET_IS_DRAGGING', payload: id });
|
26
68
|
};
|
27
69
|
|
28
70
|
const handleDragEnter = (id: string, container: string) => {
|
29
|
-
if (dragData
|
30
|
-
|
31
|
-
|
32
|
-
const draggedIndex = newItems.indexOf(draggedItem);
|
33
|
-
const targetIndex = newItems.findIndex((item) => item.id === id);
|
34
|
-
|
35
|
-
newItems.splice(draggedIndex, 1);
|
36
|
-
newItems.splice(targetIndex, 0, draggedItem);
|
37
|
-
|
38
|
-
setItems(newItems);
|
39
|
-
setDragData({ id: dragData.id, initialGroup: container });
|
71
|
+
if (state.dragData.id !== id) {
|
72
|
+
dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
|
73
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: state.dragData.id, initialGroup: container } });
|
40
74
|
}
|
41
75
|
};
|
42
76
|
|
43
77
|
const handleDragEnd = () => {
|
44
|
-
|
45
|
-
|
78
|
+
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
79
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
46
80
|
};
|
47
81
|
|
48
82
|
const changeCategory = (itemId: string, container: string) => {
|
49
|
-
|
50
|
-
if (item.id === itemId) {
|
51
|
-
return { ...item, container: container };
|
52
|
-
}
|
53
|
-
return item;
|
54
|
-
});
|
55
|
-
|
56
|
-
setItems(updatedItems);
|
83
|
+
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId, container } });
|
57
84
|
};
|
58
85
|
|
59
86
|
const handleDrop = (container: string) => {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
changeCategory(selected, container);
|
87
|
+
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
88
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
89
|
+
changeCategory(state.dragData.id, container);
|
64
90
|
};
|
65
91
|
|
66
92
|
const handleDragOver = (e: Event, container: string) => {
|
67
93
|
e.preventDefault();
|
68
|
-
|
94
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
69
95
|
};
|
70
96
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
dragData,
|
77
|
-
setDragData,
|
78
|
-
isDragging,
|
79
|
-
setIsDragging,
|
80
|
-
activeContainer,
|
81
|
-
setActiveContainer,
|
97
|
+
const contextValue = useMemo(() => ({
|
98
|
+
items: state.items,
|
99
|
+
dragData: state.dragData,
|
100
|
+
isDragging: state.isDragging,
|
101
|
+
activeContainer: state.activeContainer,
|
82
102
|
handleDragStart,
|
83
103
|
handleDragEnter,
|
84
104
|
handleDragEnd,
|
85
105
|
handleDrop,
|
86
|
-
handleDragOver
|
87
|
-
};
|
106
|
+
handleDragOver
|
107
|
+
}), [state]);
|
88
108
|
|
89
109
|
return (
|
90
110
|
<DragContext.Provider value={contextValue}>{children}</DragContext.Provider>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
export interface ItemType {
|
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 DraggableProviderType {
|
23
|
+
children: React.ReactNode;
|
24
|
+
initialItems: ItemType[];
|
25
|
+
onReorder: (items: ItemType[]) => void;
|
26
|
+
}
|
@@ -27,18 +27,19 @@ const DraggableDefault = (props) => {
|
|
27
27
|
return (
|
28
28
|
<>
|
29
29
|
<DraggableProvider initialItems={data}
|
30
|
-
|
30
|
+
onReorder={(items) => setInitialState(items)}
|
31
31
|
>
|
32
32
|
<Draggable.Container {...props}>
|
33
33
|
<SelectableList variant="checkbox">
|
34
34
|
{initialState.map(({ id, text }) => (
|
35
|
-
<Draggable.Item
|
35
|
+
<Draggable.Item dragId={id}
|
36
36
|
key={id}
|
37
37
|
>
|
38
38
|
<SelectableList.Item
|
39
39
|
label={text}
|
40
40
|
name={id}
|
41
41
|
value={id}
|
42
|
+
{...props}
|
42
43
|
/>
|
43
44
|
</Draggable.Item>
|
44
45
|
))}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
To use the Draggable kit, you must use the DraggableProvider and pass in `initialItems`. The `
|
1
|
+
To use the Draggable kit, you must use the DraggableProvider and pass in `initialItems`. The `onReorder` is a function that returns the data as it changes as items are reordered. Use this to manage state as shown.
|
2
2
|
|
3
3
|
The `Draggable.Container` specifies the container within which items can be dropped.
|
4
|
-
The `Draggable.Item` specifies the items that can be dragged and dropped. `
|
4
|
+
The `Draggable.Item` specifies the items that can be dragged and dropped. `dragId` is a REQUIRED prop for Draggable.Item.
|
@@ -18,7 +18,7 @@ const containers = ["To Do", "In Progress", "Done"];
|
|
18
18
|
// Initial items to be dragged
|
19
19
|
const data = [
|
20
20
|
{
|
21
|
-
id: "
|
21
|
+
id: "11",
|
22
22
|
container: "To Do",
|
23
23
|
title: "Task 1",
|
24
24
|
description: "Bug fixes",
|
@@ -26,7 +26,7 @@ const data = [
|
|
26
26
|
assignee_img: "https://randomuser.me/api/portraits/men/44.jpg",
|
27
27
|
},
|
28
28
|
{
|
29
|
-
id: "
|
29
|
+
id: "12",
|
30
30
|
container: "To Do",
|
31
31
|
title: "Task 2",
|
32
32
|
description: "Documentation",
|
@@ -34,7 +34,7 @@ const data = [
|
|
34
34
|
assignee_img: "https://randomuser.me/api/portraits/women/8.jpg",
|
35
35
|
},
|
36
36
|
{
|
37
|
-
id: "
|
37
|
+
id: "13",
|
38
38
|
container: "In Progress",
|
39
39
|
title: "Task 3",
|
40
40
|
description: "Add a variant",
|
@@ -42,7 +42,7 @@ const data = [
|
|
42
42
|
assignee_img: "https://randomuser.me/api/portraits/women/10.jpg",
|
43
43
|
},
|
44
44
|
{
|
45
|
-
id: "
|
45
|
+
id: "14",
|
46
46
|
container: "To Do",
|
47
47
|
title: "Task 4",
|
48
48
|
description: "Add jest tests",
|
@@ -50,7 +50,7 @@ const data = [
|
|
50
50
|
assignee_img: "https://randomuser.me/api/portraits/men/8.jpg",
|
51
51
|
},
|
52
52
|
{
|
53
|
-
id: "
|
53
|
+
id: "15",
|
54
54
|
container: "Done",
|
55
55
|
title: "Task 5",
|
56
56
|
description: "Alpha testing",
|
@@ -58,7 +58,7 @@ const data = [
|
|
58
58
|
assignee_img: "https://randomuser.me/api/portraits/men/18.jpg",
|
59
59
|
},
|
60
60
|
{
|
61
|
-
id: "
|
61
|
+
id: "16",
|
62
62
|
container: "In Progress",
|
63
63
|
title: "Task 6",
|
64
64
|
description: "Release",
|
@@ -83,7 +83,7 @@ const DraggableMultipleContainer = (props) => {
|
|
83
83
|
|
84
84
|
return (
|
85
85
|
<DraggableProvider initialItems={data}
|
86
|
-
|
86
|
+
onReorder={(items) => setInitialState(items)}
|
87
87
|
>
|
88
88
|
<Flex
|
89
89
|
justifyContent="center"
|
@@ -92,6 +92,7 @@ const DraggableMultipleContainer = (props) => {
|
|
92
92
|
{containers?.map((container) => (
|
93
93
|
<Draggable.Container
|
94
94
|
container={container}
|
95
|
+
htmlOptions={{style:{ width: "200px", height: "70vh"}}}
|
95
96
|
key={container}
|
96
97
|
padding="sm"
|
97
98
|
>
|
@@ -112,12 +113,13 @@ const DraggableMultipleContainer = (props) => {
|
|
112
113
|
}) => (
|
113
114
|
<Draggable.Item
|
114
115
|
container={container}
|
115
|
-
|
116
|
+
dragId={id}
|
116
117
|
key={id}
|
117
118
|
>
|
118
119
|
<Card
|
119
120
|
marginBottom="sm"
|
120
121
|
padding="sm"
|
122
|
+
{...props}
|
121
123
|
>
|
122
124
|
<Flex justify="between">
|
123
125
|
<FlexItem>
|
@@ -130,6 +132,7 @@ const DraggableMultipleContainer = (props) => {
|
|
130
132
|
<Title paddingLeft="xs"
|
131
133
|
size={4}
|
132
134
|
text={title}
|
135
|
+
{...props}
|
133
136
|
/>
|
134
137
|
</Flex>
|
135
138
|
</FlexItem>
|
@@ -138,10 +141,12 @@ const DraggableMultipleContainer = (props) => {
|
|
138
141
|
rounded
|
139
142
|
text={badgeProperties(container).text}
|
140
143
|
variant={badgeProperties(container).color}
|
144
|
+
{...props}
|
141
145
|
/>
|
142
146
|
</Flex>
|
143
147
|
<Body paddingTop="xs"
|
144
148
|
text={description}
|
149
|
+
{...props}
|
145
150
|
/>
|
146
151
|
</Card>
|
147
152
|
</Draggable.Item>
|
@@ -0,0 +1 @@
|
|
1
|
+
The Draggable kit can also be used to achieve more complex, multiple container functionality as shown here. This complex usage requires the full subcomponent structure.
|