ant-design/components/badge/index.jsx
Bruce Mitchener 11c0a6a203 Name classes without Ant* prefix.
Where necessary, prefix the classes imported from react-component
with 'Rc' rather than prefixing the Ant classes with 'Ant'.

The prefixing of Ant classes wasn't consistent and isn't necessary
in many cases.
2016-03-21 20:16:38 +07:00

60 lines
1.5 KiB
JavaScript

import React from 'react';
import Animate from 'rc-animate';
import ScrollNumber from './ScrollNumber';
import classNames from 'classnames';
export default class Badge extends React.Component {
render() {
let { count, prefixCls, overflowCount, className, style, children } = this.props;
const dot = this.props.dot;
count = count > overflowCount ? `${overflowCount}+` : count;
// dot mode don't need count
if (dot) {
count = '';
}
// null undefined "" "0" 0
const hidden = (!count || count === '0') && !dot;
const scrollNumberCls = prefixCls + (dot ? '-dot' : '-count');
const badgeCls = classNames({
[className]: !!className,
[prefixCls]: true,
[`${prefixCls}-not-a-wrapper`]: !children,
});
return (
<span className={badgeCls} title={count} {...this.props} style={null}>
{children}
<Animate component=""
showProp="data-show"
transitionName={`${prefixCls}-zoom`}
transitionAppear>
{
hidden ? null :
<ScrollNumber data-show={!hidden} className={scrollNumberCls}
count={count} style={style} />
}
</Animate>
</span>
);
}
}
Badge.defaultProps = {
prefixCls: 'ant-badge',
count: null,
dot: false,
overflowCount: 99,
};
Badge.propTypes = {
count: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number
]),
dot: React.PropTypes.bool,
overflowCount: React.PropTypes.number,
};