@zonsh/ui 0.5.0 → 0.6.1
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 +643 -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,1715 @@
|
|
|
1
|
+
# Shop
|
|
2
|
+
|
|
3
|
+
```tsx
|
|
4
|
+
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, AspectRatio, Breadcrumb, Button, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, Empty, EmptyActions, EmptyDescription, EmptyMedia, EmptyTitle, Eyebrow, Field, FieldError, FieldItem, FieldLabel, Fieldset, FieldsetLegend, Form, Heading, Index, Input, Label, Lightbox, LightboxTrigger, Mono, NumberField, NumberRoll, Progress, Radio, RadioGroup, Tag, Text, ToggleGroup, ToggleGroupItem, TwoTone, fromMinorUnits, useLocale } from "@zonsh/ui";
|
|
5
|
+
import { Wordmark } from "@zonsh/ui/brand";
|
|
6
|
+
import { CircleCheckIcon, MaximizeIcon, RotateCcwIcon, ShoppingBagIcon, StoreIcon, TruckIcon } from "lucide-react";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
|
|
9
|
+
const CURRENCY = "EUR";
|
|
10
|
+
|
|
11
|
+
/** Delivery costs this much below FREE_FROM; pickup at the studio is free. Both in cents. */
|
|
12
|
+
const DELIVERY_FEE = 690;
|
|
13
|
+
|
|
14
|
+
const FREE_FROM = 8000;
|
|
15
|
+
|
|
16
|
+
type Shape = "bowl" | "cup" | "vase" | "plate" | "jug" | "mug";
|
|
17
|
+
|
|
18
|
+
type Category = "dining" | "drinking" | "vessels";
|
|
19
|
+
|
|
20
|
+
const categories: { value: Category | "all"; label: string }[] = [
|
|
21
|
+
{ value: "all", label: "All" },
|
|
22
|
+
{ value: "dining", label: "Dining" },
|
|
23
|
+
{ value: "drinking", label: "Drinking" },
|
|
24
|
+
{ value: "vessels", label: "Vessels" },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The glazes, each with the tone the studio pictures are drawn in. The swatch beside a glaze's
|
|
29
|
+
* name is the one place colour appears: it tells the glazes apart, always with the name.
|
|
30
|
+
*/
|
|
31
|
+
const glazes: Record<string, string> = {
|
|
32
|
+
Ash: "#b9b5ae",
|
|
33
|
+
Oat: "#e0d7c6",
|
|
34
|
+
Slate: "#596066",
|
|
35
|
+
Celadon: "#b3c2b5",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface Product {
|
|
39
|
+
id: string;
|
|
40
|
+
/** The studio's own code for the piece, set in mono. */
|
|
41
|
+
sku: string;
|
|
42
|
+
name: string;
|
|
43
|
+
/** The one line under the name: clay and finish. */
|
|
44
|
+
line: string;
|
|
45
|
+
category: Category;
|
|
46
|
+
/** Price in cents, for the smallest size. */
|
|
47
|
+
price: number;
|
|
48
|
+
shape: Shape;
|
|
49
|
+
clay: "Stoneware" | "Porcelain";
|
|
50
|
+
glazes: string[];
|
|
51
|
+
/** Sizes and what each adds to the price, in cents. */
|
|
52
|
+
sizes?: { value: string; label: string; extra: number }[];
|
|
53
|
+
/** Size or capacity when there is one size. */
|
|
54
|
+
measure?: string;
|
|
55
|
+
tag?: { label: string; variant?: "muted"; tone?: "warning" };
|
|
56
|
+
about: string;
|
|
57
|
+
care: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const products: Product[] = [
|
|
61
|
+
{
|
|
62
|
+
id: "bowl",
|
|
63
|
+
sku: "SL-101",
|
|
64
|
+
name: "Breakfast bowl",
|
|
65
|
+
line: "Stoneware, dipped glaze",
|
|
66
|
+
category: "dining",
|
|
67
|
+
price: 3200,
|
|
68
|
+
shape: "bowl",
|
|
69
|
+
clay: "Stoneware",
|
|
70
|
+
glazes: ["Ash", "Oat", "Slate"],
|
|
71
|
+
sizes: [
|
|
72
|
+
{ value: "14", label: "14 cm", extra: 0 },
|
|
73
|
+
{ value: "17", label: "17 cm", extra: 600 },
|
|
74
|
+
],
|
|
75
|
+
about:
|
|
76
|
+
"Thrown on the wheel and trimmed with a low foot, deep enough for porridge or soup. The glaze stops short of the foot, where the bare clay shows.",
|
|
77
|
+
care: "Dishwasher and microwave safe. Hand-washing keeps the glaze bright longer.",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "cup",
|
|
81
|
+
sku: "SL-204",
|
|
82
|
+
name: "Tea cup",
|
|
83
|
+
line: "Porcelain, no handle",
|
|
84
|
+
category: "drinking",
|
|
85
|
+
price: 2400,
|
|
86
|
+
shape: "cup",
|
|
87
|
+
clay: "Porcelain",
|
|
88
|
+
glazes: ["Ash", "Celadon"],
|
|
89
|
+
measure: "About 200 ml",
|
|
90
|
+
tag: { label: "Few left", tone: "warning" },
|
|
91
|
+
about: "Holds about 200 ml and sits warm in the hand. The foot is left unglazed.",
|
|
92
|
+
care: "Dishwasher safe. Not for the microwave: the rim is thin.",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "vase",
|
|
96
|
+
sku: "SL-307",
|
|
97
|
+
name: "Bud vase",
|
|
98
|
+
line: "Stoneware, matte",
|
|
99
|
+
category: "vessels",
|
|
100
|
+
price: 2800,
|
|
101
|
+
shape: "vase",
|
|
102
|
+
clay: "Stoneware",
|
|
103
|
+
glazes: ["Oat", "Slate"],
|
|
104
|
+
measure: "18 cm tall",
|
|
105
|
+
about: "A narrow neck for one or two stems. Glazed inside, so it holds water.",
|
|
106
|
+
care: "Rinse by hand. A bottle brush reaches the shoulder.",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "plate",
|
|
110
|
+
sku: "SL-112",
|
|
111
|
+
name: "Dinner plate",
|
|
112
|
+
line: "Stoneware, satin glaze",
|
|
113
|
+
category: "dining",
|
|
114
|
+
price: 3600,
|
|
115
|
+
shape: "plate",
|
|
116
|
+
clay: "Stoneware",
|
|
117
|
+
glazes: ["Ash", "Oat", "Slate"],
|
|
118
|
+
sizes: [
|
|
119
|
+
{ value: "22", label: "22 cm", extra: 0 },
|
|
120
|
+
{ value: "27", label: "27 cm", extra: 800 },
|
|
121
|
+
],
|
|
122
|
+
about: "A wide, shallow rim that stacks well. Satin, so knives leave few marks.",
|
|
123
|
+
care: "Dishwasher and microwave safe.",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "jug",
|
|
127
|
+
sku: "SL-315",
|
|
128
|
+
name: "Serving jug",
|
|
129
|
+
line: "Stoneware, pulled spout",
|
|
130
|
+
category: "vessels",
|
|
131
|
+
price: 5400,
|
|
132
|
+
shape: "jug",
|
|
133
|
+
clay: "Stoneware",
|
|
134
|
+
glazes: ["Ash", "Slate"],
|
|
135
|
+
measure: "About 1 litre",
|
|
136
|
+
tag: { label: "Made to order", variant: "muted" },
|
|
137
|
+
about: "About a litre, with a spout that pours without dripping. Made to order in three weeks.",
|
|
138
|
+
care: "Dishwasher safe. Pour hot drinks with the handle, not the body.",
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: "mug",
|
|
142
|
+
sku: "SL-210",
|
|
143
|
+
name: "Everyday mug",
|
|
144
|
+
line: "Stoneware, pulled handle",
|
|
145
|
+
category: "drinking",
|
|
146
|
+
price: 2900,
|
|
147
|
+
shape: "mug",
|
|
148
|
+
clay: "Stoneware",
|
|
149
|
+
glazes: ["Oat", "Slate", "Celadon"],
|
|
150
|
+
measure: "About 300 ml",
|
|
151
|
+
about: "A straight mug for 300 ml with a handle wide enough for three fingers.",
|
|
152
|
+
care: "Dishwasher and microwave safe.",
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
const productById = (id: string) => products.find((p) => p.id === id) ?? products[0]!;
|
|
157
|
+
|
|
158
|
+
interface Line {
|
|
159
|
+
/** Product, glaze and size: the same piece in another glaze is another line. */
|
|
160
|
+
key: string;
|
|
161
|
+
productId: string;
|
|
162
|
+
glaze: string;
|
|
163
|
+
size?: string;
|
|
164
|
+
quantity: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const lineKey = (productId: string, glaze: string, size?: string) => [productId, glaze, size ?? ""].join(":");
|
|
168
|
+
|
|
169
|
+
function unitPrice(line: Pick<Line, "productId" | "size">) {
|
|
170
|
+
const product = productById(line.productId);
|
|
171
|
+
const size = product.sizes?.find((s) => s.value === line.size);
|
|
172
|
+
return product.price + (size?.extra ?? 0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function variantLabel(line: Pick<Line, "productId" | "glaze" | "size">) {
|
|
176
|
+
const size = productById(line.productId).sizes?.find((s) => s.value === line.size);
|
|
177
|
+
return [line.glaze, size?.label].filter(Boolean).join(" · ");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const subtotalOf = (lines: Line[]) => lines.reduce((sum, l) => sum + unitPrice(l) * l.quantity, 0);
|
|
181
|
+
|
|
182
|
+
const countOf = (lines: Line[]) => lines.reduce((sum, l) => sum + l.quantity, 0);
|
|
183
|
+
|
|
184
|
+
const deliveryFee = (subtotal: number) => (subtotal >= FREE_FROM ? 0 : DELIVERY_FEE);
|
|
185
|
+
|
|
186
|
+
const pieces = (n: number) => `${n} ${n === 1 ? "piece" : "pieces"}`;
|
|
187
|
+
|
|
188
|
+
/** Prices are kept in cents and formatted once, at the edge, for the reader's locale. */
|
|
189
|
+
function usePrice() {
|
|
190
|
+
const locale = useLocale() ?? "en-IE";
|
|
191
|
+
return React.useMemo(() => {
|
|
192
|
+
const format = new Intl.NumberFormat(locale, { style: "currency", currency: CURRENCY });
|
|
193
|
+
return (cents: number) => format.format(Number(fromMinorUnits(cents, CURRENCY)));
|
|
194
|
+
}, [locale]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** An amount that changes as the visitor shops: its changed digits roll to the new value. */
|
|
198
|
+
function Amount({ cents }: { cents: number }) {
|
|
199
|
+
const locale = useLocale() ?? "en-IE";
|
|
200
|
+
return (
|
|
201
|
+
<NumberRoll
|
|
202
|
+
value={Number(fromMinorUnits(cents, CURRENCY))}
|
|
203
|
+
locale={locale}
|
|
204
|
+
format={{ style: "currency", currency: CURRENCY }}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** "3 pieces", the count rolling. */
|
|
210
|
+
function Pieces({ n }: { n: number }) {
|
|
211
|
+
return (
|
|
212
|
+
<>
|
|
213
|
+
<NumberRoll value={n} /> {n === 1 ? "piece" : "pieces"}
|
|
214
|
+
</>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The cart a visitor starts with in this demo, so the cart and checkout have something in them. */
|
|
219
|
+
const sampleCart: Line[] = [
|
|
220
|
+
{ key: lineKey("bowl", "Ash", "17"), productId: "bowl", glaze: "Ash", size: "17", quantity: 1 },
|
|
221
|
+
{ key: lineKey("cup", "Celadon"), productId: "cup", glaze: "Celadon", quantity: 1 },
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
// ── Studio pictures ──────────────────────────────────────────────────────────
|
|
225
|
+
|
|
226
|
+
/*
|
|
227
|
+
* Stand-ins for product photography, drawn as SVG and used as ordinary image URLs: the piece in
|
|
228
|
+
* its glaze on a seamless paper backdrop, lit from the left, with a soft contact shadow and a
|
|
229
|
+
* little grain. Like photos, they look the same in the light and the dark theme. A real shop
|
|
230
|
+
* replaces `photo()` with its photo URLs: same ratio (4:5), same light, same angle per view.
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
type View = "front" | "above" | "detail";
|
|
234
|
+
|
|
235
|
+
const views: { view: View; label: string }[] = [
|
|
236
|
+
{ view: "front", label: "from the front" },
|
|
237
|
+
{ view: "above", label: "from above" },
|
|
238
|
+
{ view: "detail", label: "close up on the glaze" },
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
function mix(a: string, b: string, t: number) {
|
|
242
|
+
const n = (hex: string, i: number) => parseInt(hex.slice(1 + i * 2, 3 + i * 2), 16);
|
|
243
|
+
const c = [0, 1, 2].map((i) => Math.round(n(a, i) + (n(b, i) - n(a, i)) * t));
|
|
244
|
+
return `#${c.map((v) => v.toString(16).padStart(2, "0")).join("")}`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const ellipse = (cx: number, cy: number, rx: number, ry: number) =>
|
|
248
|
+
`M${cx - rx} ${cy}A${rx} ${ry} 0 1 0 ${cx + rx} ${cy}A${rx} ${ry} 0 1 0 ${cx - rx} ${cy}Z`;
|
|
249
|
+
|
|
250
|
+
interface Form {
|
|
251
|
+
/** The body's silhouette below the rim. */
|
|
252
|
+
body: string;
|
|
253
|
+
/** The opening: cx, cy, rx, ry. */
|
|
254
|
+
rim: [number, number, number, number];
|
|
255
|
+
/** Where a dipped glaze stops, as a y; without it the body is glazed to the foot. */
|
|
256
|
+
dip?: number;
|
|
257
|
+
foot?: string;
|
|
258
|
+
handle?: string;
|
|
259
|
+
spout?: string;
|
|
260
|
+
/** Half the width of the contact shadow, and its y. */
|
|
261
|
+
shadow: [number, number];
|
|
262
|
+
/** From above: the outer radius and the opening's. */
|
|
263
|
+
above: [number, number];
|
|
264
|
+
/** The point the close-up centres on. */
|
|
265
|
+
focus: [number, number];
|
|
266
|
+
/** How much larger than drawn the piece sits in the frame. */
|
|
267
|
+
scale: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const forms: Record<Shape, Form> = {
|
|
271
|
+
bowl: {
|
|
272
|
+
body: "M78 262A122 26 0 0 0 322 262C314 334 262 366 200 366C138 366 86 334 78 262Z",
|
|
273
|
+
rim: [200, 262, 122, 26],
|
|
274
|
+
dip: 330,
|
|
275
|
+
foot: "M164 360L168 378H232L236 360Z",
|
|
276
|
+
shadow: [92, 380],
|
|
277
|
+
above: [150, 128],
|
|
278
|
+
focus: [118, 318],
|
|
279
|
+
scale: 1.22,
|
|
280
|
+
},
|
|
281
|
+
cup: {
|
|
282
|
+
body: "M136 222A64 14 0 0 0 264 222C264 294 254 352 230 368H170C146 352 136 294 136 222Z",
|
|
283
|
+
rim: [200, 222, 64, 14],
|
|
284
|
+
foot: "M172 366L174 378H226L228 366Z",
|
|
285
|
+
shadow: [64, 380],
|
|
286
|
+
above: [92, 82],
|
|
287
|
+
focus: [146, 268],
|
|
288
|
+
scale: 1.38,
|
|
289
|
+
},
|
|
290
|
+
vase: {
|
|
291
|
+
body: "M184 150A16 5 0 0 0 216 150C216 196 222 224 242 256C272 300 268 344 246 372H154C132 344 128 300 158 256C178 224 184 196 184 150Z",
|
|
292
|
+
rim: [200, 150, 16, 5],
|
|
293
|
+
shadow: [72, 378],
|
|
294
|
+
above: [104, 22],
|
|
295
|
+
focus: [170, 250],
|
|
296
|
+
scale: 1.25,
|
|
297
|
+
},
|
|
298
|
+
plate: {
|
|
299
|
+
body: ellipse(200, 344, 164, 40),
|
|
300
|
+
rim: [200, 334, 164, 38],
|
|
301
|
+
shadow: [150, 362],
|
|
302
|
+
above: [176, 116],
|
|
303
|
+
focus: [96, 330],
|
|
304
|
+
scale: 1.1,
|
|
305
|
+
},
|
|
306
|
+
jug: {
|
|
307
|
+
body: "M148 196A52 12 0 0 0 252 196C258 250 280 302 270 344C264 364 242 372 200 372C158 372 136 364 130 344C120 302 142 250 148 196Z",
|
|
308
|
+
rim: [200, 196, 52, 12],
|
|
309
|
+
spout: "M166 192C154 190 142 186 131 179C134 190 144 200 160 205Z",
|
|
310
|
+
handle: "M254 226C312 226 318 310 264 326",
|
|
311
|
+
shadow: [92, 380],
|
|
312
|
+
above: [112, 96],
|
|
313
|
+
focus: [148, 228],
|
|
314
|
+
scale: 1.25,
|
|
315
|
+
},
|
|
316
|
+
mug: {
|
|
317
|
+
body: "M140 214A60 13 0 0 0 260 214V354C260 364 236 370 200 370C164 370 140 364 140 354Z",
|
|
318
|
+
rim: [200, 214, 60, 13],
|
|
319
|
+
handle: "M260 246C310 246 310 322 260 322",
|
|
320
|
+
shadow: [80, 380],
|
|
321
|
+
above: [96, 86],
|
|
322
|
+
focus: [160, 260],
|
|
323
|
+
scale: 1.32,
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const frameGround = "bg-[#e8e6e2]";
|
|
328
|
+
|
|
329
|
+
/** Photos keep their own light; in the dark theme they step down a little, so they don't glare. */
|
|
330
|
+
const photoTone = "dark:brightness-[.86]";
|
|
331
|
+
|
|
332
|
+
function scene(product: Product, glaze: string, view: View) {
|
|
333
|
+
const tone = glazes[glaze] ?? "#b9b5ae";
|
|
334
|
+
const clay = product.clay === "Porcelain" ? "#ecebe6" : "#cbbba6";
|
|
335
|
+
const f = forms[product.shape];
|
|
336
|
+
const light = mix(tone, "#ffffff", 0.45);
|
|
337
|
+
const dark = mix(tone, "#000000", 0.38);
|
|
338
|
+
const inside = mix(tone, "#000000", 0.28);
|
|
339
|
+
const defs = `
|
|
340
|
+
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
|
341
|
+
<stop offset="0" stop-color="${paper.top}"/><stop offset=".6" stop-color="${paper.horizon}"/>
|
|
342
|
+
<stop offset="1" stop-color="${paper.floor}"/>
|
|
343
|
+
</linearGradient>
|
|
344
|
+
<radialGradient id="glow" cx=".42" cy=".4" r=".62">
|
|
345
|
+
<stop offset="0" stop-color="#fff" stop-opacity=".6"/><stop offset="1" stop-color="#fff" stop-opacity="0"/>
|
|
346
|
+
</radialGradient>
|
|
347
|
+
<linearGradient id="glaze" x1="0" y1="0" x2="1" y2="0">
|
|
348
|
+
<stop offset="0" stop-color="${light}"/><stop offset=".38" stop-color="${tone}"/>
|
|
349
|
+
<stop offset="1" stop-color="${dark}"/>
|
|
350
|
+
</linearGradient>
|
|
351
|
+
<linearGradient id="clay" x1="0" y1="0" x2="1" y2="0">
|
|
352
|
+
<stop offset="0" stop-color="${mix(clay, "#ffffff", 0.35)}"/><stop offset=".4" stop-color="${clay}"/>
|
|
353
|
+
<stop offset="1" stop-color="${mix(clay, "#000000", 0.32)}"/>
|
|
354
|
+
</linearGradient>
|
|
355
|
+
<linearGradient id="inside" x1="0" y1="0" x2="1" y2="1">
|
|
356
|
+
<stop offset="0" stop-color="${inside}"/><stop offset="1" stop-color="${mix(tone, "#ffffff", 0.2)}"/>
|
|
357
|
+
</linearGradient>
|
|
358
|
+
<radialGradient id="top" cx=".38" cy=".35" r=".75">
|
|
359
|
+
<stop offset="0" stop-color="${light}"/><stop offset=".6" stop-color="${tone}"/>
|
|
360
|
+
<stop offset="1" stop-color="${dark}"/>
|
|
361
|
+
</radialGradient>
|
|
362
|
+
<filter id="soft" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="9"/></filter>
|
|
363
|
+
<filter id="grain"><feTurbulence type="fractalNoise" baseFrequency=".85" numOctaves="2" stitchTiles="stitch"/>
|
|
364
|
+
<feColorMatrix type="saturate" values="0"/></filter>
|
|
365
|
+
<clipPath id="form"><path d="${f.body}"/></clipPath>`;
|
|
366
|
+
|
|
367
|
+
let piece: string;
|
|
368
|
+
if (view === "above") {
|
|
369
|
+
const [outer, opening] = f.above;
|
|
370
|
+
const handle = f.handle
|
|
371
|
+
? `<rect x="${200 + outer - 6}" y="237" width="${Math.round(outer * 0.42)}" height="22" rx="11" fill="${tone}"/>`
|
|
372
|
+
: "";
|
|
373
|
+
const well =
|
|
374
|
+
product.shape === "plate"
|
|
375
|
+
? `<circle cx="200" cy="248" r="${opening * 0.5}" fill="none" stroke="${dark}" stroke-opacity=".15" stroke-width="1.5"/>`
|
|
376
|
+
: "";
|
|
377
|
+
piece = `
|
|
378
|
+
<circle cx="214" cy="262" r="${outer + 6}" fill="#000" opacity=".16" filter="url(#soft)"/>
|
|
379
|
+
${handle}
|
|
380
|
+
<circle cx="200" cy="248" r="${outer}" fill="url(#top)"/>
|
|
381
|
+
<circle cx="200" cy="248" r="${opening}" fill="url(#inside)"/>
|
|
382
|
+
<circle cx="200" cy="248" r="${opening}" fill="none" stroke="${light}" stroke-opacity=".7" stroke-width="2"/>
|
|
383
|
+
${well}`;
|
|
384
|
+
} else {
|
|
385
|
+
const [cx, cy, rx, ry] = f.rim;
|
|
386
|
+
const d = f.dip;
|
|
387
|
+
const glazed =
|
|
388
|
+
d === undefined
|
|
389
|
+
? `<path d="${f.body}" fill="url(#glaze)"/>`
|
|
390
|
+
: `<path d="${f.body}" fill="url(#clay)"/>
|
|
391
|
+
<g clip-path="url(#form)"><path d="M0 0H400V${d}C360 ${d + 4} 330 ${d - 6} 300 ${d + 2}S240 ${d + 12} 210 ${d + 4}S150 ${d - 4} 120 ${d + 6}S60 ${d} 0 ${d + 2}Z" fill="url(#glaze)"/></g>`;
|
|
392
|
+
const opening =
|
|
393
|
+
product.shape === "plate"
|
|
394
|
+
? `<path d="${ellipse(cx, cy, rx, ry)}" fill="url(#top)"/>
|
|
395
|
+
<path d="${ellipse(cx, cy + 4, rx * 0.62, ry * 0.58)}" fill="${mix(tone, "#000000", 0.08)}" opacity=".6"/>`
|
|
396
|
+
: `<path d="${ellipse(cx, cy, rx, ry)}" fill="${light}"/>
|
|
397
|
+
<path d="${ellipse(cx, cy + 1, rx - Math.max(3, rx * 0.06), ry - Math.max(1.5, ry * 0.12))}" fill="url(#inside)"/>`;
|
|
398
|
+
const handle = f.handle
|
|
399
|
+
? `<path d="${f.handle}" fill="none" stroke="${dark}" stroke-width="15" stroke-linecap="round"/>
|
|
400
|
+
<path d="${f.handle}" fill="none" stroke="${tone}" stroke-width="10" stroke-linecap="round"/>`
|
|
401
|
+
: "";
|
|
402
|
+
const shine =
|
|
403
|
+
product.shape === "plate"
|
|
404
|
+
? ""
|
|
405
|
+
: `<path d="M${cx - rx * 0.72} ${cy + ry + 14}C${cx - rx * 0.8} ${cy + ry + 60} ${cx - rx * 0.7} ${cy + ry + 90} ${cx - rx * 0.56} ${cy + ry + 110}" fill="none" stroke="#fff" stroke-opacity=".35" stroke-width="6" stroke-linecap="round" clip-path="url(#form)"/>`;
|
|
406
|
+
piece = `
|
|
407
|
+
<ellipse cx="208" cy="${f.shadow[1]}" rx="${f.shadow[0]}" ry="12" fill="#000" opacity=".22" filter="url(#soft)"/>
|
|
408
|
+
${f.foot ? `<path d="${f.foot}" fill="url(#clay)"/>` : ""}
|
|
409
|
+
${handle}
|
|
410
|
+
${glazed}
|
|
411
|
+
${shine}
|
|
412
|
+
${f.spout ? `<path d="${f.spout}" fill="${tone}"/>` : ""}
|
|
413
|
+
${opening}`;
|
|
414
|
+
}
|
|
415
|
+
const [fx, fy] = f.focus;
|
|
416
|
+
const framed =
|
|
417
|
+
view === "detail"
|
|
418
|
+
? `<g transform="translate(200 250) scale(2.6) translate(${-fx} ${-fy})">${piece}</g>`
|
|
419
|
+
: view === "above"
|
|
420
|
+
? `<g transform="translate(200 250) scale(${Math.min(f.scale, 170 / f.above[0])}) translate(-200 -250)">${piece}</g>`
|
|
421
|
+
: `<g transform="translate(200 290) scale(${f.scale}) translate(-200 -290)">${piece}</g>`;
|
|
422
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 500" width="800" height="1000"><defs>${defs}</defs>
|
|
423
|
+
<rect width="400" height="500" fill="url(#bg)"/><rect width="400" height="500" fill="url(#glow)"/>
|
|
424
|
+
${framed}
|
|
425
|
+
<rect width="400" height="500" filter="url(#grain)" opacity=".07"/></svg>`;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const photoCache = new Map<string, string>();
|
|
429
|
+
|
|
430
|
+
/** A studio picture's URL. With real photos: `product.photos[glaze][view]`. */
|
|
431
|
+
function photo(product: Product, glaze: string, view: View = "front") {
|
|
432
|
+
const key = `${product.id}:${glaze}:${view}`;
|
|
433
|
+
let url = photoCache.get(key);
|
|
434
|
+
if (!url) {
|
|
435
|
+
url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(scene(product, glaze, view).replace(/\s+/g, " "))}`;
|
|
436
|
+
photoCache.set(key, url);
|
|
437
|
+
}
|
|
438
|
+
return url;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const viewLabel = (view: View) => views.find((v) => v.view === view)!.label;
|
|
442
|
+
|
|
443
|
+
/** A small round sample of a glaze: colour that names a choice, always beside its name. */
|
|
444
|
+
function Swatch({ glaze, className = "size-3" }: { glaze: string; className?: string }) {
|
|
445
|
+
return (
|
|
446
|
+
<span
|
|
447
|
+
aria-hidden
|
|
448
|
+
className={`inline-block shrink-0 rounded-full border border-black/15 dark:border-white/25 ${className}`}
|
|
449
|
+
style={{ background: glazes[glaze] }}
|
|
450
|
+
/>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ── Shop state ────────────────────────────────────────────────────────────────
|
|
455
|
+
|
|
456
|
+
type Page = { name: "products" } | { name: "product"; id: string; opened?: boolean } | { name: "checkout" };
|
|
457
|
+
|
|
458
|
+
function useCart(initial: Line[]) {
|
|
459
|
+
const [lines, setLines] = React.useState<Line[]>(initial);
|
|
460
|
+
const add = React.useCallback((line: Omit<Line, "key">) => {
|
|
461
|
+
const key = lineKey(line.productId, line.glaze, line.size);
|
|
462
|
+
setLines((all) =>
|
|
463
|
+
all.some((l) => l.key === key)
|
|
464
|
+
? all.map((l) => (l.key === key ? { ...l, quantity: Math.min(10, l.quantity + line.quantity) } : l))
|
|
465
|
+
: [...all, { ...line, key }],
|
|
466
|
+
);
|
|
467
|
+
}, []);
|
|
468
|
+
const setQuantity = React.useCallback(
|
|
469
|
+
(key: string, quantity: number) =>
|
|
470
|
+
setLines((all) => all.map((l) => (l.key === key ? { ...l, quantity } : l))),
|
|
471
|
+
[],
|
|
472
|
+
);
|
|
473
|
+
const remove = React.useCallback((key: string) => setLines((all) => all.filter((l) => l.key !== key)), []);
|
|
474
|
+
const clear = React.useCallback(() => setLines([]), []);
|
|
475
|
+
return { lines, add, setQuantity, remove, clear };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
type Cart = ReturnType<typeof useCart>;
|
|
479
|
+
|
|
480
|
+
/** A breadcrumb step that is a button: the demo has no routes. With routes, give it an `href`. */
|
|
481
|
+
const crumb = (onClick: () => void) => (
|
|
482
|
+
<button type="button" onClick={onClick} className="cursor-pointer border-0 bg-transparent p-0" />
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
// ── The shop's bar ───────────────────────────────────────────────────────────
|
|
486
|
+
|
|
487
|
+
/** The terms line, the shop's name and the cart button, whose name says what is in it. */
|
|
488
|
+
function ShopBar({
|
|
489
|
+
count,
|
|
490
|
+
onHome,
|
|
491
|
+
onOpenCart,
|
|
492
|
+
}: {
|
|
493
|
+
count: number;
|
|
494
|
+
onHome: () => void;
|
|
495
|
+
onOpenCart: () => void;
|
|
496
|
+
}) {
|
|
497
|
+
const price = usePrice();
|
|
498
|
+
return (
|
|
499
|
+
<header className="flex flex-col">
|
|
500
|
+
<p className="m-0 flex flex-wrap items-center justify-center gap-x-3 gap-y-1 border-b border-border/60 pb-3 text-center font-mono text-[11px] tracking-[0.08em] text-muted-foreground uppercase">
|
|
501
|
+
<span className="text-foreground-soft">Sample shop</span>
|
|
502
|
+
<span aria-hidden>·</span>
|
|
503
|
+
<span>Free delivery from {price(FREE_FROM)}</span>
|
|
504
|
+
<span aria-hidden className="hidden @md/shop:inline">
|
|
505
|
+
·
|
|
506
|
+
</span>
|
|
507
|
+
<span className="hidden @md/shop:inline">Pickup at the studio</span>
|
|
508
|
+
</p>
|
|
509
|
+
<div className="flex items-center justify-between gap-4 py-5">
|
|
510
|
+
<button
|
|
511
|
+
type="button"
|
|
512
|
+
onClick={onHome}
|
|
513
|
+
aria-label="Studio Lehm, all pieces"
|
|
514
|
+
className="cursor-pointer rounded-item border-0 bg-transparent p-0 text-start text-foreground focus-ring"
|
|
515
|
+
>
|
|
516
|
+
<Wordmark>Studio Lehm</Wordmark>
|
|
517
|
+
</button>
|
|
518
|
+
{/* Named by what it shows, and the words it can't: "Cart 2 pieces", "Cart empty". */}
|
|
519
|
+
<Button variant="secondary" size="sm" onClick={onOpenCart}>
|
|
520
|
+
<ShoppingBagIcon />
|
|
521
|
+
Cart
|
|
522
|
+
{count > 0 && (
|
|
523
|
+
<Mono className="min-w-3 text-center tabular-nums">
|
|
524
|
+
<NumberRoll value={count} />
|
|
525
|
+
</Mono>
|
|
526
|
+
)}
|
|
527
|
+
<span className="sr-only">{count ? (count === 1 ? "piece" : "pieces") : "empty"}</span>
|
|
528
|
+
</Button>
|
|
529
|
+
</div>
|
|
530
|
+
</header>
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// ── Product grid ─────────────────────────────────────────────────────────────
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* A product in the grid. Not a box: the picture is the object, in a 20px frame, with the name in
|
|
538
|
+
* Licht and the price in mono under it. The name is the one action, stretched over the whole
|
|
539
|
+
* item, so the picture opens the product too, and the item shows the focus ring (within three
|
|
540
|
+
* levels of the button, where forced colours look for it). A second view shows on hover.
|
|
541
|
+
*/
|
|
542
|
+
function ProductTile({ product, onOpen }: { product: Product; onOpen: () => void }) {
|
|
543
|
+
const price = usePrice();
|
|
544
|
+
const glaze = product.glazes[0]!;
|
|
545
|
+
return (
|
|
546
|
+
<li className="group relative flex min-w-0 flex-col rounded-card outline-offset-[6px] has-[button:focus-visible]:outline-2 has-[button:focus-visible]:outline-(--control-focus)">
|
|
547
|
+
<AspectRatio
|
|
548
|
+
ratio={4 / 5}
|
|
549
|
+
className={`mb-3.5 overflow-hidden rounded-card border border-border/60 ${frameGround}`}
|
|
550
|
+
>
|
|
551
|
+
<img
|
|
552
|
+
src={photo(product, glaze, "front")}
|
|
553
|
+
alt=""
|
|
554
|
+
width={400}
|
|
555
|
+
height={500}
|
|
556
|
+
decoding="async"
|
|
557
|
+
className={`size-full object-cover ${photoTone}`}
|
|
558
|
+
/>
|
|
559
|
+
<img
|
|
560
|
+
src={photo(product, glaze, "above")}
|
|
561
|
+
alt=""
|
|
562
|
+
width={400}
|
|
563
|
+
height={500}
|
|
564
|
+
loading="lazy"
|
|
565
|
+
decoding="async"
|
|
566
|
+
className={`absolute inset-0 size-full object-cover opacity-0 ${photoTone} transition-opacity duration-300 ease-(--ease) motion-reduce:transition-none pointer-fine:group-hover:opacity-100`}
|
|
567
|
+
/>
|
|
568
|
+
</AspectRatio>
|
|
569
|
+
{product.tag && (
|
|
570
|
+
// Over a photo, which is light in both themes, the tag keeps the light theme's ink.
|
|
571
|
+
<Tag
|
|
572
|
+
variant={product.tag.variant}
|
|
573
|
+
tone={product.tag.tone}
|
|
574
|
+
className="theme-light absolute start-3 top-3"
|
|
575
|
+
>
|
|
576
|
+
{product.tag.label}
|
|
577
|
+
</Tag>
|
|
578
|
+
)}
|
|
579
|
+
<div className="flex flex-col gap-1 @2xl/shop:flex-row @2xl/shop:items-baseline @2xl/shop:justify-between @2xl/shop:gap-3">
|
|
580
|
+
<h3 className="m-0 font-heading text-[19px] leading-tight font-light tracking-[-0.01em] @3xl/shop:text-[22px]">
|
|
581
|
+
<button
|
|
582
|
+
type="button"
|
|
583
|
+
onClick={onOpen}
|
|
584
|
+
className="cursor-pointer border-0 bg-transparent p-0 text-start text-foreground outline-none after:absolute after:inset-0 after:content-['']"
|
|
585
|
+
>
|
|
586
|
+
{product.name}
|
|
587
|
+
</button>
|
|
588
|
+
</h3>
|
|
589
|
+
<p className="m-0 font-mono text-[13px] text-foreground tabular-nums">
|
|
590
|
+
{product.sizes ? <span className="text-muted-foreground">from </span> : null}
|
|
591
|
+
{price(product.price)}
|
|
592
|
+
</p>
|
|
593
|
+
</div>
|
|
594
|
+
<p className="m-0 mt-1.5 text-[13px] leading-snug text-muted-foreground">{product.line}</p>
|
|
595
|
+
<p className="m-0 mt-2.5 flex items-center gap-1.5">
|
|
596
|
+
{product.glazes.map((g) => (
|
|
597
|
+
<Swatch key={g} glaze={g} className="size-2.5" />
|
|
598
|
+
))}
|
|
599
|
+
<span className="ms-1 font-mono text-[11px] text-muted-foreground">
|
|
600
|
+
<span className="sr-only">Glazes: {product.glazes.join(", ")}</span>
|
|
601
|
+
<span aria-hidden>{product.glazes.length} glazes</span>
|
|
602
|
+
</span>
|
|
603
|
+
</p>
|
|
604
|
+
</li>
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function ProductGrid({ onOpen }: { onOpen: (id: string) => void }) {
|
|
609
|
+
const titleId = React.useId();
|
|
610
|
+
const [category, setCategory] = React.useState<Category | "all">("all");
|
|
611
|
+
const shown = category === "all" ? products : products.filter((p) => p.category === category);
|
|
612
|
+
return (
|
|
613
|
+
<section aria-labelledby={titleId} className="flex flex-col gap-10 @3xl/shop:gap-14">
|
|
614
|
+
<div className="grid gap-5 pt-4 @3xl/shop:grid-cols-[minmax(0,7fr)_minmax(0,5fr)] @3xl/shop:items-end @3xl/shop:gap-12 @3xl/shop:pt-10">
|
|
615
|
+
<div className="flex flex-col gap-4">
|
|
616
|
+
<Eyebrow>Tableware</Eyebrow>
|
|
617
|
+
<TwoTone id={titleId}>
|
|
618
|
+
<>Pieces for every day.</>
|
|
619
|
+
<>Thrown and glazed by hand.</>
|
|
620
|
+
</TwoTone>
|
|
621
|
+
</div>
|
|
622
|
+
<Text tone="soft" className="max-w-md @3xl/shop:pb-1.5">
|
|
623
|
+
Made in small batches at the studio. Every glaze runs a little differently, so no two pieces are
|
|
624
|
+
quite alike.
|
|
625
|
+
</Text>
|
|
626
|
+
</div>
|
|
627
|
+
|
|
628
|
+
<div className="flex flex-col gap-8">
|
|
629
|
+
<div className="flex flex-wrap items-center justify-between gap-4 border-t border-border/60 pt-5">
|
|
630
|
+
<ToggleGroup
|
|
631
|
+
aria-label="Category"
|
|
632
|
+
value={[category]}
|
|
633
|
+
onValueChange={(v) => v[0] && setCategory(v[0] as Category | "all")}
|
|
634
|
+
>
|
|
635
|
+
{categories.map((c) => (
|
|
636
|
+
<ToggleGroupItem key={c.value} value={c.value}>
|
|
637
|
+
{c.label}
|
|
638
|
+
</ToggleGroupItem>
|
|
639
|
+
))}
|
|
640
|
+
</ToggleGroup>
|
|
641
|
+
<p
|
|
642
|
+
aria-live="polite"
|
|
643
|
+
aria-atomic
|
|
644
|
+
className="m-0 font-mono text-xs text-muted-foreground tabular-nums"
|
|
645
|
+
>
|
|
646
|
+
<Pieces n={shown.length} />
|
|
647
|
+
</p>
|
|
648
|
+
</div>
|
|
649
|
+
<ul
|
|
650
|
+
aria-label="Pieces"
|
|
651
|
+
className="m-0 grid list-none grid-cols-2 gap-x-4 gap-y-10 p-0 @3xl/shop:grid-cols-3 @3xl/shop:gap-x-6 @3xl/shop:gap-y-14"
|
|
652
|
+
>
|
|
653
|
+
{shown.map((product) => (
|
|
654
|
+
<ProductTile key={product.id} product={product} onOpen={() => onOpen(product.id)} />
|
|
655
|
+
))}
|
|
656
|
+
</ul>
|
|
657
|
+
</div>
|
|
658
|
+
<p className="m-0 border-t border-border/60 pt-5 font-mono text-xs text-muted-foreground">
|
|
659
|
+
Sample shop: pieces, prices and terms are examples, and drawn studio pictures stand in for photos.
|
|
660
|
+
</p>
|
|
661
|
+
</section>
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// ── Product page ─────────────────────────────────────────────────────────────
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* The pictures: the large one opens the Lightbox, the thumbnails pick which one is large. They
|
|
669
|
+
* follow the chosen glaze.
|
|
670
|
+
*/
|
|
671
|
+
function Gallery({ product, glaze }: { product: Product; glaze: string }) {
|
|
672
|
+
const [current, setCurrent] = React.useState(0);
|
|
673
|
+
const items = views.map(({ view }) => ({
|
|
674
|
+
src: photo(product, glaze, view),
|
|
675
|
+
alt: `${product.name} in ${glaze}, ${viewLabel(view)}`,
|
|
676
|
+
caption: `${product.name}, ${glaze} — ${viewLabel(view)}`,
|
|
677
|
+
}));
|
|
678
|
+
const shown = items[current]!;
|
|
679
|
+
return (
|
|
680
|
+
<Lightbox items={items} index={current} onIndexChange={setCurrent}>
|
|
681
|
+
<div className="flex min-w-0 flex-col gap-3 @3xl/shop:sticky @3xl/shop:top-6 @3xl/shop:flex-row-reverse @3xl/shop:items-start @3xl/shop:self-start">
|
|
682
|
+
<LightboxTrigger
|
|
683
|
+
index={current}
|
|
684
|
+
className={`group/main relative block w-full min-w-0 flex-1 overflow-hidden rounded-card border border-border/60 ${frameGround} p-0`}
|
|
685
|
+
>
|
|
686
|
+
<AspectRatio ratio={4 / 5}>
|
|
687
|
+
<img
|
|
688
|
+
src={shown.src}
|
|
689
|
+
alt={shown.alt}
|
|
690
|
+
width={400}
|
|
691
|
+
height={500}
|
|
692
|
+
className={`size-full object-cover ${photoTone}`}
|
|
693
|
+
/>
|
|
694
|
+
</AspectRatio>
|
|
695
|
+
<span
|
|
696
|
+
aria-hidden
|
|
697
|
+
className="absolute end-3 bottom-3 flex size-8 items-center justify-center rounded-full bg-white/75 text-neutral-700 opacity-80 transition-opacity duration-150 group-hover/main:opacity-100"
|
|
698
|
+
>
|
|
699
|
+
<MaximizeIcon className="size-3.5" />
|
|
700
|
+
</span>
|
|
701
|
+
</LightboxTrigger>
|
|
702
|
+
<ul aria-label="Pictures" className="m-0 flex list-none gap-2 p-0 @3xl/shop:flex-col">
|
|
703
|
+
{items.map((item, i) => (
|
|
704
|
+
<li key={item.src} className="w-14 @3xl/shop:w-16">
|
|
705
|
+
<button
|
|
706
|
+
type="button"
|
|
707
|
+
aria-label={`Show ${views[i]!.label}`}
|
|
708
|
+
aria-pressed={i === current}
|
|
709
|
+
onClick={() => setCurrent(i)}
|
|
710
|
+
className={`block w-full cursor-pointer overflow-hidden rounded-item border border-border/60 ${frameGround} p-0 opacity-60 focus-ring transition-opacity duration-150 hover:opacity-100 aria-pressed:border-foreground aria-pressed:opacity-100`}
|
|
711
|
+
>
|
|
712
|
+
<AspectRatio ratio={4 / 5}>
|
|
713
|
+
<img
|
|
714
|
+
src={item.src}
|
|
715
|
+
alt=""
|
|
716
|
+
width={64}
|
|
717
|
+
height={80}
|
|
718
|
+
className={`size-full object-cover ${photoTone}`}
|
|
719
|
+
/>
|
|
720
|
+
</AspectRatio>
|
|
721
|
+
</button>
|
|
722
|
+
</li>
|
|
723
|
+
))}
|
|
724
|
+
</ul>
|
|
725
|
+
</div>
|
|
726
|
+
</Lightbox>
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/** A label over a picker, with the current choice beside it in mono. */
|
|
731
|
+
function PickerLabel({ id, label, value }: { id: string; label: string; value: string }) {
|
|
732
|
+
return (
|
|
733
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
734
|
+
<Label id={id} render={<span />}>
|
|
735
|
+
{label}
|
|
736
|
+
</Label>
|
|
737
|
+
<span aria-hidden className="font-mono text-xs text-muted-foreground">
|
|
738
|
+
{value}
|
|
739
|
+
</span>
|
|
740
|
+
</div>
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function ProductDetail({
|
|
745
|
+
product,
|
|
746
|
+
onBack,
|
|
747
|
+
onAdd,
|
|
748
|
+
onOpenCart,
|
|
749
|
+
moveFocus = false,
|
|
750
|
+
}: {
|
|
751
|
+
product: Product;
|
|
752
|
+
/** Move focus here on mount: when someone opened the product from the grid. */
|
|
753
|
+
moveFocus?: boolean;
|
|
754
|
+
onBack: () => void;
|
|
755
|
+
onAdd: (line: Omit<Line, "key">) => void;
|
|
756
|
+
onOpenCart: () => void;
|
|
757
|
+
}) {
|
|
758
|
+
const price = usePrice();
|
|
759
|
+
const glazeLabel = React.useId();
|
|
760
|
+
const sizeLabel = React.useId();
|
|
761
|
+
const [glaze, setGlaze] = React.useState(product.glazes[0]!);
|
|
762
|
+
const [size, setSize] = React.useState(product.sizes?.[0]?.value);
|
|
763
|
+
const [quantity, setQuantity] = React.useState(1);
|
|
764
|
+
const [added, setAdded] = React.useState<string | null>(null);
|
|
765
|
+
const each = unitPrice({ productId: product.id, size });
|
|
766
|
+
const sectionRef = React.useRef<HTMLElement>(null);
|
|
767
|
+
const titleId = React.useId();
|
|
768
|
+
const sizeName = product.sizes?.find((s) => s.value === size)?.label;
|
|
769
|
+
const category = categories.find((c) => c.value === product.category)!.label;
|
|
770
|
+
|
|
771
|
+
// Arriving from the grid, focus moves to the product so a screen reader starts at its name.
|
|
772
|
+
React.useEffect(() => {
|
|
773
|
+
if (moveFocus) sectionRef.current?.focus({ preventScroll: true });
|
|
774
|
+
}, [moveFocus]);
|
|
775
|
+
|
|
776
|
+
function add() {
|
|
777
|
+
onAdd({ productId: product.id, glaze, size, quantity });
|
|
778
|
+
setAdded(`Added ${quantity} × ${product.name}, ${variantLabel({ productId: product.id, glaze, size })}.`);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return (
|
|
782
|
+
<section
|
|
783
|
+
ref={sectionRef}
|
|
784
|
+
tabIndex={-1}
|
|
785
|
+
aria-labelledby={titleId}
|
|
786
|
+
className="flex flex-col gap-6 pt-2 outline-none"
|
|
787
|
+
>
|
|
788
|
+
<Breadcrumb
|
|
789
|
+
items={[{ label: "All pieces", render: crumb(onBack) }, { label: category }, { label: product.name }]}
|
|
790
|
+
/>
|
|
791
|
+
<div className="grid gap-8 @3xl/shop:grid-cols-[minmax(0,7fr)_minmax(0,5fr)] @3xl/shop:gap-14">
|
|
792
|
+
<Gallery key={glaze} product={product} glaze={glaze} />
|
|
793
|
+
|
|
794
|
+
<div className="flex min-w-0 flex-col gap-8">
|
|
795
|
+
<div className="flex flex-col gap-3">
|
|
796
|
+
<div className="flex items-center gap-3">
|
|
797
|
+
<Mono className="text-xs text-muted-foreground">{product.sku}</Mono>
|
|
798
|
+
{product.tag && (
|
|
799
|
+
<Tag variant={product.tag.variant} tone={product.tag.tone}>
|
|
800
|
+
{product.tag.label}
|
|
801
|
+
</Tag>
|
|
802
|
+
)}
|
|
803
|
+
</div>
|
|
804
|
+
<Heading level={2} id={titleId}>
|
|
805
|
+
{product.name}
|
|
806
|
+
</Heading>
|
|
807
|
+
<p className="m-0 text-sm text-muted-foreground">{product.line}</p>
|
|
808
|
+
<p className="m-0 pt-2 font-mono text-[20px] leading-none tabular-nums">
|
|
809
|
+
<Amount cents={each} />
|
|
810
|
+
</p>
|
|
811
|
+
</div>
|
|
812
|
+
<Text tone="soft" size="sm">
|
|
813
|
+
{product.about}
|
|
814
|
+
</Text>
|
|
815
|
+
|
|
816
|
+
<div className="flex flex-col gap-6 border-t border-border/60 pt-6">
|
|
817
|
+
<div className="flex flex-col gap-2.5">
|
|
818
|
+
<PickerLabel id={glazeLabel} label="Glaze" value={glaze} />
|
|
819
|
+
<ToggleGroup
|
|
820
|
+
aria-labelledby={glazeLabel}
|
|
821
|
+
value={[glaze]}
|
|
822
|
+
onValueChange={(v) => v[0] && setGlaze(v[0])}
|
|
823
|
+
className="self-start"
|
|
824
|
+
>
|
|
825
|
+
{product.glazes.map((g) => (
|
|
826
|
+
<ToggleGroupItem key={g} value={g}>
|
|
827
|
+
<Swatch glaze={g} />
|
|
828
|
+
{g}
|
|
829
|
+
</ToggleGroupItem>
|
|
830
|
+
))}
|
|
831
|
+
</ToggleGroup>
|
|
832
|
+
</div>
|
|
833
|
+
{product.sizes && (
|
|
834
|
+
<div className="flex flex-col gap-2.5">
|
|
835
|
+
<PickerLabel id={sizeLabel} label="Size" value={sizeName ?? ""} />
|
|
836
|
+
<ToggleGroup
|
|
837
|
+
aria-labelledby={sizeLabel}
|
|
838
|
+
value={size ? [size] : []}
|
|
839
|
+
onValueChange={(v) => v[0] && setSize(v[0])}
|
|
840
|
+
className="self-start"
|
|
841
|
+
>
|
|
842
|
+
{product.sizes.map((s) => (
|
|
843
|
+
<ToggleGroupItem key={s.value} value={s.value}>
|
|
844
|
+
{s.label}
|
|
845
|
+
{s.extra ? (
|
|
846
|
+
<span className="font-mono text-[11px] text-muted-foreground">+{price(s.extra)}</span>
|
|
847
|
+
) : null}
|
|
848
|
+
</ToggleGroupItem>
|
|
849
|
+
))}
|
|
850
|
+
</ToggleGroup>
|
|
851
|
+
</div>
|
|
852
|
+
)}
|
|
853
|
+
<Field name="quantity" className="self-start">
|
|
854
|
+
<FieldLabel>Quantity</FieldLabel>
|
|
855
|
+
<NumberField
|
|
856
|
+
value={quantity}
|
|
857
|
+
onValueChange={(v) => setQuantity(v ?? 1)}
|
|
858
|
+
min={1}
|
|
859
|
+
max={10}
|
|
860
|
+
className="w-36"
|
|
861
|
+
/>
|
|
862
|
+
</Field>
|
|
863
|
+
{/* The one primary in this view. */}
|
|
864
|
+
<Button size="lg" onClick={add}>
|
|
865
|
+
Add to cart ·{" "}
|
|
866
|
+
<span className="font-mono tabular-nums">
|
|
867
|
+
<Amount cents={each * quantity} />
|
|
868
|
+
</span>
|
|
869
|
+
</Button>
|
|
870
|
+
<div aria-live="polite" className="-mt-2 empty:hidden">
|
|
871
|
+
{added && (
|
|
872
|
+
<p className="m-0 flex flex-wrap items-center gap-x-2 gap-y-2 text-sm text-foreground-soft">
|
|
873
|
+
<CircleCheckIcon aria-hidden className="size-4 text-success" />
|
|
874
|
+
{added}
|
|
875
|
+
<Button variant="link" onClick={onOpenCart}>
|
|
876
|
+
View cart
|
|
877
|
+
</Button>
|
|
878
|
+
</p>
|
|
879
|
+
)}
|
|
880
|
+
</div>
|
|
881
|
+
<ul className="m-0 flex list-none flex-col gap-2.5 p-0 text-[13px] text-foreground-soft">
|
|
882
|
+
<li className="flex gap-3">
|
|
883
|
+
<TruckIcon aria-hidden className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
884
|
+
<span>
|
|
885
|
+
Delivery in 3–5 working days, <Mono className="tabular-nums">{price(DELIVERY_FEE)}</Mono>;
|
|
886
|
+
free from <Mono className="tabular-nums">{price(FREE_FROM)}</Mono>
|
|
887
|
+
</span>
|
|
888
|
+
</li>
|
|
889
|
+
<li className="flex gap-3">
|
|
890
|
+
<StoreIcon aria-hidden className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
891
|
+
<span>Pickup at the studio, Thursday to Saturday, free</span>
|
|
892
|
+
</li>
|
|
893
|
+
<li className="flex gap-3">
|
|
894
|
+
<RotateCcwIcon aria-hidden className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
895
|
+
<span>Returns within 30 days, unused</span>
|
|
896
|
+
</li>
|
|
897
|
+
</ul>
|
|
898
|
+
</div>
|
|
899
|
+
|
|
900
|
+
<Accordion defaultValue={["details"]}>
|
|
901
|
+
<AccordionItem value="details">
|
|
902
|
+
<AccordionTrigger>Details</AccordionTrigger>
|
|
903
|
+
<AccordionPanel>
|
|
904
|
+
<dl className="m-0 grid grid-cols-[minmax(0,6rem)_minmax(0,1fr)] gap-x-4 gap-y-2.5 text-sm">
|
|
905
|
+
{(
|
|
906
|
+
[
|
|
907
|
+
["Clay", product.clay],
|
|
908
|
+
["Glaze", glaze],
|
|
909
|
+
["Size", sizeName ?? product.measure ?? "One size"],
|
|
910
|
+
["Made", "Thrown and glazed at the studio"],
|
|
911
|
+
["Code", product.sku],
|
|
912
|
+
] as const
|
|
913
|
+
).map(([term, detail]) => (
|
|
914
|
+
<React.Fragment key={term}>
|
|
915
|
+
<dt className="pt-0.5 eyebrow">{term}</dt>
|
|
916
|
+
<dd className="m-0 text-foreground-soft">{detail}</dd>
|
|
917
|
+
</React.Fragment>
|
|
918
|
+
))}
|
|
919
|
+
</dl>
|
|
920
|
+
</AccordionPanel>
|
|
921
|
+
</AccordionItem>
|
|
922
|
+
<AccordionItem value="care">
|
|
923
|
+
<AccordionTrigger>Care</AccordionTrigger>
|
|
924
|
+
<AccordionPanel>{product.care}</AccordionPanel>
|
|
925
|
+
</AccordionItem>
|
|
926
|
+
<AccordionItem value="terms">
|
|
927
|
+
<AccordionTrigger>Delivery and returns</AccordionTrigger>
|
|
928
|
+
<AccordionPanel>
|
|
929
|
+
Delivery costs {price(DELIVERY_FEE)} and is free from {price(FREE_FROM)}; pickup at the studio
|
|
930
|
+
is free. Return unused pieces within 30 days. Sample terms: set your own.
|
|
931
|
+
</AccordionPanel>
|
|
932
|
+
</AccordionItem>
|
|
933
|
+
</Accordion>
|
|
934
|
+
</div>
|
|
935
|
+
</div>
|
|
936
|
+
</section>
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// ── Cart ─────────────────────────────────────────────────────────────────────
|
|
941
|
+
|
|
942
|
+
/** The figures under the lines: a description list, the amounts in mono, the total last. */
|
|
943
|
+
function Totals({
|
|
944
|
+
rows,
|
|
945
|
+
}: {
|
|
946
|
+
rows: { term: string; amount: React.ReactNode; note?: string; total?: boolean }[];
|
|
947
|
+
}) {
|
|
948
|
+
return (
|
|
949
|
+
<dl className="m-0 flex flex-col">
|
|
950
|
+
{rows.map((row) => (
|
|
951
|
+
<div
|
|
952
|
+
key={row.term}
|
|
953
|
+
className={`flex items-baseline justify-between gap-4 py-1.5 ${row.total ? "mt-2 border-t border-border/60 pt-4" : ""}`}
|
|
954
|
+
>
|
|
955
|
+
<dt className={row.total ? "text-[15px] font-medium" : "text-sm text-foreground-soft"}>
|
|
956
|
+
{row.term}
|
|
957
|
+
{row.note && <span className="block text-xs text-muted-foreground">{row.note}</span>}
|
|
958
|
+
</dt>
|
|
959
|
+
<dd className={`m-0 shrink-0 font-mono tabular-nums ${row.total ? "text-[20px]" : "text-sm"}`}>
|
|
960
|
+
{row.amount}
|
|
961
|
+
</dd>
|
|
962
|
+
</div>
|
|
963
|
+
))}
|
|
964
|
+
</dl>
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/** A line's picture: the studio picture in the line's glaze, small, at the same ratio. */
|
|
969
|
+
function Thumb({ line, className }: { line: Line; className: string }) {
|
|
970
|
+
const product = productById(line.productId);
|
|
971
|
+
return (
|
|
972
|
+
<span
|
|
973
|
+
className={`block shrink-0 overflow-hidden rounded-item border border-border/60 ${frameGround} ${className}`}
|
|
974
|
+
>
|
|
975
|
+
<AspectRatio ratio={4 / 5}>
|
|
976
|
+
<img
|
|
977
|
+
src={photo(product, line.glaze)}
|
|
978
|
+
alt=""
|
|
979
|
+
width={72}
|
|
980
|
+
height={90}
|
|
981
|
+
className={`size-full object-cover ${photoTone}`}
|
|
982
|
+
/>
|
|
983
|
+
</AspectRatio>
|
|
984
|
+
</span>
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/** The cart's lines: picture, name and choices, the line's price, quantity and remove. */
|
|
989
|
+
function CartLines({ cart }: { cart: Cart }) {
|
|
990
|
+
const price = usePrice();
|
|
991
|
+
return (
|
|
992
|
+
<ul aria-label="Pieces in your cart" className="m-0 flex list-none flex-col p-0">
|
|
993
|
+
{cart.lines.map((line) => {
|
|
994
|
+
const product = productById(line.productId);
|
|
995
|
+
return (
|
|
996
|
+
<li key={line.key} className="flex gap-4 border-b border-border/60 py-5 first:pt-1">
|
|
997
|
+
<Thumb line={line} className="w-[72px]" />
|
|
998
|
+
<div className="flex min-w-0 flex-1 flex-col justify-between gap-3">
|
|
999
|
+
<div className="flex items-start justify-between gap-3">
|
|
1000
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
1001
|
+
<p className="m-0 text-[15px] leading-snug font-medium">{product.name}</p>
|
|
1002
|
+
<p className="m-0 flex items-center gap-1.5 text-[13px] text-muted-foreground">
|
|
1003
|
+
<Swatch glaze={line.glaze} className="size-2.5" />
|
|
1004
|
+
{variantLabel(line)}
|
|
1005
|
+
</p>
|
|
1006
|
+
</div>
|
|
1007
|
+
<p className="m-0 text-end font-mono text-sm tabular-nums">
|
|
1008
|
+
{line.quantity > 1 && (
|
|
1009
|
+
<span className="block text-[11px] text-muted-foreground">
|
|
1010
|
+
<NumberRoll value={line.quantity} /> × {price(unitPrice(line))}
|
|
1011
|
+
</span>
|
|
1012
|
+
)}
|
|
1013
|
+
<Amount cents={unitPrice(line) * line.quantity} />
|
|
1014
|
+
</p>
|
|
1015
|
+
</div>
|
|
1016
|
+
<div className="flex items-center justify-between gap-3">
|
|
1017
|
+
<NumberField
|
|
1018
|
+
size="sm"
|
|
1019
|
+
aria-label={`Quantity of ${product.name}`}
|
|
1020
|
+
value={line.quantity}
|
|
1021
|
+
onValueChange={(v) => cart.setQuantity(line.key, v ?? 1)}
|
|
1022
|
+
min={1}
|
|
1023
|
+
max={10}
|
|
1024
|
+
className="w-28"
|
|
1025
|
+
/>
|
|
1026
|
+
<Button
|
|
1027
|
+
size="sm"
|
|
1028
|
+
variant="ghost"
|
|
1029
|
+
aria-label={`Remove ${product.name}, ${variantLabel(line)}`}
|
|
1030
|
+
onClick={() => cart.remove(line.key)}
|
|
1031
|
+
>
|
|
1032
|
+
Remove
|
|
1033
|
+
</Button>
|
|
1034
|
+
</div>
|
|
1035
|
+
</div>
|
|
1036
|
+
</li>
|
|
1037
|
+
);
|
|
1038
|
+
})}
|
|
1039
|
+
</ul>
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/** How far the cart is from free delivery, as a quiet track that fills. */
|
|
1044
|
+
function FreeDelivery({ subtotal }: { subtotal: number }) {
|
|
1045
|
+
const price = usePrice();
|
|
1046
|
+
const toGo = FREE_FROM - subtotal;
|
|
1047
|
+
return (
|
|
1048
|
+
<Progress
|
|
1049
|
+
value={Math.min(100, (subtotal / FREE_FROM) * 100)}
|
|
1050
|
+
tone={toGo > 0 ? "default" : "success"}
|
|
1051
|
+
label={
|
|
1052
|
+
toGo > 0 ? (
|
|
1053
|
+
<>
|
|
1054
|
+
<Amount cents={toGo} /> to free delivery
|
|
1055
|
+
</>
|
|
1056
|
+
) : (
|
|
1057
|
+
"Free delivery on this order"
|
|
1058
|
+
)
|
|
1059
|
+
}
|
|
1060
|
+
getAriaValueText={() =>
|
|
1061
|
+
toGo > 0 ? `${price(subtotal)} of ${price(FREE_FROM)} for free delivery` : "Free delivery reached"
|
|
1062
|
+
}
|
|
1063
|
+
/>
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function CartDrawer({
|
|
1068
|
+
cart,
|
|
1069
|
+
open,
|
|
1070
|
+
onOpenChange,
|
|
1071
|
+
onCheckout,
|
|
1072
|
+
}: {
|
|
1073
|
+
cart: Cart;
|
|
1074
|
+
open: boolean;
|
|
1075
|
+
onOpenChange: (open: boolean) => void;
|
|
1076
|
+
onCheckout: () => void;
|
|
1077
|
+
}) {
|
|
1078
|
+
const subtotal = subtotalOf(cart.lines);
|
|
1079
|
+
const count = countOf(cart.lines);
|
|
1080
|
+
return (
|
|
1081
|
+
<Drawer side="right" open={open} onOpenChange={onOpenChange}>
|
|
1082
|
+
<DrawerContent>
|
|
1083
|
+
<DrawerHeader>
|
|
1084
|
+
<DrawerTitle>Your cart</DrawerTitle>
|
|
1085
|
+
<DrawerDescription className="text-sm">
|
|
1086
|
+
{count ? (
|
|
1087
|
+
<>
|
|
1088
|
+
<Pieces n={count} />. Delivery or pickup is chosen at checkout.
|
|
1089
|
+
</>
|
|
1090
|
+
) : (
|
|
1091
|
+
"Nothing in it yet."
|
|
1092
|
+
)}
|
|
1093
|
+
</DrawerDescription>
|
|
1094
|
+
</DrawerHeader>
|
|
1095
|
+
{cart.lines.length ? (
|
|
1096
|
+
<>
|
|
1097
|
+
<FreeDelivery subtotal={subtotal} />
|
|
1098
|
+
<CartLines cart={cart} />
|
|
1099
|
+
{/* Pinned to the bottom of the panel, so the total and checkout stay in reach of a long cart. */}
|
|
1100
|
+
<DrawerFooter className="sticky bottom-0 -mx-6 -mb-6 flex-col gap-4 border-t border-border/60 bg-field-surface px-6 pt-5 pb-6 sm:-mx-8 sm:-mb-8 sm:flex-col sm:items-stretch sm:px-8 sm:pb-8">
|
|
1101
|
+
<Totals
|
|
1102
|
+
rows={[
|
|
1103
|
+
{ term: "Subtotal", amount: <Amount cents={subtotal} /> },
|
|
1104
|
+
{
|
|
1105
|
+
term: "Delivery",
|
|
1106
|
+
amount: <Amount cents={deliveryFee(subtotal)} />,
|
|
1107
|
+
note: deliveryFee(subtotal) ? "Pickup at the studio is free." : undefined,
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
term: "Total with delivery",
|
|
1111
|
+
amount: <Amount cents={subtotal + deliveryFee(subtotal)} />,
|
|
1112
|
+
total: true,
|
|
1113
|
+
},
|
|
1114
|
+
]}
|
|
1115
|
+
/>
|
|
1116
|
+
<Button size="lg" onClick={onCheckout}>
|
|
1117
|
+
Go to checkout
|
|
1118
|
+
</Button>
|
|
1119
|
+
<DrawerClose render={<Button variant="ghost" />}>Keep browsing</DrawerClose>
|
|
1120
|
+
</DrawerFooter>
|
|
1121
|
+
</>
|
|
1122
|
+
) : (
|
|
1123
|
+
<Empty>
|
|
1124
|
+
<EmptyMedia>
|
|
1125
|
+
<ShoppingBagIcon />
|
|
1126
|
+
</EmptyMedia>
|
|
1127
|
+
<EmptyTitle>Your cart is empty</EmptyTitle>
|
|
1128
|
+
<EmptyDescription>Pick a piece and its glaze, and it waits here.</EmptyDescription>
|
|
1129
|
+
<EmptyActions>
|
|
1130
|
+
<DrawerClose render={<Button variant="secondary" />}>Browse the pieces</DrawerClose>
|
|
1131
|
+
</EmptyActions>
|
|
1132
|
+
</Empty>
|
|
1133
|
+
)}
|
|
1134
|
+
</DrawerContent>
|
|
1135
|
+
</Drawer>
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// ── Checkout ─────────────────────────────────────────────────────────────────
|
|
1140
|
+
|
|
1141
|
+
/** A pretend round trip that never resolves after unmount. */
|
|
1142
|
+
function useFakeRequest() {
|
|
1143
|
+
const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
1144
|
+
React.useEffect(() => () => clearTimeout(timer.current), []);
|
|
1145
|
+
return React.useCallback(
|
|
1146
|
+
(ms: number) =>
|
|
1147
|
+
new Promise<void>((resolve) => {
|
|
1148
|
+
clearTimeout(timer.current);
|
|
1149
|
+
timer.current = setTimeout(resolve, ms);
|
|
1150
|
+
}),
|
|
1151
|
+
[],
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
type Method = "delivery" | "pickup";
|
|
1156
|
+
|
|
1157
|
+
/** The order: what is in it, and what it costs with the chosen way to get it. */
|
|
1158
|
+
function OrderSummary({
|
|
1159
|
+
lines,
|
|
1160
|
+
method,
|
|
1161
|
+
onEdit,
|
|
1162
|
+
titleId,
|
|
1163
|
+
}: {
|
|
1164
|
+
lines: Line[];
|
|
1165
|
+
method: Method;
|
|
1166
|
+
onEdit?: () => void;
|
|
1167
|
+
titleId: string;
|
|
1168
|
+
}) {
|
|
1169
|
+
const subtotal = subtotalOf(lines);
|
|
1170
|
+
const delivery = method === "pickup" ? 0 : deliveryFee(subtotal);
|
|
1171
|
+
return (
|
|
1172
|
+
<>
|
|
1173
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
1174
|
+
<h3 id={titleId} className="m-0 eyebrow">
|
|
1175
|
+
Your order
|
|
1176
|
+
</h3>
|
|
1177
|
+
{onEdit ? (
|
|
1178
|
+
<Button variant="link" onClick={onEdit}>
|
|
1179
|
+
Edit cart
|
|
1180
|
+
</Button>
|
|
1181
|
+
) : (
|
|
1182
|
+
<Mono className="text-xs text-muted-foreground tabular-nums">
|
|
1183
|
+
<Pieces n={countOf(lines)} />
|
|
1184
|
+
</Mono>
|
|
1185
|
+
)}
|
|
1186
|
+
</div>
|
|
1187
|
+
<ul className="m-0 flex list-none flex-col gap-4 p-0">
|
|
1188
|
+
{lines.map((line) => {
|
|
1189
|
+
const product = productById(line.productId);
|
|
1190
|
+
return (
|
|
1191
|
+
<li key={line.key} className="flex items-center gap-3">
|
|
1192
|
+
<Thumb line={line} className="w-12" />
|
|
1193
|
+
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
1194
|
+
<span className="text-sm font-medium">{product.name}</span>
|
|
1195
|
+
<span className="text-xs text-muted-foreground">
|
|
1196
|
+
{variantLabel(line)} · <NumberRoll value={line.quantity} /> ×
|
|
1197
|
+
</span>
|
|
1198
|
+
</span>
|
|
1199
|
+
<Mono className="text-sm tabular-nums">
|
|
1200
|
+
<Amount cents={unitPrice(line) * line.quantity} />
|
|
1201
|
+
</Mono>
|
|
1202
|
+
</li>
|
|
1203
|
+
);
|
|
1204
|
+
})}
|
|
1205
|
+
</ul>
|
|
1206
|
+
<Totals
|
|
1207
|
+
rows={[
|
|
1208
|
+
{ term: "Subtotal", amount: <Amount cents={subtotal} /> },
|
|
1209
|
+
{
|
|
1210
|
+
term: method === "pickup" ? "Pickup" : "Delivery",
|
|
1211
|
+
amount: delivery ? <Amount cents={delivery} /> : "Free",
|
|
1212
|
+
},
|
|
1213
|
+
{ term: "Total", amount: <Amount cents={subtotal + delivery} />, total: true },
|
|
1214
|
+
]}
|
|
1215
|
+
/>
|
|
1216
|
+
</>
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/** One way to get the order, as a row of the radio group: what it is, when, and what it costs. */
|
|
1221
|
+
function MethodOption({
|
|
1222
|
+
value,
|
|
1223
|
+
title,
|
|
1224
|
+
detail,
|
|
1225
|
+
cost,
|
|
1226
|
+
}: {
|
|
1227
|
+
value: Method;
|
|
1228
|
+
title: string;
|
|
1229
|
+
detail: string;
|
|
1230
|
+
cost: string;
|
|
1231
|
+
}) {
|
|
1232
|
+
return (
|
|
1233
|
+
<FieldItem className="w-full self-stretch">
|
|
1234
|
+
<FieldLabel className="w-full cursor-pointer items-start gap-3 border-b border-border/60 py-4 font-normal">
|
|
1235
|
+
<Radio value={value} className="mt-0.5" />
|
|
1236
|
+
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
1237
|
+
<span className="text-[15px] font-medium text-foreground">{title}</span>
|
|
1238
|
+
<span className="text-[13px] text-muted-foreground">{detail}</span>
|
|
1239
|
+
</span>
|
|
1240
|
+
<Mono className="shrink-0 text-sm tabular-nums">{cost}</Mono>
|
|
1241
|
+
</FieldLabel>
|
|
1242
|
+
</FieldItem>
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
/** The heading of a part of the form: a mono index, then its name in Licht. */
|
|
1247
|
+
const stepTitle =
|
|
1248
|
+
"float-left mb-1 flex w-full items-baseline gap-3 font-heading text-[22px] font-light tracking-[-0.01em] normal-case text-foreground";
|
|
1249
|
+
|
|
1250
|
+
function Step({ n, children }: { n: number; children: React.ReactNode }) {
|
|
1251
|
+
return (
|
|
1252
|
+
<FieldsetLegend className={stepTitle}>
|
|
1253
|
+
<Index n={n} aria-hidden />
|
|
1254
|
+
{children}
|
|
1255
|
+
</FieldsetLegend>
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
function Confirmation({
|
|
1260
|
+
name,
|
|
1261
|
+
email,
|
|
1262
|
+
method,
|
|
1263
|
+
lines,
|
|
1264
|
+
onDone,
|
|
1265
|
+
}: {
|
|
1266
|
+
name: string;
|
|
1267
|
+
email: string;
|
|
1268
|
+
method: Method;
|
|
1269
|
+
lines: Line[];
|
|
1270
|
+
onDone: () => void;
|
|
1271
|
+
}) {
|
|
1272
|
+
const ref = React.useRef<HTMLElement>(null);
|
|
1273
|
+
const titleId = React.useId();
|
|
1274
|
+
const summaryId = React.useId();
|
|
1275
|
+
React.useEffect(() => ref.current?.focus({ preventScroll: true }), []);
|
|
1276
|
+
const first = name.trim().split(/\s+/)[0] ?? "";
|
|
1277
|
+
const next =
|
|
1278
|
+
method === "pickup"
|
|
1279
|
+
? [
|
|
1280
|
+
`A confirmation goes to ${email}.`,
|
|
1281
|
+
"We pack your pieces and email you when they are ready to collect.",
|
|
1282
|
+
"Pick them up at the studio, Thursday to Saturday.",
|
|
1283
|
+
]
|
|
1284
|
+
: [
|
|
1285
|
+
`A confirmation goes to ${email}.`,
|
|
1286
|
+
"We pack your pieces and send them within two working days.",
|
|
1287
|
+
"The parcel arrives in 3–5 working days, with a tracking link.",
|
|
1288
|
+
];
|
|
1289
|
+
return (
|
|
1290
|
+
<section
|
|
1291
|
+
ref={ref}
|
|
1292
|
+
tabIndex={-1}
|
|
1293
|
+
aria-labelledby={titleId}
|
|
1294
|
+
className="grid gap-10 pt-4 outline-none @3xl/shop:grid-cols-[minmax(0,7fr)_minmax(0,5fr)] @3xl/shop:gap-14 @3xl/shop:pt-10"
|
|
1295
|
+
>
|
|
1296
|
+
<div className="flex min-w-0 flex-col items-start gap-6">
|
|
1297
|
+
<p className="m-0 flex items-center gap-2 font-mono text-xs tracking-[0.08em] text-success uppercase">
|
|
1298
|
+
<CircleCheckIcon aria-hidden className="size-4" />
|
|
1299
|
+
Order received
|
|
1300
|
+
</p>
|
|
1301
|
+
<TwoTone id={titleId}>
|
|
1302
|
+
<>{first ? `Thank you, ${first}.` : "Thank you."}</>
|
|
1303
|
+
<>We'll start packing.</>
|
|
1304
|
+
</TwoTone>
|
|
1305
|
+
<p className="m-0 font-mono text-xs text-muted-foreground">
|
|
1306
|
+
Sample order: nothing was sent and nothing was charged.
|
|
1307
|
+
</p>
|
|
1308
|
+
<ol aria-label="What happens next" className="m-0 flex w-full list-none flex-col p-0">
|
|
1309
|
+
{next.map((step, i) => (
|
|
1310
|
+
<li key={step} className="flex gap-4 border-t border-border/60 py-4 text-foreground-soft">
|
|
1311
|
+
<Index n={i + 1} className="pt-1" />
|
|
1312
|
+
<span className="min-w-0 wrap-anywhere">{step}</span>
|
|
1313
|
+
</li>
|
|
1314
|
+
))}
|
|
1315
|
+
</ol>
|
|
1316
|
+
<Button variant="secondary" onClick={onDone}>
|
|
1317
|
+
Back to the shop
|
|
1318
|
+
</Button>
|
|
1319
|
+
</div>
|
|
1320
|
+
<aside
|
|
1321
|
+
aria-labelledby={summaryId}
|
|
1322
|
+
className="flex flex-col gap-5 p-5 surface-container @3xl/shop:self-start @3xl/shop:p-6"
|
|
1323
|
+
>
|
|
1324
|
+
<OrderSummary lines={lines} method={method} titleId={summaryId} />
|
|
1325
|
+
</aside>
|
|
1326
|
+
</section>
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function Checkout({ cart, onBack, onEditCart }: { cart: Cart; onBack: () => void; onEditCart: () => void }) {
|
|
1331
|
+
const price = usePrice();
|
|
1332
|
+
const request = useFakeRequest();
|
|
1333
|
+
const [method, setMethod] = React.useState<Method>("delivery");
|
|
1334
|
+
const [pending, setPending] = React.useState(false);
|
|
1335
|
+
const [placed, setPlaced] = React.useState<{ name: string; email: string; lines: Line[] } | null>(null);
|
|
1336
|
+
const subtotal = subtotalOf(cart.lines);
|
|
1337
|
+
const fee = deliveryFee(subtotal);
|
|
1338
|
+
const total = subtotal + (method === "pickup" ? 0 : fee);
|
|
1339
|
+
const titleId = React.useId();
|
|
1340
|
+
const summaryId = React.useId();
|
|
1341
|
+
|
|
1342
|
+
async function submit(values: Record<string, unknown>) {
|
|
1343
|
+
if (pending) return;
|
|
1344
|
+
setPending(true);
|
|
1345
|
+
await request(900);
|
|
1346
|
+
setPending(false);
|
|
1347
|
+
// The order is placed: keep what was in it for the confirmation, and empty the cart.
|
|
1348
|
+
setPlaced({ name: String(values.name ?? ""), email: String(values.email ?? ""), lines: cart.lines });
|
|
1349
|
+
cart.clear();
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
if (placed)
|
|
1353
|
+
return (
|
|
1354
|
+
<Confirmation
|
|
1355
|
+
name={placed.name}
|
|
1356
|
+
email={placed.email}
|
|
1357
|
+
method={method}
|
|
1358
|
+
lines={placed.lines}
|
|
1359
|
+
onDone={onBack}
|
|
1360
|
+
/>
|
|
1361
|
+
);
|
|
1362
|
+
|
|
1363
|
+
if (!cart.lines.length)
|
|
1364
|
+
return (
|
|
1365
|
+
<Empty className="py-16">
|
|
1366
|
+
<EmptyMedia>
|
|
1367
|
+
<ShoppingBagIcon />
|
|
1368
|
+
</EmptyMedia>
|
|
1369
|
+
<EmptyTitle>Nothing to check out</EmptyTitle>
|
|
1370
|
+
<EmptyDescription>Your cart is empty. Pick a piece and its glaze first.</EmptyDescription>
|
|
1371
|
+
<EmptyActions>
|
|
1372
|
+
<Button variant="secondary" onClick={onBack}>
|
|
1373
|
+
Browse the pieces
|
|
1374
|
+
</Button>
|
|
1375
|
+
</EmptyActions>
|
|
1376
|
+
</Empty>
|
|
1377
|
+
);
|
|
1378
|
+
|
|
1379
|
+
return (
|
|
1380
|
+
<section aria-labelledby={titleId} className="flex flex-col gap-6 pt-2">
|
|
1381
|
+
<Breadcrumb
|
|
1382
|
+
items={[
|
|
1383
|
+
{ label: "Shop", render: crumb(onBack) },
|
|
1384
|
+
{ label: "Cart", render: crumb(onEditCart) },
|
|
1385
|
+
{ label: "Checkout" },
|
|
1386
|
+
]}
|
|
1387
|
+
/>
|
|
1388
|
+
<Heading level={2} id={titleId}>
|
|
1389
|
+
Checkout
|
|
1390
|
+
</Heading>
|
|
1391
|
+
<div className="grid gap-10 @3xl/shop:grid-cols-[minmax(0,7fr)_minmax(0,5fr)] @3xl/shop:gap-14">
|
|
1392
|
+
{/* First on a phone, so the order is in view before the form; beside it from @3xl. */}
|
|
1393
|
+
<aside
|
|
1394
|
+
aria-labelledby={summaryId}
|
|
1395
|
+
className="flex flex-col gap-5 p-5 surface-container @3xl/shop:sticky @3xl/shop:top-6 @3xl/shop:order-last @3xl/shop:self-start @3xl/shop:p-6"
|
|
1396
|
+
>
|
|
1397
|
+
<OrderSummary lines={cart.lines} method={method} onEdit={onEditCart} titleId={summaryId} />
|
|
1398
|
+
</aside>
|
|
1399
|
+
|
|
1400
|
+
<Form className="@container min-w-0 gap-10" onFormSubmit={submit}>
|
|
1401
|
+
<Fieldset className="gap-5">
|
|
1402
|
+
<Step n={1}>Contact</Step>
|
|
1403
|
+
<div className="grid gap-5 @md/shop:grid-cols-2">
|
|
1404
|
+
<Field name="name">
|
|
1405
|
+
<FieldLabel>Full name</FieldLabel>
|
|
1406
|
+
<Input required autoComplete="name" placeholder="Mira Hofmann" />
|
|
1407
|
+
<FieldError match="valueMissing">The name for the parcel or the pickup.</FieldError>
|
|
1408
|
+
</Field>
|
|
1409
|
+
<Field name="email">
|
|
1410
|
+
<FieldLabel>Email</FieldLabel>
|
|
1411
|
+
<Input required type="email" autoComplete="email" placeholder="mira@example.com" />
|
|
1412
|
+
<FieldError match="valueMissing">We send the confirmation here.</FieldError>
|
|
1413
|
+
<FieldError match="typeMismatch">Enter an email address, like mira@example.com.</FieldError>
|
|
1414
|
+
</Field>
|
|
1415
|
+
</div>
|
|
1416
|
+
</Fieldset>
|
|
1417
|
+
|
|
1418
|
+
<Field name="method">
|
|
1419
|
+
<Fieldset
|
|
1420
|
+
render={<RadioGroup value={method} onValueChange={(v) => setMethod(v as Method)} />}
|
|
1421
|
+
className="gap-0"
|
|
1422
|
+
>
|
|
1423
|
+
<Step n={2}>Delivery or pickup</Step>
|
|
1424
|
+
<div className="mt-3 w-full border-t border-border/60">
|
|
1425
|
+
<MethodOption
|
|
1426
|
+
value="delivery"
|
|
1427
|
+
title="Delivery"
|
|
1428
|
+
detail="3–5 working days, with a tracking link"
|
|
1429
|
+
cost={fee ? price(fee) : "Free"}
|
|
1430
|
+
/>
|
|
1431
|
+
<MethodOption
|
|
1432
|
+
value="pickup"
|
|
1433
|
+
title="Pickup at the studio"
|
|
1434
|
+
detail="Thursday to Saturday; we email you when it is ready"
|
|
1435
|
+
cost="Free"
|
|
1436
|
+
/>
|
|
1437
|
+
</div>
|
|
1438
|
+
</Fieldset>
|
|
1439
|
+
</Field>
|
|
1440
|
+
|
|
1441
|
+
{method === "delivery" && (
|
|
1442
|
+
<Fieldset className="gap-5">
|
|
1443
|
+
<Step n={3}>Delivery address</Step>
|
|
1444
|
+
<Field name="street">
|
|
1445
|
+
<FieldLabel>Street and number</FieldLabel>
|
|
1446
|
+
<Input required autoComplete="street-address" placeholder="Lindenstraße 12" />
|
|
1447
|
+
<FieldError match="valueMissing">Where the parcel goes.</FieldError>
|
|
1448
|
+
</Field>
|
|
1449
|
+
<div className="grid gap-5 @md/shop:grid-cols-[minmax(0,1fr)_minmax(0,2fr)]">
|
|
1450
|
+
<Field name="postcode">
|
|
1451
|
+
<FieldLabel>Postcode</FieldLabel>
|
|
1452
|
+
<Input required autoComplete="postal-code" inputMode="numeric" placeholder="10115" />
|
|
1453
|
+
<FieldError match="valueMissing">Add the postcode.</FieldError>
|
|
1454
|
+
</Field>
|
|
1455
|
+
<Field name="city">
|
|
1456
|
+
<FieldLabel>City</FieldLabel>
|
|
1457
|
+
<Input required autoComplete="address-level2" placeholder="Berlin" />
|
|
1458
|
+
<FieldError match="valueMissing">Add the city.</FieldError>
|
|
1459
|
+
</Field>
|
|
1460
|
+
</div>
|
|
1461
|
+
</Fieldset>
|
|
1462
|
+
)}
|
|
1463
|
+
|
|
1464
|
+
<div className="flex flex-col gap-2">
|
|
1465
|
+
<h3 className={`m-0 ${stepTitle}`}>
|
|
1466
|
+
<Index n={method === "delivery" ? 4 : 3} aria-hidden />
|
|
1467
|
+
Payment
|
|
1468
|
+
</h3>
|
|
1469
|
+
<Text tone="muted" size="sm">
|
|
1470
|
+
Sample: in a real shop, payment comes next, on your payment provider's page. Nothing is charged
|
|
1471
|
+
here.
|
|
1472
|
+
</Text>
|
|
1473
|
+
</div>
|
|
1474
|
+
|
|
1475
|
+
{/* On a phone the total and the button stay at the bottom of the screen, over the page
|
|
1476
|
+
ground; from @3xl they simply end the form. */}
|
|
1477
|
+
<div className="surface-page sticky bottom-0 z-10 -mx-4 flex items-center gap-4 border-t border-border/60 px-4 pt-3 pb-[calc(0.75rem+env(safe-area-inset-bottom,0px))] @3xl/shop:static @3xl/shop:mx-0 @3xl/shop:block @3xl/shop:border-0 @3xl/shop:p-0 @3xl/shop:[background:none] @3xl/shop:before:hidden @3xl/shop:after:hidden">
|
|
1478
|
+
<p className="m-0 flex flex-col @3xl/shop:hidden">
|
|
1479
|
+
<span className="text-xs text-muted-foreground">Total</span>
|
|
1480
|
+
<Mono className="text-[17px] tabular-nums">
|
|
1481
|
+
<Amount cents={total} />
|
|
1482
|
+
</Mono>
|
|
1483
|
+
</p>
|
|
1484
|
+
<Button
|
|
1485
|
+
type="submit"
|
|
1486
|
+
size="lg"
|
|
1487
|
+
loading={pending}
|
|
1488
|
+
loadingLabel="Placing your order"
|
|
1489
|
+
className="flex-1 @3xl/shop:w-full"
|
|
1490
|
+
>
|
|
1491
|
+
<span>
|
|
1492
|
+
Place order ·{" "}
|
|
1493
|
+
<span className="font-mono tabular-nums">
|
|
1494
|
+
<Amount cents={total} />
|
|
1495
|
+
</span>
|
|
1496
|
+
</span>
|
|
1497
|
+
</Button>
|
|
1498
|
+
</div>
|
|
1499
|
+
</Form>
|
|
1500
|
+
</div>
|
|
1501
|
+
</section>
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
// ── The shop ─────────────────────────────────────────────────────────────────
|
|
1506
|
+
|
|
1507
|
+
type ShopView = "products" | "product" | "cart" | "checkout";
|
|
1508
|
+
|
|
1509
|
+
function ShopFront({ start }: { start: ShopView }) {
|
|
1510
|
+
const cart = useCart(sampleCart);
|
|
1511
|
+
const [page, setPage] = React.useState<Page>(
|
|
1512
|
+
start === "product"
|
|
1513
|
+
? { name: "product", id: "bowl" }
|
|
1514
|
+
: start === "checkout"
|
|
1515
|
+
? { name: "checkout" }
|
|
1516
|
+
: { name: "products" },
|
|
1517
|
+
);
|
|
1518
|
+
const [cartOpen, setCartOpen] = React.useState(start === "cart");
|
|
1519
|
+
const count = countOf(cart.lines);
|
|
1520
|
+
const home = () => setPage({ name: "products" });
|
|
1521
|
+
|
|
1522
|
+
return (
|
|
1523
|
+
<div className="@container/shop flex w-full max-w-5xl flex-col gap-4">
|
|
1524
|
+
<ShopBar count={count} onHome={home} onOpenCart={() => setCartOpen(true)} />
|
|
1525
|
+
{/* Says what changed in the cart, for people who can't see the count on the button. */}
|
|
1526
|
+
<p aria-live="polite" className="sr-only">
|
|
1527
|
+
{count ? `Cart: ${pieces(count)}` : "Cart is empty"}
|
|
1528
|
+
</p>
|
|
1529
|
+
{page.name === "products" && (
|
|
1530
|
+
<ProductGrid onOpen={(id) => setPage({ name: "product", id, opened: true })} />
|
|
1531
|
+
)}
|
|
1532
|
+
{page.name === "product" && (
|
|
1533
|
+
<ProductDetail
|
|
1534
|
+
key={page.id}
|
|
1535
|
+
product={productById(page.id)}
|
|
1536
|
+
moveFocus={page.opened}
|
|
1537
|
+
onBack={home}
|
|
1538
|
+
onAdd={cart.add}
|
|
1539
|
+
onOpenCart={() => setCartOpen(true)}
|
|
1540
|
+
/>
|
|
1541
|
+
)}
|
|
1542
|
+
{page.name === "checkout" && (
|
|
1543
|
+
<Checkout cart={cart} onBack={home} onEditCart={() => setCartOpen(true)} />
|
|
1544
|
+
)}
|
|
1545
|
+
<CartDrawer
|
|
1546
|
+
cart={cart}
|
|
1547
|
+
open={cartOpen}
|
|
1548
|
+
onOpenChange={setCartOpen}
|
|
1549
|
+
onCheckout={() => {
|
|
1550
|
+
setCartOpen(false);
|
|
1551
|
+
setPage({ name: "checkout" });
|
|
1552
|
+
}}
|
|
1553
|
+
/>
|
|
1554
|
+
</div>
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/** The whole shop: the grid, a product, the cart drawer and checkout. `view` picks where it starts. */
|
|
1559
|
+
export function Shop({ view = "products" }: { view?: ShopView }) {
|
|
1560
|
+
return <ShopFront key={view} start={view} />;
|
|
1561
|
+
}
|
|
1562
|
+
```
|
|
1563
|
+
|
|
1564
|
+
A fictional ceramics studio, as an editorial shop: a grid of photos with the names in Licht and the prices in mono, a product page with a gallery, a cart drawer and a one-page checkout. All sample content — drawn studio pictures for photos, nothing sent, no payment. The View control opens the demo on a product, the cart or checkout.
|
|
1565
|
+
|
|
1566
|
+
## Usage
|
|
1567
|
+
|
|
1568
|
+
The grid is not a row of boxes. Each photo is the object, in a 20px frame; the name, price and one line sit on the page under it. Keep prices as integer cents and format once, at the edge, for the reader's locale.
|
|
1569
|
+
|
|
1570
|
+
```tsx
|
|
1571
|
+
import { AspectRatio, Tag, fromMinorUnits, useLocale } from "@zonsh/ui";
|
|
1572
|
+
|
|
1573
|
+
function usePrice(currency = "EUR") {
|
|
1574
|
+
const locale = useLocale() ?? "en-IE";
|
|
1575
|
+
const format = new Intl.NumberFormat(locale, { style: "currency", currency });
|
|
1576
|
+
return (cents: number) => format.format(Number(fromMinorUnits(cents, currency)));
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
function ProductTile({ product, onOpen }: { product: Product; onOpen: () => void }) {
|
|
1580
|
+
const price = usePrice();
|
|
1581
|
+
return (
|
|
1582
|
+
// The name is the one action, stretched over the item; the item shows its focus ring.
|
|
1583
|
+
<li className="relative flex flex-col gap-3.5 rounded-card outline-offset-[6px] has-[button:focus-visible]:outline-2 has-[button:focus-visible]:outline-(--control-focus)">
|
|
1584
|
+
<AspectRatio ratio={4 / 5} className="overflow-hidden rounded-card border border-border/60">
|
|
1585
|
+
<img src={product.photo} alt="" width={800} height={1000} className="size-full object-cover" />
|
|
1586
|
+
</AspectRatio>
|
|
1587
|
+
{product.tag && <Tag className="theme-light absolute start-3 top-3">{product.tag}</Tag>}
|
|
1588
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
1589
|
+
<h3 className="m-0 font-heading text-[22px] font-light">
|
|
1590
|
+
<button type="button" onClick={onOpen} className="text-start after:absolute after:inset-0 after:content-['']">
|
|
1591
|
+
{product.name}
|
|
1592
|
+
</button>
|
|
1593
|
+
</h3>
|
|
1594
|
+
<p className="m-0 font-mono text-[13px] tabular-nums">{price(product.price)}</p>
|
|
1595
|
+
</div>
|
|
1596
|
+
<p className="m-0 text-[13px] text-muted-foreground">{product.line}</p>
|
|
1597
|
+
</li>
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
<ul aria-label="Pieces" className="m-0 grid list-none grid-cols-2 gap-x-4 gap-y-10 p-0 @3xl:grid-cols-3 @3xl:gap-x-6 @3xl:gap-y-14">
|
|
1602
|
+
{products.map((p) => <ProductTile key={p.id} product={p} onOpen={() => open(p.id)} />)}
|
|
1603
|
+
</ul>;
|
|
1604
|
+
```
|
|
1605
|
+
|
|
1606
|
+
- `AspectRatio` in a `rounded-card` frame — one ratio for the whole shop, so names and prices line up.
|
|
1607
|
+
- The name in Licht (`font-heading`, weight 300), the price in Licht Mono with `tabular-nums`.
|
|
1608
|
+
- `fromMinorUnits` — exact cents to amount, no float rounding.
|
|
1609
|
+
|
|
1610
|
+
With routes, make the name a link (``<a href={`/shop/${p.slug}`}>``); the overlay works the same.
|
|
1611
|
+
|
|
1612
|
+
To adapt it, replace `products` and `photo()` with your catalogue and photo URLs, keep the delivery terms in one place (`DELIVERY_FEE`, `FREE_FROM`) so the product page, cart and checkout can't disagree, and hand over to your payment provider after "Place order".
|
|
1613
|
+
|
|
1614
|
+
### Product photos
|
|
1615
|
+
|
|
1616
|
+
- **One ratio** everywhere (4:5 or 1:1), cropped with `object-cover`: grid, gallery, cart lines and the order summary.
|
|
1617
|
+
- **The product on one plain ground**, the same light and angle for each view (front, from above, a close-up), no baked-in text. A `Tag` says "Few left".
|
|
1618
|
+
- **Photos keep their own light** in the dark theme: the demo steps them down with `dark:brightness-[.86]` instead of inverting anything, and tags over a photo take `theme-light`.
|
|
1619
|
+
- **Alt text says what is in it** ("Breakfast bowl in Slate, from above"); `alt=""` in the grid, where the name beside it says it.
|
|
1620
|
+
- **Lazy-load** below the first row, with `width` and `height`.
|
|
1621
|
+
|
|
1622
|
+
The demo draws its pictures as SVG — a piece in its glaze on grey paper, a contact shadow, a little grain — and uses them as ordinary `<img>` URLs, so swapping in photos changes nothing else.
|
|
1623
|
+
|
|
1624
|
+
## What it shows
|
|
1625
|
+
|
|
1626
|
+
- **The grid**: a terms line ("Sample shop · Free delivery from €80.00"), the shop's `Wordmark` and a secondary cart button with the count; a `TwoTone` headline and one line; a category `ToggleGroup` with a live count; then the photos. Hovering a photo shows the piece from above.
|
|
1627
|
+
- **The product page**: a `Breadcrumb`; the gallery — a large photo that opens the `Lightbox`, thumbnails that choose it, sticky beside the text from the two-column width; the code in mono, the name in Licht, the price; glaze and size as `ToggleGroup`s, each glaze with its swatch; quantity; "Add to cart" with the price for that quantity; delivery, pickup and returns as three lines with icons; details, care and terms in an `Accordion`.
|
|
1628
|
+
- **The cart drawer**: a `Progress` track to free delivery, each line with its photo, choices, `NumberField` quantity, Remove and its price, and the totals and "Go to checkout" pinned to the bottom of the panel.
|
|
1629
|
+
- **Checkout**: one page, numbered parts — contact, delivery or pickup, the address only for delivery, payment as the provider's step — with the order on a square `surface-container` beside it (first, on a phone). On a phone the total and "Place order" stay at the bottom of the screen. "Place order" keeps its width under the spinner; the confirmation replaces the page, says what happens next, keeps the order and empties the cart.
|
|
1630
|
+
|
|
1631
|
+
## When to use
|
|
1632
|
+
|
|
1633
|
+
- A small shop: up to a few dozen products with a couple of choices each — a studio, a roastery, a bakery.
|
|
1634
|
+
- A product beside its story: the grid as a section of a marketing page.
|
|
1635
|
+
- Hundreds of products: add a `FilterBar` and pagination. Plans: the `Pricing` block.
|
|
1636
|
+
- Payment is your provider's: hand over to its form or redirect after the order step; don't build card fields.
|
|
1637
|
+
|
|
1638
|
+
## Examples
|
|
1639
|
+
|
|
1640
|
+
### Product page
|
|
1641
|
+
|
|
1642
|
+
The gallery follows the chosen glaze; the large photo opens the Lightbox, the thumbnails choose it. Glaze and size are `ToggleGroup`s (a size that costs more says so in mono), quantity a `NumberField`, then "Add to cart" — the one primary, with the price for that quantity. Adding is announced in a polite live region with a link to the cart.
|
|
1643
|
+
|
|
1644
|
+
```tsx
|
|
1645
|
+
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, AspectRatio, Breadcrumb, Button, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, Empty, EmptyActions, EmptyDescription, EmptyMedia, EmptyTitle, Eyebrow, Field, FieldError, FieldItem, FieldLabel, Fieldset, FieldsetLegend, Form, Heading, Index, Input, Label, Lightbox, LightboxTrigger, Mono, NumberField, NumberRoll, Progress, Radio, RadioGroup, Tag, Text, ToggleGroup, ToggleGroupItem, TwoTone, fromMinorUnits, useLocale } from "@zonsh/ui";
|
|
1646
|
+
import { Wordmark } from "@zonsh/ui/brand";
|
|
1647
|
+
import { CircleCheckIcon, MaximizeIcon, RotateCcwIcon, ShoppingBagIcon, StoreIcon, TruckIcon } from "lucide-react";
|
|
1648
|
+
import * as React from "react";
|
|
1649
|
+
|
|
1650
|
+
// CURRENCY, DELIVERY_FEE, FREE_FROM, Shape, Category, categories, glazes, Product, products, productById, Line, lineKey, unitPrice, variantLabel, subtotalOf, countOf, deliveryFee, pieces, usePrice, Amount, Pieces, sampleCart, View, views, mix, ellipse, Form, forms, frameGround, photoTone, scene, photoCache, photo, viewLabel, Swatch, Page, useCart, Cart, crumb, ShopBar, ProductTile, ProductGrid, Gallery, PickerLabel, ProductDetail, Totals, Thumb, CartLines, FreeDelivery, CartDrawer, useFakeRequest, Method, OrderSummary, MethodOption, stepTitle, Step, Confirmation, Checkout, ShopView, ShopFront: as in the first example on this page that uses them.
|
|
1651
|
+
|
|
1652
|
+
/** The product page on its own: the gallery, glaze and size, quantity and the one primary. */
|
|
1653
|
+
export function ProductPage() {
|
|
1654
|
+
return <ShopFront start="product" />;
|
|
1655
|
+
}
|
|
1656
|
+
```
|
|
1657
|
+
|
|
1658
|
+
### Checkout
|
|
1659
|
+
|
|
1660
|
+
Delivery or pickup as rows of a `RadioGroup` with costs; the address appears only for delivery, and the order beside the form follows the choice. The phone keeps the total and the button in a bar at the bottom.
|
|
1661
|
+
|
|
1662
|
+
```tsx
|
|
1663
|
+
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, AspectRatio, Breadcrumb, Button, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, Empty, EmptyActions, EmptyDescription, EmptyMedia, EmptyTitle, Eyebrow, Field, FieldError, FieldItem, FieldLabel, Fieldset, FieldsetLegend, Form, Heading, Index, Input, Label, Lightbox, LightboxTrigger, Mono, NumberField, NumberRoll, Progress, Radio, RadioGroup, Tag, Text, ToggleGroup, ToggleGroupItem, TwoTone, fromMinorUnits, useLocale } from "@zonsh/ui";
|
|
1664
|
+
import { Wordmark } from "@zonsh/ui/brand";
|
|
1665
|
+
import { CircleCheckIcon, MaximizeIcon, RotateCcwIcon, ShoppingBagIcon, StoreIcon, TruckIcon } from "lucide-react";
|
|
1666
|
+
import * as React from "react";
|
|
1667
|
+
|
|
1668
|
+
// CURRENCY, DELIVERY_FEE, FREE_FROM, Shape, Category, categories, glazes, Product, products, productById, Line, lineKey, unitPrice, variantLabel, subtotalOf, countOf, deliveryFee, pieces, usePrice, Amount, Pieces, sampleCart, View, views, mix, ellipse, Form, forms, frameGround, photoTone, scene, photoCache, photo, viewLabel, Swatch, Page, useCart, Cart, crumb, ShopBar, ProductTile, ProductGrid, Gallery, PickerLabel, ProductDetail, Totals, Thumb, CartLines, FreeDelivery, CartDrawer, useFakeRequest, Method, OrderSummary, MethodOption, stepTitle, Step, Confirmation, Checkout, ShopView, ShopFront: as in the first example on this page that uses them.
|
|
1669
|
+
|
|
1670
|
+
/** Checkout on its own: the order beside the form, delivery or pickup, and the address only for delivery. */
|
|
1671
|
+
export function CheckoutPage() {
|
|
1672
|
+
return <ShopFront start="checkout" />;
|
|
1673
|
+
}
|
|
1674
|
+
```
|
|
1675
|
+
|
|
1676
|
+
## The parts
|
|
1677
|
+
|
|
1678
|
+
| Part | Page | Job |
|
|
1679
|
+
| ----------------------------------------- | ------------ | ------------------------------------------------------------------------- |
|
|
1680
|
+
| `AspectRatio` | Aspect Ratio | Every photo at one ratio: grid, gallery, cart lines, order summary |
|
|
1681
|
+
| `Lightbox`, `LightboxTrigger` | Lightbox | The product's photos, full screen, from the large one in the gallery |
|
|
1682
|
+
| `TwoTone`, `Eyebrow`, `Heading` | Typography | The grid's headline; the product's name and the checkout's title in Licht |
|
|
1683
|
+
| `Breadcrumb` | Breadcrumb | Where the product or checkout sits, with a way back |
|
|
1684
|
+
| `Tag` | Tag | Stock and making notes: "Few left" (warning), "Made to order" |
|
|
1685
|
+
| `ToggleGroup` | Toggle Group | Category on the grid; glaze (with swatches) and size on the product |
|
|
1686
|
+
| `NumberField` | Number Field | The quantity, on the product page and on each cart line |
|
|
1687
|
+
| `Accordion` | Accordion | Details, care, delivery and returns, under the button |
|
|
1688
|
+
| `Drawer` | Drawer | The cart, from the side, over whatever page the reader is on |
|
|
1689
|
+
| `Progress` | Progress | How far the cart is from free delivery |
|
|
1690
|
+
| `Empty` | Empty | The empty cart, with a way back to the products |
|
|
1691
|
+
| `Form`, `Field`, `Fieldset`, `RadioGroup` | Form, Field | Checkout: contact, delivery or pickup, the address only for delivery |
|
|
1692
|
+
| `Index` | Typography | The numbers of the checkout's parts and of the confirmation's next steps |
|
|
1693
|
+
| `Button` | Button | The cart button with its count; "Place order", `loading` while pending |
|
|
1694
|
+
| `fromMinorUnits` | Money Input | Cents to the exact amount string, for `Intl.NumberFormat` |
|
|
1695
|
+
|
|
1696
|
+
## Brand rules
|
|
1697
|
+
|
|
1698
|
+
- **Do** keep one primary per view: "Add to cart", "Go to checkout", "Place order". The cart button, the way back and "Keep browsing" are secondary or ghost.
|
|
1699
|
+
- **Do** set names in Licht, and prices, codes and counts in tabular Licht Mono; compute in minor units, and show delivery costs early.
|
|
1700
|
+
- **Do** let the photos be the objects. The grid, the terms and the checkout sit under hairlines; the order summary is a square region, not a card.
|
|
1701
|
+
- **Do** mark sample content as sample.
|
|
1702
|
+
- **Don't** invent reviews, ratings, sales counts, quotes or "was" prices.
|
|
1703
|
+
- **Don't** fake scarcity: "Few left" only when true, no countdowns.
|
|
1704
|
+
- **Don't** colour prices, the count or "Add to cart". Colour names a glaze in its swatch (always beside its name), a low-stock warning and a placed order.
|
|
1705
|
+
- **Don't** build card-number fields.
|
|
1706
|
+
|
|
1707
|
+
## Accessibility
|
|
1708
|
+
|
|
1709
|
+
- The grid is a list named "Pieces"; each item's name is a button (or link) stretched over it — one target, one name — and the item shows the focus ring. The category is a named toggle group; the count after it is a polite live region.
|
|
1710
|
+
- Photos take alt text that says what is in them; in the grid, where the name is beside the photo, `alt=""`. The swatches are hidden; the glaze is read by name.
|
|
1711
|
+
- The cart button is named with its count ("Cart 3 pieces", "Cart empty"), with the words the badge can't show in `sr-only` text rather than an `aria-label`, so the name starts with what is visible; a polite live region says when it changes.
|
|
1712
|
+
- Opening a product moves focus to it. The large photo is a button named by its alt text that opens the viewer and returns focus to it; each thumbnail is named for its view ("Show from above") and pressed when shown.
|
|
1713
|
+
- Glaze and size are toggle groups named by their labels; arrow keys move between choices.
|
|
1714
|
+
- The cart drawer takes focus and returns it to the cart button. The free-delivery track reads as "€62.00 of €80.00 for free delivery". Each line's quantity field and remove button are named for the line ("Quantity of Tea cup", "Remove Tea cup, Celadon").
|
|
1715
|
+
- Checkout: each part is a fieldset with a legend; delivery or pickup is a radio group whose rows read their cost. Errors are text under each field; the first one takes focus. The confirmation takes focus.
|