Number.tsx 718 Bytes
Newer Older
Maksym Tishchenko's avatar
Maksym Tishchenko committed
1
import * as React from 'react';
Oleksii Savran's avatar
Oleksii Savran committed
2
import { WithTranslation, withTranslation } from 'react-i18next';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

interface INumber extends React.ClassAttributes<any>, WithTranslation {
  value: number;
  config?: Intl.NumberFormatOptions;
}


// Print a number
// TBD maybe use l10n instead?
class Number extends React.Component<INumber, any> {
  public constructor(props) {
    super(props);
  }

  public render() {
Oleksii Savran's avatar
Oleksii Savran committed
18
    const { value, config = {}, i18n } = this.props;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
19
20
21
22
23
24
25
26
27
28

    if (typeof value === 'number') {
      return <span>{ value.toLocaleString(i18n.language, { maximumFractionDigits: 6, ...config }) }</span>;
    } else {
      return <span>&mdash;</span>;
    }
  }
}

export default React.memo(withTranslation()(Number));