Skip to content

Commit c07b272

Browse files
committed
refactor the Divider component to be styled and replace all its occurences
1 parent 81d3dd2 commit c07b272

File tree

14 files changed

+94
-88
lines changed

14 files changed

+94
-88
lines changed

redisinsight/ui/src/components/divider/Divider.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
33
import { render } from 'uiSrc/utils/test-utils'
4-
import Divider, { Props } from './Divider'
4+
import Divider, { DividerProps } from './Divider'
55

6-
const mockedProps = mock<Props>()
6+
const mockedProps = mock<DividerProps>()
77

88
describe('Divider', () => {
99
it('should render', () => {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { HTMLAttributes } from 'react'
2+
import styled, { css } from 'styled-components'
3+
4+
export type DividerVariant = 'fullWidth' | 'half'
5+
export type DividerOrientation = 'horizontal' | 'vertical'
6+
7+
const dividerStyles = {
8+
orientation: {
9+
horizontal: css`
10+
width: 100%;
11+
height: 1px;
12+
`,
13+
vertical: css`
14+
width: 1px;
15+
height: 100%;
16+
`,
17+
},
18+
variant: {
19+
fullWidth: {
20+
horizontal: css``,
21+
vertical: css``,
22+
},
23+
half: {
24+
horizontal: css`
25+
width: 50%;
26+
`,
27+
vertical: css`
28+
height: 50%;
29+
`,
30+
},
31+
},
32+
}
33+
34+
export interface StyledDividerProps extends HTMLAttributes<HTMLHRElement> {
35+
$color?: string
36+
$orientation?: DividerOrientation
37+
$variant?: DividerVariant
38+
}
39+
40+
export const StyledDividerWrapper = styled.div<HTMLAttributes<HTMLDivElement>>`
41+
display: flex;
42+
align-items: center;
43+
justify-content: center;
44+
`
45+
46+
export const StyledDivider = styled.hr<StyledDividerProps>`
47+
border: none;
48+
background-color: ${({
49+
theme,
50+
$color = theme.semantic.color.background.neutral500,
51+
}) => $color};
52+
53+
${({ $orientation = 'horizontal' }) =>
54+
dividerStyles.orientation[$orientation]}
55+
${({ $variant = 'fullWidth', $orientation = 'horizontal' }) =>
56+
dividerStyles.variant[$variant][$orientation]}
57+
`
Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
import React from 'react'
2-
import cx from 'classnames'
32

4-
import styles from './styles.module.scss'
3+
import {
4+
StyledDividerWrapper,
5+
StyledDivider,
6+
DividerVariant,
7+
DividerOrientation,
8+
} from './Divider.styles'
59

6-
export interface Props {
7-
color?: string
8-
colorVariable?: string
9-
orientation?: 'horizontal' | 'vertical'
10-
variant?: 'fullWidth' | 'middle' | 'half'
11-
className?: string
12-
style?: any
10+
export interface DividerProps {
11+
orientation: DividerOrientation
12+
variant: DividerVariant
13+
color: string
14+
className: string
1315
}
1416

1517
const Divider = ({
1618
orientation,
1719
variant,
18-
className,
1920
color,
20-
colorVariable,
21+
className,
2122
...props
22-
}: Props) => (
23-
<div
24-
className={cx(
25-
styles.divider,
26-
styles[`divider-${variant || 'fullWidth'}`],
27-
styles[`divider-${orientation || 'horizontal'}`],
28-
className,
29-
)}
30-
{...props}
31-
>
32-
<hr
33-
style={
34-
color || colorVariable
35-
? { backgroundColor: color ?? `var(--${colorVariable})` }
36-
: {}
37-
}
23+
}: DividerProps) => (
24+
<StyledDividerWrapper {...props}>
25+
<StyledDivider
26+
$variant={variant}
27+
$orientation={orientation}
28+
$color={color}
3829
/>
39-
</div>
30+
</StyledDividerWrapper>
4031
)
4132

4233
export default Divider

redisinsight/ui/src/components/divider/styles.module.scss

Lines changed: 0 additions & 39 deletions
This file was deleted.

redisinsight/ui/src/components/notifications/components/infinite-messages/InfiniteMessages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const INFINITE_MESSAGES: Record<
101101
{!!details && (
102102
<>
103103
<Spacer size="m" />
104-
<Divider variant="fullWidth" />
104+
<Divider />
105105
<Spacer size="m" />
106106
<Row className={styles.detailsRow} justify="between">
107107
<FlexItem>

redisinsight/ui/src/pages/browser/components/bulk-actions/BulkActionsInfo/BulkActionsInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const BulkActionsInfo = (props: Props) => {
7575
)}
7676
</Row>
7777
</Col>
78-
<Divider colorVariable="separatorColor" />
78+
<Divider />
7979
{loading && (
8080
<BulkActionsProgressLine data-testid="progress-line">
8181
<div style={{ width: `${(total ? scanned / total : 0) * 100}%` }} />

redisinsight/ui/src/pages/browser/modules/key-details/components/hash-details/HashDetails.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const HashDetails = (props: Props) => {
8383
/>
8484
<Divider
8585
className={styles.divider}
86-
colorVariable="separatorColor"
8786
orientation="vertical"
8887
/>
8988
</>

redisinsight/ui/src/pages/browser/modules/key-details/components/key-details-subheader/KeyDetailsSubheader.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const KeyDetailsSubheader = ({ keyType, Actions }: Props) => (
2626
</FlexItem>
2727
<Divider
2828
className={styles.divider}
29-
colorVariable="separatorColor"
3029
orientation="vertical"
3130
/>
3231
</>

redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/forms/AddConnection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const AddConnection = (props: Props) => {
5050
showFields={{ host: true, alias: true, port: true, timeout: true }}
5151
/>
5252
<Spacer size="l" />
53-
<Divider colorVariable="separatorColor" variant="fullWidth" />
53+
<Divider />
5454
<Spacer size="m" />
5555
<DbIndex formik={formik} />
5656
<Spacer size="m" />
57-
<Divider colorVariable="separatorColor" variant="fullWidth" />
57+
<Divider />
5858
<Spacer size="m" />
5959
<ForceStandalone formik={formik} />
6060
</>
@@ -69,7 +69,7 @@ const AddConnection = (props: Props) => {
6969
{buildType !== BuildType.RedisStack && (
7070
<>
7171
<Spacer size="m" />
72-
<Divider colorVariable="separatorColor" variant="fullWidth" />
72+
<Divider />
7373
<Spacer size="m" />
7474
<SSHDetails formik={formik} />
7575
</>

redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/forms/DecompressionAndFormatters.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const DecompressionAndFormatters = ({
1717
<>
1818
<DbCompressor formik={formik} />
1919
<Spacer size="m" />
20-
<Divider colorVariable="separatorColor" variant="fullWidth" />
20+
<Divider />
2121
<Spacer size="m" />
2222
<KeyFormatSelector formik={formik} />
2323
</>

0 commit comments

Comments
 (0)