Link
This component provides a visual cue that indicates interactivity of plain text
Basic Usage
Note: The
Linkcomponent should always be wrapped inside aTypographycomponent, so that theLinkfont size and weight will inherit from the font around it.
import { Link } from '@krakentech/coral/atoms';
<Typography>
<Link href="#">This is a link</Link>
</Typography>Properties
color
<Typography>
<Link href="#" color="dark">
This is a link
</Link>
</Typography>
<Typography color="error">
<Link href="#" color="inherit">
This is a link
</Link>
</Typography>download
<Typography>
<Link href="#" download>
This tells the browser to download rather than redirect
</Link>
</Typography>target
<Typography>
<Link href="#" target="_blank">
This is a link that opens in a new window
</Link>
</Typography>Responsiveness
<Typography>
<Link href="#" color={{ base: "tertiary500", md: "secondary500" }}>
This is a link
</Link>
</Typography>Next.js Typed Routes
LinkProps is generic over the href type, which means you can integrate with Next.js statically typed linksΒ by creating a thin wrapper in your app.
First, ensure typedRoutes is enabled in your next.config.ts:
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
typedRoutes: true,
};
export default nextConfig;Then create a typed wrapper component in your repository:
import { Link as CoralLink } from '@krakentech/coral/atoms';
import type { LinkProps } from '@krakentech/coral-types';
import type { Route } from 'next';
export function Link<T extends string>(props: LinkProps<Route<T>>) {
return <CoralLink {...props} />;
}Now TypeScript will validate that href values are valid routes in your application:
import { Link } from '@components/typed-link/Link';
// β
Valid route β no error
<Link href="/about">About</AppLink>
// β Invalid route β TypeScript error
<Link href="/aboot">About</AppLink>
// For non-literal strings, cast with as Route
<Link href={('/blog/' + slug) as Route}>Blog Post</AppLink>Full API
Design
Good to know
Choose a link when you want to redirect the user to an external site or to a document, this will usually precede or follow some text e.g βDonβt have an account? Sign upβ. It is really important that link copy isnβt super vague, make it specific, clear and friendly.
What is the difference between a button and a link?
The short answer is a button does something and a link goes somewhere. The longer answer, buttons perform an action, should attract users attention and usually encourage conversion. Links should re-direct.
Why are there two colour variations?
Our primary theme is our voltage link, this should be used 99% of the time. Our secondary ink variation is to be used on top of ice.
Component breakdown
- Text: Button text
- Resting colour: Voltage & Ink
- Hover colour: Aquamarine & Blue Tang