You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
556 B
23 lines
556 B
import PropTypes from 'prop-types'
|
|
|
|
const Truncate = ({ text, maxlen = 12 }) => {
|
|
if (text === null || typeof text === 'undefined' || text === '') {
|
|
return null
|
|
}
|
|
|
|
const textString = text.toString()
|
|
|
|
const truncatedText =
|
|
textString.length < maxlen
|
|
? textString
|
|
: textString.substr(0, maxlen / 2) + '...' + textString.substr(textString.length - maxlen / 2)
|
|
|
|
return truncatedText
|
|
}
|
|
|
|
Truncate.propTypes = {
|
|
text: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
maxlen: PropTypes.number
|
|
}
|
|
|
|
export default Truncate
|
|
|