Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report(redesign): move gauge styles to main stylesheet #8893

Merged
merged 3 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions lighthouse-core/report/html/report-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,134 @@
border: 0;
}

/* Gauge */

.lh-gauge__wrapper--pass {
color: var(--color-pass);
fill: var(--color-pass);
stroke: var(--color-pass);
}

.lh-gauge__wrapper--average {
color: var(--color-average);
fill: var(--color-average);
stroke: var(--color-average);
}

.lh-gauge__wrapper--fail {
color: var(--color-fail);
fill: var(--color-fail);
stroke: var(--color-fail);
}

.lh-gauge {
stroke-linecap: round;
width: var(--gauge-circle-size);
height: var(--gauge-circle-size);
}

.lh-category .lh-gauge {
--gauge-circle-size: var(--gauge-circle-size-big);
}

.lh-gauge-base {
opacity: 0.1;
stroke: var(--circle-background);
stroke-width: var(--circle-border-width);
}

.lh-gauge-arc {
fill: none;
stroke: var(--circle-color);
stroke-width: var(--circle-border-width);
animation: load-gauge var(--transition-length) ease forwards;
animation-delay: 250ms;
}

.lh-gauge__svg-wrapper {
position: relative;
height: var(--gauge-circle-size);
}
.lh-category .lh-gauge__svg-wrapper {
--gauge-circle-size: var(--gauge-circle-size-big);
}

/* The plugin badge overlay */
.lh-gauge__wrapper--plugin .lh-gauge__svg-wrapper::before {
width: var(--plugin-badge-size);
height: var(--plugin-badge-size);
background-color: var(--plugin-badge-bg);
background-image: var(--plugin-icon-url);
background-repeat: no-repeat;
background-size: var(--plugin-icon-size);
background-position: 58% 50%;
content: "";
position: absolute;
right: -6px;
bottom: 0px;
display: block;
z-index: 100;
box-shadow: 0 0 4px rgba(0,0,0,.2);
border-radius: 25%;
}
.lh-category .lh-gauge__wrapper--plugin .lh-gauge__svg-wrapper::before {
width: var(--plugin-badge-size-big);
height: var(--plugin-badge-size-big);
}

@keyframes load-gauge {
from { stroke-dasharray: 0 352; }
}

.lh-gauge__percentage {
width: 100%;
height: var(--inset-size);
position: absolute;
border-radius: inherit;
font-family: var(--monospace-font-family);
font-size: var(--score-number-font-size);
line-height: var(--score-number-font-size);
text-align: center;
top: calc(var(--score-container-padding) + var(--gauge-circle-size) / 3);
}

.lh-category .lh-gauge__percentage {
--gauge-circle-size: var(--gauge-circle-size-big);
--score-number-font-size: var(--score-number-font-size-big);
}

.lh-gauge__wrapper {
position: relative;
display: flex;
align-items: center;
flex-direction: column;
text-decoration: none;
padding: var(--score-container-padding);

--circle-border-width: 8;
--transition-length: 1s;

/* Contain the layout style paint & layers during animation*/
contain: content;
will-change: opacity; /* Only using for layer promotion */
}

.lh-gauge__label {
font-size: var(--score-title-font-size);
line-height: var(--score-title-line-height);
margin-top: 10px;
text-align: center;
color: var(--body-text-color);
}

/* TODO(#8185) use more BEM (.lh-gauge__label--big) instead of relying on descendant selector */
.lh-category .lh-gauge__label {
--score-title-font-size: var(--score-title-font-size-big);
--score-title-line-height: var(--score-title-line-height-big);
margin-top: 14px;
}


.lh-scores-header .lh-gauge__wrapper,
.lh-scores-header .lh-gauge--pwa__wrapper,
.lh-sticky-header .lh-gauge__wrapper,
Expand Down
126 changes: 0 additions & 126 deletions lighthouse-core/report/html/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -532,132 +532,6 @@

<!-- Lighthouse score gauge -->
<template id="tmpl-lh-gauge">
<style>
.lh-gauge__wrapper--pass {
color: var(--color-pass);
fill: var(--color-pass);
stroke: var(--color-pass);
}

.lh-gauge__wrapper--average {
color: var(--color-average);
fill: var(--color-average);
stroke: var(--color-average);
}

.lh-gauge__wrapper--fail {
color: var(--color-fail);
fill: var(--color-fail);
stroke: var(--color-fail);
}

