|
1 | | -import React from 'react'; |
| 1 | +import React, { type ComponentProps } from 'react'; |
| 2 | +import { IconLoadingCircle } from '../Icons'; |
2 | 3 |
|
3 | | -// FIXME: remove color and size props and let the loading indicator to be styled via CSS |
4 | | -export type LoadingIndicatorProps = { |
5 | | - /** Set the color of the LoadingIndicator */ |
6 | | - color?: string; |
7 | | - /** The size of the loading icon, @default 15px */ |
8 | | - size?: number; |
9 | | -}; |
| 4 | +export type LoadingIndicatorProps = ComponentProps<typeof IconLoadingCircle>; |
10 | 5 |
|
11 | | -const UnMemoizedLoadingIndicator = (props: LoadingIndicatorProps) => { |
12 | | - const { color, size = 15 } = props; |
13 | | - const baseColor = 'var(--str-chat__loading-indicator-base-color)'; |
14 | | - const indicatorColor = color ?? 'var(--str-chat__loading-indicator-color)'; |
15 | | - |
16 | | - return ( |
17 | | - <div |
18 | | - className={`str-chat__loading-indicator`} |
19 | | - data-testid='loading-indicator-wrapper' |
20 | | - style={{ height: size, width: size }} |
21 | | - > |
22 | | - <svg |
23 | | - height={size} |
24 | | - viewBox={`0 0 30 30`} |
25 | | - width={size} |
26 | | - xmlns='http://www.w3.org/2000/svg' |
27 | | - > |
28 | | - <defs> |
29 | | - <linearGradient id='a' x1='50%' x2='50%' y1='0%' y2='100%'> |
30 | | - <stop |
31 | | - offset='0%' |
32 | | - stopColor={baseColor} |
33 | | - stopOpacity='0' |
34 | | - style={{ stopColor: baseColor }} |
35 | | - /> |
36 | | - <stop |
37 | | - data-testid='loading-indicator-circle' |
38 | | - offset='100%' |
39 | | - stopColor={indicatorColor} |
40 | | - stopOpacity='1' |
41 | | - style={{ stopColor: indicatorColor }} |
42 | | - /> |
43 | | - </linearGradient> |
44 | | - </defs> |
45 | | - <path |
46 | | - d='M2.518 23.321l1.664-1.11A12.988 12.988 0 0 0 15 28c7.18 0 13-5.82 13-13S22.18 2 15 2V0c8.284 0 15 6.716 15 15 0 8.284-6.716 15-15 15-5.206 0-9.792-2.652-12.482-6.679z' |
47 | | - fill='url(#a)' |
48 | | - fillRule='evenodd' |
49 | | - /> |
50 | | - </svg> |
51 | | - </div> |
52 | | - ); |
53 | | -}; |
54 | | - |
55 | | -/** |
56 | | - * Simple loading spinner |
57 | | - */ |
58 | | -export const LoadingIndicator = React.memo( |
59 | | - UnMemoizedLoadingIndicator, |
60 | | - (prevProps, nextProps) => |
61 | | - prevProps.color === nextProps.color && prevProps.size === nextProps.size, |
62 | | -) as typeof UnMemoizedLoadingIndicator; |
| 6 | +export const LoadingIndicator = (props: LoadingIndicatorProps) => ( |
| 7 | + <IconLoadingCircle {...props} className='str-chat__loading-indicator' /> |
| 8 | +); |
0 commit comments