Design a responsive UI kit using Turborepo where Package A is core logic and Package B…
- User
Design a responsive UI kit using Turborepo where Package A is core logic and Package B is React components. Make Package B tree-shakeable with sideEffects false and export individual CSS modules for each component.
Assistant
This is a comprehensive request for designing a responsive UI kit using Turborepo with specific requirements:
- Turborepo setup: Multi-package workspace
- Package A (Core logic): Utilities, types, algorithms
- Package B (React components): UI components, tree-shakeable
- Features required:
- sideEffects: false for tree-shaking
- Individual CSS modules per component
- Responsive design
- Proper package.json configuration
- Build setup
I'll create a complete, production-ready example with:
- Turborepo configuration
- Package structure
- Build configuration
- Tree-shaking setup
- CSS modules
- TypeScript support
- Example components
- Responsive utilities
Let me structure this comprehensively.
Responsive UI Kit with Turborepo
A complete guide to building a tree-shakeable, responsive UI kit with clear separation of concerns.
Project Structure
ui-kit/ ├── packages/ │ ├── core/ # Package A: Core logic │ │ ├── src/ │ │ │ ├── hooks/ │ │ │ ├── utils/ │ │ │ ├── types/ │ │ │ └── index.ts │ │ ├── package.json │ │ ├── tsconfig.json │ │ └── build.config.ts │ ├── react/ # Package B: React components │ │ ├── src/ │ │ │ ├── components/ │ │ │ ├── styles/ │ │ │ ├── index.ts │ │ │ └── index.d.ts │ │ ├── package.json │ │ ├── tsconfig.json │ │ └── build.config.ts │ └── docs/ # Optional: Storybook ├── turbo.json ├── package.json ├── tsconfig.json └── pnpm-workspace.yaml1. Root Configuration
package.json{ "name": "ui-kit", "version": "1.0.0", "private": true, "description": "Tree-shakeable responsive UI kit", "scripts": { "dev": "turbo run dev --parallel", "build": "turbo run build", "lint": "turbo run lint", "type-check": "turbo run type-check", "test": "turbo run test", "clean": "turbo run clean && rm -rf node_modules" }, "devDependencies": { "@types/node": "^20.10.0", "@types/react": "^18.2.0", "typescript": "^5.3.0", "turbo": "^1.10.0", "vite": "^5.0.0", "vitest": "^1.0.0", "tsup": "^8.0.0" }, "packageManager": "pnpm@8.0.0" }turbo.json{ "$schema": "https://turbo.build/schema.json", "globalDependencies": ["**/.env"], "tasks": { "build": { "outputs": ["dist/**"], "cache": true, "dependsOn": ["^build"] }, "dev": { "cache": false, "persistent": true }, "lint": { "outputs": [".eslintcache"], "cache": true }, "type-check": { "cache": true }, "test": { "outputs": ["coverage/**"], "cache": true, "inputs": ["src/**", "**/*.test.ts", "**/*.test.tsx"] }, "clean": { "cache": false } } }pnpm-workspace.yamlpackages: - "packages/*"tsconfig.json{ "compilerOptions": { "target": "ES2020", "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "moduleResolution": "bundler", "jsx": "react-jsx", "declaration": true, "declarationMap": true, "sourceMap": true, "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true } }2. Package A: Core Logic
packages/core/package.json{ "name": "@ui-kit/core", "version": "1.0.0", "description": "Core utilities and types for UI kit", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", "files": ["dist"], "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }, "./hooks": { "types": "./dist/hooks/index.d.ts", "import": "./dist/hooks/index.js" }, "./utils": { "types": "./dist/utils/index.d.ts", "import": "./dist/utils/index.js" }, "./types": { "types": "./dist/types/index.d.ts", "import": "./dist/types/index.js" } }, "scripts": { "build": "tsup", "dev": "tsup --watch", "type-check": "tsc --noEmit", "lint": "eslint src --ext .ts,.tsx", "test": "vitest", "clean": "rm -rf dist" }, "sideEffects": false, "peerDependencies": { "react": "^18.0.0", "react-dom": "^18.0.0" }, "devDependencies": { "@types/react": "^18.2.0", "react": "^18.2.0", "tsup": "^8.0.0" } }packages/core/tsconfig.json{ "extends": "../../tsconfig.json", "compilerOptions": { "lib": ["ES2020"], "jsx": "react-jsx" }, "include": ["src"], "exclude": ["dist", "node_modules"] }packages/core/build.config.tsimport { defineConfig } from 'tsup'; export default defineConfig([ { entry: { index: 'src/index.ts', 'hooks/index': 'src/hooks/index.ts', 'utils/index': 'src/utils/index.ts', 'types/index': 'src/types/index.ts', }, format: ['esm'], dts: true, splitting: false, sourcemap: true, clean: true, external: ['react', 'react-dom'], }, ]);packages/core/src/types/index.ts/** * Responsive breakpoints in pixels */ export const BREAKPOINTS = { xs: 0, sm: 640, md: 768, lg: 1024, xl: 1280, '2xl': 1536, } as const; export type Breakpoint = keyof typeof BREAKPOINTS; /** * Common theme properties */ export interface Theme { colors: { primary: string; secondary: string; danger: string; success: string; warning: string; background: string; foreground: string; }; spacing: Record<number, string>; typography: { fontFamily: string; sizes: Record<string, string>; weights: Record<string, number>; }; } export interface ResponsiveValue<T> { base?: T; sm?: T; md?: T; lg?: T; xl?: T; } export interface Size { width?: string | number; height?: string | number; } export interface Padding { top?: string | number; right?: string | number; bottom?: string | number; left?: string | number; }packages/core/src/utils/index.tsimport { BREAKPOINTS, ResponsiveValue, Breakpoint } from '../types'; /** * Convert responsive value to CSS custom properties */ export function responsiveToCSS<T extends string | number>( prop: string, value: ResponsiveValue<T>, ): Record<string, string> { const css: Record<string, string> = {}; // Base value if (value.base !== undefined) { css[`--${prop}`] = String(value.base); } // Responsive values Object.entries(value).forEach(([breakpoint, val]) => { if (breakpoint !== 'base' && val !== undefined) { css[`--${prop}-${breakpoint}`] = String(val); } }); return css; } /** * Generate media query helper */ export const media = { up: (breakpoint: Breakpoint | number): string => { const px = typeof breakpoint === 'number' ? breakpoint : BREAKPOINTS[breakpoint]; return `@media (min-width: ${px}px)`; }, down: (breakpoint: Breakpoint | number): string => { const px = typeof breakpoint === 'number' ? breakpoint : BREAKPOINTS[breakpoint]; return `@media (max-width: ${px - 1}px)`; }, between: ( min: Breakpoint | number, max: Breakpoint | number, ): string => { const minPx = typeof min === 'number' ? min : BREAKPOINTS[min]; const maxPx = typeof max === 'number' ? max : BREAKPOINTS[max]; return `@media (min-width: ${minPx}px) and (max-width: ${maxPx - 1}px)`; }, }; /** * Merge CSS class names (simple implementation) */ export function classNames(...classes: (string | false | undefined)[]): string { return classes.filter(Boolean).join(' '); } /** * Convert spacing value to CSS unit */ export function getSpacing(value: number | string): string { if (typeof value === 'string') return value; // Assuming 4px base unit (Tailwind style) return `${value * 4}px`; } /** * Check if value is responsive object */ export function isResponsive<T>( value: unknown, ): value is ResponsiveValue<T> { return ( typeof value === 'object' && value !== null && Object.keys(value).some(key => ['base', 'sm', 'md', 'lg', 'xl'].includes(key) ) ); }packages/core/src/hooks/index.tsimport { useState, useEffect, useCallback, RefObject } from 'react'; import { Breakpoint, BREAKPOINTS } from '../types'; /** * Hook to detect current breakpoint */ export function useBreakpoint(defaultBreakpoint: Breakpoint = 'md'): Breakpoint { const [breakpoint, setBreakpoint] = useState<Breakpoint>(defaultBreakpoint); useEffect(() => { const checkBreakpoint = () => { const width = window.innerWidth; const breakpoints = Object.entries(BREAKPOINTS) .sort(([, a], [, b]) => b - a) .find(([, px]) => width >= px)?.[0]; setBreakpoint((breakpoints as Breakpoint) || 'xs'); }; checkBreakpoint(); window.addEventListener('resize', checkBreakpoint); return () => window.removeEventListener('resize', checkBreakpoint); }, []); return breakpoint; } /** * Hook to detect media query */ export function useMediaQuery(query: string): boolean { const [matches, setMatches] = useState(false); useEffect(() => { const media = window.matchMedia(query); if (media.matches !== matches) { setMatches(media.matches); } const listener = () => setMatches(media.matches); media.addEventListener('change', listener); return () => media.removeEventListener('change', listener); }, [matches, query]); return matches; } /** * Hook for click outside detection */ export function useClickOutside<T extends HTMLElement>( ref: RefObject<T>, callback: () => void, ): void { useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (ref.current && !ref.current.contains(event.target as Node)) { callback(); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, [callback, ref]); } /** * Hook for controlled input */ export function useInput(initialValue: string = '') { const [value, setValue] = useState(initialValue); const reset = useCallback(() => setValue(initialValue), [initialValue]); return { value, setValue, bind: { value, onChange: (e: React.ChangeEvent<HTMLInputElement>) => setValue(e.target.value), }, reset, }; }packages/core/src/index.ts// Types export * from './types'; // Utils export * from './utils'; // Hooks export * from './hooks';3. Package B: React Components
packages/react/package.json{ "name": "@ui-kit/react", "version": "1.0.0", "description": "Tree-shakeable React components with individual CSS modules", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", "files": ["dist"], "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }, "./button": { "types": "./dist/components/Button/index.d.ts", "import": "./dist/components/Button/index.js" }, "./card": { "types": "./dist/components/Card/index.d.ts", "import": "./dist/components/Card/index.js" }, "./input": { "types": "./dist/components/Input/index.d.ts", "import": "./dist/components/Input/index.js" }, "./grid": { "types": "./dist/components/Grid/index.d.ts", "import": "./dist/components/Grid/index.js" } }, "scripts": { "build": "tsup", "dev": "tsup --watch", "type-check": "tsc --noEmit", "lint": "eslint src --ext .ts,.tsx", "test": "vitest", "clean": "rm -rf dist" }, "sideEffects": false, "peerDependencies": { "react": "^18.0.0", "react-dom": "^18.0.0" }, "dependencies": { "@ui-kit/core": "workspace:*" }, "devDependencies": { "@types/react": "^18.2.0", "@types/react-dom": "^18.2.0", "react": "^18.2.0", "react-dom": "^18.2.0", "tsup": "^8.0.0", "postcss": "^8.4.0", "postcss-modules": "^6.0.0" } }packages/react/build.config.tsimport { defineConfig } from 'tsup'; import path from 'path'; export default defineConfig({ entry: { index: 'src/index.ts', 'components/Button/index': 'src/components/Button/index.tsx', 'components/Card/index': 'src/components/Card/index.tsx', 'components/Input/index': 'src/components/Input/index.tsx', 'components/Grid/index': 'src/components/Grid/index.tsx', }, format: ['esm'], dts: true, splitting: false, sourcemap: true, clean: true, external: ['react', 'react-dom', '@ui-kit/core'], loader: { '.module.css': 'empty', }, esbuildPlugins: [], });packages/react/tsconfig.json{ "extends": "../../tsconfig.json", "compilerOptions": { "lib": ["ES2020", "DOM"], "jsx": "react-jsx" }, "include": ["src"], "exclude": ["dist", "node_modules"] }packages/react/src/components/Button/Button.tsximport React, { ButtonHTMLAttributes } from 'react'; import { classNames } from '@ui-kit/core'; import styles from './Button.module.css'; export type ButtonVariant = 'primary' | 'secondary' | 'danger'; export type ButtonSize = 'sm' | 'md' | 'lg'; export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { /** Visual variant */ variant?: ButtonVariant; /** Button size */ size?: ButtonSize; /** Full width button */ fullWidth?: boolean; /** Loading state */ isLoading?: boolean; /** Disabled state */ disabled?: boolean; } /** * Tree-shakeable Button component with CSS modules */ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( ( { variant = 'primary', size = 'md', fullWidth = false, isLoading = false, disabled = false, children, className, ...props }, ref, ) => { return ( <button ref={ref} disabled={disabled || isLoading} className={classNames( styles.button, styles[`variant-${variant}`], styles[`size-${size}`], fullWidth && styles.fullWidth, isLoading && styles.loading, className, )} {...props} > {isLoading && <span className={styles.spinner} aria-hidden="true" />} <span className={styles.label}>{children}</span> </button> ); }, ); Button.displayName = 'Button';packages/react/src/components/Button/Button.module.css.button { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; border: none; border-radius: 0.375rem; cursor: pointer; font-weight: 500; transition: all 0.2s ease-in-out; position: relative; /* Responsive padding */ padding: clamp(0.375rem, 2vw, 0.5rem) clamp(0.75rem, 3vw, 1rem); font-size: clamp(0.875rem, 1.5vw, 1rem); } /* Variants */ .variant-primary { background-color: #3b82f6; color: white; } .variant-primary:hover:not(:disabled) { background-color: #2563eb; box-shadow: 0 4px 6px rgba(59, 130, 246, 0.25); } .variant-primary:active:not(:disabled) { background-color: #1d4ed8; } .variant-secondary { background-color: #e5e7eb; color: #1f2937; } .variant-secondary:hover:not(:disabled) { background-color: #d1d5db; } .variant-danger { background-color: #ef4444; color: white; } .variant-danger:hover:not(:disabled) { background-color: #dc2626; } /* Sizes */ .size-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; min-height: 2rem; } .size-md { padding: 0.5rem 1rem; font-size: 1rem; min-height: 2.5rem; } .size-lg { padding: 0.75rem 1.5rem; font-size: 1.125rem; min-height: 3rem; } /* Modifiers */ .fullWidth { width: 100%; } .loading { opacity: 0.7; pointer-events: none; } /* Spinner animation */ .spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.6s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } .label { display: inline-block; } /* Focus states */ .button:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; } /* Disabled state */ .button:disabled { opacity: 0.5; cursor: not-allowed; } /* Responsive adjustments */ @media (max-width: 640px) { .button { font-size: 0.875rem; padding: 0.375rem 0.75rem; } .size-lg { padding: 0.5rem 1rem; font-size: 1rem; } }packages/react/src/components/Button/index.tsxexport { Button } from './Button'; export type { ButtonProps, ButtonVariant, ButtonSize } from './Button';packages/react/src/components/Card/Card.tsximport React, { HTMLAttributes } from 'react'; import { classNames } from '@ui-kit/core'; import styles from './Card.module.css'; export interface CardProps extends HTMLAttributes<HTMLDivElement> { /** Visual elevation level */ elevation?: 'none' | 'sm' | 'md' | 'lg'; /** Add padding */ padded?: boolean; /** Border radius variant */ rounded?: 'none' | 'sm' | 'md' | 'lg'; /** Hover effect */ interactive?: boolean; } export const Card = React.forwardRef<HTMLDivElement, CardProps>( ( { elevation = 'md', padded = true, rounded = 'md', interactive = false, className, children, ...props }, ref, ) => { return ( <div ref={ref} className={classNames( styles.card, styles[`elevation-${elevation}`], styles[`rounded-${rounded}`], padded && styles.padded, interactive && styles.interactive, className, )} {...props} > {children} </div> ); }, ); Card.displayName = 'Card';packages/react/src/components/Card/Card.module.css.card { background-color: white; border: 1px solid #e5e7eb; overflow: hidden; } /* Elevation / Shadow levels */ .elevation-none { box-shadow: none; } .elevation-sm { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); } .elevation-md { box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .elevation-lg { box-shadow: 0 20px 25px rgba(0, 0, 0, 0.1); } /* Border radius */ .rounded-none { border-radius: 0; } .rounded-sm { border-radius: 0.25rem; } .rounded-md { border-radius: 0.5rem; } .rounded-lg { border-radius: 1rem; } /* Padding */ .padded { padding: clamp(1rem, 4vw, 1.5rem); } /* Interactive */ .interactive { transition: all 0.2s ease-in-out; cursor: pointer; } .interactive:hover { transform: translateY(-2px); box-shadow: 0 20px 25px rgba(0, 0, 0, 0.15); } .interactive:active { transform: translateY(0); } /* Responsive padding */ @media (max-width: 640px) { .padded { padding: 1rem; } }packages/react/src/components/Input/Input.tsximport React, { InputHTMLAttributes } from 'react'; import { classNames } from '@ui-kit/core'; import styles from './Input.module.css'; export type InputSize = 'sm' | 'md' | 'lg'; export interface InputProps extends InputHTMLAttributes<HTMLInputElement> { /** Input size variant */ size?: InputSize; /** Error state */ error?: boolean; /** Error message */ errorMessage?: string; /** Label text */ label?: string; /** Helper text */ helperText?: string; /** Full width input */ fullWidth?: boolean; } /** * Tree-shakeable Input component with integrated label and error messaging */ export const Input = React.forwardRef<HTMLInputElement, InputProps>( ( { size = 'md', error = false, errorMessage, label, helperText, fullWidth = false, className, id, ...props }, ref, ) => { const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`; return ( <div className={classNames(styles.container, fullWidth && styles.fullWidth)}> {label && ( <label htmlFor={inputId} className={styles.label}> {label} </label> )} <input ref={ref} id={inputId} className={classNames( styles.input, styles[`size-${size}`], error && styles.error, className, )} {...props} /> {(errorMessage || helperText) && ( <span className={classNames( styles.message, error && styles.errorMessage, )}> {errorMessage || helperText} </span> )} </div> ); }, ); Input.displayName = 'Input';packages/react/src/components/Input/Input.module.css.container { display: inline-flex; flex-direction: column; gap: 0.5rem; } .fullWidth { width: 100%; } .label { font-size: 0.875rem; font-weight: 500; color: #374151; cursor: pointer; } .input { padding: clamp(0.375rem, 1.5vw, 0.5rem) clamp(0.75rem, 2vw, 1rem); border: 2px solid #d1d5db; border-radius: 0.375rem; font-size: 1rem; font-family: inherit; transition: all 0.2s ease-in-out; /* Remove default appearance */ appearance: none; background-color: white; } .input:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); } .input:disabled { background-color: #f3f4f6; color: #9ca3af; cursor: not-allowed; } /* Sizes */ .size-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; min-height: 2rem; } .size-md { padding: 0.5rem 1rem; font-size: 1rem; min-height: 2.5rem; } .size-lg { padding: 0.75rem 1.5rem; font-size: 1.125rem; min-height: 3rem; } /* Error state */ .input.error { border-color: #ef4444; } .input.error:focus { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1); } /* Message (error/helper text) */ .message { font-size: 0.75rem; color: #6b7280; } .message.errorMessage { color: #ef4444; font-weight: 500; } /* Placeholder */ .input::placeholder { color: #d1d5db; } /* Responsive */ @media (max-width: 640px) { .input { font-size: 16px; /* Prevent zoom on iOS */ } }packages/react/src/components/Grid/Grid.tsximport React, { HTMLAttributes } from 'react'; import { classNames, ResponsiveValue } from '@ui-kit/core'; import styles from './Grid.module.css'; export interface GridProps extends HTMLAttributes<HTMLDivElement> { /** Number of columns */ columns?: number | ResponsiveValue<number>; /** Gap between items */ gap?: number | ResponsiveValue<number>; /** Vertical alignment */ verticalAlign?: 'start' | 'center' | 'end' | 'stretch'; /** Horizontal alignment */ horizontalAlign?: 'start' | 'center' | 'end' | 'stretch'; } export interface GridItemProps extends HTMLAttributes<HTMLDivElement> { /** Span across columns */ colSpan?: number; /** Span down rows */ rowSpan?: number; } /** * Responsive Grid component with CSS variables for responsive values */ export const Grid = React.forwardRef<HTMLDivElement, GridProps>( ( { columns = 1, gap = 1, verticalAlign = 'start', horizontalAlign = 'start', children, className, style, ...props }, ref, ) => { // Build CSS variables for responsive columns const gridStyle: React.CSSProperties = { ...style, '--grid-cols': 1, '--grid-gap': `${gap}rem`, } as any; if (typeof columns === 'number') { gridStyle['--grid-cols'] = columns; } else { // Handle responsive columns gridStyle['--grid-cols'] = columns.base ?? 1; if (columns.sm) gridStyle['--grid-cols-sm'] = columns.sm; if (columns.md) gridStyle['--grid-cols-md'] = columns.md; if (columns.lg) gridStyle['--grid-cols-lg'] = columns.lg; } return ( <div ref={ref} className={classNames( styles.grid, styles[`v-align-${verticalAlign}`], styles[`h-align-${horizontalAlign}`], className, )} style={gridStyle} {...props} > {children} </div> ); }, ); Grid.displayName = 'Grid'; /** * Grid item component */ export const GridItem = React.forwardRef<HTMLDivElement, GridItemProps>( ({ colSpan, rowSpan, className, style, ...props }, ref) => { return ( <div ref={ref} className={classNames(styles.item, className)} style={{ ...style, gridColumn: colSpan ? `span ${colSpan}` : undefined, gridRow: rowSpan ? `span ${rowSpan}` : undefined, }} {...props} /> ); }, ); GridItem.displayName = 'GridItem';packages/react/src/components/Grid/Grid.module.css.grid { display: grid; grid-template-columns: repeat(var(--grid-cols, 1), minmax(0, 1fr)); gap: var(--grid-gap, 1rem); } /* Vertical alignment */ .v-align-start { align-items: start; } .v-align-center { align-items: center; } .v-align-end { align-items: end; } .v-align-stretch { align-items: stretch; } /* Horizontal alignment */ .h-align-start { justify-items: start; } .h-align-center { justify-items: center; } .h-align-end { justify-items: end; } .h-align-stretch { justify-items: stretch; } /* Grid item */ .item { min-width: 0; /* Prevent overflow */ } /* Responsive columns using CSS variables */ @media (min-width: 640px) { .grid { grid-template-columns: repeat(var(--grid-cols-sm, var(--grid-cols, 1)), minmax(0, 1fr)); } } @media (min-width: 768px) { .grid { grid-template-columns: repeat(var(--grid-cols-md, var(--grid-cols-sm, var(--grid-cols, 1))), minmax(0, 1fr)); } } @media (min-width: 1024px) { .grid { grid-template-columns: repeat(var(--grid-cols-lg, var(--grid-cols, 1)), minmax(0, 1fr)); } }packages/react/src/components/Grid/index.tsxexport { Grid, GridItem } from './Grid'; export type { GridProps, GridItemProps } from './Grid';packages/react/src/components/Button/index.tsx(Already shown)packages/react/src/components/Card/index.tsxexport { Card } from './Card'; export type { CardProps } from './Card';packages/react/src/components/Input/index.tsxexport { Input } from './Input'; export type { InputProps, InputSize } from './Input';packages/react/src/index.ts// Individual component exports (tree-shakeable) export * from './components/Button'; export * from './components/Card'; export * from './components/Input'; export * from './components/Grid';4. Verification and Testing
packages/react/src/index.d.ts// Type definitions with proper exports export type { ButtonProps, ButtonVariant, ButtonSize } from './components/Button'; export type { CardProps } from './components/Card'; export type { InputProps, InputSize } from './components/Input'; export type { GridProps, GridItemProps } from './components/Grid';5. Usage Examples
Basic Usage
// Only Button is bundled (tree-shakeable) import { Button } from '@ui-kit/react/button'; import styles from '@ui-kit/react/button/Button.module.css'; export default function App() { return ( <Button variant="primary" size="lg" onClick={() => console.log('clicked')}> Click me </Button> ); }Multiple Components
import { Button } from '@ui-kit/react/button'; import { Card } from '@ui-kit/react/card'; import { Input } from '@ui-kit/react/input'; import { Grid, GridItem } from '@ui-kit/react/grid'; import { useBreakpoint, media } from '@ui-kit/core'; export default function Dashboard() { const breakpoint = useBreakpoint(); return ( <div> <h1>Responsive Dashboard</h1> <Grid columns={breakpoint === 'sm' ? 1 : 2} gap={2} > <GridItem> <Card padded interactive> <h2>Welcome</h2> <p>This is a responsive card</p> </Card> </GridItem> <GridItem> <Card padded> <form> <Input label="Email" type="email" placeholder="your@email.com" fullWidth /> <Button fullWidth type="submit" style={{ marginTop: '1rem' }}> Submit </Button> </form> </Card> </GridItem> </Grid> </div> ); }6. Building and Distribution
Build Script Output
npm run build # Output structure: # dist/ # ├── index.js # ├── index.d.ts # ├── components/ # │ ├── Button/ # │ │ ├── index.js # │ │ ├── index.d.ts # │ │ └── Button.module.css # │ ├── Card/ # │ ├── Input/ # │ └── Grid/Verify Tree-shaking
# Install and check bundle size npm install -g webpack-cli # Create a test file with only Button import echo 'import { Button } from "@ui-kit/react/button"' > test.js # The final bundle should only include Button + core utilities npx webpack --mode production test.js -o dist/test.bundle.jsKey Features
Feature Implementation Tree-shaking sideEffects: falsein package.jsonResponsive CSS variables, useBreakpointhook, media queriesCSS Modules Individual .module.cssper componentType-safe Full TypeScript support with .d.tsfilesAccessibility Semantic HTML, ARIA attributes, focus management Performance ESM-only, no CJS bloat, proper code splitting Monorepo Turborepo with proper workspace linking This setup ensures optimal bundle sizes, excellent developer experience, and scalability!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.