import React from 'react'; import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import GraphicPaper from './svg/graphicPaper.svg'; import { Typo } from '../../foundation'; import { SvgProps } from 'react-native-svg'; import { Button } from '../button/Button'; import { useThrottledPressHandler } from '../../internal/utils/useThrottledPressHandler'; import { Spacer } from '../../internal/utilComponents/Spacer'; type BaseProps = { title: string; description?: string; graphic?: React.FC; containerStyle?: StyleProp; }; type TextOnlyProps = { variants?: 'text_only'; } & BaseProps; type WithOneButtonProps = { variants: 'with_one_button'; onPress: () => void; label: string; } & BaseProps; type WithTwoButtonProps = { variants: 'with_two_button'; onPressTop: () => void; topLabel: string; onPressBottom: () => void; bottomLabel: string; } & BaseProps; type Props = TextOnlyProps | WithOneButtonProps | WithTwoButtonProps; /** * EmptyState * - 표시할 수 있는 데이터가 없거나 결과의 내용을 포함할 수 없을때 사용하는 컴포넌트 * * ### Props * - `variants` 값에 따라 prop 사용 여부가 다를 수 있습니다. * * ### `variants` * - 'text_only' | 'with_one_button' | 'with_two_button' * - default: 'text_only' * * ### `title` * - 제목 * * ### `description` * - 내용 * * ### `graphic` * - 상단에 노출할 그래픽 * - 64 x 64 * - default: GraphicPaper * * ### `containerStyle` optional * - 상황에 따라 스타일 조정 * * ### `onPress` * - variants === 'with_one_button' 일때 제공 * - 버튼 선택시 이벤트 * * ### `label` * - variants === 'with_one_button' 일때 제공 * - 버튼 라벨 * * ### `onPressTop` * - variants === 'with_two_button' 일때 제공 * - 상단 버튼 선택시 이벤트 * * ### `topLabel` * - variants === 'with_two_button' 일때 제공 * - 상단 버튼 라벨 * * ### `onPressBottom` * - variants === 'with_two_button' 일때 제공 * - 하단 버튼 선택시 이벤트 * * ### `bottomLabel` * - variants === 'with_two_button' 일때 제공 * - 하단 버튼 라벨 * * * @example * ```tsx * // variants === 'text_only' * * * // variants === 'with_one_button' * * * // variants === 'with_two_button' * * ``` */ export function EmptyState(props: Props): React.JSX.Element { const { title, description, graphic: Graphic, containerStyle } = props; return ( {props.variants === 'with_one_button' && } {props.variants === 'with_two_button' && ( )} ); } function DefaultContent({ title, description, graphic: Graphic }: BaseProps) { const ActualGraphic = Graphic ?? GraphicPaper; return ( {title} {description && ( {description} )} ); } function WithOneButton({ label, onPress }: Pick) { const handlePress = useThrottledPressHandler(onPress); return