File size: 2,066 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "type": "composition",
  "npmDependencies": [],
  "fileDependencies": [
    "compositions/ui/toggle-tip"
  ],
  "id": "stat",
  "file": {
    "name": "stat.tsx",
    "content": "import {\n  Badge,\n  type BadgeProps,\n  Stat as ChakraStat,\n  FormatNumber,\n} from \"@chakra-ui/react\"\nimport { InfoTip } from \"./toggle-tip\"\nimport * as React from \"react\"\n\ninterface StatLabelProps extends ChakraStat.LabelProps {\n  info?: React.ReactNode\n}\n\nexport const StatLabel = React.forwardRef<HTMLDivElement, StatLabelProps>(\n  function StatLabel(props, ref) {\n    const { info, children, ...rest } = props\n    return (\n      <ChakraStat.Label {...rest} ref={ref}>\n        {children}\n        {info && <InfoTip>{info}</InfoTip>}\n      </ChakraStat.Label>\n    )\n  },\n)\n\ninterface StatValueTextProps extends ChakraStat.ValueTextProps {\n  value?: number\n  formatOptions?: Intl.NumberFormatOptions\n}\n\nexport const StatValueText = React.forwardRef<\n  HTMLDivElement,\n  StatValueTextProps\n>(function StatValueText(props, ref) {\n  const { value, formatOptions, children, ...rest } = props\n  return (\n    <ChakraStat.ValueText {...rest} ref={ref}>\n      {children ||\n        (value != null && <FormatNumber value={value} {...formatOptions} />)}\n    </ChakraStat.ValueText>\n  )\n})\n\nexport const StatUpTrend = React.forwardRef<HTMLDivElement, BadgeProps>(\n  function StatUpTrend(props, ref) {\n    return (\n      <Badge colorPalette=\"green\" gap=\"0\" {...props} ref={ref}>\n        <ChakraStat.UpIndicator />\n        {props.children}\n      </Badge>\n    )\n  },\n)\n\nexport const StatDownTrend = React.forwardRef<HTMLDivElement, BadgeProps>(\n  function StatDownTrend(props, ref) {\n    return (\n      <Badge colorPalette=\"red\" gap=\"0\" {...props} ref={ref}>\n        <ChakraStat.DownIndicator />\n        {props.children}\n      </Badge>\n    )\n  },\n)\n\nexport const StatRoot = ChakraStat.Root\nexport const StatHelpText = ChakraStat.HelpText\nexport const StatValueUnit = ChakraStat.ValueUnit\n"
  },
  "component": "Stat"
}