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

Accordion (아코디언)

원문 보기 위키 갱신

Accordion은 정보를 컴팩트한 공간에 정리하기 위한 접기/펼치기 콘텐츠 패널이에요. 해요체로 쉽게 설명드릴게요.

출처: HeroUI Accordion

본문

사용법 (Usage)

import { Accordion } from '@heroui/react';
{"name": "accordion-basic", "minHeight": "400px"}

구조 (Anatomy)

import { Accordion } from '@heroui/react';

export default () => (
  <Accordion>
    <Accordion.Item>
      <Accordion.Heading>
        <Accordion.Trigger>
          <Accordion.Indicator />
        </Accordion.Trigger>
      </Accordion.Heading>
      <Accordion.Panel>
        <Accordion.Body/>
      </Accordion.Panel>
    </Accordion.Item>
  </Accordion>
)

예시 (Examples)

Surface

{"name": "accordion-surface", "minHeight": "400px"}

구분선 없이 (Without Separator)

{"name": "accordion-without-separator", "minHeight": "400px"}

다중 펼침 (Multiple Expanded)

{"name": "accordion-multiple", "minHeight": "524px"}

비활성화 상태 (Disabled State)

{"name": "accordion-disabled", "minHeight": "524px"}

제어된 상태 (Controlled)

{"name": "accordion-controlled", "minHeight": "400px"}

사용자 지정 인디케이터 (Custom Indicator)

{"name": "accordion-custom-indicator", "minHeight": "320px"}

렌더 함수 (Render Function)

{"name": "accordion-render-function", "minHeight": "400px"}

FAQ 레이아웃 (FAQ Layout)

{"name": "accordion-faq", "minHeight": "720px"}

커스터마이징 (Customization)

Tailwind CSS

{"name": "accordion-custom-styles"}

Global CSS

Accordion 컴포넌트 클래스를 커스터마이징하려면 @layer components 지시어를 사용할 수 있어요. 더 알아보기.

@layer components {
  .accordion {
    @apply rounded-xl bg-gray-50;
  }

  .accordion__trigger {
    @apply font-semibold text-lg;
  }

  .accordion--outline {
    @apply shadow-lg border-2;
  }
}

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.

CSS 클래스 (CSS Classes)

Accordion 컴포넌트는 다음 CSS 클래스를 사용해요 (소스 스타일 보기):

기본 클래스 [!toc]

  • .accordion - 기본 아코디언 컨테이너
  • .accordion__body - 콘텐츠 본문 컨테이너
  • .accordion__heading - 헤딩 래퍼
  • .accordion__indicator - 펼침/접힘 인디케이터 아이콘
  • .accordion__item - 개별 아코디언 항목
  • .accordion__panel - 접을 수 있는 패널 컨테이너
  • .accordion__trigger - 클릭 가능한 트리거 버튼

변형 클래스 [!toc]

  • .accordion--outline - 테두리와 배경이 있는 아웃라인 변형

상태 클래스 [!toc]

  • .accordion__trigger[aria-expanded="true"] - 펼쳐진 상태
  • .accordion__panel[aria-hidden="false"] - 패널 표시 상태

상호작용 상태 (Interactive States)

컴포넌트는 유연성을 위해 CSS 의사 클래스와 데이터 속성을 모두 지원해요:

  • 호버 (Hover): 트리거의 :hover 또는 [data-hovered="true"]
  • 포커스 (Focus): 트리거의 :focus-visible 또는 [data-focus-visible="true"]
  • 비활성화 (Disabled): 트리거의 :disabled 또는 [aria-disabled="true"]
  • 펼침 (Expanded): 트리거의 [aria-expanded="true"]

API 참고 (API Reference)

Accordion

Prop Type Default Description
allowsMultipleExpanded boolean false Whether multiple items can be expanded at once
defaultExpandedKeys Iterable<Key> - The initial expanded keys
expandedKeys Iterable<Key> - The controlled expanded keys
onExpandedChange (keys: Set<Key>) => void - Handler called when expanded keys change
isDisabled boolean false Whether the entire accordion is disabled
variant "default" | "surface" "default" The visual variant of the accordion
hideSeparator boolean false Hide separator lines between accordion items
className string - Additional CSS classes
children ReactNode - The accordion items
render DOMRenderFunction<keyof React.JSX.IntrinsicElements, AccordionRenderProps> - Overrides the default DOM element with a custom render function.

Accordion.Item

Prop Type Default Description
id Key - Unique identifier for the item
isDisabled boolean false Whether this item is disabled
defaultExpanded boolean false Whether item is initially expanded
isExpanded boolean - Controlled expanded state
onExpandedChange (isExpanded: boolean) => void - Handler for expanded state changes
className string - Additional CSS classes
children ReactNode - The item content
render DOMRenderFunction<keyof React.JSX.IntrinsicElements, AccordionItemRenderProps> - Overrides the default DOM element with a custom render function.

Accordion.Trigger

Prop Type Default Description
className string - Additional CSS classes
children ReactNode | RenderFunction - Trigger content or render function
onPress () => void - Additional press handler
isDisabled boolean - Whether trigger is disabled
render DOMRenderFunction<keyof React.JSX.IntrinsicElements, TriggerRenderProps> - Overrides the default DOM element with a custom render function.

Accordion.Panel

Prop Type Default Description
className string - Additional CSS classes
children ReactNode - Panel content
render DOMRenderFunction<keyof React.JSX.IntrinsicElements, AccordionPanelRenderProps> - Overrides the default DOM element with a custom render function.

Accordion.Indicator

Prop Type Default Description
className string - Additional CSS classes
children ReactNode - Custom indicator icon

Accordion.Body

Prop Type Default Description
className string - Additional CSS classes
children ReactNode - Body content

더 알아보기 (Learn more)