Skip to content

Commit aad1dcb

Browse files
committed
apply the background color logic; this will be extracted and reused at a later point
1 parent 6719f9d commit aad1dcb

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

redisinsight/ui/src/components/base/display/progress-bar/ProgressBarLoader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ProgressBarLoader = ({
1212
...rest
1313
}: ProgressBarLoaderProps) => (
1414
<LoaderContainer className={className} style={style} {...rest}>
15-
<LoaderBar color={color} />
15+
<LoaderBar $color={color} />
1616
</LoaderContainer>
1717
)
1818

redisinsight/ui/src/components/base/display/progress-bar/progress-bar-loader.styles.ts

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
1-
import { theme } from '@redis-ui/styles'
1+
import { theme, useTheme } from '@redis-ui/styles'
22
import { ReactNode } from 'react'
33
import styled, { css, keyframes } from 'styled-components'
44

5-
const backgroundStyles = {
6-
loaderBar: {
7-
primary: css`
8-
background-color: ${theme.semantic.color.background.primary500};
9-
`,
10-
},
5+
export type EuiColorNames =
6+
| 'inherit'
7+
| 'default'
8+
| 'primary'
9+
| 'danger'
10+
| 'warning'
11+
| 'success'
12+
13+
interface LoaderBarProps {
14+
color?: string
15+
}
16+
17+
export type ColorType = LoaderBarProps['color'] | EuiColorNames | (string & {})
18+
type ThemeColors = typeof theme.semantic.color
19+
20+
export const getBarBackgroundColor = (
21+
color: ColorType,
22+
themeColors: ThemeColors,
23+
) => {
24+
if (!color) {
25+
return themeColors.background.primary300
26+
}
27+
28+
const barBackgroundColors: Map<ColorType, string> = new Map([
29+
['inherit', 'inherit'],
30+
['default', themeColors.background.primary300],
31+
['primary', themeColors.background.primary300],
32+
['danger', themeColors.background.danger600],
33+
['warning', themeColors.background.attention600],
34+
['success', themeColors.background.success600],
35+
])
36+
37+
return barBackgroundColors.get(color) ?? color
38+
}
39+
40+
export interface MapProps extends LoaderBarProps {
41+
$color?: ColorType
42+
}
43+
44+
export const useColorBackgroundStyles = ({ $color }: MapProps = {}) => {
45+
const theme = useTheme()
46+
const colors = theme.semantic.color
47+
48+
const getColorValue = (color?: ColorType) =>
49+
getBarBackgroundColor(color, colors)
50+
51+
return css`
52+
background-color: ${getColorValue($color)};
53+
`
1154
}
1255

1356
const loading = keyframes`
@@ -33,19 +76,14 @@ export const LoaderContainer = styled.div<LoaderContainerProps>`
3376
border-radius: 2px;
3477
`
3578

36-
type LoaderBarColor = keyof typeof backgroundStyles.loaderBar
37-
38-
interface LoaderBarProps {
39-
color: LoaderBarColor
40-
}
79+
export const LoaderBar = styled.div<MapProps>`
80+
${useColorBackgroundStyles}
4181
42-
export const LoaderBar = styled.div<LoaderBarProps>`
4382
position: absolute;
4483
height: 100%;
4584
width: 100%;
4685
border-radius: 2px;
4786
48-
${({ color = 'primary' }) => backgroundStyles.loaderBar[color]};
4987
animation: ${loading} 1s ease-in-out infinite;
5088
`
5189

0 commit comments

Comments
 (0)