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
This commit is contained in:
2026-09-17 23:59:49 +05:30
parent 2b8f5746bd
commit d440036211
58 changed files with 191 additions and 185 deletions

128
src/components/ds/Modal.tsx Normal file
View File

@@ -0,0 +1,128 @@
import type { DsProps } from './props';
import * as React from 'react';
import { cn } from '@/lib/utils';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
const WIDTHS = {
sm: 'sm:max-w-sm',
default: 'sm:max-w-lg',
lg: 'sm:max-w-2xl',
xl: 'sm:max-w-4xl',
};
/**
* Modal — the standard dialog shape: header, scrollable body, footer.
*
* Owning the scroll boundary here is the point. A dialog that lets its whole
* body scroll pushes the title and the confirm button off-screen on a laptop;
* this keeps both pinned and scrolls only the middle.
*/
/** @param {any} props */
/** @param {any} props */
export function Modal({
open,
onOpenChange,
title,
description,
icon: Icon,
size = 'default',
/** Footer content. Omit for a dialog whose body carries its own actions. */
footer,
children,
className,
/** Blocks closing — use while a submit is in flight. */
busy = false,
}: DsProps) {
return (
<Dialog open={open} onOpenChange={busy ? undefined : onOpenChange}>
<DialogContent
/* `dvh`, not `vh`: on a phone `100vh` is the *large* viewport, which
includes the browser chrome that is currently covering the bottom of
the screen — so a `90vh` dialog put its footer, and its confirm
button, under the address bar. */
className={cn('p-0 gap-0 overflow-hidden max-h-[calc(100dvh-2rem)] flex flex-col', WIDTHS[size], className)}
onInteractOutside={busy ? (e) => e.preventDefault() : undefined}
onEscapeKeyDown={busy ? (e) => e.preventDefault() : undefined}
>
<DialogHeader className="px-6 pt-6 pb-4 border-b border-border shrink-0 space-y-0">
<div className="flex items-start gap-3">
{Icon && (
<span className="grid place-items-center w-9 h-9 rounded-xl bg-krow-blue-tint text-krow-blue shrink-0">
<Icon className="w-4.5 h-4.5" aria-hidden="true" />
</span>
)}
<div className="min-w-0 text-left">
<DialogTitle className="text-title font-heading text-ink-1">{title}</DialogTitle>
{description && (
<DialogDescription className="text-body-sm text-ink-3 mt-1">
{description}
</DialogDescription>
)}
</div>
</div>
</DialogHeader>
<div className="flex-1 overflow-y-auto px-6 py-5">{children}</div>
{footer && (
<DialogFooter className="px-6 py-4 border-t border-border bg-surface-subtle shrink-0">
{footer}
</DialogFooter>
)}
</DialogContent>
</Dialog>
);
}
/**
* ConfirmModal — a destructive or irreversible confirmation.
*
* Defaults to the destructive tone because that is what confirmation is almost
* always for, and it labels the action with the verb ("Delete") rather than
* "OK", so the button says what will happen.
*/
/** @param {any} props */
export function ConfirmModal({
open,
onOpenChange,
title = 'Are you sure?',
description,
confirmLabel = 'Confirm',
cancelLabel = 'Cancel',
onConfirm,
tone = 'destructive',
icon = null,
busy = false,
}: DsProps) {
return (
<Modal
open={open}
onOpenChange={onOpenChange}
title={title}
description={description}
icon={icon}
size="sm"
busy={busy}
footer={
<>
<Button variant="outline" onClick={() => onOpenChange?.(false)} disabled={busy}>
{cancelLabel}
</Button>
<Button variant={tone === 'destructive' ? 'destructive' : 'default'} onClick={onConfirm} loading={busy}>
{confirmLabel}
</Button>
</>
}
>
{null}
</Modal>
);
}