|
| 1 | +# Mantine DataTable - Copilot Instructions |
| 2 | + |
| 3 | +This is a dual-purpose repository containing both the **Mantine DataTable** component package and its documentation website. Understanding this hybrid architecture is crucial for effective development. |
| 4 | + |
| 5 | +## Project Architecture |
| 6 | + |
| 7 | +### Dual Repository Structure |
| 8 | +- **Package code**: `package/` - The actual DataTable component exported to npm |
| 9 | +- **Documentation site**: `app/`, `components/` - Next.js app with examples and docs |
| 10 | +- **Build outputs**: Package builds to `dist/`, docs build for GitHub Pages deployment |
| 11 | + |
| 12 | +### Package Development Flow |
| 13 | +```bash |
| 14 | +# Core development commands (use pnpm, not yarn despite legacy docs) |
| 15 | +pnpm dev # Start Next.js dev server for docs/examples |
| 16 | +pnpm build:package # Build package only (tsup + postcss) |
| 17 | +pnpm build:docs # Build documentation site |
| 18 | +pnpm build # Build both package and docs |
| 19 | +pnpm lint # ESLint + TypeScript checks |
| 20 | +``` |
| 21 | + |
| 22 | +### Component Architecture Pattern |
| 23 | +The DataTable follows a **composition-based architecture** with specialized sub-components: |
| 24 | + |
| 25 | +```typescript |
| 26 | +// Main component in package/DataTable.tsx |
| 27 | +DataTable -> { |
| 28 | + DataTableHeader, |
| 29 | + DataTableRow[], |
| 30 | + DataTableFooter, |
| 31 | + DataTablePagination, |
| 32 | + DataTableLoader, |
| 33 | + DataTableEmptyState |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +Each sub-component has its own `.tsx`, `.css`, and sometimes `.module.css` files. Always maintain this parallel structure when adding features. |
| 38 | + |
| 39 | +## Development Conventions |
| 40 | + |
| 41 | +### Import Alias Pattern |
| 42 | +Examples use `import { DataTable } from '__PACKAGE__'` - this resolves to the local package during development. Never import from `mantine-datatable` in examples. |
| 43 | + |
| 44 | +### TypeScript Patterns |
| 45 | +- **Generic constraints**: `DataTable<T>` where T extends record type |
| 46 | +- **Prop composition**: Props inherit from base Mantine components (TableProps, etc.) |
| 47 | +- **Accessor pattern**: Use `idAccessor` prop for custom ID fields, defaults to `'id'` |
| 48 | + |
| 49 | +### CSS Architecture |
| 50 | +- **Layered imports**: `styles.css` imports all component styles |
| 51 | +- **CSS layers**: `@layer mantine, mantine-datatable` for proper specificity |
| 52 | +- **Utility classes**: Defined in `utilityClasses.css` for common patterns |
| 53 | +- **CSS variables**: Dynamic values injected via `cssVariables.ts` |
| 54 | + |
| 55 | +### Hook Patterns |
| 56 | +Custom hooks follow the pattern `useDataTable*` and are located in `package/hooks/`: |
| 57 | +- `useDataTableColumns` - Column management and persistence |
| 58 | +- `useRowExpansion` - Row expansion state |
| 59 | +- `useLastSelectionChangeIndex` - Selection behavior |
| 60 | + |
| 61 | +## Documentation Development |
| 62 | + |
| 63 | +### Example Structure |
| 64 | +Each example in `app/examples/` follows this pattern: |
| 65 | +``` |
| 66 | +feature-name/ |
| 67 | +├── page.tsx # Next.js page with controls |
| 68 | +├── FeatureExample.tsx # Actual DataTable implementation |
| 69 | +└── FeaturePageContent.tsx # Documentation content |
| 70 | +``` |
| 71 | + |
| 72 | +### Code Block Convention |
| 73 | +Use the `CodeBlock` component for syntax highlighting. Example files should be minimal and focused on demonstrating a single feature clearly. |
| 74 | + |
| 75 | +## Data Patterns |
| 76 | + |
| 77 | +### Record Structure |
| 78 | +Examples use consistent data shapes: |
| 79 | +- `companies.json` - Basic company data with id, name, address |
| 80 | +- `employees.json` - Employee data with departments/relationships |
| 81 | +- `async.ts` - Simulated API calls with delay/error simulation |
| 82 | + |
| 83 | +### Selection Patterns |
| 84 | +- **Gmail-style additive selection**: Shift+click for range selection |
| 85 | +- **Trigger modes**: `'checkbox'` | `'row'` | `'cell'` |
| 86 | +- **Custom selection logic**: Use `isRecordSelectable` for conditional selection |
| 87 | + |
| 88 | +## Build System |
| 89 | + |
| 90 | +### Package Build (tsup) |
| 91 | +- **ESM**: `tsup.esm.ts` - Modern module format |
| 92 | +- **CJS**: `tsup.cjs.ts` - CommonJS compatibility |
| 93 | +- **Types**: `tsup.dts.ts` - TypeScript declarations |
| 94 | +- **CSS**: PostCSS processes styles to `dist/` |
| 95 | + |
| 96 | +### Documentation Deployment |
| 97 | +- **GitHub Pages**: `output: 'export'` in `next.config.js` |
| 98 | +- **Base path**: `/mantine-datatable` when `GITHUB_PAGES=true` |
| 99 | +- **Environment injection**: Package version, NPM downloads via build-time fetch |
| 100 | + |
| 101 | +## Common Patterns |
| 102 | + |
| 103 | +### Adding New Features |
| 104 | +1. Create component in `package/` with `.tsx` and `.css` files |
| 105 | +2. Add to main `DataTable.tsx` component composition |
| 106 | +3. Export new types from `package/types/index.ts` |
| 107 | +4. Create example in `app/examples/new-feature/` |
| 108 | +5. Update main navigation in `app/config.ts` |
| 109 | + |
| 110 | +### Styling New Components |
| 111 | +- Use CSS custom properties for theming |
| 112 | +- Follow existing naming: `.mantine-datatable-component-name` |
| 113 | +- Import CSS in `package/styles.css` |
| 114 | +- Add utility classes to `utilityClasses.css` if reusable |
| 115 | + |
| 116 | +### TypeScript Integration |
| 117 | +- Extend base Mantine props where possible |
| 118 | +- Use composition over inheritance for prop types |
| 119 | +- Export all public types from `package/types/index.ts` |
| 120 | +- Maintain strict null checks and proper generics |
| 121 | + |
| 122 | +## Performance Considerations |
| 123 | + |
| 124 | +- **Virtualization**: Not implemented - DataTable handles reasonable record counts (< 1000s) |
| 125 | +- **Memoization**: Use `useMemo` for expensive column calculations |
| 126 | +- **CSS-in-JS**: Avoided in favor of CSS modules for better performance |
| 127 | +- **Bundle size**: Keep dependencies minimal (only Mantine + React) |
0 commit comments