import React, { ComponentProps } from 'react'; import { View } from 'react-native'; import { BackgroundColor, Icon, IconName, SemanticColor, Typo } from '../../foundation'; import { LayoutStyleProp } from '../../internal/utils/utilTypes'; import { ScreenHeaderBase } from './ScreenHeaderBase'; import { TextButton } from './TextButton'; import { PressableThrottled } from '../utils/PressableThrottled'; import { SafeAreaTopSpacer } from '../utils/SafeAreaTopSpacer'; type PropsPerOption = | { /** 구성: 타이틀, 닫기/뒤로가기 */ option: 'only_title'; } | { /** 구성: 좌측 닫기/뒤로가기, 타이틀, 우측 아이콘(0~2개) */ option: 'with_icon'; /** 우측 뷰의 안쪽 아이콘 이름 */ rightInnerIconName?: IconName; rightInnerPressHandler?: () => void; /** 우측 뷰의 바깥쪽 아이콘 이름 */ rightOuterIconName?: IconName; rightOuterPressHandler?: () => void; } | { /** 구성: 좌측 닫기/뒤로가기, 타이틀, 우측 텍스트버튼 */ option: 'with_text_button'; /** 텍스트버튼 라벨 */ buttonLabel: string; /** 텍스트버튼의 스타일 (기본값: secondary) */ buttonVariants?: 'primary' | 'secondary' | 'white'; /** 텍스트버튼 상태 (기본값: false) */ buttonDisabled?: boolean; buttonPressHandler: () => void; }; type Props = PropsPerOption & { title?: string; /** 'modal' | 'card' 타입에 따라 닫기(뒤로가기) 아이콘 위치와 모양이 달라짐 (기본값 'card') */ type?: ComponentProps['type']; /** 타이틀 영역을 대체하는 임의의 뷰를 렌더할 때 사용 */ TitleSlotComponent?: React.ReactNode; /** 아이콘, 텍스트 컬러 (기본값 text_primary) */ color?: ComponentProps['color']; /** 배경 색 (기본값 bg_primary) */ backgroundColor?: BackgroundColor | 'transparent'; /** 상단 safe area 영역 제외하려면 true (기본값 false) */ excludeSafeArea?: boolean; /** 하단 구분선 노출 여부 (기본값 true) */ showDivider?: boolean; /** 닫기/뒤로가기 버튼 핸들러 */ onPressClose: () => void; /** @deprecated 꼭 필요한 경우 프리즈마 개발자에게 사용해도 되는지 문의해주세요. */ hideCloseButton?: boolean; } & LayoutStyleProp; /** * # ScreenHeader * * * ## Props * * ### `option` * - `'only_title'` 구성: 타이틀, 닫기/뒤로가기 * - `'with_icon'` 구성: 좌측 닫기/뒤로가기, 타이틀, 우측 아이콘(0~2개) * - `'with_text_button'` 구성: 좌측 닫기/뒤로가기, 타이틀, 우측 텍스트버튼 * * * ### `option` 값에 따른 Props * * #### `'only_title'`일 때 * - 없음 * * * #### `'with_icon'`일 떄 * - `rightInnerIconName` 우측 뷰의 안쪽 아이콘 이름 * - `rightInnerPressHandler` 우측 뷰의 안쪽 아이콘 핸들러 * - `rightOuterIconName` 우측 뷰의 바깥쪽 아이콘 이름 * - `rightOuterPressHandler` 우측 뷰의 바깥쪽 아이콘 핸들러 * * * #### `'with_text_button'`일 때 * - `buttonLabel` 우측 텍스트버튼 라벨 * - `buttonVariants` 우측 텍스트버튼 타입 * - `'primary' | 'secondary' | 'white'` (기본값 `'secondary'`) * - `buttonDisabled` 우측 텍스트버튼 비활성화 여부 (기본값 `false`) * - `buttonPressHandler` 우측 텍스트버튼 핸들러 * * * ### `title` * - 타이틀 텍스트 * * * ### `type` * - `'modal' | 'card'` (기본값 `'card'`) * - 타입에 따라 닫기(뒤로가기) 아이콘 모양이 달라지며, option 값이 'only_title' 일 경우 위치도 달라짐 * * * ### `TitleSlotComponent` * - 타이틀 영역을 대체하는 임의의 뷰를 렌더할 때 사용 * * * ### `color` * - 아이콘, 텍스트 컬러 (기본값 `text_primary`) * * * ### `backgroundColor` * - 배경 색 (기본값 `bg_primary`) * - `'transparent'` 가능 * * * ### `excludeSafeArea` * - 상단 safe area 영역 제외하려면 true (기본값 `false`) * * * ### `showDivider` * - 하단 구분선 노출 여부 (기본값 `true`) * * * ### `onPressClose` * - 닫기/뒤로가기 버튼 핸들러 * * * @example * ```tsx * // only_title 1 * * * // only_title 2 * * * * // with_icon * * * * // with_text_button * * * ``` */ export function ScreenHeader(props: Props): React.JSX.Element { const { type = 'card', showDivider = true, color = 'text_primary', backgroundColor = 'bg_primary', excludeSafeArea = false, } = props; const Content: React.JSX.Element = (() => { if (props.option === 'only_title') { return ( } // 모달 타입이면 오른쪽에 닫기 아이콘 항상 존재 RightSlotComponent={type === 'card' ? <> : undefined} /> ); } else if (props.option === 'with_icon') { return ( {props.rightInnerIconName && ( )} {props.rightOuterIconName && ( )} } /> ); } else if (props.option === 'with_text_button') { const { buttonVariants = 'secondary', buttonDisabled = false } = props; return ( } /> ); } return <>; })(); return ( {excludeSafeArea ? null : } {Content} ); }