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