import * as React from 'react'; import { StyleSheet, Text, TextStyle, TouchableWithoutFeedback, View, ViewStyle, } from 'react-native'; import base from '../../_styles/themes/default.basic'; import { MDIcon } from '../icon/icon'; import OptionModel from './option-model'; interface IMDOptionItemProps { styles?: IMDOptionItemStyle; type: string; data: OptionModel; checked: boolean; disabled: boolean; icon: MDIcon; iconPosition?: string; onItemPress?: () => void; } export interface IMDOptionItemStyle { itemWrapper?: ViewStyle; item?: TextStyle; itemInverse?: TextStyle; itemDisabled?: TextStyle; itemDescribe?: TextStyle; } export const MDOptionItemStyles: IMDOptionItemStyle = { itemWrapper: { marginLeft: base.gapSize.hLarge, marginRight: base.gapSize.hLarge, paddingTop: base.gapSize.vLarge, paddingBottom: base.gapSize.vLarge, backgroundColor: base.colors.bg, borderBottomWidth: base.borderWidth.base, borderBottomColor: base.colors.borderBase, justifyContent: 'center', }, item: { textAlign: 'center', fontSize: base.fontSize.captionNormal, color: base.colors.textBody, }, itemInverse: { textAlign: 'center', fontSize: base.fontSize.captionNormal, color: base.colors.textHighlight, }, itemDisabled: { textAlign: 'center', fontSize: base.fontSize.captionNormal, color: base.colors.textDisabled, }, itemDescribe: { paddingTop: base.gapSize.vMid, textAlign: 'center', fontSize: base.fontSize.bodyLarge, color: base.colors.textCaption, }, }; const itemStyles = StyleSheet.create(MDOptionItemStyles); export default class MDOptionItem extends React.Component { public static defaultProps = { styles: itemStyles, }; constructor (props: IMDOptionItemProps) { super(props); } public render () { const type = this.props.type; if (type === 'default' || type === 'confirm') { return this.renderCommon(this.props); } else if (type === 'check') { return this.renderCheckMode(this.props); } } private renderCommon (props: IMDOptionItemProps) { const styles = props.styles || {}; const { type, data } = props; const showDescribe = type === 'confirm' && data.optionDescribe; const describe = showDescribe ? ( {props.data.optionDescribe} ) : null; return ( {} : this.props.onItemPress} > {props.data.optionContent} {describe} ); } private renderCheckMode (props: IMDOptionItemProps) { const { icon, iconPosition } = props; const styles = props.styles || {}; const text = ( {props.data.optionContent} ); return ( {} : this.props.onItemPress} > {iconPosition === 'right' ? text : icon} {iconPosition === 'right' ? icon : text} ); } }