Skip to content

Commit 87b3b6a

Browse files
georginahalpernGeorgina Halpern
andauthored
[Inspectorv2/Fluent] Open infobutton links in new tab (#17345)
Bug fix to open link in new tab vs current window other changes: - Moves fluent link usage over to the shared primitive - Adds style prop to baseprimtive --------- Co-authored-by: Georgina Halpern <[email protected]>
1 parent abce0af commit 87b3b6a

File tree

6 files changed

+39
-20
lines changed

6 files changed

+39
-20
lines changed
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import { Body1 } from "@fluentui/react-components";
21
import { PropertyLine } from "./propertyLine";
32
import { Link } from "../../primitives/link";
4-
import type { ImmutablePrimitiveProps } from "../../primitives/primitive";
3+
import type { LinkProps } from "../../primitives/link";
54
import type { PropertyLineProps } from "./propertyLine";
65
import type { FunctionComponent } from "react";
76

8-
type LinkProps = ImmutablePrimitiveProps<string> & {
9-
onLink?: () => void;
10-
url?: string;
11-
};
12-
137
/**
148
* Wraps a link in a property line
159
* @param props - PropertyLineProps and LinkProps
@@ -19,9 +13,7 @@ export const LinkPropertyLine: FunctionComponent<PropertyLineProps<string> & Lin
1913
LinkPropertyLine.displayName = "LinkPropertyLine";
2014
return (
2115
<PropertyLine {...props}>
22-
<Link inline onClick={() => props.onLink?.()} href={props.url} title={props.title}>
23-
<Body1>{props.value}</Body1>
24-
</Link>
16+
<Link {...props} />
2517
</PropertyLine>
2618
);
2719
};

packages/dev/sharedUiComponents/src/fluent/hoc/propertyLines/propertyLine.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body1, InfoLabel, Link, Checkbox, makeStyles, Body1Strong, tokens, mergeClasses } from "@fluentui/react-components";
1+
import { Body1, InfoLabel, Checkbox, makeStyles, Body1Strong, tokens, mergeClasses } from "@fluentui/react-components";
22
import {
33
ChevronCircleDown20Regular,
44
ChevronCircleDown16Regular,
@@ -13,6 +13,7 @@ import { Collapse } from "../../primitives/collapse";
1313
import { copyCommandToClipboard } from "../../../copyCommandToClipboard";
1414
import { ToolContext } from "../fluentToolWrapper";
1515
import type { PrimitiveProps } from "../../primitives/primitive";
16+
import { Link } from "../../primitives/link";
1617
import { ToggleButton } from "../../primitives/toggleButton";
1718
import { Button } from "../../primitives/button";
1819
import { CustomTokens } from "../../primitives/utils";
@@ -136,7 +137,7 @@ export const PropertyLine = forwardRef<HTMLDivElement, PropsWithChildren<Propert
136137
const [expanded, setExpanded] = useState("expandByDefault" in props ? props.expandByDefault : false);
137138
const cachedVal = useRef(nullable ? props.value : null);
138139

139-
const description = props.docLink ? <Link href={props.docLink}>{props.description ?? "Docs"}</Link> : props.description;
140+
const description = props.docLink ? <Link url={props.docLink} value={props.description ?? "Docs"} /> : props.description;
140141

141142
// Process children to handle nullable state -- creating component in disabled state with default value in lieu of null value
142143
const processedChildren =

packages/dev/sharedUiComponents/src/fluent/primitives/colorPicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ColorSlider,
88
ColorArea,
99
AlphaSlider,
10-
Link,
1110
makeStyles,
1211
Popover,
1312
PopoverSurface,
@@ -24,6 +23,7 @@ import { SpinButton } from "./spinButton";
2423
import { TextInput } from "./textInput";
2524
import { NumberDropdown } from "./dropdown";
2625
import { ValidateColorHex } from "./utils";
26+
import { Link } from "./link";
2727
import { ToolContext } from "../hoc/fluentToolWrapper";
2828

2929
const useColorPickerStyles = makeStyles({
@@ -233,7 +233,7 @@ export const InputHexField: FunctionComponent<InputHexProps> = (props) => {
233233
<Body1Strong>Color3.FromHexString(GAMMA_HEX).toLinearSpace()</Body1Strong>
234234
<br />
235235
<br />
236-
<Link href="https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/"> Read more in our docs! </Link>
236+
<Link url="https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/" value="Read more in our docs!" />
237237
</>
238238
),
239239
}
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1-
// No special styling / functionality yet!
1+
import type { FunctionComponent, PropsWithChildren } from "react";
2+
import { Body1, Link as FluentLink } from "@fluentui/react-components";
3+
import type { ImmutablePrimitiveProps } from "./primitive";
24

3-
export { Link } from "@fluentui/react-components";
5+
export type LinkProps = ImmutablePrimitiveProps<string> & {
6+
/**
7+
* Used if you want to handle the link click yourself
8+
*/
9+
onLink?: () => void;
10+
/**
11+
* The URL the link points to
12+
*/
13+
url?: string;
14+
/**
15+
* Defines whether to open the link in current tab or new tab. Default is new
16+
*/
17+
target?: "current" | "new";
18+
};
19+
20+
export const Link: FunctionComponent<PropsWithChildren<LinkProps>> = (props) => {
21+
const { target, url, onLink, ...rest } = props;
22+
return (
23+
<FluentLink inline target={target === "current" ? "_self" : "_blank"} rel="noopener noreferrer" href={url} onClick={onLink ?? undefined} {...rest}>
24+
{props.children}
25+
<Body1>{props.value}</Body1>
26+
</FluentLink>
27+
);
28+
};

packages/dev/sharedUiComponents/src/fluent/primitives/messageBar.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export const MessageBar: FunctionComponent<MessageBarProps> = (props) => {
3030
{docLink && (
3131
<>
3232
{" - "}
33-
<Link href={docLink} target="_blank" rel="noopener noreferrer">
34-
Learn More
35-
</Link>
33+
<Link url={docLink} value="Learn More" />
3634
</>
3735
)}
3836
</MessageBarBody>

packages/dev/sharedUiComponents/src/fluent/primitives/primitive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export type BasePrimitiveProps = {
99
* Optional class name to apply custom styles to the component.
1010
*/
1111
className?: string;
12-
12+
/**
13+
* Optional style object to apply custom inline styles to the top-level HTML element.
14+
*/
15+
style?: React.CSSProperties;
1316
/**
1417
* Optional title for the component, used for tooltips or accessibility.
1518
*/

0 commit comments

Comments
 (0)