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,251 +1,266 @@
|
|
1
|
-
import { useClickOutside } from
|
2
|
-
import { onKeydown, focusItemByIndex } from
|
3
|
-
import { initFloatingUi } from
|
4
|
-
import {
|
5
|
-
|
1
|
+
import { useClickOutside } from "stimulus-use";
|
2
|
+
import { onKeydown, focusItemByIndex } from "./dropdown_menu_controller";
|
3
|
+
import { initFloatingUi } from "../utils/floating_ui";
|
4
|
+
import {
|
5
|
+
getSameLevelItems,
|
6
|
+
focusTrigger,
|
7
|
+
hideContent,
|
8
|
+
showContent,
|
9
|
+
lockScroll,
|
10
|
+
unlockScroll,
|
11
|
+
onClickOutside,
|
12
|
+
setGroupLabelsId,
|
13
|
+
getNextEnabledIndex,
|
14
|
+
getPreviousEnabledIndex,
|
15
|
+
focusElement,
|
16
|
+
} from "../utils";
|
17
|
+
import { Controller } from "@hotwired/stimulus";
|
6
18
|
const SelectController = class extends Controller {
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
this.isOpenValue = true;
|
44
|
-
let elementToFocus = null;
|
45
|
-
if (this.selectedValue) {
|
46
|
-
const item = this.itemTargets.find((i) => i.dataset.value === this.selectedValue);
|
47
|
-
if (item && !item.dataset.disabled) {
|
48
|
-
elementToFocus = item;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
if (!elementToFocus) {
|
52
|
-
if (event instanceof KeyboardEvent) {
|
53
|
-
const key = event.key;
|
54
|
-
if (['ArrowDown', 'Enter', ' '].includes(key)) {
|
55
|
-
elementToFocus = this.items[0];
|
56
|
-
}
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
elementToFocus = this.contentTarget;
|
60
|
-
}
|
61
|
-
}
|
62
|
-
focusElement(elementToFocus);
|
63
|
-
}
|
64
|
-
close() {
|
65
|
-
this.isOpenValue = false;
|
66
|
-
}
|
67
|
-
onItemFocus(event) {
|
68
|
-
const item = event.currentTarget;
|
69
|
-
item.tabIndex = 0;
|
70
|
-
}
|
71
|
-
onItemBlur(event) {
|
72
|
-
const item = event.currentTarget;
|
73
|
-
item.tabIndex = -1;
|
19
|
+
static name = "select";
|
20
|
+
// targets
|
21
|
+
static targets = [
|
22
|
+
"trigger",
|
23
|
+
"contentContainer",
|
24
|
+
"content",
|
25
|
+
"item",
|
26
|
+
"triggerText",
|
27
|
+
"group",
|
28
|
+
"select",
|
29
|
+
];
|
30
|
+
// values
|
31
|
+
static values = {
|
32
|
+
isOpen: Boolean,
|
33
|
+
selected: String,
|
34
|
+
};
|
35
|
+
connect() {
|
36
|
+
this.items = getSameLevelItems({
|
37
|
+
content: this.contentTarget,
|
38
|
+
items: this.itemTargets,
|
39
|
+
closestContentSelector: '[data-select-target="content"]',
|
40
|
+
});
|
41
|
+
this.itemsInnerText = this.items.map((i) => i.innerText.trim());
|
42
|
+
this.searchString = "";
|
43
|
+
useClickOutside(this, {
|
44
|
+
element: this.contentTarget,
|
45
|
+
dispatchEvent: false,
|
46
|
+
});
|
47
|
+
this.DOMKeydownListener = this.onDOMKeydown.bind(this);
|
48
|
+
setGroupLabelsId(this);
|
49
|
+
}
|
50
|
+
toggle(event) {
|
51
|
+
if (this.isOpenValue) {
|
52
|
+
this.close();
|
53
|
+
} else {
|
54
|
+
this.open(event);
|
74
55
|
}
|
75
|
-
|
76
|
-
|
56
|
+
}
|
57
|
+
open(event) {
|
58
|
+
this.isOpenValue = true;
|
59
|
+
let elementToFocus = null;
|
60
|
+
if (this.selectedValue) {
|
61
|
+
const item = this.itemTargets.find(
|
62
|
+
(i) => i.dataset.value === this.selectedValue,
|
63
|
+
);
|
64
|
+
if (item && !item.dataset.disabled) {
|
65
|
+
elementToFocus = item;
|
66
|
+
}
|
77
67
|
}
|
78
|
-
|
79
|
-
|
80
|
-
const
|
81
|
-
if (
|
82
|
-
|
83
|
-
let newIndex = 0;
|
84
|
-
if (key === 'ArrowUp') {
|
85
|
-
newIndex = getPreviousEnabledIndex({
|
86
|
-
items: this.items,
|
87
|
-
currentIndex: index,
|
88
|
-
wrapAround: false,
|
89
|
-
});
|
90
|
-
}
|
91
|
-
else {
|
92
|
-
newIndex = getNextEnabledIndex({
|
93
|
-
items: this.items,
|
94
|
-
currentIndex: index,
|
95
|
-
wrapAround: false,
|
96
|
-
});
|
97
|
-
}
|
98
|
-
this.items[newIndex].focus();
|
68
|
+
if (!elementToFocus) {
|
69
|
+
if (event instanceof KeyboardEvent) {
|
70
|
+
const key = event.key;
|
71
|
+
if (["ArrowDown", "Enter", " "].includes(key)) {
|
72
|
+
elementToFocus = this.items[0];
|
99
73
|
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
}
|
104
|
-
}
|
105
|
-
focusContent() {
|
106
|
-
this.contentTarget.focus();
|
107
|
-
}
|
108
|
-
select(event) {
|
109
|
-
const item = event.currentTarget;
|
110
|
-
const value = item.dataset.value;
|
111
|
-
this.selectedValue = value;
|
112
|
-
this.close();
|
74
|
+
} else {
|
75
|
+
elementToFocus = this.contentTarget;
|
76
|
+
}
|
113
77
|
}
|
114
|
-
|
115
|
-
|
78
|
+
focusElement(elementToFocus);
|
79
|
+
}
|
80
|
+
close() {
|
81
|
+
this.isOpenValue = false;
|
82
|
+
}
|
83
|
+
onItemFocus(event) {
|
84
|
+
const item = event.currentTarget;
|
85
|
+
item.tabIndex = 0;
|
86
|
+
}
|
87
|
+
onItemBlur(event) {
|
88
|
+
const item = event.currentTarget;
|
89
|
+
item.tabIndex = -1;
|
90
|
+
}
|
91
|
+
focusItemByIndex(event = null, index = null) {
|
92
|
+
focusItemByIndex(this, event, index);
|
93
|
+
}
|
94
|
+
focusItem(event) {
|
95
|
+
const item = event.currentTarget;
|
96
|
+
const index = this.items.indexOf(item);
|
97
|
+
if (event instanceof KeyboardEvent) {
|
98
|
+
const key = event.key;
|
99
|
+
let newIndex = 0;
|
100
|
+
if (key === "ArrowUp") {
|
101
|
+
newIndex = getPreviousEnabledIndex({
|
102
|
+
items: this.items,
|
103
|
+
currentIndex: index,
|
104
|
+
wrapAround: false,
|
105
|
+
});
|
106
|
+
} else {
|
107
|
+
newIndex = getNextEnabledIndex({
|
108
|
+
items: this.items,
|
109
|
+
currentIndex: index,
|
110
|
+
wrapAround: false,
|
111
|
+
});
|
112
|
+
}
|
113
|
+
this.items[newIndex].focus();
|
114
|
+
} else {
|
115
|
+
// item mouseover event
|
116
|
+
this.items[index].focus();
|
116
117
|
}
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
118
|
+
}
|
119
|
+
focusContent() {
|
120
|
+
this.contentTarget.focus();
|
121
|
+
}
|
122
|
+
select(event) {
|
123
|
+
const item = event.currentTarget;
|
124
|
+
const value = item.dataset.value;
|
125
|
+
this.selectedValue = value;
|
126
|
+
this.close();
|
127
|
+
}
|
128
|
+
clickOutside(event) {
|
129
|
+
onClickOutside(this, event);
|
130
|
+
}
|
131
|
+
isOpenValueChanged(isOpen, previousIsOpen) {
|
132
|
+
if (isOpen) {
|
133
|
+
lockScroll(this.contentTarget.id);
|
134
|
+
showContent({
|
135
|
+
trigger: this.triggerTarget,
|
136
|
+
content: this.contentTarget,
|
137
|
+
contentContainer: this.contentContainerTarget,
|
138
|
+
setEqualWidth: true,
|
139
|
+
});
|
140
|
+
this.cleanup = initFloatingUi({
|
141
|
+
referenceElement: this.triggerTarget,
|
142
|
+
floatingElement: this.contentContainerTarget,
|
143
|
+
side: this.contentTarget.dataset.side,
|
144
|
+
align: this.contentTarget.dataset.align,
|
145
|
+
sideOffset: 4,
|
146
|
+
});
|
147
|
+
this.setupEventListeners();
|
148
|
+
} else {
|
149
|
+
unlockScroll(this.contentTarget.id);
|
150
|
+
hideContent({
|
151
|
+
trigger: this.triggerTarget,
|
152
|
+
content: this.contentTarget,
|
153
|
+
contentContainer: this.contentContainerTarget,
|
154
|
+
});
|
155
|
+
if (previousIsOpen) {
|
156
|
+
focusTrigger(this.triggerTarget);
|
157
|
+
}
|
158
|
+
this.cleanupEventListeners();
|
147
159
|
}
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
}
|
159
|
-
});
|
160
|
-
this.selectTarget.value = value;
|
161
|
-
}
|
162
|
-
this.triggerTarget.dataset.hasValue = `${!!value && value.length > 0}`;
|
163
|
-
const placeholder = this.triggerTarget.dataset.placeholder;
|
164
|
-
if (placeholder && this.triggerTarget.dataset.hasValue === 'false') {
|
165
|
-
this.triggerTextTarget.textContent = placeholder;
|
160
|
+
}
|
161
|
+
selectedValueChanged(value) {
|
162
|
+
const item = this.itemTargets.find((i) => i.dataset.value === value);
|
163
|
+
if (item) {
|
164
|
+
this.triggerTextTarget.textContent = item.textContent;
|
165
|
+
this.itemTargets.forEach((i) => {
|
166
|
+
if (i.dataset.value === value) {
|
167
|
+
i.setAttribute("aria-selected", "true");
|
168
|
+
} else {
|
169
|
+
i.setAttribute("aria-selected", "false");
|
166
170
|
}
|
171
|
+
});
|
172
|
+
this.selectTarget.value = value;
|
167
173
|
}
|
168
|
-
|
169
|
-
|
174
|
+
this.triggerTarget.dataset.hasValue = `${!!value && value.length > 0}`;
|
175
|
+
const placeholder = this.triggerTarget.dataset.placeholder;
|
176
|
+
if (placeholder && this.triggerTarget.dataset.hasValue === "false") {
|
177
|
+
this.triggerTextTarget.textContent = placeholder;
|
170
178
|
}
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
179
|
+
}
|
180
|
+
disconnect() {
|
181
|
+
this.cleanupEventListeners();
|
182
|
+
}
|
183
|
+
onDOMKeydown(event) {
|
184
|
+
if (!this.isOpenValue) return;
|
185
|
+
onKeydown(this, event);
|
186
|
+
const { key, altKey, ctrlKey, metaKey } = event;
|
187
|
+
if (
|
188
|
+
key === "Backspace" ||
|
189
|
+
key === "Clear" ||
|
190
|
+
(key.length === 1 && key !== " " && !altKey && !ctrlKey && !metaKey)
|
191
|
+
) {
|
192
|
+
this.handleSearch(key);
|
181
193
|
}
|
182
|
-
|
183
|
-
|
194
|
+
}
|
195
|
+
setupEventListeners() {
|
196
|
+
document.addEventListener("keydown", this.DOMKeydownListener);
|
197
|
+
}
|
198
|
+
cleanupEventListeners() {
|
199
|
+
if (this.cleanup) this.cleanup();
|
200
|
+
document.removeEventListener("keydown", this.DOMKeydownListener);
|
201
|
+
}
|
202
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
|
203
|
+
handleSearch(char) {
|
204
|
+
const searchString = this.getSearchString(char);
|
205
|
+
const focusedItem = this.items.find(
|
206
|
+
(item) => document.activeElement === item,
|
207
|
+
);
|
208
|
+
const focusedIndex = focusedItem ? this.items.indexOf(focusedItem) : 0;
|
209
|
+
const searchIndex = this.getIndexByLetter(searchString, focusedIndex + 1);
|
210
|
+
// if a match was found, go to it
|
211
|
+
if (searchIndex >= 0) {
|
212
|
+
this.focusItemByIndex(null, searchIndex);
|
184
213
|
}
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
214
|
+
// if no matches, clear the timeout and search string
|
215
|
+
else {
|
216
|
+
window.clearTimeout(this.searchTimeout);
|
217
|
+
this.searchString = "";
|
189
218
|
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
window.clearTimeout(this.searchTimeout);
|
203
|
-
this.searchString = '';
|
204
|
-
}
|
219
|
+
}
|
220
|
+
filterItemsInnerText(items, filter) {
|
221
|
+
return items.filter((item) => {
|
222
|
+
const matches = item.toLowerCase().indexOf(filter.toLowerCase()) === 0;
|
223
|
+
return matches;
|
224
|
+
});
|
225
|
+
}
|
226
|
+
getSearchString(char) {
|
227
|
+
// reset typing timeout and start new timeout
|
228
|
+
// this allows us to make multiple-letter matches, like a native select
|
229
|
+
if (typeof this.searchTimeout === "number") {
|
230
|
+
window.clearTimeout(this.searchTimeout);
|
205
231
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
232
|
+
this.searchTimeout = window.setTimeout(() => {
|
233
|
+
this.searchString = "";
|
234
|
+
}, 500);
|
235
|
+
// add most recent letter to saved search string
|
236
|
+
this.searchString += char;
|
237
|
+
return this.searchString;
|
238
|
+
}
|
239
|
+
// return the index of an option from an array of options, based on a search string
|
240
|
+
// if the filter is multiple iterations of the same letter (e.g "aaa"), then cycle through first-letter matches
|
241
|
+
getIndexByLetter(filter, startIndex) {
|
242
|
+
const orderedItems = [
|
243
|
+
...this.itemsInnerText.slice(startIndex),
|
244
|
+
...this.itemsInnerText.slice(0, startIndex),
|
245
|
+
];
|
246
|
+
const firstMatch = this.filterItemsInnerText(orderedItems, filter)[0];
|
247
|
+
const allSameLetter = (array) =>
|
248
|
+
array.every((letter) => letter === array[0]);
|
249
|
+
// first check if there is an exact match for the typed string
|
250
|
+
if (firstMatch) {
|
251
|
+
const index = this.itemsInnerText.indexOf(firstMatch);
|
252
|
+
return index;
|
211
253
|
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
218
|
-
this.searchTimeout = window.setTimeout(() => {
|
219
|
-
this.searchString = '';
|
220
|
-
}, 500);
|
221
|
-
// add most recent letter to saved search string
|
222
|
-
this.searchString += char;
|
223
|
-
return this.searchString;
|
254
|
+
// if the same letter is being repeated, cycle through first-letter matches
|
255
|
+
else if (allSameLetter(filter.split(""))) {
|
256
|
+
const matches = this.filterItemsInnerText(orderedItems, filter[0]);
|
257
|
+
const index = this.itemsInnerText.indexOf(matches[0]);
|
258
|
+
return index;
|
224
259
|
}
|
225
|
-
//
|
226
|
-
|
227
|
-
|
228
|
-
const orderedItems = [
|
229
|
-
...this.itemsInnerText.slice(startIndex),
|
230
|
-
...this.itemsInnerText.slice(0, startIndex),
|
231
|
-
];
|
232
|
-
const firstMatch = this.filterItemsInnerText(orderedItems, filter)[0];
|
233
|
-
const allSameLetter = (array) => array.every((letter) => letter === array[0]);
|
234
|
-
// first check if there is an exact match for the typed string
|
235
|
-
if (firstMatch) {
|
236
|
-
const index = this.itemsInnerText.indexOf(firstMatch);
|
237
|
-
return index;
|
238
|
-
}
|
239
|
-
// if the same letter is being repeated, cycle through first-letter matches
|
240
|
-
else if (allSameLetter(filter.split(''))) {
|
241
|
-
const matches = this.filterItemsInnerText(orderedItems, filter[0]);
|
242
|
-
const index = this.itemsInnerText.indexOf(matches[0]);
|
243
|
-
return index;
|
244
|
-
}
|
245
|
-
// if no matches, return -1
|
246
|
-
else {
|
247
|
-
return -1;
|
248
|
-
}
|
260
|
+
// if no matches, return -1
|
261
|
+
else {
|
262
|
+
return -1;
|
249
263
|
}
|
264
|
+
}
|
250
265
|
};
|
251
266
|
export { SelectController };
|
@@ -1,30 +1,29 @@
|
|
1
|
-
import { Controller } from
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
2
2
|
export default class default_1 extends Controller {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
this.open();
|
13
|
-
}
|
14
|
-
}
|
15
|
-
open() {
|
16
|
-
this.element.dataset.state = 'expanded';
|
17
|
-
this.element.dataset.collapsible = '';
|
18
|
-
this.panelTarget.style.removeProperty('left');
|
19
|
-
this.panelOffsetTarget.style.removeProperty('width');
|
20
|
-
}
|
21
|
-
close() {
|
22
|
-
this.element.dataset.state = 'collapsed';
|
23
|
-
this.element.dataset.collapsible = 'offcanvas';
|
24
|
-
this.panelTarget.style.left = `-${this.width}px`;
|
25
|
-
this.panelOffsetTarget.style.width = `${0}`;
|
26
|
-
}
|
27
|
-
isOpen() {
|
28
|
-
return this.element.dataset.state === 'expanded';
|
3
|
+
static targets = ["panel", "panelOffset"];
|
4
|
+
connect() {
|
5
|
+
this.width = this.element.offsetWidth;
|
6
|
+
}
|
7
|
+
toggle() {
|
8
|
+
if (this.isOpen()) {
|
9
|
+
this.close();
|
10
|
+
} else {
|
11
|
+
this.open();
|
29
12
|
}
|
13
|
+
}
|
14
|
+
open() {
|
15
|
+
this.element.dataset.state = "expanded";
|
16
|
+
this.element.dataset.collapsible = "";
|
17
|
+
this.panelTarget.style.removeProperty("left");
|
18
|
+
this.panelOffsetTarget.style.removeProperty("width");
|
19
|
+
}
|
20
|
+
close() {
|
21
|
+
this.element.dataset.state = "collapsed";
|
22
|
+
this.element.dataset.collapsible = "offcanvas";
|
23
|
+
this.panelTarget.style.left = `-${this.width}px`;
|
24
|
+
this.panelOffsetTarget.style.width = `${0}`;
|
25
|
+
}
|
26
|
+
isOpen() {
|
27
|
+
return this.element.dataset.state === "expanded";
|
28
|
+
}
|
30
29
|
}
|
@@ -1,12 +1,15 @@
|
|
1
|
-
import { Controller } from
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
2
2
|
export default class extends Controller {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
connect() {
|
4
|
+
this.sidebarId = this.element.dataset.sidebarId;
|
5
|
+
}
|
6
|
+
toggle() {
|
7
|
+
const sidebar = this.application.getControllerForElementAndIdentifier(
|
8
|
+
document.querySelector(`#${this.sidebarId}`),
|
9
|
+
"sidebar",
|
10
|
+
);
|
11
|
+
if (sidebar) {
|
12
|
+
sidebar.toggle();
|
11
13
|
}
|
14
|
+
}
|
12
15
|
}
|