Skip to content

Commit 675cc88

Browse files
authored
feat: search results styling (#43)
1 parent 2ff6382 commit 675cc88

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

public/components/search-results.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,34 @@ export function searchResults({ query, results }) {
33

44
if (!results) return "";
55

6-
const resultsHTML = results ? results
7-
.filter(Boolean)
8-
.map(([method, path, operation]) => {
9-
const route = `${method} ${path}`.replace(queryRegex, `<mark>$1</mark>`);
10-
const summary = operation.summary.replace(queryRegex, `<mark>$1</mark>`);
11-
return `<article>
6+
const resultsHTML = results
7+
? results
8+
.filter(Boolean)
9+
.map(([method, path, operation]) => {
10+
const route = `${method} ${path}`.replace(
11+
queryRegex,
12+
`<mark>$1</mark>`
13+
);
14+
const summary = operation.summary.replace(
15+
queryRegex,
16+
`<mark>$1</mark>`
17+
);
18+
return `<li>
1219
<a href="/${method}/${path}">
13-
${summary}
14-
(<code>${route}</code>)
20+
<h3>${summary}</h3>
21+
<pre><code>${route}</code></pre>
1522
</a>
16-
</article>`;
17-
})
18-
.join("\n") : "";
23+
</li>`;
24+
})
25+
.join("\n")
26+
: "";
1927

2028
if (resultsHTML) {
21-
return `<h2>Results</h2>
29+
return `<h2>${results.length} Results</h2>
2230
23-
${resultsHTML}`;
31+
<ul>
32+
${resultsHTML}
33+
</ul>`;
2434
}
2535

2636
if (query) {

public/style.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ button {
4141
padding: 0.375em 0.75em;
4242
}
4343

44-
4544
label.has-placeholder > span,
4645
label.has-placeholder > br {
4746
/* @hidden-accessible */
@@ -154,6 +153,25 @@ form h1 {
154153
margin-left: calc(-0.75em - 1px);
155154
}
156155

156+
/* Search results */
157+
.results ul {
158+
list-style: none;
159+
padding: 0;
160+
}
161+
.results li a {
162+
display: block;
163+
padding: 1em;
164+
margin: 0 -1em;
165+
166+
text-decoration: none;
167+
}
168+
.results li a:hover {
169+
background: #ffc;
170+
}
171+
.results li a > * {
172+
margin: 0;
173+
}
174+
157175
/* Details */
158176
.details {
159177
margin-left: -1.5rem;

0 commit comments

Comments
 (0)