create-vizcraft-playground 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.
Files changed (49) hide show
  1. package/index.js +171 -0
  2. package/package.json +44 -0
  3. package/template/.github/skills/vizcraft-playground/SKILL.md +573 -0
  4. package/template/README.md +59 -0
  5. package/template/eslint.config.js +23 -0
  6. package/template/index.html +13 -0
  7. package/template/package.json +37 -0
  8. package/template/public/vite.svg +1 -0
  9. package/template/scripts/generate-plugin.js +594 -0
  10. package/template/scripts/init-playground.js +119 -0
  11. package/template/src/App.scss +137 -0
  12. package/template/src/App.tsx +72 -0
  13. package/template/src/assets/react.svg +1 -0
  14. package/template/src/components/InfoModal/InfoModal.scss +211 -0
  15. package/template/src/components/InfoModal/InfoModal.tsx +85 -0
  16. package/template/src/components/Landing/Landing.scss +85 -0
  17. package/template/src/components/Landing/Landing.tsx +55 -0
  18. package/template/src/components/Shell.tsx +144 -0
  19. package/template/src/components/StepIndicator/StepIndicator.scss +151 -0
  20. package/template/src/components/StepIndicator/StepIndicator.tsx +73 -0
  21. package/template/src/components/VizInfoBeacon/VizInfoBeacon.scss +41 -0
  22. package/template/src/components/VizInfoBeacon/VizInfoBeacon.tsx +157 -0
  23. package/template/src/components/plugin-kit/CanvasStage.tsx +30 -0
  24. package/template/src/components/plugin-kit/ConceptPills.tsx +55 -0
  25. package/template/src/components/plugin-kit/PluginLayout.tsx +41 -0
  26. package/template/src/components/plugin-kit/SidePanel.tsx +69 -0
  27. package/template/src/components/plugin-kit/StageHeader.tsx +35 -0
  28. package/template/src/components/plugin-kit/StatBadge.tsx +35 -0
  29. package/template/src/components/plugin-kit/index.ts +42 -0
  30. package/template/src/components/plugin-kit/plugin-kit.scss +241 -0
  31. package/template/src/components/plugin-kit/useConceptModal.tsx +51 -0
  32. package/template/src/index.scss +81 -0
  33. package/template/src/main.tsx +14 -0
  34. package/template/src/playground.config.ts +27 -0
  35. package/template/src/plugins/hello-world/concepts.tsx +70 -0
  36. package/template/src/plugins/hello-world/helloWorldSlice.ts +29 -0
  37. package/template/src/plugins/hello-world/index.ts +48 -0
  38. package/template/src/plugins/hello-world/main.scss +32 -0
  39. package/template/src/plugins/hello-world/main.tsx +144 -0
  40. package/template/src/plugins/hello-world/useHelloWorldAnimation.ts +99 -0
  41. package/template/src/registry.ts +73 -0
  42. package/template/src/store/slices/simulationSlice.ts +47 -0
  43. package/template/src/store/store.ts +13 -0
  44. package/template/src/types/ModelPlugin.ts +55 -0
  45. package/template/src/utils/random.ts +11 -0
  46. package/template/tsconfig.app.json +35 -0
  47. package/template/tsconfig.json +7 -0
  48. package/template/tsconfig.node.json +26 -0
  49. package/template/vite.config.ts +7 -0
