@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.
Files changed (151) hide show
  1. package/LICENSE +2 -0
  2. package/package.json +10 -7
  3. package/src/atoms/search/types.ts +5 -0
  4. package/src/components/common/ButtonBase/ButtonBase.tsx +70 -0
  5. package/src/components/common/ButtonBase/types.ts +27 -0
  6. package/src/components/common/Headline/Headline.tsx +81 -0
  7. package/src/components/common/ImageWithFallback/ImageWithFallback.tsx +66 -0
  8. package/src/components/common/ProductCard/ProductCard.tsx +305 -0
  9. package/src/components/common/ProductCard/ProductCardSkeleton.tsx +83 -0
  10. package/src/components/common/ProductCard/productCardVariants.ts +63 -0
  11. package/src/components/common/ProductCard/types.ts +49 -0
  12. package/src/components/common/ProductGrid/ProductGrid.tsx +73 -0
  13. package/src/components/common/ProductGrid/productGridVariants.ts +31 -0
  14. package/src/components/common/SparkleAnimation/SparkleAnimation.tsx +105 -0
  15. package/src/components/common/SparkleAnimation/types.ts +6 -0
  16. package/src/components/common/Spinner/Spinner.tsx +30 -0
  17. package/src/components/common/SuggestionButton/SuggestionButton.tsx +258 -0
  18. package/src/components/common/SuggestionButton/types.ts +14 -0
  19. package/src/components/common/Text/Text.tsx +58 -0
  20. package/src/components/common/Text/textVariantClasses.ts +106 -0
  21. package/src/components/common/Text/types.ts +23 -0
  22. package/src/components/common/TextInput/TextInput.tsx +34 -0
  23. package/src/components/models/colorsConfig.ts +28 -0
  24. package/src/components/search/FilterScrollbar/AppliedFiltersScrollbar.tsx +70 -0
  25. package/src/components/search/FilterScrollbar/DynamicFiltersScrollbar.tsx +52 -0
  26. package/src/components/search/SearchFilter/SearchFilter.tsx +84 -0
  27. package/src/components/search/SearchFilter/SearchFilterHeader.tsx +42 -0
  28. package/src/components/search/SearchFilter/SearchFilterItem.tsx +42 -0
  29. package/src/components/search/SearchFilter/types.ts +48 -0
  30. package/src/components/search/SearchInput/SearchInput.tsx +135 -0
  31. package/src/components/search/SearchInput/searchInputVariants.ts +27 -0
  32. package/src/components/search/SearchInputAutocomplete/SearchAutocomplete.tsx +62 -0
  33. package/src/components/search/SearchInputForm/SearchInputForm.tsx +66 -0
  34. package/src/components/search/SearchResultsFilterSidebar/SearchResultsFilter.tsx +82 -0
  35. package/src/components/search/SearchResultsFilterSidebar/searchFilterSidebarVariants.ts +45 -0
  36. package/{dist/packages/components/src/components/search/SearchResultsFilterSidebar/types.d.ts → src/components/search/SearchResultsFilterSidebar/types.ts} +1 -1
  37. package/src/components/search/SearchResultsStates/NoSearchResultsFound.tsx +41 -0
  38. package/src/components/search/SearchResultsStates/SearchResultsGrid.tsx +105 -0
  39. package/src/components/search/SearchResultsStates/SearchResultsLoadingGrid.tsx +50 -0
  40. package/src/components/search/types.ts +5 -0
  41. package/{dist/packages/components/src/components/test/types.d.ts → src/components/test/types.ts} +1 -1
  42. package/src/config/chatElementDisplayLocation.ts +22 -0
  43. package/{dist/packages/components/src/index.js → src/index.ts} +10 -0
  44. package/src/logging/logger.ts +21 -0
  45. package/src/types/external.ts +24 -0
  46. package/{dist/packages/components/src/util/camelCase.d.ts → src/util/camelCase.ts} +33 -11
  47. package/src/util/camelCasedPropertiesDeep.ts +81 -0
  48. package/src/util/formatPrice.ts +14 -0
  49. package/src/util/internal.ts +95 -0
  50. package/{dist/packages/components/src/util/primitive.d.ts → src/util/primitive.ts} +2 -0
  51. package/src/util/splitWords.ts +72 -0
  52. package/{dist/packages/components/src/util/trim.d.ts → src/util/trim.ts} +5 -1
  53. package/dist/packages/components/src/atoms/search/types.d.ts +0 -5
  54. package/dist/packages/components/src/atoms/search/types.js +0 -1
  55. package/dist/packages/components/src/components/common/ButtonBase/ButtonBase.d.ts +0 -2
  56. package/dist/packages/components/src/components/common/ButtonBase/ButtonBase.js +0 -41
  57. package/dist/packages/components/src/components/common/ButtonBase/types.d.ts +0 -24
  58. package/dist/packages/components/src/components/common/ButtonBase/types.js +0 -6
  59. package/dist/packages/components/src/components/common/Headline/Headline.d.ts +0 -10
  60. package/dist/packages/components/src/components/common/Headline/Headline.js +0 -34
  61. package/dist/packages/components/src/components/common/ImageWithFallback/ImageWithFallback.d.ts +0 -12
  62. package/dist/packages/components/src/components/common/ImageWithFallback/ImageWithFallback.js +0 -26
  63. package/dist/packages/components/src/components/common/ProductCard/ProductCard.d.ts +0 -39
  64. package/dist/packages/components/src/components/common/ProductCard/ProductCard.js +0 -83
  65. package/dist/packages/components/src/components/common/ProductCard/ProductCardSkeleton.d.ts +0 -9
  66. package/dist/packages/components/src/components/common/ProductCard/ProductCardSkeleton.js +0 -15
  67. package/dist/packages/components/src/components/common/ProductCard/productCardVariants.d.ts +0 -8
  68. package/dist/packages/components/src/components/common/ProductCard/productCardVariants.js +0 -50
  69. package/dist/packages/components/src/components/common/ProductCard/types.d.ts +0 -39
  70. package/dist/packages/components/src/components/common/ProductCard/types.js +0 -10
  71. package/dist/packages/components/src/components/common/ProductGrid/ProductGrid.d.ts +0 -14
  72. package/dist/packages/components/src/components/common/ProductGrid/ProductGrid.js +0 -13
  73. package/dist/packages/components/src/components/common/ProductGrid/productGridVariants.d.ts +0 -10
  74. package/dist/packages/components/src/components/common/ProductGrid/productGridVariants.js +0 -16
  75. package/dist/packages/components/src/components/common/SparkleAnimation/SparkleAnimation.d.ts +0 -7
  76. package/dist/packages/components/src/components/common/SparkleAnimation/SparkleAnimation.js +0 -40
  77. package/dist/packages/components/src/components/common/SparkleAnimation/types.d.ts +0 -6
  78. package/dist/packages/components/src/components/common/SparkleAnimation/types.js +0 -7
  79. package/dist/packages/components/src/components/common/Spinner/Spinner.d.ts +0 -5
  80. package/dist/packages/components/src/components/common/Spinner/Spinner.js +0 -16
  81. package/dist/packages/components/src/components/common/SuggestionButton/SuggestionButton.d.ts +0 -18
  82. package/dist/packages/components/src/components/common/SuggestionButton/SuggestionButton.js +0 -210
  83. package/dist/packages/components/src/components/common/SuggestionButton/types.d.ts +0 -1
  84. package/dist/packages/components/src/components/common/SuggestionButton/types.js +0 -1
  85. package/dist/packages/components/src/components/common/Text/Text.d.ts +0 -12
  86. package/dist/packages/components/src/components/common/Text/Text.js +0 -26
  87. package/dist/packages/components/src/components/common/Text/textVariantClasses.d.ts +0 -171
  88. package/dist/packages/components/src/components/common/Text/textVariantClasses.js +0 -103
  89. package/dist/packages/components/src/components/common/Text/types.d.ts +0 -16
  90. package/dist/packages/components/src/components/common/Text/types.js +0 -6
  91. package/dist/packages/components/src/components/common/TextInput/TextInput.d.ts +0 -8
  92. package/dist/packages/components/src/components/common/TextInput/TextInput.js +0 -25
  93. package/dist/packages/components/src/components/models/colorsConfig.d.ts +0 -26
  94. package/dist/packages/components/src/components/models/colorsConfig.js +0 -23
  95. package/dist/packages/components/src/components/search/FilterScrollbar/AppliedFiltersScrollbar.d.ts +0 -11
  96. package/dist/packages/components/src/components/search/FilterScrollbar/AppliedFiltersScrollbar.js +0 -18
  97. package/dist/packages/components/src/components/search/FilterScrollbar/DynamicFiltersScrollbar.d.ts +0 -15
  98. package/dist/packages/components/src/components/search/FilterScrollbar/DynamicFiltersScrollbar.js +0 -15
  99. package/dist/packages/components/src/components/search/SearchFilter/SearchFilter.d.ts +0 -2
  100. package/dist/packages/components/src/components/search/SearchFilter/SearchFilter.js +0 -24
  101. package/dist/packages/components/src/components/search/SearchFilter/SearchFilterHeader.d.ts +0 -2
  102. package/dist/packages/components/src/components/search/SearchFilter/SearchFilterHeader.js +0 -9
  103. package/dist/packages/components/src/components/search/SearchFilter/SearchFilterItem.d.ts +0 -2
  104. package/dist/packages/components/src/components/search/SearchFilter/SearchFilterItem.js +0 -13
  105. package/dist/packages/components/src/components/search/SearchFilter/types.d.ts +0 -42
  106. package/dist/packages/components/src/components/search/SearchFilter/types.js +0 -1
  107. package/dist/packages/components/src/components/search/SearchInput/SearchInput.d.ts +0 -16
  108. package/dist/packages/components/src/components/search/SearchInput/SearchInput.js +0 -38
  109. package/dist/packages/components/src/components/search/SearchInput/searchInputVariants.d.ts +0 -13
  110. package/dist/packages/components/src/components/search/SearchInput/searchInputVariants.js +0 -12
  111. package/dist/packages/components/src/components/search/SearchInputAutocomplete/SearchAutocomplete.d.ts +0 -10
  112. package/dist/packages/components/src/components/search/SearchInputAutocomplete/SearchAutocomplete.js +0 -14
  113. package/dist/packages/components/src/components/search/SearchInputForm/SearchInputForm.d.ts +0 -16
  114. package/dist/packages/components/src/components/search/SearchInputForm/SearchInputForm.js +0 -13
  115. package/dist/packages/components/src/components/search/SearchInputForm/types.js +0 -1
  116. package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/SearchResultsFilter.d.ts +0 -14
  117. package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/SearchResultsFilter.js +0 -15
  118. package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/searchFilterSidebarVariants.d.ts +0 -16
  119. package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/searchFilterSidebarVariants.js +0 -29
  120. package/dist/packages/components/src/components/search/SearchResultsFilterSidebar/types.js +0 -1
  121. package/dist/packages/components/src/components/search/SearchResultsStates/NoSearchResultsFound.d.ts +0 -8
  122. package/dist/packages/components/src/components/search/SearchResultsStates/NoSearchResultsFound.js +0 -10
  123. package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsGrid.d.ts +0 -24
  124. package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsGrid.js +0 -19
  125. package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsLoadingGrid.d.ts +0 -6
  126. package/dist/packages/components/src/components/search/SearchResultsStates/SearchResultsLoadingGrid.js +0 -10
  127. package/dist/packages/components/src/components/search/types.d.ts +0 -5
  128. package/dist/packages/components/src/components/search/types.js +0 -6
  129. package/dist/packages/components/src/components/test/types.js +0 -1
  130. package/dist/packages/components/src/config/chatElementDisplayLocation.d.ts +0 -21
  131. package/dist/packages/components/src/config/chatElementDisplayLocation.js +0 -23
  132. package/dist/packages/components/src/index.d.ts +0 -45
  133. package/dist/packages/components/src/logging/logger.d.ts +0 -7
  134. package/dist/packages/components/src/logging/logger.js +0 -16
  135. package/dist/packages/components/src/types/external.d.ts +0 -21
  136. package/dist/packages/components/src/types/external.js +0 -5
  137. package/dist/packages/components/src/util/camelCase.js +0 -2
  138. package/dist/packages/components/src/util/camelCasedPropertiesDeep.d.ts +0 -53
  139. package/dist/packages/components/src/util/camelCasedPropertiesDeep.js +0 -1
  140. package/dist/packages/components/src/util/formatPrice.d.ts +0 -1
  141. package/dist/packages/components/src/util/formatPrice.js +0 -11
  142. package/dist/packages/components/src/util/internal.d.ts +0 -27
  143. package/dist/packages/components/src/util/internal.js +0 -4
  144. package/dist/packages/components/src/util/primitive.js +0 -2
  145. package/dist/packages/components/src/util/splitWords.d.ts +0 -55
  146. package/dist/packages/components/src/util/splitWords.js +0 -2
  147. package/dist/packages/components/src/util/trim.js +0 -2
  148. package/dist/packages/components/src/util/unknownArray.js +0 -1
  149. package/dist/tsconfig.tsbuildinfo +0 -1
  150. /package/{dist/packages/components/src/components/search/SearchInputForm/types.d.ts → src/components/search/SearchInputForm/types.ts} +0 -0
  151. /package/{dist/packages/components/src/util/unknownArray.d.ts → src/util/unknownArray.ts} +0 -0
