RadioGroup (라디오 그룹)
RadioGroup은 한 번에 하나의 옵션만 선택할 수 있는 라디오 버튼 세트예요. 가로와 세로 방향을 모두 지원하며, 선택 상태를 자동으로 관리해요. RadioGroup.Item의 렌더 함수를 사용해 선택 상태에 따라 콘텐츠를 완전히 커스터마이징할 수도 있어요.
출처: 문서
본문
Import
import { RadioGroup } from 'heroui-native';
Anatomy
<RadioGroup>
<RadioGroup.Item>
<Label>...</Label>
<Description>...</Description>
<Radio>
<Radio.Indicator>
<Radio.IndicatorThumb />
</Radio.Indicator>
</Radio>
</RadioGroup.Item>
<FieldError>...</FieldError>
</RadioGroup>
- RadioGroup: 라디오 항목의 선택 상태를 관리하는 컨테이너예요. 가로와 세로 방향을 모두 지원해요.
- RadioGroup.Item: RadioGroup 안의 개별 라디오 옵션이에요. 반드시 RadioGroup 안에서 사용해야 해요. 선택 상태를 처리하며, 텍스트 children이 제공되면 기본
<Radio />표시기를 렌더링해요. 상태(isSelected,isInvalid,isDisabled)에 접근할 수 있는 렌더 함수 children을 지원해요. - Label: 라디오 옵션을 위한 선택 가능한 텍스트 라벨(선택 사항)이에요. 접근성을 위해 라디오와 연결돼요. Label 컴포넌트를 직접 사용해요.
- Description: 라벨 아래의 보조 텍스트(선택 사항)예요. 라디오 옵션에 대한 추가 컨텍스트를 제공해요. Description 컴포넌트를 직접 사용해요.
- Radio:
RadioGroup.Item안에서 라디오 표시기를 렌더링하는 데 사용되는 Radio 컴포넌트예요.RadioGroupItem컨텍스트를 자동으로 감지해서isSelected,isDisabled,isInvalid,variant를 파생해요. - Radio.Indicator: 라디오 원을 위한 선택적 컨테이너예요. children이 없으면 기본 thumb을 렌더링해요. 시각적 선택 상태를 관리해요. 전체 API는 Radio를 참조해요.
- Radio.IndicatorBackground: 표시기 콘텐츠 뒤에 렌더링되는 테마 인식 배경 컨테이너(선택 사항)예요. 활성 테마가 기본 배경 콘텐츠(예:
glass)를 등록한 경우, 선택되지 않고 유효하지 않은 상태에서secondaryvariant에 자동으로 마운트돼요.Radio.Indicator의backgroundprop으로 교체하거나 제거할 수 있어요. - Radio.IndicatorThumb: 선택되었을 때 나타나는 선택적 내부 원이에요. 선택 상태에 따라 scale이 애니메이션돼요. 커스텀 콘텐츠로 교체할 수 있어요. 전체 API는 Radio를 참조해요.
- FieldError: 라디오 그룹이 유효하지 않을 때 표시되는 오류 메시지예요. 라디오 그룹 콘텐츠 아래에 애니메이션과 함께 표시돼요. FieldError 컴포넌트를 직접 사용해요.
Usage
Basic Usage
간단한 문자열 children을 가진 RadioGroup은 타이틀과 표시기를 자동으로 렌더링해요.
<RadioGroup value={value} onValueChange={setValue}>
<RadioGroup.Item value="option1">Option 1</RadioGroup.Item>
<RadioGroup.Item value="option2">Option 2</RadioGroup.Item>
<RadioGroup.Item value="option3">Option 3</RadioGroup.Item>
</RadioGroup>
With Descriptions
각 라디오 옵션 아래에 추가 컨텍스트를 위한 설명 텍스트를 추가해요.
import { RadioGroup, Radio, Label, Description } from 'heroui-native';
import { View } from 'react-native';
<RadioGroup value={value} onValueChange={setValue}>
<RadioGroup.Item value="standard">
<View>
<Label>Standard Shipping</Label>
<Description>Delivered in 5-7 business days</Description>
</View>
<Radio />
</RadioGroup.Item>
<RadioGroup.Item value="express">
<View>
<Label>Express Shipping</Label>
<Description>Delivered in 2-3 business days</Description>
</View>
<Radio />
</RadioGroup.Item>
</RadioGroup>;
Custom Indicator
Radio 하위 컴포넌트를 사용해 기본 표시기 thumb을 커스텀 콘텐츠로 교체해요.
import { RadioGroup, Radio, Label } from 'heroui-native';
<RadioGroup value={value} onValueChange={setValue}>
<RadioGroup.Item value="custom">
{({ isSelected }) => (
<>
<Label>Custom Option</Label>
<Radio>
<Radio.Indicator>
{isSelected && (
<Animated.View entering={FadeIn}>
<Icon name="check" size={12} />
</Animated.View>
)}
</Radio.Indicator>
</Radio>
</>
)}
</RadioGroup.Item>
</RadioGroup>;
With Render Function
RadioGroup.Item에 렌더 함수를 사용해서 상태에 접근하고 전체 콘텐츠를 커스터마이징해요.
import { RadioGroup, Radio, Label } from 'heroui-native';
<RadioGroup value={value} onValueChange={setValue}>
<RadioGroup.Item value="option1">
{({ isSelected, isInvalid, isDisabled }) => (
<>
<Label>Option 1</Label>
<Radio>
<Radio.Indicator>{isSelected && <CustomIcon />}</Radio.Indicator>
</Radio>
</>
)}
</RadioGroup.Item>
</RadioGroup>;
With Error Message
라디오 그룹 아래에 유효성 검사 오류를 표시해요.
import { RadioGroup, FieldError } from 'heroui-native';
function RadioGroupWithError() {
const [value, setValue] = React.useState<string | undefined>(undefined);
return (
<RadioGroup value={value} onValueChange={setValue} isInvalid={!value}>
<RadioGroup.Item value="agree">I agree to the terms</RadioGroup.Item>
<RadioGroup.Item value="disagree">I do not agree</RadioGroup.Item>
<FieldError isInvalid={!value}>
Please select an option to continue
</FieldError>
</RadioGroup>
);
}
Example
import {
Description,
Label,
Radio,
RadioGroup,
Separator,
Surface,
} from 'heroui-native';
import React from 'react';
import { View } from 'react-native';
export default function RadioGroupExample() {
const [selection, setSelection] = React.useState('desc1');
return (
<Surface className="w-full">
<RadioGroup value={selection} onValueChange={setSelection}>
<RadioGroup.Item value="desc1">
<View>
<Label>Standard Shipping</Label>
<Description>Delivered in 5-7 business days</Description>
</View>
<Radio />
</RadioGroup.Item>
<Separator className="my-1" />
<RadioGroup.Item value="desc2">
<View>
<Label>Express Shipping</Label>
<Description>Delivered in 2-3 business days</Description>
</View>
<Radio />
</RadioGroup.Item>
<Separator className="my-1" />
<RadioGroup.Item value="desc3">
<View>
<Label>Overnight Shipping</Label>
<Description>Delivered next business day</Description>
</View>
<Radio />
</RadioGroup.Item>
</RadioGroup>
</Surface>
);
}
GitHub 저장소에서 더 많은 예제를 볼 수 있어요.
API Reference
RadioGroup
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
undefined |
라디오 그룹 콘텐츠 |
value |
string | undefined |
undefined |
라디오 그룹의 현재 선택된 값 |
onValueChange |
(val: string) => void |
undefined |
선택된 값이 변경될 때 호출되는 콜백 |
isDisabled |
boolean |
false |
전체 라디오 그룹이 비활성화되었는지 여부 |
isInvalid |
boolean |
false |
라디오 그룹이 유효하지 않은지 여부 |
variant |
'primary' | 'secondary' |
undefined |
라디오 그룹의 variant 스타일 (항목에 설정되지 않으면 항목이 상속함) |
animation |
"disable-all" | undefined |
undefined |
애니메이션 구성. "disable-all"로 모든 애니메이션을 비활성화 (children 포함) |
className |
string |
undefined |
커스텀 클래스 이름 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View prop을 지원해요 |
RadioGroup.Item
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode | ((props: RadioGroupItemRenderProps) => React.ReactNode) |
undefined |
라디오 항목 콘텐츠 또는 라디오 항목을 커스터마이징할 렌더 함수 |
value |
string |
undefined |
이 라디오 항목과 연결된 값 |
isDisabled |
boolean |
false |
이 특정 라디오 항목이 비활성화되었는지 여부 |
isInvalid |
boolean |
false |
라디오 항목이 유효하지 않은지 여부 |
variant |
'primary' | 'secondary' |
'primary' |
라디오 항목의 variant 스타일 |
hitSlop |
number |
6 |
pressable 영역의 히트 슬롭 |
className |
string |
undefined |
커스텀 클래스 이름 |
...PressableProps |
PressableProps |
- | 모든 표준 React Native Pressable prop을 지원해요 (disabled 제외) |
RadioGroupItemRenderProps
| prop | type | description |
|---|---|---|
isSelected |
boolean |
라디오 항목이 선택되었는지 여부 |
isInvalid |
boolean |
라디오 항목이 유효하지 않은지 여부 |
isDisabled |
boolean |
라디오 항목이 비활성화되었는지 여부 |
Radio (inside RadioGroup.Item)
Radio 컴포넌트는 RadioGroup.Item 안에서 라디오 표시기를 렌더링하는 데 사용돼요. RadioGroup.Item 안에 배치되면 Radio 컴포넌트는 자동으로 RadioGroupItem 컨텍스트를 감지해서 isSelected, isDisabled, isInvalid, variant를 파생해요 — 수동으로 prop을 전달할 필요가 없어요.
기본 표시기에는 <Radio />를 사용하고, 커스텀 스타일링을 위해서는 Radio.Indicator와 Radio.IndicatorThumb로 구성하세요.
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode | ((props: RadioRenderProps) => React.ReactNode) |
undefined |
라디오를 커스터마이징할 children 요소 또는 렌더 함수 |
variant |
'primary' | 'secondary' |
'primary' |
라디오의 variant 스타일 |
isSelected |
boolean |
undefined |
라디오가 현재 선택되었는지 여호 |
isDisabled |
boolean |
undefined |
라디오가 비활성화되어 상호작용할 수 없는지 여부 |
isInvalid |
boolean |
false |
라디오가 유효하지 않은지 여부 (danger 색상 표시) |
className |
string |
undefined |
적용할 추가 CSS 클래스 |
animation |
RadioRootAnimation |
- | 라디오를 위한 애니메이션 구성 |
onSelectedChange |
(isSelected: boolean) => void |
undefined |
라디오 선택 상태가 변경될 때 호출되는 콜백 |
...PressableProps |
PressableProps |
- | 모든 표준 React Native Pressable prop을 지원해요 (disabled 제외) |
RadioRenderProps
| prop | type | description |
|---|---|---|
isSelected |
boolean |
라디오가 선택되었는지 여부 |
isDisabled |
boolean |
라디오가 비활성화되었는지 여부 |
isInvalid |
boolean |
라디오가 유효하지 않은지 여부 |
RadioRootAnimation
라디오 루트 컴포넌트를 위한 애니메이션 구성이에요. 값은 다음과 같아요:
"disable-all": children(Indicator, IndicatorThumb)을 포함한 모든 애니메이션 비활성화undefined: 기본 애니메이션 사용
Radio.Indicator
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
undefined |
라디오 표시기의 콘텐츠 |
className |
string |
undefined |
표시기를 위한 추가 CSS 클래스 |
background |
React.ReactNode |
- | 표시기 콘텐츠 뒤의 배경 레이어. undefined는 선택되지 않고 유효하지 않은 상태에서 secondary variant의 테마 인식 기본값을 렌더링하고, 커스텀 노드는 이를 교체하며, null은 제거해요 |
...AnimatedViewProps |
AnimatedProps<ViewProps> |
- | 모든 Reanimated Animated.View prop을 지원해요 |
Radio.IndicatorBackground
표시기 콘텐츠 뒤에 렌더링되는 absolute-fill 컨테이너예요. children이 없으면 활성 라이브러리 테마가 기본 콘텐츠(예: glass 블러 레이어)를 결정해요. 동일한 위치 지정과 클리핑으로 커스텀 콘텐츠를 호스팅하려면 children을 전달하세요.
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 배경 컨테이너 안의 커스텀 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...ViewProps |
ViewProps |
- | 모든 표준 View prop을 지원해요 |
Radio.IndicatorThumb
| prop | type | default | description |
|---|---|---|---|
className |
string |
undefined |
thumb을 위한 추가 CSS 클래스 |
animation |
RadioIndicatorThumbAnimation |
- | thumb을 위한 애니메이션 구성 |
isAnimatedStyleActive |
boolean |
true |
애니메이션 스타일(react-native-reanimated)이 활성인지 여부 |
...AnimatedViewProps |
AnimatedProps<ViewProps> |
- | 모든 Reanimated Animated.View prop을 지원해요 |
RadioIndicatorThumbAnimation
라디오 표시기 thumb 컴포넌트를 위한 애니메이션 구성이에요. 값은 다음과 같아요:
false또는"disabled": 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용object: 커스텀 애니메이션 구성
| prop | type | default | description |
|---|---|---|---|
state |
'disabled' | boolean |
- | 속성을 커스터마이징하는 동안 애니메이션 비활성화 |
scale.value |
[number, number] |
[1.5, 1] |
Scale 값 [선택 안 됨, 선택됨] |
scale.timingConfig |
WithTimingConfig |
{ duration: 300, easing: Easing.out(Easing.ease) } |
애니메이션 타이밍 구성 |
Note: 라벨, 설명, 오류 메시지에는 기본 컴포넌트를 직접 사용하세요:
- 라벨에는 Label 컴포넌트 사용
- 설명에는 Description 컴포넌트 사용
- 오류 메시지에는 FieldError 컴포넌트 사용
Hooks
useRadioGroup
Returns:
| Property | Type | Description |
|---|---|---|
value |
string | undefined |
현재 선택된 값 |
isDisabled |
boolean |
라디오 그룹이 비활성화되었는지 여부 |
isInvalid |
boolean |
라디오 그룹이 유효하지 않은 상태인지 여부 |
variant |
'primary' | 'secondary' |
라디오 그룹의 variant 스타일 |
onValueChange |
(value: string) => void |
선택된 값을 변경하는 함수 |
useRadioGroupItem
Returns:
| Property | Type | Description |
|---|---|---|
isSelected |
boolean |
라디오 항목이 선택되었는지 여부 |
isDisabled |
boolean | undefined |
라디오 항목이 비활성화되었는지 여부 |
isInvalid |
boolean | undefined |
라디오 항목이 유효하지 않은지 여부 |
variant |
'primary' | 'secondary' | undefined |
라디오 항목의 variant 스타일 |
onSelectedChange |
((isSelected: boolean) => void) | undefined |
선택 상태를 변경하는 콜백 (그룹에서 이 항목을 선택함) |