@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.
- package/dist/AnimatedText/AnimatedText.cjs +1 -0
- package/dist/AnimatedText/AnimatedText.js +1 -0
- package/dist/CSSVariablesEditor/CssVariablesEditorComponent.d.cts +2 -2
- package/dist/CSSVariablesEditor/CssVariablesEditorComponent.d.ts +2 -2
- package/dist/CSSVariablesEditor/components/CSSVariablesEditor.cjs +1 -1
- package/dist/CSSVariablesEditor/components/CSSVariablesEditor.js +1 -1
- package/dist/Carousel/Carousel.d.cts +2 -2
- package/dist/Carousel/Carousel.d.ts +2 -2
- package/dist/Carousel/components/Container.cjs +1 -1
- package/dist/Carousel/components/Container.js +1 -1
- package/dist/ChatFooter/ChatFooter.d.cts +2 -2
- package/dist/ChatFooter/components/index.d.cts +3 -3
- package/dist/ChatFooter/components/index.d.ts +5 -5
- package/dist/ChatHeader/ChatHeader.d.cts +2 -2
- package/dist/ChatHeader/ChatHeader.d.ts +2 -2
- package/dist/ChatPreview/ChatPreview.cjs +13 -3
- package/dist/ChatPreview/ChatPreview.d.cts +2 -2
- package/dist/ChatPreview/ChatPreview.d.ts +2 -2
- package/dist/ChatPreview/ChatPreview.js +13 -3
- package/dist/ChatPreview/components/Message.cjs +1 -1
- package/dist/ChatPreview/components/Message.js +1 -1
- package/dist/ChatPreview/types/types.d.cts +5 -4
- package/dist/ChatPreview/types/types.d.ts +5 -4
- package/dist/ChatPreviewComparison/ChatPreviewComparison.cjs +13 -3
- package/dist/ChatPreviewComparison/ChatPreviewComparison.d.cts +2 -2
- package/dist/ChatPreviewComparison/ChatPreviewComparison.d.ts +2 -2
- package/dist/ChatPreviewComparison/ChatPreviewComparison.js +13 -3
- package/dist/ChatPreviewComparison/components/Message.cjs +1 -1
- package/dist/ChatPreviewComparison/components/Message.js +1 -1
- package/dist/ChatPreviewComparison/types/types.d.cts +4 -4
- package/dist/ChatPreviewComparison/types/types.d.ts +4 -4
- package/dist/ChatPreviewLoading/ChatPreviewLoading.cjs +1 -1
- package/dist/ChatPreviewLoading/ChatPreviewLoading.d.cts +2 -2
- package/dist/ChatPreviewLoading/ChatPreviewLoading.d.ts +2 -2
- package/dist/ChatPreviewLoading/ChatPreviewLoading.js +1 -1
- package/dist/Container/Container.d.cts +174 -174
- package/dist/Container/Container.d.ts +174 -174
- package/dist/DesignTokens/DesignTokensComponent.cjs +1 -1
- package/dist/DesignTokens/DesignTokensComponent.d.cts +2 -2
- package/dist/DesignTokens/DesignTokensComponent.d.ts +2 -2
- package/dist/DesignTokens/DesignTokensComponent.js +1 -1
- package/dist/DocumentRetrievalCard/DocumentRetrievalCard.d.ts +2 -2
- package/dist/FloatingButton/FloatingButton.d.cts +2 -2
- package/dist/FloatingButton/FloatingButton.d.ts +2 -2
- package/dist/FloatingChat/FloatingChat.cjs +4 -3
- package/dist/FloatingChat/FloatingChat.d.cts +2 -2
- package/dist/FloatingChat/FloatingChat.d.ts +2 -2
- package/dist/FloatingChat/FloatingChat.js +4 -3
- package/dist/FloatingChat/components/AgentMessage.cjs +9 -5
- package/dist/FloatingChat/components/AgentMessage.js +9 -5
- package/dist/FloatingChat/components/ChatMessages.cjs +1 -1
- package/dist/FloatingChat/components/ChatMessages.js +1 -1
- package/dist/FloatingChat/components/Layout.cjs +11 -11
- package/dist/FloatingChat/components/Layout.js +11 -11
- package/dist/FloatingChat/components/ModalSheet.cjs +1 -1
- package/dist/FloatingChat/components/ModalSheet.js +1 -1
- package/dist/FloatingChat/components/ReviewCardsCarousel.cjs +2 -1
- package/dist/FloatingChat/components/ReviewCardsCarousel.js +2 -1
- package/dist/FloatingChat/components/ScrollToBottomButton.cjs +1 -1
- package/dist/FloatingChat/components/ScrollToBottomButton.js +1 -1
- package/dist/Form/Form.cjs +1 -1
- package/dist/Form/Form.js +1 -1
- package/dist/Image/Image.d.cts +2 -2
- package/dist/Image/Image.d.ts +2 -2
- package/dist/ImageGallery/ImageGallery.d.cts +2 -2
- package/dist/ImageGallery/ImageGallery.d.ts +2 -2
- package/dist/ImageGallery/components/NormalLayout.cjs +1 -1
- package/dist/ImageGallery/components/NormalLayout.js +1 -1
- package/dist/MarkdownProcessor/MarkdownProcessor.cjs +1 -1
- package/dist/MarkdownProcessor/MarkdownProcessor.d.cts +2 -2
- package/dist/MarkdownProcessor/MarkdownProcessor.d.ts +2 -2
- package/dist/MarkdownProcessor/MarkdownProcessor.js +1 -1
- package/dist/Message/components/AgentContent.cjs +1 -1
- package/dist/Message/components/AgentContent.js +1 -1
- package/dist/ProductCard/ProductCard.cjs +9 -5
- package/dist/ProductCard/ProductCard.d.cts +2 -2
- package/dist/ProductCard/ProductCard.d.ts +2 -2
- package/dist/ProductCard/ProductCard.js +4 -1
- package/dist/ProductCard/components/Header.cjs +3 -3
- package/dist/ProductCard/components/Header.js +3 -3
- package/dist/PromptButton/PromptButton.d.cts +2 -2
- package/dist/PromptButton/PromptButton.d.ts +2 -2
- package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.cjs +3 -2
- package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.d.cts +2 -2
- package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.d.ts +2 -2
- package/dist/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.js +3 -2
- package/dist/PromptButtonCarouselWithImage/components/Layout.cjs +8 -3
- package/dist/PromptButtonCarouselWithImage/components/Layout.js +8 -3
- package/dist/PromptButtonCarouselWithImage/components/PromptButtonsCarousel.cjs +53 -3
- package/dist/PromptButtonCarouselWithImage/components/PromptButtonsCarousel.js +53 -3
- package/dist/PromptCarousel/PromptCarousel.cjs +70 -33
- package/dist/PromptCarousel/PromptCarousel.d.cts +2 -2
- package/dist/PromptCarousel/PromptCarousel.d.ts +2 -2
- package/dist/PromptCarousel/PromptCarousel.js +71 -34
- package/dist/PromptCarousel/hooks/index.cjs +2 -4
- package/dist/PromptCarousel/hooks/index.js +2 -4
- package/dist/PromptCarousel/hooks/useCoordinatedScrollAnimation.cjs +91 -0
- package/dist/PromptCarousel/hooks/useCoordinatedScrollAnimation.js +90 -0
- package/dist/PromptCarousel/hooks/useScrollSync.cjs +65 -0
- package/dist/PromptCarousel/hooks/useScrollSync.js +64 -0
- package/dist/ReviewCard/ReviewCard.cjs +1 -1
- package/dist/ReviewCard/ReviewCard.d.cts +2 -2
- package/dist/ReviewCard/ReviewCard.d.ts +2 -2
- package/dist/ReviewCard/ReviewCard.js +1 -1
- package/dist/ReviewCard/components/index.d.cts +6 -6
- package/dist/ReviewCard/components/index.d.ts +6 -6
- package/dist/SalesAgentProductCard/SalesAgentProductCard.d.cts +2 -2
- package/dist/SalesAgentProductCard/SalesAgentProductCard.d.ts +2 -2
- package/dist/SalesAgentProductCard/components/index.d.cts +8 -8
- package/dist/SalesAgentProductCard/components/index.d.ts +6 -6
- package/dist/SocialProof/SocialProof.d.cts +2 -2
- package/dist/SocialProof/SocialProof.d.ts +2 -2
- package/dist/SocialProof/components/Headline.cjs +1 -1
- package/dist/SocialProof/components/Headline.js +1 -1
- package/dist/SocialProof/components/LayoutSingle.cjs +1 -1
- package/dist/SocialProof/components/LayoutSingle.js +1 -1
- package/dist/Stack/Stack.d.cts +2 -2
- package/dist/Stack/Stack.d.ts +2 -2
- package/dist/Stack/hooks/useFormatStackChildren.cjs +1 -1
- package/dist/Stack/hooks/useFormatStackChildren.js +1 -1
- package/dist/Title/components/Image.cjs +1 -1
- package/dist/Title/components/Image.js +1 -1
- package/dist/TitledPromptCarousel/TitledPromptCarousel.d.cts +2 -2
- package/dist/TitledPromptCarousel/TitledPromptCarousel.d.ts +2 -2
- package/dist/TypingAnimation/TypingAnimation.cjs +2 -2
- package/dist/TypingAnimation/TypingAnimation.d.ts +2 -2
- package/dist/TypingAnimation/TypingAnimation.js +2 -2
- package/dist/Typography/Typography.d.cts +4 -4
- package/dist/Typography/Typography.d.ts +4 -4
- package/dist/WidgetTextField/WidgetTextField.cjs +11 -6
- package/dist/WidgetTextField/WidgetTextField.d.cts +3 -2
- package/dist/WidgetTextField/WidgetTextField.d.ts +3 -2
- package/dist/WidgetTextField/WidgetTextField.js +7 -2
- package/dist/WidgetTextField/components/FakeTextInput.cjs +2 -2
- package/dist/WidgetTextField/components/FakeTextInput.js +2 -2
- package/dist/WidgetTextField/components/Icon.cjs +10 -9
- package/dist/WidgetTextField/components/Icon.js +10 -9
- package/dist/WidgetTextField/components/Skeleton.cjs +1 -1
- package/dist/WidgetTextField/components/Skeleton.js +1 -1
- package/dist/WidgetTextField/types/types.d.cts +3 -0
- package/dist/WidgetTextField/types/types.d.ts +3 -0
- package/dist/WidgetWrapper/WidgetWrapper.d.cts +2 -2
- package/dist/WidgetWrapper/WidgetWrapper.d.ts +2 -2
- package/dist/WidgetWrapperWithTitle/WidgetWrapperWithTitle.d.cts +2 -2
- package/dist/WidgetWrapperWithTitle/WidgetWrapperWithTitle.d.ts +2 -2
- package/dist/styles.css +1 -1
- package/dist/utils/CustomIcon.cjs +1 -1
- package/dist/utils/CustomIcon.js +1 -1
- package/dist/utils/useDragToScroll.cjs +68 -0
- package/dist/utils/useDragToScroll.js +67 -0
- package/package.json +1 -1
- package/src/components/AnimatedText/AnimatedText.tsx +2 -0
- package/src/components/ChatPreview/ChatPreview.tsx +20 -3
- package/src/components/ChatPreview/types/types.ts +5 -4
- package/src/components/ChatPreviewComparison/ChatPreviewComparison.tsx +20 -3
- package/src/components/ChatPreviewComparison/types/types.ts +4 -4
- package/src/components/FloatingChat/FloatingChat.tsx +3 -2
- package/src/components/FloatingChat/components/AgentMessage.tsx +1 -0
- package/src/components/FloatingChat/components/Layout.tsx +7 -2
- package/src/components/FloatingChat/components/ReviewCardsCarousel.tsx +3 -0
- package/src/components/ProductCard/ProductCard.tsx +12 -1
- package/src/components/ProductCard/components/Header.tsx +10 -8
- package/src/components/PromptButtonCarouselWithImage/PromptButtonCarouselWithImage.tsx +6 -3
- package/src/components/PromptButtonCarouselWithImage/components/Layout.tsx +13 -4
- package/src/components/PromptButtonCarouselWithImage/components/PromptButtonsCarousel.tsx +63 -20
- package/src/components/PromptCarousel/PromptCarousel.tsx +88 -51
- package/src/components/PromptCarousel/hooks/index.ts +2 -4
- package/src/components/PromptCarousel/hooks/useCoordinatedScrollAnimation.ts +115 -0
- package/src/components/PromptCarousel/hooks/useHorizontalScrollAnimation.ts +71 -78
- package/src/components/PromptCarousel/hooks/useScrollSync.ts +83 -0
- package/src/components/WidgetTextField/WidgetTextField.tsx +9 -1
- package/src/components/WidgetTextField/components/FakeTextInput.tsx +6 -2
- package/src/components/WidgetTextField/components/Icon.tsx +43 -9
- package/src/components/WidgetTextField/types/types.ts +3 -0
- package/src/components/utils/useDragToScroll.ts +83 -0
- package/dist/PromptCarousel/components/BlockScrollContainer.cjs +0 -23
- package/dist/PromptCarousel/components/BlockScrollContainer.js +0 -21
- package/dist/PromptCarousel/components/ButtonContainerRow.cjs +0 -34
- package/dist/PromptCarousel/components/ButtonContainerRow.js +0 -32
- package/dist/PromptCarousel/components/CarouselContentWithBlockScroll.cjs +0 -45
- package/dist/PromptCarousel/components/CarouselContentWithBlockScroll.js +0 -44
- package/dist/PromptCarousel/components/CarouselContentWithRowScroll.cjs +0 -33
- package/dist/PromptCarousel/components/CarouselContentWithRowScroll.js +0 -32
- package/dist/PromptCarousel/components/index.cjs +0 -13
- package/dist/PromptCarousel/components/index.js +0 -13
- package/dist/PromptCarousel/hooks/useButtonScrollPosition.cjs +0 -79
- package/dist/PromptCarousel/hooks/useButtonScrollPosition.js +0 -78
- package/dist/PromptCarousel/hooks/useCarouselAnimation.cjs +0 -23
- package/dist/PromptCarousel/hooks/useCarouselAnimation.js +0 -22
- package/dist/PromptCarousel/hooks/useCarouselRefs.cjs +0 -20
- package/dist/PromptCarousel/hooks/useCarouselRefs.js +0 -19
- package/dist/PromptCarousel/hooks/useGetScrollProperties.cjs +0 -18
- package/dist/PromptCarousel/hooks/useGetScrollProperties.js +0 -17
- package/dist/PromptCarousel/hooks/useHorizontalScrollAnimation.cjs +0 -78
- package/dist/PromptCarousel/hooks/useHorizontalScrollAnimation.js +0 -77
- package/src/components/PromptCarousel/components/BlockScrollContainer.tsx +0 -34
- package/src/components/PromptCarousel/components/ButtonContainerRow.tsx +0 -46
- package/src/components/PromptCarousel/components/CarouselContentWithBlockScroll.tsx +0 -83
- package/src/components/PromptCarousel/components/CarouselContentWithRowScroll.tsx +0 -71
- package/src/components/PromptCarousel/components/index.ts +0 -9
- package/src/components/PromptCarousel/hooks/useButtonScrollPosition.ts +0 -128
- package/src/components/PromptCarousel/hooks/useCarouselAnimation.ts +0 -47
- package/src/components/PromptCarousel/hooks/useCarouselRefs.ts +0 -27
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
1
2
|
import { Theme } from '../Tokens';
|
|
2
3
|
import { resolveTheme } from '../utils/resolveTheme';
|
|
3
4
|
import { WidgetTextField } from '../WidgetTextField';
|
|
4
5
|
import { ProductCardWidgetComponents } from './components';
|
|
5
6
|
import { ProductCardProps } from './types';
|
|
7
|
+
import { TypographyColor } from '../Typography/types';
|
|
6
8
|
|
|
7
9
|
export const ProductCard = ({
|
|
8
10
|
theme = Theme.GLOBAL_CUSTOM,
|
|
@@ -47,7 +49,16 @@ export const ProductCard = ({
|
|
|
47
49
|
theme={resolvedTheme}
|
|
48
50
|
placeholder={placeholder}
|
|
49
51
|
onClick={onInputClick}
|
|
50
|
-
|
|
52
|
+
textColor={
|
|
53
|
+
resolvedTheme === Theme.MINIMAL
|
|
54
|
+
? TypographyColor.TEXT_LIGHT
|
|
55
|
+
: TypographyColor.TEXT_SECONDARY
|
|
56
|
+
}
|
|
57
|
+
className={classNames(
|
|
58
|
+
resolvedTheme === Theme.MINIMAL
|
|
59
|
+
? 'envive-tw-bg-transparent'
|
|
60
|
+
: 'envive-tw-bg-background-light',
|
|
61
|
+
)}
|
|
51
62
|
/>
|
|
52
63
|
</ProductCardWidgetComponents.Poster>
|
|
53
64
|
);
|
|
@@ -34,20 +34,22 @@ export const Header = ({
|
|
|
34
34
|
className={stackClasses}
|
|
35
35
|
>
|
|
36
36
|
<Typography
|
|
37
|
-
variant={TypographyVariant.
|
|
37
|
+
variant={TypographyVariant.H1_MD}
|
|
38
38
|
color={TypographyColor.TEXT_LIGHT}
|
|
39
39
|
className={headlineClasses}
|
|
40
40
|
numberOfLines={2}
|
|
41
41
|
>
|
|
42
42
|
{headline}
|
|
43
43
|
</Typography>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
{animatedText.length > 0 && (
|
|
45
|
+
<AnimatedText
|
|
46
|
+
sequence={animatedText}
|
|
47
|
+
getNodeWrapper={animatedTextWrapper}
|
|
48
|
+
typingDuration={textTypingDuration}
|
|
49
|
+
transition={textTransition}
|
|
50
|
+
loop={loop}
|
|
51
|
+
/>
|
|
52
|
+
)}
|
|
51
53
|
</Stack>
|
|
52
54
|
);
|
|
53
55
|
};
|
|
@@ -22,8 +22,10 @@ export const PromptButtonCarouselWithImage = ({
|
|
|
22
22
|
}: PromptButtonCarouselWithImageProps) => {
|
|
23
23
|
const finalTheme = resolveTheme(theme);
|
|
24
24
|
|
|
25
|
-
if (promptButtonsTexts && promptButtonsTexts?.length
|
|
26
|
-
throw new Error(
|
|
25
|
+
if (promptButtonsTexts && promptButtonsTexts?.length < 3) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
'PromptButtonsCarouselWithImage: promptButtonsTexts must have at least 3 items',
|
|
28
|
+
);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
return (
|
|
@@ -37,6 +39,7 @@ export const PromptButtonCarouselWithImage = ({
|
|
|
37
39
|
<PromptButtonCarouselWithImageComponents.TextField
|
|
38
40
|
isLoading={isLoading}
|
|
39
41
|
placeholder={textFieldPlaceholder}
|
|
42
|
+
className={finalTheme === Theme.MINIMAL ? '!envive-tw-border-border-medium' : undefined}
|
|
40
43
|
onClick={() => handleTextFieldClick(textFieldPlaceholder)}
|
|
41
44
|
theme={finalTheme}
|
|
42
45
|
/>
|
|
@@ -52,7 +55,7 @@ export const PromptButtonCarouselWithImage = ({
|
|
|
52
55
|
<PromptButtonCarouselWithImageComponents.PromptButtonsCarousel
|
|
53
56
|
theme={finalTheme}
|
|
54
57
|
isLoading={isLoading}
|
|
55
|
-
promptButtonsTexts={promptButtonsTexts}
|
|
58
|
+
promptButtonsTexts={promptButtonsTexts || []}
|
|
56
59
|
promptButtonType={promptButtonType}
|
|
57
60
|
handlePromptButtonClick={handlePromptButtonClick}
|
|
58
61
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { cloneElement } from 'react';
|
|
2
|
+
import { cloneElement, isValidElement } from 'react';
|
|
3
3
|
import { useGetContentSize } from '../../utils/useGetContentSize';
|
|
4
4
|
import { calculateWidthImageGallery } from '../../SocialProof/utils/functions';
|
|
5
5
|
import { Stack } from '../../Stack';
|
|
@@ -7,6 +7,7 @@ import { useCheckIsMobile } from '../../utils/useCheckIsMobile';
|
|
|
7
7
|
import { ImageProps } from './Image';
|
|
8
8
|
import { WidgetTextFieldProps } from '../../WidgetTextField/types/types';
|
|
9
9
|
import { useHorizontalWheelScroll } from '../../utils/useHorizontalWheelScroll';
|
|
10
|
+
import { useDragToScroll } from '../../utils/useDragToScroll';
|
|
10
11
|
|
|
11
12
|
type LayoutProps = {
|
|
12
13
|
id: string;
|
|
@@ -36,6 +37,10 @@ export const Layout = ({
|
|
|
36
37
|
heightDefault: 245,
|
|
37
38
|
});
|
|
38
39
|
const wheelScrollRef = useHorizontalWheelScroll(!isMobile);
|
|
40
|
+
useDragToScroll(wheelScrollRef, {
|
|
41
|
+
direction: isMobile ? 'y' : 'x',
|
|
42
|
+
isEnabled: true,
|
|
43
|
+
});
|
|
39
44
|
|
|
40
45
|
const combinedRef = (node: HTMLDivElement | null) => {
|
|
41
46
|
contentSizeRef.current = node;
|
|
@@ -73,19 +78,23 @@ export const Layout = ({
|
|
|
73
78
|
}}
|
|
74
79
|
gap={4}
|
|
75
80
|
className={classNames(
|
|
76
|
-
'[&::-webkit-scrollbar]:hidden envive-tw-h-fit
|
|
81
|
+
'[&::-webkit-scrollbar]:hidden envive-tw-h-fit',
|
|
77
82
|
isMobile ? 'envive-tw-w-full envive-tw-overflow-y-auto' : 'envive-tw-overflow-x-auto',
|
|
78
83
|
isMobile || hideTextField
|
|
79
84
|
? 'envive-tw-w-full'
|
|
80
|
-
: 'envive-tw-max-w-[300px] md:envive-tw-max-w-[450px] lg:envive-tw-max-w-[
|
|
85
|
+
: 'envive-tw-max-w-[300px] md:envive-tw-max-w-[450px] lg:envive-tw-max-w-[900px]',
|
|
81
86
|
)}
|
|
82
87
|
>
|
|
83
88
|
{promptButtons}
|
|
84
89
|
</Stack>
|
|
85
90
|
</Stack>
|
|
86
91
|
{!hideTextField &&
|
|
92
|
+
isValidElement(textField) &&
|
|
87
93
|
cloneElement(textField as React.ReactElement<WidgetTextFieldProps>, {
|
|
88
|
-
className:
|
|
94
|
+
className: classNames(
|
|
95
|
+
isMobile ? 'envive-tw-w-full' : 'envive-tw-min-w-[276px]',
|
|
96
|
+
(textField as React.ReactElement<WidgetTextFieldProps>).props.className,
|
|
97
|
+
),
|
|
89
98
|
})}
|
|
90
99
|
</Stack>
|
|
91
100
|
</Stack>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Theme } from '../../../../tokens/theme/theme';
|
|
2
2
|
import { PromptButton, PromptButtonVariant } from '../../PromptButton';
|
|
3
3
|
import { resolveTheme } from '../../utils/resolveTheme';
|
|
4
|
+
import { useCheckIsMobile } from '../../utils/useCheckIsMobile';
|
|
5
|
+
import { Stack } from '../../Stack';
|
|
4
6
|
|
|
5
7
|
type PromptButtonsCarouselProps = {
|
|
6
8
|
theme: Theme;
|
|
@@ -10,6 +12,25 @@ type PromptButtonsCarouselProps = {
|
|
|
10
12
|
handlePromptButtonClick: (text: string) => void;
|
|
11
13
|
};
|
|
12
14
|
|
|
15
|
+
function distributeInThreeRows<T>(items: T[]): [T[], T[], T[]] {
|
|
16
|
+
const n = items.length;
|
|
17
|
+
const perRow = [1, 1, 1];
|
|
18
|
+
let remaining = Math.max(0, n - 3);
|
|
19
|
+
let idx = 0;
|
|
20
|
+
while (remaining > 0) {
|
|
21
|
+
perRow[idx % 3] += 1;
|
|
22
|
+
remaining -= 1;
|
|
23
|
+
idx += 1;
|
|
24
|
+
}
|
|
25
|
+
let start = 0;
|
|
26
|
+
const [row0, row1, row2] = perRow.map(count => {
|
|
27
|
+
const row = items.slice(start, start + count);
|
|
28
|
+
start += count;
|
|
29
|
+
return row;
|
|
30
|
+
});
|
|
31
|
+
return [row0, row1, row2];
|
|
32
|
+
}
|
|
33
|
+
|
|
13
34
|
export const PromptButtonsCarousel = ({
|
|
14
35
|
theme,
|
|
15
36
|
isLoading,
|
|
@@ -18,29 +39,51 @@ export const PromptButtonsCarousel = ({
|
|
|
18
39
|
handlePromptButtonClick,
|
|
19
40
|
}: PromptButtonsCarouselProps) => {
|
|
20
41
|
const finalTheme = resolveTheme(theme);
|
|
42
|
+
const { isMobile } = useCheckIsMobile();
|
|
21
43
|
|
|
22
44
|
const promptButtonsTextsFinal = isLoading
|
|
23
45
|
? ['Loading 1...', 'Loading 2...', 'Loading 3...']
|
|
24
|
-
: promptButtonsTexts;
|
|
46
|
+
: promptButtonsTexts || [];
|
|
25
47
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/>
|
|
42
|
-
</div>
|
|
43
|
-
))}
|
|
44
|
-
</>
|
|
48
|
+
const renderButton = (text: string) => (
|
|
49
|
+
<div
|
|
50
|
+
key={text}
|
|
51
|
+
className="envive-tw-flex-shrink-0"
|
|
52
|
+
>
|
|
53
|
+
<PromptButton
|
|
54
|
+
id={`prompt-button-${text}`}
|
|
55
|
+
isLoading={isLoading}
|
|
56
|
+
label={text}
|
|
57
|
+
variant={promptButtonType}
|
|
58
|
+
className="envive-tw-w-fit"
|
|
59
|
+
theme={finalTheme}
|
|
60
|
+
onClick={() => handlePromptButtonClick(text)}
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
45
63
|
);
|
|
64
|
+
|
|
65
|
+
if (isMobile) {
|
|
66
|
+
const [row0, row1, row2] = distributeInThreeRows(promptButtonsTextsFinal);
|
|
67
|
+
const rows = [row0, row1, row2].filter(row => row.length > 0);
|
|
68
|
+
return (
|
|
69
|
+
<Stack
|
|
70
|
+
direction="column"
|
|
71
|
+
gap="4"
|
|
72
|
+
className="envive-tw-w-full"
|
|
73
|
+
>
|
|
74
|
+
{rows.map(row => (
|
|
75
|
+
<Stack
|
|
76
|
+
key={row.join('-')}
|
|
77
|
+
direction="row"
|
|
78
|
+
gap="4"
|
|
79
|
+
className="envive-tw-w-full envive-tw-flex-nowrap"
|
|
80
|
+
>
|
|
81
|
+
{row.map(renderButton)}
|
|
82
|
+
</Stack>
|
|
83
|
+
))}
|
|
84
|
+
</Stack>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return <>{promptButtonsTextsFinal.map(renderButton)}</>;
|
|
46
89
|
};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { useScrollContainer } from 'react-indiana-drag-scroll';
|
|
2
3
|
import { Theme } from '../../../tokens/theme/theme';
|
|
3
4
|
import { PromptButton, PromptButtonVariant } from '../PromptButton';
|
|
4
5
|
import { useCheckIsMobile } from '../utils/useCheckIsMobile';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
PromptCarouselProps,
|
|
8
|
-
PromptCarouselRows,
|
|
9
|
-
RepetitionNumberSuffix,
|
|
10
|
-
} from './types/types';
|
|
11
|
-
import { useCarouselAnimation, useCarouselButtons, useCarouselRefs } from './hooks';
|
|
12
|
-
import { PromptCarouselComponents } from './components';
|
|
6
|
+
import { AnimationSpeed, PromptCarouselProps, PromptCarouselRows } from './types/types';
|
|
7
|
+
import { useCarouselButtons, useCoordinatedScrollAnimation, useScrollSync } from './hooks';
|
|
13
8
|
import { Container } from '../Container';
|
|
14
9
|
import { isAnimated, removeSpaces, shouldShowTwoRows } from './utils/functions';
|
|
15
10
|
import { resolveTheme } from '../utils/resolveTheme';
|
|
11
|
+
import { Stack } from '../Stack';
|
|
16
12
|
|
|
17
13
|
export const PromptCarousel = ({
|
|
18
14
|
id,
|
|
@@ -37,21 +33,39 @@ export const PromptCarousel = ({
|
|
|
37
33
|
const shouldShowTwoRowsValue = shouldShowTwoRows(promptCarouselRows, isMobile);
|
|
38
34
|
const finalTheme = resolveTheme(theme);
|
|
39
35
|
|
|
40
|
-
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
blockScrollRef,
|
|
45
|
-
blockFirstRowStackRef,
|
|
46
|
-
scrollRefs,
|
|
47
|
-
} = useCarouselRefs({ shouldShowTwoRows: shouldShowTwoRowsValue });
|
|
36
|
+
const { ref: dragScrollRef1 } = useScrollContainer();
|
|
37
|
+
const { ref: dragScrollRef2 } = useScrollContainer();
|
|
38
|
+
const scrollContainerRef1 = useRef<HTMLDivElement>(null);
|
|
39
|
+
const scrollContainerRef2 = useRef<HTMLDivElement>(null);
|
|
48
40
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
const setRef1 = useCallback(
|
|
42
|
+
(el: HTMLDivElement | null) => {
|
|
43
|
+
if (typeof dragScrollRef1 === 'function') dragScrollRef1(el);
|
|
44
|
+
scrollContainerRef1.current = el;
|
|
45
|
+
},
|
|
46
|
+
[dragScrollRef1],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const setRef2 = useCallback(
|
|
50
|
+
(el: HTMLDivElement | null) => {
|
|
51
|
+
if (typeof dragScrollRef2 === 'function') dragScrollRef2(el);
|
|
52
|
+
scrollContainerRef2.current = el;
|
|
53
|
+
},
|
|
54
|
+
[dragScrollRef2],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const scrollContainerRefs = shouldShowTwoRowsValue
|
|
58
|
+
? [scrollContainerRef1, scrollContainerRef2]
|
|
59
|
+
: [scrollContainerRef1];
|
|
60
|
+
|
|
61
|
+
useCoordinatedScrollAnimation({
|
|
62
|
+
scrollContainerRefs,
|
|
53
63
|
animationSpeed,
|
|
54
|
-
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
useScrollSync({
|
|
67
|
+
scrollContainerRefs,
|
|
68
|
+
enabled: true,
|
|
55
69
|
});
|
|
56
70
|
|
|
57
71
|
const { visibleButtonsFirstRow, visibleButtonsSecondRow } = useCarouselButtons({
|
|
@@ -60,11 +74,12 @@ export const PromptCarousel = ({
|
|
|
60
74
|
});
|
|
61
75
|
|
|
62
76
|
const renderButton = useCallback(
|
|
63
|
-
(text: string, index: number,
|
|
77
|
+
(text: string, index: number, duplicateIndex = 0) => {
|
|
64
78
|
const textWithoutSpaces = removeSpaces(text);
|
|
65
|
-
const buttonId =
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
const buttonId =
|
|
80
|
+
duplicateIndex > 0
|
|
81
|
+
? `${id}-${textWithoutSpaces}-duplicate-${duplicateIndex}`
|
|
82
|
+
: `${id}-${textWithoutSpaces}`;
|
|
68
83
|
const buttonKey = `button-${buttonId}`;
|
|
69
84
|
|
|
70
85
|
return (
|
|
@@ -75,7 +90,7 @@ export const PromptCarousel = ({
|
|
|
75
90
|
variant={promptButtonType}
|
|
76
91
|
theme={finalTheme}
|
|
77
92
|
isLoading={isLoading}
|
|
78
|
-
bold={boldFirstButton && index === 0}
|
|
93
|
+
bold={boldFirstButton && index === 0 && duplicateIndex === 0}
|
|
79
94
|
onClick={() => handleButtonClick?.(text)}
|
|
80
95
|
/>
|
|
81
96
|
);
|
|
@@ -83,6 +98,14 @@ export const PromptCarousel = ({
|
|
|
83
98
|
[id, promptButtonType, boldFirstButton, handleButtonClick, isLoading, finalTheme],
|
|
84
99
|
);
|
|
85
100
|
|
|
101
|
+
const renderButtonRow = (buttons: string[], startIndex: number) => (
|
|
102
|
+
<>
|
|
103
|
+
{buttons.map((text, i) => renderButton(text, startIndex + i, 0))}
|
|
104
|
+
{isAnimatedValue && buttons.map((text, i) => renderButton(text, startIndex + i, 1))}
|
|
105
|
+
{isAnimatedValue && buttons.map((text, i) => renderButton(text, startIndex + i, 2))}
|
|
106
|
+
</>
|
|
107
|
+
);
|
|
108
|
+
|
|
86
109
|
const defaultAriaLabel = ariaLabel || 'Prompt carousel with suggested actions';
|
|
87
110
|
|
|
88
111
|
return (
|
|
@@ -98,30 +121,44 @@ export const PromptCarousel = ({
|
|
|
98
121
|
aria-busy={isLoading}
|
|
99
122
|
aria-live={isAnimatedValue && !isLoading ? 'polite' : undefined}
|
|
100
123
|
>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
<Stack
|
|
125
|
+
direction="column"
|
|
126
|
+
gap="2"
|
|
127
|
+
>
|
|
128
|
+
<div
|
|
129
|
+
className="envive-tw-no-scrollbar envive-tw-relative envive-tw-w-full envive-tw-overflow-x-scroll"
|
|
130
|
+
ref={setRef1}
|
|
131
|
+
style={{ cursor: 'grab', userSelect: 'none' }}
|
|
132
|
+
>
|
|
133
|
+
<div className="envive-tw-relative envive-tw-inline-block envive-tw-whitespace-nowrap">
|
|
134
|
+
<Stack
|
|
135
|
+
direction="row"
|
|
136
|
+
gap="2"
|
|
137
|
+
className="envive-tw-pl-0 envive-tw-h-full envive-tw-items-center"
|
|
138
|
+
>
|
|
139
|
+
{renderButtonRow(visibleButtonsFirstRow, 0)}
|
|
140
|
+
</Stack>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
{shouldShowTwoRowsValue && (
|
|
145
|
+
<div
|
|
146
|
+
className="envive-tw-no-scrollbar envive-tw-relative envive-tw-w-full envive-tw-overflow-x-scroll"
|
|
147
|
+
ref={setRef2}
|
|
148
|
+
style={{ cursor: 'grab', userSelect: 'none' }}
|
|
149
|
+
>
|
|
150
|
+
<div className="envive-tw-relative envive-tw-inline-block envive-tw-whitespace-nowrap">
|
|
151
|
+
<Stack
|
|
152
|
+
direction="row"
|
|
153
|
+
gap="2"
|
|
154
|
+
className="envive-tw-pl-0 envive-tw-h-full envive-tw-items-center"
|
|
155
|
+
>
|
|
156
|
+
{renderButtonRow(visibleButtonsSecondRow, visibleButtonsFirstRow.length)}
|
|
157
|
+
</Stack>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
161
|
+
</Stack>
|
|
125
162
|
</Container>
|
|
126
163
|
);
|
|
127
164
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { useHorizontalScrollAnimation } from './useHorizontalScrollAnimation';
|
|
2
|
-
export { useButtonScrollPosition } from './useButtonScrollPosition';
|
|
3
|
-
export { useCarouselRefs } from './useCarouselRefs';
|
|
4
1
|
export { useCarouselButtons } from './useCarouselButtons';
|
|
5
|
-
export {
|
|
2
|
+
export { useCoordinatedScrollAnimation } from './useCoordinatedScrollAnimation';
|
|
3
|
+
export { useScrollSync } from './useScrollSync';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { AnimationSpeed } from '../types/types';
|
|
3
|
+
|
|
4
|
+
interface UseCoordinatedScrollAnimationOptions {
|
|
5
|
+
scrollContainerRefs: React.RefObject<HTMLDivElement>[];
|
|
6
|
+
animationSpeed?: `${AnimationSpeed}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useCoordinatedScrollAnimation({
|
|
10
|
+
scrollContainerRefs,
|
|
11
|
+
animationSpeed = AnimationSpeed.NONE,
|
|
12
|
+
}: UseCoordinatedScrollAnimationOptions): void {
|
|
13
|
+
const resumeTimeoutRef = useRef<number | null>(null);
|
|
14
|
+
const scrollAnimationRefs = useRef<number[]>([]);
|
|
15
|
+
const isPausedRef = useRef(false);
|
|
16
|
+
|
|
17
|
+
let PIXELS_PER_SECOND = 0;
|
|
18
|
+
switch (animationSpeed) {
|
|
19
|
+
case AnimationSpeed.FAST:
|
|
20
|
+
PIXELS_PER_SECOND = 60;
|
|
21
|
+
break;
|
|
22
|
+
case AnimationSpeed.SLOW:
|
|
23
|
+
PIXELS_PER_SECOND = 30;
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
PIXELS_PER_SECOND = 0;
|
|
27
|
+
}
|
|
28
|
+
const RESUME_DELAY_MS = 1500;
|
|
29
|
+
const isAnimated = animationSpeed !== AnimationSpeed.NONE;
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!isAnimated || scrollContainerRefs.length === 0) return undefined;
|
|
33
|
+
|
|
34
|
+
const containers = scrollContainerRefs
|
|
35
|
+
.map(ref => ref.current)
|
|
36
|
+
.filter((el): el is HTMLDivElement => el !== null);
|
|
37
|
+
|
|
38
|
+
if (containers.length === 0) return undefined;
|
|
39
|
+
|
|
40
|
+
const animationStates = containers.map(() => ({
|
|
41
|
+
lastTimestamp: null as number | null,
|
|
42
|
+
accumulatedScroll: 0,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
const step = (timestamp: number) => {
|
|
46
|
+
if (!isPausedRef.current) {
|
|
47
|
+
containers.forEach((containerElement, index) => {
|
|
48
|
+
const container = containerElement;
|
|
49
|
+
if (container.scrollWidth <= container.clientWidth) return;
|
|
50
|
+
|
|
51
|
+
const stateElement = animationStates[index];
|
|
52
|
+
const state = stateElement;
|
|
53
|
+
if (state.lastTimestamp === null) state.lastTimestamp = timestamp;
|
|
54
|
+
|
|
55
|
+
const delta = timestamp - state.lastTimestamp;
|
|
56
|
+
state.lastTimestamp = timestamp;
|
|
57
|
+
|
|
58
|
+
state.accumulatedScroll += PIXELS_PER_SECOND * (delta / 1000);
|
|
59
|
+
|
|
60
|
+
const pixelsToScroll = Math.floor(state.accumulatedScroll);
|
|
61
|
+
if (pixelsToScroll > 0) {
|
|
62
|
+
container.scrollLeft += pixelsToScroll;
|
|
63
|
+
state.accumulatedScroll -= pixelsToScroll;
|
|
64
|
+
|
|
65
|
+
if (Math.ceil(container.scrollLeft) >= container.scrollWidth - container.clientWidth) {
|
|
66
|
+
container.scrollLeft = 0;
|
|
67
|
+
state.accumulatedScroll = 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const rafId = requestAnimationFrame(step);
|
|
74
|
+
scrollAnimationRefs.current[0] = rafId;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
scrollAnimationRefs.current[0] = requestAnimationFrame(step);
|
|
78
|
+
|
|
79
|
+
const pauseAnimation = () => {
|
|
80
|
+
isPausedRef.current = true;
|
|
81
|
+
if (resumeTimeoutRef.current) {
|
|
82
|
+
clearTimeout(resumeTimeoutRef.current);
|
|
83
|
+
resumeTimeoutRef.current = null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const scheduleResumeAnimation = () => {
|
|
88
|
+
resumeTimeoutRef.current = window.setTimeout(() => {
|
|
89
|
+
isPausedRef.current = false;
|
|
90
|
+
animationStates.forEach(stateElement => {
|
|
91
|
+
const state = stateElement;
|
|
92
|
+
state.lastTimestamp = null;
|
|
93
|
+
});
|
|
94
|
+
}, RESUME_DELAY_MS);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
containers.forEach(container => {
|
|
98
|
+
container.addEventListener('mouseenter', pauseAnimation);
|
|
99
|
+
container.addEventListener('mouseleave', scheduleResumeAnimation);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return () => {
|
|
103
|
+
scrollAnimationRefs.current.forEach(rafId => {
|
|
104
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
105
|
+
});
|
|
106
|
+
containers.forEach(container => {
|
|
107
|
+
container.removeEventListener('mouseenter', pauseAnimation);
|
|
108
|
+
container.removeEventListener('mouseleave', scheduleResumeAnimation);
|
|
109
|
+
});
|
|
110
|
+
if (resumeTimeoutRef.current) {
|
|
111
|
+
clearTimeout(resumeTimeoutRef.current);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}, [isAnimated, PIXELS_PER_SECOND, scrollContainerRefs]);
|
|
115
|
+
}
|