버튼

GHDS 컴포넌트 문서 표준의 참조 구현입니다.

이 페이지는 GHDS 컴포넌트 문서 표준의 참조 구현이에요 — 앞으로의 모든 컴포넌트 페이지(Card, Input, M10/M11의 모든 컴포넌트)는 동일한 8개 섹션을 같은 순서로 따라요.

개요

Button은 단일하고 즉각적인, 사용자가 시작하는 동작을 실행해요 — 폼 제출, 선택 확인, 무언가 열기. 목적지가 내비게이션(동작이 아닌)일 때는 링크를 대신 사용하세요 — React에서는 <a>를 asChild로 감싸고, Web Components에서는 <gh-button>에 href를 지정하면 같은 버튼 스타일의 실제 <a href>로 렌더돼요.

구조

실제 <button>(또는 React에서 asChild를 통한 Radix Slot 렌더 요소, <gh-button>에 href를 지정했을 때는 실제 <a href>)이 모든 네이티브 키보드 및 클릭 시맨틱을 가져요. 라벨 뒤에 손그림 SketchSurface 외곽선이 있으며 순전히 장식용이에요(aria-hidden="true", focusable="false", 툴링용 SVG <title> 포함) — 의미를 전달하지 않으므로 제거해도 버튼의 동작이나 알려지는 방식이 변하지 않아요.

변형 및 상태

정확히 세 가지 변형이 있어요: primary, danger, neutral — secondary, ghost, link 변형은 없어요.

State Status Notes
기본 Implemented —
Hover Implemented 변형에 따라 채우기/텍스트 색상이 변해요.
Active / 눌림 Implemented —
Focus Implemented 수동 포커스 링(comp.button.focus.ring)이지 네이티브 :focus-visible이 아니에요.
비활성화 Implemented —
로딩 Not implemented —
오류 Not implemented —

사용법

Do

  • 파괴적이거나 되돌릴 수 없는 동작에만 danger를 사용하세요.
  • 버튼처럼 보이지만 페이지를 이동해야 할 때 asChild(React)나 href(Web Components)로 링크 시맨틱을 유지하세요.
  • 뷰마다 하나의 primary 버튼을 유지하세요 — 주요 동작이 명확해야 해요.

Don't

  • 색상만으로 위험 동작을 전달하지 마세요 — 라벨이 무슨 일이 일어나는지 말해줘야 해요.
  • 화면 다른 곳에 이유를 설명하지 않고 버튼을 비활성화하지 마세요.
  • 네이티브 <button> 안에 <a>를 중첩하지 마세요 — asChild(React)나 href(Web Components)를 대신 사용하세요.

접근성

콘텐츠

라벨은 짧은 동사 구예요 — “Delete”, “Cancel”, “Save changes” — 문장이 아니며 끝에 문장 부호가 없어요.

Props API

React@ghds/react

PropTypeDefaultDescription
variant'primary' | 'danger' | 'neutral''primary'시각적 의도.
asChildbooleanfalse<button> 대신 단일 자식 요소(Radix Slot)로 렌더해요.
disabledbooleanfalse인터랙션을 비활성화해요.
type'button' | 'submit' | 'reset''button'네이티브 버튼 타입.
...restButtonHTMLAttributes—다른 모든 네이티브 <button> 속성이 전달돼요.

Web Components@ghds/web-components

PropTypeDefaultDescription
variant'primary' | 'danger' | 'neutral''primary'reflected 속성.
type'button' | 'submit' | 'reset''button'폼 연결을 구동해요(formAssociated = true).
disabledbooleanfalsereflected 속성. href보다 우선해요 — 비활성화된 버튼은 shadow 링크가 아니라 <button>으로 렌더돼요. 라이트 DOM <a href> 자식은 링크로 남고, aria-disabled="true"가 지정되며 컴포넌트가 업그레이드된 뒤 활성화가 취소돼요.
hrefstring—지정하면(비활성화가 아닐 때) <button> 대신 실제 <a href>로 렌더하고, 변형·포커스 스타일은 그대로 유지해요.
targetstring—href가 있을 때 내부 <a>로 전달돼요.
relstring—href가 있을 때 내부 <a>로 전달돼요(예: target='_blank'와 함께 'noopener noreferrer').

React Native@ghds/react-native

PropTypeDefaultDescription
labelstring—보이는 접근성 라벨 — 필수(children 없음).
onPress(event: GestureResponderEvent) => void—누름 핸들러.
variant'primary' | 'danger''primary'React Native에는 neutral 변형이 없어요.
disabledbooleanfalse인터랙션을 비활성화해요.
testIDstring—쿼리용 테스트 핸들.
accessibilityHintstring—동작 결과를 설명하는 보조 a11y 힌트.

코드 예시

// React — @ghds/react
import { Button } from '@ghds/react/button';

<Button variant="primary">Primary</Button>;
<Button variant="danger">Delete</Button>;
<Button variant="neutral">Cancel</Button>;

// 링크로 렌더하기 — <a> 시맨틱을 유지하면서 버튼 스타일을 입혀요
<Button asChild variant="primary">
  <a href="/getting-started/">Get Started →</a>
</Button>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
  import '@ghds/web-components/button';
</script>
<gh-button variant="primary">Primary</gh-button>
<gh-button variant="danger">Delete</gh-button>
<gh-button variant="neutral">Cancel</gh-button>

<!-- 링크로 렌더하기 — shadow root 안에 실제 <a href>를 렌더해요 -->
<gh-button variant="primary" href="/getting-started/">Get Started →</gh-button>
<gh-button variant="neutral" href="https://example.com/" target="_blank" rel="noopener noreferrer">
  External
</gh-button>

<!-- 라이트 DOM 링크: JS가 실행되기 전부터 정적 HTML에 <a href>가 있어요(크롤러, JS를
     끈 방문자). gh-button이 슬롯된 앵커를 스타일링하고, target / rel / aria-label은
     앵커에 직접 지정해요. -->
<gh-button variant="primary"><a href="/getting-started/">Get Started →</a></gh-button>
// React Native — @ghds/react-native ('neutral' 변형이 없어요. 자식 대신 label 문자열과 onPress를 써요)
import { Button } from '@ghds/react-native/button';

<Button label="Delete" variant="danger" onPress={() => {}} />;

라이브 데모

React와 Web Components가 아래에 라이브로 렌더돼요. 동일한 토큰으로 구동되며 — 헤더에서 다크 모드를 토글하면 둘 다 동일하게 반응해요. React Native는 추가 react-native-web 연결 없이는 브라우저에서 실행할 수 없어요(이 사이트에 설정되지 않음), 따라서 사용법은 코드 샘플로 보여줘요.

React @ghds/react

Web Components @ghds/web-components

Primary Delete Cancel Disabled