shadcn-rails 0.1.0
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 +7 -0
- data/.dockerignore +40 -0
- data/CHANGELOG.md +54 -0
- data/CLAUDE.md +463 -0
- data/PROGRESS.md +485 -0
- data/README.md +1483 -0
- data/Rakefile +29 -0
- data/__tests__/controllers/__snapshots__/calendar_controller.test.js.snap +13 -0
- data/__tests__/controllers/__snapshots__/popover_controller.test.js.snap +46 -0
- data/__tests__/controllers/__snapshots__/sheet_controller.test.js.snap +111 -0
- data/__tests__/controllers/__snapshots__/tabs_controller.test.js.snap +27 -0
- data/__tests__/controllers/accordion_controller.test.js +904 -0
- data/__tests__/controllers/calendar_controller.test.js +1370 -0
- data/__tests__/controllers/carousel_controller.test.js +912 -0
- data/__tests__/controllers/checkbox_controller.test.js +454 -0
- data/__tests__/controllers/collapsible_controller.test.js +407 -0
- data/__tests__/controllers/combobox_controller.test.js +966 -0
- data/__tests__/controllers/context_menu_controller.test.js +627 -0
- data/__tests__/controllers/date_picker_controller.test.js +636 -0
- data/__tests__/controllers/dialog_controller.test.js +878 -0
- data/__tests__/controllers/drawer_controller.test.js +995 -0
- data/__tests__/controllers/menubar_controller.test.js +736 -0
- data/__tests__/controllers/navigation_menu_controller.test.js +598 -0
- data/__tests__/controllers/popover_controller.test.js +1007 -0
- data/__tests__/controllers/radio_group_controller.test.js +640 -0
- data/__tests__/controllers/resizable_controller.test.js +680 -0
- data/__tests__/controllers/select_controller.test.js +674 -0
- data/__tests__/controllers/sheet_controller.test.js +986 -0
- data/__tests__/controllers/slider_controller.test.js +1036 -0
- data/__tests__/controllers/switch_controller.test.js +424 -0
- data/__tests__/controllers/tabs_controller.test.js +907 -0
- data/__tests__/controllers/toggle_group_controller.test.js +839 -0
- data/__tests__/controllers/tooltip_controller.test.js +808 -0
- data/__tests__/helpers/stimulus-test-helper.js +203 -0
- data/app/assets/config/manifest.js +1 -0
- data/app/assets/javascripts/shadcn/controllers/accordion_controller.d.ts +53 -0
- data/app/assets/javascripts/shadcn/controllers/accordion_controller.js +140 -0
- data/app/assets/javascripts/shadcn/controllers/avatar_controller.d.ts +22 -0
- data/app/assets/javascripts/shadcn/controllers/avatar_controller.js +26 -0
- data/app/assets/javascripts/shadcn/controllers/calendar_controller.js +592 -0
- data/app/assets/javascripts/shadcn/controllers/carousel_controller.js +263 -0
- data/app/assets/javascripts/shadcn/controllers/checkbox_controller.d.ts +31 -0
- data/app/assets/javascripts/shadcn/controllers/checkbox_controller.js +48 -0
- data/app/assets/javascripts/shadcn/controllers/collapsible_controller.d.ts +43 -0
- data/app/assets/javascripts/shadcn/controllers/collapsible_controller.js +73 -0
- data/app/assets/javascripts/shadcn/controllers/combobox_controller.js +234 -0
- data/app/assets/javascripts/shadcn/controllers/command_controller.js +141 -0
- data/app/assets/javascripts/shadcn/controllers/command_dialog_controller.js +162 -0
- data/app/assets/javascripts/shadcn/controllers/context_menu_controller.js +202 -0
- data/app/assets/javascripts/shadcn/controllers/date_picker_controller.js +282 -0
- data/app/assets/javascripts/shadcn/controllers/dialog_controller.d.ts +67 -0
- data/app/assets/javascripts/shadcn/controllers/dialog_controller.js +187 -0
- data/app/assets/javascripts/shadcn/controllers/drawer_controller.d.ts +58 -0
- data/app/assets/javascripts/shadcn/controllers/drawer_controller.js +112 -0
- data/app/assets/javascripts/shadcn/controllers/dropdown_controller.d.ts +83 -0
- data/app/assets/javascripts/shadcn/controllers/dropdown_controller.js +225 -0
- data/app/assets/javascripts/shadcn/controllers/hover_card_controller.d.ts +59 -0
- data/app/assets/javascripts/shadcn/controllers/hover_card_controller.js +143 -0
- data/app/assets/javascripts/shadcn/controllers/input_otp_controller.d.ts +44 -0
- data/app/assets/javascripts/shadcn/controllers/input_otp_controller.js +206 -0
- data/app/assets/javascripts/shadcn/controllers/menubar_controller.js +323 -0
- data/app/assets/javascripts/shadcn/controllers/navigation_menu_controller.js +251 -0
- data/app/assets/javascripts/shadcn/controllers/popover_controller.d.ts +56 -0
- data/app/assets/javascripts/shadcn/controllers/popover_controller.js +141 -0
- data/app/assets/javascripts/shadcn/controllers/radio_group_controller.d.ts +47 -0
- data/app/assets/javascripts/shadcn/controllers/radio_group_controller.js +108 -0
- data/app/assets/javascripts/shadcn/controllers/resizable_controller.js +272 -0
- data/app/assets/javascripts/shadcn/controllers/scroll_area_controller.d.ts +44 -0
- data/app/assets/javascripts/shadcn/controllers/scroll_area_controller.js +74 -0
- data/app/assets/javascripts/shadcn/controllers/select_controller.d.ts +84 -0
- data/app/assets/javascripts/shadcn/controllers/select_controller.js +222 -0
- data/app/assets/javascripts/shadcn/controllers/sheet_controller.d.ts +60 -0
- data/app/assets/javascripts/shadcn/controllers/sheet_controller.js +151 -0
- data/app/assets/javascripts/shadcn/controllers/sidebar_controller.js +148 -0
- data/app/assets/javascripts/shadcn/controllers/slider_controller.d.ts +102 -0
- data/app/assets/javascripts/shadcn/controllers/slider_controller.js +364 -0
- data/app/assets/javascripts/shadcn/controllers/switch_controller.d.ts +46 -0
- data/app/assets/javascripts/shadcn/controllers/switch_controller.js +78 -0
- data/app/assets/javascripts/shadcn/controllers/tabs_controller.d.ts +51 -0
- data/app/assets/javascripts/shadcn/controllers/tabs_controller.js +126 -0
- data/app/assets/javascripts/shadcn/controllers/toast_controller.d.ts +37 -0
- data/app/assets/javascripts/shadcn/controllers/toast_controller.js +58 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_controller.d.ts +27 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_controller.js +42 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_group_controller.d.ts +44 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_group_controller.js +68 -0
- data/app/assets/javascripts/shadcn/controllers/tooltip_controller.d.ts +56 -0
- data/app/assets/javascripts/shadcn/controllers/tooltip_controller.js +117 -0
- data/app/assets/javascripts/shadcn/index.d.ts +74 -0
- data/app/assets/javascripts/shadcn/index.js +133 -0
- data/app/assets/stylesheets/.keep +0 -0
- data/app/assets/stylesheets/shadcn/base.css +445 -0
- data/app/assets/stylesheets/shadcn/components.css +513 -0
- data/app/assets/stylesheets/shadcn/index.css +18 -0
- data/app/assets/stylesheets/shadcn/themes/gray.css +68 -0
- data/app/assets/stylesheets/shadcn/themes/slate.css +68 -0
- data/app/assets/stylesheets/shadcn/themes/stone.css +68 -0
- data/app/assets/stylesheets/shadcn/themes/zinc.css +68 -0
- data/app/components/shadcn/accordion_component.rb +63 -0
- data/app/components/shadcn/accordion_content_component.rb +29 -0
- data/app/components/shadcn/accordion_item_component.rb +40 -0
- data/app/components/shadcn/accordion_trigger_component.rb +49 -0
- data/app/components/shadcn/alert_component.rb +75 -0
- data/app/components/shadcn/alert_description_component.rb +12 -0
- data/app/components/shadcn/alert_dialog_action_component.rb +24 -0
- data/app/components/shadcn/alert_dialog_cancel_component.rb +24 -0
- data/app/components/shadcn/alert_dialog_component.rb +71 -0
- data/app/components/shadcn/alert_dialog_content_component.rb +57 -0
- data/app/components/shadcn/alert_dialog_description_component.rb +12 -0
- data/app/components/shadcn/alert_dialog_footer_component.rb +19 -0
- data/app/components/shadcn/alert_dialog_header_component.rb +19 -0
- data/app/components/shadcn/alert_dialog_title_component.rb +12 -0
- data/app/components/shadcn/alert_title_component.rb +12 -0
- data/app/components/shadcn/aspect_ratio_component.rb +49 -0
- data/app/components/shadcn/avatar_component.rb +107 -0
- data/app/components/shadcn/avatar_fallback_component.rb +17 -0
- data/app/components/shadcn/badge_component.rb +49 -0
- data/app/components/shadcn/base_component.rb +100 -0
- data/app/components/shadcn/breadcrumb_component.rb +70 -0
- data/app/components/shadcn/breadcrumb_item_component.rb +50 -0
- data/app/components/shadcn/button_component.rb +141 -0
- data/app/components/shadcn/button_group_component.rb +69 -0
- data/app/components/shadcn/calendar_component.rb +337 -0
- data/app/components/shadcn/card_action_component.rb +10 -0
- data/app/components/shadcn/card_component.rb +63 -0
- data/app/components/shadcn/card_content_component.rb +19 -0
- data/app/components/shadcn/card_description_component.rb +12 -0
- data/app/components/shadcn/card_footer_component.rb +12 -0
- data/app/components/shadcn/card_header_component.rb +24 -0
- data/app/components/shadcn/card_title_component.rb +18 -0
- data/app/components/shadcn/carousel_component.rb +275 -0
- data/app/components/shadcn/checkbox_component.rb +103 -0
- data/app/components/shadcn/collapsible_component.rb +66 -0
- data/app/components/shadcn/collapsible_content_component.rb +28 -0
- data/app/components/shadcn/combobox_component.rb +322 -0
- data/app/components/shadcn/command_component.rb +52 -0
- data/app/components/shadcn/command_dialog_component.rb +76 -0
- data/app/components/shadcn/command_empty_component.rb +12 -0
- data/app/components/shadcn/command_group_component.rb +34 -0
- data/app/components/shadcn/command_input_component.rb +59 -0
- data/app/components/shadcn/command_item_component.rb +48 -0
- data/app/components/shadcn/command_list_component.rb +38 -0
- data/app/components/shadcn/command_separator_component.rb +12 -0
- data/app/components/shadcn/command_shortcut_component.rb +12 -0
- data/app/components/shadcn/context_menu_component.rb +64 -0
- data/app/components/shadcn/context_menu_content_component.rb +44 -0
- data/app/components/shadcn/context_menu_item_component.rb +63 -0
- data/app/components/shadcn/context_menu_label_component.rb +18 -0
- data/app/components/shadcn/context_menu_separator_component.rb +12 -0
- data/app/components/shadcn/context_menu_shortcut_component.rb +12 -0
- data/app/components/shadcn/date_picker_component.rb +368 -0
- data/app/components/shadcn/dialog_component.rb +77 -0
- data/app/components/shadcn/dialog_content_component.rb +91 -0
- data/app/components/shadcn/dialog_description_component.rb +12 -0
- data/app/components/shadcn/dialog_footer_component.rb +12 -0
- data/app/components/shadcn/dialog_header_component.rb +19 -0
- data/app/components/shadcn/dialog_title_component.rb +12 -0
- data/app/components/shadcn/drawer_component.rb +72 -0
- data/app/components/shadcn/drawer_content_component.rb +76 -0
- data/app/components/shadcn/drawer_description_component.rb +12 -0
- data/app/components/shadcn/drawer_footer_component.rb +12 -0
- data/app/components/shadcn/drawer_header_component.rb +19 -0
- data/app/components/shadcn/drawer_title_component.rb +12 -0
- data/app/components/shadcn/dropdown_menu_component.rb +75 -0
- data/app/components/shadcn/dropdown_menu_content_component.rb +49 -0
- data/app/components/shadcn/dropdown_menu_group_component.rb +10 -0
- data/app/components/shadcn/dropdown_menu_item_component.rb +63 -0
- data/app/components/shadcn/dropdown_menu_label_component.rb +18 -0
- data/app/components/shadcn/dropdown_menu_separator_component.rb +12 -0
- data/app/components/shadcn/dropdown_menu_shortcut_component.rb +12 -0
- data/app/components/shadcn/empty_component.rb +48 -0
- data/app/components/shadcn/empty_content_component.rb +12 -0
- data/app/components/shadcn/empty_description_component.rb +12 -0
- data/app/components/shadcn/empty_header_component.rb +29 -0
- data/app/components/shadcn/empty_media_component.rb +21 -0
- data/app/components/shadcn/empty_title_component.rb +12 -0
- data/app/components/shadcn/field_component.rb +113 -0
- data/app/components/shadcn/hover_card_component.rb +64 -0
- data/app/components/shadcn/hover_card_content_component.rb +36 -0
- data/app/components/shadcn/input_component.rb +108 -0
- data/app/components/shadcn/input_group_component.rb +70 -0
- data/app/components/shadcn/input_otp_component.rb +183 -0
- data/app/components/shadcn/item_actions_component.rb +12 -0
- data/app/components/shadcn/item_component.rb +98 -0
- data/app/components/shadcn/item_content_component.rb +24 -0
- data/app/components/shadcn/item_description_component.rb +12 -0
- data/app/components/shadcn/item_footer_component.rb +12 -0
- data/app/components/shadcn/item_group_component.rb +24 -0
- data/app/components/shadcn/item_header_component.rb +12 -0
- data/app/components/shadcn/item_media_component.rb +22 -0
- data/app/components/shadcn/item_separator_component.rb +12 -0
- data/app/components/shadcn/item_title_component.rb +12 -0
- data/app/components/shadcn/kbd_component.rb +36 -0
- data/app/components/shadcn/label_component.rb +49 -0
- data/app/components/shadcn/menubar_checkbox_item_component.rb +76 -0
- data/app/components/shadcn/menubar_component.rb +56 -0
- data/app/components/shadcn/menubar_content_component.rb +64 -0
- data/app/components/shadcn/menubar_item_component.rb +65 -0
- data/app/components/shadcn/menubar_label_component.rb +27 -0
- data/app/components/shadcn/menubar_menu_component.rb +34 -0
- data/app/components/shadcn/menubar_radio_group_component.rb +42 -0
- data/app/components/shadcn/menubar_radio_item_component.rb +76 -0
- data/app/components/shadcn/menubar_separator_component.rb +22 -0
- data/app/components/shadcn/menubar_shortcut_component.rb +21 -0
- data/app/components/shadcn/menubar_sub_component.rb +38 -0
- data/app/components/shadcn/menubar_sub_content_component.rb +45 -0
- data/app/components/shadcn/menubar_sub_trigger_component.rb +59 -0
- data/app/components/shadcn/menubar_trigger_component.rb +31 -0
- data/app/components/shadcn/native_select_component.rb +150 -0
- data/app/components/shadcn/navigation_menu_component.rb +76 -0
- data/app/components/shadcn/navigation_menu_content_component.rb +30 -0
- data/app/components/shadcn/navigation_menu_item_component.rb +39 -0
- data/app/components/shadcn/navigation_menu_link_component.rb +38 -0
- data/app/components/shadcn/navigation_menu_list_component.rb +29 -0
- data/app/components/shadcn/navigation_menu_trigger_component.rb +59 -0
- data/app/components/shadcn/pagination_component.rb +195 -0
- data/app/components/shadcn/pagination_content_component.rb +47 -0
- data/app/components/shadcn/pagination_ellipsis_component.rb +30 -0
- data/app/components/shadcn/pagination_item_component.rb +53 -0
- data/app/components/shadcn/pagination_next_component.rb +48 -0
- data/app/components/shadcn/pagination_previous_component.rb +48 -0
- data/app/components/shadcn/popover_component.rb +76 -0
- data/app/components/shadcn/popover_content_component.rb +25 -0
- data/app/components/shadcn/progress_component.rb +77 -0
- data/app/components/shadcn/radio_group_component.rb +129 -0
- data/app/components/shadcn/radio_group_item_component.rb +109 -0
- data/app/components/shadcn/resizable_handle_component.rb +98 -0
- data/app/components/shadcn/resizable_panel_component.rb +56 -0
- data/app/components/shadcn/resizable_panel_group_component.rb +94 -0
- data/app/components/shadcn/scroll_area_component.rb +110 -0
- data/app/components/shadcn/select_component.rb +151 -0
- data/app/components/shadcn/select_group_component.rb +32 -0
- data/app/components/shadcn/select_item_component.rb +59 -0
- data/app/components/shadcn/select_separator_component.rb +12 -0
- data/app/components/shadcn/separator_component.rb +54 -0
- data/app/components/shadcn/sheet_component.rb +82 -0
- data/app/components/shadcn/sheet_content_component.rb +95 -0
- data/app/components/shadcn/sheet_description_component.rb +12 -0
- data/app/components/shadcn/sheet_footer_component.rb +12 -0
- data/app/components/shadcn/sheet_header_component.rb +19 -0
- data/app/components/shadcn/sheet_title_component.rb +12 -0
- data/app/components/shadcn/sidebar_component.rb +180 -0
- data/app/components/shadcn/sidebar_content_component.rb +32 -0
- data/app/components/shadcn/sidebar_footer_component.rb +24 -0
- data/app/components/shadcn/sidebar_group_action_component.rb +26 -0
- data/app/components/shadcn/sidebar_group_component.rb +38 -0
- data/app/components/shadcn/sidebar_group_content_component.rb +32 -0
- data/app/components/shadcn/sidebar_group_label_component.rb +25 -0
- data/app/components/shadcn/sidebar_header_component.rb +24 -0
- data/app/components/shadcn/sidebar_inset_component.rb +25 -0
- data/app/components/shadcn/sidebar_menu_action_component.rb +37 -0
- data/app/components/shadcn/sidebar_menu_badge_component.rb +25 -0
- data/app/components/shadcn/sidebar_menu_button_component.rb +52 -0
- data/app/components/shadcn/sidebar_menu_component.rb +32 -0
- data/app/components/shadcn/sidebar_menu_item_component.rb +41 -0
- data/app/components/shadcn/sidebar_menu_skeleton_component.rb +46 -0
- data/app/components/shadcn/sidebar_menu_sub_button_component.rb +43 -0
- data/app/components/shadcn/sidebar_menu_sub_component.rb +33 -0
- data/app/components/shadcn/sidebar_menu_sub_item_component.rb +30 -0
- data/app/components/shadcn/sidebar_provider_component.rb +57 -0
- data/app/components/shadcn/sidebar_rail_component.rb +30 -0
- data/app/components/shadcn/sidebar_separator_component.rb +24 -0
- data/app/components/shadcn/sidebar_trigger_component.rb +51 -0
- data/app/components/shadcn/skeleton_component.rb +29 -0
- data/app/components/shadcn/slider_component.rb +76 -0
- data/app/components/shadcn/spinner_component.rb +67 -0
- data/app/components/shadcn/switch_component.rb +147 -0
- data/app/components/shadcn/table_body_component.rb +16 -0
- data/app/components/shadcn/table_caption_component.rb +12 -0
- data/app/components/shadcn/table_cell_component.rb +12 -0
- data/app/components/shadcn/table_component.rb +57 -0
- data/app/components/shadcn/table_footer_component.rb +16 -0
- data/app/components/shadcn/table_head_component.rb +12 -0
- data/app/components/shadcn/table_header_component.rb +16 -0
- data/app/components/shadcn/table_row_component.rb +40 -0
- data/app/components/shadcn/tabs_component.rb +78 -0
- data/app/components/shadcn/tabs_content_component.rb +32 -0
- data/app/components/shadcn/tabs_list_component.rb +30 -0
- data/app/components/shadcn/tabs_trigger_component.rb +37 -0
- data/app/components/shadcn/textarea_component.rb +84 -0
- data/app/components/shadcn/toast_action_component.rb +18 -0
- data/app/components/shadcn/toast_component.rb +114 -0
- data/app/components/shadcn/toast_description_component.rb +12 -0
- data/app/components/shadcn/toast_title_component.rb +12 -0
- data/app/components/shadcn/toast_viewport_component.rb +12 -0
- data/app/components/shadcn/toggle_component.rb +77 -0
- data/app/components/shadcn/toggle_group_component.rb +96 -0
- data/app/components/shadcn/toggle_group_item_component.rb +62 -0
- data/app/components/shadcn/tooltip_component.rb +89 -0
- data/app/components/shadcn/typography_component.rb +112 -0
- data/babel.config.cjs +5 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/config/importmap.rb +5 -0
- data/fly.toml +26 -0
- data/jest.config.js +19 -0
- data/jest.setup.js +8 -0
- data/lib/generators/shadcn/component/component_generator.rb +188 -0
- data/lib/generators/shadcn/install/install_generator.rb +140 -0
- data/lib/generators/shadcn/install/templates/initializer.rb.tt +35 -0
- data/lib/generators/shadcn/install/templates/shadcn.yml.tt +35 -0
- data/lib/generators/shadcn/theme/theme_generator.rb +128 -0
- data/lib/shadcn/rails/class_merger.rb +228 -0
- data/lib/shadcn/rails/configuration.rb +341 -0
- data/lib/shadcn/rails/engine.rb +59 -0
- data/lib/shadcn/rails/helpers/class_name_helper.rb +35 -0
- data/lib/shadcn/rails/helpers/component_helper.rb +60 -0
- data/lib/shadcn/rails/helpers/pagination_helper.rb +187 -0
- data/lib/shadcn/rails/version.rb +7 -0
- data/lib/shadcn/rails.rb +179 -0
- data/package-lock.json +7415 -0
- data/package.json +68 -0
- data/rollup.config.js +29 -0
- data/sig/shadcn/rails.rbs +6 -0
- metadata +526 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stimulus controller for the Input OTP component
|
|
5
|
+
* Handles multi-slot OTP input with keyboard navigation
|
|
6
|
+
*/
|
|
7
|
+
export default class extends Controller {
|
|
8
|
+
static targets = ["slot", "input", "hiddenInput", "caret"]
|
|
9
|
+
static values = {
|
|
10
|
+
length: { type: Number, default: 6 },
|
|
11
|
+
pattern: { type: String, default: "" },
|
|
12
|
+
disabled: { type: Boolean, default: false }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
connect() {
|
|
16
|
+
this.updateHiddenInput()
|
|
17
|
+
this.updateCarets()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
handleInput(event) {
|
|
21
|
+
const input = event.target
|
|
22
|
+
const index = parseInt(input.dataset.index)
|
|
23
|
+
let value = input.value
|
|
24
|
+
|
|
25
|
+
// Apply pattern validation if set
|
|
26
|
+
if (this.patternValue) {
|
|
27
|
+
const regex = new RegExp(this.patternValue)
|
|
28
|
+
if (!regex.test(value)) {
|
|
29
|
+
input.value = ""
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Only keep last character if multiple entered
|
|
35
|
+
if (value.length > 1) {
|
|
36
|
+
value = value.slice(-1)
|
|
37
|
+
input.value = value
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.updateHiddenInput()
|
|
41
|
+
this.updateCarets()
|
|
42
|
+
|
|
43
|
+
// Auto-advance to next slot
|
|
44
|
+
if (value && index < this.lengthValue - 1) {
|
|
45
|
+
this.focusInput(index + 1)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
handleKeydown(event) {
|
|
50
|
+
const input = event.target
|
|
51
|
+
const index = parseInt(input.dataset.index)
|
|
52
|
+
|
|
53
|
+
switch (event.key) {
|
|
54
|
+
case "Backspace":
|
|
55
|
+
if (!input.value && index > 0) {
|
|
56
|
+
// Move to previous slot and clear it
|
|
57
|
+
event.preventDefault()
|
|
58
|
+
this.focusInput(index - 1)
|
|
59
|
+
this.inputTargets[index - 1].value = ""
|
|
60
|
+
this.updateHiddenInput()
|
|
61
|
+
this.updateCarets()
|
|
62
|
+
}
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
case "ArrowLeft":
|
|
66
|
+
if (index > 0) {
|
|
67
|
+
event.preventDefault()
|
|
68
|
+
this.focusInput(index - 1)
|
|
69
|
+
}
|
|
70
|
+
break
|
|
71
|
+
|
|
72
|
+
case "ArrowRight":
|
|
73
|
+
if (index < this.lengthValue - 1) {
|
|
74
|
+
event.preventDefault()
|
|
75
|
+
this.focusInput(index + 1)
|
|
76
|
+
}
|
|
77
|
+
break
|
|
78
|
+
|
|
79
|
+
case "Delete":
|
|
80
|
+
input.value = ""
|
|
81
|
+
this.updateHiddenInput()
|
|
82
|
+
this.updateCarets()
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
handleFocus(event) {
|
|
88
|
+
const input = event.target
|
|
89
|
+
const slot = input.closest("[data-shadcn--input-otp-target='slot']")
|
|
90
|
+
if (slot) {
|
|
91
|
+
slot.classList.add("z-10", "ring-1", "ring-ring")
|
|
92
|
+
}
|
|
93
|
+
this.updateCarets()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
handleBlur(event) {
|
|
97
|
+
const input = event.target
|
|
98
|
+
const slot = input.closest("[data-shadcn--input-otp-target='slot']")
|
|
99
|
+
if (slot) {
|
|
100
|
+
slot.classList.remove("z-10", "ring-1", "ring-ring")
|
|
101
|
+
}
|
|
102
|
+
this.updateCarets()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
handlePaste(event) {
|
|
106
|
+
event.preventDefault()
|
|
107
|
+
const pastedData = event.clipboardData.getData("text")
|
|
108
|
+
|
|
109
|
+
// Apply pattern validation if set
|
|
110
|
+
let chars = pastedData.split("")
|
|
111
|
+
if (this.patternValue) {
|
|
112
|
+
const regex = new RegExp(this.patternValue)
|
|
113
|
+
chars = chars.filter(char => regex.test(char))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fill slots starting from current position
|
|
117
|
+
const startIndex = parseInt(event.target.dataset.index)
|
|
118
|
+
chars.slice(0, this.lengthValue - startIndex).forEach((char, i) => {
|
|
119
|
+
const input = this.inputTargets[startIndex + i]
|
|
120
|
+
if (input) {
|
|
121
|
+
input.value = char
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
this.updateHiddenInput()
|
|
126
|
+
this.updateCarets()
|
|
127
|
+
|
|
128
|
+
// Focus appropriate slot after paste
|
|
129
|
+
const nextEmptyIndex = this.findNextEmptySlot(startIndex)
|
|
130
|
+
if (nextEmptyIndex !== -1) {
|
|
131
|
+
this.focusInput(nextEmptyIndex)
|
|
132
|
+
} else {
|
|
133
|
+
this.focusInput(Math.min(startIndex + chars.length, this.lengthValue - 1))
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
focusSlot(event) {
|
|
138
|
+
const slot = event.currentTarget
|
|
139
|
+
const index = parseInt(slot.dataset.index)
|
|
140
|
+
this.focusInput(index)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
focusInput(index) {
|
|
144
|
+
const input = this.inputTargets[index]
|
|
145
|
+
if (input && !this.disabledValue) {
|
|
146
|
+
input.focus()
|
|
147
|
+
input.select()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
findNextEmptySlot(startIndex) {
|
|
152
|
+
for (let i = startIndex; i < this.lengthValue; i++) {
|
|
153
|
+
if (!this.inputTargets[i]?.value) {
|
|
154
|
+
return i
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return -1
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
updateHiddenInput() {
|
|
161
|
+
if (!this.hasHiddenInputTarget) return
|
|
162
|
+
|
|
163
|
+
const value = this.inputTargets.map(input => input.value || "").join("")
|
|
164
|
+
this.hiddenInputTarget.value = value
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
updateCarets() {
|
|
168
|
+
// Hide all carets
|
|
169
|
+
this.caretTargets.forEach(caret => {
|
|
170
|
+
caret.classList.add("hidden")
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
// Show caret in focused empty slot
|
|
174
|
+
const activeInput = this.inputTargets.find(input =>
|
|
175
|
+
document.activeElement === input && !input.value
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
if (activeInput) {
|
|
179
|
+
const index = parseInt(activeInput.dataset.index)
|
|
180
|
+
const caret = this.caretTargets[index]
|
|
181
|
+
if (caret) {
|
|
182
|
+
caret.classList.remove("hidden")
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Get the complete OTP value
|
|
188
|
+
get value() {
|
|
189
|
+
return this.inputTargets.map(input => input.value || "").join("")
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Check if OTP is complete
|
|
193
|
+
get isComplete() {
|
|
194
|
+
return this.value.length === this.lengthValue
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Clear all inputs
|
|
198
|
+
clear() {
|
|
199
|
+
this.inputTargets.forEach(input => {
|
|
200
|
+
input.value = ""
|
|
201
|
+
})
|
|
202
|
+
this.updateHiddenInput()
|
|
203
|
+
this.updateCarets()
|
|
204
|
+
this.focusInput(0)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Menubar controller
|
|
5
|
+
* Handles menu opening/closing, keyboard navigation, hover behavior
|
|
6
|
+
*/
|
|
7
|
+
export default class extends Controller {
|
|
8
|
+
static targets = ["menu", "trigger", "content", "item", "sub", "subTrigger", "subContent"]
|
|
9
|
+
static values = {
|
|
10
|
+
openIndex: { type: Number, default: -1 }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
connect() {
|
|
14
|
+
this.focusedIndex = -1
|
|
15
|
+
this.isMenuOpen = false
|
|
16
|
+
this.boundHandleClickOutside = this.handleClickOutside.bind(this)
|
|
17
|
+
this.boundHandleKeydown = this.handleKeydown.bind(this)
|
|
18
|
+
this.closeSubTimer = null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
disconnect() {
|
|
22
|
+
this.closeAll()
|
|
23
|
+
document.removeEventListener("click", this.boundHandleClickOutside)
|
|
24
|
+
document.removeEventListener("keydown", this.boundHandleKeydown)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toggle(event) {
|
|
28
|
+
event?.preventDefault()
|
|
29
|
+
const trigger = event.currentTarget
|
|
30
|
+
const menu = trigger.closest("[data-shadcn--menubar-target='menu']")
|
|
31
|
+
const menuIndex = this.menuTargets.indexOf(menu)
|
|
32
|
+
|
|
33
|
+
if (this.openIndexValue === menuIndex) {
|
|
34
|
+
this.closeAll()
|
|
35
|
+
} else {
|
|
36
|
+
this.openMenu(menuIndex)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
hoverOpen(event) {
|
|
41
|
+
// Only open on hover if a menu is already open
|
|
42
|
+
if (!this.isMenuOpen) return
|
|
43
|
+
|
|
44
|
+
const trigger = event.currentTarget
|
|
45
|
+
const menu = trigger.closest("[data-shadcn--menubar-target='menu']")
|
|
46
|
+
const menuIndex = this.menuTargets.indexOf(menu)
|
|
47
|
+
|
|
48
|
+
if (this.openIndexValue !== menuIndex) {
|
|
49
|
+
this.openMenu(menuIndex)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
openMenu(index) {
|
|
54
|
+
// Close any currently open menu
|
|
55
|
+
this.closeAllMenus()
|
|
56
|
+
|
|
57
|
+
if (index < 0 || index >= this.menuTargets.length) return
|
|
58
|
+
|
|
59
|
+
const menu = this.menuTargets[index]
|
|
60
|
+
const trigger = menu.querySelector("[data-shadcn--menubar-target='trigger']")
|
|
61
|
+
const content = menu.querySelector("[data-shadcn--menubar-target='content']")
|
|
62
|
+
|
|
63
|
+
if (trigger && content) {
|
|
64
|
+
trigger.setAttribute("aria-expanded", "true")
|
|
65
|
+
trigger.dataset.state = "open"
|
|
66
|
+
content.hidden = false
|
|
67
|
+
content.dataset.state = "open"
|
|
68
|
+
this.positionContent(trigger, content)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.openIndexValue = index
|
|
72
|
+
this.isMenuOpen = true
|
|
73
|
+
this.focusedIndex = -1
|
|
74
|
+
|
|
75
|
+
// Add event listeners
|
|
76
|
+
document.addEventListener("click", this.boundHandleClickOutside)
|
|
77
|
+
document.addEventListener("keydown", this.boundHandleKeydown)
|
|
78
|
+
|
|
79
|
+
// Focus first item
|
|
80
|
+
this.focusNextItem()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
closeAllMenus() {
|
|
84
|
+
this.triggerTargets.forEach(trigger => {
|
|
85
|
+
trigger.setAttribute("aria-expanded", "false")
|
|
86
|
+
trigger.dataset.state = "closed"
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
this.contentTargets.forEach(content => {
|
|
90
|
+
content.dataset.state = "closed"
|
|
91
|
+
content.hidden = true
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
this.closeAllSubs()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
closeAll() {
|
|
98
|
+
this.closeAllMenus()
|
|
99
|
+
this.openIndexValue = -1
|
|
100
|
+
this.isMenuOpen = false
|
|
101
|
+
this.focusedIndex = -1
|
|
102
|
+
|
|
103
|
+
document.removeEventListener("click", this.boundHandleClickOutside)
|
|
104
|
+
document.removeEventListener("keydown", this.boundHandleKeydown)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
selectItem(event) {
|
|
108
|
+
const item = event.currentTarget
|
|
109
|
+
if (item.dataset.disabled !== undefined) return
|
|
110
|
+
|
|
111
|
+
this.dispatch("select", { detail: { item } })
|
|
112
|
+
this.closeAll()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
toggleCheckbox(event) {
|
|
116
|
+
const item = event.currentTarget
|
|
117
|
+
if (item.dataset.disabled !== undefined) return
|
|
118
|
+
|
|
119
|
+
const isChecked = item.dataset.state === "checked"
|
|
120
|
+
item.dataset.state = isChecked ? "unchecked" : "checked"
|
|
121
|
+
item.setAttribute("aria-checked", (!isChecked).toString())
|
|
122
|
+
|
|
123
|
+
// Toggle the check icon visibility
|
|
124
|
+
const indicator = item.querySelector("span svg")
|
|
125
|
+
if (indicator) {
|
|
126
|
+
indicator.style.display = isChecked ? "none" : "block"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.dispatch("check", { detail: { item, checked: !isChecked } })
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
selectRadio(event) {
|
|
133
|
+
const item = event.currentTarget
|
|
134
|
+
if (item.dataset.disabled !== undefined) return
|
|
135
|
+
|
|
136
|
+
const group = item.closest("[role='group']")
|
|
137
|
+
if (group) {
|
|
138
|
+
// Uncheck all radio items in the group
|
|
139
|
+
group.querySelectorAll("[role='menuitemradio']").forEach(radio => {
|
|
140
|
+
radio.dataset.state = "unchecked"
|
|
141
|
+
radio.setAttribute("aria-checked", "false")
|
|
142
|
+
const indicator = radio.querySelector("span svg")
|
|
143
|
+
if (indicator) indicator.style.display = "none"
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Check this item
|
|
148
|
+
item.dataset.state = "checked"
|
|
149
|
+
item.setAttribute("aria-checked", "true")
|
|
150
|
+
const indicator = item.querySelector("span svg")
|
|
151
|
+
if (indicator) indicator.style.display = "block"
|
|
152
|
+
|
|
153
|
+
this.dispatch("radioChange", { detail: { item, value: item.dataset.value } })
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Submenu handling
|
|
157
|
+
openSub(event) {
|
|
158
|
+
this.cancelCloseSubTimer()
|
|
159
|
+
|
|
160
|
+
const subTrigger = event.currentTarget
|
|
161
|
+
const sub = subTrigger.closest("[data-shadcn--menubar-target='sub']")
|
|
162
|
+
const subContent = sub?.querySelector("[data-shadcn--menubar-target='subContent']")
|
|
163
|
+
|
|
164
|
+
if (subTrigger && subContent) {
|
|
165
|
+
// Close other submenus at the same level
|
|
166
|
+
this.closeAllSubs()
|
|
167
|
+
|
|
168
|
+
subTrigger.setAttribute("aria-expanded", "true")
|
|
169
|
+
subTrigger.dataset.state = "open"
|
|
170
|
+
subContent.hidden = false
|
|
171
|
+
subContent.dataset.state = "open"
|
|
172
|
+
this.positionSubContent(subTrigger, subContent)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
startCloseSubTimer() {
|
|
177
|
+
this.closeSubTimer = setTimeout(() => {
|
|
178
|
+
this.closeAllSubs()
|
|
179
|
+
}, 100)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
cancelCloseSubTimer() {
|
|
183
|
+
if (this.closeSubTimer) {
|
|
184
|
+
clearTimeout(this.closeSubTimer)
|
|
185
|
+
this.closeSubTimer = null
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
closeAllSubs() {
|
|
190
|
+
this.subTriggerTargets.forEach(trigger => {
|
|
191
|
+
trigger.setAttribute("aria-expanded", "false")
|
|
192
|
+
trigger.dataset.state = "closed"
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
this.subContentTargets.forEach(content => {
|
|
196
|
+
content.dataset.state = "closed"
|
|
197
|
+
content.hidden = true
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
handleClickOutside(event) {
|
|
202
|
+
if (!this.element.contains(event.target)) {
|
|
203
|
+
this.closeAll()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
handleKeydown(event) {
|
|
208
|
+
switch (event.key) {
|
|
209
|
+
case "Escape":
|
|
210
|
+
this.closeAll()
|
|
211
|
+
if (this.openIndexValue >= 0) {
|
|
212
|
+
this.triggerTargets[this.openIndexValue]?.focus()
|
|
213
|
+
}
|
|
214
|
+
break
|
|
215
|
+
case "ArrowDown":
|
|
216
|
+
event.preventDefault()
|
|
217
|
+
this.focusNextItem()
|
|
218
|
+
break
|
|
219
|
+
case "ArrowUp":
|
|
220
|
+
event.preventDefault()
|
|
221
|
+
this.focusPreviousItem()
|
|
222
|
+
break
|
|
223
|
+
case "ArrowRight":
|
|
224
|
+
event.preventDefault()
|
|
225
|
+
this.openNextMenu()
|
|
226
|
+
break
|
|
227
|
+
case "ArrowLeft":
|
|
228
|
+
event.preventDefault()
|
|
229
|
+
this.openPreviousMenu()
|
|
230
|
+
break
|
|
231
|
+
case "Home":
|
|
232
|
+
event.preventDefault()
|
|
233
|
+
this.focusFirstItem()
|
|
234
|
+
break
|
|
235
|
+
case "End":
|
|
236
|
+
event.preventDefault()
|
|
237
|
+
this.focusLastItem()
|
|
238
|
+
break
|
|
239
|
+
case "Enter":
|
|
240
|
+
case " ":
|
|
241
|
+
event.preventDefault()
|
|
242
|
+
this.selectFocusedItem()
|
|
243
|
+
break
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
openNextMenu() {
|
|
248
|
+
const nextIndex = (this.openIndexValue + 1) % this.menuTargets.length
|
|
249
|
+
this.openMenu(nextIndex)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
openPreviousMenu() {
|
|
253
|
+
const prevIndex = this.openIndexValue <= 0 ? this.menuTargets.length - 1 : this.openIndexValue - 1
|
|
254
|
+
this.openMenu(prevIndex)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
focusNextItem() {
|
|
258
|
+
const items = this.currentMenuItems
|
|
259
|
+
if (items.length === 0) return
|
|
260
|
+
|
|
261
|
+
this.focusedIndex = (this.focusedIndex + 1) % items.length
|
|
262
|
+
items[this.focusedIndex].focus()
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
focusPreviousItem() {
|
|
266
|
+
const items = this.currentMenuItems
|
|
267
|
+
if (items.length === 0) return
|
|
268
|
+
|
|
269
|
+
this.focusedIndex = this.focusedIndex <= 0 ? items.length - 1 : this.focusedIndex - 1
|
|
270
|
+
items[this.focusedIndex].focus()
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
focusFirstItem() {
|
|
274
|
+
const items = this.currentMenuItems
|
|
275
|
+
if (items.length === 0) return
|
|
276
|
+
|
|
277
|
+
this.focusedIndex = 0
|
|
278
|
+
items[0].focus()
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
focusLastItem() {
|
|
282
|
+
const items = this.currentMenuItems
|
|
283
|
+
if (items.length === 0) return
|
|
284
|
+
|
|
285
|
+
this.focusedIndex = items.length - 1
|
|
286
|
+
items[this.focusedIndex].focus()
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
selectFocusedItem() {
|
|
290
|
+
const items = this.currentMenuItems
|
|
291
|
+
if (this.focusedIndex >= 0 && this.focusedIndex < items.length) {
|
|
292
|
+
items[this.focusedIndex].click()
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
get currentMenuItems() {
|
|
297
|
+
if (this.openIndexValue < 0) return []
|
|
298
|
+
const menu = this.menuTargets[this.openIndexValue]
|
|
299
|
+
if (!menu) return []
|
|
300
|
+
|
|
301
|
+
const content = menu.querySelector("[data-shadcn--menubar-target='content']")
|
|
302
|
+
if (!content) return []
|
|
303
|
+
|
|
304
|
+
return Array.from(content.querySelectorAll("[data-shadcn--menubar-target='item']"))
|
|
305
|
+
.filter(item => item.dataset.disabled === undefined)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
positionContent(trigger, content) {
|
|
309
|
+
const triggerRect = trigger.getBoundingClientRect()
|
|
310
|
+
|
|
311
|
+
content.style.position = "absolute"
|
|
312
|
+
content.style.top = "100%"
|
|
313
|
+
content.style.left = "0"
|
|
314
|
+
content.style.marginTop = "4px"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
positionSubContent(trigger, content) {
|
|
318
|
+
content.style.position = "absolute"
|
|
319
|
+
content.style.top = "0"
|
|
320
|
+
content.style.left = "100%"
|
|
321
|
+
content.style.marginLeft = "2px"
|
|
322
|
+
}
|
|
323
|
+
}
|