shadcn_phlexcomponents 0.1.17 → 0.1.18
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/javascript/controllers/accordion_controller.js +90 -100
- data/app/javascript/controllers/alert_dialog_controller.js +4 -4
- data/app/javascript/controllers/avatar_controller.js +11 -11
- data/app/javascript/controllers/checkbox_controller.js +26 -25
- data/app/javascript/controllers/collapsible_controller.js +36 -34
- data/app/javascript/controllers/combobox_controller.js +231 -262
- data/app/javascript/controllers/command_controller.js +184 -204
- data/app/javascript/controllers/date_picker_controller.js +257 -240
- data/app/javascript/controllers/date_range_picker_controller.js +200 -188
- data/app/javascript/controllers/dialog_controller.js +78 -78
- data/app/javascript/controllers/dropdown_menu_controller.js +208 -228
- data/app/javascript/controllers/dropdown_menu_sub_controller.js +97 -110
- data/app/javascript/controllers/form_field_controller.js +16 -16
- data/app/javascript/controllers/hover_card_controller.js +71 -68
- data/app/javascript/controllers/loading_button_controller.js +10 -10
- data/app/javascript/controllers/popover_controller.js +78 -84
- data/app/javascript/controllers/progress_controller.js +11 -11
- data/app/javascript/controllers/radio_group_controller.js +74 -74
- data/app/javascript/controllers/select_controller.js +232 -246
- data/app/javascript/controllers/sidebar_controller.js +27 -26
- data/app/javascript/controllers/sidebar_trigger_controller.js +9 -12
- data/app/javascript/controllers/slider_controller.js +74 -73
- data/app/javascript/controllers/switch_controller.js +23 -22
- data/app/javascript/controllers/tabs_controller.js +61 -60
- data/app/javascript/controllers/theme_switcher_controller.js +27 -27
- data/app/javascript/controllers/toast_container_controller.js +31 -44
- data/app/javascript/controllers/toast_controller.js +18 -18
- data/app/javascript/controllers/toggle_controller.js +17 -16
- data/app/javascript/controllers/toggle_group_controller.js +17 -16
- data/app/javascript/controllers/tooltip_controller.js +77 -74
- data/app/javascript/shadcn_phlexcomponents.js +58 -58
- data/app/javascript/utils/command.js +334 -392
- data/app/javascript/utils/floating_ui.js +108 -147
- data/app/javascript/utils/index.js +190 -253
- data/app/stylesheets/date_picker.css +1 -1
- data/app/stylesheets/shadcn_phlexcomponents.css +173 -0
- data/app/typescript/controllers/combobox_controller.ts +0 -1
- data/app/typescript/controllers/date_picker_controller.ts +25 -7
- data/app/typescript/controllers/tooltip_controller.ts +1 -1
- data/app/typescript/utils/command.ts +0 -2
- data/app/typescript/utils/floating_ui.ts +11 -20
- data/app/typescript/utils/index.ts +0 -7
- data/lib/shadcn_phlexcomponents/components/accordion.rb +1 -1
- data/lib/shadcn_phlexcomponents/components/alert_dialog.rb +6 -6
- data/lib/shadcn_phlexcomponents/components/base.rb +2 -2
- data/lib/shadcn_phlexcomponents/components/combobox.rb +13 -13
- data/lib/shadcn_phlexcomponents/components/command.rb +13 -13
- data/lib/shadcn_phlexcomponents/components/date_picker.rb +18 -12
- data/lib/shadcn_phlexcomponents/components/date_range_picker.rb +7 -3
- data/lib/shadcn_phlexcomponents/components/dialog.rb +6 -6
- data/lib/shadcn_phlexcomponents/components/sheet.rb +7 -7
- data/lib/shadcn_phlexcomponents/components/toggle.rb +1 -1
- data/lib/shadcn_phlexcomponents/version.rb +1 -1
- metadata +2 -1
@@ -1,200 +1,212 @@
|
|
1
|
-
import { DatePickerController } from
|
2
|
-
import dayjs from
|
3
|
-
import customParseFormat from
|
4
|
-
import utc from
|
1
|
+
import { DatePickerController } from './date_picker_controller';
|
2
|
+
import dayjs from 'dayjs';
|
3
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
4
|
+
import utc from 'dayjs/plugin/utc';
|
5
5
|
dayjs.extend(customParseFormat);
|
6
6
|
dayjs.extend(utc);
|
7
|
-
const DELIMITER =
|
8
|
-
const DAYJS_FORMAT =
|
7
|
+
const DELIMITER = ' - ';
|
8
|
+
const DAYJS_FORMAT = 'YYYY-MM-DD';
|
9
9
|
const DateRangePickerController = class extends DatePickerController {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}
|
43
|
-
inputDate(event) {
|
44
|
-
const value = event.target.value;
|
45
|
-
const dates = value.split(DELIMITER).filter((d) => d.length > 0);
|
46
|
-
if (dates.length > 0) {
|
47
|
-
const startDate = dates[0];
|
48
|
-
const endDate = dates[1];
|
49
|
-
let selectedDates = this.calendar.context.selectedDates;
|
50
|
-
if (dayjs(startDate, this.format, true).isValid()) {
|
51
|
-
const dayjsDate = dayjs(value, this.format).format(DAYJS_FORMAT);
|
52
|
-
selectedDates[0] = dayjsDate;
|
53
|
-
}
|
54
|
-
if (dayjs(endDate, this.format, true).isValid()) {
|
55
|
-
const dayjsDate = dayjs(endDate, this.format).format(DAYJS_FORMAT);
|
56
|
-
selectedDates[1] = dayjsDate;
|
57
|
-
}
|
58
|
-
selectedDates = selectedDates.filter((d) => !!d);
|
59
|
-
this.calendar.set({
|
60
|
-
selectedDates: selectedDates,
|
61
|
-
});
|
62
|
-
if (selectedDates[0]) {
|
63
|
-
this.dateValue = selectedDates[0];
|
64
|
-
}
|
65
|
-
if (selectedDates[1]) {
|
66
|
-
this.endDateValue = selectedDates[1];
|
67
|
-
}
|
68
|
-
} else {
|
69
|
-
this.calendar.set({
|
70
|
-
selectedDates: [],
|
71
|
-
});
|
72
|
-
this.dateValue = "";
|
73
|
-
this.endDateValue = "";
|
74
|
-
}
|
75
|
-
}
|
76
|
-
dateValueChanged(value) {
|
77
|
-
this.onClickDateListener = this.onClickDate.bind(this);
|
78
|
-
const endDate = this.endDateValue;
|
79
|
-
let datesDisplay = "";
|
80
|
-
if (value && value.length > 0) {
|
81
|
-
const dayjsDate = dayjs(value);
|
82
|
-
const formattedDate = dayjsDate.format(this.format);
|
83
|
-
this.hiddenInputTarget.value = dayjsDate.utc().format();
|
84
|
-
if (endDate) {
|
85
|
-
datesDisplay = `${formattedDate}${DELIMITER}${dayjs(endDate).format(this.format)}`;
|
86
|
-
} else {
|
87
|
-
datesDisplay = `${formattedDate}${DELIMITER}`;
|
88
|
-
}
|
89
|
-
} else {
|
90
|
-
this.hiddenInputTarget.value = "";
|
91
|
-
if (endDate) {
|
92
|
-
datesDisplay = `${DELIMITER}${dayjs(endDate).format(this.format)}`;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
if (this.hasInputTarget) this.inputTarget.value = datesDisplay;
|
96
|
-
if (this.hasTriggerTextTarget) {
|
97
|
-
const hasValue = (!!value && value.length > 0) || !!endDate;
|
98
|
-
this.triggerTarget.dataset.hasValue = `${hasValue}`;
|
99
|
-
if (this.triggerTarget.dataset.placeholder && !hasValue) {
|
100
|
-
this.triggerTextTarget.textContent =
|
101
|
-
this.triggerTarget.dataset.placeholder;
|
102
|
-
} else {
|
103
|
-
this.triggerTextTarget.textContent = datesDisplay;
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
endDateValueChanged(value) {
|
108
|
-
const startDate = this.dateValue;
|
109
|
-
let datesDisplay = "";
|
110
|
-
if (value && value.length > 0) {
|
111
|
-
const dayjsDate = dayjs(value);
|
112
|
-
const formattedDate = dayjsDate.format(this.format);
|
113
|
-
this.endHiddenInputTarget.value = dayjsDate.utc().format();
|
114
|
-
if (startDate) {
|
115
|
-
datesDisplay = `${dayjs(startDate).format(this.format)}${DELIMITER}${formattedDate}`;
|
116
|
-
} else {
|
117
|
-
datesDisplay = `${DELIMITER}${formattedDate}`;
|
118
|
-
}
|
119
|
-
} else {
|
120
|
-
this.endHiddenInputTarget.value = "";
|
121
|
-
if (startDate) {
|
122
|
-
datesDisplay = `${dayjs(startDate).format(this.format)}${DELIMITER}`;
|
123
|
-
}
|
10
|
+
// targets
|
11
|
+
static targets = [
|
12
|
+
'trigger',
|
13
|
+
'triggerText',
|
14
|
+
'contentContainer',
|
15
|
+
'content',
|
16
|
+
'input',
|
17
|
+
'hiddenInput',
|
18
|
+
'endHiddenInput',
|
19
|
+
'inputContainer',
|
20
|
+
'calendar',
|
21
|
+
'overlay',
|
22
|
+
];
|
23
|
+
// values
|
24
|
+
static values = {
|
25
|
+
isOpen: Boolean,
|
26
|
+
date: String,
|
27
|
+
endDate: String,
|
28
|
+
};
|
29
|
+
inputBlur() {
|
30
|
+
const dates = this.calendar.context.selectedDates;
|
31
|
+
const startDate = dates[0];
|
32
|
+
const endDate = dates[1];
|
33
|
+
let datesDisplay = '';
|
34
|
+
if (startDate) {
|
35
|
+
datesDisplay = `${dayjs(startDate).format(this.format)}${DELIMITER}`;
|
36
|
+
}
|
37
|
+
if (endDate) {
|
38
|
+
datesDisplay = `${datesDisplay}${dayjs(endDate).format(this.format)}`;
|
39
|
+
}
|
40
|
+
this.inputTarget.value = datesDisplay;
|
41
|
+
this.inputContainerTarget.dataset.focus = 'false';
|
124
42
|
}
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
43
|
+
inputDate(event) {
|
44
|
+
const value = event.target.value;
|
45
|
+
const dates = value.split(DELIMITER).filter((d) => d.length > 0);
|
46
|
+
if (dates.length > 0) {
|
47
|
+
const startDate = dates[0];
|
48
|
+
const endDate = dates[1];
|
49
|
+
let selectedDates = this.calendar.context.selectedDates;
|
50
|
+
if (dayjs(startDate, this.format, true).isValid()) {
|
51
|
+
const dayjsDate = dayjs(value, this.format).format(DAYJS_FORMAT);
|
52
|
+
selectedDates[0] = dayjsDate;
|
53
|
+
}
|
54
|
+
if (dayjs(endDate, this.format, true).isValid()) {
|
55
|
+
const dayjsDate = dayjs(endDate, this.format).format(DAYJS_FORMAT);
|
56
|
+
selectedDates[1] = dayjsDate;
|
57
|
+
}
|
58
|
+
selectedDates = selectedDates.filter((d) => !!d);
|
59
|
+
this.calendar.set({
|
60
|
+
selectedDates: selectedDates,
|
61
|
+
});
|
62
|
+
if (selectedDates[0]) {
|
63
|
+
this.dateValue = selectedDates[0];
|
64
|
+
}
|
65
|
+
if (selectedDates[1]) {
|
66
|
+
this.endDateValue = selectedDates[1];
|
67
|
+
}
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
this.calendar.set({
|
71
|
+
selectedDates: [],
|
72
|
+
});
|
73
|
+
this.dateValue = '';
|
74
|
+
this.endDateValue = '';
|
75
|
+
}
|
135
76
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
77
|
+
dateValueChanged(value) {
|
78
|
+
this.onClickDateListener = this.onClickDate.bind(this);
|
79
|
+
const endDate = this.endDateValue;
|
80
|
+
let datesDisplay = '';
|
81
|
+
if (value && value.length > 0) {
|
82
|
+
const dayjsDate = dayjs(value);
|
83
|
+
const formattedDate = dayjsDate.format(this.format);
|
84
|
+
this.hiddenInputTarget.value = dayjsDate.utc().format();
|
85
|
+
if (endDate) {
|
86
|
+
datesDisplay = `${formattedDate}${DELIMITER}${dayjs(endDate).format(this.format)}`;
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
datesDisplay = `${formattedDate}${DELIMITER}`;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
this.hiddenInputTarget.value = '';
|
94
|
+
if (endDate) {
|
95
|
+
datesDisplay = `${DELIMITER}${dayjs(endDate).format(this.format)}`;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
if (this.hasInputTarget)
|
99
|
+
this.inputTarget.value = datesDisplay;
|
100
|
+
if (this.hasTriggerTextTarget) {
|
101
|
+
const hasValue = (!!value && value.length > 0) || !!endDate;
|
102
|
+
this.triggerTarget.dataset.hasValue = `${hasValue}`;
|
103
|
+
if (this.triggerTarget.dataset.placeholder && !hasValue) {
|
104
|
+
this.triggerTextTarget.textContent =
|
105
|
+
this.triggerTarget.dataset.placeholder;
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
this.triggerTextTarget.textContent = datesDisplay;
|
109
|
+
}
|
110
|
+
}
|
153
111
|
}
|
154
|
-
|
155
|
-
|
156
|
-
|
112
|
+
endDateValueChanged(value) {
|
113
|
+
const startDate = this.dateValue;
|
114
|
+
let datesDisplay = '';
|
115
|
+
if (value && value.length > 0) {
|
116
|
+
const dayjsDate = dayjs(value);
|
117
|
+
const formattedDate = dayjsDate.format(this.format);
|
118
|
+
this.endHiddenInputTarget.value = dayjsDate.utc().format();
|
119
|
+
if (startDate) {
|
120
|
+
datesDisplay = `${dayjs(startDate).format(this.format)}${DELIMITER}${formattedDate}`;
|
121
|
+
}
|
122
|
+
else {
|
123
|
+
datesDisplay = `${DELIMITER}${formattedDate}`;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
else {
|
127
|
+
this.endHiddenInputTarget.value = '';
|
128
|
+
if (startDate) {
|
129
|
+
datesDisplay = `${dayjs(startDate).format(this.format)}${DELIMITER}`;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if (this.hasInputTarget)
|
133
|
+
this.inputTarget.value = datesDisplay;
|
134
|
+
if (this.hasTriggerTextTarget) {
|
135
|
+
const hasValue = (!!value && value.length > 0) || !!startDate;
|
136
|
+
this.triggerTarget.dataset.hasValue = `${hasValue}`;
|
137
|
+
if (this.triggerTarget.dataset.placeholder && !hasValue) {
|
138
|
+
this.triggerTextTarget.textContent =
|
139
|
+
this.triggerTarget.dataset.placeholder;
|
140
|
+
}
|
141
|
+
else {
|
142
|
+
this.triggerTextTarget.textContent = datesDisplay;
|
143
|
+
}
|
144
|
+
}
|
157
145
|
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
146
|
+
getOptions() {
|
147
|
+
let options = {
|
148
|
+
type: 'multiple',
|
149
|
+
selectionDatesMode: 'multiple-ranged',
|
150
|
+
displayMonthsCount: 2,
|
151
|
+
monthsToSwitch: 1,
|
152
|
+
displayDatesOutside: false,
|
153
|
+
enableJumpToSelectedDate: true,
|
154
|
+
onClickDate: this.onClickDateListener,
|
155
|
+
};
|
156
|
+
const selectedDates = [];
|
157
|
+
const startDate = this.element.dataset.value;
|
158
|
+
const endDate = this.element.dataset.endValue;
|
159
|
+
if (startDate && dayjs(startDate).isValid()) {
|
160
|
+
const date = dayjs(startDate).format(DAYJS_FORMAT);
|
161
|
+
selectedDates.push(date);
|
162
|
+
}
|
163
|
+
if (endDate && dayjs(endDate).isValid()) {
|
164
|
+
const date = dayjs(endDate).format(DAYJS_FORMAT);
|
165
|
+
selectedDates.push(date);
|
166
|
+
}
|
167
|
+
options.selectedDates = selectedDates;
|
168
|
+
try {
|
169
|
+
options = {
|
170
|
+
...options,
|
171
|
+
...JSON.parse(this.element.dataset.options || ''),
|
172
|
+
};
|
173
|
+
}
|
174
|
+
catch {
|
175
|
+
// noop
|
176
|
+
}
|
177
|
+
if (options.selectedDates && options.selectedDates.length > 0) {
|
178
|
+
this.dateValue = `${options.selectedDates[0]}`;
|
179
|
+
if (options.selectedDates[1]) {
|
180
|
+
this.endDateValue = `${options.selectedDates[1]}`;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
return options;
|
166
184
|
}
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
185
|
+
onClickDate(self) {
|
186
|
+
const dates = self.context.selectedDates;
|
187
|
+
if (dates.length > 0) {
|
188
|
+
const startDate = dates[0];
|
189
|
+
const endDate = dates[1];
|
190
|
+
this.dateValue = startDate;
|
191
|
+
if (endDate) {
|
192
|
+
this.endDateValue = endDate;
|
193
|
+
this.close();
|
194
|
+
}
|
195
|
+
else {
|
196
|
+
this.endDateValue = '';
|
197
|
+
}
|
198
|
+
}
|
199
|
+
else {
|
200
|
+
this.dateValue = '';
|
201
|
+
this.endDateValue = '';
|
202
|
+
}
|
172
203
|
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const endDate = dates[1];
|
180
|
-
this.dateValue = startDate;
|
181
|
-
if (endDate) {
|
182
|
-
this.endDateValue = endDate;
|
183
|
-
this.close();
|
184
|
-
} else {
|
185
|
-
this.endDateValue = "";
|
186
|
-
}
|
187
|
-
} else {
|
188
|
-
this.dateValue = "";
|
189
|
-
this.endDateValue = "";
|
204
|
+
setupInputMask() {
|
205
|
+
const pattern = this.format.replace(/[^\/]/g, '9');
|
206
|
+
const im = new Inputmask(`${pattern}${DELIMITER}${pattern}`, {
|
207
|
+
showMaskOnHover: false,
|
208
|
+
});
|
209
|
+
im.mask(this.inputTarget);
|
190
210
|
}
|
191
|
-
}
|
192
|
-
setupInputMask() {
|
193
|
-
const pattern = this.format.replace(/[^\/]/g, "9");
|
194
|
-
const im = new Inputmask(`${pattern}${DELIMITER}${pattern}`, {
|
195
|
-
showMaskOnHover: false,
|
196
|
-
});
|
197
|
-
im.mask(this.inputTarget);
|
198
|
-
}
|
199
211
|
};
|
200
212
|
export { DateRangePickerController };
|
@@ -1,83 +1,83 @@
|
|
1
|
-
import { Controller } from
|
2
|
-
import {
|
3
|
-
focusElement,
|
4
|
-
focusTrigger,
|
5
|
-
showContent,
|
6
|
-
hideContent,
|
7
|
-
getFocusableElements,
|
8
|
-
anyNestedComponentsOpen,
|
9
|
-
handleTabNavigation,
|
10
|
-
} from "../utils";
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import { focusElement, focusTrigger, showContent, hideContent, getFocusableElements, anyNestedComponentsOpen, handleTabNavigation, } from '../utils';
|
11
3
|
const DialogController = class extends Controller {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
open() {
|
23
|
-
this.isOpenValue = true;
|
24
|
-
}
|
25
|
-
close() {
|
26
|
-
this.isOpenValue = false;
|
27
|
-
}
|
28
|
-
isOpenValueChanged(isOpen, previousIsOpen) {
|
29
|
-
if (isOpen) {
|
30
|
-
showContent({
|
31
|
-
trigger: this.triggerTarget,
|
32
|
-
content: this.contentTarget,
|
33
|
-
contentContainer: this.contentTarget,
|
34
|
-
appendToBody: true,
|
35
|
-
overlay: this.overlayTarget,
|
36
|
-
});
|
37
|
-
const focusableElements = getFocusableElements(this.contentTarget);
|
38
|
-
focusElement(focusableElements[0]);
|
39
|
-
this.setupEventListeners();
|
40
|
-
} else {
|
41
|
-
hideContent({
|
42
|
-
trigger: this.triggerTarget,
|
43
|
-
content: this.contentTarget,
|
44
|
-
contentContainer: this.contentTarget,
|
45
|
-
overlay: this.overlayTarget,
|
46
|
-
});
|
47
|
-
if (previousIsOpen) {
|
48
|
-
focusTrigger(this.triggerTarget);
|
49
|
-
}
|
50
|
-
this.cleanupEventListeners();
|
4
|
+
// targets
|
5
|
+
static targets = ['trigger', 'content', 'overlay'];
|
6
|
+
// values
|
7
|
+
static values = {
|
8
|
+
isOpen: Boolean,
|
9
|
+
};
|
10
|
+
connect() {
|
11
|
+
this.DOMKeydownListener = this.onDOMKeydown.bind(this);
|
12
|
+
this.DOMClickListener = this.onDOMClick.bind(this);
|
51
13
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
14
|
+
open() {
|
15
|
+
this.isOpenValue = true;
|
16
|
+
}
|
17
|
+
close() {
|
18
|
+
this.isOpenValue = false;
|
19
|
+
}
|
20
|
+
isOpenValueChanged(isOpen, previousIsOpen) {
|
21
|
+
if (isOpen) {
|
22
|
+
showContent({
|
23
|
+
trigger: this.triggerTarget,
|
24
|
+
content: this.contentTarget,
|
25
|
+
contentContainer: this.contentTarget,
|
26
|
+
appendToBody: true,
|
27
|
+
overlay: this.overlayTarget,
|
28
|
+
});
|
29
|
+
const focusableElements = getFocusableElements(this.contentTarget);
|
30
|
+
focusElement(focusableElements[0]);
|
31
|
+
this.setupEventListeners();
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
hideContent({
|
35
|
+
trigger: this.triggerTarget,
|
36
|
+
content: this.contentTarget,
|
37
|
+
contentContainer: this.contentTarget,
|
38
|
+
overlay: this.overlayTarget,
|
39
|
+
});
|
40
|
+
if (previousIsOpen) {
|
41
|
+
focusTrigger(this.triggerTarget);
|
42
|
+
}
|
43
|
+
this.cleanupEventListeners();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
disconnect() {
|
47
|
+
this.cleanupEventListeners();
|
48
|
+
}
|
49
|
+
onDOMClick(event) {
|
50
|
+
if (!this.isOpenValue)
|
51
|
+
return;
|
52
|
+
const target = event.target;
|
53
|
+
if (target === this.triggerTarget)
|
54
|
+
return;
|
55
|
+
if (this.contentTarget.contains(target))
|
56
|
+
return;
|
57
|
+
const shouldClose = !anyNestedComponentsOpen(this.contentTarget);
|
58
|
+
if (shouldClose)
|
59
|
+
this.close();
|
60
|
+
}
|
61
|
+
onDOMKeydown(event) {
|
62
|
+
if (!this.isOpenValue)
|
63
|
+
return;
|
64
|
+
const key = event.key;
|
65
|
+
if (key === 'Escape') {
|
66
|
+
const shouldClose = !anyNestedComponentsOpen(this.contentTarget);
|
67
|
+
if (shouldClose)
|
68
|
+
this.close();
|
69
|
+
}
|
70
|
+
else if (key === 'Tab') {
|
71
|
+
handleTabNavigation(this.contentTarget, event);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
setupEventListeners() {
|
75
|
+
document.addEventListener('keydown', this.DOMKeydownListener);
|
76
|
+
document.addEventListener('pointerdown', this.DOMClickListener);
|
77
|
+
}
|
78
|
+
cleanupEventListeners() {
|
79
|
+
document.removeEventListener('keydown', this.DOMKeydownListener);
|
80
|
+
document.removeEventListener('pointerdown', this.DOMClickListener);
|
72
81
|
}
|
73
|
-
}
|
74
|
-
setupEventListeners() {
|
75
|
-
document.addEventListener("keydown", this.DOMKeydownListener);
|
76
|
-
document.addEventListener("pointerdown", this.DOMClickListener);
|
77
|
-
}
|
78
|
-
cleanupEventListeners() {
|
79
|
-
document.removeEventListener("keydown", this.DOMKeydownListener);
|
80
|
-
document.removeEventListener("pointerdown", this.DOMClickListener);
|
81
|
-
}
|
82
82
|
};
|
83
83
|
export { DialogController };
|