Skip to content

Commit 7a4f961

Browse files
committed
fix(circular-progress): Fix interactive part of the sample
1 parent 718e5e7 commit 7a4f961

File tree

2 files changed

+52
-58
lines changed

2 files changed

+52
-58
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
igc-circular-progress {
22
--diameter: 100px;
33
--stroke-thickness: 5px;
4+
}
5+
6+
.sample-content {
7+
width: 300px;
8+
display: flex;
9+
align-items: center;
10+
margin-top: 30px;
11+
}
12+
13+
.circular-progress-container {
14+
margin-right: 50px;
15+
margin-left: 20px;
16+
}
17+
18+
.buttons-container {
19+
display: flex;
20+
gap: 10px;
421
}

samples/inputs/circular-progress-indicator/dynamic/src/index.tsx

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import { IgrCircularProgress, IgrCircularGradient, IgrIconButton, IgrCircularProgressModule, IgrCircularGradientModule, IgrIconButtonModule, registerIconFromText } from 'igniteui-react';
@@ -12,70 +12,47 @@ IgrIconButtonModule.register();
1212
const addIconText = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>';
1313
const removeIconText = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 13H5v-2h14v2z"/></svg>';
1414

15-
export default class DynamicCircularProgress extends React.Component<any, any> {
15+
export default function DynamicCircularProgress() {
1616

17-
public circularProgress: IgrCircularProgress;
18-
public addIcon: IgrIconButton;
19-
public removeIcon: IgrIconButton;
17+
const [currentValue, setCurrentValue] = useState<number>(0);
2018

21-
constructor(props: any) {
22-
super(props);
19+
useEffect(() => {
20+
registerIconFromText("add", addIconText, "material");
21+
registerIconFromText("remove", removeIconText, "material");
22+
}, []);
2323

24-
registerIconFromText(
25-
"add", addIconText, "material"
26-
);
27-
registerIconFromText(
28-
"remove", removeIconText, "material"
29-
);
30-
31-
this.circularProgressRef = this.circularProgressRef.bind(this);
32-
this.onIconClick = this.onIconClick.bind(this);
33-
}
34-
35-
public render(): JSX.Element {
36-
return (
37-
<div style={{width: "300px", display: "flex", alignItems: "center", marginTop: "30px"}}>
38-
<IgrCircularProgress ref={this.circularProgressRef} style={{marginRight: "50px", marginLeft: "20px"}} max={100} value={100}>
39-
<IgrCircularGradient offset="0%" color="#ff9a40">
40-
</IgrCircularGradient>
41-
<IgrCircularGradient offset="50%" color="#1eccd4">
42-
</IgrCircularGradient>
43-
<IgrCircularGradient offset="100%" color="#ff0079">
44-
</IgrCircularGradient>
45-
</IgrCircularProgress>
46-
<div style={{display: "flex", justifyContent: "space evenly", marginTop: "20px"}} onClick={this.onIconClick}>
47-
<IgrIconButton className="removeIcon" name="remove" collection="material">
48-
</IgrIconButton>
49-
<IgrIconButton className="addIcon" name="add" collection="material">
50-
</IgrIconButton>
51-
</div>
52-
</div>
53-
);
54-
}
55-
56-
public circularProgressRef(progress: IgrCircularProgress)
57-
{
58-
if(!progress) { return; }
59-
this.circularProgress = progress;
24+
const incrementProgress = () => {
25+
setCurrentValue(currentValue + 10);
26+
if (currentValue > 100) {
27+
setCurrentValue(100);
28+
}
6029
}
6130

62-
public onIconClick(e: any) {
63-
const target = e.target as HTMLElement;
64-
const iconButton: any = target.closest('igc-icon-button');
65-
if(iconButton.getAttribute("classname") === "removeIcon")
66-
{
67-
if(this.circularProgress.value > 0) {
68-
this.circularProgress.value = this.circularProgress.value - 10;
69-
}
70-
else {
71-
this.circularProgress.value = 0;
72-
}
73-
}
74-
else {
75-
this.circularProgress.value = this.circularProgress.value + 10;
31+
const decrementProgress = () => {
32+
setCurrentValue(currentValue - 10);
33+
if (currentValue < 0) {
34+
setCurrentValue(0);
7635
}
77-
7836
}
37+
38+
return (
39+
<div className="sample-content">
40+
<IgrCircularProgress className="circular-progress-container" max={100} value={currentValue}>
41+
<IgrCircularGradient slot="gradient" offset="0%" color="#ff9a40">
42+
</IgrCircularGradient>
43+
<IgrCircularGradient slot="gradient" offset="50%" color="#1eccd4">
44+
</IgrCircularGradient>
45+
<IgrCircularGradient slot="gradient" offset="100%" color="#ff0079">
46+
</IgrCircularGradient>
47+
</IgrCircularProgress>
48+
<div className="buttons-container">
49+
<IgrIconButton className="removeIcon" name="remove" collection="material" onClick={decrementProgress}>
50+
</IgrIconButton>
51+
<IgrIconButton className="addIcon" name="add" collection="material" onClick={incrementProgress}>
52+
</IgrIconButton>
53+
</div>
54+
</div>
55+
);
7956
}
8057

8158
// rendering above class to the React DOM

0 commit comments

Comments
 (0)