Button (Button)
Button은 눌렀을 때 어떤 동작을 실행하는 상호작용 컴포넌트예요. HeroUI Native의 Button은 문자열 children을 라벨로 자동 렌더링하고, Button.Label, Button.Background 같은 컴파운드 파트로 자유롭게 꾸밀 수 있답니다. 피드백 애니메이션과 크기·variant도 풍부하게 제공해요.
출처: 문서
본문
Import
import { Button } from 'heroui-native';
Anatomy
<Button>
<Button.Label>...</Button.Label>
</Button>
- Button: 누르기 상호작용, 애니메이션, variant를 처리하는 메인 컨테이너예요. 문자열 children을 라벨로 렌더링하거나 컴파운드 컴포넌트로 사용자 정의 레이아웃을 지원해요.
- Button.Background: 버튼 표면 뒤에 렌더링되는 선택적 테마 인식 배경 컨테이너예요. 활성 테마가 기본 배경 콘텐츠(예:
glass)를 등록했을 때secondary와tertiaryvariant에 대해 자동으로 마운트돼요.backgroundprop으로 교체하거나 제거할 수 있어요. - Button.Label: 버튼의 텍스트 콘텐츠예요. 부모 Button 컨텍스트에서 크기와 variant 스타일을 상속받아요.
Usage
기본 사용법
Button 컴포넌트는 문자열 children을 받아 자동으로 라벨로 렌더링해요.
<Button>Basic Button</Button>
컴파운드 파트 사용
라벨 컴포넌트를 명시적으로 제어하려면 Button.Label을 사용하세요.
<Button>
<Button.Label>Click me</Button.Label>
</Button>
아이콘과 함께
시각적 커뮤니케이션을 강화하려면 아이콘과 라벨을 조합하세요.
<Button>
<Icon name="add" size={20} />
<Button.Label>Add Item</Button.Label>
</Button>
<Button>
<Button.Label>Download</Button.Label>
<Icon name="download" size={18} />
</Button>
아이콘만
isIconOnly prop으로 정사각형 아이콘 전용 버튼을 만들 수 있어요.
<Button isIconOnly accessibilityLabel="Like">
<Icon name="heart" size={18} />
</Button>
크기 (Sizes)
세 가지 크기 옵션으로 버튼 치수를 제어할 수 있어요.
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
Variant
강조 수준이 다른 일곱 가지 시각적 variant 중에서 선택하세요.
<Button variant="primary">Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="tertiary">Tertiary</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="danger">Danger</Button>
<Button variant="danger-soft">Danger Soft</Button>
피드백 Variant (Feedback Variants)
feedbackVariant prop은 어떤 누르기 피드백 효과가 렌더링되는지 제어해요:
'scale-highlight'(기본값): 내장 스케일 + 하이라이트 오버레이'scale-ripple': 내장 스케일 + 리플 오버레이'scale': 내장 스케일만 (오버레이 없음)'none': 피드백 애니메이션 없음
{/* Scale + Highlight (default) */}
<Button feedbackVariant="scale-highlight">Highlight Effect</Button>
{/* Scale + Ripple */}
<Button feedbackVariant="scale-ripple">Ripple Effect</Button>
{/* Scale only */}
<Button feedbackVariant="scale">Scale Only</Button>
{/* No feedback */}
<Button feedbackVariant="none">No Feedback</Button>
커스텀 애니메이션 (Custom Animation)
animation prop은 개별 하위 애니메이션을 제어해요. 그 형태는 feedbackVariant에 따라 달라져요.
{/* Customize scale and highlight (default feedbackVariant) */}
<Button
animation={{
scale: { value: 0.97 },
highlight: {
backgroundColor: { value: '#3b82f6' },
opacity: { value: [0, 0.2] },
},
}}
>
Custom Highlight
</Button>
{/* Customize scale and ripple */}
<Button
feedbackVariant="scale-ripple"
animation={{
scale: { value: 0.97 },
ripple: {
backgroundColor: { value: '#3b82f6' },
opacity: { value: [0, 0.3, 0] },
},
}}
>
Custom Ripple
</Button>
개별 애니메이션 비활성화
특정 하위 애니메이션을 false로 설정해 비활성화할 수 있어요:
{/* Disable scale, keep highlight */}
<Button animation={{ scale: false }}>No Scale</Button>
{/* Disable highlight, keep scale */}
<Button animation={{ highlight: false }}>No Highlight</Button>
{/* Disable both */}
<Button animation={{ scale: false, highlight: false }}>No Animations</Button>
모든 애니메이션 비활성화
모든 피드백을 비활성화하려면 animation={false}를, 계단식 비활성화에는 animation="disable-all"을 사용하세요:
<Button animation={false}>Disabled</Button>
<Button animation="disable-all">Disable All (cascading)</Button>
스피너가 있는 로딩 상태 (Loading State with Spinner)
스피너 애니메이션으로 버튼을 로딩 상태로 바꿀 수 있어요.
const themeColorAccentForeground = useThemeColor('accent-foreground');
<Button
layout={LinearTransition.springify()}
variant="primary"
onPress={() => {
setIsDownloading(true);
setTimeout(() => {
setIsDownloading(false);
}, 3000);
}}
isIconOnly={isDownloading}
className="self-center"
>
{isDownloading ? (
<Spinner entering={FadeIn.delay(50)} color={themeColorAccentForeground} />
) : (
'Download now'
)}
</Button>;
LinearGradient로 커스텀 배경 (Custom Background with LinearGradient)
절대 위치 요소를 사용해 그라디언트 배경을 추가할 수 있어요. 기본 하이라이트 오버레이를 끄려면 feedbackVariant="none"을, 커스텀 리플 효과에는 feedbackVariant="scale-ripple"을 사용하세요.
import { Button, PressableFeedback } from 'heroui-native';
import { LinearGradient } from 'expo-linear-gradient';
import { StyleSheet } from 'react-native';
{/* Gradient with no feedback overlay */}
<Button feedbackVariant="none">
<LinearGradient
colors={['#9333ea', '#ec4899']}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={StyleSheet.absoluteFill}
/>
<Button.Label className="text-white font-bold">Gradient</Button.Label>
</Button>
{/* Gradient with custom ripple effect */}
<Button
feedbackVariant="scale-ripple"
animation={{
ripple: {
backgroundColor: { value: 'white' },
opacity: { value: [0, 0.5, 0] },
},
}}
>
<LinearGradient
colors={['#0d9488', '#ec4899']}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={StyleSheet.absoluteFill}
/>
<Button.Label className="text-white font-bold" pointerEvents="none">
Gradient with Ripple
</Button.Label>
</Button>
Example
import { Button, useThemeColor } from 'heroui-native';
import { Ionicons } from '@expo/vector-icons';
import { View } from 'react-native';
export default function ButtonExample() {
const [
themeColorAccentForeground,
themeColorAccentSoftForeground,
themeColorDangerForeground,
themeColorDefaultForeground,
] = useThemeColor([
'accent-foreground',
'accent-soft-foreground',
'danger-foreground',
'default-foreground',
]);
return (
<View className="gap-4 p-4">
<Button variant="primary">
<Ionicons name="add" size={20} color={themeColorAccentForeground} />
<Button.Label>Add Item</Button.Label>
</Button>
<View className="flex-row gap-4">
<Button size="sm" isIconOnly accessibilityLabel="Like">
<Ionicons name="heart" size={16} color={themeColorAccentForeground} />
</Button>
<Button
size="sm"
variant="secondary"
isIconOnly
accessibilityLabel="Bookmark"
>
<Ionicons
name="bookmark"
size={16}
color={themeColorAccentSoftForeground}
/>
</Button>
<Button
size="sm"
variant="danger"
isIconOnly
accessibilityLabel="Delete"
>
<Ionicons name="trash" size={16} color={themeColorDangerForeground} />
</Button>
</View>
<Button variant="tertiary">
<Button.Label>Learn More</Button.Label>
<Ionicons
name="chevron-forward"
size={18}
color={themeColorDefaultForeground}
/>
</Button>
</View>
);
}
더 많은 예시는 GitHub 저장소에서 찾을 수 있어요.
API Reference
Button
Button은 animation(재정의됨)을 제외한 PressableFeedback의 모든 props를 추가 버튼 전용 props와 함께 상속해요.
| prop | type | default | description |
|---|---|---|---|
variant |
'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft' |
'primary' |
버튼의 시각적 variant |
size |
'sm' | 'md' | 'lg' |
'md' |
버튼의 크기 |
isIconOnly |
boolean |
false |
버튼이 아이콘만 표시하는지(정사각형 비율) 여부 |
feedbackVariant |
'scale-highlight' | 'scale-ripple' | 'scale' | 'none' |
'scale-highlight' |
어떤 피드백 효과가 렌더링되는지 결정 |
animation |
ButtonAnimation |
- | 애니메이션 구성(feedbackVariant에 따라 형태가 달라짐) |
background |
React.ReactNode |
- | 버튼 표면 뒤의 배경 레이어. undefined는 secondary·tertiary variant의 테마 인식 기본값을 렌더링, 커스텀 노드는 교체, null은 제거 |
isDisabled, className, children 및 모든 Pressable props를 포함한 상속 props는 PressableFeedback API Reference를 참고하세요.
ButtonAnimation
animation prop은 feedbackVariant를 기반으로 한 판별 유니언(discriminated union)이에요. AnimationRoot 제어 흐름을 따릅니다:
true또는undefined: 기본 애니메이션 사용false또는"disabled": 모든 피드백 애니메이션 비활성화"disable-all": 자식 컴파운드 파트를 포함한 모든 애니메이션 계단식 비활성화object: 하위 애니메이션 키가 있는 커스텀 구성(아래 참고)
feedbackVariant="scale-highlight"(기본값)일 때:
| prop | type | default | description |
|---|---|---|---|
scale |
PressableFeedbackScaleAnimation |
- | 스케일 애니메이션 구성(false로 비활성화) |
highlight |
PressableFeedbackHighlightAnimation |
- | 하이라이트 오버레이 구성(false로 비활성화) |
state |
'disabled' | 'disable-all' | boolean |
- | 구성은 유지한 채 애니메이션 상태 제어(런타임 토글) |
feedbackVariant="scale-ripple"일 때:
| prop | type | default | description |
|---|---|---|---|
scale |
PressableFeedbackScaleAnimation |
- | 스케일 애니메이션 구성(false로 비활성화) |
ripple |
PressableFeedbackRippleAnimation |
- | 리플 오버레이 구성(false로 비활성화) |
state |
'disabled' | 'disable-all' | boolean |
- | 구성은 유지한 채 애니메이션 상태 제어(런타임 토글) |
feedbackVariant="scale"일 때:
| prop | type | default | description |
|---|---|---|---|
scale |
PressableFeedbackScaleAnimation |
- | 스케일 애니메이션 구성(false로 비활성화) |
state |
'disabled' | 'disable-all' | boolean |
- | 구성은 유지한 채 애니메이션 상태 제어(런타임 토글) |
feedbackVariant="none"일 때:
문자열 값으로는 'disable-all'만 허용돼요. 모든 피드백 효과가 비활성화됩니다.
자세한 애니메이션 하위 타입(PressableFeedbackScaleAnimation, PressableFeedbackHighlightAnimation, PressableFeedbackRippleAnimation)은 PressableFeedback API Reference를 참고하세요.
Button.Background
버튼 표면 뒤에 렌더링되는 absolute-fill 컨테이너예요. children이 없으면 활성 라이브러리 테마가 기본 콘텐츠(예: glass 블러 레이어)를 결정하고, children을 전달하면 동일한 위치 지정과 클리핑으로 커스텀 콘텐츠를 호스팅할 수 있어요.
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 배경 컨테이너 내부의 커스텀 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...ViewProps |
ViewProps |
- | 모든 표준 View props 지원 |
Button.Label
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 라벨로 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 Text props 지원 |
Hooks
useButton
Button 컨텍스트 값에 접근하는 훅이에요. 버튼의 size, variant, disabled 상태를 반환합니다.
import { useButton } from 'heroui-native';
const { size, variant, isDisabled } = useButton();
반환 값 (Return Value)
| property | type | description |
|---|---|---|
size |
'sm' | 'md' | 'lg' |
버튼의 크기 |
variant |
'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft' |
버튼의 시각적 variant |
isDisabled |
boolean |
버튼이 비활성화되었는지 여부 |
Note: 이 훅은 Button 컴포넌트 내부에서 사용해야 해요. 버튼 컨텍스트 밖에서 호출하면 에러가 발생합니다.