shadcn_phlexcomponents 0.1.0 → 0.1.1

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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/tailwind/choices.css +324 -0
  3. data/app/assets/tailwind/vanilla-calendar-pro.css +5 -0
  4. data/app/javascript/controllers/combobox_controller.js +19 -276
  5. data/app/javascript/controllers/date_picker_controller.js +118 -0
  6. data/app/javascript/controllers/date_range_picker_controller.js +231 -0
  7. data/app/javascript/controllers/dropdown_menu_controller.js +1 -1
  8. data/app/javascript/controllers/hover_card_controller.js +33 -126
  9. data/app/javascript/controllers/sidebar_controller.js +0 -1
  10. data/app/javascript/controllers/tooltip_controller.js +32 -126
  11. data/lib/components/accordion.rb +3 -3
  12. data/lib/components/accordion_content.rb +12 -10
  13. data/lib/components/accordion_item.rb +3 -3
  14. data/lib/components/accordion_trigger.rb +3 -3
  15. data/lib/components/alert_description.rb +1 -1
  16. data/lib/components/alert_dialog.rb +2 -2
  17. data/lib/components/alert_dialog_action.rb +2 -2
  18. data/lib/components/alert_dialog_action_to.rb +5 -2
  19. data/lib/components/alert_dialog_cancel.rb +1 -1
  20. data/lib/components/alert_dialog_content.rb +1 -1
  21. data/lib/components/alert_dialog_description.rb +1 -1
  22. data/lib/components/alert_dialog_footer.rb +1 -1
  23. data/lib/components/alert_dialog_header.rb +1 -1
  24. data/lib/components/alert_dialog_title.rb +1 -1
  25. data/lib/components/alert_dialog_trigger.rb +2 -2
  26. data/lib/components/aspect_ratio.rb +1 -1
  27. data/lib/components/avatar.rb +1 -1
  28. data/lib/components/avatar_fallback.rb +1 -1
  29. data/lib/components/avatar_image.rb +1 -2
  30. data/lib/components/badge.rb +2 -8
  31. data/lib/components/base.rb +5 -5
  32. data/lib/components/breadcrumb.rb +1 -1
  33. data/lib/components/breadcrumb_ellipsis.rb +1 -1
  34. data/lib/components/breadcrumb_item.rb +1 -1
  35. data/lib/components/breadcrumb_link.rb +1 -1
  36. data/lib/components/breadcrumb_page.rb +1 -1
  37. data/lib/components/breadcrumb_separator.rb +1 -1
  38. data/lib/components/button.rb +1 -1
  39. data/lib/components/card.rb +1 -1
  40. data/lib/components/card_content.rb +1 -1
  41. data/lib/components/card_description.rb +1 -1
  42. data/lib/components/card_footer.rb +1 -1
  43. data/lib/components/card_header.rb +1 -1
  44. data/lib/components/card_title.rb +1 -1
  45. data/lib/components/checkbox.rb +14 -10
  46. data/lib/components/checkbox_group.rb +9 -8
  47. data/lib/components/collapsible.rb +2 -3
  48. data/lib/components/collapsible_content.rb +2 -3
  49. data/lib/components/collapsible_trigger.rb +5 -5
  50. data/lib/components/combobox.rb +57 -0
  51. data/lib/components/combobox_item.rb +9 -0
  52. data/lib/components/date_picker.rb +94 -0
  53. data/lib/components/date_range_picker.rb +113 -0
  54. data/lib/components/dialog.rb +1 -1
  55. data/lib/components/dialog_close.rb +1 -1
  56. data/lib/components/dialog_content.rb +2 -2
  57. data/lib/components/dialog_description.rb +1 -1
  58. data/lib/components/dialog_footer.rb +1 -1
  59. data/lib/components/dialog_header.rb +1 -1
  60. data/lib/components/dialog_title.rb +1 -1
  61. data/lib/components/dialog_trigger.rb +2 -2
  62. data/lib/components/dropdown_menu.rb +5 -5
  63. data/lib/components/dropdown_menu_content.rb +12 -9
  64. data/lib/components/dropdown_menu_item.rb +5 -6
  65. data/lib/components/dropdown_menu_item_to.rb +6 -3
  66. data/lib/components/dropdown_menu_label.rb +2 -3
  67. data/lib/components/dropdown_menu_separator.rb +5 -5
  68. data/lib/components/dropdown_menu_trigger.rb +9 -10
  69. data/lib/components/hover_card.rb +6 -6
  70. data/lib/components/hover_card_content.rb +8 -12
  71. data/lib/components/hover_card_trigger.rb +5 -11
  72. data/lib/components/input.rb +1 -1
  73. data/lib/components/label.rb +1 -2
  74. data/lib/components/link.rb +5 -2
  75. data/lib/components/loading_button.rb +1 -1
  76. data/lib/components/pagination.rb +4 -4
  77. data/lib/components/pagination_ellipsis.rb +3 -3
  78. data/lib/components/pagination_link.rb +5 -5
  79. data/lib/components/pagination_next.rb +5 -5
  80. data/lib/components/pagination_previous.rb +4 -4
  81. data/lib/components/popover.rb +6 -7
  82. data/lib/components/popover_content.rb +13 -10
  83. data/lib/components/popover_trigger.rb +5 -6
  84. data/lib/components/progress.rb +7 -7
  85. data/lib/components/radio_group.rb +4 -4
  86. data/lib/components/radio_group_item.rb +8 -8
  87. data/lib/components/select.rb +67 -72
  88. data/lib/components/select_content.rb +12 -7
  89. data/lib/components/select_group.rb +3 -3
  90. data/lib/components/select_item.rb +9 -8
  91. data/lib/components/select_label.rb +6 -5
  92. data/lib/components/select_trigger.rb +12 -10
  93. data/lib/components/separator.rb +3 -3
  94. data/lib/components/sheet.rb +9 -9
  95. data/lib/components/sheet_close.rb +4 -4
  96. data/lib/components/sheet_content.rb +13 -15
  97. data/lib/components/sheet_description.rb +3 -3
  98. data/lib/components/sheet_footer.rb +2 -2
  99. data/lib/components/sheet_header.rb +2 -2
  100. data/lib/components/sheet_title.rb +3 -3
  101. data/lib/components/sheet_trigger.rb +6 -6
  102. data/lib/components/sidebar.rb +30 -25
  103. data/lib/components/sidebar_container.rb +1 -1
  104. data/lib/components/sidebar_content.rb +1 -1
  105. data/lib/components/sidebar_footer.rb +2 -2
  106. data/lib/components/sidebar_group.rb +1 -1
  107. data/lib/components/sidebar_group_content.rb +1 -1
  108. data/lib/components/sidebar_group_label.rb +2 -2
  109. data/lib/components/sidebar_header.rb +2 -2
  110. data/lib/components/sidebar_inset.rb +1 -1
  111. data/lib/components/sidebar_menu.rb +2 -2
  112. data/lib/components/sidebar_menu_button.rb +5 -5
  113. data/lib/components/sidebar_menu_item.rb +1 -1
  114. data/lib/components/sidebar_menu_sub.rb +2 -2
  115. data/lib/components/sidebar_menu_sub_button.rb +7 -7
  116. data/lib/components/sidebar_menu_sub_item.rb +1 -1
  117. data/lib/components/sidebar_trigger.rb +5 -5
  118. data/lib/components/skeleton.rb +2 -2
  119. data/lib/components/switch.rb +10 -9
  120. data/lib/components/table.rb +7 -5
  121. data/lib/components/table_body.rb +2 -2
  122. data/lib/components/table_caption.rb +2 -2
  123. data/lib/components/table_cell.rb +2 -2
  124. data/lib/components/table_footer.rb +2 -2
  125. data/lib/components/table_head.rb +3 -3
  126. data/lib/components/table_header.rb +2 -2
  127. data/lib/components/table_row.rb +2 -2
  128. data/lib/components/tabs.rb +3 -3
  129. data/lib/components/tabs_content.rb +5 -5
  130. data/lib/components/tabs_list.rb +4 -4
  131. data/lib/components/tabs_trigger.rb +3 -3
  132. data/lib/components/textarea.rb +1 -1
  133. data/lib/components/theme_switcher.rb +2 -2
  134. data/lib/components/toast.rb +15 -14
  135. data/lib/components/toast_action.rb +5 -4
  136. data/lib/components/toast_action_to.rb +5 -2
  137. data/lib/components/toast_container.rb +5 -5
  138. data/lib/components/toast_content.rb +1 -1
  139. data/lib/components/toast_description.rb +1 -1
  140. data/lib/components/toast_title.rb +1 -1
  141. data/lib/components/tooltip.rb +8 -8
  142. data/lib/components/tooltip_content.rb +8 -11
  143. data/lib/components/tooltip_trigger.rb +9 -11
  144. data/lib/shadcn_phlexcomponents/alias.rb +3 -1
  145. data/lib/shadcn_phlexcomponents/version.rb +1 -1
  146. metadata +9 -4
  147. data/app/javascript/controllers/datepicker_controller.js +0 -47
  148. data/lib/components/datepicker.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c58d65f96139c65cf3ae55605ec361a7eaa506df6c6bab8fdd67132fc47f50e3
