Skip to content

Commit bda593a

Browse files
committed
Merge branch 'Mil4n0r/resultset-typing' of github.com:dxc-technology/halstack-react into Mil4n0r/resultset-typing
2 parents f257095 + 4de8ac3 commit bda593a

File tree

14 files changed

+409
-96
lines changed

14 files changed

+409
-96
lines changed

lib/src/breadcrumbs/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,34 @@ type Item = {
33
label: string;
44
};
55
type Props = {
6+
/**
7+
* Provides a label that describes the type of navigation enabled by
8+
* the component.
9+
*/
610
ariaLabel?: string;
11+
/**
12+
* Array of objects representing the items of the breadcrumbs.
13+
*/
714
items: Item[];
15+
/**
16+
* Number of items before showing a collapsed version of the
17+
* breadcrumbs. It can't be lower than two (root/collapsed action and
18+
* current page).
19+
*/
820
itemsBeforeCollapse?: number;
21+
/**
22+
* Callback for custom navigation with third-party libraries such as
23+
* Next ('useRouter') or React Router ('useNavigate').
24+
* This function will be called when an item is clicked,
25+
* receiving its 'href' as a parameter.
26+
* @param href
27+
* @returns
28+
*/
929
onItemClick?: (href: string) => void;
30+
/**
31+
* When items are collapsed, whether the root item should always be
32+
* displayed or not.
33+
*/
1034
showRoot?: boolean;
1135
};
1236

lib/src/container/types.ts

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,129 @@ type OverflowValues = "visible" | "hidden" | "clip" | "scroll" | "auto";
5050
type Overflow = OverflowValues | { x?: OverflowValues; y?: OverflowValues };
5151

5252
type Props = {
53+
/**
54+
* Based on the CSS property background allows configuring all properties related to the background of a container.
55+
*
56+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/background
57+
*/
58+
background?: Background;
59+
/**
60+
* Based on the CSS property border allows configuring all properties related to the border of a container.
61+
*/
62+
border?: Border;
63+
/**
64+
* Sets the border-radius CSS property.
65+
*
66+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius
67+
*/
68+
borderRadius?: string;
69+
/**
70+
* Sets the box-shadow CSS property.
71+
*
72+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
73+
*/
74+
boxShadow?: string;
75+
/**
76+
* Sets the box-sizing CSS property.
77+
*
78+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
79+
*/
5380
boxSizing?: "border-box" | "content-box";
81+
/**
82+
* Custom content inside the container.
83+
*/
84+
children: React.ReactNode;
85+
/**
86+
* Sets the display CSS property.
87+
* The set of values is limited to the ones related to the outer display type.
88+
* If you want to apply any pattern from the inner box and how the children are laid out,
89+
* we recommend you to use the Flex and Grid components.
90+
*
91+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/display
92+
*/
5493
display?: "block" | "inline-block" | "inline" | "none";
55-
width?: string;
94+
/**
95+
* Sets the float CSS property.
96+
*
97+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/float
98+
*/
99+
float?: "left" | "right" | "none";
100+
/**
101+
* Sets the height CSS property.
102+
*
103+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/height
104+
*/
56105
height?: string;
106+
/**
107+
* Based on the CSS property inset this prop is a shorthand that corresponds
108+
* to the top, right, bottom, and/or left properties.
109+
*/
110+
inset?: Inset;
111+
/**
112+
* Size of the margin to be applied to the component.
113+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties
114+
* in order to specify different margin sizes.
115+
*/
116+
margin?: Space;
117+
/**
118+
* Sets the max-height CSS property.
119+
*
120+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/max-height
121+
*/
57122
maxWidth?: string;
123+
/**
124+
* Sets the max-width CSS property.
125+
*
126+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
127+
*/
58128
maxHeight?: string;
129+
/**
130+
* Sets the min-height CSS property.
131+
*
132+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/min-height
133+
*/
59134
minWidth?: string;
135+
/**
136+
* Sets the min-width CSS property.
137+
*
138+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/min-width
139+
*/
60140
minHeight?: string;
61-
padding?: Space;
62-
border?: Border;
63-
borderRadius?: string;
64-
margin?: Space;
141+
/**
142+
* Based on the CSS property outline allows configuring all properties related
143+
* to the outline of a container.
144+
*/
145+
outline?: Outline;
146+
/**
147+
* Sets the overflow CSS property.
148+
*
149+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
150+
*/
65151
overflow?: Overflow;
152+
/**
153+
* Size of the margin to be applied to the component.
154+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties
155+
* in order to specify different margin sizes.
156+
*/
157+
padding?: Space;
158+
/**
159+
* Sets the position CSS property.
160+
*
161+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/position
162+
*/
66163
position?: "static" | "relative" | "absolute" | "fixed" | "sticky";
67-
inset?: Inset;
68-
float?: "left" | "right" | "none";
164+
/**
165+
* Sets the width CSS property.
166+
*
167+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/width
168+
*/
169+
width?: string;
170+
/**
171+
* Sets the z-index CSS property.
172+
*
173+
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
174+
*/
69175
zIndex?: "auto" | number;
70-
background?: Background;
71-
boxShadow?: string;
72-
outline?: Outline;
73-
children: React.ReactNode;
74176
};
75177

