Skip to content

Commit c671921

Browse files
authored
feat(Content): add editorial support (#10881)
* feat(Content): add editorial support * update prop description * docs updates
1 parent 08f530d commit c671921

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

packages/react-core/src/components/Content/Content.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export interface ContentProps extends React.HTMLProps<HTMLElement>, OUIAProps {
5353
isPlainList?: boolean;
5454
/** Flag to indicate the link (or all links within the content) has visited styles applied if the browser determines the link has been visited. */
5555
isVisitedLink?: boolean;
56+
/** Flag to indicate the content has editorial styling. This styling increases the font size of body text and small text by one tier, increasing body text to large and small text to the previous body text size. */
57+
isEditorial?: boolean;
5658
/** Value to overwrite the randomly generated data-ouia-component-id. */
5759
ouiaId?: number | string;
5860
/** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
@@ -89,6 +91,7 @@ export const Content: React.FunctionComponent<ContentProps> = ({
8991
isVisitedLink = false,
9092
ouiaId,
9193
ouiaSafe = true,
94+
isEditorial = false,
9295
...props
9396
}: ContentProps) => {
9497
const wrappingComponent = component ?? 'div';
@@ -106,6 +109,7 @@ export const Content: React.FunctionComponent<ContentProps> = ({
106109
componentStyles[wrappingComponent],
107110
isList && isPlainList && styles.modifiers.plain,
108111
isVisitedLink && styles.modifiers.visited,
112+
isEditorial && styles.modifiers.editorial,
109113
className
110114
)}
111115
>

packages/react-core/src/components/Content/__tests__/Content.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,30 @@ test('Renders with inherited element props spread to the component', () => {
264264
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
265265
});
266266

267+
test(`Renders without class name ${styles.modifiers.editorial} by default`, () => {
268+
render(<Content>Test</Content>);
269+
expect(screen.getByText('Test')).not.toHaveClass('pf-m-editorial');
270+
});
271+
272+
test(`Renders with class name ${styles.modifiers.editorial} when isEditorial = true`, () => {
273+
render(<Content isEditorial>Test</Content>);
274+
expect(screen.getByText('Test')).toHaveClass('pf-m-editorial');
275+
});
276+
277+
test(`Renders with class name ${styles.modifiers.editorial} when isEditorial = true and component is specified`, () => {
278+
render(
279+
<Content component="h1" isEditorial>
280+
Test
281+
</Content>
282+
);
283+
expect(screen.getByText('Test')).toHaveClass('pf-m-editorial');
284+
});
285+
286+
test(`Renders without class name ${styles.modifiers.editorial} when isEditorial = false`, () => {
287+
render(<Content isEditorial={false}>Test</Content>);
288+
expect(screen.getByText('Test')).not.toHaveClass('pf-m-editorial');
289+
});
290+
267291
test('Matches the snapshot', () => {
268292
const { asFragment } = render(<Content ouiaId="ouia-id">Test</Content>);
269293
expect(asFragment()).toMatchSnapshot();

packages/react-core/src/components/Content/examples/Content.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ HTML elements wrapped by `<Content>` are styled by the content component.
6262
```ts file="./ContentVisited.tsx"
6363

6464
```
65+
66+
### Editorial content
67+
68+
Editorial styling increases the font size of body text and small text by 1 tier, where body text becomes "lg" and small text becomes "md". To applying editorial styling, use `isEditorial`.
69+
70+
```ts file="./ContentEditorial.tsx"
71+
72+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { Content, ContentVariants } from '@patternfly/react-core';
3+
4+
export const ContentEditorial: React.FunctionComponent = () => (
5+
<>
6+
<Content component={ContentVariants.h1} isEditorial>
7+
Example of editorial content via components
8+
</Content>
9+
<Content component={ContentVariants.p} isEditorial>
10+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan, metus ultrices eleifend gravida, nulla
11+
nunc varius lectus, nec rutrum justo nibh eu lectus. Ut vulputate semper dui. Fusce erat odio, sollicitudin vel
12+
erat vel, interdum mattis neque. Sub works as well!
13+
</Content>
14+
<br />
15+
<Content isEditorial>
16+
<h1>Example of editorial content via wrapper</h1>
17+
<p>
18+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan, metus ultrices eleifend gravida, nulla
19+
nunc varius lectus, nec rutrum justo nibh eu lectus. Ut vulputate semper dui. Fusce erat odio, sollicitudin vel
20+
erat vel, interdum mattis neque. Sub works as well!
21+
</p>
22+
</Content>
23+
</>
24+
);

0 commit comments

Comments
 (0)