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,294 +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 = [
|
12
|
-
'trigger',
|
13
|
-
'contentWrapper',
|
14
|
-
'content',
|
15
|
-
'item',
|
16
|
-
'triggerText',
|
17
|
-
'group',
|
18
|
-
'label',
|
19
|
-
'select',
|
20
|
-
]
|
21
|
-
|
22
|
-
static values = {
|
23
|
-
selected: String,
|
24
|
-
}
|
25
|
-
|
26
|
-
connect() {
|
27
|
-
this.DOMClickListener = this.onDOMClick.bind(this)
|
28
|
-
this.DOMKeydownListener = this.onDOMKeydown.bind(this)
|
29
|
-
|
30
|
-
this.setAriaLabelledby()
|
31
|
-
|
32
|
-
this.items = [
|
33
|
-
...this.element.querySelectorAll(
|
34
|
-
'[data-shadcn-phlexcomponents--select-target="item"]:not([data-disabled])',
|
35
|
-
),
|
36
|
-
]
|
37
|
-
|
38
|
-
this.search = ''
|
39
|
-
this.searchTimer = null
|
40
|
-
this.resetSearchTimer = null
|
41
|
-
}
|
42
|
-
|
43
|
-
// Methods
|
44
|
-
toggle() {
|
45
|
-
if (this.isOpen()) {
|
46
|
-
this.close()
|
47
|
-
} else {
|
48
|
-
this.open()
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
open() {
|
53
|
-
const triggerWidth = this.triggerTarget.offsetWidth
|
54
|
-
this.contentWrapperTarget.classList.remove('hidden')
|
55
|
-
|
56
|
-
const contentWrapperWidth = this.contentWrapperTarget.offsetWidth
|
57
|
-
|
58
|
-
if (contentWrapperWidth < triggerWidth) {
|
59
|
-
this.contentWrapperTarget.style.width = `${triggerWidth}px`
|
60
|
-
}
|
61
|
-
|
62
|
-
this.triggerTarget.ariaExpanded = true
|
63
|
-
this.contentTarget.dataset.state = 'open'
|
64
|
-
|
65
|
-
if (this.selectedValue) {
|
66
|
-
const item = this.itemTargets.find(
|
67
|
-
(i) => i.dataset.value === this.selectedValue,
|
68
|
-
)
|
69
|
-
|
70
|
-
if (item && !item.dataset.disabled) {
|
71
|
-
item.focus()
|
72
|
-
} else {
|
73
|
-
this.contentTarget.focus()
|
74
|
-
}
|
75
|
-
} else {
|
76
|
-
this.focusItem(null, 0)
|
77
|
-
}
|
78
|
-
|
79
|
-
if (window.innerHeight < document.documentElement.scrollHeight) {
|
80
|
-
document.body.dataset.scrollLocked = 1
|
81
|
-
}
|
82
|
-
this.setupEventListeners()
|
83
|
-
|
84
|
-
this.cleanup = autoUpdate(
|
85
|
-
this.triggerTarget,
|
86
|
-
this.contentWrapperTarget,
|
87
|
-
() => {
|
88
|
-
computePosition(this.triggerTarget, this.contentWrapperTarget, {
|
89
|
-
placement: 'bottom',
|
90
|
-
strategy: 'fixed',
|
91
|
-
middleware: [flip(), shift(), offset(4)],
|
92
|
-
}).then(({ x, y }) => {
|
93
|
-
Object.assign(this.contentWrapperTarget.style, {
|
94
|
-
left: `${x}px`,
|
95
|
-
top: `${y}px`,
|
96
|
-
})
|
97
|
-
})
|
98
|
-
},
|
99
|
-
)
|
100
|
-
}
|
101
|
-
|
102
|
-
close() {
|
103
|
-
this.contentTarget.dataset.state = 'closed'
|
104
|
-
this.triggerTarget.ariaExpanded = false
|
105
|
-
this.cleanup()
|
106
|
-
this.cleanupEventListeners()
|
107
|
-
delete document.body.dataset.scrollLocked
|
108
|
-
|
109
|
-
setTimeout(() => {
|
110
|
-
this.contentWrapperTarget.classList.add('hidden')
|
111
|
-
}, 100)
|
112
|
-
|
113
|
-
if (this.triggerTarget.nodeName === 'DIV') {
|
114
|
-
this.triggerTarget.firstElementChild.focus()
|
115
|
-
} else {
|
116
|
-
this.triggerTarget.focus()
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
setAriaLabelledby() {
|
121
|
-
this.groupTargets.forEach((g) => {
|
122
|
-
const label = g.querySelector(
|
123
|
-
'[data-shadcn-phlexcomponents--select-target="label"]',
|
124
|
-
)
|
125
|
-
|
126
|
-
if (label) {
|
127
|
-
const ariaId = this.element.dataset.ariaId
|
128
|
-
const labelledby = `${ariaId}-${label.textContent
|
129
|
-
.toLowerCase()
|
130
|
-
.trim()
|
131
|
-
.replace(/ /, '-')}`
|
132
|
-
label.setAttribute('id', labelledby)
|
133
|
-
g.setAttribute('aria-labelledby', labelledby)
|
134
|
-
}
|
135
|
-
})
|
136
|
-
}
|
137
|
-
|
138
|
-
isOpen() {
|
139
|
-
return this.triggerTarget.ariaExpanded === 'true'
|
140
|
-
}
|
141
|
-
|
142
|
-
focusItem(event = null, index = null) {
|
143
|
-
let itemIndex = index
|
144
|
-
|
145
|
-
if (event) {
|
146
|
-
const item = event.currentTarget || event.target
|
147
|
-
itemIndex = this.items.indexOf(item)
|
148
|
-
}
|
149
|
-
|
150
|
-
const item = this.items[itemIndex]
|
151
|
-
item.tabIndex = 0
|
152
|
-
item.focus()
|
153
|
-
|
154
|
-
this.items.forEach((item, index) => {
|
155
|
-
if (index !== itemIndex) {
|
156
|
-
item.tabIndex = -1
|
157
|
-
}
|
158
|
-
})
|
159
|
-
}
|
160
|
-
|
161
|
-
focusFirstItem() {
|
162
|
-
this.focusItem(null, 0)
|
163
|
-
}
|
164
|
-
|
165
|
-
focusLastItem() {
|
166
|
-
this.focusItem(null, this.items.length - 1)
|
167
|
-
}
|
168
|
-
|
169
|
-
focusPrevItem(event) {
|
170
|
-
const item = event.currentTarget || event.target
|
171
|
-
const index = this.items.indexOf(item)
|
172
|
-
|
173
|
-
if (index - 1 >= 0) {
|
174
|
-
this.focusItem(null, index - 1)
|
175
|
-
}
|
176
|
-
}
|
177
|
-
|
178
|
-
focusNextItem(event) {
|
179
|
-
const item = event.currentTarget || event.target
|
180
|
-
const index = this.items.indexOf(item)
|
181
|
-
|
182
|
-
if (index + 1 < this.items.length) {
|
183
|
-
this.focusItem(null, index + 1)
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
selectItem(event) {
|
188
|
-
const item = event.currentTarget || event.target
|
189
|
-
const value = item.dataset.value
|
190
|
-
this.selectedValue = value
|
191
|
-
this.close()
|
192
|
-
}
|
193
|
-
|
194
|
-
focusContent() {
|
195
|
-
this.items.forEach((item) => {
|
196
|
-
item.blur()
|
197
|
-
})
|
198
|
-
|
199
|
-
this.contentTarget.focus()
|
200
|
-
}
|
201
|
-
|
202
|
-
selectedValueChanged(value) {
|
203
|
-
const item = this.itemTargets.find((i) => i.dataset.value === value)
|
204
|
-
|
205
|
-
if (item) {
|
206
|
-
this.triggerTextTarget.textContent = item.textContent
|
207
|
-
|
208
|
-
this.itemTargets.forEach((i) => {
|
209
|
-
if (i.dataset.value === value) {
|
210
|
-
i.setAttribute('aria-selected', 'true')
|
211
|
-
} else {
|
212
|
-
i.setAttribute('aria-selected', 'false')
|
213
|
-
}
|
214
|
-
})
|
215
|
-
|
216
|
-
this.selectTarget.value = value
|
217
|
-
}
|
218
|
-
|
219
|
-
delete this.triggerTarget.dataset.placeholder
|
220
|
-
const hasPlaceholder = this.triggerTarget.dataset.placeholderText
|
221
|
-
|
222
|
-
if (hasPlaceholder) {
|
223
|
-
if (!value || value.length === 0) {
|
224
|
-
this.triggerTarget.dataset.placeholder = true
|
225
|
-
this.triggerTextTarget.textContent = hasPlaceholder
|
226
|
-
}
|
227
|
-
}
|
228
|
-
}
|
229
|
-
|
230
|
-
handleSearchChange(search) {
|
231
|
-
const item = this.items.find((i) =>
|
232
|
-
i.textContent.toLowerCase().startsWith(search.toLowerCase()),
|
233
|
-
)
|
234
|
-
|
235
|
-
if (item) {
|
236
|
-
item.focus()
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
handleSearch(key) {
|
241
|
-
const search = this.search + key
|
242
|
-
this.search = search
|
243
|
-
|
244
|
-
window.clearTimeout(this.searchTimer)
|
245
|
-
window.clearTimeout(this.resetSearchTimer)
|
246
|
-
|
247
|
-
if (search !== '') {
|
248
|
-
this.searchTimer = window.setTimeout(() => {
|
249
|
-
this.handleSearchChange(search)
|
250
|
-
}, 150)
|
251
|
-
|
252
|
-
this.resetSearchTimer = window.setTimeout(() => {
|
253
|
-
this.search = ''
|
254
|
-
}, 300)
|
255
|
-
}
|
256
|
-
}
|
257
|
-
|
258
|
-
// Global listeners
|
259
|
-
onDOMClick(event) {
|
260
|
-
const htmlFor = event.target.htmlFor
|
261
|
-
|
262
|
-
if (htmlFor === this.triggerTarget.id) return
|
263
|
-
if (event.target) if (this.element.contains(event.target)) return
|
264
|
-
|
265
|
-
this.close()
|
266
|
-
}
|
267
|
-
|
268
|
-
onDOMKeydown(event) {
|
269
|
-
if (!this.isOpen()) return
|
270
|
-
|
271
|
-
const key = event.key
|
272
|
-
const isModifierKey = event.ctrlKey || event.altKey || event.metaKey
|
273
|
-
|
274
|
-
if (key === 'Tab') event.preventDefault()
|
275
|
-
|
276
|
-
if (!isModifierKey && key.length === 1) this.handleSearch(key)
|
277
|
-
|
278
|
-
if (key === 'Escape') {
|
279
|
-
this.close()
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
setupEventListeners() {
|
284
|
-
document.addEventListener('click', this.DOMClickListener)
|
285
|
-
document.addEventListener('keydown', this.DOMKeydownListener)
|
286
|
-
}
|
287
|
-
|
288
|
-
cleanupEventListeners() {
|
289
|
-
document.removeEventListener('click', this.DOMClickListener)
|
290
|
-
document.removeEventListener('keydown', this.DOMKeydownListener)
|
291
|
-
window.clearTimeout(this.searchTimer)
|
292
|
-
window.clearTimeout(this.resetSearchTimer)
|
293
|
-
}
|
294
|
-
}
|
@@ -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--sheet-target="trigger"]',
|
97
|
-
)
|
98
|
-
|
99
|
-
if (trigger) return
|
100
|
-
|
101
|
-
const close = target.closest(
|
102
|
-
'[data-action*="shadcn-phlexcomponents--sheet#close"]',
|
103
|
-
)
|
104
|
-
|
105
|
-
if (
|
106
|
-
close ||
|
107
|
-
(target.dataset.action &&
|
108
|
-
target.dataset.action.includes('shadcn-phlexcomponents--sheet#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,15 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
connect() {
|
5
|
-
this.sidebarId = this.element.dataset.sidebarId
|
6
|
-
}
|
7
|
-
|
8
|
-
toggle() {
|
9
|
-
const sidebar = this.application.getControllerForElementAndIdentifier(
|
10
|
-
document.querySelector(`#${this.sidebarId}`),
|
11
|
-
'shadcn-phlexcomponents--sidebar',
|
12
|
-
)
|
13
|
-
sidebar.toggle()
|
14
|
-
}
|
15
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['input']
|
5
|
-
static values = {
|
6
|
-
checked: Boolean,
|
7
|
-
}
|
8
|
-
|
9
|
-
toggle() {
|
10
|
-
this.checkedValue = !this.checkedValue
|
11
|
-
}
|
12
|
-
|
13
|
-
checkedValueChanged(value) {
|
14
|
-
if (value === true) {
|
15
|
-
this.element.ariaChecked = true
|
16
|
-
this.element.dataset.checked = true
|
17
|
-
this.inputTarget.checked = true
|
18
|
-
} else {
|
19
|
-
this.element.ariaChecked = false
|
20
|
-
this.element.dataset.checked = false
|
21
|
-
this.inputTarget.checked = false
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
@@ -1,73 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['trigger', 'content']
|
5
|
-
static values = {
|
6
|
-
selected: String,
|
7
|
-
}
|
8
|
-
|
9
|
-
connect() {
|
10
|
-
this.triggers = this.triggerTargets.filter((t) => !t.disabled)
|
11
|
-
|
12
|
-
if (!this.selectedValue) {
|
13
|
-
this.selectedValue = this.triggerTargets[0].dataset.value
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
setActiveTab(event) {
|
18
|
-
this.selectedValue = event.target.dataset.value
|
19
|
-
}
|
20
|
-
|
21
|
-
setActiveToPrev(event) {
|
22
|
-
const trigger = event.currentTarget
|
23
|
-
const index = this.triggers.indexOf(trigger)
|
24
|
-
let prevIndex = index - 1
|
25
|
-
|
26
|
-
if (index === 0) {
|
27
|
-
prevIndex = this.triggers.length - 1
|
28
|
-
}
|
29
|
-
|
30
|
-
this.selectedValue = this.triggers[prevIndex].dataset.value
|
31
|
-
this.triggers[prevIndex].focus()
|
32
|
-
}
|
33
|
-
|
34
|
-
setActiveToNext(event) {
|
35
|
-
const trigger = event.currentTarget
|
36
|
-
const index = this.triggers.indexOf(trigger)
|
37
|
-
let nextIndex = index + 1
|
38
|
-
|
39
|
-
if (index === this.triggers.length - 1) {
|
40
|
-
nextIndex = 0
|
41
|
-
}
|
42
|
-
|
43
|
-
this.selectedValue = this.triggers[nextIndex].dataset.value
|
44
|
-
this.triggers[nextIndex].focus()
|
45
|
-
}
|
46
|
-
|
47
|
-
selectedValueChanged(value) {
|
48
|
-
this.triggerTargets.forEach((trigger) => {
|
49
|
-
const triggerValue = trigger.dataset.value
|
50
|
-
const content = this.contentTargets.find((c) => {
|
51
|
-
return c.dataset.value === triggerValue
|
52
|
-
})
|
53
|
-
|
54
|
-
if (!content) {
|
55
|
-
throw new Error(
|
56
|
-
`Could not find TabsContent with value "${triggerValue}"`,
|
57
|
-
)
|
58
|
-
}
|
59
|
-
|
60
|
-
if (triggerValue === value) {
|
61
|
-
trigger.ariaSelected = true
|
62
|
-
trigger.tabIndex = 0
|
63
|
-
trigger.dataset.state = 'active'
|
64
|
-
content.classList.remove('hidden')
|
65
|
-
} else {
|
66
|
-
trigger.ariaSelected = false
|
67
|
-
trigger.tabIndex = -1
|
68
|
-
trigger.dataset.state = 'inactive'
|
69
|
-
content.classList.add('hidden')
|
70
|
-
}
|
71
|
-
})
|
72
|
-
}
|
73
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
add({ title, description, variant = 'default' }) {
|
5
|
-
const template =
|
6
|
-
variant === 'default'
|
7
|
-
? this.element.querySelector('[data-variant="default"]')
|
8
|
-
: this.element.querySelector('[data-variant="destructive"]')
|
9
|
-
|
10
|
-
const clone = template.content.cloneNode(true)
|
11
|
-
|
12
|
-
if (title) {
|
13
|
-
clone.querySelector('[data-title]').textContent = title
|
14
|
-
}
|
15
|
-
|
16
|
-
if (description) {
|
17
|
-
clone.querySelector('[data-description]').textContent = description
|
18
|
-
}
|
19
|
-
|
20
|
-
this.element.append(clone)
|
21
|
-
}
|
22
|
-
}
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
connect() {
|
5
|
-
this.focusableElements = this.element.querySelectorAll('button')
|
6
|
-
this.duration = Number(this.element.dataset.duration)
|
7
|
-
|
8
|
-
this.focusableElements.forEach((el) => {
|
9
|
-
el.addEventListener('focus', () => {
|
10
|
-
this.cancelDismiss()
|
11
|
-
})
|
12
|
-
el.addEventListener('blur', () => {
|
13
|
-
this.dismiss()
|
14
|
-
})
|
15
|
-
})
|
16
|
-
|
17
|
-
this.dismiss()
|
18
|
-
}
|
19
|
-
|
20
|
-
cancelDismiss() {
|
21
|
-
window.clearTimeout(this.timer)
|
22
|
-
}
|
23
|
-
|
24
|
-
close() {
|
25
|
-
this.element.dataset.state = 'closed'
|
26
|
-
|
27
|
-
setTimeout(() => {
|
28
|
-
this.element.remove()
|
29
|
-
}, 100)
|
30
|
-
}
|
31
|
-
|
32
|
-
dismiss(event) {
|
33
|
-
if (event && event.type === 'mouseout') {
|
34
|
-
if (this.element.contains(document.activeElement)) {
|
35
|
-
return
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
if (this.duration > 0) {
|
40
|
-
this.timer = setTimeout(() => {
|
41
|
-
this.close()
|
42
|
-
}, this.duration)
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
@@ -1,41 +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
|
-
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
|
-
})
|
40
|
-
}
|
41
|
-
}
|
data/lib/components/accordion.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ShadcnPhlexcomponents
|
4
|
-
class Accordion < Base
|
5
|
-
def initialize(value: nil, multiple: false, aria_id: "accordion-#{SecureRandom.hex(5)}", **attributes)
|
6
|
-
@multiple = multiple
|
7
|
-
@value = value&.is_a?(String) ? [value] : value
|
8
|
-
@aria_id = aria_id
|
9
|
-
super(**attributes)
|
10
|
-
end
|
11
|
-
|
12
|
-
def item(**attributes, &)
|
13
|
-
AccordionItem(**attributes, &)
|
14
|
-
end
|
15
|
-
|
16
|
-
def trigger(**attributes, &)
|
17
|
-
AccordionTrigger(aria_id: @aria_id, **attributes, &)
|
18
|
-
end
|
19
|
-
|
20
|
-
def content(**attributes, &)
|
21
|
-
AccordionContent(aria_id: @aria_id, **attributes, &)
|
22
|
-
end
|
23
|
-
|
24
|
-
def default_attributes
|
25
|
-
{
|
26
|
-
data: {
|
27
|
-
value: (@value || []).to_json,
|
28
|
-
multiple: @multiple.to_s,
|
29
|
-
controller: "shadcn-phlexcomponents--accordion",
|
30
|
-
},
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
def view_template(&)
|
35
|
-
div(**@attributes, &)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|