@shohojdhara/atomix 0.1.30 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/README.md +151 -39
- package/dist/atomix.css +13529 -0
- package/dist/atomix.min.css +15 -0
- package/dist/index.d.ts +6112 -1757
- package/dist/index.esm.js +16852 -8364
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16892 -8369
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/themes/boomdevs.css +13241 -0
- package/dist/themes/boomdevs.min.css +353 -0
- package/dist/themes/esrar.css +15374 -0
- package/dist/themes/esrar.min.css +189 -0
- package/dist/themes/mashroom.css +28079 -0
- package/dist/themes/mashroom.min.css +403 -0
- package/dist/themes/shaj-default.css +14203 -0
- package/dist/themes/shaj-default.min.css +500 -0
- package/dist/themes/yabai.css +13711 -0
- package/dist/themes/yabai.min.css +189 -0
- package/package.json +126 -99
- package/src/components/Accordion/Accordion.stories.tsx +271 -0
- package/src/components/Accordion/Accordion.tsx +131 -0
- package/src/components/Accordion/index.ts +3 -0
- package/src/components/AtomixLogo/AtomixLogo.tsx +36 -0
- package/src/components/AtomixLogo/index.ts +3 -0
- package/src/components/AtomixLogo.tsx +40 -0
- package/src/components/Avatar/Avatar.stories.tsx +257 -0
- package/src/components/Avatar/Avatar.tsx +68 -0
- package/src/components/Avatar/AvatarGroup.tsx +73 -0
- package/src/components/Avatar/index.ts +3 -0
- package/src/components/Badge/Badge.stories.tsx +371 -0
- package/src/components/Badge/Badge.tsx +39 -0
- package/src/components/Badge/index.ts +3 -0
- package/src/components/Block/Block.stories.tsx +408 -0
- package/src/components/Block/Block.tsx +137 -0
- package/src/components/Block/index.ts +1 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +106 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +112 -0
- package/src/components/Breadcrumb/index.ts +3 -0
- package/src/components/Button/Button.stories.tsx +312 -0
- package/src/components/Button/Button.tsx +69 -0
- package/src/components/Button/index.ts +3 -0
- package/src/components/Callout/Callout.stories.tsx +588 -0
- package/src/components/Callout/Callout.tsx +78 -0
- package/src/components/Callout/index.ts +1 -0
- package/src/components/Card/Card.stories.tsx +105 -0
- package/src/components/Card/Card.tsx +69 -0
- package/src/components/Card/ElevationCard.tsx +47 -0
- package/src/components/Card/index.ts +15 -0
- package/src/components/Chart/AdvancedChart.tsx +624 -0
- package/src/components/Chart/AnimatedChart.tsx +206 -0
- package/src/components/Chart/AreaChart.tsx +27 -0
- package/src/components/Chart/BarChart.tsx +148 -0
- package/src/components/Chart/BubbleChart.tsx +411 -0
- package/src/components/Chart/CandlestickChart.tsx +765 -0
- package/src/components/Chart/Chart.stories.tsx +527 -0
- package/src/components/Chart/Chart.tsx +218 -0
- package/src/components/Chart/ChartRenderer.tsx +322 -0
- package/src/components/Chart/ChartToolbar.tsx +436 -0
- package/src/components/Chart/ChartTooltip.tsx +101 -0
- package/src/components/Chart/DonutChart.tsx +370 -0
- package/src/components/Chart/FunnelChart.tsx +393 -0
- package/src/components/Chart/GaugeChart.tsx +550 -0
- package/src/components/Chart/HeatmapChart.tsx +614 -0
- package/src/components/Chart/LineChart.tsx +172 -0
- package/src/components/Chart/LineChartNew.tsx +167 -0
- package/src/components/Chart/MultiAxisChart.tsx +498 -0
- package/src/components/Chart/PieChart.tsx +103 -0
- package/src/components/Chart/RadarChart.tsx +332 -0
- package/src/components/Chart/RealTimeChart.tsx +436 -0
- package/src/components/Chart/ScatterChart.tsx +152 -0
- package/src/components/Chart/TreemapChart.tsx +574 -0
- package/src/components/Chart/WaterfallChart.tsx +450 -0
- package/src/components/Chart/index.ts +119 -0
- package/src/components/Chart/types.ts +338 -0
- package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +44 -0
- package/src/components/ColorModeToggle/ColorModeToggle.tsx +85 -0
- package/src/components/ColorModeToggle/index.ts +2 -0
- package/src/components/Countdown/Countdown.stories.tsx +46 -0
- package/src/components/Countdown/Countdown.tsx +90 -0
- package/src/components/Countdown/index.ts +2 -0
- package/src/components/DataTable/DataTable.stories.tsx +248 -0
- package/src/components/DataTable/DataTable.tsx +213 -0
- package/src/components/DataTable/index.ts +3 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +364 -0
- package/src/components/DatePicker/DatePicker.tsx +504 -0
- package/src/components/DatePicker/index.ts +4 -0
- package/src/components/DatePicker/readme.md +106 -0
- package/src/components/DatePicker/types.ts +167 -0
- package/src/components/DatePicker/utils.ts +185 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +358 -0
- package/src/components/Dropdown/Dropdown.tsx +352 -0
- package/src/components/Dropdown/index.ts +14 -0
- package/src/components/Dropdown/readme.md +151 -0
- package/src/components/EdgePanel/EdgePanel.stories.tsx +266 -0
- package/src/components/EdgePanel/EdgePanel.tsx +73 -0
- package/src/components/EdgePanel/index.ts +1 -0
- package/src/components/Form/Checkbox.stories.tsx +76 -0
- package/src/components/Form/Checkbox.tsx +69 -0
- package/src/components/Form/Form.stories.tsx +497 -0
- package/src/components/Form/Form.tsx +46 -0
- package/src/components/Form/FormGroup.stories.tsx +162 -0
- package/src/components/Form/FormGroup.tsx +53 -0
- package/src/components/Form/Input.stories.tsx +106 -0
- package/src/components/Form/Input.tsx +87 -0
- package/src/components/Form/Radio.stories.tsx +94 -0
- package/src/components/Form/Radio.tsx +65 -0
- package/src/components/Form/Select.stories.tsx +151 -0
- package/src/components/Form/Select.tsx +191 -0
- package/src/components/Form/Textarea.stories.tsx +123 -0
- package/src/components/Form/Textarea.tsx +78 -0
- package/src/components/Form/index.ts +7 -0
- package/src/components/Hero/Hero.stories.tsx +295 -0
- package/src/components/Hero/Hero.tsx +175 -0
- package/src/components/Hero/index.ts +6 -0
- package/src/components/Icon/Icon.tsx +87 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/List/List.stories.tsx +122 -0
- package/src/components/List/List.tsx +35 -0
- package/src/components/List/ListGroup.tsx +35 -0
- package/src/components/List/index.ts +2 -0
- package/src/components/Messages/Messages.stories.tsx +160 -0
- package/src/components/Messages/Messages.tsx +172 -0
- package/src/components/Messages/index.ts +3 -0
- package/src/components/Modal/Modal.stories.tsx +284 -0
- package/src/components/Modal/Modal.tsx +198 -0
- package/src/components/Modal/README.md +169 -0
- package/src/components/Modal/index.ts +1 -0
- package/src/components/Navigation/Menu/MegaMenu.tsx +109 -0
- package/src/components/Navigation/Menu/Menu.stories.tsx +339 -0
- package/src/components/Navigation/Menu/Menu.tsx +111 -0
- package/src/components/Navigation/Nav/Nav.stories.tsx +456 -0
- package/src/components/Navigation/Nav/Nav.tsx +51 -0
- package/src/components/Navigation/Nav/NavDropdown.tsx +105 -0
- package/src/components/Navigation/Nav/NavItem.tsx +168 -0
- package/src/components/Navigation/Navbar/Navbar.stories.tsx +569 -0
- package/src/components/Navigation/Navbar/Navbar.tsx +150 -0
- package/src/components/Navigation/README.md +314 -0
- package/src/components/Navigation/SideMenu/SideMenu.README.md +494 -0
- package/src/components/Navigation/SideMenu/SideMenu.stories.tsx +609 -0
- package/src/components/Navigation/SideMenu/SideMenu.tsx +101 -0
- package/src/components/Navigation/SideMenu/SideMenuItem.tsx +103 -0
- package/src/components/Navigation/SideMenu/SideMenuList.tsx +41 -0
- package/src/components/Navigation/index.ts +23 -0
- package/src/components/Pagination/Pagination.stories.tsx +188 -0
- package/src/components/Pagination/Pagination.tsx +162 -0
- package/src/components/Pagination/index.ts +1 -0
- package/src/components/PhotoViewer/PhotoViewer.stories.tsx +397 -0
- package/src/components/PhotoViewer/PhotoViewer.tsx +246 -0
- package/src/components/PhotoViewer/PhotoViewerHeader.tsx +184 -0
- package/src/components/PhotoViewer/PhotoViewerImage.tsx +173 -0
- package/src/components/PhotoViewer/PhotoViewerInfo.tsx +91 -0
- package/src/components/PhotoViewer/PhotoViewerNavigation.tsx +85 -0
- package/src/components/PhotoViewer/PhotoViewerThumbnails.tsx +63 -0
- package/src/components/PhotoViewer/README.md +358 -0
- package/src/components/PhotoViewer/examples/ImageGallery.tsx +187 -0
- package/src/components/PhotoViewer/examples/SimpleGallery.tsx +73 -0
- package/src/components/PhotoViewer/examples/index.ts +2 -0
- package/src/components/PhotoViewer/index.ts +14 -0
- package/src/components/Popover/Popover.stories.tsx +143 -0
- package/src/components/Popover/Popover.tsx +137 -0
- package/src/components/Popover/index.ts +5 -0
- package/src/components/Popover/readme.md +120 -0
- package/src/components/ProductReview/ProductReview.stories.tsx +88 -0
- package/src/components/ProductReview/ProductReview.tsx +169 -0
- package/src/components/ProductReview/index.ts +3 -0
- package/src/components/Progress/Progress.stories.tsx +75 -0
- package/src/components/Progress/Progress.tsx +45 -0
- package/src/components/Progress/index.ts +1 -0
- package/src/components/Rating/Rating.stories.tsx +109 -0
- package/src/components/Rating/Rating.tsx +286 -0
- package/src/components/Rating/index.ts +6 -0
- package/src/components/River/River.stories.tsx +230 -0
- package/src/components/River/River.tsx +134 -0
- package/src/components/River/index.ts +2 -0
- package/src/components/SectionIntro/SectionIntro.stories.tsx +143 -0
- package/src/components/SectionIntro/SectionIntro.tsx +184 -0
- package/src/components/SectionIntro/index.ts +3 -0
- package/src/components/Slider/Slider.stories.tsx +241 -0
- package/src/components/Slider/Slider.tsx +225 -0
- package/src/components/Slider/index.ts +24 -0
- package/src/components/Spinner/Spinner.stories.tsx +65 -0
- package/src/components/Spinner/Spinner.tsx +36 -0
- package/src/components/Spinner/index.ts +2 -0
- package/src/components/Steps/Steps.stories.tsx +158 -0
- package/src/components/Steps/Steps.tsx +115 -0
- package/src/components/Steps/index.ts +3 -0
- package/src/components/Tab/Tab.stories.tsx +129 -0
- package/src/components/Tab/Tab.tsx +111 -0
- package/src/components/Tab/index.ts +2 -0
- package/src/components/Testimonial/Testimonial.stories.tsx +180 -0
- package/src/components/Testimonial/Testimonial.tsx +138 -0
- package/src/components/Testimonial/index.ts +3 -0
- package/src/components/Todo/Todo.stories.tsx +103 -0
- package/src/components/Todo/Todo.tsx +158 -0
- package/src/components/Todo/index.ts +1 -0
- package/src/components/Toggle/Toggle.stories.tsx +49 -0
- package/src/components/Toggle/Toggle.tsx +84 -0
- package/src/components/Toggle/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +115 -0
- package/src/components/Tooltip/Tooltip.tsx +150 -0
- package/src/components/Tooltip/index.ts +3 -0
- package/src/components/Upload/Upload.stories.tsx +220 -0
- package/src/components/Upload/Upload.tsx +354 -0
- package/src/components/Upload/index.ts +3 -0
- package/src/components/VideoPlayer/VideoPlayer.stories.tsx +484 -0
- package/src/components/VideoPlayer/VideoPlayer.tsx +574 -0
- package/src/components/VideoPlayer/index.ts +7 -0
- package/src/components/index.ts +111 -0
- package/src/layouts/Grid/Container.tsx +58 -0
- package/src/layouts/Grid/Grid.stories.tsx +861 -0
- package/src/layouts/Grid/Grid.tsx +68 -0
- package/src/layouts/Grid/GridCol.tsx +161 -0
- package/src/layouts/Grid/README.md +108 -0
- package/src/layouts/Grid/Row.tsx +70 -0
- package/src/layouts/Grid/index.ts +8 -0
- package/src/layouts/MasonryGrid/MasonryGrid.stories.tsx +387 -0
- package/src/layouts/MasonryGrid/MasonryGrid.tsx +408 -0
- package/src/layouts/MasonryGrid/MasonryGridItem.tsx +44 -0
- package/src/layouts/MasonryGrid/README.md +117 -0
- package/src/layouts/MasonryGrid/index.ts +4 -0
- package/src/layouts/index.ts +7 -0
- package/src/lib/README.md +89 -0
- package/src/lib/composables/index.ts +63 -0
- package/src/lib/composables/useAccordion.ts +129 -0
- package/src/lib/composables/useAmbientMode.ts +90 -0
- package/src/lib/composables/useBadge.ts +42 -0
- package/src/lib/composables/useBarChart.ts +365 -0
- package/src/lib/composables/useBlock.ts +56 -0
- package/src/lib/composables/useBreadcrumb.ts +81 -0
- package/src/lib/composables/useButton.ts +59 -0
- package/src/lib/composables/useCallout.ts +55 -0
- package/src/lib/composables/useCard.ts +155 -0
- package/src/lib/composables/useChart.ts +1082 -0
- package/src/lib/composables/useChartAnalytics.ts +505 -0
- package/src/lib/composables/useChartData.ts +38 -0
- package/src/lib/composables/useChartExport.ts +392 -0
- package/src/lib/composables/useChartInteraction.ts +34 -0
- package/src/lib/composables/useChartInteractions.ts +123 -0
- package/src/lib/composables/useChartPerformance.ts +323 -0
- package/src/lib/composables/useChartScale.ts +48 -0
- package/src/lib/composables/useChartToolbar.ts +532 -0
- package/src/lib/composables/useCheckbox.ts +70 -0
- package/src/lib/composables/useDataTable.ts +208 -0
- package/src/lib/composables/useDatePicker.ts +564 -0
- package/src/lib/composables/useDropdown.ts +272 -0
- package/src/lib/composables/useEdgePanel.ts +261 -0
- package/src/lib/composables/useForm.ts +62 -0
- package/src/lib/composables/useFormGroup.ts +51 -0
- package/src/lib/composables/useHero.ts +250 -0
- package/src/lib/composables/useInput.ts +58 -0
- package/src/lib/composables/useLineChart.ts +319 -0
- package/src/lib/composables/useMessages.ts +77 -0
- package/src/lib/composables/useModal.ts +110 -0
- package/src/lib/composables/useNavbar.ts +288 -0
- package/src/lib/composables/usePagination.ts +101 -0
- package/src/lib/composables/usePhotoViewer.ts +937 -0
- package/src/lib/composables/usePieChart.ts +362 -0
- package/src/lib/composables/usePopover.ts +354 -0
- package/src/lib/composables/useProgress.ts +74 -0
- package/src/lib/composables/useRadio.ts +47 -0
- package/src/lib/composables/useRating.ts +174 -0
- package/src/lib/composables/useRiver.ts +205 -0
- package/src/lib/composables/useSelect.ts +52 -0
- package/src/lib/composables/useSideMenu.ts +197 -0
- package/src/lib/composables/useSlider.ts +339 -0
- package/src/lib/composables/useSpinner.ts +42 -0
- package/src/lib/composables/useTextarea.ts +55 -0
- package/src/lib/composables/useTodo.ts +141 -0
- package/src/lib/composables/useVideoPlayer.ts +398 -0
- package/src/lib/constants/components.ts +1433 -0
- package/src/lib/constants/index.ts +4 -0
- package/src/lib/index.ts +11 -0
- package/src/lib/types/components.ts +4750 -0
- package/src/lib/types/index.ts +2 -0
- package/src/lib/utils/dom.ts +41 -0
- package/src/lib/utils/icons.ts +74 -0
- package/src/lib/utils/index.ts +55 -0
- package/src/lib/utils/useForkRef.test.tsx +64 -0
- package/src/lib/utils/useForkRef.ts +36 -0
- package/src/lib/utils.test.ts +14 -0
- package/src/styles/01-settings/_index.scss +2 -0
- package/src/styles/01-settings/_settings.accordion.scss +7 -5
- package/src/styles/01-settings/_settings.animations.scss +0 -0
- package/src/styles/01-settings/_settings.avatar-group.scss +6 -3
- package/src/styles/01-settings/_settings.avatar.scss +2 -2
- package/src/styles/01-settings/_settings.badge.scss +15 -9
- package/src/styles/01-settings/_settings.block.scss +11 -0
- package/src/styles/01-settings/_settings.border-radius.scss +12 -9
- package/src/styles/01-settings/_settings.border.scss +4 -1
- package/src/styles/01-settings/_settings.box-shadow.scss +1 -1
- package/src/styles/01-settings/_settings.breadcrumb.scss +9 -8
- package/src/styles/01-settings/_settings.breakpoints.scss +0 -0
- package/src/styles/01-settings/_settings.btn-group.scss +4 -1
- package/src/styles/01-settings/_settings.button.scss +19 -21
- package/src/styles/01-settings/_settings.callout.scss +42 -24
- package/src/styles/01-settings/_settings.card.scss +12 -10
- package/src/styles/01-settings/_settings.chart.scss +199 -0
- package/src/styles/01-settings/_settings.checkbox-group.scss +0 -0
- package/src/styles/01-settings/_settings.checkbox.scss +0 -0
- package/src/styles/01-settings/_settings.color-mode.scss +0 -0
- package/src/styles/01-settings/_settings.colors.scss +20 -0
- package/src/styles/01-settings/_settings.config.scss +1 -1
- package/src/styles/01-settings/_settings.countdown.scss +0 -0
- package/src/styles/01-settings/_settings.data-table.scss +0 -0
- package/src/styles/01-settings/_settings.datepicker.scss +0 -0
- package/src/styles/01-settings/_settings.dropdown.scss +0 -0
- package/src/styles/01-settings/_settings.edge-panel.scss +0 -0
- package/src/styles/01-settings/_settings.fonts.scss +1 -1
- package/src/styles/01-settings/_settings.form-group.scss +0 -0
- package/src/styles/01-settings/_settings.form.scss +0 -0
- package/src/styles/01-settings/_settings.grid.scss +3 -3
- package/src/styles/01-settings/_settings.hero.scss +1 -1
- package/src/styles/01-settings/_settings.input.scss +1 -1
- package/src/styles/01-settings/_settings.link.scss +0 -0
- package/src/styles/01-settings/_settings.list-group.scss +0 -0
- package/src/styles/01-settings/_settings.list.scss +0 -0
- package/src/styles/01-settings/_settings.maps.scss +43 -8
- package/src/styles/01-settings/_settings.masonry-grid.scss +0 -0
- package/src/styles/01-settings/_settings.menu.scss +0 -0
- package/src/styles/01-settings/_settings.messages.scss +0 -0
- package/src/styles/01-settings/_settings.modal.scss +1 -1
- package/src/styles/01-settings/_settings.nav.scss +0 -0
- package/src/styles/01-settings/_settings.navbar.scss +0 -0
- package/src/styles/01-settings/_settings.pagination.scss +0 -0
- package/src/styles/01-settings/_settings.photoviewer.scss +89 -23
- package/src/styles/01-settings/_settings.popover.scss +0 -0
- package/src/styles/01-settings/_settings.position.scss +0 -0
- package/src/styles/01-settings/_settings.progress.scss +0 -0
- package/src/styles/01-settings/_settings.rating.scss +0 -0
- package/src/styles/01-settings/_settings.river.scss +0 -0
- package/src/styles/01-settings/_settings.sectionintro.scss +0 -0
- package/src/styles/01-settings/_settings.select.scss +0 -0
- package/src/styles/01-settings/_settings.side-menu.scss +0 -0
- package/src/styles/01-settings/_settings.skeleton.scss +0 -0
- package/src/styles/01-settings/_settings.slider.scss +59 -0
- package/src/styles/01-settings/_settings.spacing.scss +11 -3
- package/src/styles/01-settings/_settings.spinner.scss +0 -0
- package/src/styles/01-settings/_settings.steps.scss +1 -1
- package/src/styles/01-settings/_settings.tabs.scss +4 -4
- package/src/styles/01-settings/_settings.testimonials.scss +0 -0
- package/src/styles/01-settings/_settings.todo.scss +0 -0
- package/src/styles/01-settings/_settings.toggle.scss +1 -1
- package/src/styles/01-settings/_settings.tooltip.scss +0 -0
- package/src/styles/01-settings/_settings.typography.scss +2 -0
- package/src/styles/01-settings/_settings.upload.scss +0 -0
- package/src/styles/01-settings/_settings.video-player.scss +64 -0
- package/src/styles/01-settings/_settings.z-layers.scss +0 -0
- package/src/styles/02-tools/_index.scss +1 -0
- package/src/styles/02-tools/_tools.animations.scss +82 -0
- package/src/styles/02-tools/_tools.border-radius.scss +0 -0
- package/src/styles/02-tools/_tools.breakpoints.scss +0 -0
- package/src/styles/02-tools/_tools.button.scss +5 -0
- package/src/styles/02-tools/_tools.clearfix.scss +0 -0
- package/src/styles/02-tools/_tools.color-functions.scss +0 -0
- package/src/styles/02-tools/_tools.color-mode.scss +1 -1
- package/src/styles/02-tools/_tools.component.scss +479 -0
- package/src/styles/02-tools/_tools.event.scss +0 -0
- package/src/styles/02-tools/_tools.grid.scss +0 -0
- package/src/styles/02-tools/_tools.hidden-visually.scss +0 -0
- package/src/styles/02-tools/_tools.hidden.scss +0 -0
- package/src/styles/02-tools/_tools.map-loop.scss +0 -0
- package/src/styles/02-tools/_tools.media-queries.scss +0 -0
- package/src/styles/02-tools/_tools.object-fit.scss +0 -0
- package/src/styles/02-tools/_tools.placeholder.scss +0 -0
- package/src/styles/02-tools/_tools.rem.scss +5 -1
- package/src/styles/02-tools/_tools.size.scss +0 -0
- package/src/styles/02-tools/_tools.spacing.scss +0 -0
- package/src/styles/02-tools/_tools.to-rgb.scss +0 -0
- package/src/styles/02-tools/_tools.transition.scss +0 -0
- package/src/styles/02-tools/_tools.utilities.scss +0 -0
- package/src/styles/02-tools/_tools.utility-api.scss +23 -2
- package/src/styles/03-generic/_generic.fonts.scss +0 -0
- package/src/styles/03-generic/_generic.reset.scss +0 -0
- package/src/styles/03-generic/_generic.root.scss +5 -1
- package/src/styles/03-generic/_generic.selection.scss +0 -0
- package/src/styles/03-generic/_index.scss +0 -0
- package/src/styles/04-elements/_elements.all.scss +0 -0
- package/src/styles/04-elements/_elements.body.scss +0 -0
- package/src/styles/04-elements/_elements.heading.scss +0 -0
- package/src/styles/04-elements/_elements.html.scss +0 -0
- package/src/styles/04-elements/_elements.links.scss +0 -0
- package/src/styles/04-elements/_index.scss +0 -0
- package/src/styles/05-objects/_index.scss +1 -0
- package/src/styles/05-objects/_objects.block.scss +122 -0
- package/src/styles/05-objects/_objects.container.scss +14 -10
- package/src/styles/05-objects/_objects.grid.scss +0 -0
- package/src/styles/05-objects/_objects.masonry-grid.scss +0 -0
- package/src/styles/06-components/_components.accordion.scss +3 -1
- package/src/styles/06-components/_components.avatar-group.scss +0 -0
- package/src/styles/06-components/_components.avatar.scss +0 -0
- package/src/styles/06-components/_components.badge.scss +9 -9
- package/src/styles/06-components/_components.breadcrumb.scss +0 -0
- package/src/styles/06-components/_components.btn-group.scss +0 -0
- package/src/styles/06-components/_components.button.scss +0 -0
- package/src/styles/06-components/_components.callout.scss +2 -1
- package/src/styles/06-components/_components.card.scss +0 -1
- package/src/styles/06-components/_components.chart.scss +2102 -0
- package/src/styles/06-components/_components.checkbox-group.scss +0 -0
- package/src/styles/06-components/_components.checkbox.scss +0 -0
- package/src/styles/06-components/_components.color-mode-toggle.scss +0 -0
- package/src/styles/06-components/_components.countdown.scss +0 -0
- package/src/styles/06-components/_components.data-table.scss +0 -0
- package/src/styles/06-components/_components.datepicker.scss +0 -0
- package/src/styles/06-components/_components.dropdown.scss +0 -0
- package/src/styles/06-components/_components.edge-panel.scss +0 -0
- package/src/styles/06-components/_components.form-group.scss +0 -0
- package/src/styles/06-components/_components.form.scss +0 -0
- package/src/styles/06-components/_components.hero.scss +1 -0
- package/src/styles/06-components/_components.icon.scss +2 -2
- package/src/styles/06-components/_components.image-gallery.scss +0 -0
- package/src/styles/06-components/_components.input.scss +0 -0
- package/src/styles/06-components/_components.list-group.scss +0 -0
- package/src/styles/06-components/_components.list.scss +0 -0
- package/src/styles/06-components/_components.menu.scss +0 -0
- package/src/styles/06-components/_components.messages.scss +0 -0
- package/src/styles/06-components/_components.modal.scss +3 -0
- package/src/styles/06-components/_components.nav.scss +0 -0
- package/src/styles/06-components/_components.navbar.scss +0 -0
- package/src/styles/06-components/_components.pagination.scss +0 -0
- package/src/styles/06-components/_components.photoviewer.scss +603 -545
- package/src/styles/06-components/_components.popover.scss +0 -0
- package/src/styles/06-components/_components.product-review.scss +0 -0
- package/src/styles/06-components/_components.progress.scss +0 -0
- package/src/styles/06-components/_components.rating.scss +0 -0
- package/src/styles/06-components/_components.river.scss +0 -0
- package/src/styles/06-components/_components.sectionintro.scss +0 -0
- package/src/styles/06-components/_components.select.scss +0 -0
- package/src/styles/06-components/_components.side-menu.scss +0 -0
- package/src/styles/06-components/_components.skeleton.scss +0 -0
- package/src/styles/06-components/_components.slider.scss +273 -0
- package/src/styles/06-components/_components.spinner.scss +0 -0
- package/src/styles/06-components/_components.steps.scss +1 -0
- package/src/styles/06-components/_components.tabs.scss +0 -0
- package/src/styles/06-components/_components.testimonials.scss +0 -0
- package/src/styles/06-components/_components.todo.scss +0 -0
- package/src/styles/06-components/_components.toggle.scss +0 -0
- package/src/styles/06-components/_components.tooltip.scss +4 -9
- package/src/styles/06-components/_components.upload.scss +0 -0
- package/src/styles/06-components/_components.video-player.scss +623 -0
- package/src/styles/06-components/_index.scss +3 -0
- package/src/styles/06-components/old.chart.styles.scss +2819 -0
- package/src/styles/99-utilities/_index.scss +0 -0
- package/src/styles/99-utilities/_utilities.background.scss +0 -0
- package/src/styles/99-utilities/_utilities.border.scss +0 -0
- package/src/styles/99-utilities/_utilities.clearfix.scss +0 -0
- package/src/styles/99-utilities/_utilities.display.scss +0 -0
- package/src/styles/99-utilities/_utilities.flex.scss +0 -0
- package/src/styles/99-utilities/_utilities.link.scss +0 -0
- package/src/styles/99-utilities/_utilities.object-fit.scss +0 -0
- package/src/styles/99-utilities/_utilities.opacity.scss +0 -0
- package/src/styles/99-utilities/_utilities.overflow.scss +0 -0
- package/src/styles/99-utilities/_utilities.position.scss +0 -0
- package/src/styles/99-utilities/_utilities.scss +2 -1
- package/src/styles/99-utilities/_utilities.shadow.scss +0 -0
- package/src/styles/99-utilities/_utilities.sizes.scss +0 -0
- package/src/styles/99-utilities/_utilities.spacing.scss +0 -0
- package/src/styles/99-utilities/_utilities.text.scss +5 -0
- package/src/styles/99-utilities/_utilities.visibility.scss +0 -0
- package/src/styles/99-utilities/_utilities.visually-hidden.scss +0 -0
- package/src/styles/99-utilities/_utilities.z-index.scss +0 -0
- package/src/styles/css-modules.d.ts +0 -0
- package/src/styles/index.scss +0 -0
- package/dist/index.css +0 -15
- package/dist/index.esm.css +0 -15
- package/dist/index.min.css +0 -15
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { ChartDataPoint } from '../types/components';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pie chart specific options
|
|
6
|
+
*/
|
|
7
|
+
export interface PieChartOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Inner radius for donut charts (0-1)
|
|
10
|
+
*/
|
|
11
|
+
innerRadius?: number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Whether to show labels
|
|
15
|
+
*/
|
|
16
|
+
showLabels?: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether to show percentages
|
|
20
|
+
*/
|
|
21
|
+
showPercentages?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether to show values
|
|
25
|
+
*/
|
|
26
|
+
showValues?: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Start angle in degrees
|
|
30
|
+
*/
|
|
31
|
+
startAngle?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether to sort slices by value
|
|
35
|
+
*/
|
|
36
|
+
sortByValue?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Padding angle between slices in degrees
|
|
40
|
+
*/
|
|
41
|
+
padAngle?: number;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether to enable animations
|
|
45
|
+
*/
|
|
46
|
+
enableAnimations?: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether to enable hover effects
|
|
50
|
+
*/
|
|
51
|
+
enableHoverEffects?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether to enable selection
|
|
55
|
+
*/
|
|
56
|
+
enableSelection?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Hover offset in pixels
|
|
60
|
+
*/
|
|
61
|
+
hoverOffset?: number;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Animation duration in milliseconds
|
|
65
|
+
*/
|
|
66
|
+
animationDuration?: number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Label formatter function
|
|
70
|
+
*/
|
|
71
|
+
labelFormatter?: (value: number, percentage: number, label: string) => string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Pie slice interface
|
|
76
|
+
*/
|
|
77
|
+
export interface PieSlice {
|
|
78
|
+
dataPoint: ChartDataPoint;
|
|
79
|
+
index: number;
|
|
80
|
+
startAngle: number;
|
|
81
|
+
endAngle: number;
|
|
82
|
+
midAngle: number;
|
|
83
|
+
color: string;
|
|
84
|
+
percentage: number;
|
|
85
|
+
value: number;
|
|
86
|
+
label: string;
|
|
87
|
+
path: string;
|
|
88
|
+
labelPosition: { x: number; y: number };
|
|
89
|
+
clientX?: number;
|
|
90
|
+
clientY?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Hook for pie chart functionality
|
|
95
|
+
*/
|
|
96
|
+
export function usePieChart(data: ChartDataPoint[], options: PieChartOptions = {}) {
|
|
97
|
+
const [hoveredSlice, setHoveredSlice] = useState<number | null>(null);
|
|
98
|
+
const [selectedSlices, setSelectedSlices] = useState<Set<number>>(new Set());
|
|
99
|
+
const [animationProgress, setAnimationProgress] = useState(0);
|
|
100
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
101
|
+
|
|
102
|
+
// Filter and sort data
|
|
103
|
+
const processedData = useMemo(() => {
|
|
104
|
+
// Filter out invalid data points
|
|
105
|
+
const validData = data.filter(
|
|
106
|
+
point =>
|
|
107
|
+
typeof point.value === 'number' &&
|
|
108
|
+
!isNaN(point.value) &&
|
|
109
|
+
isFinite(point.value) &&
|
|
110
|
+
point.value > 0
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (!validData.length) return [];
|
|
114
|
+
|
|
115
|
+
// Sort by value if enabled
|
|
116
|
+
if (options.sortByValue) {
|
|
117
|
+
return [...validData].sort((a, b) => b.value - a.value);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return validData;
|
|
121
|
+
}, [data, options.sortByValue]);
|
|
122
|
+
|
|
123
|
+
// Calculate total value
|
|
124
|
+
const totalValue = useMemo(() => {
|
|
125
|
+
return processedData.reduce((sum, point) => sum + point.value, 0);
|
|
126
|
+
}, [processedData]);
|
|
127
|
+
|
|
128
|
+
// Generate pie slices
|
|
129
|
+
const slices = useMemo(() => {
|
|
130
|
+
if (!processedData.length || totalValue <= 0) return [];
|
|
131
|
+
|
|
132
|
+
const centerX = 400; // Default center
|
|
133
|
+
const centerY = 200;
|
|
134
|
+
const outerRadius = 150;
|
|
135
|
+
const innerRadius = outerRadius * (options.innerRadius || 0);
|
|
136
|
+
|
|
137
|
+
const defaultColors = [
|
|
138
|
+
'#7AFFD7',
|
|
139
|
+
'#1AFFD2',
|
|
140
|
+
'#00E6C3',
|
|
141
|
+
'#4DFF9F',
|
|
142
|
+
'#1AFF85',
|
|
143
|
+
'#00E66B',
|
|
144
|
+
'#DD6061',
|
|
145
|
+
'#FF1A1A',
|
|
146
|
+
'#E60000',
|
|
147
|
+
'#FFCC00',
|
|
148
|
+
'#E6B800',
|
|
149
|
+
'#B38F00',
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
let currentAngle = ((options.startAngle || 0) * Math.PI) / 180;
|
|
153
|
+
const padAngleRad = ((options.padAngle || 1) * Math.PI) / 180;
|
|
154
|
+
|
|
155
|
+
return processedData.map((point, i) => {
|
|
156
|
+
const percentage = point.value / totalValue;
|
|
157
|
+
const angle = percentage * 2 * Math.PI - padAngleRad;
|
|
158
|
+
const endAngle = currentAngle + angle;
|
|
159
|
+
const midAngle = currentAngle + angle / 2;
|
|
160
|
+
|
|
161
|
+
// Calculate path
|
|
162
|
+
const outerStartX = centerX + outerRadius * Math.cos(currentAngle);
|
|
163
|
+
const outerStartY = centerY + outerRadius * Math.sin(currentAngle);
|
|
164
|
+
const outerEndX = centerX + outerRadius * Math.cos(endAngle);
|
|
165
|
+
const outerEndY = centerY + outerRadius * Math.sin(endAngle);
|
|
166
|
+
|
|
167
|
+
const largeArcFlag = angle > Math.PI ? 1 : 0;
|
|
168
|
+
|
|
169
|
+
let path: string;
|
|
170
|
+
|
|
171
|
+
if (innerRadius > 0) {
|
|
172
|
+
// Donut chart path
|
|
173
|
+
const innerStartX = centerX + innerRadius * Math.cos(endAngle);
|
|
174
|
+
const innerStartY = centerY + innerRadius * Math.sin(endAngle);
|
|
175
|
+
const innerEndX = centerX + innerRadius * Math.cos(currentAngle);
|
|
176
|
+
const innerEndY = centerY + innerRadius * Math.sin(currentAngle);
|
|
177
|
+
|
|
178
|
+
path = [
|
|
179
|
+
`M ${outerStartX},${outerStartY}`,
|
|
180
|
+
`A ${outerRadius},${outerRadius} 0 ${largeArcFlag},1 ${outerEndX},${outerEndY}`,
|
|
181
|
+
`L ${innerStartX},${innerStartY}`,
|
|
182
|
+
`A ${innerRadius},${innerRadius} 0 ${largeArcFlag},0 ${innerEndX},${innerEndY}`,
|
|
183
|
+
'Z',
|
|
184
|
+
].join(' ');
|
|
185
|
+
} else {
|
|
186
|
+
// Pie chart path
|
|
187
|
+
path = [
|
|
188
|
+
`M ${centerX},${centerY}`,
|
|
189
|
+
`L ${outerStartX},${outerStartY}`,
|
|
190
|
+
`A ${outerRadius},${outerRadius} 0 ${largeArcFlag},1 ${outerEndX},${outerEndY}`,
|
|
191
|
+
'Z',
|
|
192
|
+
].join(' ');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Calculate label position
|
|
196
|
+
const labelRadius = (outerRadius + innerRadius) / 2 || outerRadius * 0.7;
|
|
197
|
+
const labelX = centerX + labelRadius * Math.cos(midAngle);
|
|
198
|
+
const labelY = centerY + labelRadius * Math.sin(midAngle);
|
|
199
|
+
|
|
200
|
+
const slice: PieSlice = {
|
|
201
|
+
dataPoint: point,
|
|
202
|
+
index: i,
|
|
203
|
+
startAngle: currentAngle,
|
|
204
|
+
endAngle,
|
|
205
|
+
midAngle,
|
|
206
|
+
color: (point.color || defaultColors[i % defaultColors.length]) as string,
|
|
207
|
+
percentage: percentage * 100,
|
|
208
|
+
value: point.value,
|
|
209
|
+
label: point.label,
|
|
210
|
+
path,
|
|
211
|
+
labelPosition: { x: labelX, y: labelY },
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
currentAngle = endAngle + padAngleRad;
|
|
215
|
+
|
|
216
|
+
return slice;
|
|
217
|
+
});
|
|
218
|
+
}, [processedData, totalValue, options.innerRadius, options.startAngle, options.padAngle]);
|
|
219
|
+
|
|
220
|
+
// Animation helpers
|
|
221
|
+
const startAnimation = useCallback(() => {
|
|
222
|
+
if (!options.enableAnimations) return;
|
|
223
|
+
|
|
224
|
+
setIsAnimating(true);
|
|
225
|
+
setAnimationProgress(0);
|
|
226
|
+
|
|
227
|
+
const duration = options.animationDuration || 1000;
|
|
228
|
+
const startTime = Date.now();
|
|
229
|
+
|
|
230
|
+
const animate = () => {
|
|
231
|
+
const elapsed = Date.now() - startTime;
|
|
232
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
233
|
+
|
|
234
|
+
// Easing function (ease-out)
|
|
235
|
+
const easedProgress = 1 - Math.pow(1 - progress, 3);
|
|
236
|
+
setAnimationProgress(easedProgress);
|
|
237
|
+
|
|
238
|
+
if (progress < 1) {
|
|
239
|
+
requestAnimationFrame(animate);
|
|
240
|
+
} else {
|
|
241
|
+
setIsAnimating(false);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
requestAnimationFrame(animate);
|
|
246
|
+
}, [options.enableAnimations, options.animationDuration]);
|
|
247
|
+
|
|
248
|
+
// Slice interaction handlers
|
|
249
|
+
const handleSliceHover = useCallback(
|
|
250
|
+
(index: number, clientX?: number, clientY?: number) => {
|
|
251
|
+
if (!options.enableHoverEffects) return;
|
|
252
|
+
setHoveredSlice(index);
|
|
253
|
+
|
|
254
|
+
// Store client coordinates for tooltip positioning
|
|
255
|
+
if (clientX !== undefined && clientY !== undefined && slices[index]) {
|
|
256
|
+
slices[index].clientX = clientX;
|
|
257
|
+
slices[index].clientY = clientY;
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
[options.enableHoverEffects, slices]
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const handleSliceLeave = useCallback(() => {
|
|
264
|
+
setHoveredSlice(null);
|
|
265
|
+
}, []);
|
|
266
|
+
|
|
267
|
+
const handleSliceClick = useCallback(
|
|
268
|
+
(index: number) => {
|
|
269
|
+
if (!options.enableSelection) return;
|
|
270
|
+
|
|
271
|
+
setSelectedSlices(prev => {
|
|
272
|
+
const newSet = new Set(prev);
|
|
273
|
+
if (newSet.has(index)) {
|
|
274
|
+
newSet.delete(index);
|
|
275
|
+
} else {
|
|
276
|
+
newSet.add(index);
|
|
277
|
+
}
|
|
278
|
+
return newSet;
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
[options.enableSelection]
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
// Format label
|
|
285
|
+
const formatLabel = useCallback(
|
|
286
|
+
(slice: PieSlice) => {
|
|
287
|
+
if (options.labelFormatter) {
|
|
288
|
+
return options.labelFormatter(slice.value, slice.percentage, slice.label);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const parts = [];
|
|
292
|
+
|
|
293
|
+
if (options.showLabels !== false) {
|
|
294
|
+
parts.push(slice.label);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (options.showPercentages) {
|
|
298
|
+
parts.push(`${Math.round(slice.percentage)}%`);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (options.showValues) {
|
|
302
|
+
parts.push(slice.value.toString());
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return parts.join(' - ');
|
|
306
|
+
},
|
|
307
|
+
[options.labelFormatter, options.showLabels, options.showPercentages, options.showValues]
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
// Get slice transform for hover effect
|
|
311
|
+
const getSliceTransform = useCallback(
|
|
312
|
+
(slice: PieSlice, isHovered: boolean) => {
|
|
313
|
+
if (!isHovered || !options.enableHoverEffects || !options.hoverOffset) {
|
|
314
|
+
return '';
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const offsetX = Math.cos(slice.midAngle) * options.hoverOffset;
|
|
318
|
+
const offsetY = Math.sin(slice.midAngle) * options.hoverOffset;
|
|
319
|
+
|
|
320
|
+
return `translate(${offsetX}, ${offsetY})`;
|
|
321
|
+
},
|
|
322
|
+
[options.enableHoverEffects, options.hoverOffset]
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
// Check if slice is selected
|
|
326
|
+
const isSliceSelected = useCallback(
|
|
327
|
+
(index: number) => {
|
|
328
|
+
return selectedSlices.has(index);
|
|
329
|
+
},
|
|
330
|
+
[selectedSlices]
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
// Data
|
|
335
|
+
processedData,
|
|
336
|
+
slices,
|
|
337
|
+
totalValue,
|
|
338
|
+
|
|
339
|
+
// State
|
|
340
|
+
hoveredSlice,
|
|
341
|
+
selectedSlices,
|
|
342
|
+
animationProgress,
|
|
343
|
+
isAnimating,
|
|
344
|
+
|
|
345
|
+
// Handlers
|
|
346
|
+
handleSliceHover,
|
|
347
|
+
handleSliceLeave,
|
|
348
|
+
handleSliceClick,
|
|
349
|
+
startAnimation,
|
|
350
|
+
|
|
351
|
+
// Utilities
|
|
352
|
+
formatLabel,
|
|
353
|
+
getSliceTransform,
|
|
354
|
+
isSliceSelected,
|
|
355
|
+
|
|
356
|
+
// State setters
|
|
357
|
+
setHoveredSlice,
|
|
358
|
+
setSelectedSlices,
|
|
359
|
+
setAnimationProgress,
|
|
360
|
+
setIsAnimating,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { useState, useRef, useEffect, RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
type PopoverPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
4
|
+
type PopoverTrigger = 'click' | 'hover';
|
|
5
|
+
|
|
6
|
+
interface UsePopoverProps {
|
|
7
|
+
position?: PopoverPosition | 'auto';
|
|
8
|
+
trigger?: PopoverTrigger;
|
|
9
|
+
offset?: number;
|
|
10
|
+
delay?: number;
|
|
11
|
+
defaultOpen?: boolean;
|
|
12
|
+
isOpen?: boolean;
|
|
13
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
14
|
+
closeOnClickOutside?: boolean;
|
|
15
|
+
closeOnEscape?: boolean;
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface UsePopoverResult {
|
|
20
|
+
isOpen: boolean;
|
|
21
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
22
|
+
triggerRef: RefObject<HTMLElement | null>;
|
|
23
|
+
popoverRef: RefObject<HTMLDivElement | null>;
|
|
24
|
+
arrowRef: RefObject<HTMLDivElement | null>;
|
|
25
|
+
popoverId: string;
|
|
26
|
+
currentPosition: PopoverPosition;
|
|
27
|
+
updatePosition: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Hook for managing popover state and positioning logic
|
|
32
|
+
*/
|
|
33
|
+
export const usePopover = ({
|
|
34
|
+
position = 'top',
|
|
35
|
+
trigger = 'click',
|
|
36
|
+
offset = 12,
|
|
37
|
+
delay = 0,
|
|
38
|
+
defaultOpen = false,
|
|
39
|
+
isOpen: controlledIsOpen,
|
|
40
|
+
onOpenChange,
|
|
41
|
+
closeOnClickOutside = true,
|
|
42
|
+
closeOnEscape = true,
|
|
43
|
+
id,
|
|
44
|
+
}: UsePopoverProps): UsePopoverResult => {
|
|
45
|
+
const [isOpen, setIsOpenState] = useState(defaultOpen);
|
|
46
|
+
const [currentPosition, setCurrentPosition] = useState<PopoverPosition>(
|
|
47
|
+
position === 'auto' ? 'top' : (position as PopoverPosition)
|
|
48
|
+
);
|
|
49
|
+
const triggerRef = useRef<HTMLElement>(null);
|
|
50
|
+
const popoverRef = useRef<HTMLDivElement>(null);
|
|
51
|
+
const arrowRef = useRef<HTMLDivElement>(null);
|
|
52
|
+
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
53
|
+
const popoverId = id || `popover-${Math.random().toString(36).slice(2, 11)}`;
|
|
54
|
+
|
|
55
|
+
// Use controlled state if provided
|
|
56
|
+
const isControlled = controlledIsOpen !== undefined;
|
|
57
|
+
const isOpenState = isControlled ? controlledIsOpen : isOpen;
|
|
58
|
+
|
|
59
|
+
// Define setIsOpen function before using it in useEffect
|
|
60
|
+
const setIsOpen = (newIsOpen: boolean) => {
|
|
61
|
+
if (!isControlled) {
|
|
62
|
+
setIsOpenState(newIsOpen);
|
|
63
|
+
}
|
|
64
|
+
if (onOpenChange) {
|
|
65
|
+
onOpenChange(newIsOpen);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Handle hover events if trigger is hover
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (trigger !== 'hover' || !triggerRef.current || !popoverRef.current) return undefined;
|
|
72
|
+
|
|
73
|
+
const handleTriggerMouseEnter = () => {
|
|
74
|
+
if (timeoutRef.current !== null) {
|
|
75
|
+
clearTimeout(timeoutRef.current);
|
|
76
|
+
timeoutRef.current = null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (delay > 0) {
|
|
80
|
+
timeoutRef.current = setTimeout(() => {
|
|
81
|
+
setIsOpen(true);
|
|
82
|
+
}, delay);
|
|
83
|
+
} else {
|
|
84
|
+
setIsOpen(true);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const handleTriggerMouseLeave = () => {
|
|
89
|
+
if (timeoutRef.current !== null) {
|
|
90
|
+
clearTimeout(timeoutRef.current);
|
|
91
|
+
timeoutRef.current = null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
timeoutRef.current = setTimeout(() => {
|
|
95
|
+
if (!popoverRef.current?.matches(':hover')) {
|
|
96
|
+
setIsOpen(false);
|
|
97
|
+
}
|
|
98
|
+
}, 100);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const handlePopoverMouseEnter = () => {
|
|
102
|
+
if (timeoutRef.current !== null) {
|
|
103
|
+
clearTimeout(timeoutRef.current);
|
|
104
|
+
timeoutRef.current = null;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handlePopoverMouseLeave = () => {
|
|
109
|
+
setIsOpen(false);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Add hover event listeners
|
|
113
|
+
triggerRef.current.addEventListener('mouseenter', handleTriggerMouseEnter);
|
|
114
|
+
triggerRef.current.addEventListener('mouseleave', handleTriggerMouseLeave);
|
|
115
|
+
popoverRef.current.addEventListener('mouseenter', handlePopoverMouseEnter);
|
|
116
|
+
popoverRef.current.addEventListener('mouseleave', handlePopoverMouseLeave);
|
|
117
|
+
|
|
118
|
+
return () => {
|
|
119
|
+
if (triggerRef.current) {
|
|
120
|
+
triggerRef.current.removeEventListener('mouseenter', handleTriggerMouseEnter);
|
|
121
|
+
triggerRef.current.removeEventListener('mouseleave', handleTriggerMouseLeave);
|
|
122
|
+
}
|
|
123
|
+
if (popoverRef.current) {
|
|
124
|
+
popoverRef.current.removeEventListener('mouseenter', handlePopoverMouseEnter);
|
|
125
|
+
popoverRef.current.removeEventListener('mouseleave', handlePopoverMouseLeave);
|
|
126
|
+
}
|
|
127
|
+
if (timeoutRef.current !== null) {
|
|
128
|
+
window.clearTimeout(timeoutRef.current);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}, [trigger, delay, isOpenState]);
|
|
132
|
+
|
|
133
|
+
const updatePosition = (event?: Event) => {
|
|
134
|
+
if (!triggerRef.current || !popoverRef.current) return;
|
|
135
|
+
|
|
136
|
+
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
137
|
+
const popoverRect = popoverRef.current.getBoundingClientRect();
|
|
138
|
+
const viewportWidth = window.innerWidth;
|
|
139
|
+
const viewportHeight = window.innerHeight;
|
|
140
|
+
|
|
141
|
+
// Check if the trigger is near viewport edges
|
|
142
|
+
const isNearViewportEdge =
|
|
143
|
+
triggerRect.top < 50 ||
|
|
144
|
+
triggerRect.bottom > viewportHeight - 50 ||
|
|
145
|
+
triggerRect.left < 50 ||
|
|
146
|
+
triggerRect.right > viewportWidth - 50;
|
|
147
|
+
|
|
148
|
+
// If this is a scroll update and trigger isn't near edges, skip repositioning
|
|
149
|
+
if (event?.type === 'scroll' && !isNearViewportEdge) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Calculate space available in each direction
|
|
154
|
+
const spaceTop = triggerRect.top;
|
|
155
|
+
const spaceBottom = viewportHeight - triggerRect.bottom;
|
|
156
|
+
const spaceLeft = triggerRect.left;
|
|
157
|
+
const spaceRight = viewportWidth - triggerRect.right;
|
|
158
|
+
|
|
159
|
+
// Determine best position based on available space
|
|
160
|
+
let bestPosition: PopoverPosition = position === 'auto' ? 'top' : (position as PopoverPosition);
|
|
161
|
+
|
|
162
|
+
// If specified position is 'auto', find the position with most space
|
|
163
|
+
if (position === 'auto') {
|
|
164
|
+
const spaces = [
|
|
165
|
+
{ position: 'top', space: spaceTop },
|
|
166
|
+
{ position: 'right', space: spaceRight },
|
|
167
|
+
{ position: 'bottom', space: spaceBottom },
|
|
168
|
+
{ position: 'left', space: spaceLeft },
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
// Sort by available space (descending)
|
|
172
|
+
spaces.sort((a, b) => b.space - a.space);
|
|
173
|
+
|
|
174
|
+
// Select position with most space
|
|
175
|
+
bestPosition = spaces[0]?.position as PopoverPosition;
|
|
176
|
+
} else {
|
|
177
|
+
// Check if the preferred position has enough space
|
|
178
|
+
const needsFlip =
|
|
179
|
+
(position === 'top' &&
|
|
180
|
+
spaceTop < popoverRect.height + offset &&
|
|
181
|
+
spaceBottom >= popoverRect.height + offset) ||
|
|
182
|
+
(position === 'bottom' &&
|
|
183
|
+
spaceBottom < popoverRect.height + offset &&
|
|
184
|
+
spaceTop >= popoverRect.height + offset) ||
|
|
185
|
+
(position === 'left' &&
|
|
186
|
+
spaceLeft < popoverRect.width + offset &&
|
|
187
|
+
spaceRight >= popoverRect.width + offset) ||
|
|
188
|
+
(position === 'right' &&
|
|
189
|
+
spaceRight < popoverRect.width + offset &&
|
|
190
|
+
spaceLeft >= popoverRect.width + offset);
|
|
191
|
+
|
|
192
|
+
if (needsFlip) {
|
|
193
|
+
// Flip to the opposite side
|
|
194
|
+
const oppositePositions: Record<PopoverPosition | 'auto', PopoverPosition> = {
|
|
195
|
+
top: 'bottom',
|
|
196
|
+
bottom: 'top',
|
|
197
|
+
left: 'right',
|
|
198
|
+
right: 'left',
|
|
199
|
+
auto: 'bottom',
|
|
200
|
+
};
|
|
201
|
+
bestPosition = oppositePositions[position as PopoverPosition | 'auto'];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setCurrentPosition(bestPosition);
|
|
206
|
+
|
|
207
|
+
// Calculate position based on the determined best position
|
|
208
|
+
let top = 0;
|
|
209
|
+
let left = 0;
|
|
210
|
+
|
|
211
|
+
// Calculate viewport-relative position
|
|
212
|
+
switch (bestPosition) {
|
|
213
|
+
case 'top':
|
|
214
|
+
top = triggerRect.top - popoverRect.height - offset;
|
|
215
|
+
left = triggerRect.left + triggerRect.width / 2 - popoverRect.width / 2;
|
|
216
|
+
break;
|
|
217
|
+
case 'bottom':
|
|
218
|
+
top = triggerRect.bottom + offset;
|
|
219
|
+
left = triggerRect.left + triggerRect.width / 2 - popoverRect.width / 2;
|
|
220
|
+
break;
|
|
221
|
+
case 'left':
|
|
222
|
+
top = triggerRect.top + triggerRect.height / 2 - popoverRect.height / 2;
|
|
223
|
+
left = triggerRect.left - popoverRect.width - offset;
|
|
224
|
+
break;
|
|
225
|
+
case 'right':
|
|
226
|
+
top = triggerRect.top + triggerRect.height / 2 - popoverRect.height / 2;
|
|
227
|
+
left = triggerRect.right + offset;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Constrain to viewport boundaries
|
|
232
|
+
if (left < 0) {
|
|
233
|
+
left = 5;
|
|
234
|
+
} else if (left + popoverRect.width > viewportWidth) {
|
|
235
|
+
left = viewportWidth - popoverRect.width - 5;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (top < 0) {
|
|
239
|
+
top = 5;
|
|
240
|
+
} else if (top + popoverRect.height > viewportHeight) {
|
|
241
|
+
top = viewportHeight - popoverRect.height - 5;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Add scroll position to convert viewport coordinates to absolute position
|
|
245
|
+
const absoluteTop = top + window.scrollY;
|
|
246
|
+
const absoluteLeft = left + window.scrollX;
|
|
247
|
+
|
|
248
|
+
// Apply position using absolute positioning to follow when scrolling
|
|
249
|
+
popoverRef.current.style.position = 'absolute';
|
|
250
|
+
popoverRef.current.style.top = `${absoluteTop}px`;
|
|
251
|
+
popoverRef.current.style.left = `${absoluteLeft}px`;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// Position the popover
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (!isOpenState || !triggerRef.current || !popoverRef.current) return undefined;
|
|
257
|
+
|
|
258
|
+
// Initial positioning
|
|
259
|
+
updatePosition();
|
|
260
|
+
|
|
261
|
+
// Update position on resize
|
|
262
|
+
window.addEventListener('resize', updatePosition);
|
|
263
|
+
|
|
264
|
+
// Update position on scroll, but throttled for performance
|
|
265
|
+
let scrollTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
266
|
+
const handleScroll = (e: Event) => {
|
|
267
|
+
if (scrollTimeout) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
scrollTimeout = setTimeout(() => {
|
|
272
|
+
updatePosition(e);
|
|
273
|
+
scrollTimeout = null;
|
|
274
|
+
}, 100);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
278
|
+
|
|
279
|
+
// Update position less frequently to handle content changes
|
|
280
|
+
const intervalId: ReturnType<typeof setInterval> = setInterval(() => {
|
|
281
|
+
updatePosition();
|
|
282
|
+
}, 500);
|
|
283
|
+
|
|
284
|
+
return () => {
|
|
285
|
+
window.removeEventListener('resize', updatePosition);
|
|
286
|
+
window.removeEventListener('scroll', handleScroll);
|
|
287
|
+
if (scrollTimeout) {
|
|
288
|
+
clearTimeout(scrollTimeout);
|
|
289
|
+
}
|
|
290
|
+
clearInterval(intervalId);
|
|
291
|
+
};
|
|
292
|
+
}, [isOpenState, position, offset]);
|
|
293
|
+
|
|
294
|
+
// Handle click outside to close popover
|
|
295
|
+
useEffect(() => {
|
|
296
|
+
if (!isOpenState || !closeOnClickOutside) return undefined;
|
|
297
|
+
|
|
298
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
299
|
+
if (
|
|
300
|
+
popoverRef.current &&
|
|
301
|
+
!popoverRef.current.contains(event.target as Node) &&
|
|
302
|
+
triggerRef.current &&
|
|
303
|
+
!triggerRef.current.contains(event.target as Node)
|
|
304
|
+
) {
|
|
305
|
+
setIsOpen(false);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
310
|
+
|
|
311
|
+
return () => {
|
|
312
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
313
|
+
};
|
|
314
|
+
}, [isOpenState, closeOnClickOutside]);
|
|
315
|
+
|
|
316
|
+
// Handle escape key to close popover
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
if (!isOpenState || !closeOnEscape) return undefined;
|
|
319
|
+
|
|
320
|
+
const handleEscapeKey = (event: KeyboardEvent) => {
|
|
321
|
+
if (event.key === 'Escape') {
|
|
322
|
+
setIsOpen(false);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
document.addEventListener('keydown', handleEscapeKey);
|
|
327
|
+
|
|
328
|
+
return () => {
|
|
329
|
+
document.removeEventListener('keydown', handleEscapeKey);
|
|
330
|
+
};
|
|
331
|
+
}, [isOpenState, closeOnEscape]);
|
|
332
|
+
|
|
333
|
+
// Clean up on unmount
|
|
334
|
+
useEffect(() => {
|
|
335
|
+
return () => {
|
|
336
|
+
if (timeoutRef.current !== null) {
|
|
337
|
+
window.clearTimeout(timeoutRef.current);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}, []);
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
isOpen: isOpenState,
|
|
344
|
+
setIsOpen,
|
|
345
|
+
triggerRef,
|
|
346
|
+
popoverRef,
|
|
347
|
+
arrowRef,
|
|
348
|
+
popoverId,
|
|
349
|
+
currentPosition,
|
|
350
|
+
updatePosition,
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
export default usePopover;
|