@udixio/ui-react 0.0.1 → 0.1.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/.eslintrc.mjs +22 -0
- package/.storybook/main.ts +20 -0
- package/.storybook/preview.ts +1 -0
- package/CHANGELOG.md +141 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2820 -0
- package/dist/lib/components/Button.d.ts.map +1 -0
- package/dist/lib/components/Card.d.ts.map +1 -0
- package/dist/lib/components/Carousel.d.ts.map +1 -0
- package/dist/lib/components/CarouselItem.d.ts.map +1 -0
- package/{lib → dist/lib}/components/Divided.d.ts +1 -1
- package/dist/lib/components/Divided.d.ts.map +1 -0
- package/dist/lib/components/Fab.d.ts.map +1 -0
- package/dist/lib/components/IconButton.d.ts.map +1 -0
- package/dist/lib/components/NavigationRail.d.ts.map +1 -0
- package/dist/lib/components/NavigationRailItem.d.ts.map +1 -0
- package/dist/lib/components/ProgressIndicator.d.ts.map +1 -0
- package/dist/lib/components/Slider.d.ts.map +1 -0
- package/dist/lib/components/Snackbar.d.ts.map +1 -0
- package/dist/lib/components/Switch.d.ts.map +1 -0
- package/dist/lib/components/Tab.d.ts.map +1 -0
- package/dist/lib/components/Tabs.d.ts.map +1 -0
- package/dist/lib/components/TextField.d.ts.map +1 -0
- package/dist/lib/components/ToolTip.d.ts.map +1 -0
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/effects/SyncedFixedWrapper.d.ts.map +1 -0
- package/dist/lib/effects/custom-scroll/custom-scroll.effect.d.ts.map +1 -0
- package/dist/lib/effects/custom-scroll/custom-scroll.interface.d.ts.map +1 -0
- package/dist/lib/effects/custom-scroll/custom-scroll.style.d.ts.map +1 -0
- package/dist/lib/effects/custom-scroll/index.d.ts.map +1 -0
- package/dist/lib/effects/index.d.ts.map +1 -0
- package/dist/lib/effects/ripple/RippleEffect.d.ts.map +1 -0
- package/dist/lib/effects/ripple/index.d.ts.map +1 -0
- package/dist/lib/effects/smooth-scroll.effect.d.ts.map +1 -0
- package/dist/lib/icon/icon.d.ts.map +1 -0
- package/dist/lib/icon/index.d.ts.map +1 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/interfaces/button.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/card.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/carousel-item.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/carousel.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/divider.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/fab.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/icon-button.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/index.d.ts.map +1 -0
- package/dist/lib/interfaces/navigation-rail-item.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/navigation-rail.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/progress-indicator.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/slider.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/snackbar.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/switch.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/tab.interface.d.ts.map +1 -0
- package/{lib → dist/lib}/interfaces/tabs.interface.d.ts +1 -1
- package/dist/lib/interfaces/tabs.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/text-field.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/tooltip.interface.d.ts.map +1 -0
- package/dist/lib/styles/button.style.d.ts.map +1 -0
- package/dist/lib/styles/card.style.d.ts.map +1 -0
- package/dist/lib/styles/carousel-item.style.d.ts.map +1 -0
- package/dist/lib/styles/carousel.style.d.ts.map +1 -0
- package/dist/lib/styles/divider.style.d.ts.map +1 -0
- package/dist/lib/styles/fab.style.d.ts.map +1 -0
- package/dist/lib/styles/icon-button.style.d.ts.map +1 -0
- package/dist/lib/styles/index.d.ts.map +1 -0
- package/dist/lib/styles/navigation-rail-item.style.d.ts.map +1 -0
- package/dist/lib/styles/navigation-rail.style.d.ts.map +1 -0
- package/dist/lib/styles/progress-indicator.style.d.ts.map +1 -0
- package/dist/lib/styles/slider.style.d.ts.map +1 -0
- package/dist/lib/styles/snackbar.style.d.ts.map +1 -0
- package/dist/lib/styles/switch.style.d.ts.map +1 -0
- package/dist/lib/styles/tab.style.d.ts.map +1 -0
- package/{lib → dist/lib}/styles/tabs.style.d.ts +1 -1
- package/dist/lib/styles/tabs.style.d.ts.map +1 -0
- package/dist/lib/styles/text-field.style.d.ts.map +1 -0
- package/dist/lib/styles/tooltip.style.d.ts.map +1 -0
- package/dist/lib/utils/component-helper.d.ts.map +1 -0
- package/dist/lib/utils/component.d.ts.map +1 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/string.d.ts.map +1 -0
- package/dist/lib/utils/styles/classnames.d.ts.map +1 -0
- package/dist/lib/utils/styles/get-classname.d.ts.map +1 -0
- package/dist/lib/utils/styles/index.d.ts.map +1 -0
- package/package.json +12 -7
- package/postcss.config.mjs +5 -0
- package/src/index.css +4 -0
- package/src/index.ts +1 -0
- package/src/lib/components/Button.tsx +140 -0
- package/src/lib/components/Card.tsx +31 -0
- package/src/lib/components/Carousel.tsx +190 -0
- package/src/lib/components/CarouselItem.tsx +53 -0
- package/src/lib/components/Divided.tsx +13 -0
- package/src/lib/components/Fab.tsx +109 -0
- package/src/lib/components/IconButton.tsx +141 -0
- package/src/lib/components/NavigationRail.tsx +178 -0
- package/src/lib/components/NavigationRailItem.tsx +199 -0
- package/src/lib/components/ProgressIndicator.tsx +157 -0
- package/src/lib/components/Slider.tsx +361 -0
- package/src/lib/components/Snackbar.tsx +66 -0
- package/src/lib/components/Switch.tsx +94 -0
- package/src/lib/components/Tab.tsx +110 -0
- package/src/lib/components/Tabs.tsx +85 -0
- package/src/lib/components/TextField.tsx +269 -0
- package/src/lib/components/ToolTip.tsx +232 -0
- package/src/lib/components/index.ts +19 -0
- package/src/lib/effects/SyncedFixedWrapper.tsx +64 -0
- package/src/lib/effects/custom-scroll/custom-scroll.effect.tsx +287 -0
- package/src/lib/effects/custom-scroll/custom-scroll.interface.ts +25 -0
- package/src/lib/effects/custom-scroll/custom-scroll.style.ts +32 -0
- package/src/lib/effects/custom-scroll/index.ts +3 -0
- package/src/lib/effects/index.ts +4 -0
- package/src/lib/effects/ripple/RippleEffect.tsx +103 -0
- package/src/lib/effects/ripple/index.tsx +1 -0
- package/src/lib/effects/smooth-scroll.effect.tsx +91 -0
- package/src/lib/icon/icon.tsx +47 -0
- package/src/lib/icon/index.ts +1 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/interfaces/button.interface.ts +46 -0
- package/src/lib/interfaces/card.interface.ts +8 -0
- package/src/lib/interfaces/carousel-item.interface.ts +11 -0
- package/src/lib/interfaces/carousel.interface.ts +21 -0
- package/src/lib/interfaces/divider.interface.ts +7 -0
- package/src/lib/interfaces/fab.interface.ts +19 -0
- package/src/lib/interfaces/icon-button.interface.ts +35 -0
- package/src/lib/interfaces/index.ts +16 -0
- package/src/lib/interfaces/navigation-rail-item.interface.ts +38 -0
- package/src/lib/interfaces/navigation-rail.interface.ts +39 -0
- package/src/lib/interfaces/progress-indicator.interface.ts +35 -0
- package/src/lib/interfaces/slider.interface.ts +29 -0
- package/src/lib/interfaces/snackbar.interface.ts +13 -0
- package/src/lib/interfaces/switch.interface.ts +14 -0
- package/src/lib/interfaces/tab.interface.ts +30 -0
- package/src/lib/interfaces/tabs.interface.ts +22 -0
- package/src/lib/interfaces/text-field.interface.ts +48 -0
- package/src/lib/interfaces/tooltip.interface.ts +35 -0
- package/src/lib/styles/button.style.ts +155 -0
- package/src/lib/styles/card.style.ts +22 -0
- package/src/lib/styles/carousel-item.style.ts +11 -0
- package/src/lib/styles/carousel.style.ts +12 -0
- package/src/lib/styles/divider.style.ts +17 -0
- package/src/lib/styles/fab.style.ts +55 -0
- package/src/lib/styles/icon-button.style.ts +140 -0
- package/src/lib/styles/index.ts +15 -0
- package/src/lib/styles/navigation-rail-item.style.ts +44 -0
- package/src/lib/styles/navigation-rail.style.ts +20 -0
- package/src/lib/styles/progress-indicator.style.ts +30 -0
- package/src/lib/styles/slider.style.ts +27 -0
- package/src/lib/styles/snackbar.style.ts +14 -0
- package/src/lib/styles/switch.style.ts +51 -0
- package/src/lib/styles/tab.style.ts +68 -0
- package/src/lib/styles/tabs.style.ts +13 -0
- package/src/lib/styles/text-field.style.ts +104 -0
- package/src/lib/styles/tooltip.style.ts +37 -0
- package/src/lib/utils/component-helper.ts +134 -0
- package/src/lib/utils/component.ts +34 -0
- package/src/lib/utils/index.ts +7 -0
- package/src/lib/utils/string.ts +9 -0
- package/src/lib/utils/styles/classnames.ts +49 -0
- package/src/lib/utils/styles/get-classname.ts +73 -0
- package/src/lib/utils/styles/index.ts +3 -0
- package/src/stories/action/button.stories.tsx +86 -0
- package/src/stories/action/fab.stories.tsx +54 -0
- package/src/stories/action/icon-button.stories.tsx +134 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +5 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +15 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +3 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +12 -0
- package/src/stories/assets/youtube.svg +4 -0
- package/src/stories/communication/ProgressIndicator.stories.tsx +57 -0
- package/src/stories/communication/SnackBar.stories.tsx +32 -0
- package/src/stories/communication/tool-tip.stories.tsx +133 -0
- package/src/stories/containment/card.stories.tsx +42 -0
- package/src/stories/containment/carousel.stories.tsx +65 -0
- package/src/stories/containment/divider.stories.tsx +35 -0
- package/src/stories/effect/smooth-scroll.stories.tsx +45 -0
- package/src/stories/navigation/navigation-rail/navigation-rail-item.stories.tsx +65 -0
- package/src/stories/navigation/navigation-rail/navigation-rail.stories.tsx +122 -0
- package/src/stories/navigation/tabs/tab.stories.tsx +57 -0
- package/src/stories/navigation/tabs/tabs.stories.tsx +102 -0
- package/src/stories/selection/slider.stories.tsx +85 -0
- package/src/stories/selection/switch.stories.tsx +46 -0
- package/src/stories/text-inputs/text-field.stories.tsx +135 -0
- package/src/tests/Button.spec.tsx +67 -0
- package/src/udixio.css +120 -0
- package/theme.config.ts +7 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +51 -0
- package/tsconfig.spec.json +37 -0
- package/tsconfig.storybook.json +38 -0
- package/vite.config.ts +75 -0
- package/index.d.ts.map +0 -1
- package/index.js +0 -10841
- package/lib/components/Button.d.ts.map +0 -1
- package/lib/components/Card.d.ts.map +0 -1
- package/lib/components/Carousel.d.ts.map +0 -1
- package/lib/components/CarouselItem.d.ts.map +0 -1
- package/lib/components/Divided.d.ts.map +0 -1
- package/lib/components/Fab.d.ts.map +0 -1
- package/lib/components/IconButton.d.ts.map +0 -1
- package/lib/components/NavigationRail.d.ts.map +0 -1
- package/lib/components/NavigationRailItem.d.ts.map +0 -1
- package/lib/components/ProgressIndicator.d.ts.map +0 -1
- package/lib/components/Slider.d.ts.map +0 -1
- package/lib/components/Snackbar.d.ts.map +0 -1
- package/lib/components/Switch.d.ts.map +0 -1
- package/lib/components/Tab.d.ts.map +0 -1
- package/lib/components/Tabs.d.ts.map +0 -1
- package/lib/components/TextField.d.ts.map +0 -1
- package/lib/components/ToolTip.d.ts.map +0 -1
- package/lib/components/index.d.ts.map +0 -1
- package/lib/effects/SyncedFixedWrapper.d.ts.map +0 -1
- package/lib/effects/custom-scroll/custom-scroll.effect.d.ts.map +0 -1
- package/lib/effects/custom-scroll/custom-scroll.interface.d.ts.map +0 -1
- package/lib/effects/custom-scroll/custom-scroll.style.d.ts.map +0 -1
- package/lib/effects/custom-scroll/index.d.ts.map +0 -1
- package/lib/effects/index.d.ts.map +0 -1
- package/lib/effects/ripple/RippleEffect.d.ts.map +0 -1
- package/lib/effects/ripple/index.d.ts.map +0 -1
- package/lib/effects/smooth-scroll.effect.d.ts.map +0 -1
- package/lib/icon/icon.d.ts.map +0 -1
- package/lib/icon/index.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/interfaces/button.interface.d.ts.map +0 -1
- package/lib/interfaces/card.interface.d.ts.map +0 -1
- package/lib/interfaces/carousel-item.interface.d.ts.map +0 -1
- package/lib/interfaces/carousel.interface.d.ts.map +0 -1
- package/lib/interfaces/divider.interface.d.ts.map +0 -1
- package/lib/interfaces/fab.interface.d.ts.map +0 -1
- package/lib/interfaces/icon-button.interface.d.ts.map +0 -1
- package/lib/interfaces/index.d.ts.map +0 -1
- package/lib/interfaces/navigation-rail-item.interface.d.ts.map +0 -1
- package/lib/interfaces/navigation-rail.interface.d.ts.map +0 -1
- package/lib/interfaces/progress-indicator.interface.d.ts.map +0 -1
- package/lib/interfaces/slider.interface.d.ts.map +0 -1
- package/lib/interfaces/snackbar.interface.d.ts.map +0 -1
- package/lib/interfaces/switch.interface.d.ts.map +0 -1
- package/lib/interfaces/tab.interface.d.ts.map +0 -1
- package/lib/interfaces/tabs.interface.d.ts.map +0 -1
- package/lib/interfaces/text-field.interface.d.ts.map +0 -1
- package/lib/interfaces/tooltip.interface.d.ts.map +0 -1
- package/lib/styles/button.style.d.ts.map +0 -1
- package/lib/styles/card.style.d.ts.map +0 -1
- package/lib/styles/carousel-item.style.d.ts.map +0 -1
- package/lib/styles/carousel.style.d.ts.map +0 -1
- package/lib/styles/divider.style.d.ts.map +0 -1
- package/lib/styles/fab.style.d.ts.map +0 -1
- package/lib/styles/icon-button.style.d.ts.map +0 -1
- package/lib/styles/index.d.ts.map +0 -1
- package/lib/styles/navigation-rail-item.style.d.ts.map +0 -1
- package/lib/styles/navigation-rail.style.d.ts.map +0 -1
- package/lib/styles/progress-indicator.style.d.ts.map +0 -1
- package/lib/styles/slider.style.d.ts.map +0 -1
- package/lib/styles/snackbar.style.d.ts.map +0 -1
- package/lib/styles/switch.style.d.ts.map +0 -1
- package/lib/styles/tab.style.d.ts.map +0 -1
- package/lib/styles/tabs.style.d.ts.map +0 -1
- package/lib/styles/text-field.style.d.ts.map +0 -1
- package/lib/styles/tooltip.style.d.ts.map +0 -1
- package/lib/utils/component-helper.d.ts.map +0 -1
- package/lib/utils/component.d.ts.map +0 -1
- package/lib/utils/index.d.ts.map +0 -1
- package/lib/utils/string.d.ts.map +0 -1
- package/lib/utils/styles/classnames.d.ts.map +0 -1
- package/lib/utils/styles/get-classname.d.ts.map +0 -1
- package/lib/utils/styles/index.d.ts.map +0 -1
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{lib → dist/lib}/components/Button.d.ts +0 -0
- /package/{lib → dist/lib}/components/Card.d.ts +0 -0
- /package/{lib → dist/lib}/components/Carousel.d.ts +0 -0
- /package/{lib → dist/lib}/components/CarouselItem.d.ts +0 -0
- /package/{lib → dist/lib}/components/Fab.d.ts +0 -0
- /package/{lib → dist/lib}/components/IconButton.d.ts +0 -0
- /package/{lib → dist/lib}/components/NavigationRail.d.ts +0 -0
- /package/{lib → dist/lib}/components/NavigationRailItem.d.ts +0 -0
- /package/{lib → dist/lib}/components/ProgressIndicator.d.ts +0 -0
- /package/{lib → dist/lib}/components/Slider.d.ts +0 -0
- /package/{lib → dist/lib}/components/Snackbar.d.ts +0 -0
- /package/{lib → dist/lib}/components/Switch.d.ts +0 -0
- /package/{lib → dist/lib}/components/Tab.d.ts +0 -0
- /package/{lib → dist/lib}/components/Tabs.d.ts +0 -0
- /package/{lib → dist/lib}/components/TextField.d.ts +0 -0
- /package/{lib → dist/lib}/components/ToolTip.d.ts +0 -0
- /package/{lib → dist/lib}/components/index.d.ts +0 -0
- /package/{lib → dist/lib}/effects/SyncedFixedWrapper.d.ts +0 -0
- /package/{lib → dist/lib}/effects/custom-scroll/custom-scroll.effect.d.ts +0 -0
- /package/{lib → dist/lib}/effects/custom-scroll/custom-scroll.interface.d.ts +0 -0
- /package/{lib → dist/lib}/effects/custom-scroll/custom-scroll.style.d.ts +0 -0
- /package/{lib → dist/lib}/effects/custom-scroll/index.d.ts +0 -0
- /package/{lib → dist/lib}/effects/index.d.ts +0 -0
- /package/{lib → dist/lib}/effects/ripple/RippleEffect.d.ts +0 -0
- /package/{lib → dist/lib}/effects/ripple/index.d.ts +0 -0
- /package/{lib → dist/lib}/effects/smooth-scroll.effect.d.ts +0 -0
- /package/{lib → dist/lib}/icon/icon.d.ts +0 -0
- /package/{lib → dist/lib}/icon/index.d.ts +0 -0
- /package/{lib → dist/lib}/index.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/button.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/card.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/carousel-item.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/carousel.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/divider.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/fab.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/icon-button.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/index.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/navigation-rail-item.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/navigation-rail.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/progress-indicator.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/slider.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/snackbar.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/switch.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/tab.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/text-field.interface.d.ts +0 -0
- /package/{lib → dist/lib}/interfaces/tooltip.interface.d.ts +0 -0
- /package/{lib → dist/lib}/styles/button.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/card.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/carousel-item.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/carousel.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/divider.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/fab.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/icon-button.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/index.d.ts +0 -0
- /package/{lib → dist/lib}/styles/navigation-rail-item.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/navigation-rail.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/progress-indicator.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/slider.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/snackbar.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/switch.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/tab.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/text-field.style.d.ts +0 -0
- /package/{lib → dist/lib}/styles/tooltip.style.d.ts +0 -0
- /package/{lib → dist/lib}/utils/component-helper.d.ts +0 -0
- /package/{lib → dist/lib}/utils/component.d.ts +0 -0
- /package/{lib → dist/lib}/utils/index.d.ts +0 -0
- /package/{lib → dist/lib}/utils/string.d.ts +0 -0
- /package/{lib → dist/lib}/utils/styles/classnames.d.ts +0 -0
- /package/{lib → dist/lib}/utils/styles/get-classname.d.ts +0 -0
- /package/{lib → dist/lib}/utils/styles/index.d.ts +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cloneElement,
|
|
3
|
+
isValidElement,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import { MotionProps } from '../utils';
|
|
9
|
+
import { Button } from './Button';
|
|
10
|
+
import { ToolTipInterface } from '../interfaces';
|
|
11
|
+
import { toolStyle } from '../styles';
|
|
12
|
+
import { v4 } from 'uuid';
|
|
13
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
14
|
+
import { SyncedFixedWrapper } from '../effects';
|
|
15
|
+
|
|
16
|
+
export const ToolTip = ({
|
|
17
|
+
variant = 'plain',
|
|
18
|
+
buttons,
|
|
19
|
+
className,
|
|
20
|
+
children,
|
|
21
|
+
title,
|
|
22
|
+
text,
|
|
23
|
+
position,
|
|
24
|
+
targetRef,
|
|
25
|
+
ref,
|
|
26
|
+
trigger = ['hover', 'focus'],
|
|
27
|
+
...props
|
|
28
|
+
}: MotionProps<ToolTipInterface>) => {
|
|
29
|
+
if (!children && !targetRef) {
|
|
30
|
+
throw new Error('ToolTip must have a child or a targetRef');
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(trigger)) {
|
|
33
|
+
trigger = [trigger];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (buttons && !Array.isArray(buttons)) {
|
|
37
|
+
buttons = [buttons];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const internalRef = useRef<HTMLElement | null>(null); // Ref interne au cas où targetRef est undefined
|
|
41
|
+
const resolvedRef = targetRef || internalRef; // Utilise targetRef si défini, sinon internalRef
|
|
42
|
+
|
|
43
|
+
const [currentToolTipId, setCurrentToolTipId] = useState<string | null>(null);
|
|
44
|
+
const [id] = useState(v4());
|
|
45
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
46
|
+
|
|
47
|
+
const timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const handleUpdate = (event: CustomEvent) => {
|
|
51
|
+
setCurrentToolTipId(event.detail);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
document.addEventListener('tooltip-update', handleUpdate as EventListener);
|
|
55
|
+
return () => {
|
|
56
|
+
document.removeEventListener(
|
|
57
|
+
'tooltip-update',
|
|
58
|
+
handleUpdate as EventListener
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (timeout.current) clearTimeout(timeout.current);
|
|
65
|
+
|
|
66
|
+
if (currentToolTipId) {
|
|
67
|
+
setIsVisible(currentToolTipId === id);
|
|
68
|
+
} else {
|
|
69
|
+
timeout.current = setTimeout(() => {
|
|
70
|
+
setIsVisible(false);
|
|
71
|
+
}, 1200);
|
|
72
|
+
}
|
|
73
|
+
}, [currentToolTipId, id]);
|
|
74
|
+
|
|
75
|
+
// Ajouter des gestionnaires sur l'élément cible (targetRef ou internalRef)
|
|
76
|
+
|
|
77
|
+
const handleMouseEnter = () => {
|
|
78
|
+
if (trigger.includes('hover')) {
|
|
79
|
+
const event = new CustomEvent('tooltip-update', { detail: id });
|
|
80
|
+
document.dispatchEvent(event);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleMouseLeave = () => {
|
|
85
|
+
if (trigger.includes('hover')) {
|
|
86
|
+
const event = new CustomEvent('tooltip-update', { detail: null });
|
|
87
|
+
document.dispatchEvent(event);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const handleClick = () => {
|
|
92
|
+
if (trigger.includes('click')) {
|
|
93
|
+
const event = new CustomEvent('tooltip-update', {
|
|
94
|
+
detail: isVisible ? null : id,
|
|
95
|
+
});
|
|
96
|
+
document.dispatchEvent(event);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const handleFocus = () => {
|
|
101
|
+
if (trigger.includes('focus')) {
|
|
102
|
+
const event = new CustomEvent('tooltip-update', { detail: id });
|
|
103
|
+
document.dispatchEvent(event);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleBlur = () => {
|
|
108
|
+
if (trigger.includes('focus')) {
|
|
109
|
+
const event = new CustomEvent('tooltip-update', { detail: null });
|
|
110
|
+
document.dispatchEvent(event);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (resolvedRef?.current) {
|
|
116
|
+
const targetElement = resolvedRef.current;
|
|
117
|
+
|
|
118
|
+
targetElement.addEventListener('mouseenter', handleMouseEnter);
|
|
119
|
+
targetElement.addEventListener('mouseleave', handleMouseLeave);
|
|
120
|
+
targetElement.addEventListener('click', handleClick);
|
|
121
|
+
targetElement.addEventListener('focus', handleFocus);
|
|
122
|
+
targetElement.addEventListener('blur', handleBlur);
|
|
123
|
+
|
|
124
|
+
// Nettoyage au démontage
|
|
125
|
+
return () => {
|
|
126
|
+
targetElement.removeEventListener('mouseenter', handleMouseEnter);
|
|
127
|
+
targetElement.removeEventListener('mouseleave', handleMouseLeave);
|
|
128
|
+
targetElement.removeEventListener('click', handleClick);
|
|
129
|
+
targetElement.removeEventListener('focus', handleFocus);
|
|
130
|
+
targetElement.removeEventListener('blur', handleBlur);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}, [resolvedRef, trigger, id, isVisible]);
|
|
134
|
+
|
|
135
|
+
// Si targetRef est undefined, on applique la réf au premier enfant
|
|
136
|
+
const enhancedChildren =
|
|
137
|
+
!targetRef && isValidElement(children)
|
|
138
|
+
? cloneElement(children, { ref: internalRef } as any)
|
|
139
|
+
: children;
|
|
140
|
+
|
|
141
|
+
if (!position && typeof window !== 'undefined') {
|
|
142
|
+
if (resolvedRef?.current && !position) {
|
|
143
|
+
const rect = resolvedRef.current.getBoundingClientRect();
|
|
144
|
+
|
|
145
|
+
const viewportWidth = window.innerWidth;
|
|
146
|
+
const viewportHeight = window.innerHeight;
|
|
147
|
+
|
|
148
|
+
const x = rect.left / viewportWidth; // X entre 0 et 1
|
|
149
|
+
const y = rect.top / viewportHeight; // Y entre 0 et 1
|
|
150
|
+
|
|
151
|
+
if (variant === 'plain') {
|
|
152
|
+
if (x < 1 / 3) {
|
|
153
|
+
position = 'right';
|
|
154
|
+
} else if (x > 2 / 3) {
|
|
155
|
+
position = 'left';
|
|
156
|
+
} else {
|
|
157
|
+
position = y > 0.5 ? 'top' : 'bottom';
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
if (x < 1 / 2 && y < 1 / 2) {
|
|
161
|
+
position = 'bottom-right';
|
|
162
|
+
} else if (x > 1 / 2 && y < 1 / 2) {
|
|
163
|
+
position = 'bottom-left';
|
|
164
|
+
} else if (x > 1 / 2 && y > 1 / 2) {
|
|
165
|
+
position = 'top-left';
|
|
166
|
+
} else if (x < 1 / 2 && y > 1 / 2) {
|
|
167
|
+
position = 'top-right';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const styles = toolStyle({
|
|
174
|
+
variant,
|
|
175
|
+
buttons,
|
|
176
|
+
className,
|
|
177
|
+
title,
|
|
178
|
+
text,
|
|
179
|
+
position,
|
|
180
|
+
trigger,
|
|
181
|
+
targetRef: targetRef as any,
|
|
182
|
+
children: children as any,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<>
|
|
187
|
+
{enhancedChildren}
|
|
188
|
+
<AnimatePresence>
|
|
189
|
+
{isVisible && (
|
|
190
|
+
<SyncedFixedWrapper targetRef={resolvedRef}>
|
|
191
|
+
<motion.div
|
|
192
|
+
initial={{ opacity: currentToolTipId ? 1 : 0 }}
|
|
193
|
+
animate={{ opacity: 1 }}
|
|
194
|
+
transition={{ duration: currentToolTipId ? 0 : 0.3 }}
|
|
195
|
+
exit={{ opacity: currentToolTipId ? 1 : 0 }}
|
|
196
|
+
className={styles.toolTip}
|
|
197
|
+
{...props}
|
|
198
|
+
onMouseEnter={handleMouseEnter}
|
|
199
|
+
onMouseLeave={handleMouseLeave}
|
|
200
|
+
>
|
|
201
|
+
<motion.div
|
|
202
|
+
className={styles.container}
|
|
203
|
+
layoutId={'tool-tip'}
|
|
204
|
+
transition={{
|
|
205
|
+
type: 'spring',
|
|
206
|
+
stiffness: 200,
|
|
207
|
+
damping: 20,
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
{title && <div className={styles.subHead}>{title}</div>}
|
|
211
|
+
<div className={styles.supportingText}>{text}</div>
|
|
212
|
+
{buttons && (
|
|
213
|
+
<div className={styles.actions}>
|
|
214
|
+
{Array.isArray(buttons) &&
|
|
215
|
+
buttons.map((buttonArgs, index) => (
|
|
216
|
+
<Button
|
|
217
|
+
key={index}
|
|
218
|
+
size={'small'}
|
|
219
|
+
variant={'text'}
|
|
220
|
+
{...buttonArgs}
|
|
221
|
+
/>
|
|
222
|
+
))}
|
|
223
|
+
</div>
|
|
224
|
+
)}
|
|
225
|
+
</motion.div>
|
|
226
|
+
</motion.div>
|
|
227
|
+
</SyncedFixedWrapper>
|
|
228
|
+
)}
|
|
229
|
+
</AnimatePresence>
|
|
230
|
+
</>
|
|
231
|
+
);
|
|
232
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './Button';
|
|
2
|
+
export * from './Card';
|
|
3
|
+
export * from './Carousel';
|
|
4
|
+
export * from './CarouselItem';
|
|
5
|
+
export * from './CarouselItem';
|
|
6
|
+
export * from './Divided';
|
|
7
|
+
export * from './Fab';
|
|
8
|
+
export * from './IconButton';
|
|
9
|
+
export * from './IconButton';
|
|
10
|
+
export * from './ProgressIndicator';
|
|
11
|
+
export * from './Slider';
|
|
12
|
+
export * from './Snackbar';
|
|
13
|
+
export * from './Switch';
|
|
14
|
+
export * from './Tab';
|
|
15
|
+
export * from './Tabs';
|
|
16
|
+
export * from './TextField';
|
|
17
|
+
export * from './NavigationRailItem';
|
|
18
|
+
export * from './NavigationRail';
|
|
19
|
+
export * from './ToolTip';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ReactNode,
|
|
3
|
+
type RefObject,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import { createPortal } from 'react-dom';
|
|
9
|
+
|
|
10
|
+
type SyncedFixedWrapperProps = {
|
|
11
|
+
targetRef: RefObject<any>;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const SyncedFixedWrapper = ({
|
|
16
|
+
targetRef,
|
|
17
|
+
children,
|
|
18
|
+
}: SyncedFixedWrapperProps) => {
|
|
19
|
+
const [style, setStyle] = useState<React.CSSProperties | null>(null);
|
|
20
|
+
const resizeObserver = useRef<ResizeObserver | null>(null);
|
|
21
|
+
|
|
22
|
+
const updatePosition = () => {
|
|
23
|
+
const target = targetRef.current;
|
|
24
|
+
if (!target) return;
|
|
25
|
+
|
|
26
|
+
const rect = target.getBoundingClientRect();
|
|
27
|
+
|
|
28
|
+
console.log(target);
|
|
29
|
+
|
|
30
|
+
setStyle({
|
|
31
|
+
position: 'fixed',
|
|
32
|
+
top: rect.top,
|
|
33
|
+
left: rect.left,
|
|
34
|
+
width: rect.width,
|
|
35
|
+
height: rect.height,
|
|
36
|
+
pointerEvents: 'none', // si le wrapper ne doit pas capter les events
|
|
37
|
+
zIndex: 999, // personnalise si besoin
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const target = targetRef.current;
|
|
43
|
+
if (!target) return;
|
|
44
|
+
|
|
45
|
+
updatePosition();
|
|
46
|
+
|
|
47
|
+
window.addEventListener('scroll', updatePosition, true);
|
|
48
|
+
window.addEventListener('resize', updatePosition);
|
|
49
|
+
|
|
50
|
+
// Observe resize of the target element
|
|
51
|
+
resizeObserver.current = new ResizeObserver(updatePosition);
|
|
52
|
+
resizeObserver.current.observe(target);
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
window.removeEventListener('scroll', updatePosition, true);
|
|
56
|
+
window.removeEventListener('resize', updatePosition);
|
|
57
|
+
resizeObserver.current?.disconnect();
|
|
58
|
+
};
|
|
59
|
+
}, [targetRef]);
|
|
60
|
+
|
|
61
|
+
if (!style) return null;
|
|
62
|
+
|
|
63
|
+
return createPortal(<div style={style}>{children}</div>, document.body);
|
|
64
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { motion, useMotionValueEvent, useScroll } from 'motion/react';
|
|
3
|
+
import { throttle } from 'throttle-debounce';
|
|
4
|
+
import { CustomScrollInterface } from './custom-scroll.interface';
|
|
5
|
+
import { customScrollStyle } from './custom-scroll.style';
|
|
6
|
+
import { ReactProps } from '../../utils';
|
|
7
|
+
|
|
8
|
+
export const CustomScroll = ({
|
|
9
|
+
children,
|
|
10
|
+
orientation = 'vertical',
|
|
11
|
+
scrollSize,
|
|
12
|
+
onScroll,
|
|
13
|
+
className,
|
|
14
|
+
draggable = false,
|
|
15
|
+
throttleDuration = 75,
|
|
16
|
+
}: ReactProps<CustomScrollInterface>) => {
|
|
17
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
18
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
19
|
+
|
|
20
|
+
// Ajout de l'état pour la largeur et la hauteur
|
|
21
|
+
const [dimensions, setDimensions] = useState<{
|
|
22
|
+
width: number | null;
|
|
23
|
+
height: number | null;
|
|
24
|
+
}>({
|
|
25
|
+
width: null,
|
|
26
|
+
height: null,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Utilisation de ResizeObserver pour surveiller la largeur ET la hauteur
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!ref.current) return;
|
|
32
|
+
|
|
33
|
+
const observer = new ResizeObserver((entries) => {
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
if (entry.target === ref.current) {
|
|
36
|
+
setDimensions({
|
|
37
|
+
width: entry.contentRect.width,
|
|
38
|
+
height: entry.contentRect.height, // On observe aussi la hauteur maintenant
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
observer.observe(ref.current);
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
observer.disconnect();
|
|
48
|
+
};
|
|
49
|
+
}, [ref]);
|
|
50
|
+
|
|
51
|
+
const contentScrollSize = useRef<{
|
|
52
|
+
height: number;
|
|
53
|
+
width: number;
|
|
54
|
+
} | null>(null);
|
|
55
|
+
const containerSize = useRef<{
|
|
56
|
+
height: number;
|
|
57
|
+
width: number;
|
|
58
|
+
} | null>(null);
|
|
59
|
+
|
|
60
|
+
const getContentScrollSize = () => {
|
|
61
|
+
const el = contentRef.current;
|
|
62
|
+
if (!el) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
width: scrollSize ?? el.scrollWidth,
|
|
67
|
+
height: scrollSize ?? el.scrollHeight,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const getContainerSize = (): { width: number; height: number } | null => {
|
|
71
|
+
const el = ref.current;
|
|
72
|
+
if (!el) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
width: el.clientWidth,
|
|
77
|
+
height: el.clientHeight, // Correction ici pour retourner la bonne hauteur
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const { scrollYProgress, scrollXProgress } = useScroll({
|
|
82
|
+
container: ref,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const handleScrollThrottledRef = useRef<
|
|
86
|
+
((latestValue: number, scrollOrientation: 'x' | 'y') => void) | null
|
|
87
|
+
>(null);
|
|
88
|
+
|
|
89
|
+
if (!handleScrollThrottledRef.current) {
|
|
90
|
+
handleScrollThrottledRef.current = throttle(
|
|
91
|
+
throttleDuration,
|
|
92
|
+
(latestValue, scrollOrientation: 'x' | 'y') => {
|
|
93
|
+
if (!containerSize.current || !contentScrollSize.current) return;
|
|
94
|
+
if (onScroll) {
|
|
95
|
+
if (orientation === 'horizontal' && scrollOrientation === 'x') {
|
|
96
|
+
onScroll({
|
|
97
|
+
scrollProgress: latestValue,
|
|
98
|
+
scroll: latestValue * contentScrollSize.current.width,
|
|
99
|
+
scrollTotal: contentScrollSize.current.width,
|
|
100
|
+
scrollVisible: containerSize.current.width,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (orientation === 'vertical' && scrollOrientation === 'y') {
|
|
104
|
+
onScroll({
|
|
105
|
+
scrollProgress: latestValue,
|
|
106
|
+
scroll: latestValue * contentScrollSize.current.height,
|
|
107
|
+
scrollTotal: contentScrollSize.current.height,
|
|
108
|
+
scrollVisible: containerSize.current.height,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const handleScroll = (latestValue: number, scrollOrientation: 'x' | 'y') => {
|
|
117
|
+
if (handleScrollThrottledRef.current) {
|
|
118
|
+
handleScrollThrottledRef.current(latestValue, scrollOrientation);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Gestion des changements pour la width ET la height
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (dimensions.width) handleScroll(scrollXProgress.get(), 'x');
|
|
125
|
+
if (dimensions.height) handleScroll(scrollYProgress.get(), 'y'); // Nouvelle ligne : mise à jour pour la hauteur
|
|
126
|
+
}, [dimensions]);
|
|
127
|
+
|
|
128
|
+
useMotionValueEvent(scrollXProgress, 'change', (latestValue) => {
|
|
129
|
+
handleScroll(latestValue, 'x');
|
|
130
|
+
});
|
|
131
|
+
useMotionValueEvent(scrollYProgress, 'change', (latestValue) => {
|
|
132
|
+
handleScroll(latestValue, 'y');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
136
|
+
useLayoutEffect(() => {
|
|
137
|
+
if (isInitialized) return;
|
|
138
|
+
if (!containerSize.current || !contentScrollSize.current || !onScroll)
|
|
139
|
+
return;
|
|
140
|
+
|
|
141
|
+
onScroll({
|
|
142
|
+
scrollProgress: 0,
|
|
143
|
+
scroll: 0,
|
|
144
|
+
scrollTotal:
|
|
145
|
+
orientation == 'vertical'
|
|
146
|
+
? contentScrollSize.current.height
|
|
147
|
+
: contentScrollSize.current.width,
|
|
148
|
+
scrollVisible:
|
|
149
|
+
orientation == 'vertical'
|
|
150
|
+
? containerSize.current.height
|
|
151
|
+
: containerSize.current.width,
|
|
152
|
+
});
|
|
153
|
+
setIsInitialized(true);
|
|
154
|
+
}, [containerSize, contentScrollSize, onScroll]);
|
|
155
|
+
|
|
156
|
+
contentScrollSize.current = getContentScrollSize();
|
|
157
|
+
containerSize.current = getContainerSize();
|
|
158
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
159
|
+
|
|
160
|
+
const styles = customScrollStyle({
|
|
161
|
+
isDragging,
|
|
162
|
+
children,
|
|
163
|
+
className,
|
|
164
|
+
onScroll,
|
|
165
|
+
orientation,
|
|
166
|
+
scrollSize,
|
|
167
|
+
draggable,
|
|
168
|
+
throttleDuration,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const [startX, setStartX] = useState<number | null>(0);
|
|
172
|
+
const [scrollLeft, setScrollLeft] = useState(0);
|
|
173
|
+
|
|
174
|
+
const handleDrag = (e: MouseEvent) => {
|
|
175
|
+
if (!draggable) return;
|
|
176
|
+
const container = ref.current;
|
|
177
|
+
if (!container) return;
|
|
178
|
+
if (startX == null) return;
|
|
179
|
+
const x = e.pageX - container.offsetLeft; // Déplace au fur et à mesure
|
|
180
|
+
const walk = (x - startX) * 1.5; // Sensibilité du drag
|
|
181
|
+
container.scrollLeft = scrollLeft - walk; // Mise à jour manuelle du défilement
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const handleMouseDown = (e: any) => {
|
|
185
|
+
const container = ref.current;
|
|
186
|
+
if (!container) return;
|
|
187
|
+
setIsDragging(true);
|
|
188
|
+
setStartX(e.pageX - container.offsetLeft); // Détecte la position initiale
|
|
189
|
+
setScrollLeft(container.scrollLeft); // Stocke la position de défilement actuelle
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const handleMouseMove = (e: any) => {
|
|
193
|
+
if (!isDragging) return;
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
handleDrag(e);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const handleMouseUp = () => {
|
|
199
|
+
setIsDragging(false);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const handleMouseLeave = () => {
|
|
203
|
+
setIsDragging(false);
|
|
204
|
+
};
|
|
205
|
+
const handleDragStart = (e: any) => {
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const timerRef = useRef<NodeJS.Timeout | null>(null);
|
|
210
|
+
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
// Nettoie le timer lorsqu'on quitte le composant (important pour éviter les fuites de mémoire)
|
|
213
|
+
return () => {
|
|
214
|
+
if (timerRef.current) {
|
|
215
|
+
clearTimeout(timerRef.current);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}, []);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<div
|
|
222
|
+
className={styles.customScroll}
|
|
223
|
+
ref={ref}
|
|
224
|
+
onMouseDown={handleMouseDown}
|
|
225
|
+
onMouseMove={handleMouseMove}
|
|
226
|
+
onMouseUp={handleMouseUp}
|
|
227
|
+
onMouseLeave={handleMouseLeave}
|
|
228
|
+
onDragStart={handleDragStart}
|
|
229
|
+
onScroll={(e) => {
|
|
230
|
+
if (!isDragging) {
|
|
231
|
+
// Met à jour l'état pour indiquer que le scroll est en cours
|
|
232
|
+
setStartX(null);
|
|
233
|
+
setIsDragging(true);
|
|
234
|
+
// Réinitialiser le timer (on le supprime si des scrolls successifs se produisent)
|
|
235
|
+
if (timerRef.current) {
|
|
236
|
+
clearTimeout(timerRef.current);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Créer un nouveau timer : `isDrawing` sera désactivé après 1 seconde
|
|
240
|
+
timerRef.current = setTimeout(() => {
|
|
241
|
+
setIsDragging(false);
|
|
242
|
+
}, 1000); // 1000ms = 1 seconde
|
|
243
|
+
}
|
|
244
|
+
}}
|
|
245
|
+
>
|
|
246
|
+
<div
|
|
247
|
+
ref={contentRef}
|
|
248
|
+
style={
|
|
249
|
+
orientation === 'vertical'
|
|
250
|
+
? { height: containerSize?.current?.height ?? '100%' }
|
|
251
|
+
: { width: containerSize?.current?.width ?? '100%' }
|
|
252
|
+
}
|
|
253
|
+
className={styles.track}
|
|
254
|
+
>
|
|
255
|
+
{children}
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
{containerSize.current && contentScrollSize.current && (
|
|
259
|
+
<>
|
|
260
|
+
{orientation === 'vertical' &&
|
|
261
|
+
contentScrollSize.current.height > containerSize.current.height && (
|
|
262
|
+
<motion.div
|
|
263
|
+
className={'flex-none'}
|
|
264
|
+
style={{
|
|
265
|
+
height:
|
|
266
|
+
contentScrollSize.current.height -
|
|
267
|
+
containerSize.current.height,
|
|
268
|
+
}}
|
|
269
|
+
/>
|
|
270
|
+
)}
|
|
271
|
+
|
|
272
|
+
{orientation === 'horizontal' &&
|
|
273
|
+
contentScrollSize.current.width > containerSize.current.width && (
|
|
274
|
+
<motion.div
|
|
275
|
+
className={'flex-none'}
|
|
276
|
+
style={{
|
|
277
|
+
width:
|
|
278
|
+
contentScrollSize.current.width -
|
|
279
|
+
containerSize.current.width,
|
|
280
|
+
}}
|
|
281
|
+
/>
|
|
282
|
+
)}
|
|
283
|
+
</>
|
|
284
|
+
)}
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
orientation?: 'vertical' | 'horizontal';
|
|
6
|
+
scrollSize?: number;
|
|
7
|
+
onScroll?: (args: {
|
|
8
|
+
scroll: number;
|
|
9
|
+
scrollProgress: number;
|
|
10
|
+
scrollTotal: number;
|
|
11
|
+
scrollVisible: number;
|
|
12
|
+
}) => void;
|
|
13
|
+
draggable?: boolean;
|
|
14
|
+
throttleDuration?: number;
|
|
15
|
+
};
|
|
16
|
+
type CustomScrollStates = {
|
|
17
|
+
isDragging: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export interface CustomScrollInterface {
|
|
21
|
+
type: 'div';
|
|
22
|
+
props: Props;
|
|
23
|
+
states: CustomScrollStates;
|
|
24
|
+
elements: ['customScroll', 'track'];
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CustomScrollInterface } from './custom-scroll.interface';
|
|
2
|
+
import { classNames, defaultClassNames } from '../../utils';
|
|
3
|
+
|
|
4
|
+
export const customScrollStyle = defaultClassNames<CustomScrollInterface>(
|
|
5
|
+
'customScroll',
|
|
6
|
+
({ orientation, draggable, isDragging }) => ({
|
|
7
|
+
customScroll: classNames(
|
|
8
|
+
'flex h-full w-full',
|
|
9
|
+
draggable && [
|
|
10
|
+
'[&::-webkit-scrollbar-track]:rounded-full',
|
|
11
|
+
'[&::-webkit-scrollbar-track]:bg-transparent',
|
|
12
|
+
'[&::-webkit-scrollbar-thumb]:rounded-full',
|
|
13
|
+
{
|
|
14
|
+
'[&::-webkit-scrollbar-thumb]:bg-outline': isDragging,
|
|
15
|
+
'[&::-webkit-scrollbar-thumb]:bg-transparent': !isDragging,
|
|
16
|
+
},
|
|
17
|
+
{ '[&::-webkit-scrollbar]:h-2': orientation === 'horizontal' },
|
|
18
|
+
{ '[&::-webkit-scrollbar]:w-2': orientation === 'vertical' },
|
|
19
|
+
],
|
|
20
|
+
{
|
|
21
|
+
'overflow-y-scroll flex-col': orientation === 'vertical',
|
|
22
|
+
'overflow-x-scroll flex-row': orientation === 'horizontal',
|
|
23
|
+
'cursor-grab': draggable && !isDragging,
|
|
24
|
+
'cursor-grabbing': draggable && isDragging,
|
|
25
|
+
}
|
|
26
|
+
),
|
|
27
|
+
track: classNames('overflow-hidden flex-none sticky', {
|
|
28
|
+
'left-0 h-full': orientation === 'horizontal',
|
|
29
|
+
'top-0 w-full': orientation === 'vertical',
|
|
30
|
+
}),
|
|
31
|
+
})
|
|
32
|
+
);
|