@envive-ai/react-toolkit 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -0
- package/package.json +10 -7
- package/src/atoms/search/types.ts +5 -0
- package/src/components/common/ButtonBase/ButtonBase.tsx +70 -0
- package/src/components/common/ButtonBase/types.ts +27 -0
- package/src/components/common/Headline/Headline.tsx +81 -0
- package/src/components/common/ImageWithFallback/ImageWithFallback.tsx +66 -0
- package/src/components/common/ProductCard/ProductCard.tsx +305 -0
- package/src/components/common/ProductCard/ProductCardSkeleton.tsx +83 -0
- package/src/components/common/ProductCard/productCardVariants.ts +63 -0
- package/src/components/common/ProductCard/types.ts +49 -0
- package/src/components/common/ProductGrid/ProductGrid.tsx +73 -0
- package/src/components/common/ProductGrid/productGridVariants.ts +31 -0
- package/src/components/common/SparkleAnimation/SparkleAnimation.tsx +105 -0
- package/src/components/common/SparkleAnimation/types.ts +6 -0
- package/src/components/common/Spinner/Spinner.tsx +30 -0
- package/src/components/common/SuggestionButton/SuggestionButton.tsx +258 -0
- package/src/components/common/SuggestionButton/types.ts +14 -0
- package/src/components/common/Text/Text.tsx +58 -0
- package/src/components/common/Text/textVariantClasses.ts +106 -0
- package/src/components/common/Text/types.ts +23 -0
- package/src/components/common/TextInput/TextInput.tsx +34 -0
- package/src/components/models/colorsConfig.ts +28 -0
- package/src/components/search/FilterScrollbar/AppliedFiltersScrollbar.tsx +70 -0
- package/src/components/search/FilterScrollbar/DynamicFiltersScrollbar.tsx +52 -0
- package/src/components/search/SearchFilter/SearchFilter.tsx +84 -0
- package/src/components/search/SearchFilter/SearchFilterHeader.tsx +42 -0
- package/src/components/search/SearchFilter/SearchFilterItem.tsx +42 -0
- package/src/components/search/SearchFilter/types.ts +48 -0
- package/src/components/search/SearchInput/SearchInput.tsx +135 -0
- package/src/components/search/SearchInput/searchInputVariants.ts +27 -0
- package/src/components/search/SearchInputAutocomplete/SearchAutocomplete.tsx +62 -0
- package/src/components/search/SearchInputForm/SearchInputForm.tsx +66 -0
- package/src/components/search/SearchResultsFilterSidebar/SearchResultsFilter.tsx +82 -0
- package/src/components/search/SearchResultsFilterSidebar/searchFilterSidebarVariants.ts +45 -0
- package/{dist/packages/components/src/components/search/SearchResultsFilterSidebar/types.d.ts → src/components/search/SearchResultsFilterSidebar/types.ts} +1 -1
- package/src/components/search/SearchResultsStates/NoSearchResultsFound.tsx +41 -0
- package/src/components/search/SearchResultsStates/SearchResultsGrid.tsx +105 -0
- package/src/components/search/SearchResultsStates/SearchResultsLoadingGrid.tsx +50 -0
- package/src/components/search/types.ts +5 -0
- package/{dist/packages/components/src/components/test/types.d.ts → src/components/test/types.ts} +1 -1
- package/src/config/chatElementDisplayLocation.ts +22 -0
- package/{dist/packages/components/src/index.js → src/index.ts} +10 -0
- package/src/logging/logger.ts +21 -0
- package/src/types/external.ts +24 -0
- package/{dist/packages/components/src/util/camelCase.d.ts → src/util/camelCase.ts} +33 -11
- package/src/util/camelCasedPropertiesDeep.ts +81 -0
- package/src/util/formatPrice.ts +14 -0
- package/src/util/internal.ts +95 -0
- package/{dist/packages/components/src/util/primitive.d.ts → src/util/primitive.ts} +2 -0
- package/src/util/splitWords.ts +72 -0
- package/{dist/packages/components/src/util/trim.d.ts → src/util/trim.ts} +5 -1
- package/dist/packages/components/src/atoms/search/types.d.ts +0 -5
- package/dist/packages/components/src/atoms/search/types.js +0 -1
- package/dist/packages/components/src/components/common/ButtonBase/ButtonBase.d.ts +0 -2
- package/dist/packages/components/src/components/common/ButtonBase/ButtonBase.js +0 -41
- package/dist/packages/components/src/components/common/ButtonBase/types.d.ts +0 -24
- package/dist/packages/components/src/components/common/ButtonBase/types.js +0 -6
- package/dist/packages/components/src/components/common/Headline/Headline.d.ts +0 -10
- package/dist/packages/components/src/components/common/Headline/Headline.js +0 -34
- package/dist/packages/components/src/components/common/ImageWithFallback/ImageWithFallback.d.ts +0 -12
- package/dist/packages/components/src/components/common/ImageWithFallback/ImageWithFallback.js +0 -26
- package/dist/packages/components/src/components/common/ProductCard/ProductCard.d.ts +0 -39
- package/dist/packages/components/src/components/common/ProductCard/ProductCard.js +0 -83
- package/dist/packages/components/src/components/common/ProductCard/ProductCardSkeleton.d.ts +0 -9
- package/dist/packages/components/src/components/common/ProductCard/ProductCardSkeleton.js +0 -15
- package/dist/packages/components/src/components/common/ProductCard/productCardVariants.d.ts +0 -8
- package/dist/packages/components/src/components/common/ProductCard/productCardVariants.js +0 -50
- package/dist/packages/components/src/components/common/ProductCard/types.d.ts +0 -39
- package/dist/packages/components/src/components/common/ProductCard/types.js +0 -10
- package/dist/packages/components/src/components/common/ProductGrid/ProductGrid.d.ts +0 -14
- package/dist/packages/components/src/components/common/ProductGrid/ProductGrid.js +0 -13
- package/dist/packages/components/src/components/common/ProductGrid/productGridVariants.d.ts +0 -10
- package/dist/packages/components/src/components/common/ProductGrid/productGridVariants.js +0 -16
- package/dist/packages/components/src/components/common/SparkleAnimation/SparkleAnimation.d.ts +0 -7
- package/dist/packages/components/src/components/common/SparkleAnimation/SparkleAnimation.js +0 -40
- package/dist/packages/components/src/components/common/SparkleAnimation/types.d.ts +0 -6
- package/dist/packages/components/src/components/common/SparkleAnimation/types.js +0 -7
- package/dist/packages/components/src/components/common/Spinner/Spinner.d.ts +0 -5
- package/dist/packages/components/src/components/common/Spinner/Spinner.js +0 -16
- package/dist/packages/components/src/components/common/SuggestionButton/SuggestionButton.d.ts +0 -18
- package/dist/packages/components/src/components/common/SuggestionButton/SuggestionButton.js +0 -210
- package/dist/packages/components/src/components/common/SuggestionButton/types.d.ts +0 -1
- package/dist/packages/components/src/components/common/SuggestionButton/types.js +0 -1
- package/dist/packages/components/src/components/common/Text/Text.d.ts +0 -12
- package/dist/packages/components/src/components/common/Text/Text.js +0 -26
- package/dist/packages/components/src/components/common/Text/textVariantClasses.d.ts +0 -171
- package/dist/packages/components/src/components/common/Text/textVariantClasses.js +0 -103
- package/dist/packages/components/src/components/common/Text/types.d.ts +0 -16
- package/dist/packages/components/src/components/common/Text/types.js +0 -6
- package/dist/packages/components/src/components/common/TextInput/TextInput.d.ts +0 -8
- package/dist/packages/components/src/components/common/TextInput/TextInput.js +0 -25
- package/dist/packages/components/src/components/models/colorsConfig.d.ts +0 -26
- package/dist/packages/components/src/components/models/colorsConfig.js +0 -23
- package/dist/packages/components/src/components/search/FilterScrollbar/AppliedFiltersScrollbar.d.ts +0 -11
- package/dist/packages/components/src/components/search/FilterScrollbar/AppliedFiltersScrollbar.js +0 -18
- package/dist/packages/components/src/components/search/FilterScrollbar/DynamicFiltersScrollbar.d.ts +0 -15
- package/dist/packages/components/src/components/search/FilterScrollbar/DynamicFiltersScrollbar.js +0 -15
- package/dist/packages/components/src/components/search/SearchFilter/SearchFilter.d.ts +0 -2
- package/dist/packages/components/src/components/search/SearchFilter/SearchFilter.js +0 -24
- package/dist/packages/components/src/components/search/SearchFilter/SearchFilterHeader.d.ts +0 -2
- package/dist/packages/components/src/components/search/SearchFilter/SearchFilterHeader.js +0 -9
- package/dist/packages/components/src/components/search/SearchFilter/SearchFilterItem.d.ts +0 -2
- package/dist/packages/components/src/components/search/SearchFilter/SearchFilterItem.js +0 -13
- package/dist/packages/components/src/components/search/SearchFilter/types.d.ts +0 -42
- package/dist/packages/components/src/components/search/SearchFilter/types.js +0 -1
- package/dist/packages/components/src/components/search/SearchInput/SearchInput.d.ts +0 -16
- package/dist/packages/components/src/components/search/SearchInput/SearchInput.js +0 -38
- package/dist/packages/components/src/components/search/SearchInput/searchInputVariants.d.ts +0 -13
- package/dist/packages/components/src/components/search/SearchInput/searchInputVariants.js +0 -12
- package/dist/packages/components/src/components/search/SearchInputAutocomplete/SearchAutocomplete.d.ts +0 -10
- package/dist/packages/components/src/components/search/SearchInputAutocomplete/SearchAutocomplete.js +0 -14
- package/dist/packages/components/src/components/search/SearchInputForm/SearchInputForm.d.ts +0 -16
- package/dist/packages/components/src/components/search/SearchInputForm/SearchInputForm.js +0 -13
- package/dist/packages/components/src/components/search/SearchInputForm/types.js +0 -1
- package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/SearchResultsFilter.d.ts +0 -14
- package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/SearchResultsFilter.js +0 -15
- package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/searchFilterSidebarVariants.d.ts +0 -16
- package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/searchFilterSidebarVariants.js +0 -29
- package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/types.js +0 -1
- package/dist/packages/components/src/components/search/SearchResultsStates/NoSearchResultsFound.d.ts +0 -8
- package/dist/packages/components/src/components/search/SearchResultsStates/NoSearchResultsFound.js +0 -10
- package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsGrid.d.ts +0 -24
- package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsGrid.js +0 -19
- package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsLoadingGrid.d.ts +0 -6
- package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsLoadingGrid.js +0 -10
- package/dist/packages/components/src/components/search/types.d.ts +0 -5
- package/dist/packages/components/src/components/search/types.js +0 -6
- package/dist/packages/components/src/components/test/types.js +0 -1
- package/dist/packages/components/src/config/chatElementDisplayLocation.d.ts +0 -21
- package/dist/packages/components/src/config/chatElementDisplayLocation.js +0 -23
- package/dist/packages/components/src/index.d.ts +0 -45
- package/dist/packages/components/src/logging/logger.d.ts +0 -7
- package/dist/packages/components/src/logging/logger.js +0 -16
- package/dist/packages/components/src/types/external.d.ts +0 -21
- package/dist/packages/components/src/types/external.js +0 -5
- package/dist/packages/components/src/util/camelCase.js +0 -2
- package/dist/packages/components/src/util/camelCasedPropertiesDeep.d.ts +0 -53
- package/dist/packages/components/src/util/camelCasedPropertiesDeep.js +0 -1
- package/dist/packages/components/src/util/formatPrice.d.ts +0 -1
- package/dist/packages/components/src/util/formatPrice.js +0 -11
- package/dist/packages/components/src/util/internal.d.ts +0 -27
- package/dist/packages/components/src/util/internal.js +0 -4
- package/dist/packages/components/src/util/primitive.js +0 -2
- package/dist/packages/components/src/util/splitWords.d.ts +0 -55
- package/dist/packages/components/src/util/splitWords.js +0 -2
- package/dist/packages/components/src/util/trim.js +0 -2
- package/dist/packages/components/src/util/unknownArray.js +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/{dist/packages/components/src/components/search/SearchInputForm/types.d.ts → src/components/search/SearchInputForm/types.ts} +0 -0
- /package/{dist/packages/components/src/util/unknownArray.d.ts → src/util/unknownArray.ts} +0 -0
package/LICENSE
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envive-ai/react-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React component library for Envive services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -11,14 +11,16 @@
|
|
|
11
11
|
"author": "Envive AI",
|
|
12
12
|
"license": "UNLICENSED",
|
|
13
13
|
"type": "module",
|
|
14
|
-
"main": "dist/index.js",
|
|
15
|
-
"module": "dist/index.js",
|
|
16
|
-
"types": "dist/index.d.ts",
|
|
14
|
+
"main": "dist/src/index.js",
|
|
15
|
+
"module": "dist/src/index.js",
|
|
16
|
+
"types": "dist/src/index.d.ts",
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"src",
|
|
20
|
+
"!**/*.tsbuildinfo"
|
|
19
21
|
],
|
|
20
22
|
"scripts": {
|
|
21
|
-
"build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
|
|
23
|
+
"build": "tsc -p tsconfig.lib.json && tsc-alias -p tsconfig.lib.json",
|
|
22
24
|
"prepublish": "npm run build"
|
|
23
25
|
},
|
|
24
26
|
"dependencies": {
|
|
@@ -26,7 +28,8 @@
|
|
|
26
28
|
"framer-motion": "^12.23.12",
|
|
27
29
|
"react-icons": "^5.0.1",
|
|
28
30
|
"react-indiana-drag-scroll": "^3.0.3-alpha",
|
|
29
|
-
"vite-plugin-svgr": "^4.5.0"
|
|
31
|
+
"vite-plugin-svgr": "^4.5.0",
|
|
32
|
+
"@envive-ai/react-icons": "0.1.0"
|
|
30
33
|
},
|
|
31
34
|
"peerDependencies": {
|
|
32
35
|
"react": "^18.3.1",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { createElement, useEffect, useRef } from 'react';
|
|
3
|
+
import { ButtonBaseOverrides, type ButtonBaseProps } from './types';
|
|
4
|
+
import { Text } from 'src/components/common/Text/Text';
|
|
5
|
+
|
|
6
|
+
export const ButtonBase = ({
|
|
7
|
+
type = 'button',
|
|
8
|
+
isDisabled = false,
|
|
9
|
+
dataAttributes,
|
|
10
|
+
buttonClass,
|
|
11
|
+
text,
|
|
12
|
+
textClass,
|
|
13
|
+
icon,
|
|
14
|
+
iconClass = 'spiffy-tw-w-[21px] spiffy-tw-h-[21px]',
|
|
15
|
+
dataTestId,
|
|
16
|
+
onClick,
|
|
17
|
+
disablePadding = false,
|
|
18
|
+
}: ButtonBaseProps) => {
|
|
19
|
+
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
20
|
+
|
|
21
|
+
const buttonClassName = classNames({
|
|
22
|
+
[ButtonBaseOverrides.BUTTON]: true,
|
|
23
|
+
'spiffy-tw-flex': true,
|
|
24
|
+
'spiffy-tw-min-h-[36px]': true,
|
|
25
|
+
'spiffy-tw-cursor-pointer': true,
|
|
26
|
+
'spiffy-tw-items-center': true,
|
|
27
|
+
'spiffy-tw-gap-2': true,
|
|
28
|
+
'spiffy-tw-px-4': !disablePadding,
|
|
29
|
+
'spiffy-tw-transition-colors': true,
|
|
30
|
+
'spiffy-tw-opacity-40': isDisabled,
|
|
31
|
+
'spiffy-tw-cursor-not-allowed': isDisabled,
|
|
32
|
+
[`${buttonClass}`]: buttonClass != null,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const textClassName = classNames({
|
|
36
|
+
[ButtonBaseOverrides.BUTTON_TEXT]: true,
|
|
37
|
+
'spiffy-tw-whitespace-nowrap': true,
|
|
38
|
+
[`${textClass}`]: textClass != null,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const iconClassName = classNames({
|
|
42
|
+
[ButtonBaseOverrides.BUTTON_ICON]: true,
|
|
43
|
+
[`${iconClass}`]: iconClass != null,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (dataAttributes && buttonRef.current) {
|
|
48
|
+
Object.entries(dataAttributes).forEach(([key, value]) => {
|
|
49
|
+
buttonRef.current?.setAttribute(key, value as string);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, [dataAttributes]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<button
|
|
56
|
+
type={type}
|
|
57
|
+
ref={buttonRef}
|
|
58
|
+
className={buttonClassName}
|
|
59
|
+
disabled={isDisabled}
|
|
60
|
+
data-testid={dataTestId}
|
|
61
|
+
onClick={onClick}
|
|
62
|
+
>
|
|
63
|
+
{icon &&
|
|
64
|
+
createElement(icon, {
|
|
65
|
+
className: iconClassName,
|
|
66
|
+
})}
|
|
67
|
+
<Text className={textClassName}>{text}</Text>
|
|
68
|
+
</button>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, CSSProperties } from 'react';
|
|
2
|
+
import type { TestProps } from 'src/components/test/types';
|
|
3
|
+
|
|
4
|
+
export interface ButtonHoverStyles extends CSSProperties {
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ButtonBaseProps extends TestProps {
|
|
10
|
+
type?: ButtonHTMLAttributes<HTMLButtonElement>['type'];
|
|
11
|
+
isDisabled?: boolean;
|
|
12
|
+
dataAttributes?: Record<string, string>;
|
|
13
|
+
buttonClass?: string;
|
|
14
|
+
text: string;
|
|
15
|
+
textClass?: string;
|
|
16
|
+
icon?: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
|
|
17
|
+
iconClass?: string;
|
|
18
|
+
onClick?: () => void;
|
|
19
|
+
disablePadding?: boolean;
|
|
20
|
+
dataTestId?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum ButtonBaseOverrides {
|
|
24
|
+
BUTTON = 'spiffy-button-base-button',
|
|
25
|
+
BUTTON_TEXT = 'spiffy-button-base-button-text',
|
|
26
|
+
BUTTON_ICON = 'spiffy-button-base-button-icon',
|
|
27
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { HeadlineVariantMap } from '../Text/textVariantClasses';
|
|
3
|
+
|
|
4
|
+
export type HeadlineVariant = 't1' | 't2' | 't3' | 'h1' | 'h2' | 'h3' | 'h4';
|
|
5
|
+
|
|
6
|
+
export type HeadlineProps = {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
variant?: HeadlineVariant;
|
|
11
|
+
testId?: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Headline = ({ children, className, style, testId, variant = 'h1' }: HeadlineProps) => {
|
|
16
|
+
const variantClassNames = variant ? HeadlineVariantMap[variant] : {};
|
|
17
|
+
const textClassNames = classNames(className, variantClassNames, {
|
|
18
|
+
'spiffy-tw-font-[Poppins,sans-serif]': true,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const T1 = () => (
|
|
22
|
+
<h1 data-testid={testId} className={textClassNames} style={style}>
|
|
23
|
+
{children}
|
|
24
|
+
</h1>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const T2 = () => (
|
|
28
|
+
<h2 data-testid={testId} className={textClassNames} style={style}>
|
|
29
|
+
{children}
|
|
30
|
+
</h2>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const T3 = () => (
|
|
34
|
+
<h3 data-testid={testId} className={textClassNames} style={style}>
|
|
35
|
+
{children}
|
|
36
|
+
</h3>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const H1 = () => (
|
|
40
|
+
<h1 data-testid={testId} className={textClassNames} style={style}>
|
|
41
|
+
{children}
|
|
42
|
+
</h1>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const H2 = () => (
|
|
46
|
+
<h2 data-testid={testId} className={textClassNames} style={style}>
|
|
47
|
+
{children}
|
|
48
|
+
</h2>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const H3 = () => (
|
|
52
|
+
<h3 data-testid={testId} className={textClassNames} style={style}>
|
|
53
|
+
{children}
|
|
54
|
+
</h3>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const H4 = () => (
|
|
58
|
+
<h4 data-testid={testId} className={textClassNames} style={style}>
|
|
59
|
+
{children}
|
|
60
|
+
</h4>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
switch (variant) {
|
|
64
|
+
case 't1':
|
|
65
|
+
return T1();
|
|
66
|
+
case 't2':
|
|
67
|
+
return T2();
|
|
68
|
+
case 't3':
|
|
69
|
+
return T3();
|
|
70
|
+
case 'h1':
|
|
71
|
+
return H1();
|
|
72
|
+
case 'h2':
|
|
73
|
+
return H2();
|
|
74
|
+
case 'h3':
|
|
75
|
+
return H3();
|
|
76
|
+
case 'h4':
|
|
77
|
+
return H4();
|
|
78
|
+
default:
|
|
79
|
+
throw new Error(`Invalid variant: ${variant}`);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface ImageWithFallbackProps {
|
|
5
|
+
src: string | undefined;
|
|
6
|
+
alt: string;
|
|
7
|
+
fallbackClassnames?: string;
|
|
8
|
+
fallback: React.ReactNode;
|
|
9
|
+
dataTestId?: string;
|
|
10
|
+
imageClassnames: string;
|
|
11
|
+
onLoad?: () => void;
|
|
12
|
+
onError?: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ImageWithFallback = ({
|
|
16
|
+
src,
|
|
17
|
+
alt,
|
|
18
|
+
dataTestId,
|
|
19
|
+
fallbackClassnames,
|
|
20
|
+
fallback,
|
|
21
|
+
imageClassnames,
|
|
22
|
+
onLoad,
|
|
23
|
+
onError,
|
|
24
|
+
}: ImageWithFallbackProps) => {
|
|
25
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
26
|
+
const [isError, setIsError] = useState(false);
|
|
27
|
+
|
|
28
|
+
const imageExtraClassnames = classNames(imageClassnames, {
|
|
29
|
+
'spiffy-tw-block': isLoaded,
|
|
30
|
+
'spiffy-tw-hidden': !isLoaded,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const fallbackMergedClassNames = classNames(
|
|
34
|
+
{
|
|
35
|
+
'spiffy-tw-flex': true,
|
|
36
|
+
'spiffy-tw-flex-col': true,
|
|
37
|
+
'spiffy-tw-items-center': true,
|
|
38
|
+
},
|
|
39
|
+
fallbackClassnames,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (isError) {
|
|
43
|
+
return <div className={fallbackMergedClassNames}>{fallback}</div>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
{!isLoaded && <div className={fallbackMergedClassNames}>{fallback}</div>}
|
|
49
|
+
|
|
50
|
+
<img
|
|
51
|
+
src={src}
|
|
52
|
+
className={imageExtraClassnames}
|
|
53
|
+
data-testid={dataTestId}
|
|
54
|
+
alt={alt}
|
|
55
|
+
onLoad={() => {
|
|
56
|
+
setIsLoaded(true);
|
|
57
|
+
onLoad?.();
|
|
58
|
+
}}
|
|
59
|
+
onError={() => {
|
|
60
|
+
setIsError(true);
|
|
61
|
+
onError?.();
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { MdStar } from 'react-icons/md';
|
|
3
|
+
import { Text } from 'src/components/common/Text/Text';
|
|
4
|
+
import {
|
|
5
|
+
variantClassMap,
|
|
6
|
+
variantHoverClassMap,
|
|
7
|
+
productCardLayoutVariantClasses,
|
|
8
|
+
variantTitleColorMap,
|
|
9
|
+
} from './productCardVariants';
|
|
10
|
+
import { Headline } from '../Headline/Headline';
|
|
11
|
+
import { ImageWithFallback } from 'src/components/common/ImageWithFallback/ImageWithFallback';
|
|
12
|
+
import type {
|
|
13
|
+
ProductCardConfig,
|
|
14
|
+
ProductCardHoverVariant,
|
|
15
|
+
ProductCardLayoutVariant,
|
|
16
|
+
ProductCardVariant,
|
|
17
|
+
} from './types';
|
|
18
|
+
import type { TestProps } from 'src/components/test/types';
|
|
19
|
+
import type { ChatElementDisplayLocation } from 'src/config/chatElementDisplayLocation';
|
|
20
|
+
import Logger from 'src/logging/logger';
|
|
21
|
+
import { Spinner } from '../Spinner/Spinner';
|
|
22
|
+
import { formatPrice } from 'src/util/formatPrice';
|
|
23
|
+
|
|
24
|
+
const formatReviews = (stars: number) =>
|
|
25
|
+
String(
|
|
26
|
+
Number(stars).toLocaleString('en-US', { minimumFractionDigits: 1, maximumFractionDigits: 1 }),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
interface RatingSummaryProps {
|
|
30
|
+
stars: number;
|
|
31
|
+
reviewCount: number;
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const RatingSummary = ({ stars, reviewCount, className }: RatingSummaryProps) => {
|
|
36
|
+
const group = classNames(
|
|
37
|
+
'spiffy-product-card-rating',
|
|
38
|
+
'spiffy-product-card-text-color',
|
|
39
|
+
'spiffy-tw-flex',
|
|
40
|
+
'spiffy-tw-flex-row',
|
|
41
|
+
'spiffy-tw-items-center',
|
|
42
|
+
'spiffy-tw-gap-1',
|
|
43
|
+
'spiffy-tw-text-[--spiffy-colors-text-primary]',
|
|
44
|
+
'spiffy-tw-tracking-[0.8px]',
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const starClassnames = classNames(
|
|
48
|
+
'spiffy-product-card-rating-star-color',
|
|
49
|
+
'spiffy-tw-fill-[--spiffy-colors-accent-primary]',
|
|
50
|
+
'spiffy-tw-w-[14px]',
|
|
51
|
+
'spiffy-tw-h-[14px]',
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div className={className}>
|
|
56
|
+
<div className={group}>
|
|
57
|
+
<MdStar className={starClassnames} />
|
|
58
|
+
<Text variant="body3">{formatReviews(stars)}</Text>
|
|
59
|
+
<Text variant="body3">({reviewCount})</Text>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
interface PriceSectionProps {
|
|
66
|
+
originalPrice?: string;
|
|
67
|
+
salePrice?: string;
|
|
68
|
+
pricePrefix?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const PriceSection = ({ originalPrice, salePrice, pricePrefix }: PriceSectionProps) => {
|
|
72
|
+
if (!originalPrice) return null;
|
|
73
|
+
|
|
74
|
+
const priceClassName = classNames(
|
|
75
|
+
'spiffy-product-card-price',
|
|
76
|
+
'spiffy-product-card-text-color',
|
|
77
|
+
'spiffy-tw-font-regular',
|
|
78
|
+
'spiffy-tw-flex',
|
|
79
|
+
'spiffy-tw-flex-wrap',
|
|
80
|
+
'spiffy-tw-gap-1',
|
|
81
|
+
'spiffy-tw-text-sm',
|
|
82
|
+
'spiffy-tw-font-[400]',
|
|
83
|
+
'spiffy-tw-leading-[100%]',
|
|
84
|
+
'spiffy-tw-tracking-[0.8px]',
|
|
85
|
+
'spiffy-tw-text-[--spiffy-colors-text-primary]',
|
|
86
|
+
);
|
|
87
|
+
const showSalePrice = salePrice && originalPrice !== salePrice;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div className={priceClassName}>
|
|
91
|
+
{pricePrefix && <Text>{pricePrefix}</Text>}
|
|
92
|
+
{showSalePrice && <Text>{salePrice}</Text>}
|
|
93
|
+
<Text className={showSalePrice ? 'spiffy-tw-line-through' : ''}>{originalPrice}</Text>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
interface ProductCardProps extends TestProps {
|
|
99
|
+
productCardConfig?: ProductCardConfig;
|
|
100
|
+
merchantShortName: string;
|
|
101
|
+
title: string;
|
|
102
|
+
url?: string;
|
|
103
|
+
searchResponseId?: string;
|
|
104
|
+
productResponseId?: string;
|
|
105
|
+
cardDisplayLocation: ChatElementDisplayLocation.IN_CHAT | ChatElementDisplayLocation.PRODUCT_GRID;
|
|
106
|
+
imageUrl?: string;
|
|
107
|
+
originalPrice?: number;
|
|
108
|
+
averageRating?: number;
|
|
109
|
+
numberReviews?: number;
|
|
110
|
+
salePrice?: number;
|
|
111
|
+
variant?: ProductCardVariant;
|
|
112
|
+
hoverVariant?: ProductCardHoverVariant;
|
|
113
|
+
layoutVariant?: ProductCardLayoutVariant;
|
|
114
|
+
zoomOnHover?: boolean;
|
|
115
|
+
aspectRatio?: '3:4' | 'square' | 'none';
|
|
116
|
+
clickPosition?: number | null;
|
|
117
|
+
growWithContainer?: boolean;
|
|
118
|
+
handleClick: (clickedUrl: string) => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const ProductCard = ({
|
|
122
|
+
productCardConfig,
|
|
123
|
+
merchantShortName,
|
|
124
|
+
imageUrl,
|
|
125
|
+
title,
|
|
126
|
+
url,
|
|
127
|
+
originalPrice,
|
|
128
|
+
averageRating,
|
|
129
|
+
numberReviews,
|
|
130
|
+
salePrice,
|
|
131
|
+
variant,
|
|
132
|
+
hoverVariant,
|
|
133
|
+
dataTestId,
|
|
134
|
+
layoutVariant = 'normal',
|
|
135
|
+
zoomOnHover = false,
|
|
136
|
+
aspectRatio = 'none',
|
|
137
|
+
growWithContainer = false,
|
|
138
|
+
handleClick,
|
|
139
|
+
}: ProductCardProps) => {
|
|
140
|
+
// const orgUIConfig = useAtomValue(orgUIConfigAtom);
|
|
141
|
+
// const { productCardConfig } = orgUIConfig;
|
|
142
|
+
|
|
143
|
+
const finalVariant = variant ?? productCardConfig?.variant ?? 'filled';
|
|
144
|
+
const finalHoverVariant = hoverVariant ?? productCardConfig?.hoverVariant ?? 'backgroundDark';
|
|
145
|
+
const finalLayoutVariant = layoutVariant ?? productCardConfig?.layoutVariant ?? 'normal';
|
|
146
|
+
const pricePrefix = productCardConfig?.pricePrefix;
|
|
147
|
+
|
|
148
|
+
if (productCardConfig == null) {
|
|
149
|
+
Logger.logError('[ProductCard] productCardConfig is null', undefined, {
|
|
150
|
+
merchant: merchantShortName,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const layoutClasses = productCardLayoutVariantClasses[finalLayoutVariant];
|
|
157
|
+
|
|
158
|
+
const containerClassnames = classNames(
|
|
159
|
+
'spiffy-tw-cursor-pointer',
|
|
160
|
+
'spiffy-tw-flex',
|
|
161
|
+
'spiffy-tw-flex-col',
|
|
162
|
+
'spiffy-tw-gap-inherit',
|
|
163
|
+
'spiffy-tw-overflow-hidden',
|
|
164
|
+
{
|
|
165
|
+
'spiffy-tw-h-full': growWithContainer,
|
|
166
|
+
'spiffy-tw-w-full': growWithContainer,
|
|
167
|
+
'spiffy-tw-max-w-full': growWithContainer,
|
|
168
|
+
},
|
|
169
|
+
!growWithContainer && layoutClasses.container,
|
|
170
|
+
variantClassMap.get(finalVariant) ?? [],
|
|
171
|
+
variantHoverClassMap.get(finalHoverVariant) ?? [],
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const verticalContainerVariantClasses =
|
|
175
|
+
productCardLayoutVariantClasses[layoutVariant].verticalContainer;
|
|
176
|
+
|
|
177
|
+
const verticalContainerClassnames = classNames(
|
|
178
|
+
'spiffy-tw-flex',
|
|
179
|
+
'spiffy-tw-flex-col',
|
|
180
|
+
'spiffy-tw-overflow-hidden',
|
|
181
|
+
'spiffy-tw-gap-inherit',
|
|
182
|
+
{
|
|
183
|
+
'spiffy-tw-h-full': growWithContainer,
|
|
184
|
+
'spiffy-tw-w-full': growWithContainer,
|
|
185
|
+
'spiffy-tw-flex-1': growWithContainer,
|
|
186
|
+
},
|
|
187
|
+
...(!growWithContainer && layoutVariant ? verticalContainerVariantClasses : []),
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const linkClassnames = classNames({
|
|
191
|
+
'spiffy-tw-w-full': true,
|
|
192
|
+
'spiffy-tw-h-full': true,
|
|
193
|
+
'spiffy-tw-overflow-hidden': true,
|
|
194
|
+
'spiffy-tw-select-none': true,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Fixed outer container that maintains size and clips overflow
|
|
198
|
+
// This is useful for zoomOnHover and aspect ratio enforcement
|
|
199
|
+
const imageClipContainerClassnames = classNames(
|
|
200
|
+
'spiffy-tw-w-full',
|
|
201
|
+
'spiffy-tw-overflow-hidden', // This clips any content that exceeds boundaries
|
|
202
|
+
{
|
|
203
|
+
'spiffy-tw-flex-shrink-0': growWithContainer,
|
|
204
|
+
|
|
205
|
+
'spiffy-tw-tw-h-full': !growWithContainer,
|
|
206
|
+
},
|
|
207
|
+
aspectRatio === '3:4' ? 'spiffy-tw-aspect-[3/4]' : '',
|
|
208
|
+
aspectRatio === 'square' ? 'spiffy-tw-aspect-square' : '',
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
// Inner container that can scale for zoom effect
|
|
212
|
+
const imageContainerClassnames = classNames(
|
|
213
|
+
linkClassnames,
|
|
214
|
+
zoomOnHover
|
|
215
|
+
? [
|
|
216
|
+
'spiffy-tw-transition-transform',
|
|
217
|
+
'spiffy-tw-duration-200',
|
|
218
|
+
'spiffy-tw-origin-top',
|
|
219
|
+
'hover:spiffy-tw-scale-105',
|
|
220
|
+
]
|
|
221
|
+
: [],
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const contentClassnames = classNames(
|
|
225
|
+
'spiffy-tw-flex',
|
|
226
|
+
'spiffy-tw-flex-col',
|
|
227
|
+
'spiffy-tw-p-2',
|
|
228
|
+
'spiffy-tw-pr-2',
|
|
229
|
+
'spiffy-tw-items-start',
|
|
230
|
+
'spiffy-tw-justify-end',
|
|
231
|
+
{
|
|
232
|
+
'spiffy-tw-flex-grow-0': layoutVariant === 'tall' || layoutVariant === 'square',
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const productTitleClassnames = classNames(
|
|
237
|
+
'spiffy-tw-line-clamp-2',
|
|
238
|
+
'spiffy-tw-overflow-clip',
|
|
239
|
+
'spiffy-tw-tracking-[0.8px]',
|
|
240
|
+
'spiffy-tw-whitespace-normal',
|
|
241
|
+
'spiffy-tw-normal-case',
|
|
242
|
+
variantTitleColorMap.get(finalVariant) ?? 'spiffy-tw-text-[--spiffy-colors-text-primary]',
|
|
243
|
+
...layoutClasses.productTitle,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const priceAndRatingContainerClassnames = classNames(
|
|
247
|
+
'spiffy-tw-flex',
|
|
248
|
+
'spiffy-tw-flex-row',
|
|
249
|
+
'spiffy-tw-justify-between',
|
|
250
|
+
'spiffy-tw-items-center',
|
|
251
|
+
'spiffy-tw-w-full',
|
|
252
|
+
'spiffy-tw-pt-2',
|
|
253
|
+
'spiffy-tw-gap-2',
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const imageClassnames = classNames(
|
|
257
|
+
'spiffy-tw-bg-transparent',
|
|
258
|
+
'spiffy-tw-w-full',
|
|
259
|
+
'spiffy-tw-h-full',
|
|
260
|
+
'spiffy-tw-object-cover',
|
|
261
|
+
'spiffy-tw-object-top',
|
|
262
|
+
'spiffy-tw-select-none',
|
|
263
|
+
'spiffy-tw-pointer-events-none',
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<div className={containerClassnames} data-testid={dataTestId}>
|
|
268
|
+
<a href={url} onClick={() => handleClick(url || '')} target="_self" draggable={false}>
|
|
269
|
+
<div className={verticalContainerClassnames}>
|
|
270
|
+
<div className={imageClipContainerClassnames}>
|
|
271
|
+
<div className={imageContainerClassnames}>
|
|
272
|
+
{imageUrl && (
|
|
273
|
+
<ImageWithFallback
|
|
274
|
+
// TODO: Fix once
|
|
275
|
+
// src={resolve(imageUrl, layoutVariant === 'tall' ? 300 : 178)}
|
|
276
|
+
src={imageUrl}
|
|
277
|
+
alt={title}
|
|
278
|
+
fallback={<Spinner className="spiffy-tw-w-6 spiffy-tw-h-6" />}
|
|
279
|
+
imageClassnames={imageClassnames}
|
|
280
|
+
/>
|
|
281
|
+
)}
|
|
282
|
+
</div>
|
|
283
|
+
</div>
|
|
284
|
+
<div className={contentClassnames}>
|
|
285
|
+
<Headline variant="h4" className={productTitleClassnames}>
|
|
286
|
+
{title}
|
|
287
|
+
</Headline>
|
|
288
|
+
<div className={priceAndRatingContainerClassnames}>
|
|
289
|
+
{(originalPrice || salePrice) && (
|
|
290
|
+
<PriceSection
|
|
291
|
+
originalPrice={formatPrice(originalPrice)}
|
|
292
|
+
salePrice={formatPrice(salePrice)}
|
|
293
|
+
pricePrefix={pricePrefix}
|
|
294
|
+
/>
|
|
295
|
+
)}
|
|
296
|
+
{averageRating && numberReviews && (
|
|
297
|
+
<RatingSummary stars={averageRating} reviewCount={numberReviews} />
|
|
298
|
+
)}
|
|
299
|
+
</div>
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
</a>
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { ProductCardSkeletonOverrides, type ProductCardLayoutVariant } from './types';
|
|
4
|
+
import { productCardLayoutVariantClasses } from './productCardVariants';
|
|
5
|
+
|
|
6
|
+
interface ProductCardSkeletonProps {
|
|
7
|
+
layoutVariant: ProductCardLayoutVariant;
|
|
8
|
+
aspectRatio?: '3:4' | 'square' | 'none';
|
|
9
|
+
growWithContainer?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const ProductCardSkeleton: FC<ProductCardSkeletonProps> = ({
|
|
13
|
+
layoutVariant,
|
|
14
|
+
aspectRatio,
|
|
15
|
+
growWithContainer = false,
|
|
16
|
+
}) => {
|
|
17
|
+
const finalLayoutVariant = layoutVariant || 'normal';
|
|
18
|
+
const layoutClasses = productCardLayoutVariantClasses[finalLayoutVariant];
|
|
19
|
+
|
|
20
|
+
const containerClasses = classNames(
|
|
21
|
+
ProductCardSkeletonOverrides.PRODUCT_CARD_SKELETON_CONTAINER,
|
|
22
|
+
'spiffy-tw-flex',
|
|
23
|
+
'spiffy-tw-flex-col',
|
|
24
|
+
'spiffy-tw-gap-inherit',
|
|
25
|
+
'spiffy-tw-bg-transparent',
|
|
26
|
+
!growWithContainer ? layoutClasses.container : '',
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const verticalContainerClasses = classNames(
|
|
30
|
+
'spiffy-tw-flex',
|
|
31
|
+
'spiffy-tw-flex-col',
|
|
32
|
+
'spiffy-tw-overflow-hidden',
|
|
33
|
+
'spiffy-tw-gap-inherit',
|
|
34
|
+
!growWithContainer ? layoutClasses.verticalContainer : '',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const imageClipContainerClasses = classNames(
|
|
38
|
+
'spiffy-tw-w-full',
|
|
39
|
+
aspectRatio === '3:4' ? 'spiffy-tw-aspect-[3/4]' : '',
|
|
40
|
+
aspectRatio === 'square' ? 'spiffy-tw-aspect-square' : '',
|
|
41
|
+
'spiffy-tw-overflow-hidden',
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const imageSkeletonClasses = classNames(
|
|
45
|
+
'spiffy-tw-bg-[#F4F4F6]',
|
|
46
|
+
'spiffy-tw-animate-pulse',
|
|
47
|
+
'spiffy-tw-opacity-70',
|
|
48
|
+
'spiffy-tw-w-full',
|
|
49
|
+
'spiffy-tw-h-full',
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const contentContainerClasses = classNames(
|
|
53
|
+
'spiffy-tw-flex',
|
|
54
|
+
'spiffy-tw-flex-col',
|
|
55
|
+
'spiffy-tw-gap-2',
|
|
56
|
+
'spiffy-tw-w-full',
|
|
57
|
+
'spiffy-tw-p-2',
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const textSkeletonClasses = classNames(
|
|
61
|
+
ProductCardSkeletonOverrides.PRODUCT_CARD_SKELETON,
|
|
62
|
+
'spiffy-tw-h-[15px]',
|
|
63
|
+
'spiffy-tw-block',
|
|
64
|
+
'spiffy-tw-rounded-sm',
|
|
65
|
+
'spiffy-tw-animate-pulse',
|
|
66
|
+
'spiffy-tw-opacity-70',
|
|
67
|
+
'spiffy-tw-bg-[#F4F4F6]',
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div className={containerClasses}>
|
|
72
|
+
<div className={verticalContainerClasses}>
|
|
73
|
+
<div className={imageClipContainerClasses}>
|
|
74
|
+
<div className={imageSkeletonClasses} />
|
|
75
|
+
</div>
|
|
76
|
+
<div className={contentContainerClasses}>
|
|
77
|
+
<div className={classNames(textSkeletonClasses, 'spiffy-tw-w-full')} />
|
|
78
|
+
<div className={classNames(textSkeletonClasses, 'spiffy-tw-w-[60%]')} />
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
};
|