@friggframework/devtools 2.0.0-next.3 → 2.0.0-next.30
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/frigg-cli/.eslintrc.js +141 -0
- package/frigg-cli/__tests__/jest.config.js +102 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +483 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +418 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +592 -0
- package/frigg-cli/__tests__/utils/command-tester.js +170 -0
- package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
- package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
- package/frigg-cli/__tests__/utils/test-setup.js +286 -0
- package/frigg-cli/build-command/index.js +54 -0
- package/frigg-cli/deploy-command/index.js +36 -0
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +312 -0
- package/frigg-cli/generate-command/azure-generator.js +43 -0
- package/frigg-cli/generate-command/gcp-generator.js +47 -0
- package/frigg-cli/generate-command/index.js +332 -0
- package/frigg-cli/generate-command/terraform-generator.js +555 -0
- package/frigg-cli/generate-iam-command.js +115 -0
- package/frigg-cli/index.js +47 -1
- package/frigg-cli/index.test.js +1 -4
- package/frigg-cli/init-command/backend-first-handler.js +756 -0
- package/frigg-cli/init-command/index.js +93 -0
- package/frigg-cli/init-command/template-handler.js +143 -0
- package/frigg-cli/install-command/index.js +1 -4
- package/frigg-cli/package.json +51 -0
- package/frigg-cli/start-command/index.js +24 -4
- package/frigg-cli/test/init-command.test.js +180 -0
- package/frigg-cli/test/npm-registry.test.js +319 -0
- package/frigg-cli/ui-command/index.js +154 -0
- package/frigg-cli/utils/app-resolver.js +319 -0
- package/frigg-cli/utils/backend-path.js +16 -17
- package/frigg-cli/utils/npm-registry.js +167 -0
- package/frigg-cli/utils/process-manager.js +199 -0
- package/frigg-cli/utils/repo-detection.js +405 -0
- package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +245 -0
- package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +596 -0
- package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
- package/infrastructure/GENERATE-IAM-DOCS.md +253 -0
- package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
- package/infrastructure/README-TESTING.md +332 -0
- package/infrastructure/README.md +421 -0
- package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/aws-discovery.js +568 -0
- package/infrastructure/aws-discovery.test.js +373 -0
- package/infrastructure/build-time-discovery.js +206 -0
- package/infrastructure/build-time-discovery.test.js +375 -0
- package/infrastructure/create-frigg-infrastructure.js +3 -5
- package/infrastructure/frigg-deployment-iam-stack.yaml +379 -0
- package/infrastructure/iam-generator.js +687 -0
- package/infrastructure/iam-generator.test.js +169 -0
- package/infrastructure/iam-policy-basic.json +212 -0
- package/infrastructure/iam-policy-full.json +282 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/run-discovery.js +110 -0
- package/infrastructure/serverless-template.js +923 -113
- package/infrastructure/serverless-template.test.js +541 -0
- package/management-ui/.eslintrc.js +22 -0
- package/management-ui/README.md +203 -0
- package/management-ui/components.json +21 -0
- package/management-ui/docs/phase2-integration-guide.md +320 -0
- package/management-ui/index.html +13 -0
- package/management-ui/package-lock.json +16517 -0
- package/management-ui/package.json +76 -0
- package/management-ui/packages/devtools/frigg-cli/ui-command/index.js +302 -0
- package/management-ui/postcss.config.js +6 -0
- package/management-ui/server/api/backend.js +256 -0
- package/management-ui/server/api/cli.js +315 -0
- package/management-ui/server/api/codegen.js +663 -0
- package/management-ui/server/api/connections.js +857 -0
- package/management-ui/server/api/discovery.js +185 -0
- package/management-ui/server/api/environment/index.js +1 -0
- package/management-ui/server/api/environment/router.js +378 -0
- package/management-ui/server/api/environment.js +328 -0
- package/management-ui/server/api/integrations.js +876 -0
- package/management-ui/server/api/logs.js +248 -0
- package/management-ui/server/api/monitoring.js +282 -0
- package/management-ui/server/api/open-ide.js +31 -0
- package/management-ui/server/api/project.js +1029 -0
- package/management-ui/server/api/users/sessions.js +371 -0
- package/management-ui/server/api/users/simulation.js +254 -0
- package/management-ui/server/api/users.js +362 -0
- package/management-ui/server/api-contract.md +275 -0
- package/management-ui/server/index.js +873 -0
- package/management-ui/server/middleware/errorHandler.js +93 -0
- package/management-ui/server/middleware/security.js +32 -0
- package/management-ui/server/processManager.js +296 -0
- package/management-ui/server/server.js +346 -0
- package/management-ui/server/services/aws-monitor.js +413 -0
- package/management-ui/server/services/npm-registry.js +347 -0
- package/management-ui/server/services/template-engine.js +538 -0
- package/management-ui/server/utils/cliIntegration.js +220 -0
- package/management-ui/server/utils/environment/auditLogger.js +471 -0
- package/management-ui/server/utils/environment/awsParameterStore.js +264 -0
- package/management-ui/server/utils/environment/encryption.js +278 -0
- package/management-ui/server/utils/environment/envFileManager.js +286 -0
- package/management-ui/server/utils/import-commonjs.js +28 -0
- package/management-ui/server/utils/response.js +83 -0
- package/management-ui/server/websocket/handler.js +325 -0
- package/management-ui/src/App.jsx +109 -0
- package/management-ui/src/assets/FriggLogo.svg +1 -0
- package/management-ui/src/components/AppRouter.jsx +65 -0
- package/management-ui/src/components/Button.jsx +70 -0
- package/management-ui/src/components/Card.jsx +97 -0
- package/management-ui/src/components/EnvironmentCompare.jsx +400 -0
- package/management-ui/src/components/EnvironmentEditor.jsx +372 -0
- package/management-ui/src/components/EnvironmentImportExport.jsx +469 -0
- package/management-ui/src/components/EnvironmentSchema.jsx +491 -0
- package/management-ui/src/components/EnvironmentSecurity.jsx +463 -0
- package/management-ui/src/components/ErrorBoundary.jsx +73 -0
- package/management-ui/src/components/IntegrationCard.jsx +481 -0
- package/management-ui/src/components/IntegrationCardEnhanced.jsx +770 -0
- package/management-ui/src/components/IntegrationExplorer.jsx +379 -0
- package/management-ui/src/components/IntegrationStatus.jsx +336 -0
- package/management-ui/src/components/Layout.jsx +716 -0
- package/management-ui/src/components/LoadingSpinner.jsx +113 -0
- package/management-ui/src/components/RepositoryPicker.jsx +248 -0
- package/management-ui/src/components/SessionMonitor.jsx +350 -0
- package/management-ui/src/components/StatusBadge.jsx +208 -0
- package/management-ui/src/components/UserContextSwitcher.jsx +212 -0
- package/management-ui/src/components/UserSimulation.jsx +327 -0
- package/management-ui/src/components/Welcome.jsx +434 -0
- package/management-ui/src/components/codegen/APIEndpointGenerator.jsx +637 -0
- package/management-ui/src/components/codegen/APIModuleSelector.jsx +227 -0
- package/management-ui/src/components/codegen/CodeGenerationWizard.jsx +247 -0
- package/management-ui/src/components/codegen/CodePreviewEditor.jsx +316 -0
- package/management-ui/src/components/codegen/DynamicModuleForm.jsx +271 -0
- package/management-ui/src/components/codegen/FormBuilder.jsx +737 -0
- package/management-ui/src/components/codegen/IntegrationGenerator.jsx +855 -0
- package/management-ui/src/components/codegen/ProjectScaffoldWizard.jsx +797 -0
- package/management-ui/src/components/codegen/SchemaBuilder.jsx +303 -0
- package/management-ui/src/components/codegen/TemplateSelector.jsx +586 -0
- package/management-ui/src/components/codegen/index.js +10 -0
- package/management-ui/src/components/connections/ConnectionConfigForm.jsx +362 -0
- package/management-ui/src/components/connections/ConnectionHealthMonitor.jsx +182 -0
- package/management-ui/src/components/connections/ConnectionTester.jsx +200 -0
- package/management-ui/src/components/connections/EntityRelationshipMapper.jsx +292 -0
- package/management-ui/src/components/connections/OAuthFlow.jsx +204 -0
- package/management-ui/src/components/connections/index.js +5 -0
- package/management-ui/src/components/index.js +21 -0
- package/management-ui/src/components/monitoring/APIGatewayMetrics.jsx +222 -0
- package/management-ui/src/components/monitoring/LambdaMetrics.jsx +169 -0
- package/management-ui/src/components/monitoring/MetricsChart.jsx +197 -0
- package/management-ui/src/components/monitoring/MonitoringDashboard.jsx +393 -0
- package/management-ui/src/components/monitoring/SQSMetrics.jsx +246 -0
- package/management-ui/src/components/monitoring/index.js +6 -0
- package/management-ui/src/components/monitoring/monitoring.css +218 -0
- package/management-ui/src/components/theme-provider.jsx +52 -0
- package/management-ui/src/components/theme-toggle.jsx +39 -0
- package/management-ui/src/components/ui/badge.tsx +36 -0
- package/management-ui/src/components/ui/button.test.jsx +56 -0
- package/management-ui/src/components/ui/button.tsx +57 -0
- package/management-ui/src/components/ui/card.tsx +76 -0
- package/management-ui/src/components/ui/dropdown-menu.tsx +199 -0
- package/management-ui/src/components/ui/select.tsx +157 -0
- package/management-ui/src/components/ui/skeleton.jsx +15 -0
- package/management-ui/src/hooks/useFrigg.jsx +601 -0
- package/management-ui/src/hooks/useSocket.jsx +58 -0
- package/management-ui/src/index.css +193 -0
- package/management-ui/src/lib/utils.ts +6 -0
- package/management-ui/src/main.jsx +10 -0
- package/management-ui/src/pages/CodeGeneration.jsx +14 -0
- package/management-ui/src/pages/Connections.jsx +252 -0
- package/management-ui/src/pages/ConnectionsEnhanced.jsx +633 -0
- package/management-ui/src/pages/Dashboard.jsx +311 -0
- package/management-ui/src/pages/Environment.jsx +314 -0
- package/management-ui/src/pages/IntegrationConfigure.jsx +669 -0
- package/management-ui/src/pages/IntegrationDiscovery.jsx +567 -0
- package/management-ui/src/pages/IntegrationTest.jsx +742 -0
- package/management-ui/src/pages/Integrations.jsx +253 -0
- package/management-ui/src/pages/Monitoring.jsx +17 -0
- package/management-ui/src/pages/Simulation.jsx +155 -0
- package/management-ui/src/pages/Users.jsx +492 -0
- package/management-ui/src/services/api.js +41 -0
- package/management-ui/src/services/apiModuleService.js +193 -0
- package/management-ui/src/services/websocket-handlers.js +120 -0
- package/management-ui/src/test/api/project.test.js +273 -0
- package/management-ui/src/test/components/Welcome.test.jsx +378 -0
- package/management-ui/src/test/mocks/server.js +178 -0
- package/management-ui/src/test/setup.js +61 -0
- package/management-ui/src/test/utils/test-utils.jsx +134 -0
- package/management-ui/src/utils/repository.js +98 -0
- package/management-ui/src/utils/repository.test.js +118 -0
- package/management-ui/src/workflows/phase2-integration-workflows.js +884 -0
- package/management-ui/tailwind.config.js +63 -0
- package/management-ui/tsconfig.json +37 -0
- package/management-ui/tsconfig.node.json +10 -0
- package/management-ui/vite.config.js +26 -0
- package/management-ui/vitest.config.js +38 -0
- package/package.json +16 -9
- package/infrastructure/app-handler-helpers.js +0 -57
- package/infrastructure/backend-utils.js +0 -90
- package/infrastructure/routers/auth.js +0 -26
- package/infrastructure/routers/integration-defined-routers.js +0 -37
- package/infrastructure/routers/middleware/loadUser.js +0 -15
- package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
- package/infrastructure/routers/user.js +0 -41
- package/infrastructure/routers/websocket.js +0 -55
- package/infrastructure/workers/integration-defined-workers.js +0 -24
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* Monitoring Dashboard Styles */
|
|
2
|
+
.monitoring-dashboard {
|
|
3
|
+
@apply p-6 max-w-7xl mx-auto;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/* Status indicators */
|
|
7
|
+
.status-indicator {
|
|
8
|
+
@apply inline-block w-3 h-3 rounded-full;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.status-indicator.success {
|
|
12
|
+
@apply bg-green-500;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.status-indicator.warning {
|
|
16
|
+
@apply bg-yellow-500;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.status-indicator.error {
|
|
20
|
+
@apply bg-red-500;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.status-indicator.inactive {
|
|
24
|
+
@apply bg-gray-400;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Metric cards */
|
|
28
|
+
.metric-card {
|
|
29
|
+
@apply border rounded-lg p-4 bg-white shadow-sm hover:shadow-md transition-shadow;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.metric-value {
|
|
33
|
+
@apply text-2xl font-mono font-bold;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.metric-label {
|
|
37
|
+
@apply text-sm text-gray-600 mb-1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Progress bars for charts */
|
|
41
|
+
.progress-bar {
|
|
42
|
+
@apply w-full bg-gray-200 rounded-full overflow-hidden;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.progress-fill {
|
|
46
|
+
@apply h-full transition-all duration-300 ease-in-out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* Health indicators */
|
|
50
|
+
.health-good {
|
|
51
|
+
@apply text-green-600;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.health-warning {
|
|
55
|
+
@apply text-yellow-600;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.health-critical {
|
|
59
|
+
@apply text-red-600;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* Responsive grid layouts */
|
|
63
|
+
.metrics-grid {
|
|
64
|
+
@apply grid gap-4;
|
|
65
|
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.metrics-grid-2 {
|
|
69
|
+
@apply grid grid-cols-1 md:grid-cols-2 gap-4;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.metrics-grid-3 {
|
|
73
|
+
@apply grid grid-cols-1 md:grid-cols-3 gap-4;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.metrics-grid-4 {
|
|
77
|
+
@apply grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Animation for real-time updates */
|
|
81
|
+
@keyframes pulse-update {
|
|
82
|
+
0% { background-color: rgba(59, 130, 246, 0.1); }
|
|
83
|
+
50% { background-color: rgba(59, 130, 246, 0.2); }
|
|
84
|
+
100% { background-color: transparent; }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.metric-updated {
|
|
88
|
+
animation: pulse-update 1s ease-in-out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Loading states */
|
|
92
|
+
.metric-loading {
|
|
93
|
+
@apply animate-pulse bg-gray-200 rounded;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* Error states */
|
|
97
|
+
.metric-error {
|
|
98
|
+
@apply border-red-300 bg-red-50 text-red-700;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* Success states */
|
|
102
|
+
.metric-success {
|
|
103
|
+
@apply border-green-300 bg-green-50 text-green-700;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* Warning states */
|
|
107
|
+
.metric-warning {
|
|
108
|
+
@apply border-yellow-300 bg-yellow-50 text-yellow-700;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Chart containers */
|
|
112
|
+
.chart-container {
|
|
113
|
+
@apply w-full h-64 flex items-center justify-center;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.chart-placeholder {
|
|
117
|
+
@apply text-gray-400 text-center;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Real-time indicators */
|
|
121
|
+
.real-time-indicator {
|
|
122
|
+
@apply inline-flex items-center gap-1 text-xs text-green-600;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.real-time-indicator::before {
|
|
126
|
+
content: '';
|
|
127
|
+
@apply w-2 h-2 bg-green-500 rounded-full animate-pulse;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Latency visualization */
|
|
131
|
+
.latency-bar {
|
|
132
|
+
@apply flex h-6 rounded overflow-hidden;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.latency-segment {
|
|
136
|
+
@apply flex items-center justify-center text-xs text-white font-mono;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Connection status */
|
|
140
|
+
.connection-status {
|
|
141
|
+
@apply flex items-center gap-2 text-sm;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.connection-dot {
|
|
145
|
+
@apply w-2 h-2 rounded-full;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.connection-dot.connected {
|
|
149
|
+
@apply bg-green-500 animate-pulse;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.connection-dot.disconnected {
|
|
153
|
+
@apply bg-red-500;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.connection-dot.connecting {
|
|
157
|
+
@apply bg-yellow-500 animate-spin;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Monitoring dashboard specific overrides */
|
|
161
|
+
.monitoring-dashboard .card {
|
|
162
|
+
@apply border border-gray-200 rounded-lg bg-white shadow-sm;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.monitoring-dashboard .card:hover {
|
|
166
|
+
@apply shadow-md;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Navigation tabs */
|
|
170
|
+
.monitoring-nav {
|
|
171
|
+
@apply flex gap-2 mb-6;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.monitoring-nav button {
|
|
175
|
+
@apply px-4 py-2 rounded text-sm font-medium transition-colors;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.monitoring-nav button.active {
|
|
179
|
+
@apply bg-blue-600 text-white;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.monitoring-nav button:not(.active) {
|
|
183
|
+
@apply bg-gray-100 text-gray-700 hover:bg-gray-200;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* Responsive breakpoints */
|
|
187
|
+
@media (max-width: 768px) {
|
|
188
|
+
.monitoring-dashboard {
|
|
189
|
+
@apply p-4;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.metrics-grid-4 {
|
|
193
|
+
@apply grid-cols-1;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.metrics-grid-3 {
|
|
197
|
+
@apply grid-cols-1;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.metrics-grid-2 {
|
|
201
|
+
@apply grid-cols-1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* Dark mode support (future enhancement) */
|
|
206
|
+
@media (prefers-color-scheme: dark) {
|
|
207
|
+
.monitoring-dashboard {
|
|
208
|
+
@apply text-gray-100;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.monitoring-dashboard .card {
|
|
212
|
+
@apply bg-gray-800 border-gray-700;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.metric-label {
|
|
216
|
+
@apply text-gray-400;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const ThemeContext = createContext({
|
|
4
|
+
theme: 'system',
|
|
5
|
+
setTheme: () => null,
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
export function ThemeProvider({ children, defaultTheme = 'system', storageKey = 'frigg-ui-theme', ...props }) {
|
|
9
|
+
const [theme, setTheme] = useState(
|
|
10
|
+
() => localStorage.getItem(storageKey) || defaultTheme
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const root = window.document.documentElement
|
|
15
|
+
|
|
16
|
+
root.classList.remove('light', 'dark')
|
|
17
|
+
|
|
18
|
+
if (theme === 'system') {
|
|
19
|
+
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
20
|
+
? 'dark'
|
|
21
|
+
: 'light'
|
|
22
|
+
|
|
23
|
+
root.classList.add(systemTheme)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
root.classList.add(theme)
|
|
28
|
+
}, [theme])
|
|
29
|
+
|
|
30
|
+
const value = {
|
|
31
|
+
theme,
|
|
32
|
+
setTheme: (theme) => {
|
|
33
|
+
localStorage.setItem(storageKey, theme)
|
|
34
|
+
setTheme(theme)
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ThemeContext.Provider {...props} value={value}>
|
|
40
|
+
{children}
|
|
41
|
+
</ThemeContext.Provider>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const useTheme = () => {
|
|
46
|
+
const context = useContext(ThemeContext)
|
|
47
|
+
|
|
48
|
+
if (context === undefined)
|
|
49
|
+
throw new Error('useTheme must be used within a ThemeProvider')
|
|
50
|
+
|
|
51
|
+
return context
|
|
52
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Moon, Sun, Monitor } from 'lucide-react'
|
|
3
|
+
import {
|
|
4
|
+
DropdownMenu,
|
|
5
|
+
DropdownMenuContent,
|
|
6
|
+
DropdownMenuItem,
|
|
7
|
+
DropdownMenuTrigger,
|
|
8
|
+
} from './ui/dropdown-menu'
|
|
9
|
+
import { useTheme } from './theme-provider'
|
|
10
|
+
|
|
11
|
+
export function ThemeToggle() {
|
|
12
|
+
const { theme, setTheme } = useTheme()
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<DropdownMenu>
|
|
16
|
+
<DropdownMenuTrigger asChild>
|
|
17
|
+
<button className="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-10 w-10">
|
|
18
|
+
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
|
19
|
+
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
|
20
|
+
<span className="sr-only">Toggle theme</span>
|
|
21
|
+
</button>
|
|
22
|
+
</DropdownMenuTrigger>
|
|
23
|
+
<DropdownMenuContent align="end">
|
|
24
|
+
<DropdownMenuItem onClick={() => setTheme('light')}>
|
|
25
|
+
<Sun className="mr-2 h-4 w-4" />
|
|
26
|
+
<span>Light</span>
|
|
27
|
+
</DropdownMenuItem>
|
|
28
|
+
<DropdownMenuItem onClick={() => setTheme('dark')}>
|
|
29
|
+
<Moon className="mr-2 h-4 w-4" />
|
|
30
|
+
<span>Dark</span>
|
|
31
|
+
</DropdownMenuItem>
|
|
32
|
+
<DropdownMenuItem onClick={() => setTheme('system')}>
|
|
33
|
+
<Monitor className="mr-2 h-4 w-4" />
|
|
34
|
+
<span>System</span>
|
|
35
|
+
</DropdownMenuItem>
|
|
36
|
+
</DropdownMenuContent>
|
|
37
|
+
</DropdownMenu>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
const badgeVariants = cva(
|
|
7
|
+
"inline-flex items-center border px-2.5 py-0.5 text-xs font-semibold transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-0 rounded-sm",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default:
|
|
12
|
+
"border-primary/20 bg-primary text-primary-foreground shadow-sm hover:bg-primary/80",
|
|
13
|
+
secondary:
|
|
14
|
+
"border-secondary/20 bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
15
|
+
destructive:
|
|
16
|
+
"border-destructive/20 bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/80",
|
|
17
|
+
outline: "text-foreground border-2",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
variant: "default",
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export interface BadgeProps
|
|
27
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
28
|
+
VariantProps<typeof badgeVariants> {}
|
|
29
|
+
|
|
30
|
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
31
|
+
return (
|
|
32
|
+
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { Badge, badgeVariants }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
import { Button } from './button'
|
|
5
|
+
|
|
6
|
+
describe('Button Component', () => {
|
|
7
|
+
it('renders button with text', () => {
|
|
8
|
+
render(<Button>Click me</Button>)
|
|
9
|
+
|
|
10
|
+
expect(screen.getByRole('button', { name: /click me/i })).toBeInTheDocument()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('handles click events', async () => {
|
|
14
|
+
const user = userEvent.setup()
|
|
15
|
+
const handleClick = vi.fn()
|
|
16
|
+
|
|
17
|
+
render(<Button onClick={handleClick}>Click me</Button>)
|
|
18
|
+
|
|
19
|
+
await user.click(screen.getByRole('button'))
|
|
20
|
+
|
|
21
|
+
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('applies variant classes correctly', () => {
|
|
25
|
+
render(<Button variant="destructive">Delete</Button>)
|
|
26
|
+
|
|
27
|
+
const button = screen.getByRole('button')
|
|
28
|
+
expect(button).toHaveClass('bg-destructive')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('applies size classes correctly', () => {
|
|
32
|
+
render(<Button size="sm">Small</Button>)
|
|
33
|
+
|
|
34
|
+
const button = screen.getByRole('button')
|
|
35
|
+
expect(button).toHaveClass('h-8') // sm size uses h-8, not h-9
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('can be disabled', () => {
|
|
39
|
+
render(<Button disabled>Disabled</Button>)
|
|
40
|
+
|
|
41
|
+
const button = screen.getByRole('button')
|
|
42
|
+
expect(button).toBeDisabled()
|
|
43
|
+
expect(button).toHaveClass('disabled:pointer-events-none')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('renders as child component when asChild is true', () => {
|
|
47
|
+
render(
|
|
48
|
+
<Button asChild>
|
|
49
|
+
<a href="/test">Link Button</a>
|
|
50
|
+
</Button>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
expect(screen.getByRole('link')).toBeInTheDocument()
|
|
54
|
+
expect(screen.getByText('Link Button')).toBeInTheDocument()
|
|
55
|
+
})
|
|
56
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-0 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 rounded-sm",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default:
|
|
13
|
+
"bg-primary text-primary-foreground shadow-md hover:bg-primary/90 border border-primary/20",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 border border-destructive/20",
|
|
16
|
+
outline:
|
|
17
|
+
"border-2 border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground hover:border-accent",
|
|
18
|
+
secondary:
|
|
19
|
+
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80 border border-secondary/20",
|
|
20
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "h-9 px-4 py-2",
|
|
25
|
+
sm: "h-8 px-3 text-xs",
|
|
26
|
+
lg: "h-10 px-8",
|
|
27
|
+
icon: "h-9 w-9",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
variant: "default",
|
|
32
|
+
size: "default",
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
export interface ButtonProps
|
|
38
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
39
|
+
VariantProps<typeof buttonVariants> {
|
|
40
|
+
asChild?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
44
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
45
|
+
const Comp = asChild ? Slot : "button"
|
|
46
|
+
return (
|
|
47
|
+
<Comp
|
|
48
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
49
|
+
ref={ref}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
Button.displayName = "Button"
|
|
56
|
+
|
|
57
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const Card = React.forwardRef<
|
|
6
|
+
HTMLDivElement,
|
|
7
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
8
|
+
>(({ className, ...props }, ref) => (
|
|
9
|
+
<div
|
|
10
|
+
ref={ref}
|
|
11
|
+
className={cn(
|
|
12
|
+
"border-2 bg-card text-card-foreground shadow-lg rounded-sm",
|
|
13
|
+
className
|
|
14
|
+
)}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
))
|
|
18
|
+
Card.displayName = "Card"
|
|
19
|
+
|
|
20
|
+
const CardHeader = React.forwardRef<
|
|
21
|
+
HTMLDivElement,
|
|
22
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
23
|
+
>(({ className, ...props }, ref) => (
|
|
24
|
+
<div
|
|
25
|
+
ref={ref}
|
|
26
|
+
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
))
|
|
30
|
+
CardHeader.displayName = "CardHeader"
|
|
31
|
+
|
|
32
|
+
const CardTitle = React.forwardRef<
|
|
33
|
+
HTMLDivElement,
|
|
34
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
35
|
+
>(({ className, ...props }, ref) => (
|
|
36
|
+
<div
|
|
37
|
+
ref={ref}
|
|
38
|
+
className={cn("font-semibold leading-none tracking-tight", className)}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
))
|
|
42
|
+
CardTitle.displayName = "CardTitle"
|
|
43
|
+
|
|
44
|
+
const CardDescription = React.forwardRef<
|
|
45
|
+
HTMLDivElement,
|
|
46
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
47
|
+
>(({ className, ...props }, ref) => (
|
|
48
|
+
<div
|
|
49
|
+
ref={ref}
|
|
50
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
))
|
|
54
|
+
CardDescription.displayName = "CardDescription"
|
|
55
|
+
|
|
56
|
+
const CardContent = React.forwardRef<
|
|
57
|
+
HTMLDivElement,
|
|
58
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
59
|
+
>(({ className, ...props }, ref) => (
|
|
60
|
+
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
|
61
|
+
))
|
|
62
|
+
CardContent.displayName = "CardContent"
|
|
63
|
+
|
|
64
|
+
const CardFooter = React.forwardRef<
|
|
65
|
+
HTMLDivElement,
|
|
66
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
67
|
+
>(({ className, ...props }, ref) => (
|
|
68
|
+
<div
|
|
69
|
+
ref={ref}
|
|
70
|
+
className={cn("flex items-center p-6 pt-0", className)}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
))
|
|
74
|
+
CardFooter.displayName = "CardFooter"
|
|
75
|
+
|
|
76
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|