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,157 +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--alert-dialog-target="trigger"]',
|
97
|
-
)
|
98
|
-
|
99
|
-
if (trigger) return
|
100
|
-
|
101
|
-
const close = target.closest(
|
102
|
-
'[data-action*="shadcn-phlexcomponents--alert-dialog#close"]',
|
103
|
-
)
|
104
|
-
|
105
|
-
if (
|
106
|
-
close ||
|
107
|
-
(target.dataset.action &&
|
108
|
-
target.dataset.action.includes(
|
109
|
-
'shadcn-phlexcomponents--alert-dialog#close',
|
110
|
-
))
|
111
|
-
)
|
112
|
-
this.close()
|
113
|
-
}
|
114
|
-
|
115
|
-
onDOMKeydown(event) {
|
116
|
-
if (!this.isOpen()) return
|
117
|
-
|
118
|
-
const key = event.key
|
119
|
-
|
120
|
-
if (key === 'Escape') {
|
121
|
-
this.close()
|
122
|
-
} else if (key === 'Tab') {
|
123
|
-
// If Shift + Tab pressed on first element, go to last element
|
124
|
-
if (event.shiftKey && document.activeElement === this.firstElement) {
|
125
|
-
event.preventDefault()
|
126
|
-
this.lastElement.focus()
|
127
|
-
}
|
128
|
-
// If Tab pressed on last element, go to first element
|
129
|
-
else if (!event.shiftKey && document.activeElement === this.lastElement) {
|
130
|
-
event.preventDefault()
|
131
|
-
this.firstElement.focus()
|
132
|
-
}
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
setupEventListeners() {
|
137
|
-
document.addEventListener('click', this.DOMClickListener)
|
138
|
-
document.addEventListener('keydown', this.DOMKeydownListener)
|
139
|
-
}
|
140
|
-
|
141
|
-
cleanupEventListeners() {
|
142
|
-
document.removeEventListener('click', this.DOMClickListener)
|
143
|
-
document.removeEventListener('keydown', this.DOMKeydownListener)
|
144
|
-
}
|
145
|
-
|
146
|
-
addInert() {
|
147
|
-
Array.from(document.body.children)
|
148
|
-
.filter((el) => el !== this.contentElement)
|
149
|
-
.forEach((el) => el.setAttribute('inert', ''))
|
150
|
-
}
|
151
|
-
|
152
|
-
removeInert() {
|
153
|
-
Array.from(document.body.children)
|
154
|
-
.filter((el) => el.hasAttribute('inert'))
|
155
|
-
.forEach((el) => el.removeAttribute('inert'))
|
156
|
-
}
|
157
|
-
}
|
@@ -1,28 +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
|
-
preventDefault(event) {
|
14
|
-
event.preventDefault()
|
15
|
-
}
|
16
|
-
|
17
|
-
checkedValueChanged(value) {
|
18
|
-
if (value === true) {
|
19
|
-
this.element.ariaChecked = true
|
20
|
-
this.element.dataset.checked = true
|
21
|
-
this.inputTarget.checked = true
|
22
|
-
} else {
|
23
|
-
this.element.ariaChecked = false
|
24
|
-
this.element.dataset.checked = false
|
25
|
-
this.inputTarget.checked = false
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['trigger', 'content', 'item']
|
5
|
-
|
6
|
-
connect() {
|
7
|
-
if (this.isOpen()) {
|
8
|
-
this.open()
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
|
-
toggle() {
|
13
|
-
if (this.isOpen()) {
|
14
|
-
this.close()
|
15
|
-
} else {
|
16
|
-
this.open()
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
isOpen() {
|
21
|
-
return this.triggerTarget.ariaExpanded === 'true'
|
22
|
-
}
|
23
|
-
|
24
|
-
open() {
|
25
|
-
this.triggerTarget.ariaExpanded = true
|
26
|
-
this.triggerTarget.dataset.state = 'open'
|
27
|
-
this.contentTarget.classList.remove('hidden')
|
28
|
-
}
|
29
|
-
|
30
|
-
close() {
|
31
|
-
this.triggerTarget.ariaExpanded = false
|
32
|
-
this.triggerTarget.dataset.state = 'closed'
|
33
|
-
this.contentTarget.classList.add('hidden')
|
34
|
-
}
|
35
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
import Choices from 'choices.js'
|
3
|
-
export default class extends Controller {
|
4
|
-
static targets = ['select']
|
5
|
-
|
6
|
-
connect() {
|
7
|
-
if (this.element.dataset.value) {
|
8
|
-
const option = this.selectTarget.querySelector(
|
9
|
-
`[value=${this.element.dataset.value}]`,
|
10
|
-
)
|
11
|
-
|
12
|
-
if (option) {
|
13
|
-
option.selected = true
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
this.choices = new Choices(this.selectTarget, {
|
18
|
-
itemSelectText: '',
|
19
|
-
placeholderValue: this.element.dataset.placeholder,
|
20
|
-
})
|
21
|
-
|
22
|
-
if (this.element.dataset.includeBlank === 'false') {
|
23
|
-
this.choices.removeChoice('')
|
24
|
-
}
|
25
|
-
|
26
|
-
this.selectTarget.addEventListener(
|
27
|
-
'hideDropdown',
|
28
|
-
function () {
|
29
|
-
this.choices.containerOuter.element.focus()
|
30
|
-
}.bind(this),
|
31
|
-
false,
|
32
|
-
)
|
33
|
-
}
|
34
|
-
}
|
@@ -1,118 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
import { Calendar } from 'vanilla-calendar-pro'
|
3
|
-
import dayjs from 'dayjs'
|
4
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
5
|
-
import utc from 'dayjs/plugin/utc'
|
6
|
-
dayjs.extend(customParseFormat)
|
7
|
-
dayjs.extend(utc)
|
8
|
-
|
9
|
-
export default class extends Controller {
|
10
|
-
static targets = ['dateInput', 'hiddenInput', 'clearButton', 'calendarIcon']
|
11
|
-
|
12
|
-
connect() {
|
13
|
-
this.date = this.element.dataset.value
|
14
|
-
this.format = this.element.dataset.format
|
15
|
-
const settings = this.getSettings()
|
16
|
-
settings.type = 'default'
|
17
|
-
|
18
|
-
if (this.date && dayjs(this.date).isValid()) {
|
19
|
-
const dayjsDate = dayjs(this.date)
|
20
|
-
const formattedDate = dayjsDate.format(this.format)
|
21
|
-
this.dateInputTarget.value = formattedDate
|
22
|
-
settings.selectedDates = [dayjsDate.format('YYYY-MM-DD')]
|
23
|
-
}
|
24
|
-
|
25
|
-
const calendar = new Calendar(this.dateInputTarget, {
|
26
|
-
inputMode: true,
|
27
|
-
enableJumpToSelectedDate: true,
|
28
|
-
...settings,
|
29
|
-
onClickDate(self, event) {
|
30
|
-
const date = self.context.selectedDates[0]
|
31
|
-
|
32
|
-
const controllerElement = self.context.inputElement.closest(
|
33
|
-
'[data-controller="shadcn-phlexcomponents--date-picker"]',
|
34
|
-
)
|
35
|
-
|
36
|
-
const hiddenInput = controllerElement.querySelector(
|
37
|
-
'[data-shadcn-phlexcomponents--date-picker-target="hiddenInput"]',
|
38
|
-
)
|
39
|
-
|
40
|
-
if (date) {
|
41
|
-
const formattedDate = dayjs(date).format(
|
42
|
-
controllerElement.dataset.format,
|
43
|
-
)
|
44
|
-
self.context.inputElement.value = formattedDate
|
45
|
-
controllerElement.dataset.hasValue = 'true'
|
46
|
-
const utcDate = dayjs(date).utc().format()
|
47
|
-
hiddenInput.value = utcDate
|
48
|
-
} else {
|
49
|
-
self.context.inputElement.value = ''
|
50
|
-
controllerElement.dataset.hasValue = 'false'
|
51
|
-
hiddenInput.value = ''
|
52
|
-
}
|
53
|
-
},
|
54
|
-
})
|
55
|
-
calendar.init()
|
56
|
-
|
57
|
-
this.calendar = calendar
|
58
|
-
}
|
59
|
-
|
60
|
-
inputBlur() {
|
61
|
-
const date = this.calendar.selectedDates[0]
|
62
|
-
|
63
|
-
if (date) {
|
64
|
-
const formattedDate = dayjs(date).format(this.format)
|
65
|
-
this.dateInputTarget.value = formattedDate
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
changeDate(event) {
|
70
|
-
const value = event.target.value
|
71
|
-
|
72
|
-
if (value.length > 0 && dayjs(value, this.format, true).isValid()) {
|
73
|
-
const dayjsDate = dayjs(value, this.format)
|
74
|
-
this.calendar.set({
|
75
|
-
selectedDates: [dayjsDate.format('YYYY-MM-DD')],
|
76
|
-
})
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
closeCalendar(event) {
|
81
|
-
const key = event.key
|
82
|
-
|
83
|
-
if (key === 'Escape' || key === 'Tab') {
|
84
|
-
this.calendar.hide()
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
clear() {
|
89
|
-
this.dateInputTarget.value = ''
|
90
|
-
this.hiddenInputTarget.value = ''
|
91
|
-
|
92
|
-
this.calendar.set({
|
93
|
-
selectedDates: [],
|
94
|
-
})
|
95
|
-
|
96
|
-
this.element.dataset.hasValue = 'false'
|
97
|
-
}
|
98
|
-
|
99
|
-
showClearButton() {
|
100
|
-
if (this.element.dataset.hasValue === 'true') {
|
101
|
-
this.clearButtonTarget.classList.remove('!hidden')
|
102
|
-
this.calendarIconTarget.classList.add('hidden')
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
hideClearButton() {
|
107
|
-
this.clearButtonTarget.classList.add('!hidden')
|
108
|
-
this.calendarIconTarget.classList.remove('hidden')
|
109
|
-
}
|
110
|
-
|
111
|
-
getSettings() {
|
112
|
-
try {
|
113
|
-
return JSON.parse(this.element.dataset.settings)
|
114
|
-
} catch {
|
115
|
-
return {}
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
@@ -1,231 +0,0 @@
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
2
|
-
import { Calendar } from 'vanilla-calendar-pro'
|
3
|
-
import dayjs from 'dayjs'
|
4
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
5
|
-
import utc from 'dayjs/plugin/utc'
|
6
|
-
dayjs.extend(customParseFormat)
|
7
|
-
dayjs.extend(utc)
|
8
|
-
|
9
|
-
// window.dayjs = dayjs
|
10
|
-
export default class extends Controller {
|
11
|
-
static targets = [
|
12
|
-
'startDateInput',
|
13
|
-
'endDateInput',
|
14
|
-
'startDateHiddenInput',
|
15
|
-
'endDateHiddenInput',
|
16
|
-
'clearButton',
|
17
|
-
'calendarIcon',
|
18
|
-
]
|
19
|
-
|
20
|
-
connect() {
|
21
|
-
this.startDate = this.element.dataset.startDate
|
22
|
-
this.endDate = this.element.dataset.endDate
|
23
|
-
this.format = this.element.dataset.format
|
24
|
-
this.type = this.element.dataset.type
|
25
|
-
const settings = this.getSettings()
|
26
|
-
settings.type = 'multiple'
|
27
|
-
settings.selectionDatesMode = 'multiple-ranged'
|
28
|
-
settings.displayMonthsCount = 2
|
29
|
-
settings.monthsToSwitch = 1
|
30
|
-
settings.displayDatesOutside = false
|
31
|
-
|
32
|
-
if (this.startDate && dayjs(this.startDate).isValid()) {
|
33
|
-
const dayjsDate = dayjs(this.startDate)
|
34
|
-
const formattedDate = dayjsDate.format(this.format)
|
35
|
-
this.startDateInputTarget.value = formattedDate
|
36
|
-
settings.selectedDates = [dayjsDate.format('YYYY-MM-DD')]
|
37
|
-
}
|
38
|
-
|
39
|
-
if (this.endDate && dayjs(this.endDate).isValid()) {
|
40
|
-
const dayjsDate = dayjs(this.endDate)
|
41
|
-
const formattedDate = dayjsDate.format(this.format)
|
42
|
-
this.endDateInputTarget.value = formattedDate
|
43
|
-
settings.selectedDates = [
|
44
|
-
...settings.selectedDates,
|
45
|
-
dayjsDate.format('YYYY-MM-DD'),
|
46
|
-
]
|
47
|
-
}
|
48
|
-
|
49
|
-
const calendar = new Calendar(this.element, {
|
50
|
-
inputMode: true,
|
51
|
-
enableJumpToSelectedDate: true,
|
52
|
-
...settings,
|
53
|
-
onShow(self) {
|
54
|
-
const controllerElement = self.context.inputElement
|
55
|
-
|
56
|
-
const startDateInput = controllerElement.querySelector(
|
57
|
-
'[data-shadcn-phlexcomponents--date-range-picker-target="startDateInput"]',
|
58
|
-
)
|
59
|
-
|
60
|
-
const endDateInput = controllerElement.querySelector(
|
61
|
-
'[data-shadcn-phlexcomponents--date-range-picker-target="endDateInput"]',
|
62
|
-
)
|
63
|
-
|
64
|
-
controllerElement.dataset.focus = 'true'
|
65
|
-
if (document.activeElement !== endDateInput) {
|
66
|
-
startDateInput.focus()
|
67
|
-
}
|
68
|
-
},
|
69
|
-
onHide(self) {
|
70
|
-
const controllerElement = self.context.inputElement
|
71
|
-
controllerElement.dataset.focus = 'false'
|
72
|
-
},
|
73
|
-
onClickDate(self, event) {
|
74
|
-
const dates = self.context.selectedDates.filter((date) => !!date)
|
75
|
-
const controllerElement = self.context.inputElement
|
76
|
-
|
77
|
-
const startDateInput = controllerElement.querySelector(
|
78
|
-
'[data-shadcn-phlexcomponents--date-range-picker-target="startDateInput"]',
|
79
|
-
)
|
80
|
-
|
81
|
-
const endDateInput = controllerElement.querySelector(
|
82
|
-
'[data-shadcn-phlexcomponents--date-range-picker-target="endDateInput"]',
|
83
|
-
)
|
84
|
-
|
85
|
-
const startDateHiddenInput = controllerElement.querySelector(
|
86
|
-
'[data-shadcn-phlexcomponents--date-range-picker-target="startDateHiddenInput"]',
|
87
|
-
)
|
88
|
-
|
89
|
-
const endDateHiddenInput = controllerElement.querySelector(
|
90
|
-
'[data-shadcn-phlexcomponents--date-range-picker-target="endDateHiddenInput"]',
|
91
|
-
)
|
92
|
-
|
93
|
-
if (dates.length > 0) {
|
94
|
-
const startDate = dates[0]
|
95
|
-
const endDate = dates[1]
|
96
|
-
|
97
|
-
const formattedStartDate = dayjs(startDate).format(
|
98
|
-
controllerElement.dataset.format,
|
99
|
-
)
|
100
|
-
startDateInput.value = formattedStartDate
|
101
|
-
controllerElement.dataset.hasValue = 'true'
|
102
|
-
const utcStartDate = dayjs(startDate).utc().format()
|
103
|
-
startDateHiddenInput.value = utcStartDate
|
104
|
-
|
105
|
-
if (endDate) {
|
106
|
-
const formattedEndDate = dayjs(endDate).format(
|
107
|
-
controllerElement.dataset.format,
|
108
|
-
)
|
109
|
-
endDateInput.value = formattedEndDate
|
110
|
-
const utcEndDate = dayjs(endDate).utc().format()
|
111
|
-
endDateHiddenInput.value = utcEndDate
|
112
|
-
} else {
|
113
|
-
endDateInput.value = ''
|
114
|
-
endDateHiddenInput.value = ''
|
115
|
-
}
|
116
|
-
} else {
|
117
|
-
self.context.inputElement.value = ''
|
118
|
-
endDateInput.value = ''
|
119
|
-
controllerElement.dataset.hasValue = 'false'
|
120
|
-
startDateHiddenInput.value = ''
|
121
|
-
endDateHiddenInput.value = ''
|
122
|
-
}
|
123
|
-
},
|
124
|
-
})
|
125
|
-
calendar.init()
|
126
|
-
|
127
|
-
this.calendar = calendar
|
128
|
-
}
|
129
|
-
|
130
|
-
openCalendar(event) {
|
131
|
-
this.calendar.show()
|
132
|
-
}
|
133
|
-
|
134
|
-
closeCalendar(event) {
|
135
|
-
const key = event.key
|
136
|
-
|
137
|
-
switch (key) {
|
138
|
-
case 'Tab':
|
139
|
-
if (
|
140
|
-
event.target.dataset[
|
141
|
-
'shadcnPhlexcomponents-DateRangePickerTarget'
|
142
|
-
] === 'startDateInput'
|
143
|
-
) {
|
144
|
-
if (event.shiftKey) {
|
145
|
-
this.calendar.hide()
|
146
|
-
}
|
147
|
-
} else {
|
148
|
-
if (!event.shiftKey) {
|
149
|
-
this.calendar.hide()
|
150
|
-
}
|
151
|
-
}
|
152
|
-
|
153
|
-
break
|
154
|
-
case 'Escape':
|
155
|
-
this.calendar.hide()
|
156
|
-
break
|
157
|
-
default:
|
158
|
-
break
|
159
|
-
}
|
160
|
-
}
|
161
|
-
|
162
|
-
changeDate(event) {
|
163
|
-
const value = event.target.value
|
164
|
-
const dates = this.calendar.selectedDates.filter((date) => !!date)
|
165
|
-
|
166
|
-
if (
|
167
|
-
event.target.dataset['shadcnPhlexcomponents-DateRangePickerTarget'] ===
|
168
|
-
'startDateInput'
|
169
|
-
) {
|
170
|
-
if (dayjs(value, this.format, true).isValid()) {
|
171
|
-
const dayjsDate = dayjs(value, this.format)
|
172
|
-
dates[0] = dayjsDate.format('YYYY-MM-DD')
|
173
|
-
|
174
|
-
this.calendar.set({
|
175
|
-
selectedDates: dates,
|
176
|
-
})
|
177
|
-
this.element.dataset.hasValue = 'true'
|
178
|
-
}
|
179
|
-
} else {
|
180
|
-
if (dayjs(value, this.format, true).isValid()) {
|
181
|
-
const dayjsDate = dayjs(value, this.format)
|
182
|
-
dates[1] = dayjsDate.format('YYYY-MM-DD')
|
183
|
-
|
184
|
-
this.calendar.set({
|
185
|
-
selectedDates: dates,
|
186
|
-
})
|
187
|
-
this.element.dataset.hasValue = 'true'
|
188
|
-
}
|
189
|
-
}
|
190
|
-
}
|
191
|
-
|
192
|
-
openCalendar() {
|
193
|
-
setTimeout(() => {
|
194
|
-
this.calendar.show()
|
195
|
-
}, 125)
|
196
|
-
}
|
197
|
-
|
198
|
-
clear() {
|
199
|
-
this.startDateInputTarget.value = ''
|
200
|
-
|
201
|
-
if (this.hasEndDateInputTarget) {
|
202
|
-
this.endDateInputTarget.value = ''
|
203
|
-
}
|
204
|
-
|
205
|
-
this.calendar.set({
|
206
|
-
selectedDates: [],
|
207
|
-
})
|
208
|
-
|
209
|
-
this.element.dataset.hasValue = 'false'
|
210
|
-
}
|
211
|
-
|
212
|
-
showClearButton() {
|
213
|
-
if (this.element.dataset.hasValue === 'true') {
|
214
|
-
this.clearButtonTarget.classList.remove('!hidden')
|
215
|
-
this.calendarIconTarget.classList.add('hidden')
|
216
|
-
}
|
217
|
-
}
|
218
|
-
|
219
|
-
hideClearButton() {
|
220
|
-
this.clearButtonTarget.classList.add('!hidden')
|
221
|
-
this.calendarIconTarget.classList.remove('hidden')
|
222
|
-
}
|
223
|
-
|
224
|
-
getSettings() {
|
225
|
-
try {
|
226
|
-
return JSON.parse(this.element.dataset.settings)
|
227
|
-
} catch {
|
228
|
-
return {}
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|