-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2cc5bf
commit 9ec5d63
Showing
9 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@import "vanilla-framework"; | ||
@include vanilla; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Meta } from "@storybook/react"; | ||
|
||
import { ExternalLink } from "."; | ||
|
||
const meta: Meta<typeof ExternalLink> = { | ||
title: "Components/ExternalLink", | ||
component: ExternalLink, | ||
tags: ["autodocs"], | ||
}; | ||
export default meta; | ||
|
||
export const Example = { | ||
args: { | ||
children: "maas.io", | ||
to: "https://maas.io", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
import { vi } from "vitest"; | ||
|
||
import { ExternalLink } from "./ExternalLink"; | ||
|
||
test("renders with correct attributes", () => { | ||
render(<ExternalLink to="https://example.com">Example Link</ExternalLink>); | ||
|
||
const linkElement = screen.getByText(/example link/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
expect(linkElement).toHaveAttribute("rel", "noreferrer noopener"); | ||
expect(linkElement).toHaveAttribute("href", "https://example.com"); | ||
expect(linkElement).toHaveAttribute("target", "_blank"); | ||
}); | ||
|
||
test("calls onClick handler when pressed", async () => { | ||
const handleClick = vi.fn(); | ||
|
||
render( | ||
<ExternalLink onClick={handleClick} to="https://example.com"> | ||
Example Link | ||
</ExternalLink>, | ||
); | ||
|
||
const linkElement = screen.getByText(/example link/i); | ||
await userEvent.click(linkElement); | ||
|
||
expect(handleClick).toHaveBeenCalled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Link, LinkProps } from "@canonical/react-components"; | ||
import type { LinkProps as RouterLinkProps } from "react-router-dom"; | ||
|
||
type ExternalLinkProps = Pick<LinkProps, "children"> & | ||
Omit<RouterLinkProps, "children"> & { to: string }; | ||
export const ExternalLink = ({ children, to, ...props }: ExternalLinkProps) => ( | ||
<Link {...props} href={to} rel="noreferrer noopener" target="_blank"> | ||
{children} | ||
</Link> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ExternalLink"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./Meter"; | ||
export * from "./ExternalLink"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters