Anchor
An anchor component for creating links.
View in Storybook (opens in a new tab)
Installation
import { Anchor } from "@ginga-ui/core";Basic usage
A simple link example.
anchor.tsx
import { Anchor } from "@ginga-ui/core";
export function BasicExample() {
return <Anchor href="https://example.com">Click the link</Anchor>;
}External link
Opens a link to an external site in a new tab.
anchor.tsx
import { Anchor } from "@ginga-ui/core";
export function ExternalExample() {
return (
<Anchor href="https://github.com/newt239/ginga-ui" target="_blank">
Open on GitHub (new tab)
</Anchor>
);
}Disabled
Use the disabled prop to disable the link.
Regular linkDisabled link
anchor.tsx
anchor.module.css
import { Anchor } from "@ginga-ui/core";
import styles from "./anchor.module.css";
export function DisabledExample() {
return (
<div className={styles.linkStack}>
<Anchor href="https://example.com">Regular link</Anchor>
<Anchor href="https://example.com" disabled>
Disabled link
</Anchor>
</div>
);
}Button style
Use variant="button" to make the link look like a button. buttonVariant and size accept the same variants and sizes as Button.
anchor.tsx
anchor.module.css
import { Anchor } from "@ginga-ui/core";
import styles from "./anchor.module.css";
export function ButtonVariantExample() {
return (
<div className={styles.buttonRow}>
<Anchor href="https://example.com" variant="button">
Filled
</Anchor>
<Anchor href="https://example.com" variant="button" buttonVariant="light">
Light
</Anchor>
<Anchor
href="https://example.com"
variant="button"
buttonVariant="outline"
>
Outline
</Anchor>
<Anchor href="https://example.com" variant="button" buttonVariant="ghost">
Ghost
</Anchor>
</div>
);
}Router link
Pass a function to render to draw the link with another component such as next/link. Pass the received props, including ref, to an a element.
anchor.tsx
import { Anchor } from "@ginga-ui/core";
import NextLink from "next/link";
export function RouterLinkExample() {
return (
<Anchor href="/components" render={(props) => <NextLink {...props} />}>
Go to components
</Anchor>
);
}Props
Anchor
| Name | Type | Default | Description |
|---|---|---|---|
variant | "default" | "button" | "default" | Appearance of the link. "button" makes it look like a Button. |
buttonVariant | "filled" | "light" | "outline" | "ghost" | "reverse" | "filled" | Button variant used when variant is "button". |
size | "sm" | "md" | "lg" | "md" | Button size used when variant is "button". |
disabled | boolean | false | Disables the link. |
startIcon | ReactNode | - | Icon shown before the label when variant is "button". |
endIcon | ReactNode | - | Icon shown after the label when variant is "button". |
render | (props, renderProps) => ReactElement | - | Replaces the root element, such as with next/link. It is used only when href is set. |
Also accepts the props of React Aria's Link (opens in a new tab).