Skip to content

Commit 759d11b

Browse files
authored
IWidgetLink improvements (#1813)
* Added more customization to the IWidgetLink * Updated docs * Various updates to resolve GitHub conversations.
1 parent 152cafe commit 759d11b

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

docs/documentation/docs/controls/Dashboard.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import { WidgetSize, Dashboard } from '@pnp/spfx-controls-react/lib/Dashboard';
2222

2323
```TypeScript
2424
const linkExample = { href: "#" };
25+
const customizedLinkExample = {
26+
href: "#",
27+
title: "This is a customized link!",
28+
color: "red",
29+
target: "_top"
30+
};
2531
const calloutItemsExample = [
2632
{
2733
id: "action_1",
@@ -71,7 +77,7 @@ const calloutItemsExample = [
7177
{
7278
title: "Card 2",
7379
size: WidgetSize.Single,
74-
link: linkExample,
80+
link: customizedLinkExample,
7581
},
7682
{
7783
title: "Card 3",
@@ -142,6 +148,9 @@ Provides Widget link properties
142148
| Property | Type | Required | Description |
143149
| ---- | ---- | ---- | ---- |
144150
| href | string | yes | Link to be opened. |
151+
| title | string | no | The text to display for the link, if not provided, the default text will be used. |
152+
| color | string | no | The color of the link, if not provided, the "default" color will be used. The available colors can be found on the [official Fluent UI documentation of the Text control](https://fluentsite.z22.web.core.windows.net/0.66.2/components/text/definition#variations-color). |
153+
| target | string | no | The target property value for the generated anchor tag, if not provided, the default target will be *_blank*. |
145154

146155
Enum `WidgetSize`
147156

src/controls/dashboard/widget/IWidget.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,20 @@ export interface IWidgetBodyContent {
9797
* Widget link
9898
*/
9999
export interface IWidgetLink {
100+
/**
101+
* Link to be opened
102+
*/
100103
href: string;
104+
/**
105+
* The text to display for the link, if not provided, the default text will be used
106+
*/
107+
title?: string;
108+
/**
109+
* The color of the link, if not provided, the "brand" color will be used. The available colors can be found on the [official Fluent UI documentation of the Text control](https://fluentsite.z22.web.core.windows.net/0.66.2/components/text/definition#variations-color)
110+
*/
111+
color?: string;
112+
/**
113+
* The target for the generated anchor tag, if not provided, the default target will be _blank
114+
*/
115+
target?: "_blank" | "_self" | "_parent" | "_top" | "framename";
101116
}

src/controls/dashboard/widget/WidgetFooter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export const WidgetFooter = ({ widget }: { widget: IWidget }): JSX.Element => (
99
<Text
1010
as="a"
1111
href={widget.link.href}
12-
target="_blank"
13-
content={strings.ViewMore}
12+
target={widget.link.target ?? "_blank"}
13+
content={widget.link.title ?? strings.ViewMore}
1414
size="small"
15-
color="brand"
15+
color={widget.link.color ?? "default"}
1616
style={{ textDecoration: "none" }}
1717
/>
1818
</Flex>

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,12 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
906906
}];
907907

908908
const linkExample = { href: "#" };
909+
const customizedLinkExample = {
910+
href: "#",
911+
title: "This is a customized link!",
912+
color: "red",
913+
target: "_top"
914+
};
909915
const calloutItemsExample = [
910916
{
911917
id: "action_1",
@@ -2049,7 +2055,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
20492055
{
20502056
title: "Card 2",
20512057
size: WidgetSize.Single,
2052-
link: linkExample,
2058+
link: customizedLinkExample,
20532059
},
20542060
{
20552061
title: "Card 3",
@@ -2059,7 +2065,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
20592065
{
20602066
title: "Card 4",
20612067
size: WidgetSize.Single,
2062-
link: linkExample,
2068+
link: customizedLinkExample,
20632069
},
20642070
{
20652071
title: "Card 5",

0 commit comments

Comments
 (0)