Skip to content

Commit 71a09cc

Browse files
committed
Restore ability to have headings
1 parent 52f14b2 commit 71a09cc

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/main/js/add-item.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { getI18n } from "@/util/i18n";
2+
import { createElementFromHtml } from "@/util/dom";
23

4+
const enableHeadings = false;
35
const nameInput = document.querySelector(`#createItem input[name="name"]`);
46
const copyFromInput = document.querySelector(`#createItem input[name="from"]`);
57
const copyRadio = document.querySelector(`#createItem input[value="copy"]`);
@@ -116,6 +118,29 @@ document.addEventListener("DOMContentLoaded", () => {
116118
//////////////////////////////////
117119
// Draw functions
118120

121+
function drawCategory(category) {
122+
const heading = createElementFromHtml(
123+
"<div class='jenkins-choice-list__heading'></div>",
124+
);
125+
const title = createElementFromHtml("<h2>" + category.name + "</h2>");
126+
const description = createElementFromHtml(
127+
"<p>" + category.description + "</p>",
128+
);
129+
heading.appendChild(title);
130+
heading.appendChild(description);
131+
const response = [];
132+
133+
if (enableHeadings) {
134+
response.push(heading);
135+
}
136+
137+
category.items.forEach((elem) => {
138+
response.push(drawItem(elem));
139+
});
140+
141+
return response;
142+
}
143+
119144
function drawItem(elem) {
120145
var item = document.createElement("div");
121146
item.className =
@@ -209,9 +234,7 @@ document.addEventListener("DOMContentLoaded", () => {
209234
// Render all categories
210235
var $categories = document.querySelector(".categories template");
211236
data.categories.forEach((elem) => {
212-
elem.items.forEach((elem) => {
213-
$categories.before(drawItem(elem));
214-
});
237+
drawCategory(elem).forEach((e) => $categories.before(e));
215238
});
216239

217240
// Init NameField

src/main/scss/components/_choice-list.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
border: var(--card-border-width) solid var(--card-border-color);
88
background: var(--card-background);
99

10+
&__heading {
11+
font-size: 1rem;
12+
padding: 0.875rem;
13+
border-bottom: var(--card-border-width) solid var(--card-border-color);
14+
15+
& > * {
16+
margin: 0;
17+
}
18+
19+
h2 {
20+
font-weight: var(--font-bold-weight);
21+
font-size: var(--font-size-sm);
22+
margin-bottom: 0.5rem;
23+
}
24+
25+
p {
26+
color: var(--text-color-secondary);
27+
}
28+
}
29+
1030
&__item {
1131
-webkit-touch-callout: none;
1232
position: relative;

0 commit comments

Comments
 (0)