import React from 'react'; import { Pressable, View } from 'react-native'; import { Icon, Typo } from '../../foundation'; import { LayoutStyleProp } from '../../internal/utils/utilTypes'; import { useThrottledPressHandler } from '../../internal/utils/useThrottledPressHandler'; import { isNil, noop } from '../../internal/utils/functions'; /** * 브레드크럼 아이템들을 자식으로 받아 구분자를 추가하여 레이아웃을 구성하는 역할 */ function BreadcrumbContainer(props: { children: ReturnType[] } & LayoutStyleProp) { return ( {React.Children.map(props.children, (child, index) => { if (child.type !== BreadcrumbItem) { throw new Error( `${BreadcrumbContainer.displayName}의 자식 컴포넌트로 ${BreadcrumbItem.displayName}을 사용하세요`, ); } const isLastItem = index === React.Children.count(props.children) - 1; return ( {isLastItem ? React.cloneElement(child, { ellipsis: isLastItem }) : child} {isLastItem ? null : ( )} ); })} ); } BreadcrumbContainer.displayName = 'Breadcrumb.Container'; /** * 브레드크럼 아이템 */ function BreadcrumbItem(props: { label: string; onPress?: () => void; /** * @deprecated 직접 사용하지 마세요. `Breadcrumb.Container` 컴포넌트에서 마지막 아이템을 말줄임 처리합니다. */ ellipsis?: boolean; }): JSX.Element { const throttledOnPress = useThrottledPressHandler(props.onPress ?? noop, true); return ( {props.label} ); } BreadcrumbItem.displayName = 'Breadcrumb.Item'; /** * # Breadcrumb 컴포넌트 * * * ## `Breadcrumb.Container` 컴포넌트 Props * * ### `layoutStyle` * - 컴포넌트를 배치하는데 필요한 ViewStyle 모음 * * * ## `Breadcrumb.Item` 컴포넌트 Props * * ### `label` * - 브레드크럼 아이템의 라벨 * * ### `onPress` * - 브레드크럼 아이템을 눌렀을 때의 동작 * - 전달하지 않을 경우 해당 아이템을 눌러도 터치 피드백이 없습니다. * * ### `ellipsis` (직접 사용 X) * - label 말줄임 처리 여부 * - 디자인시스템 가이드상 마지막 아이템에만 말줄임 처리를 하도록 되어있습니다. `Breadcrumb.Container` 컴포넌트에서 자동으로 처리합니다. * * * ## 예시 * * @example * ```tsx * * * * * * * * * * * ``` * */ export const Breadcrumb = { /** Breadcrumb 객체에 작성된 문서를 봐주세요 */ Container: BreadcrumbContainer, /** Breadcrumb 객체에 작성된 문서를 봐주세요 */ Item: BreadcrumbItem, };