-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
368 lines (314 loc) · 14.8 KB
/
index.html
File metadata and controls
368 lines (314 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SGDS Playground - Component Examples</title>
<script type="module" src="../src/index.ts"></script>
<link href="./src/themes/day.css" rel="stylesheet" type="text/css" />
<link href="./src/css/sgds.css" rel="stylesheet" type="text/css" />
<link href="./playground/css/utility.css" rel="stylesheet" type="text/css" />
<style>
* {
box-sizing: border-box;
}
</style>
</head>
<body class="sgds:bg-default sgds:text-default">
<sgds-masthead fluid></sgds-masthead>
<sgds-mainnav fluid id="main-nav">
<strong slot="brand">SGDS Playground</strong>
</sgds-mainnav>
<div class="sgds-container sgds:min-h-[calc(100vh-108px)]">
<div class="sgds:py-xl">
<div class="sgds:mb-xl">
<h1 class="sgds:text-5-xl sgds:font-bold sgds:mb-4">Component Examples</h1>
<p class="sgds:text-lg sgds:text-subtle">
Explore all available Singapore Design System web components. Click on any component below to view
interactive examples, code samples, and usage patterns.
</p>
</div>
<div class="sgds:flex sgds:gap-md sgds:items-end sgds:mb-2-xl">
<sgds-input
class="sgds:w-full"
id="search-input"
type="search"
label="Search"
placeholder="Search by title..."
clearable
>
<sgds-icon slot="prefix" name="search"></sgds-icon>
</sgds-input>
<sgds-select id="category-filter" label="Category" placeholder="All categories" clearable> </sgds-select>
</div>
<div id="search-results" class="sgds-grid" style="display: none"></div>
<div id="content"></div>
</div>
</div>
<sgds-footer></sgds-footer>
<script type="module">
const categoryDescriptions = {
null: "Core components for building user interfaces and forms.",
pattern: "Atomic typography and layout patterns used as building blocks.",
blocks: "Section-level blocks combining components into reusable page sections.",
templates: "Full page templates assembled from blocks for common page types.",
layouts: "Pre-built page layouts and templates for common application patterns.",
patterns: "Reusable pattern examples combining multiple components.",
typography: "Typography examples and text styling demonstrations.",
utility: "Utility classes and styling examples.",
css: "CSS examples and styling references."
};
function generateDescription(filename) {
const title = filename.replace(".html", "");
const descriptions = {
Button: "Primary action button with multiple variants, tones, and sizes.",
Input: "Text input field with validation, error states, and helper text.",
Select: "Dropdown selection field with native and customizable options.",
Combobox: "Searchable dropdown with autocomplete functionality.",
Datepicker: "Interactive date selection with calendar interface.",
Form: "Complete form examples with validation and submission.",
noValidateForm: "Form examples without built-in validation.",
Table: "Structured data display with headers and rows.",
Pagination: "Multi-variant pagination for navigating large datasets.",
Badge: "Label component for status, counts, and categories.",
DescriptionList: "Semantic list for terms and definitions.",
Breadcrumb: "Hierarchical navigation showing page location in site structure.",
Link: "Hyperlink component with various styling options.",
Dropdown: "Menu dropdown with nested items and actions.",
Mainnav: "Primary navigation bar for application header.",
header: "Page header component with masthead integration.",
Masthead: "Top-level branding and navigation component.",
Footer: "Page footer with links and information sections.",
Card: "Container for grouped content with consistent styling.",
Drawer: "Side panel for navigation or additional content.",
IconCard: "Card with icon, title, and description for feature display.",
ImageCard: "Card with image, title, and metadata display.",
ThumbnailCard: "Compact card with thumbnail image and text.",
IconList: "List of items with icons for feature lists.",
Toast: "Non-intrusive notification messages.",
Modal: "Dialog box for important user interactions.",
Spinner: "Loading indicator for asynchronous operations.",
SystemBanner: "Alert banner for system-wide messages.",
IconButton: "Button displaying only an icon for compact UI.",
CloseButton: "Specialized button for dismissing elements.",
anchor: "Skip link and anchor navigation utilities."
};
return descriptions[title] || `${title} component examples`;
}
function buildMainnavDropdowns(files) {
const nav = document.getElementById("main-nav");
const folders = {};
const rootFiles = [];
for (const file of files) {
if (!file.folder) {
rootFiles.push(file);
continue;
}
if (!folders[file.folder]) folders[file.folder] = [];
folders[file.folder].push(file);
}
if (rootFiles.length > 0) {
const dropdown = document.createElement("sgds-mainnav-dropdown");
const toggler = document.createElement("span");
toggler.setAttribute("slot", "toggler");
toggler.textContent = "Components";
dropdown.appendChild(toggler);
for (const file of rootFiles) {
const item = document.createElement("sgds-dropdown-item");
const link = document.createElement("a");
link.href = file.url;
link.textContent = file.title;
item.appendChild(link);
dropdown.appendChild(item);
}
nav.appendChild(dropdown);
}
const navFolders = ["pattern", "blocks", "templates", "layouts", "typography", "utility"];
for (const folder of navFolders) {
const folderFiles = folders[folder];
if (!folderFiles || folderFiles.length === 0) continue;
const dropdown = document.createElement("sgds-mainnav-dropdown");
const toggler = document.createElement("span");
toggler.setAttribute("slot", "toggler");
toggler.textContent = folder.charAt(0).toUpperCase() + folder.slice(1);
dropdown.appendChild(toggler);
for (const file of folderFiles) {
const item = document.createElement("sgds-dropdown-item");
const link = document.createElement("a");
link.href = file.url;
link.textContent = file.title;
item.appendChild(link);
dropdown.appendChild(item);
}
nav.appendChild(dropdown);
}
}
let allFiles = [];
let activeCategory = "";
let activeQuery = "";
function buildCardElement(file) {
const folderDisplayName = file.folder
? file.folder.charAt(0).toUpperCase() + file.folder.slice(1)
: "Components";
const col = document.createElement("div");
col.className = "sgds-col-3 sgds-col-sm-3 sgds-col-md-3 sgds-col-lg-3 sgds-col-xl-3 sgds-col-2-xl-3";
const card = document.createElement("sgds-card");
card.setAttribute("stretchedLink", "");
const categoryTag = document.createElement("sgds-badge");
categoryTag.setAttribute("outlined", "");
categoryTag.setAttribute("slot", "upper");
categoryTag.textContent = folderDisplayName;
const title = document.createElement("span");
title.setAttribute("slot", "title");
title.textContent = file.title;
const description = document.createElement("span");
description.setAttribute("slot", "description");
description.textContent = generateDescription(file.title);
const footer = document.createElement("sgds-link");
footer.setAttribute("slot", "footer");
const link = document.createElement("a");
link.href = file.url;
link.innerHTML = 'View Examples <sgds-icon name="arrow-right"></sgds-icon>';
footer.appendChild(link);
card.appendChild(categoryTag);
card.appendChild(title);
card.appendChild(description);
card.appendChild(footer);
col.appendChild(card);
return col;
}
function applyFilters() {
const searchResults = document.getElementById("search-results");
const contentContainer = document.getElementById("content");
const hasFilter = activeQuery.trim() || activeCategory;
if (!hasFilter) {
searchResults.style.display = "none";
searchResults.innerHTML = "";
contentContainer.style.display = "";
return;
}
const lowerQuery = activeQuery.toLowerCase();
const matched = allFiles.filter(f => {
const matchesQuery = !lowerQuery || f.title.toLowerCase().includes(lowerQuery);
const fileCategory = f.folder || "components";
const matchesCategory = !activeCategory || fileCategory === activeCategory;
return matchesQuery && matchesCategory;
});
contentContainer.style.display = "none";
searchResults.innerHTML = "";
if (matched.length === 0) {
searchResults.style.display = "block";
searchResults.innerHTML = '<p class="sgds:text-subtle">No results found.</p>';
return;
}
searchResults.style.display = "";
for (const file of matched) {
searchResults.appendChild(buildCardElement(file));
}
}
async function loadPlaygroundFiles() {
try {
console.log("Fetching playground files...");
const response = await fetch("/api/playground-files");
console.log("Response status:", response.status);
if (!response.ok) {
const errorText = await response.text();
console.error("API error:", errorText);
throw new Error(`API returned ${response.status}: ${errorText}`);
}
const files = await response.json();
console.log("Found files:", files);
allFiles = files;
const categories = [...new Set(files.map(f => f.folder || "components"))];
const categoryFilter = document.getElementById("category-filter");
const allOption = document.createElement("sgds-select-option");
allOption.setAttribute("value", "");
allOption.textContent = "All";
categoryFilter.appendChild(allOption);
for (const cat of categories) {
const option = document.createElement("sgds-select-option");
option.setAttribute("value", cat);
option.textContent = cat.charAt(0).toUpperCase() + cat.slice(1);
categoryFilter.appendChild(option);
}
const searchInput = document.getElementById("search-input");
searchInput.addEventListener("sgds-input", e => {
activeQuery = e.target.value;
applyFilters();
});
searchInput.addEventListener("sgds-clear", () => {
activeQuery = "";
applyFilters();
});
categoryFilter.addEventListener("sgds-change", e => {
activeCategory = e.target.value || "";
applyFilters();
});
categoryFilter.addEventListener("sgds-clear", () => {
activeCategory = "";
applyFilters();
});
buildMainnavDropdowns(files);
// Group files by folder
const groupedByFolder = files.reduce((acc, file) => {
const folder = file.folder;
if (!acc[folder]) {
acc[folder] = [];
}
acc[folder].push(file);
return acc;
}, {});
// Sort categories by appearance order
const categoryOrder = [null, "pattern", "blocks", "templates", "layouts", "patterns", "typography", "utility", "css"];
const sortedCategories = categoryOrder.filter(cat => groupedByFolder[cat]);
// Render content
const contentContainer = document.getElementById("content");
if (sortedCategories.length === 0) {
contentContainer.innerHTML = '<div class="sgds:text-muted">No playground files found</div>';
return;
}
const accordion = document.createElement("sgds-accordion");
accordion.setAttribute("allowMultiple", "");
accordion.setAttribute("variant", "border");
for (const folder of sortedCategories) {
const filesInCategory = groupedByFolder[folder];
const folderDisplayName = folder ? folder.charAt(0).toUpperCase() + folder.slice(1) : "Components";
const accordionItem = document.createElement("sgds-accordion-item");
accordionItem.setAttribute("open", "");
const header = document.createElement("div");
header.setAttribute("slot", "header");
header.textContent = `${folderDisplayName} (${filesInCategory.length})`;
const content = document.createElement("div");
content.setAttribute("slot", "content");
const grid = document.createElement("div");
grid.className = "sgds-grid";
for (const file of filesInCategory) {
grid.appendChild(buildCardElement(file));
}
content.appendChild(grid);
accordionItem.appendChild(header);
accordionItem.appendChild(content);
accordion.appendChild(accordionItem);
}
contentContainer.appendChild(accordion);
} catch (error) {
console.error("Failed to load playground files:", error);
const contentContainer = document.getElementById("content");
const alert = document.createElement("sgds-alert");
alert.setAttribute("variant", "danger");
alert.setAttribute("dismissible", "false");
const title = document.createElement("span");
title.setAttribute("slot", "title");
title.textContent = "Error loading playground files";
const message = document.createElement("span");
message.setAttribute("slot", "description");
message.innerHTML = `${error.message}<br/><small>Check browser console for more details.</small>`;
alert.appendChild(title);
alert.appendChild(message);
contentContainer.appendChild(alert);
}
}
document.addEventListener("DOMContentLoaded", loadPlaygroundFiles);
</script>
</body>
</html>