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