Button
버튼 또는 버튼처럼 보이는 컴포넌트를 표시합니다.
설치
사용법
import { Button } from "@/components/ui/button"<Button variant="outline">Button</Button>KRDS 정렬
- 분류: 기존 shadcn
buttonprimitive를 유지하는 KRDS-styled 컴포넌트입니다.Button,buttonVariants,asChild사용 방식은 shadcn 패턴과 호환됩니다. - KRDS 적용:
default는 KRDS primary 버튼으로 렌더링되며primary,tertiary,text는 기존 variant를 깨지 않는 추가 alias/확장입니다. - 사용 권장: 아이콘 버튼과 인라인 아이콘 간격은 기존 예제처럼
data-icon="inline-start"또는data-icon="inline-end"로 명시하세요.
커서
Tailwind v4는 Button에 대해 기본 커서를 cursor: default로 둡니다.
cursor: pointer 동작을 유지하려면 CSS 파일에 다음 코드를 추가하세요.
이 옵션은 프로젝트 설정 단계에서도 pointer cursor 옵션으로 활성화할 수 있습니다.
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}예제
Size
size prop으로 Button 크기를 변경합니다.
Default
Outline
Secondary
Ghost
Destructive
Link
KRDS의 텍스트 링크는 Button의 variant="link"로 통합되었습니다. 별도의 Link 컴포넌트는 호환을 위해 남아 있지만 새 코드는 <Button variant="link" asChild> 패턴을 사용하세요.
<Button variant="link" asChild>
<a href="/notice">공지사항 바로가기</a>
</Button>외부 링크에는 target="_blank"와 rel="noreferrer"를 명시하고, 시각적 표시를 위해 인라인으로 외부 링크 아이콘을 추가합니다.
import { ExternalLinkIcon } from "lucide-react"
<Button variant="link" asChild>
<a href="https://www.krds.go.kr" target="_blank" rel="noreferrer">
KRDS 가이드라인
<ExternalLinkIcon aria-label="새 창 열림" />
</a>
</Button>KRDS 텍스트 컬러 톤(기본/본문/약함)이 필요할 때는 className으로 토큰을 적용합니다.
| 톤 | className |
|---|---|
| 기본(파랑) | (variant 기본값) |
| 본문 톤 | text-foreground hover:text-[var(--krds-light-color-link-hover,#0b50d0)] |
| 약함 | text-muted-foreground hover:text-foreground |
| 항상 밑줄 | underline |
Icon
With Icon
Remember to add the data-icon="inline-start" or data-icon="inline-end" attribute to the icon for the correct spacing.
Rounded
rounded-full 클래스로 Button을 둥글게 만듭니다.
Spinner
버튼 안에 <Spinner /> 컴포넌트를 렌더링해 로딩 상태를 표시합니다. 올바른 간격을 위해 스피너에 data-icon="inline-start" 또는 data-icon="inline-end" 속성을 추가하세요.
Button Group
To create a button group, use the ButtonGroup component. Button Group documentation for more details.
As Child
<Button />의 asChild prop으로 다른 컴포넌트를 버튼처럼 렌더링할 수 있습니다. 링크를 버튼 형태로 표시하는 예시는 다음과 같습니다.
RTL
RTL 지원을 활성화하려면 RTL 설정 가이드를 참고하세요.
API 참조
Button
Button 컴포넌트는 button 요소 위에 KRDS 스타일과 공통 동작을 얹는 래퍼입니다.
| 속성 | 타입 | 기본값 |
|---|---|---|
variant | "default" | "primary" | "secondary" | "outline" | "tertiary" | "ghost" | "text" | "destructive" | "link" | "default" |
size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "default" |
asChild | boolean | false |