-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.html
More file actions
470 lines (426 loc) · 12.9 KB
/
Copy pathui.html
File metadata and controls
470 lines (426 loc) · 12.9 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<style>
body {
font-family: "Inter", sans-serif;
padding: 24px;
background-color: #f3f5f7;
color: #202020;
/* text color */
}
h1 {
font-size: 24px;
font-weight: 600;
margin-bottom: 32px;
}
/* Container for the two divs */
.outer {
display: flex;
gap: 64px;
align-items: flex-start;
}
/* styling for left and right containers */
#left,
#right {
flex: 1;
min-width: 0;
}
.question-item {
/* Container for each question in the left panel */
background-color: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 16px 24px;
width: 100%;
margin: 0;
margin-bottom: 16px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
transition: background-color 0.2s ease, border-color 0.2s ease,
box-shadow 0.2s ease;
font-size: 16px;
font-weight: 600;
color: #202020;
text-align: left;
font-family: inherit;
}
.question-item.active-question-item {
/* Styling for the current question the user is answering */
border: 2px solid #562672;
background-color: #f8f0ff;
box-shadow: 0px 2px 6px rgba(86, 38, 114, 0.15);
}
.question-item.active-question-item:hover,
.question-item.active-question-item:focus-within {
border-color: #411d56;
background-color: #f5ebfe;
}
.question-text {
/* Span containing the actual question text */
overflow: hidden;
white-space: normal; /* Allow wrapping */
flex-grow: 1;
}
.selected-answer-text {
/* Span showing the selected answer for past questions */
font-weight: 400;
font-size: 14px;
color: #562672;
margin-left: 8px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
background-color: #f5ebfe;
padding: 4px 8px;
border-radius: 4px;
}
.answerButton {
background-color: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 24px;
width: 100%;
margin: 0;
margin-bottom: 16px;
box-sizing: border-box;
/* Text */
font-size: 16px;
font-weight: 600;
color: #202020;
text-align: left;
font-family: inherit;
}
.answerButton:hover,
.answerButton:focus {
background-color: #f8f8f8;
border-color: #cccccc;
box-shadow: 0px 4px 8px 0px rgba(32, 32, 32, 0.16);
}
/* Span containing the actual question text */
.text {
overflow: hidden;
white-space: normal;
display: inline-flex;
align-items: center;
}
.hidden {
display: none;
}
.visible {
display: block;
}
/* Reset button style */
#resetButton {
background-color: #ffffff;
color: #202020;
border: 1px solid #562672;
border-radius: 4px;
padding: 12px 24px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease, box-shadow 0.3s ease,
border-color 0.3s ease;
margin-top: 0;
text-align: center;
width: 150px;
position: absolute;
top: 24px;
right: 24px;
}
#resultsContainer {
background-color: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 24px;
width: 100%;
margin: 0;
margin-bottom: 16px;
box-sizing: border-box;
font-size: 16px;
font-weight: 400;
color: #202020;
text-align: left;
font-family: inherit;
}
#resultsContainer h3 {
font-size: 24px;
font-weight: 400;
}
#resultsContainer p {
font-size: 16px;
margin-bottom: 8px;
}
#hexVisual {
width: 96px;
height: 48px;
border-radius: 4px;
border-color: #202020;
border: solid 1px;
margin-top: 8px;
}
#tokenDescriptionDisplay {
color: #202020;
font-weight: 400;
font-style: italic;
white-space: pre-wrap;
}
#resetButton:hover {
background-color: #ffffff;
border-color: #411d56;
box-shadow: 0px 2px 4px 0px rgba(32, 32, 32, 0.08);
}
@media (min-width: 768px) {
.outer {
flex-direction: row;
/* Side-by-side columns */
gap: 64px;
align-items: flex-start;
/* Align to top */
}
.question-item {
font-size: 18px;
}
.answerButton {
font-size: 18px;
}
.selected-answer-text {
font-size: 16px;
}
}
</style>
<h1>Axis Token Picker</h1>
<button id="resetButton">Reset</button>
<div id="outer" class="outer">
<div id="left"></div>
<div id="right">
<div id="currentAnswersContainer" class="visible"></div>
<div id="resultsContainer" class="hidden">
<h3>Your Token Details:</h3>
<p><strong>Token Path:</strong> <span id="tokenPathDisplay"></span></p>
<p>
<strong>Figma Syntax:</strong> <span id="figmaSyntaxDisplay"></span>
</p>
<p><strong>Hex Value:</strong> <span id="tokenHexDisplay"></span></p>
<div id="hexVisual"></div>
<p>
<strong>Description:</strong> <span id="tokenDescriptionDisplay"></span>
</p>
</div>
</div>
</div>
<script src="tokenMapping.js"></script>
<script src="q&a.js"></script>
<script>
//Waits for the HTMl to fully load
document.addEventListener("DOMContentLoaded", () => {
const leftPanel = document.getElementById("left");
const currentAnswersContainer = document.getElementById(
"currentAnswersContainer"
);
const resultsContainer = document.getElementById("resultsContainer");
const resetButton = document.getElementById("resetButton");
// Result display elements
const tokenPathDisplay = document.getElementById("tokenPathDisplay");
const figmaSyntaxDisplay = document.getElementById("figmaSyntaxDisplay");
const tokenHexDisplay = document.getElementById("tokenHexDisplay");
const hexVisual = document.getElementById("hexVisual");
const tokenDescriptionDisplay = document.getElementById(
"tokenDescriptionDisplay"
);
let currentQuestionId = null; // question ID currently displayed
let currentUserAnswerPath = []; //array to store sequence of answeer IDs
let currentQuestionHistory = []; //array to store questions already answered
function findQuestionById(id) {
// Ensure allQuestions is available
if (typeof allQuestions === "undefined" || !allQuestions) {
console.error("allQuestions is not defined!");
return undefined;
}
return allQuestions.find((q) => q.id === id);
}
function setVisibility(element, show) {
if (element) {
if (show) {
element.classList.remove("hidden");
element.classList.add("visible");
} else {
element.classList.add("hidden");
element.classList.remove("visible");
}
}
}
function renderLeftPanel() {
if (!leftPanel) {
console.error("leftPanel element not found");
return;
}
leftPanel.innerHTML = ""; // Clear previous content
// Render history
currentQuestionHistory.forEach((item) => {
const historyItemDiv = document.createElement("div");
historyItemDiv.classList.add("question-item", "visible");
historyItemDiv.innerHTML = `
<span class="question-text">${item.text}</span>
<span class="selected-answer-text">${item.selectedAnswerText}</span>
`;
leftPanel.appendChild(historyItemDiv);
});
// Render current question
const currentQuestion = findQuestionById(currentQuestionId);
if (currentQuestion) {
const currentQuestionDiv = document.createElement("div");
currentQuestionDiv.classList.add(
"question-item",
"visible",
"active-question-item"
);
currentQuestionDiv.innerHTML = `<span class="question-text">${currentQuestion.text}</span>`;
leftPanel.appendChild(currentQuestionDiv);
}
}
function displayCurrentAnswers() {
if (!currentAnswersContainer) {
console.error("currentAnswersContainer element not found");
return;
}
currentAnswersContainer.innerHTML = "";
setVisibility(resultsContainer, false); // Hide results when new answers are shown
const question = findQuestionById(currentQuestionId);
if (!question) {
setVisibility(currentAnswersContainer, false);
return;
}
// Ensure question.answers is an array before trying to iterate
if (Array.isArray(question.answers)) {
question.answers.forEach((answer) => {
const button = document.createElement("button");
button.classList.add("answerButton");
button.dataset.answerId = answer.id;
button.dataset.nextQuestion = answer.nextQuestion || "";
button.textContent = answer.text;
button.addEventListener("click", handleAnswerSelection);
currentAnswersContainer.appendChild(button);
});
setVisibility(currentAnswersContainer, true);
} else {
console.error(
"Question.answers is not an array for questionId:",
currentQuestionId
);
setVisibility(currentAnswersContainer, false);
}
}
function handleAnswerSelection(event) {
const selectedButton = event.currentTarget;
const answerId = selectedButton.dataset.answerId;
const nextQuestion = selectedButton.dataset.nextQuestion;
const answerText = selectedButton.textContent;
const questionBeingAnswered = findQuestionById(currentQuestionId);
if (!questionBeingAnswered) {
console.error(
"Error: Could not find the question being answered. CurrentQuestionId:",
currentQuestionId
);
return;
}
//add answered Qs to history
currentQuestionHistory.push({
questionId: questionBeingAnswered.id,
text: questionBeingAnswered.text,
selectedAnswerId: answerId,
selectedAnswerText: answerText,
});
// add selected answer IDs to path
currentUserAnswerPath.push(answerId);
if (nextQuestion) {
currentQuestionId = nextQuestion;
renderLeftPanel();
displayCurrentAnswers();
} else {
currentQuestionId = null;
renderLeftPanel();
displayCurrentAnswers();
const tokenDetails = getTokenDetailsForUserPath(currentUserAnswerPath);
displayResults(tokenDetails);
}
}
function displayResults(details) {
if (
!resultsContainer ||
!tokenPathDisplay ||
!figmaSyntaxDisplay ||
!tokenHexDisplay ||
!hexVisual
) {
console.error("One or more results display elements are missing.");
return;
}
setVisibility(currentAnswersContainer, false);
setVisibility(resultsContainer, true);
if (details.error) {
tokenPathDisplay.textContent = "Error";
figmaSyntaxDisplay.textContent = details.error;
tokenHexDisplay.textContent = `Path: ${
details.userAnswerPathAttempted ||
details.referencePathAttempted ||
"N/A"
}`;
hexVisual.style.backgroundColor = "transparent";
} else {
tokenPathDisplay.textContent = details.tokenPath || "N/A";
figmaSyntaxDisplay.textContent = details.figmaSyntax || "N/A";
tokenHexDisplay.textContent = details.hexValue || "N/A";
tokenDescriptionDisplay.textContent =
details.description || "No description available.";
if (
details.hexValue &&
details.hexValue !== "N/A" &&
details.hexValue !== "Alias Resolution Error"
) {
hexVisual.style.backgroundColor = details.hexValue;
} else {
hexVisual.style.backgroundColor = "transparent";
}
}
}
// Resets the application to its initial state.
function resetApp() {
currentUserAnswerPath = [];
currentQuestionHistory = [];
if (
typeof allQuestions !== "undefined" &&
allQuestions &&
allQuestions.length > 0
) {
currentQuestionId = allQuestions[0].id;
} else {
currentQuestionId = null;
console.error(
"allQuestions array is empty or not defined. UI cannot initialize questions."
);
if (leftPanel)
leftPanel.innerHTML = `<div class="question-item visible">Error: Question data is missing or not loaded.</div>`;
if (currentAnswersContainer) currentAnswersContainer.innerHTML = "";
setVisibility(resultsContainer, false);
return;
}
if (currentQuestionId) {
renderLeftPanel();
displayCurrentAnswers();
} else {
if (leftPanel)
leftPanel.innerHTML = `<div class="question-item visible">No questions defined.</div>`;
if (currentAnswersContainer) currentAnswersContainer.innerHTML = "";
}
setVisibility(resultsContainer, false);
}
if (resetButton) {
resetButton.addEventListener("click", resetApp);
} else {
console.error("Reset button not found.");
}
// Initial load
resetApp();
});
</script>