Skip to content

Commit 1ad201a

Browse files
committed
style: distinguish search result badges
1 parent 429bfdc commit 1ad201a

5 files changed

Lines changed: 84 additions & 18 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
describe('search styles', () => {
5+
test('marks page type and domain result badges with distinct classes', () => {
6+
const searchService = fs.readFileSync(
7+
path.join(__dirname, '../src/search-service.js'),
8+
'utf8',
9+
);
10+
11+
expect(searchService).toContain('search-result-badge-page-type');
12+
expect(searchService).toContain('search-result-badge-domain');
13+
});
14+
15+
test('renders result badges as subtle prominent chips', () => {
16+
const styles = fs.readFileSync(
17+
path.join(__dirname, '../../attack-style/components/_search.scss'),
18+
'utf8',
19+
);
20+
21+
const badgeStyle = styles.match(/\.search-result-badge\s*\{(?<body>[^}]+)\}/)?.groups?.body ?? '';
22+
23+
expect(badgeStyle).toContain('color: white;');
24+
expect(badgeStyle).toContain('font-size: 0.8rem;');
25+
26+
expect(styles).toContain('.search-result-badge-page-type');
27+
expect(styles).toContain('border-color: color-functions.color(active);');
28+
expect(styles).toContain('background: color-functions.color-alternate(active, 1.5);');
29+
expect(styles).toContain('.search-result-badge-domain');
30+
expect(styles).toContain('border-color: color-functions.color(deemphasis);');
31+
expect(styles).toContain('background: color-functions.color(deemphasis);');
32+
});
33+
});

attack-search/src/search-service.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,16 +1005,20 @@ module.exports = class SearchService {
10051005
const badges = [];
10061006
const pageTypeLabel = this.#pageTypeBadgeLabel(result);
10071007

1008-
if (pageTypeLabel) badges.push(pageTypeLabel);
1008+
if (pageTypeLabel) badges.push({ label: pageTypeLabel, className: 'search-result-badge-page-type' });
10091009
result.domains.forEach((domain) => {
1010-
if (DOMAIN_LABELS[domain]) badges.push(DOMAIN_LABELS[domain]);
1010+
if (DOMAIN_LABELS[domain]) {
1011+
badges.push({ label: DOMAIN_LABELS[domain], className: 'search-result-badge-domain' });
1012+
}
10111013
});
10121014

10131015
if (badges.length === 0) return '';
10141016

10151017
return `
10161018
<div class="search-result-badges">
1017-
${badges.map(badge => `<span class="search-result-badge">${badge}</span>`).join('')}
1019+
${badges.map((badge) => `
1020+
<span class="search-result-badge ${badge.className}">${badge.label}</span>
1021+
`).join('')}
10181022
</div>
10191023
`;
10201024
}

attack-style/components/_search.scss

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,29 @@
224224
.search-result-badges {
225225
display: flex;
226226
flex-wrap: wrap;
227-
gap: 5px;
228-
margin: 4px 0 6px;
227+
gap: 6px;
228+
margin: 6px 0 8px;
229229
}
230230

231231
.search-result-badge {
232-
padding: 1px 6px;
233-
border: 1px solid color-functions.border-color(body);
232+
padding: 2px 8px;
233+
border: 1px solid;
234234
border-radius: 4px;
235-
font-size: 0.75rem;
235+
color: white;
236+
font-size: 0.8rem;
236237
font-weight: 700;
237238
}
238239

240+
.search-result-badge-page-type {
241+
border-color: color-functions.color(active);
242+
background: color-functions.color-alternate(active, 1.5);
243+
}
244+
245+
.search-result-badge-domain {
246+
border-color: color-functions.color(deemphasis);
247+
background: color-functions.color(deemphasis);
248+
}
249+
239250
.search-no-results .preview {
240251
display: flex;
241252
align-items: center;

attack-theme/static/style-attack.css

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

attack-theme/static/style-user.css

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)