({
id,
className,
children,
config,
data,
dataKey,
ref,
layout = 'horizontal',
containerHeight,
...props
}: Omit<React.ComponentProps<'div'>, 'children'> &
Pick<ChartContextProps, 'data' | 'dataKey'> & {
config: ChartConfig
containerHeight?: number
layout?: ChartLayout
children: ReactElement | ((props: ChartContextProps) => ReactElement)
})
| 173 | } |
| 174 | |
| 175 | const Chart = ({ |
| 176 | id, |
| 177 | className, |
| 178 | children, |
| 179 | config, |
| 180 | data, |
| 181 | dataKey, |
| 182 | ref, |
| 183 | layout = 'horizontal', |
| 184 | containerHeight, |
| 185 | ...props |
| 186 | }: Omit<React.ComponentProps<'div'>, 'children'> & |
| 187 | Pick<ChartContextProps, 'data' | 'dataKey'> & { |
| 188 | config: ChartConfig |
| 189 | containerHeight?: number |
| 190 | layout?: ChartLayout |
| 191 | children: ReactElement | ((props: ChartContextProps) => ReactElement) |
| 192 | }) => { |
| 193 | const isMobile = useIsMobile() |
| 194 | const uniqueId = useId() |
| 195 | const chartId = useMemo(() => `chart-${id || uniqueId.replace(/:/g, '')}`, [id, uniqueId]) |
| 196 | |
| 197 | const [selectedLegend, setSelectedLegend] = useState<string | null>(null) |
| 198 | |
| 199 | const onLegendSelect = useCallback((legendItem: string | null) => { |
| 200 | setSelectedLegend(legendItem) |
| 201 | }, []) |
| 202 | |
| 203 | const _data = data ?? [] |
| 204 | const _dataKey = dataKey ?? 'value' |
| 205 | |
| 206 | const value = useMemo( |
| 207 | () => ({ |
| 208 | config, |
| 209 | selectedLegend, |
| 210 | onLegendSelect, |
| 211 | data: _data, |
| 212 | dataKey: _dataKey, |
| 213 | layout, |
| 214 | }), |
| 215 | [config, selectedLegend, onLegendSelect, _data, _dataKey, layout] |
| 216 | ) |
| 217 | |
| 218 | return ( |
| 219 | <ChartContext value={value}> |
| 220 | <div |
| 221 | data-chart={chartId} |
| 222 | ref={ref} |
| 223 | className={twMerge( |
| 224 | 'z-20 flex w-full justify-center text-xs', |
| 225 | "[&_.recharts-cartesian-axis-tick_text]:fill-muted-fg [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/80 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden [&_.recharts-surface_.recharts-text.recharts-cartesian-axis-tick-value]:*:fill-muted-fg", |
| 226 | "[&_.recharts-dot[fill='#fff']]:fill-(--line-color)", |
| 227 | '[&_.recharts-active-dot>.recharts-dot]:stroke-fg/10', |
| 228 | |
| 229 | '[&_.recharts-surface_g]:focus:outline-hidden', |
| 230 | |
| 231 | className |
| 232 | )} |
nothing calls this directly
no test coverage detected