playbook_ui 13.30.0 → 13.31.0.pre.alpha.play1262iconstyles3172
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/docs/_advanced_table_beta_sort.html.erb +59 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_sort.md +6 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +3 -2
- data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +4 -4
- data/app/pb_kits/playbook/pb_card/_card.tsx +4 -3
- data/app/pb_kits/playbook/pb_collapsible/__snapshots__/collapsible.test.js.snap +1 -1
- data/app/pb_kits/playbook/pb_collapsible/index.js +6 -1
- data/app/pb_kits/playbook/pb_date_time_stacked/docs/_date_time_stacked_default_swift.md +33 -0
- data/app/pb_kits/playbook/pb_date_time_stacked/docs/_date_time_stacked_props_swift.md +18 -0
- data/app/pb_kits/playbook/pb_date_time_stacked/docs/example.yml +6 -1
- 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 +2 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.md +1 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.jsx +5 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.jsx +11 -4
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.md +4 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.jsx +2 -2
- 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 +6 -4
- 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 +142 -15
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +6 -5
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +18 -0
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +228 -218
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_error.html.erb +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_error.jsx +34 -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/dropdown.html.erb +14 -12
- data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +7 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +17 -2
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/_fixed_confirmation_toast.tsx +9 -3
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/_fixed_confirmation_toast_custom_icon.html.erb +32 -0
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/_fixed_confirmation_toast_custom_icon.jsx +48 -0
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.rb +16 -11
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.test.js +72 -0
- data/app/pb_kits/playbook/pb_icon/_icon.scss +211 -1
- data/app/pb_kits/playbook/pb_icon/_icon.tsx +136 -13
- data/app/pb_kits/playbook/pb_icon/docs/_icon_default.html.erb +1 -1
- data/app/pb_kits/playbook/pb_icon/docs/_icon_default.jsx +2 -3
- data/app/pb_kits/playbook/pb_icon/icon.rb +43 -17
- data/app/pb_kits/playbook/pb_icon/icon_aliases.json +39 -0
- 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_nav/_nav_item.test.js +2 -2
- data/app/pb_kits/playbook/pb_nav/docs/_collapsible_nav.html.erb +1 -1
- data/app/pb_kits/playbook/pb_nav/docs/_collapsible_nav.jsx +1 -0
- data/app/pb_kits/playbook/pb_nav/docs/_collapsible_nav.md +3 -1
- data/app/pb_kits/playbook/pb_nav/item.html.erb +1 -1
- data/app/pb_kits/playbook/pb_nav/item.rb +1 -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.md +4 -4
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.html.erb +11 -0
- data/app/pb_kits/playbook/pb_overlay/docs/example.yml +4 -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_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/table_header.html.erb +16 -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/utilities/globalProps.ts +1 -0
- data/dist/menu.yml +2 -2
- data/dist/playbook-rails.js +7 -7
- data/lib/playbook/version.rb +2 -2
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40926fc2e7c733b41e34cd183f1e0ba98adf9c136615f73415a64a88bdcd7ef5
|
4
|
+
data.tar.gz: '038a9914dad8b716dbb6bcd3cc9c73ff2c4b5b3f59ee578130903e68e791a5ea'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cad3db04fdc0cd38b2896803be0002f866cf654a0c21e61f21fcf26dda0de2a0819324245f606e2a5b28a1da0f70d8a66a89a6961a5d3c3403557e45dd322130
|
7
|
+
data.tar.gz: 1099544d9ecf11f27874c3939ab83aaf50e9b7f09cae1459eecf06bfea553782f1b98ec0936ef92211ea9ed3822d325aff0259b418d118f6411fb0bfa17e89bd
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<%# Example sort method for demonstration purposes %>
|
2
|
+
<% if params["sort"] %>
|
3
|
+
<% sort_param = params["sort"].gsub(/_(asc|desc)\z/, "") %>
|
4
|
+
<% sort_direction = params["sort"].end_with?("_asc") ? 1 : -1 %>
|
5
|
+
<% @table_data.sort! do |a, b|
|
6
|
+
value_a = a[sort_param]
|
7
|
+
value_b = b[sort_param]
|
8
|
+
|
9
|
+
value_a = value_a.to_i if value_a.is_a?(String) && value_a.match?(/^\d+$/)
|
10
|
+
value_b = value_b.to_i if value_b.is_a?(String) && value_b.match?(/^\d+$/)
|
11
|
+
|
12
|
+
sort_direction * (value_a <=> value_b)
|
13
|
+
end %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<%
|
17
|
+
column_definitions = [
|
18
|
+
{
|
19
|
+
accessor: "year",
|
20
|
+
label: "Year",
|
21
|
+
cellAccessors: ["quarter", "month", "day"],
|
22
|
+
sort_menu: [
|
23
|
+
{ item: "Year", link: "?sort=year_asc#table-sort", active: params["sort"] == "year_asc", direction: "asc" },
|
24
|
+
{ item: "Year", link: "?sort=year_desc#table-sort", active: params["sort"] == "year_desc", direction: "desc" }
|
25
|
+
],
|
26
|
+
},
|
27
|
+
{
|
28
|
+
accessor: "newEnrollments",
|
29
|
+
label: "New Enrollments",
|
30
|
+
},
|
31
|
+
{
|
32
|
+
accessor: "scheduledMeetings",
|
33
|
+
label: "Scheduled Meetings",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
accessor: "attendanceRate",
|
37
|
+
label: "Attendance Rate",
|
38
|
+
},
|
39
|
+
{
|
40
|
+
accessor: "completedClasses",
|
41
|
+
label: "Completed Classes",
|
42
|
+
},
|
43
|
+
{
|
44
|
+
accessor: "classCompletionRate",
|
45
|
+
label: "Class Completion Rate",
|
46
|
+
},
|
47
|
+
{
|
48
|
+
accessor: "graduatedStudents",
|
49
|
+
label: "Graduated Students",
|
50
|
+
}
|
51
|
+
]
|
52
|
+
|
53
|
+
subrow_headers = ["Quarter", "Month", "Day"]
|
54
|
+
%>
|
55
|
+
|
56
|
+
<%= pb_rails("advanced_table", props: { table_data: @table_data, column_definitions: column_definitions }) do %>
|
57
|
+
<%= pb_rails("advanced_table/table_header", props: { column_definitions: column_definitions }) %>
|
58
|
+
<%= pb_rails("advanced_table/table_body", props: { id: "subrow_headers", table_data: @table_data, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all" }) %>
|
59
|
+
<% end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Optionally enable sorting by passing `sort_menu` to any `column_definition`(s). Sort options are determined by an array of `item` objects passed to the `sort_menu` prop.
|
2
|
+
|
3
|
+
</br>
|
4
|
+
<div class="pb_pill_kit_warning"><div class="pb_title_kit_size_4 pb_pill_text">Disclaimer</div></div>
|
5
|
+
|
6
|
+
This example uses a custom sort method that may need to be modified or replaced within your project.
|
@@ -2,14 +2,15 @@ examples:
|
|
2
2
|
rails:
|
3
3
|
- advanced_table_beta: Default (Required Props)
|
4
4
|
- advanced_table_beta_subrow_headers: SubRow Headers
|
5
|
+
- advanced_table_beta_sort: Enable Sorting
|
5
6
|
react:
|
6
7
|
- advanced_table_default: Default (Required Props)
|
7
8
|
- advanced_table_loading: Loading State
|
8
|
-
- advanced_table_sort:
|
9
|
+
- advanced_table_sort: Enable Sorting
|
9
10
|
- advanced_table_sort_control: Sort Control
|
10
11
|
- advanced_table_expanded_control: Expanded Control
|
11
12
|
- advanced_table_subrow_headers: SubRow Headers
|
12
13
|
- advanced_table_collapsible_trail: Collapsible Trail
|
13
14
|
- advanced_table_table_options: Table Options
|
14
15
|
- advanced_table_table_props: Table Props
|
15
|
-
- advanced_table_inline_row_loading:
|
16
|
+
- advanced_table_inline_row_loading: Inline Row Loading
|
@@ -1,11 +1,11 @@
|
|
1
1
|
<%= pb_content_tag do %>
|
2
|
-
<%= pb_rails("table/table_row", props: {tag:"div"}) do %>
|
2
|
+
<%= pb_rails("table/table_row", props: { tag: "div" }) do %>
|
3
3
|
<% object.column_definitions.each_with_index do |item, index| %>
|
4
|
-
<%= pb_rails("table/table_header", props: { tag:"div", id:item[:accessor], classname:object.th_classname}) do %>
|
5
|
-
<%= pb_rails("flex", props:{ align: "center", justify: index.zero? ? "start" : "end", text_align:"end" }) do %>
|
4
|
+
<%= pb_rails("table/table_header", props: { tag: "div", id: item[:accessor], classname: object.th_classname, sort_menu: item[:sort_menu] }) do %>
|
5
|
+
<%= pb_rails("flex", props:{ align: "center", justify: index.zero? ? "start" : "end", text_align: "end" }) do %>
|
6
6
|
<% if index.zero? && (object.enable_toggle_expansion == "header" || object.enable_toggle_expansion == "all") %>
|
7
7
|
<button class="gray-icon toggle-all-icon" onclick="expandAllRows(this)">
|
8
|
-
<%= pb_rails("icon", props: { icon: "arrows-from-line", cursor: "pointer", fixed_width: true, padding_right:"xs" }) %>
|
8
|
+
<%= pb_rails("icon", props: { icon: "arrows-from-line", cursor: "pointer", fixed_width: true, padding_right: "xs" }) %>
|
9
9
|
</button>
|
10
10
|
<% end %>
|
11
11
|
<%= item[:label] %>
|
@@ -20,6 +20,7 @@ type CardPropTypes = {
|
|
20
20
|
children: React.ReactChild[] | React.ReactChild | number,
|
21
21
|
className?: string,
|
22
22
|
data?: {[key: string]: string},
|
23
|
+
dragId?: string,
|
23
24
|
draggableItem?: boolean,
|
24
25
|
dragHandle?: boolean,
|
25
26
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
@@ -85,11 +86,11 @@ const Card = (props: CardPropTypes): React.ReactElement => {
|
|
85
86
|
children,
|
86
87
|
className,
|
87
88
|
data = {},
|
89
|
+
dragId,
|
88
90
|
dragHandle = true,
|
89
91
|
draggableItem = false,
|
90
92
|
highlight = {},
|
91
93
|
htmlOptions = {},
|
92
|
-
id,
|
93
94
|
selected = false,
|
94
95
|
tag = 'div',
|
95
96
|
} = props
|
@@ -126,8 +127,8 @@ const Card = (props: CardPropTypes): React.ReactElement => {
|
|
126
127
|
<>
|
127
128
|
{
|
128
129
|
draggableItem ? (
|
129
|
-
<Draggable.Item
|
130
|
-
key={
|
130
|
+
<Draggable.Item dragId={dragId}
|
131
|
+
key={dragId}
|
131
132
|
>
|
132
133
|
<Tag
|
133
134
|
{...ariaProps}
|
@@ -28,7 +28,7 @@ exports[`html structure is correct 1`] = `
|
|
28
28
|
style="vertical-align: middle; color: rgb(193, 205, 214);"
|
29
29
|
>
|
30
30
|
<i
|
31
|
-
class="pb_icon_kit far fa-fw fa-lg fa-chevron-down"
|
31
|
+
class="pb_icon_kit far far fa-lg fa-fw fa-fw fa-lg fa-chevron-down"
|
32
32
|
/>
|
33
33
|
<span
|
34
34
|
aria-label="chevron-down icon"
|
@@ -14,7 +14,12 @@ export default class PbCollapsible extends PbEnhancedElement {
|
|
14
14
|
this.element.addEventListener('click', () => {
|
15
15
|
this.toggleElement(this.target)
|
16
16
|
})
|
17
|
-
|
17
|
+
// Check the initial state of the collapsible content and set the arrow accordingly
|
18
|
+
if (this.target.classList.contains('is-visible')) {
|
19
|
+
this.displayUpArrow()
|
20
|
+
} else {
|
21
|
+
this.displayDownArrow()
|
22
|
+
}
|
18
23
|
// Listen for a custom event to toggle the collapsible
|
19
24
|
document.addEventListener(`${this.target.id}`, () => {
|
20
25
|
this.toggleElement(this.target)
|
@@ -0,0 +1,33 @@
|
|
1
|
+

|
2
|
+
|
3
|
+
```swift
|
4
|
+
VStack(alignment: .leading, spacing: Spacing.small) {
|
5
|
+
PBDateTimeStacked(
|
6
|
+
timeZoneIdentifier: "EDT",
|
7
|
+
isLowercase: true,
|
8
|
+
isMonthStacked: true,
|
9
|
+
isMonthBold: true
|
10
|
+
)
|
11
|
+
PBDateTimeStacked(
|
12
|
+
timeZoneIdentifier: "EDT",
|
13
|
+
isYearDisplayed: true,
|
14
|
+
isLowercase: true,
|
15
|
+
isMonthStacked: true,
|
16
|
+
isMonthBold: true,
|
17
|
+
isYearBold: true,
|
18
|
+
dateVariant: .standard
|
19
|
+
)
|
20
|
+
PBDateTimeStacked(
|
21
|
+
timeZoneIdentifier: "GMT+9",
|
22
|
+
isLowercase: true,
|
23
|
+
isMonthStacked: true,
|
24
|
+
isMonthBold: true
|
25
|
+
)
|
26
|
+
PBDateTimeStacked(
|
27
|
+
timeZoneIdentifier: "MDT",
|
28
|
+
isLowercase: true,
|
29
|
+
isMonthStacked: true,
|
30
|
+
isMonthBold: true
|
31
|
+
)
|
32
|
+
}
|
33
|
+
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
### Props
|
2
|
+
| Name | Type | Description | Default | Values |
|
3
|
+
| --- | ----------- | --------- | --------- | --------- |
|
4
|
+
| **dateTime** | `Date` | Takes a date type to calculate the current date | `Date()` | |
|
5
|
+
| **timeDate** | `Date` | Takes a date type to calculate the current time | `Date()` | |
|
6
|
+
| **timeZoneIdentifier** | `String` | A string value that is used in a function to get the correct time in the corrresponding time zone. This value is also used to display the time zone next to the time | | |
|
7
|
+
| **isYearDisplayed** | `Bool` | Determines whether or not the year is displayed with the month and day | `false` | `true` `false` |
|
8
|
+
| **isLowercase** | `Bool` | Determines whether or not am/pm is capitalized | `false` | `true` `false` |
|
9
|
+
| **isMonthStacked** | `Bool` | Determines whether or not the value for month is stacked over the date | `false` | `true` `false` |
|
10
|
+
| **isMonthBold** | `Bool` | Determines whether or not the month is in bold | `false` | `true` `false` |
|
11
|
+
| **isYearBold** | `Bool` | Determines whether or not the year is in bold | `false` | `true` `false` |
|
12
|
+
| **dateAlignment** | `HorizontalAlignment` | Sets alignment of date | `.trailing` | `leading` `center` `trailing` |
|
13
|
+
| **timeAlignment** | `HorizontalAlignment` | Sets alignment of the time zone | `.leading` | `leading` `center` `trailing` |
|
14
|
+
| **dateVariant** | `Variant` | Allows user to choose the style in which the date is displayed | `.short(showIcon: false)` | `.short(showIcon: false)` `.dayDate(showYear: false)` `.standard` ` .withIcon(isStandard: true)` `.withIcon(isStandard: false)` |
|
15
|
+
| **timeVariant** | `Variant` | Allows user to choose the style in which the time is displayed | `.time` | `.time` `.iconTimeZone` `.withTimeZoneHeader` |
|
16
|
+
| **dateSize** | `String` | Allows user to choose the size of the date that is being displayed | `.title4` | `title4` `body` `caption` `large` `subcaption` |
|
17
|
+
| **timeStyle** | `PBFont` | Allows user to choose the size of the time that is being displayed | `.caption` | `body` `caption` `large` `subcaption`|
|
18
|
+
| **timeZoneStyle** | `PBFont` | Allows user to choose the size of the time zone that is being displayed | `.caption` | `body` `caption` `large` `subcaption`|
|
@@ -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, onReorder }:
|
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
|
-
onReorder(items);
|
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
|
+
}
|
@@ -32,13 +32,14 @@ const DraggableDefault = (props) => {
|
|
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
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.
|
@@ -113,12 +113,13 @@ const DraggableMultipleContainer = (props) => {
|
|
113
113
|
}) => (
|
114
114
|
<Draggable.Item
|
115
115
|
container={container}
|
116
|
-
|
116
|
+
dragId={id}
|
117
117
|
key={id}
|
118
118
|
>
|
119
119
|
<Card
|
120
120
|
marginBottom="sm"
|
121
121
|
padding="sm"
|
122
|
+
{...props}
|
122
123
|
>
|
123
124
|
<Flex justify="between">
|
124
125
|
<FlexItem>
|
@@ -131,6 +132,7 @@ const DraggableMultipleContainer = (props) => {
|
|
131
132
|
<Title paddingLeft="xs"
|
132
133
|
size={4}
|
133
134
|
text={title}
|
135
|
+
{...props}
|
134
136
|
/>
|
135
137
|
</Flex>
|
136
138
|
</FlexItem>
|
@@ -139,10 +141,12 @@ const DraggableMultipleContainer = (props) => {
|
|
139
141
|
rounded
|
140
142
|
text={badgeProperties(container).text}
|
141
143
|
variant={badgeProperties(container).color}
|
144
|
+
{...props}
|
142
145
|
/>
|
143
146
|
</Flex>
|
144
147
|
<Body paddingTop="xs"
|
145
148
|
text={description}
|
149
|
+
{...props}
|
146
150
|
/>
|
147
151
|
</Card>
|
148
152
|
</Draggable.Item>
|
@@ -36,29 +36,32 @@ const DraggableWithCards = (props) => {
|
|
36
36
|
>
|
37
37
|
<Draggable.Container {...props}>
|
38
38
|
{initialState.map(({ id, text }) => (
|
39
|
-
<Card
|
39
|
+
<Card dragId={id}
|
40
40
|
draggableItem
|
41
41
|
highlight={{ color: "primary", position: "side" }}
|
42
|
-
id={id}
|
43
42
|
key={id}
|
44
43
|
marginBottom="xs"
|
45
44
|
padding="xs"
|
45
|
+
{...props}
|
46
46
|
>
|
47
47
|
<Flex alignItems="stretch"
|
48
48
|
flexDirection="column"
|
49
49
|
>
|
50
50
|
<Flex gap="xs">
|
51
51
|
<Title size={4}
|
52
|
-
text={text}
|
52
|
+
text={text}
|
53
|
+
{...props}
|
53
54
|
/>
|
54
55
|
<Badge
|
55
56
|
text="35-12345"
|
56
57
|
variant="primary"
|
58
|
+
{...props}
|
57
59
|
/>
|
58
60
|
</Flex>
|
59
61
|
<Caption
|
60
62
|
size="xs"
|
61
63
|
text="8:00A • Township Name • 90210"
|
64
|
+
{...props}
|
62
65
|
/>
|
63
66
|
<Flex gap="xxs"
|
64
67
|
spacing="between"
|
@@ -66,6 +69,7 @@ const DraggableWithCards = (props) => {
|
|
66
69
|
<Flex gap="xxs">
|
67
70
|
<Caption color="error"
|
68
71
|
size="xs"
|
72
|
+
{...props}
|
69
73
|
>
|
70
74
|
<Icon icon="house-circle-exclamation" />
|
71
75
|
</Caption>
|
@@ -78,14 +82,17 @@ const DraggableWithCards = (props) => {
|
|
78
82
|
<Badge rounded
|
79
83
|
text="Schedule QA"
|
80
84
|
variant="warning"
|
85
|
+
{...props}
|
81
86
|
/>
|
82
87
|
<Badge rounded
|
83
88
|
text="Flex"
|
84
|
-
variant="primary"
|
89
|
+
variant="primary"
|
90
|
+
{...props}
|
85
91
|
/>
|
86
92
|
<Badge rounded
|
87
93
|
text="R99"
|
88
94
|
variant="primary"
|
95
|
+
{...props}
|
89
96
|
/>
|
90
97
|
</Flex>
|
91
98
|
</Flex>
|
@@ -1,3 +1,5 @@
|
|
1
|
-
For a simplified version of the Draggable API for the Card kit, You can use the the Card kit as the Draggable Item by using the `draggableItem` prop
|
1
|
+
For a simplified version of the Draggable API for the Card kit, You can use the the Card kit as the Draggable Item by using the `draggableItem` prop. The dragHandle is added by default but this can be opted out of by setting `dragHandle` to false on the Card kit.
|
2
2
|
|
3
|
-
|
3
|
+
In addition to the above `dragId` is a REQUIRED prop to be passedd to the Card kit when implementing dragging.
|
4
|
+
|
5
|
+
The dev must manage state as shown.
|
@@ -30,11 +30,11 @@ const DraggableWithList = (props) => {
|
|
30
30
|
<DraggableProvider initialItems={data}
|
31
31
|
onReorder={(items) => setInitialState(items)}
|
32
32
|
>
|
33
|
-
<List
|
33
|
+
<List enableDrag
|
34
34
|
{...props}
|
35
35
|
>
|
36
36
|
{initialState.map(({ id, text }) => (
|
37
|
-
<ListItem
|
37
|
+
<ListItem dragId={id}
|
38
38
|
key={id}
|
39
39
|
>
|
40
40
|
{text}
|
@@ -1 +1,7 @@
|
|
1
|
-
For a simplified version of the Draggable API for the List kit, use the DraggableProvider to wrap the List kit and use the `
|
1
|
+
For a simplified version of the Draggable API for the List kit, use the DraggableProvider to wrap the List kit and use the `enableDrag` prop.
|
2
|
+
|
3
|
+
In addition to the above `dragId` is a REQUIRED prop to be passed to the List kit when implementing dragging.
|
4
|
+
|
5
|
+
The dev must manage state as shown.
|
6
|
+
|
7
|
+
The dragHandle is added by default but this can be opted out of by setting `dragHandle` to false on the List kit.
|
@@ -29,16 +29,18 @@ const DraggableWithSelectableList = (props) => {
|
|
29
29
|
<DraggableProvider initialItems={data}
|
30
30
|
onReorder={(items) => setInitialState(items)}
|
31
31
|
>
|
32
|
-
<SelectableList
|
33
|
-
variant="
|
32
|
+
<SelectableList enableDrag
|
33
|
+
variant="radio"
|
34
34
|
{...props}
|
35
35
|
>
|
36
36
|
{initialState.map(({ id, text }) => (
|
37
|
-
<SelectableList.Item
|
37
|
+
<SelectableList.Item
|
38
|
+
dragId={id}
|
38
39
|
key={id}
|
39
40
|
label={text}
|
40
|
-
name=
|
41
|
+
name="radio-test"
|
41
42
|
value={id}
|
43
|
+
{...props}
|
42
44
|
/>
|
43
45
|
))}
|
44
46
|
</SelectableList>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
For a simplified version of the Draggable API for the SelectableList kit, use the DraggableProvider to wrap the SelectableList kit and use the `enableDrag` prop.
|
2
|
+
|
3
|
+
In addition to the above `dragId` is a REQUIRED prop to be passed to the SelectableList kit when implementing dragging.
|
4
|
+
|
5
|
+
The dev must manage state as shown.
|
6
|
+
|
7
|
+
The dragHandle is added by default but this can be opted out of by setting `dragHandle` to false on the SelectableList kit.
|