4
- data.tar.gz: a5d2e0e553ec1d540f8cb9447f4155a6046ddd59fe4603bbe47c68bd0fc00878
3
+ metadata.gz: b5a7961ff2a344236185487eb3c083149bbe1bb134507a157dbd78ce0c28fafd
4
+ data.tar.gz: c9937557a99ba2f970f8ec5debe80d8fb645684f3f747d13bea75b39f78b5761
5
5
  SHA512:
6
- metadata.gz: 4d1331caf33e5bc9f84c4bd0568d3d7fcb23d59179f7ebc34b08c55a115963b43d6e330b0038de36ffea482b5128fcca48cf34b17eec9c1a1ed4563913e82478
7
- data.tar.gz: e0d13bab547ef003d9716ba3525ed2a581c0039a596660b8731c362fe76508be22a542f436998e5e7da691a1551318cecfa68fac57e4218fe665ec00b802f154
6
+ metadata.gz: 8b33c092d55a544be3aad9739c9ed6e2b9115fb880de97fc1f53cb93cc0afaff6f3eafab9b56767f24a5c2cca95fafab1622da77489144e2b8efeea65fd1265e
7
+ data.tar.gz: fdb7904d95124983ae4ea8e2139610c094ef09b4661a15f360c1df3fcd212348976c2ebc23924e847ceae8ec2396ab5a44779c2a9f119b352c4cd96f0d591988
@@ -0,0 +1,324 @@
1
+ .choices {
2
+ position: relative;
3
+ overflow: hidden;
4
+
5
+ @apply rounded-md focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-1;
6
+ }
7
+ .choices:focus {
8
+ outline: 0;
9
+ }
10
+ .choices:last-child {
11
+ margin-bottom: 0;
12
+ }
13
+ .choices.is-open {
14
+ overflow: visible;
15
+ }
16
+ .choices.is-disabled {
17
+ @apply opacity-50;
18
+ }
19
+ .choices.is-disabled .choices__inner,
20
+ .choices.is-disabled .choices__input {
21
+ @apply cursor-not-allowed select-none hover:bg-background;
22
+ }
23
+ .choices.is-disabled .choices__item {
24
+ cursor: not-allowed;
25
+ }
26
+ .choices [hidden] {
27
+ @apply hidden;
28
+ }
29
+ .choices[data-type*='select-one'] {
30
+ @apply cursor-pointer;
31
+ }
32
+ .choices[data-type*='select-one'] .choices__button {
33
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjMDAwIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==);
34
+ padding: 0;
35
+ background-size: 8px;
36
+ position: absolute;
37
+ top: 50%;
38
+ right: 0;
39
+ margin-top: -10px;
40
+ margin-right: 25px;
41
+ height: 20px;
42
+ width: 20px;
43
+ border-radius: 10em;
44
+ opacity: 0.25;
45
+ }
46
+ .choices[data-type*='select-one'] .choices__button:focus,
47
+ .choices[data-type*='select-one'] .choices__button:hover {
48
+ opacity: 1;
49
+ }
50
+ .choices[data-type*='select-one'] .choices__button:focus {
51
+ box-shadow: 0 0 0 2px #005f75;
52
+ }
53
+ .choices[data-type*='select-one']
54
+ .choices__item[data-placeholder]
55
+ .choices__button {
56
+ display: none;
57
+ }
58
+
59
+ .choices[data-type*='select-one']::after {
60
+ @apply bg-accent-foreground h-4 w-4 opacity-50 top-1/2 -translate-y-1/2 right-4;
61
+ mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevrons-up-down-icon lucide-chevrons-up-down"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>');
62
+ mask-repeat: no-repeat;
63
+ position: absolute;
64
+ content: '';
65
+ mask-size: auto 16px;
66
+ mask-position: center;
67
+ }
68
+
69
+ .choices[data-type*='select-one'][dir='rtl']::after {
70
+ left: 11.5px;
71
+ right: auto;
72
+ }
73
+ .choices[data-type*='select-one'][dir='rtl'] .choices__button {
74
+ right: auto;
75
+ left: 0;
76
+ margin-left: 25px;
77
+ margin-right: 0;
78
+ }
79
+ .choices[data-type*='select-multiple'] .choices__inner,
80
+ .choices[data-type*='text'] .choices__inner {
81
+ cursor: text;
82
+ }
83
+ .choices[data-type*='select-multiple'] .choices__button,
84
+ .choices[data-type*='text'] .choices__button {
85
+ position: relative;
86
+ display: inline-block;
87
+ margin: 0-4px 0 8px;
88
+ padding-left: 16px;
89
+ border-left: 1px solid #003642;
90
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==);
91
+ background-size: 8px;
92
+ width: 8px;
93
+ line-height: 1;
94
+ opacity: 0.75;
95
+ border-radius: 0;
96
+ }
97
+ .choices[data-type*='select-multiple'] .choices__button:focus,
98
+ .choices[data-type*='select-multiple'] .choices__button:hover,
99
+ .choices[data-type*='text'] .choices__button:focus,
100
+ .choices[data-type*='text'] .choices__button:hover {
101
+ opacity: 1;
102
+ }
103
+ .choices__inner {
104
+ @apply inline-flex items-center gap-2 whitespace-nowrap rounded-md text-sm w-full;
105
+ @apply font-medium transition-colors disabled:pointer-events-none disabled:opacity-50;
106
+ @apply [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 border border-input;
107
+ @apply bg-background shadow-sm hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2;
108
+ }
109
+
110
+ .is-focused .choices__inner,
111
+ .is-open .choices__inner {
112
+ @apply ring-ring outline-none ring-1;
113
+ }
114
+ .is-open .choices__inner {
115
+ /* border-radius: 2.5px 2.5px 0 0; */
116
+ }
117
+ .is-flipped.is-open .choices__inner {
118
+ /* border-radius: 0 0 2.5px 2.5px; */
119
+ }
120
+ .choices__list {
121
+ /* margin: 0;
122
+ padding-left: 0;
123
+ list-style: none; */
124
+ }
125
+ .choices__list--single {
126
+ /* display: inline-block;
127
+ padding: 4px 16px 4px 4px;
128
+ width: 100%; */
129
+ }
130
+ [dir='rtl'] .choices__list--single {
131
+ /* padding-right: 4px;
132
+ padding-left: 16px; */
133
+ }
134
+ .choices__list--single .choices__item {
135
+ width: 100%;
136
+ }
137
+ .choices__list--multiple {
138
+ display: inline;
139
+ }
140
+ .choices__list--multiple .choices__item {
141
+ display: inline-block;
142
+ vertical-align: middle;
143
+ border-radius: 20px;
144
+ padding: 4px 10px;
145
+ font-size: 12px;
146
+ font-weight: 500;
147
+ margin-right: 3.75px;
148
+ margin-bottom: 3.75px;
149
+ background-color: #005f75;
150
+ border: 1px solid #004a5c;
151
+ color: #fff;
152
+ word-break: break-all;
153
+ box-sizing: border-box;
154
+ }
155
+ .choices__list--multiple .choices__item[data-deletable] {
156
+ padding-right: 5px;
157
+ }
158
+ [dir='rtl'] .choices__list--multiple .choices__item {
159
+ margin-right: 0;
160
+ margin-left: 3.75px;
161
+ }
162
+ .choices__list--multiple .choices__item.is-highlighted {
163
+ background-color: #004a5c;
164
+ border: 1px solid #003642;
165
+ }
166
+ .is-disabled .choices__list--multiple .choices__item {
167
+ background-color: #aaa;
168
+ border: 1px solid #919191;
169
+ }
170
+ .choices__list--dropdown,
171
+ .choices__list[aria-expanded] {
172
+ z-index: 1;
173
+ position: absolute;
174
+ @apply hidden top-full w-full z-50 rounded-md border bg-popover text-popover-foreground shadow-md;
175
+ @apply mt-2 outline-none animate-in fade-in-0
176
+ zoom-in-95 slide-in-from-top-2;
177
+ }
178
+ .is-active.choices__list--dropdown,
179
+ .is-active.choices__list[aria-expanded] {
180
+ display: block;
181
+ }
182
+
183
+ .is-flipped .choices__list--dropdown,
184
+ .is-flipped .choices__list[aria-expanded] {
185
+ top: auto;
186
+ bottom: 100%;
187
+ margin-top: 0;
188
+ margin-bottom: -1px;
189
+ border-radius: 0.25rem 0.25rem 0 0;
190
+ }
191
+
192
+ .choices__list--dropdown .choices__list,
193
+ .choices__list[aria-expanded] .choices__list {
194
+ @apply relative max-h-80 overflow-auto p-1 text-foreground;
195
+ -webkit-overflow-scrolling: touch;
196
+ will-change: scroll-position;
197
+ }
198
+ .choices__list--dropdown .choices__item,
199
+ .choices__list[aria-expanded] .choices__item {
200
+ @apply relative flex cursor-default gap-2 select-none items-center rounded-sm min-h-8;
201
+ @apply px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none;
202
+ @apply data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground;
203
+ @apply data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0;
204
+ }
205
+
206
+ .choices__list--dropdown .choices__item.is-selected::after {
207
+ @apply bg-accent-foreground h-4 w-4 top-1/2 -translate-y-1/2 right-2;
208
+ mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check-icon lucide-check"><path d="M20 6 9 17l-5-5"/></svg>');
209
+ mask-repeat: no-repeat;
210
+ position: absolute;
211
+ content: '';
212
+ mask-size: auto 16px;
213
+ mask-position: center;
214
+ }
215
+
216
+ [dir='rtl'] .choices__list--dropdown .choices__item,
217
+ [dir='rtl'] .choices__list[aria-expanded] .choices__item {
218
+ text-align: right;
219
+ }
220
+ @media (min-width: 640px) {
221
+ .choices__list--dropdown .choices__item--selectable[data-select-text],
222
+ .choices__list[aria-expanded] .choices__item--selectable[data-select-text] {
223
+ padding-right: 100px;
224
+ }
225
+ .choices__list--dropdown .choices__item--selectable[data-select-text]::after,
226
+ .choices__list[aria-expanded]
227
+ .choices__item--selectable[data-select-text]::after {
228
+ content: attr(data-select-text);
229
+ font-size: 12px;
230
+ opacity: 0;
231
+ position: absolute;
232
+ right: 10px;
233
+ top: 50%;
234
+ transform: translateY(-50%);
235
+ }
236
+ [dir='rtl']
237
+ .choices__list--dropdown
238
+ .choices__item--selectable[data-select-text],
239
+ [dir='rtl']
240
+ .choices__list[aria-expanded]
241
+ .choices__item--selectable[data-select-text] {
242
+ text-align: right;
243
+ padding-left: 100px;
244
+ padding-right: 10px;
245
+ }
246
+ [dir='rtl']
247
+ .choices__list--dropdown
248
+ .choices__item--selectable[data-select-text]::after,
249
+ [dir='rtl']
250
+ .choices__list[aria-expanded]
251
+ .choices__item--selectable[data-select-text]::after {
252
+ right: auto;
253
+ left: 10px;
254
+ }
255
+ }
256
+ .choices__list--dropdown .choices__item--selectable.is-highlighted,
257
+ .choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
258
+ @apply bg-accent data-[selected=true]:text-accent-foreground;
259
+ }
260
+ .choices__list--dropdown .choices__item--selectable.is-highlighted::after,
261
+ /* .choices__list[aria-expanded] .choices__item--selectable.is-highlighted::after {
262
+ opacity: 0.5;
263
+ } */
264
+ .choices__item {
265
+ cursor: default;
266
+ }
267
+ .choices__item--selectable {
268
+ cursor: pointer;
269
+ }
270
+ .choices__item--disabled {
271
+ cursor: not-allowed;
272
+ -webkit-user-select: none;
273
+ user-select: none;
274
+ opacity: 0.5;
275
+ }
276
+ .choices__heading {
277
+ @apply px-2 py-1.5 text-sm font-bold;
278
+ }
279
+
280
+ .choices__button {
281
+ text-indent: -9999px;
282
+ appearance: none;
283
+ border: 0;
284
+ background-color: transparent;
285
+ background-repeat: no-repeat;
286
+ background-position: center;
287
+ cursor: pointer;
288
+ }
289
+ .choices__button:focus,
290
+ .choices__input:focus {
291
+ outline: 0;
292
+ }
293
+ .choices__input {
294
+ @apply flex w-full rounded-md bg-transparent p-3 text-sm outline-none;
295
+ @apply placeholder:text-muted-foreground h-9 border-b;
296
+ }
297
+ .choices__input::-webkit-search-cancel-button,
298
+ .choices__input::-webkit-search-decoration,
299
+ .choices__input::-webkit-search-results-button,
300
+ .choices__input::-webkit-search-results-decoration {
301
+ display: none;
302
+ }
303
+ .choices__input::-ms-clear,
304
+ .choices__input::-ms-reveal {
305
+ display: none;
306
+ width: 0;
307
+ height: 0;
308
+ }
309
+ [dir='rtl'] .choices__input {
310
+ padding-right: 2px;
311
+ padding-left: 0;
312
+ }
313
+
314
+ .choices__item[data-value='']::after {
315
+ @apply hidden;
316
+ }
317
+
318
+ .choices__placeholder {
319
+ @apply text-muted-foreground;
320
+ }
321
+
322
+ .choices__item.has-no-results {
323
+ @apply text-muted-foreground;
324
+ }
@@ -1,6 +1,11 @@
1
1
  /* Layout */
