velvetkit 0.1.0.beta
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/CHANGELOG.md +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +197 -0
- data/lib/generators/velvetkit/add/add_generator.rb +111 -0
- data/lib/generators/velvetkit/ai/ai_generator.rb +78 -0
- data/lib/generators/velvetkit/helpers.rb +64 -0
- data/lib/generators/velvetkit/install/install_generator.rb +108 -0
- data/lib/velvetkit/namespace.rb +57 -0
- data/lib/velvetkit/reference.rb +108 -0
- data/lib/velvetkit/registry.rb +162 -0
- data/lib/velvetkit/version.rb +5 -0
- data/lib/velvetkit.rb +28 -0
- data/registry/app/assets/tailwind/velvetkit.css +342 -0
- data/registry/app/components/ui/accordion/content.html.erb +5 -0
- data/registry/app/components/ui/accordion/content.rb +34 -0
- data/registry/app/components/ui/accordion/item.html.erb +1 -0
- data/registry/app/components/ui/accordion/item.rb +40 -0
- data/registry/app/components/ui/accordion/trigger.html.erb +1 -0
- data/registry/app/components/ui/accordion/trigger.rb +37 -0
- data/registry/app/components/ui/accordion.html.erb +7 -0
- data/registry/app/components/ui/accordion.rb +34 -0
- data/registry/app/components/ui/alert/description.html.erb +1 -0
- data/registry/app/components/ui/alert/description.rb +12 -0
- data/registry/app/components/ui/alert/title.html.erb +1 -0
- data/registry/app/components/ui/alert/title.rb +12 -0
- data/registry/app/components/ui/alert.html.erb +16 -0
- data/registry/app/components/ui/alert.rb +55 -0
- data/registry/app/components/ui/avatar/fallback.html.erb +1 -0
- data/registry/app/components/ui/avatar/fallback.rb +12 -0
- data/registry/app/components/ui/avatar/image.rb +20 -0
- data/registry/app/components/ui/avatar.html.erb +1 -0
- data/registry/app/components/ui/avatar.rb +56 -0
- data/registry/app/components/ui/avatar_group.html.erb +1 -0
- data/registry/app/components/ui/avatar_group.rb +35 -0
- data/registry/app/components/ui/badge.html.erb +1 -0
- data/registry/app/components/ui/badge.rb +38 -0
- data/registry/app/components/ui/banner.html.erb +10 -0
- data/registry/app/components/ui/banner.rb +47 -0
- data/registry/app/components/ui/base.rb +53 -0
- data/registry/app/components/ui/breadcrumb/auto_ellipsis.html.erb +23 -0
- data/registry/app/components/ui/breadcrumb/auto_ellipsis.rb +12 -0
- data/registry/app/components/ui/breadcrumb/ellipsis.html.erb +18 -0
- data/registry/app/components/ui/breadcrumb/ellipsis.rb +8 -0
- data/registry/app/components/ui/breadcrumb/item.html.erb +1 -0
- data/registry/app/components/ui/breadcrumb/item.rb +12 -0
- data/registry/app/components/ui/breadcrumb/item_slot.html.erb +10 -0
- data/registry/app/components/ui/breadcrumb/item_slot.rb +47 -0
- data/registry/app/components/ui/breadcrumb/list.html.erb +1 -0
- data/registry/app/components/ui/breadcrumb/list.rb +12 -0
- data/registry/app/components/ui/breadcrumb/separator.html.erb +1 -0
- data/registry/app/components/ui/breadcrumb/separator.rb +12 -0
- data/registry/app/components/ui/breadcrumb.html.erb +30 -0
- data/registry/app/components/ui/breadcrumb.rb +83 -0
- data/registry/app/components/ui/button.html.erb +1 -0
- data/registry/app/components/ui/button.rb +81 -0
- data/registry/app/components/ui/button_to.html.erb +1 -0
- data/registry/app/components/ui/button_to.rb +33 -0
- data/registry/app/components/ui/card/content.html.erb +1 -0
- data/registry/app/components/ui/card/content.rb +12 -0
- data/registry/app/components/ui/card/description.html.erb +1 -0
- data/registry/app/components/ui/card/description.rb +12 -0
- data/registry/app/components/ui/card/footer.html.erb +1 -0
- data/registry/app/components/ui/card/footer.rb +12 -0
- data/registry/app/components/ui/card/header.html.erb +1 -0
- data/registry/app/components/ui/card/header.rb +15 -0
- data/registry/app/components/ui/card/title.html.erb +1 -0
- data/registry/app/components/ui/card/title.rb +12 -0
- data/registry/app/components/ui/card.html.erb +1 -0
- data/registry/app/components/ui/card.rb +18 -0
- data/registry/app/components/ui/checkbox.html.erb +18 -0
- data/registry/app/components/ui/checkbox.rb +133 -0
- data/registry/app/components/ui/data_grid.html.erb +2 -0
- data/registry/app/components/ui/data_grid.rb +84 -0
- data/registry/app/components/ui/date_picker.html.erb +70 -0
- data/registry/app/components/ui/date_picker.rb +111 -0
- data/registry/app/components/ui/dialog/close.html.erb +7 -0
- data/registry/app/components/ui/dialog/close.rb +53 -0
- data/registry/app/components/ui/dialog/content.html.erb +26 -0
- data/registry/app/components/ui/dialog/content.rb +102 -0
- data/registry/app/components/ui/dialog/description.html.erb +1 -0
- data/registry/app/components/ui/dialog/description.rb +16 -0
- data/registry/app/components/ui/dialog/footer.html.erb +1 -0
- data/registry/app/components/ui/dialog/footer.rb +14 -0
- data/registry/app/components/ui/dialog/header.html.erb +1 -0
- data/registry/app/components/ui/dialog/header.rb +16 -0
- data/registry/app/components/ui/dialog/title.html.erb +1 -0
- data/registry/app/components/ui/dialog/title.rb +16 -0
- data/registry/app/components/ui/dialog/trigger.html.erb +5 -0
- data/registry/app/components/ui/dialog/trigger.rb +75 -0
- data/registry/app/components/ui/dialog.html.erb +3 -0
- data/registry/app/components/ui/dialog.rb +41 -0
- data/registry/app/components/ui/divider.html.erb +9 -0
- data/registry/app/components/ui/divider.rb +41 -0
- data/registry/app/components/ui/icon.html.erb +1 -0
- data/registry/app/components/ui/icon.rb +41 -0
- data/registry/app/components/ui/image.html.erb +1 -0
- data/registry/app/components/ui/image.rb +74 -0
- data/registry/app/components/ui/input.html.erb +9 -0
- data/registry/app/components/ui/input.rb +127 -0
- data/registry/app/components/ui/input_group/addon.html.erb +6 -0
- data/registry/app/components/ui/input_group/addon.rb +51 -0
- data/registry/app/components/ui/input_group/field.rb +26 -0
- data/registry/app/components/ui/input_group.html.erb +5 -0
- data/registry/app/components/ui/input_group.rb +55 -0
- data/registry/app/components/ui/label.html.erb +2 -0
- data/registry/app/components/ui/label.rb +48 -0
- data/registry/app/components/ui/link.html.erb +1 -0
- data/registry/app/components/ui/link.rb +64 -0
- data/registry/app/components/ui/menu/content.html.erb +5 -0
- data/registry/app/components/ui/menu/content.rb +106 -0
- data/registry/app/components/ui/menu/group.html.erb +1 -0
- data/registry/app/components/ui/menu/group.rb +19 -0
- data/registry/app/components/ui/menu/item.html.erb +1 -0
- data/registry/app/components/ui/menu/item.rb +68 -0
- data/registry/app/components/ui/menu/label.html.erb +1 -0
- data/registry/app/components/ui/menu/label.rb +33 -0
- data/registry/app/components/ui/menu/separator.html.erb +1 -0
- data/registry/app/components/ui/menu/separator.rb +20 -0
- data/registry/app/components/ui/menu/trigger.html.erb +1 -0
- data/registry/app/components/ui/menu/trigger.rb +29 -0
- data/registry/app/components/ui/menu.html.erb +3 -0
- data/registry/app/components/ui/menu.rb +23 -0
- data/registry/app/components/ui/native_select.html.erb +16 -0
- data/registry/app/components/ui/native_select.rb +109 -0
- data/registry/app/components/ui/pagination.html.erb +34 -0
- data/registry/app/components/ui/pagination.rb +62 -0
- data/registry/app/components/ui/password_input.html.erb +20 -0
- data/registry/app/components/ui/password_input.rb +94 -0
- data/registry/app/components/ui/popover/content.html.erb +12 -0
- data/registry/app/components/ui/popover/content.rb +83 -0
- data/registry/app/components/ui/popover/trigger.html.erb +1 -0
- data/registry/app/components/ui/popover/trigger.rb +29 -0
- data/registry/app/components/ui/popover.html.erb +3 -0
- data/registry/app/components/ui/popover.rb +24 -0
- data/registry/app/components/ui/radio_group/item.html.erb +18 -0
- data/registry/app/components/ui/radio_group/item.rb +97 -0
- data/registry/app/components/ui/radio_group.html.erb +1 -0
- data/registry/app/components/ui/radio_group.rb +35 -0
- data/registry/app/components/ui/select.html.erb +60 -0
- data/registry/app/components/ui/select.rb +181 -0
- data/registry/app/components/ui/sheet/close.rb +4 -0
- data/registry/app/components/ui/sheet/content.html.erb +24 -0
- data/registry/app/components/ui/sheet/content.rb +97 -0
- data/registry/app/components/ui/sheet/trigger.rb +4 -0
- data/registry/app/components/ui/sheet.html.erb +3 -0
- data/registry/app/components/ui/sheet.rb +37 -0
- data/registry/app/components/ui/sidebar/content.html.erb +1 -0
- data/registry/app/components/ui/sidebar/content.rb +18 -0
- data/registry/app/components/ui/sidebar/footer.html.erb +3 -0
- data/registry/app/components/ui/sidebar/footer.rb +16 -0
- data/registry/app/components/ui/sidebar/group.html.erb +1 -0
- data/registry/app/components/ui/sidebar/group.rb +19 -0
- data/registry/app/components/ui/sidebar/group_label.html.erb +1 -0
- data/registry/app/components/ui/sidebar/group_label.rb +18 -0
- data/registry/app/components/ui/sidebar/header.html.erb +1 -0
- data/registry/app/components/ui/sidebar/header.rb +16 -0
- data/registry/app/components/ui/sidebar/inset.html.erb +1 -0
- data/registry/app/components/ui/sidebar/inset.rb +17 -0
- data/registry/app/components/ui/sidebar/menu.html.erb +1 -0
- data/registry/app/components/ui/sidebar/menu.rb +18 -0
- data/registry/app/components/ui/sidebar/menu_button.html.erb +1 -0
- data/registry/app/components/ui/sidebar/menu_button.rb +30 -0
- data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -0
- data/registry/app/components/ui/sidebar/menu_item.rb +23 -0
- data/registry/app/components/ui/sidebar/trigger.html.erb +1 -0
- data/registry/app/components/ui/sidebar/trigger.rb +24 -0
- data/registry/app/components/ui/sidebar/wrapper.html.erb +1 -0
- data/registry/app/components/ui/sidebar/wrapper.rb +40 -0
- data/registry/app/components/ui/sidebar.html.erb +11 -0
- data/registry/app/components/ui/sidebar.rb +29 -0
- data/registry/app/components/ui/spinner.html.erb +1 -0
- data/registry/app/components/ui/spinner.rb +20 -0
- data/registry/app/components/ui/switch.html.erb +12 -0
- data/registry/app/components/ui/switch.rb +109 -0
- data/registry/app/components/ui/table/cell.html.erb +1 -0
- data/registry/app/components/ui/table/cell.rb +16 -0
- data/registry/app/components/ui/table/column.html.erb +1 -0
- data/registry/app/components/ui/table/column.rb +18 -0
- data/registry/app/components/ui/table/head.html.erb +1 -0
- data/registry/app/components/ui/table/head.rb +13 -0
- data/registry/app/components/ui/table/row.html.erb +1 -0
- data/registry/app/components/ui/table/row.rb +26 -0
- data/registry/app/components/ui/table.html.erb +4 -0
- data/registry/app/components/ui/table.rb +45 -0
- data/registry/app/components/ui/tabs/content.html.erb +1 -0
- data/registry/app/components/ui/tabs/content.rb +43 -0
- data/registry/app/components/ui/tabs/list.html.erb +1 -0
- data/registry/app/components/ui/tabs/list.rb +28 -0
- data/registry/app/components/ui/tabs/trigger.html.erb +1 -0
- data/registry/app/components/ui/tabs/trigger.rb +91 -0
- data/registry/app/components/ui/tabs.html.erb +3 -0
- data/registry/app/components/ui/tabs.rb +27 -0
- data/registry/app/components/ui/text.html.erb +1 -0
- data/registry/app/components/ui/text.rb +48 -0
- data/registry/app/components/ui/theme_toggle.html.erb +9 -0
- data/registry/app/components/ui/theme_toggle.rb +63 -0
- data/registry/app/components/ui/tooltip/content.html.erb +1 -0
- data/registry/app/components/ui/tooltip/content.rb +65 -0
- data/registry/app/components/ui/tooltip/trigger.html.erb +1 -0
- data/registry/app/components/ui/tooltip/trigger.rb +33 -0
- data/registry/app/components/ui/tooltip.html.erb +3 -0
- data/registry/app/components/ui/tooltip.rb +24 -0
- data/registry/app/components/ui/typography/blockquote.html.erb +1 -0
- data/registry/app/components/ui/typography/blockquote.rb +15 -0
- data/registry/app/components/ui/typography/code.html.erb +1 -0
- data/registry/app/components/ui/typography/code.rb +25 -0
- data/registry/app/components/ui/typography/h1.rb +7 -0
- data/registry/app/components/ui/typography/h2.rb +7 -0
- data/registry/app/components/ui/typography/h3.rb +7 -0
- data/registry/app/components/ui/typography/h4.rb +7 -0
- data/registry/app/components/ui/typography/large.rb +7 -0
- data/registry/app/components/ui/typography/lead.rb +7 -0
- data/registry/app/components/ui/typography/muted.rb +7 -0
- data/registry/app/components/ui/typography/small.rb +7 -0
- data/registry/app/javascript/ag_grid.ts +26 -0
- data/registry/app/javascript/cally.ts +8 -0
- data/registry/app/javascript/controllers/ui/_internal/use_dismiss.ts +88 -0
- data/registry/app/javascript/controllers/ui/_internal/use_floating.ts +112 -0
- data/registry/app/javascript/controllers/ui/accordion_controller.ts +100 -0
- data/registry/app/javascript/controllers/ui/alert_controller.ts +7 -0
- data/registry/app/javascript/controllers/ui/banner_controller.ts +7 -0
- data/registry/app/javascript/controllers/ui/data_grid_controller.ts +198 -0
- data/registry/app/javascript/controllers/ui/date_picker_controller.ts +141 -0
- data/registry/app/javascript/controllers/ui/dialog_controller.ts +70 -0
- data/registry/app/javascript/controllers/ui/menu_controller.ts +201 -0
- data/registry/app/javascript/controllers/ui/password_visibility_controller.ts +43 -0
- data/registry/app/javascript/controllers/ui/popover_controller.ts +108 -0
- data/registry/app/javascript/controllers/ui/select_controller.ts +274 -0
- data/registry/app/javascript/controllers/ui/sidebar_controller.ts +64 -0
- data/registry/app/javascript/controllers/ui/tabs_controller.ts +74 -0
- data/registry/app/javascript/controllers/ui/theme_controller.ts +101 -0
- data/registry/app/javascript/controllers/ui/tooltip_controller.ts +102 -0
- data/registry/app/javascript/velvetkit_icons.ts +58 -0
- data/registry/app/views/layouts/_theme_script.html.erb +19 -0
- data/registry/components.yml +102 -0
- data/registry/config/locales/velvetkit.en.yml +56 -0
- data/registry/docs/agents.md +62 -0
- data/registry/test/components/previews/ui/accordion_preview/faq_style.html.erb +20 -0
- data/registry/test/components/previews/ui/accordion_preview/multiple.html.erb +27 -0
- data/registry/test/components/previews/ui/accordion_preview/single.html.erb +22 -0
- data/registry/test/components/previews/ui/accordion_preview.rb +31 -0
- data/registry/test/components/previews/ui/alert_preview/title_only.html.erb +12 -0
- data/registry/test/components/previews/ui/alert_preview/variants.html.erb +22 -0
- data/registry/test/components/previews/ui/alert_preview/with_icon.html.erb +12 -0
- data/registry/test/components/previews/ui/alert_preview/with_link.html.erb +18 -0
- data/registry/test/components/previews/ui/alert_preview.rb +34 -0
- data/registry/test/components/previews/ui/avatar_group_preview/default.html.erb +11 -0
- data/registry/test/components/previews/ui/avatar_group_preview/overflow.html.erb +23 -0
- data/registry/test/components/previews/ui/avatar_group_preview/small.html.erb +12 -0
- data/registry/test/components/previews/ui/avatar_group_preview.rb +23 -0
- data/registry/test/components/previews/ui/avatar_preview/colors.html.erb +8 -0
- data/registry/test/components/previews/ui/avatar_preview/shapes.html.erb +10 -0
- data/registry/test/components/previews/ui/avatar_preview/sizes.html.erb +8 -0
- data/registry/test/components/previews/ui/avatar_preview/with_image.html.erb +10 -0
- data/registry/test/components/previews/ui/avatar_preview.rb +24 -0
- data/registry/test/components/previews/ui/badge_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/badge_preview/variants.html.erb +8 -0
- data/registry/test/components/previews/ui/badge_preview/with_icon.html.erb +14 -0
- data/registry/test/components/previews/ui/badge_preview.rb +20 -0
- data/registry/test/components/previews/ui/banner_preview/introduction.html.erb +9 -0
- data/registry/test/components/previews/ui/banner_preview/promotion.html.erb +9 -0
- data/registry/test/components/previews/ui/banner_preview/with_illustration.html.erb +12 -0
- data/registry/test/components/previews/ui/banner_preview.rb +25 -0
- data/registry/test/components/previews/ui/breadcrumb_preview/collapsed.html.erb +50 -0
- data/registry/test/components/previews/ui/breadcrumb_preview/default.html.erb +8 -0
- data/registry/test/components/previews/ui/breadcrumb_preview/long_path.html.erb +8 -0
- data/registry/test/components/previews/ui/breadcrumb_preview/medium.html.erb +7 -0
- data/registry/test/components/previews/ui/breadcrumb_preview/with_avatar.html.erb +8 -0
- data/registry/test/components/previews/ui/breadcrumb_preview.rb +66 -0
- data/registry/test/components/previews/ui/button_preview/disabled.html.erb +39 -0
- data/registry/test/components/previews/ui/button_preview/icon_only.html.erb +17 -0
- data/registry/test/components/previews/ui/button_preview/loading.html.erb +12 -0
- data/registry/test/components/previews/ui/button_preview/sizes.html.erb +6 -0
- data/registry/test/components/previews/ui/button_preview/variants.html.erb +8 -0
- data/registry/test/components/previews/ui/button_preview/with_both_icons.html.erb +12 -0
- data/registry/test/components/previews/ui/button_preview/with_leading_icon.html.erb +22 -0
- data/registry/test/components/previews/ui/button_preview/with_trailing_icon.html.erb +14 -0
- data/registry/test/components/previews/ui/button_preview.rb +65 -0
- data/registry/test/components/previews/ui/button_to_preview/states.html.erb +8 -0
- data/registry/test/components/previews/ui/button_to_preview/variants.html.erb +5 -0
- data/registry/test/components/previews/ui/button_to_preview/with_icon.html.erb +11 -0
- data/registry/test/components/previews/ui/button_to_preview.rb +21 -0
- data/registry/test/components/previews/ui/card_preview/complete.html.erb +31 -0
- data/registry/test/components/previews/ui/card_preview/default.html.erb +7 -0
- data/registry/test/components/previews/ui/card_preview/settings_form.html.erb +25 -0
- data/registry/test/components/previews/ui/card_preview/with_footer.html.erb +13 -0
- data/registry/test/components/previews/ui/card_preview/with_header.html.erb +11 -0
- data/registry/test/components/previews/ui/card_preview.rb +44 -0
- data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +9 -0
- data/registry/test/components/previews/ui/checkbox_preview/states.html.erb +22 -0
- data/registry/test/components/previews/ui/checkbox_preview/with_label.html.erb +5 -0
- data/registry/test/components/previews/ui/checkbox_preview.rb +27 -0
- data/registry/test/components/previews/ui/data_grid_preview.rb +18 -0
- data/registry/test/components/previews/ui/date_picker_preview/default.html.erb +3 -0
- data/registry/test/components/previews/ui/date_picker_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/date_picker_preview.rb +13 -0
- data/registry/test/components/previews/ui/dialog_preview/confirmation.html.erb +11 -0
- data/registry/test/components/previews/ui/dialog_preview/custom_trigger.html.erb +16 -0
- data/registry/test/components/previews/ui/dialog_preview/default.html.erb +15 -0
- data/registry/test/components/previews/ui/dialog_preview/long_content.html.erb +16 -0
- data/registry/test/components/previews/ui/dialog_preview/playground.html.erb +12 -0
- data/registry/test/components/previews/ui/dialog_preview/scrollable_body.html.erb +29 -0
- data/registry/test/components/previews/ui/dialog_preview/sizes.html.erb +46 -0
- data/registry/test/components/previews/ui/dialog_preview/without_close_button.html.erb +11 -0
- data/registry/test/components/previews/ui/dialog_preview/without_title.html.erb +13 -0
- data/registry/test/components/previews/ui/dialog_preview.rb +38 -0
- data/registry/test/components/previews/ui/divider_preview/horizontal.html.erb +5 -0
- data/registry/test/components/previews/ui/divider_preview/vertical.html.erb +9 -0
- data/registry/test/components/previews/ui/divider_preview/with_label.html.erb +5 -0
- data/registry/test/components/previews/ui/divider_preview.rb +19 -0
- data/registry/test/components/previews/ui/icon_preview/common.html.erb +8 -0
- data/registry/test/components/previews/ui/icon_preview/sizes.html.erb +7 -0
- data/registry/test/components/previews/ui/icon_preview.rb +20 -0
- data/registry/test/components/previews/ui/image_preview/radii.html.erb +8 -0
- data/registry/test/components/previews/ui/image_preview/sizing.html.erb +9 -0
- data/registry/test/components/previews/ui/image_preview.rb +16 -0
- data/registry/test/components/previews/ui/input_group_preview/addons.html.erb +29 -0
- data/registry/test/components/previews/ui/input_group_preview/playground.html.erb +12 -0
- data/registry/test/components/previews/ui/input_group_preview.rb +17 -0
- data/registry/test/components/previews/ui/input_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/input_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/input_preview/with_labels.html.erb +10 -0
- data/registry/test/components/previews/ui/input_preview.rb +33 -0
- data/registry/test/components/previews/ui/label_preview/sizes.html.erb +6 -0
- data/registry/test/components/previews/ui/label_preview/states.html.erb +6 -0
- data/registry/test/components/previews/ui/label_preview/weights.html.erb +5 -0
- data/registry/test/components/previews/ui/label_preview.rb +22 -0
- data/registry/test/components/previews/ui/link_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/link_preview/variants.html.erb +8 -0
- data/registry/test/components/previews/ui/link_preview/with_icons.html.erb +11 -0
- data/registry/test/components/previews/ui/link_preview.rb +20 -0
- data/registry/test/components/previews/ui/menu_preview/positions.html.erb +122 -0
- data/registry/test/components/previews/ui/menu_preview/variants.html.erb +218 -0
- data/registry/test/components/previews/ui/menu_preview.rb +26 -0
- data/registry/test/components/previews/ui/native_select_preview/sizes.html.erb +6 -0
- data/registry/test/components/previews/ui/native_select_preview/states.html.erb +6 -0
- data/registry/test/components/previews/ui/native_select_preview.rb +23 -0
- data/registry/test/components/previews/ui/pagination_preview/states.html.erb +15 -0
- data/registry/test/components/previews/ui/pagination_preview.rb +15 -0
- data/registry/test/components/previews/ui/password_input_preview/states.html.erb +19 -0
- data/registry/test/components/previews/ui/password_input_preview.rb +21 -0
- data/registry/test/components/previews/ui/popover_preview/default.html.erb +7 -0
- data/registry/test/components/previews/ui/popover_preview/positions.html.erb +30 -0
- data/registry/test/components/previews/ui/popover_preview/with_close_button.html.erb +8 -0
- data/registry/test/components/previews/ui/popover_preview/with_rich_content.html.erb +17 -0
- data/registry/test/components/previews/ui/popover_preview/without_title.html.erb +9 -0
- data/registry/test/components/previews/ui/popover_preview.rb +32 -0
- data/registry/test/components/previews/ui/radio_group_preview/default.html.erb +10 -0
- data/registry/test/components/previews/ui/radio_group_preview/disabled.html.erb +17 -0
- data/registry/test/components/previews/ui/radio_group_preview/with_required.html.erb +10 -0
- data/registry/test/components/previews/ui/radio_group_preview.rb +25 -0
- data/registry/test/components/previews/ui/select_preview/default.html.erb +4 -0
- data/registry/test/components/previews/ui/select_preview/long_list.html.erb +5 -0
- data/registry/test/components/previews/ui/select_preview/multiple.html.erb +6 -0
- data/registry/test/components/previews/ui/select_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/select_preview/states.html.erb +6 -0
- data/registry/test/components/previews/ui/select_preview.rb +45 -0
- data/registry/test/components/previews/ui/sheet_preview/bottom.html.erb +12 -0
- data/registry/test/components/previews/ui/sheet_preview/left.html.erb +10 -0
- data/registry/test/components/previews/ui/sheet_preview/playground.html.erb +15 -0
- data/registry/test/components/previews/ui/sheet_preview/right.html.erb +11 -0
- data/registry/test/components/previews/ui/sheet_preview/top.html.erb +8 -0
- data/registry/test/components/previews/ui/sheet_preview.rb +22 -0
- data/registry/test/components/previews/ui/sidebar_preview/_brand.html.erb +14 -0
- data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +60 -0
- data/registry/test/components/previews/ui/sidebar_preview/collapsible.html.erb +55 -0
- data/registry/test/components/previews/ui/sidebar_preview/default.html.erb +17 -0
- data/registry/test/components/previews/ui/sidebar_preview/with_dropdown_header.html.erb +33 -0
- data/registry/test/components/previews/ui/sidebar_preview/with_groups.html.erb +22 -0
- data/registry/test/components/previews/ui/sidebar_preview.rb +15 -0
- data/registry/test/components/previews/ui/spinner_preview/in_buttons.html.erb +7 -0
- data/registry/test/components/previews/ui/spinner_preview/sizes.html.erb +7 -0
- data/registry/test/components/previews/ui/spinner_preview.rb +19 -0
- data/registry/test/components/previews/ui/switch_preview/default.html.erb +4 -0
- data/registry/test/components/previews/ui/switch_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/switch_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/switch_preview.rb +26 -0
- data/registry/test/components/previews/ui/table_preview/customers.html.erb +15 -0
- data/registry/test/components/previews/ui/table_preview/empty.html.erb +8 -0
- data/registry/test/components/previews/ui/table_preview/with_caption.html.erb +14 -0
- data/registry/test/components/previews/ui/table_preview.rb +12 -0
- data/registry/test/components/previews/ui/tabs_preview/default.html.erb +39 -0
- data/registry/test/components/previews/ui/tabs_preview/pill_variant.html.erb +18 -0
- data/registry/test/components/previews/ui/tabs_preview/settings_form.html.erb +42 -0
- data/registry/test/components/previews/ui/tabs_preview/with_icons.html.erb +34 -0
- data/registry/test/components/previews/ui/tabs_preview.rb +33 -0
- data/registry/test/components/previews/ui/text_preview/sizes.html.erb +10 -0
- data/registry/test/components/previews/ui/text_preview/tones.html.erb +5 -0
- data/registry/test/components/previews/ui/text_preview/weights.html.erb +6 -0
- data/registry/test/components/previews/ui/text_preview.rb +26 -0
- data/registry/test/components/previews/ui/theme_toggle_preview/in_a_header.html.erb +14 -0
- data/registry/test/components/previews/ui/theme_toggle_preview/palette.html.erb +47 -0
- data/registry/test/components/previews/ui/theme_toggle_preview.rb +15 -0
- data/registry/test/components/previews/ui/tooltip_preview/default.html.erb +8 -0
- data/registry/test/components/previews/ui/tooltip_preview/positions.html.erb +34 -0
- data/registry/test/components/previews/ui/tooltip_preview/with_button.html.erb +8 -0
- data/registry/test/components/previews/ui/tooltip_preview/with_icon.html.erb +10 -0
- data/registry/test/components/previews/ui/tooltip_preview.rb +29 -0
- data/registry/test/components/previews/ui/typography_preview/article.html.erb +11 -0
- data/registry/test/components/previews/ui/typography_preview/code_and_quotes.html.erb +6 -0
- data/registry/test/components/previews/ui/typography_preview/headings.html.erb +6 -0
- data/registry/test/components/previews/ui/typography_preview/text_styles.html.erb +7 -0
- data/registry/test/components/previews/ui/typography_preview.rb +23 -0
- data/registry/test/components/ui/accordion/content_test.rb +64 -0
- data/registry/test/components/ui/accordion/item_test.rb +61 -0
- data/registry/test/components/ui/accordion/trigger_test.rb +80 -0
- data/registry/test/components/ui/accordion_test.rb +96 -0
- data/registry/test/components/ui/alert/description_test.rb +37 -0
- data/registry/test/components/ui/alert/title_test.rb +38 -0
- data/registry/test/components/ui/alert_test.rb +184 -0
- data/registry/test/components/ui/avatar_group_test.rb +79 -0
- data/registry/test/components/ui/avatar_test.rb +129 -0
- data/registry/test/components/ui/badge_test.rb +112 -0
- data/registry/test/components/ui/banner_test.rb +116 -0
- data/registry/test/components/ui/base_test.rb +98 -0
- data/registry/test/components/ui/breadcrumb/ellipsis_test.rb +51 -0
- data/registry/test/components/ui/breadcrumb/item_test.rb +39 -0
- data/registry/test/components/ui/breadcrumb/list_test.rb +34 -0
- data/registry/test/components/ui/breadcrumb/separator_test.rb +36 -0
- data/registry/test/components/ui/breadcrumb_test.rb +276 -0
- data/registry/test/components/ui/button_test.rb +276 -0
- data/registry/test/components/ui/button_to_test.rb +74 -0
- data/registry/test/components/ui/card/content_test.rb +41 -0
- data/registry/test/components/ui/card/description_test.rb +32 -0
- data/registry/test/components/ui/card/footer_test.rb +34 -0
- data/registry/test/components/ui/card/header_test.rb +57 -0
- data/registry/test/components/ui/card/title_test.rb +34 -0
- data/registry/test/components/ui/card_test.rb +67 -0
- data/registry/test/components/ui/checkbox_test.rb +236 -0
- data/registry/test/components/ui/data_grid_test.rb +88 -0
- data/registry/test/components/ui/date_picker_test.rb +168 -0
- data/registry/test/components/ui/dialog/content_test.rb +156 -0
- data/registry/test/components/ui/dialog/trigger_test.rb +74 -0
- data/registry/test/components/ui/dialog_test.rb +54 -0
- data/registry/test/components/ui/divider_test.rb +69 -0
- data/registry/test/components/ui/icon_test.rb +82 -0
- data/registry/test/components/ui/image_test.rb +74 -0
- data/registry/test/components/ui/input_group_test.rb +143 -0
- data/registry/test/components/ui/input_test.rb +251 -0
- data/registry/test/components/ui/label_test.rb +96 -0
- data/registry/test/components/ui/link_test.rb +95 -0
- data/registry/test/components/ui/menu/content_test.rb +233 -0
- data/registry/test/components/ui/menu/group_test.rb +24 -0
- data/registry/test/components/ui/menu/item_test.rb +76 -0
- data/registry/test/components/ui/menu/label_test.rb +43 -0
- data/registry/test/components/ui/menu/separator_test.rb +32 -0
- data/registry/test/components/ui/menu/trigger_test.rb +109 -0
- data/registry/test/components/ui/menu_test.rb +152 -0
- data/registry/test/components/ui/native_select_test.rb +118 -0
- data/registry/test/components/ui/pagination_test.rb +92 -0
- data/registry/test/components/ui/password_input_test.rb +98 -0
- data/registry/test/components/ui/popover/content_test.rb +226 -0
- data/registry/test/components/ui/popover/trigger_test.rb +83 -0
- data/registry/test/components/ui/popover_test.rb +101 -0
- data/registry/test/components/ui/radio_group/item_test.rb +14 -0
- data/registry/test/components/ui/radio_group_test.rb +139 -0
- data/registry/test/components/ui/select_test.rb +181 -0
- data/registry/test/components/ui/sheet/content_test.rb +135 -0
- data/registry/test/components/ui/sheet/trigger_test.rb +23 -0
- data/registry/test/components/ui/sheet_test.rb +43 -0
- data/registry/test/components/ui/sidebar/menu_button_test.rb +43 -0
- data/registry/test/components/ui/sidebar/trigger_test.rb +17 -0
- data/registry/test/components/ui/sidebar/wrapper_test.rb +15 -0
- data/registry/test/components/ui/sidebar_test.rb +43 -0
- data/registry/test/components/ui/spinner_test.rb +63 -0
- data/registry/test/components/ui/switch_test.rb +206 -0
- data/registry/test/components/ui/table_test.rb +106 -0
- data/registry/test/components/ui/tabs/content_test.rb +93 -0
- data/registry/test/components/ui/tabs/list_test.rb +65 -0
- data/registry/test/components/ui/tabs/trigger_test.rb +159 -0
- data/registry/test/components/ui/tabs_test.rb +88 -0
- data/registry/test/components/ui/text_test.rb +84 -0
- data/registry/test/components/ui/theme_toggle_test.rb +88 -0
- data/registry/test/components/ui/tooltip/content_test.rb +135 -0
- data/registry/test/components/ui/tooltip/trigger_test.rb +52 -0
- data/registry/test/components/ui/tooltip_test.rb +97 -0
- data/registry/test/components/ui/typography/code_blockquote_test.rb +57 -0
- data/registry/test/components/ui/typography/heading_test.rb +71 -0
- data/registry/test/components/ui/typography/text_variants_test.rb +71 -0
- metadata +540 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
import { useFloating, type Placement } from './_internal/use_floating.js';
|
|
3
|
+
import { useDismiss } from './_internal/use_dismiss.js';
|
|
4
|
+
|
|
5
|
+
export default class extends Controller<HTMLElement> {
|
|
6
|
+
static targets = ['trigger', 'content'];
|
|
7
|
+
|
|
8
|
+
declare readonly triggerTarget: HTMLButtonElement;
|
|
9
|
+
declare readonly contentTarget: HTMLElement;
|
|
10
|
+
|
|
11
|
+
private floatingCleanup: (() => void) | null = null;
|
|
12
|
+
private dismissCleanup: (() => void) | null = null;
|
|
13
|
+
private isOpen = false;
|
|
14
|
+
|
|
15
|
+
connect() {
|
|
16
|
+
this.close();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
disconnect() {
|
|
20
|
+
this.cleanup();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toggle(event: Event) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
if (this.isOpen) {
|
|
26
|
+
this.close();
|
|
27
|
+
} else {
|
|
28
|
+
this.open();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
open() {
|
|
33
|
+
if (this.isOpen) return;
|
|
34
|
+
|
|
35
|
+
const placement = this.getPlacement();
|
|
36
|
+
const floating = useFloating(this.triggerTarget, this.contentTarget, {
|
|
37
|
+
placement,
|
|
38
|
+
offset: 4,
|
|
39
|
+
flip: true,
|
|
40
|
+
shift: true,
|
|
41
|
+
});
|
|
42
|
+
this.floatingCleanup = floating.destroy;
|
|
43
|
+
|
|
44
|
+
const dismiss = useDismiss(this.contentTarget, {
|
|
45
|
+
outsideClick: true,
|
|
46
|
+
escapeKey: true,
|
|
47
|
+
outsideClickExclude: this.triggerTarget,
|
|
48
|
+
onDismiss: () => this.close(),
|
|
49
|
+
});
|
|
50
|
+
this.dismissCleanup = dismiss.destroy;
|
|
51
|
+
|
|
52
|
+
this.contentTarget.removeAttribute('hidden');
|
|
53
|
+
this.contentTarget.dataset.state = 'open';
|
|
54
|
+
this.triggerTarget.setAttribute('aria-expanded', 'true');
|
|
55
|
+
|
|
56
|
+
// Focus the checked option if this is a radio menu, else the first item.
|
|
57
|
+
this.focusInitialItem();
|
|
58
|
+
|
|
59
|
+
this.isOpen = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
close() {
|
|
63
|
+
if (!this.isOpen) return;
|
|
64
|
+
|
|
65
|
+
this.cleanup();
|
|
66
|
+
|
|
67
|
+
this.contentTarget.setAttribute('hidden', '');
|
|
68
|
+
this.contentTarget.dataset.state = 'closed';
|
|
69
|
+
this.triggerTarget.setAttribute('aria-expanded', 'false');
|
|
70
|
+
|
|
71
|
+
// Return focus to trigger
|
|
72
|
+
this.triggerTarget.focus();
|
|
73
|
+
|
|
74
|
+
this.isOpen = false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private cleanup() {
|
|
78
|
+
if (this.floatingCleanup) {
|
|
79
|
+
this.floatingCleanup();
|
|
80
|
+
this.floatingCleanup = null;
|
|
81
|
+
}
|
|
82
|
+
if (this.dismissCleanup) {
|
|
83
|
+
this.dismissCleanup();
|
|
84
|
+
this.dismissCleanup = null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Keyboard navigation on trigger
|
|
89
|
+
triggerKeydown(event: KeyboardEvent) {
|
|
90
|
+
switch (event.key) {
|
|
91
|
+
case 'ArrowDown':
|
|
92
|
+
case 'ArrowUp':
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
this.open();
|
|
95
|
+
// After open, focus the appropriate item
|
|
96
|
+
if (event.key === 'ArrowDown') {
|
|
97
|
+
this.focusFirstItem();
|
|
98
|
+
} else {
|
|
99
|
+
this.focusLastItem();
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case 'Enter':
|
|
103
|
+
case ' ':
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
this.open();
|
|
106
|
+
this.focusFirstItem();
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Keyboard navigation within menu
|
|
112
|
+
contentKeydown(event: KeyboardEvent) {
|
|
113
|
+
const items = this.enabledItems;
|
|
114
|
+
const currentIndex = items.indexOf(document.activeElement as HTMLElement);
|
|
115
|
+
|
|
116
|
+
switch (event.key) {
|
|
117
|
+
case 'ArrowDown':
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
this.focusNextItem(items, currentIndex);
|
|
120
|
+
break;
|
|
121
|
+
case 'ArrowUp':
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
this.focusPreviousItem(items, currentIndex);
|
|
124
|
+
break;
|
|
125
|
+
case 'Home':
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
this.focusFirstItem();
|
|
128
|
+
break;
|
|
129
|
+
case 'End':
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
this.focusLastItem();
|
|
132
|
+
break;
|
|
133
|
+
case 'Tab':
|
|
134
|
+
// Close menu on Tab, let default tab behavior continue
|
|
135
|
+
this.close();
|
|
136
|
+
break;
|
|
137
|
+
case 'Enter':
|
|
138
|
+
case ' ':
|
|
139
|
+
// Activate the focused item
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
(document.activeElement as HTMLElement)?.click();
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private get enabledItems(): HTMLElement[] {
|
|
147
|
+
return Array.from(
|
|
148
|
+
this.contentTarget.querySelectorAll('[data-ui--menu-target="item"]:not([data-disabled])')
|
|
149
|
+
) as HTMLElement[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// WAI-ARIA: opening a menu that contains a checked menuitemradio /
|
|
153
|
+
// menuitemcheckbox should move focus to that item rather than the first.
|
|
154
|
+
private focusInitialItem() {
|
|
155
|
+
const checked = this.enabledItems.find(
|
|
156
|
+
(item) => item.getAttribute('aria-checked') === 'true',
|
|
157
|
+
);
|
|
158
|
+
if (checked) {
|
|
159
|
+
checked.focus();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.focusFirstItem();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private focusFirstItem() {
|
|
166
|
+
const items = this.enabledItems;
|
|
167
|
+
if (items.length > 0) {
|
|
168
|
+
items[0]?.focus();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private focusLastItem() {
|
|
173
|
+
const items = this.enabledItems;
|
|
174
|
+
if (items.length > 0) {
|
|
175
|
+
items[items.length - 1]?.focus();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private focusNextItem(items: HTMLElement[], currentIndex: number) {
|
|
180
|
+
if (items.length === 0) return;
|
|
181
|
+
const nextIndex = currentIndex >= 0 && currentIndex < items.length - 1 ? currentIndex + 1 : 0;
|
|
182
|
+
items[nextIndex]?.focus();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private focusPreviousItem(items: HTMLElement[], currentIndex: number) {
|
|
186
|
+
if (items.length === 0) return;
|
|
187
|
+
const prevIndex = currentIndex > 0 ? currentIndex - 1 : items.length - 1;
|
|
188
|
+
items[prevIndex]?.focus();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private getPlacement(): Placement {
|
|
192
|
+
const side = this.contentTarget.dataset.side || 'bottom';
|
|
193
|
+
const align = this.contentTarget.dataset.align || 'start';
|
|
194
|
+
|
|
195
|
+
if (align === 'center') {
|
|
196
|
+
return side as Placement;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return `${side}-${align}` as Placement;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// Connects to data-controller="ui--password-visibility"
|
|
4
|
+
//
|
|
5
|
+
// Toggles a password field between masked and plain text, swapping the
|
|
6
|
+
// eye/eye-off icons and keeping the trigger's accessible name and pressed
|
|
7
|
+
// state in sync so screen readers announce the change.
|
|
8
|
+
export default class extends Controller<HTMLElement> {
|
|
9
|
+
static targets = ['input', 'toggle', 'iconShow', 'iconHide'];
|
|
10
|
+
|
|
11
|
+
declare readonly hasInputTarget: boolean;
|
|
12
|
+
declare readonly hasToggleTarget: boolean;
|
|
13
|
+
declare readonly hasIconShowTarget: boolean;
|
|
14
|
+
declare readonly hasIconHideTarget: boolean;
|
|
15
|
+
declare readonly inputTarget: HTMLInputElement;
|
|
16
|
+
declare readonly toggleTarget: HTMLElement;
|
|
17
|
+
declare readonly iconShowTarget: HTMLElement;
|
|
18
|
+
declare readonly iconHideTarget: HTMLElement;
|
|
19
|
+
|
|
20
|
+
toggle(event?: Event) {
|
|
21
|
+
event?.preventDefault();
|
|
22
|
+
if (!this.hasInputTarget) return;
|
|
23
|
+
|
|
24
|
+
const revealed = this.inputTarget.type === 'text';
|
|
25
|
+
this.inputTarget.type = revealed ? 'password' : 'text';
|
|
26
|
+
this.sync(!revealed);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private sync(revealed: boolean) {
|
|
30
|
+
// Inline styles, to match the server-rendered initial state and to stay
|
|
31
|
+
// immune to any competing display utility.
|
|
32
|
+
if (this.hasIconShowTarget) this.iconShowTarget.style.display = revealed ? 'none' : '';
|
|
33
|
+
if (this.hasIconHideTarget) this.iconHideTarget.style.display = revealed ? '' : 'none';
|
|
34
|
+
|
|
35
|
+
if (this.hasToggleTarget) {
|
|
36
|
+
this.toggleTarget.setAttribute('aria-pressed', revealed ? 'true' : 'false');
|
|
37
|
+
this.toggleTarget.setAttribute(
|
|
38
|
+
'aria-label',
|
|
39
|
+
revealed ? 'Hide password' : 'Show password',
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
import { useFloating, type Placement } from './_internal/use_floating.js';
|
|
3
|
+
import { useDismiss } from './_internal/use_dismiss.js';
|
|
4
|
+
|
|
5
|
+
export default class extends Controller<HTMLElement> {
|
|
6
|
+
static targets = ['trigger', 'content', 'arrow'];
|
|
7
|
+
|
|
8
|
+
declare readonly triggerTarget: HTMLButtonElement;
|
|
9
|
+
declare readonly contentTarget: HTMLElement;
|
|
10
|
+
declare readonly arrowTarget: HTMLElement;
|
|
11
|
+
|
|
12
|
+
private floatingCleanup: (() => void) | null = null;
|
|
13
|
+
private dismissCleanup: (() => void) | null = null;
|
|
14
|
+
private isOpen = false;
|
|
15
|
+
|
|
16
|
+
connect() {
|
|
17
|
+
// Initialize with content hidden
|
|
18
|
+
this.close();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
disconnect() {
|
|
22
|
+
this.cleanup();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toggle() {
|
|
26
|
+
if (this.isOpen) {
|
|
27
|
+
this.close();
|
|
28
|
+
} else {
|
|
29
|
+
this.open();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
open() {
|
|
34
|
+
if (this.isOpen) return;
|
|
35
|
+
|
|
36
|
+
const placement = this.getPlacement();
|
|
37
|
+
const floating = useFloating(this.triggerTarget, this.contentTarget, {
|
|
38
|
+
placement,
|
|
39
|
+
offset: 8,
|
|
40
|
+
flip: true,
|
|
41
|
+
shift: true,
|
|
42
|
+
arrow: this.arrowTarget,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this.floatingCleanup = floating.destroy;
|
|
46
|
+
|
|
47
|
+
// Set up dismiss handlers
|
|
48
|
+
const dismiss = useDismiss(this.contentTarget, {
|
|
49
|
+
outsideClick: true,
|
|
50
|
+
escapeKey: true,
|
|
51
|
+
focusOut: true,
|
|
52
|
+
outsideClickExclude: this.triggerTarget,
|
|
53
|
+
onDismiss: (reason) => {
|
|
54
|
+
this.close();
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
this.dismissCleanup = dismiss.destroy;
|
|
58
|
+
|
|
59
|
+
// Show content
|
|
60
|
+
this.contentTarget.removeAttribute('hidden');
|
|
61
|
+
this.contentTarget.dataset.state = 'open';
|
|
62
|
+
|
|
63
|
+
// Update trigger aria
|
|
64
|
+
this.triggerTarget.setAttribute('aria-expanded', 'true');
|
|
65
|
+
|
|
66
|
+
// Focus the content for accessibility
|
|
67
|
+
this.contentTarget.focus();
|
|
68
|
+
|
|
69
|
+
this.isOpen = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
close() {
|
|
73
|
+
if (!this.isOpen) return;
|
|
74
|
+
|
|
75
|
+
this.cleanup();
|
|
76
|
+
|
|
77
|
+
// Hide content
|
|
78
|
+
this.contentTarget.setAttribute('hidden', '');
|
|
79
|
+
this.contentTarget.dataset.state = 'closed';
|
|
80
|
+
|
|
81
|
+
// Update trigger aria
|
|
82
|
+
this.triggerTarget.setAttribute('aria-expanded', 'false');
|
|
83
|
+
|
|
84
|
+
this.isOpen = false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private cleanup() {
|
|
88
|
+
if (this.floatingCleanup) {
|
|
89
|
+
this.floatingCleanup();
|
|
90
|
+
this.floatingCleanup = null;
|
|
91
|
+
}
|
|
92
|
+
if (this.dismissCleanup) {
|
|
93
|
+
this.dismissCleanup();
|
|
94
|
+
this.dismissCleanup = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private getPlacement(): Placement {
|
|
99
|
+
const side = this.contentTarget.dataset.side || 'top';
|
|
100
|
+
const align = this.contentTarget.dataset.align || 'center';
|
|
101
|
+
|
|
102
|
+
if (align === 'center') {
|
|
103
|
+
return side as Placement;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return `${side}-${align}` as Placement;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
import { useFloating } from './_internal/use_floating.js';
|
|
3
|
+
import { useDismiss } from './_internal/use_dismiss.js';
|
|
4
|
+
|
|
5
|
+
// Connects to data-controller="ui--select"
|
|
6
|
+
//
|
|
7
|
+
// The WAI-ARIA select-only combobox, with an optional search box. Focus stays
|
|
8
|
+
// on the trigger, or moves to the search box when there is one; either way
|
|
9
|
+
// the highlighted option is announced through aria-activedescendant.
|
|
10
|
+
//
|
|
11
|
+
// The hidden native <select> holds the value. Every pick is written to it and
|
|
12
|
+
// announced with `input` and `change`, so forms and listeners see an ordinary
|
|
13
|
+
// select. A multiple select stays open while you tick options.
|
|
14
|
+
export default class extends Controller<HTMLElement> {
|
|
15
|
+
static targets = ['trigger', 'value', 'panel', 'listbox', 'option', 'native', 'search', 'empty'];
|
|
16
|
+
static values = { multiple: Boolean, summary: String, placeholder: String };
|
|
17
|
+
|
|
18
|
+
declare readonly triggerTarget: HTMLButtonElement;
|
|
19
|
+
declare readonly valueTarget: HTMLElement;
|
|
20
|
+
declare readonly panelTarget: HTMLElement;
|
|
21
|
+
declare readonly optionTargets: HTMLElement[];
|
|
22
|
+
declare readonly nativeTarget: HTMLSelectElement;
|
|
23
|
+
declare readonly hasSearchTarget: boolean;
|
|
24
|
+
declare readonly searchTarget: HTMLInputElement;
|
|
25
|
+
declare readonly hasEmptyTarget: boolean;
|
|
26
|
+
declare readonly emptyTarget: HTMLElement;
|
|
27
|
+
declare readonly multipleValue: boolean;
|
|
28
|
+
declare readonly summaryValue: string;
|
|
29
|
+
declare readonly placeholderValue: string;
|
|
30
|
+
|
|
31
|
+
private isOpen = false;
|
|
32
|
+
private active: HTMLElement | null = null;
|
|
33
|
+
private typed = '';
|
|
34
|
+
private typedAt = 0;
|
|
35
|
+
private floatingCleanup: (() => void) | null = null;
|
|
36
|
+
private dismissCleanup: (() => void) | null = null;
|
|
37
|
+
private onReset = () => requestAnimationFrame(() => this.sync());
|
|
38
|
+
private onInvalid = () => this.triggerTarget.setAttribute('aria-invalid', 'true');
|
|
39
|
+
|
|
40
|
+
connect() {
|
|
41
|
+
this.nativeTarget.form?.addEventListener('reset', this.onReset);
|
|
42
|
+
this.nativeTarget.addEventListener('invalid', this.onInvalid);
|
|
43
|
+
this.sync();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
disconnect() {
|
|
47
|
+
this.nativeTarget.form?.removeEventListener('reset', this.onReset);
|
|
48
|
+
this.nativeTarget.removeEventListener('invalid', this.onInvalid);
|
|
49
|
+
this.teardown();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
toggle(event: Event) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
if (this.isOpen) this.close();
|
|
55
|
+
else this.open();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Keys on the trigger and, when there is one, the search box.
|
|
59
|
+
keydown(event: KeyboardEvent) {
|
|
60
|
+
const fromSearch = event.currentTarget === (this.hasSearchTarget ? this.searchTarget : null);
|
|
61
|
+
|
|
62
|
+
if (!this.isOpen) {
|
|
63
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
this.open(event.key === 'ArrowUp' ? 'last' : 'first');
|
|
66
|
+
} else if (this.isPrintable(event) && !this.multipleValue) {
|
|
67
|
+
this.typeahead(event.key, true);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const visible = this.visible();
|
|
73
|
+
const index = this.active ? visible.indexOf(this.active) : -1;
|
|
74
|
+
const step = (to: number) => {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
this.highlight(visible[Math.max(0, Math.min(to, visible.length - 1))]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
switch (event.key) {
|
|
80
|
+
case 'ArrowDown': return step(index + 1);
|
|
81
|
+
case 'ArrowUp': return step(index - 1);
|
|
82
|
+
case 'PageDown': return step(index + 10);
|
|
83
|
+
case 'PageUp': return step(index - 10);
|
|
84
|
+
case 'Home': if (!fromSearch) step(0); return;
|
|
85
|
+
case 'End': if (!fromSearch) step(visible.length - 1); return;
|
|
86
|
+
case 'Enter':
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
if (this.active) this.pick(this.active);
|
|
89
|
+
return;
|
|
90
|
+
case ' ':
|
|
91
|
+
if (fromSearch) return; // a space is part of the search
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
if (this.active) this.pick(this.active);
|
|
94
|
+
return;
|
|
95
|
+
case 'Escape':
|
|
96
|
+
// Only the dropdown: not the Dialog or Sheet it may sit in.
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
this.close();
|
|
100
|
+
return;
|
|
101
|
+
case 'Tab':
|
|
102
|
+
this.close(false);
|
|
103
|
+
return;
|
|
104
|
+
default:
|
|
105
|
+
if (!fromSearch && this.isPrintable(event)) this.typeahead(event.key, false);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
filter() {
|
|
110
|
+
if (!this.hasSearchTarget) return;
|
|
111
|
+
|
|
112
|
+
const query = this.searchTarget.value.trim().toLowerCase();
|
|
113
|
+
this.optionTargets.forEach((option) => {
|
|
114
|
+
option.hidden = query !== '' && !this.label(option).toLowerCase().includes(query);
|
|
115
|
+
});
|
|
116
|
+
const visible = this.visible();
|
|
117
|
+
if (this.hasEmptyTarget) this.emptyTarget.hidden = visible.length > 0;
|
|
118
|
+
if (!this.active || this.active.hidden) this.highlight(visible[0] ?? null);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
choose(event: Event) {
|
|
122
|
+
this.pick(event.currentTarget as HTMLElement);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
hover(event: Event) {
|
|
126
|
+
const option = event.currentTarget as HTMLElement;
|
|
127
|
+
if (option !== this.active) this.highlight(option, false);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Clicking inside the list must not take focus away.
|
|
131
|
+
keepFocus(event: Event) {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private open(start: 'first' | 'last' = 'first') {
|
|
136
|
+
if (this.isOpen || this.triggerTarget.disabled) return;
|
|
137
|
+
|
|
138
|
+
this.panelTarget.style.minWidth = `${this.triggerTarget.offsetWidth}px`;
|
|
139
|
+
this.floatingCleanup = useFloating(this.triggerTarget, this.panelTarget, {
|
|
140
|
+
placement: 'bottom-start',
|
|
141
|
+
offset: 4,
|
|
142
|
+
strategy: 'fixed',
|
|
143
|
+
}).destroy;
|
|
144
|
+
this.dismissCleanup = useDismiss(this.panelTarget, {
|
|
145
|
+
escapeKey: false, // handled in keydown, so it can stop at the dropdown
|
|
146
|
+
outsideClickExclude: this.triggerTarget,
|
|
147
|
+
onDismiss: () => this.close(false),
|
|
148
|
+
}).destroy;
|
|
149
|
+
|
|
150
|
+
this.panelTarget.hidden = false;
|
|
151
|
+
this.panelTarget.dataset.state = 'open';
|
|
152
|
+
this.triggerTarget.setAttribute('aria-expanded', 'true');
|
|
153
|
+
this.isOpen = true;
|
|
154
|
+
|
|
155
|
+
if (this.hasSearchTarget) {
|
|
156
|
+
this.searchTarget.value = '';
|
|
157
|
+
this.filter();
|
|
158
|
+
this.searchTarget.focus();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const chosen = this.optionTargets.find((o) => o.getAttribute('aria-selected') === 'true' && o.dataset.value !== '');
|
|
162
|
+
const visible = this.visible();
|
|
163
|
+
this.highlight(chosen ?? (start === 'last' ? visible[visible.length - 1] : visible[0]) ?? null);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private close(refocus = true) {
|
|
167
|
+
if (!this.isOpen) return;
|
|
168
|
+
|
|
169
|
+
this.teardown();
|
|
170
|
+
this.panelTarget.hidden = true;
|
|
171
|
+
this.panelTarget.dataset.state = 'closed';
|
|
172
|
+
this.triggerTarget.setAttribute('aria-expanded', 'false');
|
|
173
|
+
this.focusTarget().removeAttribute('aria-activedescendant');
|
|
174
|
+
this.highlight(null);
|
|
175
|
+
this.isOpen = false;
|
|
176
|
+
if (refocus) this.triggerTarget.focus();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private pick(option: HTMLElement) {
|
|
180
|
+
const value = option.dataset.value ?? '';
|
|
181
|
+
const native = this.nativeTarget;
|
|
182
|
+
const before = Array.from(native.selectedOptions).map((o) => o.value).join('\n');
|
|
183
|
+
|
|
184
|
+
if (this.multipleValue) {
|
|
185
|
+
const item = Array.from(native.options).find((o) => o.value === value);
|
|
186
|
+
if (item) item.selected = !item.selected;
|
|
187
|
+
} else {
|
|
188
|
+
native.value = value;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
this.sync();
|
|
192
|
+
if (!this.multipleValue) this.close();
|
|
193
|
+
|
|
194
|
+
if (Array.from(native.selectedOptions).map((o) => o.value).join('\n') !== before) {
|
|
195
|
+
native.dispatchEvent(new Event('input', { bubbles: true }));
|
|
196
|
+
native.dispatchEvent(new Event('change', { bubbles: true }));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Ticks and trigger text, from the native select's current state.
|
|
201
|
+
private sync() {
|
|
202
|
+
const chosen = new Set(Array.from(this.nativeTarget.selectedOptions).map((o) => o.value));
|
|
203
|
+
this.optionTargets.forEach((option) => {
|
|
204
|
+
const on = chosen.has(option.dataset.value ?? '');
|
|
205
|
+
option.setAttribute('aria-selected', String(on));
|
|
206
|
+
const check = option.querySelector<HTMLElement>('[data-ui--select-target="check"]');
|
|
207
|
+
if (check) check.hidden = !on;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const labels = this.optionTargets
|
|
211
|
+
.filter((o) => o.dataset.value !== '' && chosen.has(o.dataset.value ?? ''))
|
|
212
|
+
.map((o) => this.label(o));
|
|
213
|
+
const text = labels.length > 2 ? this.summaryValue.replace('%{count}', String(labels.length)) : labels.join(', ');
|
|
214
|
+
this.valueTarget.textContent = text || this.placeholderValue;
|
|
215
|
+
this.valueTarget.classList.toggle('text-muted-foreground', !text);
|
|
216
|
+
if (this.nativeTarget.checkValidity()) this.triggerTarget.removeAttribute('aria-invalid');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private highlight(option: HTMLElement | null, scroll = true) {
|
|
220
|
+
this.optionTargets.forEach((o) => {
|
|
221
|
+
if (o === option) o.dataset.highlighted = '';
|
|
222
|
+
else delete o.dataset.highlighted;
|
|
223
|
+
});
|
|
224
|
+
this.active = option;
|
|
225
|
+
if (!option) return;
|
|
226
|
+
|
|
227
|
+
this.focusTarget().setAttribute('aria-activedescendant', option.id);
|
|
228
|
+
if (scroll) option.scrollIntoView({ block: 'nearest' });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Jump to the next option starting with what was typed in the last half
|
|
232
|
+
// second. Closed, it changes the value directly, as a native select does.
|
|
233
|
+
private typeahead(key: string, closed: boolean) {
|
|
234
|
+
const now = Date.now();
|
|
235
|
+
this.typed = now - this.typedAt > 500 ? key : this.typed + key;
|
|
236
|
+
this.typedAt = now;
|
|
237
|
+
|
|
238
|
+
const query = this.typed.toLowerCase();
|
|
239
|
+
const options = this.visible();
|
|
240
|
+
const current = closed
|
|
241
|
+
? options.findIndex((o) => o.getAttribute('aria-selected') === 'true')
|
|
242
|
+
: options.indexOf(this.active as HTMLElement);
|
|
243
|
+
const ordered = [...options.slice(current + 1), ...options.slice(0, current + 1)];
|
|
244
|
+
const match = ordered.find((o) => this.label(o).toLowerCase().startsWith(query));
|
|
245
|
+
if (!match) return;
|
|
246
|
+
|
|
247
|
+
if (closed) this.pick(match);
|
|
248
|
+
else this.highlight(match);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private visible() {
|
|
252
|
+
return this.optionTargets.filter((o) => !o.hidden);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private label(option: HTMLElement) {
|
|
256
|
+
return option.textContent?.trim() ?? '';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Where keyboard focus sits while the list is open.
|
|
260
|
+
private focusTarget(): HTMLElement {
|
|
261
|
+
return this.hasSearchTarget ? this.searchTarget : this.triggerTarget;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private isPrintable(event: KeyboardEvent) {
|
|
265
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private teardown() {
|
|
269
|
+
this.floatingCleanup?.();
|
|
270
|
+
this.dismissCleanup?.();
|
|
271
|
+
this.floatingCleanup = null;
|
|
272
|
+
this.dismissCleanup = null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
type SidebarState = 'collapsed' | 'expanded';
|
|
4
|
+
type CollapsibleType = 'icon' | 'none';
|
|
5
|
+
|
|
6
|
+
export default class extends Controller<HTMLElement> {
|
|
7
|
+
static targets = ['sidebar', 'trigger'];
|
|
8
|
+
|
|
9
|
+
declare readonly hasSidebarTarget: boolean;
|
|
10
|
+
declare readonly hasTriggerTarget: boolean;
|
|
11
|
+
declare readonly sidebarTarget: HTMLElement;
|
|
12
|
+
declare readonly triggerTargets: HTMLElement[];
|
|
13
|
+
|
|
14
|
+
connect() {
|
|
15
|
+
if (!this.hasSidebarTarget) return;
|
|
16
|
+
|
|
17
|
+
const savedState = localStorage.getItem('ui-sidebar-state') as SidebarState | null;
|
|
18
|
+
const savedCollapsible = localStorage.getItem('ui-sidebar-collapsible') as CollapsibleType | null;
|
|
19
|
+
|
|
20
|
+
if (savedState && savedCollapsible) {
|
|
21
|
+
this.setSidebarState(savedState);
|
|
22
|
+
this.setSidebarCollapsibleType(savedCollapsible);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.syncTriggers();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toggle() {
|
|
29
|
+
if (!this.hasSidebarTarget) return;
|
|
30
|
+
|
|
31
|
+
if (this.sidebarState() === 'collapsed') {
|
|
32
|
+
this.setSidebarState('expanded');
|
|
33
|
+
this.setSidebarCollapsibleType('none');
|
|
34
|
+
} else {
|
|
35
|
+
this.setSidebarState('collapsed');
|
|
36
|
+
this.setSidebarCollapsibleType('icon');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.syncTriggers();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private sidebarState(): SidebarState {
|
|
43
|
+
return (this.sidebarTarget.getAttribute('data-state') as SidebarState) || 'expanded';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private setSidebarState(state: SidebarState) {
|
|
47
|
+
localStorage.setItem('ui-sidebar-state', state);
|
|
48
|
+
this.sidebarTarget.setAttribute('data-state', state);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private setSidebarCollapsibleType(type: CollapsibleType) {
|
|
52
|
+
localStorage.setItem('ui-sidebar-collapsible', type);
|
|
53
|
+
this.sidebarTarget.setAttribute('data-collapsible', type);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private syncTriggers() {
|
|
57
|
+
if (!this.hasTriggerTarget) return;
|
|
58
|
+
|
|
59
|
+
const expanded = this.sidebarState() !== 'collapsed';
|
|
60
|
+
this.triggerTargets.forEach((trigger) => {
|
|
61
|
+
trigger.setAttribute('aria-expanded', expanded ? 'true' : 'false');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|