playbook_ui 16.8.0.pre.alpha.PLAY2935formbuilderrequiredindicatorbug16780 → 16.8.0.pre.alpha.PLAY2945selectformblankselection16424
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/Components/RegularTableView.tsx +0 -2
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +0 -2
- data/app/pb_kits/playbook/pb_advanced_table/Components/VirtualizedTableView.tsx +1 -5
- data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableState.ts +0 -24
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +0 -144
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.jsx +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.md +0 -6
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sticky_header.jsx +4 -12
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sticky_header.md +0 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sticky_header_rails.html.erb +2 -16
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sticky_header_rails.md +0 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props_sticky_header.html.erb +2 -16
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props_sticky_header.jsx +5 -12
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props_sticky_header_rails.md +0 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props_sticky_header_react.md +3 -5
- data/app/pb_kits/playbook/pb_advanced_table/docs/_playground.json +2 -5
- data/app/pb_kits/playbook/pb_advanced_table/docs/_playground.overrides.json +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/advanced_table_column_definitions_styling.json +1 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +0 -3
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +0 -2
- data/app/pb_kits/playbook/pb_card/_card.tsx +1 -1
- data/app/pb_kits/playbook/pb_card/card.html.erb +1 -1
- data/app/pb_kits/playbook/pb_currency/_currency.tsx +6 -9
- data/app/pb_kits/playbook/pb_currency/currency.rb +10 -5
- data/app/pb_kits/playbook/pb_currency/currency.test.js +1 -44
- data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +21 -36
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_dialog_submission.jsx +2 -2
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +0 -19
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards_rails.md +0 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards_react.md +0 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list_rails.md +0 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list_react.md +1 -3
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list_rails.md +1 -3
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list_react.md +1 -3
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +0 -16
- data/app/pb_kits/playbook/pb_draggable/draggable_container.html.erb +1 -3
- data/app/pb_kits/playbook/pb_draggable/draggable_item.html.erb +0 -1
- data/app/pb_kits/playbook/pb_draggable/index.js +7 -149
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableContainer.tsx +0 -1
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +1 -67
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with_select_examples.html.erb +31 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_with_required_indicator.html.erb +19 -20
- data/app/pb_kits/playbook/pb_form/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_icon/_icon.scss +1 -2
- data/app/pb_kits/playbook/pb_icon/docs/_icon_fa_kit.html.erb +1 -0
- data/app/pb_kits/playbook/pb_icon/docs/_icon_fa_kit.jsx +21 -0
- data/app/pb_kits/playbook/pb_icon/docs/_icon_fa_kit.md +7 -0
- data/app/pb_kits/playbook/pb_icon/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_icon/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_list/_list_item.tsx +1 -4
- data/app/pb_kits/playbook/pb_list/item.html.erb +1 -1
- data/app/pb_kits/playbook/pb_pb_circle_chart/docs/_pb_circle_chart_default.jsx +1 -1
- data/app/pb_kits/playbook/pb_pb_circle_chart/docs/example.yml +0 -2
- data/app/pb_kits/playbook/pb_pb_circle_chart/docs/index.js +1 -2
- data/app/pb_kits/playbook/pb_table/docs/_table_sticky.html.erb +83 -85
- data/app/pb_kits/playbook/pb_table/docs/_table_sticky.jsx +86 -88
- data/app/pb_kits/playbook/pb_table/docs/_table_sticky.md +1 -3
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_external_filter_rails.md +1 -1
- data/app/pb_kits/playbook/pb_text_input/_text_input.scss +0 -37
- data/dist/chunks/{_typeahead-DA__Kgp5.js → _typeahead-D2TWdJTn.js} +1 -1
- data/dist/chunks/vendor.js +2 -2
- data/dist/menu.yml +130 -70
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/forms/builder/collection_select_field.rb +1 -1
- data/lib/playbook/forms/builder/form_field_builder.rb +0 -2
- data/lib/playbook/forms/builder/select_field.rb +1 -1
- data/lib/playbook/forms/builder/time_zone_select_field.rb +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +8 -16
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/ColumnLayoutHelper.ts +0 -138
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_width.jsx +0 -57
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_width.md +0 -66
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_enable_toggle_expansion_rails.html.erb +0 -62
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_enable_toggle_expansion_rails.md +0 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sticky_scroll_limitation.jsx +0 -68
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sticky_scroll_limitation.md +0 -7
- data/app/pb_kits/playbook/pb_draggable/touchDrag.test.js +0 -38
- data/app/pb_kits/playbook/pb_draggable/utilities/touchDrag.ts +0 -173
- data/app/pb_kits/playbook/pb_pb_circle_chart/docs/_pb_circle_chart_centered_data.html.erb +0 -90
- data/app/pb_kits/playbook/pb_pb_circle_chart/docs/_pb_circle_chart_centered_data.jsx +0 -100
- data/app/pb_kits/playbook/pb_pb_circle_chart/docs/_pb_circle_chart_centered_data.md +0 -1
|
@@ -68,7 +68,7 @@ module Playbook
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def title_text
|
|
71
|
-
if null_display
|
|
71
|
+
if null_display
|
|
72
72
|
null_display
|
|
73
73
|
elsif swap_negative
|
|
74
74
|
absolute_amount(abbr_or_format_amount)
|
|
@@ -125,7 +125,14 @@ module Playbook
|
|
|
125
125
|
# Convert numeric input to string format
|
|
126
126
|
def convert_amount(input)
|
|
127
127
|
if input.is_a?(Numeric)
|
|
128
|
-
|
|
128
|
+
if input.zero? && null_display.nil?
|
|
129
|
+
""
|
|
130
|
+
else
|
|
131
|
+
format("%.2f", input)
|
|
132
|
+
end
|
|
133
|
+
# Handle string representations of zero
|
|
134
|
+
elsif input.to_s.strip.match?(/^-?0+(\.0+)?$/) && null_display.nil?
|
|
135
|
+
""
|
|
129
136
|
else
|
|
130
137
|
input.to_s
|
|
131
138
|
end
|
|
@@ -135,7 +142,6 @@ module Playbook
|
|
|
135
142
|
return "" if currency_amount.blank?
|
|
136
143
|
|
|
137
144
|
value = currency_amount.split(".").first
|
|
138
|
-
value = "0" if value.blank?
|
|
139
145
|
if comma_separator
|
|
140
146
|
number_with_delimiter(value.gsub(",", ""))
|
|
141
147
|
else
|
|
@@ -146,8 +152,7 @@ module Playbook
|
|
|
146
152
|
def decimal_value
|
|
147
153
|
return "00" if currency_amount.blank?
|
|
148
154
|
|
|
149
|
-
|
|
150
|
-
fraction.ljust(2, "0")[0, 2]
|
|
155
|
+
currency_amount.split(".")[1] || "00"
|
|
151
156
|
end
|
|
152
157
|
|
|
153
158
|
def units_element
|
|
@@ -178,48 +178,5 @@ test('handles numeric amounts correctly', () => {
|
|
|
178
178
|
expect(screen.getByTestId('test-numeric-no-symbol')).toHaveTextContent('400.50')
|
|
179
179
|
expect(screen.getByTestId('test-numeric-medium-size')).toHaveTextContent('$500.55')
|
|
180
180
|
expect(screen.getByTestId('test-numeric-negative')).toHaveTextContent('-$600.70')
|
|
181
|
-
expect(screen.getByTestId('test-numeric-null')).toHaveTextContent('
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
test('renders zero values with leading digit', () => {
|
|
185
|
-
render(
|
|
186
|
-
<>
|
|
187
|
-
<Currency
|
|
188
|
-
amount="0"
|
|
189
|
-
data={{ testid: 'test-string-zero' }}
|
|
190
|
-
/>
|
|
191
|
-
<Currency
|
|
192
|
-
amount={0}
|
|
193
|
-
data={{ testid: 'test-numeric-zero' }}
|
|
194
|
-
/>
|
|
195
|
-
</>
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
expect(screen.getByTestId('test-string-zero')).toHaveTextContent('$0.00')
|
|
199
|
-
expect(screen.getByTestId('test-numeric-zero')).toHaveTextContent('$0.00')
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
test('normalizes string zero with single decimal digit to .00', () => {
|
|
203
|
-
render(
|
|
204
|
-
<Currency
|
|
205
|
-
amount="0.0"
|
|
206
|
-
commaSeparator
|
|
207
|
-
data={{ testid: 'test-string-zero-single-decimal' }}
|
|
208
|
-
/>
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
expect(screen.getByTestId('test-string-zero-single-decimal')).toHaveTextContent('$0.00')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test('nullDisplay only applies when amount is empty', () => {
|
|
215
|
-
render(
|
|
216
|
-
<Currency
|
|
217
|
-
amount="-.53"
|
|
218
|
-
data={{ testid: 'test-null-display-negative' }}
|
|
219
|
-
nullDisplay="$0.00"
|
|
220
|
-
/>
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
expect(screen.getByTestId('test-null-display-negative')).toHaveTextContent('-$')
|
|
224
|
-
expect(screen.getByTestId('test-null-display-negative')).not.toHaveTextContent('$0.00')
|
|
181
|
+
expect(screen.getByTestId('test-numeric-null')).toHaveTextContent('$.00')
|
|
225
182
|
})
|
|
@@ -79,57 +79,42 @@
|
|
|
79
79
|
|
|
80
80
|
<%= javascript_tag do %>
|
|
81
81
|
(function() {
|
|
82
|
-
const initQuickPickChangeListener = (input) => {
|
|
83
|
-
if (!<%= object.selection_type == "quickpick" %>) return
|
|
84
|
-
if (input.dataset.quickpickInitialized) return
|
|
85
|
-
|
|
86
|
-
input.dataset.quickpickInitialized = "true"
|
|
87
|
-
input.addEventListener("change", ({ target }) => {
|
|
88
|
-
const startDate = document.getElementById("<%= object.start_date_id %>")
|
|
89
|
-
const endDate = document.getElementById("<%= object.end_date_id %>")
|
|
90
|
-
const splittedValue = target.value.split(" to ")
|
|
91
|
-
startDate.value = splittedValue[0]
|
|
92
|
-
endDate.value = splittedValue[1] ? splittedValue[1] : splittedValue[0]
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
82
|
const loadDatePicker = () => {
|
|
97
|
-
const input = document.getElementById("<%= object.picker_id %>")
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (typeof window.datePickerHelper !== "function") return false
|
|
101
|
-
|
|
102
|
-
window.datePickerHelper(<%= object.date_picker_config %>, "<%= object.scroll_container %>")
|
|
103
|
-
initQuickPickChangeListener(input)
|
|
104
|
-
|
|
105
|
-
return true
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let attempts = 0
|
|
109
|
-
const retryLoad = () => {
|
|
110
|
-
if (loadDatePicker()) return
|
|
83
|
+
const input = document.getElementById("<%= object.picker_id %>");
|
|
84
|
+
if (input && !input._flatpickr) {
|
|
85
|
+
datePickerHelper(<%= object.date_picker_config %>, "<%= object.scroll_container %>")
|
|
111
86
|
|
|
112
|
-
|
|
113
|
-
|
|
87
|
+
if (<%= object.selection_type == "quickpick" %>) {
|
|
88
|
+
document.getElementById("<%= object.picker_id %>").addEventListener("change", ({ target }) => {
|
|
89
|
+
const startDate = document.getElementById("<%= object.start_date_id %>")
|
|
90
|
+
const endDate = document.getElementById("<%= object.end_date_id %>")
|
|
91
|
+
const splittedValue = target.value.split(" to ")
|
|
92
|
+
startDate.value = splittedValue[0]
|
|
93
|
+
endDate.value = splittedValue[1] ? splittedValue[1] : splittedValue[0]
|
|
94
|
+
})
|
|
95
|
+
}
|
|
114
96
|
}
|
|
115
97
|
}
|
|
116
98
|
|
|
99
|
+
// Try to initialize immediately if DOM is ready
|
|
117
100
|
if (document.readyState === "loading") {
|
|
118
|
-
window.addEventListener("DOMContentLoaded",
|
|
101
|
+
window.addEventListener("DOMContentLoaded", loadDatePicker)
|
|
119
102
|
} else {
|
|
120
|
-
|
|
103
|
+
loadDatePicker()
|
|
121
104
|
}
|
|
122
105
|
|
|
123
106
|
// For dynamically added content (modals, etc.), check again after a brief delay
|
|
124
107
|
setTimeout(() => {
|
|
125
|
-
const input = document.getElementById("<%= object.picker_id %>")
|
|
108
|
+
const input = document.getElementById("<%= object.picker_id %>");
|
|
126
109
|
if (input && !input._flatpickr) {
|
|
127
|
-
|
|
110
|
+
loadDatePicker();
|
|
128
111
|
}
|
|
129
|
-
}, 100)
|
|
112
|
+
}, 100);
|
|
130
113
|
|
|
131
114
|
if (<%= !object.custom_event_type.empty? %>) {
|
|
132
|
-
window.addEventListener("<%= object.custom_event_type %>",
|
|
115
|
+
window.addEventListener("<%= object.custom_event_type %>", () => {
|
|
116
|
+
loadDatePicker()
|
|
117
|
+
})
|
|
133
118
|
}
|
|
134
119
|
})()
|
|
135
120
|
<% end %>
|
|
@@ -36,10 +36,10 @@ const DatePickerDialogSubmission = () => {
|
|
|
36
36
|
<Dialog.Body>
|
|
37
37
|
<DatePicker
|
|
38
38
|
defaultDate={dateFixed || undefined}
|
|
39
|
-
key={
|
|
39
|
+
key={`fixed-${pickerInstance}`}
|
|
40
40
|
label="Date"
|
|
41
41
|
onChange={(dateStr) => setDateFixed(dateStr || "")}
|
|
42
|
-
pickerId={
|
|
42
|
+
pickerId={`datePickerFixed-${pickerInstance}`}
|
|
43
43
|
staticPosition={false}
|
|
44
44
|
/>
|
|
45
45
|
</Dialog.Body>
|
|
@@ -8,25 +8,6 @@
|
|
|
8
8
|
cursor: grab;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
&.is_touch_active {
|
|
12
|
-
.pb_draggable_handle,
|
|
13
|
-
.card_draggable_handle {
|
|
14
|
-
color: $text_lt_default;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.pb_draggable_handle,
|
|
19
|
-
.card_draggable_handle {
|
|
20
|
-
touch-action: none;
|
|
21
|
-
-webkit-touch-callout: none;
|
|
22
|
-
user-select: none;
|
|
23
|
-
cursor: grab;
|
|
24
|
-
|
|
25
|
-
&:active {
|
|
26
|
-
color: $text_lt_default;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
11
|
&.is_dragging {
|
|
31
12
|
position: relative;
|
|
32
13
|
|
|
@@ -5,5 +5,3 @@ Use the `draggable` kit and manage state as shown.
|
|
|
5
5
|
`draggable/draggable_container` kit creates the container within which the cards can be dragged and dropped.
|
|
6
6
|
|
|
7
7
|
The Card kit is optimized to work with the draggable kit. To enable drag, use the `draggable_item` and `drag_id` props on the Card kit as shown. An additional optional boolean prop (set to true by default) of `drag_handle` is also available to show the drag handle icon.
|
|
8
|
-
|
|
9
|
-
On touch devices, drag from the grip handle (no long press). Swiping the card body scrolls as usual. Keep `drag_handle` enabled on mobile. Desktop mouse drag is unchanged.
|
|
@@ -6,5 +6,4 @@ Use `DraggableProvider` and manage state as shown.
|
|
|
6
6
|
|
|
7
7
|
The Card kit is optimized to work with the draggable kit. To enable drag, use the `draggableItem` and `dragId` props on the Card kit as shown. An additional optional boolean prop (set to true by default) of `dragHandle` is also available to show the drag handle icon.
|
|
8
8
|
|
|
9
|
-
On touch devices, drag from the grip handle (no long press). Swiping the card body scrolls as usual. Keep `dragHandle` enabled on mobile. Desktop mouse drag is unchanged.
|
|
10
9
|
|
|
@@ -3,5 +3,3 @@ For a simplified version of the Draggable API for the List kit, you can do the f
|
|
|
3
3
|
The List kit is optimized to work with the draggable kit. To enable drag, use the `enable_drag` prop on List kit with an array of the included items AND `drag_id` prop on ListItems. You will also need to include the `items` prop containing your array of listed items for the Draggable API.
|
|
4
4
|
|
|
5
5
|
An additional optional boolean prop (set to true by default) of `drag_handle` is also available on ListItem kit to show the drag handle icon.
|
|
6
|
-
|
|
7
|
-
On touch devices, drag from the grip handle (no long press). Swiping the rest of the row scrolls as usual. Keep `drag_handle` enabled on mobile. Desktop mouse drag is unchanged.
|
|
@@ -2,6 +2,4 @@ For a simplified version of the Draggable API for the List kit, you can do the f
|
|
|
2
2
|
|
|
3
3
|
Use `DraggableProvider` and manage state as shown.
|
|
4
4
|
|
|
5
|
-
The List kit is optimized to work with the draggable kit. To enable drag, use the `enableDrag` prop on List kit AND `dragId` prop on ListItem. An additional optional boolean prop (set to true by default) of `dragHandle` is also available on
|
|
6
|
-
|
|
7
|
-
On touch devices, drag from the grip handle (no long press). Swiping the rest of the row scrolls as usual. Keep `dragHandle` enabled on mobile. Desktop mouse drag is unchanged.
|
|
5
|
+
The List kit is optimized to work with the draggable kit. To enable drag, use the `enableDrag` prop on List kit AND `dragId` prop on ListItem. An additional optional boolean prop (set to true by default) of `dragHandle` is also available on List kit to show the drag handle icon.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
For a simplified version of the Draggable API for the SelectableList kit, you can do the following:
|
|
2
2
|
|
|
3
|
-
The SelectableList kit is optimized to work with the draggable kit. To enable drag, use the `enable_drag` prop on SelectableList kit AND `drag_id` prop within the SelectableList kit prop. An additional optional boolean prop (set to true by default) of `drag_handle` is also available on SelectableList kit to show the drag handle icon.
|
|
4
|
-
|
|
5
|
-
On touch devices, drag from the grip handle (no long press). Swiping the rest of the row scrolls as usual. Keep `drag_handle` enabled on mobile. Desktop mouse drag is unchanged.
|
|
3
|
+
The SelectableList kit is optimized to work with the draggable kit. To enable drag, use the `enable_drag` prop on SelectableList kit AND `drag_id` prop within the SelectableList kit prop. An additional optional boolean prop (set to true by default) of `drag_handle` is also available on SelectableList kit to show the drag handle icon.
|
|
@@ -2,6 +2,4 @@ For a simplified version of the Draggable API for the SelectableList kit, you ca
|
|
|
2
2
|
|
|
3
3
|
Use `DraggableProvider` and manage state as shown.
|
|
4
4
|
|
|
5
|
-
The SelectableList kit is optimized to work with the draggable kit. To enable drag, use the `enableDrag` prop on SelectableList kit AND `dragId` prop on SelectableList.Item. An additional optional boolean prop (set to true by default) of `dragHandle` is also available on SelectableList kit to show the drag handle icon.
|
|
6
|
-
|
|
7
|
-
On touch devices, drag from the grip handle (no long press). Swiping the rest of the row scrolls as usual. Keep `dragHandle` enabled on mobile. Desktop mouse drag is unchanged.
|
|
5
|
+
The SelectableList kit is optimized to work with the draggable kit. To enable drag, use the `enableDrag` prop on SelectableList kit AND `dragId` prop on SelectableList.Item. An additional optional boolean prop (set to true by default) of `dragHandle` is also available on SelectableList kit to show the drag handle icon.
|
|
@@ -211,14 +211,6 @@ test("Attached draggable HTML attributes", () => {
|
|
|
211
211
|
expect(item).toHaveAttribute("draggable");
|
|
212
212
|
});
|
|
213
213
|
|
|
214
|
-
test("draggable items expose data-pb-drag-id for touch reordering", () => {
|
|
215
|
-
render(<DefaultDraggableKit />);
|
|
216
|
-
const kit = screen.getByTestId(testId);
|
|
217
|
-
|
|
218
|
-
const item = kit.querySelector(".pb_draggable_item");
|
|
219
|
-
expect(item).toHaveAttribute("data-pb-drag-id", "1");
|
|
220
|
-
});
|
|
221
|
-
|
|
222
214
|
test("generated dragHandle with List", () => {
|
|
223
215
|
render(<DraggableKitWithList />);
|
|
224
216
|
const kit = screen.getByTestId(testId);
|
|
@@ -310,14 +302,6 @@ const DraggableMultipleContainers = () => {
|
|
|
310
302
|
);
|
|
311
303
|
};
|
|
312
304
|
|
|
313
|
-
test("draggable containers expose data-pb-drag-container when provided", () => {
|
|
314
|
-
render(<DraggableMultipleContainers />);
|
|
315
|
-
const kit = screen.getByTestId(testId);
|
|
316
|
-
|
|
317
|
-
const container = kit.querySelector('[data-testid="container-To Do"]');
|
|
318
|
-
expect(container).toHaveAttribute("data-pb-drag-container", "To Do");
|
|
319
|
-
});
|
|
320
|
-
|
|
321
305
|
test("renders multiple containers with correct items", () => {
|
|
322
306
|
render(<DraggableMultipleContainers />);
|
|
323
307
|
|
|
@@ -2,32 +2,7 @@ import PbEnhancedElement from "../pb_enhanced_element";
|
|
|
2
2
|
|
|
3
3
|
const DRAGGABLE_SELECTOR = "[data-pb-draggable]";
|
|
4
4
|
const DRAGGABLE_CONTAINER = ".pb_draggable_container";
|
|
5
|
-
const DRAG_HANDLE_SELECTOR = ".pb_draggable_handle, .card_draggable_handle";
|
|
6
5
|
const NEEDS_CLONE = ["shadow", "outline", "line"]; // clone only for these types
|
|
7
|
-
const DRAG_THRESHOLD_PX = 5;
|
|
8
|
-
|
|
9
|
-
const isTouchDragDevice = () => {
|
|
10
|
-
const hasTouch = "ontouchstart" in window;
|
|
11
|
-
const hasCoarsePointer =
|
|
12
|
-
typeof window.matchMedia === "function" &&
|
|
13
|
-
window.matchMedia("(hover: none) and (pointer: coarse)").matches;
|
|
14
|
-
|
|
15
|
-
return hasTouch || hasCoarsePointer;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getDragIdFromElement = (element) => {
|
|
19
|
-
const item = element?.closest(".pb_draggable_item");
|
|
20
|
-
if (!item) return null;
|
|
21
|
-
|
|
22
|
-
return item.getAttribute("data-pb-drag-id") || item.id;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const getContainerFromElement = (element) => {
|
|
26
|
-
const container = element?.closest(DRAGGABLE_CONTAINER);
|
|
27
|
-
if (!container) return null;
|
|
28
|
-
|
|
29
|
-
return container.getAttribute("data-pb-drag-container") || container.id;
|
|
30
|
-
};
|
|
31
6
|
|
|
32
7
|
export default class PbDraggable extends PbEnhancedElement {
|
|
33
8
|
static get selector() { return DRAGGABLE_SELECTOR; }
|
|
@@ -46,8 +21,6 @@ export default class PbDraggable extends PbEnhancedElement {
|
|
|
46
21
|
this.hasMultipleContainers = false;
|
|
47
22
|
this.dragZoneType = "";
|
|
48
23
|
this.dragZoneColor = "";
|
|
49
|
-
this.useTouchDrag = isTouchDragDevice();
|
|
50
|
-
this.touchCleanups = [];
|
|
51
24
|
|
|
52
25
|
// If DOM is already loaded, bind immediately; otherwise wait for DOMContentLoaded
|
|
53
26
|
if (document.readyState === "loading") {
|
|
@@ -81,14 +54,9 @@ export default class PbDraggable extends PbEnhancedElement {
|
|
|
81
54
|
|
|
82
55
|
this.element.querySelectorAll(".pb_draggable_item")
|
|
83
56
|
.forEach(item => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
item.addEventListener("dragstart", this.handleDragStart.bind(this));
|
|
89
|
-
item.addEventListener("dragend", this.handleDragEnd.bind(this));
|
|
90
|
-
item.addEventListener("dragenter", this.handleDragEnter.bind(this));
|
|
91
|
-
}
|
|
57
|
+
item.addEventListener("dragstart", this.handleDragStart.bind(this));
|
|
58
|
+
item.addEventListener("dragend", this.handleDragEnd.bind(this));
|
|
59
|
+
item.addEventListener("dragenter", this.handleDragEnter.bind(this));
|
|
92
60
|
});
|
|
93
61
|
|
|
94
62
|
containers.forEach(c => {
|
|
@@ -97,118 +65,8 @@ export default class PbDraggable extends PbEnhancedElement {
|
|
|
97
65
|
});
|
|
98
66
|
}
|
|
99
67
|
|
|
100
|
-
bindTouchDragForItem(item) {
|
|
101
|
-
const handle = item.querySelector(DRAG_HANDLE_SELECTOR);
|
|
102
|
-
const dragTarget = handle || item;
|
|
103
|
-
const state = {
|
|
104
|
-
active: false,
|
|
105
|
-
dragging: false,
|
|
106
|
-
startX: 0,
|
|
107
|
-
startY: 0,
|
|
108
|
-
lastTargetDragId: null,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const resetState = () => {
|
|
112
|
-
state.active = false;
|
|
113
|
-
state.dragging = false;
|
|
114
|
-
state.lastTargetDragId = null;
|
|
115
|
-
item.classList.remove("is_touch_active");
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const pointerEventFromTouch = (touch, target) => ({
|
|
119
|
-
target,
|
|
120
|
-
clientX: touch.clientX,
|
|
121
|
-
clientY: touch.clientY,
|
|
122
|
-
preventDefault: () => undefined,
|
|
123
|
-
stopPropagation: () => undefined,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const onTouchStart = (event) => {
|
|
127
|
-
if (handle && !handle.contains(event.target)) return;
|
|
128
|
-
|
|
129
|
-
const touch = event.touches[0];
|
|
130
|
-
if (!touch) return;
|
|
131
|
-
|
|
132
|
-
state.active = true;
|
|
133
|
-
state.startX = touch.clientX;
|
|
134
|
-
state.startY = touch.clientY;
|
|
135
|
-
item.classList.add("is_touch_active");
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const onTouchMove = (event) => {
|
|
139
|
-
if (!state.active) return;
|
|
140
|
-
|
|
141
|
-
const touch = event.touches[0];
|
|
142
|
-
if (!touch) return;
|
|
143
|
-
|
|
144
|
-
if (!state.dragging) {
|
|
145
|
-
const deltaX = touch.clientX - state.startX;
|
|
146
|
-
const deltaY = touch.clientY - state.startY;
|
|
147
|
-
|
|
148
|
-
if (Math.hypot(deltaX, deltaY) < DRAG_THRESHOLD_PX) return;
|
|
149
|
-
|
|
150
|
-
state.dragging = true;
|
|
151
|
-
this.handleDragStart(pointerEventFromTouch(touch, item));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
event.preventDefault();
|
|
155
|
-
|
|
156
|
-
const elementBelow = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
157
|
-
const targetItem = elementBelow?.closest(".pb_draggable_item");
|
|
158
|
-
const targetDragId = getDragIdFromElement(elementBelow);
|
|
159
|
-
|
|
160
|
-
if (targetItem && targetItem !== item && targetDragId !== state.lastTargetDragId) {
|
|
161
|
-
state.lastTargetDragId = targetDragId;
|
|
162
|
-
this.handleDragEnter(pointerEventFromTouch(touch, targetItem));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const targetContainer = getContainerFromElement(elementBelow);
|
|
166
|
-
if (targetContainer) {
|
|
167
|
-
const containerElement = elementBelow.closest(DRAGGABLE_CONTAINER);
|
|
168
|
-
if (containerElement) {
|
|
169
|
-
this.handleDragOver(pointerEventFromTouch(touch, containerElement));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const finishTouchDrag = (touch) => {
|
|
175
|
-
if (!state.active) return;
|
|
176
|
-
|
|
177
|
-
if (state.dragging && touch) {
|
|
178
|
-
const elementBelow = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
179
|
-
const containerElement = elementBelow?.closest(DRAGGABLE_CONTAINER);
|
|
180
|
-
|
|
181
|
-
if (containerElement) {
|
|
182
|
-
this.handleDrop(pointerEventFromTouch(touch, containerElement));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
this.handleDragEnd({ target: item });
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
resetState();
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const onTouchEnd = (event) => finishTouchDrag(event.changedTouches[0]);
|
|
192
|
-
const onTouchCancel = (event) => finishTouchDrag(event.changedTouches[0]);
|
|
193
|
-
|
|
194
|
-
dragTarget.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
195
|
-
dragTarget.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
196
|
-
dragTarget.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
197
|
-
dragTarget.addEventListener("touchcancel", onTouchCancel, { passive: true });
|
|
198
|
-
|
|
199
|
-
return () => {
|
|
200
|
-
dragTarget.removeEventListener("touchstart", onTouchStart);
|
|
201
|
-
dragTarget.removeEventListener("touchmove", onTouchMove);
|
|
202
|
-
dragTarget.removeEventListener("touchend", onTouchEnd);
|
|
203
|
-
dragTarget.removeEventListener("touchcancel", onTouchCancel);
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
68
|
/* ---------------- DRAG START ---------------- */
|
|
208
69
|
handleDragStart(event) {
|
|
209
|
-
const item = event.target.closest(".pb_draggable_item");
|
|
210
|
-
if (!item) return;
|
|
211
|
-
|
|
212
70
|
// Needed to prevent images within draggable items from being independently draggable
|
|
213
71
|
// Needed if using Image kit in draggable items
|
|
214
72
|
if (event.target.tagName.toLowerCase() === "img") {
|
|
@@ -216,9 +74,9 @@ export default class PbDraggable extends PbEnhancedElement {
|
|
|
216
74
|
return;
|
|
217
75
|
}
|
|
218
76
|
|
|
219
|
-
const container =
|
|
220
|
-
this.draggedItem =
|
|
221
|
-
this.draggedItemId =
|
|
77
|
+
const container = event.target.closest(DRAGGABLE_CONTAINER);
|
|
78
|
+
this.draggedItem = event.target;
|
|
79
|
+
this.draggedItemId = event.target.id;
|
|
222
80
|
this.dragZoneType = this.element.dataset.dropZoneType || "";
|
|
223
81
|
this.dragZoneColor = this.element.dataset.dropZoneColor || "";
|
|
224
82
|
|
|
@@ -264,7 +122,7 @@ export default class PbDraggable extends PbEnhancedElement {
|
|
|
264
122
|
}
|
|
265
123
|
|
|
266
124
|
if (this.dragZoneType !== "line") {
|
|
267
|
-
requestAnimationFrame(() => (
|
|
125
|
+
requestAnimationFrame(() => (event.target.style.opacity = "0.5"));
|
|
268
126
|
}
|
|
269
127
|
}
|
|
270
128
|
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
import { globalProps } from "../../utilities/globalProps";
|
|
10
10
|
import { DraggableContext } from "../context";
|
|
11
11
|
import { noop } from '../../utilities/object'
|
|
12
|
-
import { bindTouchDrag, isTouchDragDevice } from "../utilities/touchDrag";
|
|
13
12
|
|
|
14
13
|
type DraggableItemProps = {
|
|
15
14
|
aria?: { [key: string]: string };
|
|
@@ -55,76 +54,12 @@ const DraggableItem = (props: DraggableItemProps) => {
|
|
|
55
54
|
handleDragStart,
|
|
56
55
|
handleDragEnter,
|
|
57
56
|
handleDragEnd,
|
|
58
|
-
handleDrop,
|
|
59
|
-
handleDragOver,
|
|
60
57
|
dropZone = 'ghost',
|
|
61
58
|
dropZoneColor = 'neutral',
|
|
62
59
|
direction = 'horizontal'
|
|
63
60
|
} = DraggableContext();
|
|
64
61
|
|
|
65
62
|
const itemRef = React.useRef<HTMLElement>(null);
|
|
66
|
-
const [useTouchDrag, setUseTouchDrag] = React.useState(false);
|
|
67
|
-
const handlersRef = React.useRef({
|
|
68
|
-
handleDragStart,
|
|
69
|
-
handleDragEnter,
|
|
70
|
-
handleDragEnd,
|
|
71
|
-
handleDrop,
|
|
72
|
-
handleDragOver,
|
|
73
|
-
onDragStart,
|
|
74
|
-
onDragEnter,
|
|
75
|
-
onDragOver,
|
|
76
|
-
onDrop,
|
|
77
|
-
onDragEnd,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
handlersRef.current = {
|
|
81
|
-
handleDragStart,
|
|
82
|
-
handleDragEnter,
|
|
83
|
-
handleDragEnd,
|
|
84
|
-
handleDrop,
|
|
85
|
-
handleDragOver,
|
|
86
|
-
onDragStart,
|
|
87
|
-
onDragEnter,
|
|
88
|
-
onDragOver,
|
|
89
|
-
onDrop,
|
|
90
|
-
onDragEnd,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
React.useEffect(() => {
|
|
94
|
-
setUseTouchDrag(isTouchDragDevice());
|
|
95
|
-
}, []);
|
|
96
|
-
|
|
97
|
-
React.useEffect(() => {
|
|
98
|
-
if (!useTouchDrag || !itemRef.current || !dragId) return;
|
|
99
|
-
|
|
100
|
-
return bindTouchDrag({
|
|
101
|
-
dragId,
|
|
102
|
-
container,
|
|
103
|
-
itemElement: itemRef.current,
|
|
104
|
-
handlers: {
|
|
105
|
-
onDragStart: (id, itemContainer) => {
|
|
106
|
-
handlersRef.current.handleDragStart(id, itemContainer);
|
|
107
|
-
handlersRef.current.onDragStart();
|
|
108
|
-
},
|
|
109
|
-
onDragEnter: (targetDragId, targetContainer) => {
|
|
110
|
-
handlersRef.current.handleDragEnter(targetDragId, targetContainer);
|
|
111
|
-
handlersRef.current.onDragEnter();
|
|
112
|
-
},
|
|
113
|
-
onDragOver: (event, targetContainer) => {
|
|
114
|
-
handlersRef.current.handleDragOver(event, targetContainer);
|
|
115
|
-
handlersRef.current.onDragOver();
|
|
116
|
-
},
|
|
117
|
-
onDrop: (dropContainer) => {
|
|
118
|
-
handlersRef.current.handleDrop(dropContainer);
|
|
119
|
-
handlersRef.current.onDrop();
|
|
120
|
-
},
|
|
121
|
-
onDragEnd: () => {
|
|
122
|
-
handlersRef.current.handleDragEnd();
|
|
123
|
-
handlersRef.current.onDragEnd();
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
}, [useTouchDrag, dragId, container]);
|
|
128
63
|
|
|
129
64
|
const ariaProps = buildAriaProps(aria);
|
|
130
65
|
const dataProps = buildDataProps(data);
|
|
@@ -187,8 +122,7 @@ const DraggableItem = (props: DraggableItemProps) => {
|
|
|
187
122
|
{...dataProps}
|
|
188
123
|
{...htmlProps}
|
|
189
124
|
className={classes}
|
|
190
|
-
|
|
191
|
-
draggable={!useTouchDrag}
|
|
125
|
+
draggable
|
|
192
126
|
id={id}
|
|
193
127
|
key={dragId}
|
|
194
128
|
onDrag={onDrag}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<%
|
|
2
|
+
example_collection = [
|
|
3
|
+
OpenStruct.new(name: "Alabama", value: 1),
|
|
4
|
+
OpenStruct.new(name: "Alaska", value: 2),
|
|
5
|
+
OpenStruct.new(name: "Arizona", value: 3),
|
|
6
|
+
OpenStruct.new(name: "Arkansas", value: 4),
|
|
7
|
+
OpenStruct.new(name: "California", value: 5),
|
|
8
|
+
OpenStruct.new(name: "Colorado", value: 6),
|
|
9
|
+
OpenStruct.new(name: "Connecticut", value: 7),
|
|
10
|
+
OpenStruct.new(name: "Delaware", value: 8),
|
|
11
|
+
OpenStruct.new(name: "Florida", value: 9),
|
|
12
|
+
OpenStruct.new(name: "Georgia", value: 10),
|
|
13
|
+
]
|
|
14
|
+
%>
|
|
15
|
+
|
|
16
|
+
<%= pb_form_with(scope: :example, url: "", method: :get) do |form| %>
|
|
17
|
+
<%= form.select :example_select, [ ["Yes", 1], ["No", 2], ["Maybe", 3] ], props: { label: "Select Default" } %>
|
|
18
|
+
<%= form.select :example_select_2, [ ["Yes", 1], ["No", 2], ["Maybe", 3] ], props: { label: "Select with Blank Selection", blank_selection: "Blank selection..." } %>
|
|
19
|
+
<%= form.select :example_select_3, [ ["Yes", 1], ["No", 2], ["Maybe", 3] ], { include_blank: "Include blank..." }, {}, props: { label: "Select with Include Blank" } %>
|
|
20
|
+
<%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: "Collection Select Default" } %>
|
|
21
|
+
<%= form.collection_select :example_collection_select_2, example_collection, :value, :name, props: { label: "Collection Select with Blank Selection", blank_selection: "Blank selection..." } %>
|
|
22
|
+
<%= form.collection_select :example_collection_select_3, example_collection, :value, :name, { include_blank: "Include blank..." }, {}, props: { label: "Collection Select with Include Blank" } %>
|
|
23
|
+
<%= form.time_zone_select_field :example_time_zone_select, ActiveSupport::TimeZone.us_zones, props: { label: "Time Zone Select Default" } %>
|
|
24
|
+
<%= form.time_zone_select_field :example_time_zone_select_2, ActiveSupport::TimeZone.us_zones, { default: "Eastern Time (US & Canada)" }, props: { label: "Time Zone Select with a Default Selection" } %>
|
|
25
|
+
<%= form.time_zone_select_field :example_time_zone_select_3, ActiveSupport::TimeZone.us_zones, props: { label: "Time Zone Select with Blank Selection", blank_selection: "Blank selection..." } %>
|
|
26
|
+
<%= form.time_zone_select_field :example_time_zone_select_4, ActiveSupport::TimeZone.us_zones, { include_blank: "Include blank..." }, {}, props: { label: "Time Zone Select with Include Blank" } %>
|
|
27
|
+
<%= form.actions do |action| %>
|
|
28
|
+
<%= action.submit %>
|
|
29
|
+
<%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>
|
|
30
|
+
<% end %>
|
|
31
|
+
<% end %>
|