Skip to content

Commit 89a055d

Browse files
pgallinoV-SANT
andauthored
Improved detail and payload rendering in the right sidebar (#141)
- Ensured key-value pairs stay on the same line. - Fixed JSON formatting to prevent overflow. - Applied CSS tweaks for better alignment and responsiveness. before: ![image](https://github.com/user-attachments/assets/d08c2b90-ea4f-4c7e-bd93-d036fdaae362) after: ![image](https://github.com/user-attachments/assets/b1c7c174-a5f6-496d-bfb7-0fb09b2ace4c) --------- Co-authored-by: V-SANT <[email protected]>
1 parent 21646c5 commit 89a055d

File tree

2 files changed

+116
-8
lines changed

2 files changed

+116
-8
lines changed

src/graphics/right_bar.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,65 @@ function createWarningElement(key: string, value: string): HTMLLIElement {
407407
return listItem;
408408
}
409409

410-
// Function to create payload element
410+
// Function to create a payload element
411411
function createPayloadElement(key: string, value: object): HTMLLIElement {
412+
// Create the list item that will hold the payload
412413
const listItem = document.createElement("li");
414+
listItem.classList.add("payload-item"); // Apply styling
415+
416+
// Create the key (title) element for the payload
417+
const keyElement = document.createElement("strong");
418+
keyElement.classList.add("payload-key");
419+
keyElement.textContent = `${key}:`; // Set the text content
420+
421+
// Create a container to wrap the JSON content
422+
const preContainer = document.createElement("div");
423+
preContainer.classList.add("payload-container"); // Apply styling
424+
425+
// Create the <pre> element to display formatted JSON
413426
const pre = document.createElement("pre");
414-
pre.textContent = JSON.stringify(value, null, 2); // Pretty-print JSON
415-
listItem.innerHTML = `<strong>${key}:</strong>`;
416-
listItem.appendChild(pre);
427+
pre.classList.add("payload-content");
428+
pre.textContent = JSON.stringify(value, null, 2); // Pretty-print JSON for readability
417429

430+
// Append the <pre> element inside its container
431+
preContainer.appendChild(pre);
432+
433+
// Append key element and preContainer to the list item
434+
listItem.appendChild(keyElement);
435+
listItem.appendChild(preContainer);
436+
437+
// Return the formatted list item
418438
return listItem;
419439
}
420440

421-
// Function to create regular detail element
441+
// Function to create a regular detail element
422442
function createDetailElement(key: string, value: string): HTMLLIElement {
443+
// Create the list item that will hold the detail
423444
const listItem = document.createElement("li");
424-
listItem.innerHTML = `<strong>${key}:</strong> ${value}`;
445+
listItem.classList.add("detail-item"); // Apply styling
446+
447+
// Create a container to keep key and value aligned in the same row
448+
const container = document.createElement("div");
449+
container.classList.add("detail-container");
450+
451+
// Create the key element (label)
452+
const keyElement = document.createElement("span");
453+
keyElement.classList.add("detail-key");
454+
keyElement.textContent = `${key}:`; // Set the text content
455+
456+
// Create the value element
457+
const valueElement = document.createElement("span");
458+
valueElement.classList.add("detail-value");
459+
valueElement.textContent = value; // Set the text content
460+
461+
// Append key and value elements to the container
462+
container.appendChild(keyElement);
463+
container.appendChild(valueElement);
464+
465+
// Append the container to the list item
466+
listItem.appendChild(container);
467+
468+
// Return the formatted list item
425469
return listItem;
426470
}
427471

src/styles/info.css

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
border-radius: 8px;
6969
margin: 10px 0;
7070
overflow: hidden;
71-
max-width: 300px;
7271
}
7372

7473
/* Title style for the warning */
@@ -86,8 +85,73 @@
8685
/* Message style for the warning */
8786
.warning-sign .warning-message {
8887
padding: 10px;
89-
margin: 0;
88+
margin: 3px;
9089
text-align: center;
9190
font-size: 18px;
9291
line-height: 1.4;
9392
}
93+
94+
.detail-item {
95+
list-style: none; /* Removes default list styling */
96+
padding: 6px 10px; /* Adds padding for spacing */
97+
border-bottom: 1px solid #ddd; /* Adds a subtle separator between items */
98+
}
99+
100+
.detail-container {
101+
display: flex; /* Uses flexbox for alignment */
102+
justify-content: space-between; /* Keeps key and value on the same line */
103+
align-items: center; /* Ensures vertical alignment */
104+
width: 100%; /* Makes sure it takes up the full width */
105+
white-space: nowrap; /* Prevents text from wrapping to the next line */
106+
}
107+
108+
.detail-key {
109+
font-weight: bold; /* Makes the key stand out */
110+
color: #000000; /* Sets the text color to black */
111+
flex-shrink: 0; /* Prevents the key from shrinking too much */
112+
margin-right: 8px; /* Adds spacing between key and value */
113+
}
114+
115+
.detail-value {
116+
color: #000000; /* Sets the text color to black */
117+
text-align: right; /* Aligns the value to the right */
118+
flex-grow: 1; /* Allows the value to expand to fill available space */
119+
overflow: hidden; /* Hides any overflowing text */
120+
text-overflow: ellipsis; /* Adds "..." if the text is too long */
121+
}
122+
123+
.payload-item {
124+
display: flex;
125+
flex-direction: column; /* Ensures key and JSON block are stacked */
126+
width: 100%; /* Makes sure it doesn't exceed the sidebar width */
127+
margin-top: 10px; /* Adds spacing above */
128+
}
129+
130+
.payload-key {
131+
font-weight: bold; /* Makes the key stand out */
132+
margin-bottom: 5px; /* Adds spacing between the key and the payload */
133+
}
134+
135+
.payload-container {
136+
background-color: #f4f4f4; /* Light background for contrast */
137+
border-radius: 6px; /* Rounds the corners */
138+
padding: 10px; /* Adds padding inside the container */
139+
border: 1px solid #ddd; /* Adds a subtle border */
140+
width: 100%; /* Ensures the container occupies the full width */
141+
max-width: 100%; /* Prevents it from exceeding the sidebar width */
142+
overflow-x: auto; /* Enables horizontal scrolling if needed */
143+
box-sizing: border-box; /* Ensures padding and border do not affect width */
144+
display: block;
145+
}
146+
147+
.payload-content {
148+
color: #fff; /* White text for better readability */
149+
font-family: monospace; /* Uses a monospace font for JSON formatting */
150+
font-size: 14px; /* Ensures good readability */
151+
background-color: #111; /* Dark background for better contrast */
152+
padding: 10px; /* Adds spacing inside */
153+
border-radius: 6px; /* Rounds the corners */
154+
width: 100%; /* Ensures it takes the full width of the container */
155+
max-width: 100%; /* Prevents it from exceeding the container */
156+
display: block;
157+
}

0 commit comments

Comments
 (0)