import React from 'react' ; import PropTypes from 'prop-types' ; import { Text } from 'react-native' ; import HtmlView from 'react-native-htmlview' ; export interface DateFieldProps { [ htmlAttributes ] : unknown ; /** The date field data. */ field : { value ? : string ; editable ? : string ; } ; default editable ? : boolean ; render ? : ( date : Date | null ) => React . ComponentType | React . ReactNode ; } export const DateField = ( { field , editable , render , ... otherProps } ) => { if ( ! field || ( ! field . editable && ! field . value ) ) { return null ; } if ( field . editable && editable ) { return < HtmlView value = { field . editable } { ... otherProps } />; } let children ; if ( render ) { children = render ( field . value ? new Date ( field . value ) : null ) ; } else { children = field . value as string ; } return render ? < > { children } < /> : <Text>{children}</Text > ; } ; DateField . propTypes = { field : PropTypes . shape ( { value : PropTypes . any , editable : PropTypes . string } ) . isRequired , editable : PropTypes . bool , render : PropTypes . func } ; DateField . defaultProps = { editable : true } ; DateField . displayName = 'Date' ;