@@ -0,0 +1,119 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import readline from "readline";
4
+ import { fileURLToPath } from "url";
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const root = path.join(__dirname, "..");
9
+
10
+ // ── Readline helpers ───────────────────────────────────────
11
+ const rl = readline.createInterface({
12
+ input: process.stdin,
13
+ output: process.stdout,
14
+ });
15
+
16
+ const ask = (question, fallback) =>
17
+ new Promise((resolve) => {
18
+ const suffix = fallback ? ` (${fallback}): ` : ": ";
19
+ rl.question(question + suffix, (answer) => {
20
+ resolve(answer.trim() || fallback || "");
21
+ });
22
+ });
23
+
24
+ // ── Helpers ────────────────────────────────────────────────
25
+ const toSlug = (str) =>
26
+ str
27
+ .toLowerCase()
28
+ .replace(/[^a-z0-9]+/g, "-")
29
+ .replace(/(^-|-$)/g, "");
30
+
31
+ // ── Main ───────────────────────────────────────────────────
32
+ async function main() {
33
+ console.log("");
34
+ console.log("╔═══════════════════════════════════════════════╗");
35
+ console.log("║ VizCraft Playground — Init Wizard ║");
36
+ console.log("╚═══════════════════════════════════════════════╝");
37
+ console.log("");
38
+ console.log(" Configure your playground branding.");
39
+ console.log("");
40
+
41
+ const title = await ask(" Playground title", "My Playground");
42
+ const subtitle = await ask(
43
+ " Subtitle (one-liner for the landing page)",
44
+ "Explore interactive visualizations.",
45
+ );
46
+ const accent = await ask(" Primary accent colour (hex)", "#3b82f6");
47
+ const slug = toSlug(title);
48
+
49
+ console.log("");
50
+
51
+ // ── 1. Write playground.config.ts ──────────────────────
52
+ const configPath = path.join(root, "src/playground.config.ts");
53
+ const configContent = `/* ═══════════════════════════════════════════════════════
54
+ * Playground Configuration
55
+ *
56
+ * Single source of truth for branding & metadata.
57
+ * Run \`npm run init\` to regenerate this file interactively,
58
+ * or edit the values below directly.
59
+ * ═══════════════════════════════════════════════════════ */
60
+
61
+ export interface PlaygroundConfig {
62
+ /** Project slug (kebab-case), used in package.json name */
63
+ name: string;
64
+ /** Display title shown on the landing page */
65
+ title: string;
66
+ /** One-liner shown below the title on the landing page */
67
+ subtitle: string;
68
+ /** Primary accent colour (hex) */
69
+ accent: string;
70
+ }
71
+
72
+ const playgroundConfig: PlaygroundConfig = {
73
+ name: "${slug}",
74
+ title: "${title.replace(/"/g, '\\"')}",
75
+ subtitle:
76
+ "${subtitle.replace(/"/g, '\\"')}",
77
+ accent: "${accent}",
78
+ };
79
+
80
+ export default playgroundConfig;
81
+ `;
82
+ fs.writeFileSync(configPath, configContent);
83
+ console.log(" ✔ src/playground.config.ts");
84
+
85
+ // ── 2. Update package.json name ────────────────────────
86
+ const pkgPath = path.join(root, "package.json");
87
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
88
+ pkg.name = slug;
89
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
90
+ console.log(" ✔ package.json (name → " + slug + ")");
91
+
92
+ // ── 3. Update index.html <title> ──────────────────────
93
+ const htmlPath = path.join(root, "index.html");
94
+ let html = fs.readFileSync(htmlPath, "utf-8");
95
+ html = html.replace(/<title>.*<\/title>/, "<title>" + title + "</title>");
96
+ fs.writeFileSync(htmlPath, html);
97
+ console.log(" ✔ index.html (title → " + title + ")");
98
+
99
+ // ── 4. Update README headline + subtitle ───────────────
100
+ const readmePath = path.join(root, "README.md");
101
+ if (fs.existsSync(readmePath)) {
102
+ let readme = fs.readFileSync(readmePath, "utf-8");
103
+ readme = readme.replace(/^# .*$/m, "# " + title);
104
+ fs.writeFileSync(readmePath, readme);
105
+ console.log(" ✔ README.md");
106
+ }
107
+
108
+ console.log("");
109
+ console.log(" All done! Run `npm run dev` to start.");
110
+ console.log("");
111
+
112
+ rl.close();
113
+ }
114
+
115
+ main().catch((err) => {
116
+ console.error(err);
117
+ rl.close();
118
+ process.exit(1);
119
+ });
@@ -0,0 +1,137 @@
1
+ .app {
2
+ width: 100%;
3
+ height: 100vh;
4
+ margin: 0;
5
+ padding: 0;
6
+ box-sizing: border-box;
7
+ overflow: hidden;
8
+
9
+ display: flex;
10
+ flex-direction: column;
11
+
12
+ /* dark slate */
13
+ color: #e5e7eb;
14
+ /* light gray */
15
+ font-family:
16
+ system-ui,
17
+ -apple-system,
18
+ BlinkMacSystemFont,
19
+ "Segoe UI",
20
+ sans-serif;
21
+ background-color: #111827; // Gray-900
22
+ }
23
+
24
+ .app-header {
25
+ padding: 1rem 2rem;
26
+ background-color: #1f2937; // Gray-800
27
+ border-bottom: 1px solid #374151; // Gray-700
28
+ flex-shrink: 0;
29
+
30
+ h1 {
31
+ margin: 0;
32
+ font-size: 1.5rem;
33
+ color: #f3f4f6;
34
+ }
35
+
36
+ p {
37
+ margin: 0.25rem 0 0;
38
+ color: #9ca3af;
39
+ font-size: 0.875rem;
40
+ }
41
+
42
+ &__nav {
43
+ display: flex;
44
+ align-items: center;
45
+ gap: 1rem;
46
+ }
47
+
48
+ &__back {
49
+ background: none;
50
+ border: 1px solid #475569;
51
+ color: #e2e8f0;
52
+ font-size: 1.1rem;
53
+ width: 36px;
54
+ height: 36px;
55
+ border-radius: 8px;
56
+ cursor: pointer;
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ flex-shrink: 0;
61
+ transition:
62
+ background 0.15s,
63
+ border-color 0.15s;
64
+ padding: 0;
65
+
66
+ &:hover {
67
+ background: #334155;
68
+ border-color: #64748b;
69
+ }
70
+ }
71
+
72
+ &__text {
73
+ min-width: 0;
74
+ }
75
+
76
+ &__breadcrumb {
77
+ display: flex;
78
+ align-items: center;
79
+ gap: 0.5rem;
80
+ font-size: 1.25rem;
81
+ font-weight: 600;
82
+ color: #f3f4f6;
83
+ flex-wrap: wrap;
84
+ }
85
+
86
+ &__sep {
87
+ color: #475569;
88
+ font-weight: 400;
89
+ }
90
+
91
+ &__plugin-name {
92
+ color: #e2e8f0;
93
+ }
94
+
95
+ &__category {
96
+ font-weight: 500;
97
+ }
98
+
99
+ &__select {
100
+ background: #0f172a;
101
+ color: #e2e8f0;
102
+ border: 1px solid #475569;
103
+ border-radius: 6px;
104
+ padding: 0.25rem 0.5rem;
105
+ font-size: 1rem;
106
+ font-weight: 600;
107
+ cursor: pointer;
108
+
109
+ &:hover {
110
+ border-color: #64748b;
111
+ }
112
+
113
+ &:focus {
114
+ outline: none;
115
+ border-color: #818cf8;
116
+ }
117
+ }
118
+ }
119
+
120
+ .main-content {
121
+ flex: 1;
122
+ display: flex;
123
+ flex-direction: row;
124
+ overflow: hidden;
125
+ position: relative;
126
+ }
127
+
128
+ .visualization-container {
129
+ flex: 1;
130
+ position: relative;
131
+ overflow: hidden;
132
+ display: flex;
133
+ justify-content: center;
134
+ align-items: center;
135
+ padding: 2rem;
136
+ background-color: #111827; // Gray-900
137
+ }
@@ -0,0 +1,72 @@
1
+ import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
2
+ import "./App.scss";
3
+ import Shell from "./components/Shell";
4
+ import Landing from "./components/Landing/Landing";
5
+ import { categories, findCategory, findPlugin } from "./registry";
6
+
7
+ /**
8
+ * Wrapper that resolves /:categoryId/:pluginId params and
9
+ * feeds the matching plugin into Shell.
10
+ */
11
+ function PluginRoute() {
12
+ // react-router doesn't expose useParams without a generic, so grab from URL
13
+ const [, categoryId, pluginId] = window.location.pathname.split("/");
14
+
15
+ const category = findCategory(categoryId);
16
+ const plugin = findPlugin(pluginId);
17
+
18
+ if (!category || !plugin) {
19
+ return <Navigate to="/" replace />;
20
+ }
21
+
22
+ return <Shell plugin={plugin} category={category} />;
23
+ }
24
+
25
+ /**
26
+ * Redirect bare category URLs (e.g. /system-design) to the first plugin
27
+ * inside that category.
28
+ */
29
+ function CategoryRedirect() {
30
+ const [, categoryId] = window.location.pathname.split("/");
31
+ const category = findCategory(categoryId);
32
+
33
+ if (!category || category.plugins.length === 0) {
34
+ return <Navigate to="/" replace />;
35
+ }
36
+
37
+ return <Navigate to={`/${category.id}/${category.plugins[0].id}`} replace />;
38
+ }
39
+
40
+ function App() {
41
+ // Build one Route per category (for bare-category redirects)
42
+ // and one per category/plugin pair.
43
+ return (
44
+ <BrowserRouter>
45
+ <Routes>
46
+ <Route path="/" element={<Landing />} />
47
+
48
+ {categories.map((cat) => (
49
+ <Route
50
+ key={cat.id}
51
+ path={`/${cat.id}`}
52
+ element={<CategoryRedirect />}
53
+ />
54
+ ))}
55
+
56
+ {categories.flatMap((cat) =>
57
+ cat.plugins.map((p) => (
58
+ <Route
59
+ key={`${cat.id}/${p.id}`}
60
+ path={`/${cat.id}/${p.id}`}
61
+ element={<PluginRoute />}
62
+ />
63
+ )),
64
+ )}
65
+
66
+ <Route path="*" element={<Navigate to="/" replace />} />
67
+ </Routes>
68
+ </BrowserRouter>
69
+ );
70
+ }
71
+
72
+ export default App;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
@@ -0,0 +1,211 @@
1
+ .info-modal-backdrop {
2
+ position: fixed;
3
+ inset: 0;
4
+ background: rgba(0, 0, 0, 0.72);
5
+ backdrop-filter: blur(4px);
6
+ z-index: 100;
7
+ animation: fadeIn 0.18s ease-out;
8
+ }
9
+
10
+ .info-modal {
11
+ --accent: #60a5fa;
12
+
13
+ position: fixed;
14
+ top: 50%;
15
+ left: 50%;
16
+ transform: translate(-50%, -50%);
17
+ width: min(88vw, 860px);
18
+ max-height: 82vh;
19
+ background: #1e293b;
20
+ border-radius: 16px;
21
+ box-shadow:
22
+ 0 30px 60px -12px rgba(0, 0, 0, 0.55),
23
+ 0 0 0 1px rgba(255, 255, 255, 0.06);
24
+ display: flex;
25
+ flex-direction: column;
26
+ overflow: hidden;
27
+ z-index: 101;
28
+ border: 1px solid #334155;
29
+ animation: modalSlideIn 0.22s ease-out;
30
+
31
+ &__header {
32
+ padding: 1.25rem 1.5rem;
33
+ background: #0f172a;
34
+ border-bottom: 1px solid #334155;
35
+ display: flex;
36
+ justify-content: space-between;
37
+ align-items: flex-start;
38
+ gap: 1rem;
39
+ flex-shrink: 0;
40
+ }
41
+
42
+ &__title {
43
+ margin: 0;
44
+ color: #f1f5f9;
45
+ font-size: 1.35rem;
46
+ font-weight: 700;
47
+ letter-spacing: -0.01em;
48
+ }
49
+
50
+ &__subtitle {
51
+ margin: 0.3rem 0 0;
52
+ color: #94a3b8;
53
+ font-size: 0.82rem;
54
+ }
55
+
56
+ &__close {
57
+ background: transparent;
58
+ border: none;
59
+ color: #64748b;
60
+ font-size: 1.6rem;
61
+ line-height: 1;
62
+ cursor: pointer;
63
+ padding: 0.35rem 0.5rem;
64
+ border-radius: 8px;
65
+ transition: all 0.15s;
66
+ flex-shrink: 0;
67
+
68
+ &:hover {
69
+ background: #334155;
70
+ color: #f1f5f9;
71
+ }
72
+ }
73
+
74
+ &__body {
75
+ flex: 1;
76
+ display: flex;
77
+ gap: 1.5rem;
78
+ padding: 1.5rem;
79
+ overflow-y: auto;
80
+
81
+ // Custom scrollbar
82
+ &::-webkit-scrollbar {
83
+ width: 6px;
84
+ }
85
+ &::-webkit-scrollbar-track {
86
+ background: transparent;
87
+ }
88
+ &::-webkit-scrollbar-thumb {
89
+ background: #334155;
90
+ border-radius: 3px;
91
+ }
92
+ }
93
+
94
+ &__sections {
95
+ flex: 1;
96
+ display: flex;
97
+ flex-direction: column;
98
+ gap: 1rem;
99
+ min-width: 0;
100
+ }
101
+
102
+ &__section {
103
+ --section-accent: var(--accent);
104
+ background: #0f172a;
105
+ border-radius: 12px;
106
+ border: 1px solid #1e293b;
107
+ border-left: 3px solid var(--section-accent);
108
+ padding: 1.1rem 1.25rem;
109
+ transition: border-color 0.15s;
110
+ }
111
+
112
+ &__section-title {
113
+ margin: 0 0 0.6rem;
114
+ color: var(--section-accent);
115
+ font-size: 0.95rem;
116
+ font-weight: 600;
117
+ letter-spacing: 0.01em;
118
+ }
119
+
120
+ &__section-content {
121
+ color: #cbd5e1;
122
+ font-size: 0.85rem;
123
+ line-height: 1.65;
124
+
125
+ p {
126
+ margin: 0 0 0.5rem;
127
+ &:last-child {
128
+ margin-bottom: 0;
129
+ }
130
+ }
131
+
132
+ strong {
133
+ color: #e2e8f0;
134
+ font-weight: 600;
135
+ }
136
+
137
+ code {
138
+ background: #1e293b;
139
+ color: #fbbf24;
140
+ padding: 0.15em 0.4em;
141
+ border-radius: 4px;
142
+ font-size: 0.9em;
143
+ font-family: "SF Mono", "Fira Code", monospace;
144
+ }
145
+
146
+ ul {
147
+ margin: 0.4rem 0;
148
+ padding-left: 1.2rem;
149
+
150
+ li {
151
+ margin-bottom: 0.3rem;
152
+ }
153
+ }
154
+ }
155
+
156
+ &__aside {
157
+ flex: 0 0 220px;
158
+ background: #0f172a;
159
+ border-radius: 12px;
160
+ border: 1px solid #1e293b;
161
+ padding: 1.1rem;
162
+ color: #94a3b8;
163
+ font-size: 0.8rem;
164
+ line-height: 1.6;
165
+ align-self: flex-start;
166
+
167
+ h4 {
168
+ margin: 0 0 0.6rem;
169
+ color: #e2e8f0;
170
+ font-size: 0.85rem;
171
+ }
172
+ }
173
+ }
174
+
175
+ @keyframes fadeIn {
176
+ from {
177
+ opacity: 0;
178
+ }
179
+ to {
180
+ opacity: 1;
181
+ }
182
+ }
183
+
184
+ @keyframes modalSlideIn {
185
+ from {
186
+ opacity: 0;
187
+ transform: translate(-50%, -48%);
188
+ }
189
+ to {
190
+ opacity: 1;
191
+ transform: translate(-50%, -50%);
192
+ }
193
+ }
194
+
195
+ // Responsive
196
+ @media (max-width: 700px) {
197
+ .info-modal {
198
+ width: 96vw;
199
+ max-height: 90vh;
200
+
201
+ &__body {
202
+ flex-direction: column;
203
+ padding: 1rem;
204
+ }
205
+
206
+ &__aside {
207
+ flex: none;
208
+ width: 100%;
209
+ }
210
+ }
211
+ }
@@ -0,0 +1,85 @@
1
+ import React, { useEffect } from "react";
2
+ import "./InfoModal.scss";
3
+
4
+ export interface InfoModalSection {
5
+ title: string;
6
+ content: React.ReactNode;
7
+ accent?: string;
8
+ }
9
+
10
+ export interface InfoModalProps {
11
+ isOpen: boolean;
12
+ onClose: () => void;
13
+ title: string;
14
+ subtitle?: string;
15
+ accentColor?: string;
16
+ sections: InfoModalSection[];
17
+ aside?: React.ReactNode;
18
+ }
19
+
20
+ const InfoModal: React.FC<InfoModalProps> = ({
21
+ isOpen,
22
+ onClose,
23
+ title,
24
+ subtitle,
25
+ accentColor = "#60a5fa",
26
+ sections,
27
+ aside,
28
+ }) => {
29
+ useEffect(() => {
30
+ if (!isOpen) return;
31
+ const handler = (e: KeyboardEvent) => {
32
+ if (e.key === "Escape") onClose();
33
+ };
34
+ window.addEventListener("keydown", handler);
35
+ return () => window.removeEventListener("keydown", handler);
36
+ }, [isOpen, onClose]);
37
+
38
+ if (!isOpen) return null;
39
+
40
+ return (
41
+ <>
42
+ <div className="info-modal-backdrop" onClick={onClose} />
43
+ <div
44
+ className="info-modal"
45
+ style={{ "--accent": accentColor } as React.CSSProperties}
46
+ >
47
+ <div className="info-modal__header">
48
+ <div>
49
+ <h2 className="info-modal__title">{title}</h2>
50
+ {subtitle && <p className="info-modal__subtitle">{subtitle}</p>}
51
+ </div>
52
+ <button className="info-modal__close" onClick={onClose}>
53
+ &times;
54
+ </button>
55
+ </div>
56
+
57
+ <div className="info-modal__body">
58
+ <div className="info-modal__sections">
59
+ {sections.map((section, i) => (
60
+ <div
61
+ key={i}
62
+ className="info-modal__section"
63
+ style={
64
+ section.accent
65
+ ? ({
66
+ "--section-accent": section.accent,
67
+ } as React.CSSProperties)
68
+ : undefined
69
+ }
70
+ >
71
+ <h3 className="info-modal__section-title">{section.title}</h3>
72
+ <div className="info-modal__section-content">
73
+ {section.content}
74
+ </div>
75
+ </div>
76
+ ))}
77
+ </div>
78
+ {aside && <div className="info-modal__aside">{aside}</div>}
79
+ </div>
80
+ </div>
81
+ </>
82
+ );
83
+ };
84
+
85
+ export default InfoModal;