Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate FormattedNumber component from jsx to tsx #17361

Merged
merged 4 commits into from
Nov 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,19 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { formatNumber } from '@superset-ui/core';

const propTypes = {
num: PropTypes.number,
format: PropTypes.string,
};

const defaultProps = {
num: 0,
format: undefined,
};
interface FormattedNumberProps {
num?: string | number;
format?: string;
}

function FormattedNumber({ num, format }) {
function FormattedNumber({ num = 0, format }: FormattedNumberProps) {
if (format) {
return <span title={num}>{formatNumber(format, num)}</span>;
// @ts-expect-error formatNumber can actually accept strings, even though it's not typed as such
return <span title={`${num}`}>{formatNumber(format, num)}</span>;
}
return <span>{num}</span>;
}

FormattedNumber.propTypes = propTypes;
FormattedNumber.defaultProps = defaultProps;

export default FormattedNumber;