TextLink
A link in the accent colour, inside a sentence or on its own.
Overview
A link that sits in text. A link that is an action is a ButtonLink.
In sentence
Questions? Email [email protected], or read the terms first.
import { Body, TextLink } from "@hackcove/ui";
<Body as="p">
Questions? Email <TextLink href="mailto:[email protected]">[email protected]</TextLink>, or
read the <TextLink href="#terms">terms</TextLink> first.
</Body>TextLink inside a Body.Questions? Email [email protected], or read the terms first.
import { Body } from "@hackcove/ui";
<Body as="p">
Questions? Email <a href="mailto:[email protected]">[email protected]</a>, or read the{" "}
<a href="#terms">terms</a> first.
</Body><a> has none of the theme's link colour, weight or focus ring.External
import { TextLink } from "@hackcove/ui";
<TextLink href="https://example.com" external>
example.com
</TextLink>external opens another site in a new tab and adds rel="noreferrer" with it.import { TextLink } from "@hackcove/ui";
<TextLink href="https://example.com" target="_blank">
example.com
</TextLink>target="_blank" by hand leaves out the rel. Say external and the link gets both.Router
import { TextLink } from "@hackcove/ui";
<TextLink render={(p) => <a href="#terms" {...p} />}>Read the terms</TextLink>
render draws the router's own <Link>; here an anchor stands in.Stretch
Quote 12
import { Card, TextLink } from "@hackcove/ui";
<Card title="Quote 12">
<TextLink href="#quote-12" stretch>
Open the quote
</TextLink>
</Card>stretch makes the whole of the nearest relative ancestor the click target: a Card here, a TableRow in a table.Usage
- Use
TextLinkfor every link in running text. Never a bare<a>. externalis for another site: it opens a new tab withrel="noreferrer".- In an app with a router,
renderdraws the router's own<Link>:render={(p) => <Link to="/terms" {...p} />}. The library has no router. sizepins the type size toxsorsm; left out, the link takes the size of its text.monosets the monospace face for a path or an id.tonegives the link a meaning's colour (warn,danger,positive,info,muted), underlined on hover. Use it for a link that is the message, like "3 failed".stretchmakes the nearestrelativeancestor the click target: aCardor aTableRow. Put it on the one link in that row.- A router's own
<Link>that must look like aTextLinktakeslinkClass, and a stretched onelinkStretchClassas well.
Accessibility
- A
TextLinkis a native<a>, so it is in the tab order and opens with Enter. - It has a focus ring from the component, so the keyboard focus is always visible.
externalsetstarget="_blank"andrel="noreferrer".- Every anchor prop (
aria-*,download,title, a handler) goes on the<a>;renderreceives them as well.
API
TextLink
An inline text link in the accent colour. Every anchor prop goes on the <a>. With render it draws the app's own router <Link> instead (render={(p) => <Link to="/terms" {...p} />}). size pins the type size (xs or sm), tone gives it a meaning's colour and mono sets the monospace face.
externalOpens in a new tab: adds target="_blank" and rel="noreferrer".
- Type
boolean- Default
false
href- Type
string
monoThe monospace face, for a path, an id or a command.
- Type
boolean- Default
false
render- Type
LinkRender
sizeThe link's own type size. Left out, it takes the size of the text around it.
- Type
"sm" | "xs"
stretchThe link covers its nearest relative ancestor, so the whole row or card is the click target.
- Type
boolean- Default
false
toneA meaning's colour, as on the inline roles: warn for a warning link, danger, positive,
info or muted. Left out, the link is the accent colour.
- Type
"positive" | "danger" | "info" | "warn" | "muted"
Functions
linkClassThe classes of an inline text link, for a router's own<Link>that must look like aTextLink.linkStretchClassStretches a link's hit area over its nearestrelativeancestor, so a whole row or card opens it; add it to the one link in the row.