@@ -0,0 +1,63 @@
1
+ import type {
2
+ ProductCardVariant,
3
+ ProductCardHoverVariant,
4
+ ProductCardLayoutVariant,
5
+ } from './types';
6
+
7
+ /**
8
+ * Shared variant mapping configurations for ProductCard components
9
+ */
10
+
11
+ export const variantClassMap = new Map<ProductCardVariant, string[]>([
12
+ ['filled', ['spiffy-tw-bg-[--spiffy-colors-background-secondary]', 'spiffy-tw-shadow-md']],
13
+ [
14
+ 'bordered',
15
+ [
16
+ 'spiffy-tw-bg-[--spiffy-colors-background-secondary]',
17
+ 'spiffy-tw-border',
18
+ 'spiffy-tw-border-[--spiffy-colors-border-light]',
19
+ ],
20
+ ],
21
+ ['minimal', ['spiffy-tw-bg-transparent']],
22
+ [
23
+ 'transparentBordered',
24
+ [
25
+ 'spiffy-tw-bg-transparent',
26
+ 'spiffy-tw-border',
27
+ 'spiffy-tw-border-[--spiffy-colors-border-light]',
28
+ ],
29
+ ],
30
+ ]);
31
+
32
+ export const variantHoverClassMap = new Map<ProductCardHoverVariant, string[]>([
33
+ ['backgroundDark', ['hover:spiffy-tw-bg-[--spiffy-colors-background-secondary-dark]']],
34
+ ['none', []],
35
+ ]);
36
+
37
+ export const variantTitleColorMap = new Map<ProductCardVariant, string>([
38
+ ['filled', 'spiffy-tw-text-[--spiffy-colors-text-link]'],
39
+ ['bordered', 'spiffy-tw-text-[--spiffy-colors-text-primary]'],
40
+ ['minimal', 'spiffy-tw-text-[--spiffy-colors-text-primary]'],
41
+ ['transparentBordered', 'spiffy-tw-text-[--spiffy-colors-text-primary]'],
42
+ ]);
43
+
44
+ export const productCardLayoutVariantClasses: Record<
45
+ ProductCardLayoutVariant,
46
+ Record<string, string[]>
47
+ > = {
48
+ normal: {
49
+ productTitle: ['spiffy-product-card-title'],
50
+ container: ['spiffy-tw-w-[208px]'],
51
+ verticalContainer: ['spiffy-tw-rounded-[8px]', 'spiffy-tw-h-[268px]'],
52
+ },
53
+ tall: {
54
+ productTitle: ['spiffy-product-card-title-tall', 'spiffy-tw-pt-[8px]'],
55
+ container: ['spiffy-tw-w-[160px] lg:spiffy-tw-w-[300px]'],
56
+ verticalContainer: ['lg:spiffy-tw-h-[496px]'],
57
+ },
58
+ square: {
59
+ productTitle: ['spiffy-product-card-title-tall', 'spiffy-tw-pt-[8px]'],
60
+ container: ['spiffy-tw-w-[160px] lg:spiffy-tw-w-[280px]'],
61
+ verticalContainer: ['lg:spiffy-tw-h-[400px]'],
62
+ },
63
+ };
@@ -0,0 +1,49 @@
1
+ import type { ResponseCategory, SearchResponseProduct } from 'src/types/external';
2
+ import type { CamelCasedPropertiesDeep } from 'src/util/camelCasedPropertiesDeep';
3
+
4
+ export enum ProductCardSkeletonOverrides {
5
+ PRODUCT_CARD_SKELETON_CONTAINER = 'spiffy-product-card-skeleton-container',
6
+ PRODUCT_CARD_SKELETON = 'spiffy-product-card-skeleton',
7
+ }
8
+
9
+ export enum AnimatedProductCardOverrides {
10
+ PRODUCT_CARD_ANIMATED_CONTAINER = 'spiffy-product-card-animated-container',
11
+ PRODUCT_CARD_ANIMATED_IMAGE_CONTAINER = 'spiffy-product-card-animated',
12
+ }
13
+
14
+ export type ProductGridVariant = 'standard' | 'square';
15
+
16
+ export type ProductCardVariant = 'filled' | 'bordered' | 'minimal' | 'transparentBordered';
17
+
18
+ export type ProductCardHoverVariant = 'backgroundDark' | 'none';
19
+
20
+ export type ProductCardLayoutVariant = 'normal' | 'tall' | 'square';
21
+ export type ProductCardImageAspectRatio = '1/1' | '4/3' | '3/4' | '16/9' | '9/16';
22
+
23
+ export interface ProductCardConfig {
24
+ variant: ProductCardVariant;
25
+ hoverVariant: ProductCardHoverVariant;
26
+ layoutVariant: ProductCardLayoutVariant;
27
+ pricePrefix?: string;
28
+ }
29
+
30
+ export interface SearchResponseProductAttributes {
31
+ category: ResponseCategory.Product;
32
+ attributes: CamelCasedPropertiesDeep<SearchResponseProduct>;
33
+ }
34
+
35
+ export interface ProductCardSkeletonProps {
36
+ layoutVariant: ProductCardLayoutVariant;
37
+ aspectRatio: ProductCardImageAspectRatio;
38
+ growWithContainer?: boolean;
39
+ }
40
+
41
+ export interface ProductGridProps {
42
+ productList: SearchResponseProductAttributes['attributes'][];
43
+ productGridVariant: ProductGridVariant;
44
+ productGridClasses: string;
45
+ productCardConfig?: ProductCardConfig;
46
+ merchantShortName: string;
47
+ searchResponseId: string;
48
+ cardsGrowWithContainer?: boolean;
49
+ }
@@ -0,0 +1,73 @@
1
+ import type { ProductCardConfig, ProductGridVariant } from '../ProductCard/types';
2
+ import { ProductCard } from '../ProductCard/ProductCard';
3
+ import { productGridVariantClasses } from './productGridVariants';
4
+ import classNames from 'classnames';
5
+ import { ChatElementDisplayLocation } from 'src/config/chatElementDisplayLocation';
6
+ import { SearchResponseProduct } from 'src/types/external';
7
+
8
+ interface ProductGridProps {
9
+ productList: SearchResponseProduct[];
10
+ productGridVariant: ProductGridVariant;
11
+ productGridClasses: string;
12
+ productCardConfig?: ProductCardConfig;
13
+ merchantShortName: string;
14
+ searchResponseId: string;
15
+ cardsGrowWithContainer?: boolean;
16
+ handleClick: (clickedUrl: string) => void;
17
+ }
18
+
19
+ export const ProductGrid = ({
20
+ productList,
21
+ productGridVariant,
22
+ productGridClasses,
23
+ productCardConfig,
24
+ merchantShortName,
25
+ searchResponseId,
26
+ cardsGrowWithContainer = true,
27
+ handleClick,
28
+ }: ProductGridProps) => {
29
+ const {
30
+ productCardVariant,
31
+ productCardHoverVariant,
32
+ productCardLayoutVariant,
33
+ productCardImageAspectRatio,
34
+ zoomOnHover,
35
+ } = productGridVariantClasses[productGridVariant];
36
+
37
+ const cardContainerClasses = classNames({
38
+ 'spiffy-tw-w-full': cardsGrowWithContainer,
39
+ 'spiffy-tw-h-full': cardsGrowWithContainer,
40
+ });
41
+
42
+ return (
43
+ <div className={productGridClasses}>
44
+ {productList.map((product: (typeof productList)[0], index: number) => (
45
+ <div key={product.id} className={cardContainerClasses}>
46
+ <ProductCard
47
+ productCardConfig={productCardConfig}
48
+ merchantShortName={merchantShortName}
49
+ key={product.id}
50
+ imageUrl={product.imageUrl}
51
+ searchResponseId={searchResponseId}
52
+ productResponseId={product.responseId}
53
+ title={product.title}
54
+ url={product.url}
55
+ originalPrice={product.originalPrice}
56
+ salePrice={product.salePrice}
57
+ averageRating={product.averageRating}
58
+ numberReviews={product.numberReviews}
59
+ cardDisplayLocation={ChatElementDisplayLocation.PRODUCT_GRID}
60
+ layoutVariant={productCardLayoutVariant}
61
+ variant={productCardVariant}
62
+ hoverVariant={productCardHoverVariant}
63
+ zoomOnHover={zoomOnHover}
64
+ aspectRatio={productCardImageAspectRatio}
65
+ clickPosition={index}
66
+ growWithContainer={cardsGrowWithContainer}
67
+ handleClick={handleClick}
68
+ />
69
+ </div>
70
+ ))}
71
+ </div>
72
+ );
73
+ };
@@ -0,0 +1,31 @@
1
+ import type {
2
+ ProductCardHoverVariant,
3
+ ProductCardLayoutVariant,
4
+ ProductCardVariant,
5
+ ProductGridVariant,
6
+ } from '../ProductCard/types';
7
+
8
+ interface ProductGridVariantClasses {
9
+ productCardVariant: ProductCardVariant;
10
+ productCardHoverVariant: ProductCardHoverVariant;
11
+ productCardLayoutVariant: ProductCardLayoutVariant;
12
+ productCardImageAspectRatio: '3:4' | 'square' | 'none';
13
+ zoomOnHover: boolean;
14
+ }
15
+
16
+ export const productGridVariantClasses: Record<ProductGridVariant, ProductGridVariantClasses> = {
17
+ standard: {
18
+ productCardVariant: 'minimal',
19
+ productCardHoverVariant: 'backgroundDark',
20
+ productCardLayoutVariant: 'tall',
21
+ productCardImageAspectRatio: '3:4',
22
+ zoomOnHover: true,
23
+ },
24
+ square: {
25
+ productCardVariant: 'minimal',
26
+ productCardHoverVariant: 'backgroundDark',
27
+ productCardLayoutVariant: 'square',
28
+ productCardImageAspectRatio: 'square',
29
+ zoomOnHover: true,
30
+ },
31
+ };
@@ -0,0 +1,105 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { type Transition, motion } from 'framer-motion';
3
+ import classNames from 'classnames';
4
+
5
+ import FourPointStar from '@envive-ai/react-icons/src/FourPointStar';
6
+ import { SparkleAnimationOverride } from './types';
7
+
8
+ // Animation timing constants
9
+ const ANIMATION_CYCLE_TIME = 1000; // 1 second between cycles
10
+ const STAR_DELAY_OFFSET = 250; // 250ms delay between each star
11
+
12
+ interface SparkleAnimationProps {
13
+ color: string;
14
+ className?: string;
15
+ animate?: boolean; // Whether to animate the sparkles, defaults to true
16
+ }
17
+
18
+ export const SparkleAnimation = ({ color, className, animate = true }: SparkleAnimationProps) => {
19
+ // Star visibility states - start visible if not animating, invisible if animating
20
+ const [mainStarScale, setMainStarScale] = useState(animate ? 0 : 1);
21
+ const [smallStar1Scale, setSmallStar1Scale] = useState(animate ? 0 : 1);
22
+ const [smallStar2Scale, setSmallStar2Scale] = useState(animate ? 0 : 1);
23
+
24
+ // Container: 24px x 24px with relative positioning
25
+ const containerClasses = classNames(
26
+ SparkleAnimationOverride.CONTAINER,
27
+ 'spiffy-tw-w-6 spiffy-tw-h-6 spiffy-tw-relative',
28
+ className,
29
+ );
30
+
31
+ // When animation is disabled, ensure all stars are visible
32
+ useEffect(() => {
33
+ if (!animate) {
34
+ setMainStarScale(1);
35
+ setSmallStar1Scale(1);
36
+ setSmallStar2Scale(1);
37
+ return;
38
+ }
39
+ }, [animate]);
40
+
41
+ // Animation cycle effect
42
+ useEffect(() => {
43
+ if (!animate) return;
44
+
45
+ // Toggle between visible (1) and invisible (0)
46
+ const newScale = mainStarScale === 1 ? 0 : 1;
47
+
48
+ // Stagger the star animations
49
+ setTimeout(() => setMainStarScale(newScale), ANIMATION_CYCLE_TIME);
50
+ setTimeout(() => setSmallStar1Scale(newScale), ANIMATION_CYCLE_TIME + STAR_DELAY_OFFSET);
51
+ setTimeout(() => setSmallStar2Scale(newScale), ANIMATION_CYCLE_TIME + 2 * STAR_DELAY_OFFSET);
52
+ }, [mainStarScale, animate]);
53
+
54
+ // Animation transition settings
55
+ const starTransition: Transition = { duration: 0.3, ease: 'easeOut' };
56
+
57
+ return (
58
+ <div className={containerClasses}>
59
+ {/* Main star - center, slightly above container */}
60
+ <div
61
+ className={classNames(
62
+ SparkleAnimationOverride.STAR_ONE_CONTAINER,
63
+ 'spiffy-tw-absolute -spiffy-tw-top-[2px] spiffy-tw-left-0',
64
+ )}
65
+ >
66
+ <motion.div animate={{ scale: mainStarScale }} transition={starTransition}>
67
+ <FourPointStar
68
+ fill={color}
69
+ className="spiffy-tw-w-4 spiffy-tw-h-4 spiffy-tw-inline-block"
70
+ />
71
+ </motion.div>
72
+ </div>
73
+
74
+ {/* Small star 1 - upper right */}
75
+ <div
76
+ className={classNames(
77
+ SparkleAnimationOverride.STAR_TWO_CONTAINER,
78
+ 'spiffy-tw-absolute -spiffy-tw-top-[7px] spiffy-tw-left-[10px]',
79
+ )}
80
+ >
81
+ <motion.div animate={{ scale: smallStar1Scale }} transition={starTransition}>
82
+ <FourPointStar
83
+ fill={color}
84
+ className="spiffy-tw-w-2 spiffy-tw-h-2 spiffy-tw-inline-block"
85
+ />
86
+ </motion.div>
87
+ </div>
88
+
89
+ {/* Small star 2 - lower right */}
90
+ <div
91
+ className={classNames(
92
+ SparkleAnimationOverride.STAR_THREE_CONTAINER,
93
+ 'spiffy-tw-absolute spiffy-tw-top-[1px] spiffy-tw-left-[12px]',
94
+ )}
95
+ >
96
+ <motion.div animate={{ scale: smallStar2Scale }} transition={starTransition}>
97
+ <FourPointStar
98
+ fill={color}
99
+ className="spiffy-tw-w-2 spiffy-tw-h-2 spiffy-tw-inline-block"
100
+ />
101
+ </motion.div>
102
+ </div>
103
+ </div>
104
+ );
105
+ };
@@ -0,0 +1,6 @@
1
+ export enum SparkleAnimationOverride {
2
+ CONTAINER = 'spiffy-sparkle-animation-container',
3
+ STAR_ONE_CONTAINER = 'spiffy-sparkle-animation-star-one-container',
4
+ STAR_TWO_CONTAINER = 'spiffy-sparkle-animation-star-two-container',
5
+ STAR_THREE_CONTAINER = 'spiffy-sparkle-animation-star-three-container',
6
+ }
@@ -0,0 +1,30 @@
1
+ import classNames from "classnames";
2
+
3
+ type SpinnerProps = {
4
+ className?: string;
5
+ }
6
+
7
+ export const Spinner = ({ className }: SpinnerProps) => {
8
+ const svgClassnames = classNames({
9
+ 'spiffy-tw-w-4': true,
10
+ 'spiffy-tw-h-4': true,
11
+ 'spiffy-tw-text-gray-200': true,
12
+ 'spiffy-tw-animate-spin': true,
13
+ 'spiffy-tw-dark:text-gray-600': true,
14
+ 'spiffy-tw-fill-black': true,
15
+ }, className);
16
+
17
+ const spanClassnames = classNames({
18
+ 'spiffy-tw-sr-only': true,
19
+ });
20
+
21
+ return (
22
+ <div role="status">
23
+ <svg aria-hidden="true" className={svgClassnames} viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
24
+ <path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
25
+ <path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
26
+ </svg>
27
+ <span className={spanClassnames}>Loading...</span>
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,258 @@
1
+ import classNames from 'classnames';
2
+ import OutlinedStar from '@envive-ai/react-icons/src/OutlinedStar';
3
+ import FourPointStar from '@envive-ai/react-icons/src/FourPointStar';
4
+ import type { SuggestionButtonVariant } from './types';
5
+ import { ButtonBase } from '../ButtonBase/ButtonBase';
6
+ import { TestProps } from '../../test/types';
7
+
8
+ export const SPIFFY_SUGGESTION_BUTTON_QUESTION_CLASS = 'spiffy-suggestion-button-question-class';
9
+ export const SPIFFY_SUGGESTION_BUTTON_ANSWER_CLASS = 'spiffy-suggestion-button-answer-class';
10
+ export const SPIFFY_SUGGESTION_BUTTON_TEXT_CLASS = 'spiffy-suggestion-button-text-class';
11
+
12
+ // Add a comment that includes the hover prefix so that tailwind will pickup and generate the right css
13
+ // Common class patterns to avoid duplication
14
+ const BORDER_CLASS = 'spiffy-tw-border'; // hover:spiffy-tw-border
15
+ const TEXT_LINK_CLASSES = [
16
+ 'spiffy-tw-text-[--spiffy-colors-text-link]', // hover:spiffy-tw-text-[--spiffy-colors-text-link]
17
+ 'spiffy-tw-fill-[--spiffy-colors-text-link]', // hover:spiffy-tw-fill-[--spiffy-colors-text-link]
18
+ 'spiffy-tw-stroke-[--spiffy-colors-text-link]', // hover:spiffy-tw-stroke-[--spiffy-colors-text-link]
19
+ ];
20
+ const TEXT_LIGHT_CLASSES = [
21
+ 'spiffy-tw-text-[--spiffy-colors-text-light]', // hover:spiffy-tw-text-[--spiffy-colors-text-light]
22
+ 'spiffy-tw-fill-[--spiffy-colors-text-light]', // hover:spiffy-tw-fill-[--spiffy-colors-text-light]
23
+ 'spiffy-tw-stroke-[--spiffy-colors-text-light]', // hover:spiffy-tw-stroke-[--spiffy-colors-text-light]
24
+ ];
25
+ const TEXT_PRIMARY_CLASSES = [
26
+ 'spiffy-tw-text-[--spiffy-colors-text-primary]', // hover:spiffy-tw-text-[--spiffy-colors-text-primary]
27
+ 'spiffy-tw-fill-[--spiffy-colors-text-primary]', // hover:spiffy-tw-fill-[--spiffy-colors-text-primary]
28
+ 'spiffy-tw-stroke-[--spiffy-colors-text-primary]', // hover:spiffy-tw-stroke-[--spiffy-colors-text-primary]
29
+ ];
30
+ const ACCENT_PRIMARY_CLASSES = [
31
+ 'spiffy-tw-fill-[--spiffy-colors-accent-primary]', // hover:spiffy-tw-fill-[--spiffy-colors-accent-primary]
32
+ 'spiffy-tw-stroke-[--spiffy-colors-accent-primary]', // hover:spiffy-tw-stroke-[--spiffy-colors-accent-primary]
33
+ ];
34
+ const DARK_BACKGROUND_CLASSES = [
35
+ 'spiffy-tw-bg-[--spiffy-colors-background-dark]', // hover:spiffy-tw-bg-[--spiffy-colors-background-dark]
36
+ 'spiffy-tw-border-[--spiffy-colors-background-dark]', // hover:spiffy-tw-border-[--spiffy-colors-background-secondary]
37
+ ];
38
+ const SECONDARY_DARK_BACKGROUND_CLASSES = [
39
+ 'spiffy-tw-bg-[--spiffy-colors-background-secondary-dark]', // hover:spiffy-tw-bg-[--spiffy-colors-background-secondary-dark]
40
+ 'spiffy-tw-border-[--spiffy-colors-background-secondary-dark]', // hover:spiffy-tw-border-[--spiffy-colors-background-secondary-dark]
41
+ ];
42
+
43
+ const variantClassMap = new Map<SuggestionButtonVariant, string[]>([
44
+ [
45
+ 'outlined',
46
+ [
47
+ 'spiffy-tw-border-[--spiffy-colors-border-outline]', // hover:spiffy-tw-border-[--spiffy-colors-border-outline]
48
+ ...TEXT_LINK_CLASSES,
49
+ ],
50
+ ],
51
+ [
52
+ 'outlinedLight',
53
+ [
54
+ 'spiffy-tw-border-[--spiffy-colors-border-outline]', // hover:spiffy-tw-border-[--spiffy-colors-border-outline]
55
+ 'spiffy-tw-bg-[--spiffy-colors-background-light]', // hover:spiffy-tw-bg-[--spiffy-colors-background-light]
56
+ ...TEXT_LINK_CLASSES,
57
+ BORDER_CLASS,
58
+ ],
59
+ ],
60
+ [
61
+ 'primary',
62
+ [
63
+ 'spiffy-tw-bg-[--spiffy-colors-background-primary]', // hover:spiffy-tw-bg-[--spiffy-colors-background-primary]
64
+ 'spiffy-tw-border-[--spiffy-colors-background-primary]', // hover:spiffy-tw-border-[--spiffy-colors-background-secondary]
65
+ ...TEXT_LIGHT_CLASSES,
66
+ BORDER_CLASS,
67
+ ],
68
+ ],
69
+ [
70
+ 'secondary',
71
+ [
72
+ 'spiffy-tw-bg-[--spiffy-colors-background-secondary]', // hover:spiffy-tw-bg-[--spiffy-colors-background-secondary]
73
+ 'spiffy-tw-text-[--spiffy-colors-text-link]', // hover:spiffy-tw-text-[--spiffy-colors-text-link]
74
+ 'spiffy-tw-border-[--spiffy-colors-background-secondary]', // hover:spiffy-tw-border-[--spiffy-colors-background-secondary]
75
+ ...ACCENT_PRIMARY_CLASSES,
76
+ BORDER_CLASS,
77
+ ],
78
+ ],
79
+ [
80
+ 'tertiary',
81
+ [
82
+ 'spiffy-tw-bg-[--spiffy-colors-background-tertiary]', // hover:spiffy-tw-bg-[--spiffy-colors-background-tertiary]
83
+ 'spiffy-tw-border-[--spiffy-colors-background-tertiary]', // hover:spiffy-tw-border-[--spiffy-colors-background-secondary]
84
+ ...TEXT_LINK_CLASSES,
85
+ BORDER_CLASS,
86
+ ],
87
+ ],
88
+ ['dark', [...DARK_BACKGROUND_CLASSES, ...TEXT_LIGHT_CLASSES, BORDER_CLASS]],
89
+ [
90
+ 'darkPrimary',
91
+ [
92
+ ...DARK_BACKGROUND_CLASSES,
93
+ 'spiffy-tw-text-[--spiffy-colors-text-light]', // hover:spiffy-tw-text-[--spiffy-colors-text-light]
94
+ ...ACCENT_PRIMARY_CLASSES,
95
+ BORDER_CLASS,
96
+ ],
97
+ ],
98
+ [
99
+ 'darkAccent',
100
+ [
101
+ ...DARK_BACKGROUND_CLASSES,
102
+ 'spiffy-tw-text-[--spiffy-colors-text-light]', // hover:spiffy-tw-text-[--spiffy-colors-text-light]
103
+ 'spiffy-tw-fill-[--spiffy-colors-text-accent]', // hover:spiffy-tw-fill-[--spiffy-colors-text-accent]
104
+ 'spiffy-tw-stroke-[--spiffy-colors-text-accent]', // hover:spiffy-tw-stroke-[--spiffy-colors-text-accent]
105
+ BORDER_CLASS,
106
+ ],
107
+ ],
108
+ [
109
+ 'transparent',
110
+ [
111
+ 'spiffy-tw-bg-transparent', // hover:spiffy-tw-bg-transparent
112
+ 'spiffy-tw-border-[--spiffy-colors-background-light]', // hover:spiffy-tw-border-[--spiffy-colors-background-light]
113
+ 'spiffy-tw-text-[--spiffy-colors-text-light]', // hover:spiffy-tw-text-[--spiffy-colors-text-light]
114
+ 'spiffy-tw-fill-transparent', // hover:spiffy-tw-fill-transparent
115
+ 'spiffy-tw-stroke-[--spiffy-colors-text-light]', // hover:spiffy-tw-stroke-[--spiffy-colors-text-light]
116
+ BORDER_CLASS,
117
+ ],
118
+ ],
119
+ [
120
+ 'transparentDark',
121
+ [
122
+ 'spiffy-tw-bg-transparent', // hover:spiffy-tw-bg-transparent
123
+ 'spiffy-tw-border-[--spiffy-colors-border-light]', // hover:spiffy-tw-border-[--spiffy-colors-border-light]
124
+ 'spiffy-tw-text-[--spiffy-colors-text-primary]', // hover:spiffy-tw-text-[--spiffy-colors-text-primary]
125
+ 'spiffy-tw-fill-transparent', // hover:spiffy-tw-fill-transparent
126
+ 'spiffy-tw-stroke-[--spiffy-colors-text-primary]', // hover:spiffy-tw-stroke-[--spiffy-colors-text-primary]
127
+ BORDER_CLASS,
128
+ ],
129
+ ],
130
+ // This is used as the hover state for transparent
131
+ ['secondaryDark', [...SECONDARY_DARK_BACKGROUND_CLASSES, ...TEXT_LINK_CLASSES, BORDER_CLASS]],
132
+ [
133
+ 'secondaryAccent',
134
+ [
135
+ ...SECONDARY_DARK_BACKGROUND_CLASSES,
136
+ 'spiffy-tw-text-[--spiffy-colors-text-link]', // hover:spiffy-tw-text-[--spiffy-colors-text-link]
137
+ ...ACCENT_PRIMARY_CLASSES,
138
+ BORDER_CLASS,
139
+ ],
140
+ ],
141
+ [
142
+ 'lightDark',
143
+ [
144
+ 'spiffy-tw-bg-[--spiffy-colors-background-light]', // hover:spiffy-tw-bg-[--spiffy-colors-background-light]
145
+ 'spiffy-tw-border-[--spiffy-colors-background-dark]', // hover:spiffy-tw-border-[--spiffy-colors-background-dark]
146
+ ...TEXT_PRIMARY_CLASSES,
147
+ BORDER_CLASS,
148
+ ],
149
+ ],
150
+ ]);
151
+
152
+ interface SuggestionButtonProps extends TestProps {
153
+ variant: SuggestionButtonVariant;
154
+ hoverVariant: SuggestionButtonVariant;
155
+ isDisabled: boolean;
156
+ content: string;
157
+ boldText?: boolean;
158
+ borderRadius?: 'sm' | 'md' | 'lg';
159
+ isAnswer?: boolean;
160
+ dataAttributes?: Record<string, string>;
161
+ onClick: () => void;
162
+ }
163
+
164
+ const borderedVariants = [
165
+ 'outlined',
166
+ 'outlinedLight',
167
+ 'primary',
168
+ 'secondary',
169
+ 'tertiary',
170
+ 'dark',
171
+ 'darkAccent',
172
+ 'darkPrimary',
173
+ 'transparent',
174
+ 'transparentDark',
175
+ 'secondaryDark',
176
+ 'secondaryAccent',
177
+ 'lightDark',
178
+ ];
179
+
180
+ const hoverTransform = (variantClass: string[]): string[] =>
181
+ variantClass?.map((className) => `hover:${className}`);
182
+
183
+ export const SuggestionButton = ({
184
+ variant,
185
+ hoverVariant,
186
+ isDisabled,
187
+ content,
188
+ boldText,
189
+ borderRadius = 'lg',
190
+ isAnswer = false,
191
+ dataAttributes,
192
+ dataTestId,
193
+ onClick,
194
+ }: SuggestionButtonProps) => {
195
+ const buttonClassName = classNames({
196
+ [SPIFFY_SUGGESTION_BUTTON_QUESTION_CLASS]: !isAnswer,
197
+ [SPIFFY_SUGGESTION_BUTTON_ANSWER_CLASS]: isAnswer,
198
+ '!spiffy-tw-rounded-[20px]': borderRadius === 'lg',
199
+ '!spiffy-tw-rounded-[8px]': borderRadius === 'md',
200
+ '!spiffy-tw-rounded-[0px]': borderRadius === 'sm',
201
+ 'spiffy-tw-border-[1px]': borderedVariants.includes(variant),
202
+ 'spiffy-tw-border-solid': borderedVariants.includes(variant),
203
+ });
204
+ const textClassName = classNames({
205
+ 'spiffy-tw-text-[14px]': true,
206
+ 'spiffy-tw-leading-[100%]': true,
207
+ '!spiffy-tw-font-bold': boldText,
208
+ });
209
+
210
+ const iconClass = classNames({
211
+ 'spiffy-tw-w-[11px]': true,
212
+ 'spiffy-tw-h-[11px]': true,
213
+ 'spiffy-tw-stroke-inherit': true,
214
+ 'spiffy-tw-fill-inherit': true,
215
+ });
216
+
217
+ const baseClasses = variantClassMap.get(variant) ?? [];
218
+ const hoverClasses = variantClassMap.get(hoverVariant) ?? [];
219
+
220
+ // Separate border classes for proper cascading
221
+ const baseBorderClasses = baseClasses.filter((cls) => cls.includes('border'));
222
+ const baseNonBorderClasses = baseClasses.filter((cls) => !cls.includes('border'));
223
+ const hoverBorderClasses = hoverClasses.filter((cls) => cls.includes('border'));
224
+ const hoverNonBorderClasses = hoverClasses.filter((cls) => !cls.includes('border'));
225
+
226
+ const variantClasses = [
227
+ ...baseNonBorderClasses,
228
+ ...hoverTransform(hoverNonBorderClasses),
229
+ ...baseBorderClasses,
230
+ ...hoverTransform(hoverBorderClasses),
231
+ ];
232
+
233
+ const buttonClass = `${buttonClassName} ${variantClasses.join(' ')}`;
234
+
235
+ // Choose icon based on variant to match legacy exactly
236
+ const getIcon = () => {
237
+ if (isAnswer) return undefined;
238
+ if (variant === 'transparentDark') {
239
+ return OutlinedStar;
240
+ }
241
+ return FourPointStar;
242
+ };
243
+
244
+ return (
245
+ <ButtonBase
246
+ text={content}
247
+ dataAttributes={dataAttributes}
248
+ dataTestId={dataTestId}
249
+ isDisabled={isDisabled}
250
+ // we may want to support custom icons in the future
251
+ icon={getIcon()}
252
+ iconClass={isAnswer ? undefined : iconClass}
253
+ textClass={`${SPIFFY_SUGGESTION_BUTTON_TEXT_CLASS} ${textClassName}`}
254
+ buttonClass={buttonClass}
255
+ onClick={onClick}
256
+ />
257
+ );
258
+ };
@@ -0,0 +1,14 @@
1
+ export type SuggestionButtonVariant =
2
+ | 'outlined'
3
+ | 'outlinedLight'
4
+ | 'primary'
5
+ | 'secondary'
6
+ | 'tertiary'
7
+ | 'dark'
8
+ | 'darkAccent'
9
+ | 'darkPrimary'
10
+ | 'secondaryDark'
11
+ | 'secondaryAccent'
12
+ | 'transparent'
13
+ | 'transparentDark'
14
+ | 'lightDark';