|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Tiny Design is a React component UI library (80+ components) published as `@tiny-design/react`. It's a pnpm monorepo managed with Turborepo. |
| 6 | + |
| 7 | +## Monorepo Layout |
| 8 | + |
| 9 | +``` |
| 10 | +packages/react/ → @tiny-design/react (main component library) |
| 11 | +packages/tokens/ → @tiny-design/tokens (design tokens, SCSS variables) |
| 12 | +packages/icons/ → @tiny-design/icons (SVG icon components) |
| 13 | +apps/docs/ → documentation site (Vite + MDX) |
| 14 | +``` |
| 15 | + |
| 16 | +All three publishable packages use **fixed versioning** — they always share the same version number. |
| 17 | + |
| 18 | +## Common Commands |
| 19 | + |
| 20 | +```bash |
| 21 | +pnpm install # Install dependencies |
| 22 | +pnpm dev # Start docs dev server |
| 23 | +pnpm build # Build all packages (turborepo handles dependency order: tokens → react → docs) |
| 24 | +pnpm test # Run all tests |
| 25 | +pnpm lint # ESLint across all packages |
| 26 | +pnpm lint:style # Stylelint for SCSS files |
| 27 | +``` |
| 28 | + |
| 29 | +### Scoped Commands |
| 30 | + |
| 31 | +```bash |
| 32 | +pnpm --filter @tiny-design/react test -- --testPathPattern=button # Test a single component |
| 33 | +pnpm --filter @tiny-design/react test:update # Update snapshots |
| 34 | +pnpm --filter @tiny-design/react test:coverage # Coverage report |
| 35 | +``` |
| 36 | + |
| 37 | +## Component Structure |
| 38 | + |
| 39 | +Every component in `packages/react/src/` follows this layout: |
| 40 | + |
| 41 | +``` |
| 42 | +component-name/ |
| 43 | +├── component-name.tsx # Implementation (React.forwardRef, function components) |
| 44 | +├── types.ts # Props interfaces |
| 45 | +├── index.tsx # Barrel export |
| 46 | +├── index.md # English docs |
| 47 | +├── index.zh_CN.md # Chinese docs |
| 48 | +├── style/ |
| 49 | +│ ├── _index.scss # Styles (SCSS partial) |
| 50 | +│ └── index.tsx # Style entry point |
| 51 | +├── demo/ |
| 52 | +│ └── basic.tsx # Usage examples |
| 53 | +└── __tests__/ |
| 54 | + └── component-name.test.tsx |
| 55 | +``` |
| 56 | + |
| 57 | +When adding a new component: |
| 58 | +1. Create its directory under `packages/react/src/` |
| 59 | +2. Export it from `packages/react/src/index.ts` |
| 60 | +3. Add a route in `apps/docs/src/routers.tsx` |
| 61 | + |
| 62 | +## Code Conventions |
| 63 | + |
| 64 | +- **TypeScript strict mode** is enabled |
| 65 | +- **CSS class prefix**: `ty-` (e.g., `.ty-btn`, `.ty-modal`), customizable via `ConfigProvider` |
| 66 | +- **BEM-ish naming**: `ty-component`, `ty-component__element`, `ty-component_modifier` |
| 67 | +- **Ref forwarding**: all components use `React.forwardRef` |
| 68 | +- **Props pattern**: extend `BaseProps` (style, className, prefixCls) + intrinsic element props |
| 69 | +- **Formatting**: Prettier — single quotes, semicolons, 100 char width, 2-space indent |
| 70 | +- **Commits**: Conventional Commits — `feat(button): add loading state`, `fix(modal): prevent scroll` |
| 71 | +- **Pre-commit hook**: husky + lint-staged auto-fixes SCSS via stylelint |
| 72 | + |
| 73 | +## Testing |
| 74 | + |
| 75 | +- **Framework**: Jest + @testing-library/react + @testing-library/jest-dom |
| 76 | +- **Config**: `packages/react/jest.config.js` (ts-jest, jsdom environment) |
| 77 | +- Tests live in `__tests__/` within each component directory |
| 78 | + |
| 79 | +## Build Pipeline |
| 80 | + |
| 81 | +The react package build (`packages/react`): |
| 82 | +1. `tsdown` — transpiles TS → JS (ESM in `es/`, CJS in `lib/`), generates `.d.ts` |
| 83 | +2. `build-styles.js` — compiles component SCSS → CSS via Sass + PostCSS |
| 84 | +3. `inject-style-imports.js` — adds CSS imports into JS entry files |
| 85 | + |
| 86 | +## Changesets & Releases |
| 87 | + |
| 88 | +- Use `pnpm changeset` to create a changeset file in `.changeset/` |
| 89 | +- On merge to `master`, CI creates a "Version Packages" PR |
| 90 | +- Merging that PR publishes to npm and deploys the docs site |
| 91 | +- `@tiny-design/docs` is excluded from npm publishing |
| 92 | + |
| 93 | +## Key Dependencies |
| 94 | + |
| 95 | +- React 18.2+, TypeScript 5.4 |
| 96 | +- Popper.js (`@popperjs/core`) for positioning (tooltips, dropdowns, popovers) |
| 97 | +- `react-transition-group` for animations |
| 98 | +- `classnames` for conditional class construction |
| 99 | +- Node.js >= 22, pnpm 10.x |
0 commit comments