velvetkit 0.2.2 → 0.4.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 +4 -4
- data/CHANGELOG.md +80 -0
- data/README.md +30 -8
- data/lib/generators/velvetkit/add/add_generator.rb +77 -0
- data/lib/generators/velvetkit/helpers.rb +29 -2
- data/lib/generators/velvetkit/icons/icons_generator.rb +71 -0
- data/lib/generators/velvetkit/install/install_generator.rb +9 -12
- data/lib/velvetkit/icons.rb +148 -0
- data/lib/velvetkit/registry.rb +5 -2
- data/lib/velvetkit/version.rb +4 -1
- data/lib/velvetkit.rb +8 -0
- data/registry/app/assets/tailwind/velvetkit.css +90 -155
- data/registry/app/components/ui/alert.rb +1 -1
- data/registry/app/components/ui/chart.html.erb +47 -0
- data/registry/app/components/ui/chart.rb +177 -0
- data/registry/app/components/ui/command/group.rb +27 -0
- data/registry/app/components/ui/command/item.rb +64 -0
- data/registry/app/components/ui/command.html.erb +41 -0
- data/registry/app/components/ui/command.rb +122 -0
- data/registry/app/components/ui/confirm_dialog.html.erb +13 -0
- data/registry/app/components/ui/confirm_dialog.rb +55 -0
- data/registry/app/components/ui/date_picker.html.erb +58 -64
- data/registry/app/components/ui/date_picker.rb +199 -75
- data/registry/app/components/ui/empty_state.html.erb +20 -0
- data/registry/app/components/ui/empty_state.rb +46 -0
- data/registry/app/components/ui/file_field.html.erb +14 -4
- data/registry/app/components/ui/file_field.rb +179 -28
- data/registry/app/components/ui/gallery/image.rb +20 -0
- data/registry/app/components/ui/gallery.html.erb +52 -0
- data/registry/app/components/ui/gallery.rb +164 -0
- data/registry/app/components/ui/icon.html.erb +1 -1
- data/registry/app/components/ui/icon.rb +80 -8
- data/registry/app/components/ui/kbd.html.erb +27 -0
- data/registry/app/components/ui/kbd.rb +134 -0
- data/registry/app/components/ui/number_input.html.erb +11 -0
- data/registry/app/components/ui/number_input.rb +103 -0
- data/registry/app/components/ui/password_input.html.erb +1 -1
- data/registry/app/components/ui/progress/segment.rb +25 -0
- data/registry/app/components/ui/progress.html.erb +25 -0
- data/registry/app/components/ui/progress.rb +182 -0
- data/registry/app/components/ui/select.html.erb +24 -5
- data/registry/app/components/ui/select.rb +44 -5
- data/registry/app/components/ui/stepper/step.html.erb +27 -0
- data/registry/app/components/ui/stepper/step.rb +213 -0
- data/registry/app/components/ui/stepper.html.erb +19 -0
- data/registry/app/components/ui/stepper.rb +145 -0
- data/registry/app/components/ui/theme_toggle.rb +2 -4
- data/registry/app/components/ui/timeline/item.html.erb +21 -0
- data/registry/app/components/ui/timeline/item.rb +145 -0
- data/registry/app/components/ui/timeline.html.erb +1 -0
- data/registry/app/components/ui/timeline.rb +42 -0
- data/registry/app/components/ui/toast.rb +6 -6
- data/registry/app/components/ui/toggle_group/item.html.erb +1 -0
- data/registry/app/components/ui/toggle_group/item.rb +85 -0
- data/registry/app/components/ui/toggle_group.html.erb +1 -0
- data/registry/app/components/ui/toggle_group.rb +79 -0
- data/registry/app/javascript/chart_js.ts +37 -0
- data/registry/app/javascript/controllers/ui/_internal/date_format.ts +74 -0
- data/registry/app/javascript/controllers/ui/_internal/shortcut.ts +80 -0
- data/registry/app/javascript/controllers/ui/chart_controller.ts +585 -0
- data/registry/app/javascript/controllers/ui/command_controller.ts +454 -0
- data/registry/app/javascript/controllers/ui/confirm_dialog_controller.ts +110 -0
- data/registry/app/javascript/controllers/ui/date_picker_controller.ts +247 -82
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +288 -16
- data/registry/app/javascript/controllers/ui/gallery_controller.ts +568 -0
- data/registry/app/javascript/controllers/ui/kbd_controller.ts +60 -0
- data/registry/app/javascript/controllers/ui/number_input_controller.ts +111 -0
- data/registry/app/javascript/controllers/ui/progress_controller.ts +87 -0
- data/registry/app/javascript/controllers/ui/select_controller.ts +198 -8
- data/registry/app/javascript/controllers/ui/stepper_controller.ts +187 -0
- data/registry/app/javascript/vanilla_calendar.ts +15 -0
- data/registry/components.yml +28 -5
- data/registry/config/locales/velvetkit.en.yml +84 -0
- data/registry/docs/agents.md +7 -4
- data/registry/icons/lucide/LICENSE +39 -0
- data/registry/icons/lucide/align-center.svg +17 -0
- data/registry/icons/lucide/align-left.svg +17 -0
- data/registry/icons/lucide/align-right.svg +17 -0
- data/registry/icons/lucide/arrow-left.svg +16 -0
- data/registry/icons/lucide/arrow-right.svg +16 -0
- data/registry/icons/lucide/badge-check.svg +16 -0
- data/registry/icons/lucide/bar-chart-3.svg +18 -0
- data/registry/icons/lucide/bell.svg +16 -0
- data/registry/icons/lucide/bold.svg +15 -0
- data/registry/icons/lucide/book-open.svg +16 -0
- data/registry/icons/lucide/calendar.svg +18 -0
- data/registry/icons/lucide/chart-column.svg +18 -0
- data/registry/icons/lucide/check.svg +15 -0
- data/registry/icons/lucide/chevron-down.svg +15 -0
- data/registry/icons/lucide/chevron-left.svg +15 -0
- data/registry/icons/lucide/chevron-right.svg +15 -0
- data/registry/icons/lucide/chevrons-up-down.svg +16 -0
- data/registry/icons/lucide/circle-alert.svg +17 -0
- data/registry/icons/lucide/circle-check.svg +16 -0
- data/registry/icons/lucide/cloud.svg +15 -0
- data/registry/icons/lucide/credit-card.svg +16 -0
- data/registry/icons/lucide/download.svg +17 -0
- data/registry/icons/lucide/ellipsis-vertical.svg +17 -0
- data/registry/icons/lucide/ellipsis.svg +17 -0
- data/registry/icons/lucide/eye-off.svg +18 -0
- data/registry/icons/lucide/eye.svg +16 -0
- data/registry/icons/lucide/file-plus.svg +18 -0
- data/registry/icons/lucide/file-text.svg +19 -0
- data/registry/icons/lucide/file.svg +16 -0
- data/registry/icons/lucide/folder-kanban.svg +18 -0
- data/registry/icons/lucide/folder.svg +15 -0
- data/registry/icons/lucide/git-branch.svg +18 -0
- data/registry/icons/lucide/globe.svg +17 -0
- data/registry/icons/lucide/graduation-cap.svg +17 -0
- data/registry/icons/lucide/grip-vertical.svg +20 -0
- data/registry/icons/lucide/home.svg +16 -0
- data/registry/icons/lucide/inbox.svg +16 -0
- data/registry/icons/lucide/info.svg +17 -0
- data/registry/icons/lucide/italic.svg +17 -0
- data/registry/icons/lucide/keyboard.svg +23 -0
- data/registry/icons/lucide/layout-dashboard.svg +18 -0
- data/registry/icons/lucide/layout-grid.svg +18 -0
- data/registry/icons/lucide/life-buoy.svg +20 -0
- data/registry/icons/lucide/list.svg +20 -0
- data/registry/icons/lucide/loader.svg +22 -0
- data/registry/icons/lucide/lock.svg +16 -0
- data/registry/icons/lucide/log-out.svg +17 -0
- data/registry/icons/lucide/mail.svg +16 -0
- data/registry/icons/lucide/menu.svg +17 -0
- data/registry/icons/lucide/message-circle.svg +15 -0
- data/registry/icons/lucide/minus.svg +15 -0
- data/registry/icons/lucide/monitor.svg +17 -0
- data/registry/icons/lucide/moon.svg +15 -0
- data/registry/icons/lucide/newspaper.svg +18 -0
- data/registry/icons/lucide/package.svg +18 -0
- data/registry/icons/lucide/panel-left.svg +16 -0
- data/registry/icons/lucide/pause.svg +16 -0
- data/registry/icons/lucide/percent.svg +17 -0
- data/registry/icons/lucide/plus.svg +16 -0
- data/registry/icons/lucide/printer.svg +17 -0
- data/registry/icons/lucide/qr-code.svg +26 -0
- data/registry/icons/lucide/receipt.svg +17 -0
- data/registry/icons/lucide/rocket.svg +18 -0
- data/registry/icons/lucide/rotate-cw.svg +16 -0
- data/registry/icons/lucide/search.svg +16 -0
- data/registry/icons/lucide/settings.svg +16 -0
- data/registry/icons/lucide/shield-check.svg +16 -0
- data/registry/icons/lucide/shield.svg +15 -0
- data/registry/icons/lucide/store.svg +17 -0
- data/registry/icons/lucide/sun-moon.svg +19 -0
- data/registry/icons/lucide/sun.svg +23 -0
- data/registry/icons/lucide/trash-2.svg +19 -0
- data/registry/icons/lucide/truck.svg +19 -0
- data/registry/icons/lucide/underline.svg +16 -0
- data/registry/icons/lucide/upload.svg +17 -0
- data/registry/icons/lucide/user-plus.svg +18 -0
- data/registry/icons/lucide/user.svg +16 -0
- data/registry/icons/lucide/users.svg +18 -0
- data/registry/icons/lucide/workflow.svg +17 -0
- data/registry/icons/lucide/x.svg +16 -0
- data/registry/icons/lucide/zoom-in.svg +18 -0
- data/registry/icons/lucide/zoom-out.svg +17 -0
- data/registry/icons/phosphor/LICENSE +21 -0
- data/registry/icons/phosphor/arrow-clockwise.svg +2 -0
- data/registry/icons/phosphor/arrow-left.svg +2 -0
- data/registry/icons/phosphor/arrow-right.svg +2 -0
- data/registry/icons/phosphor/bell.svg +2 -0
- data/registry/icons/phosphor/book-open.svg +2 -0
- data/registry/icons/phosphor/calendar-blank.svg +2 -0
- data/registry/icons/phosphor/caret-down.svg +2 -0
- data/registry/icons/phosphor/caret-left.svg +2 -0
- data/registry/icons/phosphor/caret-right.svg +2 -0
- data/registry/icons/phosphor/caret-up-down.svg +2 -0
- data/registry/icons/phosphor/chart-bar.svg +2 -0
- data/registry/icons/phosphor/chat-circle.svg +2 -0
- data/registry/icons/phosphor/check-circle.svg +2 -0
- data/registry/icons/phosphor/check.svg +2 -0
- data/registry/icons/phosphor/circle-half.svg +2 -0
- data/registry/icons/phosphor/cloud.svg +2 -0
- data/registry/icons/phosphor/credit-card.svg +2 -0
- data/registry/icons/phosphor/desktop.svg +2 -0
- data/registry/icons/phosphor/dots-six-vertical.svg +2 -0
- data/registry/icons/phosphor/dots-three-vertical.svg +2 -0
- data/registry/icons/phosphor/dots-three.svg +2 -0
- data/registry/icons/phosphor/download-simple.svg +2 -0
- data/registry/icons/phosphor/envelope.svg +2 -0
- data/registry/icons/phosphor/eye-slash.svg +2 -0
- data/registry/icons/phosphor/eye.svg +2 -0
- data/registry/icons/phosphor/file-plus.svg +2 -0
- data/registry/icons/phosphor/file-text.svg +2 -0
- data/registry/icons/phosphor/file.svg +2 -0
- data/registry/icons/phosphor/flow-arrow.svg +2 -0
- data/registry/icons/phosphor/folder.svg +2 -0
- data/registry/icons/phosphor/gear.svg +2 -0
- data/registry/icons/phosphor/git-branch.svg +2 -0
- data/registry/icons/phosphor/globe.svg +2 -0
- data/registry/icons/phosphor/graduation-cap.svg +2 -0
- data/registry/icons/phosphor/grid-four.svg +2 -0
- data/registry/icons/phosphor/house.svg +2 -0
- data/registry/icons/phosphor/info.svg +2 -0
- data/registry/icons/phosphor/kanban.svg +2 -0
- data/registry/icons/phosphor/keyboard.svg +2 -0
- data/registry/icons/phosphor/lifebuoy.svg +2 -0
- data/registry/icons/phosphor/list.svg +2 -0
- data/registry/icons/phosphor/lock.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass-minus.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass-plus.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass.svg +2 -0
- data/registry/icons/phosphor/minus.svg +2 -0
- data/registry/icons/phosphor/moon.svg +2 -0
- data/registry/icons/phosphor/newspaper.svg +2 -0
- data/registry/icons/phosphor/package.svg +2 -0
- data/registry/icons/phosphor/pause.svg +2 -0
- data/registry/icons/phosphor/percent.svg +2 -0
- data/registry/icons/phosphor/plus.svg +2 -0
- data/registry/icons/phosphor/printer.svg +2 -0
- data/registry/icons/phosphor/qr-code.svg +2 -0
- data/registry/icons/phosphor/receipt.svg +2 -0
- data/registry/icons/phosphor/rocket.svg +2 -0
- data/registry/icons/phosphor/seal-check.svg +2 -0
- data/registry/icons/phosphor/shield-check.svg +2 -0
- data/registry/icons/phosphor/shield.svg +2 -0
- data/registry/icons/phosphor/sidebar.svg +2 -0
- data/registry/icons/phosphor/sign-out.svg +2 -0
- data/registry/icons/phosphor/spinner.svg +2 -0
- data/registry/icons/phosphor/squares-four.svg +2 -0
- data/registry/icons/phosphor/storefront.svg +2 -0
- data/registry/icons/phosphor/sun.svg +2 -0
- data/registry/icons/phosphor/text-align-center.svg +2 -0
- data/registry/icons/phosphor/text-align-left.svg +2 -0
- data/registry/icons/phosphor/text-align-right.svg +2 -0
- data/registry/icons/phosphor/text-b.svg +2 -0
- data/registry/icons/phosphor/text-italic.svg +2 -0
- data/registry/icons/phosphor/text-underline.svg +2 -0
- data/registry/icons/phosphor/trash.svg +2 -0
- data/registry/icons/phosphor/tray.svg +2 -0
- data/registry/icons/phosphor/truck.svg +2 -0
- data/registry/icons/phosphor/upload-simple.svg +2 -0
- data/registry/icons/phosphor/user-plus.svg +2 -0
- data/registry/icons/phosphor/user.svg +2 -0
- data/registry/icons/phosphor/users.svg +2 -0
- data/registry/icons/phosphor/warning-circle.svg +2 -0
- data/registry/icons/phosphor/x.svg +2 -0
- data/registry/icons/tabler/LICENSE +21 -0
- data/registry/icons/tabler/alert-circle.svg +18 -0
- data/registry/icons/tabler/align-center.svg +18 -0
- data/registry/icons/tabler/align-left.svg +18 -0
- data/registry/icons/tabler/align-right.svg +18 -0
- data/registry/icons/tabler/arrow-left.svg +18 -0
- data/registry/icons/tabler/arrow-right.svg +18 -0
- data/registry/icons/tabler/bell.svg +17 -0
- data/registry/icons/tabler/bold.svg +17 -0
- data/registry/icons/tabler/book.svg +20 -0
- data/registry/icons/tabler/building-store.svg +20 -0
- data/registry/icons/tabler/calendar.svg +21 -0
- data/registry/icons/tabler/chart-bar.svg +19 -0
- data/registry/icons/tabler/check.svg +16 -0
- data/registry/icons/tabler/chevron-down.svg +16 -0
- data/registry/icons/tabler/chevron-left.svg +16 -0
- data/registry/icons/tabler/chevron-right.svg +16 -0
- data/registry/icons/tabler/circle-check.svg +17 -0
- data/registry/icons/tabler/cloud.svg +16 -0
- data/registry/icons/tabler/credit-card.svg +19 -0
- data/registry/icons/tabler/device-desktop.svg +19 -0
- data/registry/icons/tabler/dots-vertical.svg +18 -0
- data/registry/icons/tabler/dots.svg +18 -0
- data/registry/icons/tabler/download.svg +18 -0
- data/registry/icons/tabler/eye-off.svg +18 -0
- data/registry/icons/tabler/eye.svg +17 -0
- data/registry/icons/tabler/file-plus.svg +19 -0
- data/registry/icons/tabler/file-text.svg +20 -0
- data/registry/icons/tabler/file.svg +17 -0
- data/registry/icons/tabler/folder.svg +16 -0
- data/registry/icons/tabler/git-branch.svg +21 -0
- data/registry/icons/tabler/grip-vertical.svg +21 -0
- data/registry/icons/tabler/home.svg +18 -0
- data/registry/icons/tabler/inbox.svg +17 -0
- data/registry/icons/tabler/info-circle.svg +18 -0
- data/registry/icons/tabler/italic.svg +18 -0
- data/registry/icons/tabler/keyboard.svg +23 -0
- data/registry/icons/tabler/layout-dashboard.svg +19 -0
- data/registry/icons/tabler/layout-grid.svg +19 -0
- data/registry/icons/tabler/layout-kanban.svg +19 -0
- data/registry/icons/tabler/layout-sidebar.svg +17 -0
- data/registry/icons/tabler/lifebuoy.svg +21 -0
- data/registry/icons/tabler/list.svg +21 -0
- data/registry/icons/tabler/loader.svg +23 -0
- data/registry/icons/tabler/lock.svg +18 -0
- data/registry/icons/tabler/logout.svg +18 -0
- data/registry/icons/tabler/mail.svg +17 -0
- data/registry/icons/tabler/menu-2.svg +18 -0
- data/registry/icons/tabler/message-circle.svg +16 -0
- data/registry/icons/tabler/minus.svg +16 -0
- data/registry/icons/tabler/moon.svg +16 -0
- data/registry/icons/tabler/news.svg +19 -0
- data/registry/icons/tabler/package.svg +20 -0
- data/registry/icons/tabler/percentage.svg +18 -0
- data/registry/icons/tabler/player-pause.svg +17 -0
- data/registry/icons/tabler/plus.svg +17 -0
- data/registry/icons/tabler/printer.svg +18 -0
- data/registry/icons/tabler/qrcode.svg +27 -0
- data/registry/icons/tabler/receipt.svg +16 -0
- data/registry/icons/tabler/rocket.svg +18 -0
- data/registry/icons/tabler/rosette-discount-check.svg +17 -0
- data/registry/icons/tabler/rotate-clockwise.svg +16 -0
- data/registry/icons/tabler/school.svg +17 -0
- data/registry/icons/tabler/search.svg +17 -0
- data/registry/icons/tabler/selector.svg +17 -0
- data/registry/icons/tabler/settings.svg +17 -0
- data/registry/icons/tabler/shield-check.svg +17 -0
- data/registry/icons/tabler/shield.svg +16 -0
- data/registry/icons/tabler/sitemap.svg +20 -0
- data/registry/icons/tabler/sun-moon.svg +21 -0
- data/registry/icons/tabler/sun.svg +17 -0
- data/registry/icons/tabler/trash.svg +20 -0
- data/registry/icons/tabler/truck.svg +18 -0
- data/registry/icons/tabler/underline.svg +17 -0
- data/registry/icons/tabler/upload.svg +18 -0
- data/registry/icons/tabler/user-plus.svg +19 -0
- data/registry/icons/tabler/user.svg +17 -0
- data/registry/icons/tabler/users.svg +19 -0
- data/registry/icons/tabler/world.svg +20 -0
- data/registry/icons/tabler/x.svg +17 -0
- data/registry/icons/tabler/zoom-in.svg +19 -0
- data/registry/icons/tabler/zoom-out.svg +18 -0
- data/registry/icons.yml +90 -0
- data/registry/test/components/previews/ui/chart_preview/cash_flow.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/donut.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/margin.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/pie.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/sales.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/stock.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/takings.html.erb +8 -0
- data/registry/test/components/previews/ui/chart_preview.rb +46 -0
- data/registry/test/components/previews/ui/command_preview/_picked.html.erb +14 -0
- data/registry/test/components/previews/ui/command_preview/dialog.html.erb +24 -0
- data/registry/test/components/previews/ui/command_preview/inline.html.erb +16 -0
- data/registry/test/components/previews/ui/command_preview/playground.html.erb +15 -0
- data/registry/test/components/previews/ui/command_preview/server_search.html.erb +24 -0
- data/registry/test/components/previews/ui/command_preview/shortcuts.html.erb +12 -0
- data/registry/test/components/previews/ui/command_preview/till.html.erb +17 -0
- data/registry/test/components/previews/ui/command_preview.rb +25 -0
- data/registry/test/components/previews/ui/confirm_dialog_preview/destructive.html.erb +7 -0
- data/registry/test/components/previews/ui/confirm_dialog_preview/in_form.html.erb +6 -0
- data/registry/test/components/previews/ui/confirm_dialog_preview/on_link.html.erb +5 -0
- data/registry/test/components/previews/ui/confirm_dialog_preview/plain.html.erb +3 -0
- data/registry/test/components/previews/ui/confirm_dialog_preview/with_description.html.erb +4 -0
- data/registry/test/components/previews/ui/confirm_dialog_preview.rb +20 -0
- data/registry/test/components/previews/ui/date_picker_preview/custom_presets.html.erb +6 -0
- data/registry/test/components/previews/ui/date_picker_preview/in_form.html.erb +11 -0
- data/registry/test/components/previews/ui/date_picker_preview/range.html.erb +5 -0
- data/registry/test/components/previews/ui/date_picker_preview/states.html.erb +4 -3
- data/registry/test/components/previews/ui/date_picker_preview.rb +26 -6
- data/registry/test/components/previews/ui/empty_state_preview/in_card.html.erb +7 -0
- data/registry/test/components/previews/ui/empty_state_preview/no_results.html.erb +3 -0
- data/registry/test/components/previews/ui/empty_state_preview/outline.html.erb +3 -0
- data/registry/test/components/previews/ui/empty_state_preview/with_actions.html.erb +4 -0
- data/registry/test/components/previews/ui/empty_state_preview/with_media.html.erb +8 -0
- data/registry/test/components/previews/ui/empty_state_preview.rb +26 -0
- data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +1 -1
- data/registry/test/components/previews/ui/file_field_preview/product_photos.html.erb +12 -0
- data/registry/test/components/previews/ui/file_field_preview/single_image.html.erb +4 -0
- data/registry/test/components/previews/ui/file_field_preview.rb +32 -5
- data/registry/test/components/previews/ui/gallery_preview/hover_zoom.html.erb +13 -0
- data/registry/test/components/previews/ui/gallery_preview/landscape.html.erb +5 -0
- data/registry/test/components/previews/ui/gallery_preview/product_page.html.erb +13 -0
- data/registry/test/components/previews/ui/gallery_preview/single.html.erb +3 -0
- data/registry/test/components/previews/ui/gallery_preview.rb +45 -0
- data/registry/test/components/previews/ui/icon_preview/common.html.erb +19 -3
- data/registry/test/components/previews/ui/icon_preview/labelled.html.erb +4 -0
- data/registry/test/components/previews/ui/icon_preview/missing.html.erb +3 -0
- data/registry/test/components/previews/ui/icon_preview.rb +18 -3
- data/registry/test/components/previews/ui/input_group_preview/playground.html.erb +2 -2
- data/registry/test/components/previews/ui/input_group_preview.rb +3 -3
- data/registry/test/components/previews/ui/kbd_preview/bound.html.erb +20 -0
- data/registry/test/components/previews/ui/kbd_preview/keys.html.erb +13 -0
- data/registry/test/components/previews/ui/kbd_preview/menu.html.erb +13 -0
- data/registry/test/components/previews/ui/kbd_preview/search_field.html.erb +8 -0
- data/registry/test/components/previews/ui/kbd_preview/shortcuts_list.html.erb +17 -0
- data/registry/test/components/previews/ui/kbd_preview/till.html.erb +23 -0
- data/registry/test/components/previews/ui/kbd_preview/tooltip_and_buttons.html.erb +14 -0
- data/registry/test/components/previews/ui/kbd_preview.rb +32 -0
- data/registry/test/components/previews/ui/number_input_preview/cart.html.erb +11 -0
- data/registry/test/components/previews/ui/number_input_preview/decimals.html.erb +4 -0
- data/registry/test/components/previews/ui/number_input_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/number_input_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/number_input_preview/stock_adjustment.html.erb +3 -0
- data/registry/test/components/previews/ui/number_input_preview.rb +36 -0
- data/registry/test/components/previews/ui/progress_preview/file_upload.html.erb +36 -0
- data/registry/test/components/previews/ui/progress_preview/free_shipping.html.erb +4 -0
- data/registry/test/components/previews/ui/progress_preview/indeterminate.html.erb +4 -0
- data/registry/test/components/previews/ui/progress_preview/sizes_and_tones.html.erb +8 -0
- data/registry/test/components/previews/ui/progress_preview/steps.html.erb +9 -0
- data/registry/test/components/previews/ui/progress_preview/storage.html.erb +8 -0
- data/registry/test/components/previews/ui/progress_preview/storage_by_category.html.erb +7 -0
- data/registry/test/components/previews/ui/progress_preview/tasks_by_status.html.erb +14 -0
- data/registry/test/components/previews/ui/progress_preview/traffic_by_source.html.erb +15 -0
- data/registry/test/components/previews/ui/progress_preview.rb +46 -0
- data/registry/test/components/previews/ui/select_preview/server_search.html.erb +22 -0
- data/registry/test/components/previews/ui/select_preview.rb +5 -0
- data/registry/test/components/previews/ui/stepper_preview/approvals.html.erb +9 -0
- data/registry/test/components/previews/ui/stepper_preview/checklist.html.erb +12 -0
- data/registry/test/components/previews/ui/stepper_preview/dot_wizard.html.erb +41 -0
- data/registry/test/components/previews/ui/stepper_preview/failed_deploy.html.erb +13 -0
- data/registry/test/components/previews/ui/stepper_preview/inline.html.erb +31 -0
- data/registry/test/components/previews/ui/stepper_preview/onboarding.html.erb +12 -0
- data/registry/test/components/previews/ui/stepper_preview/order_tracking.html.erb +10 -0
- data/registry/test/components/previews/ui/stepper_preview/price_calculator.html.erb +14 -0
- data/registry/test/components/previews/ui/stepper_preview/server_driven.html.erb +20 -0
- data/registry/test/components/previews/ui/stepper_preview/sidebar.html.erb +43 -0
- data/registry/test/components/previews/ui/stepper_preview/wizard.html.erb +55 -0
- data/registry/test/components/previews/ui/stepper_preview.rb +57 -0
- data/registry/test/components/previews/ui/timeline_preview/activity_log.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/colored.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/colored_by_meaning.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/failed_delivery.html.erb +6 -0
- data/registry/test/components/previews/ui/timeline_preview/order_status.html.erb +9 -0
- data/registry/test/components/previews/ui/timeline_preview/real_dates.html.erb +5 -0
- data/registry/test/components/previews/ui/timeline_preview/stock_history.html.erb +6 -0
- data/registry/test/components/previews/ui/timeline_preview.rb +40 -0
- data/registry/test/components/previews/ui/toggle_group_preview/icon_only.html.erb +5 -0
- data/registry/test/components/previews/ui/toggle_group_preview/in_form.html.erb +11 -0
- data/registry/test/components/previews/ui/toggle_group_preview/multiple.html.erb +5 -0
- data/registry/test/components/previews/ui/toggle_group_preview/outline.html.erb +5 -0
- data/registry/test/components/previews/ui/toggle_group_preview/sizes.html.erb +9 -0
- data/registry/test/components/previews/ui/toggle_group_preview/with_icons.html.erb +5 -0
- data/registry/test/components/previews/ui/toggle_group_preview.rb +36 -0
- data/registry/test/components/ui/accordion/trigger_test.rb +1 -1
- data/registry/test/components/ui/alert_test.rb +10 -10
- data/registry/test/components/ui/badge_test.rb +3 -3
- data/registry/test/components/ui/banner_test.rb +3 -3
- data/registry/test/components/ui/breadcrumb/ellipsis_test.rb +2 -2
- data/registry/test/components/ui/button_test.rb +17 -14
- data/registry/test/components/ui/button_to_test.rb +2 -2
- data/registry/test/components/ui/chart_test.rb +187 -0
- data/registry/test/components/ui/checkbox_test.rb +2 -2
- data/registry/test/components/ui/command/group_test.rb +19 -0
- data/registry/test/components/ui/command/item_test.rb +47 -0
- data/registry/test/components/ui/command_test.rb +110 -0
- data/registry/test/components/ui/confirm_dialog_test.rb +68 -0
- data/registry/test/components/ui/date_picker_test.rb +129 -111
- data/registry/test/components/ui/empty_state_test.rb +87 -0
- data/registry/test/components/ui/file_field_test.rb +105 -9
- data/registry/test/components/ui/gallery_test.rb +192 -0
- data/registry/test/components/ui/icon_test.rb +60 -20
- data/registry/test/components/ui/input_group_test.rb +1 -1
- data/registry/test/components/ui/kbd_test.rb +150 -0
- data/registry/test/components/ui/link_test.rb +3 -3
- data/registry/test/components/ui/navigation_menu_test.rb +2 -2
- data/registry/test/components/ui/number_input_test.rb +155 -0
- data/registry/test/components/ui/progress_test.rb +188 -0
- data/registry/test/components/ui/select_test.rb +62 -0
- data/registry/test/components/ui/session_tabs_test.rb +3 -3
- data/registry/test/components/ui/spinner_test.rb +9 -9
- data/registry/test/components/ui/stepper_test.rb +239 -0
- data/registry/test/components/ui/tabs/trigger_test.rb +2 -2
- data/registry/test/components/ui/theme_toggle_test.rb +6 -8
- data/registry/test/components/ui/timeline_test.rb +175 -0
- data/registry/test/components/ui/toast_test.rb +11 -10
- data/registry/test/components/ui/toggle_group_test.rb +162 -0
- metadata +399 -3
- data/registry/app/javascript/cally.ts +0 -8
- data/registry/app/javascript/velvetkit_icons.ts +0 -78
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# A keyboard key, or a shortcut, written the way the reader's computer labels
|
|
4
|
+
# it. "mod" is ⌘ on a Mac and Ctrl elsewhere:
|
|
5
|
+
#
|
|
6
|
+
# <%= render(UI::Kbd.new("mod+k")) %> ⌘K, or Ctrl+K
|
|
7
|
+
# <%= render(UI::Kbd.new("shift+enter")) %> ⇧↵, or Shift+Enter
|
|
8
|
+
# <%= render(UI::Kbd.new(%w[g i])) %> G then I
|
|
9
|
+
# <%= render(UI::Kbd.new) { "Fn" } %> any key, as written
|
|
10
|
+
#
|
|
11
|
+
# It takes its colours from the text around it, so it reads the same in a
|
|
12
|
+
# paragraph, a menu, a tooltip or a filled button.
|
|
13
|
+
#
|
|
14
|
+
# Names: mod, cmd (meta), ctrl, alt (option), shift, enter, esc, tab, space,
|
|
15
|
+
# backspace, delete, up, down, left, right; anything else (k, /, F5) is shown
|
|
16
|
+
# as written. A letter is lowercase on its own (n, g then i), since that's what
|
|
17
|
+
# you type, and a capital with a modifier (⌘K), the way menus show it; Shift
|
|
18
|
+
# is always written out (⇧G), so a capital never means Shift. Screen readers
|
|
19
|
+
# hear the key's name, "Command", not the symbol.
|
|
20
|
+
#
|
|
21
|
+
# The Mac or not guess comes from the browser's user agent, so the page
|
|
22
|
+
# doesn't change once it's loaded; the controller corrects it if a cached
|
|
23
|
+
# page guessed for someone else.
|
|
24
|
+
#
|
|
25
|
+
# `bind: true` makes the shortcut press the button or link it sits in (a
|
|
26
|
+
# sequence can't be bound); `bind: "#save"` presses that element instead, or
|
|
27
|
+
# focuses it if it's a field, like "/" for search. It
|
|
28
|
+
# leaves typing alone, unless the shortcut uses mod, ctrl or alt, and the
|
|
29
|
+
# element gets aria-keyshortcuts so screen readers announce it.
|
|
30
|
+
class UI::Kbd < UI::Base
|
|
31
|
+
# name => [Mac symbol, Mac name, other label, other name]
|
|
32
|
+
KEYS = {
|
|
33
|
+
"mod" => [ "⌘", "Command", "Ctrl", "Control" ],
|
|
34
|
+
"cmd" => [ "⌘", "Command", "Win", "Windows" ],
|
|
35
|
+
"ctrl" => [ "⌃", "Control", "Ctrl", "Control" ],
|
|
36
|
+
"alt" => [ "⌥", "Option", "Alt", "Alt" ],
|
|
37
|
+
"shift" => [ "⇧", "Shift", "Shift", "Shift" ],
|
|
38
|
+
"enter" => [ "↵", "Return", "Enter", "Enter" ],
|
|
39
|
+
"esc" => [ "Esc", "Escape", "Esc", "Escape" ],
|
|
40
|
+
"tab" => [ "⇥", "Tab", "Tab", "Tab" ],
|
|
41
|
+
"space" => [ "Space", "Space", "Space", "Space" ],
|
|
42
|
+
"backspace" => [ "⌫", "Delete", "Backspace", "Backspace" ],
|
|
43
|
+
"delete" => [ "⌦", "Forward Delete", "Del", "Delete" ],
|
|
44
|
+
"up" => [ "↑", "Up Arrow", "↑", "Up Arrow" ],
|
|
45
|
+
"down" => [ "↓", "Down Arrow", "↓", "Down Arrow" ],
|
|
46
|
+
"left" => [ "←", "Left Arrow", "←", "Left Arrow" ],
|
|
47
|
+
"right" => [ "→", "Right Arrow", "→", "Right Arrow" ]
|
|
48
|
+
}.freeze
|
|
49
|
+
|
|
50
|
+
# Where Linux calls a key something else: the Windows key is Super there.
|
|
51
|
+
LINUX_KEYS = { "cmd" => [ "Super", "Super" ] }.freeze
|
|
52
|
+
|
|
53
|
+
ALIASES = { "command" => "cmd", "meta" => "cmd", "control" => "ctrl", "option" => "alt", "opt" => "alt",
|
|
54
|
+
"return" => "enter", "escape" => "esc", "del" => "delete", "arrowup" => "up",
|
|
55
|
+
"arrowdown" => "down", "arrowleft" => "left", "arrowright" => "right" }.freeze
|
|
56
|
+
|
|
57
|
+
SIZES = {
|
|
58
|
+
sm: "h-4 min-w-4 px-1 text-[10px]",
|
|
59
|
+
default: "h-5 min-w-5 px-1 text-xs",
|
|
60
|
+
lg: "h-6 min-w-6 px-1.5 text-sm"
|
|
61
|
+
}.freeze
|
|
62
|
+
|
|
63
|
+
KEY = "inline-flex items-center justify-center rounded-sm border border-current/15 bg-current/[0.07] " \
|
|
64
|
+
"font-sans font-medium leading-none tracking-normal whitespace-nowrap shadow-[0_1px_0] shadow-current/10"
|
|
65
|
+
|
|
66
|
+
APPLE = /Macintosh|Mac OS X|iPhone|iPad|iPod/
|
|
67
|
+
# A Linux desktop; Android and ChromeOS say Linux too, but don't call it Super.
|
|
68
|
+
LINUX = /Linux|X11/
|
|
69
|
+
NOT_LINUX = /Android|CrOS/
|
|
70
|
+
|
|
71
|
+
MODIFIERS = %w[mod cmd ctrl alt shift].freeze
|
|
72
|
+
|
|
73
|
+
def initialize(keys = nil, size: :default, bind: nil, class: nil, **html_attrs)
|
|
74
|
+
@keys = keys
|
|
75
|
+
@size = SIZES.key?(size.to_sym) ? size.to_sym : :default
|
|
76
|
+
@bind = bind
|
|
77
|
+
@user_class = binding.local_variable_get(:class)
|
|
78
|
+
@html_attrs = html_attrs
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# One combo per step: "mod+k" is one step, %w[g i] two.
|
|
82
|
+
def steps
|
|
83
|
+
Array(@keys).map { |combo| combo.to_s.split("+").map(&:strip).reject(&:empty?) }.reject(&:empty?)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def written? = @keys.nil?
|
|
87
|
+
|
|
88
|
+
# mac, linux, or other (Windows and the rest), as the user agent suggests.
|
|
89
|
+
def platform
|
|
90
|
+
agent = request&.user_agent.to_s
|
|
91
|
+
return "mac" if agent.match?(APPLE)
|
|
92
|
+
return "linux" if agent.match?(LINUX) && !agent.match?(NOT_LINUX)
|
|
93
|
+
|
|
94
|
+
"other"
|
|
95
|
+
rescue StandardError
|
|
96
|
+
"other"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# [label, name] for a key Linux names differently, or nil.
|
|
100
|
+
def linux_labels(key) = LINUX_KEYS[ALIASES.fetch(key.downcase, key.downcase)]
|
|
101
|
+
|
|
102
|
+
# [mac label, mac name, other label, other name] for one key of a combo.
|
|
103
|
+
def key_labels(key, combo = [ key ])
|
|
104
|
+
name = ALIASES.fetch(key.downcase, key.downcase)
|
|
105
|
+
return KEYS[name] if KEYS.key?(name)
|
|
106
|
+
|
|
107
|
+
label = key.length == 1 ? (modified?(combo) ? key.upcase : key.downcase) : key
|
|
108
|
+
[ label, label, label, label ]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def key_class = cn(KEY, SIZES[@size])
|
|
112
|
+
|
|
113
|
+
def modified?(combo) = combo.any? { |key| MODIFIERS.include?(ALIASES.fetch(key.downcase, key.downcase)) }
|
|
114
|
+
|
|
115
|
+
# One key: the symbol shown, its name for screen readers. A key that's
|
|
116
|
+
# already a word (Esc, F5) is just the word.
|
|
117
|
+
def key_tag(label, name, extra = nil)
|
|
118
|
+
face = label == name ? label : safe_join([ tag.span(label, aria: { hidden: true }), tag.span(name, class: "sr-only") ])
|
|
119
|
+
tag.kbd(face, class: cn(key_class, extra))
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def root_attrs
|
|
123
|
+
{ **@html_attrs, class: cn("group/kbd inline-flex items-center gap-1 align-middle font-sans font-normal text-current/80", @user_class),
|
|
124
|
+
data: { slot: "kbd", platform: platform, controller: "ui--kbd", **bind_data, **(@html_attrs[:data] || {}) } }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
def bind_data
|
|
130
|
+
return {} unless @bind && steps.size == 1
|
|
131
|
+
|
|
132
|
+
{ "ui--kbd-keys-value": steps.first.join("+"), "ui--kbd-target-value": (@bind == true ? "" : @bind.to_s) }
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<%# frozen_string_literal: true %>
|
|
2
|
+
<% group = capture do %><%= render(group_component) do |g| %>
|
|
3
|
+
<% g.with_field(**field_options) %>
|
|
4
|
+
<% g.with_addon(align: "inline-start", class: UI::NumberInput::ADDON_CLASSES) do %>
|
|
5
|
+
<%= render(UI::Button.new(**step_button_options(:decrement))) do %><%= render(UI::Icon.new(name: "minus", size: icon_size)) %><% end %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% g.with_addon(align: "inline-end", class: UI::NumberInput::ADDON_CLASSES) do %>
|
|
8
|
+
<%= render(UI::Button.new(**step_button_options(:increment))) do %><%= render(UI::Icon.new(name: "plus", size: icon_size)) %><% end %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<% end %><% end %>
|
|
11
|
+
<%= render(wrapper) { group } %>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "securerandom"
|
|
4
|
+
|
|
5
|
+
# A number field with - and + buttons, for quantities and stock counts. It's a
|
|
6
|
+
# real <input type="number">, so typing, arrow keys, `min:`, `max:`, `step:` and
|
|
7
|
+
# form validation all work as usual, and it takes the same label, hint, error
|
|
8
|
+
# and form-builder options as UI::Input.
|
|
9
|
+
#
|
|
10
|
+
# <%= render(UI::NumberInput.new(form: f, field: :quantity, min: 1, max: 99, class: "w-32")) %>
|
|
11
|
+
# <%= render(UI::NumberInput.new(name: "weight", value: 1.5, step: 0.25, size: :lg)) %>
|
|
12
|
+
#
|
|
13
|
+
# Holding a button keeps counting. Each step fires `input`, and `change` fires
|
|
14
|
+
# once when the button is let go, so a form that submits on change sends one
|
|
15
|
+
# request however long the button is held. A button turns off at its limit.
|
|
16
|
+
#
|
|
17
|
+
# The buttons are left out of the tab order: arrow keys do the same job from
|
|
18
|
+
# the field, and tabbing along a row of quantities shouldn't stop three times.
|
|
19
|
+
# Screen readers can still reach them. `size: :lg` is for touch screens.
|
|
20
|
+
class UI::NumberInput < UI::Base
|
|
21
|
+
SIZES = {
|
|
22
|
+
sm: { group: "h-8 [&>input]:text-xs", button: "w-8", icon: :xs },
|
|
23
|
+
default: { group: "h-9", button: "w-9", icon: :sm },
|
|
24
|
+
lg: { group: "h-12 [&>input]:text-base", button: "w-12", icon: :default }
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
# Reaches the field from the group, because UI::InputGroup::Field sets its own
|
|
28
|
+
# classes. The browser's spinner goes, in favour of the buttons.
|
|
29
|
+
GROUP_CLASSES = "[&>input]:h-full [&>input]:min-w-0 [&>input]:px-1 [&>input]:text-center " \
|
|
30
|
+
"[&>input]:[appearance:textfield] [&>input::-webkit-inner-spin-button]:appearance-none " \
|
|
31
|
+
"[&>input::-webkit-outer-spin-button]:appearance-none"
|
|
32
|
+
|
|
33
|
+
# The buttons fill the group's height, rather than the addon's usual inset.
|
|
34
|
+
ADDON_CLASSES = "cursor-default self-stretch p-0 has-[>button]:ml-0 has-[>button]:mr-0"
|
|
35
|
+
|
|
36
|
+
STEP_BUTTON = {
|
|
37
|
+
decrement: { label: "Decrease", direction: "down", edge: "rounded-e-none border-e border-input" },
|
|
38
|
+
increment: { label: "Increase", direction: "up", edge: "rounded-s-none border-s border-input" }
|
|
39
|
+
}.freeze
|
|
40
|
+
|
|
41
|
+
def initialize(size: :default, min: nil, max: nil, step: nil, form: nil, field: nil, label: nil, hint: nil,
|
|
42
|
+
required: false, disabled: false, error: nil, class: nil, **html_attrs)
|
|
43
|
+
@size = SIZES.key?(size.to_sym) ? size.to_sym : :default
|
|
44
|
+
@min = min
|
|
45
|
+
@max = max
|
|
46
|
+
@step = step
|
|
47
|
+
@form = form
|
|
48
|
+
@field = field
|
|
49
|
+
@required = required
|
|
50
|
+
@disabled = disabled
|
|
51
|
+
# The <input> is wrapped by the group's border, so the label has to sit
|
|
52
|
+
# outside it; give the field a stable id for the label to point at.
|
|
53
|
+
@input_id = html_attrs[:id] || "ui-number-input-#{SecureRandom.hex(4)}"
|
|
54
|
+
@user_class = binding.local_variable_get(:class)
|
|
55
|
+
@html_attrs = html_attrs
|
|
56
|
+
@wrapper = UI::FormField.new(label: label, hint: hint, error: error,
|
|
57
|
+
required: required, disabled: disabled,
|
|
58
|
+
form: form, field: field, for: @input_id)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
attr_reader :wrapper
|
|
62
|
+
|
|
63
|
+
def group_component
|
|
64
|
+
UI::InputGroup.new(class: cn(GROUP_CLASSES, SIZES[@size][:group], @user_class),
|
|
65
|
+
data: { controller: "ui--number-input" })
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def field_options
|
|
69
|
+
{ type: :number, form: @form, field: @field, label: false, required: @required, disabled: @disabled,
|
|
70
|
+
error: wrapper.error?, "aria-describedby": wrapper.describedby, min: @min, max: @max, step: @step,
|
|
71
|
+
inputmode: inputmode, **@html_attrs, id: @input_id, data: field_data }.compact
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def step_button_options(kind)
|
|
75
|
+
button = STEP_BUTTON.fetch(kind)
|
|
76
|
+
{ variant: :ghost, disabled: @disabled || @html_attrs[:readonly].present?, tabindex: -1,
|
|
77
|
+
# Lifted on focus, so the neighbouring field doesn't cover the kit's ring.
|
|
78
|
+
class: cn("relative h-full p-0 text-foreground select-none touch-manipulation focus:z-10 disabled:opacity-40",
|
|
79
|
+
SIZES[@size][:button], button[:edge]),
|
|
80
|
+
aria: { label: t("ui.number_input.#{kind}", default: button[:label]), controls: @input_id },
|
|
81
|
+
data: { "ui--number-input-target": kind.to_s, "ui--number-input-direction-param": button[:direction],
|
|
82
|
+
action: "pointerdown->ui--number-input#press click->ui--number-input#click" } }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def icon_size = SIZES[@size][:icon]
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
# The keypad a phone shows. Its number pad has no minus sign, so that's only
|
|
90
|
+
# for fields that can't go below zero.
|
|
91
|
+
def inputmode
|
|
92
|
+
return "decimal" if @step.to_s == "any" || @step.to_f % 1 != 0
|
|
93
|
+
return "numeric" if @min && @min.to_f >= 0
|
|
94
|
+
|
|
95
|
+
nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def field_data
|
|
99
|
+
data = @html_attrs[:data] || {}
|
|
100
|
+
action = [ "input->ui--number-input#sync change->ui--number-input#sync", data[:action] ].compact.join(" ")
|
|
101
|
+
data.merge("ui--number-input-target": "input", action: action)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%# frozen_string_literal: true %>
|
|
2
2
|
<%# The Stimulus targets live on wrapper spans, not the icons themselves:
|
|
3
|
-
UI::Icon sets its own `data: {
|
|
3
|
+
UI::Icon sets its own `data: { icon: ... }`, and a second `data:` hash
|
|
4
4
|
passed through html_attrs replaces it wholesale, leaving a blank icon.
|
|
5
5
|
Visibility uses an inline style rather than a `hidden` class so no
|
|
6
6
|
utility-layer ordering can leave both icons showing at once. %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# One part of a UI::Progress that's split by category, like the photos in a
|
|
4
|
+
# storage bar. Drawn by UI::Progress, not on its own.
|
|
5
|
+
#
|
|
6
|
+
# <% progress.with_segment(value: 6.4, label: "Photos") %>
|
|
7
|
+
# <% progress.with_segment(value: 2, label: "Backups", color: 5, value_text: "2 GB, last night") %>
|
|
8
|
+
#
|
|
9
|
+
# `color:` is one of the kit's five chart colours, 1 to 5; segments take them
|
|
10
|
+
# in order otherwise. `class:` sets anything else, like a background of your own.
|
|
11
|
+
class UI::Progress::Segment < UI::Base
|
|
12
|
+
attr_reader :label, :color, :user_class, :value_text
|
|
13
|
+
|
|
14
|
+
def initialize(value:, label:, color: nil, value_text: nil, class: nil)
|
|
15
|
+
@value = value
|
|
16
|
+
@label = label
|
|
17
|
+
@color = color
|
|
18
|
+
@value_text = value_text
|
|
19
|
+
@user_class = binding.local_variable_get(:class)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def value = [ @value.to_f, 0 ].max
|
|
23
|
+
|
|
24
|
+
def call = nil
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<%# frozen_string_literal: true %>
|
|
2
|
+
<%= tag.div(**root_attrs) do %>
|
|
3
|
+
<% if header? %>
|
|
4
|
+
<div class="flex items-baseline justify-between gap-3 text-sm">
|
|
5
|
+
<% if label.present? %><span id="<%= label_id %>" class="font-medium text-foreground"><%= label %></span><% end %>
|
|
6
|
+
<span class="<%= cn("ms-auto text-muted-foreground tabular-nums", ("hidden" unless show_value?)) %>" data-ui--progress-target="text" aria-hidden="true"><%= value_text %></span>
|
|
7
|
+
</div>
|
|
8
|
+
<% end %>
|
|
9
|
+
<%= tag.div(**bar_attrs) do %>
|
|
10
|
+
<%= tag.div(**indicator_attrs) do %>
|
|
11
|
+
<% segments.each_with_index do |segment, index| %><%= tag.div(**segment_attrs(segment, index)) %><% end %>
|
|
12
|
+
<% end %>
|
|
13
|
+
<% end %>
|
|
14
|
+
<% if legend? %>
|
|
15
|
+
<ul class="flex flex-wrap gap-x-4 gap-y-1 pt-1 text-sm" data-slot="progress-legend">
|
|
16
|
+
<% segments.each_with_index do |segment, index| %>
|
|
17
|
+
<li class="flex items-center gap-1.5">
|
|
18
|
+
<span class="<%= cn("size-2 shrink-0 rounded-full", swatch(segment, index), segment.user_class) %>" aria-hidden="true"></span>
|
|
19
|
+
<span class="text-foreground"><%= segment.label %></span>
|
|
20
|
+
<span class="text-muted-foreground tabular-nums"><%= segment_text(segment) %></span>
|
|
21
|
+
</li>
|
|
22
|
+
<% end %>
|
|
23
|
+
</ul>
|
|
24
|
+
<% end %>
|
|
25
|
+
<% end %>
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "securerandom"
|
|
4
|
+
|
|
5
|
+
# A bar showing how far along something is: an upload, an import, storage
|
|
6
|
+
# used, a profile half filled in. Leave out `value:` and it shows that work is
|
|
7
|
+
# going on without saying how much is left.
|
|
8
|
+
#
|
|
9
|
+
# <%= render(UI::Progress.new(value: 64, label: "Uploading report.pdf", show_value: true)) %>
|
|
10
|
+
# <%= render(UI::Progress.new(value: 3, max: 12, label: "Importing", value_text: "%{value} of %{max} files", show_value: true)) %>
|
|
11
|
+
# <%= render(UI::Progress.new(label: "Preparing your export")) %>
|
|
12
|
+
#
|
|
13
|
+
# Split by category, it adds up its segments and shows a legend:
|
|
14
|
+
#
|
|
15
|
+
# <%= render(UI::Progress.new(max: 15, label: "Storage", value_text: "%{value} GB of %{max} GB",
|
|
16
|
+
# segment_text: "%{value} GB", show_value: true)) do |progress| %>
|
|
17
|
+
# <% progress.with_segment(value: 6.4, label: "Photos") %>
|
|
18
|
+
# <% progress.with_segment(value: 3.1, label: "Mail") %>
|
|
19
|
+
# <% end %>
|
|
20
|
+
#
|
|
21
|
+
# With `max:` the segments fill as far as their total and the rest of the track
|
|
22
|
+
# is what's left: free space, tasks to do. Leave `max:` out and they fill the
|
|
23
|
+
# bar as shares of a whole, like traffic by source:
|
|
24
|
+
#
|
|
25
|
+
# <%= render(UI::Progress.new(label: "Visits by source")) do |progress| %>
|
|
26
|
+
# <% progress.with_segment(value: 5_210, label: "Search") %>
|
|
27
|
+
# <% progress.with_segment(value: 2_870, label: "Direct") %>
|
|
28
|
+
# <% end %>
|
|
29
|
+
#
|
|
30
|
+
# Segments take the chart colours in order. The legend names them, since a
|
|
31
|
+
# colour alone doesn't say which is which; `legend: false` leaves it out when
|
|
32
|
+
# the page already says. `segment_text:` is each one's amount in the legend,
|
|
33
|
+
# with %{value} and %{percent} (its share of max). It defaults to the value
|
|
34
|
+
# against a max, and to the percentage for shares of a whole.
|
|
35
|
+
#
|
|
36
|
+
# `value_text:` is what's shown (with `show_value: true`) and what a screen
|
|
37
|
+
# reader hears. It can use %{value}, %{max} and %{percent}, and defaults to
|
|
38
|
+
# "40%". `tone:` colours the bar (:success, :warning, :destructive) for a bar
|
|
39
|
+
# that means something, like storage nearly full.
|
|
40
|
+
#
|
|
41
|
+
# Updating it: re-render it from a Turbo Stream (with `method: :morph` the bar
|
|
42
|
+
# slides to its new width), or from JavaScript set its
|
|
43
|
+
# `data-ui--progress-value-value` attribute, as an upload's progress event
|
|
44
|
+
# would. It fires `ui--progress:complete` when it reaches the end.
|
|
45
|
+
class UI::Progress < UI::Base
|
|
46
|
+
SIZES = { sm: "h-1", default: "h-2", lg: "h-3" }.freeze
|
|
47
|
+
|
|
48
|
+
TONES = {
|
|
49
|
+
default: { track: "bg-primary/15", bar: "bg-primary" },
|
|
50
|
+
success: { track: "bg-emerald-500/15", bar: "bg-emerald-500 dark:bg-emerald-600" },
|
|
51
|
+
warning: { track: "bg-amber-500/15", bar: "bg-amber-500 dark:bg-amber-600" },
|
|
52
|
+
destructive: { track: "bg-destructive/15", bar: "bg-destructive" }
|
|
53
|
+
}.freeze
|
|
54
|
+
|
|
55
|
+
# Slides a short bar across, again and again. With reduced motion it's a
|
|
56
|
+
# full, faint bar instead: still there, not moving.
|
|
57
|
+
INDETERMINATE = "absolute inset-y-0 w-2/5 animate-[velvetkit-progress_1.4s_ease-in-out_infinite] " \
|
|
58
|
+
"motion-reduce:w-full motion-reduce:animate-none motion-reduce:opacity-50"
|
|
59
|
+
DETERMINATE = "h-full transition-[width] duration-300 ease-out motion-reduce:transition-none"
|
|
60
|
+
|
|
61
|
+
SWATCHES = { 1 => "bg-chart-1", 2 => "bg-chart-2", 3 => "bg-chart-3", 4 => "bg-chart-4", 5 => "bg-chart-5" }.freeze
|
|
62
|
+
|
|
63
|
+
renders_many :segments, UI::Progress::Segment
|
|
64
|
+
|
|
65
|
+
def initialize(value: nil, max: nil, label: nil, value_text: nil, show_value: false, size: :default,
|
|
66
|
+
tone: :default, legend: true, segment_text: nil, class: nil, **html_attrs)
|
|
67
|
+
@given_max = max if max.to_f.positive?
|
|
68
|
+
@value = value&.clamp(0, @given_max || 100)
|
|
69
|
+
@legend = legend
|
|
70
|
+
@segment_text = segment_text
|
|
71
|
+
@label = label
|
|
72
|
+
@value_text = value_text
|
|
73
|
+
@show_value = show_value
|
|
74
|
+
@size = SIZES.key?(size.to_sym) ? size.to_sym : :default
|
|
75
|
+
@tone = TONES.key?(tone.to_sym) ? tone.to_sym : :default
|
|
76
|
+
@user_class = binding.local_variable_get(:class)
|
|
77
|
+
@aria = html_attrs.delete(:aria) || {}
|
|
78
|
+
@html_attrs = html_attrs
|
|
79
|
+
@label_id = "ui-progress-#{SecureRandom.hex(4)}"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
attr_reader :label, :label_id
|
|
83
|
+
|
|
84
|
+
# 100 unless given; with segments and no max:, their total, so they fill the
|
|
85
|
+
# bar as shares of a whole.
|
|
86
|
+
def max
|
|
87
|
+
return @given_max if @given_max
|
|
88
|
+
|
|
89
|
+
total = segments.sum(&:value)
|
|
90
|
+
whole? ? total : 100
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Segments with no max: shares of a whole, not parts of a limit.
|
|
94
|
+
def whole? = @given_max.nil? && segmented? && segments.sum(&:value).positive?
|
|
95
|
+
|
|
96
|
+
# With segments, their total; the bar's own value: is ignored.
|
|
97
|
+
def value
|
|
98
|
+
return @value unless segmented?
|
|
99
|
+
|
|
100
|
+
segments.sum(&:value).clamp(0, max)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def segmented? = segments.any?
|
|
104
|
+
|
|
105
|
+
def indeterminate? = value.nil?
|
|
106
|
+
|
|
107
|
+
# Rounded down, so it never says 100% before it's done.
|
|
108
|
+
def percent
|
|
109
|
+
return nil if indeterminate?
|
|
110
|
+
|
|
111
|
+
(value.to_f / max * 100).floor
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def text_format = @value_text || t("ui.progress.value_text", default: "%{percent}%")
|
|
115
|
+
|
|
116
|
+
def value_text
|
|
117
|
+
return nil if indeterminate?
|
|
118
|
+
|
|
119
|
+
text_format.gsub("%{value}", number(value)).gsub("%{max}", number(max)).gsub("%{percent}", percent.to_s)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def header? = @label.present? || (@show_value && !indeterminate?)
|
|
123
|
+
|
|
124
|
+
def root_attrs
|
|
125
|
+
{ **@html_attrs, class: cn("w-full", (header? || legend?) && "space-y-1.5", @user_class),
|
|
126
|
+
data: { slot: "progress", controller: "ui--progress", "ui--progress-max-value": number(max),
|
|
127
|
+
"ui--progress-format-value": text_format,
|
|
128
|
+
"ui--progress-determinate-class": DETERMINATE, "ui--progress-indeterminate-class": INDETERMINATE,
|
|
129
|
+
**(@html_attrs[:data] || {}),
|
|
130
|
+
**(indeterminate? ? {} : { "ui--progress-value-value": number(value) }) } }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def bar_attrs
|
|
134
|
+
named = @label.present? ? { labelledby: label_id } : { label: t("ui.progress.label", default: "Progress") }
|
|
135
|
+
{ role: "progressbar", class: cn("relative w-full overflow-hidden rounded-full", SIZES[@size], TONES[@tone][:track]),
|
|
136
|
+
data: { state: state, "ui--progress-target": "bar" },
|
|
137
|
+
aria: { valuemin: 0, valuemax: number(max), valuenow: (number(value) unless indeterminate?),
|
|
138
|
+
valuetext: value_text, busy: (true if state != "complete"), **named, **@aria }.compact }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def indicator_attrs
|
|
142
|
+
colour = segmented? ? "flex gap-0.5 overflow-hidden" : TONES[@tone][:bar]
|
|
143
|
+
{ class: cn("rounded-full", colour, indeterminate? ? INDETERMINATE : DETERMINATE),
|
|
144
|
+
style: ("width: #{percent}%" unless indeterminate?),
|
|
145
|
+
data: { slot: "progress-indicator", "ui--progress-target": "indicator" } }.compact
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def show_value? = @show_value && !indeterminate?
|
|
149
|
+
|
|
150
|
+
def legend? = segmented? && @legend
|
|
151
|
+
|
|
152
|
+
# Each segment's share of the filled part, so together they fill it; a
|
|
153
|
+
# small one keeps a sliver, so it doesn't vanish.
|
|
154
|
+
def segment_attrs(segment, index)
|
|
155
|
+
{ class: cn("h-full min-w-1", swatch(segment, index), segment.user_class),
|
|
156
|
+
style: "flex: #{number(segment.value)} 1 0%", title: "#{segment.label}: #{segment_text(segment)}",
|
|
157
|
+
data: { slot: "progress-segment" } }
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def swatch(segment, index) = SWATCHES[segment.color] || SWATCHES[(index % SWATCHES.size) + 1]
|
|
161
|
+
|
|
162
|
+
def segment_text(segment)
|
|
163
|
+
segment.value_text ||
|
|
164
|
+
(@segment_text || (whole? ? "%{percent}%" : "%{value}"))
|
|
165
|
+
.gsub("%{value}", number(segment.value))
|
|
166
|
+
.gsub("%{percent}", share(segment).to_s)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
private
|
|
170
|
+
|
|
171
|
+
def state
|
|
172
|
+
return "indeterminate" if indeterminate?
|
|
173
|
+
|
|
174
|
+
value >= max ? "complete" : "loading"
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Rounded, not down: shares of a whole should add up to about 100.
|
|
178
|
+
def share(segment) = (segment.value / max.to_f * 100).round
|
|
179
|
+
|
|
180
|
+
# 3, not 3.0; 2.5 stays 2.5.
|
|
181
|
+
def number(n) = (n.to_f % 1).zero? ? n.to_i.to_s : n.to_s
|
|
182
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%= tag.div(class: "relative w-full", data: root_data) do %>
|
|
1
|
+
<%= tag.div(class: "relative w-full", data: remote? ? root_data.merge(status_texts) : root_data) do %>
|
|
2
2
|
<% if render_label? %>
|
|
3
3
|
<div class="mb-2"><%= render(label_component) { label_text } %></div>
|
|
4
4
|
<% end %>
|
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95") do %>
|
|
14
14
|
<% if searchable? %>
|
|
15
15
|
<div class="flex items-center gap-2 border-b px-3 py-2">
|
|
16
|
-
|
|
16
|
+
<% if remote? %>
|
|
17
|
+
<%# The magnifying glass turns into a spinner while a search is slow. %>
|
|
18
|
+
<span class="flex shrink-0 text-muted-foreground" data-ui--select-target="searchIcon"><%= render(UI::Icon.new(name: "search", size: :sm)) %></span>
|
|
19
|
+
<span class="hidden shrink-0 text-muted-foreground" data-ui--select-target="spinner" aria-hidden="true"><%= render(UI::Icon.new(name: "loader", size: :sm, class: "animate-spin motion-reduce:animate-[spin_1.5s_linear_infinite]")) %></span>
|
|
20
|
+
<% else %>
|
|
21
|
+
<%= render(UI::Icon.new(name: "search", size: :sm, class: "shrink-0 text-muted-foreground")) %>
|
|
22
|
+
<% end %>
|
|
17
23
|
<%= tag.input(type: "search", id: search_id, autocomplete: "off",
|
|
18
24
|
placeholder: t("ui.select.search", default: "Search"),
|
|
19
25
|
class: "w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden",
|
|
@@ -32,9 +38,7 @@
|
|
|
32
38
|
<%= tag.div(id: option_id(index), role: "option", aria: { selected: selected?(value).to_s },
|
|
33
39
|
data: { value: value, "ui--select-target": "option",
|
|
34
40
|
action: "click->ui--select#choose mousemove->ui--select#hover" },
|
|
35
|
-
class:
|
|
36
|
-
"outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground aria-selected:font-medium " \
|
|
37
|
-
"#{value.to_s.empty? ? "text-muted-foreground" : ""}") do %>
|
|
41
|
+
class: option_classes(value)) do %>
|
|
38
42
|
<span class="truncate"><%= label %></span>
|
|
39
43
|
<span class="absolute right-2 flex size-4 items-center justify-center text-primary dark:text-foreground" data-ui--select-target="check" <%= "hidden" unless selected?(value) %>>
|
|
40
44
|
<%= render(UI::Icon.new(name: "check", size: :sm)) %>
|
|
@@ -46,6 +50,21 @@
|
|
|
46
50
|
<% if searchable? %>
|
|
47
51
|
<p hidden data-ui--select-target="empty" class="px-3 py-3 text-sm text-muted-foreground"><%= t("ui.select.no_matches", default: "No matches") %></p>
|
|
48
52
|
<% end %>
|
|
53
|
+
<% if remote? %>
|
|
54
|
+
<%# Searching and failures are announced; the options themselves are read as they're highlighted. %>
|
|
55
|
+
<p hidden role="status" data-ui--select-target="status" class="flex items-center gap-2 px-3 py-3 text-sm text-muted-foreground"></p>
|
|
56
|
+
<template data-ui--select-target="template">
|
|
57
|
+
<%= tag.div(role: "option", aria: { selected: "false" },
|
|
58
|
+
data: { value: "", "ui--select-target": "option",
|
|
59
|
+
action: "click->ui--select#choose mousemove->ui--select#hover" },
|
|
60
|
+
class: option_classes("x")) do %>
|
|
61
|
+
<span class="truncate"></span>
|
|
62
|
+
<span class="absolute right-2 flex size-4 items-center justify-center text-primary dark:text-foreground" data-ui--select-target="check" hidden>
|
|
63
|
+
<%= render(UI::Icon.new(name: "check", size: :sm)) %>
|
|
64
|
+
</span>
|
|
65
|
+
<% end %>
|
|
66
|
+
</template>
|
|
67
|
+
<% end %>
|
|
49
68
|
<% end %>
|
|
50
69
|
|
|
51
70
|
<% if wrapper.hint.present? || wrapper.error_message.present? %>
|
|
@@ -17,6 +17,25 @@ require "securerandom"
|
|
|
17
17
|
# `searchable: true` adds a search box that filters the list; `multiple: true`
|
|
18
18
|
# lets people pick several, posting `name[]` like a native multiple select.
|
|
19
19
|
#
|
|
20
|
+
# `url:` searches on the server instead, for lists too long to send to the
|
|
21
|
+
# page, such as products, customers or suppliers. Opening the list asks
|
|
22
|
+
# `GET url?q=` for a starting list, and typing asks again with what was typed,
|
|
23
|
+
# a moment after the typing stops. The server answers with JSON, either
|
|
24
|
+
# `[{ "value": 7, "label": "Acme Traders" }, ...]` or `[["Acme Traders", 7], ...]`;
|
|
25
|
+
# it decides what matches and how many come back. `param:` renames `q`.
|
|
26
|
+
# `options:` are what show before then, so pass the current choice, or an edit
|
|
27
|
+
# form opens with nothing named:
|
|
28
|
+
#
|
|
29
|
+
# <%= render(UI::Select.new(form: f, field: :customer_id, url: customers_search_path,
|
|
30
|
+
# options: [[@order.customer&.name, @order.customer_id]].reject { _1.first.nil? },
|
|
31
|
+
# prompt: "Find a customer")) %>
|
|
32
|
+
#
|
|
33
|
+
# # app/controllers/customers_controller.rb
|
|
34
|
+
# def search
|
|
35
|
+
# customers = Customer.where("name ILIKE ?", "%#{Customer.sanitize_sql_like(params[:q].to_s)}%").order(:name).limit(20)
|
|
36
|
+
# render json: customers.map { { value: _1.id, label: _1.name } }
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
20
39
|
# UI::NativeSelect is the browser's own control, for when a phone's system
|
|
21
40
|
# picker is the better fit.
|
|
22
41
|
#
|
|
@@ -42,7 +61,7 @@ class UI::Select < UI::Base
|
|
|
42
61
|
)
|
|
43
62
|
|
|
44
63
|
def initialize(name: nil, options: [], selected: nil, prompt: nil,
|
|
45
|
-
label: nil, hint: nil, size: :default, searchable: false, multiple: false,
|
|
64
|
+
label: nil, hint: nil, size: :default, searchable: false, multiple: false, url: nil, param: "q",
|
|
46
65
|
required: false, error: nil, disabled: false,
|
|
47
66
|
form: nil, field: nil,
|
|
48
67
|
class: nil, **html_attrs)
|
|
@@ -52,7 +71,9 @@ class UI::Select < UI::Base
|
|
|
52
71
|
@prompt = prompt
|
|
53
72
|
@label = label
|
|
54
73
|
@size = size
|
|
55
|
-
@
|
|
74
|
+
@url = url
|
|
75
|
+
@param = param
|
|
76
|
+
@searchable = searchable || url.present?
|
|
56
77
|
@multiple = multiple
|
|
57
78
|
@required = required
|
|
58
79
|
@error = error
|
|
@@ -73,6 +94,7 @@ class UI::Select < UI::Base
|
|
|
73
94
|
delegate :render_label?, :label_text, :label_component, to: :wrapper
|
|
74
95
|
|
|
75
96
|
def searchable? = @searchable
|
|
97
|
+
def remote? = @url.present?
|
|
76
98
|
def multiple? = @multiple
|
|
77
99
|
|
|
78
100
|
def trigger_id = "ui-select-#{@uid}"
|
|
@@ -138,9 +160,26 @@ class UI::Select < UI::Base
|
|
|
138
160
|
def summary = t("ui.select.selected", default: "%{count} selected", count: "%{count}")
|
|
139
161
|
|
|
140
162
|
def root_data
|
|
141
|
-
{ controller: "ui--select", "ui--select-multiple-value": multiple?.to_s,
|
|
142
|
-
|
|
143
|
-
|
|
163
|
+
data = { controller: "ui--select", "ui--select-multiple-value": multiple?.to_s,
|
|
164
|
+
"ui--select-summary-value": summary,
|
|
165
|
+
"ui--select-placeholder-value": prompt || t("ui.select.placeholder", default: "Choose…") }
|
|
166
|
+
return data unless remote?
|
|
167
|
+
|
|
168
|
+
data.merge("ui--select-url-value": @url, "ui--select-param-value": @param)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# What a fetched option is built from: one rendered here, so it has the same
|
|
172
|
+
# classes as the options the page arrived with.
|
|
173
|
+
def option_classes(value)
|
|
174
|
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-8 pl-2 #{size == :sm ? "text-xs" : "text-sm"} " \
|
|
175
|
+
"outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground aria-selected:font-medium " \
|
|
176
|
+
"#{value.to_s.empty? ? "text-muted-foreground" : ""}"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Said while a search is on its way, and when one fails.
|
|
180
|
+
def status_texts
|
|
181
|
+
{ "ui--select-searching-value": t("ui.select.searching", default: "Searching…"),
|
|
182
|
+
"ui--select-failed-value": t("ui.select.failed", default: "Couldn't load the results. Try again.") }
|
|
144
183
|
end
|
|
145
184
|
|
|
146
185
|
# The hidden native select. Everything the caller passed beyond our own
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<%= tag.li(**item_attrs) do %>
|
|
2
|
+
<%= tag.div class: head_classes do %>
|
|
3
|
+
<%= tag.span(**indicator_attrs) do %>
|
|
4
|
+
<% unless dot? %>
|
|
5
|
+
<%= tag.span number_glyph, class: glyph_classes(:number) %>
|
|
6
|
+
<%= tag.span render(UI::Icon.new(name: "check", size: :sm)), class: glyph_classes(:complete) %>
|
|
7
|
+
<%= tag.span "!", class: glyph_classes(:error) + " font-bold" %>
|
|
8
|
+
<%= tag.span render(UI::Icon.new(name: "loader", size: :sm, class: "animate-spin")), class: glyph_classes(:loading) %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<% if connector? %>
|
|
12
|
+
<%= tag.span class: connector_classes, aria: { hidden: true } do %><%= tag.span class: connector_fill_classes %><% end %>
|
|
13
|
+
<% end %>
|
|
14
|
+
<% end %>
|
|
15
|
+
<%= tag.div class: text_classes do %>
|
|
16
|
+
<% if link? %>
|
|
17
|
+
<%= link_to @href, class: link_classes do %><%= tag.span @title, id: title_id, class: title_classes %><% end %>
|
|
18
|
+
<% elsif navigable? %>
|
|
19
|
+
<%= tag.button(**select_attrs) do %><%= tag.span @title, id: title_id, class: title_classes %><% end %>
|
|
20
|
+
<% else %>
|
|
21
|
+
<%= tag.span @title, id: title_id, class: title_classes %>
|
|
22
|
+
<% end %>
|
|
23
|
+
<% if description? %><%= tag.span @description, class: description_classes %><% end %>
|
|
24
|
+
<% status_texts.each do |text, classes| %><%= tag.span ", #{text}", class: classes %><% end %>
|
|
25
|
+
<% if inline_panel? %><%= tag.div(panel, **panel_attrs) %><% end %>
|
|
26
|
+
<% end %>
|
|
27
|
+
<% end %>
|