import { Progress as GuiProgress } from '@hanzo/gui'; import * as React from 'react'; const SIZE = { sm: 4, md: 8, lg: 12, xl: 16, } as const; type Size = keyof typeof SIZE; interface TrackProps { readonly borderStartRadius?: number | string; readonly borderEndRadius?: number | string; readonly className?: string; readonly style?: React.CSSProperties; } interface ProgressProps extends React.ComponentPropsWithoutRef<'div'> { readonly value?: number | null; readonly min?: number; readonly max?: number; readonly size?: Size; readonly color?: string; readonly trackProps?: TrackProps; // Common Chakra layout shorthands that consumers currently pass. readonly w?: string; readonly flex?: string | number; } function normalizeValue(value: number | null | undefined, min: number, max: number): number { if (value == null) return 0; if (max <= min) return 0; return Math.round(((value - min) / (max - min)) * 100); } export const Progress = React.forwardRef( function Progress(props, ref) { const { value, min = 0, max = 100, size = 'md', color, trackProps, style, w, flex, ...rest } = props; const percent = normalizeValue(value, min, max); const trackStyle: React.CSSProperties = { ...trackProps?.style, ...(trackProps?.borderStartRadius !== undefined && { borderStartStartRadius: trackProps.borderStartRadius, borderEndStartRadius: trackProps.borderStartRadius, }), ...(trackProps?.borderEndRadius !== undefined && { borderStartEndRadius: trackProps.borderEndRadius, borderEndEndRadius: trackProps.borderEndRadius, }), }; const rootStyle: React.CSSProperties = { position: 'relative', ...style, ...(w !== undefined && { width: w === 'full' ? '100%' : w }), ...(flex !== undefined && { flex }), }; return (
{ /* gui drives the fill off `value` — it sizes the indicator to 200% and translates it — and eases it with the config's transition driver. Geometry from the primitive, paint from these props, so the bar is a consequence of state rather than a hand-written width + CSS transition. */ }
); }, );