import React, {FunctionComponent} from 'react' import { SINGLE_STAT_DEFAULT_STYLE, SINGLE_STAT_DEFAULT_TEST_ID, SINGLE_STAT_RESIZER_DEFAULT_STYLE, SINGLE_STAT_SVG_DEFAULT_ATTRIBUTES, SINGLE_STAT_SVG_TEXT_DEFAULT_ATTRIBUTES, SINGLE_STAT_SVG_TEXT_DEFAULT_STYLE, } from '../../constants/singleStatStyles' import {SingleStatLayerConfig} from '../../types' import {formatStatValue} from '../../utils/formatStatValue' interface Props { stat: number config: SingleStatLayerConfig } const getDefaultViewBox = (stat: string): string => `0 0 ${stat.length * 55} 100` export const SingleStatLayer: FunctionComponent = props => { const {stat, config} = props const { backgroundColor = null, decimalPlaces, prefix, resizerStyle = {}, style = {}, suffix, svgAttributes = {viewBox: ''}, svgStyle = {}, svgTextAttributes = {}, svgTextStyle = {}, testID = SINGLE_STAT_DEFAULT_TEST_ID, textColor, textOpacity = 1, } = config const formattedValue = formatStatValue(stat, {decimalPlaces, prefix, suffix}) let viewBox = getDefaultViewBox(formattedValue) if (svgAttributes.viewBox) { viewBox = typeof svgAttributes.viewBox === 'function' ? svgAttributes.viewBox(formattedValue) : svgAttributes.viewBox } return (
{formattedValue}
) }