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,275 +1,274 @@
|
|
1
|
-
import { Controller } from
|
2
|
-
import { useClickOutside } from
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
2
|
+
import { useClickOutside } from "stimulus-use";
|
3
|
+
import {
|
4
|
+
focusTrigger,
|
5
|
+
getFocusableElements,
|
6
|
+
showContent,
|
7
|
+
hideContent,
|
8
|
+
lockScroll,
|
9
|
+
unlockScroll,
|
10
|
+
handleTabNavigation,
|
11
|
+
focusElement,
|
12
|
+
} from "../utils";
|
13
|
+
import { initFloatingUi } from "../utils/floating_ui";
|
14
|
+
import { Calendar } from "vanilla-calendar-pro";
|
15
|
+
import Inputmask from "inputmask";
|
16
|
+
import dayjs from "dayjs";
|
17
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
18
|
+
import utc from "dayjs/plugin/utc";
|
10
19
|
dayjs.extend(customParseFormat);
|
11
20
|
dayjs.extend(utc);
|
12
21
|
const SMALL_SCREEN_BREAKPOINT = 768;
|
13
22
|
const isSmallScreen = () => {
|
14
|
-
|
23
|
+
return window.innerWidth < SMALL_SCREEN_BREAKPOINT;
|
15
24
|
};
|
16
|
-
const DAYJS_FORMAT =
|
25
|
+
const DAYJS_FORMAT = "YYYY-MM-DD";
|
17
26
|
const DatePickerController = class extends Controller {
|
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
|
-
this.calendarTarget.removeAttribute('tabindex');
|
44
|
-
useClickOutside(this, { element: this.contentTarget, dispatchEvent: false });
|
27
|
+
static name = "date-picker";
|
28
|
+
// targets
|
29
|
+
static targets = [
|
30
|
+
"trigger",
|
31
|
+
"triggerText",
|
32
|
+
"contentContainer",
|
33
|
+
"content",
|
34
|
+
"input",
|
35
|
+
"hiddenInput",
|
36
|
+
"inputContainer",
|
37
|
+
"calendar",
|
38
|
+
"overlay",
|
39
|
+
];
|
40
|
+
// values
|
41
|
+
static values = { isOpen: Boolean, date: String };
|
42
|
+
connect() {
|
43
|
+
this.format = this.element.dataset.format || "DD/MM/YYYY";
|
44
|
+
this.mask = this.element.dataset.mask === "true";
|
45
|
+
this.DOMKeydownListener = this.onDOMKeydown.bind(this);
|
46
|
+
this.onClickDateListener = this.onClickDate.bind(this);
|
47
|
+
const options = this.getOptions();
|
48
|
+
this.calendar = new Calendar(this.calendarTarget, options);
|
49
|
+
this.calendar.init();
|
50
|
+
if (this.hasInputTarget && this.mask) {
|
51
|
+
this.setupInputMask();
|
45
52
|
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
this.calendarTarget.removeAttribute("tabindex");
|
54
|
+
useClickOutside(this, {
|
55
|
+
element: this.contentTarget,
|
56
|
+
dispatchEvent: false,
|
57
|
+
});
|
58
|
+
}
|
59
|
+
contentContainerTargetConnected() {
|
60
|
+
if (isSmallScreen()) {
|
61
|
+
const windowHeight = window.innerHeight;
|
62
|
+
const datePickerHeight = this.identifier === "date-picker" ? 300 : 600;
|
63
|
+
let topOffset = 0;
|
64
|
+
if (windowHeight > datePickerHeight) {
|
65
|
+
topOffset = (windowHeight - datePickerHeight) / 2;
|
66
|
+
}
|
67
|
+
Object.assign(this.contentContainerTarget.style, {
|
68
|
+
top: `${topOffset}px`,
|
69
|
+
left: "50%",
|
70
|
+
transform: "translateX(-50%)",
|
71
|
+
pointerEvents: "auto",
|
72
|
+
});
|
61
73
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
}
|
74
|
+
}
|
75
|
+
toggle() {
|
76
|
+
if (this.isOpenValue) {
|
77
|
+
this.close();
|
78
|
+
} else {
|
79
|
+
this.open();
|
69
80
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
this.inputTarget.value = dateDisplay;
|
83
|
-
this.inputContainerTarget.dataset.focus = 'false';
|
81
|
+
}
|
82
|
+
open() {
|
83
|
+
this.isOpenValue = true;
|
84
|
+
}
|
85
|
+
close() {
|
86
|
+
this.isOpenValue = false;
|
87
|
+
}
|
88
|
+
inputBlur() {
|
89
|
+
let dateDisplay = "";
|
90
|
+
const date = this.calendar.context.selectedDates[0];
|
91
|
+
if (date) {
|
92
|
+
dateDisplay = dayjs(date).format(this.format);
|
84
93
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
this.calendar.set({
|
96
|
-
selectedDates: [dayjsDate],
|
97
|
-
});
|
98
|
-
this.dateValue = dayjsDate;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
setContainerFocus() {
|
102
|
-
this.inputContainerTarget.dataset.focus = 'true';
|
103
|
-
}
|
104
|
-
clickOutside(event) {
|
105
|
-
const target = event.target;
|
106
|
-
// Let trigger handle state
|
107
|
-
if (target === this.triggerTarget)
|
108
|
-
return;
|
109
|
-
if (this.triggerTarget.contains(target))
|
110
|
-
return;
|
111
|
-
if (this.triggerTarget.id === target.getAttribute('for'))
|
112
|
-
return;
|
113
|
-
this.close();
|
114
|
-
}
|
115
|
-
isOpenValueChanged(isOpen, previousIsOpen) {
|
116
|
-
if (isOpen) {
|
117
|
-
showContent({
|
118
|
-
trigger: this.triggerTarget,
|
119
|
-
content: this.contentTarget,
|
120
|
-
contentContainer: this.contentContainerTarget,
|
121
|
-
});
|
122
|
-
// Prevent width from changing when changing to month/year view
|
123
|
-
if (!this.contentTarget.dataset.width) {
|
124
|
-
const contentWidth = this.contentTarget.offsetWidth;
|
125
|
-
this.contentTarget.dataset.width = `${contentWidth}`;
|
126
|
-
this.contentTarget.style.maxWidth = `${contentWidth}px`;
|
127
|
-
this.contentTarget.style.minWidth = `${contentWidth}px`;
|
128
|
-
}
|
129
|
-
if (isSmallScreen()) {
|
130
|
-
lockScroll(this.contentTarget.id);
|
131
|
-
this.overlayTarget.style.display = '';
|
132
|
-
this.overlayTarget.dataset.state = 'open';
|
133
|
-
}
|
134
|
-
else {
|
135
|
-
this.cleanup = initFloatingUi({
|
136
|
-
referenceElement: this.hasInputTarget
|
137
|
-
? this.inputTarget
|
138
|
-
: this.triggerTarget,
|
139
|
-
floatingElement: this.contentContainerTarget,
|
140
|
-
side: this.contentTarget.dataset.side,
|
141
|
-
align: this.contentTarget.dataset.align,
|
142
|
-
sideOffset: 4,
|
143
|
-
});
|
144
|
-
}
|
145
|
-
let elementToFocus = null;
|
146
|
-
const focusableElements = getFocusableElements(this.contentTarget);
|
147
|
-
const selectedElement = Array.from(focusableElements).find((e) => e.ariaSelected);
|
148
|
-
const currentElement = this.contentTarget.querySelector('[aria-current]');
|
149
|
-
if (selectedElement) {
|
150
|
-
elementToFocus = selectedElement;
|
151
|
-
}
|
152
|
-
else if (currentElement) {
|
153
|
-
const firstElementChild = currentElement.firstElementChild;
|
154
|
-
elementToFocus = firstElementChild;
|
155
|
-
}
|
156
|
-
else {
|
157
|
-
elementToFocus = focusableElements[0];
|
158
|
-
}
|
159
|
-
focusElement(elementToFocus);
|
160
|
-
this.setupEventListeners();
|
161
|
-
}
|
162
|
-
else {
|
163
|
-
hideContent({
|
164
|
-
trigger: this.triggerTarget,
|
165
|
-
content: this.contentTarget,
|
166
|
-
contentContainer: this.contentContainerTarget,
|
167
|
-
});
|
168
|
-
if (isSmallScreen()) {
|
169
|
-
unlockScroll(this.contentTarget.id);
|
170
|
-
this.overlayTarget.style.display = 'none';
|
171
|
-
this.overlayTarget.dataset.state = 'closed';
|
172
|
-
}
|
173
|
-
if (previousIsOpen) {
|
174
|
-
focusTrigger(this.triggerTarget);
|
175
|
-
}
|
176
|
-
this.cleanupEventListeners();
|
177
|
-
}
|
94
|
+
this.inputTarget.value = dateDisplay;
|
95
|
+
this.inputContainerTarget.dataset.focus = "false";
|
96
|
+
}
|
97
|
+
inputDate(event) {
|
98
|
+
const value = event.target.value;
|
99
|
+
if (value.length === 0) {
|
100
|
+
this.calendar.set({
|
101
|
+
selectedDates: [],
|
102
|
+
});
|
103
|
+
this.dateValue = "";
|
178
104
|
}
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if (this.hasTriggerTextTarget) {
|
186
|
-
this.triggerTarget.dataset.hasValue = 'true';
|
187
|
-
this.triggerTextTarget.textContent = formattedDate;
|
188
|
-
}
|
189
|
-
this.hiddenInputTarget.value = dayjsDate.utc().format();
|
190
|
-
}
|
191
|
-
else {
|
192
|
-
if (this.hasInputTarget)
|
193
|
-
this.inputTarget.value = '';
|
194
|
-
if (this.hasTriggerTextTarget) {
|
195
|
-
this.triggerTarget.dataset.hasValue = 'false';
|
196
|
-
if (this.triggerTarget.dataset.placeholder) {
|
197
|
-
this.triggerTextTarget.textContent =
|
198
|
-
this.triggerTarget.dataset.placeholder;
|
199
|
-
}
|
200
|
-
else {
|
201
|
-
this.triggerTextTarget.textContent = '';
|
202
|
-
}
|
203
|
-
}
|
204
|
-
this.hiddenInputTarget.value = '';
|
205
|
-
}
|
105
|
+
if (value.length > 0 && dayjs(value, this.format, true).isValid()) {
|
106
|
+
const dayjsDate = dayjs(value, this.format).format(DAYJS_FORMAT);
|
107
|
+
this.calendar.set({
|
108
|
+
selectedDates: [dayjsDate],
|
109
|
+
});
|
110
|
+
this.dateValue = dayjsDate;
|
206
111
|
}
|
207
|
-
|
208
|
-
|
112
|
+
}
|
113
|
+
setContainerFocus() {
|
114
|
+
this.inputContainerTarget.dataset.focus = "true";
|
115
|
+
}
|
116
|
+
clickOutside(event) {
|
117
|
+
const target = event.target;
|
118
|
+
// Let trigger handle state
|
119
|
+
if (target === this.triggerTarget) return;
|
120
|
+
if (this.triggerTarget.contains(target)) return;
|
121
|
+
if (this.triggerTarget.id === target.getAttribute("for")) return;
|
122
|
+
this.close();
|
123
|
+
}
|
124
|
+
isOpenValueChanged(isOpen, previousIsOpen) {
|
125
|
+
if (isOpen) {
|
126
|
+
showContent({
|
127
|
+
trigger: this.triggerTarget,
|
128
|
+
content: this.contentTarget,
|
129
|
+
contentContainer: this.contentContainerTarget,
|
130
|
+
});
|
131
|
+
// Prevent width from changing when changing to month/year view
|
132
|
+
if (!this.contentTarget.dataset.width) {
|
133
|
+
const contentWidth = this.contentTarget.offsetWidth;
|
134
|
+
this.contentTarget.dataset.width = `${contentWidth}`;
|
135
|
+
this.contentTarget.style.maxWidth = `${contentWidth}px`;
|
136
|
+
this.contentTarget.style.minWidth = `${contentWidth}px`;
|
137
|
+
}
|
138
|
+
if (isSmallScreen()) {
|
139
|
+
lockScroll(this.contentTarget.id);
|
140
|
+
this.overlayTarget.style.display = "";
|
141
|
+
this.overlayTarget.dataset.state = "open";
|
142
|
+
} else {
|
143
|
+
this.cleanup = initFloatingUi({
|
144
|
+
referenceElement: this.hasInputTarget
|
145
|
+
? this.inputTarget
|
146
|
+
: this.triggerTarget,
|
147
|
+
floatingElement: this.contentContainerTarget,
|
148
|
+
side: this.contentTarget.dataset.side,
|
149
|
+
align: this.contentTarget.dataset.align,
|
150
|
+
sideOffset: 4,
|
151
|
+
});
|
152
|
+
}
|
153
|
+
let elementToFocus = null;
|
154
|
+
const focusableElements = getFocusableElements(this.contentTarget);
|
155
|
+
const selectedElement = Array.from(focusableElements).find(
|
156
|
+
(e) => e.ariaSelected,
|
157
|
+
);
|
158
|
+
const currentElement = this.contentTarget.querySelector("[aria-current]");
|
159
|
+
if (selectedElement) {
|
160
|
+
elementToFocus = selectedElement;
|
161
|
+
} else if (currentElement) {
|
162
|
+
const firstElementChild = currentElement.firstElementChild;
|
163
|
+
elementToFocus = firstElementChild;
|
164
|
+
} else {
|
165
|
+
elementToFocus = focusableElements[0];
|
166
|
+
}
|
167
|
+
focusElement(elementToFocus);
|
168
|
+
this.setupEventListeners();
|
169
|
+
} else {
|
170
|
+
hideContent({
|
171
|
+
trigger: this.triggerTarget,
|
172
|
+
content: this.contentTarget,
|
173
|
+
contentContainer: this.contentContainerTarget,
|
174
|
+
});
|
175
|
+
if (isSmallScreen()) {
|
176
|
+
unlockScroll(this.contentTarget.id);
|
177
|
+
this.overlayTarget.style.display = "none";
|
178
|
+
this.overlayTarget.dataset.state = "closed";
|
179
|
+
}
|
180
|
+
if (previousIsOpen) {
|
181
|
+
focusTrigger(this.triggerTarget);
|
182
|
+
}
|
183
|
+
this.cleanupEventListeners();
|
209
184
|
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
185
|
+
}
|
186
|
+
dateValueChanged(value) {
|
187
|
+
if (value && value.length > 0) {
|
188
|
+
const dayjsDate = dayjs(value);
|
189
|
+
const formattedDate = dayjsDate.format(this.format);
|
190
|
+
if (this.hasInputTarget) this.inputTarget.value = formattedDate;
|
191
|
+
if (this.hasTriggerTextTarget) {
|
192
|
+
this.triggerTarget.dataset.hasValue = "true";
|
193
|
+
this.triggerTextTarget.textContent = formattedDate;
|
194
|
+
}
|
195
|
+
this.hiddenInputTarget.value = dayjsDate.utc().format();
|
196
|
+
} else {
|
197
|
+
if (this.hasInputTarget) this.inputTarget.value = "";
|
198
|
+
if (this.hasTriggerTextTarget) {
|
199
|
+
this.triggerTarget.dataset.hasValue = "false";
|
200
|
+
if (this.triggerTarget.dataset.placeholder) {
|
201
|
+
this.triggerTextTarget.textContent =
|
202
|
+
this.triggerTarget.dataset.placeholder;
|
203
|
+
} else {
|
204
|
+
this.triggerTextTarget.textContent = "";
|
218
205
|
}
|
206
|
+
}
|
207
|
+
this.hiddenInputTarget.value = "";
|
219
208
|
}
|
220
|
-
|
221
|
-
|
209
|
+
}
|
210
|
+
disconnect() {
|
211
|
+
this.cleanupEventListeners();
|
212
|
+
}
|
213
|
+
onClickDate(self) {
|
214
|
+
const date = self.context.selectedDates[0];
|
215
|
+
if (date) {
|
216
|
+
this.dateValue = date;
|
217
|
+
this.close();
|
218
|
+
} else {
|
219
|
+
this.dateValue = "";
|
222
220
|
}
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
221
|
+
}
|
222
|
+
setupEventListeners() {
|
223
|
+
document.addEventListener("keydown", this.DOMKeydownListener);
|
224
|
+
}
|
225
|
+
cleanupEventListeners() {
|
226
|
+
if (this.cleanup) this.cleanup();
|
227
|
+
document.removeEventListener("keydown", this.DOMKeydownListener);
|
228
|
+
}
|
229
|
+
getOptions() {
|
230
|
+
let options = {
|
231
|
+
type: "default",
|
232
|
+
enableJumpToSelectedDate: true,
|
233
|
+
onClickDate: this.onClickDateListener,
|
234
|
+
};
|
235
|
+
const date = this.element.dataset.value;
|
236
|
+
if (date && dayjs(date).isValid()) {
|
237
|
+
const dayjsDate = dayjs(date).format(DAYJS_FORMAT);
|
238
|
+
options.selectedDates = [dayjsDate];
|
227
239
|
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
if (date && dayjs(date).isValid()) {
|
236
|
-
const dayjsDate = dayjs(date).format(DAYJS_FORMAT);
|
237
|
-
options.selectedDates = [dayjsDate];
|
238
|
-
}
|
239
|
-
try {
|
240
|
-
options = {
|
241
|
-
...options,
|
242
|
-
...JSON.parse(this.element.dataset.options || ''),
|
243
|
-
};
|
244
|
-
}
|
245
|
-
catch {
|
246
|
-
// noop
|
247
|
-
}
|
248
|
-
if (options.selectedDates && options.selectedDates.length > 0) {
|
249
|
-
this.dateValue = `${options.selectedDates[0]}`;
|
250
|
-
}
|
251
|
-
return options;
|
240
|
+
try {
|
241
|
+
options = {
|
242
|
+
...options,
|
243
|
+
...JSON.parse(this.element.dataset.options || ""),
|
244
|
+
};
|
245
|
+
} catch {
|
246
|
+
// noop
|
252
247
|
}
|
253
|
-
|
254
|
-
|
255
|
-
return;
|
256
|
-
const key = event.key;
|
257
|
-
if (key === 'Escape') {
|
258
|
-
this.close();
|
259
|
-
}
|
260
|
-
else if (key === 'Tab') {
|
261
|
-
handleTabNavigation(this.contentTarget, event);
|
262
|
-
}
|
263
|
-
else if (['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft'].includes(key) &&
|
264
|
-
document.activeElement != this.inputTarget) {
|
265
|
-
event.preventDefault();
|
266
|
-
}
|
248
|
+
if (options.selectedDates && options.selectedDates.length > 0) {
|
249
|
+
this.dateValue = `${options.selectedDates[0]}`;
|
267
250
|
}
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
251
|
+
return options;
|
252
|
+
}
|
253
|
+
onDOMKeydown(event) {
|
254
|
+
if (!this.isOpenValue) return;
|
255
|
+
const key = event.key;
|
256
|
+
if (key === "Escape") {
|
257
|
+
this.close();
|
258
|
+
} else if (key === "Tab") {
|
259
|
+
handleTabNavigation(this.contentTarget, event);
|
260
|
+
} else if (
|
261
|
+
["ArrowUp", "ArrowDown", "ArrowRight", "ArrowLeft"].includes(key) &&
|
262
|
+
document.activeElement != this.inputTarget
|
263
|
+
) {
|
264
|
+
event.preventDefault();
|
273
265
|
}
|
266
|
+
}
|
267
|
+
setupInputMask() {
|
268
|
+
const im = new Inputmask(this.format.replace(/[^/]/g, "9"), {
|
269
|
+
showMaskOnHover: false,
|
270
|
+
});
|
271
|
+
im.mask(this.inputTarget);
|
272
|
+
}
|
274
273
|
};
|
275
274
|
export { DatePickerController };
|