// Tremor BarList [v0.1.1] import React from 'react'; import { cx, focusRing } from '../../lib/utils'; type Bar = T & { key?: string href?: string value: number name: string } interface BarListProps extends React.HTMLAttributes { data: Bar[] valueFormatter?: ( value: number ) => string showAnimation?: boolean onValueChange?: ( payload: Bar ) => void sortOrder?: 'ascending' | 'descending' | 'none' } function BarListInner( { data = [], valueFormatter = value => value.toString(), showAnimation = false, onValueChange, sortOrder = 'descending', className, ...props }: BarListProps, forwardedRef: React.ForwardedRef ) { const Component = onValueChange ? 'button' : 'div'; const sortedData = React.useMemo( () => { if ( sortOrder === 'none' ) { return data; } return [ ...data ].sort( ( a, b ) => { return sortOrder === 'ascending' ? a.value - b.value : b.value - a.value; } ); }, [ data, sortOrder ] ); const widths = React.useMemo( () => { const maxValue = Math.max( ...sortedData.map( item => item.value ), 0 ); return sortedData.map( item => item.value === 0 ? 0 : Math.max( ( item.value / maxValue ) * 100, 2 ) ); }, [ sortedData ] ); const rowHeight = 'h-8'; return (
{ sortedData.map( ( item, index ) => ( { onValueChange?.( item ); } } >
{ item.href ? ( event.stopPropagation() } > { item.name } ) : (

{ item.name }

) }
) ) }
{ sortedData.map( ( item, index ) => (

{ valueFormatter( item.value ) }

) ) }
); } BarListInner.displayName = 'BarList'; const BarList = React.forwardRef( BarListInner ) as ( p: BarListProps & { ref?: React.ForwardedRef }, ) => ReturnType; export default BarList; export { BarList, type BarListProps, };