Skip to content

Commit a9867d5

Browse files
chowsepaulirish
authored andcommitted
Report: Updated styles (#2297)
1 parent 112c2c7 commit a9867d5

File tree

5 files changed

+281
-159
lines changed

5 files changed

+281
-159
lines changed

lighthouse-core/report/v2/renderer/category-renderer.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,32 +117,28 @@ class CategoryRenderer {
117117
* @return {!Element}
118118
*/
119119
_renderTimelineMetricAudit(audit, scale) {
120-
const element = this._dom.createElement('div',
121-
`lh-timeline-metric lh-timeline-metric--${Util.calculateRating(audit.score)}`);
120+
const tmpl = this._dom.cloneTemplate('#tmpl-lh-timeline-metric', this._templateContext);
121+
const element = this._dom.find('.lh-timeline-metric', tmpl);
122+
element.classList.add(`lh-timeline-metric--${Util.calculateRating(audit.score)}`);
122123

123-
const sparklineContainerEl = this._dom.createChildOf(element, 'div',
124-
'lh-timeline-metric__sparkline');
125-
const titleEl = this._dom.createChildOf(element, 'div', 'lh-timeline-metric__title');
126-
const titleNameEl = this._dom.createChildOf(titleEl, 'span', 'lh-timeline-metric__name');
127-
const titleValueEl = this._dom.createChildOf(titleEl, 'span', 'lh-timeline-metric__value');
128-
titleNameEl.textContent = audit.result.description;
129-
titleValueEl.textContent = audit.result.displayValue;
124+
const titleEl = this._dom.find('.lh-timeline-metric__title', tmpl);
125+
titleEl.textContent = audit.result.description;
126+
127+
const valueEl = this._dom.find('.lh-timeline-metric__value', tmpl);
128+
valueEl.textContent = audit.result.displayValue;
129+
130+
const descriptionEl = this._dom.find('.lh-timeline-metric__description', tmpl);
131+
descriptionEl.appendChild(this._dom.convertMarkdownLinkSnippets(audit.result.helpText));
130132

131133
if (typeof audit.result.rawValue !== 'number') {
132134
const debugStrEl = this._dom.createChildOf(element, 'div', 'lh-debug');
133135
debugStrEl.textContent = audit.result.debugString || 'Report error: no metric information';
134136
return element;
135137
}
136138

137-
const sparklineEl = this._dom.createChildOf(sparklineContainerEl, 'div',
138-
'lh-sparkline lh-sparkline--thin');
139-
const sparklineBarEl = this._dom.createChildOf(sparklineEl, 'div', 'lh-sparkline__bar');
139+
const sparklineBarEl = this._dom.find('.lh-sparkline__bar', tmpl);
140140
sparklineBarEl.style.width = `${audit.result.rawValue / scale * 100}%`;
141141

142-
const descriptionEl = this._dom.createChildOf(element, 'div',
143-
'lh-timeline-metric__description');
144-
descriptionEl.appendChild(this._dom.convertMarkdownLinkSnippets(audit.result.helpText));
145-
146142
return element;
147143
}
148144

@@ -219,19 +215,21 @@ class CategoryRenderer {
219215
'lh-audit-group__header lh-expandable-details__header');
220216
auditGroupHeader.textContent = group.title;
221217

222-
const auditGroupDescription = this._dom.createElement('div', 'lh-audit-group__description');
223-
auditGroupDescription.appendChild(this._dom.convertMarkdownLinkSnippets(group.description));
224-
225218
const auditGroupSummary = this._dom.createElement('summary',
226219
'lh-audit-group__summary lh-expandable-details__summary');
227220
const auditGroupArrow = this._dom.createElement('div', 'lh-toggle-arrow', {
228221
title: 'See audits',
229222
});
230223
auditGroupSummary.appendChild(auditGroupHeader);
231224
auditGroupSummary.appendChild(auditGroupArrow);
232-
233225
auditGroupElem.appendChild(auditGroupSummary);
234-
auditGroupElem.appendChild(auditGroupDescription);
226+
227+
if (group.description) {
228+
const auditGroupDescription = this._dom.createElement('div', 'lh-audit-group__description');
229+
auditGroupDescription.appendChild(this._dom.convertMarkdownLinkSnippets(group.description));
230+
auditGroupElem.appendChild(auditGroupDescription);
231+
}
232+
235233
return auditGroupElem;
236234
}
237235

@@ -240,10 +238,10 @@ class CategoryRenderer {
240238
* @return {!Element}
241239
*/
242240
_renderPassedAuditsSection(elements) {
243-
const passedElem = this._dom.createElement('details', 'lh-passed-audits');
244-
const passedSummary = this._dom.createElement('summary', 'lh-passed-audits-summary');
245-
passedElem.appendChild(passedSummary);
246-
passedSummary.textContent = `View ${elements.length} passed items`;
241+
const passedElem = this._renderAuditGroup({
242+
title: `${elements.length} Passed Audits`,
243+
});
244+
passedElem.classList.add('lh-passed-audits');
247245
elements.forEach(elem => passedElem.appendChild(elem));
248246
return passedElem;
249247
}
@@ -344,14 +342,18 @@ class CategoryRenderer {
344342
!audit.result.debugString);
345343
const nonPassedAudits = nonManualAudits.filter(audit => !passedAudits.includes(audit));
346344

347-
for (const audit of nonPassedAudits) {
348-
element.appendChild(this._renderAudit(audit));
349-
}
345+
const nonPassedElem = this._renderAuditGroup({
346+
title: `${nonPassedAudits.length} failed audits`,
347+
});
348+
nonPassedElem.open = true;
349+
nonPassedAudits.forEach(audit => nonPassedElem.appendChild(this._renderAudit(audit)));
350+
element.appendChild(nonPassedElem);
350351

351352
// Create a passed section if there are passing audits.
352353
if (passedAudits.length) {
353-
const passedElements = passedAudits.map(audit => this._renderAudit(audit));
354-
const passedElem = this._renderPassedAuditsSection(passedElements);
354+
const passedElem = this._renderPassedAuditsSection(
355+
passedAudits.map(audit => this._renderAudit(audit))
356+
);
355357
element.appendChild(passedElem);
356358
}
357359

lighthouse-core/report/v2/renderer/report-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ ReportRenderer.CategoryJSON; // eslint-disable-line no-unused-expressions
189189
/**
190190
* @typedef {{
191191
* title: string,
192-
* description: string,
192+
* description: (string|undefined),
193193
* }}
194194
*/
195195
ReportRenderer.GroupJSON; // eslint-disable-line no-unused-expressions

0 commit comments

Comments
 (0)