Skip to content

Commit 094ad89

Browse files
chore(Routers): updated react/router and removed reach/router in examples (#11545)
* chore(Routers): updated react/router and removed reach/router in examples * Updated errors from react router upgrade * Fixed a11y error in demo * Added back and repurposed router examples * Removed types/react-router depdevs * Updated yarnlock
1 parent fc874c9 commit 094ad89

File tree

18 files changed

+161
-227
lines changed

18 files changed

+161
-227
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-i
1414
import UploadIcon from '@patternfly/react-icons/dist/esm/icons/upload-icon';
1515
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
1616
import QuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/question-circle-icon';
17-
import { Link } from '@reach/router';
1817

1918
## Examples
2019

@@ -86,11 +85,11 @@ Inline links should use `component="span"` and the `isInline` property to wrap i
8685
```ts file="./ButtonInlineSpanLink.tsx"
8786
```
8887

89-
### Router link
88+
### Custom component
9089

91-
Router links can be used for in-app linking in React environments to prevent page reloading.
90+
In addition to being able to pass a string to the `component` property, you can provide more fine-tuned customization by passing a callback that returns a component.
9291

93-
```ts file="./ButtonRouterLink.tsx"
92+
```ts file="./ButtonCustomComponent.tsx"
9493
```
9594

9695
### Aria-disabled examples
@@ -124,3 +123,13 @@ Stateful buttons are ideal for displaying the state of notifications. Use `varia
124123

125124
```ts file="./ButtonStateful.tsx"
126125
```
126+
127+
## Using router links
128+
129+
Router links can be used for in-app linking in React environments to prevent page reloading. To use a `Link` component from a router package, you can follow our [custom component example](#custom-component) and pass a callback to the `component` property of the `Button`:
130+
131+
```nolive
132+
<Button variant="link" component={(props: any) => <Link {...props} to="#" />}>
133+
Router link
134+
</Button>
135+
```
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+
4+
export const ButtonCustomComponent: React.FunctionComponent = () => (
5+
<Button variant="link" component={(props: any) => <a {...props} href="#" />}>
6+
Router link
7+
</Button>
8+
);

packages/react-core/src/components/Button/examples/ButtonRouterLink.tsx

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

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ propComponents: ['Label', 'LabelGroup']
77

88
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
99
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
10-
import { Link } from '@reach/router';
1110
import './Label.css';
1211

1312
## Examples
@@ -30,12 +29,6 @@ import './Label.css';
3029

3130
```
3231

33-
### Label with router link
34-
35-
```ts file="LabelRouterLink.tsx"
36-
37-
```
38-
3932
### Editable labels
4033

4134
Click or press either enter or space to begin editing a label. After editing, click outside the label or press enter again to complete the edit. To cancel an edit, press escape.
@@ -97,3 +90,19 @@ The contents of a label group can be modified by removing labels or adding new o
9790
```ts file="LabelGroupEditableAdd.tsx"
9891

9992
```
93+
94+
## Using router links
95+
96+
Router links can be used for in-app linking in React environments to prevent page reloading. To use a `Link` component from a router package, you can use the `render` property of the `Label`:
97+
98+
```nolive
99+
<Label
100+
render={({ className, content, componentRef }) => (
101+
<Link to="/" className={className} innerRef={componentRef}>
102+
{content}
103+
</Link>
104+
)}
105+
>
106+
Label router link
107+
</Label>
108+
```

packages/react-core/src/components/Label/examples/LabelRouterLink.tsx

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

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ propComponents: ['Masthead', 'MastheadToggle', 'MastheadMain', 'MastheadBrand',
66
---
77

88
import BarsIcon from '@patternfly/react-icons/dist/js/icons/bars-icon';
9-
import { Link } from '@reach/router';
109
import pfIcon from '../../assets/PF-HorizontalLogo-Color.svg';
1110

1211
To maintain proper layout and formatting, a `<Masthead>` should contain both a `<MastheadMain>` and `<MastheadContent>` component.
1312

14-
Mastheads contain the `<MastheadMain>` that wraps a `<PageToggleButton>` and `<MastheadBrand>`. The `<MastheadBrand>` wraps `<MastheadLogo>`. The masthead also contains the page's header toolbar within `<MastheadContent>`.
13+
Mastheads contain the `<MastheadMain>` that wraps a `<PageToggleButton>` and `<MastheadBrand>`. The `<MastheadBrand>` wraps `<MastheadLogo>`. The masthead also contains the page's header toolbar within `<MastheadContent>`.
1514

1615
## Examples
1716

@@ -45,7 +44,20 @@ To maintain proper layout and formatting, a `<Masthead>` should contain both a `
4544
```ts file="./MastheadInsets.tsx"
4645
```
4746

48-
### With icon router link
47+
### Custom logo component
4948

50-
```ts file="./MastheadIconRouterLink.tsx"
49+
In addition to being able to pass a string to the `component` property of `MastheadLogo`, you can provide more fine-tuned customization by passing a callback that returns a component.
50+
51+
52+
```ts file="./MastheadLogoCustomComponent.tsx"
5153
```
54+
55+
## Using router links
56+
57+
Router links can be used for in-app linking in React environments to prevent page reloading. To use a `Link` component from a router package, you can follow our [custom logo component example](#custom-logo-component) and pass a callback to the `component` property of the `MastheadLogo`:
58+
59+
```nolive
60+
<MastheadLogo component={(props) => <Link {...props} to="#" />}>
61+
<Brand ...brandProps />
62+
</MastheadLogo>
63+
```

packages/react-core/src/components/Masthead/examples/MastheadIconRouterLink.tsx renamed to packages/react-core/src/components/Masthead/examples/MastheadLogoCustomComponent.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ import {
1010
Brand
1111
} from '@patternfly/react-core';
1212
import BarsIcon from '@patternfly/react-icons/dist/js/icons/bars-icon';
13-
import { Link } from '@reach/router';
1413
import pfIcon from '../../assets/PF-HorizontalLogo-Color.svg';
1514

16-
export const MastheadIconRouterLink: React.FunctionComponent = () => (
15+
export const MastheadLogoCustomComponent: React.FunctionComponent = () => (
1716
<Masthead id="icon-router-link">
1817
<MastheadMain>
1918
<MastheadToggle>
2019
<Button variant="plain" onClick={() => {}} aria-label="Global navigation" icon={<BarsIcon />} />
2120
</MastheadToggle>
2221
<MastheadBrand>
23-
<MastheadLogo component={(props) => <Link {...props} to="#" />}>
22+
<MastheadLogo component={(props) => <a {...props} href="#" />}>
2423
<Brand src={pfIcon} alt="PatternFly" heights={{ default: '36px' }} />
2524
</MastheadLogo>
2625
</MastheadBrand>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,15 @@ To control the height of a menu, use the `maxMenuHeight` property. Selecting the
229229
```ts file="MenuFilterDrilldown.tsx"
230230

231231
```
232+
233+
## Using router links
234+
235+
Router links can be used for in-app linking in React environments to prevent page reloading. To use a `Link` component from a router package, you can pass a callback to the `component` property of the `MenuItem`:
236+
237+
```nolive
238+
<MenuItem
239+
component={(props) => <Link {...props} to="#" />}
240+
>
241+
{...Link Content}
242+
</MenuItem>
243+
```

packages/react-core/src/demos/CustomMenus/CustomMenus.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ section: components
44
subsection: menus
55
---
66

7-
import { Link } from '@reach/router';
8-
97
import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
108
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
119
import TableIcon from '@patternfly/react-icons/dist/esm/icons/table-icon';

packages/react-core/src/demos/Masthead.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import ThIcon from '@patternfly/react-icons/dist/esm/icons/th-icon';
1313
import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg';
1414
import pfIcon from './assets/pf-logo-small.svg';
1515
import pfLogo from './assets/PF-HorizontalLogo-Color.svg';
16-
import { Link } from '@reach/router';
1716

1817
## Demos
1918

0 commit comments

Comments
 (0)