import React, { SFC } from 'react'; import PropTypes from 'prop-types'; import get from 'lodash/get'; import pure from 'recompose/pure'; import Typography, { TypographyProps } from '@material-ui/core/Typography'; import sanitizeRestProps from './sanitizeRestProps'; import { InjectedFieldProps, FieldProps, fieldPropTypes } from './types'; export const removeTags = (input: string) => input ? input.replace(/<[^>]+>/gm, '') : ''; interface Props extends FieldProps { stripTags: boolean; } const RichTextField: SFC = ({ className, source, record = {}, stripTags, ...rest }) => { const value = get(record, source); if (stripTags) { return ( {removeTags(value)} ); } return ( ); }; const EnhancedRichTextField = pure(RichTextField); EnhancedRichTextField.defaultProps = { addLabel: true, stripTags: false, }; EnhancedRichTextField.propTypes = { ...Typography.propTypes, ...fieldPropTypes, stripTags: PropTypes.bool, }; EnhancedRichTextField.displayName = 'EnhancedRichTextField'; export default EnhancedRichTextField;