@udixio/ui-react 2.10.13 → 2.10.15
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/package.json +4 -2
- package/.eslintrc.mjs +0 -22
- package/.storybook/main.ts +0 -20
- package/.storybook/preview.ts +0 -1
- package/CHANGELOG.md +0 -1144
- package/postcss.config.mjs +0 -5
- package/src/index.css +0 -4
- package/src/index.ts +0 -1
- package/src/lib/components/AnchorPositioner.tsx +0 -185
- package/src/lib/components/Button.tsx +0 -208
- package/src/lib/components/Card.tsx +0 -47
- package/src/lib/components/Carousel.tsx +0 -437
- package/src/lib/components/CarouselItem.tsx +0 -61
- package/src/lib/components/Checkbox.tsx +0 -120
- package/src/lib/components/Chip.tsx +0 -341
- package/src/lib/components/Chips.tsx +0 -331
- package/src/lib/components/ContextMenu.tsx +0 -109
- package/src/lib/components/DatePicker.tsx +0 -432
- package/src/lib/components/Divider.tsx +0 -20
- package/src/lib/components/Fab.tsx +0 -127
- package/src/lib/components/FabMenu.tsx +0 -239
- package/src/lib/components/IconButton.tsx +0 -146
- package/src/lib/components/Menu.tsx +0 -88
- package/src/lib/components/MenuGroup.tsx +0 -34
- package/src/lib/components/MenuHeadline.tsx +0 -9
- package/src/lib/components/MenuItem.tsx +0 -215
- package/src/lib/components/NavigationRail.tsx +0 -186
- package/src/lib/components/NavigationRailItem.tsx +0 -227
- package/src/lib/components/ProgressIndicator.tsx +0 -214
- package/src/lib/components/SideSheet.tsx +0 -135
- package/src/lib/components/Slider.tsx +0 -374
- package/src/lib/components/Snackbar.tsx +0 -77
- package/src/lib/components/Switch.tsx +0 -107
- package/src/lib/components/Tab.tsx +0 -123
- package/src/lib/components/TabGroup.tsx +0 -66
- package/src/lib/components/TabGroupContext.tsx +0 -16
- package/src/lib/components/TabPanel.tsx +0 -27
- package/src/lib/components/TabPanels.tsx +0 -76
- package/src/lib/components/Tabs.tsx +0 -105
- package/src/lib/components/TextField.tsx +0 -586
- package/src/lib/components/Tooltip.tsx +0 -217
- package/src/lib/components/index.ts +0 -34
- package/src/lib/config/config.interface.ts +0 -9
- package/src/lib/config/define-config.ts +0 -16
- package/src/lib/config/index.ts +0 -2
- package/src/lib/effects/AnimateOnScroll.ts +0 -391
- package/src/lib/effects/State.tsx +0 -90
- package/src/lib/effects/SyncedFixedWrapper.tsx +0 -62
- package/src/lib/effects/ThemeProvider.tsx +0 -174
- package/src/lib/effects/block-scroll.effect.tsx +0 -313
- package/src/lib/effects/custom-scroll/custom-scroll.effect.tsx +0 -407
- package/src/lib/effects/custom-scroll/custom-scroll.interface.ts +0 -29
- package/src/lib/effects/custom-scroll/custom-scroll.style.ts +0 -32
- package/src/lib/effects/custom-scroll/index.ts +0 -3
- package/src/lib/effects/index.ts +0 -7
- package/src/lib/effects/ripple/RippleEffect.tsx +0 -116
- package/src/lib/effects/ripple/index.tsx +0 -1
- package/src/lib/effects/scrollDriven.ts +0 -239
- package/src/lib/effects/smooth-scroll.effect.tsx +0 -112
- package/src/lib/effects/theme.worker.ts +0 -97
- package/src/lib/hooks/index.ts +0 -10
- package/src/lib/hooks/useTooltipTrigger.ts +0 -270
- package/src/lib/icon/icon.tsx +0 -125
- package/src/lib/icon/index.ts +0 -1
- package/src/lib/index.ts +0 -8
- package/src/lib/interfaces/button.interface.ts +0 -65
- package/src/lib/interfaces/card.interface.ts +0 -11
- package/src/lib/interfaces/carousel-item.interface.ts +0 -12
- package/src/lib/interfaces/carousel.interface.ts +0 -41
- package/src/lib/interfaces/checkbox.interface.ts +0 -39
- package/src/lib/interfaces/chip.interface.ts +0 -97
- package/src/lib/interfaces/chips.interface.ts +0 -37
- package/src/lib/interfaces/date-picker.interface.ts +0 -79
- package/src/lib/interfaces/divider.interface.ts +0 -7
- package/src/lib/interfaces/fab-menu.interface.ts +0 -12
- package/src/lib/interfaces/fab.interface.ts +0 -27
- package/src/lib/interfaces/icon-button.interface.ts +0 -38
- package/src/lib/interfaces/index.ts +0 -26
- package/src/lib/interfaces/menu-group.interface.ts +0 -13
- package/src/lib/interfaces/menu-item.interface.ts +0 -29
- package/src/lib/interfaces/menu.interface.ts +0 -19
- package/src/lib/interfaces/navigation-rail-item.interface.ts +0 -39
- package/src/lib/interfaces/navigation-rail.interface.ts +0 -39
- package/src/lib/interfaces/progress-indicator.interface.ts +0 -41
- package/src/lib/interfaces/side-sheet.interface.tsx +0 -28
- package/src/lib/interfaces/slider.interface.ts +0 -27
- package/src/lib/interfaces/snackbar.interface.ts +0 -13
- package/src/lib/interfaces/switch.interface.ts +0 -14
- package/src/lib/interfaces/tab-group.interface.ts +0 -13
- package/src/lib/interfaces/tab-panels.interface.ts +0 -21
- package/src/lib/interfaces/tab.interface.ts +0 -31
- package/src/lib/interfaces/tabs.interface.ts +0 -22
- package/src/lib/interfaces/text-field.interface.ts +0 -61
- package/src/lib/interfaces/tooltip.interface.ts +0 -61
- package/src/lib/styles/button.style.ts +0 -136
- package/src/lib/styles/card.style.ts +0 -29
- package/src/lib/styles/carousel-item.style.ts +0 -24
- package/src/lib/styles/carousel.style.ts +0 -22
- package/src/lib/styles/checkbox.style.ts +0 -64
- package/src/lib/styles/chip.style.ts +0 -62
- package/src/lib/styles/chips.style.ts +0 -20
- package/src/lib/styles/date-picker.style.ts +0 -43
- package/src/lib/styles/divider.style.ts +0 -31
- package/src/lib/styles/fab-menu.style.ts +0 -29
- package/src/lib/styles/fab.style.ts +0 -49
- package/src/lib/styles/icon-button.style.ts +0 -168
- package/src/lib/styles/index.ts +0 -25
- package/src/lib/styles/menu-group.style.ts +0 -34
- package/src/lib/styles/menu-headline.style.ts +0 -20
- package/src/lib/styles/menu-item.style.ts +0 -45
- package/src/lib/styles/menu.style.ts +0 -32
- package/src/lib/styles/navigation-rail-item.style.ts +0 -56
- package/src/lib/styles/navigation-rail.style.ts +0 -36
- package/src/lib/styles/progress-indicator.style.ts +0 -72
- package/src/lib/styles/side-sheet.style.ts +0 -45
- package/src/lib/styles/slider.style.ts +0 -41
- package/src/lib/styles/snackbar.style.ts +0 -26
- package/src/lib/styles/switch.style.ts +0 -67
- package/src/lib/styles/tab-panels.style.ts +0 -35
- package/src/lib/styles/tab.style.ts +0 -78
- package/src/lib/styles/tabs.style.ts +0 -22
- package/src/lib/styles/text-field.style.ts +0 -115
- package/src/lib/styles/tooltip.style.ts +0 -48
- package/src/lib/utils/component-helper.ts +0 -134
- package/src/lib/utils/component.ts +0 -34
- package/src/lib/utils/index.ts +0 -7
- package/src/lib/utils/string.ts +0 -9
- package/src/lib/utils/styles/classnames.ts +0 -49
- package/src/lib/utils/styles/get-classname.ts +0 -96
- package/src/lib/utils/styles/index.ts +0 -4
- package/src/lib/utils/styles/use-classnames.ts +0 -25
- package/src/stories/action/button.stories.tsx +0 -86
- package/src/stories/action/fab.stories.tsx +0 -54
- package/src/stories/action/icon-button.stories.tsx +0 -134
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -5
- 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 +0 -15
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -3
- 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 +0 -12
- package/src/stories/assets/youtube.svg +0 -4
- package/src/stories/communication/ProgressIndicator.stories.tsx +0 -57
- package/src/stories/communication/SnackBar.stories.tsx +0 -32
- package/src/stories/communication/tool-tip.stories.tsx +0 -133
- package/src/stories/containment/card.stories.tsx +0 -42
- package/src/stories/containment/carousel.stories.tsx +0 -65
- package/src/stories/containment/divider.stories.tsx +0 -35
- package/src/stories/containment/slide-sheet.stories.tsx +0 -45
- package/src/stories/effect/smooth-scroll.stories.tsx +0 -54
- package/src/stories/navigation/navigation-rail/navigation-rail-item.stories.tsx +0 -65
- package/src/stories/navigation/navigation-rail/navigation-rail.stories.tsx +0 -122
- package/src/stories/navigation/tabs/tab.stories.tsx +0 -57
- package/src/stories/navigation/tabs/tabs.stories.tsx +0 -102
- package/src/stories/selection/slider.stories.tsx +0 -85
- package/src/stories/selection/switch.stories.tsx +0 -46
- package/src/stories/text-inputs/text-field.stories.tsx +0 -135
- package/src/tests/Button.spec.tsx +0 -67
- package/src/tests/useClassNames.spec.tsx +0 -82
- package/src/udixio.css +0 -120
- package/theme.config.ts +0 -7
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -51
- package/tsconfig.spec.json +0 -37
- package/tsconfig.storybook.json +0 -38
- package/vite.config.ts +0 -96
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
-
import { motion, useMotionValueEvent, useScroll } from 'motion/react';
|
|
3
|
-
import { CustomScrollInterface } from './custom-scroll.interface';
|
|
4
|
-
import { customScrollStyle } from './custom-scroll.style';
|
|
5
|
-
import { ReactProps } from '../../utils';
|
|
6
|
-
|
|
7
|
-
// Throttle helper that guarantees execution of the latest call after the wait window (leading + trailing)
|
|
8
|
-
function createScrollThrottle(
|
|
9
|
-
wait: number,
|
|
10
|
-
fn: (latestValue: number, scrollOrientation: 'x' | 'y') => void,
|
|
11
|
-
) {
|
|
12
|
-
let lastInvokeTime = 0;
|
|
13
|
-
let trailingTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
14
|
-
let lastArgs: { v: number; o: 'x' | 'y' } | null = null;
|
|
15
|
-
|
|
16
|
-
const invoke = (v: number, o: 'x' | 'y') => {
|
|
17
|
-
lastInvokeTime = Date.now();
|
|
18
|
-
fn(v, o);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return (v: number, o: 'x' | 'y') => {
|
|
22
|
-
const now = Date.now();
|
|
23
|
-
const remaining = wait - (now - lastInvokeTime);
|
|
24
|
-
|
|
25
|
-
if (remaining <= 0) {
|
|
26
|
-
if (trailingTimeout) {
|
|
27
|
-
clearTimeout(trailingTimeout);
|
|
28
|
-
trailingTimeout = null;
|
|
29
|
-
}
|
|
30
|
-
invoke(v, o);
|
|
31
|
-
} else {
|
|
32
|
-
// Save the latest call and schedule a trailing execution
|
|
33
|
-
lastArgs = { v, o };
|
|
34
|
-
if (!trailingTimeout) {
|
|
35
|
-
trailingTimeout = setTimeout(() => {
|
|
36
|
-
trailingTimeout = null;
|
|
37
|
-
const args = lastArgs;
|
|
38
|
-
lastArgs = null;
|
|
39
|
-
if (args) invoke(args.v, args.o);
|
|
40
|
-
}, remaining);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const CustomScroll = ({
|
|
47
|
-
children,
|
|
48
|
-
orientation = 'vertical',
|
|
49
|
-
scrollSize,
|
|
50
|
-
onScroll,
|
|
51
|
-
className,
|
|
52
|
-
draggable = false,
|
|
53
|
-
throttleDuration = 75,
|
|
54
|
-
scroll,
|
|
55
|
-
setScroll,
|
|
56
|
-
}: ReactProps<CustomScrollInterface>) => {
|
|
57
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
58
|
-
const contentRef = useRef<HTMLDivElement>(null);
|
|
59
|
-
|
|
60
|
-
// Ajout de l'état pour la largeur et la hauteur
|
|
61
|
-
const [dimensions, setDimensions] = useState<{
|
|
62
|
-
width: number | null;
|
|
63
|
-
height: number | null;
|
|
64
|
-
}>({
|
|
65
|
-
width: null,
|
|
66
|
-
height: null,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Utilisation de ResizeObserver pour surveiller la largeur ET la hauteur
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (!ref.current) return;
|
|
72
|
-
|
|
73
|
-
const observer = new ResizeObserver((entries) => {
|
|
74
|
-
for (const entry of entries) {
|
|
75
|
-
if (entry.target === ref.current) {
|
|
76
|
-
setDimensions({
|
|
77
|
-
width: entry.contentRect.width,
|
|
78
|
-
height: entry.contentRect.height, // On observe aussi la hauteur maintenant
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
observer.observe(ref.current);
|
|
85
|
-
|
|
86
|
-
return () => {
|
|
87
|
-
observer.disconnect();
|
|
88
|
-
};
|
|
89
|
-
}, [ref]);
|
|
90
|
-
|
|
91
|
-
const contentScrollSize = useRef<{
|
|
92
|
-
height: number;
|
|
93
|
-
width: number;
|
|
94
|
-
} | null>(null);
|
|
95
|
-
const containerSize = useRef<{
|
|
96
|
-
height: number;
|
|
97
|
-
width: number;
|
|
98
|
-
} | null>(null);
|
|
99
|
-
|
|
100
|
-
const getContentScrollSize = () => {
|
|
101
|
-
const el = contentRef.current;
|
|
102
|
-
if (!el) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
width: scrollSize ?? el.scrollWidth,
|
|
107
|
-
height: scrollSize ?? el.scrollHeight,
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
const getContainerSize = (): { width: number; height: number } | null => {
|
|
111
|
-
const el = ref.current;
|
|
112
|
-
if (!el) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
width: el.clientWidth,
|
|
117
|
-
height: el.clientHeight, // Correction ici pour retourner la bonne hauteur
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const { scrollYProgress, scrollXProgress } = useScroll({
|
|
122
|
-
container: ref,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const handleScrollThrottledRef = useRef<
|
|
126
|
-
((latestValue: number, scrollOrientation: 'x' | 'y') => void) | null
|
|
127
|
-
>(null);
|
|
128
|
-
|
|
129
|
-
if (!handleScrollThrottledRef.current) {
|
|
130
|
-
handleScrollThrottledRef.current = createScrollThrottle(
|
|
131
|
-
throttleDuration,
|
|
132
|
-
(latestValue, scrollOrientation: 'x' | 'y') => {
|
|
133
|
-
if (
|
|
134
|
-
!containerSize.current ||
|
|
135
|
-
!contentScrollSize.current ||
|
|
136
|
-
!ref.current
|
|
137
|
-
)
|
|
138
|
-
return;
|
|
139
|
-
|
|
140
|
-
// Notify simple percentage if requested
|
|
141
|
-
if (scrollOrientation === (orientation === 'horizontal' ? 'x' : 'y')) {
|
|
142
|
-
setScroll?.(latestValue);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (onScroll) {
|
|
146
|
-
if (orientation === 'horizontal' && scrollOrientation === 'x') {
|
|
147
|
-
onScroll({
|
|
148
|
-
scrollProgress: latestValue,
|
|
149
|
-
scroll:
|
|
150
|
-
latestValue *
|
|
151
|
-
(contentScrollSize.current.width - ref.current.clientWidth),
|
|
152
|
-
scrollTotal:
|
|
153
|
-
contentScrollSize.current.width - ref.current.clientWidth,
|
|
154
|
-
scrollVisible: containerSize.current.width,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
if (orientation === 'vertical' && scrollOrientation === 'y') {
|
|
158
|
-
onScroll({
|
|
159
|
-
scrollProgress: latestValue,
|
|
160
|
-
scroll:
|
|
161
|
-
latestValue *
|
|
162
|
-
(contentScrollSize.current.height - ref.current.clientHeight),
|
|
163
|
-
scrollTotal:
|
|
164
|
-
contentScrollSize.current.height - ref.current.clientHeight,
|
|
165
|
-
scrollVisible: containerSize.current.height,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const handleScroll = (latestValue: number, scrollOrientation: 'x' | 'y') => {
|
|
174
|
-
if (handleScrollThrottledRef.current) {
|
|
175
|
-
handleScrollThrottledRef.current(latestValue, scrollOrientation);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// Gestion des changements pour la width ET la height
|
|
180
|
-
useEffect(() => {
|
|
181
|
-
if (dimensions.width) handleScroll(scrollXProgress.get(), 'x');
|
|
182
|
-
if (dimensions.height) handleScroll(scrollYProgress.get(), 'y'); // Nouvelle ligne : mise à jour pour la hauteur
|
|
183
|
-
}, [dimensions]);
|
|
184
|
-
|
|
185
|
-
// Apply controlled scroll percentage to DOM when provided
|
|
186
|
-
useEffect(() => {
|
|
187
|
-
const container = ref.current;
|
|
188
|
-
const content = contentRef.current;
|
|
189
|
-
if (!container || !content) return;
|
|
190
|
-
if (typeof scroll !== 'number') return;
|
|
191
|
-
const clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v));
|
|
192
|
-
if (orientation === 'horizontal') {
|
|
193
|
-
const total = Math.max(0, (scrollSize ?? content.scrollWidth) - container.clientWidth);
|
|
194
|
-
container.scrollLeft = clamp(scroll * total, 0, total);
|
|
195
|
-
} else {
|
|
196
|
-
const total = Math.max(0, (scrollSize ?? content.scrollHeight) - container.clientHeight);
|
|
197
|
-
container.scrollTop = clamp(scroll * total, 0, total);
|
|
198
|
-
}
|
|
199
|
-
}, [scroll, orientation, scrollSize]);
|
|
200
|
-
|
|
201
|
-
useMotionValueEvent(scrollXProgress, 'change', (latestValue) => {
|
|
202
|
-
handleScroll(latestValue, 'x');
|
|
203
|
-
});
|
|
204
|
-
useMotionValueEvent(scrollYProgress, 'change', (latestValue) => {
|
|
205
|
-
handleScroll(latestValue, 'y');
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const [isInitialized, setIsInitialized] = useState(false);
|
|
209
|
-
useLayoutEffect(() => {
|
|
210
|
-
if (isInitialized) return;
|
|
211
|
-
if (!containerSize.current || !contentScrollSize.current || !onScroll)
|
|
212
|
-
return;
|
|
213
|
-
|
|
214
|
-
onScroll({
|
|
215
|
-
scrollProgress: 0,
|
|
216
|
-
scroll: 0,
|
|
217
|
-
scrollTotal:
|
|
218
|
-
orientation == 'vertical'
|
|
219
|
-
? contentScrollSize.current.height
|
|
220
|
-
: contentScrollSize.current.width,
|
|
221
|
-
scrollVisible:
|
|
222
|
-
orientation == 'vertical'
|
|
223
|
-
? containerSize.current.height
|
|
224
|
-
: containerSize.current.width,
|
|
225
|
-
});
|
|
226
|
-
setIsInitialized(true);
|
|
227
|
-
}, [containerSize, contentScrollSize, onScroll]);
|
|
228
|
-
|
|
229
|
-
contentScrollSize.current = getContentScrollSize();
|
|
230
|
-
containerSize.current = getContainerSize();
|
|
231
|
-
const [isDragging, setIsDragging] = useState(false);
|
|
232
|
-
|
|
233
|
-
const styles = customScrollStyle({
|
|
234
|
-
isDragging,
|
|
235
|
-
children,
|
|
236
|
-
className,
|
|
237
|
-
onScroll,
|
|
238
|
-
orientation,
|
|
239
|
-
scrollSize,
|
|
240
|
-
draggable,
|
|
241
|
-
throttleDuration,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const [startX, setStartX] = useState<number | null>(0);
|
|
245
|
-
const [scrollLeft, setScrollLeft] = useState(0);
|
|
246
|
-
|
|
247
|
-
const handleDrag = (e: MouseEvent) => {
|
|
248
|
-
if (!draggable) return;
|
|
249
|
-
const container = ref.current;
|
|
250
|
-
if (!container) return;
|
|
251
|
-
if (startX == null) return;
|
|
252
|
-
const x = e.pageX - container.offsetLeft; // Déplace au fur et à mesure
|
|
253
|
-
const walk = (x - startX) * 1.5; // Sensibilité du drag
|
|
254
|
-
container.scrollLeft = scrollLeft - walk; // Mise à jour manuelle du défilement
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const handleMouseDown = (e: any) => {
|
|
258
|
-
const container = ref.current;
|
|
259
|
-
if (!container) return;
|
|
260
|
-
setIsDragging(true);
|
|
261
|
-
setStartX(e.pageX - container.offsetLeft); // Détecte la position initiale
|
|
262
|
-
setScrollLeft(container.scrollLeft); // Stocke la position de défilement actuelle
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
const handleMouseMove = (e: any) => {
|
|
266
|
-
if (!isDragging) return;
|
|
267
|
-
e.preventDefault();
|
|
268
|
-
handleDrag(e);
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const handleMouseUp = () => {
|
|
272
|
-
setIsDragging(false);
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
const handleMouseLeave = () => {
|
|
276
|
-
setIsDragging(false);
|
|
277
|
-
};
|
|
278
|
-
const handleDragStart = (e: any) => {
|
|
279
|
-
e.preventDefault();
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const timerRef = useRef<NodeJS.Timeout | null>(null);
|
|
283
|
-
|
|
284
|
-
useEffect(() => {
|
|
285
|
-
// Nettoie le timer lorsqu'on quitte le composant (important pour éviter les fuites de mémoire)
|
|
286
|
-
return () => {
|
|
287
|
-
if (timerRef.current) {
|
|
288
|
-
clearTimeout(timerRef.current);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
}, []);
|
|
292
|
-
|
|
293
|
-
// External controller: listen for bubbling custom event to set scroll programmatically
|
|
294
|
-
useEffect(() => {
|
|
295
|
-
const el = ref.current;
|
|
296
|
-
if (!el) return;
|
|
297
|
-
const handler = (ev: Event) => {
|
|
298
|
-
const detail = (ev as CustomEvent).detail as
|
|
299
|
-
| { progress?: number; scroll?: number; orientation?: 'horizontal' | 'vertical' }
|
|
300
|
-
| undefined;
|
|
301
|
-
const container = ref.current;
|
|
302
|
-
if (!container || !detail) return;
|
|
303
|
-
const ori = detail.orientation ?? orientation;
|
|
304
|
-
if (typeof detail.progress === 'number') {
|
|
305
|
-
if (ori === 'horizontal') {
|
|
306
|
-
const total = Math.max(
|
|
307
|
-
0,
|
|
308
|
-
(contentScrollSize.current?.width ?? 0) - container.clientWidth,
|
|
309
|
-
);
|
|
310
|
-
container.scrollLeft = Math.min(total, Math.max(0, detail.progress * total));
|
|
311
|
-
} else {
|
|
312
|
-
const total = Math.max(
|
|
313
|
-
0,
|
|
314
|
-
(contentScrollSize.current?.height ?? 0) - container.clientHeight,
|
|
315
|
-
);
|
|
316
|
-
container.scrollTop = Math.min(total, Math.max(0, detail.progress * total));
|
|
317
|
-
}
|
|
318
|
-
} else if (typeof detail.scroll === 'number') {
|
|
319
|
-
if (ori === 'horizontal') {
|
|
320
|
-
const total = Math.max(
|
|
321
|
-
0,
|
|
322
|
-
(contentScrollSize.current?.width ?? 0) - container.clientWidth,
|
|
323
|
-
);
|
|
324
|
-
container.scrollLeft = Math.min(total, Math.max(0, detail.scroll));
|
|
325
|
-
} else {
|
|
326
|
-
const total = Math.max(
|
|
327
|
-
0,
|
|
328
|
-
(contentScrollSize.current?.height ?? 0) - container.clientHeight,
|
|
329
|
-
);
|
|
330
|
-
container.scrollTop = Math.min(total, Math.max(0, detail.scroll));
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
el.addEventListener('udx:customScroll:set', handler as EventListener);
|
|
335
|
-
return () => {
|
|
336
|
-
el.removeEventListener('udx:customScroll:set', handler as EventListener);
|
|
337
|
-
};
|
|
338
|
-
}, [orientation]);
|
|
339
|
-
|
|
340
|
-
return (
|
|
341
|
-
<div
|
|
342
|
-
className={styles.customScroll}
|
|
343
|
-
ref={ref}
|
|
344
|
-
onMouseDown={handleMouseDown}
|
|
345
|
-
onMouseMove={handleMouseMove}
|
|
346
|
-
onMouseUp={handleMouseUp}
|
|
347
|
-
onMouseLeave={handleMouseLeave}
|
|
348
|
-
onDragStart={handleDragStart}
|
|
349
|
-
onScroll={(e) => {
|
|
350
|
-
if (!isDragging) {
|
|
351
|
-
// Met à jour l'état pour indiquer que le scroll est en cours
|
|
352
|
-
setStartX(null);
|
|
353
|
-
setIsDragging(true);
|
|
354
|
-
// Réinitialiser le timer (on le supprime si des scrolls successifs se produisent)
|
|
355
|
-
if (timerRef.current) {
|
|
356
|
-
clearTimeout(timerRef.current);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// Créer un nouveau timer : `isDrawing` sera désactivé après 1 seconde
|
|
360
|
-
timerRef.current = setTimeout(() => {
|
|
361
|
-
setIsDragging(false);
|
|
362
|
-
}, 1000); // 1000ms = 1 seconde
|
|
363
|
-
}
|
|
364
|
-
}}
|
|
365
|
-
>
|
|
366
|
-
<div
|
|
367
|
-
ref={contentRef}
|
|
368
|
-
style={
|
|
369
|
-
orientation === 'vertical'
|
|
370
|
-
? { height: containerSize?.current?.height ?? '100%' }
|
|
371
|
-
: { width: containerSize?.current?.width ?? '100%' }
|
|
372
|
-
}
|
|
373
|
-
className={styles.track}
|
|
374
|
-
>
|
|
375
|
-
{children}
|
|
376
|
-
</div>
|
|
377
|
-
|
|
378
|
-
{containerSize.current && contentScrollSize.current && (
|
|
379
|
-
<>
|
|
380
|
-
{orientation === 'vertical' &&
|
|
381
|
-
contentScrollSize.current.height > containerSize.current.height && (
|
|
382
|
-
<motion.div
|
|
383
|
-
className={'flex-none'}
|
|
384
|
-
style={{
|
|
385
|
-
height:
|
|
386
|
-
contentScrollSize.current.height -
|
|
387
|
-
containerSize.current.height,
|
|
388
|
-
}}
|
|
389
|
-
/>
|
|
390
|
-
)}
|
|
391
|
-
|
|
392
|
-
{orientation === 'horizontal' &&
|
|
393
|
-
contentScrollSize.current.width > containerSize.current.width && (
|
|
394
|
-
<motion.div
|
|
395
|
-
className={'flex-none'}
|
|
396
|
-
style={{
|
|
397
|
-
width:
|
|
398
|
-
contentScrollSize.current.width -
|
|
399
|
-
containerSize.current.width,
|
|
400
|
-
}}
|
|
401
|
-
/>
|
|
402
|
-
)}
|
|
403
|
-
</>
|
|
404
|
-
)}
|
|
405
|
-
</div>
|
|
406
|
-
);
|
|
407
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
// Controlled percentage (0..1). If provided, the container will reflect this progress.
|
|
14
|
-
scroll?: number;
|
|
15
|
-
// Callback fired with the latest scroll percentage (0..1) when user scrolls/drags.
|
|
16
|
-
setScroll?: (progress: number) => void;
|
|
17
|
-
draggable?: boolean;
|
|
18
|
-
throttleDuration?: number;
|
|
19
|
-
};
|
|
20
|
-
type CustomScrollStates = {
|
|
21
|
-
isDragging: boolean;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export interface CustomScrollInterface {
|
|
25
|
-
type: 'div';
|
|
26
|
-
props: Props;
|
|
27
|
-
states: CustomScrollStates;
|
|
28
|
-
elements: ['customScroll', 'track'];
|
|
29
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
);
|
package/src/lib/effects/index.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { AnimatePresence, motion } from 'motion/react';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
interface RippleEffectProps {
|
|
5
|
-
triggerRef: React.RefObject<any> | React.ForwardedRef<any>;
|
|
6
|
-
colorName?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const RippleEffect: React.FC<RippleEffectProps> = ({
|
|
10
|
-
colorName = 'on-surface',
|
|
11
|
-
triggerRef,
|
|
12
|
-
}) => {
|
|
13
|
-
const ripple = {
|
|
14
|
-
initial: {
|
|
15
|
-
opacity: 1,
|
|
16
|
-
['--r' as any]: '25%',
|
|
17
|
-
},
|
|
18
|
-
animate: {
|
|
19
|
-
opacity: 1,
|
|
20
|
-
['--r' as any]: '100%',
|
|
21
|
-
transition: {
|
|
22
|
-
duration: 0.5,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
exit: {
|
|
26
|
-
opacity: 0,
|
|
27
|
-
['--r' as any]: '100%',
|
|
28
|
-
transition: {
|
|
29
|
-
duration: 0.3,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
34
|
-
const [isCompleted, setIsCompleted] = useState(true);
|
|
35
|
-
const [isActive, setIsActive] = useState(false);
|
|
36
|
-
const [coordinates, setCoordinates] = useState({ x: 50, y: 50 });
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (isActive) {
|
|
40
|
-
// restart presence cycle to allow exit animation after mouse up
|
|
41
|
-
setIsCompleted(true);
|
|
42
|
-
setIsCompleted(false);
|
|
43
|
-
}
|
|
44
|
-
}, [isActive]);
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
const element = triggerRef?.current;
|
|
48
|
-
if (element) {
|
|
49
|
-
element.addEventListener('mousedown', handleMouseDown);
|
|
50
|
-
element.addEventListener('mouseup', handleMouseUp);
|
|
51
|
-
element.addEventListener('mouseleave', handleMouseLeave);
|
|
52
|
-
return () => {
|
|
53
|
-
element.removeEventListener('mousedown', handleMouseDown);
|
|
54
|
-
element.removeEventListener('mouseup', handleMouseUp);
|
|
55
|
-
element.removeEventListener('mouseleave', handleMouseLeave);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}, [triggerRef]);
|
|
59
|
-
|
|
60
|
-
const handleMouseDown = (e: MouseEvent) => {
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
62
|
-
// @ts-expect-error
|
|
63
|
-
const el = triggerRef?.current as Element & {
|
|
64
|
-
clientWidth: number;
|
|
65
|
-
clientHeight: number;
|
|
66
|
-
};
|
|
67
|
-
const rect = el.getBoundingClientRect();
|
|
68
|
-
setIsActive(true);
|
|
69
|
-
setCoordinates({
|
|
70
|
-
x: ((e.clientX - rect.left) / el.clientWidth) * 100,
|
|
71
|
-
y: ((e.clientY - rect.top) / el.clientHeight) * 100,
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
const handleMouseLeave = (_e: MouseEvent) => {
|
|
75
|
-
setIsActive(false);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const handleMouseUp = (_e: MouseEvent) => {
|
|
79
|
-
setIsActive(false);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Build the background as a function of state.
|
|
83
|
-
// color token mixed to a subtle alpha
|
|
84
|
-
const colorMix = `color-mix(in srgb, var(--state-color,_var(--color-${colorName})) 10%, transparent)`;
|
|
85
|
-
// const colorMix = `red`;
|
|
86
|
-
|
|
87
|
-
const style: React.CSSProperties & Record<string, any> = {
|
|
88
|
-
position: 'absolute',
|
|
89
|
-
inset: 0,
|
|
90
|
-
width: '100%',
|
|
91
|
-
height: '100%',
|
|
92
|
-
// supply CSS variables for gradient center and radius
|
|
93
|
-
['--x' as any]: coordinates.x + '%',
|
|
94
|
-
['--y' as any]: coordinates.y + '%',
|
|
95
|
-
['--r' as any]: '0%', // will be animated by motion
|
|
96
|
-
background: `radial-gradient(ellipse at var(--x) var(--y), ${colorMix} var(--r), transparent calc(var(--r) * 2))`,
|
|
97
|
-
pointerEvents: 'none',
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<AnimatePresence mode="wait">
|
|
102
|
-
{(isActive || (!isActive && !isCompleted)) && (
|
|
103
|
-
<motion.div
|
|
104
|
-
style={style}
|
|
105
|
-
variants={ripple}
|
|
106
|
-
initial="initial"
|
|
107
|
-
animate="animate"
|
|
108
|
-
exit="exit"
|
|
109
|
-
onAnimationComplete={() => setIsCompleted(true)}
|
|
110
|
-
/>
|
|
111
|
-
)}
|
|
112
|
-
</AnimatePresence>
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export default RippleEffect;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as RippleEffect } from './RippleEffect';
|