@zonsh/ui 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +639 -0
- package/README.md +49 -21
- package/dist/brand.d.ts +3 -0
- package/dist/brand.js +7 -0
- package/dist/components/_breadcrumb-more.d.ts +6 -0
- package/dist/components/_breadcrumb-more.js +5 -0
- package/dist/components/_drawing-svg.d.ts +11 -0
- package/dist/components/_drawing-svg.js +30 -0
- package/dist/components/_media.d.ts +159 -0
- package/dist/components/_media.js +266 -0
- package/dist/components/_overlay.d.ts +8 -5
- package/dist/components/_overlay.js +11 -6
- package/dist/components/_scheduler-calendar.d.ts +71 -0
- package/dist/components/_scheduler-calendar.js +940 -0
- package/dist/components/_scheduler-editor.d.ts +29 -0
- package/dist/components/_scheduler-editor.js +111 -0
- package/dist/components/_scheduler-menu.d.ts +16 -0
- package/dist/components/_scheduler-menu.js +18 -0
- package/dist/components/_scheduler-parts.d.ts +164 -0
- package/dist/components/_scheduler-parts.js +327 -0
- package/dist/components/_suggest-list.d.ts +142 -0
- package/dist/components/_suggest-list.js +159 -0
- package/dist/components/_toolbar-more.d.ts +24 -0
- package/dist/components/_toolbar-more.js +25 -0
- package/dist/components/accordion.d.ts +1 -1
- package/dist/components/accordion.js +7 -7
- 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/ascii-field.js +2 -1
- 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 +389 -24
- 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 +64 -8
- 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 +38 -1
- package/dist/components/chart.js +27 -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 +4 -4
- 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 +37 -12
- 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 +77 -16
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/copy-button.js +8 -6
- 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 +190 -28
- package/dist/components/illustration.js +53 -31
- package/dist/components/input-group.d.ts +6 -11
- package/dist/components/input-group.js +21 -19
- 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/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +76 -9
- package/dist/components/lightbox.js +354 -48
- 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 +153 -31
- package/dist/components/message.d.ts +62 -11
- package/dist/components/message.js +51 -14
- 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 -10
- package/dist/components/number-field.d.ts +2 -9
- package/dist/components/number-field.js +90 -26
- 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 +35 -17
- 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 +8 -3
- 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 +4 -3
- package/dist/components/response.js +39 -15
- 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 +90 -31
- package/dist/components/site-header.d.ts +18 -13
- package/dist/components/site-header.js +26 -9
- package/dist/components/skeleton.d.ts +18 -8
- package/dist/components/skeleton.js +23 -8
- package/dist/components/slider.js +2 -2
- package/dist/components/sortable.d.ts +55 -4
- package/dist/components/sortable.js +187 -94
- 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 +13 -7
- package/dist/components/table.js +124 -23
- package/dist/components/tabs.js +15 -8
- 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 +50 -7
- package/dist/components/theme.js +168 -12
- package/dist/components/time-field.d.ts +6 -10
- package/dist/components/time-field.js +19 -9
- 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 +17 -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 +8 -3
- package/dist/components/toolbar.d.ts +57 -4
- package/dist/components/toolbar.js +219 -16
- package/dist/components/tooltip.d.ts +5 -3
- package/dist/components/tooltip.js +14 -6
- package/dist/components/tour.d.ts +1 -1
- package/dist/components/tour.js +70 -24
- package/dist/components/tree.js +33 -10
- 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 +182 -225
- 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 +10 -4
- package/dist/lib/glide.js +14 -5
- 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 +4 -3
- package/dist/lib/table-fit.js +92 -25
- 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 +75 -77
- 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 -193
- package/dist/styles/material.css +177 -31
- package/dist/styles/parts/ai.css +20 -14
- package/dist/styles/parts/brand.css +2 -2
- package/dist/styles/parts/controls.css +51 -38
- package/dist/styles/parts/data.css +43 -11
- package/dist/styles/parts/editor.css +372 -0
- package/dist/styles/parts/feedback.css +75 -15
- 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 +237 -25
- package/dist/styles/parts/overlays.css +110 -8
- package/dist/styles/parts/pdf.css +15 -9
- package/dist/styles/pdf.css +3 -0
- package/dist/styles/prose.css +3 -0
- package/dist/styles/tokens.css +105 -15
- 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,3940 @@
|
|
|
1
|
+
# Theme editor
|
|
2
|
+
|
|
3
|
+
```tsx
|
|
4
|
+
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, Alert, AlertDescription, AlertTitle, Avatar, AvatarGroup, BottomNav, BottomNavItem, Button, ButtonGroup, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CodeBlock, Collapsible, CollapsiblePanel, CollapsibleTrigger, ColorPickerPanel, ColorSwatch, CopyButton, cn, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Empty, EmptyActions, EmptyDescription, EmptyMedia, EmptyTitle, Field, FieldDescription, FieldError, FieldLabel, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, ItemTitle, Kbd, KbdShortcut, Label, Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Meter, MoneyInput, NativeSelect, NativeSelectOption, NumberField, Pagination, Popover, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger, Progress, Radio, RadioGroup, ScrollArea, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Slider, Stat, StatGroup, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Tabs, TabsList, TabsPanel, TabsTab, Tag, Textarea, themeFromPreset, Toggle, Toolbar, ToolbarButton, ToolbarSeparator, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipTrigger, Breadcrumb, Rating, Stepper, Timeline, TimelineChange, TimelineComment, TimelineContent, TimelineItem, TimelineTime, TimelineTitle, type ThemeColor, type ThemePreset, type ThemeSettings, type ThemeShape } from "@zonsh/ui";
|
|
5
|
+
import { decodeThemePreset, encodeThemePreset, fixThemeContrast, formatThemeColor, normalizeThemePreset, parseThemeColor, THEME_CORNERS, THEME_HEIGHTS, THEME_SELECTORS, themeContrast, themeHeights, themePalette, themeShapeTokens, themeTokenGroups, zonThemePreset, type ThemeToken } from "@zonsh/ui/theme";
|
|
6
|
+
import { Calendar } from "@zonsh/ui/calendar";
|
|
7
|
+
import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@zonsh/ui/chart";
|
|
8
|
+
import { ArchiveIcon, CalendarPlusIcon, ChevronDownIcon, CircleAlertIcon, CircleCheckIcon, ClipboardPasteIcon, CoffeeIcon, CopyIcon, DownloadIcon, EllipsisIcon, FlameIcon, Flower2Icon, InboxIcon, InfoIcon, LayoutGridIcon, ListFilterIcon, ListIcon, LockIcon, LockOpenIcon, MailIcon, MoonIcon, OctagonXIcon, PackageIcon, CalendarDaysIcon as BottomNavClassesIcon, HouseIcon as BottomNavShopIcon, UserIcon as BottomNavAccountIcon, PencilIcon, PinIcon, PlusIcon, PrinterIcon, RotateCcwIcon, RulerDimensionLineIcon, SearchIcon, ShuffleIcon, SoupIcon, SunIcon, TriangleAlertIcon, TruckIcon, UserPlusIcon, UtensilsIcon, XIcon, GiftIcon, ImageIcon, MessageSquareIcon, SendIcon, UploadIcon } from "lucide-react";
|
|
9
|
+
import { Bar, BarChart, CartesianGrid, Cell, Pie, PieChart, XAxis, YAxis } from "recharts";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
|
|
12
|
+
type Mode = "light" | "dark";
|
|
13
|
+
|
|
14
|
+
type Format = "oklch" | "hex";
|
|
15
|
+
|
|
16
|
+
const specs = themeTokenGroups.flatMap((g) => g.tokens);
|
|
17
|
+
|
|
18
|
+
const clamp = (v: number, min = 0, max = 1) => Math.min(max, Math.max(min, v));
|
|
19
|
+
|
|
20
|
+
const round = (v: number, digits: number) => Number(v.toFixed(digits));
|
|
21
|
+
|
|
22
|
+
const wrap = (h: number) => ((Math.round(h) % 360) + 360) % 360;
|
|
23
|
+
|
|
24
|
+
/** A hue difference as a turn of −180° to 180°. */
|
|
25
|
+
const turn = (h: number) => ((((Math.round(h) + 180) % 360) + 360) % 360) - 180;
|
|
26
|
+
|
|
27
|
+
const pick = (min: number, max: number) => min + Math.random() * (max - min);
|
|
28
|
+
|
|
29
|
+
/* ── Seeds: the three colours a theme starts from ──────────────────────────── */
|
|
30
|
+
|
|
31
|
+
type Seed = "base" | "theme" | "accent";
|
|
32
|
+
|
|
33
|
+
const SEEDS: Seed[] = ["base", "theme", "accent"];
|
|
34
|
+
|
|
35
|
+
const seedInfo: Record<Seed, { label: string; lands: string }> = {
|
|
36
|
+
base: { label: "Background", lands: "Tints the greys: the page, surfaces, edges and text." },
|
|
37
|
+
theme: { label: "Accent", lands: "The primary button, checked controls and the focus outline." },
|
|
38
|
+
accent: { label: "Categories", lands: "The six category tones, in tags and charts." },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** zon's first tone (blue, 250°): an accent seed turns the tones so this one lands on its hue. */
|
|
42
|
+
const LEAD_TONE_HUE = 250;
|
|
43
|
+
|
|
44
|
+
/** The colour a seed stands for in these settings: what its picker shows when nothing was picked. */
|
|
45
|
+
function seedColor(seed: Seed, s: ThemeSettings): ThemeColor {
|
|
46
|
+
if (seed === "base") return { l: 0.62, c: Math.min(0.3, s.tint / 0.12), h: s.tintHue, a: 1 };
|
|
47
|
+
if (seed === "theme") return { l: 0.55, c: s.accent * 0.19, h: s.accentHue, a: 1 };
|
|
48
|
+
return { l: 0.6, c: 0.15 * s.vivid, h: wrap(LEAD_TONE_HUE + s.toneShift), a: 1 };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The settings a picked seed colour sets: its hue, and an amount of colour from its chroma. */
|
|
52
|
+
function fromSeed(seed: Seed, color: ThemeColor): Partial<ThemeSettings> {
|
|
53
|
+
if (seed === "base") return { tintHue: wrap(color.h), tint: round(Math.min(0.03, color.c * 0.12), 3) };
|
|
54
|
+
if (seed === "theme") return { accentHue: wrap(color.h), accent: round(clamp(color.c / 0.19), 2) };
|
|
55
|
+
return { toneShift: turn(color.h - LEAD_TONE_HUE), vivid: round(clamp(color.c / 0.15, 0.3, 1.5), 2) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Anchors = Partial<Record<Seed, ThemeColor>>;
|
|
59
|
+
|
|
60
|
+
/* ── Families: where Shuffle may take each seed ────────────────────────────── */
|
|
61
|
+
|
|
62
|
+
interface Family {
|
|
63
|
+
id: string;
|
|
64
|
+
label: string;
|
|
65
|
+
/** The hues it covers, in degrees; the end may pass 360. Missing: any hue (a neutral). */
|
|
66
|
+
hues?: readonly [number, number];
|
|
67
|
+
/** The greys' tint it draws for the base seed. */
|
|
68
|
+
tint?: readonly [number, number];
|
|
69
|
+
/** The primary's colour it draws for the theme seed. */
|
|
70
|
+
accent?: readonly [number, number];
|
|
71
|
+
/** The dot beside its name, when the family's hue alone doesn't show it (brown is a dark, quiet orange). */
|
|
72
|
+
dot?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ANY = "any";
|
|
76
|
+
|
|
77
|
+
/** Well-known colour families, by OKLCH hue. */
|
|
78
|
+
const HUED: Family[] = [
|
|
79
|
+
{ id: "red", label: "Red", hues: [18, 30] },
|
|
80
|
+
{ id: "coral", label: "Coral", hues: [30, 42] },
|
|
81
|
+
{ id: "orange", label: "Orange", hues: [44, 58] },
|
|
82
|
+
// Brown is orange made dark and quiet: the primary takes a low chroma, so it reads as wood,
|
|
83
|
+
// leather or coffee, and the greys a warm tint.
|
|
84
|
+
{
|
|
85
|
+
id: "brown",
|
|
86
|
+
label: "Brown",
|
|
87
|
+
hues: [48, 68],
|
|
88
|
+
accent: [0.26, 0.42],
|
|
89
|
+
tint: [0.012, 0.022],
|
|
90
|
+
dot: "oklch(0.48 0.07 58)",
|
|
91
|
+
},
|
|
92
|
+
{ id: "amber", label: "Amber", hues: [62, 78] },
|
|
93
|
+
{ id: "yellow", label: "Yellow", hues: [86, 102] },
|
|
94
|
+
{ id: "lime", label: "Lime", hues: [112, 128] },
|
|
95
|
+
{ id: "green", label: "Green", hues: [136, 156] },
|
|
96
|
+
{ id: "teal", label: "Teal", hues: [172, 190] },
|
|
97
|
+
{ id: "cyan", label: "Cyan", hues: [198, 218] },
|
|
98
|
+
{ id: "blue", label: "Blue", hues: [238, 258] },
|
|
99
|
+
{ id: "indigo", label: "Indigo", hues: [262, 278] },
|
|
100
|
+
{ id: "violet", label: "Violet", hues: [282, 298] },
|
|
101
|
+
{ id: "purple", label: "Purple", hues: [302, 318] },
|
|
102
|
+
{ id: "pink", label: "Pink", hues: [336, 352] },
|
|
103
|
+
{ id: "rose", label: "Rose", hues: [354, 376] },
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const GREYS: Family[] = [
|
|
107
|
+
{ id: "neutral", label: "Neutral", tint: [0, 0.002], accent: [0, 0.06] },
|
|
108
|
+
{ id: "stone", label: "Stone", hues: [55, 82], tint: [0.005, 0.014], accent: [0.08, 0.2] },
|
|
109
|
+
{ id: "slate", label: "Slate", hues: [235, 262], tint: [0.006, 0.018], accent: [0.1, 0.24] },
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The families each seed offers after Any. The greys only take a light tint, so a base in a
|
|
114
|
+
* colour family is a tinted grey; the accent turns the tones, which always span the circle, so
|
|
115
|
+
* it has no greys.
|
|
116
|
+
*/
|
|
117
|
+
const families: Record<Seed, Family[]> = {
|
|
118
|
+
base: [...GREYS, ...HUED.filter((f) => !["coral", "yellow", "lime", "cyan", "pink"].includes(f.id))],
|
|
119
|
+
theme: [GREYS[0]!, ...HUED],
|
|
120
|
+
accent: HUED.filter((f) => f.id !== "brown"),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type Families = Partial<Record<Seed, string>>;
|
|
124
|
+
|
|
125
|
+
const familyOf = (seed: Seed, id: string | undefined) => families[seed].find((f) => f.id === id);
|
|
126
|
+
|
|
127
|
+
const familyHue = (f: Family) => (f.hues ? wrap((f.hues[0] + f.hues[1]) / 2) : 0);
|
|
128
|
+
|
|
129
|
+
/** The dot beside a family's name. */
|
|
130
|
+
const familyDot = (seed: Seed, f: Family) =>
|
|
131
|
+
f.dot ?? `oklch(0.66 ${f.hues ? (f.tint && seed !== "accent" ? 0.05 : 0.16) : 0} ${familyHue(f)})`;
|
|
132
|
+
|
|
133
|
+
/** A new colour for one seed: inside its family, or anywhere for Any. */
|
|
134
|
+
function draw(seed: Seed, family: Family | undefined, s: ThemeSettings): Partial<ThemeSettings> {
|
|
135
|
+
const hue = family?.hues ? wrap(pick(family.hues[0], family.hues[1])) : wrap(pick(0, 360));
|
|
136
|
+
if (seed === "base") {
|
|
137
|
+
const [lo, hi] = family?.tint ?? (family ? [0.012, 0.03] : [0.006, 0.03]);
|
|
138
|
+
return { tintHue: hue, tint: round(pick(lo, hi), 3) };
|
|
139
|
+
}
|
|
140
|
+
if (seed === "theme") {
|
|
141
|
+
const [lo, hi] = family?.accent ?? (family ? [0.5, 1] : [0.35, 1]);
|
|
142
|
+
// With Any, the primary takes the greys' own hue half the time, anywhere on the circle otherwise.
|
|
143
|
+
const h = family || Math.random() >= 0.5 ? hue : s.tintHue;
|
|
144
|
+
return { accentHue: h, accent: round(pick(lo, hi), 2) };
|
|
145
|
+
}
|
|
146
|
+
return { toneShift: turn(hue - LEAD_TONE_HUE), vivid: round(family ? pick(0.85, 1.2) : pick(0.7, 1.3), 2) };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* New settings. A kept seed stays exactly as it is; the others draw a new colour from their
|
|
151
|
+
* family, or anywhere. The ground and the status hue always move.
|
|
152
|
+
*/
|
|
153
|
+
function shuffle(settings: ThemeSettings, kept: ThemePreset["seeds"], picked: Families): ThemeSettings {
|
|
154
|
+
const out = { ...zonThemePreset.settings };
|
|
155
|
+
for (const seed of SEEDS) {
|
|
156
|
+
const keys = seedKeys[seed];
|
|
157
|
+
if (kept[seed]) for (const key of keys) out[key] = settings[key];
|
|
158
|
+
else Object.assign(out, draw(seed, familyOf(seed, picked[seed]), out));
|
|
159
|
+
}
|
|
160
|
+
out.statusShift = Math.round(pick(-12, 12));
|
|
161
|
+
out.ground = round(pick(0, 1), 2);
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The generator settings each seed sets. */
|
|
166
|
+
const seedKeys: Record<Seed, (keyof ThemeSettings)[]> = {
|
|
167
|
+
base: ["tintHue", "tint"],
|
|
168
|
+
theme: ["accentHue", "accent"],
|
|
169
|
+
accent: ["toneShift", "vivid"],
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/** The colour picked for a seed while the settings are still the ones it set; otherwise its own. */
|
|
173
|
+
function shownSeed(seed: Seed, settings: ThemeSettings, anchor: ThemeColor | undefined) {
|
|
174
|
+
if (anchor) {
|
|
175
|
+
const set = normalizeThemePreset({ settings: { ...settings, ...fromSeed(seed, anchor) } }).settings;
|
|
176
|
+
if (seedKeys[seed].every((key) => set[key] === settings[key])) return anchor;
|
|
177
|
+
}
|
|
178
|
+
return seedColor(seed, settings);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* ── Export ───────────────────────────────────────────────────────────────── */
|
|
182
|
+
|
|
183
|
+
/** What the export carries: the code, a palette for each theme, the shape both share, and the
|
|
184
|
+
stylesheet and theme.json file that apply them (themeFromPreset). */
|
|
185
|
+
|
|
186
|
+
type ThemeValues = ReturnType<typeof themeFromPreset>;
|
|
187
|
+
|
|
188
|
+
function toPrompt(values: ThemeValues) {
|
|
189
|
+
return `This project uses @zonsh/ui, the zon design system. Keep its components, materials and rules as they are, and apply this theme instead of zon's own: colours for light and dark, and a shape — density and corners — for both.
|
|
190
|
+
|
|
191
|
+
The theme's preset code is \`${values.code}\`. If the installed @zonsh/ui exports \`themeFromPreset\`, \`themeFromPreset("${values.code}").css\` is the stylesheet for it; otherwise use the values below, which are the same theme.
|
|
192
|
+
|
|
193
|
+
Each key is a CSS custom property from zon's tokens.css. Put the "light" values on \`${THEME_SELECTORS.light}\`, the "dark" values on \`${THEME_SELECTORS.dark}\` and the "shape" values on \`${THEME_SELECTORS.shape}\`, in the app stylesheet after \`@import "@zonsh/ui/styles.css";\`. Any token not listed keeps zon's value. Never set a height, a padding or a radius on a component by hand: they come from these tokens (--density scales the components' heights, padding, gaps and type), so every control follows the theme.
|
|
194
|
+
|
|
195
|
+
Keep using the semantic tokens and utilities (bg-background, text-foreground, text-muted-foreground, material-primary, --success, --tone-blue …) rather than literal colours, so the theme reaches every component. Status colours keep their meaning; tones stay categories.
|
|
196
|
+
|
|
197
|
+
\`\`\`json
|
|
198
|
+
${values.json.trimEnd()}
|
|
199
|
+
\`\`\`
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The density's name for its default control height. */
|
|
204
|
+
function densityName(height: number): string {
|
|
205
|
+
return (
|
|
206
|
+
{ 30: "Dense", 34: "Compact", 38: "Default", 42: "Comfortable", 46: "Spacious" }[height] ?? `${height}px`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* ── State, kept in this browser between visits ───────────────────────────── */
|
|
211
|
+
|
|
212
|
+
interface Saved {
|
|
213
|
+
preset: ThemePreset;
|
|
214
|
+
/** The colour last picked by hand for a seed, shown while the settings are still the ones it set. */
|
|
215
|
+
anchors: Anchors;
|
|
216
|
+
/** The family each seed draws from on Shuffle; missing is Any. Editor state, not part of the code. */
|
|
217
|
+
families: Families;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const STORAGE_KEY = "zon-theme-editor";
|
|
221
|
+
|
|
222
|
+
const empty: Saved = { preset: zonThemePreset, anchors: {}, families: {} };
|
|
223
|
+
|
|
224
|
+
const isColor = (value: unknown): value is ThemeColor =>
|
|
225
|
+
typeof value === "object" &&
|
|
226
|
+
value !== null &&
|
|
227
|
+
(["l", "c", "h", "a"] as const).every((key) => Number.isFinite((value as Record<string, unknown>)[key]));
|
|
228
|
+
|
|
229
|
+
/** Saved state with only the anchors and families that are well formed. */
|
|
230
|
+
function clean(preset: ThemePreset, anchors: Anchors = {}, picked: Families = {}): Saved {
|
|
231
|
+
const a: Anchors = {};
|
|
232
|
+
const f: Families = {};
|
|
233
|
+
for (const seed of SEEDS) {
|
|
234
|
+
if (isColor(anchors[seed])) a[seed] = anchors[seed];
|
|
235
|
+
if (familyOf(seed, picked[seed])) f[seed] = picked[seed];
|
|
236
|
+
}
|
|
237
|
+
return { preset, anchors: a, families: f };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function load(): Saved {
|
|
241
|
+
try {
|
|
242
|
+
const raw = typeof localStorage === "undefined" ? null : localStorage.getItem(STORAGE_KEY);
|
|
243
|
+
if (!raw) return empty;
|
|
244
|
+
const saved = JSON.parse(raw) as Partial<Saved> & Partial<ThemePreset>;
|
|
245
|
+
// An earlier editor kept the settings, the pins and the shape at the top level, with the shape
|
|
246
|
+
// free rather than stepped: normalizing moves it onto the nearest steps.
|
|
247
|
+
return clean(normalizeThemePreset(saved.preset ?? saved), saved.anchors, saved.families);
|
|
248
|
+
} catch {
|
|
249
|
+
return empty;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* ── The block ────────────────────────────────────────────────────────────── */
|
|
254
|
+
|
|
255
|
+
/** The width at which the menu and the preview fit side by side (56rem). */
|
|
256
|
+
const WIDE = 896;
|
|
257
|
+
|
|
258
|
+
/** Whether the editor itself (not the window) is wide enough for two columns. */
|
|
259
|
+
function useWide(el: HTMLElement | null) {
|
|
260
|
+
const [wide, setWide] = React.useState(true);
|
|
261
|
+
React.useLayoutEffect(() => {
|
|
262
|
+
if (!el) return;
|
|
263
|
+
const measure = () => setWide(el.getBoundingClientRect().width >= WIDE);
|
|
264
|
+
measure();
|
|
265
|
+
const observer = new ResizeObserver(measure);
|
|
266
|
+
observer.observe(el);
|
|
267
|
+
return () => observer.disconnect();
|
|
268
|
+
}, [el]);
|
|
269
|
+
return wide;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** How often, at most, a drag restyles the preview: often enough to watch, rarely enough to stay smooth. */
|
|
273
|
+
const PREVIEW_INTERVAL = 80;
|
|
274
|
+
|
|
275
|
+
interface ThemeEditorProps {
|
|
276
|
+
/**
|
|
277
|
+
* The create command for a new app with this theme, in the Use this theme dialog. The docs pass
|
|
278
|
+
* their package-manager command here; without it, a plain `pnpm create` line shows.
|
|
279
|
+
*/
|
|
280
|
+
createCommand?: (code: string) => React.ReactNode;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** zon's own theme as a code: the editor is back at zon when it shows this. */
|
|
284
|
+
const ZON_CODE = encodeThemePreset(zonThemePreset);
|
|
285
|
+
|
|
286
|
+
/** Text colours that read below their ratio on the ground they sit on. */
|
|
287
|
+
function countFailing(palette: Record<string, ThemeColor>) {
|
|
288
|
+
return specs.filter((s) => {
|
|
289
|
+
const color = palette[s.name];
|
|
290
|
+
const ground = s.on && palette[s.on.token];
|
|
291
|
+
return s.on && color && ground && themeContrast(color, ground) < s.on.min;
|
|
292
|
+
}).length;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** The title, the theme being edited and the way back to zon's own. */
|
|
296
|
+
const MenuHeader = React.memo(function MenuHeader({
|
|
297
|
+
isZon,
|
|
298
|
+
mode,
|
|
299
|
+
onMode,
|
|
300
|
+
onReset,
|
|
301
|
+
}: {
|
|
302
|
+
isZon: boolean;
|
|
303
|
+
mode: Mode;
|
|
304
|
+
onMode: (mode: Mode) => void;
|
|
305
|
+
onReset: () => void;
|
|
306
|
+
}) {
|
|
307
|
+
return (
|
|
308
|
+
<header className="flex flex-col gap-3 border-b border-border px-4 pt-4 pb-3">
|
|
309
|
+
<div className="flex items-center gap-2">
|
|
310
|
+
<h2 className="me-auto font-heading text-xl font-light">Theme editor</h2>
|
|
311
|
+
<Button size="sm" variant="ghost" onClick={onReset} disabled={isZon}>
|
|
312
|
+
<RotateCcwIcon />
|
|
313
|
+
Back to zon
|
|
314
|
+
</Button>
|
|
315
|
+
</div>
|
|
316
|
+
<ToggleGroup
|
|
317
|
+
aria-label="Theme to edit"
|
|
318
|
+
value={[mode]}
|
|
319
|
+
onValueChange={(v: string[]) => v[0] && onMode(v[0] as Mode)}
|
|
320
|
+
className="w-full *:flex-1"
|
|
321
|
+
>
|
|
322
|
+
<ToggleGroupItem value="light" icon={<SunIcon />}>
|
|
323
|
+
Light
|
|
324
|
+
</ToggleGroupItem>
|
|
325
|
+
<ToggleGroupItem value="dark" icon={<MoonIcon />}>
|
|
326
|
+
Dark
|
|
327
|
+
</ToggleGroupItem>
|
|
328
|
+
</ToggleGroup>
|
|
329
|
+
</header>
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
/** The code, opening one, shuffling and using the theme: what you leave the editor with. */
|
|
334
|
+
function MenuFooter({
|
|
335
|
+
code,
|
|
336
|
+
pins,
|
|
337
|
+
values,
|
|
338
|
+
onLoad,
|
|
339
|
+
onShuffle,
|
|
340
|
+
onlyChanges,
|
|
341
|
+
onOnlyChanges,
|
|
342
|
+
format,
|
|
343
|
+
onFormat,
|
|
344
|
+
createCommand,
|
|
345
|
+
}: {
|
|
346
|
+
createCommand?: (code: string) => React.ReactNode;
|
|
347
|
+
code: string;
|
|
348
|
+
pins: number;
|
|
349
|
+
values: ThemeValues;
|
|
350
|
+
onLoad: (preset: ThemePreset) => void;
|
|
351
|
+
onShuffle: () => void;
|
|
352
|
+
onlyChanges: boolean;
|
|
353
|
+
onOnlyChanges: (value: boolean) => void;
|
|
354
|
+
format: Format;
|
|
355
|
+
onFormat: (format: Format) => void;
|
|
356
|
+
}) {
|
|
357
|
+
return (
|
|
358
|
+
<div className="flex flex-col gap-3 border-t border-border p-4">
|
|
359
|
+
<PresetCode code={code} />
|
|
360
|
+
{/* Side by side where both labels fit, else one under the other: "Open preset" is never cut. */}
|
|
361
|
+
<div className="flex flex-wrap gap-2 *:flex-auto">
|
|
362
|
+
<OpenPreset code={code} onLoad={onLoad} />
|
|
363
|
+
<Button variant="secondary" onClick={onShuffle}>
|
|
364
|
+
<ShuffleIcon />
|
|
365
|
+
Shuffle
|
|
366
|
+
</Button>
|
|
367
|
+
<UseThemeDialog
|
|
368
|
+
values={values}
|
|
369
|
+
pins={pins}
|
|
370
|
+
onlyChanges={onlyChanges}
|
|
371
|
+
onOnlyChanges={onOnlyChanges}
|
|
372
|
+
format={format}
|
|
373
|
+
onFormat={onFormat}
|
|
374
|
+
createCommand={createCommand}
|
|
375
|
+
/>
|
|
376
|
+
</div>
|
|
377
|
+
</div>
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** The one line an app needs for a theme. */
|
|
382
|
+
const providerLine = (code: string) => `<ThemeProvider preset="${code}">`;
|
|
383
|
+
|
|
384
|
+
/** One way to use the theme: what it is and when, then the exact text to copy. */
|
|
385
|
+
function UseOption({
|
|
386
|
+
index,
|
|
387
|
+
title,
|
|
388
|
+
copy,
|
|
389
|
+
children,
|
|
390
|
+
code,
|
|
391
|
+
language,
|
|
392
|
+
filename,
|
|
393
|
+
wrap,
|
|
394
|
+
tall,
|
|
395
|
+
custom,
|
|
396
|
+
}: {
|
|
397
|
+
index: number;
|
|
398
|
+
title: string;
|
|
399
|
+
/** The copy button's name. */
|
|
400
|
+
copy: string;
|
|
401
|
+
children: React.ReactNode;
|
|
402
|
+
code: string;
|
|
403
|
+
language: string;
|
|
404
|
+
filename?: string;
|
|
405
|
+
wrap?: boolean;
|
|
406
|
+
/** A long text, shown in a box that scrolls. */
|
|
407
|
+
tall?: boolean;
|
|
408
|
+
/** Shown instead of the code block, when the host has its own. */
|
|
409
|
+
custom?: React.ReactNode;
|
|
410
|
+
}) {
|
|
411
|
+
return (
|
|
412
|
+
<section aria-label={title} className="flex min-w-0 flex-col gap-2 border-t border-border pt-4">
|
|
413
|
+
<h3 className="flex items-baseline gap-2 text-sm font-medium text-foreground">
|
|
414
|
+
<span className="font-mono text-xs text-muted-foreground tabular-nums">
|
|
415
|
+
{String(index).padStart(2, "0")}
|
|
416
|
+
</span>
|
|
417
|
+
{title}
|
|
418
|
+
</h3>
|
|
419
|
+
<p className="text-sm text-pretty text-muted-foreground @2xl/use:flex-1">{children}</p>
|
|
420
|
+
{custom ?? (
|
|
421
|
+
<CodeBlock
|
|
422
|
+
language={language}
|
|
423
|
+
filename={filename}
|
|
424
|
+
copyable
|
|
425
|
+
labels={{ copy }}
|
|
426
|
+
code={code}
|
|
427
|
+
wrap={wrap}
|
|
428
|
+
className={tall ? "max-h-64" : undefined}
|
|
429
|
+
/>
|
|
430
|
+
)}
|
|
431
|
+
</section>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Three ways side by side on a wide dialog, two then one across, and one under another on a
|
|
437
|
+
* phone; the dialog's own width decides, not the window's.
|
|
438
|
+
*/
|
|
439
|
+
const useRow =
|
|
440
|
+
"grid gap-x-6 gap-y-5 @2xl/use:grid-cols-2 @2xl/use:[&>:last-child]:col-span-2 @5xl/use:grid-cols-3 @5xl/use:[&>:last-child]:col-span-1";
|
|
441
|
+
|
|
442
|
+
function UseThemeDialog({
|
|
443
|
+
values,
|
|
444
|
+
pins,
|
|
445
|
+
onlyChanges,
|
|
446
|
+
onOnlyChanges,
|
|
447
|
+
format,
|
|
448
|
+
onFormat,
|
|
449
|
+
createCommand,
|
|
450
|
+
}: {
|
|
451
|
+
createCommand?: (code: string) => React.ReactNode;
|
|
452
|
+
values: ThemeValues;
|
|
453
|
+
pins: number;
|
|
454
|
+
onlyChanges: boolean;
|
|
455
|
+
onOnlyChanges: (value: boolean) => void;
|
|
456
|
+
format: Format;
|
|
457
|
+
onFormat: (format: Format) => void;
|
|
458
|
+
}) {
|
|
459
|
+
const code = values.code;
|
|
460
|
+
return (
|
|
461
|
+
<Dialog>
|
|
462
|
+
<DialogTrigger render={<Button className="basis-full" />}>
|
|
463
|
+
<DownloadIcon />
|
|
464
|
+
Use this theme
|
|
465
|
+
</DialogTrigger>
|
|
466
|
+
<DialogContent size="xl">
|
|
467
|
+
<DialogHeader>
|
|
468
|
+
<DialogTitle>Use this theme</DialogTitle>
|
|
469
|
+
<DialogDescription>
|
|
470
|
+
The preset code changes as you edit, and each way below carries the theme as it is now. Pick the
|
|
471
|
+
one that fits where it goes.
|
|
472
|
+
</DialogDescription>
|
|
473
|
+
</DialogHeader>
|
|
474
|
+
<DialogBody className="@container/use flex flex-col gap-6">
|
|
475
|
+
<div className={useRow}>
|
|
476
|
+
<UseOption index={1} title="Preset code" copy="Copy preset code" code={code} language="text">
|
|
477
|
+
The whole theme in {code.length} letters and digits
|
|
478
|
+
{pins > 0 && `, 8 of them for each of the ${pins} colours pinned by hand`}. Keep it to come back
|
|
479
|
+
to the theme, or paste it into Open preset.
|
|
480
|
+
</UseOption>
|
|
481
|
+
<UseOption
|
|
482
|
+
index={2}
|
|
483
|
+
title="In a React app"
|
|
484
|
+
copy="Copy provider code"
|
|
485
|
+
code={`import { ThemeProvider } from "@zonsh/ui";\n\n${providerLine(code)}\n <App />\n</ThemeProvider>`}
|
|
486
|
+
language="tsx"
|
|
487
|
+
filename="app.tsx"
|
|
488
|
+
>
|
|
489
|
+
For an app that already uses @zonsh/ui: wrap it in the provider and every component takes the
|
|
490
|
+
theme.
|
|
491
|
+
</UseOption>
|
|
492
|
+
{/* The docs fill `createCommand` with their package-manager command; a plain pnpm line otherwise. */}
|
|
493
|
+
<UseOption
|
|
494
|
+
index={3}
|
|
495
|
+
title="Start a new app"
|
|
496
|
+
copy="Copy create command"
|
|
497
|
+
custom={createCommand?.(code)}
|
|
498
|
+
code={`pnpm create zon@latest my-app --preset ${code}`}
|
|
499
|
+
language="bash"
|
|
500
|
+
>
|
|
501
|
+
Starts a new project with @zonsh/ui installed and this theme already set.
|
|
502
|
+
</UseOption>
|
|
503
|
+
</div>
|
|
504
|
+
<div className="flex flex-wrap items-center gap-x-6 gap-y-3 border-t border-border pt-4">
|
|
505
|
+
<span className="text-sm text-muted-foreground">For the JSON, CSS and prompt below:</span>
|
|
506
|
+
<Label>
|
|
507
|
+
<Switch checked={onlyChanges} onCheckedChange={onOnlyChanges} />
|
|
508
|
+
Only what changed
|
|
509
|
+
</Label>
|
|
510
|
+
<ToggleGroup
|
|
511
|
+
aria-label="Colour format"
|
|
512
|
+
value={[format]}
|
|
513
|
+
onValueChange={(v: string[]) => v[0] && onFormat(v[0] as Format)}
|
|
514
|
+
>
|
|
515
|
+
<ToggleGroupItem value="oklch">OKLCH</ToggleGroupItem>
|
|
516
|
+
<ToggleGroupItem value="hex">Hex</ToggleGroupItem>
|
|
517
|
+
</ToggleGroup>
|
|
518
|
+
</div>
|
|
519
|
+
<div className={useRow}>
|
|
520
|
+
<UseOption
|
|
521
|
+
index={4}
|
|
522
|
+
title="JSON"
|
|
523
|
+
copy="Copy JSON"
|
|
524
|
+
code={values.json}
|
|
525
|
+
language="json"
|
|
526
|
+
filename="theme.json"
|
|
527
|
+
tall
|
|
528
|
+
>
|
|
529
|
+
theme.json: commit it and give it to the provider (import theme from "./theme.json"). Written
|
|
530
|
+
the same way every time, one token to a line, so a change to the theme reviews as the tokens
|
|
531
|
+
that changed.
|
|
532
|
+
</UseOption>
|
|
533
|
+
<UseOption
|
|
534
|
+
index={5}
|
|
535
|
+
title="CSS"
|
|
536
|
+
copy="Copy CSS"
|
|
537
|
+
code={values.css}
|
|
538
|
+
language="css"
|
|
539
|
+
filename="theme.css"
|
|
540
|
+
tall
|
|
541
|
+
>
|
|
542
|
+
For a stylesheet without the provider, or a server-rendered first paint: paste it after
|
|
543
|
+
@zonsh/ui/styles.css. Tokens it leaves out keep zon's values.
|
|
544
|
+
</UseOption>
|
|
545
|
+
<UseOption
|
|
546
|
+
index={6}
|
|
547
|
+
title="Prompt for an AI"
|
|
548
|
+
copy="Copy prompt"
|
|
549
|
+
code={toPrompt(values)}
|
|
550
|
+
language="markdown"
|
|
551
|
+
filename="prompt.md"
|
|
552
|
+
wrap
|
|
553
|
+
tall
|
|
554
|
+
>
|
|
555
|
+
Hand it to a coding assistant working in your project: it says where each value goes and what to
|
|
556
|
+
leave alone.
|
|
557
|
+
</UseOption>
|
|
558
|
+
</div>
|
|
559
|
+
</DialogBody>
|
|
560
|
+
<DialogFooter>
|
|
561
|
+
<DialogClose render={<Button variant="secondary" />}>Done</DialogClose>
|
|
562
|
+
</DialogFooter>
|
|
563
|
+
</DialogContent>
|
|
564
|
+
</Dialog>
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/* ── The menu ─────────────────────────────────────────────────────────────── */
|
|
569
|
+
|
|
570
|
+
function Section({
|
|
571
|
+
title,
|
|
572
|
+
children,
|
|
573
|
+
rule = true,
|
|
574
|
+
className,
|
|
575
|
+
}: {
|
|
576
|
+
title: string;
|
|
577
|
+
children: React.ReactNode;
|
|
578
|
+
/** A hairline above it, between it and the section before. */
|
|
579
|
+
rule?: boolean;
|
|
580
|
+
className?: string;
|
|
581
|
+
}) {
|
|
582
|
+
return (
|
|
583
|
+
<section
|
|
584
|
+
aria-label={title}
|
|
585
|
+
className={cn("flex flex-col gap-4 px-4 pt-5 pb-6", rule && "hairline", className)}
|
|
586
|
+
>
|
|
587
|
+
<h3 className="eyebrow">{title}</h3>
|
|
588
|
+
{children}
|
|
589
|
+
</section>
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** A value a row can scrub through: dragged sideways, or stepped with the arrow keys. */
|
|
594
|
+
interface Scrub {
|
|
595
|
+
steps: readonly number[];
|
|
596
|
+
value: number;
|
|
597
|
+
onChange: (value: number) => void;
|
|
598
|
+
/** The value in words, announced as it changes. */
|
|
599
|
+
say: (value: number) => string;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** How far the pointer moves before a press becomes a scrub, so a plain click still opens the row. */
|
|
603
|
+
const SCRUB_THRESHOLD = 4;
|
|
604
|
+
|
|
605
|
+
/** How far the pointer moves for each step. */
|
|
606
|
+
const SCRUB_STEP = 24;
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Scrubbing on a row, as on a label in a design app: press and drag sideways and the value steps
|
|
610
|
+
* with the pointer; the arrow keys step it too. A press that moves less than the threshold stays a
|
|
611
|
+
* click.
|
|
612
|
+
*/
|
|
613
|
+
function useScrub(scrub: Scrub | undefined) {
|
|
614
|
+
const latest = React.useRef(scrub);
|
|
615
|
+
latest.current = scrub;
|
|
616
|
+
const drag = React.useRef<{ id: number; x: number; index: number; moved: boolean } | null>(null);
|
|
617
|
+
const swallowClick = React.useRef(false);
|
|
618
|
+
const [scrubbing, setScrubbing] = React.useState(false);
|
|
619
|
+
const [said, setSaid] = React.useState("");
|
|
620
|
+
|
|
621
|
+
const stepTo = (index: number) => {
|
|
622
|
+
const s = latest.current;
|
|
623
|
+
if (!s) return;
|
|
624
|
+
const next = s.steps[Math.min(s.steps.length - 1, Math.max(0, index))]!;
|
|
625
|
+
if (next === s.value) return;
|
|
626
|
+
s.onChange(next);
|
|
627
|
+
setSaid(s.say(next));
|
|
628
|
+
};
|
|
629
|
+
const indexOf = () => {
|
|
630
|
+
const s = latest.current!;
|
|
631
|
+
const i = s.steps.indexOf(s.value);
|
|
632
|
+
return i < 0 ? 0 : i;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
if (!scrub) return { scrubbing: false, said: "", props: {} };
|
|
636
|
+
const props: React.HTMLAttributes<HTMLElement> = {
|
|
637
|
+
onPointerDown(event) {
|
|
638
|
+
if (event.button !== 0) return;
|
|
639
|
+
drag.current = { id: event.pointerId, x: event.clientX, index: indexOf(), moved: false };
|
|
640
|
+
},
|
|
641
|
+
onPointerMove(event) {
|
|
642
|
+
const d = drag.current;
|
|
643
|
+
if (!d || d.id !== event.pointerId) return;
|
|
644
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
645
|
+
const dx = (event.clientX - d.x) * (rtl ? -1 : 1);
|
|
646
|
+
if (!d.moved) {
|
|
647
|
+
if (Math.abs(dx) < SCRUB_THRESHOLD) return;
|
|
648
|
+
d.moved = true;
|
|
649
|
+
d.x += Math.sign(dx) * SCRUB_THRESHOLD;
|
|
650
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
651
|
+
setScrubbing(true);
|
|
652
|
+
}
|
|
653
|
+
stepTo(d.index + Math.trunc(((event.clientX - d.x) * (rtl ? -1 : 1)) / SCRUB_STEP));
|
|
654
|
+
},
|
|
655
|
+
onPointerUp(event) {
|
|
656
|
+
if (drag.current?.moved) {
|
|
657
|
+
swallowClick.current = true;
|
|
658
|
+
setScrubbing(false);
|
|
659
|
+
// A click follows a pointerup on the same element; if none does, forget it.
|
|
660
|
+
window.setTimeout(() => (swallowClick.current = false), 0);
|
|
661
|
+
}
|
|
662
|
+
drag.current = null;
|
|
663
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId))
|
|
664
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
665
|
+
},
|
|
666
|
+
onPointerCancel() {
|
|
667
|
+
drag.current = null;
|
|
668
|
+
setScrubbing(false);
|
|
669
|
+
},
|
|
670
|
+
onClickCapture(event) {
|
|
671
|
+
// The click that ends a scrub does not open the popover.
|
|
672
|
+
if (!swallowClick.current) return;
|
|
673
|
+
swallowClick.current = false;
|
|
674
|
+
event.preventDefault();
|
|
675
|
+
event.stopPropagation();
|
|
676
|
+
},
|
|
677
|
+
onKeyDown(event) {
|
|
678
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
679
|
+
const by =
|
|
680
|
+
event.key === "ArrowUp" || event.key === (rtl ? "ArrowLeft" : "ArrowRight")
|
|
681
|
+
? 1
|
|
682
|
+
: event.key === "ArrowDown" || event.key === (rtl ? "ArrowRight" : "ArrowLeft")
|
|
683
|
+
? -1
|
|
684
|
+
: 0;
|
|
685
|
+
if (by) stepTo(indexOf() + by);
|
|
686
|
+
else if (event.key === "Home") stepTo(0);
|
|
687
|
+
else if (event.key === "End") stepTo(Infinity);
|
|
688
|
+
else return;
|
|
689
|
+
event.preventDefault();
|
|
690
|
+
},
|
|
691
|
+
};
|
|
692
|
+
return { scrubbing, said, props };
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* One setting as a compact row: its name, its value under it and a picture of it at the end.
|
|
697
|
+
* Pressing it opens a popover with the control; with `scrub`, dragging along it or the arrow keys
|
|
698
|
+
* change the value in place.
|
|
699
|
+
*/
|
|
700
|
+
function SettingRow({
|
|
701
|
+
label,
|
|
702
|
+
value,
|
|
703
|
+
visual,
|
|
704
|
+
wide,
|
|
705
|
+
scrub,
|
|
706
|
+
children,
|
|
707
|
+
}: {
|
|
708
|
+
label: string;
|
|
709
|
+
value: React.ReactNode;
|
|
710
|
+
visual: React.ReactNode;
|
|
711
|
+
wide: boolean;
|
|
712
|
+
scrub?: Scrub;
|
|
713
|
+
children: React.ReactNode;
|
|
714
|
+
}) {
|
|
715
|
+
const { scrubbing, said, props } = useScrub(scrub);
|
|
716
|
+
const hint = React.useId();
|
|
717
|
+
return (
|
|
718
|
+
<Popover>
|
|
719
|
+
<PopoverTrigger
|
|
720
|
+
{...props}
|
|
721
|
+
aria-describedby={scrub ? hint : undefined}
|
|
722
|
+
data-scrubbing={scrubbing ? "" : undefined}
|
|
723
|
+
className={cn(
|
|
724
|
+
"flex min-h-12 w-full min-w-0 cursor-pointer items-center gap-3 rounded-button material-row px-3 py-1.5 text-start focus-ring data-popup-open:bg-control-hover data-popup-open:text-foreground",
|
|
725
|
+
scrub && "cursor-ew-resize touch-pan-y select-none data-scrubbing:bg-control-hover",
|
|
726
|
+
)}
|
|
727
|
+
>
|
|
728
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
729
|
+
<span className="text-xs text-muted-foreground">{label}</span>
|
|
730
|
+
<span className="truncate font-mono text-[13px] text-foreground tabular-nums">{value}</span>
|
|
731
|
+
</span>
|
|
732
|
+
{visual}
|
|
733
|
+
</PopoverTrigger>
|
|
734
|
+
{scrub && (
|
|
735
|
+
<>
|
|
736
|
+
<span id={hint} hidden>
|
|
737
|
+
Drag sideways or press the arrow keys to change it.
|
|
738
|
+
</span>
|
|
739
|
+
<span aria-live="polite" className="sr-only">
|
|
740
|
+
{said}
|
|
741
|
+
</span>
|
|
742
|
+
</>
|
|
743
|
+
)}
|
|
744
|
+
{/* Beside the menu, over the preview, rather than inside the menu's own width. */}
|
|
745
|
+
<PopoverContent
|
|
746
|
+
side={wide ? "right" : "bottom"}
|
|
747
|
+
align="start"
|
|
748
|
+
sideOffset={12}
|
|
749
|
+
positioner={{ collisionBoundary: "clipping-ancestors" }}
|
|
750
|
+
className="w-80 gap-3"
|
|
751
|
+
>
|
|
752
|
+
{children}
|
|
753
|
+
</PopoverContent>
|
|
754
|
+
</Popover>
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const Controls = React.memo(function Controls({
|
|
759
|
+
preset,
|
|
760
|
+
anchors,
|
|
761
|
+
families: picked,
|
|
762
|
+
failing,
|
|
763
|
+
mode,
|
|
764
|
+
wide,
|
|
765
|
+
onSettings,
|
|
766
|
+
onShape,
|
|
767
|
+
onPick,
|
|
768
|
+
onKeep,
|
|
769
|
+
onFamily,
|
|
770
|
+
onUnpinAll,
|
|
771
|
+
tokens,
|
|
772
|
+
}: {
|
|
773
|
+
preset: ThemePreset;
|
|
774
|
+
anchors: Anchors;
|
|
775
|
+
families: Families;
|
|
776
|
+
failing: number;
|
|
777
|
+
mode: Mode;
|
|
778
|
+
wide: boolean;
|
|
779
|
+
onSettings: (patch: Partial<ThemeSettings>) => void;
|
|
780
|
+
onShape: (patch: Partial<ThemeShape>) => void;
|
|
781
|
+
onPick: (seed: Seed, color: ThemeColor) => void;
|
|
782
|
+
onKeep: (seed: Seed, keep: boolean) => void;
|
|
783
|
+
onFamily: (seed: Seed, id: string) => void;
|
|
784
|
+
onUnpinAll: () => void;
|
|
785
|
+
tokens: React.ReactNode;
|
|
786
|
+
}) {
|
|
787
|
+
const { settings, shape } = preset;
|
|
788
|
+
const h = themeHeights(shape.controlHeight);
|
|
789
|
+
const corners = Math.round(shape.corners * 100);
|
|
790
|
+
const r = radiiOf(shape);
|
|
791
|
+
|
|
792
|
+
return (
|
|
793
|
+
<div className="flex flex-col">
|
|
794
|
+
<div className="flex flex-col gap-1 p-2">
|
|
795
|
+
{SEEDS.map((seed) => (
|
|
796
|
+
<SeedRow
|
|
797
|
+
key={seed}
|
|
798
|
+
seed={seed}
|
|
799
|
+
color={shownSeed(seed, settings, anchors[seed])}
|
|
800
|
+
family={picked[seed] ?? ANY}
|
|
801
|
+
kept={preset.seeds[seed]}
|
|
802
|
+
wide={wide}
|
|
803
|
+
onPick={onPick}
|
|
804
|
+
onKeep={onKeep}
|
|
805
|
+
onFamily={onFamily}
|
|
806
|
+
/>
|
|
807
|
+
))}
|
|
808
|
+
{failing > 0 && (
|
|
809
|
+
<p aria-live="polite" className="flex items-center gap-1.5 px-3 py-1 text-xs text-warning">
|
|
810
|
+
<TriangleAlertIcon aria-hidden className="size-3.5 shrink-0" />
|
|
811
|
+
{failing} {failing === 1 ? "colour reads" : "colours read"} below contrast in {mode}. Advanced
|
|
812
|
+
shows which.
|
|
813
|
+
</p>
|
|
814
|
+
)}
|
|
815
|
+
</div>
|
|
816
|
+
<div className="grid gap-1 border-t border-border p-2 @md/menu:grid-cols-2">
|
|
817
|
+
<SettingRow
|
|
818
|
+
label="Corners"
|
|
819
|
+
value={`${corners}% · cards ${r["--radius-card"]}px`}
|
|
820
|
+
wide={wide}
|
|
821
|
+
scrub={{
|
|
822
|
+
steps: THEME_CORNERS,
|
|
823
|
+
value: shape.corners,
|
|
824
|
+
onChange: (corners) => onShape({ corners }),
|
|
825
|
+
say: (v) => `Corners ${Math.round(v * 100)}%`,
|
|
826
|
+
}}
|
|
827
|
+
visual={
|
|
828
|
+
<span
|
|
829
|
+
aria-hidden
|
|
830
|
+
className="size-5 shrink-0 border-e-2 border-t-2 border-foreground-soft"
|
|
831
|
+
style={{ borderStartEndRadius: `${r["--radius-control"]}px` }}
|
|
832
|
+
/>
|
|
833
|
+
}
|
|
834
|
+
>
|
|
835
|
+
<StepSlider
|
|
836
|
+
label="Corners"
|
|
837
|
+
steps={THEME_CORNERS}
|
|
838
|
+
value={shape.corners}
|
|
839
|
+
onChange={(corners) => onShape({ corners })}
|
|
840
|
+
tick={(v) => `${Math.round(v * 100)}`}
|
|
841
|
+
format={{ style: "percent" }}
|
|
842
|
+
/>
|
|
843
|
+
</SettingRow>
|
|
844
|
+
<SettingRow
|
|
845
|
+
label="Density"
|
|
846
|
+
value={`${densityName(shape.controlHeight)} · ${h.sm} / ${h.default} / ${h.lg}`}
|
|
847
|
+
wide={wide}
|
|
848
|
+
scrub={{
|
|
849
|
+
steps: THEME_HEIGHTS,
|
|
850
|
+
value: shape.controlHeight,
|
|
851
|
+
onChange: (controlHeight) => onShape({ controlHeight }),
|
|
852
|
+
say: (v) => `Density ${densityName(v)}, ${v} pixel controls`,
|
|
853
|
+
}}
|
|
854
|
+
visual={
|
|
855
|
+
<RulerDimensionLineIcon aria-hidden className="size-4 shrink-0 rotate-90 text-foreground-soft" />
|
|
856
|
+
}
|
|
857
|
+
>
|
|
858
|
+
<StepSlider
|
|
859
|
+
label="Density"
|
|
860
|
+
steps={THEME_HEIGHTS}
|
|
861
|
+
value={shape.controlHeight}
|
|
862
|
+
onChange={(controlHeight) => onShape({ controlHeight })}
|
|
863
|
+
tick={(v) => `${v}`}
|
|
864
|
+
/>
|
|
865
|
+
</SettingRow>
|
|
866
|
+
</div>
|
|
867
|
+
<p className="px-4 pb-3 text-xs text-muted-foreground">
|
|
868
|
+
Shuffle draws each colour from its family and leaves the ones you keep. Drag Corners or Density
|
|
869
|
+
sideways to step them.
|
|
870
|
+
</p>
|
|
871
|
+
|
|
872
|
+
<Collapsible className="hairline">
|
|
873
|
+
<CollapsibleTrigger className="w-full px-4 py-4">Advanced</CollapsibleTrigger>
|
|
874
|
+
<CollapsiblePanel>
|
|
875
|
+
<Advanced settings={settings} onChange={onSettings} />
|
|
876
|
+
<Section title="Tokens">
|
|
877
|
+
<p className="text-sm text-muted-foreground">
|
|
878
|
+
Open a token to set it by lightness, chroma and hue, or paste a value. A colour set by hand is
|
|
879
|
+
pinned: Shuffle leaves it alone, and the preset code grows by 8 characters for it.
|
|
880
|
+
</p>
|
|
881
|
+
<Pinned pinned={preset.pinned} onUnpinAll={onUnpinAll} />
|
|
882
|
+
<div className="-mx-2">{tokens}</div>
|
|
883
|
+
</Section>
|
|
884
|
+
</CollapsiblePanel>
|
|
885
|
+
</Collapsible>
|
|
886
|
+
</div>
|
|
887
|
+
);
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
/** A family's name after its dot; Any has a dashed ring, as it could be any colour. */
|
|
891
|
+
function FamilyLabel({ label, dot }: { label: string; dot?: string }) {
|
|
892
|
+
return (
|
|
893
|
+
<span className="inline-flex min-w-0 items-center gap-2">
|
|
894
|
+
<span
|
|
895
|
+
aria-hidden
|
|
896
|
+
className={cn(
|
|
897
|
+
"size-2.5 shrink-0 rounded-full",
|
|
898
|
+
!dot && "border border-dashed border-foreground-soft",
|
|
899
|
+
)}
|
|
900
|
+
style={dot ? { background: dot } : undefined}
|
|
901
|
+
/>
|
|
902
|
+
<span className="truncate">{label}</span>
|
|
903
|
+
</span>
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* A seed's row: its name and colour, the family Shuffle draws it from, the colour itself (which
|
|
909
|
+
* opens the picker) and Keep, which leaves it out of Shuffle.
|
|
910
|
+
*/
|
|
911
|
+
function SeedRow({
|
|
912
|
+
seed,
|
|
913
|
+
color,
|
|
914
|
+
family,
|
|
915
|
+
kept,
|
|
916
|
+
wide,
|
|
917
|
+
onPick,
|
|
918
|
+
onKeep,
|
|
919
|
+
onFamily,
|
|
920
|
+
}: {
|
|
921
|
+
seed: Seed;
|
|
922
|
+
color: ThemeColor;
|
|
923
|
+
family: string;
|
|
924
|
+
kept: boolean;
|
|
925
|
+
wide: boolean;
|
|
926
|
+
onPick: (seed: Seed, color: ThemeColor) => void;
|
|
927
|
+
onKeep: (seed: Seed, keep: boolean) => void;
|
|
928
|
+
onFamily: (seed: Seed, id: string) => void;
|
|
929
|
+
}) {
|
|
930
|
+
const { label, lands } = seedInfo[seed];
|
|
931
|
+
const css = formatThemeColor(color);
|
|
932
|
+
const hex = formatThemeColor(color, "hex").toUpperCase();
|
|
933
|
+
const items = React.useMemo(
|
|
934
|
+
() => [
|
|
935
|
+
{ value: ANY, label: <FamilyLabel label="Any" /> },
|
|
936
|
+
...families[seed].map((f) => ({
|
|
937
|
+
value: f.id,
|
|
938
|
+
label: <FamilyLabel label={f.label} dot={familyDot(seed, f)} />,
|
|
939
|
+
})),
|
|
940
|
+
],
|
|
941
|
+
[seed],
|
|
942
|
+
);
|
|
943
|
+
return (
|
|
944
|
+
<div role="group" aria-label={label} className="flex min-h-12 items-center gap-1.5 px-3 py-1.5">
|
|
945
|
+
<span className="flex min-w-16 flex-1 flex-col">
|
|
946
|
+
<span className="text-xs text-muted-foreground">{label}</span>
|
|
947
|
+
<span className="truncate font-mono text-[13px] text-foreground tabular-nums">{hex}</span>
|
|
948
|
+
</span>
|
|
949
|
+
<Select items={items} value={family} onValueChange={(v) => v && onFamily(seed, v as string)}>
|
|
950
|
+
<SelectTrigger size="sm" aria-label={`${label} family`} className="w-[8.5rem] min-w-0 shrink-0">
|
|
951
|
+
<SelectValue />
|
|
952
|
+
</SelectTrigger>
|
|
953
|
+
<SelectContent>
|
|
954
|
+
{items.map((item) => (
|
|
955
|
+
<SelectItem key={item.value} value={item.value}>
|
|
956
|
+
{item.label}
|
|
957
|
+
</SelectItem>
|
|
958
|
+
))}
|
|
959
|
+
</SelectContent>
|
|
960
|
+
</Select>
|
|
961
|
+
<Popover>
|
|
962
|
+
<PopoverTrigger
|
|
963
|
+
aria-label={`${label} colour, ${hex}`}
|
|
964
|
+
className="inline-flex size-(--control-h-sm) shrink-0 cursor-pointer items-center justify-center rounded-full material-row focus-ring data-popup-open:bg-control-hover"
|
|
965
|
+
>
|
|
966
|
+
<ColorSwatch color={css} className="size-5 rounded-full" />
|
|
967
|
+
</PopoverTrigger>
|
|
968
|
+
<PopoverContent
|
|
969
|
+
side={wide ? "right" : "bottom"}
|
|
970
|
+
align="start"
|
|
971
|
+
sideOffset={12}
|
|
972
|
+
positioner={{ collisionBoundary: "clipping-ancestors" }}
|
|
973
|
+
className="w-80 gap-3"
|
|
974
|
+
>
|
|
975
|
+
<PopoverTitle>{label}</PopoverTitle>
|
|
976
|
+
<PopoverDescription>
|
|
977
|
+
{lands} {kept ? "Kept: Shuffle leaves it." : "Shuffle draws a new one from its family."}
|
|
978
|
+
</PopoverDescription>
|
|
979
|
+
<ColorPickerPanel
|
|
980
|
+
format="oklch"
|
|
981
|
+
value={css}
|
|
982
|
+
onValueChange={(value) => {
|
|
983
|
+
const parsed = parseThemeColor(value);
|
|
984
|
+
if (parsed) onPick(seed, { ...parsed, a: 1 });
|
|
985
|
+
}}
|
|
986
|
+
/>
|
|
987
|
+
</PopoverContent>
|
|
988
|
+
</Popover>
|
|
989
|
+
<Tooltip>
|
|
990
|
+
<TooltipTrigger
|
|
991
|
+
render={
|
|
992
|
+
<Toggle
|
|
993
|
+
size="icon-sm"
|
|
994
|
+
pressed={kept}
|
|
995
|
+
onPressedChange={(pressed) => onKeep(seed, pressed)}
|
|
996
|
+
aria-label={`Keep ${label}`}
|
|
997
|
+
/>
|
|
998
|
+
}
|
|
999
|
+
>
|
|
1000
|
+
{kept ? <LockIcon /> : <LockOpenIcon />}
|
|
1001
|
+
</TooltipTrigger>
|
|
1002
|
+
<TooltipContent side={wide ? "right" : "top"}>Keep: Shuffle leaves it</TooltipContent>
|
|
1003
|
+
</Tooltip>
|
|
1004
|
+
</div>
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* A slider that stops only on the given steps, with a mono label under each. The track is the
|
|
1010
|
+
* Slider's own; the labels sit where its thumb stops (it stays inside the track, 18px wide).
|
|
1011
|
+
*/
|
|
1012
|
+
function StepSlider({
|
|
1013
|
+
label,
|
|
1014
|
+
steps,
|
|
1015
|
+
value,
|
|
1016
|
+
onChange,
|
|
1017
|
+
tick,
|
|
1018
|
+
format,
|
|
1019
|
+
}: {
|
|
1020
|
+
label: string;
|
|
1021
|
+
steps: readonly number[];
|
|
1022
|
+
value: number;
|
|
1023
|
+
onChange: (value: number) => void;
|
|
1024
|
+
tick: (value: number) => string;
|
|
1025
|
+
format?: Intl.NumberFormatOptions;
|
|
1026
|
+
}) {
|
|
1027
|
+
const min = steps[0]!;
|
|
1028
|
+
const max = steps.at(-1)!;
|
|
1029
|
+
const step = steps[1]! - min;
|
|
1030
|
+
return (
|
|
1031
|
+
<div className="flex flex-col gap-1">
|
|
1032
|
+
<Slider
|
|
1033
|
+
label={label}
|
|
1034
|
+
showValue
|
|
1035
|
+
min={min}
|
|
1036
|
+
max={max}
|
|
1037
|
+
step={step}
|
|
1038
|
+
value={value}
|
|
1039
|
+
format={format}
|
|
1040
|
+
onValueChange={(v: number) => onChange(v)}
|
|
1041
|
+
/>
|
|
1042
|
+
<div
|
|
1043
|
+
aria-hidden
|
|
1044
|
+
className="relative mx-[9px] h-4 font-mono text-[11px] text-muted-foreground tabular-nums"
|
|
1045
|
+
>
|
|
1046
|
+
{steps.map((s) => (
|
|
1047
|
+
<span
|
|
1048
|
+
key={s}
|
|
1049
|
+
className={cn(
|
|
1050
|
+
"absolute top-0 -translate-x-1/2 rtl:translate-x-1/2",
|
|
1051
|
+
s === value && "text-foreground",
|
|
1052
|
+
)}
|
|
1053
|
+
style={{ insetInlineStart: `${((s - min) / (max - min)) * 100}%` }}
|
|
1054
|
+
>
|
|
1055
|
+
{tick(s)}
|
|
1056
|
+
</span>
|
|
1057
|
+
))}
|
|
1058
|
+
</div>
|
|
1059
|
+
</div>
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function PresetCode({ code }: { code: string }) {
|
|
1064
|
+
return (
|
|
1065
|
+
<Field>
|
|
1066
|
+
<FieldLabel>Your theme as a code</FieldLabel>
|
|
1067
|
+
<InputGroup>
|
|
1068
|
+
<InputGroupInput
|
|
1069
|
+
value={code}
|
|
1070
|
+
readOnly
|
|
1071
|
+
spellCheck={false}
|
|
1072
|
+
className="font-mono tracking-wider uppercase"
|
|
1073
|
+
onFocus={(event) => event.currentTarget.select()}
|
|
1074
|
+
/>
|
|
1075
|
+
<InputGroupAddon align="inline-end">
|
|
1076
|
+
<CopyButton
|
|
1077
|
+
value={code}
|
|
1078
|
+
labels={{ copy: "Copy preset code" }}
|
|
1079
|
+
render={<InputGroupButton size="icon" variant="ghost" />}
|
|
1080
|
+
/>
|
|
1081
|
+
</InputGroupAddon>
|
|
1082
|
+
</InputGroup>
|
|
1083
|
+
</Field>
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/** A code to open, pasted into a popover; one that can't be read says why. */
|
|
1088
|
+
function OpenPreset({ code, onLoad }: { code: string; onLoad: (preset: ThemePreset) => void }) {
|
|
1089
|
+
const [open, setOpen] = React.useState(false);
|
|
1090
|
+
const [text, setText] = React.useState("");
|
|
1091
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
1092
|
+
|
|
1093
|
+
const submit = () => {
|
|
1094
|
+
if (!text.trim()) {
|
|
1095
|
+
setError("Paste a preset code, or edit the theme to get one.");
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
try {
|
|
1099
|
+
const preset = decodeThemePreset(text);
|
|
1100
|
+
setError(null);
|
|
1101
|
+
if (encodeThemePreset(preset) !== code) onLoad(preset);
|
|
1102
|
+
setText("");
|
|
1103
|
+
setOpen(false);
|
|
1104
|
+
} catch (e) {
|
|
1105
|
+
setError((e as Error).message);
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
return (
|
|
1110
|
+
<Popover
|
|
1111
|
+
open={open}
|
|
1112
|
+
onOpenChange={(next) => {
|
|
1113
|
+
setOpen(next);
|
|
1114
|
+
if (!next) setError(null);
|
|
1115
|
+
}}
|
|
1116
|
+
>
|
|
1117
|
+
<PopoverTrigger render={<Button variant="secondary" />}>
|
|
1118
|
+
<ClipboardPasteIcon />
|
|
1119
|
+
Open preset
|
|
1120
|
+
</PopoverTrigger>
|
|
1121
|
+
<PopoverContent side="top" align="start" className="w-80">
|
|
1122
|
+
<form
|
|
1123
|
+
className="flex flex-col gap-3"
|
|
1124
|
+
onSubmit={(event) => {
|
|
1125
|
+
event.preventDefault();
|
|
1126
|
+
submit();
|
|
1127
|
+
}}
|
|
1128
|
+
>
|
|
1129
|
+
<Field error={error ?? undefined}>
|
|
1130
|
+
<FieldLabel>Preset code</FieldLabel>
|
|
1131
|
+
<Input
|
|
1132
|
+
value={text}
|
|
1133
|
+
placeholder="Z1…"
|
|
1134
|
+
spellCheck={false}
|
|
1135
|
+
autoComplete="off"
|
|
1136
|
+
autoCapitalize="characters"
|
|
1137
|
+
className="font-mono tracking-wider uppercase"
|
|
1138
|
+
onChange={(event) => {
|
|
1139
|
+
setText(event.target.value);
|
|
1140
|
+
setError(null);
|
|
1141
|
+
}}
|
|
1142
|
+
/>
|
|
1143
|
+
<FieldDescription>
|
|
1144
|
+
Letters and digits, as the editor or an AI wrote it. Case, spaces and hyphens don't matter.
|
|
1145
|
+
</FieldDescription>
|
|
1146
|
+
<FieldError />
|
|
1147
|
+
</Field>
|
|
1148
|
+
<Button type="submit" variant="secondary" className="self-end">
|
|
1149
|
+
Open
|
|
1150
|
+
</Button>
|
|
1151
|
+
</form>
|
|
1152
|
+
</PopoverContent>
|
|
1153
|
+
</Popover>
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/** The colours pinned by hand, in either theme, and the way to let them all go. */
|
|
1158
|
+
function Pinned({ pinned, onUnpinAll }: { pinned: ThemePreset["pinned"]; onUnpinAll: () => void }) {
|
|
1159
|
+
const list = (["light", "dark"] as const).flatMap((mode) =>
|
|
1160
|
+
Object.entries(pinned[mode]).map(([name, color]) => ({ name, mode, color })),
|
|
1161
|
+
);
|
|
1162
|
+
if (list.length === 0) return null;
|
|
1163
|
+
return (
|
|
1164
|
+
<div className="flex flex-col gap-2">
|
|
1165
|
+
<p className="flex items-center gap-1.5 text-sm text-foreground-soft">
|
|
1166
|
+
<PinIcon aria-hidden className="size-3.5" />
|
|
1167
|
+
{list.length === 1 ? "Pinned, so it stays as you set it:" : "Pinned, so they stay as you set them:"}
|
|
1168
|
+
</p>
|
|
1169
|
+
<ul className="m-0 flex list-none flex-wrap gap-1.5 p-0">
|
|
1170
|
+
{list.map(({ name, mode, color }) => (
|
|
1171
|
+
<li key={mode + name}>
|
|
1172
|
+
<Tag variant="outline">
|
|
1173
|
+
<ColorSwatch color={formatThemeColor(color)} className="size-3" />
|
|
1174
|
+
{name} · {mode}
|
|
1175
|
+
</Tag>
|
|
1176
|
+
</li>
|
|
1177
|
+
))}
|
|
1178
|
+
</ul>
|
|
1179
|
+
<Button size="sm" variant="secondary" onClick={onUnpinAll} className="self-start">
|
|
1180
|
+
Unpin all
|
|
1181
|
+
</Button>
|
|
1182
|
+
</div>
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
const Advanced = React.memo(function Advanced({
|
|
1187
|
+
settings,
|
|
1188
|
+
onChange,
|
|
1189
|
+
}: {
|
|
1190
|
+
settings: ThemeSettings;
|
|
1191
|
+
onChange: (patch: Partial<ThemeSettings>) => void;
|
|
1192
|
+
}) {
|
|
1193
|
+
const hueLabel = (text: string, hue: number, chroma = 0.14) => (
|
|
1194
|
+
<span className="flex items-center gap-2">
|
|
1195
|
+
<ColorSwatch color={formatThemeColor({ l: 0.65, c: chroma, h: hue, a: 1 })} className="rounded-full" />
|
|
1196
|
+
{text}
|
|
1197
|
+
</span>
|
|
1198
|
+
);
|
|
1199
|
+
|
|
1200
|
+
return (
|
|
1201
|
+
<div className="flex flex-col">
|
|
1202
|
+
<Section title="Background" rule={false} className="pt-1">
|
|
1203
|
+
<Slider
|
|
1204
|
+
label="Ground"
|
|
1205
|
+
showValue
|
|
1206
|
+
min={0}
|
|
1207
|
+
max={1}
|
|
1208
|
+
step={0.01}
|
|
1209
|
+
value={settings.ground}
|
|
1210
|
+
onValueChange={(ground: number) => onChange({ ground })}
|
|
1211
|
+
format={{ style: "percent" }}
|
|
1212
|
+
/>
|
|
1213
|
+
<Slider
|
|
1214
|
+
label="Tint"
|
|
1215
|
+
showValue
|
|
1216
|
+
min={0}
|
|
1217
|
+
max={0.04}
|
|
1218
|
+
step={0.001}
|
|
1219
|
+
value={settings.tint}
|
|
1220
|
+
onValueChange={(tint: number) => onChange({ tint })}
|
|
1221
|
+
/>
|
|
1222
|
+
<Slider
|
|
1223
|
+
label={hueLabel("Tint hue", settings.tintHue, Math.max(settings.tint * 4, 0.04))}
|
|
1224
|
+
showValue
|
|
1225
|
+
min={0}
|
|
1226
|
+
max={359}
|
|
1227
|
+
step={1}
|
|
1228
|
+
value={settings.tintHue}
|
|
1229
|
+
onValueChange={(tintHue: number) => onChange({ tintHue })}
|
|
1230
|
+
/>
|
|
1231
|
+
</Section>
|
|
1232
|
+
|
|
1233
|
+
<Section title="Accent">
|
|
1234
|
+
<Slider
|
|
1235
|
+
label="Colour"
|
|
1236
|
+
showValue
|
|
1237
|
+
min={0}
|
|
1238
|
+
max={1}
|
|
1239
|
+
step={0.01}
|
|
1240
|
+
value={settings.accent}
|
|
1241
|
+
onValueChange={(accent: number) => onChange({ accent })}
|
|
1242
|
+
format={{ style: "percent" }}
|
|
1243
|
+
/>
|
|
1244
|
+
<Slider
|
|
1245
|
+
label={hueLabel("Hue", settings.accentHue, Math.max(settings.accent * 0.19, 0.04))}
|
|
1246
|
+
showValue
|
|
1247
|
+
min={0}
|
|
1248
|
+
max={359}
|
|
1249
|
+
step={1}
|
|
1250
|
+
value={settings.accentHue}
|
|
1251
|
+
onValueChange={(accentHue: number) => onChange({ accentHue })}
|
|
1252
|
+
/>
|
|
1253
|
+
</Section>
|
|
1254
|
+
|
|
1255
|
+
<Section title="Status and tones">
|
|
1256
|
+
<Slider
|
|
1257
|
+
label="Vividness"
|
|
1258
|
+
showValue
|
|
1259
|
+
min={0.3}
|
|
1260
|
+
max={1.5}
|
|
1261
|
+
step={0.01}
|
|
1262
|
+
value={settings.vivid}
|
|
1263
|
+
onValueChange={(vivid: number) => onChange({ vivid })}
|
|
1264
|
+
format={{ style: "percent" }}
|
|
1265
|
+
/>
|
|
1266
|
+
<Slider
|
|
1267
|
+
label="Turn the tones"
|
|
1268
|
+
showValue
|
|
1269
|
+
min={-180}
|
|
1270
|
+
max={180}
|
|
1271
|
+
step={1}
|
|
1272
|
+
value={settings.toneShift}
|
|
1273
|
+
onValueChange={(toneShift: number) => onChange({ toneShift })}
|
|
1274
|
+
format={{ style: "unit", unit: "degree", unitDisplay: "narrow" }}
|
|
1275
|
+
/>
|
|
1276
|
+
<Slider
|
|
1277
|
+
label="Status hue"
|
|
1278
|
+
showValue
|
|
1279
|
+
min={-12}
|
|
1280
|
+
max={12}
|
|
1281
|
+
step={1}
|
|
1282
|
+
value={settings.statusShift}
|
|
1283
|
+
onValueChange={(statusShift: number) => onChange({ statusShift })}
|
|
1284
|
+
format={{ style: "unit", unit: "degree", unitDisplay: "narrow" }}
|
|
1285
|
+
/>
|
|
1286
|
+
</Section>
|
|
1287
|
+
</div>
|
|
1288
|
+
);
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
/* ── Tokens ───────────────────────────────────────────────────────────────── */
|
|
1292
|
+
|
|
1293
|
+
const TokenList = React.memo(function TokenList({
|
|
1294
|
+
palette,
|
|
1295
|
+
pinned,
|
|
1296
|
+
mode,
|
|
1297
|
+
selected,
|
|
1298
|
+
onSelect,
|
|
1299
|
+
onPin,
|
|
1300
|
+
onUnpin,
|
|
1301
|
+
}: {
|
|
1302
|
+
palette: Record<string, ThemeColor>;
|
|
1303
|
+
/** Read now, not deferred: a token's own sliders follow the pointer. */
|
|
1304
|
+
pinned: Record<string, ThemeColor>;
|
|
1305
|
+
mode: Mode;
|
|
1306
|
+
selected: string | null;
|
|
1307
|
+
onSelect: React.Dispatch<React.SetStateAction<string | null>>;
|
|
1308
|
+
onPin: (name: string, color: ThemeColor) => void;
|
|
1309
|
+
onUnpin: (name: string) => void;
|
|
1310
|
+
}) {
|
|
1311
|
+
const zon = React.useMemo(() => themePalette(zonThemePreset, mode), [mode]);
|
|
1312
|
+
return (
|
|
1313
|
+
<div className="flex flex-col gap-5">
|
|
1314
|
+
{themeTokenGroups.map((group) => (
|
|
1315
|
+
<section key={group.title} aria-label={group.title} className="flex flex-col">
|
|
1316
|
+
<h4 className="px-2 pb-1.5 font-mono text-xs text-muted-foreground">{group.title}</h4>
|
|
1317
|
+
{group.tokens.map((spec) => {
|
|
1318
|
+
const now = pinned[spec.name];
|
|
1319
|
+
return (
|
|
1320
|
+
<TokenRow
|
|
1321
|
+
key={spec.name}
|
|
1322
|
+
spec={spec}
|
|
1323
|
+
palette={now ? { ...palette, [spec.name]: now } : palette}
|
|
1324
|
+
zonValue={zon[spec.name]}
|
|
1325
|
+
pinned={spec.name in pinned}
|
|
1326
|
+
open={selected === spec.name}
|
|
1327
|
+
onToggle={() => onSelect((s) => (s === spec.name ? null : spec.name))}
|
|
1328
|
+
onChange={(color) => onPin(spec.name, color)}
|
|
1329
|
+
onUnpin={() => onUnpin(spec.name)}
|
|
1330
|
+
/>
|
|
1331
|
+
);
|
|
1332
|
+
})}
|
|
1333
|
+
</section>
|
|
1334
|
+
))}
|
|
1335
|
+
</div>
|
|
1336
|
+
);
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
function TokenRow({
|
|
1340
|
+
spec,
|
|
1341
|
+
palette,
|
|
1342
|
+
zonValue,
|
|
1343
|
+
pinned,
|
|
1344
|
+
open,
|
|
1345
|
+
onToggle,
|
|
1346
|
+
onChange,
|
|
1347
|
+
onUnpin,
|
|
1348
|
+
}: {
|
|
1349
|
+
spec: ThemeToken;
|
|
1350
|
+
palette: Record<string, ThemeColor>;
|
|
1351
|
+
zonValue: ThemeColor | undefined;
|
|
1352
|
+
pinned: boolean;
|
|
1353
|
+
open: boolean;
|
|
1354
|
+
onToggle: () => void;
|
|
1355
|
+
onChange: (color: ThemeColor) => void;
|
|
1356
|
+
onUnpin: () => void;
|
|
1357
|
+
}) {
|
|
1358
|
+
const color = palette[spec.name];
|
|
1359
|
+
const ground = spec.on ? palette[spec.on.token] : undefined;
|
|
1360
|
+
const id = React.useId();
|
|
1361
|
+
if (!color) return null;
|
|
1362
|
+
const ratio = ground ? themeContrast(color, ground) : null;
|
|
1363
|
+
const low = ratio !== null && spec.on && ratio < spec.on.min;
|
|
1364
|
+
|
|
1365
|
+
return (
|
|
1366
|
+
<div className={cn("flex flex-col rounded-button", open && "bg-(--ink-ghost)")}>
|
|
1367
|
+
<button
|
|
1368
|
+
type="button"
|
|
1369
|
+
aria-expanded={open}
|
|
1370
|
+
aria-controls={id}
|
|
1371
|
+
onClick={onToggle}
|
|
1372
|
+
className="flex min-h-(--control-h) w-full cursor-pointer items-center gap-3 rounded-button px-2 text-start focus-ring hover:bg-(--ink-ghost)"
|
|
1373
|
+
>
|
|
1374
|
+
<ColorSwatch color={formatThemeColor(color)} className="size-5" />
|
|
1375
|
+
<span className="flex min-w-0 flex-1 flex-col py-1.5">
|
|
1376
|
+
<span className="flex items-center gap-1.5 font-mono text-xs text-foreground">
|
|
1377
|
+
{spec.name}
|
|
1378
|
+
{pinned && <PinIcon aria-label="Pinned" className="size-3 text-muted-foreground" />}
|
|
1379
|
+
</span>
|
|
1380
|
+
<span className="truncate text-xs text-muted-foreground">{spec.label}</span>
|
|
1381
|
+
</span>
|
|
1382
|
+
{ratio !== null && (
|
|
1383
|
+
<span
|
|
1384
|
+
className={cn(
|
|
1385
|
+
"flex items-center gap-1 font-mono text-[11px] tabular-nums",
|
|
1386
|
+
low ? "text-warning" : "text-muted-foreground",
|
|
1387
|
+
)}
|
|
1388
|
+
>
|
|
1389
|
+
{low && <TriangleAlertIcon aria-hidden className="size-3" />}
|
|
1390
|
+
{ratio.toFixed(1)}:1
|
|
1391
|
+
<span className="sr-only">{low ? `, below ${spec.on!.min}:1` : ", passes"}</span>
|
|
1392
|
+
</span>
|
|
1393
|
+
)}
|
|
1394
|
+
</button>
|
|
1395
|
+
{open && (
|
|
1396
|
+
<TokenEditor
|
|
1397
|
+
id={id}
|
|
1398
|
+
spec={spec}
|
|
1399
|
+
color={color}
|
|
1400
|
+
ground={ground}
|
|
1401
|
+
zonValue={zonValue}
|
|
1402
|
+
pinned={pinned}
|
|
1403
|
+
onChange={onChange}
|
|
1404
|
+
onUnpin={onUnpin}
|
|
1405
|
+
/>
|
|
1406
|
+
)}
|
|
1407
|
+
</div>
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function TokenEditor({
|
|
1412
|
+
id,
|
|
1413
|
+
spec,
|
|
1414
|
+
color,
|
|
1415
|
+
ground,
|
|
1416
|
+
zonValue,
|
|
1417
|
+
pinned,
|
|
1418
|
+
onChange,
|
|
1419
|
+
onUnpin,
|
|
1420
|
+
}: {
|
|
1421
|
+
id: string;
|
|
1422
|
+
spec: ThemeToken;
|
|
1423
|
+
color: ThemeColor;
|
|
1424
|
+
ground: ThemeColor | undefined;
|
|
1425
|
+
zonValue: ThemeColor | undefined;
|
|
1426
|
+
pinned: boolean;
|
|
1427
|
+
onChange: (color: ThemeColor) => void;
|
|
1428
|
+
onUnpin: () => void;
|
|
1429
|
+
}) {
|
|
1430
|
+
const [text, setText] = React.useState(formatThemeColor(color));
|
|
1431
|
+
const [invalid, setInvalid] = React.useState(false);
|
|
1432
|
+
const shown = formatThemeColor(color);
|
|
1433
|
+
React.useEffect(() => {
|
|
1434
|
+
setText(shown);
|
|
1435
|
+
setInvalid(false);
|
|
1436
|
+
}, [shown]);
|
|
1437
|
+
|
|
1438
|
+
const commit = () => {
|
|
1439
|
+
const parsed = parseThemeColor(text);
|
|
1440
|
+
if (parsed) onChange(parsed);
|
|
1441
|
+
else setInvalid(true);
|
|
1442
|
+
};
|
|
1443
|
+
const fixed =
|
|
1444
|
+
ground && spec.on && themeContrast(color, ground) < spec.on.min
|
|
1445
|
+
? fixThemeContrast(color, ground, spec.on.min)
|
|
1446
|
+
: null;
|
|
1447
|
+
const hasAlpha = color.a < 1 || (zonValue?.a ?? 1) < 1;
|
|
1448
|
+
|
|
1449
|
+
return (
|
|
1450
|
+
<div id={id} className="flex flex-col gap-3 px-3 pt-1 pb-4">
|
|
1451
|
+
<Input
|
|
1452
|
+
size="sm"
|
|
1453
|
+
aria-label={`Value of ${spec.name}`}
|
|
1454
|
+
aria-invalid={invalid || undefined}
|
|
1455
|
+
value={text}
|
|
1456
|
+
onChange={(event) => {
|
|
1457
|
+
setText(event.target.value);
|
|
1458
|
+
setInvalid(false);
|
|
1459
|
+
}}
|
|
1460
|
+
onBlur={commit}
|
|
1461
|
+
onKeyDown={(event) => event.key === "Enter" && commit()}
|
|
1462
|
+
className="font-mono text-xs"
|
|
1463
|
+
/>
|
|
1464
|
+
<Slider
|
|
1465
|
+
label="Lightness"
|
|
1466
|
+
showValue
|
|
1467
|
+
min={0}
|
|
1468
|
+
max={1}
|
|
1469
|
+
step={0.005}
|
|
1470
|
+
value={color.l}
|
|
1471
|
+
onValueChange={(l: number) => onChange({ ...color, l })}
|
|
1472
|
+
/>
|
|
1473
|
+
<Slider
|
|
1474
|
+
label="Chroma"
|
|
1475
|
+
showValue
|
|
1476
|
+
min={0}
|
|
1477
|
+
max={0.37}
|
|
1478
|
+
step={0.001}
|
|
1479
|
+
value={color.c}
|
|
1480
|
+
onValueChange={(c: number) => onChange({ ...color, c })}
|
|
1481
|
+
/>
|
|
1482
|
+
<Slider
|
|
1483
|
+
label="Hue"
|
|
1484
|
+
showValue
|
|
1485
|
+
min={0}
|
|
1486
|
+
max={359}
|
|
1487
|
+
step={1}
|
|
1488
|
+
value={Math.round(color.h)}
|
|
1489
|
+
onValueChange={(h: number) => onChange({ ...color, h })}
|
|
1490
|
+
/>
|
|
1491
|
+
{hasAlpha && (
|
|
1492
|
+
<Slider
|
|
1493
|
+
label="Opacity"
|
|
1494
|
+
showValue
|
|
1495
|
+
min={0}
|
|
1496
|
+
max={1}
|
|
1497
|
+
step={0.01}
|
|
1498
|
+
value={color.a}
|
|
1499
|
+
onValueChange={(a: number) => onChange({ ...color, a })}
|
|
1500
|
+
format={{ style: "percent" }}
|
|
1501
|
+
/>
|
|
1502
|
+
)}
|
|
1503
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
1504
|
+
{fixed && (
|
|
1505
|
+
<Button size="sm" variant="secondary" onClick={() => onChange(fixed)}>
|
|
1506
|
+
Fix contrast
|
|
1507
|
+
</Button>
|
|
1508
|
+
)}
|
|
1509
|
+
{pinned && (
|
|
1510
|
+
<Button size="sm" variant="ghost" onClick={onUnpin}>
|
|
1511
|
+
<RotateCcwIcon />
|
|
1512
|
+
Unpin
|
|
1513
|
+
</Button>
|
|
1514
|
+
)}
|
|
1515
|
+
{zonValue && (
|
|
1516
|
+
<span className="ms-auto font-mono text-[11px] text-muted-foreground">
|
|
1517
|
+
zon {formatThemeColor(zonValue)}
|
|
1518
|
+
</span>
|
|
1519
|
+
)}
|
|
1520
|
+
</div>
|
|
1521
|
+
</div>
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
/* ── Preview: the theme at work, then the theme itself ──────────────────────── */
|
|
1526
|
+
|
|
1527
|
+
function applyPalette(el: HTMLElement, palette: Record<string, ThemeColor>, shape: ThemeShape) {
|
|
1528
|
+
for (const [name, color] of Object.entries(palette)) el.style.setProperty(name, formatThemeColor(color));
|
|
1529
|
+
for (const [name, value] of Object.entries(themeShapeTokens(shape))) el.style.setProperty(name, value);
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
interface Anchor {
|
|
1533
|
+
node: Element;
|
|
1534
|
+
top: number;
|
|
1535
|
+
/** The preview when it scrolls itself, or null when the page does. */
|
|
1536
|
+
scroller: HTMLElement | null;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/** The card nearest the top of what you see, and where it is now. */
|
|
1540
|
+
function findAnchor(el: HTMLElement): Anchor | null {
|
|
1541
|
+
const scroller =
|
|
1542
|
+
el.scrollHeight > el.clientHeight + 1 && getComputedStyle(el).overflowY !== "visible" ? el : null;
|
|
1543
|
+
const viewTop = scroller ? scroller.getBoundingClientRect().top : 0;
|
|
1544
|
+
let best: Anchor | null = null;
|
|
1545
|
+
for (const node of el.querySelectorAll("[data-preview-card]")) {
|
|
1546
|
+
const box = node.getBoundingClientRect();
|
|
1547
|
+
if (box.bottom <= viewTop) continue;
|
|
1548
|
+
if (!best || Math.abs(box.top - viewTop) < Math.abs(best.top - viewTop))
|
|
1549
|
+
best = { node, top: box.top, scroller };
|
|
1550
|
+
}
|
|
1551
|
+
return best;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
/** Scrolls by as much as the anchor moved, so it is back where it was. */
|
|
1555
|
+
function keepAnchor({ node, top, scroller }: Anchor) {
|
|
1556
|
+
const moved = node.getBoundingClientRect().top - top;
|
|
1557
|
+
if (Math.abs(moved) < 0.5) return;
|
|
1558
|
+
if (scroller) scroller.scrollTop += moved;
|
|
1559
|
+
else window.scrollBy(0, moved);
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
type PreviewPage = "use" | "system";
|
|
1563
|
+
|
|
1564
|
+
/** Popups render inside the preview, so they take its tokens too. */
|
|
1565
|
+
const PortalContext = React.createContext<{ container: HTMLElement | null }>({ container: null });
|
|
1566
|
+
|
|
1567
|
+
const usePortal = () => React.useContext(PortalContext);
|
|
1568
|
+
|
|
1569
|
+
/**
|
|
1570
|
+
* One tile of the preview, in one of the three kinds a page uses: an object you could pick up (a
|
|
1571
|
+
* 20px card), a part of the page (a square region) or only a hairline and space (plain). Tiles sit
|
|
1572
|
+
* many to a view, so they keep a small padding and a small title.
|
|
1573
|
+
*/
|
|
1574
|
+
function PreviewCard({
|
|
1575
|
+
title,
|
|
1576
|
+
description,
|
|
1577
|
+
action,
|
|
1578
|
+
footer,
|
|
1579
|
+
children,
|
|
1580
|
+
variant = "card",
|
|
1581
|
+
className,
|
|
1582
|
+
}: {
|
|
1583
|
+
title: string;
|
|
1584
|
+
description?: React.ReactNode;
|
|
1585
|
+
action?: React.ReactNode;
|
|
1586
|
+
footer?: React.ReactNode;
|
|
1587
|
+
children?: React.ReactNode;
|
|
1588
|
+
variant?: "card" | "region" | "plain";
|
|
1589
|
+
className?: string;
|
|
1590
|
+
}) {
|
|
1591
|
+
const plain = variant === "plain";
|
|
1592
|
+
return (
|
|
1593
|
+
<Card
|
|
1594
|
+
data-preview-card
|
|
1595
|
+
variant={variant}
|
|
1596
|
+
render={<section aria-label={title} />}
|
|
1597
|
+
className={cn(plain ? "gap-3 pt-3 pb-1" : "gap-4 [--card-padding:20px]", className)}
|
|
1598
|
+
>
|
|
1599
|
+
<div className={cn("flex gap-3", plain ? "min-h-(--control-h-sm) items-center" : "items-start")}>
|
|
1600
|
+
<CardHeader className="min-w-0 flex-1 gap-1">
|
|
1601
|
+
{plain ? (
|
|
1602
|
+
<h3 className="m-0 eyebrow">{title}</h3>
|
|
1603
|
+
) : (
|
|
1604
|
+
<CardTitle className="text-lg sm:text-lg">{title}</CardTitle>
|
|
1605
|
+
)}
|
|
1606
|
+
{description && <CardDescription className="text-[13px]">{description}</CardDescription>}
|
|
1607
|
+
</CardHeader>
|
|
1608
|
+
{action}
|
|
1609
|
+
</div>
|
|
1610
|
+
{children !== undefined && <CardContent className="flex flex-col gap-3">{children}</CardContent>}
|
|
1611
|
+
{footer && <CardFooter>{footer}</CardFooter>}
|
|
1612
|
+
</Card>
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
interface Tile {
|
|
1617
|
+
key: string;
|
|
1618
|
+
/** About how tall it is, in px at zon's shape: only to share the cards out evenly. */
|
|
1619
|
+
weight: number;
|
|
1620
|
+
node: React.ReactNode;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* Columns of cards. Each card is given to the column with the least in it so far, by its weight
|
|
1625
|
+
* rather than its measured height, so a card never changes column when the theme makes it taller:
|
|
1626
|
+
* only the cards under it move down.
|
|
1627
|
+
*/
|
|
1628
|
+
function Masonry({ tiles, columns }: { tiles: Tile[]; columns: number }) {
|
|
1629
|
+
const shared = React.useMemo(() => {
|
|
1630
|
+
const out = Array.from({ length: columns }, () => ({ weight: 0, tiles: [] as Tile[] }));
|
|
1631
|
+
for (const tile of tiles) {
|
|
1632
|
+
const column = out.reduce((a, b) => (b.weight < a.weight ? b : a));
|
|
1633
|
+
column.tiles.push(tile);
|
|
1634
|
+
column.weight += tile.weight;
|
|
1635
|
+
}
|
|
1636
|
+
return out;
|
|
1637
|
+
}, [tiles, columns]);
|
|
1638
|
+
return (
|
|
1639
|
+
<div
|
|
1640
|
+
className="grid items-start gap-4"
|
|
1641
|
+
style={{ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` }}
|
|
1642
|
+
>
|
|
1643
|
+
{shared.map((column, i) => (
|
|
1644
|
+
<div key={i} className="flex min-w-0 flex-col gap-4">
|
|
1645
|
+
{column.tiles.map((tile) => (
|
|
1646
|
+
<React.Fragment key={tile.key}>{tile.node}</React.Fragment>
|
|
1647
|
+
))}
|
|
1648
|
+
</div>
|
|
1649
|
+
))}
|
|
1650
|
+
</div>
|
|
1651
|
+
);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
/** The narrowest a column of tiles gets, and the gap between columns, in px. */
|
|
1655
|
+
const COLUMN_MIN = 240;
|
|
1656
|
+
|
|
1657
|
+
const COLUMN_GAP = 16;
|
|
1658
|
+
|
|
1659
|
+
const MAX_COLUMNS = 5;
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* How many columns of tiles fit the preview's own width (not the window's): one on a phone, then
|
|
1663
|
+
* two, three, four and five as it widens, each at least COLUMN_MIN wide.
|
|
1664
|
+
*/
|
|
1665
|
+
function useColumns(el: HTMLElement | null) {
|
|
1666
|
+
const [columns, setColumns] = React.useState(3);
|
|
1667
|
+
React.useLayoutEffect(() => {
|
|
1668
|
+
if (!el) return;
|
|
1669
|
+
const measure = () => {
|
|
1670
|
+
const style = getComputedStyle(el);
|
|
1671
|
+
const width =
|
|
1672
|
+
el.clientWidth - parseFloat(style.paddingInlineStart) - parseFloat(style.paddingInlineEnd);
|
|
1673
|
+
const fit = Math.floor((width + COLUMN_GAP) / (COLUMN_MIN + COLUMN_GAP));
|
|
1674
|
+
setColumns(Math.min(MAX_COLUMNS, Math.max(1, fit)));
|
|
1675
|
+
};
|
|
1676
|
+
measure();
|
|
1677
|
+
const observer = new ResizeObserver(measure);
|
|
1678
|
+
observer.observe(el);
|
|
1679
|
+
return () => observer.disconnect();
|
|
1680
|
+
}, [el]);
|
|
1681
|
+
return columns;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
/**
|
|
1685
|
+
* The preview: two pages under the edited tokens. The colours arrive through `attach`, which
|
|
1686
|
+
* hands the element to the editor to set them on directly; the cards render again only for a new
|
|
1687
|
+
* page, a new theme to show or a new column count.
|
|
1688
|
+
*/
|
|
1689
|
+
function Preview({
|
|
1690
|
+
mode,
|
|
1691
|
+
page,
|
|
1692
|
+
onPage,
|
|
1693
|
+
palette,
|
|
1694
|
+
shape,
|
|
1695
|
+
attach,
|
|
1696
|
+
className,
|
|
1697
|
+
}: {
|
|
1698
|
+
mode: Mode;
|
|
1699
|
+
page: PreviewPage;
|
|
1700
|
+
onPage: (page: PreviewPage) => void;
|
|
1701
|
+
palette: Record<string, ThemeColor>;
|
|
1702
|
+
shape: ThemeShape;
|
|
1703
|
+
attach: (el: HTMLDivElement | null) => void;
|
|
1704
|
+
className?: string;
|
|
1705
|
+
}) {
|
|
1706
|
+
const [host, setHost] = React.useState<HTMLDivElement | null>(null);
|
|
1707
|
+
const portal = React.useMemo(() => ({ container: host }), [host]);
|
|
1708
|
+
const columns = useColumns(host);
|
|
1709
|
+
const ref = React.useCallback(
|
|
1710
|
+
(el: HTMLDivElement | null) => {
|
|
1711
|
+
setHost(el);
|
|
1712
|
+
attach(el);
|
|
1713
|
+
},
|
|
1714
|
+
[attach],
|
|
1715
|
+
);
|
|
1716
|
+
const system = React.useMemo(() => systemTiles(palette, shape), [palette, shape]);
|
|
1717
|
+
|
|
1718
|
+
const turn = (next: PreviewPage) => {
|
|
1719
|
+
onPage(next);
|
|
1720
|
+
if (host && host.scrollTop > 0) host.scrollTop = 0;
|
|
1721
|
+
else if (host && host.getBoundingClientRect().top < 0) host.scrollIntoView({ block: "start" });
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
return (
|
|
1725
|
+
<div
|
|
1726
|
+
ref={ref}
|
|
1727
|
+
data-slot="theme-editor-preview"
|
|
1728
|
+
aria-label={`Preview, ${mode}: ${page === "use" ? "Kiln, a ceramics studio" : "the system"}`}
|
|
1729
|
+
role="region"
|
|
1730
|
+
className={cn(
|
|
1731
|
+
mode === "dark" ? "theme-dark" : "theme-light",
|
|
1732
|
+
"@container/preview relative bg-background p-4 text-foreground [overflow-anchor:none]",
|
|
1733
|
+
className,
|
|
1734
|
+
)}
|
|
1735
|
+
>
|
|
1736
|
+
<PortalContext.Provider value={portal}>
|
|
1737
|
+
<Masonry tiles={page === "use" ? inUseTiles : system} columns={columns} />
|
|
1738
|
+
</PortalContext.Provider>
|
|
1739
|
+
<div className="pointer-events-none sticky bottom-4 z-10 mt-6 flex justify-center">
|
|
1740
|
+
<ToggleGroup
|
|
1741
|
+
aria-label="Preview page"
|
|
1742
|
+
value={[page]}
|
|
1743
|
+
onValueChange={(v: string[]) => v[0] && turn(v[0] as PreviewPage)}
|
|
1744
|
+
className="pointer-events-auto shadow-lg"
|
|
1745
|
+
>
|
|
1746
|
+
<ToggleGroupItem value="use">
|
|
1747
|
+
<span className="font-mono tabular-nums">01</span> In use
|
|
1748
|
+
</ToggleGroupItem>
|
|
1749
|
+
<ToggleGroupItem value="system">
|
|
1750
|
+
<span className="font-mono tabular-nums">02</span> System
|
|
1751
|
+
</ToggleGroupItem>
|
|
1752
|
+
</ToggleGroup>
|
|
1753
|
+
</div>
|
|
1754
|
+
</div>
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/* ── Page 01: Kiln, a ceramics studio's shop and classes ────────────────────── */
|
|
1759
|
+
|
|
1760
|
+
const collections = [
|
|
1761
|
+
{ key: "mugs", label: "Mugs", tone: "blue" },
|
|
1762
|
+
{ key: "bowls", label: "Bowls", tone: "aqua" },
|
|
1763
|
+
{ key: "vases", label: "Vases", tone: "violet" },
|
|
1764
|
+
{ key: "plates", label: "Plates", tone: "orange" },
|
|
1765
|
+
] as const;
|
|
1766
|
+
|
|
1767
|
+
type CollectionKey = (typeof collections)[number]["key"];
|
|
1768
|
+
|
|
1769
|
+
const weekly = [
|
|
1770
|
+
{ week: "W34", mugs: 14, bowls: 9, vases: 5, plates: 8 },
|
|
1771
|
+
{ week: "W35", mugs: 16, bowls: 10, vases: 4, plates: 9 },
|
|
1772
|
+
{ week: "W36", mugs: 13, bowls: 12, vases: 6, plates: 7 },
|
|
1773
|
+
{ week: "W37", mugs: 18, bowls: 9, vases: 5, plates: 10 },
|
|
1774
|
+
{ week: "W38", mugs: 17, bowls: 11, vases: 7, plates: 9 },
|
|
1775
|
+
{ week: "W39", mugs: 20, bowls: 13, vases: 6, plates: 12 },
|
|
1776
|
+
];
|
|
1777
|
+
|
|
1778
|
+
const weekTotal = (w: (typeof weekly)[number]) => w.mugs + w.bowls + w.vases + w.plates;
|
|
1779
|
+
|
|
1780
|
+
const thisWeek = weekTotal(weekly.at(-1)!);
|
|
1781
|
+
|
|
1782
|
+
const lastWeek = weekTotal(weekly.at(-2)!);
|
|
1783
|
+
|
|
1784
|
+
// Each collection keeps its own tone, here and in the tags, whatever order the chart would give.
|
|
1785
|
+
const weeklyConfig = Object.fromEntries(
|
|
1786
|
+
collections.map((c) => [c.key, { label: c.label, color: `var(--tone-${c.tone})` }]),
|
|
1787
|
+
) satisfies ChartConfig;
|
|
1788
|
+
|
|
1789
|
+
function OrdersChartCard() {
|
|
1790
|
+
return (
|
|
1791
|
+
<PreviewCard title="Orders by collection" description="The last six weeks.">
|
|
1792
|
+
<ChartContainer
|
|
1793
|
+
config={weeklyConfig}
|
|
1794
|
+
className="aspect-auto h-40"
|
|
1795
|
+
aria-label="Orders by collection per week"
|
|
1796
|
+
>
|
|
1797
|
+
<BarChart data={weekly} margin={{ top: 4, right: 4, left: 0, bottom: 0 }}>
|
|
1798
|
+
<CartesianGrid vertical={false} />
|
|
1799
|
+
<XAxis dataKey="week" tickMargin={8} />
|
|
1800
|
+
<YAxis width={28} tickMargin={4} />
|
|
1801
|
+
<ChartTooltip content={<ChartTooltipContent />} />
|
|
1802
|
+
{collections.map((c, i) => (
|
|
1803
|
+
<Bar
|
|
1804
|
+
key={c.key}
|
|
1805
|
+
isAnimationActive={false}
|
|
1806
|
+
dataKey={c.key}
|
|
1807
|
+
stackId="orders"
|
|
1808
|
+
fill={`var(--color-${c.key})`}
|
|
1809
|
+
radius={i === collections.length - 1 ? [3, 3, 0, 0] : 0}
|
|
1810
|
+
maxBarSize={28}
|
|
1811
|
+
/>
|
|
1812
|
+
))}
|
|
1813
|
+
<ChartLegend content={<ChartLegendContent />} />
|
|
1814
|
+
</BarChart>
|
|
1815
|
+
</ChartContainer>
|
|
1816
|
+
<StatGroup className="grid-cols-2">
|
|
1817
|
+
<Stat label="This week" value={thisWeek} change={thisWeek / lastWeek - 1} size="sm" />
|
|
1818
|
+
<Stat label="Busiest" value="Mugs" description="20 orders in W39" size="sm" />
|
|
1819
|
+
</StatGroup>
|
|
1820
|
+
</PreviewCard>
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
const takings = [3880, 4010, 3950, 4220, 4105, 4380, 4290, 4510, 4460, 4700, 4680, 4920];
|
|
1825
|
+
|
|
1826
|
+
function TakingsCard() {
|
|
1827
|
+
return (
|
|
1828
|
+
<PreviewCard variant="plain" title="September">
|
|
1829
|
+
<StatGroup className="grid-cols-1">
|
|
1830
|
+
<Stat
|
|
1831
|
+
label="Takings"
|
|
1832
|
+
value={4920}
|
|
1833
|
+
format={{ style: "currency", currency: "EUR", maximumFractionDigits: 0 }}
|
|
1834
|
+
change={0.051}
|
|
1835
|
+
changeLabel="vs. August"
|
|
1836
|
+
series={takings}
|
|
1837
|
+
/>
|
|
1838
|
+
</StatGroup>
|
|
1839
|
+
<StatGroup className="grid-cols-2">
|
|
1840
|
+
<Stat
|
|
1841
|
+
label="Average order"
|
|
1842
|
+
value={48.7}
|
|
1843
|
+
format={{ style: "currency", currency: "EUR" }}
|
|
1844
|
+
change={0.02}
|
|
1845
|
+
size="sm"
|
|
1846
|
+
/>
|
|
1847
|
+
<Stat label="Returns" value={3} change={-0.25} better="down" size="sm" />
|
|
1848
|
+
</StatGroup>
|
|
1849
|
+
</PreviewCard>
|
|
1850
|
+
);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
function FiringCard() {
|
|
1854
|
+
return (
|
|
1855
|
+
<PreviewCard
|
|
1856
|
+
title="Schedule a firing"
|
|
1857
|
+
description="Runs overnight, cools for a day."
|
|
1858
|
+
footer={
|
|
1859
|
+
<Button className="w-full">
|
|
1860
|
+
<FlameIcon />
|
|
1861
|
+
Schedule firing
|
|
1862
|
+
</Button>
|
|
1863
|
+
}
|
|
1864
|
+
>
|
|
1865
|
+
<Field>
|
|
1866
|
+
<FieldLabel>Kiln</FieldLabel>
|
|
1867
|
+
<NativeSelect defaultValue="big">
|
|
1868
|
+
<NativeSelectOption value="big">Big kiln · 220 litres</NativeSelectOption>
|
|
1869
|
+
<NativeSelectOption value="test">Test kiln · 40 litres</NativeSelectOption>
|
|
1870
|
+
<NativeSelectOption value="raku">Raku kiln · outdoors</NativeSelectOption>
|
|
1871
|
+
</NativeSelect>
|
|
1872
|
+
</Field>
|
|
1873
|
+
<Field>
|
|
1874
|
+
<FieldLabel>Firing</FieldLabel>
|
|
1875
|
+
<ToggleGroup defaultValue={["glaze"]} aria-label="Firing" className="w-full *:flex-1">
|
|
1876
|
+
<ToggleGroupItem value="bisque">Bisque</ToggleGroupItem>
|
|
1877
|
+
<ToggleGroupItem value="glaze">Glaze</ToggleGroupItem>
|
|
1878
|
+
</ToggleGroup>
|
|
1879
|
+
</Field>
|
|
1880
|
+
<Slider
|
|
1881
|
+
label="Peak temperature"
|
|
1882
|
+
showValue
|
|
1883
|
+
min={900}
|
|
1884
|
+
max={1300}
|
|
1885
|
+
step={10}
|
|
1886
|
+
defaultValue={1240}
|
|
1887
|
+
format={{ style: "unit", unit: "celsius" }}
|
|
1888
|
+
/>
|
|
1889
|
+
<Field>
|
|
1890
|
+
<FieldLabel>Pieces</FieldLabel>
|
|
1891
|
+
<NumberField defaultValue={24} min={1} max={80} />
|
|
1892
|
+
</Field>
|
|
1893
|
+
<Field>
|
|
1894
|
+
<FieldLabel>Notes</FieldLabel>
|
|
1895
|
+
<Textarea placeholder="Shelves, cones, anything the next person should know" className="min-h-20" />
|
|
1896
|
+
</Field>
|
|
1897
|
+
</PreviewCard>
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
const stock = [
|
|
1902
|
+
{ name: "Stoneware clay", value: 72, left: "130 kg" },
|
|
1903
|
+
{ name: "Porcelain", value: 41, left: "48 kg" },
|
|
1904
|
+
{ name: "Celadon glaze", value: 12, left: "1.5 l" },
|
|
1905
|
+
{ name: "Tenmoku glaze", value: 64, left: "7 l" },
|
|
1906
|
+
];
|
|
1907
|
+
|
|
1908
|
+
const stockTone = (value: number) => (value < 20 ? "warning" : "default");
|
|
1909
|
+
|
|
1910
|
+
function StockCard() {
|
|
1911
|
+
return (
|
|
1912
|
+
<PreviewCard
|
|
1913
|
+
variant="plain"
|
|
1914
|
+
title="Clay and glaze"
|
|
1915
|
+
action={
|
|
1916
|
+
<Tag tone="warning" dot>
|
|
1917
|
+
1 low
|
|
1918
|
+
</Tag>
|
|
1919
|
+
}
|
|
1920
|
+
footer={
|
|
1921
|
+
<Button variant="secondary" size="sm">
|
|
1922
|
+
<PackageIcon />
|
|
1923
|
+
Order supplies
|
|
1924
|
+
</Button>
|
|
1925
|
+
}
|
|
1926
|
+
>
|
|
1927
|
+
{stock.map((s) => (
|
|
1928
|
+
<Meter key={s.name} value={s.value} label={`${s.name} · ${s.left}`} showValue tone={stockTone} />
|
|
1929
|
+
))}
|
|
1930
|
+
</PreviewCard>
|
|
1931
|
+
);
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
const recent: {
|
|
1935
|
+
who: string;
|
|
1936
|
+
what: string;
|
|
1937
|
+
id: string;
|
|
1938
|
+
collection: CollectionKey;
|
|
1939
|
+
status: "success" | "warning" | "info" | "destructive";
|
|
1940
|
+
label: string;
|
|
1941
|
+
sum: string;
|
|
1942
|
+
}[] = [
|
|
1943
|
+
{
|
|
1944
|
+
who: "Ines Duarte",
|
|
1945
|
+
what: "2 speckled mugs",
|
|
1946
|
+
id: "#1052",
|
|
1947
|
+
collection: "mugs",
|
|
1948
|
+
status: "info",
|
|
1949
|
+
label: "New",
|
|
1950
|
+
sum: "€64.00",
|
|
1951
|
+
},
|
|
1952
|
+
{
|
|
1953
|
+
who: "Tom Becker",
|
|
1954
|
+
what: "Tall vase, ash glaze",
|
|
1955
|
+
id: "#1051",
|
|
1956
|
+
collection: "vases",
|
|
1957
|
+
status: "success",
|
|
1958
|
+
label: "Paid",
|
|
1959
|
+
sum: "€128.00",
|
|
1960
|
+
},
|
|
1961
|
+
{
|
|
1962
|
+
who: "Aiko Mori",
|
|
1963
|
+
what: "3 rice bowls",
|
|
1964
|
+
id: "#1050",
|
|
1965
|
+
collection: "bowls",
|
|
1966
|
+
status: "warning",
|
|
1967
|
+
label: "Unpaid",
|
|
1968
|
+
sum: "€42.50",
|
|
1969
|
+
},
|
|
1970
|
+
{
|
|
1971
|
+
who: "Lena Vogt",
|
|
1972
|
+
what: "4 dinner plates",
|
|
1973
|
+
id: "#1049",
|
|
1974
|
+
collection: "plates",
|
|
1975
|
+
status: "destructive",
|
|
1976
|
+
label: "Failed",
|
|
1977
|
+
sum: "€96.00",
|
|
1978
|
+
},
|
|
1979
|
+
{
|
|
1980
|
+
who: "Omar Haddad",
|
|
1981
|
+
what: "Espresso cup",
|
|
1982
|
+
id: "#1048",
|
|
1983
|
+
collection: "mugs",
|
|
1984
|
+
status: "success",
|
|
1985
|
+
label: "Paid",
|
|
1986
|
+
sum: "€32.00",
|
|
1987
|
+
},
|
|
1988
|
+
];
|
|
1989
|
+
|
|
1990
|
+
const collectionIcon: Record<CollectionKey, React.ComponentType<{ className?: string }>> = {
|
|
1991
|
+
mugs: CoffeeIcon,
|
|
1992
|
+
bowls: SoupIcon,
|
|
1993
|
+
vases: Flower2Icon,
|
|
1994
|
+
plates: UtensilsIcon,
|
|
1995
|
+
};
|
|
1996
|
+
|
|
1997
|
+
function RecentOrdersCard() {
|
|
1998
|
+
const { container } = usePortal();
|
|
1999
|
+
return (
|
|
2000
|
+
<PreviewCard
|
|
2001
|
+
variant="region"
|
|
2002
|
+
title="Recent orders"
|
|
2003
|
+
description="Paid orders ship within ten working days."
|
|
2004
|
+
action={
|
|
2005
|
+
<Menu>
|
|
2006
|
+
<MenuTrigger render={<Button variant="ghost" size="icon" aria-label="Order actions" />}>
|
|
2007
|
+
<EllipsisIcon />
|
|
2008
|
+
</MenuTrigger>
|
|
2009
|
+
<MenuContent portal={{ container }} align="end">
|
|
2010
|
+
<MenuItem>
|
|
2011
|
+
<PrinterIcon />
|
|
2012
|
+
Print packing slips
|
|
2013
|
+
</MenuItem>
|
|
2014
|
+
<MenuItem>
|
|
2015
|
+
<TruckIcon />
|
|
2016
|
+
Mark as shipped
|
|
2017
|
+
</MenuItem>
|
|
2018
|
+
<MenuSeparator />
|
|
2019
|
+
<MenuItem variant="destructive">
|
|
2020
|
+
<XIcon />
|
|
2021
|
+
Cancel order
|
|
2022
|
+
</MenuItem>
|
|
2023
|
+
</MenuContent>
|
|
2024
|
+
</Menu>
|
|
2025
|
+
}
|
|
2026
|
+
>
|
|
2027
|
+
<ItemGroup className="-mx-2">
|
|
2028
|
+
{recent.map((o) => {
|
|
2029
|
+
const Icon = collectionIcon[o.collection];
|
|
2030
|
+
return (
|
|
2031
|
+
<Item key={o.id} size="sm">
|
|
2032
|
+
<ItemContent>
|
|
2033
|
+
<ItemTitle>{o.who}</ItemTitle>
|
|
2034
|
+
<ItemDescription className="flex items-center gap-1.5">
|
|
2035
|
+
<Icon className="size-3.5 shrink-0" />
|
|
2036
|
+
<span className="truncate">{o.what}</span>
|
|
2037
|
+
</ItemDescription>
|
|
2038
|
+
</ItemContent>
|
|
2039
|
+
<ItemActions className="flex-col items-end gap-1">
|
|
2040
|
+
<span className="font-mono text-sm text-foreground tabular-nums">{o.sum}</span>
|
|
2041
|
+
<Tag tone={o.status} dot>
|
|
2042
|
+
{o.label}
|
|
2043
|
+
</Tag>
|
|
2044
|
+
</ItemActions>
|
|
2045
|
+
</Item>
|
|
2046
|
+
);
|
|
2047
|
+
})}
|
|
2048
|
+
</ItemGroup>
|
|
2049
|
+
</PreviewCard>
|
|
2050
|
+
);
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
function PaymentAlert() {
|
|
2054
|
+
return (
|
|
2055
|
+
<Alert tone="warning" data-preview-card aria-label="A payment failed">
|
|
2056
|
+
<TriangleAlertIcon />
|
|
2057
|
+
<AlertTitle>A payment failed</AlertTitle>
|
|
2058
|
+
<AlertDescription>Lena Vogt's card was declined for #1049. We'll remind her tomorrow.</AlertDescription>
|
|
2059
|
+
</Alert>
|
|
2060
|
+
);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
function ClassesEmptyCard() {
|
|
2064
|
+
return (
|
|
2065
|
+
<Card
|
|
2066
|
+
data-preview-card
|
|
2067
|
+
variant="region"
|
|
2068
|
+
render={<section aria-label="December classes" />}
|
|
2069
|
+
className="[--card-padding:20px]"
|
|
2070
|
+
>
|
|
2071
|
+
<Empty className="gap-3 py-2">
|
|
2072
|
+
<EmptyMedia>
|
|
2073
|
+
<CalendarPlusIcon />
|
|
2074
|
+
</EmptyMedia>
|
|
2075
|
+
<EmptyTitle className="text-xl sm:text-xl">No classes in December</EmptyTitle>
|
|
2076
|
+
<EmptyDescription>Add a date and people can book a place from the shop.</EmptyDescription>
|
|
2077
|
+
<EmptyActions>
|
|
2078
|
+
<Button variant="secondary" size="sm">
|
|
2079
|
+
<PlusIcon />
|
|
2080
|
+
Add a class
|
|
2081
|
+
</Button>
|
|
2082
|
+
</EmptyActions>
|
|
2083
|
+
</Empty>
|
|
2084
|
+
</Card>
|
|
2085
|
+
);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
const classDays = [5, 12, 19, 26].map((d) => new Date(2026, 10, d));
|
|
2089
|
+
|
|
2090
|
+
function ClassesCard() {
|
|
2091
|
+
const [days, setDays] = React.useState<Date[] | undefined>(classDays);
|
|
2092
|
+
return (
|
|
2093
|
+
<PreviewCard title="Throwing for beginners" description="Thursdays, 18:00 to 20:30.">
|
|
2094
|
+
{/* A small month: its days at the dense height, so it fits a narrow column. */}
|
|
2095
|
+
<div className="-mx-2 overflow-x-auto [--control-h:var(--control-h-sm)]">
|
|
2096
|
+
<Calendar
|
|
2097
|
+
mode="multiple"
|
|
2098
|
+
defaultMonth={new Date(2026, 10, 1)}
|
|
2099
|
+
selected={days}
|
|
2100
|
+
onSelect={setDays}
|
|
2101
|
+
className="mx-auto w-fit"
|
|
2102
|
+
/>
|
|
2103
|
+
</div>
|
|
2104
|
+
<div className="flex items-center gap-3 border-t border-border pt-3">
|
|
2105
|
+
<AvatarGroup max={4} size="sm">
|
|
2106
|
+
{["Mara Kühn", "Jonas Weber", "Sofia Rossi", "Ali Demir", "Pia Lang", "Noah Berg"].map((name) => (
|
|
2107
|
+
<Avatar key={name} name={name} />
|
|
2108
|
+
))}
|
|
2109
|
+
</AvatarGroup>
|
|
2110
|
+
<span className="text-sm text-muted-foreground">6 of 8 booked for the 12th</span>
|
|
2111
|
+
</div>
|
|
2112
|
+
</PreviewCard>
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
const notifications = [
|
|
2117
|
+
{ id: "orders", title: "New orders", text: "An email for every order, as it comes in.", on: true },
|
|
2118
|
+
{ id: "stock", title: "Low stock", text: "When clay or a glaze drops under a fifth.", on: true },
|
|
2119
|
+
{ id: "bookings", title: "Class bookings", text: "When someone books or cancels a place.", on: false },
|
|
2120
|
+
{ id: "summary", title: "Weekly summary", text: "Takings and orders, every Monday at 8:00.", on: true },
|
|
2121
|
+
];
|
|
2122
|
+
|
|
2123
|
+
function NotificationsCard() {
|
|
2124
|
+
return (
|
|
2125
|
+
<PreviewCard variant="plain" title="Notifications" description="Sent to studio@kiln.example.">
|
|
2126
|
+
<div className="flex flex-col">
|
|
2127
|
+
{notifications.map((n, i) => (
|
|
2128
|
+
<Label
|
|
2129
|
+
key={n.id}
|
|
2130
|
+
className={cn("items-start justify-between gap-4 py-2.5", i > 0 && "border-t border-border")}
|
|
2131
|
+
>
|
|
2132
|
+
<span className="flex flex-col gap-0.5">
|
|
2133
|
+
<span>{n.title}</span>
|
|
2134
|
+
<span className="text-[13px] font-normal text-muted-foreground">{n.text}</span>
|
|
2135
|
+
</span>
|
|
2136
|
+
<Switch defaultChecked={n.on} />
|
|
2137
|
+
</Label>
|
|
2138
|
+
))}
|
|
2139
|
+
</div>
|
|
2140
|
+
</PreviewCard>
|
|
2141
|
+
);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
const faq = {
|
|
2145
|
+
orders: [
|
|
2146
|
+
{
|
|
2147
|
+
q: "Can I change an order?",
|
|
2148
|
+
a: "Until it goes in the kiln. Write to us within two days and we change the glaze or the size.",
|
|
2149
|
+
},
|
|
2150
|
+
{
|
|
2151
|
+
q: "Is every piece the same?",
|
|
2152
|
+
a: "No. Each one is thrown by hand, so sizes vary by a few millimetres and glazes pool differently.",
|
|
2153
|
+
},
|
|
2154
|
+
],
|
|
2155
|
+
shipping: [
|
|
2156
|
+
{
|
|
2157
|
+
q: "When does my order ship?",
|
|
2158
|
+
a: "Within ten working days. Pieces made to order take about three weeks.",
|
|
2159
|
+
},
|
|
2160
|
+
{
|
|
2161
|
+
q: "What if it arrives broken?",
|
|
2162
|
+
a: "Send us a photo within a week and we make you a new one.",
|
|
2163
|
+
},
|
|
2164
|
+
],
|
|
2165
|
+
classes: [
|
|
2166
|
+
{ q: "Do I need any experience?", a: "No. The first evening starts with centring the clay." },
|
|
2167
|
+
{ q: "What should I wear?", a: "Clothes that can get muddy, and short nails." },
|
|
2168
|
+
],
|
|
2169
|
+
};
|
|
2170
|
+
|
|
2171
|
+
function HelpCard() {
|
|
2172
|
+
return (
|
|
2173
|
+
<PreviewCard variant="plain" title="Questions">
|
|
2174
|
+
<Tabs defaultValue="orders">
|
|
2175
|
+
<TabsList variant="underline">
|
|
2176
|
+
<TabsTab value="orders">Orders</TabsTab>
|
|
2177
|
+
<TabsTab value="shipping">Shipping</TabsTab>
|
|
2178
|
+
<TabsTab value="classes">Classes</TabsTab>
|
|
2179
|
+
</TabsList>
|
|
2180
|
+
{(Object.keys(faq) as (keyof typeof faq)[]).map((key) => (
|
|
2181
|
+
<TabsPanel key={key} value={key}>
|
|
2182
|
+
<Accordion defaultValue={[faq[key][0]!.q]}>
|
|
2183
|
+
{faq[key].map((item) => (
|
|
2184
|
+
<AccordionItem key={item.q} value={item.q}>
|
|
2185
|
+
<AccordionTrigger>{item.q}</AccordionTrigger>
|
|
2186
|
+
<AccordionPanel>{item.a}</AccordionPanel>
|
|
2187
|
+
</AccordionItem>
|
|
2188
|
+
))}
|
|
2189
|
+
</Accordion>
|
|
2190
|
+
</TabsPanel>
|
|
2191
|
+
))}
|
|
2192
|
+
</Tabs>
|
|
2193
|
+
</PreviewCard>
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
const products: {
|
|
2198
|
+
name: string;
|
|
2199
|
+
collection: CollectionKey;
|
|
2200
|
+
stock: number;
|
|
2201
|
+
price: string;
|
|
2202
|
+
}[] = [
|
|
2203
|
+
{ name: "Mug", collection: "mugs", stock: 18, price: "€32" },
|
|
2204
|
+
{ name: "Rice bowl", collection: "bowls", stock: 4, price: "€14" },
|
|
2205
|
+
{ name: "Tall vase", collection: "vases", stock: 0, price: "€128" },
|
|
2206
|
+
{ name: "Plate", collection: "plates", stock: 22, price: "€24" },
|
|
2207
|
+
];
|
|
2208
|
+
|
|
2209
|
+
function ProductsCard() {
|
|
2210
|
+
const [inStock, setInStock] = React.useState(false);
|
|
2211
|
+
const shown = inStock ? products.filter((p) => p.stock > 0) : products;
|
|
2212
|
+
return (
|
|
2213
|
+
<PreviewCard variant="plain" title="Products">
|
|
2214
|
+
<Toolbar aria-label="Product actions" className="self-start">
|
|
2215
|
+
<ToolbarButton aria-label="Filter">
|
|
2216
|
+
<ListFilterIcon />
|
|
2217
|
+
</ToolbarButton>
|
|
2218
|
+
<ToolbarSeparator />
|
|
2219
|
+
<ToolbarButton aria-pressed={inStock} onClick={() => setInStock((on) => !on)}>
|
|
2220
|
+
In stock
|
|
2221
|
+
</ToolbarButton>
|
|
2222
|
+
<ToolbarButton>Archive</ToolbarButton>
|
|
2223
|
+
</Toolbar>
|
|
2224
|
+
{/* Tighter cells than a full-width table's, for a column a quarter of the preview wide. */}
|
|
2225
|
+
<Table
|
|
2226
|
+
size="sm"
|
|
2227
|
+
className="[&_:is(th,td)]:px-2.5 [&_:is(th,td):first-child]:ps-4 [&_:is(th,td):last-child]:pe-4"
|
|
2228
|
+
>
|
|
2229
|
+
<TableHeader>
|
|
2230
|
+
<TableRow>
|
|
2231
|
+
<TableHead>Product</TableHead>
|
|
2232
|
+
<TableHead>Stock</TableHead>
|
|
2233
|
+
<TableHead numeric>Price</TableHead>
|
|
2234
|
+
</TableRow>
|
|
2235
|
+
</TableHeader>
|
|
2236
|
+
<TableBody>
|
|
2237
|
+
{shown.map((p) => (
|
|
2238
|
+
<TableRow key={p.name}>
|
|
2239
|
+
<TableCell className="text-foreground">{p.name}</TableCell>
|
|
2240
|
+
<TableCell>
|
|
2241
|
+
{p.stock === 0 ? (
|
|
2242
|
+
<Tag variant="muted">Sold out</Tag>
|
|
2243
|
+
) : p.stock < 5 ? (
|
|
2244
|
+
<Tag tone="warning" dot>
|
|
2245
|
+
{p.stock} left
|
|
2246
|
+
</Tag>
|
|
2247
|
+
) : (
|
|
2248
|
+
<span className="font-mono tabular-nums">{p.stock}</span>
|
|
2249
|
+
)}
|
|
2250
|
+
</TableCell>
|
|
2251
|
+
<TableCell numeric>{p.price}</TableCell>
|
|
2252
|
+
</TableRow>
|
|
2253
|
+
))}
|
|
2254
|
+
</TableBody>
|
|
2255
|
+
</Table>
|
|
2256
|
+
</PreviewCard>
|
|
2257
|
+
);
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
const channels = [
|
|
2261
|
+
{ channel: "online", orders: 212 },
|
|
2262
|
+
{ channel: "studio", orders: 96 },
|
|
2263
|
+
{ channel: "markets", orders: 54 },
|
|
2264
|
+
];
|
|
2265
|
+
|
|
2266
|
+
const channelsConfig = {
|
|
2267
|
+
online: { label: "Online" },
|
|
2268
|
+
studio: { label: "In the studio" },
|
|
2269
|
+
markets: { label: "Markets" },
|
|
2270
|
+
} satisfies ChartConfig;
|
|
2271
|
+
|
|
2272
|
+
const channelTotal = channels.reduce((sum, c) => sum + c.orders, 0);
|
|
2273
|
+
|
|
2274
|
+
function ChannelsCard() {
|
|
2275
|
+
return (
|
|
2276
|
+
<PreviewCard title="Where orders come from" description="July to September.">
|
|
2277
|
+
<ChartContainer
|
|
2278
|
+
config={channelsConfig}
|
|
2279
|
+
palette="tones"
|
|
2280
|
+
className="mx-auto aspect-square w-full max-w-40"
|
|
2281
|
+
aria-label="Orders by channel"
|
|
2282
|
+
>
|
|
2283
|
+
<PieChart>
|
|
2284
|
+
<ChartTooltip content={<ChartTooltipContent nameKey="channel" hideLabel />} />
|
|
2285
|
+
<Pie
|
|
2286
|
+
data={channels}
|
|
2287
|
+
dataKey="orders"
|
|
2288
|
+
nameKey="channel"
|
|
2289
|
+
innerRadius="64%"
|
|
2290
|
+
outerRadius="92%"
|
|
2291
|
+
paddingAngle={2}
|
|
2292
|
+
startAngle={90}
|
|
2293
|
+
endAngle={-270}
|
|
2294
|
+
isAnimationActive={false}
|
|
2295
|
+
>
|
|
2296
|
+
{channels.map((c) => (
|
|
2297
|
+
<Cell key={c.channel} fill={`var(--color-${c.channel})`} />
|
|
2298
|
+
))}
|
|
2299
|
+
</Pie>
|
|
2300
|
+
<text
|
|
2301
|
+
x="50%"
|
|
2302
|
+
y="50%"
|
|
2303
|
+
textAnchor="middle"
|
|
2304
|
+
dominantBaseline="middle"
|
|
2305
|
+
className="fill-foreground font-heading text-[24px] font-light"
|
|
2306
|
+
>
|
|
2307
|
+
{channelTotal}
|
|
2308
|
+
</text>
|
|
2309
|
+
</PieChart>
|
|
2310
|
+
</ChartContainer>
|
|
2311
|
+
<dl className="m-0 flex flex-col">
|
|
2312
|
+
{channels.map((c, i) => (
|
|
2313
|
+
<div
|
|
2314
|
+
key={c.channel}
|
|
2315
|
+
className={cn("flex items-center gap-2 py-2 text-sm", i > 0 && "border-t border-border")}
|
|
2316
|
+
>
|
|
2317
|
+
<span
|
|
2318
|
+
aria-hidden
|
|
2319
|
+
className="size-2 rounded-full"
|
|
2320
|
+
style={{ background: `var(--color-${c.channel})` }}
|
|
2321
|
+
/>
|
|
2322
|
+
<dt className="text-foreground-soft">
|
|
2323
|
+
{channelsConfig[c.channel as keyof typeof channelsConfig].label}
|
|
2324
|
+
</dt>
|
|
2325
|
+
<dd className="ms-auto font-mono text-foreground tabular-nums">
|
|
2326
|
+
{c.orders} · {Math.round((c.orders / channelTotal) * 100)}%
|
|
2327
|
+
</dd>
|
|
2328
|
+
</div>
|
|
2329
|
+
))}
|
|
2330
|
+
</dl>
|
|
2331
|
+
</PreviewCard>
|
|
2332
|
+
);
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
const kilns = [
|
|
2336
|
+
{ name: "Big kiln", state: "Firing", tone: "info", note: "Glaze, 1,180 °C of 1,240", progress: 82 },
|
|
2337
|
+
{ name: "Test kiln", state: "Cooling", tone: "warning", note: "240 °C, open after 16:00", progress: null },
|
|
2338
|
+
{ name: "Raku kiln", state: "Ready", tone: "success", note: "Swept and loaded", progress: null },
|
|
2339
|
+
] as const;
|
|
2340
|
+
|
|
2341
|
+
function KilnsCard() {
|
|
2342
|
+
return (
|
|
2343
|
+
<PreviewCard variant="plain" title="Kilns">
|
|
2344
|
+
{kilns.map((k) => (
|
|
2345
|
+
<div key={k.name} className="flex flex-col gap-2">
|
|
2346
|
+
<div className="flex items-center gap-2">
|
|
2347
|
+
<span className="text-sm text-foreground">{k.name}</span>
|
|
2348
|
+
<span className="ms-auto">
|
|
2349
|
+
<Tag tone={k.tone} dot>
|
|
2350
|
+
{k.state}
|
|
2351
|
+
</Tag>
|
|
2352
|
+
</span>
|
|
2353
|
+
</div>
|
|
2354
|
+
<span className="font-mono text-xs text-muted-foreground">{k.note}</span>
|
|
2355
|
+
{k.progress !== null && <Progress value={k.progress} aria-label={`${k.name} firing`} />}
|
|
2356
|
+
</div>
|
|
2357
|
+
))}
|
|
2358
|
+
</PreviewCard>
|
|
2359
|
+
);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
function FindCard() {
|
|
2363
|
+
return (
|
|
2364
|
+
<PreviewCard
|
|
2365
|
+
title="Find anything"
|
|
2366
|
+
action={
|
|
2367
|
+
<ToggleGroup defaultValue={["list"]} aria-label="View" reveal="label">
|
|
2368
|
+
<ToggleGroupItem value="list" icon={<ListIcon />}>
|
|
2369
|
+
List
|
|
2370
|
+
</ToggleGroupItem>
|
|
2371
|
+
<ToggleGroupItem value="grid" icon={<LayoutGridIcon />}>
|
|
2372
|
+
Grid
|
|
2373
|
+
</ToggleGroupItem>
|
|
2374
|
+
</ToggleGroup>
|
|
2375
|
+
}
|
|
2376
|
+
>
|
|
2377
|
+
<InputGroup>
|
|
2378
|
+
<InputGroupAddon>
|
|
2379
|
+
<SearchIcon />
|
|
2380
|
+
</InputGroupAddon>
|
|
2381
|
+
<InputGroupInput type="search" defaultValue="mug" aria-label="Search the studio" />
|
|
2382
|
+
<InputGroupAddon align="inline-end">
|
|
2383
|
+
<KbdShortcut keys={["mod", "K"]} />
|
|
2384
|
+
</InputGroupAddon>
|
|
2385
|
+
</InputGroup>
|
|
2386
|
+
<ItemGroup className="-mx-2">
|
|
2387
|
+
<Item size="sm" variant="raised">
|
|
2388
|
+
<ItemMedia variant="icon">
|
|
2389
|
+
<CoffeeIcon />
|
|
2390
|
+
</ItemMedia>
|
|
2391
|
+
<ItemContent>
|
|
2392
|
+
<ItemTitle>Speckled mug</ItemTitle>
|
|
2393
|
+
<ItemDescription>Product · 18 in stock</ItemDescription>
|
|
2394
|
+
</ItemContent>
|
|
2395
|
+
<ItemActions>
|
|
2396
|
+
<Kbd>↵</Kbd>
|
|
2397
|
+
</ItemActions>
|
|
2398
|
+
</Item>
|
|
2399
|
+
<Item size="sm">
|
|
2400
|
+
<ItemMedia variant="icon">
|
|
2401
|
+
<InboxIcon />
|
|
2402
|
+
</ItemMedia>
|
|
2403
|
+
<ItemContent>
|
|
2404
|
+
<ItemTitle>#1052, 2 speckled mugs</ItemTitle>
|
|
2405
|
+
<ItemDescription>Order · Ines Duarte</ItemDescription>
|
|
2406
|
+
</ItemContent>
|
|
2407
|
+
</Item>
|
|
2408
|
+
</ItemGroup>
|
|
2409
|
+
</PreviewCard>
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
function NewProductCard() {
|
|
2414
|
+
return (
|
|
2415
|
+
<PreviewCard
|
|
2416
|
+
title="New product"
|
|
2417
|
+
description="Shown in the shop once it has a price."
|
|
2418
|
+
footer={
|
|
2419
|
+
<div className="flex w-full justify-end gap-2">
|
|
2420
|
+
<Button variant="ghost">Discard</Button>
|
|
2421
|
+
<Button variant="secondary">Save draft</Button>
|
|
2422
|
+
</div>
|
|
2423
|
+
}
|
|
2424
|
+
>
|
|
2425
|
+
<Field>
|
|
2426
|
+
<FieldLabel>Name</FieldLabel>
|
|
2427
|
+
<Input defaultValue="Ash-glazed bowl" />
|
|
2428
|
+
</Field>
|
|
2429
|
+
<div className="grid grid-cols-2 gap-3">
|
|
2430
|
+
<Field>
|
|
2431
|
+
<FieldLabel>Price</FieldLabel>
|
|
2432
|
+
<MoneyInput currency="EUR" locale="en-IE" defaultValue="36.00" />
|
|
2433
|
+
</Field>
|
|
2434
|
+
<Field>
|
|
2435
|
+
<FieldLabel>In stock</FieldLabel>
|
|
2436
|
+
<NumberField defaultValue={6} min={0} />
|
|
2437
|
+
</Field>
|
|
2438
|
+
</div>
|
|
2439
|
+
<Label>
|
|
2440
|
+
<Checkbox defaultChecked />
|
|
2441
|
+
Made to order when sold out
|
|
2442
|
+
</Label>
|
|
2443
|
+
</PreviewCard>
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
function TeamCard() {
|
|
2448
|
+
return (
|
|
2449
|
+
<PreviewCard variant="plain" title="Studio team">
|
|
2450
|
+
<div className="flex flex-col">
|
|
2451
|
+
{[
|
|
2452
|
+
{ name: "Mara Kühn", role: "Owner" },
|
|
2453
|
+
{ name: "Jonas Weber", role: "Teaches" },
|
|
2454
|
+
{ name: "Sofia Rossi", role: "Shop" },
|
|
2455
|
+
].map((m, i) => (
|
|
2456
|
+
<div
|
|
2457
|
+
key={m.name}
|
|
2458
|
+
className={cn("flex items-center gap-3 py-2.5", i > 0 && "border-t border-border")}
|
|
2459
|
+
>
|
|
2460
|
+
<Avatar name={m.name} size="sm" />
|
|
2461
|
+
<span className="text-sm text-foreground">{m.name}</span>
|
|
2462
|
+
<span className="ms-auto font-mono text-xs text-muted-foreground">{m.role}</span>
|
|
2463
|
+
</div>
|
|
2464
|
+
))}
|
|
2465
|
+
</div>
|
|
2466
|
+
<InputGroup>
|
|
2467
|
+
<InputGroupAddon>
|
|
2468
|
+
<MailIcon />
|
|
2469
|
+
</InputGroupAddon>
|
|
2470
|
+
<InputGroupInput type="email" placeholder="name@example.com" aria-label="Email to invite" />
|
|
2471
|
+
<InputGroupAddon align="inline-end">
|
|
2472
|
+
<InputGroupButton variant="secondary">
|
|
2473
|
+
<UserPlusIcon />
|
|
2474
|
+
Invite
|
|
2475
|
+
</InputGroupButton>
|
|
2476
|
+
</InputGroupAddon>
|
|
2477
|
+
</InputGroup>
|
|
2478
|
+
</PreviewCard>
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
function OrdersBar() {
|
|
2483
|
+
const [page, setPage] = React.useState(1);
|
|
2484
|
+
return (
|
|
2485
|
+
<PreviewCard
|
|
2486
|
+
variant="plain"
|
|
2487
|
+
title="Orders"
|
|
2488
|
+
action={
|
|
2489
|
+
<Button size="sm" variant="secondary">
|
|
2490
|
+
<PlusIcon />
|
|
2491
|
+
New order
|
|
2492
|
+
</Button>
|
|
2493
|
+
}
|
|
2494
|
+
>
|
|
2495
|
+
<Tabs defaultValue="all">
|
|
2496
|
+
<TabsList variant="underline">
|
|
2497
|
+
{[
|
|
2498
|
+
["all", "All", 128],
|
|
2499
|
+
["unpaid", "Unpaid", 2],
|
|
2500
|
+
["ship", "To ship", 5],
|
|
2501
|
+
].map(([value, label, count]) => (
|
|
2502
|
+
<TabsTab key={value} value={value as string}>
|
|
2503
|
+
{label} <span className="font-mono text-xs text-muted-foreground tabular-nums">{count}</span>
|
|
2504
|
+
</TabsTab>
|
|
2505
|
+
))}
|
|
2506
|
+
</TabsList>
|
|
2507
|
+
</Tabs>
|
|
2508
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
2509
|
+
<span className="font-mono text-xs text-muted-foreground tabular-nums">1–20 of 128</span>
|
|
2510
|
+
<Pagination size="sm" page={page} pageCount={7} siblingCount={0} onPageChange={setPage} />
|
|
2511
|
+
</div>
|
|
2512
|
+
</PreviewCard>
|
|
2513
|
+
);
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
function ProductHeader() {
|
|
2517
|
+
return (
|
|
2518
|
+
<PreviewCard variant="plain" title="Product">
|
|
2519
|
+
<Breadcrumb
|
|
2520
|
+
items={[
|
|
2521
|
+
{ label: "Shop", href: "#shop" },
|
|
2522
|
+
{ label: "Bowls", href: "#bowls" },
|
|
2523
|
+
{ label: "Ash-glazed bowl" },
|
|
2524
|
+
]}
|
|
2525
|
+
/>
|
|
2526
|
+
<div className="flex items-center gap-2">
|
|
2527
|
+
<h4 className="m-0 me-auto font-heading text-2xl font-light text-foreground">Ash-glazed bowl</h4>
|
|
2528
|
+
<Tag tone="success" dot>
|
|
2529
|
+
Live
|
|
2530
|
+
</Tag>
|
|
2531
|
+
</div>
|
|
2532
|
+
<Tabs defaultValue="details">
|
|
2533
|
+
<TabsList variant="underline">
|
|
2534
|
+
<TabsTab value="details">Details</TabsTab>
|
|
2535
|
+
<TabsTab value="photos">Photos</TabsTab>
|
|
2536
|
+
<TabsTab value="stock">Stock</TabsTab>
|
|
2537
|
+
</TabsList>
|
|
2538
|
+
</Tabs>
|
|
2539
|
+
</PreviewCard>
|
|
2540
|
+
);
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
const today = [
|
|
2544
|
+
{
|
|
2545
|
+
icon: CircleCheckIcon,
|
|
2546
|
+
tone: "text-success",
|
|
2547
|
+
title: "#1052 is paid",
|
|
2548
|
+
note: "Ines Duarte, €64.00",
|
|
2549
|
+
time: "09:12",
|
|
2550
|
+
},
|
|
2551
|
+
{
|
|
2552
|
+
icon: InfoIcon,
|
|
2553
|
+
tone: "text-info",
|
|
2554
|
+
title: "Big kiln passed 1,000 °C",
|
|
2555
|
+
note: "Glaze firing, on schedule",
|
|
2556
|
+
time: "10:40",
|
|
2557
|
+
},
|
|
2558
|
+
{
|
|
2559
|
+
icon: TriangleAlertIcon,
|
|
2560
|
+
tone: "text-warning",
|
|
2561
|
+
title: "Porcelain slip is low",
|
|
2562
|
+
note: "4 kg left, about two days",
|
|
2563
|
+
time: "11:05",
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
icon: OctagonXIcon,
|
|
2567
|
+
tone: "text-destructive",
|
|
2568
|
+
title: "Label printer is offline",
|
|
2569
|
+
note: "3 packing slips waiting",
|
|
2570
|
+
time: "11:30",
|
|
2571
|
+
},
|
|
2572
|
+
] as const;
|
|
2573
|
+
|
|
2574
|
+
function TodayCard() {
|
|
2575
|
+
return (
|
|
2576
|
+
<PreviewCard variant="region" title="Today" description="Since the studio opened.">
|
|
2577
|
+
<ul className="m-0 flex list-none flex-col gap-2 p-0">
|
|
2578
|
+
{today.map((t) => (
|
|
2579
|
+
<li key={t.title} className="flex items-start gap-3 rounded-item material-raised px-3 py-2.5">
|
|
2580
|
+
<t.icon aria-hidden className={cn("mt-0.5 size-4 shrink-0", t.tone)} />
|
|
2581
|
+
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
2582
|
+
<span className="text-sm text-foreground">{t.title}</span>
|
|
2583
|
+
<span className="text-[13px] text-muted-foreground">
|
|
2584
|
+
<span className="font-mono text-xs tabular-nums">{t.time}</span> · {t.note}
|
|
2585
|
+
</span>
|
|
2586
|
+
</span>
|
|
2587
|
+
</li>
|
|
2588
|
+
))}
|
|
2589
|
+
</ul>
|
|
2590
|
+
</PreviewCard>
|
|
2591
|
+
);
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
const quickActions = [
|
|
2595
|
+
{ icon: PackageIcon, label: "New product", keys: ["mod", "N"] },
|
|
2596
|
+
{ icon: CalendarPlusIcon, label: "Schedule a class", keys: ["mod", "L"] },
|
|
2597
|
+
{ icon: PrinterIcon, label: "Print packing slips", keys: ["mod", "P"] },
|
|
2598
|
+
{ icon: FlameIcon, label: "Log a firing", keys: ["mod", "F"] },
|
|
2599
|
+
] as const;
|
|
2600
|
+
|
|
2601
|
+
function QuickActionsCard() {
|
|
2602
|
+
return (
|
|
2603
|
+
<PreviewCard title="Quick actions">
|
|
2604
|
+
<InputGroup>
|
|
2605
|
+
<InputGroupAddon>
|
|
2606
|
+
<SearchIcon />
|
|
2607
|
+
</InputGroupAddon>
|
|
2608
|
+
<InputGroupInput placeholder="Type a command" aria-label="Type a command" />
|
|
2609
|
+
</InputGroup>
|
|
2610
|
+
<div className="-mx-2 flex flex-col">
|
|
2611
|
+
<span className="px-2 pt-1 pb-2 eyebrow">Actions</span>
|
|
2612
|
+
<ul className="m-0 flex list-none flex-col p-0">
|
|
2613
|
+
{quickActions.map((a, i) => (
|
|
2614
|
+
<li
|
|
2615
|
+
key={a.label}
|
|
2616
|
+
className={cn(
|
|
2617
|
+
"flex h-(--control-h) items-center gap-3 rounded-item px-2 text-sm text-foreground",
|
|
2618
|
+
i === 0 && "material-row bg-control-hover",
|
|
2619
|
+
)}
|
|
2620
|
+
>
|
|
2621
|
+
<a.icon aria-hidden className="size-4 shrink-0 text-muted-foreground" />
|
|
2622
|
+
<span className="me-auto truncate">{a.label}</span>
|
|
2623
|
+
<KbdShortcut keys={[...a.keys]} />
|
|
2624
|
+
</li>
|
|
2625
|
+
))}
|
|
2626
|
+
</ul>
|
|
2627
|
+
</div>
|
|
2628
|
+
</PreviewCard>
|
|
2629
|
+
);
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
const uploads = [
|
|
2633
|
+
{ name: "ash-bowl-front.jpg", size: "2.4 MB", progress: 100 },
|
|
2634
|
+
{ name: "ash-bowl-top.jpg", size: "1.9 MB", progress: 64 },
|
|
2635
|
+
{ name: "ash-bowl-detail.jpg", size: "3.1 MB", progress: 12 },
|
|
2636
|
+
] as const;
|
|
2637
|
+
|
|
2638
|
+
function UploadsCard() {
|
|
2639
|
+
return (
|
|
2640
|
+
<PreviewCard variant="plain" title="Photos" description="3 of 8 for Ash-glazed bowl.">
|
|
2641
|
+
{uploads.map((u) => (
|
|
2642
|
+
<div key={u.name} className="flex flex-col gap-2">
|
|
2643
|
+
<div className="flex items-center gap-2">
|
|
2644
|
+
<ImageIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />
|
|
2645
|
+
<span className="min-w-0 flex-1 truncate font-mono text-xs text-foreground">{u.name}</span>
|
|
2646
|
+
<span className="font-mono text-xs text-muted-foreground tabular-nums">{u.size}</span>
|
|
2647
|
+
{u.progress === 100 ? (
|
|
2648
|
+
<span className="flex w-8 justify-end">
|
|
2649
|
+
<CircleCheckIcon aria-label="Uploaded" className="size-4 shrink-0 text-success" />
|
|
2650
|
+
</span>
|
|
2651
|
+
) : (
|
|
2652
|
+
<span className="w-8 text-end font-mono text-xs text-muted-foreground tabular-nums">
|
|
2653
|
+
{u.progress}%
|
|
2654
|
+
</span>
|
|
2655
|
+
)}
|
|
2656
|
+
</div>
|
|
2657
|
+
<Progress value={u.progress} aria-label={`Uploading ${u.name}`} />
|
|
2658
|
+
</div>
|
|
2659
|
+
))}
|
|
2660
|
+
<Button variant="secondary" size="sm" className="self-start">
|
|
2661
|
+
<UploadIcon />
|
|
2662
|
+
Add photos
|
|
2663
|
+
</Button>
|
|
2664
|
+
</PreviewCard>
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
function ShippingCard() {
|
|
2669
|
+
return (
|
|
2670
|
+
<PreviewCard
|
|
2671
|
+
title="Ship to"
|
|
2672
|
+
description="#1052 · Ines Duarte"
|
|
2673
|
+
footer={
|
|
2674
|
+
<div className="flex w-full justify-end gap-2">
|
|
2675
|
+
<Button variant="ghost">Cancel</Button>
|
|
2676
|
+
<Button variant="secondary">Save address</Button>
|
|
2677
|
+
</div>
|
|
2678
|
+
}
|
|
2679
|
+
>
|
|
2680
|
+
<Field>
|
|
2681
|
+
<FieldLabel>Street and number</FieldLabel>
|
|
2682
|
+
<Input defaultValue="Rua das Flores 28" autoComplete="street-address" />
|
|
2683
|
+
</Field>
|
|
2684
|
+
<div className="grid grid-cols-[2fr_3fr] gap-3">
|
|
2685
|
+
<Field>
|
|
2686
|
+
<FieldLabel>Postcode</FieldLabel>
|
|
2687
|
+
<Input defaultValue="1200-195" autoComplete="postal-code" />
|
|
2688
|
+
</Field>
|
|
2689
|
+
<Field>
|
|
2690
|
+
<FieldLabel>City</FieldLabel>
|
|
2691
|
+
<Input defaultValue="Lisbon" autoComplete="address-level2" />
|
|
2692
|
+
</Field>
|
|
2693
|
+
</div>
|
|
2694
|
+
<Field>
|
|
2695
|
+
<FieldLabel>Country</FieldLabel>
|
|
2696
|
+
<NativeSelect defaultValue="PT">
|
|
2697
|
+
<NativeSelectOption value="DE">Germany</NativeSelectOption>
|
|
2698
|
+
<NativeSelectOption value="PT">Portugal</NativeSelectOption>
|
|
2699
|
+
<NativeSelectOption value="ES">Spain</NativeSelectOption>
|
|
2700
|
+
</NativeSelect>
|
|
2701
|
+
</Field>
|
|
2702
|
+
<Label>
|
|
2703
|
+
<Checkbox defaultChecked />
|
|
2704
|
+
Bill to the same address
|
|
2705
|
+
</Label>
|
|
2706
|
+
</PreviewCard>
|
|
2707
|
+
);
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
function DeliveryCard() {
|
|
2711
|
+
return (
|
|
2712
|
+
<PreviewCard variant="plain" title="Delivery" description="What the shop offers at checkout.">
|
|
2713
|
+
<RadioGroup defaultValue="post" aria-label="Default delivery" className="flex flex-col">
|
|
2714
|
+
{[
|
|
2715
|
+
{ value: "pickup", title: "Pick up at the studio", note: "Free, Tuesday to Saturday" },
|
|
2716
|
+
{ value: "post", title: "Post, insured", note: "€7.50, 3–5 working days" },
|
|
2717
|
+
{ value: "courier", title: "Courier in the city", note: "€12.00, next working day" },
|
|
2718
|
+
].map((o, i) => (
|
|
2719
|
+
<Label key={o.value} className={cn("items-start gap-3 py-2.5", i > 0 && "border-t border-border")}>
|
|
2720
|
+
<Radio value={o.value} className="mt-0.5" />
|
|
2721
|
+
<span className="flex flex-col gap-0.5">
|
|
2722
|
+
<span>{o.title}</span>
|
|
2723
|
+
<span className="text-[13px] font-normal text-muted-foreground">{o.note}</span>
|
|
2724
|
+
</span>
|
|
2725
|
+
</Label>
|
|
2726
|
+
))}
|
|
2727
|
+
</RadioGroup>
|
|
2728
|
+
<Field>
|
|
2729
|
+
<FieldLabel>Free delivery from</FieldLabel>
|
|
2730
|
+
<MoneyInput currency="EUR" locale="en-IE" defaultValue="80.00" />
|
|
2731
|
+
</Field>
|
|
2732
|
+
</PreviewCard>
|
|
2733
|
+
);
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
function ActivityCard() {
|
|
2737
|
+
return (
|
|
2738
|
+
<PreviewCard variant="region" title="Order #1052">
|
|
2739
|
+
<Timeline aria-label="Order #1052 history">
|
|
2740
|
+
<TimelineItem icon={<TruckIcon />}>
|
|
2741
|
+
<TimelineTitle>
|
|
2742
|
+
<strong>Sofia</strong> booked the post
|
|
2743
|
+
</TimelineTitle>
|
|
2744
|
+
<TimelineTime dateTime="2026-11-11T11:20">20 min ago</TimelineTime>
|
|
2745
|
+
</TimelineItem>
|
|
2746
|
+
<TimelineItem icon={<MessageSquareIcon />}>
|
|
2747
|
+
<TimelineTitle>
|
|
2748
|
+
<strong>Ines Duarte</strong> left a note
|
|
2749
|
+
</TimelineTitle>
|
|
2750
|
+
<TimelineTime dateTime="2026-11-11T09:30">09:30</TimelineTime>
|
|
2751
|
+
<TimelineContent>
|
|
2752
|
+
<TimelineComment>
|
|
2753
|
+
<p>Could the two mugs go in one box? They are a present.</p>
|
|
2754
|
+
</TimelineComment>
|
|
2755
|
+
</TimelineContent>
|
|
2756
|
+
</TimelineItem>
|
|
2757
|
+
<TimelineItem icon={<CircleCheckIcon />} status="success">
|
|
2758
|
+
<TimelineTitle>Paid by card</TimelineTitle>
|
|
2759
|
+
<TimelineTime dateTime="2026-11-11T09:12">09:12</TimelineTime>
|
|
2760
|
+
<TimelineContent>
|
|
2761
|
+
<TimelineChange field="Status" from="Unpaid" to={<Tag tone="success">Paid</Tag>} />
|
|
2762
|
+
</TimelineContent>
|
|
2763
|
+
</TimelineItem>
|
|
2764
|
+
<TimelineItem icon={<InboxIcon />}>
|
|
2765
|
+
<TimelineTitle>
|
|
2766
|
+
<strong>Ines Duarte</strong> placed the order
|
|
2767
|
+
</TimelineTitle>
|
|
2768
|
+
<TimelineTime dateTime="2026-11-11T09:10">09:10</TimelineTime>
|
|
2769
|
+
</TimelineItem>
|
|
2770
|
+
</Timeline>
|
|
2771
|
+
</PreviewCard>
|
|
2772
|
+
);
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
const invoiceLines = [
|
|
2776
|
+
{ what: "Speckled mug", qty: 2, sum: "€64.00" },
|
|
2777
|
+
{ what: "Gift wrap", qty: 1, sum: "€4.00" },
|
|
2778
|
+
{ what: "Post, insured", qty: 1, sum: "€7.50" },
|
|
2779
|
+
] as const;
|
|
2780
|
+
|
|
2781
|
+
function InvoiceCard() {
|
|
2782
|
+
return (
|
|
2783
|
+
<PreviewCard
|
|
2784
|
+
title="Invoice 2026-0412"
|
|
2785
|
+
description="Due 25 November"
|
|
2786
|
+
action={
|
|
2787
|
+
<Tag tone="warning" dot>
|
|
2788
|
+
Open
|
|
2789
|
+
</Tag>
|
|
2790
|
+
}
|
|
2791
|
+
footer={
|
|
2792
|
+
<div className="flex w-full justify-end gap-2">
|
|
2793
|
+
<Button variant="ghost">
|
|
2794
|
+
<DownloadIcon />
|
|
2795
|
+
PDF
|
|
2796
|
+
</Button>
|
|
2797
|
+
<Button variant="secondary">
|
|
2798
|
+
<MailIcon />
|
|
2799
|
+
Send
|
|
2800
|
+
</Button>
|
|
2801
|
+
</div>
|
|
2802
|
+
}
|
|
2803
|
+
>
|
|
2804
|
+
<ul className="m-0 flex list-none flex-col p-0">
|
|
2805
|
+
{invoiceLines.map((l, i) => (
|
|
2806
|
+
<li
|
|
2807
|
+
key={l.what}
|
|
2808
|
+
className={cn("flex items-baseline gap-2 py-2 text-sm", i > 0 && "border-t border-border")}
|
|
2809
|
+
>
|
|
2810
|
+
<span className="me-auto text-foreground">{l.what}</span>
|
|
2811
|
+
<span className="font-mono text-xs text-muted-foreground tabular-nums">× {l.qty}</span>
|
|
2812
|
+
<span className="w-16 text-end font-mono text-foreground tabular-nums">{l.sum}</span>
|
|
2813
|
+
</li>
|
|
2814
|
+
))}
|
|
2815
|
+
</ul>
|
|
2816
|
+
<dl className="m-0 grid grid-cols-[1fr_auto] gap-x-3 gap-y-1 border-t border-border pt-3 text-sm">
|
|
2817
|
+
<dt className="text-muted-foreground">VAT 23%, included</dt>
|
|
2818
|
+
<dd className="m-0 text-end font-mono text-muted-foreground tabular-nums">€14.11</dd>
|
|
2819
|
+
<dt className="font-medium text-foreground">Total</dt>
|
|
2820
|
+
<dd className="m-0 text-end font-mono text-lg text-foreground tabular-nums">€75.50</dd>
|
|
2821
|
+
</dl>
|
|
2822
|
+
</PreviewCard>
|
|
2823
|
+
);
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
function RateClassCard() {
|
|
2827
|
+
return (
|
|
2828
|
+
<PreviewCard
|
|
2829
|
+
title="How was the class?"
|
|
2830
|
+
description="Wheel basics, Thursday evening."
|
|
2831
|
+
footer={
|
|
2832
|
+
<div className="flex w-full justify-end">
|
|
2833
|
+
<Button variant="secondary">
|
|
2834
|
+
<SendIcon className="rtl:-scale-x-100" />
|
|
2835
|
+
Send
|
|
2836
|
+
</Button>
|
|
2837
|
+
</div>
|
|
2838
|
+
}
|
|
2839
|
+
>
|
|
2840
|
+
<Field name="class-rating">
|
|
2841
|
+
<FieldLabel>Your rating</FieldLabel>
|
|
2842
|
+
<Rating defaultValue={4} />
|
|
2843
|
+
</Field>
|
|
2844
|
+
<Field>
|
|
2845
|
+
<FieldLabel>What would you change?</FieldLabel>
|
|
2846
|
+
<Textarea placeholder="More time at the wheel, a slower start …" className="min-h-24" />
|
|
2847
|
+
</Field>
|
|
2848
|
+
</PreviewCard>
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2852
|
+
function OpenClassCard() {
|
|
2853
|
+
return (
|
|
2854
|
+
<PreviewCard variant="plain" title="Open a class">
|
|
2855
|
+
<Stepper
|
|
2856
|
+
orientation="vertical"
|
|
2857
|
+
aria-label="Open a class"
|
|
2858
|
+
value={2}
|
|
2859
|
+
steps={[
|
|
2860
|
+
{ title: "Details", description: "Wheel basics, six evenings" },
|
|
2861
|
+
{ title: "Dates", description: "Thursdays from 8 January" },
|
|
2862
|
+
{ title: "Price and seats", description: "€240, eight seats" },
|
|
2863
|
+
{ title: "Publish", description: "Shown in the shop and the newsletter" },
|
|
2864
|
+
]}
|
|
2865
|
+
/>
|
|
2866
|
+
</PreviewCard>
|
|
2867
|
+
);
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
const packing = [
|
|
2871
|
+
{ label: "Two speckled mugs, wrapped", done: true },
|
|
2872
|
+
{ label: "Card with the note", done: true },
|
|
2873
|
+
{ label: "Box filled, nothing moves", done: false },
|
|
2874
|
+
{ label: "Fragile label on top", done: false },
|
|
2875
|
+
] as const;
|
|
2876
|
+
|
|
2877
|
+
function PackingCard() {
|
|
2878
|
+
return (
|
|
2879
|
+
<PreviewCard
|
|
2880
|
+
variant="region"
|
|
2881
|
+
title="Packing #1052"
|
|
2882
|
+
action={<span className="font-mono text-xs text-muted-foreground tabular-nums">2 / 4</span>}
|
|
2883
|
+
>
|
|
2884
|
+
<div className="flex flex-col gap-3">
|
|
2885
|
+
{packing.map((p) => (
|
|
2886
|
+
<Label key={p.label}>
|
|
2887
|
+
<Checkbox defaultChecked={p.done} />
|
|
2888
|
+
{p.label}
|
|
2889
|
+
</Label>
|
|
2890
|
+
))}
|
|
2891
|
+
</div>
|
|
2892
|
+
</PreviewCard>
|
|
2893
|
+
);
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
function GiftCardCard() {
|
|
2897
|
+
return (
|
|
2898
|
+
<PreviewCard title="Gift card" description="Sold on 2 November, €50.00.">
|
|
2899
|
+
<div className="flex material-field items-center gap-2 rounded-control px-3 py-1.5">
|
|
2900
|
+
<GiftIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />
|
|
2901
|
+
<span className="me-auto font-mono text-sm tracking-wider text-foreground">KILN-7Q4F-2MXA</span>
|
|
2902
|
+
<CopyButton value="KILN-7Q4F-2MXA" size="icon-sm" variant="ghost" />
|
|
2903
|
+
</div>
|
|
2904
|
+
<Meter value={32} max={50} label="Left to spend" format={{ style: "currency", currency: "EUR" }} />
|
|
2905
|
+
</PreviewCard>
|
|
2906
|
+
);
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
/**
|
|
2910
|
+
* In the order a person would read them; Masonry shares them out over the columns. The weights
|
|
2911
|
+
* are their heights at zon's shape in a four-column preview.
|
|
2912
|
+
*/
|
|
2913
|
+
const inUseTiles: Tile[] = [
|
|
2914
|
+
{ key: "orders-bar", weight: 164, node: <OrdersBar /> },
|
|
2915
|
+
{ key: "orders", weight: 412, node: <OrdersChartCard /> },
|
|
2916
|
+
{ key: "firing", weight: 565, node: <FiringCard /> },
|
|
2917
|
+
{ key: "stock", weight: 271, node: <StockCard /> },
|
|
2918
|
+
{ key: "alert", weight: 122, node: <PaymentAlert /> },
|
|
2919
|
+
{ key: "recent", weight: 468, node: <RecentOrdersCard /> },
|
|
2920
|
+
{ key: "today", weight: 500, node: <TodayCard /> },
|
|
2921
|
+
{ key: "takings", weight: 361, node: <TakingsCard /> },
|
|
2922
|
+
{ key: "product", weight: 166, node: <ProductHeader /> },
|
|
2923
|
+
{ key: "products", weight: 265, node: <ProductsCard /> },
|
|
2924
|
+
{ key: "uploads", weight: 227, node: <UploadsCard /> },
|
|
2925
|
+
{ key: "empty", weight: 439, node: <ClassesEmptyCard /> },
|
|
2926
|
+
{ key: "channels", weight: 393, node: <ChannelsCard /> },
|
|
2927
|
+
{ key: "quick", weight: 317, node: <QuickActionsCard /> },
|
|
2928
|
+
{ key: "kilns", weight: 244, node: <KilnsCard /> },
|
|
2929
|
+
{ key: "shipping", weight: 416, node: <ShippingCard /> },
|
|
2930
|
+
{ key: "find", weight: 328, node: <FindCard /> },
|
|
2931
|
+
{ key: "activity", weight: 471, node: <ActivityCard /> },
|
|
2932
|
+
{ key: "classes", weight: 454, node: <ClassesCard /> },
|
|
2933
|
+
{ key: "invoice", weight: 380, node: <InvoiceCard /> },
|
|
2934
|
+
{ key: "notifications", weight: 382, node: <NotificationsCard /> },
|
|
2935
|
+
{ key: "delivery", weight: 351, node: <DeliveryCard /> },
|
|
2936
|
+
{ key: "packing", weight: 218, node: <PackingCard /> },
|
|
2937
|
+
{ key: "help", weight: 413, node: <HelpCard /> },
|
|
2938
|
+
{ key: "open-class", weight: 340, node: <OpenClassCard /> },
|
|
2939
|
+
{ key: "new-product", weight: 379, node: <NewProductCard /> },
|
|
2940
|
+
{ key: "rate", weight: 365, node: <RateClassCard /> },
|
|
2941
|
+
{ key: "gift", weight: 200, node: <GiftCardCard /> },
|
|
2942
|
+
{ key: "team", weight: 243, node: <TeamCard /> },
|
|
2943
|
+
];
|
|
2944
|
+
|
|
2945
|
+
/* ── Page 02: the system, every token and part in the edited theme ──────────── */
|
|
2946
|
+
|
|
2947
|
+
function SwatchCard({
|
|
2948
|
+
title,
|
|
2949
|
+
tokens,
|
|
2950
|
+
palette,
|
|
2951
|
+
}: {
|
|
2952
|
+
title: string;
|
|
2953
|
+
tokens: readonly ThemeToken[];
|
|
2954
|
+
palette: Record<string, ThemeColor>;
|
|
2955
|
+
}) {
|
|
2956
|
+
const names = [...new Set(tokens.map((t) => t.name))];
|
|
2957
|
+
return (
|
|
2958
|
+
<PreviewCard title={title}>
|
|
2959
|
+
<ul className="m-0 grid list-none grid-cols-2 gap-x-3 gap-y-4 p-0">
|
|
2960
|
+
{names.map((name) => {
|
|
2961
|
+
const color = palette[name];
|
|
2962
|
+
return (
|
|
2963
|
+
<li key={name} className="flex min-w-0 flex-col gap-1.5">
|
|
2964
|
+
<span
|
|
2965
|
+
aria-hidden
|
|
2966
|
+
className="h-10 rounded-item border border-field-edge"
|
|
2967
|
+
style={{ background: `var(${name})` }}
|
|
2968
|
+
/>
|
|
2969
|
+
<span className="truncate font-mono text-[11px] text-foreground" title={name}>
|
|
2970
|
+
{name}
|
|
2971
|
+
</span>
|
|
2972
|
+
<span className="truncate font-mono text-[10px] text-muted-foreground">
|
|
2973
|
+
{color ? formatThemeColor(color, "hex") : ""}
|
|
2974
|
+
</span>
|
|
2975
|
+
</li>
|
|
2976
|
+
);
|
|
2977
|
+
})}
|
|
2978
|
+
</ul>
|
|
2979
|
+
</PreviewCard>
|
|
2980
|
+
);
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
function TypeCard() {
|
|
2984
|
+
return (
|
|
2985
|
+
<PreviewCard title="Type" description="Three faces, three jobs.">
|
|
2986
|
+
<div className="flex flex-col gap-1.5">
|
|
2987
|
+
<span className="eyebrow">Licht · headlines, weight 300</span>
|
|
2988
|
+
<p className="m-0 font-heading text-4xl leading-tight font-light text-foreground">
|
|
2989
|
+
Thrown, trimmed, fired.
|
|
2990
|
+
</p>
|
|
2991
|
+
</div>
|
|
2992
|
+
<div className="flex flex-col gap-1.5 border-t border-border pt-4">
|
|
2993
|
+
<span className="eyebrow">Licht Sans · reading and controls</span>
|
|
2994
|
+
<p className="m-0 text-[15px] text-foreground-soft">
|
|
2995
|
+
Every piece is thrown by hand in the studio, dried for a week and fired twice, so no two are quite
|
|
2996
|
+
the same.
|
|
2997
|
+
</p>
|
|
2998
|
+
</div>
|
|
2999
|
+
<div className="flex flex-col gap-1.5 border-t border-border pt-4">
|
|
3000
|
+
<span className="eyebrow">Licht Mono · labels and figures</span>
|
|
3001
|
+
<p className="m-0 font-mono text-sm text-foreground tabular-nums">#1052 · €64.00 · 1,240 °C · W39</p>
|
|
3002
|
+
</div>
|
|
3003
|
+
</PreviewCard>
|
|
3004
|
+
);
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
function ButtonsCard() {
|
|
3008
|
+
return (
|
|
3009
|
+
<PreviewCard title="Buttons" description="One primary per view; the rest raised or flat.">
|
|
3010
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
3011
|
+
<Button>Primary</Button>
|
|
3012
|
+
<Button variant="secondary">Secondary</Button>
|
|
3013
|
+
<Button variant="ghost">Ghost</Button>
|
|
3014
|
+
<Button variant="destructive">Destructive</Button>
|
|
3015
|
+
<Button variant="link">Link</Button>
|
|
3016
|
+
</div>
|
|
3017
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
3018
|
+
<Button variant="secondary" size="sm">
|
|
3019
|
+
Small
|
|
3020
|
+
</Button>
|
|
3021
|
+
<Button variant="secondary">Default</Button>
|
|
3022
|
+
<Button variant="secondary" size="lg">
|
|
3023
|
+
Large
|
|
3024
|
+
</Button>
|
|
3025
|
+
<Button variant="secondary" size="icon" aria-label="Add">
|
|
3026
|
+
<PlusIcon />
|
|
3027
|
+
</Button>
|
|
3028
|
+
<Button variant="secondary" disabled>
|
|
3029
|
+
Disabled
|
|
3030
|
+
</Button>
|
|
3031
|
+
</div>
|
|
3032
|
+
</PreviewCard>
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
function FieldsCard() {
|
|
3037
|
+
return (
|
|
3038
|
+
<PreviewCard title="Fields" description="Recessed, with a label above and help below.">
|
|
3039
|
+
<Field>
|
|
3040
|
+
<FieldLabel>Studio name</FieldLabel>
|
|
3041
|
+
<Input defaultValue="Kiln" />
|
|
3042
|
+
<FieldDescription>Shown on receipts and in the shop.</FieldDescription>
|
|
3043
|
+
</Field>
|
|
3044
|
+
<Field error="Enter an email address, such as studio@kiln.example.">
|
|
3045
|
+
<FieldLabel>Email</FieldLabel>
|
|
3046
|
+
<Input defaultValue="studio@" />
|
|
3047
|
+
<FieldError />
|
|
3048
|
+
</Field>
|
|
3049
|
+
<div className="grid grid-cols-2 gap-3">
|
|
3050
|
+
<Field>
|
|
3051
|
+
<FieldLabel>Currency</FieldLabel>
|
|
3052
|
+
<NativeSelect defaultValue="eur">
|
|
3053
|
+
<NativeSelectOption value="eur">EUR</NativeSelectOption>
|
|
3054
|
+
<NativeSelectOption value="gbp">GBP</NativeSelectOption>
|
|
3055
|
+
</NativeSelect>
|
|
3056
|
+
</Field>
|
|
3057
|
+
<Field disabled>
|
|
3058
|
+
<FieldLabel>VAT number</FieldLabel>
|
|
3059
|
+
<Input placeholder="Not set" />
|
|
3060
|
+
</Field>
|
|
3061
|
+
</div>
|
|
3062
|
+
</PreviewCard>
|
|
3063
|
+
);
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
const statusTags = [
|
|
3067
|
+
{ variant: "success", label: "Paid", icon: CircleCheckIcon, token: "--success" },
|
|
3068
|
+
{ variant: "warning", label: "Unpaid", icon: CircleAlertIcon, token: "--warning" },
|
|
3069
|
+
{ variant: "info", label: "New", icon: InfoIcon, token: "--info" },
|
|
3070
|
+
{ variant: "destructive", label: "Failed", icon: OctagonXIcon, token: "--destructive" },
|
|
3071
|
+
] as const;
|
|
3072
|
+
|
|
3073
|
+
const tones = ["blue", "aqua", "violet", "magenta", "orange", "lime"] as const;
|
|
3074
|
+
|
|
3075
|
+
function TagsCard() {
|
|
3076
|
+
return (
|
|
3077
|
+
<PreviewCard title="Tags" description="Grey by default; colour only for a status or a category.">
|
|
3078
|
+
<div className="flex flex-wrap gap-2">
|
|
3079
|
+
<Tag>Default</Tag>
|
|
3080
|
+
<Tag variant="muted">Muted</Tag>
|
|
3081
|
+
<Tag variant="outline">Outline</Tag>
|
|
3082
|
+
</div>
|
|
3083
|
+
<div className="flex flex-wrap gap-2">
|
|
3084
|
+
{statusTags.map((s) => (
|
|
3085
|
+
<Tag key={s.variant} tone={s.variant} dot>
|
|
3086
|
+
{s.label}
|
|
3087
|
+
</Tag>
|
|
3088
|
+
))}
|
|
3089
|
+
</div>
|
|
3090
|
+
<div className="flex flex-wrap gap-2">
|
|
3091
|
+
{tones.map((t) => (
|
|
3092
|
+
<Tag key={t} tone={t} dot>
|
|
3093
|
+
{t[0]!.toUpperCase() + t.slice(1)}
|
|
3094
|
+
</Tag>
|
|
3095
|
+
))}
|
|
3096
|
+
</div>
|
|
3097
|
+
</PreviewCard>
|
|
3098
|
+
);
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
function StatusCard() {
|
|
3102
|
+
return (
|
|
3103
|
+
<PreviewCard title="Status at work" description="One meaning each, always with words.">
|
|
3104
|
+
<div className="flex flex-col">
|
|
3105
|
+
{statusTags.map((s, i) => (
|
|
3106
|
+
<div
|
|
3107
|
+
key={s.variant}
|
|
3108
|
+
className={cn("flex items-center gap-2.5 py-2", i > 0 && "border-t border-border")}
|
|
3109
|
+
>
|
|
3110
|
+
<s.icon aria-hidden className="size-4" style={{ color: `var(${s.token})` }} />
|
|
3111
|
+
<span className="text-sm text-foreground">{s.label}</span>
|
|
3112
|
+
<span className="ms-auto font-mono text-xs text-muted-foreground">{s.token}</span>
|
|
3113
|
+
</div>
|
|
3114
|
+
))}
|
|
3115
|
+
</div>
|
|
3116
|
+
<Progress value={64} tone="success" label="Orders paid" showValue />
|
|
3117
|
+
<Progress value={38} tone="destructive" label="Upload failed at 38%" showValue />
|
|
3118
|
+
</PreviewCard>
|
|
3119
|
+
);
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
function ChoicesCard() {
|
|
3123
|
+
return (
|
|
3124
|
+
<PreviewCard title="Choices" description="Checked controls take the primary fill.">
|
|
3125
|
+
<div className="grid grid-cols-2 gap-x-4 gap-y-3">
|
|
3126
|
+
<Label>
|
|
3127
|
+
<Checkbox defaultChecked />
|
|
3128
|
+
Glazed
|
|
3129
|
+
</Label>
|
|
3130
|
+
<Label>
|
|
3131
|
+
<Checkbox />
|
|
3132
|
+
Signed
|
|
3133
|
+
</Label>
|
|
3134
|
+
<Label>
|
|
3135
|
+
<Checkbox indeterminate />
|
|
3136
|
+
Some sizes
|
|
3137
|
+
</Label>
|
|
3138
|
+
<Label>
|
|
3139
|
+
<Checkbox disabled />
|
|
3140
|
+
Gift wrap
|
|
3141
|
+
</Label>
|
|
3142
|
+
</div>
|
|
3143
|
+
<RadioGroup
|
|
3144
|
+
defaultValue="matte"
|
|
3145
|
+
aria-label="Finish"
|
|
3146
|
+
className="flex flex-row flex-wrap gap-4 border-t border-border pt-4"
|
|
3147
|
+
>
|
|
3148
|
+
<Label>
|
|
3149
|
+
<Radio value="matte" />
|
|
3150
|
+
Matte
|
|
3151
|
+
</Label>
|
|
3152
|
+
<Label>
|
|
3153
|
+
<Radio value="satin" />
|
|
3154
|
+
Satin
|
|
3155
|
+
</Label>
|
|
3156
|
+
<Label>
|
|
3157
|
+
<Radio value="gloss" />
|
|
3158
|
+
Gloss
|
|
3159
|
+
</Label>
|
|
3160
|
+
</RadioGroup>
|
|
3161
|
+
<div className="flex flex-wrap gap-x-6 gap-y-3 border-t border-border pt-4">
|
|
3162
|
+
<Label>
|
|
3163
|
+
<Switch defaultChecked />
|
|
3164
|
+
On
|
|
3165
|
+
</Label>
|
|
3166
|
+
<Label>
|
|
3167
|
+
<Switch />
|
|
3168
|
+
Off
|
|
3169
|
+
</Label>
|
|
3170
|
+
<Label>
|
|
3171
|
+
<Switch disabled />
|
|
3172
|
+
Disabled
|
|
3173
|
+
</Label>
|
|
3174
|
+
</div>
|
|
3175
|
+
</PreviewCard>
|
|
3176
|
+
);
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
function GroupsCard() {
|
|
3180
|
+
const { container } = usePortal();
|
|
3181
|
+
const [page, setPage] = React.useState(2);
|
|
3182
|
+
return (
|
|
3183
|
+
<PreviewCard
|
|
3184
|
+
title="Groups and overlays"
|
|
3185
|
+
description="Joined buttons, toggles, pages, and what opens over them."
|
|
3186
|
+
>
|
|
3187
|
+
<ButtonGroup aria-label="Piece actions">
|
|
3188
|
+
<Button variant="secondary">
|
|
3189
|
+
<PencilIcon />
|
|
3190
|
+
Edit
|
|
3191
|
+
</Button>
|
|
3192
|
+
<Button variant="secondary">
|
|
3193
|
+
<CopyIcon />
|
|
3194
|
+
Duplicate
|
|
3195
|
+
</Button>
|
|
3196
|
+
<Button variant="secondary" size="icon" aria-label="Archive">
|
|
3197
|
+
<ArchiveIcon />
|
|
3198
|
+
</Button>
|
|
3199
|
+
</ButtonGroup>
|
|
3200
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
3201
|
+
<ToggleGroup defaultValue={["week"]} aria-label="Period">
|
|
3202
|
+
<ToggleGroupItem value="day">Day</ToggleGroupItem>
|
|
3203
|
+
<ToggleGroupItem value="week">Week</ToggleGroupItem>
|
|
3204
|
+
<ToggleGroupItem value="month">Month</ToggleGroupItem>
|
|
3205
|
+
</ToggleGroup>
|
|
3206
|
+
<Toggle defaultPressed aria-label="Show grid">
|
|
3207
|
+
<LayoutGridIcon />
|
|
3208
|
+
Grid
|
|
3209
|
+
</Toggle>
|
|
3210
|
+
</div>
|
|
3211
|
+
<Pagination size="sm" page={page} pageCount={6} onPageChange={setPage} />
|
|
3212
|
+
<div className="flex flex-wrap items-center gap-2 border-t border-border pt-4">
|
|
3213
|
+
<Menu>
|
|
3214
|
+
<MenuTrigger render={<Button variant="secondary" />}>
|
|
3215
|
+
Menu
|
|
3216
|
+
<ChevronDownIcon />
|
|
3217
|
+
</MenuTrigger>
|
|
3218
|
+
<MenuContent portal={{ container }}>
|
|
3219
|
+
<MenuItem>
|
|
3220
|
+
<PencilIcon />
|
|
3221
|
+
Rename
|
|
3222
|
+
</MenuItem>
|
|
3223
|
+
<MenuItem>
|
|
3224
|
+
<CopyIcon />
|
|
3225
|
+
Duplicate
|
|
3226
|
+
</MenuItem>
|
|
3227
|
+
<MenuSeparator />
|
|
3228
|
+
<MenuItem variant="destructive">
|
|
3229
|
+
<XIcon />
|
|
3230
|
+
Delete
|
|
3231
|
+
</MenuItem>
|
|
3232
|
+
</MenuContent>
|
|
3233
|
+
</Menu>
|
|
3234
|
+
<Popover>
|
|
3235
|
+
<PopoverTrigger render={<Button variant="secondary" />}>Popover</PopoverTrigger>
|
|
3236
|
+
<PopoverContent portal={{ container }}>
|
|
3237
|
+
<PopoverTitle>Glaze notes</PopoverTitle>
|
|
3238
|
+
<PopoverDescription>Celadon runs at 1,240 °C. Keep it off the bottom 5 mm.</PopoverDescription>
|
|
3239
|
+
</PopoverContent>
|
|
3240
|
+
</Popover>
|
|
3241
|
+
<Dialog>
|
|
3242
|
+
<DialogTrigger render={<Button variant="secondary" />}>Dialog</DialogTrigger>
|
|
3243
|
+
<DialogContent portal={{ container }} size="sm">
|
|
3244
|
+
<DialogHeader>
|
|
3245
|
+
<DialogTitle>Close the studio for a day?</DialogTitle>
|
|
3246
|
+
<DialogDescription>
|
|
3247
|
+
Classes that day are cancelled and everyone booked gets an email.
|
|
3248
|
+
</DialogDescription>
|
|
3249
|
+
</DialogHeader>
|
|
3250
|
+
<DialogFooter>
|
|
3251
|
+
<DialogClose render={<Button variant="secondary" />}>Keep it open</DialogClose>
|
|
3252
|
+
<DialogClose render={<Button />}>Close for the day</DialogClose>
|
|
3253
|
+
</DialogFooter>
|
|
3254
|
+
</DialogContent>
|
|
3255
|
+
</Dialog>
|
|
3256
|
+
<span className="ms-auto flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
3257
|
+
Search <KbdShortcut keys={["mod", "K"]} />
|
|
3258
|
+
</span>
|
|
3259
|
+
</div>
|
|
3260
|
+
</PreviewCard>
|
|
3261
|
+
);
|
|
3262
|
+
}
|
|
3263
|
+
|
|
3264
|
+
const toneData = [
|
|
3265
|
+
{ tone: "blue", pieces: 46 },
|
|
3266
|
+
{ tone: "aqua", pieces: 31 },
|
|
3267
|
+
{ tone: "violet", pieces: 18 },
|
|
3268
|
+
{ tone: "magenta", pieces: 12 },
|
|
3269
|
+
{ tone: "orange", pieces: 25 },
|
|
3270
|
+
{ tone: "lime", pieces: 9 },
|
|
3271
|
+
];
|
|
3272
|
+
|
|
3273
|
+
const toneConfig = Object.fromEntries(
|
|
3274
|
+
tones.map((t) => [t, { label: t[0]!.toUpperCase() + t.slice(1), color: `var(--tone-${t})` }]),
|
|
3275
|
+
) satisfies ChartConfig;
|
|
3276
|
+
|
|
3277
|
+
/** The two looks of BottomNav on a strip of page each, live: tap, or press and drag the mark. */
|
|
3278
|
+
function BottomNavCard() {
|
|
3279
|
+
const [capsule, setCapsule] = React.useState("shop");
|
|
3280
|
+
const [bar, setBar] = React.useState("shop");
|
|
3281
|
+
const items = (
|
|
3282
|
+
<>
|
|
3283
|
+
<BottomNavItem value="shop" icon={<BottomNavShopIcon />} label="Shop" />
|
|
3284
|
+
<BottomNavItem value="orders" icon={<PackageIcon />} label="Orders" badge={3} />
|
|
3285
|
+
<BottomNavItem value="classes" icon={<BottomNavClassesIcon />} label="Classes" />
|
|
3286
|
+
<BottomNavItem value="account" icon={<BottomNavAccountIcon />} label="Account" />
|
|
3287
|
+
</>
|
|
3288
|
+
);
|
|
3289
|
+
return (
|
|
3290
|
+
<PreviewCard
|
|
3291
|
+
title="Bottom nav"
|
|
3292
|
+
description="A phone's places, as a capsule and as a bar. Tap, or drag the mark."
|
|
3293
|
+
>
|
|
3294
|
+
<div className="flex flex-col gap-3 [--bottom-nav-bar:calc(var(--control-h-lg)+12px)]">
|
|
3295
|
+
{/* Each strip is as tall as its bar, which follows the control height: the capsule with its
|
|
3296
|
+
8px above and 16px below, the bar with its hairline, and the strips' 1px edges. */}
|
|
3297
|
+
<div className="relative h-[calc(var(--bottom-nav-bar)+26px)] overflow-hidden rounded-item border border-border/60 bg-background">
|
|
3298
|
+
<BottomNav
|
|
3299
|
+
variant="capsule"
|
|
3300
|
+
position="absolute"
|
|
3301
|
+
aria-label="Kiln, capsule"
|
|
3302
|
+
value={capsule}
|
|
3303
|
+
onValueChange={setCapsule}
|
|
3304
|
+
>
|
|
3305
|
+
{items}
|
|
3306
|
+
</BottomNav>
|
|
3307
|
+
</div>
|
|
3308
|
+
<div className="relative h-[calc(var(--bottom-nav-bar)+3px)] overflow-hidden rounded-item border border-border/60 bg-background">
|
|
3309
|
+
<BottomNav position="absolute" aria-label="Kiln, bar" value={bar} onValueChange={setBar}>
|
|
3310
|
+
{items}
|
|
3311
|
+
</BottomNav>
|
|
3312
|
+
</div>
|
|
3313
|
+
</div>
|
|
3314
|
+
</PreviewCard>
|
|
3315
|
+
);
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
function TonesChartCard() {
|
|
3319
|
+
return (
|
|
3320
|
+
<PreviewCard title="Tones in a chart" description="Six hues for things people must tell apart.">
|
|
3321
|
+
<ChartContainer config={toneConfig} className="aspect-auto h-40" aria-label="Six category tones">
|
|
3322
|
+
<BarChart data={toneData} margin={{ top: 4, right: 4, left: 0, bottom: 0 }}>
|
|
3323
|
+
<CartesianGrid vertical={false} />
|
|
3324
|
+
<XAxis dataKey="tone" hide />
|
|
3325
|
+
<YAxis width={24} tickMargin={4} />
|
|
3326
|
+
<ChartTooltip content={<ChartTooltipContent nameKey="tone" hideLabel />} />
|
|
3327
|
+
<Bar dataKey="pieces" radius={[3, 3, 0, 0]} maxBarSize={32} isAnimationActive={false}>
|
|
3328
|
+
{toneData.map((d) => (
|
|
3329
|
+
<Cell key={d.tone} fill={`var(--color-${d.tone})`} />
|
|
3330
|
+
))}
|
|
3331
|
+
</Bar>
|
|
3332
|
+
</BarChart>
|
|
3333
|
+
</ChartContainer>
|
|
3334
|
+
<div className="flex flex-wrap gap-2">
|
|
3335
|
+
{toneData.map((d) => (
|
|
3336
|
+
<Tag key={d.tone} tone={d.tone as (typeof tones)[number]} dot>
|
|
3337
|
+
{toneConfig[d.tone]!.label} · {d.pieces}
|
|
3338
|
+
</Tag>
|
|
3339
|
+
))}
|
|
3340
|
+
</div>
|
|
3341
|
+
</PreviewCard>
|
|
3342
|
+
);
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
const radii = [
|
|
3346
|
+
{ token: "--radius-card", label: "Cards" },
|
|
3347
|
+
{ token: "--radius-button", label: "Buttons" },
|
|
3348
|
+
{ token: "--radius-control", label: "Fields" },
|
|
3349
|
+
{ token: "--radius-item", label: "Items" },
|
|
3350
|
+
{ token: "--radius-checkbox", label: "Checkboxes" },
|
|
3351
|
+
];
|
|
3352
|
+
|
|
3353
|
+
/** A shape's radii in px, by token: the button's scaled, the rest at zon's offsets from it. */
|
|
3354
|
+
function radiiOf(shape: ThemeShape): Record<string, number> {
|
|
3355
|
+
const tokens = themeShapeTokens(shape);
|
|
3356
|
+
return Object.fromEntries(radii.map((r) => [r.token, parseInt(tokens[r.token] ?? "0", 10)]));
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
function CornersCard({ shape }: { shape: ThemeShape }) {
|
|
3360
|
+
const px = radiiOf(shape);
|
|
3361
|
+
return (
|
|
3362
|
+
<PreviewCard
|
|
3363
|
+
title="Corners"
|
|
3364
|
+
description={`Buttons at ${Math.round(shape.corners * 100)}% of zon's 12px; the rest keep their distance from them. Regions stay square.`}
|
|
3365
|
+
>
|
|
3366
|
+
<ul className="m-0 grid list-none grid-cols-5 gap-2 p-0">
|
|
3367
|
+
{radii.map((r) => (
|
|
3368
|
+
<li key={r.token} className="flex min-w-0 flex-col items-center gap-1.5">
|
|
3369
|
+
<span
|
|
3370
|
+
aria-hidden
|
|
3371
|
+
className="size-12 border-s-2 border-t-2 border-foreground-soft"
|
|
3372
|
+
style={{ borderStartStartRadius: `var(${r.token})` }}
|
|
3373
|
+
/>
|
|
3374
|
+
<span className="text-xs text-foreground">{r.label}</span>
|
|
3375
|
+
<span className="font-mono text-[10px] text-muted-foreground tabular-nums">{px[r.token]}px</span>
|
|
3376
|
+
</li>
|
|
3377
|
+
))}
|
|
3378
|
+
</ul>
|
|
3379
|
+
</PreviewCard>
|
|
3380
|
+
);
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
function HeightsCard({ shape }: { shape: ThemeShape }) {
|
|
3384
|
+
const h = themeHeights(shape.controlHeight);
|
|
3385
|
+
const rows = [
|
|
3386
|
+
{ size: "sm" as const, label: "Dense", px: h.sm },
|
|
3387
|
+
{ size: "default" as const, label: "Default", px: h.default },
|
|
3388
|
+
{ size: "lg" as const, label: "Prominent", px: h.lg },
|
|
3389
|
+
];
|
|
3390
|
+
return (
|
|
3391
|
+
<PreviewCard
|
|
3392
|
+
title="Density"
|
|
3393
|
+
description="Every button, field and select takes these heights; padding, gaps and type follow."
|
|
3394
|
+
>
|
|
3395
|
+
{rows.map((r) => (
|
|
3396
|
+
<div key={r.size} className="flex items-center gap-3">
|
|
3397
|
+
<span className="w-24 shrink-0 font-mono text-xs text-muted-foreground tabular-nums">
|
|
3398
|
+
{r.label} {r.px}
|
|
3399
|
+
</span>
|
|
3400
|
+
{r.size !== "lg" && <Input size={r.size} placeholder="Field" aria-label={`${r.label} field`} />}
|
|
3401
|
+
<Button variant="secondary" size={r.size} className="shrink-0">
|
|
3402
|
+
Button
|
|
3403
|
+
</Button>
|
|
3404
|
+
</div>
|
|
3405
|
+
))}
|
|
3406
|
+
</PreviewCard>
|
|
3407
|
+
);
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
function AlertsCard() {
|
|
3411
|
+
return (
|
|
3412
|
+
<PreviewCard
|
|
3413
|
+
variant="plain"
|
|
3414
|
+
title="Alerts"
|
|
3415
|
+
description="Square regions; the colour is on the icon and title."
|
|
3416
|
+
>
|
|
3417
|
+
<Alert>
|
|
3418
|
+
<InfoIcon />
|
|
3419
|
+
<AlertTitle>Default</AlertTitle>
|
|
3420
|
+
<AlertDescription>The studio is closed on 24 December.</AlertDescription>
|
|
3421
|
+
</Alert>
|
|
3422
|
+
<Alert tone="success">
|
|
3423
|
+
<CircleCheckIcon />
|
|
3424
|
+
<AlertTitle>Success</AlertTitle>
|
|
3425
|
+
<AlertDescription>Order #1052 is paid.</AlertDescription>
|
|
3426
|
+
</Alert>
|
|
3427
|
+
<Alert tone="destructive">
|
|
3428
|
+
<OctagonXIcon />
|
|
3429
|
+
<AlertTitle>Destructive</AlertTitle>
|
|
3430
|
+
<AlertDescription>The label printer is offline.</AlertDescription>
|
|
3431
|
+
</Alert>
|
|
3432
|
+
</PreviewCard>
|
|
3433
|
+
);
|
|
3434
|
+
}
|
|
3435
|
+
|
|
3436
|
+
function ItemsCard() {
|
|
3437
|
+
return (
|
|
3438
|
+
<PreviewCard title="Items" description="Flat with hairlines, outlined or raised.">
|
|
3439
|
+
{(["default", "outline", "raised"] as const).map((variant) => (
|
|
3440
|
+
<Item key={variant} size="sm" variant={variant}>
|
|
3441
|
+
<ItemMedia variant="icon">
|
|
3442
|
+
<PackageIcon />
|
|
3443
|
+
</ItemMedia>
|
|
3444
|
+
<ItemContent>
|
|
3445
|
+
<ItemTitle className="capitalize">{variant}</ItemTitle>
|
|
3446
|
+
<ItemDescription>Ash-glazed bowl · 6 in stock</ItemDescription>
|
|
3447
|
+
</ItemContent>
|
|
3448
|
+
<ItemActions>
|
|
3449
|
+
<Kbd>↵</Kbd>
|
|
3450
|
+
</ItemActions>
|
|
3451
|
+
</Item>
|
|
3452
|
+
))}
|
|
3453
|
+
</PreviewCard>
|
|
3454
|
+
);
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3457
|
+
function RangesCard() {
|
|
3458
|
+
return (
|
|
3459
|
+
<PreviewCard title="Ranges" description="Recessed tracks, the foreground ink on them.">
|
|
3460
|
+
<Progress value={72} label="Glaze firing" showValue />
|
|
3461
|
+
<Meter value={0.4} label="Clay left" showValue format={{ style: "percent" }} />
|
|
3462
|
+
<Slider defaultValue={[1180, 1240]} min={900} max={1300} step={10} aria-label="Firing range" />
|
|
3463
|
+
<div className="flex items-center gap-3">
|
|
3464
|
+
<Avatar name="Mara Kühn" size="sm" />
|
|
3465
|
+
<Rating readOnly size="sm" value={4.5} />
|
|
3466
|
+
<span className="ms-auto font-mono text-xs text-muted-foreground tabular-nums">4.5 / 5</span>
|
|
3467
|
+
</div>
|
|
3468
|
+
</PreviewCard>
|
|
3469
|
+
);
|
|
3470
|
+
}
|
|
3471
|
+
|
|
3472
|
+
/** Page 02 follows the colours and the shape, so it is built again when they change. */
|
|
3473
|
+
function systemTiles(palette: Record<string, ThemeColor>, shape: ThemeShape): Tile[] {
|
|
3474
|
+
const groups = themeTokenGroups.map((g) => ({
|
|
3475
|
+
key: `tokens-${g.title}`,
|
|
3476
|
+
weight: 80 + Math.ceil(new Set(g.tokens.map((t) => t.name)).size / 2) * 84,
|
|
3477
|
+
node: <SwatchCard title={g.title} tokens={g.tokens} palette={palette} />,
|
|
3478
|
+
}));
|
|
3479
|
+
return [
|
|
3480
|
+
groups[0]!,
|
|
3481
|
+
{ key: "type", weight: 560, node: <TypeCard /> },
|
|
3482
|
+
{ key: "buttons", weight: 388, node: <ButtonsCard /> },
|
|
3483
|
+
groups[1]!,
|
|
3484
|
+
{ key: "fields", weight: 426, node: <FieldsCard /> },
|
|
3485
|
+
{ key: "tags", weight: 312, node: <TagsCard /> },
|
|
3486
|
+
...groups.slice(2, 4),
|
|
3487
|
+
{ key: "status", weight: 370, node: <StatusCard /> },
|
|
3488
|
+
{ key: "choices", weight: 370, node: <ChoicesCard /> },
|
|
3489
|
+
...groups.slice(4),
|
|
3490
|
+
{ key: "tones", weight: 416, node: <TonesChartCard /> },
|
|
3491
|
+
{ key: "alerts", weight: 368, node: <AlertsCard /> },
|
|
3492
|
+
{ key: "items", weight: 396, node: <ItemsCard /> },
|
|
3493
|
+
{ key: "ranges", weight: 287, node: <RangesCard /> },
|
|
3494
|
+
{ key: "groups", weight: 457, node: <GroupsCard /> },
|
|
3495
|
+
{ key: "bottom-nav", weight: 300, node: <BottomNavCard /> },
|
|
3496
|
+
{ key: "corners", weight: 245, node: <CornersCard shape={shape} /> },
|
|
3497
|
+
{ key: "heights", weight: 270, node: <HeightsCard shape={shape} /> },
|
|
3498
|
+
];
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
export function ThemeEditor({ createCommand }: ThemeEditorProps = {}) {
|
|
3502
|
+
const [state, setState] = React.useState<Saved>(load);
|
|
3503
|
+
const [mode, setMode] = React.useState<Mode>(() =>
|
|
3504
|
+
typeof document !== "undefined" && document.documentElement.classList.contains("dark") ? "dark" : "light",
|
|
3505
|
+
);
|
|
3506
|
+
const [selected, setSelected] = React.useState<string | null>(null);
|
|
3507
|
+
const [onlyChanges, setOnlyChanges] = React.useState(true);
|
|
3508
|
+
const [format, setFormat] = React.useState<Format>("oklch");
|
|
3509
|
+
const [page, setPage] = React.useState<PreviewPage>("use");
|
|
3510
|
+
const [root, setRoot] = React.useState<HTMLDivElement | null>(null);
|
|
3511
|
+
const wide = useWide(root);
|
|
3512
|
+
// The controls follow the pointer at once; everything the colours feed (the palette, the
|
|
3513
|
+
// summary, the token list, the preview) follows a step behind, and skips steps while busy.
|
|
3514
|
+
const shown = React.useDeferredValue(state);
|
|
3515
|
+
const preset = state.preset;
|
|
3516
|
+
const code = React.useMemo(() => encodeThemePreset(preset), [preset]);
|
|
3517
|
+
|
|
3518
|
+
// Saved once the controls rest, not on every step of a drag.
|
|
3519
|
+
React.useEffect(() => {
|
|
3520
|
+
const timer = window.setTimeout(() => {
|
|
3521
|
+
try {
|
|
3522
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
|
3523
|
+
} catch {
|
|
3524
|
+
/* private window or blocked storage: the editor still works, it just forgets */
|
|
3525
|
+
}
|
|
3526
|
+
}, 300);
|
|
3527
|
+
return () => window.clearTimeout(timer);
|
|
3528
|
+
}, [state]);
|
|
3529
|
+
|
|
3530
|
+
const themes = React.useMemo(
|
|
3531
|
+
() => ({ light: themePalette(shown.preset, "light"), dark: themePalette(shown.preset, "dark") }),
|
|
3532
|
+
[shown.preset],
|
|
3533
|
+
);
|
|
3534
|
+
const values = React.useMemo<ThemeValues>(
|
|
3535
|
+
() => themeFromPreset(shown.preset, { format, onlyChanges }),
|
|
3536
|
+
[shown.preset, format, onlyChanges],
|
|
3537
|
+
);
|
|
3538
|
+
// How many text colours fall below their contrast in the theme shown.
|
|
3539
|
+
const failing = React.useMemo(() => countFailing(themes[mode]), [themes, mode]);
|
|
3540
|
+
|
|
3541
|
+
// The preview's colours go straight onto its element as custom properties, so a drag
|
|
3542
|
+
// restyles it without React rendering its components again.
|
|
3543
|
+
const palette = themes[mode];
|
|
3544
|
+
const paletteRef = React.useRef(palette);
|
|
3545
|
+
const shape = shown.preset.shape;
|
|
3546
|
+
const shapeRef = React.useRef(shape);
|
|
3547
|
+
paletteRef.current = palette;
|
|
3548
|
+
shapeRef.current = shape;
|
|
3549
|
+
const previewEl = React.useRef<HTMLDivElement | null>(null);
|
|
3550
|
+
const appliedShape = React.useRef("");
|
|
3551
|
+
const restyle = React.useCallback(() => {
|
|
3552
|
+
const el = previewEl.current;
|
|
3553
|
+
if (!el) return;
|
|
3554
|
+
// A new height or new corners change how tall the cards are. The card at the top of the view
|
|
3555
|
+
// stays where it is, so what you were looking at stays in front of you.
|
|
3556
|
+
const key = JSON.stringify(shapeRef.current);
|
|
3557
|
+
const anchor = key !== appliedShape.current ? findAnchor(el) : null;
|
|
3558
|
+
appliedShape.current = key;
|
|
3559
|
+
applyPalette(el, paletteRef.current, shapeRef.current);
|
|
3560
|
+
if (anchor) keepAnchor(anchor);
|
|
3561
|
+
}, []);
|
|
3562
|
+
const attachPreview = React.useCallback(
|
|
3563
|
+
(el: HTMLDivElement | null) => {
|
|
3564
|
+
previewEl.current = el;
|
|
3565
|
+
restyle();
|
|
3566
|
+
},
|
|
3567
|
+
[restyle],
|
|
3568
|
+
);
|
|
3569
|
+
// Restyling the whole preview is the expensive part of a change, so it happens at most every
|
|
3570
|
+
// PREVIEW_INTERVAL ms, always ending on the latest colours.
|
|
3571
|
+
const applied = React.useRef(0);
|
|
3572
|
+
const pending = React.useRef(0);
|
|
3573
|
+
React.useEffect(() => {
|
|
3574
|
+
const run = () => {
|
|
3575
|
+
applied.current = performance.now();
|
|
3576
|
+
restyle();
|
|
3577
|
+
};
|
|
3578
|
+
const wait = PREVIEW_INTERVAL - (performance.now() - applied.current);
|
|
3579
|
+
window.clearTimeout(pending.current);
|
|
3580
|
+
pending.current = window.setTimeout(() => requestAnimationFrame(run), Math.max(0, wait));
|
|
3581
|
+
return () => window.clearTimeout(pending.current);
|
|
3582
|
+
}, [palette, shape, restyle]);
|
|
3583
|
+
|
|
3584
|
+
const update = React.useCallback(
|
|
3585
|
+
(next: (s: Saved) => Saved) =>
|
|
3586
|
+
setState((s) => {
|
|
3587
|
+
const out = next(s);
|
|
3588
|
+
return { ...out, preset: normalizeThemePreset(out.preset) };
|
|
3589
|
+
}),
|
|
3590
|
+
[],
|
|
3591
|
+
);
|
|
3592
|
+
const setSettings = React.useCallback(
|
|
3593
|
+
(patch: Partial<ThemeSettings>) =>
|
|
3594
|
+
update((s) => ({ ...s, preset: { ...s.preset, settings: { ...s.preset.settings, ...patch } } })),
|
|
3595
|
+
[update],
|
|
3596
|
+
);
|
|
3597
|
+
const setShape = React.useCallback(
|
|
3598
|
+
(patch: Partial<ThemeShape>) =>
|
|
3599
|
+
update((s) => ({ ...s, preset: { ...s.preset, shape: { ...s.preset.shape, ...patch } } })),
|
|
3600
|
+
[update],
|
|
3601
|
+
);
|
|
3602
|
+
const pickSeed = React.useCallback(
|
|
3603
|
+
(seed: Seed, color: ThemeColor) =>
|
|
3604
|
+
update((s) => ({
|
|
3605
|
+
...s,
|
|
3606
|
+
preset: { ...s.preset, settings: { ...s.preset.settings, ...fromSeed(seed, color) } },
|
|
3607
|
+
anchors: { ...s.anchors, [seed]: color },
|
|
3608
|
+
})),
|
|
3609
|
+
[update],
|
|
3610
|
+
);
|
|
3611
|
+
const keepSeed = React.useCallback(
|
|
3612
|
+
(seed: Seed, keep: boolean) =>
|
|
3613
|
+
update((s) => ({ ...s, preset: { ...s.preset, seeds: { ...s.preset.seeds, [seed]: keep } } })),
|
|
3614
|
+
[update],
|
|
3615
|
+
);
|
|
3616
|
+
// A family picked gives its seed a colour from it at once, kept or not: it was asked for.
|
|
3617
|
+
const pickFamily = React.useCallback(
|
|
3618
|
+
(seed: Seed, id: string) =>
|
|
3619
|
+
update((s) => {
|
|
3620
|
+
const family = familyOf(seed, id);
|
|
3621
|
+
const { [seed]: _, ...families } = s.families;
|
|
3622
|
+
return {
|
|
3623
|
+
...s,
|
|
3624
|
+
families: family ? { ...families, [seed]: id } : families,
|
|
3625
|
+
preset: {
|
|
3626
|
+
...s.preset,
|
|
3627
|
+
settings: { ...s.preset.settings, ...draw(seed, family, s.preset.settings) },
|
|
3628
|
+
},
|
|
3629
|
+
};
|
|
3630
|
+
}),
|
|
3631
|
+
[update],
|
|
3632
|
+
);
|
|
3633
|
+
const onShuffle = React.useCallback(
|
|
3634
|
+
() =>
|
|
3635
|
+
update((s) => ({
|
|
3636
|
+
...s,
|
|
3637
|
+
preset: { ...s.preset, settings: shuffle(s.preset.settings, s.preset.seeds, s.families) },
|
|
3638
|
+
})),
|
|
3639
|
+
[update],
|
|
3640
|
+
);
|
|
3641
|
+
const loadCode = React.useCallback(
|
|
3642
|
+
(next: ThemePreset) => setState((s) => ({ ...s, preset: next, anchors: {} })),
|
|
3643
|
+
[],
|
|
3644
|
+
);
|
|
3645
|
+
const reset = React.useCallback(() => setState(empty), []);
|
|
3646
|
+
const unpinAll = React.useCallback(
|
|
3647
|
+
() => update((s) => ({ ...s, preset: { ...s.preset, pinned: { light: {}, dark: {} } } })),
|
|
3648
|
+
[update],
|
|
3649
|
+
);
|
|
3650
|
+
const pin = React.useCallback(
|
|
3651
|
+
(name: string, color: ThemeColor) =>
|
|
3652
|
+
update((s) => ({
|
|
3653
|
+
...s,
|
|
3654
|
+
preset: {
|
|
3655
|
+
...s.preset,
|
|
3656
|
+
pinned: { ...s.preset.pinned, [mode]: { ...s.preset.pinned[mode], [name]: color } },
|
|
3657
|
+
},
|
|
3658
|
+
})),
|
|
3659
|
+
[mode, update],
|
|
3660
|
+
);
|
|
3661
|
+
const unpin = React.useCallback(
|
|
3662
|
+
(name: string) =>
|
|
3663
|
+
update((s) => {
|
|
3664
|
+
const { [name]: _, ...rest } = s.preset.pinned[mode];
|
|
3665
|
+
return { ...s, preset: { ...s.preset, pinned: { ...s.preset.pinned, [mode]: rest } } };
|
|
3666
|
+
}),
|
|
3667
|
+
[mode, update],
|
|
3668
|
+
);
|
|
3669
|
+
|
|
3670
|
+
const pins = Object.keys(preset.pinned.light).length + Object.keys(preset.pinned.dark).length;
|
|
3671
|
+
|
|
3672
|
+
const controls = (
|
|
3673
|
+
<Controls
|
|
3674
|
+
preset={preset}
|
|
3675
|
+
anchors={state.anchors}
|
|
3676
|
+
families={state.families}
|
|
3677
|
+
failing={failing}
|
|
3678
|
+
mode={mode}
|
|
3679
|
+
wide={wide}
|
|
3680
|
+
onSettings={setSettings}
|
|
3681
|
+
onShape={setShape}
|
|
3682
|
+
onPick={pickSeed}
|
|
3683
|
+
onKeep={keepSeed}
|
|
3684
|
+
onFamily={pickFamily}
|
|
3685
|
+
onUnpinAll={unpinAll}
|
|
3686
|
+
tokens={
|
|
3687
|
+
<TokenList
|
|
3688
|
+
palette={palette}
|
|
3689
|
+
pinned={preset.pinned[mode]}
|
|
3690
|
+
mode={mode}
|
|
3691
|
+
selected={selected}
|
|
3692
|
+
onSelect={setSelected}
|
|
3693
|
+
onPin={pin}
|
|
3694
|
+
onUnpin={unpin}
|
|
3695
|
+
/>
|
|
3696
|
+
}
|
|
3697
|
+
/>
|
|
3698
|
+
);
|
|
3699
|
+
|
|
3700
|
+
return (
|
|
3701
|
+
<div ref={setRoot} data-slot="theme-editor" className="w-full">
|
|
3702
|
+
<div
|
|
3703
|
+
className={cn(
|
|
3704
|
+
"flex w-full surface-container",
|
|
3705
|
+
wide ? "h-(--theme-editor-height,780px) overflow-hidden" : "flex-col",
|
|
3706
|
+
)}
|
|
3707
|
+
>
|
|
3708
|
+
<aside
|
|
3709
|
+
aria-label="Theme settings"
|
|
3710
|
+
className={cn(
|
|
3711
|
+
"@container/menu flex flex-col",
|
|
3712
|
+
wide ? "w-[340px] shrink-0 border-e border-border" : "border-b border-border",
|
|
3713
|
+
)}
|
|
3714
|
+
>
|
|
3715
|
+
<MenuHeader isZon={code === ZON_CODE} mode={mode} onMode={setMode} onReset={reset} />
|
|
3716
|
+
{wide ? <ScrollArea className="min-h-0 flex-1">{controls}</ScrollArea> : controls}
|
|
3717
|
+
<MenuFooter
|
|
3718
|
+
code={code}
|
|
3719
|
+
pins={pins}
|
|
3720
|
+
values={values}
|
|
3721
|
+
onLoad={loadCode}
|
|
3722
|
+
onShuffle={onShuffle}
|
|
3723
|
+
onlyChanges={onlyChanges}
|
|
3724
|
+
onOnlyChanges={setOnlyChanges}
|
|
3725
|
+
format={format}
|
|
3726
|
+
onFormat={setFormat}
|
|
3727
|
+
createCommand={createCommand}
|
|
3728
|
+
/>
|
|
3729
|
+
</aside>
|
|
3730
|
+
<Preview
|
|
3731
|
+
mode={mode}
|
|
3732
|
+
page={page}
|
|
3733
|
+
onPage={setPage}
|
|
3734
|
+
palette={palette}
|
|
3735
|
+
shape={shape}
|
|
3736
|
+
attach={attachPreview}
|
|
3737
|
+
className={wide ? "min-h-0 flex-1 overflow-auto" : undefined}
|
|
3738
|
+
/>
|
|
3739
|
+
</div>
|
|
3740
|
+
</div>
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
```
|
|
3744
|
+
|
|
3745
|
+
Makes zon's theme your own (colours, control height, corners) without touching components. Edit on the left, preview a real app on the right, take it away as a preset code, `theme.json`, CSS or an AI prompt.
|
|
3746
|
+
|
|
3747
|
+
## Usage
|
|
3748
|
+
|
|
3749
|
+
The code is the whole theme in 16 letters and digits, such as `Z100CC8PWCHOK8M4` (zon's own). Give it to the provider:
|
|
3750
|
+
|
|
3751
|
+
```tsx
|
|
3752
|
+
import { ThemeProvider } from "@zonsh/ui";
|
|
3753
|
+
|
|
3754
|
+
<ThemeProvider preset="Z11ARFCXWTUPYKES">
|
|
3755
|
+
<App />
|
|
3756
|
+
</ThemeProvider>;
|
|
3757
|
+
```
|
|
3758
|
+
|
|
3759
|
+
- `preset` — a code, preset or `theme.json` (also on `ThemeScope`).
|
|
3760
|
+
- `themeFromPreset(code).css` — the theme as CSS.
|
|
3761
|
+
- `themePresetFromColor(colour)` — a preset from one brand colour.
|
|
3762
|
+
|
|
3763
|
+
The provider adds the stylesheet to `<head>` at runtime; an unreadable code keeps zon's theme and warns in development. For a server-rendered first paint, use `themeFromPreset` (server-safe):
|
|
3764
|
+
|
|
3765
|
+
```tsx
|
|
3766
|
+
import { themeFromPreset } from "@zonsh/ui";
|
|
3767
|
+
|
|
3768
|
+
const theme = themeFromPreset("Z11ARFCXWTUPYKES");
|
|
3769
|
+
|
|
3770
|
+
// In <head>, after the library's stylesheet (a Next.js root layout, say):
|
|
3771
|
+
<style dangerouslySetInnerHTML={{ __html: theme.css }} />;
|
|
3772
|
+
```
|
|
3773
|
+
|
|
3774
|
+
`theme.css` goes after `@import "@zonsh/ui/styles.css";`; `theme.light`, `theme.dark` and `theme.shape` are token maps. An agent given a code pastes `themeFromPreset(code).css`.
|
|
3775
|
+
|
|
3776
|
+
## When to use
|
|
3777
|
+
|
|
3778
|
+
- A product's own colours (a warmer paper, a tinted slate, a coloured primary), handed on as a code or data.
|
|
3779
|
+
- One brand colour needs no editor: `themePresetFromColor("#c2410c")` or `pnpm create zon@latest theme --color "#c2410c"` (see Theme, "Your own colour"); open its code here to fine-tune.
|
|
3780
|
+
- Not for one-off colours in a page: use semantic tokens.
|
|
3781
|
+
|
|
3782
|
+
## The editor
|
|
3783
|
+
|
|
3784
|
+
**The menu (left).** Three seeds: **Background** tints the greys (page, surfaces, edges, text), **Accent** colours the primary, checked controls and the focus outline, **Categories** turns the six category tones (not the status colours). Each row has a **family**, the colour and **Keep**. **Shuffle** draws the seed from its family (**Any**, or Neutral, Stone, Slate, Red … Rose); picking one sets a colour at once. Press the colour to fine-tune; **Keep** leaves the seed out of Shuffle.
|
|
3785
|
+
|
|
3786
|
+
**Corners** steps the button's radius by 25% of zon's 12px (0 to 200%), other radii keeping their distance as nested shapes do. **Density** sets the default control height in 4px steps (30 to 46, Dense to Spacious). Press a row for its slider, drag along it, or use the arrows. **Advanced** holds the generator's sliders and every token (set by L, C, H or pasted, then pinned). Top: **Back to zon**, Light or Dark, and contrast warnings. Bottom: the **preset code**, **Open preset**, **Shuffle**, **Use this theme**.
|
|
3787
|
+
|
|
3788
|
+
**The preview (right)**: **01 In use** is Kiln, a ceramics studio's app, in real-size fragments; **02 System** shows every token, face, button, field, tag, control, overlay and the shape. Overlays open inside it, in the new colours. Tiles sit in one to five columns (each at least 240px) and keep their column; below 896px the menu sits above. Text below 4.5:1 says so and offers a fix.
|
|
3789
|
+
|
|
3790
|
+
**Use this theme** gives each way to take it with a copy button: the code, `<ThemeProvider preset="…">`, the create command, `theme.json`, CSS and an AI prompt (only changes, OKLCH or hex, if you like). Work is kept in this browser; the code leaves out families, which only steer Shuffle.
|
|
3791
|
+
|
|
3792
|
+
## Exports
|
|
3793
|
+
|
|
3794
|
+
### The export
|
|
3795
|
+
|
|
3796
|
+
The export is a set of token overrides. Paste the CSS after the library's stylesheet:
|
|
3797
|
+
|
|
3798
|
+
```css
|
|
3799
|
+
@import "tailwindcss";
|
|
3800
|
+
@import "@zonsh/ui/styles.css";
|
|
3801
|
+
|
|
3802
|
+
:root,
|
|
3803
|
+
.theme-light {
|
|
3804
|
+
--background: oklch(0.985 0.012 80);
|
|
3805
|
+
--primary-fill: oklch(0.45 0.162 265);
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3808
|
+
.dark,
|
|
3809
|
+
[data-theme="dark"],
|
|
3810
|
+
.theme-dark {
|
|
3811
|
+
--background: oklch(0.07 0.012 80);
|
|
3812
|
+
--primary-fill: oklch(0.74 0.162 265);
|
|
3813
|
+
}
|
|
3814
|
+
```
|
|
3815
|
+
|
|
3816
|
+
Always shape, light, dark, one token per line under group comments, no dates.
|
|
3817
|
+
|
|
3818
|
+
### theme.json: a theme to commit
|
|
3819
|
+
|
|
3820
|
+
Commit the JSON as `theme.json` so changes get reviewed, and give it to the provider:
|
|
3821
|
+
|
|
3822
|
+
```tsx
|
|
3823
|
+
import { ThemeProvider } from "@zonsh/ui";
|
|
3824
|
+
import theme from "./theme.json";
|
|
3825
|
+
|
|
3826
|
+
<ThemeProvider preset={theme}>
|
|
3827
|
+
<App />
|
|
3828
|
+
</ThemeProvider>;
|
|
3829
|
+
```
|
|
3830
|
+
|
|
3831
|
+
```json
|
|
3832
|
+
{
|
|
3833
|
+
"name": "zon theme",
|
|
3834
|
+
"for": "@zonsh/ui",
|
|
3835
|
+
"version": 1,
|
|
3836
|
+
"preset": "Z11ARFCXWTUPYKES",
|
|
3837
|
+
"shape": {
|
|
3838
|
+
"--density": "1.105",
|
|
3839
|
+
"--control-h": "42px"
|
|
3840
|
+
},
|
|
3841
|
+
"light": {
|
|
3842
|
+
"--background": "oklch(0.974 0.012 255)",
|
|
3843
|
+
"--foreground": "oklch(0.145 0.012 255)"
|
|
3844
|
+
},
|
|
3845
|
+
"dark": {
|
|
3846
|
+
"--background": "oklch(0.07 0.012 255)"
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
```
|
|
3850
|
+
|
|
3851
|
+
The code is the theme; `shape`, `light` and `dark` spell out its tokens in a fixed order, so diffs show changed tokens and rewrites without changes have none. `themeFromPreset(preset).json` writes it (a build script, a CI check).
|
|
3852
|
+
|
|
3853
|
+
A hand-edited value wins and counts as pinned; text on an edited ground still moves until it reads, and hover fills follow. A file of changes only reads as the whole theme. An unreadable file (another version, an unknown token, a non-colour) throws, or in the provider keeps zon's theme and warns why.
|
|
3854
|
+
|
|
3855
|
+
## The preset code
|
|
3856
|
+
|
|
3857
|
+
A code is the generator's inputs, not its output, so it stays short and expands to every token in both themes:
|
|
3858
|
+
|
|
3859
|
+
| Part | Characters | Holds |
|
|
3860
|
+
| ----- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
3861
|
+
| `Z1` | 2 | zon, format version 1 |
|
|
3862
|
+
| Body | 13 | Which seeds were kept, the greys' tint and hue, the primary's colour and hue, the vividness and turn of the tones and status colours, the ground, and the height and corner steps, as one number in base 36 |
|
|
3863
|
+
| Pins | 8 each | A token pinned by hand: its theme, which token, and its lightness, chroma, hue and alpha |
|
|
3864
|
+
| Check | 1 | A weighted sum of the others, so a mistyped character is caught |
|
|
3865
|
+
|
|
3866
|
+
Letters and digits only, case-insensitive; spaces and hyphens are ignored. Each value is held in the step its control moves in (tint to 0.001, hues to 1°, percentages to 1%, pinned lightness and chroma to 0.001), so a code loads exactly the theme it was copied from. Version 1 is frozen: a `Z1` code expands to the same tokens in every release, from zon's colours when it was made; a later format gets a new version, read beside this one. The one exception is readability: a generated text colour found below its ratio on a ground it sits on may move in a later release until it reads. Pinned colours never move.
|
|
3867
|
+
|
|
3868
|
+
`themeFromPreset` and `themePresetFromColor` (with the `ThemePreset` type) come from `@zonsh/ui`, for an app that applies a theme. The rest of the engine (reading and writing codes, the generator, the colour helpers, the geometry tokens) is `@zonsh/ui/theme`, plain code a server can run:
|
|
3869
|
+
|
|
3870
|
+
```ts
|
|
3871
|
+
import { decodeThemePreset, encodeThemePreset, themePalette } from "@zonsh/ui/theme";
|
|
3872
|
+
```
|
|
3873
|
+
|
|
3874
|
+
| Function | Does |
|
|
3875
|
+
| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
3876
|
+
| `themeFromPreset(codeOrPresetOrFile, { format?, onlyChanges?, scope? })` | `{ code, light, dark, shape, css, json }`. `format` is `"oklch"` (default) or `"hex"`; `onlyChanges` leaves out what equals zon's (default `false`, so the theme looks the same on any later zon stylesheet); `scope` writes `css` for one area, `[data-theme-scope="…"]`, instead of the page; `json` is the theme.json text |
|
|
3877
|
+
| `themeScopeStyle(theme, "light" \| "dark")` | One scheme's tokens and the shape as an inline style, for an area that is always light or always dark; see Theme, "One area of a page" |
|
|
3878
|
+
| `isThemeFile(value)`, `THEME_FILE_VERSION` | Whether a value is a theme.json file; the file format it reads and writes (1) |
|
|
3879
|
+
| `themePresetFromColor(colour, { neutral?, corners?, density?, controlHeight? })` | A preset from one brand colour and plain choices, for people and agents who don't need the editor; see Theme, "Your own colour" |
|
|
3880
|
+
| `decodeThemePreset(code)` | The `ThemePreset` a code holds; throws a `ThemePresetError` saying why for anything else |
|
|
3881
|
+
| `encodeThemePreset(preset)` | The code for a preset, after `normalizeThemePreset` moves it onto the steps a code holds |
|
|
3882
|
+
| `themePalette(preset, "light" \| "dark")` | Every colour token of one theme, as OKLCH objects |
|
|
3883
|
+
| `themeShapeTokens(shape)`, `themeHeights(controlHeight)`, `themeDensity(controlHeight)` | The geometry tokens for a shape; the dense, default and prominent heights for a default control height; the `--density` factor for it (1 at 38px) |
|
|
3884
|
+
| `themeTokenGroups`, `zonThemeTokens`, `zonThemePreset` | The tokens a theme sets, with their contrast pairs; zon's values for them; zon's own preset |
|
|
3885
|
+
| `themeContrast`, `fixThemeContrast`, `parseThemeColor`, `formatThemeColor` | The colour helpers the editor uses: WCAG ratio, the nearest lightness that reaches one, reading any CSS colour (hex, `rgb()`, `hsl()`, `oklch()`, names) and writing OKLCH and hex |
|
|
3886
|
+
|
|
3887
|
+
## How it generates
|
|
3888
|
+
|
|
3889
|
+
| Setting | Changes |
|
|
3890
|
+
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
3891
|
+
| Background seed | Tint hue from its hue, tint from its chroma (a grey seed keeps the greys neutral) |
|
|
3892
|
+
| Accent seed | Primary hue from its hue, primary colour from its chroma |
|
|
3893
|
+
| Categories seed | Turns the tones so blue lands on its hue; vividness from its chroma |
|
|
3894
|
+
| Ground | The page, surfaces, edges and charts: a deeper paper in light, a lifted charcoal in dark |
|
|
3895
|
+
| Tint, Tint hue | Every grey (ground, ink, borders, the control and field material) takes this chroma |
|
|
3896
|
+
| Accent colour | The primary button, checked controls and the focus outline, from grey to a full colour |
|
|
3897
|
+
| Vividness | The chroma of the four status colours and six tones, against zon's |
|
|
3898
|
+
| Turn the tones | Moves the six tones round the whole hue circle together |
|
|
3899
|
+
| Status hue | Moves the four status colours together by up to 12°, so green, amber, blue and red keep meaning |
|
|
3900
|
+
| Density | Dense, Compact, Default, Comfortable or Spacious: the default height of buttons, fields and selects (30, 34, 38, 42 or 46px), the dense and prominent sizes in zon's proportions (24 / 30 / 36 at Dense) and the round icon button 2px under the default; the padding, gaps and Tailwind sizes inside every component scale with it (`--density`, 0.79 to 1.21) and the type by half as much, never under 10px |
|
|
3901
|
+
| Corners | The button's radius, scaled from zon's 12px in steps of 25% (0 square, 100% zon's, 200% twice as round); the others keep zon's offsets from it — fields 2px less, items 5, checkboxes 7, cards 8px more — never below 0, and at 0 everything is square, cards too. Regions stay square |
|
|
3902
|
+
|
|
3903
|
+
**Shuffle** picks a new value for every colour setting except kept seeds and pinned tokens: each seed from its family (anywhere for Any), and the ground and status hue always. It leaves the shape alone. A generated colour below its ratio (4.5:1 for text, 3:1 for the focus outline and a checked control's tick) moves lightness just far enough, on its own ground and every other it sits on: body and secondary text on the page, raised surfaces, the hovered fill, menus and fields; captions on the page, menus and fields; status colours and tones on all of them. Pinned colours stay exactly as set. A coloured primary moves to the middle of the lightness range, where colour can show. Hover and pressed fills follow their token by zon's own step. The OKLCH export keeps every value; the hex export lowers the chroma of a colour outside sRGB until it fits, as a screen without wide colour would show it.
|
|
3904
|
+
|
|
3905
|
+
## The parts
|
|
3906
|
+
|
|
3907
|
+
| Part | Page | Job |
|
|
3908
|
+
| --------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------ |
|
|
3909
|
+
| `Popover` | Popover | Each setting's control, opened from its row; Open preset |
|
|
3910
|
+
| `Select` | Select | Each seed's family |
|
|
3911
|
+
| `ColorPickerPanel`, `Toggle` | Color Picker | A seed colour, and Keep, which leaves it out of Shuffle |
|
|
3912
|
+
| `Slider` | Slider | Corners and height in steps; the generator's settings and each token's L, C, H and alpha |
|
|
3913
|
+
| `InputGroup`, `CopyButton` | Input Group | The preset code, shown and copied |
|
|
3914
|
+
| `Collapsible` | Collapsible | Advanced |
|
|
3915
|
+
| `ToggleGroup` | Toggle Group | Light or dark to edit and preview; the preview's page; the export format |
|
|
3916
|
+
| `ScrollArea` | Scroll area | The menu beside the preview |
|
|
3917
|
+
| `Dialog`, `CodeBlock` | Dialog | Use this theme: the code, the provider, the create command, JSON, CSS and a prompt, each to copy |
|
|
3918
|
+
| `Card`, `Table`, `Toolbar`, `Chart`, `Stat` … | Card | The preview: a studio's app, then the system, under the edited tokens |
|
|
3919
|
+
|
|
3920
|
+
## Brand rules
|
|
3921
|
+
|
|
3922
|
+
- **Do** keep status colours on their meaning: green done, red failed, whatever the theme. Change how vivid they are, not what they mean.
|
|
3923
|
+
- **Do** fix every contrast warning before you export; text below 4.5:1 is hard for many people to read. Inks are checked on the page; status colours and tones on the hovered and selected fill (`--control-hover`), since they also mark selected rows and tags. Generated ones are also kept readable on their other grounds (surfaces, menus, fields).
|
|
3924
|
+
- **Do** tint the greys lightly. Past 0.02 chroma the page stops reading as neutral, and colour stops meaning anything.
|
|
3925
|
+
- **Do** keep the shape in the theme. A height or radius set by hand on one component drifts; set in the theme, every control follows.
|
|
3926
|
+
- **Don't** use the editor to colour buttons, cards or pages one by one. A theme changes the tokens; the components stay as they are.
|
|
3927
|
+
|
|
3928
|
+
## Accessibility
|
|
3929
|
+
|
|
3930
|
+
- Each setting's row is a button named by its setting and value; its popover holds a labelled control. Corners and Density also step with the arrow keys while the row has focus (Home and End go to the ends); the row's description says so, and each new value is announced.
|
|
3931
|
+
- The preset code is a labelled, read-only field with a copy button. Open preset is a labelled field in a form; an unreadable code is answered in words under it (missing characters, a mistyped one, another version).
|
|
3932
|
+
- Each seed's row is a group named for it: the family a labelled select, the colour a button named with the seed and hex value, Keep a toggle button with `aria-pressed` named for its seed.
|
|
3933
|
+
- Each token is a button that opens its editor, with `aria-expanded`; its contrast is read out with the ratio and whether it passes.
|
|
3934
|
+
- A contrast warning is a polite live region, announced when it appears or changes.
|
|
3935
|
+
- The preview is a labelled region naming its page. Its controls work, so focus and hover can be checked in the new colours. The page switch is a toggle group whose items say both number and name.
|
|
3936
|
+
- All sliders are native range inputs with visible labels and values; stepped ones show every step under the track.
|
|
3937
|
+
|
|
3938
|
+
---
|
|
3939
|
+
|
|
3940
|
+
- Import: `import { themeFromPreset, themePresetFromColor, decodeThemePreset, encodeThemePreset, normalizeThemePreset, themePalette, themeShapeTokens, themeHeights } from "@zonsh/ui"`
|