import React, { ReactElement } from 'react'; import { StyleSheet, View } from 'react-native'; import { IconProps, SemanticColor, Typo } from '../../foundation'; import { isAndroid, isNotNil } from '../../internal/utils/functions'; type Props = { count: number; children?: ReactElement }; /** * # NotificationCount 컴포넌트 * * * ## Props * * ### `count` * - 표시할 숫자값으로 0 이상의 정수 * - 0 이면 렌더링하지 않음 * * * ### `children` * - 피그마 시안에 따라 type에 맞게 사용합니다 (개발시 따로 type을 지정하지 않습니다) * - 'notification_count_only': 단일 컴포넌트로 사용 * - 'notification_count_with_icon': children으로 size 24의 Icon 컴포넌트를 사용 * * @example * ```tsx * * // 숫자만 표시 * * * // 아이콘과 함께 표시 * * * * * ``` */ export function NotificationCount(props: Props): React.JSX.Element | null { if (isNotNil(props.children)) { return ; } return ; } function Count({ count }: { count: number }) { if (count === 0) return null; const isOver = count > 99; return ( // View로 감싸서 `alignSelf: 'flex-start'` 로 인해 윗쪽으로 치우쳐지는 현상 보정 {isOver ? '99+' : count} ); } function CountWithIcon({ count, children }: Props) { const isOver = count > 99; const isUnder10 = count < 10; return ( {children} {count === 0 ? null : ( {isOver ? '99+' : count} )} ); } const styles = StyleSheet.create({ count: { backgroundColor: SemanticColor.bg_red_enabled, borderRadius: 12, paddingHorizontal: 4, alignSelf: 'flex-start', alignItems: 'center', justifyContent: 'center', minWidth: 20, height: 20, }, iconCountOutline: { backgroundColor: SemanticColor.border_white, position: 'absolute', left: 13, bottom: 9, borderRadius: 12, padding: 1, }, iconCount: { backgroundColor: SemanticColor.bg_red_enabled, minWidth: 18, height: 18, borderRadius: 12, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 4, }, });