Skip to content

Commit ef336cd

Browse files
authored
RI-7001: replace horizontal rule (#4517)
* Create custom loading-content component and replace the eui one * Create custom horizontal-rule component and replace the eui one
1 parent 3817486 commit ef336cd

File tree

29 files changed

+304
-60
lines changed

29 files changed

+304
-60
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import ExternalLink from './external-link'
2+
import { HorizontalRule, LoadingContent } from './layout'
23

3-
export { ExternalLink }
4+
export { ExternalLink, HorizontalRule, LoadingContent }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
import { render } from '@testing-library/react'
3+
import HorizontalRule from './HorizontalRule'
4+
5+
describe('HorizontalRule', () => {
6+
it('should render with default props', () => {
7+
const { container } = render(<HorizontalRule />)
8+
expect(container).toBeTruthy()
9+
expect(container.firstChild).toHaveStyle('width: 100%')
10+
})
11+
12+
it('should render with set size and margin', () => {
13+
const { container } = render(<HorizontalRule size="half" margin="xs" />)
14+
expect(container).toBeTruthy()
15+
expect(container.firstChild).toHaveStyle('width: 50%')
16+
expect(container.firstChild).toHaveStyle('margin-inline: auto')
17+
})
18+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import classNames from 'classnames'
2+
import React from 'react'
3+
4+
import {
5+
HorizontalRuleProps,
6+
StyledHorizontalRule,
7+
} from './horizontal-rule.styles'
8+
9+
const HorizontalRule = ({
10+
className,
11+
size = 'full',
12+
margin = 'l',
13+
...rest
14+
}: HorizontalRuleProps) => {
15+
const classes = classNames('RI-horizontal-rule', className)
16+
17+
return (
18+
<StyledHorizontalRule
19+
size={size}
20+
margin={margin}
21+
className={classes}
22+
{...rest}
23+
/>
24+
)
25+
}
26+
27+
export default HorizontalRule
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { HTMLAttributes } from 'react'
2+
import styled, { css } from 'styled-components'
3+
4+
export const SIZES = ['full', 'half', 'quarter'] as const
5+
export const MARGINS = ['none', 'xs', 's', 'm', 'l', 'xl', 'xxl'] as const
6+
7+
export type HorizontalRuleSize = (typeof SIZES)[number]
8+
export type HorizontalRuleMargin = (typeof MARGINS)[number]
9+
10+
const horizontalRuleStyles = {
11+
size: {
12+
full: css`
13+
width: 100%;
14+
`,
15+
half: css`
16+
width: 50%;
17+
margin-inline: auto;
18+
`,
19+
quarter: css`
20+
width: 25%;
21+
margin-inline: auto;
22+
`,
23+
},
24+
margin: {
25+
none: '',
26+
xs: css`
27+
margin-block: var(--size-xs);
28+
`,
29+
s: css`
30+
margin-block: var(--size-s);
31+
`,
32+
m: css`
33+
margin-block: var(--size-m);
34+
`,
35+
l: css`
36+
margin-block: var(--size-l);
37+
`,
38+
xl: css`
39+
margin-block: var(--size-xl);
40+
`,
41+
xxl: css`
42+
margin-block: var(--size-xxl);
43+
`,
44+
},
45+
}
46+
47+
export interface HorizontalRuleProps extends HTMLAttributes<HTMLHRElement> {
48+
size?: HorizontalRuleSize
49+
margin?: HorizontalRuleMargin
50+
}
51+
52+
export const StyledHorizontalRule = styled.hr<
53+
Omit<HorizontalRuleProps, 'size' | 'margin'> & {
54+
size?: HorizontalRuleSize
55+
margin?: HorizontalRuleMargin
56+
}
57+
>`
58+
${({ size = 'full' }) => horizontalRuleStyles.size[size]}
59+
${({ margin = 'l' }) => horizontalRuleStyles.margin[margin]}
60+
61+
/* Reset the default styles */
62+
border: none;
63+
64+
/* If the component is inside a flex box */
65+
flex-shrink: 0;
66+
flex-grow: 0;
67+
68+
background-color: var(--hrBackgroundColor);
69+
height: 1px;
70+
`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import HorizontalRule from './horizontal-rule/HorizontalRule'
2+
import LoadingContent from './loading-content/LoadingContent'
3+
4+
export { HorizontalRule, LoadingContent }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import { render } from '@testing-library/react'
3+
import LoadingContent from './LoadingContent'
4+
5+
describe('LoadingContent', () => {
6+
it('should render the component', () => {
7+
const { container } = render(<LoadingContent />)
8+
expect(container.firstChild).toHaveClass('RI-loading-content')
9+
})
10+
11+
it('should render the default number of lines (3)', () => {
12+
const { container } = render(<LoadingContent />)
13+
const lines = container.querySelectorAll('.RI-loading-content > span')
14+
expect(lines.length).toBe(3)
15+
})
16+
17+
it('should render the correct number of lines when "lines" prop is passed', () => {
18+
const { container } = render(<LoadingContent lines={5} />)
19+
const lines = container.querySelectorAll('.RI-loading-content > span')
20+
expect(lines.length).toBe(5)
21+
})
22+
23+
it('should apply the custom className if provided', () => {
24+
const { container } = render(<LoadingContent className="custom-class" />)
25+
expect(container.firstChild).toHaveClass('custom-class')
26+
})
27+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react'
2+
import classNames from 'classnames'
3+
4+
import {
5+
StyledLoadingContent,
6+
LoadingContentProps,
7+
SingleLine,
8+
SingleLineBackground,
9+
} from './loading-content.styles'
10+
11+
const LoadingContent = ({
12+
className,
13+
lines = 3,
14+
...rest
15+
}: LoadingContentProps) => {
16+
const classes = classNames('RI-loading-content', className)
17+
const lineElements = []
18+
19+
for (let i = 0; i < lines; i++) {
20+
lineElements.push(
21+
<SingleLine key={i}>
22+
<SingleLineBackground />
23+
</SingleLine>,
24+
)
25+
}
26+
27+
return (
28+
<StyledLoadingContent className={classes} {...rest}>
29+
{lineElements}
30+
</StyledLoadingContent>
31+
)
32+
}
33+
34+
export default LoadingContent
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { HTMLAttributes } from 'react'
2+
import styled, { keyframes } from 'styled-components'
3+
4+
export type LineRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
5+
6+
export interface LoadingContentProps extends HTMLAttributes<HTMLDivElement> {
7+
lines?: LineRange
8+
}
9+
10+
const loadingAnimation = keyframes`
11+
0% {
12+
transform: translateX(-53%);
13+
}
14+
15+
100% {
16+
transform: translateX(0);
17+
}
18+
`
19+
20+
export const StyledLoadingContent = styled.span<
21+
React.HtmlHTMLAttributes<HTMLSpanElement>
22+
>`
23+
display: block;
24+
width: 100%;
25+
`
26+
27+
export const SingleLine = styled.span<
28+
React.HtmlHTMLAttributes<HTMLSpanElement>
29+
>`
30+
display: block;
31+
width: 100%;
32+
height: var(--base);
33+
margin-bottom: var(--size-s);
34+
border-radius: var(--size-xs);
35+
overflow: hidden;
36+
37+
&:last-child:not(:only-child) {
38+
width: 75%;
39+
}
40+
`
41+
42+
export const SingleLineBackground = styled.span`
43+
display: block;
44+
width: 220%;
45+
height: 100%;
46+
background: linear-gradient(
47+
137deg,
48+
var(--loadingContentColor) 45%,
49+
var(--loadingContentLightestShade) 50%,
50+
var(--loadingContentColor) 55%
51+
);
52+
animation: ${loadingAnimation} 1.5s ease-in-out infinite;
53+
`

redisinsight/ui/src/components/consents-settings/ConsentsSettings.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {
1212
EuiTitle,
1313
EuiToolTip,
1414
EuiForm,
15-
EuiHorizontalRule,
1615
EuiCallOut,
1716
EuiLink,
1817
} from '@elastic/eui'
1918
import { EuiSwitchEvent } from '@elastic/eui/src/components/form/switch'
2019
import cx from 'classnames'
2120

21+
import { HorizontalRule } from 'uiSrc/components'
2222
import { compareConsents } from 'uiSrc/utils'
2323
import {
2424
updateUserConfigSettingsAction,
@@ -261,7 +261,7 @@ const ConsentsSettings = ({ onSubmitted }: Props) => {
261261
</EuiFlexItem>
262262
</EuiFlexGroup>
263263
</EuiFlexItem>
264-
<EuiHorizontalRule
264+
<HorizontalRule
265265
margin="l"
266266
className={cx({
267267
[styles.pluginWarningHR]: !!requiredConsents.length,
@@ -310,7 +310,7 @@ const ConsentsSettings = ({ onSubmitted }: Props) => {
310310
</div>
311311
{requiredConsents.length ? (
312312
<>
313-
<EuiHorizontalRule margin="l" className={styles.requiredHR} />
313+
<HorizontalRule margin="l" className={styles.requiredHR} />
314314
<EuiSpacer size="m" />
315315
<EuiText color="subdued" size="s" className={styles.smallText}>
316316
To use Redis Insight, please accept the terms and conditions:{' '}

redisinsight/ui/src/components/query/query-card/QueryCard.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useEffect, useState } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
33
import cx from 'classnames'
4-
import { EuiLoadingContent, keys } from '@elastic/eui'
4+
import { keys } from '@elastic/eui'
55
import { useParams } from 'react-router-dom'
66
import { isNull } from 'lodash'
77

8+
import { LoadingContent } from 'uiSrc/components/base/layout'
89
import {
910
DEFAULT_TEXT_VIEW_TYPE,
1011
ProfileQueryType,
@@ -233,7 +234,7 @@ const QueryCard = (props: Props) => {
233234
{isOpen && (
234235
<>
235236
{React.isValidElement(commonError) &&
236-
(!isGroupResults(resultsMode) || isNull(command)) ? (
237+
(!isGroupResults(resultsMode) || isNull(command)) ? (
237238
<QueryCardCommonResult loading={loading} result={commonError} />
238239
) : (
239240
<>
@@ -275,7 +276,7 @@ const QueryCard = (props: Props) => {
275276
/>
276277
) : (
277278
<div className={styles.loading}>
278-
<EuiLoadingContent
279+
<LoadingContent
279280
lines={5}
280281
data-testid="loading-content"
281282
/>

0 commit comments

Comments
 (0)