shadcn_phlexcomponents 0.1.5 → 0.1.11
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 +14 -0
- data/app/javascript/controllers/accordion_controller.ts +133 -0
- data/app/javascript/controllers/{avatar_controller.js → avatar_controller.ts} +4 -0
- data/app/javascript/controllers/checkbox_controller.ts +34 -0
- data/app/javascript/controllers/collapsible_controller.ts +45 -0
- data/app/javascript/controllers/combobox_controller.ts +145 -0
- data/app/javascript/controllers/command_controller.ts +129 -0
- data/app/javascript/controllers/command_root_controller.ts +355 -0
- data/app/javascript/controllers/date_picker_controller.ts +274 -0
- data/app/javascript/controllers/date_range_picker_controller.ts +243 -0
- data/app/javascript/controllers/dialog_controller.ts +113 -0
- data/app/javascript/controllers/dropdown_menu_controller.ts +133 -0
- data/app/javascript/controllers/dropdown_menu_root_controller.ts +234 -0
- data/app/javascript/controllers/dropdown_menu_sub_controller.ts +150 -0
- data/app/javascript/controllers/form_field_controller.ts +22 -0
- data/app/javascript/controllers/hover_card_controller.ts +93 -0
- data/app/javascript/controllers/{loading_button_controller.js → loading_button_controller.ts} +2 -2
- data/app/javascript/controllers/popover_controller.ts +141 -0
- data/app/javascript/controllers/progress_controller.ts +17 -0
- data/app/javascript/controllers/radio_group_controller.ts +106 -0
- data/app/javascript/controllers/select_controller.ts +200 -0
- data/app/javascript/controllers/{sidebar_controller.js → sidebar_controller.ts} +6 -2
- data/app/javascript/controllers/sidebar_trigger_controller.ts +21 -0
- data/app/javascript/controllers/slider_controller.ts +107 -0
- data/app/javascript/controllers/switch_controller.ts +30 -0
- data/app/javascript/controllers/tabs_controller.ts +79 -0
- data/app/javascript/controllers/{theme_switcher_controller.js → theme_switcher_controller.ts} +12 -9
- data/app/javascript/controllers/toast_container_controller.ts +62 -0
- data/app/javascript/controllers/toast_controller.ts +28 -0
- data/app/javascript/controllers/tooltip_controller.ts +98 -0
- data/app/javascript/shadcn_phlexcomponents.ts +57 -0
- data/app/javascript/utils.ts +437 -0
- data/app/stylesheets/date_picker.css +74 -0
- data/app/stylesheets/nouislider.css +173 -0
- data/app/stylesheets/tw-animate.css +486 -0
- data/lib/install/install_shadcn_phlexcomponents.rb +22 -9
- data/lib/shadcn_phlexcomponents/alias.rb +3 -1
- data/lib/shadcn_phlexcomponents/components/accordion.rb +129 -0
- data/lib/shadcn_phlexcomponents/components/alert.rb +59 -0
- data/lib/shadcn_phlexcomponents/components/alert_dialog.rb +276 -0
- data/lib/{components → shadcn_phlexcomponents/components}/aspect_ratio.rb +2 -2
- data/lib/shadcn_phlexcomponents/components/avatar.rb +63 -0
- data/lib/shadcn_phlexcomponents/components/badge.rb +35 -0
- data/lib/{components → shadcn_phlexcomponents/components}/base.rb +44 -7
- data/lib/shadcn_phlexcomponents/components/breadcrumb.rb +150 -0
- data/lib/shadcn_phlexcomponents/components/button.rb +49 -0
- data/lib/shadcn_phlexcomponents/components/card.rb +88 -0
- data/lib/{components → shadcn_phlexcomponents/components}/checkbox.rb +21 -17
- data/lib/{components → shadcn_phlexcomponents/components}/checkbox_group.rb +27 -16
- data/lib/shadcn_phlexcomponents/components/collapsible.rb +91 -0
- data/lib/shadcn_phlexcomponents/components/combobox.rb +398 -0
- data/lib/shadcn_phlexcomponents/components/command.rb +351 -0
- data/lib/shadcn_phlexcomponents/components/date_picker.rb +264 -0
- data/lib/shadcn_phlexcomponents/components/date_range_picker.rb +126 -0
- data/lib/shadcn_phlexcomponents/components/dialog.rb +234 -0
- data/lib/shadcn_phlexcomponents/components/dropdown_menu.rb +282 -0
- data/lib/shadcn_phlexcomponents/components/dropdown_menu_sub.rb +135 -0
- data/lib/shadcn_phlexcomponents/components/form/form_checkbox.rb +82 -0
- data/lib/shadcn_phlexcomponents/components/form/form_checkbox_group.rb +116 -0
- data/lib/shadcn_phlexcomponents/components/form/form_date_picker.rb +46 -0
- data/lib/shadcn_phlexcomponents/components/form/form_date_range_picker.rb +82 -0
- data/lib/{components → shadcn_phlexcomponents/components/form}/form_error.rb +7 -3
- data/lib/shadcn_phlexcomponents/components/form/form_helpers.rb +143 -0
- data/lib/shadcn_phlexcomponents/components/form/form_hint.rb +21 -0
- data/lib/{components → shadcn_phlexcomponents/components/form}/form_input.rb +3 -4
- data/lib/shadcn_phlexcomponents/components/form/form_radio_group.rb +106 -0
- data/lib/shadcn_phlexcomponents/components/form/form_select.rb +64 -0
- data/lib/shadcn_phlexcomponents/components/form/form_slider.rb +91 -0
- data/lib/shadcn_phlexcomponents/components/form/form_switch.rb +67 -0
- data/lib/shadcn_phlexcomponents/components/form/form_textarea.rb +59 -0
- data/lib/shadcn_phlexcomponents/components/form.rb +157 -0
- data/lib/shadcn_phlexcomponents/components/hover_card.rb +110 -0
- data/lib/shadcn_phlexcomponents/components/input.rb +31 -0
- data/lib/shadcn_phlexcomponents/components/label.rb +16 -0
- data/lib/{components → shadcn_phlexcomponents/components}/link.rb +10 -3
- data/lib/shadcn_phlexcomponents/components/loading_button.rb +28 -0
- data/lib/shadcn_phlexcomponents/components/pagination.rb +166 -0
- data/lib/shadcn_phlexcomponents/components/popover.rb +116 -0
- data/lib/{components → shadcn_phlexcomponents/components}/progress.rb +5 -5
- data/lib/shadcn_phlexcomponents/components/radio_group.rb +155 -0
- data/lib/shadcn_phlexcomponents/components/select.rb +421 -0
- data/lib/{components → shadcn_phlexcomponents/components}/separator.rb +9 -8
- data/lib/shadcn_phlexcomponents/components/sheet.rb +239 -0
- data/lib/{components → shadcn_phlexcomponents/components}/skeleton.rb +1 -1
- data/lib/shadcn_phlexcomponents/components/slider.rb +72 -0
- data/lib/shadcn_phlexcomponents/components/switch.rb +75 -0
- data/lib/shadcn_phlexcomponents/components/table.rb +140 -0
- data/lib/shadcn_phlexcomponents/components/tabs.rb +135 -0
- data/lib/shadcn_phlexcomponents/components/textarea.rb +24 -0
- data/lib/{components → shadcn_phlexcomponents/components}/theme_switcher.rb +2 -2
- data/lib/shadcn_phlexcomponents/components/toast.rb +153 -0
- data/lib/{components → shadcn_phlexcomponents/components}/toast_container.rb +24 -5
- data/lib/shadcn_phlexcomponents/components/tooltip.rb +131 -0
- data/lib/shadcn_phlexcomponents/initializers/shadcn_phlexcomponents.rb +25 -0
- data/lib/shadcn_phlexcomponents/version.rb +1 -1
- data/lib/tasks/install.rake +1 -1
- metadata +92 -168
- data/app/assets/tailwind/choices.css +0 -324
- data/app/assets/tailwind/tailwindcss-animate.css +0 -318
- data/app/assets/tailwind/vanilla-calendar-pro.css +0 -466
- data/app/javascript/controllers/accordion_controller.js +0 -133
- data/app/javascript/controllers/alert_dialog_controller.js +0 -157
- data/app/javascript/controllers/checkbox_controller.js +0 -28
- data/app/javascript/controllers/collapsible_controller.js +0 -35
- data/app/javascript/controllers/combobox_controller.js +0 -34
- data/app/javascript/controllers/date_picker_controller.js +0 -118
- data/app/javascript/controllers/date_range_picker_controller.js +0 -231
- data/app/javascript/controllers/dialog_controller.js +0 -159
- data/app/javascript/controllers/dropdown_menu_controller.js +0 -193
- data/app/javascript/controllers/hover_card_controller.js +0 -42
- data/app/javascript/controllers/popover_controller.js +0 -124
- data/app/javascript/controllers/progress_controller.js +0 -14
- data/app/javascript/controllers/radio_group_controller.js +0 -90
- data/app/javascript/controllers/select_controller.js +0 -294
- data/app/javascript/controllers/sheet_controller.js +0 -159
- data/app/javascript/controllers/sidebar_trigger_controller.js +0 -15
- data/app/javascript/controllers/switch_controller.js +0 -24
- data/app/javascript/controllers/tabs_controller.js +0 -73
- data/app/javascript/controllers/toast_container_controller.js +0 -22
- data/app/javascript/controllers/toast_controller.js +0 -45
- data/app/javascript/controllers/tooltip_controller.js +0 -41
- data/lib/components/accordion.rb +0 -38
- data/lib/components/accordion_content.rb +0 -30
- data/lib/components/accordion_item.rb +0 -26
- data/lib/components/accordion_trigger.rb +0 -45
- data/lib/components/alert.rb +0 -40
- data/lib/components/alert_description.rb +0 -11
- data/lib/components/alert_dialog.rb +0 -60
- data/lib/components/alert_dialog_action.rb +0 -22
- data/lib/components/alert_dialog_action_to.rb +0 -40
- data/lib/components/alert_dialog_cancel.rb +0 -22
- data/lib/components/alert_dialog_content.rb +0 -40
- data/lib/components/alert_dialog_description.rb +0 -22
- data/lib/components/alert_dialog_footer.rb +0 -11
- data/lib/components/alert_dialog_header.rb +0 -11
- data/lib/components/alert_dialog_title.rb +0 -22
- data/lib/components/alert_dialog_trigger.rb +0 -50
- data/lib/components/alert_title.rb +0 -11
- data/lib/components/avatar.rb +0 -31
- data/lib/components/avatar_fallback.rb +0 -21
- data/lib/components/avatar_image.rb +0 -19
- data/lib/components/badge.rb +0 -30
- data/lib/components/breadcrumb.rb +0 -51
- data/lib/components/breadcrumb_ellipsis.rb +0 -23
- data/lib/components/breadcrumb_item.rb +0 -11
- data/lib/components/breadcrumb_link.rb +0 -7
- data/lib/components/breadcrumb_page.rb +0 -21
- data/lib/components/breadcrumb_separator.rb +0 -26
- data/lib/components/button.rb +0 -53
- data/lib/components/card.rb +0 -31
- data/lib/components/card_content.rb +0 -11
- data/lib/components/card_description.rb +0 -11
- data/lib/components/card_footer.rb +0 -11
- data/lib/components/card_header.rb +0 -11
- data/lib/components/card_title.rb +0 -11
- data/lib/components/collapsible.rb +0 -31
- data/lib/components/collapsible_content.rb +0 -24
- data/lib/components/collapsible_trigger.rb +0 -50
- data/lib/components/combobox.rb +0 -57
- data/lib/components/combobox_item.rb +0 -9
- data/lib/components/date_picker.rb +0 -94
- data/lib/components/date_range_picker.rb +0 -113
- data/lib/components/dialog.rb +0 -52
- data/lib/components/dialog_close.rb +0 -42
- data/lib/components/dialog_content.rb +0 -54
- data/lib/components/dialog_description.rb +0 -22
- data/lib/components/dialog_footer.rb +0 -11
- data/lib/components/dialog_header.rb +0 -11
- data/lib/components/dialog_title.rb +0 -22
- data/lib/components/dialog_trigger.rb +0 -50
- data/lib/components/dropdown_menu.rb +0 -50
- data/lib/components/dropdown_menu_content.rb +0 -52
- data/lib/components/dropdown_menu_item.rb +0 -56
- data/lib/components/dropdown_menu_item_to.rb +0 -28
- data/lib/components/dropdown_menu_label.rb +0 -11
- data/lib/components/dropdown_menu_separator.rb +0 -20
- data/lib/components/dropdown_menu_trigger.rb +0 -57
- data/lib/components/form.rb +0 -59
- data/lib/components/form_hint.rb +0 -17
- data/lib/components/hover_card.rb +0 -33
- data/lib/components/hover_card_content.rb +0 -32
- data/lib/components/hover_card_trigger.rb +0 -44
- data/lib/components/input.rb +0 -32
- data/lib/components/label.rb +0 -14
- data/lib/components/loading_button.rb +0 -21
- data/lib/components/pagination.rb +0 -38
- data/lib/components/pagination_ellipsis.rb +0 -24
- data/lib/components/pagination_link.rb +0 -34
- data/lib/components/pagination_next.rb +0 -32
- data/lib/components/pagination_previous.rb +0 -32
- data/lib/components/popover.rb +0 -34
- data/lib/components/popover_content.rb +0 -40
- data/lib/components/popover_trigger.rb +0 -51
- data/lib/components/radio_group.rb +0 -62
- data/lib/components/radio_group_item.rb +0 -66
- data/lib/components/select.rb +0 -184
- data/lib/components/select_content.rb +0 -64
- data/lib/components/select_group.rb +0 -23
- data/lib/components/select_item.rb +0 -59
- data/lib/components/select_label.rb +0 -24
- data/lib/components/select_trigger.rb +0 -56
- data/lib/components/sheet.rb +0 -53
- data/lib/components/sheet_close.rb +0 -42
- data/lib/components/sheet_content.rb +0 -65
- data/lib/components/sheet_description.rb +0 -22
- data/lib/components/sheet_footer.rb +0 -11
- data/lib/components/sheet_header.rb +0 -11
- data/lib/components/sheet_title.rb +0 -22
- data/lib/components/sheet_trigger.rb +0 -50
- data/lib/components/sidebar.rb +0 -108
- data/lib/components/sidebar_container.rb +0 -11
- data/lib/components/sidebar_content.rb +0 -11
- data/lib/components/sidebar_footer.rb +0 -11
- data/lib/components/sidebar_group.rb +0 -11
- data/lib/components/sidebar_group_content.rb +0 -11
- data/lib/components/sidebar_group_label.rb +0 -16
- data/lib/components/sidebar_header.rb +0 -11
- data/lib/components/sidebar_inset.rb +0 -15
- data/lib/components/sidebar_menu.rb +0 -11
- data/lib/components/sidebar_menu_button.rb +0 -61
- data/lib/components/sidebar_menu_item.rb +0 -9
- data/lib/components/sidebar_menu_sub.rb +0 -14
- data/lib/components/sidebar_menu_sub_button.rb +0 -48
- data/lib/components/sidebar_menu_sub_item.rb +0 -9
- data/lib/components/sidebar_trigger.rb +0 -40
- data/lib/components/switch.rb +0 -66
- data/lib/components/table.rb +0 -75
- data/lib/components/table_body.rb +0 -11
- data/lib/components/table_caption.rb +0 -11
- data/lib/components/table_cell.rb +0 -11
- data/lib/components/table_footer.rb +0 -11
- data/lib/components/table_head.rb +0 -14
- data/lib/components/table_header.rb +0 -11
- data/lib/components/table_row.rb +0 -11
- data/lib/components/tabs.rb +0 -38
- data/lib/components/tabs_content.rb +0 -35
- data/lib/components/tabs_list.rb +0 -23
- data/lib/components/tabs_trigger.rb +0 -45
- data/lib/components/textarea.rb +0 -28
- data/lib/components/toast.rb +0 -101
- data/lib/components/toast_action.rb +0 -39
- data/lib/components/toast_action_to.rb +0 -28
- data/lib/components/toast_content.rb +0 -11
- data/lib/components/toast_description.rb +0 -11
- data/lib/components/toast_title.rb +0 -11
- data/lib/components/tooltip.rb +0 -34
- data/lib/components/tooltip_content.rb +0 -39
- data/lib/components/tooltip_trigger.rb +0 -48
@@ -1,159 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['trigger', 'content']
|
5
|
-
|
6
|
-
connect() {
|
7
|
-
this.DOMClickListener = this.onDOMClick.bind(this)
|
8
|
-
this.DOMKeydownListener = this.onDOMKeydown.bind(this)
|
9
|
-
|
10
|
-
this.focusableElements = this.contentTarget.querySelectorAll(
|
11
|
-
'button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])',
|
12
|
-
)
|
13
|
-
|
14
|
-
this.firstElement = this.focusableElements[0]
|
15
|
-
this.lastElement = this.focusableElements[this.focusableElements.length - 1]
|
16
|
-
this.contentElement = document.querySelector(`#${this.contentTarget.id}`)
|
17
|
-
}
|
18
|
-
|
19
|
-
open() {
|
20
|
-
this.showOverlay()
|
21
|
-
this.contentElement.classList.remove('hidden')
|
22
|
-
this.contentElement.dataset.state = 'open'
|
23
|
-
this.triggerTarget.ariaExpanded = true
|
24
|
-
this.setupEventListeners()
|
25
|
-
this.addInert()
|
26
|
-
|
27
|
-
if (window.innerHeight < document.documentElement.scrollHeight) {
|
28
|
-
document.body.dataset.scrollLocked = 1
|
29
|
-
}
|
30
|
-
document.body.appendChild(this.contentElement)
|
31
|
-
this.firstElement.focus() // must be after appendChild
|
32
|
-
}
|
33
|
-
|
34
|
-
close() {
|
35
|
-
this.contentElement.dataset.state = 'closed'
|
36
|
-
this.triggerTarget.ariaExpanded = false
|
37
|
-
this.cleanupEventListeners()
|
38
|
-
this.removeInert()
|
39
|
-
this.element.appendChild(this.contentElement)
|
40
|
-
|
41
|
-
setTimeout(() => {
|
42
|
-
this.contentElement.classList.add('hidden')
|
43
|
-
}, 100)
|
44
|
-
|
45
|
-
setTimeout(() => {
|
46
|
-
delete document.body.dataset.scrollLocked
|
47
|
-
this.removeOverlay()
|
48
|
-
}, 150)
|
49
|
-
|
50
|
-
this.focusTrigger()
|
51
|
-
}
|
52
|
-
|
53
|
-
focusTrigger() {
|
54
|
-
if (this.triggerTarget.dataset.asChild === 'false') {
|
55
|
-
this.triggerTarget.firstElementChild.focus()
|
56
|
-
} else {
|
57
|
-
this.triggerTarget.focus()
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
isOpen() {
|
62
|
-
return this.triggerTarget.ariaExpanded === 'true'
|
63
|
-
}
|
64
|
-
|
65
|
-
showOverlay() {
|
66
|
-
const elem = document.createElement('div')
|
67
|
-
elem.classList.add(
|
68
|
-
'fixed',
|
69
|
-
'inset-0',
|
70
|
-
'z-50',
|
71
|
-
'bg-black/80',
|
72
|
-
'data-[state=open]:animate-in',
|
73
|
-
'data-[state=closed]:animate-out',
|
74
|
-
'data-[state=closed]:fade-out-0',
|
75
|
-
'data-[state=open]:fade-in-0',
|
76
|
-
'pointer-events-auto',
|
77
|
-
)
|
78
|
-
elem.dataset.state = 'open'
|
79
|
-
elem.ariaHidden = true
|
80
|
-
elem.dataset.overlay = true
|
81
|
-
document.body.appendChild(elem)
|
82
|
-
}
|
83
|
-
|
84
|
-
removeOverlay() {
|
85
|
-
if (document.querySelector('[data-overlay]')) {
|
86
|
-
document.querySelector('[data-overlay]').remove()
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
// Global listeners
|
91
|
-
onDOMClick(event) {
|
92
|
-
if (!this.isOpen()) return
|
93
|
-
|
94
|
-
const target = event.target
|
95
|
-
const trigger = event.target.closest(
|
96
|
-
'[data-shadcn-phlexcomponents--dialog-target="trigger"]',
|
97
|
-
)
|
98
|
-
|
99
|
-
if (trigger) return
|
100
|
-
|
101
|
-
const close = target.closest(
|
102
|
-
'[data-action*="shadcn-phlexcomponents--dialog#close"]',
|
103
|
-
)
|
104
|
-
|
105
|
-
if (
|
106
|
-
close ||
|
107
|
-
(target.dataset.action &&
|
108
|
-
target.dataset.action.includes('shadcn-phlexcomponents--dialog#close'))
|
109
|
-
)
|
110
|
-
this.close()
|
111
|
-
|
112
|
-
if (this.contentElement.contains(event.target)) return
|
113
|
-
|
114
|
-
this.close()
|
115
|
-
}
|
116
|
-
|
117
|
-
onDOMKeydown(event) {
|
118
|
-
if (!this.isOpen()) return
|
119
|
-
|
120
|
-
const key = event.key
|
121
|
-
|
122
|
-
if (key === 'Escape') {
|
123
|
-
this.close()
|
124
|
-
} else if (key === 'Tab') {
|
125
|
-
// If Shift + Tab pressed on first element, go to last element
|
126
|
-
if (event.shiftKey && document.activeElement === this.firstElement) {
|
127
|
-
event.preventDefault()
|
128
|
-
this.lastElement.focus()
|
129
|
-
}
|
130
|
-
// If Tab pressed on last element, go to first element
|
131
|
-
else if (!event.shiftKey && document.activeElement === this.lastElement) {
|
132
|
-
event.preventDefault()
|
133
|
-
this.firstElement.focus()
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
setupEventListeners() {
|
139
|
-
document.addEventListener('click', this.DOMClickListener)
|
140
|
-
document.addEventListener('keydown', this.DOMKeydownListener)
|
141
|
-
}
|
142
|
-
|
143
|
-
cleanupEventListeners() {
|
144
|
-
document.removeEventListener('click', this.DOMClickListener)
|
145
|
-
document.removeEventListener('keydown', this.DOMKeydownListener)
|
146
|
-
}
|
147
|
-
|
148
|
-
addInert() {
|
149
|
-
Array.from(document.body.children)
|
150
|
-
.filter((el) => el !== this.contentElement)
|
151
|
-
.forEach((el) => el.setAttribute('inert', ''))
|
152
|
-
}
|
153
|
-
|
154
|
-
removeInert() {
|
155
|
-
Array.from(document.body.children)
|
156
|
-
.filter((el) => el.hasAttribute('inert'))
|
157
|
-
.forEach((el) => el.removeAttribute('inert'))
|
158
|
-
}
|
159
|
-
}
|
@@ -1,193 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
import {
|
3
|
-
computePosition,
|
4
|
-
flip,
|
5
|
-
shift,
|
6
|
-
offset,
|
7
|
-
autoUpdate,
|
8
|
-
} from '@floating-ui/dom'
|
9
|
-
|
10
|
-
export default class extends Controller {
|
11
|
-
static targets = ['trigger', 'contentWrapper', 'content', 'item']
|
12
|
-
|
13
|
-
connect() {
|
14
|
-
this.contentTarget.dataset.state = this.isOpen() ? 'open' : 'closed'
|
15
|
-
this.DOMClickListener = this.onDOMClick.bind(this)
|
16
|
-
this.DOMKeydownListener = this.onDOMKeydown.bind(this)
|
17
|
-
this.items = this.itemTargets.filter(
|
18
|
-
(item) => item.dataset.disabled === undefined,
|
19
|
-
)
|
20
|
-
}
|
21
|
-
|
22
|
-
toggle(event) {
|
23
|
-
const key = event.key
|
24
|
-
|
25
|
-
if (this.isOpen()) {
|
26
|
-
this.close()
|
27
|
-
} else {
|
28
|
-
this.open()
|
29
|
-
}
|
30
|
-
|
31
|
-
if (event.currentTarget === this.triggerTarget) {
|
32
|
-
if (['ArrowDown', 'Enter', ' '].includes(key)) {
|
33
|
-
setTimeout(() => {
|
34
|
-
this.focusItem(null, 0)
|
35
|
-
}, 100)
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
isOpen() {
|
41
|
-
return this.triggerTarget.ariaExpanded === 'true'
|
42
|
-
}
|
43
|
-
|
44
|
-
open() {
|
45
|
-
this.contentWrapperTarget.classList.remove('hidden')
|
46
|
-
this.triggerTarget.ariaExpanded = true
|
47
|
-
this.triggerTarget.dataset.state = 'open'
|
48
|
-
this.contentTarget.dataset.state = 'open'
|
49
|
-
|
50
|
-
setTimeout(() => {
|
51
|
-
this.focusContent()
|
52
|
-
}, 100)
|
53
|
-
|
54
|
-
this.setupEventListeners()
|
55
|
-
|
56
|
-
if (window.innerHeight < document.documentElement.scrollHeight) {
|
57
|
-
document.body.dataset.scrollLocked = 1
|
58
|
-
}
|
59
|
-
|
60
|
-
this.cleanup = autoUpdate(
|
61
|
-
this.triggerTarget,
|
62
|
-
this.contentWrapperTarget,
|
63
|
-
() => {
|
64
|
-
computePosition(this.triggerTarget, this.contentWrapperTarget, {
|
65
|
-
placement: this.element.dataset.side,
|
66
|
-
strategy: 'fixed',
|
67
|
-
middleware: [flip(), shift(), offset(4)],
|
68
|
-
}).then(({ x, y }) => {
|
69
|
-
Object.assign(this.contentWrapperTarget.style, {
|
70
|
-
left: `${x}px`,
|
71
|
-
top: `${y}px`,
|
72
|
-
})
|
73
|
-
})
|
74
|
-
},
|
75
|
-
)
|
76
|
-
}
|
77
|
-
|
78
|
-
close() {
|
79
|
-
this.triggerTarget.ariaExpanded = false
|
80
|
-
this.triggerTarget.dataset.state = 'closed'
|
81
|
-
this.contentTarget.dataset.state = 'closed'
|
82
|
-
this.cleanup()
|
83
|
-
this.cleanupEventListeners()
|
84
|
-
delete document.body.dataset.scrollLocked
|
85
|
-
|
86
|
-
setTimeout(() => {
|
87
|
-
this.contentWrapperTarget.classList.add('hidden')
|
88
|
-
}, 100)
|
89
|
-
|
90
|
-
this.focusTrigger()
|
91
|
-
}
|
92
|
-
|
93
|
-
focusTrigger() {
|
94
|
-
if (this.triggerTarget.dataset.asChild === 'false') {
|
95
|
-
this.triggerTarget.firstElementChild.focus()
|
96
|
-
} else {
|
97
|
-
this.triggerTarget.focus()
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
focusItem(event = null, index = null) {
|
102
|
-
let itemIndex = index
|
103
|
-
|
104
|
-
if (event) {
|
105
|
-
const item = event.currentTarget || event.target
|
106
|
-
itemIndex = this.items.indexOf(item)
|
107
|
-
}
|
108
|
-
|
109
|
-
this.items.forEach((item, index) => {
|
110
|
-
if (index === itemIndex) {
|
111
|
-
item.tabIndex = 0
|
112
|
-
item.focus()
|
113
|
-
} else {
|
114
|
-
item.tabIndex = -1
|
115
|
-
}
|
116
|
-
})
|
117
|
-
}
|
118
|
-
|
119
|
-
focusFirstItem() {
|
120
|
-
this.focusItem(null, 0)
|
121
|
-
}
|
122
|
-
|
123
|
-
focusLastItem() {
|
124
|
-
this.focusItem(null, this.items.length - 1)
|
125
|
-
}
|
126
|
-
|
127
|
-
focusNextItem(event) {
|
128
|
-
const item = event.currentTarget || event.target
|
129
|
-
const index = this.items.indexOf(item)
|
130
|
-
if (index === this.items.length - 1) return
|
131
|
-
|
132
|
-
this.focusItem(null, index + 1)
|
133
|
-
}
|
134
|
-
|
135
|
-
focusPrevItem(event) {
|
136
|
-
const item = event.currentTarget
|
137
|
-
const index = this.items.indexOf(item)
|
138
|
-
if (index === 0) return
|
139
|
-
|
140
|
-
this.focusItem(null, index - 1)
|
141
|
-
}
|
142
|
-
|
143
|
-
focusContent() {
|
144
|
-
this.items.forEach((item) => {
|
145
|
-
item.blur()
|
146
|
-
})
|
147
|
-
|
148
|
-
this.contentTarget.focus()
|
149
|
-
}
|
150
|
-
|
151
|
-
selectItem(event) {
|
152
|
-
if (!this.isOpen()) return
|
153
|
-
|
154
|
-
const key = event.key
|
155
|
-
const item = event.currentTarget || event.target
|
156
|
-
|
157
|
-
if (key === 'Enter' || key === ' ') {
|
158
|
-
item.click()
|
159
|
-
}
|
160
|
-
|
161
|
-
this.close()
|
162
|
-
}
|
163
|
-
|
164
|
-
// Global listeners
|
165
|
-
onDOMClick(event) {
|
166
|
-
if (!this.isOpen()) return
|
167
|
-
if (this.element.contains(event.target)) return
|
168
|
-
|
169
|
-
this.close()
|
170
|
-
}
|
171
|
-
|
172
|
-
onDOMKeydown(event) {
|
173
|
-
if (!this.isOpen()) return
|
174
|
-
|
175
|
-
const key = event.key
|
176
|
-
|
177
|
-
if (['Tab', 'Enter', ' '].includes(key)) event.preventDefault()
|
178
|
-
|
179
|
-
if (key === 'Escape') {
|
180
|
-
this.close()
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
setupEventListeners() {
|
185
|
-
document.addEventListener('click', this.DOMClickListener)
|
186
|
-
document.addEventListener('keydown', this.DOMKeydownListener)
|
187
|
-
}
|
188
|
-
|
189
|
-
cleanupEventListeners() {
|
190
|
-
document.removeEventListener('click', this.DOMClickListener)
|
191
|
-
document.removeEventListener('keydown', this.DOMKeydownListener)
|
192
|
-
}
|
193
|
-
}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
import tippy from 'tippy.js'
|
3
|
-
|
4
|
-
const hideOnEsc = {
|
5
|
-
name: 'hideOnEsc',
|
6
|
-
defaultValue: true,
|
7
|
-
fn({ hide }) {
|
8
|
-
function onKeyDown(event) {
|
9
|
-
if (event.keyCode === 27) {
|
10
|
-
hide()
|
11
|
-
}
|
12
|
-
}
|
13
|
-
|
14
|
-
return {
|
15
|
-
onShow() {
|
16
|
-
document.addEventListener('keydown', onKeyDown)
|
17
|
-
},
|
18
|
-
onHide() {
|
19
|
-
document.removeEventListener('keydown', onKeyDown)
|
20
|
-
},
|
21
|
-
}
|
22
|
-
},
|
23
|
-
}
|
24
|
-
|
25
|
-
export default class extends Controller {
|
26
|
-
static targets = ['trigger', 'content']
|
27
|
-
|
28
|
-
connect() {
|
29
|
-
const content = this.contentTarget.innerHTML
|
30
|
-
|
31
|
-
this.tippy = tippy(this.triggerTarget, {
|
32
|
-
content: content,
|
33
|
-
allowHTML: true,
|
34
|
-
interactive: true,
|
35
|
-
arrow: false,
|
36
|
-
placement: this.element.dataset.side,
|
37
|
-
plugins: [hideOnEsc],
|
38
|
-
offset: [0, 4],
|
39
|
-
delay: 250,
|
40
|
-
})
|
41
|
-
}
|
42
|
-
}
|
@@ -1,124 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
import {
|
3
|
-
computePosition,
|
4
|
-
flip,
|
5
|
-
shift,
|
6
|
-
offset,
|
7
|
-
autoUpdate,
|
8
|
-
} from '@floating-ui/dom'
|
9
|
-
|
10
|
-
export default class extends Controller {
|
11
|
-
static targets = ['trigger', 'contentWrapper', 'content', 'menuItem']
|
12
|
-
|
13
|
-
connect() {
|
14
|
-
this.DOMClickListener = this.onDOMClick.bind(this)
|
15
|
-
this.DOMKeydownListener = this.onDOMKeydown.bind(this)
|
16
|
-
|
17
|
-
this.focusableElements = this.contentTarget.querySelectorAll(
|
18
|
-
'button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])',
|
19
|
-
)
|
20
|
-
|
21
|
-
this.firstElement = this.focusableElements[0]
|
22
|
-
this.lastElement = this.focusableElements[this.focusableElements.length - 1]
|
23
|
-
}
|
24
|
-
|
25
|
-
toggle() {
|
26
|
-
if (this.isOpen()) {
|
27
|
-
this.close()
|
28
|
-
} else {
|
29
|
-
this.open()
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
onDOMClick(event) {
|
34
|
-
if (!this.isOpen()) return
|
35
|
-
if (this.element.contains(event.target)) return
|
36
|
-
|
37
|
-
this.close()
|
38
|
-
}
|
39
|
-
|
40
|
-
onDOMKeydown(event) {
|
41
|
-
if (!this.isOpen()) return
|
42
|
-
|
43
|
-
const key = event.key
|
44
|
-
|
45
|
-
if (key === 'Escape') {
|
46
|
-
this.close()
|
47
|
-
} else if (key === 'Tab') {
|
48
|
-
// If Shift + Tab pressed on first element, go to last element
|
49
|
-
if (event.shiftKey && document.activeElement === this.firstElement) {
|
50
|
-
event.preventDefault()
|
51
|
-
this.lastElement.focus()
|
52
|
-
}
|
53
|
-
// If Tab pressed on last element, go to first element
|
54
|
-
else if (!event.shiftKey && document.activeElement === this.lastElement) {
|
55
|
-
event.preventDefault()
|
56
|
-
this.firstElement.focus()
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
isOpen() {
|
62
|
-
return this.triggerTarget.ariaExpanded === 'true'
|
63
|
-
}
|
64
|
-
|
65
|
-
open() {
|
66
|
-
this.contentWrapperTarget.classList.remove('hidden')
|
67
|
-
this.triggerTarget.ariaExpanded = true
|
68
|
-
this.contentTarget.dataset.state = 'open'
|
69
|
-
this.setupEventListeners()
|
70
|
-
|
71
|
-
setTimeout(() => {
|
72
|
-
this.firstElement.focus()
|
73
|
-
}, 100)
|
74
|
-
|
75
|
-
this.cleanup = autoUpdate(
|
76
|
-
this.triggerTarget,
|
77
|
-
this.contentWrapperTarget,
|
78
|
-
() => {
|
79
|
-
computePosition(this.triggerTarget, this.contentWrapperTarget, {
|
80
|
-
placement: this.element.dataset.side,
|
81
|
-
strategy: 'fixed',
|
82
|
-
middleware: [flip(), shift(), offset(4)],
|
83
|
-
}).then(({ x, y }) => {
|
84
|
-
Object.assign(this.contentWrapperTarget.style, {
|
85
|
-
left: `${x}px`,
|
86
|
-
top: `${y}px`,
|
87
|
-
})
|
88
|
-
})
|
89
|
-
},
|
90
|
-
)
|
91
|
-
}
|
92
|
-
|
93
|
-
close() {
|
94
|
-
this.contentTarget.dataset.state = 'closed'
|
95
|
-
this.triggerTarget.ariaExpanded = false
|
96
|
-
this.cleanup()
|
97
|
-
this.cleanupEventListeners()
|
98
|
-
|
99
|
-
setTimeout(() => {
|
100
|
-
this.contentWrapperTarget.classList.add('hidden')
|
101
|
-
}, 100)
|
102
|
-
|
103
|
-
this.focusTrigger()
|
104
|
-
}
|
105
|
-
|
106
|
-
focusTrigger() {
|
107
|
-
if (this.triggerTarget.dataset.asChild === 'false') {
|
108
|
-
this.triggerTarget.firstElementChild.focus()
|
109
|
-
} else {
|
110
|
-
this.triggerTarget.focus()
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
// Global listeners
|
115
|
-
setupEventListeners() {
|
116
|
-
document.addEventListener('click', this.DOMClickListener)
|
117
|
-
document.addEventListener('keydown', this.DOMKeydownListener)
|
118
|
-
}
|
119
|
-
|
120
|
-
cleanupEventListeners() {
|
121
|
-
document.removeEventListener('click', this.DOMClickListener)
|
122
|
-
document.removeEventListener('keydown', this.DOMKeydownListener)
|
123
|
-
}
|
124
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['bar']
|
5
|
-
|
6
|
-
static values = {
|
7
|
-
progress: Number,
|
8
|
-
}
|
9
|
-
|
10
|
-
progressValueChanged(value) {
|
11
|
-
this.element.setAttribute('aria-valuenow', value)
|
12
|
-
this.barTarget.style.transform = `translateX(-${100 - value}%)`
|
13
|
-
}
|
14
|
-
}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['item']
|
5
|
-
static values = {
|
6
|
-
selected: String,
|
7
|
-
}
|
8
|
-
|
9
|
-
connect() {
|
10
|
-
if (!this.selectedValue) {
|
11
|
-
this.itemTargets[0].tabIndex = 0
|
12
|
-
}
|
13
|
-
|
14
|
-
this.items = this.itemTargets.filter((i) => !i.disabled)
|
15
|
-
}
|
16
|
-
|
17
|
-
setChecked(event) {
|
18
|
-
const item = event.currentTarget
|
19
|
-
this.selectedValue = item.dataset.value
|
20
|
-
}
|
21
|
-
|
22
|
-
preventDefault(event) {
|
23
|
-
event.preventDefault()
|
24
|
-
}
|
25
|
-
|
26
|
-
setCheckedToNext(event) {
|
27
|
-
const item = event.currentTarget
|
28
|
-
const index = this.items.indexOf(item)
|
29
|
-
let nextIndex = index + 1
|
30
|
-
|
31
|
-
if (index === this.items.length - 1) {
|
32
|
-
nextIndex = 0
|
33
|
-
}
|
34
|
-
|
35
|
-
this.selectedValue = this.items[nextIndex].dataset.value
|
36
|
-
}
|
37
|
-
|
38
|
-
setCheckedToPrev(event) {
|
39
|
-
const item = event.currentTarget
|
40
|
-
const index = this.items.indexOf(item)
|
41
|
-
let prevIndex = index - 1
|
42
|
-
|
43
|
-
if (index === 0) {
|
44
|
-
prevIndex = this.items.length - 1
|
45
|
-
}
|
46
|
-
|
47
|
-
this.selectedValue = this.items[prevIndex].dataset.value
|
48
|
-
}
|
49
|
-
|
50
|
-
focusItem() {
|
51
|
-
const item = this.itemTargets.find(
|
52
|
-
(i) => i.dataset.value === this.selectedValue,
|
53
|
-
)
|
54
|
-
|
55
|
-
if (!item) return
|
56
|
-
|
57
|
-
// Focus first item that is not disabled and allow it to be focused
|
58
|
-
if (item.disabled) {
|
59
|
-
item.tabIndex = -1
|
60
|
-
const items = this.items || this.itemTargets.filter((i) => !i.disabled)
|
61
|
-
|
62
|
-
if (items.length > 0) {
|
63
|
-
items[0].focus()
|
64
|
-
items[0].tabIndex = 0
|
65
|
-
}
|
66
|
-
} else {
|
67
|
-
item.focus()
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
selectedValueChanged(value) {
|
72
|
-
this.itemTargets.forEach((item) => {
|
73
|
-
const input = item.querySelector('[data-input]')
|
74
|
-
|
75
|
-
if (value === item.dataset.value) {
|
76
|
-
input.checked = true
|
77
|
-
item.tabIndex = 0
|
78
|
-
item.ariaChecked = true
|
79
|
-
item.dataset.checked = true
|
80
|
-
} else {
|
81
|
-
input.checked = false
|
82
|
-
item.tabIndex = -1
|
83
|
-
item.ariaChecked = false
|
84
|
-
item.dataset.checked = false
|
85
|
-
}
|
86
|
-
})
|
87
|
-
|
88
|
-
this.focusItem()
|
89
|
-
}
|
90
|
-
}
|