@glyphui/ui 0.3.0 → 0.5.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/README.md +68 -12
- package/dist/chart.d.ts +14 -202
- package/dist/chart.js +14 -456
- package/dist/components/accordion/accordion.d.ts +15 -0
- package/dist/components/accordion/accordion.js +69 -0
- package/dist/components/accordion/accordion.styles.d.ts +65 -0
- package/dist/components/accordion/accordion.styles.js +30 -0
- package/dist/components/accordion/index.d.ts +3 -0
- package/dist/components/alert/alert-icons.js +62 -0
- package/dist/components/alert/alert.d.ts +19 -0
- package/dist/components/alert/alert.js +64 -0
- package/dist/components/alert/alert.styles.d.ts +107 -0
- package/dist/components/alert/alert.styles.js +86 -0
- package/dist/components/alert/index.d.ts +3 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +29 -0
- package/dist/components/alert-dialog/alert-dialog.js +89 -0
- package/dist/components/alert-dialog/alert-dialog.styles.d.ts +63 -0
- package/dist/components/alert-dialog/alert-dialog.styles.js +19 -0
- package/dist/components/alert-dialog/confirm-dialog.js +22 -0
- package/dist/components/alert-dialog/confirm.d.ts +30 -0
- package/dist/components/alert-dialog/confirm.js +62 -0
- package/dist/components/alert-dialog/index.d.ts +4 -0
- package/dist/components/aspect-ratio/aspect-ratio.d.ts +55 -0
- package/dist/components/aspect-ratio/aspect-ratio.js +28 -0
- package/dist/components/aspect-ratio/index.d.ts +2 -0
- package/dist/components/avatar/avatar.d.ts +13 -0
- package/dist/components/avatar/avatar.js +50 -0
- package/dist/components/avatar/avatar.styles.d.ts +77 -0
- package/dist/components/avatar/avatar.styles.js +32 -0
- package/dist/components/avatar/index.d.ts +3 -0
- package/dist/components/badge/badge.d.ts +10 -0
- package/dist/components/badge/badge.js +28 -0
- package/dist/components/badge/badge.styles.d.ts +62 -0
- package/dist/components/badge/badge.styles.js +72 -0
- package/dist/components/badge/index.d.ts +3 -0
- package/dist/components/banner/banner.d.ts +17 -0
- package/dist/components/banner/banner.js +71 -0
- package/dist/components/banner/banner.styles.d.ts +98 -0
- package/dist/components/banner/banner.styles.js +27 -0
- package/dist/components/banner/index.d.ts +3 -0
- package/dist/components/blockquote/blockquote.d.ts +72 -0
- package/dist/components/blockquote/blockquote.js +47 -0
- package/dist/components/blockquote/index.d.ts +2 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +28 -0
- package/dist/components/breadcrumb/breadcrumb.js +85 -0
- package/dist/components/breadcrumb/breadcrumb.styles.d.ts +63 -0
- package/dist/components/breadcrumb/breadcrumb.styles.js +18 -0
- package/dist/components/breadcrumb/index.d.ts +3 -0
- package/dist/components/button/button.d.ts +20 -0
- package/dist/components/button/button.js +52 -0
- package/dist/components/button/button.styles.d.ts +146 -0
- package/dist/components/button/button.styles.js +64 -0
- package/dist/components/button/index.d.ts +3 -0
- package/dist/components/calendar/calendar.d.ts +9 -0
- package/dist/components/calendar/calendar.js +75 -0
- package/dist/components/calendar/calendar.styles.d.ts +171 -0
- package/dist/components/calendar/calendar.styles.js +42 -0
- package/dist/components/calendar/index.d.ts +4 -0
- package/dist/components/card/card.d.ts +17 -0
- package/dist/components/card/card.js +79 -0
- package/dist/components/card/card.styles.d.ts +113 -0
- package/dist/components/card/card.styles.js +38 -0
- package/dist/components/card/index.d.ts +3 -0
- package/dist/components/carousel/carousel.d.ts +37 -0
- package/dist/components/carousel/carousel.js +190 -0
- package/dist/components/carousel/carousel.styles.d.ts +74 -0
- package/dist/components/carousel/carousel.styles.js +35 -0
- package/dist/components/carousel/index.d.ts +3 -0
- package/dist/components/checkbox/checkbox.d.ts +37 -0
- package/dist/components/checkbox/checkbox.js +44 -0
- package/dist/components/checkbox/index.d.ts +2 -0
- package/dist/components/code/code.d.ts +18 -0
- package/dist/components/code/code.js +75 -0
- package/dist/components/code/code.styles.d.ts +76 -0
- package/dist/components/code/code.styles.js +18 -0
- package/dist/components/code/index.d.ts +3 -0
- package/dist/components/collapsible/collapsible.d.ts +56 -0
- package/dist/components/collapsible/collapsible.js +43 -0
- package/dist/components/collapsible/index.d.ts +2 -0
- package/dist/components/combobox/combobox.d.ts +50 -0
- package/dist/components/combobox/combobox.js +141 -0
- package/dist/components/combobox/combobox.styles.d.ts +110 -0
- package/dist/components/combobox/combobox.styles.js +42 -0
- package/dist/components/combobox/index.d.ts +3 -0
- package/dist/components/command-menu/command-menu.d.ts +40 -0
- package/dist/components/command-menu/command-menu.js +148 -0
- package/dist/components/command-menu/command-menu.styles.d.ts +105 -0
- package/dist/components/command-menu/command-menu.styles.js +30 -0
- package/dist/components/command-menu/index.d.ts +3 -0
- package/dist/components/container/container.d.ts +34 -0
- package/dist/components/container/container.js +30 -0
- package/dist/components/container/index.d.ts +2 -0
- package/dist/components/context-menu/context-menu.d.ts +34 -0
- package/dist/components/context-menu/context-menu.js +157 -0
- package/dist/components/context-menu/context-menu.styles.d.ts +135 -0
- package/dist/components/context-menu/context-menu.styles.js +14 -0
- package/dist/components/context-menu/index.d.ts +3 -0
- package/dist/components/copy-button/copy-button.d.ts +61 -0
- package/dist/components/copy-button/copy-button.js +79 -0
- package/dist/components/copy-button/index.d.ts +2 -0
- package/dist/components/date-picker/date-picker.d.ts +51 -0
- package/dist/components/date-picker/date-picker.js +235 -0
- package/dist/components/date-picker/date-picker.styles.d.ts +77 -0
- package/dist/components/date-picker/date-picker.styles.js +31 -0
- package/dist/components/date-picker/index.d.ts +3 -0
- package/dist/components/description-list/description-list.d.ts +15 -0
- package/dist/components/description-list/description-list.js +51 -0
- package/dist/components/description-list/description-list.styles.d.ts +74 -0
- package/dist/components/description-list/description-list.styles.js +35 -0
- package/dist/components/description-list/index.d.ts +3 -0
- package/dist/components/dialog/close-icon.js +22 -0
- package/dist/components/dialog/dialog.d.ts +21 -0
- package/dist/components/dialog/dialog.js +79 -0
- package/dist/components/dialog/dialog.styles.d.ts +83 -0
- package/dist/components/dialog/dialog.styles.js +34 -0
- package/dist/components/dialog/index.d.ts +3 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +34 -0
- package/dist/components/dropdown-menu/dropdown-menu.js +160 -0
- package/dist/components/dropdown-menu/dropdown-menu.styles.d.ts +83 -0
- package/dist/components/dropdown-menu/dropdown-menu.styles.js +38 -0
- package/dist/components/dropdown-menu/index.d.ts +3 -0
- package/dist/components/eyebrow/eyebrow.d.ts +9 -0
- package/dist/components/eyebrow/eyebrow.js +20 -0
- package/dist/components/eyebrow/eyebrow.styles.d.ts +38 -0
- package/dist/components/eyebrow/eyebrow.styles.js +13 -0
- package/dist/components/eyebrow/index.d.ts +3 -0
- package/dist/components/field/field-context.d.ts +25 -0
- package/dist/components/field/field-context.js +27 -0
- package/dist/components/field/field.d.ts +28 -0
- package/dist/{field-CWZ_FdkD.js → components/field/field.js} +20 -34
- package/dist/components/field/field.styles.d.ts +53 -0
- package/dist/components/field/field.styles.js +22 -0
- package/dist/components/field/index.d.ts +4 -0
- package/dist/components/file-upload/file-upload.d.ts +52 -0
- package/dist/components/file-upload/file-upload.js +266 -0
- package/dist/components/file-upload/file-upload.styles.d.ts +123 -0
- package/dist/components/file-upload/file-upload.styles.js +32 -0
- package/dist/components/file-upload/index.d.ts +3 -0
- package/dist/components/grid/grid.d.ts +168 -0
- package/dist/components/grid/grid.js +126 -0
- package/dist/components/grid/index.d.ts +2 -0
- package/dist/components/heading/heading.d.ts +12 -0
- package/dist/components/heading/heading.js +28 -0
- package/dist/components/heading/heading.styles.d.ts +65 -0
- package/dist/components/heading/heading.styles.js +15 -0
- package/dist/components/heading/index.d.ts +3 -0
- package/dist/components/hover-card/hover-card.d.ts +43 -0
- package/dist/components/hover-card/hover-card.js +27 -0
- package/dist/components/hover-card/index.d.ts +2 -0
- package/dist/components/input/index.d.ts +3 -0
- package/dist/components/input/input.d.ts +13 -0
- package/dist/components/input/input.js +33 -0
- package/dist/components/input/input.styles.d.ts +55 -0
- package/dist/components/input/input.styles.js +33 -0
- package/dist/components/input-otp/index.d.ts +4 -0
- package/dist/components/input-otp/index.js +5 -0
- package/dist/components/input-otp/input-otp.d.ts +23 -0
- package/dist/components/input-otp/input-otp.js +86 -0
- package/dist/components/input-otp/input-otp.styles.d.ts +71 -0
- package/dist/components/input-otp/input-otp.styles.js +30 -0
- package/dist/components/kbd/index.d.ts +2 -0
- package/dist/components/kbd/kbd.d.ts +30 -0
- package/dist/components/kbd/kbd.js +17 -0
- package/dist/components/label/index.d.ts +2 -0
- package/dist/components/label/label.d.ts +31 -0
- package/dist/components/label/label.js +17 -0
- package/dist/components/link/index.d.ts +3 -0
- package/dist/components/link/link.d.ts +14 -0
- package/dist/components/link/link.js +57 -0
- package/dist/components/link/link.styles.d.ts +89 -0
- package/dist/components/link/link.styles.js +33 -0
- package/dist/components/modal/index.d.ts +3 -0
- package/dist/components/modal/modal.d.ts +33 -0
- package/dist/components/modal/modal.js +56 -0
- package/dist/components/modal/modal.styles.d.ts +61 -0
- package/dist/components/modal/modal.styles.js +14 -0
- package/dist/components/navigation-menu/index.d.ts +3 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +37 -0
- package/dist/components/navigation-menu/navigation-menu.js +138 -0
- package/dist/components/navigation-menu/navigation-menu.styles.d.ts +111 -0
- package/dist/components/navigation-menu/navigation-menu.styles.js +39 -0
- package/dist/components/number-input/index.d.ts +3 -0
- package/dist/components/number-input/number-input.d.ts +30 -0
- package/dist/components/number-input/number-input.js +151 -0
- package/dist/components/number-input/number-input.styles.d.ts +68 -0
- package/dist/components/number-input/number-input.styles.js +35 -0
- package/dist/components/pagination/index.d.ts +4 -0
- package/dist/components/pagination/pagination-range.d.ts +11 -0
- package/dist/components/pagination/pagination-range.js +42 -0
- package/dist/components/pagination/pagination.d.ts +18 -0
- package/dist/components/pagination/pagination.js +94 -0
- package/dist/components/pagination/pagination.styles.d.ts +65 -0
- package/dist/components/pagination/pagination.styles.js +35 -0
- package/dist/components/password-input/index.d.ts +3 -0
- package/dist/components/password-input/password-input.d.ts +20 -0
- package/dist/components/password-input/password-input.js +106 -0
- package/dist/components/password-input/password-input.styles.d.ts +66 -0
- package/dist/components/password-input/password-input.styles.js +21 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/popover.d.ts +52 -0
- package/dist/components/popover/popover.js +35 -0
- package/dist/components/progress/index.d.ts +3 -0
- package/dist/components/progress/progress.d.ts +29 -0
- package/dist/components/progress/progress.js +108 -0
- package/dist/components/progress/progress.styles.d.ts +236 -0
- package/dist/components/progress/progress.styles.js +69 -0
- package/dist/components/prose/index.d.ts +2 -0
- package/dist/components/prose/prose.d.ts +90 -0
- package/dist/components/prose/prose.js +67 -0
- package/dist/components/radio-group/index.d.ts +3 -0
- package/dist/components/radio-group/radio-group.d.ts +26 -0
- package/dist/components/radio-group/radio-group.js +102 -0
- package/dist/components/radio-group/radio-group.styles.d.ts +80 -0
- package/dist/components/radio-group/radio-group.styles.js +56 -0
- package/dist/components/resizable/index.d.ts +3 -0
- package/dist/components/resizable/resizable.d.ts +17 -0
- package/dist/components/resizable/resizable.js +81 -0
- package/dist/components/resizable/resizable.styles.d.ts +53 -0
- package/dist/components/resizable/resizable.styles.js +19 -0
- package/dist/components/scroll-area/index.d.ts +2 -0
- package/dist/components/scroll-area/scroll-area.d.ts +70 -0
- package/dist/components/scroll-area/scroll-area.js +70 -0
- package/dist/components/section/index.d.ts +2 -0
- package/dist/components/section/section.d.ts +52 -0
- package/dist/components/section/section.js +41 -0
- package/dist/components/segmented-control/index.d.ts +2 -0
- package/dist/components/segmented-control/segmented-control.d.ts +92 -0
- package/dist/components/segmented-control/segmented-control.js +86 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/select.d.ts +85 -0
- package/dist/components/select/select.js +81 -0
- package/dist/components/separator/index.d.ts +2 -0
- package/dist/components/separator/separator.d.ts +40 -0
- package/dist/components/separator/separator.js +27 -0
- package/dist/components/sheet/index.d.ts +3 -0
- package/dist/components/sheet/sheet.d.ts +20 -0
- package/dist/components/sheet/sheet.js +83 -0
- package/dist/components/sheet/sheet.styles.d.ts +101 -0
- package/dist/components/sheet/sheet.styles.js +62 -0
- package/dist/components/skeleton/index.d.ts +2 -0
- package/dist/components/skeleton/skeleton.d.ts +30 -0
- package/dist/components/skeleton/skeleton.js +18 -0
- package/dist/components/slider/index.d.ts +3 -0
- package/dist/components/slider/slider.d.ts +38 -0
- package/dist/components/slider/slider.js +68 -0
- package/dist/components/slider/slider.styles.d.ts +56 -0
- package/dist/components/slider/slider.styles.js +23 -0
- package/dist/components/spinner/index.d.ts +3 -0
- package/dist/components/spinner/spinner.d.ts +9 -0
- package/dist/components/spinner/spinner.js +36 -0
- package/dist/components/spinner/spinner.styles.d.ts +53 -0
- package/dist/components/spinner/spinner.styles.js +18 -0
- package/dist/components/stack/index.d.ts +2 -0
- package/dist/components/stack/stack.d.ts +109 -0
- package/dist/components/stack/stack.js +62 -0
- package/dist/components/stat-card/index.d.ts +3 -0
- package/dist/components/stat-card/stat-card.d.ts +22 -0
- package/dist/components/stat-card/stat-card.js +82 -0
- package/dist/components/stat-card/stat-card.styles.d.ts +83 -0
- package/dist/components/stat-card/stat-card.styles.js +16 -0
- package/dist/components/stepper/index.d.ts +3 -0
- package/dist/components/stepper/stepper.d.ts +20 -0
- package/dist/components/stepper/stepper.js +100 -0
- package/dist/components/stepper/stepper.styles.d.ts +170 -0
- package/dist/components/stepper/stepper.styles.js +67 -0
- package/dist/components/switch/index.d.ts +2 -0
- package/dist/components/switch/switch.d.ts +51 -0
- package/dist/components/switch/switch.js +43 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/table.d.ts +78 -0
- package/dist/components/table/table.js +82 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/tabs.d.ts +73 -0
- package/dist/components/tabs/tabs.js +103 -0
- package/dist/components/tag-input/index.d.ts +3 -0
- package/dist/components/tag-input/tag-input.d.ts +30 -0
- package/dist/components/tag-input/tag-input.js +149 -0
- package/dist/components/tag-input/tag-input.styles.d.ts +71 -0
- package/dist/components/tag-input/tag-input.styles.js +29 -0
- package/dist/components/text/index.d.ts +3 -0
- package/dist/components/text/text.d.ts +9 -0
- package/dist/components/text/text.js +25 -0
- package/dist/components/text/text.styles.d.ts +188 -0
- package/dist/components/text/text.styles.js +36 -0
- package/dist/components/textarea/index.d.ts +2 -0
- package/dist/components/textarea/textarea.d.ts +29 -0
- package/dist/components/textarea/textarea.js +23 -0
- package/dist/components/timeline/index.d.ts +3 -0
- package/dist/components/timeline/timeline.d.ts +28 -0
- package/dist/components/timeline/timeline.js +61 -0
- package/dist/components/timeline/timeline.styles.d.ts +110 -0
- package/dist/components/timeline/timeline.styles.js +30 -0
- package/dist/components/toast/index.d.ts +2 -0
- package/dist/components/toast/toast.d.ts +119 -0
- package/dist/components/toast/toast.js +75 -0
- package/dist/components/toggle/index.d.ts +3 -0
- package/dist/components/toggle/toggle.d.ts +20 -0
- package/dist/components/toggle/toggle.js +58 -0
- package/dist/components/toggle/toggle.styles.d.ts +80 -0
- package/dist/components/toggle/toggle.styles.js +34 -0
- package/dist/components/tooltip/index.d.ts +2 -0
- package/dist/components/tooltip/tooltip.d.ts +39 -0
- package/dist/components/tooltip/tooltip.js +29 -0
- package/dist/components/tree-view/index.d.ts +3 -0
- package/dist/components/tree-view/tree-view.d.ts +31 -0
- package/dist/components/tree-view/tree-view.js +192 -0
- package/dist/components/tree-view/tree-view.styles.d.ts +59 -0
- package/dist/components/tree-view/tree-view.styles.js +32 -0
- package/dist/components/visually-hidden/index.d.ts +2 -0
- package/dist/components/visually-hidden/visually-hidden.d.ts +10 -0
- package/dist/components/visually-hidden/visually-hidden.js +16 -0
- package/dist/data-table.d.ts +3 -110
- package/dist/data-table.js +2 -224
- package/dist/form.d.ts +2 -79
- package/dist/form.js +1 -83
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/use-component-config.d.ts +13 -0
- package/dist/hooks/use-component-config.js +22 -0
- package/dist/hooks/use-controllable-state.d.ts +9 -0
- package/dist/hooks/use-controllable-state.js +18 -0
- package/dist/hooks/use-media-query.d.ts +4 -0
- package/dist/hooks/use-media-query.js +13 -0
- package/dist/hooks/use-scrolled.d.ts +4 -0
- package/dist/hooks/use-scrolled.js +17 -0
- package/dist/index.d.ts +223 -6849
- package/dist/index.js +148 -6718
- package/dist/internal/dev.js +12 -0
- package/dist/internal/icons.js +91 -0
- package/dist/motion/active-indicator.d.ts +12 -0
- package/dist/motion/active-indicator.js +26 -0
- package/dist/motion/animated-number.d.ts +21 -0
- package/dist/motion/animated-number.js +88 -0
- package/dist/motion/features.js +10 -0
- package/dist/motion/index.d.ts +10 -0
- package/dist/motion/index.js +10 -0
- package/dist/motion/motion-root.js +48 -0
- package/dist/motion/page-transition.d.ts +16 -0
- package/dist/motion/page-transition.js +23 -0
- package/dist/motion/presence-list.js +46 -0
- package/dist/motion/presence.d.ts +11 -0
- package/dist/motion/presence.js +17 -0
- package/dist/motion/reveal.d.ts +18 -0
- package/dist/motion/reveal.js +37 -0
- package/dist/motion/stagger.d.ts +29 -0
- package/dist/motion/stagger.js +52 -0
- package/dist/motion/use-motion-settings.d.ts +25 -0
- package/dist/motion/use-motion-settings.js +47 -0
- package/dist/motion/use-reveal.d.ts +11 -0
- package/dist/motion/use-reveal.js +41 -0
- package/dist/patterns/app-shell/app-shell-context.d.ts +14 -0
- package/dist/patterns/app-shell/app-shell-context.js +16 -0
- package/dist/patterns/app-shell/app-shell.d.ts +21 -0
- package/dist/patterns/app-shell/app-shell.js +82 -0
- package/dist/patterns/app-shell/app-shell.styles.d.ts +302 -0
- package/dist/patterns/app-shell/app-shell.styles.js +106 -0
- package/dist/patterns/app-shell/index.d.ts +7 -0
- package/dist/patterns/app-shell/navbar.d.ts +29 -0
- package/dist/patterns/app-shell/navbar.js +116 -0
- package/dist/patterns/app-shell/page-header.d.ts +12 -0
- package/dist/patterns/app-shell/page-header.js +38 -0
- package/dist/patterns/app-shell/sidebar.d.ts +31 -0
- package/dist/patterns/app-shell/sidebar.js +141 -0
- package/dist/patterns/async/async.d.ts +40 -0
- package/dist/patterns/async/async.js +61 -0
- package/dist/patterns/async/index.d.ts +3 -0
- package/dist/patterns/async/states.d.ts +68 -0
- package/dist/patterns/async/states.js +116 -0
- package/dist/patterns/chart/cartesian.d.ts +128 -0
- package/dist/patterns/chart/cartesian.js +552 -0
- package/dist/patterns/chart/chart-card.d.ts +39 -0
- package/dist/patterns/chart/chart-card.js +103 -0
- package/dist/patterns/chart/chart-parts.d.ts +53 -0
- package/dist/patterns/chart/chart-parts.js +282 -0
- package/dist/patterns/chart/chart.styles.d.ts +200 -0
- package/dist/patterns/chart/chart.styles.js +43 -0
- package/dist/patterns/chart/export.d.ts +45 -0
- package/dist/patterns/chart/export.js +293 -0
- package/dist/patterns/chart/funnel.d.ts +23 -0
- package/dist/patterns/chart/funnel.js +129 -0
- package/dist/patterns/chart/heatmap.d.ts +37 -0
- package/dist/patterns/chart/heatmap.js +258 -0
- package/dist/patterns/chart/icons.js +39 -0
- package/dist/patterns/chart/pie.d.ts +36 -0
- package/dist/patterns/chart/pie.js +120 -0
- package/dist/patterns/chart/radial.d.ts +75 -0
- package/dist/patterns/chart/radial.js +282 -0
- package/dist/patterns/chart/sankey.d.ts +29 -0
- package/dist/patterns/chart/sankey.js +136 -0
- package/dist/patterns/chart/scatter.d.ts +42 -0
- package/dist/patterns/chart/scatter.js +203 -0
- package/dist/patterns/chart/sparkline.d.ts +20 -0
- package/dist/patterns/chart/sparkline.js +102 -0
- package/dist/patterns/chart/treemap.d.ts +25 -0
- package/dist/patterns/chart/treemap.js +128 -0
- package/dist/patterns/chart/use-element-width.js +23 -0
- package/dist/patterns/data-table/data-table.d.ts +109 -0
- package/dist/patterns/data-table/data-table.js +233 -0
- package/dist/patterns/form/form.d.ts +89 -0
- package/dist/patterns/form/form.js +111 -0
- package/dist/provider/color-mode-script.d.ts +15 -0
- package/dist/provider/color-mode-script.js +13 -0
- package/dist/provider/color-mode.d.ts +24 -0
- package/dist/provider/color-mode.js +87 -0
- package/dist/provider/glyph-context.d.ts +51 -0
- package/dist/provider/glyph-context.js +28 -0
- package/dist/provider/glyph-provider.d.ts +37 -0
- package/dist/provider/glyph-provider.js +48 -0
- package/dist/provider/index.d.ts +6 -0
- package/dist/provider/theme-scope.d.ts +12 -0
- package/dist/provider/theme-scope.js +42 -0
- package/dist/provider/theme-style.js +15 -0
- package/dist/react-router.d.ts +18 -0
- package/dist/react-router.js +44 -0
- package/dist/register.d.ts +57 -0
- package/dist/themes.d.ts +22 -0
- package/dist/themes.js +49 -0
- package/dist/utils/cn.d.ts +6 -0
- package/dist/utils/cn.js +12 -0
- package/dist/utils/compose-refs.js +11 -0
- package/dist/{registry-BGSJoiLq.d.ts → utils/registry.d.ts} +2 -3
- package/dist/utils/styles.js +20 -0
- package/dist/{tv-DuMh7UH2.d.ts → utils/tv.d.ts} +2 -2
- package/dist/utils/tv.js +8 -0
- package/dist/utils/tw-merge-config.js +13 -0
- package/dist/vite.d.ts +27 -0
- package/dist/vite.js +29 -0
- package/fonts.css +10 -0
- package/package.json +33 -5
- package/src/components/accordion/accordion.styles.ts +1 -1
- package/src/components/alert/alert.styles.ts +1 -1
- package/src/components/alert-dialog/alert-dialog.styles.ts +5 -4
- package/src/components/alert-dialog/confirm-dialog.tsx +42 -0
- package/src/components/alert-dialog/confirm.tsx +12 -31
- package/src/components/aspect-ratio/aspect-ratio.tsx +1 -1
- package/src/components/avatar/avatar.styles.ts +1 -1
- package/src/components/badge/badge.styles.ts +12 -17
- package/src/components/banner/banner.styles.ts +5 -5
- package/src/components/blockquote/blockquote.tsx +1 -1
- package/src/components/breadcrumb/breadcrumb.styles.ts +1 -1
- package/src/components/button/button.styles.ts +6 -2
- package/src/components/calendar/calendar.styles.ts +4 -3
- package/src/components/card/card.styles.ts +1 -1
- package/src/components/carousel/carousel.styles.ts +1 -1
- package/src/components/checkbox/checkbox.tsx +20 -5
- package/src/components/code/code.styles.ts +2 -2
- package/src/components/collapsible/collapsible.tsx +1 -1
- package/src/components/combobox/combobox.styles.ts +5 -2
- package/src/components/command-menu/command-menu.styles.ts +6 -4
- package/src/components/container/container.tsx +1 -1
- package/src/components/context-menu/context-menu.styles.ts +4 -2
- package/src/components/copy-button/copy-button.tsx +1 -1
- package/src/components/date-picker/date-picker.styles.ts +2 -2
- package/src/components/description-list/description-list.styles.ts +1 -1
- package/src/components/dialog/dialog.styles.ts +11 -4
- package/src/components/dropdown-menu/dropdown-menu.styles.ts +5 -5
- package/src/components/eyebrow/eyebrow.styles.ts +2 -2
- package/src/components/field/field-context.ts +2 -0
- package/src/components/field/field.styles.ts +5 -3
- package/src/components/field/field.tsx +25 -4
- package/src/components/file-upload/file-upload.styles.ts +4 -4
- package/src/components/file-upload/file-upload.tsx +51 -48
- package/src/components/grid/grid.tsx +1 -1
- package/src/components/heading/heading.styles.ts +1 -1
- package/src/components/hover-card/hover-card.tsx +5 -2
- package/src/components/input/input.styles.ts +1 -1
- package/src/components/input-otp/input-otp.styles.ts +1 -1
- package/src/components/kbd/kbd.tsx +1 -1
- package/src/components/label/label.tsx +1 -1
- package/src/components/link/link.styles.ts +2 -2
- package/src/components/modal/modal.styles.ts +3 -1
- package/src/components/modal/modal.tsx +30 -5
- package/src/components/navigation-menu/navigation-menu.styles.ts +2 -2
- package/src/components/navigation-menu/navigation-menu.tsx +14 -4
- package/src/components/number-input/number-input.styles.ts +1 -1
- package/src/components/pagination/pagination.styles.ts +6 -4
- package/src/components/pagination/pagination.tsx +14 -1
- package/src/components/password-input/password-input.styles.ts +4 -4
- package/src/components/popover/popover.tsx +1 -1
- package/src/components/progress/progress.styles.ts +2 -2
- package/src/components/prose/prose.tsx +2 -2
- package/src/components/radio-group/radio-group.styles.ts +1 -1
- package/src/components/resizable/resizable.styles.ts +1 -1
- package/src/components/scroll-area/scroll-area.tsx +24 -2
- package/src/components/section/section.tsx +1 -1
- package/src/components/segmented-control/segmented-control.tsx +40 -9
- package/src/components/select/select.tsx +2 -2
- package/src/components/separator/separator.tsx +1 -1
- package/src/components/sheet/sheet.styles.ts +1 -1
- package/src/components/skeleton/skeleton.tsx +1 -1
- package/src/components/slider/slider.styles.ts +1 -1
- package/src/components/slider/slider.tsx +9 -2
- package/src/components/spinner/spinner.styles.ts +1 -1
- package/src/components/stack/stack.tsx +1 -1
- package/src/components/stat-card/stat-card.styles.ts +1 -1
- package/src/components/stepper/stepper.styles.ts +3 -3
- package/src/components/switch/switch.tsx +2 -2
- package/src/components/table/table.tsx +1 -1
- package/src/components/tabs/tabs.tsx +46 -15
- package/src/components/tag-input/tag-input.styles.ts +2 -2
- package/src/components/tag-input/tag-input.tsx +27 -18
- package/src/components/text/text.styles.ts +5 -5
- package/src/components/textarea/textarea.tsx +1 -1
- package/src/components/timeline/timeline.styles.ts +1 -1
- package/src/components/toast/toast.tsx +1 -1
- package/src/components/toggle/toggle.styles.ts +1 -1
- package/src/components/tooltip/tooltip.tsx +6 -3
- package/src/components/tree-view/tree-view.styles.ts +1 -1
- package/src/index.ts +3 -0
- package/src/integrations/react-router.tsx +39 -0
- package/src/integrations/vite.test-d.ts +6 -0
- package/src/integrations/vite.test.ts +28 -0
- package/src/integrations/vite.ts +33 -0
- package/src/internal/dev.ts +12 -0
- package/src/motion/active-indicator.tsx +26 -0
- package/src/motion/animated-number.tsx +113 -0
- package/src/motion/features.ts +7 -0
- package/src/motion/index.ts +9 -0
- package/src/motion/motion-root.tsx +46 -0
- package/src/motion/page-transition.tsx +30 -0
- package/src/motion/presence-list.tsx +42 -0
- package/src/motion/presence.tsx +13 -0
- package/src/motion/reveal.tsx +50 -0
- package/src/motion/stagger.tsx +81 -0
- package/src/motion/use-motion-settings.ts +52 -0
- package/src/motion/use-reveal.ts +54 -0
- package/src/patterns/app-shell/app-shell.styles.ts +19 -12
- package/src/patterns/app-shell/navbar.tsx +34 -16
- package/src/patterns/app-shell/sidebar.tsx +35 -9
- package/src/patterns/async/states.tsx +1 -1
- package/src/patterns/chart/cartesian.tsx +755 -0
- package/src/patterns/chart/chart-card.tsx +148 -0
- package/src/patterns/chart/chart-parts.tsx +330 -57
- package/src/patterns/chart/chart.styles.ts +29 -3
- package/src/patterns/chart/export.ts +334 -0
- package/src/patterns/chart/funnel.tsx +171 -0
- package/src/patterns/chart/heatmap.tsx +339 -0
- package/src/patterns/chart/icons.tsx +44 -0
- package/src/patterns/chart/index.ts +52 -7
- package/src/patterns/chart/pie.tsx +169 -0
- package/src/patterns/chart/radial.tsx +361 -0
- package/src/patterns/chart/sankey.tsx +197 -0
- package/src/patterns/chart/scatter.tsx +254 -0
- package/src/patterns/chart/sparkline.tsx +111 -0
- package/src/patterns/chart/test-utils.tsx +35 -0
- package/src/patterns/chart/treemap.tsx +198 -0
- package/src/patterns/chart/use-element-width.ts +20 -0
- package/src/patterns/data-table/data-table.tsx +1 -1
- package/src/patterns/form/form.tsx +49 -7
- package/src/patterns/form/index.ts +1 -0
- package/src/provider/color-mode-script.ts +28 -0
- package/src/provider/color-mode.tsx +14 -20
- package/src/provider/glyph-context.ts +41 -1
- package/src/provider/glyph-provider.tsx +45 -14
- package/src/provider/index.ts +4 -0
- package/src/provider/theme-scope.tsx +20 -11
- package/src/themes.ts +3 -3
- package/src/utils/styles.ts +17 -3
- package/styles.css +194 -3
- package/dist/field-context-anGPYXbW.js +0 -267
- package/dist/index-BWK4czIG.d.ts +0 -233
- package/dist/states-DR-OoDT-.js +0 -288
- package/dist/tv-DBAGlgXJ.js +0 -58
- package/src/patterns/chart/chart.tsx +0 -369
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import type { StylesEntry } from '../../utils/registry'
|
|
2
|
-
import { themedBorder } from '../../utils/styles'
|
|
2
|
+
import { focusRing, themedBorder } from '../../utils/styles'
|
|
3
3
|
import { tv, type VariantProps } from '../../utils/tv'
|
|
4
4
|
|
|
5
|
-
export const chartStyles = tv({
|
|
5
|
+
export const chartStyles = /* @__PURE__ */ tv({
|
|
6
6
|
slots: {
|
|
7
7
|
root: 'm-0 grid min-w-0 gap-3',
|
|
8
8
|
caption: 'grid gap-0.5',
|
|
9
9
|
title: 'text-small font-medium text-foreground',
|
|
10
10
|
description: 'text-caption text-muted-foreground',
|
|
11
|
-
plot:
|
|
11
|
+
plot: [
|
|
12
|
+
'relative min-w-0 [&_.recharts-surface]:overflow-visible',
|
|
13
|
+
'[&_.recharts-text]:fill-muted-foreground [&_.recharts-cartesian-axis-tick_text]:tabular-nums',
|
|
14
|
+
'[&_.recharts-layer]:outline-none [&_.recharts-sector]:outline-none [&_.recharts-rectangle]:outline-none',
|
|
15
|
+
],
|
|
16
|
+
state: 'flex items-center justify-center',
|
|
17
|
+
skeleton: 'h-full w-full rounded-md',
|
|
12
18
|
legend: 'flex flex-wrap items-center gap-x-4 gap-y-1 text-caption text-muted-foreground',
|
|
13
19
|
legendItem: 'inline-flex items-center gap-1.5',
|
|
20
|
+
legendButton: [
|
|
21
|
+
'-mx-1 inline-flex cursor-pointer items-center gap-1.5 rounded-xs px-1 py-0.5 transition-opacity hover:text-foreground',
|
|
22
|
+
'aria-[pressed=false]:opacity-45 aria-[pressed=false]:line-through aria-[pressed=false]:decoration-faint-foreground',
|
|
23
|
+
focusRing,
|
|
24
|
+
],
|
|
14
25
|
swatch: 'size-2.5 shrink-0 rounded-[2px]',
|
|
15
26
|
tooltip: [
|
|
16
27
|
'grid min-w-36 gap-1.5 rounded-md border-border bg-raised px-3 py-2 text-caption text-foreground shadow-lg',
|
|
@@ -20,16 +31,31 @@ export const chartStyles = tv({
|
|
|
20
31
|
tooltipRow: 'flex items-center gap-2',
|
|
21
32
|
tooltipName: 'flex-1 text-muted-foreground',
|
|
22
33
|
tooltipValue: 'font-mono font-medium tabular-nums text-foreground',
|
|
34
|
+
tooltipTotal: 'mt-0.5 flex items-center gap-2 border-t border-border pt-1.5',
|
|
23
35
|
center:
|
|
24
36
|
'pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center',
|
|
37
|
+
table: 'max-h-96 overflow-auto rounded-md border-(length:--glyph-border-width) border-border',
|
|
25
38
|
srOnly: 'sr-only',
|
|
26
39
|
},
|
|
27
40
|
})
|
|
28
41
|
|
|
29
42
|
export type ChartVariants = VariantProps<typeof chartStyles>
|
|
30
43
|
|
|
44
|
+
export const chartCardStyles = /* @__PURE__ */ tv({
|
|
45
|
+
slots: {
|
|
46
|
+
root: 'min-w-0',
|
|
47
|
+
header: 'flex flex-wrap items-start justify-between gap-3',
|
|
48
|
+
heading: 'grid min-w-0 gap-1',
|
|
49
|
+
controls: 'flex flex-wrap items-center gap-2',
|
|
50
|
+
body: 'min-w-0',
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export type ChartCardVariants = VariantProps<typeof chartCardStyles>
|
|
55
|
+
|
|
31
56
|
declare module '@glyphui/tokens' {
|
|
32
57
|
interface GlyphComponentRegistry {
|
|
33
58
|
Chart: StylesEntry<typeof chartStyles>
|
|
59
|
+
ChartCard: StylesEntry<typeof chartCardStyles>
|
|
34
60
|
}
|
|
35
61
|
}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import type { RefObject } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface ExportChartOptions {
|
|
4
|
+
/** Default `png`. */
|
|
5
|
+
format?: 'png' | 'svg'
|
|
6
|
+
/** File name without extension. Default `chart`. */
|
|
7
|
+
fileName?: string
|
|
8
|
+
/** PNG pixel density. Defaults to the screen's devicePixelRatio (at least 2). */
|
|
9
|
+
scale?: number
|
|
10
|
+
/**
|
|
11
|
+
* Background color. Defaults to the chart's surface, so the export reads the same as the
|
|
12
|
+
* page. Pass `"transparent"` for none.
|
|
13
|
+
*/
|
|
14
|
+
background?: string
|
|
15
|
+
/** Set false to only return the file, without downloading it. Default true. */
|
|
16
|
+
download?: boolean
|
|
17
|
+
/** Draw the chart's title in the file. Default true. Pass a string to use other text. */
|
|
18
|
+
title?: boolean | string
|
|
19
|
+
/** Draw the chart's legend in the file. Default true. */
|
|
20
|
+
legend?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Target = Element | RefObject<Element | null> | null | undefined
|
|
24
|
+
|
|
25
|
+
/** Presentation properties copied from computed styles, so the file needs no stylesheet. */
|
|
26
|
+
const PROPERTIES = [
|
|
27
|
+
'fill',
|
|
28
|
+
'fill-opacity',
|
|
29
|
+
'stroke',
|
|
30
|
+
'stroke-opacity',
|
|
31
|
+
'stroke-width',
|
|
32
|
+
'stroke-dasharray',
|
|
33
|
+
'stroke-linecap',
|
|
34
|
+
'stroke-linejoin',
|
|
35
|
+
'opacity',
|
|
36
|
+
'stop-color',
|
|
37
|
+
'stop-opacity',
|
|
38
|
+
'font-family',
|
|
39
|
+
'font-size',
|
|
40
|
+
'font-weight',
|
|
41
|
+
'font-variant-numeric',
|
|
42
|
+
'letter-spacing',
|
|
43
|
+
'text-anchor',
|
|
44
|
+
'dominant-baseline',
|
|
45
|
+
'visibility',
|
|
46
|
+
'display',
|
|
47
|
+
] as const
|
|
48
|
+
|
|
49
|
+
const VAR = /var\(\s*(--[\w-]+)\s*(?:,\s*([^()]*(?:\([^()]*\))?[^()]*))?\)/
|
|
50
|
+
|
|
51
|
+
/** Replaces `var(--x)` references with their values, read from `element` and its ancestors. */
|
|
52
|
+
export function resolveCssVariables(value: string, element: Element, depth = 0): string {
|
|
53
|
+
let result = value
|
|
54
|
+
for (let guard = 0; guard < 32; guard++) {
|
|
55
|
+
const match = VAR.exec(result)
|
|
56
|
+
if (!match) break
|
|
57
|
+
const [whole, name, fallback] = match
|
|
58
|
+
let resolved = ''
|
|
59
|
+
for (let node: Element | null = element; node && !resolved; node = node.parentElement) {
|
|
60
|
+
resolved = getComputedStyle(node).getPropertyValue(name!).trim()
|
|
61
|
+
if (!resolved && node instanceof HTMLElement)
|
|
62
|
+
resolved = node.style.getPropertyValue(name!).trim()
|
|
63
|
+
if (!resolved && node instanceof SVGElement)
|
|
64
|
+
resolved = node.style.getPropertyValue(name!).trim()
|
|
65
|
+
}
|
|
66
|
+
if (!resolved) resolved = fallback?.trim() ?? ''
|
|
67
|
+
if (depth < 8 && resolved.includes('var('))
|
|
68
|
+
resolved = resolveCssVariables(resolved, element, depth + 1)
|
|
69
|
+
result = result.replace(whole, resolved)
|
|
70
|
+
}
|
|
71
|
+
return result
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function findSvg(target: Target): SVGSVGElement {
|
|
75
|
+
const element = target && 'current' in target ? target.current : target
|
|
76
|
+
if (!element) throw new Error('exportChart: no element to export.')
|
|
77
|
+
if (element instanceof SVGSVGElement) return element
|
|
78
|
+
// The plot's main surface: the largest svg inside the chart.
|
|
79
|
+
const svgs = Array.from(element.querySelectorAll('svg'))
|
|
80
|
+
let best: SVGSVGElement | undefined
|
|
81
|
+
let bestArea = -1
|
|
82
|
+
for (const svg of svgs) {
|
|
83
|
+
const box = svg.getBoundingClientRect()
|
|
84
|
+
const area = box.width * box.height
|
|
85
|
+
if (area > bestArea) {
|
|
86
|
+
best = svg
|
|
87
|
+
bestArea = area
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!best) throw new Error('exportChart: the element contains no chart.')
|
|
91
|
+
return best
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function surfaceColor(svg: Element): string {
|
|
95
|
+
for (let node: Element | null = svg; node; node = node.parentElement) {
|
|
96
|
+
const color = getComputedStyle(node).backgroundColor
|
|
97
|
+
if (color && color !== 'transparent' && !/rgba\(.*,\s*0\)$/.test(color)) return color
|
|
98
|
+
}
|
|
99
|
+
return resolveCssVariables('var(--glyph-surface, #ffffff)', svg)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const SVG_NS = 'http://www.w3.org/2000/svg'
|
|
103
|
+
|
|
104
|
+
export interface SerializeChartOptions {
|
|
105
|
+
/** Background color. Defaults to the chart's surface; `"transparent"` for none. */
|
|
106
|
+
background?: string
|
|
107
|
+
/** Draw the chart's title above it. Default true. Pass a string to use other text. */
|
|
108
|
+
title?: boolean | string
|
|
109
|
+
/** Draw the chart's legend below it. Default true. */
|
|
110
|
+
legend?: boolean
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function svgElement(name: string, attributes: Record<string, string | number>) {
|
|
114
|
+
const element = document.createElementNS(SVG_NS, name)
|
|
115
|
+
for (const [key, value] of Object.entries(attributes)) element.setAttribute(key, String(value))
|
|
116
|
+
return element
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function colorOf(element: Element, property: 'color' | 'backgroundColor'): string {
|
|
120
|
+
const computed = getComputedStyle(element)[property]
|
|
121
|
+
if (computed && !computed.includes('var(')) return computed
|
|
122
|
+
const inline = (element as HTMLElement).style?.[property === 'color' ? 'color' : 'background']
|
|
123
|
+
return inline ? resolveCssVariables(inline, element) : ''
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Content bounds of an svg in its own units, including labels drawn outside it. */
|
|
127
|
+
function contentBox(svg: SVGSVGElement, width: number, height: number) {
|
|
128
|
+
const viewBox = svg.getAttribute('viewBox')
|
|
129
|
+
if (viewBox) {
|
|
130
|
+
const [x = 0, y = 0, w = width, h = height] = viewBox.split(/[\s,]+/).map(Number)
|
|
131
|
+
return { x, y, width: w, height: h, scale: width / (w || width) }
|
|
132
|
+
}
|
|
133
|
+
let box = { x: 0, y: 0, width, height }
|
|
134
|
+
try {
|
|
135
|
+
const bounds = svg.getBBox()
|
|
136
|
+
if (bounds.width > 0 && bounds.height > 0) {
|
|
137
|
+
const x = Math.min(0, bounds.x)
|
|
138
|
+
const y = Math.min(0, bounds.y)
|
|
139
|
+
box = {
|
|
140
|
+
x,
|
|
141
|
+
y,
|
|
142
|
+
width: Math.max(width, bounds.x + bounds.width) - x,
|
|
143
|
+
height: Math.max(height, bounds.y + bounds.height) - y,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
// No layout (e.g. jsdom): keep the element's own size.
|
|
148
|
+
}
|
|
149
|
+
return { ...box, scale: 1 }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Clones a chart's SVG with every theme variable resolved and every style inlined, and adds
|
|
154
|
+
* the chart's title and legend, so the file renders identically outside the page.
|
|
155
|
+
*/
|
|
156
|
+
export function serializeChart(
|
|
157
|
+
target: Target,
|
|
158
|
+
options: SerializeChartOptions = {},
|
|
159
|
+
): {
|
|
160
|
+
svg: string
|
|
161
|
+
width: number
|
|
162
|
+
height: number
|
|
163
|
+
} {
|
|
164
|
+
const source = findSvg(target)
|
|
165
|
+
const clone = source.cloneNode(true) as SVGSVGElement
|
|
166
|
+
const originals = [source, ...Array.from(source.querySelectorAll('*'))]
|
|
167
|
+
const copies = [clone, ...Array.from(clone.querySelectorAll('*'))]
|
|
168
|
+
originals.forEach((original, i) => {
|
|
169
|
+
const copy = copies[i]
|
|
170
|
+
if (!copy) return
|
|
171
|
+
const computed = getComputedStyle(original)
|
|
172
|
+
for (const property of PROPERTIES) {
|
|
173
|
+
const attribute = original.getAttribute(property)
|
|
174
|
+
let value = computed.getPropertyValue(property).trim()
|
|
175
|
+
if ((!value || value.includes('var(')) && attribute) value = attribute
|
|
176
|
+
if (!value) continue
|
|
177
|
+
if (value.includes('var(')) value = resolveCssVariables(value, original)
|
|
178
|
+
if (value) copy.setAttribute(property, value)
|
|
179
|
+
}
|
|
180
|
+
const inline = copy.getAttribute('style')
|
|
181
|
+
if (inline?.includes('var(')) copy.setAttribute('style', resolveCssVariables(inline, original))
|
|
182
|
+
copy.removeAttribute('class')
|
|
183
|
+
copy.removeAttribute('tabindex')
|
|
184
|
+
copy.removeAttribute('role')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const rect = source.getBoundingClientRect()
|
|
188
|
+
const plotWidth = Math.round(rect.width || Number(source.getAttribute('width')) || 600)
|
|
189
|
+
const plotHeight = Math.round(rect.height || Number(source.getAttribute('height')) || 300)
|
|
190
|
+
const box = contentBox(source, plotWidth, plotHeight)
|
|
191
|
+
const innerWidth = Math.round(box.width * box.scale)
|
|
192
|
+
const innerHeight = Math.round(box.height * box.scale)
|
|
193
|
+
|
|
194
|
+
const figure = source.closest('[data-slot=chart], [data-slot=gauge]')
|
|
195
|
+
const fontFamily = getComputedStyle(figure ?? source).fontFamily || 'system-ui, sans-serif'
|
|
196
|
+
const pad = 16
|
|
197
|
+
const titleElement = figure?.querySelector('figcaption [id]') ?? null
|
|
198
|
+
const titleText =
|
|
199
|
+
options.title === false
|
|
200
|
+
? ''
|
|
201
|
+
: typeof options.title === 'string'
|
|
202
|
+
? options.title
|
|
203
|
+
: (titleElement?.textContent ?? '').trim()
|
|
204
|
+
const header = titleText ? 30 : 0
|
|
205
|
+
|
|
206
|
+
const legendItems =
|
|
207
|
+
options.legend === false || !figure
|
|
208
|
+
? []
|
|
209
|
+
: Array.from(figure.querySelectorAll('[data-slot=chart-legend] li')).map((item) => {
|
|
210
|
+
const swatch = item.querySelector('span[style]')
|
|
211
|
+
const button = item.querySelector('button')
|
|
212
|
+
return {
|
|
213
|
+
label: (item.textContent ?? '').trim(),
|
|
214
|
+
color: swatch ? colorOf(swatch, 'backgroundColor') : '',
|
|
215
|
+
hidden: button?.getAttribute('aria-pressed') === 'false',
|
|
216
|
+
text: colorOf(item, 'color') || colorOf(figure, 'color'),
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
const legendRows: { x: number; row: number; item: (typeof legendItems)[number] }[] = []
|
|
220
|
+
let cursor = 0
|
|
221
|
+
let row = 0
|
|
222
|
+
for (const item of legendItems) {
|
|
223
|
+
const itemWidth = 16 + item.label.length * 6.6 + 16
|
|
224
|
+
if (cursor > 0 && cursor + itemWidth > innerWidth) {
|
|
225
|
+
cursor = 0
|
|
226
|
+
row++
|
|
227
|
+
}
|
|
228
|
+
legendRows.push({ x: cursor, row, item })
|
|
229
|
+
cursor += itemWidth
|
|
230
|
+
}
|
|
231
|
+
const legendHeight = legendItems.length > 0 ? (row + 1) * 20 + 8 : 0
|
|
232
|
+
|
|
233
|
+
const width = innerWidth + pad * 2
|
|
234
|
+
const height = pad + header + innerHeight + legendHeight + pad
|
|
235
|
+
const root = svgElement('svg', {
|
|
236
|
+
xmlns: SVG_NS,
|
|
237
|
+
width,
|
|
238
|
+
height,
|
|
239
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
240
|
+
'font-family': fontFamily,
|
|
241
|
+
})
|
|
242
|
+
const fill = options.background ?? surfaceColor(source)
|
|
243
|
+
if (fill !== 'transparent') root.append(svgElement('rect', { x: 0, y: 0, width, height, fill }))
|
|
244
|
+
if (titleText) {
|
|
245
|
+
const title = svgElement('text', {
|
|
246
|
+
x: pad,
|
|
247
|
+
y: pad + 14,
|
|
248
|
+
'font-size': 14,
|
|
249
|
+
'font-weight': 600,
|
|
250
|
+
fill: titleElement ? colorOf(titleElement, 'color') : colorOf(source, 'color'),
|
|
251
|
+
})
|
|
252
|
+
title.textContent = titleText
|
|
253
|
+
root.append(title)
|
|
254
|
+
}
|
|
255
|
+
clone.removeAttribute('style')
|
|
256
|
+
clone.setAttribute('x', String(pad))
|
|
257
|
+
clone.setAttribute('y', String(pad + header))
|
|
258
|
+
clone.setAttribute('width', String(innerWidth))
|
|
259
|
+
clone.setAttribute('height', String(innerHeight))
|
|
260
|
+
clone.setAttribute('viewBox', `${box.x} ${box.y} ${box.width} ${box.height}`)
|
|
261
|
+
clone.setAttribute('overflow', 'visible')
|
|
262
|
+
root.append(clone)
|
|
263
|
+
for (const { x, row: line, item } of legendRows) {
|
|
264
|
+
const y = pad + header + innerHeight + 12 + line * 20
|
|
265
|
+
const group = svgElement('g', { opacity: item.hidden ? 0.45 : 1 })
|
|
266
|
+
group.append(
|
|
267
|
+
svgElement('rect', { x: pad + x, y: y, width: 10, height: 10, rx: 2, fill: item.color }),
|
|
268
|
+
)
|
|
269
|
+
const label = svgElement('text', {
|
|
270
|
+
x: pad + x + 16,
|
|
271
|
+
y: y + 9,
|
|
272
|
+
'font-size': 12,
|
|
273
|
+
fill: item.text,
|
|
274
|
+
})
|
|
275
|
+
label.textContent = item.label
|
|
276
|
+
group.append(label)
|
|
277
|
+
root.append(group)
|
|
278
|
+
}
|
|
279
|
+
return { svg: new XMLSerializer().serializeToString(root), width, height }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function save(blob: Blob, name: string) {
|
|
283
|
+
const url = URL.createObjectURL(blob)
|
|
284
|
+
const link = document.createElement('a')
|
|
285
|
+
link.href = url
|
|
286
|
+
link.download = name
|
|
287
|
+
document.body.append(link)
|
|
288
|
+
link.click()
|
|
289
|
+
link.remove()
|
|
290
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Downloads a chart as PNG or SVG, with the theme's colors baked in. Pass the chart's
|
|
295
|
+
* element (or a ref to it, or to any wrapper such as a ChartCard). Resolves with the file.
|
|
296
|
+
*/
|
|
297
|
+
export async function exportChart(target: Target, options: ExportChartOptions = {}): Promise<Blob> {
|
|
298
|
+
const { format = 'png', fileName = 'chart', download = true } = options
|
|
299
|
+
const { svg, width, height } = serializeChart(target, {
|
|
300
|
+
...(options.background !== undefined && { background: options.background }),
|
|
301
|
+
...(options.title !== undefined && { title: options.title }),
|
|
302
|
+
...(options.legend !== undefined && { legend: options.legend }),
|
|
303
|
+
})
|
|
304
|
+
let blob: Blob
|
|
305
|
+
if (format === 'svg') {
|
|
306
|
+
blob = new Blob([svg], { type: 'image/svg+xml;charset=utf-8' })
|
|
307
|
+
} else {
|
|
308
|
+
const scale = options.scale ?? Math.max(window.devicePixelRatio || 1, 2)
|
|
309
|
+
const image = new Image()
|
|
310
|
+
image.decoding = 'async'
|
|
311
|
+
const loaded = new Promise<void>((resolve, reject) => {
|
|
312
|
+
image.onload = () => resolve()
|
|
313
|
+
image.onerror = () => reject(new Error('exportChart: the chart could not be rendered.'))
|
|
314
|
+
})
|
|
315
|
+
image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`
|
|
316
|
+
await loaded
|
|
317
|
+
const canvas = document.createElement('canvas')
|
|
318
|
+
canvas.width = Math.round(width * scale)
|
|
319
|
+
canvas.height = Math.round(height * scale)
|
|
320
|
+
const context = canvas.getContext('2d')
|
|
321
|
+
if (!context) throw new Error('exportChart: canvas is not available.')
|
|
322
|
+
context.scale(scale, scale)
|
|
323
|
+
context.drawImage(image, 0, 0, width, height)
|
|
324
|
+
blob = await new Promise<Blob>((resolve, reject) =>
|
|
325
|
+
canvas.toBlob(
|
|
326
|
+
(result) =>
|
|
327
|
+
result ? resolve(result) : reject(new Error('exportChart: PNG encoding failed.')),
|
|
328
|
+
'image/png',
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
if (download) save(blob, `${fileName}.${format}`)
|
|
333
|
+
return blob
|
|
334
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type ReactNode, useEffect, useState } from 'react'
|
|
2
|
+
import { useMotionSettings } from '../../motion/use-motion-settings'
|
|
3
|
+
import {
|
|
4
|
+
type ChartColorValue,
|
|
5
|
+
ChartFrame,
|
|
6
|
+
type ChartStateProps,
|
|
7
|
+
defaultFormatter,
|
|
8
|
+
type Key,
|
|
9
|
+
resolveColor,
|
|
10
|
+
} from './chart-parts'
|
|
11
|
+
import { useElementWidth } from './use-element-width'
|
|
12
|
+
|
|
13
|
+
type Row = Record<string, unknown>
|
|
14
|
+
|
|
15
|
+
export interface FunnelChartProps<T extends object> extends ChartStateProps {
|
|
16
|
+
/** One row per stage, in order. */
|
|
17
|
+
data: readonly T[]
|
|
18
|
+
/** Field naming each stage, e.g. `"stage"`. */
|
|
19
|
+
category: Key<T>
|
|
20
|
+
/** Field holding how many reached the stage. */
|
|
21
|
+
value: Key<T>
|
|
22
|
+
title: string
|
|
23
|
+
description?: ReactNode
|
|
24
|
+
hideTitle?: boolean
|
|
25
|
+
/** Default `chart-1`. Later stages are lighter tints of it. */
|
|
26
|
+
color?: ChartColorValue
|
|
27
|
+
valueFormatter?: (value: number) => string
|
|
28
|
+
/** Under each value: share of the first stage or of the previous one. Default `previous`. */
|
|
29
|
+
conversion?: 'first' | 'previous' | 'none'
|
|
30
|
+
className?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ROW = 44
|
|
34
|
+
const GAP = 6
|
|
35
|
+
|
|
36
|
+
const percent = (value: number) =>
|
|
37
|
+
`${value >= 0.1 ? Math.round(value * 100) : Math.round(value * 1000) / 10}%`
|
|
38
|
+
|
|
39
|
+
/** How many make it through each step of a flow, e.g. visit → signup → paid. */
|
|
40
|
+
export function FunnelChart<T extends object>(props: FunnelChartProps<T>) {
|
|
41
|
+
const {
|
|
42
|
+
data,
|
|
43
|
+
category,
|
|
44
|
+
value,
|
|
45
|
+
valueFormatter = defaultFormatter,
|
|
46
|
+
conversion = 'previous',
|
|
47
|
+
} = props
|
|
48
|
+
const { animate } = useMotionSettings()
|
|
49
|
+
const [ref, width] = useElementWidth<HTMLDivElement>()
|
|
50
|
+
const [grown, setGrown] = useState(!animate)
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const frame = requestAnimationFrame(() => setGrown(true))
|
|
53
|
+
return () => cancelAnimationFrame(frame)
|
|
54
|
+
}, [])
|
|
55
|
+
|
|
56
|
+
const rows = data.map((row) => ({
|
|
57
|
+
name: String((row as Row)[category]),
|
|
58
|
+
value: Number((row as Row)[value]) || 0,
|
|
59
|
+
}))
|
|
60
|
+
const first = rows[0]?.value || 1
|
|
61
|
+
const base = resolveColor(props.color ?? 'chart-1', 0)
|
|
62
|
+
const labelWidth = Math.min(Math.max(width * 0.26, 88), 180)
|
|
63
|
+
const valueWidth = Math.min(Math.max(width * 0.2, 84), 132)
|
|
64
|
+
const area = Math.max(width - labelWidth - valueWidth - 16, 40)
|
|
65
|
+
const height = rows.length * ROW + Math.max(rows.length - 1, 0) * GAP
|
|
66
|
+
const rate = (i: number) => {
|
|
67
|
+
const reference = conversion === 'first' ? first : (rows[i - 1]?.value ?? first)
|
|
68
|
+
return rows[i]!.value / (reference || 1)
|
|
69
|
+
}
|
|
70
|
+
const table = {
|
|
71
|
+
columns: [
|
|
72
|
+
String(category),
|
|
73
|
+
String(value),
|
|
74
|
+
...(conversion === 'none' ? [] : [conversion === 'first' ? '% of first' : '% of previous']),
|
|
75
|
+
],
|
|
76
|
+
rows: rows.map((row, i) => [
|
|
77
|
+
row.name,
|
|
78
|
+
valueFormatter(row.value),
|
|
79
|
+
...(conversion === 'none' ? [] : [i === 0 ? '100%' : percent(rate(i))]),
|
|
80
|
+
]),
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<ChartFrame
|
|
85
|
+
title={props.title}
|
|
86
|
+
description={props.description}
|
|
87
|
+
hideTitle={props.hideTitle}
|
|
88
|
+
className={props.className}
|
|
89
|
+
table={table}
|
|
90
|
+
height={height || 200}
|
|
91
|
+
isEmpty={rows.length === 0}
|
|
92
|
+
loading={props.loading}
|
|
93
|
+
error={props.error}
|
|
94
|
+
onRetry={props.onRetry}
|
|
95
|
+
empty={props.empty}
|
|
96
|
+
>
|
|
97
|
+
<div ref={ref} className="w-full">
|
|
98
|
+
<svg
|
|
99
|
+
width={width}
|
|
100
|
+
height={height}
|
|
101
|
+
viewBox={`0 0 ${width} ${height}`}
|
|
102
|
+
className="block"
|
|
103
|
+
aria-hidden="true"
|
|
104
|
+
>
|
|
105
|
+
{rows.map((row, i) => {
|
|
106
|
+
const y = i * (ROW + GAP)
|
|
107
|
+
const barWidth = Math.max((row.value / first) * area, 2)
|
|
108
|
+
const x = labelWidth + 8 + (area - barWidth) / 2
|
|
109
|
+
const mix = Math.max(100 - i * 14, 40)
|
|
110
|
+
const fill =
|
|
111
|
+
i === 0 ? base : `color-mix(in oklab, ${base} ${mix}%, var(--glyph-surface))`
|
|
112
|
+
return (
|
|
113
|
+
<g key={row.name}>
|
|
114
|
+
<text
|
|
115
|
+
x={0}
|
|
116
|
+
y={y + ROW / 2}
|
|
117
|
+
dominantBaseline="central"
|
|
118
|
+
fill="var(--glyph-foreground)"
|
|
119
|
+
fontSize={13}
|
|
120
|
+
>
|
|
121
|
+
{row.name}
|
|
122
|
+
</text>
|
|
123
|
+
<rect
|
|
124
|
+
x={x}
|
|
125
|
+
y={y + 4}
|
|
126
|
+
width={barWidth}
|
|
127
|
+
height={ROW - 8}
|
|
128
|
+
rx={4}
|
|
129
|
+
fill={fill}
|
|
130
|
+
style={{
|
|
131
|
+
transformBox: 'fill-box',
|
|
132
|
+
transformOrigin: 'center',
|
|
133
|
+
transform: grown ? 'scaleX(1)' : 'scaleX(0)',
|
|
134
|
+
transition: animate
|
|
135
|
+
? `transform calc(var(--glyph-duration-slow) * 2) var(--glyph-ease-emphasized) ${i * 60}ms`
|
|
136
|
+
: undefined,
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
<text
|
|
140
|
+
x={width}
|
|
141
|
+
y={conversion === 'none' || i === 0 ? y + ROW / 2 : y + ROW / 2 - 8}
|
|
142
|
+
dominantBaseline="central"
|
|
143
|
+
textAnchor="end"
|
|
144
|
+
fill="var(--glyph-foreground)"
|
|
145
|
+
fontSize={13}
|
|
146
|
+
fontWeight={500}
|
|
147
|
+
style={{ fontVariantNumeric: 'tabular-nums' }}
|
|
148
|
+
>
|
|
149
|
+
{valueFormatter(row.value)}
|
|
150
|
+
</text>
|
|
151
|
+
{conversion !== 'none' && i > 0 && (
|
|
152
|
+
<text
|
|
153
|
+
x={width}
|
|
154
|
+
y={y + ROW / 2 + 9}
|
|
155
|
+
dominantBaseline="central"
|
|
156
|
+
textAnchor="end"
|
|
157
|
+
fill="var(--glyph-muted-foreground)"
|
|
158
|
+
fontSize={11}
|
|
159
|
+
style={{ fontVariantNumeric: 'tabular-nums' }}
|
|
160
|
+
>
|
|
161
|
+
{percent(rate(i))} {conversion === 'first' ? 'of total' : 'converted'}
|
|
162
|
+
</text>
|
|
163
|
+
)}
|
|
164
|
+
</g>
|
|
165
|
+
)
|
|
166
|
+
})}
|
|
167
|
+
</svg>
|
|
168
|
+
</div>
|
|
169
|
+
</ChartFrame>
|
|
170
|
+
)
|
|
171
|
+
}
|