Skip to content

Commit a7b72eb

Browse files
committed
Make the component more flexible and move css in its own file
1 parent e8e8787 commit a7b72eb

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed
Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,24 @@
11
@inject IJSRuntime JSRuntime
22

3-
<div class="progress-container">
3+
<div class="progress-container" @ref="progressContainer">
44
<svg class="progress-circle" viewBox="0 0 36 36">
55
<circle class="progress-bg" cx="18" cy="18" r="15.91549431" />
66
<circle class="progress-bar" id="progressBar" cx="18" cy="18" r="15.91549431" />
77
</svg>
88
</div>
99

10-
<style>
11-
.progress-container {
12-
position: fixed;
13-
bottom: 20px;
14-
right: 20px;
15-
z-index: 1000;
16-
opacity: 0;
17-
transition: opacity 0.5s;
18-
}
19-
20-
.progress-container.visible {
21-
opacity: 1;
22-
}
23-
24-
@@keyframes fadeOut {
25-
to {
26-
opacity: 0;
27-
}
28-
}
29-
30-
.progress-circle {
31-
width: 50px;
32-
height: 50px;
33-
}
34-
35-
.progress-bg {
36-
fill: none;
37-
stroke: #f3f3f3;
38-
stroke-width: 4;
39-
}
40-
41-
.progress-bar {
42-
fill: none;
43-
stroke: #4caf50;
44-
stroke-width: 4;
45-
stroke-linecap: round;
46-
transform-origin: center;
47-
transform: rotate(-90deg);
48-
stroke-dasharray: 100, 100;
49-
stroke-dashoffset: 100;
50-
}
10+
@code {
11+
[Parameter]
12+
public string ContainerCssSelector { get; set; }
5113

52-
</style>
14+
private ElementReference progressContainer;
5315

54-
@code {
5516
protected override async Task OnAfterRenderAsync(bool firstRender)
5617
{
5718
if (firstRender)
5819
{
5920
await using var _ = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./Features/ShowBlogPost/Components/ReadingIndicator.razor.js");
60-
await JSRuntime.InvokeVoidAsync("initCircularReadingProgress");
21+
await JSRuntime.InvokeVoidAsync("initCircularReadingProgress", ContainerCssSelector, progressContainer);
6122
}
6223
}
6324
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.progress-container {
2+
position: fixed;
3+
bottom: 20px;
4+
right: 20px;
5+
z-index: 1000;
6+
opacity: 0;
7+
transition: opacity 0.5s;
8+
}
9+
10+
.progress-container.visible {
11+
opacity: 1;
12+
}
13+
14+
@keyframes fadeOut {
15+
to {
16+
opacity: 0;
17+
}
18+
}
19+
20+
.progress-circle {
21+
width: 50px;
22+
height: 50px;
23+
}
24+
25+
.progress-bg {
26+
fill: none;
27+
stroke: #f3f3f3;
28+
stroke-width: 4;
29+
}
30+
31+
.progress-bar {
32+
fill: none;
33+
stroke: #4caf50;
34+
stroke-width: 4;
35+
stroke-linecap: round;
36+
transform-origin: center;
37+
transform: rotate(-90deg);
38+
stroke-dasharray: 100, 100;
39+
stroke-dashoffset: 100;
40+
}

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/Components/ReadingIndicator.razor.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let progressTimeout;
22
let rafId;
33

4-
function getContentHeight() {
5-
const content = document.querySelector(".blog-inner-content");
4+
function getContentHeight(className) {
5+
const content = document.querySelector(className);
66
if (!content) {
77
return 0;
88
}
@@ -22,14 +22,13 @@ function hideProgressIndicator(progressContainer) {
2222
}, 500);
2323
}
2424

25-
window.initCircularReadingProgress = () => {
25+
window.initCircularReadingProgress = (parentContainer, progressContainer) => {
2626
const progressBar = document.getElementById('progressBar');
27-
const progressContainer = progressBar.closest(".progress-container");
2827

2928
const onScroll = () => {
3029
clearTimeout(progressTimeout);
3130

32-
const contentHeight = getContentHeight();
31+
const contentHeight = getContentHeight(parentContainer);
3332
const windowHeight = document.documentElement.clientHeight;
3433
const scrollAmount = document.documentElement.scrollTop;
3534
const maxScrollAmount = contentHeight - windowHeight;

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/ShowBlogPostPage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ else
5454
</div>
5555
</div>
5656

57-
<ReadingIndicator />
57+
<ReadingIndicator ContainerCssSelector=".blog-inner-content"/>
5858
}
5959

6060
@code {

0 commit comments

Comments
 (0)