-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added optional progress indicator to `<ShareContentByElements /…
…>` component
- Loading branch information
Showing
11 changed files
with
125 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
front-end-components/src/components/progress/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import "src/components/progress/styles.css"; | ||
import { ProgressProps } from "."; | ||
import classNames from "classnames"; | ||
|
||
// inspired by https://medium.com/@pppped/how-to-code-a-responsive-circular-percentage-chart-with-svg-and-css-3632f8cd7705 | ||
export const Progress: React.FC<ProgressProps> = ({ | ||
className, | ||
percentage, | ||
...props | ||
}) => { | ||
return ( | ||
<svg | ||
viewBox="0 0 40 40" | ||
className={classNames("progress-wrapper", className)} | ||
{...props} | ||
> | ||
<path | ||
className="progress-circle" | ||
d="M20 4.0845 | ||
a 15.9155 15.9155 0 0 1 0 31.831 | ||
a 15.9155 15.9155 0 0 1 0 -31.831" | ||
strokeDasharray={`${percentage}, 100`} | ||
/> | ||
</svg> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* eslint-disable react-refresh/only-export-components */ | ||
export * from "src/components/progress/component"; | ||
export * from "src/components/progress/types"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.progress-wrapper { | ||
display: block; | ||
max-width: 80%; | ||
max-height: 250px; | ||
} | ||
|
||
.progress-wrapper.progress-left { | ||
float: left; | ||
margin-right: 10px; | ||
} | ||
|
||
.progress-wrapper .progress-circle { | ||
stroke: #005EA5; | ||
fill: none; | ||
stroke-width: 6; | ||
stroke-linecap: round; | ||
animation: progress 1s ease-out forwards; | ||
} | ||
|
||
@keyframes progress { | ||
0% { | ||
stroke-dasharray: 0 100; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { SVGProps } from "react"; | ||
|
||
export type ProgressProps = Pick< | ||
SVGProps<SVGSVGElement>, | ||
"width" | "height" | "className" | ||
> & { | ||
percentage: number; | ||
}; |
24 changes: 22 additions & 2 deletions
24
front-end-components/src/components/share-content-by-elements/component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
import React, { useState } from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import { ShareContentByElementsProps } from "./types"; | ||
import { useDownloadPngImages } from "src/hooks/useDownloadImage"; | ||
import { ShareContent } from "../share-content"; | ||
import { Progress } from "../progress"; | ||
|
||
export const ShareContentByElements: React.FC<ShareContentByElementsProps> = ({ | ||
disabled, | ||
elementsSelector, | ||
showProgress, | ||
showTitles, | ||
label, | ||
...props | ||
}) => { | ||
const [imagesLoading, setImagesLoading] = useState<boolean>(); | ||
const [progress, setProgress] = useState<number>(); | ||
|
||
const downloadPngs = useDownloadPngImages({ | ||
elementsSelector, | ||
onImagesLoading: setImagesLoading, | ||
onProgress: setProgress, | ||
showTitles, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!imagesLoading) { | ||
setProgress(undefined); | ||
} | ||
}, [imagesLoading]); | ||
|
||
return ( | ||
<ShareContent | ||
disabled={imagesLoading || disabled} | ||
onSaveClick={async () => await downloadPngs()} | ||
{...props} | ||
> | ||
{label} | ||
<> | ||
{showProgress && progress && ( | ||
<Progress | ||
className="progress-left" | ||
percentage={progress} | ||
width={18} | ||
height={18} | ||
/> | ||
)} | ||
{label} | ||
</> | ||
</ShareContent> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters