-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add skeleton code for Button component * feat: add more options to Button * feat: continue building out Button * feat: add lots of Button styles * feat: add additional variants of Button * feat: additional styling fixes and code comments * docs: add docs for Button * chore: add Aria functionality to the Button * test: add tests for Button * chore: add Button to index exports * chore: tweak docs and remove router interface * fix: button prop typo * chore: update Button component to use `--seeds` nomenclature * test: use the right icon class in Button test * chore: update Button with more prefix fixes * chore: fix icon sizing * feat: provide more options for external link icons * chore: refactor Button internals, restyle hovers * feat: add Link component * chore: tweak Highlight color scheme * fix: use `button-` prefix on component tokens * fix: use `link-` prefix on component tokens * chore: remove unneeded `disabled` prop * test: add unit test for Link * chore: add Link export * chore: make `href` attribute of Link required * chore: add screen reader text for external links * test: resolve link role testing * chore: make blank target options for Links and Buttons
- Loading branch information
1 parent
b5bb785
commit b08276b
Showing
11 changed files
with
289 additions
and
27 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
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,19 @@ | ||
.seeds-link, .seeds-prose a { | ||
text-decoration: underline; | ||
} | ||
|
||
.seeds-link { | ||
--link-interior-gap: var(--seeds-s1); | ||
--link-icon-size-percentage: 75%; | ||
|
||
display: inline-flex; | ||
gap: var(--link-interior-gap); | ||
|
||
& > * { | ||
align-self: center; | ||
} | ||
|
||
& > .seeds-icon { | ||
font-size: var(--link-icon-size-percentage); | ||
} | ||
} |
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,82 @@ | ||
import React, { useContext } from "react" | ||
import { | ||
ExternalLinkScreenReaderText, | ||
NavigationContext, | ||
isExternalLink, | ||
shouldShowExternalLinkIcon, | ||
} from "../global/NavigationContext" | ||
|
||
import Icon from "../icons/Icon" | ||
import { faArrowUpRightFromSquare } from "@fortawesome/free-solid-svg-icons" | ||
|
||
import "./Link.scss" | ||
|
||
export interface LinkProps { | ||
/** Link content */ | ||
children: React.ReactNode | ||
/** URL to link to */ | ||
href: string | ||
/** Icon to show before the label text */ | ||
leadIcon?: React.ReactNode | ||
/** Icon to show after the label text */ | ||
tailIcon?: React.ReactNode | ||
/** Set to true if you don't want external links to show a related icon */ | ||
hideExternalLinkIcon?: boolean | ||
/** Set external link target if it meets accessibility criteria */ | ||
newWindowTarget?: boolean | ||
/** Set to true to hide the link from the accessibility tree */ | ||
ariaHidden?: boolean | ||
/** Accessible label if link doesn't contain text content */ | ||
ariaLabel?: string | ||
/** Element ID */ | ||
id?: string | ||
/** Additional CSS classes */ | ||
className?: string | ||
} | ||
|
||
const Link = (props: LinkProps) => { | ||
const classNames = ["seeds-link"] | ||
|
||
const tailIcon = shouldShowExternalLinkIcon(props) ? ( | ||
<Icon icon={faArrowUpRightFromSquare} /> | ||
) : ( | ||
props.tailIcon | ||
) | ||
|
||
if (props.className) classNames.push(props.className) | ||
if (props.leadIcon) classNames.push("has-lead-icon") | ||
if (tailIcon) classNames.push("has-tail-icon") | ||
|
||
const additionalProps = { | ||
id: props.id, | ||
className: classNames.join(" "), | ||
"aria-label": props.ariaLabel, | ||
"aria-hidden": props.ariaHidden, | ||
} | ||
|
||
if (props.href && isExternalLink(props.href)) { | ||
return ( | ||
<a | ||
href={props.href} | ||
target={props.newWindowTarget ? "_blank" : undefined} | ||
{...additionalProps} | ||
> | ||
{props.leadIcon} | ||
{props.children} | ||
{tailIcon} | ||
{props.newWindowTarget && <ExternalLinkScreenReaderText />} | ||
</a> | ||
) | ||
} else { | ||
const { LinkComponent } = useContext(NavigationContext) | ||
return ( | ||
<LinkComponent href={props.href} {...additionalProps}> | ||
{props.leadIcon} | ||
{props.children} | ||
{tailIcon} | ||
</LinkComponent> | ||
) | ||
} | ||
} | ||
|
||
export default 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
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,15 @@ | ||
import { ArgsTable } from "@storybook/addon-docs" | ||
import Link from "../Link" | ||
|
||
# <Link /> | ||
|
||
## Properties | ||
|
||
<ArgsTable of={Link} /> | ||
|
||
## Theme Variables | ||
|
||
| Name | Description | Default | | ||
| ----------------------------- | -------------------------- | ------------ | | ||
| `--link-interior-gap` | Space between icons/text | `--seeds-s1` | | ||
| `--link-icon-size-percentage` | Relative size to base font | `75%` | |
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,47 @@ | ||
import React from "react" | ||
|
||
import Link from "../Link" | ||
|
||
import Icon from "../../icons/Icon" | ||
import { faHeart } from "@fortawesome/free-solid-svg-icons" | ||
|
||
import MDXDocs from "./Link.docs.mdx" | ||
|
||
export default { | ||
title: "Actions/Link", | ||
component: Link, | ||
parameters: { | ||
docs: { | ||
page: MDXDocs, | ||
}, | ||
}, | ||
} | ||
|
||
export const basicLink = () => ( | ||
<p> | ||
Hello world. <Link href="#">This is a link.</Link> | ||
</p> | ||
) | ||
|
||
export const externalLink = () => ( | ||
<div style={{ display: "flex", gap: "1rem" }}> | ||
<Link href="/test">Internal Link</Link> | ||
<Link href="https://www.exygy.com" hideExternalLinkIcon> | ||
External Link (Same Window) | ||
</Link> | ||
<Link href="https://www.exygy.com" newWindowTarget> | ||
External Link (New Window) | ||
</Link> | ||
</div> | ||
) | ||
|
||
export const linksWithIcons = () => ( | ||
<div style={{ display: "flex", gap: "1rem" }}> | ||
<Link href="/test" leadIcon={<Icon icon={faHeart} />}> | ||
Lead Icon | ||
</Link> | ||
<Link href="/test" tailIcon={<Icon icon={faHeart} />}> | ||
Tail Icon | ||
</Link> | ||
</div> | ||
) |
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
Oops, something went wrong.