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
|
@@ -1,25 +1,82 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
import { DirectUpload } from '@rails/activestorage';
|
|
3
|
+
|
|
4
|
+
// Connects to data-controller="ui--file-field"
|
|
5
|
+
//
|
|
6
|
+
// The <label> around the input already opens the system picker, with no
|
|
7
|
+
// JavaScript. This adds what a label can't: dropping files on it, a tile for
|
|
8
|
+
// each chosen file with a thumbnail and a way to take it out again, checking
|
|
9
|
+
// type and size as files arrive, and, with direct upload, sending each file to
|
|
10
|
+
// storage straight away with a progress bar.
|
|
11
|
+
//
|
|
12
|
+
// Without direct upload the input itself carries the files, so it's rebuilt
|
|
13
|
+
// to match the tiles whenever one is added or taken out. With it, the input
|
|
14
|
+
// is emptied as each file starts uploading and a hidden field takes the
|
|
15
|
+
// file's signed id instead, so the form submits ids, not bytes.
|
|
16
|
+
type Labels = {
|
|
17
|
+
remove: string; uploading: string; uploaded: string; failed: string; retry: string;
|
|
18
|
+
too_big: string; max: string | null; wrong_type: string; waiting: string; added: string; removed: string;
|
|
19
|
+
units: { byte: string; kb: string; mb: string; gb: string };
|
|
20
|
+
};
|
|
21
|
+
type Upload = { xhr?: XMLHttpRequest; done: boolean };
|
|
2
22
|
|
|
3
|
-
/**
|
|
4
|
-
* UI::FileField controller — drag-and-drop over a native <input type="file">.
|
|
5
|
-
*
|
|
6
|
-
* The <label> wrapping the input already opens the native picker on click,
|
|
7
|
-
* no JS needed for that. This only adds what a label can't: highlighting the
|
|
8
|
-
* dropzone while dragging, assigning dropped files to the input, and
|
|
9
|
-
* listing the chosen file names.
|
|
10
|
-
*/
|
|
11
23
|
export default class extends Controller<HTMLElement> {
|
|
12
|
-
static targets = ['dropzone', 'input', 'filenames'];
|
|
24
|
+
static targets = ['dropzone', 'input', 'filenames', 'list', 'template', 'item', 'notice', 'status'];
|
|
25
|
+
static values = {
|
|
26
|
+
preview: Boolean,
|
|
27
|
+
directUpload: Boolean,
|
|
28
|
+
url: String,
|
|
29
|
+
name: String,
|
|
30
|
+
multiple: Boolean,
|
|
31
|
+
accept: String,
|
|
32
|
+
maxSize: Number,
|
|
33
|
+
required: Boolean,
|
|
34
|
+
labels: Object,
|
|
35
|
+
};
|
|
13
36
|
|
|
14
37
|
declare readonly dropzoneTarget: HTMLElement;
|
|
15
38
|
declare readonly inputTarget: HTMLInputElement;
|
|
16
39
|
declare readonly hasFilenamesTarget: boolean;
|
|
17
40
|
declare readonly filenamesTarget: HTMLElement;
|
|
41
|
+
declare readonly listTarget: HTMLElement;
|
|
42
|
+
declare readonly templateTarget: HTMLTemplateElement;
|
|
43
|
+
declare readonly itemTargets: HTMLElement[];
|
|
44
|
+
declare readonly hasNoticeTarget: boolean;
|
|
45
|
+
declare readonly noticeTarget: HTMLElement;
|
|
46
|
+
declare readonly hasStatusTarget: boolean;
|
|
47
|
+
declare readonly statusTarget: HTMLElement;
|
|
48
|
+
declare readonly previewValue: boolean;
|
|
49
|
+
declare readonly directUploadValue: boolean;
|
|
50
|
+
declare readonly urlValue: string;
|
|
51
|
+
declare readonly nameValue: string;
|
|
52
|
+
declare readonly multipleValue: boolean;
|
|
53
|
+
declare readonly acceptValue: string;
|
|
54
|
+
declare readonly maxSizeValue: number;
|
|
55
|
+
declare readonly requiredValue: boolean;
|
|
56
|
+
declare readonly labelsValue: Labels;
|
|
57
|
+
|
|
58
|
+
// What each tile stands for, beyond its markup.
|
|
59
|
+
private files = new WeakMap<HTMLElement, File>();
|
|
60
|
+
private uploads = new WeakMap<HTMLElement, Upload>();
|
|
61
|
+
private objectUrls = new WeakMap<HTMLElement, string>();
|
|
62
|
+
private waitingToSubmit = false;
|
|
63
|
+
private onSubmit = (event: SubmitEvent) => this.holdForUploads(event);
|
|
18
64
|
|
|
19
65
|
connect() {
|
|
20
|
-
|
|
66
|
+
// With direct upload the files travel separately, so the input itself
|
|
67
|
+
// sends nothing, not even an empty file.
|
|
68
|
+
if (this.directUploadValue) this.inputTarget.removeAttribute('name');
|
|
69
|
+
this.inputTarget.form?.addEventListener('submit', this.onSubmit);
|
|
70
|
+
if (!this.previewValue) this.updateNames();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
disconnect() {
|
|
74
|
+
this.inputTarget.form?.removeEventListener('submit', this.onSubmit);
|
|
75
|
+
this.itemTargets.forEach((item) => this.forget(item));
|
|
21
76
|
}
|
|
22
77
|
|
|
78
|
+
// ── Arriving files ──────────────────────────────────────────────────────
|
|
79
|
+
|
|
23
80
|
dragOver(event: DragEvent) {
|
|
24
81
|
event.preventDefault();
|
|
25
82
|
if (this.inputTarget.disabled) return;
|
|
@@ -34,16 +91,231 @@ export default class extends Controller<HTMLElement> {
|
|
|
34
91
|
event.preventDefault();
|
|
35
92
|
delete this.dropzoneTarget.dataset.drag;
|
|
36
93
|
|
|
37
|
-
const files = event.dataTransfer?.files;
|
|
38
|
-
if (!files
|
|
94
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
95
|
+
if (!files.length || this.inputTarget.disabled) return;
|
|
96
|
+
|
|
97
|
+
if (this.previewValue) {
|
|
98
|
+
this.add(this.multipleValue ? files : files.slice(0, 1));
|
|
99
|
+
} else {
|
|
100
|
+
this.inputTarget.files = event.dataTransfer!.files;
|
|
101
|
+
this.inputTarget.dispatchEvent(new Event('change', { bubbles: true }));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The picker's choice. Without previews, only the names are listed.
|
|
106
|
+
chosen() {
|
|
107
|
+
if (!this.previewValue) return this.updateNames();
|
|
39
108
|
|
|
40
|
-
this.inputTarget.files
|
|
41
|
-
|
|
109
|
+
const files = Array.from(this.inputTarget.files ?? []);
|
|
110
|
+
// The input's own list is replaced as the tiles are made, so the files
|
|
111
|
+
// already chosen aren't counted twice.
|
|
112
|
+
const fresh = files.filter((file) => !this.itemTargets.some((item) => this.files.get(item) === file));
|
|
113
|
+
if (fresh.length) this.add(fresh);
|
|
42
114
|
}
|
|
43
115
|
|
|
44
116
|
updateNames() {
|
|
45
117
|
if (!this.hasFilenamesTarget) return;
|
|
46
|
-
|
|
47
|
-
|
|
118
|
+
this.filenamesTarget.textContent = Array.from(this.inputTarget.files ?? []).map((file) => file.name).join(', ');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private add(files: File[]) {
|
|
122
|
+
// A single file replaces whatever was there, kept files included.
|
|
123
|
+
if (!this.multipleValue) this.itemTargets.forEach((item) => this.discard(item));
|
|
124
|
+
|
|
125
|
+
files.forEach((file) => {
|
|
126
|
+
const item = this.makeTile(file);
|
|
127
|
+
const problem = this.problemWith(file);
|
|
128
|
+
if (problem) {
|
|
129
|
+
this.setState(item, 'error', problem);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.files.set(item, file);
|
|
133
|
+
if (this.directUploadValue) this.upload(item, file);
|
|
134
|
+
});
|
|
135
|
+
this.syncInput();
|
|
136
|
+
this.say(this.labelsValue.added.replace('%{name}', files.map((f) => f.name).join(', ')));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private makeTile(file: File): HTMLElement {
|
|
140
|
+
const item = this.templateTarget.content.firstElementChild!.cloneNode(true) as HTMLElement;
|
|
141
|
+
this.part(item, 'name').textContent = file.name;
|
|
142
|
+
this.part(item, 'name').title = file.name;
|
|
143
|
+
this.part(item, 'meta').textContent = this.size(file.size);
|
|
144
|
+
this.part(item, 'remove').setAttribute('aria-label', this.labelsValue.remove.replace('%{name}', file.name));
|
|
145
|
+
this.part(item, 'progress').setAttribute('aria-label', file.name);
|
|
146
|
+
|
|
147
|
+
if (file.type.startsWith('image/')) {
|
|
148
|
+
const url = URL.createObjectURL(file);
|
|
149
|
+
this.objectUrls.set(item, url);
|
|
150
|
+
const thumb = this.part(item, 'thumb') as HTMLImageElement;
|
|
151
|
+
thumb.src = url;
|
|
152
|
+
thumb.hidden = false;
|
|
153
|
+
this.part(item, 'icon').hidden = true;
|
|
154
|
+
}
|
|
155
|
+
this.listTarget.append(item);
|
|
156
|
+
return item;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// The same rules as `accept` and `max_size`, for dropped files too, which
|
|
160
|
+
// the picker's filter never sees.
|
|
161
|
+
private problemWith(file: File): string | null {
|
|
162
|
+
if (this.acceptValue && !this.accepts(file)) return this.labelsValue.wrong_type;
|
|
163
|
+
if (this.maxSizeValue && file.size > this.maxSizeValue) {
|
|
164
|
+
return this.labelsValue.too_big.replace('%{max}', this.labelsValue.max ?? this.size(this.maxSizeValue));
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private accepts(file: File) {
|
|
170
|
+
return this.acceptValue.split(',').map((rule) => rule.trim().toLowerCase()).filter(Boolean).some((rule) => {
|
|
171
|
+
if (rule.startsWith('.')) return file.name.toLowerCase().endsWith(rule);
|
|
172
|
+
if (rule.endsWith('/*')) return file.type.toLowerCase().startsWith(rule.slice(0, -1));
|
|
173
|
+
return file.type.toLowerCase() === rule;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ── Taking files out ────────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
remove(event: Event) {
|
|
180
|
+
const item = (event.currentTarget as HTMLElement).closest<HTMLElement>('[data-ui--file-field-target="item"]');
|
|
181
|
+
if (!item) return;
|
|
182
|
+
|
|
183
|
+
const name = this.part(item, 'name').textContent ?? '';
|
|
184
|
+
this.discard(item);
|
|
185
|
+
this.syncInput();
|
|
186
|
+
this.say(this.labelsValue.removed.replace('%{name}', name));
|
|
187
|
+
this.inputTarget.focus();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private discard(item: HTMLElement) {
|
|
191
|
+
this.forget(item);
|
|
192
|
+
item.remove();
|
|
193
|
+
this.settle();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private forget(item: HTMLElement) {
|
|
197
|
+
this.uploads.get(item)?.xhr?.abort();
|
|
198
|
+
const url = this.objectUrls.get(item);
|
|
199
|
+
if (url) URL.revokeObjectURL(url);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ── Uploading ───────────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
retry(event: Event) {
|
|
205
|
+
const item = (event.currentTarget as HTMLElement).closest<HTMLElement>('[data-ui--file-field-target="item"]');
|
|
206
|
+
const file = item && this.files.get(item);
|
|
207
|
+
if (item && file) this.upload(item, file);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private upload(item: HTMLElement, file: File) {
|
|
211
|
+
const state: Upload = { done: false };
|
|
212
|
+
this.uploads.set(item, state);
|
|
213
|
+
this.setState(item, 'uploading', this.labelsValue.uploading);
|
|
214
|
+
this.setProgress(item, 0);
|
|
215
|
+
|
|
216
|
+
const watch = (xhr: XMLHttpRequest) => {
|
|
217
|
+
state.xhr = xhr;
|
|
218
|
+
xhr.upload.addEventListener('progress', (event) => {
|
|
219
|
+
if (event.lengthComputable) this.setProgress(item, event.loaded / event.total);
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
new DirectUpload(file, this.urlValue, {
|
|
223
|
+
directUploadWillCreateBlobWithXHR: (xhr: XMLHttpRequest) => { state.xhr = xhr; },
|
|
224
|
+
directUploadWillStoreFileWithXHR: watch,
|
|
225
|
+
}).create((error: Error | null, blob?: { signed_id: string }) => {
|
|
226
|
+
state.done = true;
|
|
227
|
+
if (!item.isConnected) return;
|
|
228
|
+
if (error || !blob) {
|
|
229
|
+
this.setState(item, 'error', this.labelsValue.failed);
|
|
230
|
+
this.part(item, 'retry').hidden = false;
|
|
231
|
+
} else {
|
|
232
|
+
this.keep(item, blob.signed_id);
|
|
233
|
+
this.setState(item, 'uploaded', `${this.size(file.size)} · ${this.labelsValue.uploaded}`);
|
|
234
|
+
}
|
|
235
|
+
this.settle();
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// The uploaded file's signed id goes in the form in its place.
|
|
240
|
+
private keep(item: HTMLElement, signedId: string) {
|
|
241
|
+
const field = document.createElement('input');
|
|
242
|
+
field.type = 'hidden';
|
|
243
|
+
field.name = this.nameValue;
|
|
244
|
+
field.value = signedId;
|
|
245
|
+
field.dataset.role = 'signed';
|
|
246
|
+
item.append(field);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private setState(item: HTMLElement, state: string, meta: string) {
|
|
250
|
+
item.dataset.state = state;
|
|
251
|
+
this.part(item, 'meta').textContent = meta;
|
|
252
|
+
this.part(item, 'retry').hidden = true;
|
|
253
|
+
this.part(item, 'progress').hidden = state !== 'uploading';
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private setProgress(item: HTMLElement, fraction: number) {
|
|
257
|
+
const percent = Math.round(fraction * 100);
|
|
258
|
+
this.part(item, 'bar').style.width = `${percent}%`;
|
|
259
|
+
this.part(item, 'progress').setAttribute('aria-valuenow', String(percent));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private get uploading() {
|
|
263
|
+
return this.itemTargets.some((item) => item.dataset.state === 'uploading');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Sending the form mid-upload waits for the uploads, then sends it.
|
|
267
|
+
private holdForUploads(event: SubmitEvent) {
|
|
268
|
+
if (!this.uploading) return;
|
|
269
|
+
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
event.stopImmediatePropagation();
|
|
272
|
+
this.waitingToSubmit = true;
|
|
273
|
+
if (this.hasNoticeTarget) this.noticeTarget.textContent = this.labelsValue.waiting;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private settle() {
|
|
277
|
+
if (this.uploading) return;
|
|
278
|
+
|
|
279
|
+
if (this.hasNoticeTarget) this.noticeTarget.textContent = '';
|
|
280
|
+
if (this.waitingToSubmit) {
|
|
281
|
+
this.waitingToSubmit = false;
|
|
282
|
+
this.inputTarget.form?.requestSubmit();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ── The input itself ────────────────────────────────────────────────────
|
|
287
|
+
|
|
288
|
+
// Without direct upload the input carries the files the tiles show; with
|
|
289
|
+
// it, the input is emptied, since the files travel separately. Either way a
|
|
290
|
+
// required field counts a kept or uploaded file as filled.
|
|
291
|
+
private syncInput() {
|
|
292
|
+
const carried = this.directUploadValue ? [] : this.itemTargets.map((item) => this.files.get(item)).filter((f): f is File => !!f);
|
|
293
|
+
const list = new DataTransfer();
|
|
294
|
+
carried.forEach((file) => list.items.add(file));
|
|
295
|
+
this.inputTarget.files = list.files;
|
|
296
|
+
|
|
297
|
+
const filled = this.itemTargets.some((item) => item.dataset.state !== 'error');
|
|
298
|
+
if (this.requiredValue) this.inputTarget.required = !filled;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private say(text: string) {
|
|
302
|
+
if (this.hasStatusTarget) this.statusTarget.textContent = text;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private part(item: HTMLElement, role: string): HTMLElement {
|
|
306
|
+
return item.querySelector<HTMLElement>(`[data-role="${role}"]`)!;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Written the way Rails writes it for the kept files beside it ("1.2 MB"),
|
|
310
|
+
// in the units the locale gives.
|
|
311
|
+
private size(bytes: number): string {
|
|
312
|
+
const { units } = this.labelsValue;
|
|
313
|
+
const steps: [number, string][] = [[1024 ** 3, units.gb], [1024 ** 2, units.mb], [1024, units.kb]];
|
|
314
|
+
const [divisor, unit] = steps.find(([limit]) => bytes >= limit) ?? [1, units.byte];
|
|
315
|
+
const value = bytes / divisor;
|
|
316
|
+
const number = new Intl.NumberFormat(document.documentElement.lang || undefined, {
|
|
317
|
+
maximumFractionDigits: value >= 100 || divisor === 1 ? 0 : value >= 10 ? 1 : 2,
|
|
318
|
+
}).format(value);
|
|
319
|
+
return `${number} ${unit}`;
|
|
48
320
|
}
|
|
49
321
|
}
|