Skip to content

Commit

Permalink
IWidgetLink improvements (#1813)
Browse files Browse the repository at this point in the history
* Added more customization to the IWidgetLink

* Updated docs

* Various updates to resolve GitHub conversations.
  • Loading branch information
GuidoZam authored Aug 16, 2024
1 parent 152cafe commit 759d11b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
11 changes: 10 additions & 1 deletion docs/documentation/docs/controls/Dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import { WidgetSize, Dashboard } from '@pnp/spfx-controls-react/lib/Dashboard';

```TypeScript
const linkExample = { href: "#" };
const customizedLinkExample = {
href: "#",
title: "This is a customized link!",
color: "red",
target: "_top"
};
const calloutItemsExample = [
{
id: "action_1",
Expand Down Expand Up @@ -71,7 +77,7 @@ const calloutItemsExample = [
{
title: "Card 2",
size: WidgetSize.Single,
link: linkExample,
link: customizedLinkExample,
},
{
title: "Card 3",
Expand Down Expand Up @@ -142,6 +148,9 @@ Provides Widget link properties
| Property | Type | Required | Description |
| ---- | ---- | ---- | ---- |
| href | string | yes | Link to be opened. |
| title | string | no | The text to display for the link, if not provided, the default text will be used. |
| 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). |
| target | string | no | The target property value for the generated anchor tag, if not provided, the default target will be *_blank*. |

Enum `WidgetSize`

Expand Down
15 changes: 15 additions & 0 deletions src/controls/dashboard/widget/IWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,20 @@ export interface IWidgetBodyContent {
* Widget link
*/
export interface IWidgetLink {
/**
* Link to be opened
*/
href: string;
/**
* The text to display for the link, if not provided, the default text will be used
*/
title?: string;
/**
* 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)
*/
color?: string;
/**
* The target for the generated anchor tag, if not provided, the default target will be _blank
*/
target?: "_blank" | "_self" | "_parent" | "_top" | "framename";
}
6 changes: 3 additions & 3 deletions src/controls/dashboard/widget/WidgetFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const WidgetFooter = ({ widget }: { widget: IWidget }): JSX.Element => (
<Text
as="a"
href={widget.link.href}
target="_blank"
content={strings.ViewMore}
target={widget.link.target ?? "_blank"}
content={widget.link.title ?? strings.ViewMore}
size="small"
color="brand"
color={widget.link.color ?? "default"}
style={{ textDecoration: "none" }}
/>
</Flex>
Expand Down
10 changes: 8 additions & 2 deletions src/webparts/controlsTest/components/ControlsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,12 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
}];

const linkExample = { href: "#" };
const customizedLinkExample = {
href: "#",
title: "This is a customized link!",
color: "red",
target: "_top"
};
const calloutItemsExample = [
{
id: "action_1",
Expand Down Expand Up @@ -2049,7 +2055,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
{
title: "Card 2",
size: WidgetSize.Single,
link: linkExample,
link: customizedLinkExample,
},
{
title: "Card 3",
Expand All @@ -2059,7 +2065,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
{
title: "Card 4",
size: WidgetSize.Single,
link: linkExample,
link: customizedLinkExample,
},
{
title: "Card 5",
Expand Down

0 comments on commit 759d11b

Please sign in to comment.