import * as React from 'react' ; import ClassNames from 'classnames' ; import { BadgeProps } from './interface' ; import './style/index.scss' ; const defaultProps = { dot : false , overflowCount : 99 , prefixCls : 'cp-ui-badge' , corner : false } ; const getClassNames = ( { status , prefixCls , children } ) => { return ClassNames ( prefixCls , { [ `${ prefixCls }-${ status }` ] : status , [ `${ prefixCls }-no-wrapper` ] : ! children } ) ; } ; const getOutStyle = ( style , corner ) => { let _style = { } ; if ( ! ! corner ) { _style . width = '100%' ; } _style = Object . assign ( style , _style ) ; return _style ; } ; const renderCount = ( { text , overflowCount , dot , prefixCls , corner , style } ) => { if ( dot ) { return < sup className = { `${ prefixCls }-dot` } />; } if ( text ) { let content ; const classStr = ClassNames ( `${ prefixCls }-text` , { [ `${ prefixCls }-custom` ] : typeof text !== 'number' , [ `${ prefixCls }-corner` ] : ! ! corner } ) ; if ( typeof text === 'number' ) { content = text <= overflowCount ? text : `${ overflowCount }+` ; } else { content = text ; } return ( < sup className = { classStr } style = { style } > { content } < /sup>); } return null ; } ; const Badge = props => { const { children , corner , outStyle } = props ; return ( < div className = { getClassNames ( props ) } style = { getOutStyle ( outStyle ?? { } , corner ) } > { children } { renderCount ( props ) } < /div>); } ; Badge . defaultProps = defaultProps ; export default Badge ;