Skip to content

Commit 122e761

Browse files
Merge branch 'patternfly:main' into main
2 parents d1e065b + 221c94d commit 122e761

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

packages/module/patternfly-docs/content/extensions/component-groups/examples/ErrorState/ErrorState.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ To provide users with error details, a basic error state should contain an appro
2626
```js file="./ErrorStateExample.tsx"
2727

2828
```
29+
30+
### Custom footer
31+
32+
To override default action button, specify your own using `customFooter`.
33+
34+
```js file="./ErrorStateFooterExample.tsx"
35+
36+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import React from 'react';
22
import ErrorState from "@patternfly/react-component-groups/dist/dynamic/ErrorState";
33

4-
export const BasicExample: React.FunctionComponent = () => <ErrorState errorTitle='A Basic Error' errorDescription='The following is an example of a basic error' />;
4+
export const BasicExample: React.FunctionComponent = () => <ErrorState errorTitle='Sample error title' errorDescription='Sample error description' />;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import { Button } from '@patternfly/react-core';
3+
import ErrorState from "@patternfly/react-component-groups/dist/dynamic/ErrorState";
4+
5+
// eslint-disable-next-line no-console
6+
export const BasicExample: React.FunctionComponent = () => <ErrorState errorTitle='Sample error title' errorDescription='Sample error description' customFooter={<Button variant="secondary" onClick={() => console.log("Custom button clicked")}>
7+
Custom action
8+
</Button>}/>;

packages/module/src/ErrorState/ErrorState.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as React from 'react';
22
import ErrorState from './ErrorState';
33
import { render, screen } from '@testing-library/react';
4+
import { Button } from '@patternfly/react-core';
45

56
describe('ErrorState component', () => {
67

78
it('should render correctly', () => {
8-
render(<ErrorState errorTitle='A Basic Error' errorDescription='The following is an example of a basic error' />);
9+
render(<ErrorState errorTitle='A Basic Error' errorDescription='The following is an example of a basic error' customFooter={<Button>Custom button</Button>} />);
910

1011
expect(screen.getByText('A Basic Error')).toBeVisible();
1112
expect(screen.getByText('The following is an example of a basic error')).toBeVisible();
12-
expect(screen.getByText('Go to home page')).toBeVisible();
13+
expect(screen.getByText('Custom button')).toBeVisible();
1314
});
1415

1516
it('should render correctly with default props', () => {

packages/module/src/ErrorState/ErrorState.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ export interface ErrorStateProps extends Omit<EmptyStateProps, 'children'> {
2727
errorDescription?: React.ReactNode;
2828
/** A default description of the error used if no errorDescription is provided. */
2929
defaultErrorDescription?: React.ReactNode;
30+
/** Custom footer content */
31+
customFooter?: React.ReactNode;
3032
}
3133

32-
const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'Something went wrong', errorDescription, defaultErrorDescription, ...props }: ErrorStateProps) => {
34+
const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'Something went wrong', errorDescription, defaultErrorDescription, customFooter, ...props }: ErrorStateProps) => {
3335
const classes = useStyles();
3436
return (
3537
<EmptyState variant={EmptyStateVariant.lg} {...props}>
@@ -40,15 +42,16 @@ const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'So
4042
</Stack>
4143
</EmptyStateBody>
4244
<EmptyStateFooter>
43-
{document.referrer ? (
44-
<Button variant="primary" onClick={() => history.back()}>
45+
{ customFooter ||
46+
(document.referrer ? (
47+
<Button variant="primary" onClick={() => history.back()}>
4548
Return to last page
46-
</Button>
47-
) : (
48-
<Button variant="primary" component="a" href="." target="_blank" rel="noopener noreferrer">
49+
</Button>
50+
) : (
51+
<Button variant="primary" component="a" href="." target="_blank" rel="noopener noreferrer">
4952
Go to home page
50-
</Button>
51-
)}
53+
</Button>
54+
))}
5255
</EmptyStateFooter>
5356
</EmptyState>
5457
);

0 commit comments

Comments
 (0)