import React, { ReactElement } from 'react'; import { DimensionValue, Pressable, View } from 'react-native'; import { Icon, SemanticColor, Typo } from '../../foundation'; type Props = { title: string; description?: string; onPress?: (title: string) => void; selected?: boolean; disabled?: boolean; border?: boolean; extraComponent?: ReactElement; flex?: number; width?: DimensionValue; /** * 본인 크기만큼만 차지하기 위한 옵션 * - 이 옵션을 사용할 경우, 긴 텍스트가 화면 밖으로 잘릴 수 있습니다. 따라서 부모 컴포넌트에 flexWrap: 'wrap' 처리해 주세요 */ isFitToContent?: boolean; }; /** * 체크박스 라벨 컴포넌트 * * - 선택지들의 데이터 구조, 선택 여부를 관리하는 state, 선택시 동작을 제어하는 함수를 사용처에서 자유롭게 구현하도록 했습니다. */ export function CheckboxWithLabel(props: Props): React.JSX.Element { const { onPress, title, description, disabled, selected = false, border = false, extraComponent, width, flex, isFitToContent = false, } = props; const checkboxIcon = (() => { if (selected === false) { return ; } if (selected === true && disabled === true) { return ; } return ; })(); const handlePress = () => { if (onPress) { onPress(title); } }; const borderStyle = border ? { borderWidth: 1, borderColor: SemanticColor.border_tertiary, padding: 12, borderRadius: 8, backgroundColor: SemanticColor.bg_primary, } : undefined; return ( {checkboxIcon} {title} {description && ( {description} )} {extraComponent && {extraComponent}} ); }