playbook_ui 13.29.0 → 13.30.0.pre.alpha.PBNTR353draggablev53136

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +1 -0
  3. data/app/pb_kits/playbook/index.js +1 -0
  4. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.html.erb +58 -0
  5. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.jsx +68 -0
  6. data/app/pb_kits/playbook/pb_bar_graph/docs/example.yml +2 -0
  7. data/app/pb_kits/playbook/pb_bar_graph/docs/index.js +1 -0
  8. data/app/pb_kits/playbook/pb_card/_card.scss +5 -0
  9. data/app/pb_kits/playbook/pb_card/_card.tsx +57 -9
  10. data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +9 -5
  11. data/app/pb_kits/playbook/pb_collapsible/_collapsible.tsx +2 -6
  12. data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +2 -3
  13. data/app/pb_kits/playbook/pb_draggable/_draggable.scss +2 -4
  14. data/app/pb_kits/playbook/pb_draggable/context/index.tsx +70 -50
  15. data/app/pb_kits/playbook/pb_draggable/context/types.ts +26 -0
  16. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.jsx +3 -2
  17. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.md +2 -2
  18. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.jsx +13 -8
  19. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.md +1 -0
  20. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.jsx +23 -35
  21. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.md +5 -0
  22. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.jsx +7 -7
  23. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.md +7 -1
  24. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.jsx +11 -9
  25. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.md +7 -0
  26. data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +143 -18
  27. data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +6 -5
  28. data/app/pb_kits/playbook/pb_list/_list.tsx +4 -4
  29. data/app/pb_kits/playbook/pb_list/_list_item.tsx +7 -3
  30. data/app/pb_kits/playbook/pb_overlay/_overlay.scss +72 -0
  31. data/app/pb_kits/playbook/pb_overlay/_overlay.tsx +78 -0
  32. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.html.erb +24 -0
  33. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.jsx +40 -0
  34. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.md +7 -0
  35. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.html.erb +11 -0
  36. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.jsx +36 -0
  37. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.md +5 -0
  38. data/app/pb_kits/playbook/pb_overlay/docs/example.yml +8 -0
  39. data/app/pb_kits/playbook/pb_overlay/docs/index.js +2 -0
  40. data/app/pb_kits/playbook/pb_overlay/overlay.html.erb +27 -0
  41. data/app/pb_kits/playbook/pb_overlay/overlay.rb +110 -0
  42. data/app/pb_kits/playbook/pb_overlay/overlay.test.jsx +66 -0
  43. data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_percentage.tsx +57 -0
  44. data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_token.tsx +48 -0
  45. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.scss +43 -25
  46. data/app/pb_kits/playbook/pb_selectable_list/_item.tsx +7 -3
  47. data/app/pb_kits/playbook/pb_selectable_list/_selectable_list.tsx +3 -3
  48. data/app/pb_kits/playbook/pb_table/docs/_table_alignment_column_rails.html.erb +32 -33
  49. data/app/pb_kits/playbook/pb_table/table_header.html.erb +0 -2
  50. data/app/pb_kits/playbook/pb_timeline/_item.tsx +11 -10
  51. data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +8 -6
  52. data/app/pb_kits/playbook/playbook-doc.js +2 -0
  53. data/app/pb_kits/playbook/utilities/globalProps.ts +1 -0
  54. data/dist/menu.yml +5 -1
  55. data/dist/playbook-rails.js +6 -6
  56. data/lib/playbook/kit_base.rb +19 -0
  57. data/lib/playbook/version.rb +2 -2
  58. metadata +26 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 699fcf293689b40e1140baca1e97a25053e322b9a4ca658717617798da963051
4
- data.tar.gz: ef6ec517ea86e4440ee1bc196b05f9e449c7f1b9cd17dad24875193f1f5474d6
3
+ metadata.gz: 9d681e69c84f185b628e40d1d517d5cee70c28972186ee4b47b21641a4ca4637
4
+ data.tar.gz: 0c5933b2d3d51c8d8c891f4604f1f11447f1edcf5227446b68db72a4b169731e
5
5
  SHA512:
6
- metadata.gz: b5bae58e45a15ac46583dcbe34055089959cd988b1dc9f430340b550e35567d397dfd9a803f12ae4c4e7f14fdfa4cb1ae019f5cf085eb86c632644a655a188e1
7
- data.tar.gz: 6e38e6533e9b495cdd3b7c2b85c37a57c37b4174eadbff01c77f939a65d67944d84e0db24af5247e7586374b1ce04314403e98570e1742feb68e8aaf68297b84
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'
@@ -81,4 +81,9 @@
81
81
  }
