Skip to content

Foundation: add the shared UI toolkit (cn helper, cva, '@/' alias, test setup, components/ui folder) #2257

Open

Description

@trillium

Trillium Firstmate 🤖

Overview

Set up the small pieces every shared UI component will need, so later tickets can just add components. No screen changes and no visible change in the app.

Dependencies

The Tailwind upgrade must land first because it fixes Vite plugin issues around CSS @import and path aliases that this migration relies on.

Action Items

Run yarn commands from client/, and commit client/package.json and client/yarn.lock together.

  • Add dependencies: clsx, tailwind-merge, class-variance-authority, and lucide-react (used by the icons ticket). classnames stays for now; old code keeps using it.
  • Create client/src/lib/cn.ts exporting cn(...inputs) = twMerge(clsx(inputs)), fully typed. Add cn.test.ts (merges conflicting Tailwind classes, drops falsy values).
  • Add an @/ import alias that points to client/src: in client/vite.config.mjs (resolve.alias, next to the existing @shared alias) and in client/tsconfig.json (paths). Confirm yarn typecheck, yarn build and yarn test still pass.
  • Create the folder client/src/components/ui/ for shared primitives, with a short README.md explaining the rules: one component per file, file names are lowercase-kebab (button.tsx, radio-group.tsx), each file is .tsx, typed props, cva for variants, cn() for className, no @mui/* or @emotion/* imports, no .scss imports, and each component gets a colocated *.test.tsx.
  • Add Vitest support for component tests: @testing-library/user-event and @testing-library/jest-dom as dev dependencies, plus a setup file (for example client/src/test/setup.ts, registered as test.setupFiles in vite.config.mjs). In the setup file add the small browser stubs that jsdom lacks and that Radix components need (ResizeObserver, Element.prototype.scrollIntoView, hasPointerCapture/releasePointerCapture, window.matchMedia).
  • Add one sample test that renders a throwaway element and uses userEvent and a jest-dom matcher, to prove the setup works. Delete the sample once the first real primitive test exists, or keep it as test/setup.test.ts.
  • Radix packages are not added here; each component ticket installs the ones it needs.
  • In the PR description list how to write and run a component test: yarn test in client/.

Acceptance Criteria

  • yarn typecheck, yarn build and yarn test pass in client/.
  • import { cn } from "@/lib/cn" works from both a .tsx and a .jsx file.
  • client/src/components/ui/README.md exists and lists the rules above.
  • The app looks and behaves exactly the same (no screen file changed other than imports if any).
  • The bundle size change is noted in the PR (yarn build output before/after).

Resources/Instructions

Additional Notes

  • Why @/: today only @shared has an alias, and deep relative imports like ../../parts/form/... are easy to get wrong. Proposed default: @/ = client/src. If the team prefers relative imports, say so on the ticket and this item can be dropped.
  • Packages are installed with yarn in client/, matching how the client is installed today.
  • The icon package (lucide-react) is installed here only so the icons ticket does not need to touch dependencies; if you prefer to install it there, move this item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature: Design systemmilestone: missingrole: Front Endsize: 2pt

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions