From f46a9d2916ee56c435e9ddfe1dc5338d4a77f0f9 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 26 Apr 2019 22:00:07 -0700 Subject: [PATCH 01/19] report(redesign): toggle metric descriptions --- .../report/html/renderer/category-renderer.js | 5 ++ .../html/renderer/report-ui-features.js | 34 +++++++++++ lighthouse-core/report/html/report-styles.css | 58 +++++++++++++++++-- lighthouse-core/report/html/templates.html | 28 ++++++++- 4 files changed, 118 insertions(+), 7 deletions(-) diff --git a/lighthouse-core/report/html/renderer/category-renderer.js b/lighthouse-core/report/html/renderer/category-renderer.js index adbfcc063e42..9159d2c3839d 100644 --- a/lighthouse-core/report/html/renderer/category-renderer.js +++ b/lighthouse-core/report/html/renderer/category-renderer.js @@ -200,6 +200,11 @@ class CategoryRenderer { descriptionEl.classList.add('lh-audit-group__description'); auditGroupHeader.appendChild(descriptionEl); } + if (group.title === 'Metrics') { + const toggleTmpl = this.dom.cloneTemplate('#tmpl-lh-metrics-toggle', this.templateContext); + const toggleEl = this.dom.find('.lh-metrics-toggle', toggleTmpl); + auditGroupHeader.appendChild(toggleEl); + } groupEl.appendChild(auditGroupHeader); return groupEl; diff --git a/lighthouse-core/report/html/renderer/report-ui-features.js b/lighthouse-core/report/html/renderer/report-ui-features.js index 62e5e2e8d131..d5ddea83124e 100644 --- a/lighthouse-core/report/html/renderer/report-ui-features.js +++ b/lighthouse-core/report/html/renderer/report-ui-features.js @@ -48,6 +48,14 @@ class ReportUIFeatures { this.stickyHeaderEl; // eslint-disable-line no-unused-expressions /** @type {HTMLElement} */ this.highlightEl; // eslint-disable-line no-unused-expressions + /** @type {HTMLElement} */ + this.metricDescriptionToggleEl; // eslint-disable-line no-unused-expressions + /** @type {HTMLElement} */ + this.metricDescriptionLessEl; // eslint-disable-line no-unused-expressions + /** @type {HTMLElement} */ + this.metricDescriptionMoreEl; // eslint-disable-line no-unused-expressions + /** @type {HTMLElement} */ + this.metricAuditGroup; // eslint-disable-line no-unused-expressions this.onMediaQueryChange = this.onMediaQueryChange.bind(this); this.onCopy = this.onCopy.bind(this); @@ -57,6 +65,9 @@ class ReportUIFeatures { this.printShortCutDetect = this.printShortCutDetect.bind(this); this.onChevronClick = this.onChevronClick.bind(this); this._updateStickyHeaderOnScroll = this._updateStickyHeaderOnScroll.bind(this); + this._toggleMetricDescription = this._toggleMetricDescription.bind(this); + this._setupMetricDescriptionToggleListeners = + this._setupMetricDescriptionToggleListeners.bind(this); } /** @@ -77,6 +88,9 @@ class ReportUIFeatures { this._document.addEventListener('copy', this.onCopy); this._document.addEventListener('scroll', this._updateStickyHeaderOnScroll); window.addEventListener('resize', this._updateStickyHeaderOnScroll); + + this._setupMetricDescriptionToggleElements(); + this._setupMetricDescriptionToggleListeners(); } /** @@ -140,6 +154,26 @@ class ReportUIFeatures { this._copyAttempt = false; } + _setupMetricDescriptionToggleElements() { + this.metricDescriptionToggleEl = this._dom.find('.lh-metrics-toggle', this._document); + this.metricDescriptionMoreEl = this._dom.find('.lh-metrics-toggle-more', this._document); + this.metricDescriptionLessEl = this._dom.find('.lh-metrics-toggle-less', this._document); + this.metricAuditGroup = this._dom.find('.lh-audit-group--metrics', this._document); + } + + _setupMetricDescriptionToggleListeners() { + this.metricDescriptionToggleEl.addEventListener('click', this._toggleMetricDescription); + for (const el of this._dom.findAll('.lh-metric', this._document)) { + el.addEventListener('click', this._toggleMetricDescription); + } + } + + _toggleMetricDescription() { + this.metricDescriptionMoreEl.classList.toggle('lh-metrics-toggle--active'); + this.metricDescriptionLessEl.classList.toggle('lh-metrics-toggle--active'); + this.metricAuditGroup.classList.toggle('lh-audit-group--metrics__show-descriptions'); + } + /** * Copies the report JSON to the clipboard (if supported by the browser). */ diff --git a/lighthouse-core/report/html/report-styles.css b/lighthouse-core/report/html/report-styles.css index f7c25eb117a2..4073bb746059 100644 --- a/lighthouse-core/report/html/report-styles.css +++ b/lighthouse-core/report/html/report-styles.css @@ -85,6 +85,7 @@ --color-black-800: #424242; --color-black-900: #212121; --color-black: #000000; + --color-blue: #2962FF; --color-green-700: #018642; --color-green: #0CCE6B; --color-orange-700: #D04900; @@ -98,6 +99,7 @@ --env-item-bg: var(--color-black-100); --env-name-min-width: 220px; --env-tem-padding: 10px 0px; + --expandable-padding: 0 0 2px 28px; --gauge-circle-size-big: 120px; --gauge-circle-size: 96px; --header-padding: 20px 0 20px 0; @@ -157,6 +159,7 @@ --body-font-size: 14px; --body-line-height: 20px; --env-name-min-width: 120px; + --expandable-padding: 0 0 2px 24px; --gauge-circle-size-big: 96px; --gauge-circle-size: 72px; --header-padding: 16px 0 16px 0; @@ -463,11 +466,14 @@ .lh-metric { border-bottom: 1px solid var(--report-secondary-border-color); } +.lh-metric:first-of-type { + border-top: 1px solid var(--report-secondary-border-color); +} .lh-metric__innerwrap { display: flex; + flex-wrap: wrap; justify-content: space-between; - font-weight: 500; padding: 8px var(--text-indent); } @@ -477,10 +483,7 @@ .lh-metric__title { flex: 1; -} - -.lh-metric__name { - flex: 1; + font-weight: 500; } .lh-metrics__disclaimer { @@ -491,11 +494,54 @@ } .lh-metric__description { + display: none; color: var(--secondary-text-color); + padding: var(--expandable-padding); +} +.lh-audit-group--metrics__show-descriptions .lh-metric__description { + display: block; } .lh-metric__value { white-space: nowrap; /* No wrapping between metric value and the icon */ + font-weight: 500; +} + +.lh-metrics-toggle { + display: flex; + align-items: center; + background-color: #eee; + border-radius: 20px; + overflow: hidden; + width: 74px; + height: 28px; + cursor: pointer; + user-select: none; +} +.lh-metrics-toggle div { + display: flex; + align-items: center; + justify-content: center; + padding: 2px 5px; +} +.lh-metrics-toggle--active { + background-color: var(--color-blue); +} +.lh-metrics-toggle-lines { + fill: #7F7F7F; +} +.lh-metrics-toggle--active .lh-metrics-toggle-lines { + fill: white; +} +.lh-metrics-toggle-less { + width: 50%; + height: 28px; + padding-left: 8px; +} +.lh-metrics-toggle-more { + width: 50%; + height: 28px; + padding-right: 8px; } @@ -723,6 +769,7 @@ } .lh-audit-group__header { + display: flex; font-size: var(--body-font-size); margin: 0 0 var(--lh-audit-group-vpadding); /* When the header takes 100% width, the chevron becomes small. */ @@ -730,6 +777,7 @@ } .lh-audit-group__header span.lh-audit-group__title { + flex: 1; font-weight: bold; } diff --git a/lighthouse-core/report/html/templates.html b/lighthouse-core/report/html/templates.html index 77abd4ac3074..6854487cc672 100644 --- a/lighthouse-core/report/html/templates.html +++ b/lighthouse-core/report/html/templates.html @@ -60,6 +60,7 @@ +
@@ -67,6 +68,29 @@ + + +