Skip to content

Commit 6e3e527

Browse files
committed
docs: add usage notes for ExternalLinkButton
1 parent 3834310 commit 6e3e527

File tree

6 files changed

+81
-8
lines changed

6 files changed

+81
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
section: Component groups
3+
subsection: Controls
4+
id: External link button
5+
source: react
6+
propComponents: ['ExternalLinkButton']
7+
sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/ExternalLinkButton/ExternalLinkButton.md
8+
---
9+
10+
import ExternalLinkButton from "@patternfly/react-component-groups/dist/dynamic/ExternalLinkButton"
11+
12+
The **external link button** component is a button that opens links in an external tab. To further customize this component, you can also utilize all properties of the [button component](/components/button).
13+
14+
## Examples
15+
16+
### Basic external link button
17+
18+
In order to display a basic external link button, you can use the `href` property to specify the URL and the `variant` property to set the button style.
19+
20+
```js file="./ExternalLinkButtonExample.tsx"
21+
22+
```
23+
24+
### Inline external link button
25+
26+
You may use the external link button component inline with other text by using the `inline` property.
27+
28+
```js file="./ExternalLinkButtonInlineExample.tsx"
29+
30+
```
31+
32+
### Passing props to the icon
33+
34+
You may pass props to the icon using the `iconProps` property. This is useful for customizing the title of the icon for enhanced screen reader support.
35+
36+
```js file="./ExternalLinkButtonIconPropsExample.tsx"
37+
38+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import ExternalLinkButton from '@patternfly/react-component-groups/dist/dynamic/ExternalLinkButton';
2+
3+
export const BasicExample = () => (
4+
<ExternalLinkButton
5+
href="https://www.patternfly.org"
6+
variant="primary"
7+
>
8+
Learn more about PatternFly
9+
</ExternalLinkButton>
10+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ExternalLinkButton from '@patternfly/react-component-groups/dist/dynamic/ExternalLinkButton';
2+
3+
export const BasicExample = () => (
4+
<ExternalLinkButton
5+
href="https://www.patternfly.org"
6+
iconProps={{ title: '(Opens in new tab)' }}
7+
variant="link"
8+
>
9+
Learn more about PatternFly
10+
</ExternalLinkButton>
11+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ExternalLinkButton from '@patternfly/react-component-groups/dist/dynamic/ExternalLinkButton';
2+
import { Content, ContentVariants } from '@patternfly/react-core';
3+
4+
export const BasicExample = () => (
5+
<Content component={ContentVariants.p}>
6+
Today, I had a burger for lunch. It reminded me of the
7+
<ExternalLinkButton
8+
href="https://www.patternfly.org"
9+
isInline
10+
variant="link"
11+
>
12+
PatternFly
13+
</ExternalLinkButton>
14+
design system.
15+
</Content>
16+
);

packages/module/src/ExternalLinkButton/ExternalLinkButton.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ import { ExternalLinkAltIcon } from '@patternfly/react-icons';
33
import type { SVGIconProps } from '@patternfly/react-icons/dist/esm/createIcon';
44
import { forwardRef, Ref } from 'react';
55

6-
/** extends `ButtonProps` */
6+
/** extends ButtonProps */
77
export interface ExternalLinkButtonProps extends ButtonProps {
88
/** Additional props to pass to the icon */
99
iconProps?: SVGIconProps;
1010
};
1111

12-
/**
13-
* A `Button` that opens links in an external tab.
14-
*/
1512
export const ExternalLinkButton = forwardRef(({ iconProps, ...props }: ExternalLinkButtonProps, ref: Ref<HTMLAnchorElement>) => (
1613
<Button
1714
component="a"
1815
icon={<ExternalLinkAltIcon {...iconProps} />}
1916
iconPosition="right"
17+
ouiaId="ExternalLinkButton"
2018
ref={ref}
2119
rel="noopener noreferrer"
2220
target="_blank"

packages/module/src/ExternalLinkButton/__snapshots__/ExternalLinkButton.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`ExternalLinkButton component should accept IconProps 1`] = `
77
<div>
88
<a
99
class="pf-v6-c-button pf-m-primary"
10-
data-ouia-component-id="OUIA-Generated-Button-primary-2"
10+
data-ouia-component-id="ExternalLinkButton"
1111
data-ouia-component-type="PF6/Button"
1212
data-ouia-safe="true"
1313
rel="noopener noreferrer"
@@ -41,7 +41,7 @@ exports[`ExternalLinkButton component should accept IconProps 1`] = `
4141
"container": <div>
4242
<a
4343
class="pf-v6-c-button pf-m-primary"
44-
data-ouia-component-id="OUIA-Generated-Button-primary-2"
44+
data-ouia-component-id="ExternalLinkButton"
4545
data-ouia-component-type="PF6/Button"
4646
data-ouia-safe="true"
4747
rel="noopener noreferrer"
@@ -132,7 +132,7 @@ exports[`ExternalLinkButton component should render 1`] = `
132132
<div>
133133
<a
134134
class="pf-v6-c-button pf-m-primary"
135-
data-ouia-component-id="OUIA-Generated-Button-primary-1"
135+
data-ouia-component-id="ExternalLinkButton"
136136
data-ouia-component-type="PF6/Button"
137137
data-ouia-safe="true"
138138
rel="noopener noreferrer"
@@ -161,7 +161,7 @@ exports[`ExternalLinkButton component should render 1`] = `
161161
"container": <div>
162162
<a
163163
class="pf-v6-c-button pf-m-primary"
164-
data-ouia-component-id="OUIA-Generated-Button-primary-1"
164+
data-ouia-component-id="ExternalLinkButton"
165165
data-ouia-component-type="PF6/Button"
166166
data-ouia-safe="true"
167167
rel="noopener noreferrer"

0 commit comments

Comments
 (0)