コンテンツにスキップ
Page

Command

検索できるコマンド一覧です。ヘッダーの検索は CommandDialog の中でこれを使います。

import {
Command,
CommandInput,
CommandList,
CommandEmpty,
CommandGroup,
CommandGroupHeading,
CommandItem,
CommandSeparator,
CommandDialog,
} from "@pelagornis/page/components";

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

src/components/CommandExample.tsx
import {
Command,
CommandEmpty,
CommandGroup,
CommandGroupHeading,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
} from "@pelagornis/page/components";
export default function CommandDemo() {
return (
<Command label="Commands" className="w-full max-w-sm">
<CommandInput placeholder="Search commands…" />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
<CommandGroupHeading>File</CommandGroupHeading>
<CommandItem value="new" shortcut="⌘N">
New file
</CommandItem>
<CommandItem value="open">Open</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup>
<CommandGroupHeading>Edit</CommandGroupHeading>
<CommandItem value="copy">Copy</CommandItem>
<CommandItem value="paste">Paste</CommandItem>
</CommandGroup>
</CommandList>
</Command>
);
}

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

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

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

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

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

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

パーツロール
rootcommand
emptycommand-empty
groupcommand-group
group_headingcommand-group-heading
indicatorcommand-indicator
inputcommand-input
itemcommand-item
listcommand-list
separatorcommand-separator
shortcutcommand-shortcut

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

種類状態
疑似クラスfocus-visible
data-statedisabled active default

フォーカスがあるときにコンポーネントが処理するキーです。

キー動作
ArrowDownnext-trigger
ArrowUpprevious-trigger
Homefirst-trigger
Endlast-trigger
Enteractivate