playbook_ui 14.6.0.pre.rc.20 → 14.6.0.pre.rc.22
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/pb_dialog/docs/_dialog_loading.html.erb +30 -7
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_loading.md +0 -2
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +84 -3
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +8 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_separators_hidden.html.erb +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_separators_hidden.jsx +33 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subtle_variant.html.erb +10 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subtle_variant.jsx +34 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subtle_variant.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +4 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +2 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +10 -1
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with_loading.html.erb +39 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with_loading.md +1 -0
- data/app/pb_kits/playbook/pb_form/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_form/form.rb +2 -0
- data/app/pb_kits/playbook/pb_form/formHelper.js +27 -0
- data/dist/chunks/{_typeahead-C9g4qCcE.js → _typeahead-CcgTar9x.js} +1 -1
- data/dist/chunks/_weekday_stacked-NAZZNhRD.js +45 -0
- data/dist/chunks/{lib-CEpcaI8y.js → lib-D-mTv-kp.js} +1 -1
- data/dist/chunks/{pb_form_validation-D9zkwt2b.js → pb_form_validation-BkWGwJsl.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/pb_forms_helper.rb +3 -1
- data/lib/playbook/version.rb +1 -1
- metadata +14 -6
- data/dist/chunks/_weekday_stacked-GLXxTgor.js +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de106da16b0280d3d1808a79b74e2ac4244320da229c66f50899eb9730ef8c7
|
4
|
+
data.tar.gz: 5fa46d5ee75df55b6c2752eca2f2b37796d8eafa79a2fca1c5914ef6068d135c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0820774134793841703651be09c4e988ccaecd363bb4d31b6620cccc990ae25b023ceb6b496be786f414b08760c47b6a64e2433cef4c3eea050d7ef1b3c3f3ca'
|
7
|
+
data.tar.gz: 1657f7149c67a664f3097df64462ccb08704c534b9046dfb421c8a325ad1fab699ac3416fcbca692472ccd133558f9934372c43092d5cdbaa15dab2f9756e993
|
@@ -1,13 +1,36 @@
|
|
1
1
|
<%= pb_rails("button", props: { text: "Open Dialog", data: {"open-dialog": "dialog-loading"} }) %>
|
2
2
|
|
3
|
-
<%= pb_rails("dialog", props: {
|
4
|
-
id:"dialog-loading",
|
5
|
-
size: "sm",
|
6
|
-
title: "Loading
|
7
|
-
text: "Make a loading request?",
|
8
|
-
cancel_button: "Cancel Button",
|
3
|
+
<%= pb_rails("dialog", props: {
|
4
|
+
id:"dialog-loading",
|
5
|
+
size: "sm",
|
6
|
+
title: "Loading Example",
|
7
|
+
text: "Make a loading request?",
|
8
|
+
cancel_button: "Cancel Button",
|
9
9
|
cancel_button_id: "cancel-button-loading",
|
10
|
-
confirm_button: "Okay",
|
10
|
+
confirm_button: "Okay",
|
11
11
|
confirm_button_id: "confirm-button-loading",
|
12
12
|
loading: true,
|
13
13
|
}) %>
|
14
|
+
|
15
|
+
<script>
|
16
|
+
const loadingButton = document.querySelector('[data-disable-with="Loading"]');
|
17
|
+
if (loadingButton) {
|
18
|
+
loadingButton.addEventListener("click", function() {
|
19
|
+
const okayLoadingButton = document.querySelector('[data-disable-with="Loading"]');
|
20
|
+
const cancelButton = document.querySelector('[data-disable-cancel-with="Loading"]');
|
21
|
+
let currentClass = okayLoadingButton.className;
|
22
|
+
let cancelClass = cancelButton ? cancelButton.className : "";
|
23
|
+
|
24
|
+
setTimeout(function() {
|
25
|
+
okayLoadingButton.disabled = false;
|
26
|
+
okayLoadingButton.className = currentClass.replace("_disabled_loading", "_enabled");
|
27
|
+
|
28
|
+
if (cancelButton) {
|
29
|
+
cancelButton.disabled = false;
|
30
|
+
cancelButton.className = cancelClass.replace("_disabled", "_enabled");
|
31
|
+
}
|
32
|
+
}, 5000);
|
33
|
+
|
34
|
+
});
|
35
|
+
}
|
36
|
+
</script>
|
@@ -69,15 +69,21 @@
|
|
69
69
|
padding-bottom: $space_xs;
|
70
70
|
cursor: pointer;
|
71
71
|
&:hover {
|
72
|
-
background-color: $
|
72
|
+
background-color: $bg_light;
|
73
73
|
}
|
74
74
|
|
75
75
|
&[class*="_focused"] {
|
76
|
-
background-color: $
|
76
|
+
background-color: $bg_light;
|
77
77
|
}
|
78
78
|
|
79
79
|
&[class*="_list"] {
|
80
80
|
border-bottom: 1px solid $border_light;
|
81
|
+
|
82
|
+
&:hover, &:focus {
|
83
|
+
.pb_body_kit {
|
84
|
+
color: $primary;
|
85
|
+
}
|
86
|
+
}
|
81
87
|
}
|
82
88
|
&[class*="selected"] {
|
83
89
|
background-color: $primary;
|
@@ -87,7 +93,7 @@
|
|
87
93
|
color: $white !important;
|
88
94
|
}
|
89
95
|
&:hover {
|
90
|
-
background-color: $
|
96
|
+
background-color: $product_1_background !important;
|
91
97
|
}
|
92
98
|
}
|
93
99
|
}
|
@@ -125,6 +131,81 @@
|
|
125
131
|
}
|
126
132
|
}
|
127
133
|
|
134
|
+
&.separators_hidden {
|
135
|
+
.dropdown_wrapper {
|
136
|
+
.pb_dropdown_container {
|
137
|
+
|
138
|
+
[class*="pb_dropdown_option"] {
|
139
|
+
border: none;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
&.subtle {
|
146
|
+
.dropdown_wrapper {
|
147
|
+
.pb_dropdown_container {
|
148
|
+
|
149
|
+
[class*="pb_dropdown_option"]:first-child {
|
150
|
+
margin-top: $space_xs;
|
151
|
+
}
|
152
|
+
|
153
|
+
[class*="pb_dropdown_option"]:last-child {
|
154
|
+
margin-bottom: $space_xs;
|
155
|
+
}
|
156
|
+
|
157
|
+
[class*="pb_dropdown_option"] {
|
158
|
+
margin: $space_xs;
|
159
|
+
padding: $space_xs;
|
160
|
+
border-radius: $border_radius_md;
|
161
|
+
border-bottom: none;
|
162
|
+
position: relative;
|
163
|
+
|
164
|
+
&::after {
|
165
|
+
content: "";
|
166
|
+
position: absolute;
|
167
|
+
left: -$space_xs;
|
168
|
+
right: -$space_xs;
|
169
|
+
bottom: -4.5px;
|
170
|
+
height: 1px;
|
171
|
+
background: $border_light;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
[class*="pb_dropdown_option"]:last-child::after {
|
176
|
+
display: none;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
&.separators_hidden {
|
182
|
+
.dropdown_wrapper {
|
183
|
+
.pb_dropdown_container {
|
184
|
+
[class*="pb_dropdown_option"]:first-child {
|
185
|
+
margin-top: $space_xs;
|
186
|
+
}
|
187
|
+
|
188
|
+
[class*="pb_dropdown_option"]:last-child {
|
189
|
+
margin-bottom: $space_xs;
|
190
|
+
}
|
191
|
+
|
192
|
+
[class*="pb_dropdown_option"] {
|
193
|
+
padding: $space_xxs $space_xs;
|
194
|
+
margin: $space_xxs $space_xs;
|
195
|
+
|
196
|
+
&::after {
|
197
|
+
height: 0px;
|
198
|
+
}
|
199
|
+
|
200
|
+
&[class*="selected"] {
|
201
|
+
border-bottom: none;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
128
209
|
&.dark {
|
129
210
|
.dropdown_wrapper {
|
130
211
|
[class*="dropdown_trigger_wrapper"] {
|
@@ -35,7 +35,9 @@ type DropdownProps = {
|
|
35
35
|
label?: string;
|
36
36
|
onSelect?: (arg: GenericObject) => null;
|
37
37
|
options: GenericObject;
|
38
|
+
separators: boolean;
|
38
39
|
triggerRef?: any;
|
40
|
+
variant?: "default" | "subtle";
|
39
41
|
};
|
40
42
|
|
41
43
|
interface DropdownComponent
|
@@ -62,15 +64,20 @@ const Dropdown = forwardRef((props: DropdownProps, ref: any) => {
|
|
62
64
|
label,
|
63
65
|
onSelect,
|
64
66
|
options,
|
65
|
-
|
67
|
+
separators = true,
|
68
|
+
triggerRef,
|
69
|
+
variant = "default",
|
66
70
|
} = props;
|
67
71
|
|
68
72
|
const ariaProps = buildAriaProps(aria);
|
69
73
|
const dataProps = buildDataProps(data);
|
70
74
|
const htmlProps = buildHtmlProps(htmlOptions);
|
75
|
+
const separatorsClass = separators ? '' : 'separators_hidden'
|
71
76
|
const classes = classnames(
|
72
77
|
buildCss("pb_dropdown"),
|
73
78
|
globalProps(props),
|
79
|
+
variant,
|
80
|
+
separatorsClass,
|
74
81
|
className
|
75
82
|
);
|
76
83
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%
|
2
|
+
options = [
|
3
|
+
{ label: 'United States', value: 'United States', id: 'us' },
|
4
|
+
{ label: 'Canada', value: 'Canada', id: 'ca' },
|
5
|
+
{ label: 'Pakistan', value: 'Pakistan', id: 'pk' },
|
6
|
+
]
|
7
|
+
|
8
|
+
%>
|
9
|
+
<%= pb_rails("dropdown", props: {options: options, separators: false}) %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Dropdown } from 'playbook-ui'
|
3
|
+
|
4
|
+
const DropdownSeparatorsHidden = (props) => {
|
5
|
+
|
6
|
+
const options = [
|
7
|
+
{
|
8
|
+
label: "United States",
|
9
|
+
value: "United States",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
label: "Canada",
|
13
|
+
value: "Canada",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
label: "Pakistan",
|
17
|
+
value: "Pakistan",
|
18
|
+
}
|
19
|
+
];
|
20
|
+
|
21
|
+
|
22
|
+
return (
|
23
|
+
<div>
|
24
|
+
<Dropdown
|
25
|
+
options={options}
|
26
|
+
separators={false}
|
27
|
+
{...props}
|
28
|
+
/>
|
29
|
+
</div>
|
30
|
+
)
|
31
|
+
}
|
32
|
+
|
33
|
+
export default DropdownSeparatorsHidden
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%
|
2
|
+
options = [
|
3
|
+
{ label: 'United States', value: 'United States', id: 'us' },
|
4
|
+
{ label: 'Canada', value: 'Canada', id: 'ca' },
|
5
|
+
{ label: 'Pakistan', value: 'Pakistan', id: 'pk' },
|
6
|
+
]
|
7
|
+
|
8
|
+
%>
|
9
|
+
|
10
|
+
<%= pb_rails("dropdown", props: { options: options, variant: "subtle", separators: false }) %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Dropdown } from 'playbook-ui'
|
3
|
+
|
4
|
+
const DropdownSubtleVariant = (props) => {
|
5
|
+
|
6
|
+
const options = [
|
7
|
+
{
|
8
|
+
label: "United States",
|
9
|
+
value: "United States",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
label: "Canada",
|
13
|
+
value: "Canada",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
label: "Pakistan",
|
17
|
+
value: "Pakistan",
|
18
|
+
}
|
19
|
+
];
|
20
|
+
|
21
|
+
|
22
|
+
return (
|
23
|
+
<>
|
24
|
+
<Dropdown
|
25
|
+
options={options}
|
26
|
+
separators={false}
|
27
|
+
variant="subtle"
|
28
|
+
{...props}
|
29
|
+
/>
|
30
|
+
</>
|
31
|
+
)
|
32
|
+
}
|
33
|
+
|
34
|
+
export default DropdownSubtleVariant
|
@@ -0,0 +1 @@
|
|
1
|
+
For the `subtle` variant, it is recommended that you set the `Separators` prop to `false` to remove the separator lines between the options for a more cleaner look.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
examples:
|
2
2
|
rails:
|
3
3
|
- dropdown_default: Default
|
4
|
+
- dropdown_subtle_variant: Subtle Variant
|
4
5
|
- dropdown_subcomponent_structure_rails: Subcomponent Structure
|
5
6
|
- dropdown_with_label: With Label
|
6
7
|
- dropdown_with_custom_options_rails: Custom Options
|
@@ -10,9 +11,11 @@ examples:
|
|
10
11
|
- dropdown_error: Dropdown with Error
|
11
12
|
- dropdown_default_value: Default Value
|
12
13
|
- dropdown_blank_selection: Blank Selection
|
14
|
+
- dropdown_separators_hidden: Separators Hidden
|
13
15
|
|
14
16
|
react:
|
15
17
|
- dropdown_default: Default
|
18
|
+
- dropdown_subtle_variant: Subtle Variant
|
16
19
|
- dropdown_subcomponent_structure: Subcomponent Structure
|
17
20
|
- dropdown_with_label: With Label
|
18
21
|
- dropdown_with_custom_options: Custom Options
|
@@ -23,6 +26,7 @@ examples:
|
|
23
26
|
- dropdown_default_value: Default Value
|
24
27
|
- dropdown_blank_selection: Blank Selection
|
25
28
|
- dropdown_clear_selection: Clear Selection
|
29
|
+
- dropdown_separators_hidden: Separators Hidden
|
26
30
|
# - dropdown_with_autocomplete: Autocomplete
|
27
31
|
# - dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
|
28
32
|
# - dropdown_with_external_control: useDropdown Hook
|
@@ -13,3 +13,5 @@ export { default as DropdownError } from './_dropdown_error.jsx'
|
|
13
13
|
export { default as DropdownDefaultValue } from './_dropdown_default_value.jsx'
|
14
14
|
export { default as DropdownBlankSelection } from './_dropdown_blank_selection.jsx'
|
15
15
|
export { default as DropdownClearSelection } from './_dropdown_clear_selection.jsx'
|
16
|
+
export { default as DropdownSubtleVariant } from './_dropdown_subtle_variant.jsx'
|
17
|
+
export { default as DropdownSeparatorsHidden } from './_dropdown_separators_hidden.jsx'
|
@@ -13,13 +13,18 @@ module Playbook
|
|
13
13
|
prop :default_value
|
14
14
|
prop :blank_selection, type: Playbook::Props::String,
|
15
15
|
default: ""
|
16
|
+
prop :variant, type: Playbook::Props::Enum,
|
17
|
+
values: %w[default subtle],
|
18
|
+
default: "default"
|
19
|
+
prop :separators, type: Playbook::Props::Boolean,
|
20
|
+
default: true
|
16
21
|
|
17
22
|
def data
|
18
23
|
Hash(prop(:data)).merge(pb_dropdown: true)
|
19
24
|
end
|
20
25
|
|
21
26
|
def classname
|
22
|
-
generate_classname("pb_dropdown")
|
27
|
+
generate_classname("pb_dropdown", variant, separators_class, separator: " ")
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
@@ -32,6 +37,10 @@ module Playbook
|
|
32
37
|
default_value.present? ? default_value.transform_keys(&:to_s)["id"] : ""
|
33
38
|
end
|
34
39
|
|
40
|
+
def separators_class
|
41
|
+
separators ? "" : "separators_hidden"
|
42
|
+
end
|
43
|
+
|
35
44
|
def options_with_blank
|
36
45
|
blank_selection.present? ? [{ id: "", value: "", label: blank_selection }] + options : options
|
37
46
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%= pb_form_with(scope: :example, url: "", method: :get, loading: true) do |form| %>
|
2
|
+
<%= form.text_field :example_text_field, props: { label: true } %>
|
3
|
+
|
4
|
+
<%= form.actions do |action| %>
|
5
|
+
<%= action.submit %>
|
6
|
+
<%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<script>
|
11
|
+
const loadingForm = document.querySelector(".pb_form_loading")
|
12
|
+
if (loadingForm) {
|
13
|
+
loadingForm.addEventListener("submit", function(event) {
|
14
|
+
event.preventDefault();
|
15
|
+
|
16
|
+
const submitButton = event['submitter'];
|
17
|
+
const cancelButton = event['target'].querySelector('button[type="reset"]');
|
18
|
+
|
19
|
+
if (submitButton) {
|
20
|
+
let currentClass = submitButton.className;
|
21
|
+
let newClass = currentClass.replace("_disabled_loading", "_enabled");
|
22
|
+
|
23
|
+
let cancelClass = cancelButton ? cancelButton.className : "";
|
24
|
+
let newCancelClass = cancelClass.replace("_disabled", "_enabled");
|
25
|
+
|
26
|
+
setTimeout(function() {
|
27
|
+
submitButton.disabled = false;
|
28
|
+
submitButton.className = currentClass;
|
29
|
+
|
30
|
+
if (cancelButton) {
|
31
|
+
cancelButton.disabled = false;
|
32
|
+
cancelButton.className = cancelClass;
|
33
|
+
}
|
34
|
+
}, 5000);
|
35
|
+
}
|
36
|
+
});
|
37
|
+
}
|
38
|
+
</script>
|
39
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Pressing Submit will trigger a loading state where the button content is replaced by a spinner icon and the submit button will be disabled.
|
@@ -7,6 +7,7 @@ module Playbook
|
|
7
7
|
type: Playbook::Props::Base
|
8
8
|
prop :form_system_options, deprecated: "Use options instead",
|
9
9
|
type: Playbook::Props::Base
|
10
|
+
prop :loading, type: Playbook::Props::Boolean, default: false
|
10
11
|
prop :options, type: Playbook::Props::Base
|
11
12
|
prop :validate, type: Playbook::Props::Boolean, default: false
|
12
13
|
|
@@ -22,6 +23,7 @@ module Playbook
|
|
22
23
|
aria: aria,
|
23
24
|
class: classname,
|
24
25
|
data: data,
|
26
|
+
loading: loading,
|
25
27
|
validate: validate,
|
26
28
|
}.merge(prop(:options) || prop(:form_system_options) || {})
|
27
29
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
const formHelper = () => {
|
2
|
+
const loadingForm = document.querySelector(".pb_form_loading")
|
3
|
+
if (loadingForm) {
|
4
|
+
loadingForm.addEventListener("submit", function(event) {
|
5
|
+
const submitButton = event['submitter'];
|
6
|
+
const cancelButton = event['target'].querySelector('button[type="reset"]');
|
7
|
+
|
8
|
+
if (submitButton) {
|
9
|
+
let currentClass = submitButton.className;
|
10
|
+
let newClass = currentClass.replace("_enabled", "_disabled_loading");
|
11
|
+
|
12
|
+
let cancelClass = cancelButton ? cancelButton.className : "";
|
13
|
+
let newCancelClass = cancelClass.replace("_enabled", "_disabled");
|
14
|
+
|
15
|
+
submitButton.disabled = true;
|
16
|
+
submitButton.className = newClass;
|
17
|
+
|
18
|
+
if (cancelButton) {
|
19
|
+
cancelButton.disabled = true;
|
20
|
+
cancelButton.className = newCancelClass;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
export default formHelper;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useEffect,useMemo,useContext,createElement,useState,useRef,forwardRef,useCallback,useImperativeHandle,useLayoutEffect,Component,Fragment as Fragment$1}from"react";import{
|
1
|
+
import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useEffect,useMemo,useContext,createElement,useState,useRef,forwardRef,useCallback,useImperativeHandle,useLayoutEffect,Component,Fragment as Fragment$1}from"react";import{q as getDefaultExportFromCjs,w as filter,x as omit,j as getAllIcons,y as get,n as commonjsGlobal,v as colors$1,s as highchartsTheme,z as merge,r as highchartsDarkTheme,A as useCollapsible,B as getAugmentedNamespace,C as createPopper,E as uniqueId,F as typography,G as cloneDeep,H as isString}from"./lib-D-mTv-kp.js";import*as ReactDOM from"react-dom";import ReactDOM__default,{createPortal}from"react-dom";import{TrixEditor}from"react-trix";import Trix from"trix";import require$$0 from"react-is";const initialState={items:[],dragData:{id:"",initialGroup:""},isDragging:"",activeContainer:""};const reducer=(state,action)=>{switch(action.type){case"SET_ITEMS":return Object.assign(Object.assign({},state),{items:action.payload});case"SET_DRAG_DATA":return Object.assign(Object.assign({},state),{dragData:action.payload});case"SET_IS_DRAGGING":return Object.assign(Object.assign({},state),{isDragging:action.payload});case"SET_ACTIVE_CONTAINER":return Object.assign(Object.assign({},state),{activeContainer:action.payload});case"CHANGE_CATEGORY":return Object.assign(Object.assign({},state),{items:state.items.map((item=>item.id===action.payload.itemId?Object.assign(Object.assign({},item),{container:action.payload.container}):item))});case"REORDER_ITEMS":{const{dragId:dragId,targetId:targetId}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item.id===dragId));const draggedIndex=newItems.indexOf(draggedItem);const targetIndex=newItems.findIndex((item=>item.id===targetId));newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,draggedItem);return Object.assign(Object.assign({},state),{items:newItems})}default:return state}};const DragContext=createContext({});const DraggableContext=()=>useContext(DragContext);const DraggableProvider=({children:children,initialItems:initialItems,onReorder:onReorder,onDragStart:onDragStart,onDragEnter:onDragEnter,onDragEnd:onDragEnd,onDrop:onDrop,onDragOver:onDragOver})=>{const[state,dispatch]=useReducer(reducer,initialState);useEffect((()=>{dispatch({type:"SET_ITEMS",payload:initialItems})}),[initialItems]);useEffect((()=>{onReorder(state.items)}),[state.items]);const handleDragStart=(id,container)=>{dispatch({type:"SET_DRAG_DATA",payload:{id:id,initialGroup:container}});dispatch({type:"SET_IS_DRAGGING",payload:id});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(state.dragData.id!==id){dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}});dispatch({type:"SET_DRAG_DATA",payload:{id:state.dragData.id,initialGroup:container}})}if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});if(onDragEnd)onDragEnd()};const changeCategory=(itemId,container)=>{dispatch({type:"CHANGE_CATEGORY",payload:{itemId:itemId,container:container}})};const handleDrop=container=>{dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});changeCategory(state.dragData.id,container);if(onDrop)onDrop(container)};const handleDragOver=(e2,container)=>{e2.preventDefault();dispatch({type:"SET_ACTIVE_CONTAINER",payload:container});if(onDragOver)onDragOver(e2,container)};const contextValue=useMemo((()=>({items:state.items,dragData:state.dragData,isDragging:state.isDragging,activeContainer:state.activeContainer,handleDragStart:handleDragStart,handleDragEnter:handleDragEnter,handleDragEnd:handleDragEnd,handleDrop:handleDrop,handleDragOver:handleDragOver})),[state]);return jsx$1(DragContext.Provider,Object.assign({value:contextValue},{children:children}),void 0)};var classnames$1={exports:{}};
|
2
2
|
/*!
|
3
3
|
Copyright (c) 2018 Jed Watson.
|
4
4
|
Licensed under the MIT License (MIT), see
|