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,82 +1,83 @@
|
|
1
|
-
import { Controller } from
|
2
|
-
import noUiSlider from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import noUiSlider from 'nouislider';
|
3
3
|
const SliderController = class extends Controller {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
// targets
|
5
|
+
static targets = ['slider', 'hiddenInput', 'endHiddenInput'];
|
6
|
+
connect() {
|
7
|
+
this.range = this.element.dataset.range === 'true';
|
8
|
+
this.DOMClickListener = this.onDOMClick.bind(this);
|
9
|
+
this.onUpdateValuesListener = this.onUpdateValues.bind(this);
|
10
|
+
const options = this.getOptions();
|
11
|
+
this.slider = noUiSlider.create(this.sliderTarget, options);
|
12
|
+
if (this.element.dataset.disabled === 'true') {
|
13
|
+
this.slider.disable();
|
14
|
+
}
|
15
|
+
if (this.element.dataset.id) {
|
16
|
+
const lowerHandle = this.slider.target.querySelector('.noUi-handle-lower');
|
17
|
+
if (lowerHandle) {
|
18
|
+
lowerHandle.id = this.element.dataset.id;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
this.slider.on('update', this.onUpdateValuesListener);
|
22
|
+
document.addEventListener('click', this.DOMClickListener);
|
21
23
|
}
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
disconnect() {
|
26
|
-
document.removeEventListener("click", this.DOMClickListener);
|
27
|
-
}
|
28
|
-
getOptions() {
|
29
|
-
const defaultOptions = {
|
30
|
-
connect: this.range ? true : "lower",
|
31
|
-
tooltips: true,
|
32
|
-
};
|
33
|
-
defaultOptions.range = {
|
34
|
-
min: [parseFloat(this.element.dataset.min || "0")],
|
35
|
-
max: [parseFloat(this.element.dataset.max || "100")],
|
36
|
-
};
|
37
|
-
defaultOptions.step = parseFloat(this.element.dataset.step || "1");
|
38
|
-
if (this.range) {
|
39
|
-
defaultOptions.start = [
|
40
|
-
parseFloat(this.element.dataset.value || "0"),
|
41
|
-
parseFloat(this.element.dataset.endValue || "0"),
|
42
|
-
];
|
43
|
-
defaultOptions.handleAttributes = [
|
44
|
-
{ "aria-label": "lower" },
|
45
|
-
{ "aria-label": "upper" },
|
46
|
-
];
|
47
|
-
} else {
|
48
|
-
defaultOptions.start = [parseFloat(this.element.dataset.value || "0")];
|
49
|
-
defaultOptions.handleAttributes = [{ "aria-label": "lower" }];
|
24
|
+
disconnect() {
|
25
|
+
document.removeEventListener('click', this.DOMClickListener);
|
50
26
|
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
27
|
+
getOptions() {
|
28
|
+
const defaultOptions = {
|
29
|
+
connect: this.range ? true : 'lower',
|
30
|
+
tooltips: true,
|
31
|
+
};
|
32
|
+
defaultOptions.range = {
|
33
|
+
min: [parseFloat(this.element.dataset.min || '0')],
|
34
|
+
max: [parseFloat(this.element.dataset.max || '100')],
|
35
|
+
};
|
36
|
+
defaultOptions.step = parseFloat(this.element.dataset.step || '1');
|
37
|
+
if (this.range) {
|
38
|
+
defaultOptions.start = [
|
39
|
+
parseFloat(this.element.dataset.value || '0'),
|
40
|
+
parseFloat(this.element.dataset.endValue || '0'),
|
41
|
+
];
|
42
|
+
defaultOptions.handleAttributes = [
|
43
|
+
{ 'aria-label': 'lower' },
|
44
|
+
{ 'aria-label': 'upper' },
|
45
|
+
];
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
defaultOptions.start = [parseFloat(this.element.dataset.value || '0')];
|
49
|
+
defaultOptions.handleAttributes = [{ 'aria-label': 'lower' }];
|
50
|
+
}
|
51
|
+
defaultOptions.orientation = (this.element.dataset.orientation ||
|
52
|
+
'horizontal');
|
53
|
+
try {
|
54
|
+
return {
|
55
|
+
...defaultOptions,
|
56
|
+
...JSON.parse(this.element.dataset.options || ''),
|
57
|
+
};
|
58
|
+
}
|
59
|
+
catch {
|
60
|
+
return defaultOptions;
|
61
|
+
}
|
60
62
|
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
onUpdateValues(values) {
|
64
|
+
this.hiddenInputTarget.value = `${values[0]}`;
|
65
|
+
if (this.range && this.hasEndHiddenInputTarget) {
|
66
|
+
this.endHiddenInputTarget.value = `${values[1]}`;
|
67
|
+
}
|
66
68
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
69
|
+
onDOMClick(event) {
|
70
|
+
const target = event.target;
|
71
|
+
// Focus handle of slider when label is clicked.
|
72
|
+
if (target instanceof HTMLLabelElement) {
|
73
|
+
const id = target.getAttribute('for');
|
74
|
+
if (id === this.element.dataset.id) {
|
75
|
+
const handle = document.querySelector(`#${id}`);
|
76
|
+
if (handle) {
|
77
|
+
handle.focus();
|
78
|
+
}
|
79
|
+
}
|
77
80
|
}
|
78
|
-
}
|
79
81
|
}
|
80
|
-
}
|
81
82
|
};
|
82
83
|
export { SliderController };
|
@@ -1,26 +1,27 @@
|
|
1
|
-
import { Controller } from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
2
|
const SwitchController = class extends Controller {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
// targets
|
4
|
+
static targets = ['input', 'thumb'];
|
5
|
+
// values
|
6
|
+
static values = {
|
7
|
+
isChecked: Boolean,
|
8
|
+
};
|
9
|
+
toggle() {
|
10
|
+
this.isCheckedValue = !this.isCheckedValue;
|
11
|
+
}
|
12
|
+
isCheckedValueChanged(value) {
|
13
|
+
if (value) {
|
14
|
+
this.element.ariaChecked = 'true';
|
15
|
+
this.element.dataset.state = 'checked';
|
16
|
+
this.thumbTarget.dataset.state = 'checked';
|
17
|
+
this.inputTarget.checked = true;
|
18
|
+
}
|
19
|
+
else {
|
20
|
+
this.element.ariaChecked = 'false';
|
21
|
+
this.element.dataset.state = 'unchecked';
|
22
|
+
this.thumbTarget.dataset.state = 'unchecked';
|
23
|
+
this.inputTarget.checked = false;
|
24
|
+
}
|
23
25
|
}
|
24
|
-
}
|
25
26
|
};
|
26
27
|
export { SwitchController };
|
@@ -1,66 +1,67 @@
|
|
1
|
-
import { Controller } from
|
2
|
-
import { getNextEnabledIndex, getPreviousEnabledIndex } from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import { getNextEnabledIndex, getPreviousEnabledIndex } from '../utils';
|
3
3
|
const TabsController = class extends Controller {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
// targets
|
5
|
+
static targets = ['trigger', 'content'];
|
6
|
+
// values
|
7
|
+
static values = {
|
8
|
+
active: String,
|
9
|
+
};
|
10
|
+
connect() {
|
11
|
+
if (!this.activeValue) {
|
12
|
+
this.activeValue = this.triggerTargets[0].dataset.value;
|
13
|
+
}
|
13
14
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
setActiveTab(event) {
|
16
|
+
const target = event.currentTarget;
|
17
|
+
if (event instanceof MouseEvent) {
|
18
|
+
this.activeValue = target.dataset.value;
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
const key = event.key;
|
22
|
+
const focusableTriggers = this.triggerTargets.filter((t) => !t.disabled);
|
23
|
+
const index = focusableTriggers.indexOf(target);
|
24
|
+
let newIndex = 0;
|
25
|
+
if (key === 'ArrowLeft') {
|
26
|
+
newIndex = getPreviousEnabledIndex({
|
27
|
+
items: focusableTriggers,
|
28
|
+
currentIndex: index,
|
29
|
+
wrapAround: true,
|
30
|
+
});
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
newIndex = getNextEnabledIndex({
|
34
|
+
items: focusableTriggers,
|
35
|
+
currentIndex: index,
|
36
|
+
wrapAround: true,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
this.activeValue = focusableTriggers[newIndex].dataset.value;
|
40
|
+
focusableTriggers[newIndex].focus();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
activeValueChanged(value) {
|
44
|
+
this.triggerTargets.forEach((trigger) => {
|
45
|
+
const triggerValue = trigger.dataset.value;
|
46
|
+
const content = this.contentTargets.find((c) => {
|
47
|
+
return c.dataset.value === triggerValue;
|
48
|
+
});
|
49
|
+
if (!content) {
|
50
|
+
throw new Error(`Could not find TabsContent with value "${triggerValue}"`);
|
51
|
+
}
|
52
|
+
if (triggerValue === value) {
|
53
|
+
trigger.ariaSelected = 'true';
|
54
|
+
trigger.tabIndex = 0;
|
55
|
+
trigger.dataset.state = 'active';
|
56
|
+
content.classList.remove('hidden');
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
trigger.ariaSelected = 'false';
|
60
|
+
trigger.tabIndex = -1;
|
61
|
+
trigger.dataset.state = 'inactive';
|
62
|
+
content.classList.add('hidden');
|
63
|
+
}
|
35
64
|
});
|
36
|
-
}
|
37
|
-
this.activeValue = focusableTriggers[newIndex].dataset.value;
|
38
|
-
focusableTriggers[newIndex].focus();
|
39
65
|
}
|
40
|
-
}
|
41
|
-
activeValueChanged(value) {
|
42
|
-
this.triggerTargets.forEach((trigger) => {
|
43
|
-
const triggerValue = trigger.dataset.value;
|
44
|
-
const content = this.contentTargets.find((c) => {
|
45
|
-
return c.dataset.value === triggerValue;
|
46
|
-
});
|
47
|
-
if (!content) {
|
48
|
-
throw new Error(
|
49
|
-
`Could not find TabsContent with value "${triggerValue}"`,
|
50
|
-
);
|
51
|
-
}
|
52
|
-
if (triggerValue === value) {
|
53
|
-
trigger.ariaSelected = "true";
|
54
|
-
trigger.tabIndex = 0;
|
55
|
-
trigger.dataset.state = "active";
|
56
|
-
content.classList.remove("hidden");
|
57
|
-
} else {
|
58
|
-
trigger.ariaSelected = "false";
|
59
|
-
trigger.tabIndex = -1;
|
60
|
-
trigger.dataset.state = "inactive";
|
61
|
-
content.classList.add("hidden");
|
62
|
-
}
|
63
|
-
});
|
64
|
-
}
|
65
66
|
};
|
66
67
|
export { TabsController };
|
@@ -1,32 +1,32 @@
|
|
1
|
-
import { Controller } from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
2
|
const ThemeSwitcherController = class extends Controller {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
initialize() {
|
4
|
+
if (localStorage.theme === 'dark' ||
|
5
|
+
(!('theme' in localStorage) &&
|
6
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
7
|
+
this.setDarkMode();
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
this.setLightMode();
|
11
|
+
}
|
12
12
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
toggle() {
|
14
|
+
if (document.documentElement.classList.contains('dark')) {
|
15
|
+
this.setLightMode();
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
this.setDarkMode();
|
19
|
+
}
|
20
|
+
}
|
21
|
+
setLightMode() {
|
22
|
+
localStorage.theme = 'light';
|
23
|
+
document.documentElement.classList.remove('dark');
|
24
|
+
document.documentElement.style.colorScheme = '';
|
25
|
+
}
|
26
|
+
setDarkMode() {
|
27
|
+
localStorage.theme = 'dark';
|
28
|
+
document.documentElement.classList.add('dark');
|
29
|
+
document.documentElement.style.colorScheme = 'dark';
|
19
30
|
}
|
20
|
-
}
|
21
|
-
setLightMode() {
|
22
|
-
localStorage.theme = "light";
|
23
|
-
document.documentElement.classList.remove("dark");
|
24
|
-
document.documentElement.style.colorScheme = "";
|
25
|
-
}
|
26
|
-
setDarkMode() {
|
27
|
-
localStorage.theme = "dark";
|
28
|
-
document.documentElement.classList.add("dark");
|
29
|
-
document.documentElement.style.colorScheme = "dark";
|
30
|
-
}
|
31
31
|
};
|
32
32
|
export { ThemeSwitcherController };
|
@@ -1,48 +1,35 @@
|
|
1
|
-
import { Controller } from
|
2
|
-
import DOMPurify from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import DOMPurify from 'dompurify';
|
3
3
|
const ToastContainerController = class extends Controller {
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
descriptionTemplate.remove();
|
4
|
+
addToast({ title, description, action, variant = 'default', duration = 5000, }) {
|
5
|
+
const template = (variant === 'default'
|
6
|
+
? this.element.querySelector('[data-variant="default"]')
|
7
|
+
: this.element.querySelector('[data-variant="destructive"]'));
|
8
|
+
const clone = template.content.cloneNode(true);
|
9
|
+
const toastTemplate = clone.querySelector('[data-shadcn-phlexcomponents="toast"]');
|
10
|
+
toastTemplate.dataset.duration = String(duration);
|
11
|
+
const titleTemplate = clone.querySelector('[data-shadcn-phlexcomponents="toast-title"]');
|
12
|
+
const descriptionTemplate = clone.querySelector('[data-shadcn-phlexcomponents="toast-description"]');
|
13
|
+
const actionTemplate = clone.querySelector('[data-shadcn-phlexcomponents="toast-action"]');
|
14
|
+
titleTemplate.innerHTML = DOMPurify.sanitize(title);
|
15
|
+
if (description) {
|
16
|
+
descriptionTemplate.innerHTML = DOMPurify.sanitize(description);
|
17
|
+
}
|
18
|
+
else {
|
19
|
+
descriptionTemplate.remove();
|
20
|
+
}
|
21
|
+
if (action) {
|
22
|
+
const element = document.createElement('div');
|
23
|
+
element.innerHTML = DOMPurify.sanitize(action);
|
24
|
+
const actionElement = element.firstElementChild;
|
25
|
+
const classes = actionTemplate.classList;
|
26
|
+
actionElement.classList.add(...classes);
|
27
|
+
actionTemplate.replaceWith(actionElement);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
actionTemplate.remove();
|
31
|
+
}
|
32
|
+
this.element.append(clone);
|
34
33
|
}
|
35
|
-
if (action) {
|
36
|
-
const element = document.createElement("div");
|
37
|
-
element.innerHTML = DOMPurify.sanitize(action);
|
38
|
-
const actionElement = element.firstElementChild;
|
39
|
-
const classes = actionTemplate.classList;
|
40
|
-
actionElement.classList.add(...classes);
|
41
|
-
actionTemplate.replaceWith(actionElement);
|
42
|
-
} else {
|
43
|
-
actionTemplate.remove();
|
44
|
-
}
|
45
|
-
this.element.append(clone);
|
46
|
-
}
|
47
34
|
};
|
48
35
|
export { ToastContainerController };
|
@@ -1,22 +1,22 @@
|
|
1
|
-
import { Controller } from
|
2
|
-
import { ANIMATION_OUT_DELAY } from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import { ANIMATION_OUT_DELAY } from '../utils';
|
3
3
|
const ToastController = class extends Controller {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
connect() {
|
5
|
+
this.duration = Number(this.element.dataset.duration);
|
6
|
+
this.close();
|
7
|
+
}
|
8
|
+
cancelClose() {
|
9
|
+
window.clearTimeout(this.closeTimeout);
|
10
|
+
}
|
11
|
+
close() {
|
12
|
+
if (this.duration > 0) {
|
13
|
+
this.closeTimeout = window.setTimeout(() => {
|
14
|
+
this.element.dataset.state = 'closed';
|
15
|
+
setTimeout(() => {
|
16
|
+
this.element.remove();
|
17
|
+
}, ANIMATION_OUT_DELAY);
|
18
|
+
}, this.duration);
|
19
|
+
}
|
19
20
|
}
|
20
|
-
}
|
21
21
|
};
|
22
22
|
export { ToastController };
|
@@ -1,20 +1,21 @@
|
|
1
|
-
import { Controller } from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
2
|
const ToggleController = class extends Controller {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
// values
|
4
|
+
static values = {
|
5
|
+
isOn: Boolean,
|
6
|
+
};
|
7
|
+
toggle() {
|
8
|
+
this.isOnValue = !this.isOnValue;
|
9
|
+
}
|
10
|
+
isOnValueChanged(isOn) {
|
11
|
+
if (isOn) {
|
12
|
+
this.element.dataset.state = 'on';
|
13
|
+
this.element.ariaPressed = 'true';
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
this.element.dataset.state = 'off';
|
17
|
+
this.element.ariaPressed = 'false';
|
18
|
+
}
|
17
19
|
}
|
18
|
-
}
|
19
20
|
};
|
20
21
|
export { ToggleController };
|
@@ -1,20 +1,21 @@
|
|
1
|
-
import { Controller } from
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
2
|
const ToggleController = class extends Controller {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
// values
|
4
|
+
static values = {
|
5
|
+
isOn: Boolean,
|
6
|
+
};
|
7
|
+
toggle() {
|
8
|
+
this.isOnValue = !this.isOnValue;
|
9
|
+
}
|
10
|
+
isOnValueChanged(isOn) {
|
11
|
+
if (isOn) {
|
12
|
+
this.element.dataset.state = 'on';
|
13
|
+
this.element.ariaPressed = 'true';
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
this.element.dataset.state = 'off';
|
17
|
+
this.element.ariaPressed = 'false';
|
18
|
+
}
|
17
19
|
}
|
18
|
-
}
|
19
20
|
};
|
20
21
|
export { ToggleController };
|