2
2
  [data-vc='calendar'] {
3
3
  @apply relative border box-border min-w-[272px] flex flex-col p-3 rounded-xl opacity-100 transition-opacity;
4
+ @apply animate-in fade-in-0 zoom-out-95 slide-in-from-top-2 w-[278px] sm:w-auto;
5
+ }
6
+
7
+ [data-vc='calendar'][data-vc-calendar-hidden] {
8
+ @apply animate-out fade-out-0 zoom-out-95;
4
9
  }
5
10
 
6
11
  [data-vc='calendar']:focus-visible,
@@ -1,291 +1,34 @@
1
1
  import { Controller } from '@hotwired/stimulus'
2
- import {
3
- computePosition,
4
- flip,
5
- shift,
6
- offset,
7
- autoUpdate,
8
- } from '@floating-ui/dom'
9
-
2
+ import Choices from 'choices.js'
10
3
  export default class extends Controller {
11
- static targets = [
12
- 'trigger',
13
- 'contentWrapper',
14
- 'content',
15
- 'item',
16
- 'triggerText',
17
- 'itemCheckIcon',
18
- 'select',
19
- 'searchInput',
20
- ]
21
-
22
- static values = {
23
- selected: String,
24
- }
4
+ static targets = ['select']
25
5
 
26
6
  connect() {
27
- this.contentTarget.dataset.state = this.isOpen() ? 'open' : 'closed'
28
- this.clickOutsideListener = this.onClickOutside.bind(this)
29
- this.comboboxKeydownListener = this.onComboboxKeydown.bind(this)
30
- this.searchInputKeydownListener = this.debounce(
31
- this.onSearchInputKeydown.bind(this),
32
- 100,
33
- )
34
-
35
- this.items = [
36
- ...this.element.querySelectorAll(
37
- '[data-shadcn-phlexcomponents--combobox-target="item"]:not([data-disabled])',
38
- ),
39
- ]
40
- }
41
-
42
- // Methods
43
- toggle() {
44
- if (this.isOpen()) {
45
- this.close()
46
- } else {
47
- this.open()
48
- }
49
- }
50
-
51
- open() {
52
- const triggerWidth = this.triggerTarget.offsetWidth
53
- this.contentWrapperTarget.classList.remove('hidden')
54
-
55
- const contentWrapperWidth = this.contentWrapperTarget.offsetWidth
56
-
57
- if (contentWrapperWidth < triggerWidth) {
58
- this.contentWrapperTarget.style.width = `${triggerWidth}px`
59
- }
60
-
61
- this.searchInputTarget.focus()
62
-
63
- if (this.selectedValue) {
64
- const item = this.itemTargets.find(
65
- (i) => i.dataset.value === this.selectedValue,
7
+ if (this.element.dataset.value) {
8
+ const option = this.selectTarget.querySelector(
9
+ `[value=${this.element.dataset.value}]`,
66
10
  )
67
- const index = this.items.indexOf(item)
68
- if (index > -1) {
69
- this.highlightItem(index)
70
- }
71
- } else {
72
- this.highlightItem(0)
73
- }
74
11
 
75
- this.triggerTarget.ariaExpanded = true
76
- this.contentTarget.dataset.state = 'open'
77
-
78
- if (window.innerHeight < document.documentElement.scrollHeight) {
79
- document.body.dataset.scrollLocked = 1
80
- }
81
- this.setupEventListeners()
82
-
83
- this.cleanup = autoUpdate(
84
- this.triggerTarget,
85
- this.contentWrapperTarget,
86
- () => {
87
- computePosition(this.triggerTarget, this.contentWrapperTarget, {
88
- placement: 'bottom',
89
- strategy: 'fixed',
90
- middleware: [flip(), shift(), offset(4)],
91
- }).then(({ x, y }) => {
92
- Object.assign(this.contentWrapperTarget.style, {
93
- left: `${x}px`,
94
- top: `${y}px`,
95
- })
96
- })
97
- },
98
- )
99
- }
100
-
101
- close() {
102
- this.contentTarget.dataset.state = 'closed'
103
- this.triggerTarget.ariaExpanded = false
104
- this.cleanup()
105
- this.cleanupEventListeners()
106
- delete document.body.dataset.scrollLocked
107
-
108
- setTimeout(() => {
109
- this.contentWrapperTarget.classList.add('hidden')
110
- }, 100)
111
-
112
- if (this.triggerTarget.nodeName === 'DIV') {
113
- this.triggerTarget.firstElementChild.focus()
114
- } else {
115
- this.triggerTarget.focus()
12
+ if (option) {
13
+ option.selected = true
14
+ }
116
15
  }
117
- }
118
16
 
119
- isOpen() {
120
- return this.triggerTarget.ariaExpanded === 'true'
121
- }
122
-
123
- highlightItem(selectedIndex) {
124
- const item = this.items[selectedIndex]
125
- console.log('this.highlightItem', item)
126
- item.dataset.selected = true
127
-
128
- this.items.forEach((item, index) => {
129
- if (index !== selectedIndex) item.dataset.selected = false
17
+ this.choices = new Choices(this.selectTarget, {
18
+ itemSelectText: '',
19
+ placeholderValue: this.element.dataset.placeholder,
130
20
  })
131
- }
132
-
133
- currentHighlightedIndex() {
134
- console.log('item')
135
- const item = this.items.find((i) => i.dataset.selected === 'true')
136
- return this.items.indexOf(item)
137
- console.log('item', item)
138
-
139
- // if (item) {
140
- // return this.items.indexOf(item)
141
- // }
142
-
143
- // return 0
144
- }
145
-
146
- debounce(callback, wait) {
147
- let timeoutId = null
148
- return (...args) => {
149
- window.clearTimeout(timeoutId)
150
- timeoutId = window.setTimeout(() => {
151
- callback.apply(null, args)
152
- }, wait)
153
- }
154
- }
155
-
156
- onSearchInputKeydown(event) {
157
- // console.log('search ecet', event)
158
- this.filterItems()
159
- }
160
-
161
- onArrowUpKeydown(event) {
162
- const index = this.currentHighlightedIndex()
163
- console.log('onArrowUpKeydown index', index)
164
-
165
- if (index > 0) {
166
- this.highlightItem(index - 1)
167
- }
168
21
 
169
- event.preventDefault()
170
- }
171
-
172
- onArrowDownKeydown(event) {
173
- const index = this.currentHighlightedIndex()
174
-
175
- console.log('onArrowDownKeydown index', index)
176
-
177
- console.log('index + 1 < this.items.length', index + 1 < this.items.length)
178
- if (index + 1 < this.items.length) {
179
- this.highlightItem(index + 1)
22
+ if (this.element.dataset.includeBlank === 'false') {
23
+ this.choices.removeChoice('')
180
24
  }
181
25
 
182
- event.preventDefault()
183
- }
184
-
185
- selectItem(event) {
186
- const index = this.currentHighlightedIndex()
187
- const item = this.items[index]
188
- item.click()
189
- event.preventDefault()
190
- }
191
-
192
- filterItems = () => {
193
- const search = this.searchInputTarget.value
194
- const filteredItems = this.items.filter((i) =>
195
- i.innerText.toLowerCase().includes(search),
26
+ this.selectTarget.addEventListener(
27
+ 'hideDropdown',
28
+ function () {
29
+ this.choices.containerOuter.element.focus()
30
+ }.bind(this),
31
+ false,
196
32
  )
197
-
198
- this.items.forEach((i) => {
199
- if (filteredItems.includes(i)) {
200
- i.classList.remove('hidden')
201
- } else {
202
- i.classList.add('hidden')
203
- }
204
- })
205
-
206
- this.highlightItem(this.filterItems[0])
207
- }
208
-
209
- onItemClick(event) {
210
- const item = event.currentTarget
211
- const value = item.dataset.value
212
- this.selectedValue = value
213
- this.close()
214
- }
215
-
216
- onMouseOver(event) {
217
- const item = event.currentTarget
218
- const index = this.items.indexOf(item)
219
- this.highlightItem(index)
220
- }
221
-
222
- selectedValueChanged(value) {
223
- const item = this.itemTargets.find((i) => i.dataset.value === value)
224
-
225
- this.itemCheckIconTargets.forEach((i) => {
226
- i.classList.add('hidden')
227
- })
228
-
229
- if (item) {
230
- this.triggerTextTarget.innerText = item.innerText
231
-
232
- const checkIcon = item.querySelector(
233
- '[data-shadcn-phlexcomponents--combobox-target="itemCheckIcon"]',
234
- )
235
- if (value.length > 0) checkIcon.classList.remove('hidden')
236
-
237
- this.itemTargets.forEach((i) => {
238
- if (i.dataset.value === value) {
239
- i.setAttribute('aria-selected', 'true')
240
- } else {
241
- i.setAttribute('aria-selected', 'false')
242
- }
243
- })
244
-
245
- this.selectTarget.value = value
246
- }
247
-
248
- delete this.triggerTarget.dataset.placeholder
249
- const hasPlaceholder = this.triggerTarget.dataset.placeholderText
250
-
251
- if (hasPlaceholder) {
252
- if (!value || value.length === 0) {
253
- this.triggerTarget.dataset.placeholder = true
254
- this.triggerTextTarget.innerText = hasPlaceholder
255
- }
256
- }
257
- }
258
-
259
- // Global listeners
260
- onClickOutside(event) {
261
- const htmlFor = event.target.htmlFor
262
-
263
- if (htmlFor === this.triggerTarget.id) return
264
- if (event.target) if (this.element.contains(event.target)) return
265
-
266
- this.close()
267
- }
268
-
269
- onComboboxKeydown(event) {
270
- if (!this.isOpen()) return
271
-
272
- const key = event.key
273
- if (key === 'Tab') event.preventDefault()
274
-
275
- if (key === 'Escape') {
276
- this.close()
277
- }
278
- }
279
-
280
- setupEventListeners() {
281
- document.addEventListener('click', this.clickOutsideListener)
282
- document.addEventListener('keydown', this.comboboxKeydownListener)
283
- document.addEventListener('keydown', this.searchInputKeydownListener)
284
- }
285
-
286
- cleanupEventListeners() {
287
- document.removeEventListener('click', this.clickOutsideListener)
288
- document.removeEventListener('keydown', this.comboboxKeydownListener)
289
- document.removeEventListener('keydown', this.searchInputKeydownListener)
290
33
  }
291
34
  }