.lh-gauge {
stroke-linecap: round;
width: var(--gauge-circle-size);
height: var(--gauge-circle-size);
}

.lh-category .lh-gauge {
--gauge-circle-size: var(--gauge-circle-size-big);
}

.lh-gauge-base {
opacity: 0.1;
stroke: var(--circle-background);
stroke-width: var(--circle-border-width);
}

.lh-gauge-arc {
fill: none;
stroke: var(--circle-color);
stroke-width: var(--circle-border-width);
animation: load-gauge var(--transition-length) ease forwards;
animation-delay: 250ms;
}

.lh-gauge__svg-wrapper {
position: relative;
height: var(--gauge-circle-size);
}
.lh-category .lh-gauge__svg-wrapper {
--gauge-circle-size: var(--gauge-circle-size-big);
}

/* The plugin badge overlay */
.lh-gauge__wrapper--plugin .lh-gauge__svg-wrapper::before {
width: var(--plugin-badge-size);
height: var(--plugin-badge-size);
background-color: var(--plugin-badge-bg);
background-image: var(--plugin-icon-url);
background-repeat: no-repeat;
background-size: var(--plugin-icon-size);
background-position: 58% 50%;
content: "";
position: absolute;
right: -6px;
bottom: 0px;
display: block;
z-index: 100;
box-shadow: 0 0 4px rgba(0,0,0,.2);
border-radius: 25%;
}
.lh-category .lh-gauge__wrapper--plugin .lh-gauge__svg-wrapper::before {
width: var(--plugin-badge-size-big);
height: var(--plugin-badge-size-big);
}

@keyframes load-gauge {
from { stroke-dasharray: 0 352; }
}

.lh-gauge__percentage {
width: 100%;
height: var(--inset-size);
position: absolute;
border-radius: inherit;
font-family: var(--monospace-font-family);
font-size: var(--score-number-font-size);
line-height: var(--score-number-font-size);
text-align: center;
top: calc(var(--score-container-padding) + var(--gauge-circle-size) / 3);
}

.lh-category .lh-gauge__percentage {
--gauge-circle-size: var(--gauge-circle-size-big);
--score-number-font-size: var(--score-number-font-size-big);
}

.lh-gauge__wrapper {
position: relative;
display: flex;
align-items: center;
flex-direction: column;
text-decoration: none;

--circle-border-width: 8;
--transition-length: 1s;

/* Contain the layout style paint & layers during animation*/
contain: content;
will-change: opacity; /* Only using for layer promotion */
}

.lh-gauge__label {
font-size: var(--score-title-font-size);
line-height: var(--score-title-line-height);
margin-top: 10px;
text-align: center;
color: var(--body-text-color);
}

/* TODO(#8185) use more BEM (.lh-gauge__label--big) instead of relying on descendant selector */
.lh-category .lh-gauge__label {
--score-title-font-size: var(--score-title-font-size-big);
--score-title-line-height: var(--score-title-line-height-big);
margin-top: 14px;
}

</style>
<a href="#" class="lh-gauge__wrapper">
<!-- Wrapper exists for the ::before plugin icon. Cannot create pseudo-elements on svgs. -->
<div class="lh-gauge__svg-wrapper">
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/report/html/renderer/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('DOM', () => {
});

it('does not inject duplicate styles', () => {
const clone = dom.cloneTemplate('#tmpl-lh-gauge', dom.document());
const clone2 = dom.cloneTemplate('#tmpl-lh-gauge', dom.document());
const clone = dom.cloneTemplate('#tmpl-lh-snippet', dom.document());
const clone2 = dom.cloneTemplate('#tmpl-lh-snippet', dom.document());
assert.ok(clone.querySelector('style'));
assert.ok(!clone2.querySelector('style'));
});
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/test/report/html/renderer/psi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ describe('DOM', () => {
const result = prepareLabData(sampleResultsStr, document);
assert.ok(result.scoreGaugeEl instanceof document.defaultView.Element);
assert.equal(result.scoreGaugeEl.querySelector('.lh-gauge__wrapper').href, '');
assert.ok(result.scoreGaugeEl.outerHTML.includes('<style>'), 'score gauge comes with CSS');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is ok? The PSI renderer already includes report-styles.css?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure it does. @exterkamp to confirm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, PSI imports report-styles. Should be g2g!

assert.ok(result.scoreGaugeEl.outerHTML.includes('<svg'), 'score gauge comes with SVG');

assert.ok(result.perfCategoryEl instanceof document.defaultView.Element);
Expand Down