import React from 'react' import { type Meta } from '@storybook/react-vite' import { DocsTemplate } from '../../../.storybook' import { reduceAndOrAverage } from '../../services/HelperServiceTyped' export const Example = (args: { /** Array to reduce / average */ arr: Record[] /** Name of property to reduce over */ prop: string /** Optional number to average by */ totalToDivideBy?: number | null /** Various extra props to modify result */ extras?: { /** rounds result */ round?: boolean /** floors result */ floor?: boolean /** adds thousand separator to result */ thousandSeparator?: boolean /** number of decimal places to convert to result to */ toFixed?: number /** if data point is a percentage */ percentage?: boolean /** prepend to output string */ prefix?: string /** append to output string */ suffix?: string } }): React.JSX.Element => { return ( <> Reduced data:{' '} {reduceAndOrAverage( args.arr, args.prop, args.totalToDivideBy, args.extras, )} ) } Example.storyName = 'reduceAndOrAverage' Example.args = { arr: [{ num: 1000 }, { num: 2000 }, { num: 3000 }], prop: 'num', totalToDivideBy: 3, extras: { thousandSeparator: true, prefix: '$', }, } export default { title: 'Helper Functions/reduceAndOrAverage', component: Example, parameters: { viewMode: 'docs', previewTabs: { canvas: { hidden: true }, }, docs: { page: () => ( <> reduceAndOrAverage is used when you need to reduce and/or average datapoints from a particular data property. , ]} /> ), }, }, } as Meta