claude-code-toolkit 1.0.7
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/LICENSE +21 -0
- package/README.md +476 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +183 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/install.d.ts +8 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +184 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +134 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/template.d.ts +2 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +299 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +21 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
- package/templates/.claude/hooks/README.md +342 -0
- package/templates/.claude/hooks/custom/intelligent-workflows.sh +336 -0
- package/templates/.claude/hooks/hook-manager.sh +300 -0
- package/templates/.claude/hooks/post-commit/smart-automations.sh +249 -0
- package/templates/.claude/hooks/pre-commit/code-quality-guardian.sh +257 -0
- package/templates/.claude/hooks/pre-push/deployment-guardian.sh +334 -0
- package/templates/.claude/memory/context.md +39 -0
- package/templates/.claude/memory/decisions.md +29 -0
- package/templates/.claude/memory/learnings.md +31 -0
- package/templates/.claude/memory/patterns.md +72 -0
- package/templates/.claude/memory/preferences.md +23 -0
- package/templates/.claude/skills/claude-code-hooks-master/SKILL.md +358 -0
- package/templates/.claude/skills/mobile-ui-ux-master/MobileCardGrid.tsx +270 -0
- package/templates/.claude/skills/mobile-ui-ux-master/SKILL.md +172 -0
- package/templates/.claude/skills/mobile-ui-ux-master/card-grid-template.html +260 -0
- package/templates/.claude/skills/mobile-ui-ux-master/mobile-ux-checklist.md +140 -0
- package/templates/.claude/skills/professional-documentation-writer/SKILL.md +42 -0
- package/templates/AGENTS.md +127 -0
- package/templates/CLAUDE.md +101 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# Claude Code Skill: Claude Code Hooks Master
|
|
2
|
+
|
|
3
|
+
## Metadata
|
|
4
|
+
name: claude-code-hooks-master
|
|
5
|
+
description: Master the power of Claude Code hooks for automated development workflows, continuous integration, and seamless productivity enhancement
|
|
6
|
+
author: Carlos Fadhel
|
|
7
|
+
version: 1.0.0
|
|
8
|
+
tags: automation, hooks, workflow, efficiency, ci, productivity, integration
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
Use this skill when you need to:
|
|
12
|
+
- Automate repetitive development tasks
|
|
13
|
+
- Implement continuous integration workflows
|
|
14
|
+
- Enhance development efficiency with smart automation
|
|
15
|
+
- Integrate Claude Code with external tools and services
|
|
16
|
+
- Create custom development workflows
|
|
17
|
+
- Ensure code quality through automated checks
|
|
18
|
+
|
|
19
|
+
## Core Concepts: Hooks Architecture
|
|
20
|
+
|
|
21
|
+
### What Are Claude Code Hooks?
|
|
22
|
+
Hooks are automated scripts that trigger at specific points in your development workflow:
|
|
23
|
+
- **Pre-commit**: Run before code is committed (linting, testing, formatting)
|
|
24
|
+
- **Post-commit**: Run after commits (documentation, notifications, deployment prep)
|
|
25
|
+
- **Pre-push**: Run before pushing to remote (integration tests, security checks)
|
|
26
|
+
- **Post-merge**: Run after merging branches (cleanup, notifications, deployments)
|
|
27
|
+
- **File-change**: Trigger on specific file modifications
|
|
28
|
+
- **Custom events**: User-defined triggers for specific workflows
|
|
29
|
+
|
|
30
|
+
### Hook Directory Structure
|
|
31
|
+
```
|
|
32
|
+
.claude/hooks/
|
|
33
|
+
├── pre-commit/
|
|
34
|
+
│ ├── lint-and-format.sh
|
|
35
|
+
│ ├── run-tests.sh
|
|
36
|
+
│ └── security-check.py
|
|
37
|
+
├── post-commit/
|
|
38
|
+
│ ├── update-docs.sh
|
|
39
|
+
│ ├── notify-team.py
|
|
40
|
+
│ └── backup-code.sh
|
|
41
|
+
├── pre-push/
|
|
42
|
+
│ ├── integration-tests.sh
|
|
43
|
+
│ ├── performance-check.py
|
|
44
|
+
│ └── deployment-prep.sh
|
|
45
|
+
└── custom/
|
|
46
|
+
├── on-api-change/
|
|
47
|
+
│ └── regenerate-clients.sh
|
|
48
|
+
├── on-db-migration/
|
|
49
|
+
│ └── run-migrations.sh
|
|
50
|
+
└── on-release/
|
|
51
|
+
└── publish-package.sh
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Hook Implementation Best Practices
|
|
55
|
+
|
|
56
|
+
### 1. Hook Script Standards
|
|
57
|
+
```bash
|
|
58
|
+
#!/bin/bash
|
|
59
|
+
# HOOK: pre-commit-lint-format
|
|
60
|
+
# DESCRIPTION: Lint and format code before commits
|
|
61
|
+
# AUTHOR: Claude Code Hooks Master
|
|
62
|
+
# VERSION: 1.0.0
|
|
63
|
+
|
|
64
|
+
set -e # Exit on any error
|
|
65
|
+
|
|
66
|
+
# Colors for output
|
|
67
|
+
RED='\033[0;31m'
|
|
68
|
+
GREEN='\033[0;32m'
|
|
69
|
+
YELLOW='\033[1;33m'
|
|
70
|
+
NC='\033[0m' # No Color
|
|
71
|
+
|
|
72
|
+
log_info() {
|
|
73
|
+
echo -e "${GREEN}[INFO]${NC} $1"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
log_warn() {
|
|
77
|
+
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
log_error() {
|
|
81
|
+
echo -e "${RED}[ERROR]${NC} $1"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Main execution
|
|
85
|
+
main() {
|
|
86
|
+
log_info "Running pre-commit lint and format checks..."
|
|
87
|
+
|
|
88
|
+
# Your automation logic here
|
|
89
|
+
if ! run_linter; then
|
|
90
|
+
log_error "Linting failed. Please fix issues before committing."
|
|
91
|
+
exit 1
|
|
92
|
+
fi
|
|
93
|
+
|
|
94
|
+
if ! run_formatter; then
|
|
95
|
+
log_error "Formatting failed."
|
|
96
|
+
exit 1
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
log_info "All pre-commit checks passed!"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Helper functions
|
|
103
|
+
run_linter() {
|
|
104
|
+
# Implement your linting logic
|
|
105
|
+
echo "Running linter..."
|
|
106
|
+
# Return 0 for success, 1 for failure
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
run_formatter() {
|
|
110
|
+
# Implement your formatting logic
|
|
111
|
+
echo "Running formatter..."
|
|
112
|
+
# Return 0 for success, 1 for failure
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# Run main function
|
|
116
|
+
main "$@"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 2. Error Handling & Logging
|
|
120
|
+
- Always use `set -e` to fail fast on errors
|
|
121
|
+
- Provide clear, actionable error messages
|
|
122
|
+
- Log both successes and failures
|
|
123
|
+
- Use exit codes appropriately (0 = success, 1 = failure)
|
|
124
|
+
|
|
125
|
+
### 3. Performance Considerations
|
|
126
|
+
- Keep hooks fast (< 30 seconds for pre-commit)
|
|
127
|
+
- Cache results when possible
|
|
128
|
+
- Run expensive operations in background for post-commit hooks
|
|
129
|
+
- Use parallel execution for independent checks
|
|
130
|
+
|
|
131
|
+
### 4. Integration with Claude Code Skills
|
|
132
|
+
Hooks can trigger Claude Code skills automatically:
|
|
133
|
+
```bash
|
|
134
|
+
# In a post-commit hook
|
|
135
|
+
claude_code_run_skill "professional-documentation-writer" "update-api-docs"
|
|
136
|
+
claude_code_run_skill "test-generator" "run-regression-tests"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Essential Hook Categories
|
|
140
|
+
|
|
141
|
+
### 🔍 **Quality Assurance Hooks**
|
|
142
|
+
- **Pre-commit**: Linting, formatting, type checking
|
|
143
|
+
- **Pre-push**: Full test suite, integration tests
|
|
144
|
+
- **Post-merge**: Cross-browser testing, accessibility audits
|
|
145
|
+
|
|
146
|
+
### 🚀 **Deployment Hooks**
|
|
147
|
+
- **Pre-push**: Build verification, environment checks
|
|
148
|
+
- **Post-commit**: Automatic staging deployments
|
|
149
|
+
- **Post-merge**: Production deployments (with approval gates)
|
|
150
|
+
|
|
151
|
+
### 📚 **Documentation Hooks**
|
|
152
|
+
- **Post-commit**: Auto-generate API docs, update README
|
|
153
|
+
- **On-api-change**: Regenerate client SDKs
|
|
154
|
+
- **Pre-release**: Generate changelog, update version numbers
|
|
155
|
+
|
|
156
|
+
### 🔒 **Security Hooks**
|
|
157
|
+
- **Pre-commit**: Secret scanning, dependency vulnerability checks
|
|
158
|
+
- **Pre-push**: Security testing, penetration testing triggers
|
|
159
|
+
- **Post-merge**: Security audit notifications
|
|
160
|
+
|
|
161
|
+
### 🤝 **Collaboration Hooks**
|
|
162
|
+
- **Post-commit**: Team notifications, Slack updates
|
|
163
|
+
- **Post-merge**: Code review assignments, QA notifications
|
|
164
|
+
- **On-conflict**: Conflict resolution guides, merge conflict notifications
|
|
165
|
+
|
|
166
|
+
## Advanced Automation Examples
|
|
167
|
+
|
|
168
|
+
### 1. Smart Commit Messages
|
|
169
|
+
```bash
|
|
170
|
+
# pre-commit-smart-commit.sh
|
|
171
|
+
# Analyzes changes and suggests commit message format
|
|
172
|
+
|
|
173
|
+
CHANGED_FILES=$(git diff --cached --name-only)
|
|
174
|
+
if echo "$CHANGED_FILES" | grep -q "test"; then
|
|
175
|
+
SUGGEST_TYPE="test"
|
|
176
|
+
elif echo "$CHANGED_FILES" | grep -q "docs"; then
|
|
177
|
+
SUGGEST_TYPE="docs"
|
|
178
|
+
elif echo "$CHANGED_FILES" | grep -q "\.md$"; then
|
|
179
|
+
SUGGEST_TYPE="docs"
|
|
180
|
+
else
|
|
181
|
+
SUGGEST_TYPE="feat"
|
|
182
|
+
fi
|
|
183
|
+
|
|
184
|
+
echo "Suggested commit type: $SUGGEST_TYPE"
|
|
185
|
+
echo "Example: $SUGGEST_TYPE: add user authentication"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 2. Intelligent Testing
|
|
189
|
+
```bash
|
|
190
|
+
# pre-push-smart-testing.sh
|
|
191
|
+
# Runs only relevant tests based on changed files
|
|
192
|
+
|
|
193
|
+
CHANGED_FILES=$(git diff --name-only HEAD~1)
|
|
194
|
+
TEST_COMMAND="npm test"
|
|
195
|
+
|
|
196
|
+
# Run full suite for core changes
|
|
197
|
+
if echo "$CHANGED_FILES" | grep -E "(core|config|package\.json)"; then
|
|
198
|
+
echo "Core changes detected - running full test suite"
|
|
199
|
+
TEST_COMMAND="$TEST_COMMAND -- --coverage"
|
|
200
|
+
# Run specific tests for feature changes
|
|
201
|
+
elif echo "$CHANGED_FILES" | grep -E "src/components"; then
|
|
202
|
+
echo "Component changes detected - running component tests"
|
|
203
|
+
TEST_COMMAND="$TEST_COMMAND -- --testPathPattern=components"
|
|
204
|
+
fi
|
|
205
|
+
|
|
206
|
+
eval $TEST_COMMAND
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### 3. Automated Documentation
|
|
210
|
+
```bash
|
|
211
|
+
# post-commit-docs-update.sh
|
|
212
|
+
# Auto-updates documentation based on code changes
|
|
213
|
+
|
|
214
|
+
if git diff --name-only HEAD~1 | grep -E "\.(js|ts|py)$"; then
|
|
215
|
+
echo "Code changes detected - updating documentation"
|
|
216
|
+
|
|
217
|
+
# Use Claude Code skills for documentation
|
|
218
|
+
claude_code_run_skill "professional-documentation-writer" "update-api-docs"
|
|
219
|
+
|
|
220
|
+
# Update README if necessary
|
|
221
|
+
if git diff --name-only HEAD~1 | grep -E "(README|readme)"; then
|
|
222
|
+
claude_code_run_skill "professional-documentation-writer" "update-readme"
|
|
223
|
+
fi
|
|
224
|
+
fi
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 4. Deployment Automation
|
|
228
|
+
```bash
|
|
229
|
+
# post-merge-deployment.sh
|
|
230
|
+
# Automates deployment after successful merges
|
|
231
|
+
|
|
232
|
+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
233
|
+
if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
|
|
234
|
+
echo "Merge to main branch detected - starting deployment"
|
|
235
|
+
|
|
236
|
+
# Run final checks
|
|
237
|
+
npm run test:ci
|
|
238
|
+
npm run build
|
|
239
|
+
|
|
240
|
+
# Deploy to staging
|
|
241
|
+
deploy_to_staging
|
|
242
|
+
|
|
243
|
+
# Notify team
|
|
244
|
+
notify_deployment "staging"
|
|
245
|
+
|
|
246
|
+
# Optional: auto-deploy to production after manual approval
|
|
247
|
+
if [ "$AUTO_DEPLOY_PROD" = "true" ]; then
|
|
248
|
+
deploy_to_production
|
|
249
|
+
notify_deployment "production"
|
|
250
|
+
fi
|
|
251
|
+
fi
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Integration with Claude Code Agents
|
|
255
|
+
|
|
256
|
+
### Memory System Integration
|
|
257
|
+
```bash
|
|
258
|
+
# post-commit-memory-update.sh
|
|
259
|
+
# Updates the persistent memory system with project changes
|
|
260
|
+
|
|
261
|
+
COMMIT_MSG=$(git log -1 --pretty=%B)
|
|
262
|
+
CHANGED_FILES=$(git diff --name-only HEAD~1)
|
|
263
|
+
|
|
264
|
+
# Add to decisions memory
|
|
265
|
+
if echo "$COMMIT_MSG" | grep -i "decision\|choice\|architect"; then
|
|
266
|
+
echo "## $(date) - Architecture Decision" >> .claude/memory/decisions.md
|
|
267
|
+
echo "**Decision**: $COMMIT_MSG" >> .claude/memory/decisions.md
|
|
268
|
+
fi
|
|
269
|
+
|
|
270
|
+
# Add to learnings memory
|
|
271
|
+
if echo "$COMMIT_MSG" | grep -i "learn\|discover\|find"; then
|
|
272
|
+
echo "## $(date) - Development Learning" >> .claude/memory/learnings.md
|
|
273
|
+
echo "**Insight**: $COMMIT_MSG" >> .claude/memory/learnings.md
|
|
274
|
+
fi
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Agent Triggering
|
|
278
|
+
```bash
|
|
279
|
+
# on-file-change-trigger-agents.sh
|
|
280
|
+
# Triggers specific agents based on file changes
|
|
281
|
+
|
|
282
|
+
CHANGED_FILES=$(git diff --name-only)
|
|
283
|
+
|
|
284
|
+
# Trigger mobile UI specialist for UI changes
|
|
285
|
+
if echo "$CHANGED_FILES" | grep -E "mobile|ui|component"; then
|
|
286
|
+
claude_code_run_agent "mobile-ui-specialist" "review-ui-changes"
|
|
287
|
+
fi
|
|
288
|
+
|
|
289
|
+
# Trigger code reviewer for critical files
|
|
290
|
+
if echo "$CHANGED_FILES" | grep -E "(security|auth|payment)"; then
|
|
291
|
+
claude_code_run_agent "code-reviewer" "security-review"
|
|
292
|
+
fi
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Performance & Reliability
|
|
296
|
+
|
|
297
|
+
### Hook Performance Guidelines
|
|
298
|
+
- **Pre-commit**: < 10 seconds (blocking operations)
|
|
299
|
+
- **Pre-push**: < 30 seconds (can be interrupted)
|
|
300
|
+
- **Post-commit**: < 60 seconds (background operations)
|
|
301
|
+
- **Post-merge**: < 5 minutes (deployment operations)
|
|
302
|
+
|
|
303
|
+
### Reliability Features
|
|
304
|
+
- **Timeout handling**: Prevent hanging hooks
|
|
305
|
+
- **Retry logic**: For network-dependent operations
|
|
306
|
+
- **Fallback behavior**: Graceful degradation on failures
|
|
307
|
+
- **Logging**: Comprehensive logging for debugging
|
|
308
|
+
|
|
309
|
+
### Monitoring & Maintenance
|
|
310
|
+
```bash
|
|
311
|
+
# hook-monitor.sh
|
|
312
|
+
# Monitors hook performance and health
|
|
313
|
+
|
|
314
|
+
HOOK_LOGS_DIR=".claude/hooks/logs"
|
|
315
|
+
mkdir -p "$HOOK_LOGS_DIR"
|
|
316
|
+
|
|
317
|
+
# Log hook execution time
|
|
318
|
+
start_time=$(date +%s)
|
|
319
|
+
# ... hook logic ...
|
|
320
|
+
end_time=$(date +%s)
|
|
321
|
+
duration=$((end_time - start_time))
|
|
322
|
+
|
|
323
|
+
echo "$(date): $HOOK_NAME took ${duration}s" >> "$HOOK_LOGS_DIR/performance.log"
|
|
324
|
+
|
|
325
|
+
# Alert on slow hooks
|
|
326
|
+
if [ $duration -gt 30 ]; then
|
|
327
|
+
notify_team "Slow hook detected: $HOOK_NAME (${duration}s)"
|
|
328
|
+
fi
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Security Considerations
|
|
332
|
+
|
|
333
|
+
### Safe Hook Practices
|
|
334
|
+
- **Validate inputs**: Never trust user-provided data
|
|
335
|
+
- **Limit permissions**: Run hooks with minimal required permissions
|
|
336
|
+
- **Audit logging**: Log all hook executions for security review
|
|
337
|
+
- **Secret management**: Use secure credential storage (not plain text)
|
|
338
|
+
|
|
339
|
+
### Network Security
|
|
340
|
+
- **HTTPS only**: All external API calls must use HTTPS
|
|
341
|
+
- **Certificate validation**: Verify SSL certificates
|
|
342
|
+
- **API authentication**: Use proper authentication tokens
|
|
343
|
+
- **Rate limiting**: Respect API rate limits to avoid blocks
|
|
344
|
+
|
|
345
|
+
## Input Requirements
|
|
346
|
+
- Project type (web app, mobile app, API, library)
|
|
347
|
+
- Development workflow preferences (Git flow, trunk-based, etc.)
|
|
348
|
+
- External integrations needed (CI/CD, monitoring, notifications)
|
|
349
|
+
- Performance requirements and constraints
|
|
350
|
+
|
|
351
|
+
## Output Format
|
|
352
|
+
Return production-ready hook implementations with:
|
|
353
|
+
- Proper error handling and logging
|
|
354
|
+
- Performance optimizations
|
|
355
|
+
- Security best practices
|
|
356
|
+
- Integration with existing Claude Code skills
|
|
357
|
+
- Documentation and maintenance guides
|
|
358
|
+
- Monitoring and alerting capabilities
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// MOBILE-OPTIMIZED CARD GRID COMPONENT
|
|
2
|
+
// Solves all your UI/UX pain points: consistent heights, text containment, responsive design
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import styled from 'styled-components';
|
|
6
|
+
|
|
7
|
+
// Define theme interface for styled-components
|
|
8
|
+
declare module 'styled-components' {
|
|
9
|
+
export interface DefaultTheme {
|
|
10
|
+
colors: {
|
|
11
|
+
surface: string;
|
|
12
|
+
surfaceSecondary: string;
|
|
13
|
+
textPrimary: string;
|
|
14
|
+
textSecondary: string;
|
|
15
|
+
primary: string;
|
|
16
|
+
primaryHover: string;
|
|
17
|
+
primaryActive: string;
|
|
18
|
+
icon: string;
|
|
19
|
+
focus: string;
|
|
20
|
+
disabled: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Default theme with professional colors
|
|
26
|
+
export const defaultTheme = {
|
|
27
|
+
colors: {
|
|
28
|
+
surface: '#ffffff',
|
|
29
|
+
surfaceSecondary: '#f3f4f6',
|
|
30
|
+
textPrimary: '#111827',
|
|
31
|
+
textSecondary: '#6b7280',
|
|
32
|
+
primary: '#3b82f6',
|
|
33
|
+
primaryHover: '#2563eb',
|
|
34
|
+
primaryActive: '#1d4ed8',
|
|
35
|
+
icon: '#6b7280',
|
|
36
|
+
focus: '#3b82f6',
|
|
37
|
+
disabled: '#9ca3af'
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface CardData {
|
|
42
|
+
id: string;
|
|
43
|
+
title: string;
|
|
44
|
+
description: string;
|
|
45
|
+
icon: React.ReactNode;
|
|
46
|
+
actionLabel?: string;
|
|
47
|
+
onAction?: () => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface MobileCardGridProps {
|
|
51
|
+
cards: CardData[];
|
|
52
|
+
columns?: {
|
|
53
|
+
mobile: number;
|
|
54
|
+
tablet: number;
|
|
55
|
+
desktop: number;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const MobileCardGrid: React.FC<MobileCardGridProps> = ({
|
|
60
|
+
cards,
|
|
61
|
+
columns = { mobile: 1, tablet: 2, desktop: 3 }
|
|
62
|
+
}) => {
|
|
63
|
+
return (
|
|
64
|
+
<GridContainer columns={columns}>
|
|
65
|
+
{cards.map((card) => (
|
|
66
|
+
<Card key={card.id}>
|
|
67
|
+
<CardHeader>
|
|
68
|
+
<IconContainer>
|
|
69
|
+
{card.icon}
|
|
70
|
+
</IconContainer>
|
|
71
|
+
</CardHeader>
|
|
72
|
+
|
|
73
|
+
<CardContent>
|
|
74
|
+
<CardTitle>{card.title}</CardTitle>
|
|
75
|
+
<CardDescription>{card.description}</CardDescription>
|
|
76
|
+
</CardContent>
|
|
77
|
+
|
|
78
|
+
{card.actionLabel && (
|
|
79
|
+
<CardFooter>
|
|
80
|
+
<ActionButton onClick={card.onAction}>
|
|
81
|
+
{card.actionLabel}
|
|
82
|
+
</ActionButton>
|
|
83
|
+
</CardFooter>
|
|
84
|
+
)}
|
|
85
|
+
</Card>
|
|
86
|
+
))}
|
|
87
|
+
</GridContainer>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// STYLED COMPONENTS WITH MOBILE-FIRST DESIGN
|
|
92
|
+
const GridContainer = styled.div<{ columns: { mobile: number; tablet: number; desktop: number } }>`
|
|
93
|
+
display: grid;
|
|
94
|
+
gap: 16px;
|
|
95
|
+
padding: 16px;
|
|
96
|
+
|
|
97
|
+
/* MOBILE FIRST: Single column by default */
|
|
98
|
+
grid-template-columns: 1fr;
|
|
99
|
+
|
|
100
|
+
/* TABLET: 2 columns minimum */
|
|
101
|
+
@media (min-width: 768px) {
|
|
102
|
+
grid-template-columns: repeat(${props => props.columns.tablet}, 1fr);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* DESKTOP: 3 columns */
|
|
106
|
+
@media (min-width: 1024px) {
|
|
107
|
+
grid-template-columns: repeat(${props => props.columns.desktop}, 1fr);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* CRITICAL: EQUAL HEIGHTS FOR ALL CARDS */
|
|
111
|
+
grid-auto-rows: 1fr;
|
|
112
|
+
`;
|
|
113
|
+
|
|
114
|
+
const Card = styled.div`
|
|
115
|
+
height: 100%; /* FILL GRID ROW HEIGHT */
|
|
116
|
+
background: ${props => props.theme.colors.surface || '#ffffff'};
|
|
117
|
+
border-radius: 12px;
|
|
118
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
119
|
+
display: flex;
|
|
120
|
+
flex-direction: column;
|
|
121
|
+
overflow: hidden;
|
|
122
|
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
123
|
+
|
|
124
|
+
/* HOVER EFFECTS - SAFE FOR TOUCH DEVICES */
|
|
125
|
+
@media (hover: hover) and (pointer: fine) {
|
|
126
|
+
&:hover {
|
|
127
|
+
transform: translateY(-2px);
|
|
128
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
|
|
133
|
+
const CardHeader = styled.div`
|
|
134
|
+
padding: 16px 16px 0 16px;
|
|
135
|
+
display: flex;
|
|
136
|
+
justify-content: flex-start;
|
|
137
|
+
align-items: center;
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
const IconContainer = styled.div`
|
|
141
|
+
width: 48px;
|
|
142
|
+
height: 48px;
|
|
143
|
+
border-radius: 8px;
|
|
144
|
+
background: ${props => props.theme.colors.surfaceSecondary || '#f3f4f6'};
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
flex-shrink: 0; /* PREVENT ICON DISTORTION */
|
|
149
|
+
|
|
150
|
+
/* ICON STYLING */
|
|
151
|
+
svg {
|
|
152
|
+
width: 24px;
|
|
153
|
+
height: 24px;
|
|
154
|
+
color: ${props => props.theme.colors.icon || '#6b7280'};
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
|
|
158
|
+
const CardContent = styled.div`
|
|
159
|
+
flex: 1; /* TAKE REMAINING SPACE */
|
|
160
|
+
padding: 12px 16px;
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: column;
|
|
163
|
+
gap: 8px;
|
|
164
|
+
`;
|
|
165
|
+
|
|
166
|
+
const CardTitle = styled.h3`
|
|
167
|
+
font-size: 16px;
|
|
168
|
+
font-weight: 600;
|
|
169
|
+
line-height: 1.4;
|
|
170
|
+
color: ${props => props.theme.colors.textPrimary || '#111827'};
|
|
171
|
+
margin: 0;
|
|
172
|
+
|
|
173
|
+
/* TEXT CONTAINMENT - PREVENTS LAYOUT BREAKAGE */
|
|
174
|
+
display: -webkit-box;
|
|
175
|
+
-webkit-line-clamp: 2;
|
|
176
|
+
-webkit-box-orient: vertical;
|
|
177
|
+
overflow: hidden;
|
|
178
|
+
word-break: break-word;
|
|
179
|
+
hyphens: auto;
|
|
180
|
+
`;
|
|
181
|
+
|
|
182
|
+
const CardDescription = styled.p`
|
|
183
|
+
flex: 1; /* FILL AVAILABLE SPACE TO MAINTAIN HEIGHT */
|
|
184
|
+
font-size: 14px;
|
|
185
|
+
line-height: 1.5;
|
|
186
|
+
color: ${props => props.theme.colors.textSecondary || '#6b7280'};
|
|
187
|
+
margin: 0;
|
|
188
|
+
|
|
189
|
+
/* TEXT CONTAINMENT */
|
|
190
|
+
display: -webkit-box;
|
|
191
|
+
-webkit-line-clamp: 3;
|
|
192
|
+
-webkit-box-orient: vertical;
|
|
193
|
+
overflow: hidden;
|
|
194
|
+
`;
|
|
195
|
+
|
|
196
|
+
const CardFooter = styled.div`
|
|
197
|
+
padding: 0 16px 16px 16px;
|
|
198
|
+
margin-top: auto; /* PUSH TO BOTTOM */
|
|
199
|
+
`;
|
|
200
|
+
|
|
201
|
+
const ActionButton = styled.button`
|
|
202
|
+
width: 100%;
|
|
203
|
+
padding: 12px 16px;
|
|
204
|
+
background: ${props => props.theme.colors.primary || '#3b82f6'};
|
|
205
|
+
color: white;
|
|
206
|
+
border: none;
|
|
207
|
+
border-radius: 8px;
|
|
208
|
+
font-size: 14px;
|
|
209
|
+
font-weight: 500;
|
|
210
|
+
cursor: pointer;
|
|
211
|
+
transition: background-color 0.2s ease;
|
|
212
|
+
min-height: 44px; /* TOUCH TARGET MINIMUM */
|
|
213
|
+
|
|
214
|
+
/* HOVER EFFECTS - SAFE FOR TOUCH */
|
|
215
|
+
@media (hover: hover) and (pointer: fine) {
|
|
216
|
+
&:hover {
|
|
217
|
+
background: ${props => props.theme.colors.primaryHover || '#2563eb'};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&:active {
|
|
222
|
+
background: ${props => props.theme.colors.primaryActive || '#1d4ed8'};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* FOCUS ACCESSIBILITY */
|
|
226
|
+
&:focus {
|
|
227
|
+
outline: 2px solid ${props => props.theme.colors.focus || '#3b82f6'};
|
|
228
|
+
outline-offset: 2px;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* DISABLED STATE */
|
|
232
|
+
&:disabled {
|
|
233
|
+
background: ${props => props.theme.colors.disabled || '#9ca3af'};
|
|
234
|
+
cursor: not-allowed;
|
|
235
|
+
}
|
|
236
|
+
`;
|
|
237
|
+
|
|
238
|
+
export default MobileCardGrid;
|
|
239
|
+
|
|
240
|
+
// USAGE EXAMPLE:
|
|
241
|
+
/*
|
|
242
|
+
import MobileCardGrid, { defaultTheme } from './MobileCardGrid';
|
|
243
|
+
import { ThemeProvider } from 'styled-components';
|
|
244
|
+
|
|
245
|
+
const cards = [
|
|
246
|
+
{
|
|
247
|
+
id: '1',
|
|
248
|
+
title: 'Professional Card Title',
|
|
249
|
+
description: 'This description will never break the layout or cause height inconsistencies.',
|
|
250
|
+
icon: <SomeIcon />,
|
|
251
|
+
actionLabel: 'Learn More',
|
|
252
|
+
onAction: () => console.log('Action clicked')
|
|
253
|
+
}
|
|
254
|
+
// ... more cards
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
// Optional: Wrap with ThemeProvider for custom theming
|
|
258
|
+
<ThemeProvider theme={defaultTheme}>
|
|
259
|
+
<MobileCardGrid
|
|
260
|
+
cards={cards}
|
|
261
|
+
columns={{ mobile: 1, tablet: 2, desktop: 3 }}
|
|
262
|
+
/>
|
|
263
|
+
</ThemeProvider>
|
|
264
|
+
|
|
265
|
+
// Or use with default theme (built-in fallbacks)
|
|
266
|
+
<MobileCardGrid
|
|
267
|
+
cards={cards}
|
|
268
|
+
columns={{ mobile: 1, tablet: 2, desktop: 3 }}
|
|
269
|
+
/>
|
|
270
|
+
*/
|