본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

콘텐츠 검색 버튼

원문 보기 위키 갱신

콘텐츠 검색 버튼 (ContentSearchButton)

콘텐츠 검색 버튼(ContentSearchButton)은 ContentSearch 모달을 열어주는 미리 스타일이 적용된 버튼 컴포넌트예요. 문서 검색 기능을 사이트 어디에나 쉽게 달 수 있도록 도와줘요.

출처: Nuxt UI

본문

ContentSearch 모달을 열어주는 미리 스타일된 버튼이에요.

[!WARNING] See: /docs/getting-started/integrations/content

이 컴포넌트는 @nuxt/content 모듈이 설치되어 있을 때만 사용할 수 있어요.

사용법 (Usage)

ContentSearchButton 컴포넌트는 ContentSearch 모달을 여는 데 사용해요.

<template>
  <UContentSearchButton />
</template>

이 컴포넌트는 Button 컴포넌트를 확장하므로 color, variant, size 같은 속성을 그대로 전달할 수 있어요.

<template>
  <UContentSearchButton variant="subtle" />
</template>

[!NOTE] See: #collapsed

이 버튼은 접히지 않은 상태일 때 기본적으로 color="neutral", variant="outline"을, 접힌 상태일 때는 variant="ghost"를 사용해요.

Collapsed (접힌 상태)

collapsed prop으로 버튼의 라벨과 kbds 표시 여부를 정할 수 있어요. 기본값은 true예요.

<template>
  <UContentSearchButton :collapsed="false" />
</template>

Kbds (키보드 키)

kbds prop으로 버튼 안에 표시할 키보드 키를 정할 수 있어요. 기본값은 ['meta', 'K']로, ContentSearch 컴포넌트의 기본 단축키와 맞춰져 있어요.

<template>
  <UContentSearchButton :collapsed="false" :kbds="[
  'alt',
  'O'
]" />
</template>

API

Props

/**
 * Props for the ContentSearchButton component
 */
interface ContentSearchButtonProps {
  /**
   * The icon displayed in the button. Set to `false` to hide the icon.
   * @default appConfig.ui.icons.search
   */
  icon?: any;
  /**
   * The label displayed in the button.
   * @default t('contentSearchButton.label')
   */
  label?: string | undefined;
  /**
   * The color of the button.
   * @default 'neutral'
   */
  color?: "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning" | undefined;
  /**
   * The variant of the button.
   * Defaults to 'outline' when not collapsed, 'ghost' when collapsed.
   */
  variant?: "solid" | "outline" | "soft" | "subtle" | "ghost" | "link" | undefined;
  /**
   * Whether the button is collapsed.
   * @default true
   */
  collapsed?: boolean | undefined;
  /**
   * Display a tooltip on the button when is collapsed with the button label.
   * This has priority over the global `tooltip` prop.
   * @default false
   */
  tooltip?: boolean | TooltipProps | undefined;
  /**
   * The keyboard keys to display in the button.
   * `{ variant: 'subtle' }`{lang="ts-type"}
   * @default ["meta", "k"]
   */
  kbds?: (string | undefined)[] | KbdProps[] | undefined;
  ui?: { base?: SlotClass; label?: SlotClass; trailing?: SlotClass; } & { base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; } | undefined;
  /**
   * Class to apply when the link is exact active
   */
  exactActiveClass?: string | undefined;
  /**
   * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
   */
  viewTransition?: boolean | undefined;
  autofocus?: false | true | "true" | "false" | undefined;
  disabled?: boolean | undefined;
  form?: string | undefined;
  formaction?: string | undefined;
  formenctype?: string | undefined;
  formmethod?: string | undefined;
  formnovalidate?: false | true | "true" | "false" | undefined;
  formtarget?: string | undefined;
  name?: string | undefined;
  /**
   * The type of the button when not a link.
   * @default 'button'
   */
  type?: "reset" | "submit" | "button" | undefined;
  onClick?: (event: MouseEvent): void | ((event: MouseEvent) => void)[] | undefined;
  /**
   * The element or component this component should render as when not a link.
   * @default 'button'
   */
  as?: any;
  activeColor?: "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning" | undefined;
  activeVariant?: "solid" | "outline" | "soft" | "subtle" | "ghost" | "link" | undefined;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
  /**
   * Render the button with equal padding on all sides.
   */
  square?: boolean | undefined;
  /**
   * Render the button full width.
   */
  block?: boolean | undefined;
  /**
   * Set loading state automatically based on the `@click` promise state
   */
  loadingAuto?: boolean | undefined;
  /**
   * Display an avatar on the left side.
   */
  avatar?: AvatarProps | undefined;
  /**
   * When `true`, the icon will be displayed on the left side.
   */
  leading?: boolean | undefined;
  /**
   * Display an icon on the left side.
   */
  leadingIcon?: any;
  /**
   * When `true`, the icon will be displayed on the right side.
   */
  trailing?: boolean | undefined;
  /**
   * Display an icon on the right side.
   */
  trailingIcon?: any;
  /**
   * When `true`, the loading icon will be displayed.
   */
  loading?: boolean | undefined;
  /**
   * The icon when the `loading` prop is `true`.
   * @default appConfig.ui.icons.loading
   */
  loadingIcon?: any;
}

[!NOTE] See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes

이 컴포넌트는 기본 <button> HTML 속성도 모두 지원해요.

Slots

/**
 * Slots for the ContentSearchButton component
 */
interface ContentSearchButtonSlots {
  leading(): any;
  default(): any;
  trailing(): any;
}

테마 (Theme)

export default defineAppConfig({
  ui: {
    contentSearchButton: {
      slots: {
        base: '',
        label: '',
        trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
      },
      variants: {
        collapsed: {
          true: {
            label: 'hidden',
            trailing: 'lg:hidden'
          }
        }
      }
    }
  }
})

변경 기록 (Changelog)

컴포넌트와 테마의 커밋 히스토리를 확인해 보세요.

더 알아보기 (Learn more)