UNPKG

@uiw/react-native

Version:
25 lines (23 loc) 654 B
import React from 'react'; import PropTypes from 'prop-types'; import { Text } from 'react-native'; export default function Ellipsis({ maxLen, children, placeholder, ...props }) { let content = children; if (maxLen && content && typeof content === 'string') { content = content.length > maxLen ? content.substr(0, maxLen) + placeholder : content; } return <Text {...props}>{content}</Text>; } Ellipsis.propTypes = { children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node, PropTypes.string]), placeholder: PropTypes.string, maxLen: PropTypes.number }; Ellipsis.defaultProps = { placeholder: '...' };