跳转到内容
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