82
82
  }
83
83
  }
84
+
85
+ .card_draggable_handle {
86
+ align-self: center;
87
+ color: $text_lt_light;
88
+ }
84
89
  }
@@ -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
- <Tag
117
- {...ariaProps}
118
- {...dataProps}
119
- {...htmlProps}
120
- className={classnames(cardCss, globalProps(props), className)}
121
- >
122
- {subComponentTags('Header')}
123
- {nonHeaderChildren}
124
- </Tag>
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
- // Adjust Circle Chart Block Kit Dimensions to Match the Chart for Centering
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
- ) as HTMLElement;
54
+ );
54
55
  const chartContainer = document.querySelector(`#${event.target.renderTo.id}`);
55
- if (itemToMove !== null) {
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.before(itemToMove);
60
+ if (chartContainer.firstChild !== null) {
61
+ chartContainer.firstChild.before(itemToMove);
62
+ }
59
63
  }
60
64
  };
61
65
 
@@ -60,14 +60,13 @@ const Collapsible = ({
60
60
  }
61
61
 
62
62
  const FirstChild = children[0]
63
- const SecondChild = children[1]
64
63
 
65
64
  const Main = FirstChild.type === CollapsibleMain ? FirstChild : null
66
- const Content = SecondChild.type === CollapsibleContent ? SecondChild : null
65
+ const Content = children[1]
67
66
 
68
67
 
69
68
  const { children: mainChildren = null, ...mainProps } = Main ? Main.props : {}
70
- const { children: contentChildren = null, ...contentProps } = Content ? Content.props : {}
69
+ const { children: contentChildren, ...contentProps } = Content.props
71
70
  const ariaProps = buildAriaProps(aria)
72
71
  const dataProps = buildDataProps(data)
73
72
  const htmlProps = buildHtmlProps(htmlOptions)
@@ -92,12 +91,9 @@ const Collapsible = ({
92
91
  ) : (
93
92
  FirstChild
94
93
  )}
95
-
96
- {Content && (
97
94
  <CollapsibleContent {...contentProps}>
98
95
  {contentChildren}
99
96
  </CollapsibleContent>
100
- )}
101
97
  </div>
102
98
  </CollapsibleContext.Provider>
103
99
  )
@@ -37,7 +37,6 @@
37
37
  </div>
38
38
 
39
39
  <%= javascript_tag do %>
40
- window.addEventListener("DOMContentLoaded", () => {
41
- dialogHelper()
42
- })
40
+ window.addEventListener("DOMContentLoaded", () => dialogHelper())
41
+ window.addEventListener("turbo:frame-load", () => dialogHelper())
43
42
  <% end %>
@@ -1,11 +1,9 @@
1
1
  @import "../tokens/colors";
2
+ @import "../tokens/opacity";
2
3
 
3
4
  .pb_draggable_container {
4
5
  .is_dragging {
5
- opacity: 40%;
6
- }
7
- .active {
8
- opacity: 60%;
6
+ opacity: $opacity_4;
9
7
  }
10
8
  .pb_draggable_item:hover {
11
9
  cursor: grab;
@@ -1,90 +1,110 @@
1
- import React, { createContext, useState, useContext, useEffect } from "react";
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, onChange }: any) => {
10
- const [items, setItems] = useState([]);
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
- setItems(initialItems);
58
+ dispatch({ type: 'SET_ITEMS', payload: initialItems });
17
59
  }, [initialItems]);
18
60
 
19
61
  useEffect(() => {
20
- onChange(items);
21
- }, [items]);
62
+ onReorder(state.items);
63
+ }, [state.items]);
22
64
 
23
65
  const handleDragStart = (id: string, container: string) => {
24
- setDragData({ id: id, initialGroup: container });
25
- setIsDragging(id);
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?.id !== id) {
30
- const newItems = [...items];
31
- const draggedItem = newItems.find((item) => item.id === dragData.id);
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
- setIsDragging("");
45
- setActiveContainer("");
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
- const updatedItems = items.map((item) => {
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
- setIsDragging("");
61
- setActiveContainer("");
62
- const selected = dragData.id;
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
- setActiveContainer(container);
94
+ dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
69
95
  };
70
96
 
71
-
72
-
73
- const contextValue = {
74
- items,
75
- setItems,
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
- onChange={(items) => setInitialState(items)}
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 id={id}
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 `onChange` is a function that returns the data as it changes as items are reordered. Use this to manage state as shown.
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. `Draggable.Item` requires `id` to be passed in as shown.
4
+ The `Draggable.Item` specifies the items that can be dragged and dropped. `dragId` is a REQUIRED prop for Draggable.Item.