@zonsh/ui 0.5.0 → 0.6.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.
- package/CHANGELOG.md +639 -0
- package/README.md +49 -21
- package/dist/brand.d.ts +3 -0
- package/dist/brand.js +7 -0
- package/dist/components/_breadcrumb-more.d.ts +6 -0
- package/dist/components/_breadcrumb-more.js +5 -0
- package/dist/components/_drawing-svg.d.ts +11 -0
- package/dist/components/_drawing-svg.js +30 -0
- package/dist/components/_media.d.ts +159 -0
- package/dist/components/_media.js +266 -0
- package/dist/components/_overlay.d.ts +8 -5
- package/dist/components/_overlay.js +11 -6
- package/dist/components/_scheduler-calendar.d.ts +71 -0
- package/dist/components/_scheduler-calendar.js +940 -0
- package/dist/components/_scheduler-editor.d.ts +29 -0
- package/dist/components/_scheduler-editor.js +111 -0
- package/dist/components/_scheduler-menu.d.ts +16 -0
- package/dist/components/_scheduler-menu.js +18 -0
- package/dist/components/_scheduler-parts.d.ts +164 -0
- package/dist/components/_scheduler-parts.js +327 -0
- package/dist/components/_suggest-list.d.ts +142 -0
- package/dist/components/_suggest-list.js +159 -0
- package/dist/components/_toolbar-more.d.ts +24 -0
- package/dist/components/_toolbar-more.js +25 -0
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +6 -6
- package/dist/components/action-sheet.d.ts +88 -0
- package/dist/components/action-sheet.js +124 -0
- package/dist/components/alert-dialog.js +3 -1
- package/dist/components/alert.d.ts +11 -18
- package/dist/components/alert.js +9 -6
- package/dist/components/app-bar.d.ts +93 -0
- package/dist/components/app-bar.js +175 -0
- package/dist/components/audio-player.d.ts +134 -0
- package/dist/components/audio-player.js +618 -0
- package/dist/components/avatar.d.ts +6 -6
- package/dist/components/avatar.js +13 -11
- package/dist/components/badge.d.ts +12 -12
- package/dist/components/badge.js +7 -5
- package/dist/components/bottom-nav.d.ts +53 -11
- package/dist/components/bottom-nav.js +388 -23
- package/dist/components/breadcrumb.d.ts +11 -2
- package/dist/components/breadcrumb.js +60 -6
- package/dist/components/button-group.js +5 -1
- package/dist/components/button.d.ts +23 -6
- package/dist/components/button.js +63 -7
- package/dist/components/calendar.js +8 -6
- package/dist/components/card.d.ts +10 -8
- package/dist/components/card.js +15 -14
- package/dist/components/carousel.d.ts +2 -2
- package/dist/components/carousel.js +21 -8
- package/dist/components/chart.d.ts +27 -1
- package/dist/components/chart.js +15 -5
- package/dist/components/checkbox.js +2 -2
- package/dist/components/code-block.d.ts +9 -2
- package/dist/components/code-block.js +26 -7
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +2 -2
- package/dist/components/color-picker.js +5 -5
- package/dist/components/combobox.d.ts +26 -7
- package/dist/components/combobox.js +32 -13
- package/dist/components/command.d.ts +29 -5
- package/dist/components/command.js +35 -10
- package/dist/components/context-menu.d.ts +5 -2
- package/dist/components/context-menu.js +24 -3
- package/dist/components/conversation.d.ts +1 -1
- package/dist/components/conversation.js +67 -13
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/copy-button.js +1 -1
- package/dist/components/data-table.d.ts +6 -6
- package/dist/components/data-table.js +41 -15
- package/dist/components/date-picker.d.ts +31 -9
- package/dist/components/date-picker.js +100 -18
- package/dist/components/dialog.d.ts +17 -10
- package/dist/components/dialog.js +20 -13
- package/dist/components/drawer.d.ts +26 -8
- package/dist/components/drawer.js +75 -16
- package/dist/components/drawing.d.ts +25 -0
- package/dist/components/drawing.js +32 -0
- package/dist/components/empty.js +2 -2
- package/dist/components/feature-list.d.ts +65 -13
- package/dist/components/feature-list.js +116 -15
- package/dist/components/field.js +2 -2
- package/dist/components/file-drop.d.ts +9 -7
- package/dist/components/file-drop.js +8 -43
- package/dist/components/filter-bar.d.ts +10 -9
- package/dist/components/filter-bar.js +42 -25
- package/dist/components/graph.d.ts +19 -3
- package/dist/components/graph.js +170 -25
- package/dist/components/illustration.js +3 -28
- package/dist/components/input-group.d.ts +5 -10
- package/dist/components/input-group.js +16 -16
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/item.d.ts +9 -6
- package/dist/components/item.js +13 -8
- package/dist/components/kbd.d.ts +1 -1
- package/dist/components/kbd.js +1 -1
- package/dist/components/lightbox.d.ts +76 -9
- package/dist/components/lightbox.js +333 -45
- package/dist/components/locale.d.ts +6 -6
- package/dist/components/logo.d.ts +21 -1
- package/dist/components/logo.js +32 -2
- package/dist/components/markdown-editor.d.ts +275 -0
- package/dist/components/markdown-editor.js +831 -0
- package/dist/components/mentions.d.ts +153 -0
- package/dist/components/mentions.js +507 -0
- package/dist/components/menu.d.ts +2 -1
- package/dist/components/menu.js +5 -4
- package/dist/components/menubar.d.ts +23 -5
- package/dist/components/menubar.js +97 -22
- package/dist/components/message.d.ts +62 -11
- package/dist/components/message.js +49 -13
- package/dist/components/meter.js +1 -1
- package/dist/components/money-input.d.ts +1 -1
- package/dist/components/money-input.js +1 -1
- package/dist/components/native-select.d.ts +2 -2
- package/dist/components/native-select.js +4 -4
- package/dist/components/navigation-menu.d.ts +3 -1
- package/dist/components/navigation-menu.js +23 -12
- package/dist/components/number-field.d.ts +2 -9
- package/dist/components/number-field.js +86 -36
- package/dist/components/number-roll.d.ts +26 -0
- package/dist/components/number-roll.js +81 -0
- package/dist/components/otp-field.d.ts +1 -1
- package/dist/components/otp-field.js +24 -3
- package/dist/components/pagination.d.ts +11 -3
- package/dist/components/pagination.js +59 -13
- package/dist/components/pdf-viewer.d.ts +1 -1
- package/dist/components/pdf-viewer.js +8 -8
- package/dist/components/phone-input.d.ts +1 -1
- package/dist/components/phone-input.js +2 -2
- package/dist/components/popover.js +5 -3
- package/dist/components/preview-card.d.ts +37 -2
- package/dist/components/preview-card.js +226 -2
- package/dist/components/progress.js +1 -1
- package/dist/components/prompt-input.d.ts +1 -1
- package/dist/components/prompt-input.js +24 -14
- package/dist/components/pull-to-refresh.d.ts +50 -0
- package/dist/components/pull-to-refresh.js +189 -0
- package/dist/components/quote.d.ts +6 -1
- package/dist/components/quote.js +3 -2
- package/dist/components/radio-group.js +1 -1
- package/dist/components/rating.d.ts +4 -1
- package/dist/components/rating.js +131 -10
- package/dist/components/reasoning.d.ts +1 -1
- package/dist/components/reasoning.js +7 -3
- package/dist/components/resizable.d.ts +1 -1
- package/dist/components/resizable.js +2 -2
- package/dist/components/response.d.ts +1 -1
- package/dist/components/response.js +18 -6
- package/dist/components/scheduler.d.ts +352 -0
- package/dist/components/scheduler.js +1717 -0
- package/dist/components/scroll-area.js +1 -1
- package/dist/components/select.d.ts +17 -4
- package/dist/components/select.js +140 -9
- package/dist/components/separator.d.ts +1 -1
- package/dist/components/separator.js +3 -3
- package/dist/components/sidebar.d.ts +44 -3
- package/dist/components/sidebar.js +57 -17
- package/dist/components/site-header.d.ts +18 -13
- package/dist/components/site-header.js +23 -11
- package/dist/components/skeleton.d.ts +17 -7
- package/dist/components/skeleton.js +22 -7
- package/dist/components/slider.js +2 -2
- package/dist/components/sortable.d.ts +55 -4
- package/dist/components/sortable.js +172 -103
- package/dist/components/sources.d.ts +1 -1
- package/dist/components/sources.js +2 -2
- package/dist/components/spinner.d.ts +4 -4
- package/dist/components/spinner.js +4 -4
- package/dist/components/stat.d.ts +21 -4
- package/dist/components/stat.js +17 -8
- package/dist/components/stepper.d.ts +1 -1
- package/dist/components/stepper.js +8 -7
- package/dist/components/suggestions.d.ts +11 -3
- package/dist/components/suggestions.js +10 -4
- package/dist/components/swipe-actions.d.ts +66 -0
- package/dist/components/swipe-actions.js +292 -0
- package/dist/components/switch.js +1 -1
- package/dist/components/table.d.ts +12 -6
- package/dist/components/table.js +78 -30
- package/dist/components/tabs.js +7 -4
- package/dist/components/tag.d.ts +19 -20
- package/dist/components/tag.js +9 -5
- package/dist/components/tags-input.d.ts +2 -7
- package/dist/components/tags-input.js +11 -8
- package/dist/components/textarea.d.ts +3 -2
- package/dist/components/textarea.js +4 -3
- package/dist/components/theme.d.ts +49 -6
- package/dist/components/theme.js +147 -9
- package/dist/components/time-field.d.ts +4 -9
- package/dist/components/time-field.js +6 -6
- package/dist/components/timeline.d.ts +19 -3
- package/dist/components/timeline.js +21 -9
- package/dist/components/tippy.d.ts +17 -1
- package/dist/components/tippy.js +95 -15
- package/dist/components/toast.d.ts +2 -7
- package/dist/components/toast.js +12 -8
- package/dist/components/toggle-group.d.ts +7 -1
- package/dist/components/toggle-group.js +16 -5
- package/dist/components/toggle.d.ts +2 -2
- package/dist/components/toggle.js +3 -2
- package/dist/components/tool-call.d.ts +1 -1
- package/dist/components/tool-call.js +4 -4
- package/dist/components/toolbar.d.ts +57 -4
- package/dist/components/toolbar.js +216 -16
- package/dist/components/tooltip.d.ts +1 -1
- package/dist/components/tooltip.js +4 -2
- package/dist/components/tour.d.ts +1 -1
- package/dist/components/tour.js +36 -15
- package/dist/components/tree.js +5 -5
- package/dist/components/typography.d.ts +31 -8
- package/dist/components/typography.js +21 -10
- package/dist/components/video-player.d.ts +7 -2
- package/dist/components/video-player.js +121 -220
- package/dist/index.d.ts +99 -92
- package/dist/index.js +99 -92
- package/dist/lib/calendar.d.ts +153 -0
- package/dist/lib/calendar.js +312 -0
- package/dist/lib/cn.d.ts +3 -1
- package/dist/lib/cn.js +5 -0
- package/dist/lib/code-highlight.d.ts +14 -0
- package/dist/lib/code-highlight.js +81 -18
- package/dist/lib/drag.d.ts +39 -0
- package/dist/lib/drag.js +96 -0
- package/dist/lib/editorial-assets.js +16 -8
- package/dist/lib/figure/figures/automation.js +25 -6
- package/dist/lib/figure/figures/bar-chart.js +6 -1
- package/dist/lib/figure/figures/brackets-classic.js +4 -1
- package/dist/lib/figure/figures/city.js +12 -2
- package/dist/lib/figure/figures/conveyor.js +17 -4
- package/dist/lib/figure/figures/database.js +5 -2
- package/dist/lib/figure/figures/documents.js +11 -3
- package/dist/lib/figure/figures/inbox.js +5 -2
- package/dist/lib/figure/figures/laptop.js +3 -1
- package/dist/lib/figure/figures/pipeline.js +45 -10
- package/dist/lib/figure/figures/platform.js +62 -7
- package/dist/lib/figure/figures/server.js +21 -5
- package/dist/lib/figure/figures/spreadsheet.js +29 -5
- package/dist/lib/figure/kernel.d.ts +4 -2
- package/dist/lib/figure/kernel.js +10 -5
- package/dist/lib/figure/parts.js +6 -2
- package/dist/lib/files.d.ts +31 -0
- package/dist/lib/files.js +60 -0
- package/dist/lib/gesture.d.ts +70 -0
- package/dist/lib/gesture.js +141 -0
- package/dist/lib/glide.d.ts +5 -0
- package/dist/lib/glide.js +9 -1
- package/dist/lib/icons.d.ts +1 -0
- package/dist/lib/icons.js +6 -0
- package/dist/lib/illustration-library.js +1 -6
- package/dist/lib/markdown-edit.d.ts +112 -0
- package/dist/lib/markdown-edit.js +557 -0
- package/dist/lib/markdown-rich-editor.d.ts +188 -0
- package/dist/lib/markdown-rich-editor.js +1153 -0
- package/dist/lib/markdown-rich.d.ts +63 -0
- package/dist/lib/markdown-rich.js +534 -0
- package/dist/lib/mentions.d.ts +100 -0
- package/dist/lib/mentions.js +246 -0
- package/dist/lib/motion.d.ts +18 -0
- package/dist/lib/motion.js +43 -5
- package/dist/lib/number-roll.d.ts +89 -0
- package/dist/lib/number-roll.js +391 -0
- package/dist/lib/platform.d.ts +6 -0
- package/dist/lib/platform.js +14 -0
- package/dist/lib/portal-container.d.ts +9 -0
- package/dist/lib/portal-container.js +10 -0
- package/dist/lib/press.d.ts +5 -0
- package/dist/lib/press.js +186 -0
- package/dist/lib/scheduler.d.ts +128 -0
- package/dist/lib/scheduler.js +272 -0
- package/dist/lib/scroll-edges.d.ts +9 -0
- package/dist/lib/scroll-edges.js +50 -0
- package/dist/lib/table-fit.d.ts +1 -1
- package/dist/lib/table-fit.js +65 -8
- package/dist/lib/theme-preset.d.ts +267 -0
- package/dist/lib/theme-preset.js +1046 -0
- package/dist/lib/theme-script.d.ts +23 -3
- package/dist/lib/theme-script.js +17 -5
- package/dist/lib/tippy/sprite.d.ts +36 -4
- package/dist/lib/tippy/sprite.js +188 -15
- package/dist/lib/tone.d.ts +4 -0
- package/dist/lib/tone.js +1 -0
- package/dist/messages/de.d.ts +3 -3
- package/dist/messages/de.js +274 -3
- package/dist/skills/zon-ui/SKILL.md +279 -0
- package/dist/skills/zon-ui/references/authoring.md +265 -0
- package/dist/skills/zon-ui/references/brand.md +416 -0
- package/dist/skills/zon-ui/references/components/accordion.md +199 -0
- package/dist/skills/zon-ui/references/components/action-sheet.md +268 -0
- package/dist/skills/zon-ui/references/components/alert-dialog.md +276 -0
- package/dist/skills/zon-ui/references/components/alert.md +167 -0
- package/dist/skills/zon-ui/references/components/app-bar.md +307 -0
- package/dist/skills/zon-ui/references/components/ascii-field.md +121 -0
- package/dist/skills/zon-ui/references/components/aspect-ratio.md +112 -0
- package/dist/skills/zon-ui/references/components/audio-player.md +231 -0
- package/dist/skills/zon-ui/references/components/avatar.md +98 -0
- package/dist/skills/zon-ui/references/components/badge.md +227 -0
- package/dist/skills/zon-ui/references/components/bottom-nav.md +709 -0
- package/dist/skills/zon-ui/references/components/breadcrumb.md +143 -0
- package/dist/skills/zon-ui/references/components/button-group.md +216 -0
- package/dist/skills/zon-ui/references/components/button.md +309 -0
- package/dist/skills/zon-ui/references/components/calendar.md +296 -0
- package/dist/skills/zon-ui/references/components/card.md +158 -0
- package/dist/skills/zon-ui/references/components/carousel.md +297 -0
- package/dist/skills/zon-ui/references/components/chart.md +739 -0
- package/dist/skills/zon-ui/references/components/chat.md +417 -0
- package/dist/skills/zon-ui/references/components/checkbox.md +219 -0
- package/dist/skills/zon-ui/references/components/code-block.md +143 -0
- package/dist/skills/zon-ui/references/components/code-highlight.md +118 -0
- package/dist/skills/zon-ui/references/components/collapsible.md +146 -0
- package/dist/skills/zon-ui/references/components/color-picker.md +200 -0
- package/dist/skills/zon-ui/references/components/combobox.md +455 -0
- package/dist/skills/zon-ui/references/components/command.md +326 -0
- package/dist/skills/zon-ui/references/components/contact-form.md +562 -0
- package/dist/skills/zon-ui/references/components/context-menu.md +159 -0
- package/dist/skills/zon-ui/references/components/conversation.md +146 -0
- package/dist/skills/zon-ui/references/components/copy-button.md +162 -0
- package/dist/skills/zon-ui/references/components/crm.md +1022 -0
- package/dist/skills/zon-ui/references/components/dashboard.md +612 -0
- package/dist/skills/zon-ui/references/components/data-table.md +776 -0
- package/dist/skills/zon-ui/references/components/date-picker.md +444 -0
- package/dist/skills/zon-ui/references/components/dialog.md +335 -0
- package/dist/skills/zon-ui/references/components/direction.md +165 -0
- package/dist/skills/zon-ui/references/components/drawer.md +276 -0
- package/dist/skills/zon-ui/references/components/drawing.md +94 -0
- package/dist/skills/zon-ui/references/components/empty.md +225 -0
- package/dist/skills/zon-ui/references/components/feature-list.md +412 -0
- package/dist/skills/zon-ui/references/components/field.md +209 -0
- package/dist/skills/zon-ui/references/components/file-drop.md +234 -0
- package/dist/skills/zon-ui/references/components/filter-bar.md +485 -0
- package/dist/skills/zon-ui/references/components/form.md +970 -0
- package/dist/skills/zon-ui/references/components/graph.md +339 -0
- package/dist/skills/zon-ui/references/components/illustration.md +497 -0
- package/dist/skills/zon-ui/references/components/inbox.md +263 -0
- package/dist/skills/zon-ui/references/components/input-group.md +339 -0
- package/dist/skills/zon-ui/references/components/input.md +189 -0
- package/dist/skills/zon-ui/references/components/item.md +277 -0
- package/dist/skills/zon-ui/references/components/kanban.md +626 -0
- package/dist/skills/zon-ui/references/components/kbd.md +116 -0
- package/dist/skills/zon-ui/references/components/label.md +104 -0
- package/dist/skills/zon-ui/references/components/layout.md +291 -0
- package/dist/skills/zon-ui/references/components/lightbox.md +235 -0
- package/dist/skills/zon-ui/references/components/locale.md +279 -0
- package/dist/skills/zon-ui/references/components/logo.md +257 -0
- package/dist/skills/zon-ui/references/components/markdown-editor.md +558 -0
- package/dist/skills/zon-ui/references/components/mentions.md +512 -0
- package/dist/skills/zon-ui/references/components/menu.md +218 -0
- package/dist/skills/zon-ui/references/components/menubar.md +292 -0
- package/dist/skills/zon-ui/references/components/message.md +243 -0
- package/dist/skills/zon-ui/references/components/meter.md +105 -0
- package/dist/skills/zon-ui/references/components/money-input.md +333 -0
- package/dist/skills/zon-ui/references/components/native-select.md +197 -0
- package/dist/skills/zon-ui/references/components/navigation-menu.md +253 -0
- package/dist/skills/zon-ui/references/components/number-field.md +210 -0
- package/dist/skills/zon-ui/references/components/number-roll.md +175 -0
- package/dist/skills/zon-ui/references/components/onboarding.md +896 -0
- package/dist/skills/zon-ui/references/components/otp-field.md +166 -0
- package/dist/skills/zon-ui/references/components/pagination.md +109 -0
- package/dist/skills/zon-ui/references/components/pdf-viewer.md +177 -0
- package/dist/skills/zon-ui/references/components/phone-input.md +252 -0
- package/dist/skills/zon-ui/references/components/popover.md +176 -0
- package/dist/skills/zon-ui/references/components/preview-card.md +193 -0
- package/dist/skills/zon-ui/references/components/pricing.md +724 -0
- package/dist/skills/zon-ui/references/components/progress.md +92 -0
- package/dist/skills/zon-ui/references/components/prompt-input.md +307 -0
- package/dist/skills/zon-ui/references/components/pull-to-refresh.md +188 -0
- package/dist/skills/zon-ui/references/components/quote.md +115 -0
- package/dist/skills/zon-ui/references/components/radio-group.md +215 -0
- package/dist/skills/zon-ui/references/components/rating.md +260 -0
- package/dist/skills/zon-ui/references/components/reasoning.md +102 -0
- package/dist/skills/zon-ui/references/components/resizable.md +213 -0
- package/dist/skills/zon-ui/references/components/response.md +170 -0
- package/dist/skills/zon-ui/references/components/scheduler.md +732 -0
- package/dist/skills/zon-ui/references/components/scroll-area.md +122 -0
- package/dist/skills/zon-ui/references/components/select.md +351 -0
- package/dist/skills/zon-ui/references/components/separator.md +103 -0
- package/dist/skills/zon-ui/references/components/settings.md +793 -0
- package/dist/skills/zon-ui/references/components/shop.md +1715 -0
- package/dist/skills/zon-ui/references/components/sidebar.md +813 -0
- package/dist/skills/zon-ui/references/components/sign-in.md +1639 -0
- package/dist/skills/zon-ui/references/components/site-header.md +303 -0
- package/dist/skills/zon-ui/references/components/skeleton.md +256 -0
- package/dist/skills/zon-ui/references/components/slider.md +172 -0
- package/dist/skills/zon-ui/references/components/sortable.md +405 -0
- package/dist/skills/zon-ui/references/components/sources.md +106 -0
- package/dist/skills/zon-ui/references/components/spinner.md +222 -0
- package/dist/skills/zon-ui/references/components/stat.md +267 -0
- package/dist/skills/zon-ui/references/components/stepper.md +285 -0
- package/dist/skills/zon-ui/references/components/suggestions.md +146 -0
- package/dist/skills/zon-ui/references/components/swipe-actions.md +344 -0
- package/dist/skills/zon-ui/references/components/switch.md +160 -0
- package/dist/skills/zon-ui/references/components/table.md +999 -0
- package/dist/skills/zon-ui/references/components/tabs.md +258 -0
- package/dist/skills/zon-ui/references/components/tag.md +115 -0
- package/dist/skills/zon-ui/references/components/tags-input.md +216 -0
- package/dist/skills/zon-ui/references/components/textarea.md +95 -0
- package/dist/skills/zon-ui/references/components/theme-editor.md +3940 -0
- package/dist/skills/zon-ui/references/components/theme.md +362 -0
- package/dist/skills/zon-ui/references/components/time-field.md +222 -0
- package/dist/skills/zon-ui/references/components/timeline.md +285 -0
- package/dist/skills/zon-ui/references/components/tippy.md +243 -0
- package/dist/skills/zon-ui/references/components/toast.md +220 -0
- package/dist/skills/zon-ui/references/components/toggle-group.md +261 -0
- package/dist/skills/zon-ui/references/components/toggle.md +167 -0
- package/dist/skills/zon-ui/references/components/tool-call.md +146 -0
- package/dist/skills/zon-ui/references/components/toolbar.md +260 -0
- package/dist/skills/zon-ui/references/components/tooltip.md +172 -0
- package/dist/skills/zon-ui/references/components/tour.md +423 -0
- package/dist/skills/zon-ui/references/components/tree.md +481 -0
- package/dist/skills/zon-ui/references/components/typography.md +347 -0
- package/dist/skills/zon-ui/references/components/video-player.md +386 -0
- package/dist/skills/zon-ui/references/marketing.md +467 -0
- package/dist/skills/zon-ui/references/motion.md +455 -0
- package/dist/skills/zon-ui/references/recipes.md +1232 -0
- package/dist/skills/zon-ui/references/tokens.md +866 -0
- package/dist/sources/accordion.css +4 -0
- package/dist/sources/action-sheet.css +11 -0
- package/dist/sources/alert-dialog.css +6 -0
- package/dist/sources/alert.css +3 -0
- package/dist/sources/app-bar.css +14 -0
- package/dist/sources/ascii-field.css +3 -0
- package/dist/sources/aspect-ratio.css +3 -0
- package/dist/sources/audio-player.css +20 -0
- package/dist/sources/avatar.css +3 -0
- package/dist/sources/badge.css +3 -0
- package/dist/sources/bottom-nav.css +9 -0
- package/dist/sources/breadcrumb.css +14 -0
- package/dist/sources/button-group.css +3 -0
- package/dist/sources/button.css +9 -0
- package/dist/sources/calendar.css +13 -0
- package/dist/sources/card.css +3 -0
- package/dist/sources/carousel.css +11 -0
- package/dist/sources/chart.css +5 -0
- package/dist/sources/checkbox.css +6 -0
- package/dist/sources/code-block.css +13 -0
- package/dist/sources/collapsible.css +4 -0
- package/dist/sources/color-picker.css +13 -0
- package/dist/sources/combobox.css +13 -0
- package/dist/sources/command.css +13 -0
- package/dist/sources/context-menu.css +12 -0
- package/dist/sources/conversation.css +10 -0
- package/dist/sources/copy-button.css +10 -0
- package/dist/sources/data-table.css +27 -0
- package/dist/sources/date-picker.css +20 -0
- package/dist/sources/dialog.css +9 -0
- package/dist/sources/direction.css +2 -0
- package/dist/sources/drawer.css +9 -0
- package/dist/sources/drawing.css +5 -0
- package/dist/sources/empty.css +3 -0
- package/dist/sources/feature-list.css +4 -0
- package/dist/sources/field.css +4 -0
- package/dist/sources/file-drop.css +15 -0
- package/dist/sources/filter-bar.css +30 -0
- package/dist/sources/form.css +4 -0
- package/dist/sources/graph.css +19 -0
- package/dist/sources/illustration.css +28 -0
- package/dist/sources/input-group.css +7 -0
- package/dist/sources/input.css +3 -0
- package/dist/sources/item.css +4 -0
- package/dist/sources/kbd.css +5 -0
- package/dist/sources/label.css +3 -0
- package/dist/sources/layout.css +3 -0
- package/dist/sources/lightbox.css +33 -0
- package/dist/sources/locale.css +2 -0
- package/dist/sources/logo.css +4 -0
- package/dist/sources/markdown-editor.css +41 -0
- package/dist/sources/mentions.css +13 -0
- package/dist/sources/menu.css +11 -0
- package/dist/sources/menubar.css +14 -0
- package/dist/sources/message.css +16 -0
- package/dist/sources/meter.css +4 -0
- package/dist/sources/money-input.css +10 -0
- package/dist/sources/native-select.css +4 -0
- package/dist/sources/navigation-menu.css +8 -0
- package/dist/sources/number-field.css +8 -0
- package/dist/sources/number-roll.css +6 -0
- package/dist/sources/otp-field.css +5 -0
- package/dist/sources/pagination.css +11 -0
- package/dist/sources/pdf-viewer.css +30 -0
- package/dist/sources/phone-input.css +20 -0
- package/dist/sources/popover.css +7 -0
- package/dist/sources/preview-card.css +7 -0
- package/dist/sources/progress.css +4 -0
- package/dist/sources/prompt-input.css +15 -0
- package/dist/sources/pull-to-refresh.css +14 -0
- package/dist/sources/quote.css +3 -0
- package/dist/sources/radio-group.css +5 -0
- package/dist/sources/rating.css +6 -0
- package/dist/sources/reasoning.css +6 -0
- package/dist/sources/resizable.css +4 -0
- package/dist/sources/response.css +16 -0
- package/dist/sources/scheduler.css +44 -0
- package/dist/sources/scroll-area.css +3 -0
- package/dist/sources/select.css +12 -0
- package/dist/sources/separator.css +3 -0
- package/dist/sources/sidebar.css +19 -0
- package/dist/sources/site-header.css +15 -0
- package/dist/sources/skeleton.css +3 -0
- package/dist/sources/slider.css +6 -0
- package/dist/sources/sortable.css +12 -0
- package/dist/sources/sources.css +6 -0
- package/dist/sources/spinner.css +6 -0
- package/dist/sources/stat.css +9 -0
- package/dist/sources/stepper.css +6 -0
- package/dist/sources/suggestions.css +10 -0
- package/dist/sources/swipe-actions.css +20 -0
- package/dist/sources/switch.css +5 -0
- package/dist/sources/table.css +7 -0
- package/dist/sources/tabs.css +5 -0
- package/dist/sources/tag.css +3 -0
- package/dist/sources/tags-input.css +6 -0
- package/dist/sources/textarea.css +3 -0
- package/dist/sources/theme.css +13 -0
- package/dist/sources/time-field.css +7 -0
- package/dist/sources/timeline.css +7 -0
- package/dist/sources/tippy.css +6 -0
- package/dist/sources/toast.css +6 -0
- package/dist/sources/toggle-group.css +5 -0
- package/dist/sources/toggle.css +3 -0
- package/dist/sources/tool-call.css +16 -0
- package/dist/sources/toolbar.css +14 -0
- package/dist/sources/tooltip.css +6 -0
- package/dist/sources/tour.css +14 -0
- package/dist/sources/tree.css +6 -0
- package/dist/sources/typography.css +4 -0
- package/dist/sources/video-player.css +21 -0
- package/dist/styles/ai.css +3 -0
- package/dist/styles/brand.css +98 -0
- package/dist/styles/core.css +266 -0
- package/dist/styles/editor.css +3 -0
- package/dist/styles/expressive.css +35 -56
- package/dist/styles/fonts.css +61 -117
- package/dist/styles/graph.css +4 -0
- package/dist/styles/illustration.css +4 -0
- package/dist/styles/index.css +11 -201
- package/dist/styles/material.css +138 -12
- package/dist/styles/parts/ai.css +18 -13
- package/dist/styles/parts/brand.css +2 -2
- package/dist/styles/parts/controls.css +29 -20
- package/dist/styles/parts/data.css +13 -9
- package/dist/styles/parts/editor.css +372 -0
- package/dist/styles/parts/feedback.css +32 -2
- package/dist/styles/parts/foundations.css +12 -7
- package/dist/styles/parts/graph.css +25 -9
- package/dist/styles/parts/inputs.css +172 -9
- package/dist/styles/parts/isometric.css +6 -5
- package/dist/styles/parts/navigation.css +206 -27
- package/dist/styles/parts/overlays.css +19 -4
- package/dist/styles/parts/pdf.css +2 -2
- package/dist/styles/pdf.css +3 -0
- package/dist/styles/prose.css +3 -0
- package/dist/styles/tokens.css +89 -14
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +5 -0
- package/dist/vite.d.ts +48 -59
- package/dist/vite.js +54 -21
- package/package.json +69 -2
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
# Form
|
|
2
|
+
|
|
3
|
+
```tsx
|
|
4
|
+
import { Button, Checkbox, Field, FieldDescription, FieldError, FieldLabel, Form, FormActions, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Textarea } from "@zonsh/ui";
|
|
5
|
+
import { ArrowRightIcon } from "lucide-react";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
|
|
8
|
+
const topics = [
|
|
9
|
+
{ value: "order", label: "An order I placed" },
|
|
10
|
+
{ value: "shipping", label: "Shipping and delivery" },
|
|
11
|
+
{ value: "returns", label: "Returns and refunds" },
|
|
12
|
+
{ value: "product", label: "A question about a product" },
|
|
13
|
+
{ value: "other", label: "Something else" },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export function ContactForm() {
|
|
17
|
+
const [sentTo, setSentTo] = React.useState<string | null>(null);
|
|
18
|
+
|
|
19
|
+
if (sentTo) {
|
|
20
|
+
return (
|
|
21
|
+
<div className="flex w-full max-w-xl flex-col gap-3 surface-card">
|
|
22
|
+
<p className="eyebrow">Message sent</p>
|
|
23
|
+
<p className="display text-3xl">Thank you, {sentTo}.</p>
|
|
24
|
+
<p className="text-muted-foreground">We will reply by email. Nothing else to do for now.</p>
|
|
25
|
+
<Button variant="secondary" className="self-start" onClick={() => setSentTo(null)}>
|
|
26
|
+
Write another message
|
|
27
|
+
</Button>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Form
|
|
34
|
+
className="@container w-full max-w-xl surface-card"
|
|
35
|
+
onFormSubmit={(values) => setSentTo(String(values.name).split(" ")[0] ?? "")}
|
|
36
|
+
>
|
|
37
|
+
<Field name="name">
|
|
38
|
+
<FieldLabel>Your name</FieldLabel>
|
|
39
|
+
<Input required autoComplete="name" placeholder="Alex Weber" />
|
|
40
|
+
<FieldError match="valueMissing">Tell us what to call you.</FieldError>
|
|
41
|
+
</Field>
|
|
42
|
+
|
|
43
|
+
<Field name="email">
|
|
44
|
+
<FieldLabel>Email</FieldLabel>
|
|
45
|
+
<Input required type="email" autoComplete="email" placeholder="alex@example.com" />
|
|
46
|
+
<FieldError match="valueMissing">We need an email address to reply to.</FieldError>
|
|
47
|
+
<FieldError match="typeMismatch">
|
|
48
|
+
That does not look like an email address. Check the @ part.
|
|
49
|
+
</FieldError>
|
|
50
|
+
</Field>
|
|
51
|
+
|
|
52
|
+
<Field name="topic">
|
|
53
|
+
<FieldLabel>What is it about?</FieldLabel>
|
|
54
|
+
<Select items={topics} required>
|
|
55
|
+
<SelectTrigger>
|
|
56
|
+
<SelectValue placeholder="Choose the closest fit" />
|
|
57
|
+
</SelectTrigger>
|
|
58
|
+
<SelectContent>
|
|
59
|
+
{topics.map((topic) => (
|
|
60
|
+
<SelectItem key={topic.value} value={topic.value}>
|
|
61
|
+
{topic.label}
|
|
62
|
+
</SelectItem>
|
|
63
|
+
))}
|
|
64
|
+
</SelectContent>
|
|
65
|
+
</Select>
|
|
66
|
+
<FieldError match="valueMissing">Pick one. "Something else" is a fine answer.</FieldError>
|
|
67
|
+
</Field>
|
|
68
|
+
|
|
69
|
+
<Field name="context">
|
|
70
|
+
<FieldLabel>Your message</FieldLabel>
|
|
71
|
+
<Textarea required minLength={20} placeholder="If it is about an order, the order number helps." />
|
|
72
|
+
<FieldDescription>Two or three sentences are plenty.</FieldDescription>
|
|
73
|
+
<FieldError match="valueMissing">A sentence or two helps us answer the first time.</FieldError>
|
|
74
|
+
<FieldError match="tooShort">A little more detail, please: at least 20 characters.</FieldError>
|
|
75
|
+
</Field>
|
|
76
|
+
|
|
77
|
+
<Field name="consent">
|
|
78
|
+
<FieldLabel>
|
|
79
|
+
<Checkbox required />I agree that my details are stored to answer this message.
|
|
80
|
+
</FieldLabel>
|
|
81
|
+
<FieldError match="valueMissing" className="pl-7">
|
|
82
|
+
Tick this box so we are allowed to reply.
|
|
83
|
+
</FieldError>
|
|
84
|
+
</Field>
|
|
85
|
+
|
|
86
|
+
<FormActions>
|
|
87
|
+
<Button type="submit" size="lg">
|
|
88
|
+
Send message
|
|
89
|
+
<ArrowRightIcon className="rtl:-scale-x-100" />
|
|
90
|
+
</Button>
|
|
91
|
+
</FormActions>
|
|
92
|
+
</Form>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Base UI's `Form`: a native `<form>` as a column with 20px between fields. It runs each `Field`'s validation on submit and maps server errors onto fields by `name`. Native constraints (`required`, `type="email"`) catch problems before sending; a `FieldError` with `match` replaces the browser's message with a human one, and after the first submit fields re-check as they change. End with `FormActions`: the submit on the **right**, where the eye ends, with Cancel or Back to its left. Where it sits: a form that is part of a page — a waitlist in a hero, a contact section, settings — sits on the page, grouped by hairlines, never in a card. Only a form that is the whole screen on its own (sign-in, a setup step centred under the logo) or an object people open (a dialog) takes a card (`className="surface-card"`).
|
|
98
|
+
|
|
99
|
+
## Usage
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { Button, Field, FieldError, FieldLabel, Form, FormActions, Input } from "@zonsh/ui";
|
|
103
|
+
|
|
104
|
+
<Form onFormSubmit={(values) => send(values)}>
|
|
105
|
+
<Field name="email">
|
|
106
|
+
<FieldLabel>Email</FieldLabel>
|
|
107
|
+
<Input required type="email" />
|
|
108
|
+
<FieldError match="valueMissing">We need an email address to reply to.</FieldError>
|
|
109
|
+
</Field>
|
|
110
|
+
<FormActions>
|
|
111
|
+
<Button type="submit">Send message</Button>
|
|
112
|
+
</FormActions>
|
|
113
|
+
</Form>;
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The props you'll reach for: `onFormSubmit`, `errors`, `FormActions.align`.
|
|
117
|
+
|
|
118
|
+
## When to use
|
|
119
|
+
|
|
120
|
+
- Any group of fields submitted together: contact, checkout, saved settings.
|
|
121
|
+
- One field that saves itself, such as a switch, does not need a form.
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
### Server errors
|
|
126
|
+
|
|
127
|
+
`errors` is keyed by field `name`; a bare `<FieldError />` shows each. `align="between"` puts the confirmation left — `--success` with a check, `role="status"` so it is announced.
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import { Button, Field, FieldDescription, FieldError, FieldLabel, Form, FormActions, Input } from "@zonsh/ui";
|
|
131
|
+
import { CheckIcon } from "lucide-react";
|
|
132
|
+
import * as React from "react";
|
|
133
|
+
|
|
134
|
+
async function checkWebsite(url: string) {
|
|
135
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
136
|
+
try {
|
|
137
|
+
const { hostname } = new URL(url);
|
|
138
|
+
if (!hostname.includes(".")) return "We could not reach that address. Check the spelling.";
|
|
139
|
+
} catch {
|
|
140
|
+
return "Start the address with https://";
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function ServerErrors() {
|
|
146
|
+
const [errors, setErrors] = React.useState<Record<string, string>>({});
|
|
147
|
+
const [pending, setPending] = React.useState(false);
|
|
148
|
+
const [saved, setSaved] = React.useState(false);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<Form
|
|
152
|
+
className="w-full max-w-md"
|
|
153
|
+
errors={errors}
|
|
154
|
+
onFormSubmit={async (values) => {
|
|
155
|
+
setPending(true);
|
|
156
|
+
setSaved(false);
|
|
157
|
+
const error = await checkWebsite(String(values.website));
|
|
158
|
+
setErrors(error ? { website: error } : {});
|
|
159
|
+
setSaved(!error);
|
|
160
|
+
setPending(false);
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
<Field name="website">
|
|
164
|
+
<FieldLabel>Your website</FieldLabel>
|
|
165
|
+
<Input required placeholder="https://example.com" />
|
|
166
|
+
<FieldDescription>Shown on your public profile, next to your name.</FieldDescription>
|
|
167
|
+
<FieldError />
|
|
168
|
+
</Field>
|
|
169
|
+
<FormActions align="between">
|
|
170
|
+
<span role="status" className="flex items-center gap-1.5 font-mono text-xs text-success">
|
|
171
|
+
{saved && (
|
|
172
|
+
<>
|
|
173
|
+
<CheckIcon aria-hidden className="size-3.5" />
|
|
174
|
+
Saved
|
|
175
|
+
</>
|
|
176
|
+
)}
|
|
177
|
+
</span>
|
|
178
|
+
<Button type="submit" variant="secondary" disabled={pending} focusableWhenDisabled>
|
|
179
|
+
{pending ? "Checking…" : "Save website"}
|
|
180
|
+
</Button>
|
|
181
|
+
</FormActions>
|
|
182
|
+
</Form>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Sign in
|
|
188
|
+
|
|
189
|
+
A password with `InputGroupPasswordToggle`; `autoComplete="username"` and `"current-password"` for password managers; "Forgot your password?" left, "Sign in" right. For sign-up, use `autoComplete="new-password"` and state the rules in a `FieldDescription` before anyone types.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import { Button, Checkbox, Field, FieldError, FieldLabel, Form, FormActions, Input, InputGroup, InputGroupAddon, InputGroupInput, InputGroupPasswordToggle } from "@zonsh/ui";
|
|
193
|
+
import * as React from "react";
|
|
194
|
+
|
|
195
|
+
export function SignIn() {
|
|
196
|
+
const [visible, setVisible] = React.useState(false);
|
|
197
|
+
const [pending, setPending] = React.useState(false);
|
|
198
|
+
const [signedIn, setSignedIn] = React.useState<string | null>(null);
|
|
199
|
+
|
|
200
|
+
if (signedIn) {
|
|
201
|
+
return (
|
|
202
|
+
<div className="flex w-full max-w-sm flex-col gap-3 surface-card">
|
|
203
|
+
<p className="eyebrow">Signed in</p>
|
|
204
|
+
<p className="display text-3xl">Welcome back.</p>
|
|
205
|
+
<p className="text-muted-foreground">You are signed in as {signedIn}.</p>
|
|
206
|
+
<Button variant="secondary" className="self-start" onClick={() => setSignedIn(null)}>
|
|
207
|
+
Sign out
|
|
208
|
+
</Button>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<Form
|
|
215
|
+
className="w-full max-w-sm surface-card"
|
|
216
|
+
onFormSubmit={async (values) => {
|
|
217
|
+
setPending(true);
|
|
218
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
219
|
+
setPending(false);
|
|
220
|
+
setSignedIn(String(values.email));
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<div className="flex flex-col gap-1.5">
|
|
224
|
+
<p className="display text-3xl">Sign in</p>
|
|
225
|
+
<p className="text-sm text-muted-foreground">Use the email address your invitation went to.</p>
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
<Field name="email">
|
|
229
|
+
<FieldLabel>Email</FieldLabel>
|
|
230
|
+
<Input required type="email" autoComplete="username" placeholder="alex@example.com" />
|
|
231
|
+
<FieldError match="valueMissing">Enter the email address you signed up with.</FieldError>
|
|
232
|
+
<FieldError match="typeMismatch">
|
|
233
|
+
That does not look like an email address. Check the @ part.
|
|
234
|
+
</FieldError>
|
|
235
|
+
</Field>
|
|
236
|
+
|
|
237
|
+
<Field name="password">
|
|
238
|
+
<FieldLabel>Password</FieldLabel>
|
|
239
|
+
<InputGroup>
|
|
240
|
+
<InputGroupInput
|
|
241
|
+
required
|
|
242
|
+
type={visible ? "text" : "password"}
|
|
243
|
+
autoComplete="current-password"
|
|
244
|
+
spellCheck={false}
|
|
245
|
+
/>
|
|
246
|
+
<InputGroupAddon align="inline-end">
|
|
247
|
+
<InputGroupPasswordToggle visible={visible} onVisibleChange={setVisible} />
|
|
248
|
+
</InputGroupAddon>
|
|
249
|
+
</InputGroup>
|
|
250
|
+
<FieldError match="valueMissing">Enter your password.</FieldError>
|
|
251
|
+
</Field>
|
|
252
|
+
|
|
253
|
+
<Field name="remember">
|
|
254
|
+
<FieldLabel>
|
|
255
|
+
<Checkbox />
|
|
256
|
+
Keep me signed in on this device
|
|
257
|
+
</FieldLabel>
|
|
258
|
+
</Field>
|
|
259
|
+
|
|
260
|
+
<FormActions align="between">
|
|
261
|
+
<Button variant="link" nativeButton={false} render={<a href="#forgot-password" />}>
|
|
262
|
+
Forgot your password?
|
|
263
|
+
</Button>
|
|
264
|
+
<Button type="submit" disabled={pending} focusableWhenDisabled>
|
|
265
|
+
{pending ? "Signing in…" : "Sign in"}
|
|
266
|
+
</Button>
|
|
267
|
+
</FormActions>
|
|
268
|
+
</Form>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## With form libraries
|
|
274
|
+
|
|
275
|
+
`Form` and `Field` do the layout and wiring, whoever validates. Hand the library's submit handler to `onSubmit`, each field's error to `Field error`, and end the field with a bare `<FieldError />`:
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
<Field error={errors.email}>
|
|
279
|
+
<FieldLabel>Email</FieldLabel>
|
|
280
|
+
<Input {...register("email")} type="email" />
|
|
281
|
+
<FieldError />
|
|
282
|
+
</Field>
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`error` takes a message, an object with `message` (React Hook Form's `fieldState.error`) or a list (TanStack Form's `field.state.meta.errors`, one per line). It marks the field invalid (`aria-invalid`, the red edge, `aria-describedby`), and while it shows, `Form` passes every submit to `onSubmit` so the library re-checks. Leave native constraints off the controls: the schema says what is valid, once.
|
|
286
|
+
|
|
287
|
+
### React Hook Form
|
|
288
|
+
|
|
289
|
+
With `zodResolver`. Text fields take `register`; others go through a `Controller`, whose `field.ref` lets it focus the first error. Errors appear on submit and clear as fields are fixed.
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
293
|
+
import { Button, Checkbox, Field, FieldError, FieldItem, FieldLabel, Fieldset, FieldsetLegend, Form, FormActions, Input, NumberField, Radio, RadioGroup, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Textarea } from "@zonsh/ui";
|
|
294
|
+
import { DatePicker } from "@zonsh/ui/date-picker";
|
|
295
|
+
import { format, startOfToday } from "date-fns";
|
|
296
|
+
import { CheckIcon } from "lucide-react";
|
|
297
|
+
import { Controller, useForm } from "react-hook-form";
|
|
298
|
+
import { z } from "zod";
|
|
299
|
+
import * as React from "react";
|
|
300
|
+
|
|
301
|
+
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
302
|
+
|
|
303
|
+
/** The submit button: keeps its width while pending, with the spinner over the label. */
|
|
304
|
+
function SubmitButton({ pending, label, children }: { pending: boolean; label: string; children: string }) {
|
|
305
|
+
return (
|
|
306
|
+
<Button type="submit" loading={pending} loadingLabel={label}>
|
|
307
|
+
{children}
|
|
308
|
+
</Button>
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Replaces a form once it is sent. Focus moves here, so keyboard and screen reader users follow. */
|
|
313
|
+
function Done({
|
|
314
|
+
title,
|
|
315
|
+
action,
|
|
316
|
+
onBack,
|
|
317
|
+
children,
|
|
318
|
+
}: {
|
|
319
|
+
title: string;
|
|
320
|
+
action: string;
|
|
321
|
+
onBack: () => void;
|
|
322
|
+
children: React.ReactNode;
|
|
323
|
+
}) {
|
|
324
|
+
const ref = React.useRef<HTMLElement>(null);
|
|
325
|
+
React.useEffect(() => ref.current?.focus(), []);
|
|
326
|
+
return (
|
|
327
|
+
<section
|
|
328
|
+
ref={ref}
|
|
329
|
+
tabIndex={-1}
|
|
330
|
+
aria-label={title}
|
|
331
|
+
className="flex w-full max-w-xl flex-col items-start gap-3 surface-card outline-none"
|
|
332
|
+
>
|
|
333
|
+
<p className="flex items-center gap-1.5 eyebrow text-success">
|
|
334
|
+
<CheckIcon aria-hidden className="size-3.5" />
|
|
335
|
+
{title}
|
|
336
|
+
</p>
|
|
337
|
+
<p className="text-muted-foreground">{children}</p>
|
|
338
|
+
<Button variant="secondary" onClick={onBack}>
|
|
339
|
+
{action}
|
|
340
|
+
</Button>
|
|
341
|
+
</section>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/* ── React Hook Form + Zod ─────────────────────────────────────────────────── */
|
|
346
|
+
|
|
347
|
+
const workshops = [
|
|
348
|
+
{ value: "wheel", label: "Wheel throwing for beginners" },
|
|
349
|
+
{ value: "handbuilding", label: "Hand building: pinch, coil and slab" },
|
|
350
|
+
{ value: "glazing", label: "Glazing your own pieces" },
|
|
351
|
+
];
|
|
352
|
+
|
|
353
|
+
const booking = z.object({
|
|
354
|
+
name: z.string().trim().min(1, "Tell us whose name to put on the list."),
|
|
355
|
+
email: z.email("Enter the email address we should send the booking to."),
|
|
356
|
+
workshop: z.enum(["wheel", "handbuilding", "glazing"], "Choose one of the three workshops."),
|
|
357
|
+
day: z.date("Pick the day you want to come."),
|
|
358
|
+
places: z
|
|
359
|
+
.number("Say how many places to keep.")
|
|
360
|
+
.int()
|
|
361
|
+
.min(1)
|
|
362
|
+
.max(4, "Four places at most: two people share a wheel."),
|
|
363
|
+
experience: z.enum(["none", "some", "regular"], "Tell us how much clay you have worked with."),
|
|
364
|
+
notes: z.string().max(300, "Keep it under 300 characters. We can talk about the rest on the day."),
|
|
365
|
+
terms: z.boolean().refine((agreed) => agreed, "Tick this box to book."),
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
export function WithReactHookForm() {
|
|
369
|
+
const [booked, setBooked] = React.useState<z.infer<typeof booking> | null>(null);
|
|
370
|
+
const { control, register, handleSubmit, reset, formState } = useForm({
|
|
371
|
+
resolver: zodResolver(booking),
|
|
372
|
+
defaultValues: { name: "", email: "", places: 1, notes: "", terms: false },
|
|
373
|
+
});
|
|
374
|
+
const { errors, isSubmitting } = formState;
|
|
375
|
+
|
|
376
|
+
if (booked) {
|
|
377
|
+
return (
|
|
378
|
+
<Done
|
|
379
|
+
title="Booked"
|
|
380
|
+
action="Book another workshop"
|
|
381
|
+
onBack={() => {
|
|
382
|
+
reset();
|
|
383
|
+
setBooked(null);
|
|
384
|
+
}}
|
|
385
|
+
>
|
|
386
|
+
{booked.places === 1 ? "One place" : `${booked.places} places`} on {format(booked.day, "EEEE d MMMM")}
|
|
387
|
+
. The confirmation is on its way to {booked.email}.
|
|
388
|
+
</Done>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<Form
|
|
394
|
+
className="@container w-full max-w-xl surface-card"
|
|
395
|
+
onSubmit={handleSubmit(async (values) => {
|
|
396
|
+
await wait(600);
|
|
397
|
+
setBooked(values);
|
|
398
|
+
})}
|
|
399
|
+
>
|
|
400
|
+
<Field error={errors.name}>
|
|
401
|
+
<FieldLabel>Your name</FieldLabel>
|
|
402
|
+
<Input {...register("name")} autoComplete="name" />
|
|
403
|
+
<FieldError />
|
|
404
|
+
</Field>
|
|
405
|
+
|
|
406
|
+
<Field error={errors.email}>
|
|
407
|
+
<FieldLabel>Email</FieldLabel>
|
|
408
|
+
<Input {...register("email")} type="email" autoComplete="email" placeholder="alex@example.com" />
|
|
409
|
+
<FieldError />
|
|
410
|
+
</Field>
|
|
411
|
+
|
|
412
|
+
<Controller
|
|
413
|
+
control={control}
|
|
414
|
+
name="workshop"
|
|
415
|
+
render={({ field, fieldState }) => (
|
|
416
|
+
<Field error={fieldState.error}>
|
|
417
|
+
<FieldLabel>Workshop</FieldLabel>
|
|
418
|
+
<Select
|
|
419
|
+
items={workshops}
|
|
420
|
+
value={field.value ?? null}
|
|
421
|
+
onValueChange={field.onChange}
|
|
422
|
+
inputRef={field.ref}
|
|
423
|
+
>
|
|
424
|
+
<SelectTrigger onBlur={field.onBlur}>
|
|
425
|
+
<SelectValue placeholder="Choose a workshop" />
|
|
426
|
+
</SelectTrigger>
|
|
427
|
+
<SelectContent>
|
|
428
|
+
{workshops.map((workshop) => (
|
|
429
|
+
<SelectItem key={workshop.value} value={workshop.value}>
|
|
430
|
+
{workshop.label}
|
|
431
|
+
</SelectItem>
|
|
432
|
+
))}
|
|
433
|
+
</SelectContent>
|
|
434
|
+
</Select>
|
|
435
|
+
<FieldError />
|
|
436
|
+
</Field>
|
|
437
|
+
)}
|
|
438
|
+
/>
|
|
439
|
+
|
|
440
|
+
<div className="grid gap-5 @md:grid-cols-2">
|
|
441
|
+
<Controller
|
|
442
|
+
control={control}
|
|
443
|
+
name="day"
|
|
444
|
+
render={({ field, fieldState }) => (
|
|
445
|
+
<Field error={fieldState.error}>
|
|
446
|
+
<FieldLabel>Day</FieldLabel>
|
|
447
|
+
<DatePicker
|
|
448
|
+
value={field.value ?? null}
|
|
449
|
+
onValueChange={field.onChange}
|
|
450
|
+
onBlur={field.onBlur}
|
|
451
|
+
ref={field.ref}
|
|
452
|
+
calendar={{ disabled: { before: startOfToday() } }}
|
|
453
|
+
/>
|
|
454
|
+
<FieldError />
|
|
455
|
+
</Field>
|
|
456
|
+
)}
|
|
457
|
+
/>
|
|
458
|
+
<Controller
|
|
459
|
+
control={control}
|
|
460
|
+
name="places"
|
|
461
|
+
render={({ field, fieldState }) => (
|
|
462
|
+
<Field error={fieldState.error}>
|
|
463
|
+
<FieldLabel>Places</FieldLabel>
|
|
464
|
+
<NumberField
|
|
465
|
+
value={field.value ?? null}
|
|
466
|
+
onValueChange={field.onChange}
|
|
467
|
+
onBlur={field.onBlur}
|
|
468
|
+
inputRef={field.ref}
|
|
469
|
+
min={1}
|
|
470
|
+
max={4}
|
|
471
|
+
/>
|
|
472
|
+
<FieldError />
|
|
473
|
+
</Field>
|
|
474
|
+
)}
|
|
475
|
+
/>
|
|
476
|
+
</div>
|
|
477
|
+
|
|
478
|
+
<Controller
|
|
479
|
+
control={control}
|
|
480
|
+
name="experience"
|
|
481
|
+
render={({ field, fieldState }) => (
|
|
482
|
+
<Field error={fieldState.error}>
|
|
483
|
+
<Fieldset
|
|
484
|
+
render={
|
|
485
|
+
<RadioGroup value={field.value ?? null} onValueChange={field.onChange} inputRef={field.ref} />
|
|
486
|
+
}
|
|
487
|
+
>
|
|
488
|
+
<FieldsetLegend>Experience with clay</FieldsetLegend>
|
|
489
|
+
<FieldItem>
|
|
490
|
+
<FieldLabel>
|
|
491
|
+
<Radio value="none" />
|
|
492
|
+
Never, this is my first time
|
|
493
|
+
</FieldLabel>
|
|
494
|
+
</FieldItem>
|
|
495
|
+
<FieldItem>
|
|
496
|
+
<FieldLabel>
|
|
497
|
+
<Radio value="some" />A few times, at school or in a class
|
|
498
|
+
</FieldLabel>
|
|
499
|
+
</FieldItem>
|
|
500
|
+
<FieldItem>
|
|
501
|
+
<FieldLabel>
|
|
502
|
+
<Radio value="regular" />
|
|
503
|
+
Often, I have pieces of my own
|
|
504
|
+
</FieldLabel>
|
|
505
|
+
</FieldItem>
|
|
506
|
+
</Fieldset>
|
|
507
|
+
<FieldError />
|
|
508
|
+
</Field>
|
|
509
|
+
)}
|
|
510
|
+
/>
|
|
511
|
+
|
|
512
|
+
<Field error={errors.notes}>
|
|
513
|
+
<FieldLabel>Anything we should know?</FieldLabel>
|
|
514
|
+
<Textarea
|
|
515
|
+
{...register("notes")}
|
|
516
|
+
placeholder="An allergy, a wheelchair, a piece you want to finish…"
|
|
517
|
+
/>
|
|
518
|
+
<FieldError />
|
|
519
|
+
</Field>
|
|
520
|
+
|
|
521
|
+
<Controller
|
|
522
|
+
control={control}
|
|
523
|
+
name="terms"
|
|
524
|
+
render={({ field, fieldState }) => (
|
|
525
|
+
<Field error={fieldState.error}>
|
|
526
|
+
<FieldLabel>
|
|
527
|
+
<Checkbox checked={field.value} onCheckedChange={field.onChange} ref={field.ref} />I have read
|
|
528
|
+
the terms: cancelling is free up to two days before
|
|
529
|
+
</FieldLabel>
|
|
530
|
+
<FieldError className="pl-7" />
|
|
531
|
+
</Field>
|
|
532
|
+
)}
|
|
533
|
+
/>
|
|
534
|
+
|
|
535
|
+
<FormActions>
|
|
536
|
+
<SubmitButton pending={isSubmitting} label="Booking your places">
|
|
537
|
+
Book places
|
|
538
|
+
</SubmitButton>
|
|
539
|
+
</FormActions>
|
|
540
|
+
</Form>
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/* ── TanStack Form + Zod ───────────────────────────────────────────────────── */
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### TanStack Form
|
|
548
|
+
|
|
549
|
+
Any Standard Schema with `revalidateLogic()`: checked on submit, then on change. TanStack Form does not move focus, so `onSubmitInvalid` focuses the first `aria-invalid` control.
|
|
550
|
+
|
|
551
|
+
```tsx
|
|
552
|
+
import { revalidateLogic, useForm as useTanStackForm } from "@tanstack/react-form";
|
|
553
|
+
import { Button, Checkbox, CheckboxGroup, Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, Field, FieldDescription, FieldError, FieldItem, FieldLabel, Fieldset, FieldsetLegend, Form, FormActions, Input, Slider, TagsInput, TimeField } from "@zonsh/ui";
|
|
554
|
+
import { CheckIcon } from "lucide-react";
|
|
555
|
+
import { z } from "zod";
|
|
556
|
+
import * as React from "react";
|
|
557
|
+
|
|
558
|
+
// topics, wait, SubmitButton, Done: as in the first example on this page that uses them.
|
|
559
|
+
|
|
560
|
+
const languages = [
|
|
561
|
+
"C",
|
|
562
|
+
"C#",
|
|
563
|
+
"C++",
|
|
564
|
+
"Elixir",
|
|
565
|
+
"Go",
|
|
566
|
+
"Haskell",
|
|
567
|
+
"Java",
|
|
568
|
+
"Kotlin",
|
|
569
|
+
"OCaml",
|
|
570
|
+
"PHP",
|
|
571
|
+
"Python",
|
|
572
|
+
"Ruby",
|
|
573
|
+
"Rust",
|
|
574
|
+
"Swift",
|
|
575
|
+
"TypeScript",
|
|
576
|
+
"Zig",
|
|
577
|
+
];
|
|
578
|
+
|
|
579
|
+
const reports = [
|
|
580
|
+
{ value: "failed", label: "A build fails" },
|
|
581
|
+
{ value: "release", label: "A release is published" },
|
|
582
|
+
{ value: "advisory", label: "A dependency has a security advisory" },
|
|
583
|
+
];
|
|
584
|
+
|
|
585
|
+
const project = z.object({
|
|
586
|
+
name: z.string().regex(/^[a-z0-9-]{3,40}$/, "Use 3 to 40 lowercase letters, digits and dashes."),
|
|
587
|
+
language: z.string("Choose the main language, so the build gets the right image."),
|
|
588
|
+
topics: z.array(z.string()).min(1, "Add at least one topic, so people can find the project."),
|
|
589
|
+
buildAt: z
|
|
590
|
+
.string("Pick a time for the nightly build.")
|
|
591
|
+
.refine((time) => time < "06:00", "Nightly builds run between midnight and 6:00."),
|
|
592
|
+
retention: z.number(),
|
|
593
|
+
reports: z.array(z.string()).min(1, "Choose at least one, or nobody hears about a failed build."),
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
export function WithTanStackForm() {
|
|
597
|
+
const [created, setCreated] = React.useState<string | null>(null);
|
|
598
|
+
const formRef = React.useRef<HTMLFormElement>(null);
|
|
599
|
+
const form = useTanStackForm({
|
|
600
|
+
defaultValues: {
|
|
601
|
+
name: "",
|
|
602
|
+
language: null as string | null,
|
|
603
|
+
topics: [] as string[],
|
|
604
|
+
buildAt: "02:00" as string | null,
|
|
605
|
+
retention: 30,
|
|
606
|
+
reports: ["failed"],
|
|
607
|
+
},
|
|
608
|
+
// Checked on submit, then again at every change.
|
|
609
|
+
validationLogic: revalidateLogic(),
|
|
610
|
+
validators: { onDynamic: project },
|
|
611
|
+
onSubmit: async ({ value }) => {
|
|
612
|
+
await wait(600);
|
|
613
|
+
setCreated(value.name);
|
|
614
|
+
},
|
|
615
|
+
// Once the errors are drawn, focus the first field that has one.
|
|
616
|
+
onSubmitInvalid: () =>
|
|
617
|
+
requestAnimationFrame(() =>
|
|
618
|
+
formRef.current?.querySelector<HTMLElement>("[aria-invalid=true]")?.focus(),
|
|
619
|
+
),
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
if (created) {
|
|
623
|
+
return (
|
|
624
|
+
<Done
|
|
625
|
+
title="Project created"
|
|
626
|
+
action="Create another project"
|
|
627
|
+
onBack={() => {
|
|
628
|
+
form.reset();
|
|
629
|
+
setCreated(null);
|
|
630
|
+
}}
|
|
631
|
+
>
|
|
632
|
+
<span className="font-mono text-foreground">{created}</span> builds tonight for the first time.
|
|
633
|
+
</Done>
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
return (
|
|
638
|
+
<Form
|
|
639
|
+
ref={formRef}
|
|
640
|
+
className="@container w-full max-w-xl surface-card"
|
|
641
|
+
onSubmit={(event) => {
|
|
642
|
+
event.preventDefault();
|
|
643
|
+
form.handleSubmit();
|
|
644
|
+
}}
|
|
645
|
+
>
|
|
646
|
+
<form.Field name="name">
|
|
647
|
+
{(field) => (
|
|
648
|
+
<Field error={field.state.meta.errors}>
|
|
649
|
+
<FieldLabel>Project name</FieldLabel>
|
|
650
|
+
<Input
|
|
651
|
+
value={field.state.value}
|
|
652
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
653
|
+
onBlur={field.handleBlur}
|
|
654
|
+
spellCheck={false}
|
|
655
|
+
placeholder="field-notes"
|
|
656
|
+
/>
|
|
657
|
+
<FieldDescription>
|
|
658
|
+
Lowercase letters, digits and dashes. It is part of the address.
|
|
659
|
+
</FieldDescription>
|
|
660
|
+
<FieldError />
|
|
661
|
+
</Field>
|
|
662
|
+
)}
|
|
663
|
+
</form.Field>
|
|
664
|
+
|
|
665
|
+
<form.Field name="language">
|
|
666
|
+
{(field) => (
|
|
667
|
+
<Field error={field.state.meta.errors}>
|
|
668
|
+
<FieldLabel>Main language</FieldLabel>
|
|
669
|
+
<Combobox
|
|
670
|
+
items={languages}
|
|
671
|
+
value={field.state.value}
|
|
672
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
673
|
+
>
|
|
674
|
+
<ComboboxInput placeholder="Start typing, e.g. Rust" onBlur={field.handleBlur} />
|
|
675
|
+
<ComboboxContent>
|
|
676
|
+
<ComboboxEmpty>No language matches.</ComboboxEmpty>
|
|
677
|
+
<ComboboxList>
|
|
678
|
+
{(language: string) => (
|
|
679
|
+
<ComboboxItem key={language} value={language}>
|
|
680
|
+
{language}
|
|
681
|
+
</ComboboxItem>
|
|
682
|
+
)}
|
|
683
|
+
</ComboboxList>
|
|
684
|
+
</ComboboxContent>
|
|
685
|
+
</Combobox>
|
|
686
|
+
<FieldError />
|
|
687
|
+
</Field>
|
|
688
|
+
)}
|
|
689
|
+
</form.Field>
|
|
690
|
+
|
|
691
|
+
<form.Field name="topics">
|
|
692
|
+
{(field) => (
|
|
693
|
+
<Field error={field.state.meta.errors}>
|
|
694
|
+
<FieldLabel>Topics</FieldLabel>
|
|
695
|
+
<TagsInput
|
|
696
|
+
value={field.state.value}
|
|
697
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
698
|
+
onBlur={field.handleBlur}
|
|
699
|
+
max={5}
|
|
700
|
+
placeholder="Add a topic"
|
|
701
|
+
/>
|
|
702
|
+
<FieldDescription>Up to five. Press Enter or type a comma after each one.</FieldDescription>
|
|
703
|
+
<FieldError />
|
|
704
|
+
</Field>
|
|
705
|
+
)}
|
|
706
|
+
</form.Field>
|
|
707
|
+
|
|
708
|
+
<div className="grid gap-5 @md:grid-cols-2">
|
|
709
|
+
<form.Field name="buildAt">
|
|
710
|
+
{(field) => (
|
|
711
|
+
<Field error={field.state.meta.errors}>
|
|
712
|
+
<FieldLabel>Nightly build at</FieldLabel>
|
|
713
|
+
<TimeField
|
|
714
|
+
value={field.state.value}
|
|
715
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
716
|
+
onBlur={field.handleBlur}
|
|
717
|
+
hourCycle={24}
|
|
718
|
+
step={15}
|
|
719
|
+
/>
|
|
720
|
+
<FieldError />
|
|
721
|
+
</Field>
|
|
722
|
+
)}
|
|
723
|
+
</form.Field>
|
|
724
|
+
<form.Field name="retention">
|
|
725
|
+
{(field) => (
|
|
726
|
+
<Slider
|
|
727
|
+
label="Keep build logs, in days"
|
|
728
|
+
showValue
|
|
729
|
+
min={7}
|
|
730
|
+
max={90}
|
|
731
|
+
value={field.state.value}
|
|
732
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
733
|
+
/>
|
|
734
|
+
)}
|
|
735
|
+
</form.Field>
|
|
736
|
+
</div>
|
|
737
|
+
|
|
738
|
+
<form.Field name="reports">
|
|
739
|
+
{(field) => (
|
|
740
|
+
<Field error={field.state.meta.errors}>
|
|
741
|
+
<Fieldset
|
|
742
|
+
render={
|
|
743
|
+
<CheckboxGroup
|
|
744
|
+
value={field.state.value}
|
|
745
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
746
|
+
/>
|
|
747
|
+
}
|
|
748
|
+
>
|
|
749
|
+
<FieldsetLegend>Email me when</FieldsetLegend>
|
|
750
|
+
{reports.map((report) => (
|
|
751
|
+
<FieldItem key={report.value}>
|
|
752
|
+
<FieldLabel>
|
|
753
|
+
<Checkbox value={report.value} />
|
|
754
|
+
{report.label}
|
|
755
|
+
</FieldLabel>
|
|
756
|
+
</FieldItem>
|
|
757
|
+
))}
|
|
758
|
+
</Fieldset>
|
|
759
|
+
<FieldError />
|
|
760
|
+
</Field>
|
|
761
|
+
)}
|
|
762
|
+
</form.Field>
|
|
763
|
+
|
|
764
|
+
<FormActions>
|
|
765
|
+
<form.Subscribe selector={(state) => state.isSubmitting}>
|
|
766
|
+
{(submitting) => (
|
|
767
|
+
<SubmitButton pending={submitting} label="Creating the project">
|
|
768
|
+
Create project
|
|
769
|
+
</SubmitButton>
|
|
770
|
+
)}
|
|
771
|
+
</form.Subscribe>
|
|
772
|
+
</FormActions>
|
|
773
|
+
</Form>
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/* ── React 19 server action ────────────────────────────────────────────────── */
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
### Server actions
|
|
781
|
+
|
|
782
|
+
A React 19 action with `useActionState`. It returns errors by field name into `Form errors`: each shows in its `FieldError`, focus moves to the first, and it clears when the field changes. React resets a form after its action, so return what was sent too and feed it back as `defaultValue`. Append `FileDrop` files (held in state) to the `FormData` in the `action`; `pending` puts a spinner on the submit. Any reference but `TX-4821` shows the server's error.
|
|
783
|
+
|
|
784
|
+
```tsx
|
|
785
|
+
import { Button, Field, FieldDescription, FieldError, FieldLabel, FileDrop, FileDropItem, Form, FormActions, Input, OtpField, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Textarea } from "@zonsh/ui";
|
|
786
|
+
import { CheckIcon } from "lucide-react";
|
|
787
|
+
import * as React from "react";
|
|
788
|
+
|
|
789
|
+
// wait, SubmitButton, Done: as in the first example on this page that uses them.
|
|
790
|
+
|
|
791
|
+
const disputeReasons = [
|
|
792
|
+
{ value: "unknown", label: "I don't recognise this payment" },
|
|
793
|
+
{ value: "twice", label: "I was charged twice" },
|
|
794
|
+
{ value: "undelivered", label: "I paid, but nothing arrived" },
|
|
795
|
+
];
|
|
796
|
+
|
|
797
|
+
interface DisputeState {
|
|
798
|
+
/** Errors by field name, for `Form errors`. */
|
|
799
|
+
errors?: Record<string, string>;
|
|
800
|
+
/** The number of the dispute, once it is open. */
|
|
801
|
+
opened?: string;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** Stands in for a server function (`"use server"`): the bank looks the payment up. */
|
|
805
|
+
async function disputePayment(_previous: DisputeState, data: FormData): Promise<DisputeState> {
|
|
806
|
+
await wait(800);
|
|
807
|
+
const payment = String(data.get("payment")).trim().toUpperCase();
|
|
808
|
+
if (!["TX-4821", "TX-5530", "TX-6107"].includes(payment)) {
|
|
809
|
+
return { errors: { payment: "We can't find a card payment with that reference. Check your statement." } };
|
|
810
|
+
}
|
|
811
|
+
return { opened: `D-${payment.slice(3)}` };
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
function DisputeForm({ onAgain }: { onAgain: () => void }) {
|
|
815
|
+
const [state, action, pending] = React.useActionState(disputePayment, {});
|
|
816
|
+
const [files, setFiles] = React.useState<File[]>([]);
|
|
817
|
+
|
|
818
|
+
if (state.opened) {
|
|
819
|
+
return (
|
|
820
|
+
<Done title="Dispute opened" action="Dispute another payment" onBack={onAgain}>
|
|
821
|
+
Dispute <span className="font-mono text-foreground">{state.opened}</span> is open. We will write to
|
|
822
|
+
you within five working days.
|
|
823
|
+
</Done>
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return (
|
|
828
|
+
<Form
|
|
829
|
+
className="@container w-full max-w-xl surface-card"
|
|
830
|
+
errors={state.errors}
|
|
831
|
+
// Called from a submit, the action leaves the fields as they are: as a form's `action`, React
|
|
832
|
+
// would clear them once it ran, also when it sends back an error.
|
|
833
|
+
onSubmit={(event) => {
|
|
834
|
+
event.preventDefault();
|
|
835
|
+
const data = new FormData(event.currentTarget);
|
|
836
|
+
for (const file of files) data.append("evidence", file);
|
|
837
|
+
React.startTransition(() => action(data));
|
|
838
|
+
}}
|
|
839
|
+
>
|
|
840
|
+
<Field name="payment">
|
|
841
|
+
<FieldLabel>Payment reference</FieldLabel>
|
|
842
|
+
<Input required placeholder="TX-4821" spellCheck={false} className="font-mono" />
|
|
843
|
+
<FieldDescription>On your statement, next to the amount.</FieldDescription>
|
|
844
|
+
<FieldError match="valueMissing">Enter the reference of the payment.</FieldError>
|
|
845
|
+
<FieldError />
|
|
846
|
+
</Field>
|
|
847
|
+
|
|
848
|
+
<Field name="reason">
|
|
849
|
+
<FieldLabel>What went wrong?</FieldLabel>
|
|
850
|
+
<Select items={disputeReasons} required>
|
|
851
|
+
<SelectTrigger>
|
|
852
|
+
<SelectValue placeholder="Choose the closest" />
|
|
853
|
+
</SelectTrigger>
|
|
854
|
+
<SelectContent>
|
|
855
|
+
{disputeReasons.map((reason) => (
|
|
856
|
+
<SelectItem key={reason.value} value={reason.value}>
|
|
857
|
+
{reason.label}
|
|
858
|
+
</SelectItem>
|
|
859
|
+
))}
|
|
860
|
+
</SelectContent>
|
|
861
|
+
</Select>
|
|
862
|
+
<FieldError match="valueMissing">Choose what went wrong.</FieldError>
|
|
863
|
+
</Field>
|
|
864
|
+
|
|
865
|
+
<Field name="details">
|
|
866
|
+
<FieldLabel>Tell us more</FieldLabel>
|
|
867
|
+
<Textarea placeholder="When you noticed it, and anything the shop said." />
|
|
868
|
+
</Field>
|
|
869
|
+
|
|
870
|
+
<Field>
|
|
871
|
+
<FieldLabel>Receipts or screenshots</FieldLabel>
|
|
872
|
+
<FileDrop
|
|
873
|
+
accept="image/*,.pdf"
|
|
874
|
+
maxSize={10 * 1024 * 1024}
|
|
875
|
+
hint="PNG, JPG or PDF · up to 10 MB"
|
|
876
|
+
onFiles={(added) => setFiles((current) => [...current, ...added])}
|
|
877
|
+
/>
|
|
878
|
+
{files.map((file, index) => (
|
|
879
|
+
<FileDropItem
|
|
880
|
+
key={`${file.name}-${index}`}
|
|
881
|
+
file={file}
|
|
882
|
+
onRemove={() => setFiles((current) => current.filter((_, i) => i !== index))}
|
|
883
|
+
/>
|
|
884
|
+
))}
|
|
885
|
+
</Field>
|
|
886
|
+
|
|
887
|
+
<Field name="code">
|
|
888
|
+
<FieldLabel>Code from your phone</FieldLabel>
|
|
889
|
+
<OtpField length={6} required groupSize={3} />
|
|
890
|
+
<FieldDescription>We sent it by text to the number ending in 42.</FieldDescription>
|
|
891
|
+
<FieldError match="valueMissing">Enter the code we sent you.</FieldError>
|
|
892
|
+
<FieldError match="patternMismatch">Enter all six digits.</FieldError>
|
|
893
|
+
</Field>
|
|
894
|
+
|
|
895
|
+
<FormActions>
|
|
896
|
+
<SubmitButton pending={pending} label="Opening the dispute">
|
|
897
|
+
Open dispute
|
|
898
|
+
</SubmitButton>
|
|
899
|
+
</FormActions>
|
|
900
|
+
</Form>
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
export function WithServerAction() {
|
|
905
|
+
// A new key starts a new dispute: a fresh form and action state.
|
|
906
|
+
const [round, setRound] = React.useState(0);
|
|
907
|
+
return <DisputeForm key={round} onAgain={() => setRound((n) => n + 1)} />;
|
|
908
|
+
}
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
### Binding each control
|
|
912
|
+
|
|
913
|
+
From React Hook Form's `field` (`field.value`, `field.onChange`) or TanStack Form's (`field.state.value`, `field.handleChange`); the ref is what React Hook Form focuses on error.
|
|
914
|
+
|
|
915
|
+
| Control | Value | Change | Ref and blur |
|
|
916
|
+
| -------------------- | ------------------------------------------- | --------------------------- | --------------------------------------- |
|
|
917
|
+
| `Input`, `Textarea` | `string`; `register` works | `onChange`, `onValueChange` | `ref`, `onBlur` |
|
|
918
|
+
| `Select` | the item's value, `null` while empty | `onValueChange` | `inputRef`; `onBlur` on `SelectTrigger` |
|
|
919
|
+
| `Combobox` | the item, `null` while empty | `onValueChange` | `inputRef`; `onBlur` on `ComboboxInput` |
|
|
920
|
+
| `Checkbox`, `Switch` | `checked: boolean` | `onCheckedChange` | `ref`, `onBlur` |
|
|
921
|
+
| `CheckboxGroup` | `string[]` | `onValueChange` | the first `Checkbox`'s `ref` |
|
|
922
|
+
| `RadioGroup` | the radio's value, `null` while empty | `onValueChange` | `inputRef`, `onBlur` |
|
|
923
|
+
| `NumberField` | `number`, `null` while empty | `onValueChange` | `inputRef`, `onBlur` |
|
|
924
|
+
| `Slider` | `number` (`number[]` for a range) | `onValueChange` | — |
|
|
925
|
+
| `DatePicker` | `Date`, `null` while empty | `onValueChange` | `ref`, `onBlur` |
|
|
926
|
+
| `TimeField` | `"HH:mm"`, `null` while empty or unfinished | `onValueChange` | `inputRef`, `onBlur` |
|
|
927
|
+
| `TagsInput` | `string[]` | `onValueChange` | `ref`, `onBlur` |
|
|
928
|
+
| `OtpField` | `string` | `onValueChange` | `inputRef` |
|
|
929
|
+
| `FileDrop` | keeps no value: hold the files in state | `onFiles` | `ref`, `onBlur` |
|
|
930
|
+
|
|
931
|
+
Pass `null`, not `undefined`, for an empty value (`value={field.value ?? null}`): `undefined` leaves the control uncontrolled. A library's `reset()` and a native reset both put every control back.
|
|
932
|
+
|
|
933
|
+
## Props
|
|
934
|
+
|
|
935
|
+
| Prop | Type | Default |
|
|
936
|
+
| ---------------- | ------------------------------------------------ | ------------ |
|
|
937
|
+
| `onFormSubmit` | `(values: Record<string, any>, details) => void` | — |
|
|
938
|
+
| `errors` | `Record<string, string \| string[]>` | — |
|
|
939
|
+
| `validationMode` | `"onSubmit" \| "onBlur" \| "onChange"` | `"onSubmit"` |
|
|
940
|
+
| `actionsRef` | `RefObject<{ validate(name?: string): void }>` | — |
|
|
941
|
+
|
|
942
|
+
Every other `<form>` prop is forwarded, including `action` for Server Functions. `onFormSubmit` prevents the native submit. `onSubmit` runs once the form's own checks pass, or at once while a `Field` shows a library `error`.
|
|
943
|
+
|
|
944
|
+
`FormActions` renders a `<div>` and takes its props:
|
|
945
|
+
|
|
946
|
+
| Prop | Type | Default |
|
|
947
|
+
| ------- | ------------------------------- | ------- |
|
|
948
|
+
| `align` | `"end" \| "between" \| "start"` | `"end"` |
|
|
949
|
+
|
|
950
|
+
`end`: right, primary last. `between`: a note or quiet link on the left. `start`: single-column step flows only. Data attributes: `data-align`.
|
|
951
|
+
|
|
952
|
+
## Brand rules
|
|
953
|
+
|
|
954
|
+
- **Do** use one primary submit per form, named for what happens: "Send message".
|
|
955
|
+
- **Do** end the form with `FormActions`: the primary on the right, Cancel or Back to its left as `secondary` or `ghost`.
|
|
956
|
+
- **Do** write errors that say how to fix the problem, in plain words.
|
|
957
|
+
- **Do** keep a form on the page, under hairlines, when it is part of a page; a card only for a form that is its screen on its own, with the `--field-edge` border of its inputs (`surface-card` does).
|
|
958
|
+
- **Don't** disable the submit button to signal errors; let people submit and show them what is missing.
|
|
959
|
+
|
|
960
|
+
## Accessibility
|
|
961
|
+
|
|
962
|
+
- Errors use colour **and** text, linked through `aria-describedby`; invalid controls have `aria-invalid`.
|
|
963
|
+
- On an invalid submit, focus moves to the first invalid field: by the form (native and server errors), React Hook Form (refs) or `onSubmitInvalid` (TanStack Form).
|
|
964
|
+
- Every control keeps a visible `FieldLabel`; placeholders are examples, not labels.
|
|
965
|
+
|
|
966
|
+
---
|
|
967
|
+
|
|
968
|
+
- Import: `import { Form, FormActions } from "@zonsh/ui"`
|
|
969
|
+
- Source: `packages/ui/src/components/form.tsx`
|
|
970
|
+
- Primitive: `@base-ui/react/form` (Base UI docs: `node_modules/@base-ui/react/docs/react/components/form.md`)
|