import React, { FunctionComponent } from 'react' import { TouchableOpacity,View,Text } from 'react-native' import Popup from '../popup' import { useConfig } from '../configprovider'; import actionSheetStyles from './styles'; export type ItemType = { [key: string]: T } export interface ActionSheetProps { cancelTxt: string optionTag: string optionSubTag: string chooseTagValue: string title: string color: string description: string menuItems: ItemType[] onCancel: () => void onChoose: (item: any, index: number) => void visible: boolean className: string style: React.CSSProperties } const defaultProps = { cancelTxt: '', optionTag: 'name', optionSubTag: 'subname', chooseTagValue: '', title: '', color: '#ee0a24', description: '', menuItems: [], onCancel: () => {}, onChoose: () => {}, visible: false, className: '', style: {}, } as ActionSheetProps export const ActionSheet: FunctionComponent< Partial & React.HTMLAttributes > = (props) => { const { children, cancelTxt, optionTag, optionSubTag, chooseTagValue, title, color, description, menuItems, onCancel, onChoose, visible, className, style, ...rest } = { ...defaultProps, ...props } const { theme } = useConfig(); const mStyles = actionSheetStyles(theme); const isHighlight = (item: ItemType) => { return props.chooseTagValue && props.chooseTagValue === item[props.optionTag || 'name'] ? props.color : '#1a1a1a' } const cancelActionSheet = () => { onCancel && onCancel() } const chooseItem = (item: ItemType, index: number) => { if (!item.disable) { onChoose && onChoose(item, index) } } return ( { onCancel && onCancel() }} > {title ? {title}:null} {description ? {description} : null } {menuItems.length ? ( {menuItems.map((item, index) => { return ( chooseItem(item, index)} > {item[optionTag] ? {item[optionTag]} : null} {item[optionSubTag] ? {item[optionSubTag]} : null} ) })} ) : ( children )} {cancelTxt && cancelTxt!='' ? cancelActionSheet()}> {cancelTxt} : null } ) } ActionSheet.defaultProps = defaultProps ActionSheet.displayName = 'NutActionSheet'