콘텐츠로 이동
Page

Search Field

검색 아이콘과 지우기 버튼이 있는 검색어 입력입니다.

Query: —
import { SearchField } from "@pelagornis/page/components";

위 미리보기는 이 파일을 렌더링한 것입니다. src/components/에 복사해서 시작하세요.

src/components/SearchFieldExample.tsx
import { useState } from "react";
import { SearchField, Stack, Text } from "@pelagornis/page/components";
export default function SearchFieldDemo() {
const [query, setQuery] = useState("");
return (
<Stack gap="sizeSmall" className="w-full max-w-sm">
<SearchField value={query} onValueChange={setQuery} aria-label="Search components" />
<SearchField appearance="plain" defaultValue="tokens" aria-label="Plain search" />
<Text variant="captionMd">Query: {query || "—"}</Text>
</Stack>
);
}

Search Field 컴포넌트는 .mdx 페이지에 바로 쓸 수 있습니다. frontmatter 아래에서 가져오세요. 입력에 반응하므로 client:load를 붙여 하이드레이션합니다.

src/content/docs/example.mdx
---
title: Example
---
import { SearchField } from "@pelagornis/page/components";
<SearchField client:load defaultValue="tokens" aria-label="Search" />

Markdoc 태그는 Astro 컴포넌트를 렌더링하는데, 이 컴포넌트는 클라이언트 상태가 필요합니다. 예제를 하이드레이션하는 .astro 파일로 감싼 뒤, 그 파일을 태그로 등록하세요.

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

각 variant prop에 넣을 수 있는 값입니다.

Prop값
appearancefilled plain
sizesm md lg

컴포넌트를 이루는 부분과 각 부분이 렌더링하는 data-refineui 역할입니다.

부분역할
rootsearch-field
clearsearch-field-clear
iconsearch-field-icon
inputsearch-field-input

컴포넌트가 스타일을 적용하는 상태입니다. 컴포넌트 상태는 data 속성으로 드러납니다.

종류상태
의사 클래스focus-visible

포커스가 있을 때 컴포넌트가 처리하는 키입니다.

키동작
Escapeclose