Skip to content

Commit 253d35c

Browse files
committed
add gradient for monthly badge gauge
1 parent 779e9af commit 253d35c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

assets/css/variables-color.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
/* Topics */
4646
--prpl-color-monthly: #faa310;
47+
--prpl-color-monthly-2: #faa310;
4748
--prpl-color-streak: var(--prpl-color-monthly);
4849
--prpl-color-content-badge: var(--prpl-color-monthly);
4950
--prpl-background-monthly: #fff9f0;

assets/js/web-components/prpl-gauge.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ customElements.define(
2020
maxDeg: '180deg',
2121
background: 'var(--prpl-background-monthly)',
2222
color: 'var(--prpl-color-monthly)',
23+
color2: 'var(--prpl-color-monthly-2)',
2324
start: '270deg',
2425
cutout: '57%',
2526
contentFontSize: 'var(--prpl-font-size-6xl)',
@@ -64,10 +65,25 @@ customElements.define(
6465
props.brandingId =
6566
this.getAttribute( 'branding-id' ) || props.brandingId;
6667

68+
let colorTransitions;
69+
70+
// If the progress is less than 50%, we have only one color, no gradient.
71+
if ( props.value <= 0.5 ) {
72+
colorTransitions = `${ props.color } calc(${ props.maxDeg } * ${ props.value })`;
73+
} else {
74+
// Otherwise we show first color for 0.5 and then the second color.
75+
colorTransitions = `${ props.color } calc(${
76+
props.maxDeg
77+
} * ${ 0.5 })`;
78+
colorTransitions += `, ${ props.color2 } calc(${ props.maxDeg } * ${ props.value })`;
79+
}
80+
// Add the remaining color.
81+
colorTransitions += `, var(--prpl-color-gauge-remain) calc(${ props.maxDeg } * ${ props.value }) ${ props.maxDeg }`;
82+
6783
this.innerHTML = `
6884
<div style="padding: ${ props.contentPadding };
6985
background: ${ props.background }; border-radius:var(--prpl-border-radius-big); aspect-ratio: 2 / 1; overflow: hidden; position: relative; margin-bottom: ${ props.marginBottom };">
70-
<div style="width: 100%; aspect-ratio: 1 / 1; border-radius: 100%; position: relative; background: radial-gradient(${ props.background } 0 ${ props.cutout }, transparent ${ props.cutout } 100%), conic-gradient(from ${ props.start }, ${ props.color } calc(${ props.maxDeg } * ${ props.value }), var(--prpl-color-gauge-remain) calc(${ props.maxDeg } * ${ props.value }) ${ props.maxDeg }, transparent ${ props.maxDeg }); text-align: center;">
86+
<div style="width: 100%; aspect-ratio: 1 / 1; border-radius: 100%; position: relative; background: radial-gradient(${ props.background } 0 ${ props.cutout }, transparent ${ props.cutout } 100%), conic-gradient(from ${ props.start }, ${ colorTransitions }, transparent ${ props.maxDeg }); text-align: center;">
7187
<span style="font-size: var(--prpl-font-size-small); position: absolute; top: 50%; color: var(--prpl-color-text); width: 10%; text-align: center; left:0;">0</span>
7288
<span style="font-size: ${ props.contentFontSize }; ${ contentSpecificStyles } display: block; font-weight: 600; text-align: center; position: absolute; color: var(--prpl-color-text); width: 100%; line-height: 1.2;">
7389
<span style="display:inline-block;width: 50%;">

0 commit comments

Comments
 (0)