Skip to content

Commit

Permalink
Progress Component - V1 (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
kotAPI authored Jan 7, 2024
1 parent 9d35ee8 commit 79680e7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/ui/Progress/Progress.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

import Progress from './Progress';
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';


// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
title: 'UI/Data Display/Progress',
component: Progress,
render: (args) => <SandboxEditor>
<div className='text-gray-950 my-10'>
<Progress {...args} />
</div>
</SandboxEditor>,
};

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const All = {
args: {
label: 'progress label',
maxValue: 100,
value: 45,
},
};
34 changes: 34 additions & 0 deletions src/components/ui/Progress/Progress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, {useState, useEffect} from 'react';

interface ProgressProps {
value: number;
maxValue: number;
label: string;
}

const Progress: React.FC<ProgressProps> = ({value, maxValue, label}) => {
console.log(label);
const [percentage, setPercentage] = useState(0);

useEffect(() => {
const calculatedPercentage = (value / maxValue) * 100;
setPercentage(calculatedPercentage);
}, [value, maxValue]);

return (
<div className="bg-gray-300 rounded-md">
<div
role="progressbar"
className='bg-red-800 rounded-md text-right'
aria-valuenow={value}
aria-valuemax={maxValue}
aria-valuemin={0}
style={{width: `${percentage}%`}}
>
<span className='text-gray-1000 p-2 text-sm'>{label}</span>
</div>
</div>
);
};

export default Progress;

0 comments on commit 79680e7

Please sign in to comment.