コンテンツにスキップ
Page

Field

ラベル、コントロール、ヒント、エラーメッセージをまとめます。

We never share your email.
import {
Field,
FieldLabel,
FieldHint,
FieldError,
FieldRequired,
} from "@pelagornis/page/components";

上のプレビューはこのファイルを描画したものです。src/components/ にコピーして使い始めてください。

src/components/FieldExample.tsx
import { Field, FieldError, FieldHint, FieldLabel, FieldRequired, Input, Stack } from "@pelagornis/page/components";
export default function FieldDemo() {
return (
<Stack gap="sizeLarge" className="w-full max-w-sm">
<Field>
<FieldLabel htmlFor="field-email">Email address</FieldLabel>
<Input id="field-email" type="email" placeholder="you@example.com" fullWidth />
<FieldHint>We never share your email.</FieldHint>
</Field>
<Field>
<FieldLabel htmlFor="field-password">
Password <FieldRequired />
</FieldLabel>
<Input id="field-password" type="password" error fullWidth />
<FieldError>Password is required.</FieldError>
</Field>
</Stack>
);
}

Field は React の状態を共有する複数のパーツで構成されます。MDX に書いた子要素はそれぞれ別のアイランドとして描画されるため、パーツ同士がつながりません。上の例のように .tsx ファイルで組み立て、そのファイルをインポートしてください。

src/content/docs/example.mdx
---
title: Example
---
import FieldExample from "../../components/FieldExample";
<FieldExample client:load />

client:load はページの読み込み時にアイランドをハイドレートします。ページの下の方にあるコンテンツには client:visible を使ってください。

Markdoc のタグは Astro コンポーネントを描画しますが、このコンポーネントにはクライアントの状態が必要です。例をハイドレートする .astro ファイルで包み、そのファイルをタグとして登録してください。

src/components/markdoc/FieldExample.astro
---
import FieldExample from "../FieldExample";
---
<FieldExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"field-example": {
render: component("./src/components/markdoc/FieldExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% field-example /%}

各 variant prop が受け付ける値です。

Prop値
sizesm md lg

コンポーネントを構成するパーツと、それぞれが描画する data-refineui のロールです。

パーツロール
rootfield
errorfield-error
hintfield-hint