Files
krow_talent_app/src/components/charts/muiChartTheme.ts
Aravind d440036211 chore(ts-migration): migrate UI primitives and design system to TypeScript
Phase 6. 57 files: 23 vendored shadcn primitives, 30 design-system components,
4 charts. Plus `src/components/ds/props.ts`, which is types only.

Renaming these alone took typecheck from 37 to 1008, and the reason is worth
recording because it is the shape of every remaining phase.

These components had NO prop contract. No PropTypes, no validation: in the
JavaScript every prop was optional and every extra prop was spread onto the
underlying element. TypeScript infers a destructured parameter WITHOUT a default
as REQUIRED, so the moment the files became `.tsx` it invented a rule the
components never had and rejected several hundred call sites that have always
worked. That is the compiler describing its own inference, not a defect it
found.

Three mechanical fixes, each restoring a contract that already existed:

  - 57 JSDoc `@type {React.ForwardRefExoticComponent<any>}` annotations become
    real TypeScript annotations. Those comments were the previous authors'
    deliberate compatibility types; JSDoc stops applying in a `.tsx` file, so
    converting them preserves an intent that was already written down.

  - 61 `React.forwardRef(...)` calls gain `<any, any>`. Without generics `ref`
    infers `ForwardedRef<unknown>`, which no element's `Ref<T>` accepts - so
    every primitive that forwards a ref to a `div` failed on the ref, not the
    props.

  - 78 component signatures take `DsProps`, a documented alias for
    `Record<string, any>`. It exists so the decision is recorded once and is
    greppable when someone tightens it, rather than being 78 bare `any`s with
    no explanation between them. The prop NAMES are not lost: every component
    still destructures them by name, which is where a reader looks.

Four files needed real types rather than compatibility ones. `ds/toast` takes
react-hot-toast's own `ToastOptions`, which narrows `position` to its
`ToastPosition` union instead of widening to `string` - the widening was what
made all six calls unassignable. `ds/Pagination`'s page range is genuinely
`(number | string)[]`, because it interleaves page numbers with '…' markers that
the renderer tests for. `ds/Field` narrows `children.props` at three reads, and
`ds/Avatar` needed the ref generic.

Two of my own automated passes were wrong and were caught rather than shipped. A
props-interface generator dropped alternating props, because non-overlapping
regex matches consume the separating comma - it made things worse (83 file
errors to 146) and was reverted wholesale. A second pass missed every
multi-line signature whose defaults contain a `)`, such as `onClose = () => {}`;
that needed a brace matcher rather than a character class.

56 of 57 files emit byte-identical JavaScript. The one exception is `ds/toast`,
where a JSDoc type CAST - `/** @type {ToastPosition} */ ('bottom-center')` -
became a real annotation, so the emitted output loses a comment and a pair of
now-redundant parentheses. The value is `"bottom-center"` either way; the
minified outputs differ only in esbuild's choice of mangled local names.

Verified: tsc 37 -> 35, set-difference showing zero introduced and two removed;
zero errors remain in any Phase 6 file; npm test 1684/1691 with the same seven
failures; lint 0 errors; build succeeds with the API origin inlined; baseline
artifacts untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HBG1wnuRfJKCstGB8Fekr8
2026-09-17 23:59:49 +05:30

87 lines
2.8 KiB
TypeScript

/**
* KROW styling for MUI X Charts.
*
* MUI X is the drawing layer only — the surfaces, spacing and typography around
* a chart stay KROW's. This module is what stops the two from disagreeing: the
* palette is the same one the Recharts components already use (`CHART_TONES`),
* and the `sx` block restyles MUI's axes, grid and tooltip to the design
* system's hairlines and type scale rather than Material's defaults.
*
* Everything here is presentation. No chart in this folder computes a value.
*/
import { CHART_TONES } from '@/components/ds/ChartContainer';
export const TONES = {
brand: CHART_TONES.brand,
brandSoft: 'rgba(10, 57, 223, 0.14)',
warning: '#D97706',
warningSoft: 'rgba(217, 119, 6, 0.16)',
success: '#16A34A',
grid: CHART_TONES.grid,
axis: CHART_TONES.axis,
ink: '#0F172A',
muted: '#64748B',
};
/** Type scale for chart text — matches the caption/overline sizes around it. */
const LABEL_FONT = {
fontSize: 11,
fontFamily: 'var(--font-body)',
};
/**
* Shared `sx` for every KROW chart.
*
* Axis lines and ticks are removed rather than restyled: on a compact chart the
* value labels carry the reading, and a full axis frame is the "chart junk" the
* design language avoids. The grid stays as a hairline in the same colour the
* rest of the product uses for rules.
*/
export const chartSx = {
'& .MuiChartsAxis-line': { display: 'none' },
'& .MuiChartsAxis-tick': { display: 'none' },
'& .MuiChartsAxis-tickLabel': {
...LABEL_FONT,
fill: `${TONES.muted} !important`,
},
'& .MuiChartsGrid-line': {
stroke: TONES.grid,
strokeDasharray: '3 3',
},
'& .MuiChartsLegend-root': { display: 'none' },
'& .MuiBarLabel-root': {
...LABEL_FONT,
fontWeight: 600,
fill: `${TONES.ink} !important`,
},
};
/**
* Tooltip chrome matching `Surface`.
*
* Passed through `slotProps.tooltip` so MUI's popper carries the design
* system's radius, hairline border and shadow instead of Material elevation.
*/
export const tooltipSx = {
'& .MuiChartsTooltip-root, & .MuiPopper-root .MuiPaper-root': {
borderRadius: '10px',
border: `1px solid ${TONES.grid}`,
boxShadow: '0 8px 24px -12px rgba(15, 23, 42, 0.25)',
fontFamily: 'var(--font-body)',
fontSize: 12,
},
'& .MuiChartsTooltip-table': { fontSize: 12 },
'& .MuiChartsTooltip-labelCell, & .MuiChartsTooltip-valueCell': {
fontFamily: 'var(--font-body)',
},
};
/*
* Entry animation is switched off at every call site rather than gated on
* `prefers-reduced-motion`. Two reasons: a chart that grows out of the floor is
* the decorative motion this product avoids, and MUI's bar transition leaves
* every bar at zero height if the frame loop never advances — which is exactly
* what happens in an inactive tab or an automated browser.
*/