Shared UI Package

Unified design system and Radix UI primitives shared across Next.js and Vite.

Shared UI Package (`@workspace/ui` / `@repo/ui`)

The shared UI package provides accessible, customizable components built with Tailwind CSS and Radix UI primitives. It eliminates duplicated design code between your Next.js and Vite applications.

Package Layout

The UI package lives in packages/ui:

packages/ui Structure
packages/ui/
├── src/
│   ├── components/
│   │   ├── button.tsx      # CVA button with variants
│   │   ├── card.tsx        # Container card with header/footer
│   │   ├── dialog.tsx      # Modal dialogs
│   │   └── dropdown.tsx    # Accessible dropdown menus
│   └── lib/
│       └── utils.ts        # cn() helper (clsx + tailwind-merge)
├── package.json            # Exports definition
└── tsconfig.json           # Shared base tsconfig

Creating UI Primitives with CVA

Components use Class Variance Authority (CVA) to provide strict variant typings:

Button CVA Definition
// packages/ui/src/components/button.tsx
import * as React from 'react';
import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '../lib/utils';

export const buttonVariants = cva(
  'inline-flex items-center justify-center font-medium transition-colors focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50',
  {
    variants: {
      variant: {
        default: 'bg-white text-black hover:bg-zinc-200',
        outline: 'border border-zinc-800 bg-transparent hover:bg-zinc-900 text-white',
        ghost: 'hover:bg-zinc-800 text-zinc-300 hover:text-white',
      },
      size: {
        default: 'h-9 px-4 py-2 text-sm',
        sm: 'h-8 px-3 text-xs',
        lg: 'h-10 px-6 text-base',
      },
    },
    defaultVariants: {
      variant: 'default',
      size: 'default',
    },
  }
);

Importing into Applications

In your app's package.json, Morax adds the dependency via the PNPM workspace protocol:

package.json
"dependencies": {
  "@workspace/ui": "workspace:*"
}

Zero-Build Symlinks

There is no compilation step or watch daemon required for the UI package. Next.js and Vite transpile TypeScript source files on the fly during development.