@envive-ai/react-toolkit-v3 0.3.8 → 0.3.9

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.
Files changed (203) hide show
  1. package/dist/AnimatedText/AnimatedText.cjs +1 -0
  2. package/dist/AnimatedText/AnimatedText.js +1 -0
  3. package/dist/CSSVariablesEditor/CssVariablesEditorComponent.d.cts +2 -2
  4. package/dist/CSSVariablesEditor/CssVariablesEditorComponent.d.ts +2 -2
  5. package/dist/CSSVariablesEditor/components/CSSVariablesEditor.cjs +1 -1
  6. package/dist/CSSVariablesEditor/components/CSSVariablesEditor.js +1 -1
  7. package/dist/Carousel/Carousel.d.cts +2 -2
  8. package/dist/Carousel/Carousel.d.ts +2 -2
  9. package/dist/Carousel/components/Container.cjs +1 -1
  10. package/dist/Carousel/components/Container.js +1 -1
  11. package/dist/ChatFooter/ChatFooter.d.cts +2 -2
  12. package/dist/ChatFooter/components/index.d.cts +3 -3
  13. package/dist/ChatFooter/components/index.d.ts +5 -5
  14. package/dist/ChatHeader/ChatHeader.d.cts +2 -2
  15. package/dist/ChatHeader/ChatHeader.d.ts +2 -2
  16. package/dist/ChatPreview/ChatPreview.cjs +13 -3
  17. package/dist/ChatPreview/ChatPreview.d.cts +2 -2
  18. package/dist/ChatPreview/ChatPreview.d.ts +2 -2
  19. package/dist/ChatPreview/ChatPreview.js +13 -3
  20. package/dist/ChatPreview/components/Message.cjs +1 -1
  21. package/dist/ChatPreview/components/Message.js +1 -1
  22. package/dist/ChatPreview/types/types.d.cts +5 -4
  23. package/dist/ChatPreview/types/types.d.ts +5 -4
  24. package/dist/ChatPreviewComparison/ChatPreviewComparison.cjs +13 -3
  25. package/dist/ChatPreviewComparison/ChatPreviewComparison.d.cts +2 -2
  26. package/dist/ChatPreviewComparison/ChatPreviewComparison.d.ts +2 -2
  27. package/dist/ChatPreviewComparison/ChatPreviewComparison.js +13 -3
  28. package/dist/ChatPreviewComparison/components/Message.cjs +1 -1
  29. package/dist/ChatPreviewComparison/components/Message.js +1 -1
  30. package/dist/ChatPreviewComparison/types/types.d.cts +4 -4
  31. package/dist/ChatPreviewComparison/types/types.d.ts +4 -4
  32. package/dist/ChatPreviewLoading/ChatPreviewLoading.cjs +1 -1
  33. package/dist/ChatPreviewLoading/ChatPreviewLoading.d.cts +2 -2
  34. package/dist/ChatPreviewLoading/ChatPreviewLoading.d.ts +2 -2
  35. package/dist/ChatPreviewLoading/ChatPreviewLoading.js +1 -1
  36. package/dist/Container/Container.d.cts +174 -174
  37. package/dist/Container/Container.d.ts +174 -174
  38. package/dist/DesignTokens/DesignTokensComponent.cjs +1 -1
  39. package/dist/DesignTokens/DesignTokensComponent.d.cts +2 -2
  40. package/dist/DesignTokens/DesignTokensComponent.d.ts +2 -2
  41. package/dist/DesignTokens/DesignTokensComponent.js +1 -1
  42. package/dist/DocumentRetrievalCard/DocumentRetrievalCard.d.ts +2 -2
  43. package/dist/FloatingButton/FloatingButton.d.cts +2 -2
  44. package/dist/FloatingButton/FloatingButton.d.ts +2 -2
  45. package/dist/FloatingChat/FloatingChat.cjs +4 -3
  46. package/dist/FloatingChat/FloatingChat.d.cts +2 -2
  47. package/dist/FloatingChat/FloatingChat.d.ts +2 -2
  48. package/dist/FloatingChat/FloatingChat.js +4 -3
  49. package/dist/FloatingChat/components/AgentMessage.cjs +9 -5
  50. package/dist/FloatingChat/components/AgentMessage.js +9 -5
  51. package/dist/FloatingChat/components/ChatMessages.cjs +1 -1
  52. package/dist/FloatingChat/components/ChatMessages.js +1 -1
  53. package/dist/FloatingChat/components/Layout.cjs +11 -11
  54. package/dist/FloatingChat/components/Layout.js +11 -11
  55. package/dist/FloatingChat/components/ModalSheet.cjs +1 -1
  56. package/dist/FloatingChat/components/ModalSheet.js +1 -1
  57. package/dist/FloatingChat/components/ReviewCardsCarousel.cjs +2 -1
  58. package/dist/FloatingChat/components/ReviewCardsCarousel.js +2 -1
  59. package/dist/FloatingChat/components/ScrollToBottomButton.cjs +1 -1
  60. package/dist/FloatingChat/components/ScrollToBottomButton.js +1 -1
  61. package/dist/Form/Form.cjs +1 -1
  62. package/dist/Form/Form.js +1 -1
  63. package/dist/Image/Image.d.cts +2 -2
  64. package/dist/Image/Image.d.ts +2 -2
  65. package/dist/ImageGallery/ImageGallery.d.cts +2 -2
  66. package/dist/ImageGallery/ImageGallery.d.ts +2 -2
  67. package/dist/ImageGallery/components/NormalLayout.cjs +1 -1
  68. package/dist/ImageGallery/components/NormalLayout.js +1 -1
  69. package/dist/MarkdownProcessor/MarkdownProcessor.cjs +1 -1
  70. package/dist/MarkdownProcessor/MarkdownProcessor.d.cts +2 -2
  71. package/dist/MarkdownProcessor/MarkdownProcessor.d.ts +2 -2
  72. package/dist/MarkdownProcessor/MarkdownProcessor.js +1 -1
  73. package/dist/Message/components/AgentContent.cjs +1 -1
  74. package/dist/Message/components/AgentContent.js +1 -1
  75. package/dist/ProductCard/ProductCard.cjs +9 -5
  76. package/dist/ProductCard/ProductCard.d.cts +2 -2
  77. package/dist/ProductCard/ProductCard.d.ts +2 -2
  78. package/dist/ProductCard/ProductCard.js +4 -1
  79. package/dist/ProductCard/components/Header.cjs +3 -3
  80. package/dist/ProductCard/components/Header.js +3 -3
  81. package/dist/PromptButton/PromptButton.d.cts +2 -2
  82. package/dist/PromptButton/PromptButton.d.ts +2 -2
  83. package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.cjs +3 -2
  84. package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.d.cts +2 -2
  85. package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.d.ts +2 -2
  86. package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.js +3 -2
  87. package/dist/PromptButtonCarouselWithImage/components/Layout.cjs +8 -3
  88. package/dist/PromptButtonCarouselWithImage/components/Layout.js +8 -3
  89. package/dist/PromptButtonCarouselWithImage/components/PromptButtonsCarousel.cjs +53 -3
  90. package/dist/PromptButtonCarouselWithImage/components/PromptButtonsCarousel.js +53 -3
  91. package/dist/PromptCarousel/PromptCarousel.cjs +70 -33
  92. package/dist/PromptCarousel/PromptCarousel.d.cts +2 -2
  93. package/dist/PromptCarousel/PromptCarousel.d.ts +2 -2
  94. package/dist/PromptCarousel/PromptCarousel.js +71 -34
  95. package/dist/PromptCarousel/hooks/index.cjs +2 -4
  96. package/dist/PromptCarousel/hooks/index.js +2 -4
  97. package/dist/PromptCarousel/hooks/useCoordinatedScrollAnimation.cjs +91 -0
  98. package/dist/PromptCarousel/hooks/useCoordinatedScrollAnimation.js +90 -0
  99. package/dist/PromptCarousel/hooks/useScrollSync.cjs +65 -0
  100. package/dist/PromptCarousel/hooks/useScrollSync.js +64 -0
  101. package/dist/ReviewCard/ReviewCard.cjs +1 -1
  102. package/dist/ReviewCard/ReviewCard.d.cts +2 -2
  103. package/dist/ReviewCard/ReviewCard.d.ts +2 -2
  104. package/dist/ReviewCard/ReviewCard.js +1 -1
  105. package/dist/ReviewCard/components/index.d.cts +6 -6
  106. package/dist/ReviewCard/components/index.d.ts +6 -6
  107. package/dist/SalesAgentProductCard/SalesAgentProductCard.d.cts +2 -2
  108. package/dist/SalesAgentProductCard/SalesAgentProductCard.d.ts +2 -2
  109. package/dist/SalesAgentProductCard/components/index.d.cts +8 -8
  110. package/dist/SalesAgentProductCard/components/index.d.ts +6 -6
  111. package/dist/SocialProof/SocialProof.d.cts +2 -2
  112. package/dist/SocialProof/SocialProof.d.ts +2 -2
  113. package/dist/SocialProof/components/Headline.cjs +1 -1
  114. package/dist/SocialProof/components/Headline.js +1 -1
  115. package/dist/SocialProof/components/LayoutSingle.cjs +1 -1
  116. package/dist/SocialProof/components/LayoutSingle.js +1 -1
  117. package/dist/Stack/Stack.d.cts +2 -2
  118. package/dist/Stack/Stack.d.ts +2 -2
  119. package/dist/Stack/hooks/useFormatStackChildren.cjs +1 -1
  120. package/dist/Stack/hooks/useFormatStackChildren.js +1 -1
  121. package/dist/Title/components/Image.cjs +1 -1
  122. package/dist/Title/components/Image.js +1 -1
  123. package/dist/TitledPromptCarousel/TitledPromptCarousel.d.cts +2 -2
  124. package/dist/TitledPromptCarousel/TitledPromptCarousel.d.ts +2 -2
  125. package/dist/TypingAnimation/TypingAnimation.cjs +2 -2
  126. package/dist/TypingAnimation/TypingAnimation.d.ts +2 -2
  127. package/dist/TypingAnimation/TypingAnimation.js +2 -2
  128. package/dist/Typography/Typography.d.cts +4 -4
  129. package/dist/Typography/Typography.d.ts +4 -4
  130. package/dist/WidgetTextField/WidgetTextField.cjs +11 -6
  131. package/dist/WidgetTextField/WidgetTextField.d.cts +3 -2
  132. package/dist/WidgetTextField/WidgetTextField.d.ts +3 -2
  133. package/dist/WidgetTextField/WidgetTextField.js +7 -2
  134. package/dist/WidgetTextField/components/FakeTextInput.cjs +2 -2
  135. package/dist/WidgetTextField/components/FakeTextInput.js +2 -2
  136. package/dist/WidgetTextField/components/Icon.cjs +10 -9
  137. package/dist/WidgetTextField/components/Icon.js +10 -9
  138. package/dist/WidgetTextField/components/Skeleton.cjs +1 -1
  139. package/dist/WidgetTextField/components/Skeleton.js +1 -1
  140. package/dist/WidgetTextField/types/types.d.cts +3 -0
  141. package/dist/WidgetTextField/types/types.d.ts +3 -0
  142. package/dist/WidgetWrapper/WidgetWrapper.d.cts +2 -2
  143. package/dist/WidgetWrapper/WidgetWrapper.d.ts +2 -2
  144. package/dist/WidgetWrapperWithTitle/WidgetWrapperWithTitle.d.cts +2 -2
  145. package/dist/WidgetWrapperWithTitle/WidgetWrapperWithTitle.d.ts +2 -2
  146. package/dist/styles.css +1 -1
  147. package/dist/utils/CustomIcon.cjs +1 -1
  148. package/dist/utils/CustomIcon.js +1 -1
  149. package/dist/utils/useDragToScroll.cjs +68 -0
  150. package/dist/utils/useDragToScroll.js +67 -0
  151. package/package.json +1 -1
  152. package/src/components/AnimatedText/AnimatedText.tsx +2 -0
  153. package/src/components/ChatPreview/ChatPreview.tsx +20 -3
  154. package/src/components/ChatPreview/types/types.ts +5 -4
  155. package/src/components/ChatPreviewComparison/ChatPreviewComparison.tsx +20 -3
  156. package/src/components/ChatPreviewComparison/types/types.ts +4 -4
  157. package/src/components/FloatingChat/FloatingChat.tsx +3 -2
  158. package/src/components/FloatingChat/components/AgentMessage.tsx +1 -0
  159. package/src/components/FloatingChat/components/Layout.tsx +7 -2
  160. package/src/components/FloatingChat/components/ReviewCardsCarousel.tsx +3 -0
  161. package/src/components/ProductCard/ProductCard.tsx +12 -1
  162. package/src/components/ProductCard/components/Header.tsx +10 -8
  163. package/src/components/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.tsx +6 -3
  164. package/src/components/PromptButtonCarouselWithImage/components/Layout.tsx +13 -4
  165. package/src/components/PromptButtonCarouselWithImage/components/PromptButtonsCarousel.tsx +63 -20
  166. package/src/components/PromptCarousel/PromptCarousel.tsx +88 -51
  167. package/src/components/PromptCarousel/hooks/index.ts +2 -4
  168. package/src/components/PromptCarousel/hooks/useCoordinatedScrollAnimation.ts +115 -0
  169. package/src/components/PromptCarousel/hooks/useHorizontalScrollAnimation.ts +71 -78
  170. package/src/components/PromptCarousel/hooks/useScrollSync.ts +83 -0
  171. package/src/components/WidgetTextField/WidgetTextField.tsx +9 -1
  172. package/src/components/WidgetTextField/components/FakeTextInput.tsx +6 -2
  173. package/src/components/WidgetTextField/components/Icon.tsx +43 -9
  174. package/src/components/WidgetTextField/types/types.ts +3 -0
  175. package/src/components/utils/useDragToScroll.ts +83 -0
  176. package/dist/PromptCarousel/components/BlockScrollContainer.cjs +0 -23
  177. package/dist/PromptCarousel/components/BlockScrollContainer.js +0 -21
  178. package/dist/PromptCarousel/components/ButtonContainerRow.cjs +0 -34
  179. package/dist/PromptCarousel/components/ButtonContainerRow.js +0 -32
  180. package/dist/PromptCarousel/components/CarouselContentWithBlockScroll.cjs +0 -45
  181. package/dist/PromptCarousel/components/CarouselContentWithBlockScroll.js +0 -44
  182. package/dist/PromptCarousel/components/CarouselContentWithRowScroll.cjs +0 -33
  183. package/dist/PromptCarousel/components/CarouselContentWithRowScroll.js +0 -32
  184. package/dist/PromptCarousel/components/index.cjs +0 -13
  185. package/dist/PromptCarousel/components/index.js +0 -13
  186. package/dist/PromptCarousel/hooks/useButtonScrollPosition.cjs +0 -79
  187. package/dist/PromptCarousel/hooks/useButtonScrollPosition.js +0 -78
  188. package/dist/PromptCarousel/hooks/useCarouselAnimation.cjs +0 -23
  189. package/dist/PromptCarousel/hooks/useCarouselAnimation.js +0 -22
  190. package/dist/PromptCarousel/hooks/useCarouselRefs.cjs +0 -20
  191. package/dist/PromptCarousel/hooks/useCarouselRefs.js +0 -19
  192. package/dist/PromptCarousel/hooks/useGetScrollProperties.cjs +0 -18
  193. package/dist/PromptCarousel/hooks/useGetScrollProperties.js +0 -17
  194. package/dist/PromptCarousel/hooks/useHorizontalScrollAnimation.cjs +0 -78
  195. package/dist/PromptCarousel/hooks/useHorizontalScrollAnimation.js +0 -77
  196. package/src/components/PromptCarousel/components/BlockScrollContainer.tsx +0 -34
  197. package/src/components/PromptCarousel/components/ButtonContainerRow.tsx +0 -46
  198. package/src/components/PromptCarousel/components/CarouselContentWithBlockScroll.tsx +0 -83
  199. package/src/components/PromptCarousel/components/CarouselContentWithRowScroll.tsx +0 -71
  200. package/src/components/PromptCarousel/components/index.ts +0 -9
  201. package/src/components/PromptCarousel/hooks/useButtonScrollPosition.ts +0 -128
  202. package/src/components/PromptCarousel/hooks/useCarouselAnimation.ts +0 -47
  203. package/src/components/PromptCarousel/hooks/useCarouselRefs.ts +0 -27
@@ -1,46 +0,0 @@
1
- import classNames from 'classnames';
2
- import { Stack } from '../../Stack';
3
- import { useGetScrollProperties } from '../hooks/useGetScrollProperties';
4
-
5
- export interface ButtonContainerRowProps {
6
- children: React.ReactNode;
7
- scrollRef?: React.RefObject<HTMLDivElement>;
8
- stackRef?: React.RefObject<HTMLDivElement>;
9
- className?: string;
10
- 'aria-label'?: string;
11
- 'aria-labelledby'?: string;
12
- }
13
-
14
- export const ButtonContainerRow = ({
15
- children,
16
- scrollRef,
17
- stackRef,
18
- className,
19
- 'aria-label': ariaLabel,
20
- 'aria-labelledby': ariaLabelledBy,
21
- }: ButtonContainerRowProps) => {
22
- const { scrollStyle, scrollClasses } = useGetScrollProperties();
23
-
24
- return (
25
- <div
26
- ref={scrollRef}
27
- className={classNames(...scrollClasses, className)}
28
- style={scrollStyle}
29
- role="group"
30
- aria-label={ariaLabel}
31
- aria-labelledby={ariaLabelledBy}
32
- tabIndex={0}
33
- >
34
- <div ref={stackRef}>
35
- <Stack
36
- direction="row"
37
- align="center"
38
- gap="2"
39
- className="envive-tw-h-full envive-tw-w-max envive-tw-whitespace-nowrap"
40
- >
41
- {children}
42
- </Stack>
43
- </div>
44
- </div>
45
- );
46
- };
@@ -1,83 +0,0 @@
1
- import { Stack } from '../../Stack';
2
- import { BlockScrollContainer } from './BlockScrollContainer';
3
- import { RepetitionNumberSuffix } from '../types/types';
4
-
5
- export interface CarouselContentWithBlockScrollProps {
6
- visibleButtonsFirstRow: string[];
7
- visibleButtonsSecondRow: string[];
8
- shouldShowTwoRows: boolean;
9
- renderButton: (
10
- text: string,
11
- index: number,
12
- repetitionNumber?: `${RepetitionNumberSuffix}`,
13
- ) => React.ReactNode;
14
- isAnimated: boolean;
15
- isAnimationStopped: boolean;
16
- blockScrollRef: React.RefObject<HTMLDivElement>;
17
- blockFirstRowStackRef: React.RefObject<HTMLDivElement>;
18
- }
19
-
20
- export const CarouselContentWithBlockScroll = ({
21
- visibleButtonsFirstRow,
22
- visibleButtonsSecondRow,
23
- shouldShowTwoRows,
24
- renderButton,
25
- isAnimated,
26
- isAnimationStopped,
27
- blockScrollRef,
28
- blockFirstRowStackRef,
29
- }: CarouselContentWithBlockScrollProps) => {
30
- const showRepetitions = isAnimated && isAnimationStopped;
31
-
32
- const renderRowButtons = (buttons: string[], startIndex: number) => (
33
- <>
34
- {buttons.map((text, index) => renderButton(text, startIndex + index))}
35
- {showRepetitions &&
36
- buttons.map((text, index) =>
37
- renderButton(text, startIndex + index, RepetitionNumberSuffix.TWO),
38
- )}
39
- {showRepetitions &&
40
- buttons.map((text, index) =>
41
- renderButton(text, startIndex + index, RepetitionNumberSuffix.THREE),
42
- )}
43
- </>
44
- );
45
-
46
- return (
47
- <BlockScrollContainer
48
- scrollRef={blockScrollRef}
49
- aria-label="Scrollable prompt buttons"
50
- >
51
- <Stack
52
- direction="column"
53
- gap="2"
54
- className="envive-tw-w-max"
55
- >
56
- <div
57
- ref={blockFirstRowStackRef}
58
- role={shouldShowTwoRows ? 'group' : undefined}
59
- aria-label={shouldShowTwoRows ? 'First row of prompt buttons' : undefined}
60
- >
61
- <Stack
62
- direction="row"
63
- gap="2"
64
- className="envive-tw-whitespace-nowrap"
65
- >
66
- {renderRowButtons(visibleButtonsFirstRow, 0)}
67
- </Stack>
68
- </div>
69
-
70
- {shouldShowTwoRows && visibleButtonsSecondRow.length > 0 && (
71
- <Stack
72
- direction="row"
73
- gap="2"
74
- className="envive-tw-whitespace-nowrap"
75
- aria-label="Second row of prompt buttons"
76
- >
77
- {renderRowButtons(visibleButtonsSecondRow, visibleButtonsFirstRow.length)}
78
- </Stack>
79
- )}
80
- </Stack>
81
- </BlockScrollContainer>
82
- );
83
- };
@@ -1,71 +0,0 @@
1
- import { Stack } from '../../Stack';
2
- import { ButtonContainerRow } from './ButtonContainerRow';
3
- import { RepetitionNumberSuffix } from '../types/types';
4
-
5
- export interface CarouselContentWithRowScrollProps {
6
- visibleButtonsFirstRow: string[];
7
- visibleButtonsSecondRow: string[];
8
- shouldShowTwoRows: boolean;
9
- renderButton: (
10
- text: string,
11
- index: number,
12
- repetitionNumber?: `${RepetitionNumberSuffix}`,
13
- ) => React.ReactNode;
14
- isAnimated: boolean;
15
- isAnimationStopped: boolean;
16
- firstRowScrollRef: React.RefObject<HTMLDivElement>;
17
- firstRowStackRef: React.RefObject<HTMLDivElement>;
18
- secondRowScrollRef: React.RefObject<HTMLDivElement>;
19
- }
20
-
21
- export const CarouselContentWithRowScroll = ({
22
- visibleButtonsFirstRow,
23
- visibleButtonsSecondRow,
24
- shouldShowTwoRows,
25
- isAnimated,
26
- isAnimationStopped,
27
- renderButton,
28
- firstRowScrollRef,
29
- firstRowStackRef,
30
- secondRowScrollRef,
31
- }: CarouselContentWithRowScrollProps) => {
32
- const showRepetitions = isAnimated && !isAnimationStopped;
33
-
34
- const renderRowButtons = (buttons: string[], startIndex: number) => (
35
- <>
36
- {buttons.map((text, index) => renderButton(text, startIndex + index))}
37
- {showRepetitions &&
38
- buttons.map((text, index) =>
39
- renderButton(text, startIndex + index, RepetitionNumberSuffix.TWO),
40
- )}
41
- {showRepetitions &&
42
- buttons.map((text, index) =>
43
- renderButton(text, startIndex + index, RepetitionNumberSuffix.THREE),
44
- )}
45
- </>
46
- );
47
-
48
- return (
49
- <Stack
50
- direction="column"
51
- gap="2"
52
- >
53
- <ButtonContainerRow
54
- scrollRef={firstRowScrollRef}
55
- stackRef={firstRowStackRef}
56
- aria-label={shouldShowTwoRows ? 'First row of prompt buttons' : undefined}
57
- >
58
- {renderRowButtons(visibleButtonsFirstRow, 0)}
59
- </ButtonContainerRow>
60
-
61
- {shouldShowTwoRows && (
62
- <ButtonContainerRow
63
- scrollRef={secondRowScrollRef}
64
- aria-label="Second row of prompt buttons"
65
- >
66
- {renderRowButtons(visibleButtonsSecondRow, visibleButtonsFirstRow.length)}
67
- </ButtonContainerRow>
68
- )}
69
- </Stack>
70
- );
71
- };
@@ -1,9 +0,0 @@
1
- import { CarouselContentWithRowScroll } from './CarouselContentWithRowScroll';
2
- import { CarouselContentWithBlockScroll } from './CarouselContentWithBlockScroll';
3
- import { ButtonContainerRow } from './ButtonContainerRow';
4
-
5
- export const PromptCarouselComponents = {
6
- CarouselContentWithRowScroll,
7
- CarouselContentWithBlockScroll,
8
- ButtonContainerRow,
9
- };
@@ -1,128 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import { RepetitionNumberSuffix } from '../types/types';
3
-
4
- const getElementId = (element: Element | null): string | null => {
5
- if (!element) return null;
6
- return element.id?.trim() || null;
7
- };
8
-
9
- export function useButtonScrollPosition(
10
- firstRowScrollRef: React.RefObject<HTMLDivElement>,
11
- blockScrollRef: React.RefObject<HTMLDivElement>,
12
- shouldUseRowScroll: boolean,
13
- ) {
14
- const savedButtonIdRef = useRef<string | null>(null);
15
- const savedButtonPositionRef = useRef<number | null>(null);
16
-
17
- const captureButtonUnderMouse = useCallback(
18
- (mouseX: number, mouseY: number) => {
19
- const container = firstRowScrollRef.current;
20
- if (!container) return;
21
-
22
- const containerRect = container.getBoundingClientRect();
23
-
24
- const elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
25
- const targetButtonId = getElementId(elementUnderMouse);
26
-
27
- let closestButton: HTMLElement | null = null;
28
-
29
- if (targetButtonId) {
30
- const buttonById = document.querySelector(`#${CSS.escape(targetButtonId)}`) as HTMLElement;
31
- if (
32
- buttonById &&
33
- (elementUnderMouse === buttonById || buttonById.contains(elementUnderMouse as Node))
34
- ) {
35
- closestButton = buttonById;
36
- }
37
- }
38
-
39
- if (!closestButton) {
40
- const buttons = Array.from(container.querySelectorAll('button')) as HTMLElement[];
41
- let closestDistance = Infinity;
42
-
43
- for (const button of buttons) {
44
- const buttonRect = button.getBoundingClientRect();
45
-
46
- if (
47
- mouseX >= buttonRect.left &&
48
- mouseX <= buttonRect.right &&
49
- mouseY >= buttonRect.top &&
50
- mouseY <= buttonRect.bottom
51
- ) {
52
- closestButton = button;
53
- break;
54
- }
55
-
56
- const buttonCenterX = buttonRect.left + buttonRect.width / 2;
57
- const buttonCenterY = buttonRect.top + buttonRect.height / 2;
58
- const distance = Math.sqrt((mouseX - buttonCenterX) ** 2 + (mouseY - buttonCenterY) ** 2);
59
-
60
- if (distance < closestDistance) {
61
- closestDistance = distance;
62
- closestButton = button;
63
- }
64
- }
65
- }
66
-
67
- if (closestButton) {
68
- const id = getElementId(closestButton);
69
- if (id) {
70
- savedButtonIdRef.current = id;
71
- const buttonRect = closestButton.getBoundingClientRect();
72
- savedButtonPositionRef.current = buttonRect.left - containerRect.left;
73
- }
74
- }
75
- },
76
- [firstRowScrollRef],
77
- );
78
-
79
- useEffect(() => {
80
- if (
81
- shouldUseRowScroll ||
82
- !blockScrollRef.current ||
83
- !savedButtonIdRef.current ||
84
- savedButtonPositionRef.current === null
85
- ) {
86
- return;
87
- }
88
-
89
- const container = blockScrollRef.current;
90
- const targetId = savedButtonIdRef.current.trim();
91
- const targetPosition = savedButtonPositionRef.current;
92
-
93
- const getScrollId = (id: string) => {
94
- if (id.endsWith(RepetitionNumberSuffix.TWO)) {
95
- return id;
96
- }
97
-
98
- if (id.endsWith(RepetitionNumberSuffix.THREE)) {
99
- return `${id.slice(0, -2)}${RepetitionNumberSuffix.TWO}`;
100
- }
101
-
102
- return `${id}${RepetitionNumberSuffix.TWO}`;
103
- };
104
-
105
- const applyScroll = () => {
106
- const finalId = getScrollId(targetId);
107
- const targetButton = container.querySelector(`#${CSS.escape(`${finalId}`)}`) as HTMLElement;
108
- const scrollableContent = container.firstElementChild as HTMLElement;
109
-
110
- if (!targetButton || !scrollableContent) return;
111
-
112
- const contentRect = scrollableContent.getBoundingClientRect();
113
- const buttonRect = targetButton.getBoundingClientRect();
114
- const buttonPositionInContent = buttonRect.left - contentRect.left + container.scrollLeft;
115
- const newScrollLeft = buttonPositionInContent - targetPosition;
116
-
117
- container.scrollLeft = Math.max(0, newScrollLeft);
118
- };
119
-
120
- requestAnimationFrame(() => {
121
- requestAnimationFrame(() => {
122
- requestAnimationFrame(applyScroll);
123
- });
124
- });
125
- }, [shouldUseRowScroll, blockScrollRef]);
126
-
127
- return { captureButtonUnderMouse };
128
- }
@@ -1,47 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { AnimationSpeed } from '../types/types';
3
- import { useButtonScrollPosition } from './useButtonScrollPosition';
4
- import { useHorizontalScrollAnimation } from './useHorizontalScrollAnimation';
5
-
6
- interface UseCarouselAnimationProps {
7
- firstRowScrollRef: React.RefObject<HTMLDivElement>;
8
- blockScrollRef: React.RefObject<HTMLDivElement>;
9
- scrollRefs: React.RefObject<HTMLDivElement>[];
10
- animationSpeed: `${AnimationSpeed}`;
11
- isAnimated: boolean;
12
- }
13
-
14
- export const useCarouselAnimation = ({
15
- firstRowScrollRef,
16
- blockScrollRef,
17
- scrollRefs,
18
- animationSpeed,
19
- isAnimated,
20
- }: UseCarouselAnimationProps) => {
21
- const [isAnimationStopped, setIsAnimationStopped] = useState(false);
22
- const shouldUseRowScroll = isAnimated && !isAnimationStopped;
23
-
24
- const { captureButtonUnderMouse } = useButtonScrollPosition(
25
- firstRowScrollRef,
26
- blockScrollRef,
27
- shouldUseRowScroll,
28
- );
29
-
30
- const onStopAll = useCallback(
31
- (mouseX?: number, mouseY?: number) => {
32
- if (mouseX !== undefined && mouseY !== undefined) {
33
- captureButtonUnderMouse(mouseX, mouseY);
34
- }
35
- setIsAnimationStopped(true);
36
- },
37
- [captureButtonUnderMouse],
38
- );
39
-
40
- useHorizontalScrollAnimation(
41
- scrollRefs,
42
- onStopAll,
43
- shouldUseRowScroll ? animationSpeed : AnimationSpeed.NONE,
44
- );
45
-
46
- return { isAnimationStopped, shouldUseRowScroll };
47
- };
@@ -1,27 +0,0 @@
1
- import { useMemo, useRef } from 'react';
2
-
3
- interface UseCarouselRefsProps {
4
- shouldShowTwoRows: boolean;
5
- }
6
-
7
- export const useCarouselRefs = ({ shouldShowTwoRows }: UseCarouselRefsProps) => {
8
- const firstRowScrollRef = useRef<HTMLDivElement>(null);
9
- const firstRowStackRef = useRef<HTMLDivElement>(null);
10
- const secondRowScrollRef = useRef<HTMLDivElement>(null);
11
- const blockScrollRef = useRef<HTMLDivElement>(null);
12
- const blockFirstRowStackRef = useRef<HTMLDivElement>(null);
13
-
14
- const scrollRefs = useMemo(
15
- () => (shouldShowTwoRows ? [firstRowScrollRef, secondRowScrollRef] : [firstRowScrollRef]),
16
- [shouldShowTwoRows],
17
- );
18
-
19
- return {
20
- firstRowScrollRef,
21
- firstRowStackRef,
22
- secondRowScrollRef,
23
- blockScrollRef,
24
- blockFirstRowStackRef,
25
- scrollRefs,
26
- };
27
- };