import React from 'react'; import { Pressable, StyleSheet, View } from 'react-native'; import { Icon, IconProps, SemanticColor, TextColor, Typo } from '../../foundation'; import { useThrottledPressHandler } from '../../internal/utils/useThrottledPressHandler'; import { isNotEmpty, isNotNil } from '../../internal/utils/functions'; type BaseProps = { onPress: () => void; title: string; description?: string; type?: 'actionable' | 'dismissible'; }; type InformationType = BaseProps & { variants?: 'bg_black' | 'bg_white' | 'bg_grey'; iconName?: IconProps['name']; iconColor?: IconProps['color']; }; type WarningType = BaseProps & { variants: 'bg_red' }; type Props = InformationType | WarningType; /** * InlineAlert * - 상단 또는 하단에 고정되어 노출되는 알림 컴포넌트 * - type에 따라 정보 알림과 경고 알림으로 나뉩니다 * - 스크롤에 포함되지 않도록 주의해주세요 * - 노출 여부는 호출부에서 관리합니다 * * ### Props * - `variants` 값에 따라 prop 사용 여부가 다를 수 있습니다. * * ### `variants` * - 배경 색상 * - 'bg_black' | 'bg_white' | 'bg_grey' | 'bg_red' * - default: 'bg_grey' * * ### `title` * - 알림 제목 * * ### `description` * - 알림 내용 * * ### `iconName` * - 알림 아이콘 * - default: 'information_circle_filled' * - variant === 'bg_red' 일 때 미제공 prop. 정해진 아이콘 사용 * * ### `iconColor` * - 아이콘 색상 * - default: 'text_secondary' * - variant === 'bg_red' 일 때 미제공 prop. 정해진 색상 사용 * * ### `type` * - 'actionable' 오른쪽 화살표 아이콘을 노출 * - 'dismissible' 오른쪽 x 아이콘을 노출 * - default: 'actionable' * * ### `onPress` * - 우측에 화살표 또는 x 아이콘 클릭 시 이벤트 * * @example * ```tsx * * * // 상단 고정 * * {...} * // 하단 고정 * * * ``` */ export function InlineAlert(props: Props): React.JSX.Element { const { title, description, variants, type = 'actionable', onPress } = props; const handlePress = useThrottledPressHandler(onPress); const isActionable = type === 'actionable'; const { backgroundColor, iconName, iconColor, textColor } = (() => { if (variants === 'bg_red') { return { backgroundColor: SemanticColor.bg_red_enabled, iconName: 'caution_triangle_filled' as IconProps['name'], iconColor: 'text_white' as IconProps['color'], textColor: 'text_white' as TextColor, }; } else { return { backgroundColor: { bg_black: SemanticColor.bg_enabled, bg_white: SemanticColor.bg_primary, bg_grey: SemanticColor.bg_secondary, }[variants ?? 'bg_grey'], iconName: props.iconName ?? 'information_circle_filled', iconColor: props.iconColor ?? 'text_secondary', textColor: variants === 'bg_black' ? 'text_white' : ('text_secondary' as TextColor), }; } })(); const Content = ( {title} {isNotNil(description) && isNotEmpty(description) && ( {description} )} ); return isActionable ? {Content} : Content; } const styles = StyleSheet.create({ box: { flexDirection: 'row', padding: 12, justifyContent: 'space-between', alignItems: 'flex-start' }, left: { flexDirection: 'row', gap: 8, alignItems: 'flex-start', flex: 1 }, textBox: { flexShrink: 1 }, icon: { paddingTop: 2 }, right: { paddingLeft: 8 }, });