You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Rules that apply to all packages in the monorepo
8
+
globs: **/*.{ts,tsx,js,jsx}
9
+
---
10
+
# Component Library Generation Context
11
+
12
+
When generating React component libraries similar to Clerk Elements, follow these principles and patterns to maintain a consistent and developer-friendly experience.
13
+
14
+
## Core Principles
15
+
16
+
1. **Compound Components Pattern**
17
+
- Components should be namespaced under a single parent (e.g., `FormWizard.Root`, `FormWizard.Step`)
18
+
- State should be managed through React Context
19
+
- Components must be composable and work together seamlessly
20
+
- Components should handle their own state management and validation
21
+
22
+
2. **Type Safety**
23
+
- Always implement full TypeScript support
24
+
- Use proper type definitions for all props and refs
25
+
- Implement proper generic constraints where necessary
26
+
- Export type definitions for public API
27
+
- Avoid TypeScript enums due to their runtime overhead and tree-shaking limitations; use const objects or 'as const' assertions instead:
28
+
```typescript
29
+
// Instead of enum:
30
+
enum Status { Active, Inactive }
31
+
// Prefer:
32
+
const Status = {
33
+
Active: 'active',
34
+
Inactive: 'inactive'
35
+
} as const;
36
+
37
+
// Or:
38
+
const Status = Object.freeze({
39
+
Active: 'active',
40
+
Inactive: 'inactive'
41
+
});
42
+
```
43
+
44
+
3. **Accessibility**
45
+
- Support keyboard navigation
46
+
- Include proper ARIA attributes
47
+
- Support screen readers through semantic markup
48
+
- Maintain focus management
49
+
50
+
4. **Component Structure**
51
+
52
+
Each component should follow this pattern:
53
+
```typescript
54
+
import { forwardRef, type ComponentRef, HTMLAttributes, ReactNode } from 'react';
55
+
56
+
type ComponentElement = ComponentRef<'element_type'>;
0 commit comments