Skip to content

Commit 069a5fb

Browse files
feat: removed variant from circular progress bar component
1 parent 0126ca3 commit 069a5fb

File tree

3 files changed

+24
-79
lines changed

3 files changed

+24
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
import React from 'react';
2-
import { render, fireEvent } from '@testing-library/react';
3-
import { CircularProgressBar } from '..';
1+
import React from "react";
2+
import { render } from "@testing-library/react";
3+
import { CircularProgressBar } from "..";
44

5-
describe('CircularProgressBar Component', () => {
6-
it('renders correctly with default props', () => {
7-
const { container } = render(<CircularProgressBar variant="clockwise" />);
8-
expect(container.querySelector('.deriv-circular-progress__bar')).toBeInTheDocument();
5+
describe("CircularProgressBar Component", () => {
6+
it("renders correctly with default props", () => {
7+
const { container } = render(<CircularProgressBar/>);
8+
expect(container.querySelector(".deriv-circular-progress__bar")).toBeInTheDocument();
99
});
1010

11-
it('renders children correctly', () => {
11+
it("renders children correctly", () => {
1212
const { getByText } = render(
13-
<CircularProgressBar variant="clockwise">
13+
<CircularProgressBar>
1414
<div className="circular-progress-content">Child content</div>
1515
</CircularProgressBar>
1616
);
17-
expect(getByText('Child content')).toBeInTheDocument();
17+
expect(getByText("Child content")).toBeInTheDocument();
1818
});
1919

20-
it('handles selection correctly for selectable variant', () => {
21-
const onSelectMock = jest.fn();
22-
const { container } = render(
23-
<CircularProgressBar variant="selectable" onSelect={onSelectMock} />
24-
);
25-
const progressBar = container.querySelector('.deriv-circular-progress__bar');
26-
if (progressBar) {
27-
fireEvent.click(progressBar);
28-
expect(onSelectMock).toHaveBeenCalled();
29-
} else {
30-
fail('Progress bar not found');
31-
}
32-
20+
it("renders correctly with isClockwise prop as True", () => {
21+
const { container } = render(<CircularProgressBar is_clockwise/>);
22+
expect(container.querySelector(".deriv-circular-progress--clockwise")).toBeInTheDocument();
3323
});
24+
3425
});

src/components/CircularProgressBar/index.tsx

+4-33
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import clsx from "clsx";
2-
import React, { ReactNode, useState } from "react";
2+
import React, { ReactNode} from "react";
33
import "./CircularProgressBar.scss"
44

5-
type TVariant = "clockwise" | "static" | "selectable"
65
type TCircularProgressProps = {
76
children?: ReactNode;
87
className?: string;
@@ -13,8 +12,6 @@ type TCircularProgressProps = {
1312
stroke?: number;
1413
warning_limit?: number;
1514
icon?: ReactNode;
16-
variant?: TVariant;
17-
onSelect?: () => void;
1815
};
1916

2017
export const CircularProgressBar = ({
@@ -26,25 +23,14 @@ export const CircularProgressBar = ({
2623
radius = 22,
2724
stroke = 3,
2825
warning_limit = 50,
29-
variant = "clockwise",
30-
onSelect // Function to be called when circle is selected
3126
}: TCircularProgressProps) => {
3227
const normalizedRadius = radius - stroke / 2;
3328
const circumference = normalizedRadius * 2 * Math.PI;
3429
const strokeDashoffset = circumference - (progress / 100) * circumference;
3530

36-
const [selected, setSelected] = useState(false);
37-
38-
const handleSelect = () => {
39-
setSelected(prev=>!prev);
40-
if (onSelect) {
41-
onSelect();
42-
}
43-
};
44-
4531
return (
4632
<div className={clsx("deriv-circular-progress", className)}>
47-
<svg height={radius * 2} width={radius * 2} onClick={variant === "selectable" ? handleSelect : undefined}>
33+
<svg height={radius * 2} width={radius * 2}>
4834
{children && (
4935
<foreignObject x="0" y="0" width={radius * 2} height={radius * 2}>
5036
<div className={clsx("deriv-circular-progress__content")}>
@@ -57,30 +43,15 @@ export const CircularProgressBar = ({
5743
"deriv-circular-progress--clockwise": is_clockwise,
5844
"deriv-circular-progress__bar--warning": progress <= warning_limit && progress > danger_limit,
5945
"deriv-circular-progress__bar--danger": progress <= danger_limit,
60-
"deriv-circular-progress__bar--selected": selected && variant === "selectable"
6146
})}
6247
cx={radius}
6348
cy={radius}
64-
fill={variant === "selectable" && selected ? "blue" : "transparent"}
49+
fill={"transparent"}
6550
r={normalizedRadius}
6651
strokeDasharray={`${circumference} ${circumference}`}
6752
strokeWidth={stroke}
68-
style={variant != "clockwise" ? { strokeDashoffset: "none" } : { strokeDashoffset }}
53+
style={{ strokeDashoffset }}
6954
/>
70-
{
71-
variant != "clockwise" && (
72-
<circle
73-
cx={radius}
74-
cy={radius}
75-
r={normalizedRadius}
76-
fill="none"
77-
stroke="#E8EEFC"
78-
strokeDasharray={`${circumference} ${circumference}`}
79-
strokeWidth={stroke}
80-
style={{ strokeDashoffset: circumference - strokeDashoffset }}
81-
/>
82-
)
83-
}
8455
</svg>
8556
</div>
8657
);

stories/CircularProgressBar.stories.tsx

+6-23
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ const meta = {
1414
stroke: 3,
1515
danger_limit: 20,
1616
warning_limit: 50,
17-
variant:"clockwise"
17+
is_clockwise:false
1818
},
1919
argTypes: {
2020
progress: {
2121
control: { type: "range", min: 0, max: 100, step: 1 },
2222
},
23+
is_clockwise: {
24+
options: ["true", "false"],
25+
control: { type: "boolean" },
26+
}
2327
},
2428
} as Meta<typeof CircularProgressBar>;
2529
export default meta;
@@ -30,19 +34,6 @@ export const DefaultClockWise: Story = {
3034
progress: 50,
3135
}
3236
}
33-
export const StaticProgressBar:Story = {
34-
args:{
35-
progress: 50,
36-
variant: 'static',
37-
}
38-
}
39-
40-
export const SelectableProgressBar:Story = {
41-
args:{
42-
progress: 30,
43-
variant: 'selectable',
44-
}
45-
}
4637

4738
export const CustomRadiusAndStrokeClockwise: Story = {
4839
args: {
@@ -59,17 +50,9 @@ export const ClockwiseProgress: Story = {
5950
}
6051
}
6152

62-
export const WithIconSelectable: Story = {
63-
args: {
64-
progress: 80,
65-
children: <span>🔄</span>,
66-
variant:"selectable"
67-
}
68-
}
69-
7053
export const WarningLimitClockWise = {
7154
args: {
72-
progress: 40,
55+
progress: 30,
7356
warning_limit: 30,
7457
}
7558
}

0 commit comments

Comments
 (0)