コンテンツにスキップ
Page

Alert

アイコン、タイトル、アクションを持つインラインの状態メッセージです。

import {
Alert,
AlertRow,
AlertIcon,
AlertBody,
AlertTitle,
AlertDescription,
AlertClose,
AlertActions,
AlertAction,
} from "@pelagornis/page/components";

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

src/components/AlertExample.tsx
import {
Alert,
AlertAction,
AlertActions,
AlertBody,
AlertClose,
AlertDescription,
AlertIcon,
AlertRow,
AlertTitle,
Stack,
} from "@pelagornis/page/components";
export default function AlertDemo() {
return (
<Stack gap="sizeMedium" className="w-full">
<Alert variant="info">
<AlertRow>
<AlertIcon />
<AlertBody>
<AlertTitle>Heads up</AlertTitle>
<AlertDescription>The plugin injects RefineUI styles for you.</AlertDescription>
</AlertBody>
</AlertRow>
</Alert>
<Alert variant="warning">
<AlertRow>
<AlertIcon />
<AlertBody>
<AlertTitle>Review before publishing</AlertTitle>
<AlertDescription>Two pages have no description.</AlertDescription>
</AlertBody>
<AlertClose type="button" />
</AlertRow>
<AlertActions>
<AlertAction type="button">Review</AlertAction>
</AlertActions>
</Alert>
</Stack>
);
}

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

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

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

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

src/components/markdoc/AlertExample.astro
---
import AlertExample from "../AlertExample";
---
<AlertExample 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: {
"alert-example": {
render: component("./src/components/markdoc/AlertExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% alert-example /%}

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

Prop値
variantdefault info success warning danger custom

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

パーツロール
rootalert
iconalert-icon
contentalert-content
rowalert-row
bodyalert-body
titlealert-title
descriptionalert-description
actionsalert-actions
actionalert-action
closealert-close

コンポーネントがスタイルを当てる状態です。コンポーネントの状態は data 属性として公開されます。

種類状態
疑似クラスfocus-visible