Skip to content

Commit f6290b3

Browse files
authored
Merge pull request #1835 from dxc-technology/Mil4n0r/divider-component
Added new `Divider` component
2 parents fca135f + 4bb6cf1 commit f6290b3

File tree

13 files changed

+323
-12
lines changed

13 files changed

+323
-12
lines changed

lib/src/date-input/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ export type CalendarPropsType = {
123123
*/
124124
selectedDate: Dayjs;
125125
/**
126-
* Date showed by the calendar.
126+
* Date shown by the calendar.
127127
*/
128128
innerDate: Dayjs;
129129
/**
130-
* Function called when the showed date needs to be updated.
130+
* Function called when the shown date needs to be updated.
131131
*/
132132
onInnerDateChange: (date: Dayjs) => void;
133133
/**

lib/src/divider/Divider.stories.tsx

Lines changed: 223 additions & 0 deletions
Large diffs are not rendered by default.

lib/src/divider/Divider.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from "react";
2+
import { render } from "@testing-library/react";
3+
import DxcDivider from "./Divider";
4+
5+
describe("Divider Component", () => {
6+
test("Default renders horizontal divider correctly", () => {
7+
const { container } = render(<DxcDivider />);
8+
const divider = container.querySelector("hr");
9+
10+
expect(divider.getAttribute("aria-orientation")).toBe("horizontal");
11+
});
12+
13+
test("Renders vertical divider correctly", () => {
14+
const { container } = render(<DxcDivider orientation="vertical" />);
15+
const divider = container.querySelector("hr");
16+
expect(divider.getAttribute("aria-orientation")).toBe("vertical");
17+
});
18+
19+
test("Renders divider as a decorative resource by default", () => {
20+
const { container } = render(<DxcDivider />);
21+
const divider = container.querySelector("hr");
22+
expect(divider).toBeTruthy();
23+
expect(divider.getAttribute("aria-hidden")).toBe("true");
24+
});
25+
26+
test("Renders divider as a separator if it is not decorative", () => {
27+
const { getByRole } = render(<DxcDivider decorative={false} />);
28+
const divider = getByRole("separator");
29+
expect(divider).toBeTruthy();
30+
expect(divider.getAttribute("aria-hidden")).toBe("false");
31+
});
32+
});

lib/src/divider/Divider.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from "react";
2+
import styled from "styled-components";
3+
import DividerPropsType from "./types";
4+
import CoreTokens from "../common/coreTokens";
5+
6+
const DxcDivider = ({
7+
orientation = "horizontal",
8+
weight = "regular",
9+
color = "mediumGrey",
10+
decorative = true
11+
}: DividerPropsType): JSX.Element => (
12+
<StyledDivider orientation={orientation} weight={weight} color={color} aria-orientation={orientation} aria-hidden={decorative} />
13+
);
14+
15+
const StyledDivider = styled.hr<DividerPropsType>`
16+
${({ orientation, weight, color }) => `
17+
border-color: ${
18+
color === "lightGrey"
19+
? CoreTokens.color_grey_200
20+
: color === "mediumGrey"
21+
? CoreTokens.color_grey_400
22+
: CoreTokens.color_grey_700
23+
};
24+
${orientation === "horizontal" ? "width" : "min-height"}: 100%;
25+
${orientation === "horizontal" ? "height" : "width"}: 0px;
26+
${
27+
orientation === "horizontal"
28+
? "border-width: " + (weight === "regular" ? "1px 0 0 0" : "2px 0 0 0")
29+
: "border-width: " + (weight === "regular" ? "0 0 0 1px" : "0 0 0 2px")
30+
};
31+
margin: 0px;
32+
`}
33+
`;
34+
35+
export default DxcDivider;

lib/src/divider/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type Props = {
2+
/**
3+
* The divider can be shown in horizontal or vertical.
4+
*/
5+
orientation?: "horizontal" | "vertical";
6+
/**
7+
* Modifies the thickness of the divider.
8+
*/
9+
weight?: "regular" | "strong";
10+
/**
11+
* Modifies the color of the divider.
12+
*/
13+
color?: "lightGrey" | "mediumGrey" | "darkGrey";
14+
/**
15+
* Indicates whether the divider is just a decorative resource or it works as a semantic separator of content.
16+
*/
17+
decorative?: boolean;
18+
};
19+
20+
export default Props;

lib/src/dropdown/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type Props = {
5656
*/
5757
disabled?: boolean;
5858
/**
59-
* If true, the options are showed when the dropdown is hover.
59+
* If true, the options are shown when the dropdown is hover.
6060
*/
6161
expandOnHover?: boolean;
6262
/**

lib/src/header/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ type Props = {
66
*/
77
underlined?: boolean;
88
/**
9-
* Content showed in the header. Take into account that the component applies styles
9+
* Content shown in the header. Take into account that the component applies styles
1010
* for the first child in the content, so we recommend the use of React.Fragment
1111
* to be applied correctly. Otherwise, the styles can be modified.
1212
*/
1313
content?: React.ReactNode;
1414
/**
15-
* Content showed in responsive version. It receives the close menu handler that can
15+
* Content shown in responsive version. It receives the close menu handler that can
1616
* be used to add that functionality when a element is clicked.
1717
*/
1818
responsiveContent?: (closeHandler: () => void) => React.ReactNode;

lib/src/sidenav/Sidenav.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SidenavPropsType, {
1212
import DxcFlex from "../flex/Flex";
1313
import DxcBleed from "../bleed/Bleed";
1414
import icons from "./Icons";
15+
import CoreTokens from "../common/coreTokens";
1516

1617
const DxcSidenav = ({ title, children }: SidenavPropsType): JSX.Element => {
1718
const colorsTheme = useTheme();
@@ -155,7 +156,7 @@ const SidenavTitle = styled.div`
155156
const Divider = styled.div`
156157
width: 100%;
157158
height: 1px;
158-
background-color: #999999;
159+
background-color: ${CoreTokens.color_grey_400};
159160
160161
&:last-child {
161162
display: none;

lib/src/wizard/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type StepProps = {
3232

3333
type Props = {
3434
/**
35-
* The wizard can be showed in horizontal or vertical.
35+
* The wizard can be shown in horizontal or vertical.
3636
*/
3737
mode?: "horizontal" | "vertical";
3838
/**

website/screens/components/dialog/usage/DialogUsagePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const sections = [
8484
<DxcParagraph>
8585
The overlay element makes possible to get the user attention into the
8686
dialog creating a layer between the actual application and the modal
87-
information showed in the user interface.
87+
information shown in the user interface.
8888
</DxcParagraph>
8989
</>
9090
),

0 commit comments

Comments
 (0)