about summary refs log tree commit diff
path: root/app/javascript/mastodon/features/ui/components/notifications_counter_icon.js
blob: 9673c57feff073a455181de1a85d32e46846d43e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import Icon from 'mastodon/components/icon';

const mapStateToProps = state => ({
  count: state.getIn(['notifications', 'unread']),
});

const formatNumber = num => num > 99 ? '99+' : num;

const NotificationsCounterIcon = ({ count, className }) => (
  <i className='icon-with-badge'>
    <Icon id='bell' fixedWidth className={className} />
    {count > 0 && <i className='icon-with-badge__badge'>{formatNumber(count)}</i>}
  </i>
);

NotificationsCounterIcon.propTypes = {
  count: PropTypes.number.isRequired,
  className: PropTypes.string,
};

export default connect(mapStateToProps)(NotificationsCounterIcon);