76178
export type StyledProps = Omit<Props, "display" | "width" | "height" | "opacity" | "overflow"> & {

lib/src/contextual-menu/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ type GroupItem = CommonItemProps & {
1515
};
1616
type Section = { items: (Item | GroupItem)[]; title?: string };
1717
type Props = {
18+
/**
19+
* Array of items to be displayed in the Contextual menu.
20+
* Each item can be a single/simple item, a group item or a section.
21+
*/
1822
items: (Item | GroupItem)[] | Section[];
1923
};
2024

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react";
2+
import { render } from "@testing-library/react";
3+
import DxcTypography from "./Typography";
4+
5+
describe("Typography component tests", () => {
6+
test("Renders as the selected component", () => {
7+
const { container } = render(<DxcTypography as="h1">Test H1 Text</DxcTypography>);
8+
expect(container.querySelector('h1')).not.toBeNull();
9+
});
10+
test("Renders as span if it receives invalid tag", () => {
11+
const { container } = render(<DxcTypography as="br">Test BR Text</DxcTypography>);
12+
expect(container.querySelector('br')).toBeNull();
13+
expect(container.querySelector('span')).not.toBeNull();
14+
});
15+
});

lib/src/utils/BaseTypography.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ type BaseTypographyProps = TypographyContextProps & {
2323
children: React.ReactNode;
2424
};
2525

26+
const ValidTypographyTags = [
27+
"a", "blockquote", "cite", "code", "div", "em", "figcaption", "h1", "h2", "h3", "h4", "h5", "h6", "p", "pre", "small", "span", "strong"
28+
];
29+
30+
const isValidTypography = (tag: keyof HTMLElementTagNameMap) => {
31+
return ValidTypographyTags.includes(tag);
32+
}
33+
2634
const BaseTypography = ({
2735
as,
2836
display,
@@ -40,10 +48,9 @@ const BaseTypography = ({
4048
children,
4149
}: BaseTypographyProps): JSX.Element => {
4250
const componentContext = useContext(TypographyContext);
43-
4451
const contextValue = useMemo(
4552
() => ({
46-
as: as ?? componentContext?.as ?? "span",
53+
as: isValidTypography(as) ? as : (isValidTypography(componentContext?.as) ? componentContext?.as : "span"),
4754
display: display ?? componentContext?.display ?? "inline",
4855
fontFamily: fontFamily ?? componentContext?.fontFamily ?? "Open Sans, sans-serif",
4956
fontSize: fontSize ?? componentContext?.fontSize ?? "1rem",

0 commit comments

Comments
 (0)