Implement some shadowing in ProgressCircle.

master
Icedream 2017-08-20 00:23:35 +02:00
parent aa6b84c00b
commit 7deaeea2f6
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
1 changed files with 37 additions and 2 deletions

View File

@ -16,7 +16,13 @@ const ProgressCircle = ({
const width = size; const width = size;
const height = size; const height = size;
const viewBox = [0, 0, width, height].join(' '); const extraWidth = width * 0.1;
const extraHeight = height * 0.1;
const viewBox = [
-extraWidth, -extraHeight,
width + (2 * extraWidth), height + (2 * extraHeight),
].join(' ');
const cx = width / 2; const cx = width / 2;
const cy = height / 2; const cy = height / 2;
@ -30,6 +36,8 @@ const ProgressCircle = ({
const strokeDasharray = strokeLength; const strokeDasharray = strokeLength;
const strokeDashoffset = strokeLength * (1 - finalProgress); const strokeDashoffset = strokeLength * (1 - finalProgress);
const dropShadowDefId = 'dropshadow';
return ( return (
<div <div
className={style.progressCircleContainer} className={style.progressCircleContainer}
@ -38,10 +46,37 @@ const ProgressCircle = ({
height: `${height}px`, height: `${height}px`,
}} }}
> >
<svg className={style.progressCircle} {...{ width, height, viewBox }}> <svg
className={style.progressCircle}
style={{
margin: [
-extraHeight,
-extraWidth,
].join(' '),
}}
{...{ viewBox }}
>
<defs>
<filter
id={dropShadowDefId}
height={height + extraHeight}
width={width + extraWidth}
>
<feGaussianBlur in="SourceAlpha" stdDeviation="3" /> {/* stdDeviation is how much to blur */}
<feOffset dx="0" dy="0" result="offsetblur" /> {/* how much to offset */}
<feComponentTransfer>
<feFuncA type="linear" slope="2.0" />
</feComponentTransfer>
<feMerge>
<feMergeNode /> {/* this contains the offset blurred image */}
<feMergeNode in="SourceGraphic" /> {/* this contains the element that the filter is applied to */}
</feMerge>
</filter>
</defs>
<circle <circle
fill="none" fill="none"
stroke={backStroke} stroke={backStroke}
filter={`url(#${dropShadowDefId})`}
{...{ cx, cy, r, strokeWidth }} {...{ cx, cy, r, strokeWidth }}
/> />
<circle <circle