本文へスキップ
Ginga UI
Ginga UI
English

はじめに

  • 概要
  • クイックスタート
  • テーマ生成
  • 要素の差し替え
  • 全コンポーネント

フォーム

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

表示

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

タイポグラフィ

  • Heading
  • Paragraph

ナビゲーション

  • Anchor

レイアウト

  • Box

リソース

  • 変更履歴
  • GitHub(新しいタブで開く)

ロゴ: Twemoji(新しいタブで開く) (CC-BY 4.0)

Anchor

リンクを作成するアンカーコンポーネント。

Storybook で見る(新しいタブで開く)

インストール

import { Anchor } from "@ginga-ui/core";

基本的な使い方

シンプルなリンクの使用例です。

リンクをクリック
anchor.tsx
import { Anchor } from "@ginga-ui/core";

export function BasicExample() {
  return <Anchor href="https://example.com">リンクをクリック</Anchor>;
}

外部リンク

外部サイトへのリンクを新しいタブで開きます。

GitHubで開く(新しいタブ)
anchor.tsx
import { Anchor } from "@ginga-ui/core";

export function ExternalExample() {
  return (
    <Anchor href="https://github.com/newt239/ginga-ui" target="_blank">
      GitHubで開く(新しいタブ)
    </Anchor>
  );
}

無効化

disabledプロップでリンクを無効化できます。

通常のリンク無効化されたリンク
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">通常のリンク</Anchor>
      <Anchor href="https://example.com" disabled>
        無効化されたリンク
      </Anchor>
    </div>
  );
}

ボタンスタイル

variant="button"でボタンのような見た目のリンクになります。buttonVariantとsizeでButtonと同じバリアントとサイズを指定できます。

FilledLightOutlineGhost
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>
  );
}

ルーターのリンク

render に関数を渡すと、next/link などの別のコンポーネントでリンクを描画できます。受け取った props は ref も含めて a 要素に渡してください。

コンポーネント一覧へ
anchor.tsx
import { Anchor } from "@ginga-ui/core";
import NextLink from "next/link";

export function RouterLinkExample() {
  return (
    <Anchor href="/ja/components" render={(props) => <NextLink {...props} />}>
      コンポーネント一覧へ
    </Anchor>
  );
}

Props

Anchor

名前型既定値説明
variant"default" | "button""default"リンクの見た目。"button" を指定すると Button と同じ見た目になります。
buttonVariant"filled" | "light" | "outline" | "ghost" | "reverse""filled"variant が "button" のときのボタンのバリアント。
size"sm" | "md" | "lg""md"variant が "button" のときのボタンのサイズ。
disabledbooleanfalseリンクを無効にします。
startIconReactNode-variant が "button" のときにラベルの前に表示するアイコン。
endIconReactNode-variant が "button" のときにラベルの後に表示するアイコン。
render(props, renderProps) => ReactElement-ルート要素を next/link などに差し替える関数。href があるときだけ使われます。

上記に加えて、React Aria の Link(新しいタブで開く) の props を受け取ります。