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

Alert (알림)

원문 보기 위키 갱신

Alert는 상태 표시기(indicator)와 함께 중요한 메시지와 알림을 사용자에게 표시하는 컴포넌트예요. status prop으로 상황에 맞는 아이콘과 색상을 자동 적용해요. 기본 아이콘을 커스텀 콘텐츠로 교체하고, 액션 버튼도 함께 넣을 수 있어요.

출처: 문서

본문

Import

import { Alert } from 'heroui-native';

Anatomy

<Alert>
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>...</Alert.Title>
    <Alert.Description>...</Alert.Description>
  </Alert.Content>
</Alert>
  • Alert: role="alert"과 상태 기반 스타일을 가진 메인 컨테이너예요. primitive 컨텍스트를 통해 하위 컴포넌트에 상태 컨텍스트를 제공해요.
  • Alert.Indicator: 기본적으로 상태에 맞는 아이콘을 렌더링해요. 커스텀 children을 넣으면 기본 아이콘을 재정의할 수 있어요. 크기와 색상을 커스터마이징할 수 있는 iconProps를 지원해요.
  • Alert.Content: 타이틀과 설명을 감싸는 래퍼예요. 텍스트 콘텐츠의 레이아웃 구조를 제공해요.
  • Alert.Title: 상태 기반 색상의 제목 텍스트예요. aria-labelledby를 통해 루트와 연결돼요.
  • Alert.Description: muted 색상으로 렌더링되는 본문 텍스트예요. aria-describedby를 통해 루트와 연결돼요.

Usage

Basic Usage

Alert 컴포넌트는 복합 파트를 사용해 아이콘, 타이틀, 설명이 있는 알림을 표시해요.

<Alert>
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>New features available</Alert.Title>
    <Alert.Description>
      Check out our latest updates including dark mode support and improved
      accessibility features.
    </Alert.Description>
  </Alert.Content>
</Alert>

Status Variants

status prop으로 아이콘과 타이틀 색상을 조절해요. 사용 가능한 상태는 default, accent, success, warning, danger예요.

<Alert status="success">
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>Success</Alert.Title>
    <Alert.Description>...</Alert.Description>
  </Alert.Content>
</Alert>

<Alert status="warning">
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>Scheduled maintenance</Alert.Title>
    <Alert.Description>...</Alert.Description>
  </Alert.Content>
</Alert>

<Alert status="danger">
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>Unable to connect</Alert.Title>
    <Alert.Description>...</Alert.Description>
  </Alert.Content>
</Alert>

Title Only

Alert.Description을 생략하면 간결한 한 줄 알림을 만들 수 있어요.

<Alert status="success" className="items-center">
  <Alert.Indicator className="pt-0" />
  <Alert.Content>
    <Alert.Title>Profile updated successfully</Alert.Title>
  </Alert.Content>
</Alert>

With Action Buttons

콘텐츠 옆에 버튼 같은 추가 요소를 배치할 수 있어요.

<Alert status="accent">
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title>Update available</Alert.Title>
    <Alert.Description>
      A new version of the application is available.
    </Alert.Description>
  </Alert.Content>
  <Button size="sm" variant="primary">
    Refresh
  </Button>
</Alert>

Custom Indicator

Alert.Indicator에 커스텀 children을 전달해서 기본 상태 아이콘을 교체할 수 있어요.

<Alert status="accent">
  <Alert.Indicator>
    <Spinner>
      <Spinner.Indicator iconProps={{ width: 20, height: 20 }} />
    </Spinner>
  </Alert.Indicator>
  <Alert.Content>
    <Alert.Title>Processing your request</Alert.Title>
    <Alert.Description>Please wait while we sync your data.</Alert.Description>
  </Alert.Content>
</Alert>

Custom Styling

루트와 복합 파트에 className prop으로 커스텀 스타일을 적용할 수 있어요.

<Alert className="bg-accent/10 rounded-xl">
  <Alert.Indicator className="pt-1" />
  <Alert.Content className="gap-1">
    <Alert.Title className="text-lg">...</Alert.Title>
    <Alert.Description className="text-base">...</Alert.Description>
  </Alert.Content>
</Alert>

Example

import { Alert, Button, CloseButton } from 'heroui-native';
import { View } from 'react-native';

export default function AlertExample() {
  return (
    <View className="w-full gap-4">
      <Alert status="accent">
        <Alert.Indicator />
        <Alert.Content>
          <Alert.Title>Update available</Alert.Title>
          <Alert.Description>
            A new version of the application is available. Please refresh to get
            the latest features and bug fixes.
          </Alert.Description>
        </Alert.Content>
        <Button size="sm" variant="primary">
          Refresh
        </Button>
      </Alert>

      <Alert status="danger">
        <Alert.Indicator />
        <Alert.Content>
          <Alert.Title>Unable to connect to server</Alert.Title>
          <Alert.Description>
            Unable to connect to the server. Check your internet connection and
            try again.
          </Alert.Description>
        </Alert.Content>
        <Button size="sm" variant="danger">
          Retry
        </Button>
      </Alert>

      <Alert status="success" className="items-center">
        <Alert.Indicator className="pt-0" />
        <Alert.Content>
          <Alert.Title>Profile updated successfully</Alert.Title>
        </Alert.Content>
        <CloseButton />
      </Alert>
    </View>
  );
}

GitHub 저장소에서 더 많은 예제를 볼 수 있어요.

API Reference

Alert

prop type default description
children React.ReactNode - 알림 안에 렌더링할 children 요소들
status 'default' | 'accent' | 'success' | 'warning' | 'danger' 'default' 아이콘과 색상 처리를 제어하는 상태
id string | number - 알림의 고유 식별자. 제공하지 않으면 자동 생성돼요
className string - 추가 CSS 클래스
style ViewStyle - 루트 컨테이너에 적용되는 추가 스타일
...ViewProps ViewProps - 모든 표준 React Native View prop을 지원해요

Alert.Indicator

prop type default description
children React.ReactNode - 기본 상태 아이콘 대신 렌더링할 커스텀 children
className string - 추가 CSS 클래스
iconProps AlertIconProps - 기본 상태 아이콘에 전달되는 prop (크기와 색상 오버라이드)
...ViewProps ViewProps - 모든 표준 React Native View prop을 지원해요

AlertIconProps

prop type default description
size number 18 픽셀 단위의 아이콘 크기
color string status color 문자열 형태의 아이콘 색상

Alert.Content

prop type default description
children React.ReactNode - children 요소들 (주로 Alert.Title과 Alert.Description)
className string - 추가 CSS 클래스
...ViewProps ViewProps - 모든 표준 React Native View prop을 지원해요

Alert.Title

prop type default description
children React.ReactNode - 타이틀 텍스트 콘텐츠
className string - 추가 CSS 클래스
...TextProps TextProps - 모든 표준 React Native Text prop을 지원해요

Alert.Description

prop type default description
children React.ReactNode - 설명 텍스트 콘텐츠
className string - 추가 CSS 클래스
...TextProps TextProps - 모든 표준 React Native Text prop을 지원해요

Hooks

useAlert

알림 루트 컨텍스트에 접근하는 훅이에요. 반드시 Alert 컴포넌트 안에서 사용해야 해요.

import { useAlert } from 'heroui-native';

const { status, nativeID } = useAlert();

Returns

property type description
status 'default' | 'accent' | 'success' | 'warning' | 'danger' 하위 컴포넌트 스타일링을 위한 현재 알림 상태
nativeID string 접근성과 ARIA 속성에 사용되는 고유 식별자

더 알아보기 (Learn more)