@patricio0312rev/skillset 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +176 -0
- package/bin/cli.js +37 -0
- package/package.json +55 -0
- package/src/commands/init.js +301 -0
- package/src/index.js +168 -0
- package/src/lib/config.js +200 -0
- package/src/lib/generator.js +166 -0
- package/src/utils/display.js +95 -0
- package/src/utils/readme.js +196 -0
- package/src/utils/tool-specific.js +233 -0
- package/templates/ai-engineering/agent-orchestration-planner/ SKILL.md +266 -0
- package/templates/ai-engineering/cost-latency-optimizer/ SKILL.md +270 -0
- package/templates/ai-engineering/doc-to-vector-dataset-generator/ SKILL.md +239 -0
- package/templates/ai-engineering/evaluation-harness/ SKILL.md +219 -0
- package/templates/ai-engineering/guardrails-safety-filter-builder/ SKILL.md +226 -0
- package/templates/ai-engineering/llm-debugger/ SKILL.md +283 -0
- package/templates/ai-engineering/prompt-regression-tester/ SKILL.md +216 -0
- package/templates/ai-engineering/prompt-template-builder/ SKILL.md +393 -0
- package/templates/ai-engineering/rag-pipeline-builder/ SKILL.md +244 -0
- package/templates/ai-engineering/tool-function-schema-designer/ SKILL.md +219 -0
- package/templates/architecture/adr-writer/ SKILL.md +250 -0
- package/templates/architecture/api-versioning-deprecation-planner/ SKILL.md +331 -0
- package/templates/architecture/domain-model-boundaries-mapper/ SKILL.md +300 -0
- package/templates/architecture/migration-planner/ SKILL.md +376 -0
- package/templates/architecture/performance-budget-setter/ SKILL.md +318 -0
- package/templates/architecture/reliability-strategy-builder/ SKILL.md +286 -0
- package/templates/architecture/rfc-generator/ SKILL.md +362 -0
- package/templates/architecture/scalability-playbook/ SKILL.md +279 -0
- package/templates/architecture/system-design-generator/ SKILL.md +339 -0
- package/templates/architecture/tech-debt-prioritizer/ SKILL.md +329 -0
- package/templates/backend/api-contract-normalizer/ SKILL.md +487 -0
- package/templates/backend/api-endpoint-generator/ SKILL.md +415 -0
- package/templates/backend/auth-module-builder/ SKILL.md +99 -0
- package/templates/backend/background-jobs-designer/ SKILL.md +166 -0
- package/templates/backend/caching-strategist/ SKILL.md +190 -0
- package/templates/backend/error-handling-standardizer/ SKILL.md +174 -0
- package/templates/backend/rate-limiting-abuse-protection/ SKILL.md +147 -0
- package/templates/backend/rbac-permissions-builder/ SKILL.md +158 -0
- package/templates/backend/service-layer-extractor/ SKILL.md +269 -0
- package/templates/backend/webhook-receiver-hardener/ SKILL.md +211 -0
- package/templates/ci-cd/artifact-sbom-publisher/ SKILL.md +236 -0
- package/templates/ci-cd/caching-strategy-optimizer/ SKILL.md +195 -0
- package/templates/ci-cd/deployment-checklist-generator/ SKILL.md +381 -0
- package/templates/ci-cd/github-actions-pipeline-creator/ SKILL.md +348 -0
- package/templates/ci-cd/monorepo-ci-optimizer/ SKILL.md +298 -0
- package/templates/ci-cd/preview-environments-builder/ SKILL.md +187 -0
- package/templates/ci-cd/quality-gates-enforcer/ SKILL.md +342 -0
- package/templates/ci-cd/release-automation-builder/ SKILL.md +281 -0
- package/templates/ci-cd/rollback-workflow-builder/ SKILL.md +372 -0
- package/templates/ci-cd/secrets-env-manager/ SKILL.md +242 -0
- package/templates/db-management/backup-restore-runbook-generator/ SKILL.md +505 -0
- package/templates/db-management/data-integrity-auditor/ SKILL.md +505 -0
- package/templates/db-management/data-retention-archiving-planner/ SKILL.md +430 -0
- package/templates/db-management/data-seeding-fixtures-builder/ SKILL.md +375 -0
- package/templates/db-management/db-performance-watchlist/ SKILL.md +425 -0
- package/templates/db-management/etl-sync-job-builder/ SKILL.md +457 -0
- package/templates/db-management/multi-tenant-safety-checker/ SKILL.md +398 -0
- package/templates/db-management/prisma-migration-assistant/ SKILL.md +379 -0
- package/templates/db-management/schema-consistency-checker/ SKILL.md +440 -0
- package/templates/db-management/sql-query-optimizer/ SKILL.md +324 -0
- package/templates/foundation/changelog-writer/ SKILL.md +431 -0
- package/templates/foundation/code-formatter-installer/ SKILL.md +320 -0
- package/templates/foundation/codebase-summarizer/ SKILL.md +360 -0
- package/templates/foundation/dependency-doctor/ SKILL.md +163 -0
- package/templates/foundation/dev-environment-bootstrapper/ SKILL.md +259 -0
- package/templates/foundation/dev-onboarding-builder/ SKILL.md +556 -0
- package/templates/foundation/docs-starter-kit/ SKILL.md +574 -0
- package/templates/foundation/explaining-code/SKILL.md +13 -0
- package/templates/foundation/git-hygiene-enforcer/ SKILL.md +455 -0
- package/templates/foundation/project-scaffolder/ SKILL.md +65 -0
- package/templates/foundation/project-scaffolder/references/templates.md +126 -0
- package/templates/foundation/repo-structure-linter/ SKILL.md +0 -0
- package/templates/foundation/repo-structure-linter/references/conventions.md +98 -0
- package/templates/frontend/animation-micro-interaction-pack/ SKILL.md +41 -0
- package/templates/frontend/component-scaffold-generator/ SKILL.md +562 -0
- package/templates/frontend/design-to-component-translator/ SKILL.md +547 -0
- package/templates/frontend/form-wizard-builder/ SKILL.md +553 -0
- package/templates/frontend/frontend-refactor-planner/ SKILL.md +37 -0
- package/templates/frontend/i18n-frontend-implementer/ SKILL.md +44 -0
- package/templates/frontend/modal-drawer-system/ SKILL.md +377 -0
- package/templates/frontend/page-layout-builder/ SKILL.md +630 -0
- package/templates/frontend/state-ux-flow-builder/ SKILL.md +23 -0
- package/templates/frontend/table-builder/ SKILL.md +350 -0
- package/templates/performance/alerting-dashboard-builder/ SKILL.md +162 -0
- package/templates/performance/backend-latency-profiler-helper/ SKILL.md +108 -0
- package/templates/performance/caching-cdn-strategy-planner/ SKILL.md +150 -0
- package/templates/performance/capacity-planning-helper/ SKILL.md +242 -0
- package/templates/performance/core-web-vitals-tuner/ SKILL.md +126 -0
- package/templates/performance/incident-runbook-generator/ SKILL.md +162 -0
- package/templates/performance/load-test-scenario-builder/ SKILL.md +256 -0
- package/templates/performance/observability-setup/ SKILL.md +232 -0
- package/templates/performance/postmortem-writer/ SKILL.md +203 -0
- package/templates/performance/structured-logging-standardizer/ SKILL.md +122 -0
- package/templates/security/auth-security-reviewer/ SKILL.md +428 -0
- package/templates/security/dependency-vulnerability-triage/ SKILL.md +495 -0
- package/templates/security/input-validation-sanitization-auditor/ SKILL.md +76 -0
- package/templates/security/pii-redaction-logging-policy-builder/ SKILL.md +65 -0
- package/templates/security/rbac-policy-tester/ SKILL.md +80 -0
- package/templates/security/secrets-scanner/ SKILL.md +462 -0
- package/templates/security/secure-headers-csp-builder/ SKILL.md +404 -0
- package/templates/security/security-incident-playbook-generator/ SKILL.md +76 -0
- package/templates/security/security-pr-checklist-skill/ SKILL.md +62 -0
- package/templates/security/threat-model-generator/ SKILL.md +394 -0
- package/templates/testing/contract-testing-builder/ SKILL.md +492 -0
- package/templates/testing/coverage-strategist/ SKILL.md +436 -0
- package/templates/testing/e2e-test-builder/ SKILL.md +382 -0
- package/templates/testing/flaky-test-detective/ SKILL.md +416 -0
- package/templates/testing/integration-test-builder/ SKILL.md +525 -0
- package/templates/testing/mocking-assistant/ SKILL.md +383 -0
- package/templates/testing/snapshot-test-refactorer/ SKILL.md +375 -0
- package/templates/testing/test-data-factory-builder/ SKILL.md +449 -0
- package/templates/testing/test-reporting-triage-skill/ SKILL.md +469 -0
- package/templates/testing/unit-test-generator/ SKILL.md +548 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Repository Structure Conventions
|
|
2
|
+
|
|
3
|
+
## Next.js App Router
|
|
4
|
+
|
|
5
|
+
**Required Structure:**
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
src/
|
|
9
|
+
├── app/ # Routes and pages
|
|
10
|
+
├── components/ # React components
|
|
11
|
+
├── lib/ # Utility functions
|
|
12
|
+
├── types/ # TypeScript types
|
|
13
|
+
└── hooks/ # Custom React hooks
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Naming:**
|
|
17
|
+
|
|
18
|
+
- Components: PascalCase (Button.tsx)
|
|
19
|
+
- Utilities: camelCase (formatDate.ts)
|
|
20
|
+
- Types: PascalCase (User.ts)
|
|
21
|
+
- Pages: lowercase (page.tsx, layout.tsx)
|
|
22
|
+
|
|
23
|
+
**Anti-patterns:**
|
|
24
|
+
|
|
25
|
+
- Business logic in app/ directory
|
|
26
|
+
- Helper functions outside lib/
|
|
27
|
+
- Mixed component and utility files
|
|
28
|
+
|
|
29
|
+
## NestJS
|
|
30
|
+
|
|
31
|
+
**Required Structure:**
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
├── main.ts
|
|
36
|
+
├── app.module.ts
|
|
37
|
+
├── common/ # Shared utilities
|
|
38
|
+
├── config/ # Configuration
|
|
39
|
+
└── modules/ # Feature modules
|
|
40
|
+
└── users/
|
|
41
|
+
├── users.module.ts
|
|
42
|
+
├── users.controller.ts
|
|
43
|
+
├── users.service.ts
|
|
44
|
+
├── dto/
|
|
45
|
+
└── entities/
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Naming:**
|
|
49
|
+
|
|
50
|
+
- Controllers: kebab-case.controller.ts
|
|
51
|
+
- Services: kebab-case.service.ts
|
|
52
|
+
- Modules: kebab-case.module.ts
|
|
53
|
+
- DTOs: kebab-case.dto.ts
|
|
54
|
+
|
|
55
|
+
## Python Package
|
|
56
|
+
|
|
57
|
+
**Required Structure:**
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
project_name/
|
|
61
|
+
├── __init__.py
|
|
62
|
+
├── main.py
|
|
63
|
+
├── models/
|
|
64
|
+
├── services/
|
|
65
|
+
├── utils/
|
|
66
|
+
└── tests/
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Naming:**
|
|
70
|
+
|
|
71
|
+
- Packages: snake_case
|
|
72
|
+
- Modules: snake_case.py
|
|
73
|
+
- Classes: PascalCase
|
|
74
|
+
- Functions: snake_case
|
|
75
|
+
|
|
76
|
+
## React Component Library
|
|
77
|
+
|
|
78
|
+
**Required Structure:**
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
src/
|
|
82
|
+
├── components/
|
|
83
|
+
│ └── Button/
|
|
84
|
+
│ ├── Button.tsx
|
|
85
|
+
│ ├── Button.test.tsx
|
|
86
|
+
│ ├── Button.stories.tsx
|
|
87
|
+
│ └── index.ts
|
|
88
|
+
├── hooks/
|
|
89
|
+
├── utils/
|
|
90
|
+
└── types/
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Naming:**
|
|
94
|
+
|
|
95
|
+
- Components: PascalCase directory and file
|
|
96
|
+
- Hooks: camelCase starting with 'use'
|
|
97
|
+
- Test files: \*.test.tsx
|
|
98
|
+
- Story files: \*.stories.tsx
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: animation-micro-interaction-pack
|
|
3
|
+
description: Provides reusable interaction patterns and motion presets that make UI feel polished. Includes hover effects, transitions, entrance animations, gesture feedback, and reduced-motion support. Use when adding "animations", "transitions", "micro-interactions", or "motion design".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Animation & Micro-interaction Pack
|
|
7
|
+
|
|
8
|
+
Create polished, performant animations and micro-interactions.
|
|
9
|
+
|
|
10
|
+
## Animation Patterns
|
|
11
|
+
|
|
12
|
+
**Hover Effects**: Scale, lift (translateY), glow (box-shadow), color shifts
|
|
13
|
+
**Entrance**: Fade-in, slide-in, zoom-in with stagger for lists
|
|
14
|
+
**Exit**: Fade-out, slide-out, scale-out
|
|
15
|
+
**Loading**: Pulse, skeleton waves, progress bars
|
|
16
|
+
**Gestures**: Ripple on click, drag feedback, swipe indicators
|
|
17
|
+
|
|
18
|
+
## Tailwind Animations
|
|
19
|
+
|
|
20
|
+
```css
|
|
21
|
+
/* tailwind.config.js */
|
|
22
|
+
animation: {
|
|
23
|
+
'fade-in': 'fadeIn 0.5s ease-out',
|
|
24
|
+
'slide-up': 'slideUp 0.3s ease-out',
|
|
25
|
+
'scale-in': 'scaleIn 0.2s ease-out',
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Framer Motion Examples
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
<motion.div
|
|
33
|
+
initial={{ opacity: 0, y: 20 }}
|
|
34
|
+
animate={{ opacity: 1, y: 0 }}
|
|
35
|
+
transition={{ duration: 0.3 }}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Best Practices
|
|
40
|
+
|
|
41
|
+
Use 200-300ms for micro-interactions, respect prefers-reduced-motion, animate transform/opacity for performance, add easing functions, stagger list items, provide hover/active states.
|
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: component-scaffold-generator
|
|
3
|
+
description: Generates clean React/Vue component skeletons with TypeScript types, prop variants, styling hooks, test files, Storybook stories, and usage documentation. Use when users request "create a component", "scaffold component", "new React component", or "generate component boilerplate".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Component Scaffold Generator
|
|
7
|
+
|
|
8
|
+
Generate production-ready component skeletons with types, variants, tests, and documentation.
|
|
9
|
+
|
|
10
|
+
## Core Workflow
|
|
11
|
+
|
|
12
|
+
1. **Gather requirements**: Component name, framework (React/Vue), props needed
|
|
13
|
+
2. **Choose pattern**: Determine if functional, compound, or polymorphic component
|
|
14
|
+
3. **Generate component**: Create main component file with TypeScript types
|
|
15
|
+
4. **Add variants**: Include common variants (size, color, state)
|
|
16
|
+
5. **Setup styling**: Add styling approach (Tailwind, CSS Modules, styled-components)
|
|
17
|
+
6. **Create tests**: Generate test file with basic coverage
|
|
18
|
+
7. **Add story**: Create Storybook story with examples
|
|
19
|
+
8. **Document usage**: Include JSDoc and usage examples
|
|
20
|
+
|
|
21
|
+
## Component Patterns
|
|
22
|
+
|
|
23
|
+
### Basic Functional Component (React)
|
|
24
|
+
|
|
25
|
+
````typescript
|
|
26
|
+
// Button.tsx
|
|
27
|
+
import { forwardRef } from "react";
|
|
28
|
+
import { cn } from "@/lib/utils";
|
|
29
|
+
|
|
30
|
+
export interface ButtonProps
|
|
31
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
32
|
+
variant?: "primary" | "secondary" | "ghost" | "destructive";
|
|
33
|
+
size?: "sm" | "md" | "lg";
|
|
34
|
+
isLoading?: boolean;
|
|
35
|
+
leftIcon?: React.ReactNode;
|
|
36
|
+
rightIcon?: React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Button component with multiple variants and sizes
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <Button variant="primary" size="md">
|
|
45
|
+
* Click me
|
|
46
|
+
* </Button>
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
50
|
+
(
|
|
51
|
+
{
|
|
52
|
+
variant = "primary",
|
|
53
|
+
size = "md",
|
|
54
|
+
isLoading = false,
|
|
55
|
+
leftIcon,
|
|
56
|
+
rightIcon,
|
|
57
|
+
className,
|
|
58
|
+
children,
|
|
59
|
+
disabled,
|
|
60
|
+
...props
|
|
61
|
+
},
|
|
62
|
+
ref
|
|
63
|
+
) => {
|
|
64
|
+
return (
|
|
65
|
+
<button
|
|
66
|
+
ref={ref}
|
|
67
|
+
className={cn(
|
|
68
|
+
"inline-flex items-center justify-center rounded-md font-medium transition-colors",
|
|
69
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
|
|
70
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
71
|
+
{
|
|
72
|
+
// Variants
|
|
73
|
+
"bg-blue-600 text-white hover:bg-blue-700": variant === "primary",
|
|
74
|
+
"bg-gray-200 text-gray-900 hover:bg-gray-300":
|
|
75
|
+
variant === "secondary",
|
|
76
|
+
"hover:bg-gray-100": variant === "ghost",
|
|
77
|
+
"bg-red-600 text-white hover:bg-red-700": variant === "destructive",
|
|
78
|
+
// Sizes
|
|
79
|
+
"h-8 px-3 text-sm": size === "sm",
|
|
80
|
+
"h-10 px-4 text-base": size === "md",
|
|
81
|
+
"h-12 px-6 text-lg": size === "lg",
|
|
82
|
+
},
|
|
83
|
+
className
|
|
84
|
+
)}
|
|
85
|
+
disabled={disabled || isLoading}
|
|
86
|
+
{...props}
|
|
87
|
+
>
|
|
88
|
+
{isLoading && (
|
|
89
|
+
<svg
|
|
90
|
+
className="mr-2 h-4 w-4 animate-spin"
|
|
91
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
92
|
+
fill="none"
|
|
93
|
+
viewBox="0 0 24 24"
|
|
94
|
+
>
|
|
95
|
+
<circle
|
|
96
|
+
className="opacity-25"
|
|
97
|
+
cx="12"
|
|
98
|
+
cy="12"
|
|
99
|
+
r="10"
|
|
100
|
+
stroke="currentColor"
|
|
101
|
+
strokeWidth="4"
|
|
102
|
+
/>
|
|
103
|
+
<path
|
|
104
|
+
className="opacity-75"
|
|
105
|
+
fill="currentColor"
|
|
106
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
107
|
+
/>
|
|
108
|
+
</svg>
|
|
109
|
+
)}
|
|
110
|
+
{leftIcon && <span className="mr-2">{leftIcon}</span>}
|
|
111
|
+
{children}
|
|
112
|
+
{rightIcon && <span className="ml-2">{rightIcon}</span>}
|
|
113
|
+
</button>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
Button.displayName = "Button";
|
|
119
|
+
````
|
|
120
|
+
|
|
121
|
+
### Compound Component Pattern
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Card.tsx
|
|
125
|
+
import { createContext, useContext } from "react";
|
|
126
|
+
|
|
127
|
+
interface CardContextValue {
|
|
128
|
+
variant: "default" | "outlined" | "elevated";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const CardContext = createContext<CardContextValue | undefined>(undefined);
|
|
132
|
+
|
|
133
|
+
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
134
|
+
variant?: "default" | "outlined" | "elevated";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const Card = ({
|
|
138
|
+
variant = "default",
|
|
139
|
+
className,
|
|
140
|
+
children,
|
|
141
|
+
...props
|
|
142
|
+
}: CardProps) => {
|
|
143
|
+
return (
|
|
144
|
+
<CardContext.Provider value={{ variant }}>
|
|
145
|
+
<div className={cn("rounded-lg", className)} {...props}>
|
|
146
|
+
{children}
|
|
147
|
+
</div>
|
|
148
|
+
</CardContext.Provider>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const CardHeader = ({
|
|
153
|
+
className,
|
|
154
|
+
...props
|
|
155
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
156
|
+
<div className={cn("p-6", className)} {...props} />
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
export const CardTitle = ({
|
|
160
|
+
className,
|
|
161
|
+
...props
|
|
162
|
+
}: React.HTMLAttributes<HTMLHeadingElement>) => (
|
|
163
|
+
<h3 className={cn("text-2xl font-semibold", className)} {...props} />
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
export const CardContent = ({
|
|
167
|
+
className,
|
|
168
|
+
...props
|
|
169
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
170
|
+
<div className={cn("p-6 pt-0", className)} {...props} />
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
export const CardFooter = ({
|
|
174
|
+
className,
|
|
175
|
+
...props
|
|
176
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
177
|
+
<div className={cn("flex items-center p-6 pt-0", className)} {...props} />
|
|
178
|
+
);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Test File Template
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Button.test.tsx
|
|
185
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
186
|
+
import { Button } from "./Button";
|
|
187
|
+
|
|
188
|
+
describe("Button", () => {
|
|
189
|
+
it("renders children correctly", () => {
|
|
190
|
+
render(<Button>Click me</Button>);
|
|
191
|
+
expect(
|
|
192
|
+
screen.getByRole("button", { name: /click me/i })
|
|
193
|
+
).toBeInTheDocument();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("applies variant classes correctly", () => {
|
|
197
|
+
const { rerender } = render(<Button variant="primary">Test</Button>);
|
|
198
|
+
expect(screen.getByRole("button")).toHaveClass("bg-blue-600");
|
|
199
|
+
|
|
200
|
+
rerender(<Button variant="secondary">Test</Button>);
|
|
201
|
+
expect(screen.getByRole("button")).toHaveClass("bg-gray-200");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("handles click events", () => {
|
|
205
|
+
const handleClick = jest.fn();
|
|
206
|
+
render(<Button onClick={handleClick}>Click</Button>);
|
|
207
|
+
|
|
208
|
+
fireEvent.click(screen.getByRole("button"));
|
|
209
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("shows loading state", () => {
|
|
213
|
+
render(<Button isLoading>Loading</Button>);
|
|
214
|
+
expect(screen.getByRole("button")).toBeDisabled();
|
|
215
|
+
expect(screen.getByRole("button")).toContainHTML("svg");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("renders with icons", () => {
|
|
219
|
+
render(
|
|
220
|
+
<Button leftIcon={<span data-testid="left">←</span>}>With Icon</Button>
|
|
221
|
+
);
|
|
222
|
+
expect(screen.getByTestId("left")).toBeInTheDocument();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("forwards ref correctly", () => {
|
|
226
|
+
const ref = React.createRef<HTMLButtonElement>();
|
|
227
|
+
render(<Button ref={ref}>Test</Button>);
|
|
228
|
+
expect(ref.current).toBeInstanceOf(HTMLButtonElement);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Storybook Story Template
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
// Button.stories.tsx
|
|
237
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
238
|
+
import { Button } from "./Button";
|
|
239
|
+
|
|
240
|
+
const meta: Meta<typeof Button> = {
|
|
241
|
+
title: "Components/Button",
|
|
242
|
+
component: Button,
|
|
243
|
+
tags: ["autodocs"],
|
|
244
|
+
argTypes: {
|
|
245
|
+
variant: {
|
|
246
|
+
control: "select",
|
|
247
|
+
options: ["primary", "secondary", "ghost", "destructive"],
|
|
248
|
+
},
|
|
249
|
+
size: {
|
|
250
|
+
control: "select",
|
|
251
|
+
options: ["sm", "md", "lg"],
|
|
252
|
+
},
|
|
253
|
+
isLoading: {
|
|
254
|
+
control: "boolean",
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export default meta;
|
|
260
|
+
type Story = StoryObj<typeof Button>;
|
|
261
|
+
|
|
262
|
+
export const Primary: Story = {
|
|
263
|
+
args: {
|
|
264
|
+
variant: "primary",
|
|
265
|
+
children: "Button",
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
export const Secondary: Story = {
|
|
270
|
+
args: {
|
|
271
|
+
variant: "secondary",
|
|
272
|
+
children: "Button",
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export const WithIcons: Story = {
|
|
277
|
+
args: {
|
|
278
|
+
children: "With Icons",
|
|
279
|
+
leftIcon: "←",
|
|
280
|
+
rightIcon: "→",
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export const Loading: Story = {
|
|
285
|
+
args: {
|
|
286
|
+
children: "Loading",
|
|
287
|
+
isLoading: true,
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export const Sizes: Story = {
|
|
292
|
+
render: () => (
|
|
293
|
+
<div className="flex gap-4 items-center">
|
|
294
|
+
<Button size="sm">Small</Button>
|
|
295
|
+
<Button size="md">Medium</Button>
|
|
296
|
+
<Button size="lg">Large</Button>
|
|
297
|
+
</div>
|
|
298
|
+
),
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export const Variants: Story = {
|
|
302
|
+
render: () => (
|
|
303
|
+
<div className="flex gap-4">
|
|
304
|
+
<Button variant="primary">Primary</Button>
|
|
305
|
+
<Button variant="secondary">Secondary</Button>
|
|
306
|
+
<Button variant="ghost">Ghost</Button>
|
|
307
|
+
<Button variant="destructive">Destructive</Button>
|
|
308
|
+
</div>
|
|
309
|
+
),
|
|
310
|
+
};
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Vue Component Pattern
|
|
314
|
+
|
|
315
|
+
```vue
|
|
316
|
+
<!-- Button.vue -->
|
|
317
|
+
<script setup lang="ts">
|
|
318
|
+
import { computed } from "vue";
|
|
319
|
+
|
|
320
|
+
interface Props {
|
|
321
|
+
variant?: "primary" | "secondary" | "ghost" | "destructive";
|
|
322
|
+
size?: "sm" | "md" | "lg";
|
|
323
|
+
isLoading?: boolean;
|
|
324
|
+
disabled?: boolean;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
328
|
+
variant: "primary",
|
|
329
|
+
size: "md",
|
|
330
|
+
isLoading: false,
|
|
331
|
+
disabled: false,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const emit = defineEmits<{
|
|
335
|
+
click: [event: MouseEvent];
|
|
336
|
+
}>();
|
|
337
|
+
|
|
338
|
+
const buttonClasses = computed(() => {
|
|
339
|
+
return [
|
|
340
|
+
"inline-flex items-center justify-center rounded-md font-medium transition-colors",
|
|
341
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
|
|
342
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
343
|
+
// Variants
|
|
344
|
+
{
|
|
345
|
+
"bg-blue-600 text-white hover:bg-blue-700": props.variant === "primary",
|
|
346
|
+
"bg-gray-200 text-gray-900 hover:bg-gray-300":
|
|
347
|
+
props.variant === "secondary",
|
|
348
|
+
"hover:bg-gray-100": props.variant === "ghost",
|
|
349
|
+
"bg-red-600 text-white hover:bg-red-700": props.variant === "destructive",
|
|
350
|
+
},
|
|
351
|
+
// Sizes
|
|
352
|
+
{
|
|
353
|
+
"h-8 px-3 text-sm": props.size === "sm",
|
|
354
|
+
"h-10 px-4 text-base": props.size === "md",
|
|
355
|
+
"h-12 px-6 text-lg": props.size === "lg",
|
|
356
|
+
},
|
|
357
|
+
];
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
const handleClick = (event: MouseEvent) => {
|
|
361
|
+
if (!props.disabled && !props.isLoading) {
|
|
362
|
+
emit("click", event);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
</script>
|
|
366
|
+
|
|
367
|
+
<template>
|
|
368
|
+
<button
|
|
369
|
+
:class="buttonClasses"
|
|
370
|
+
:disabled="disabled || isLoading"
|
|
371
|
+
@click="handleClick"
|
|
372
|
+
>
|
|
373
|
+
<svg
|
|
374
|
+
v-if="isLoading"
|
|
375
|
+
class="mr-2 h-4 w-4 animate-spin"
|
|
376
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
377
|
+
fill="none"
|
|
378
|
+
viewBox="0 0 24 24"
|
|
379
|
+
>
|
|
380
|
+
<circle
|
|
381
|
+
class="opacity-25"
|
|
382
|
+
cx="12"
|
|
383
|
+
cy="12"
|
|
384
|
+
r="10"
|
|
385
|
+
stroke="currentColor"
|
|
386
|
+
stroke-width="4"
|
|
387
|
+
/>
|
|
388
|
+
<path
|
|
389
|
+
class="opacity-75"
|
|
390
|
+
fill="currentColor"
|
|
391
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
392
|
+
/>
|
|
393
|
+
</svg>
|
|
394
|
+
<slot />
|
|
395
|
+
</button>
|
|
396
|
+
</template>
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Index File (Barrel Export)
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
// index.ts
|
|
403
|
+
export { Button } from "./Button";
|
|
404
|
+
export type { ButtonProps } from "./Button";
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Usage Documentation Template
|
|
408
|
+
|
|
409
|
+
````markdown
|
|
410
|
+
# Button Component
|
|
411
|
+
|
|
412
|
+
A flexible button component with multiple variants, sizes, and states.
|
|
413
|
+
|
|
414
|
+
## Installation
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
npm install @/components/ui/button
|
|
418
|
+
```
|
|
419
|
+
````
|
|
420
|
+
|
|
421
|
+
## Usage
|
|
422
|
+
|
|
423
|
+
```tsx
|
|
424
|
+
import { Button } from "@/components/ui/button";
|
|
425
|
+
|
|
426
|
+
function App() {
|
|
427
|
+
return (
|
|
428
|
+
<Button variant="primary" size="md" onClick={() => console.log("Clicked!")}>
|
|
429
|
+
Click me
|
|
430
|
+
</Button>
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
## Props
|
|
436
|
+
|
|
437
|
+
| Prop | Type | Default | Description |
|
|
438
|
+
| --------- | ---------------------------------------------------- | --------- | --------------------- |
|
|
439
|
+
| variant | 'primary' \| 'secondary' \| 'ghost' \| 'destructive' | 'primary' | Visual style variant |
|
|
440
|
+
| size | 'sm' \| 'md' \| 'lg' | 'md' | Button size |
|
|
441
|
+
| isLoading | boolean | false | Shows loading spinner |
|
|
442
|
+
| leftIcon | ReactNode | - | Icon before text |
|
|
443
|
+
| rightIcon | ReactNode | - | Icon after text |
|
|
444
|
+
| disabled | boolean | false | Disables the button |
|
|
445
|
+
|
|
446
|
+
## Examples
|
|
447
|
+
|
|
448
|
+
### With Icons
|
|
449
|
+
|
|
450
|
+
```tsx
|
|
451
|
+
<Button leftIcon={<ChevronLeft />}>Back</Button>
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Loading State
|
|
455
|
+
|
|
456
|
+
```tsx
|
|
457
|
+
<Button isLoading>Saving...</Button>
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### Destructive Action
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
<Button variant="destructive" onClick={handleDelete}>
|
|
464
|
+
Delete Account
|
|
465
|
+
</Button>
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
## Accessibility
|
|
469
|
+
|
|
470
|
+
- Keyboard navigable
|
|
471
|
+
- ARIA attributes included
|
|
472
|
+
- Focus visible styling
|
|
473
|
+
- Disabled state properly handled
|
|
474
|
+
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
## Component Structure Template
|
|
478
|
+
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
ComponentName/
|
|
482
|
+
├── ComponentName.tsx # Main component
|
|
483
|
+
├── ComponentName.test.tsx # Tests
|
|
484
|
+
├── ComponentName.stories.tsx # Storybook
|
|
485
|
+
├── types.ts # TypeScript types (if complex)
|
|
486
|
+
├── styles.module.css # CSS Modules (if used)
|
|
487
|
+
└── index.ts # Barrel export
|
|
488
|
+
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## Common Component Types
|
|
492
|
+
|
|
493
|
+
### UI Primitives
|
|
494
|
+
- Button, Input, Select, Checkbox, Radio
|
|
495
|
+
- Typography (Text, Heading, Label)
|
|
496
|
+
- Icons, Avatar, Badge
|
|
497
|
+
|
|
498
|
+
### Layout Components
|
|
499
|
+
- Container, Stack, Grid, Flex
|
|
500
|
+
- Card, Panel, Section
|
|
501
|
+
- Divider, Spacer
|
|
502
|
+
|
|
503
|
+
### Data Display
|
|
504
|
+
- Table, List, DataGrid
|
|
505
|
+
- Tooltip, Popover, Dropdown
|
|
506
|
+
- Tabs, Accordion, Collapse
|
|
507
|
+
|
|
508
|
+
### Feedback
|
|
509
|
+
- Alert, Toast, Modal
|
|
510
|
+
- Progress, Spinner, Skeleton
|
|
511
|
+
- EmptyState, ErrorBoundary
|
|
512
|
+
|
|
513
|
+
### Forms
|
|
514
|
+
- FormField, FormGroup, FormLabel
|
|
515
|
+
- FileUpload, DatePicker, RangePicker
|
|
516
|
+
- SearchInput, TagInput
|
|
517
|
+
|
|
518
|
+
## Best Practices
|
|
519
|
+
|
|
520
|
+
1. **Forward refs**: Use `forwardRef` for DOM access
|
|
521
|
+
2. **Type props properly**: Extend native HTML element props
|
|
522
|
+
3. **Use composition**: Compound components when appropriate
|
|
523
|
+
4. **Accessibility first**: ARIA attributes, keyboard nav
|
|
524
|
+
5. **Variants system**: Size, color, state variants
|
|
525
|
+
6. **Loading states**: Handle async operations
|
|
526
|
+
7. **Error states**: Validate and show errors
|
|
527
|
+
8. **Test coverage**: At least 80% coverage
|
|
528
|
+
9. **Document usage**: JSDoc and README examples
|
|
529
|
+
10. **Export types**: Make TypeScript types available
|
|
530
|
+
|
|
531
|
+
## Styling Approaches
|
|
532
|
+
|
|
533
|
+
### Tailwind CSS (Recommended)
|
|
534
|
+
- Use `cn()` utility for conditional classes
|
|
535
|
+
- Define variants with object syntax
|
|
536
|
+
- Responsive utilities built-in
|
|
537
|
+
|
|
538
|
+
### CSS Modules
|
|
539
|
+
- Scoped styles by default
|
|
540
|
+
- Type-safe with TypeScript
|
|
541
|
+
- Better for complex animations
|
|
542
|
+
|
|
543
|
+
### Styled Components
|
|
544
|
+
- CSS-in-JS with props
|
|
545
|
+
- Dynamic theming support
|
|
546
|
+
- Runtime styling
|
|
547
|
+
|
|
548
|
+
## Output Checklist
|
|
549
|
+
|
|
550
|
+
Every generated component should include:
|
|
551
|
+
|
|
552
|
+
- [ ] Main component file with TypeScript types
|
|
553
|
+
- [ ] Prop interface with JSDoc comments
|
|
554
|
+
- [ ] Multiple variants (size, color, state)
|
|
555
|
+
- [ ] Accessibility attributes
|
|
556
|
+
- [ ] Test file with key scenarios
|
|
557
|
+
- [ ] Storybook story with examples
|
|
558
|
+
- [ ] Barrel export (index.ts)
|
|
559
|
+
- [ ] Usage documentation
|
|
560
|
+
- [ ] Error handling
|
|
561
|
+
- [ ] Loading states (if applicable)
|
|
562
|
+
```
|