File size: 824 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { formatNumber, formatNumberCompact } from '@automattic/number-formatters';
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';

import './style.scss';

export const Count = ( {
	count,
	primary = false,
	compact = false,
	forwardRef,
	numberFormat: numberFormatFromProps,
	translate,
	locale,
	...props
} ) => {
	const effectiveNumberFormat = numberFormatFromProps ?? formatNumber;

	return (
		<span ref={ forwardRef } className={ clsx( 'count', { 'is-primary': primary } ) } { ...props }>
			{ compact ? formatNumberCompact( count ) : effectiveNumberFormat( count ) }
		</span>
	);
};

Count.propTypes = {
	count: PropTypes.number.isRequired,
	numberFormat: PropTypes.func,
	primary: PropTypes.bool,
	compact: PropTypes.bool,
};

export default localize( Count );