soapbox/app/soapbox/components/ui/progress-bar/progress-bar.tsx

34 wiersze
926 B
TypeScript
Czysty Zwykły widok Historia

2023-02-03 00:03:22 +00:00
import clsx from 'clsx';
2022-05-02 16:57:14 +00:00
import React from 'react';
2023-02-03 00:03:22 +00:00
import { spring } from 'react-motion';
import Motion from 'soapbox/features/ui/util/optional-motion';
2022-05-02 16:57:14 +00:00
interface IProgressBar {
2023-02-03 00:03:22 +00:00
/** Number between 0 and 1 to represent the percentage complete. */
progress: number
/** Height of the progress bar. */
size?: 'sm' | 'md'
2022-05-02 16:57:14 +00:00
}
/** A horizontal meter filled to the given percentage. */
2023-02-03 00:03:22 +00:00
const ProgressBar: React.FC<IProgressBar> = ({ progress, size = 'md' }) => (
<div
className={clsx('h-2.5 w-full overflow-hidden rounded-lg bg-gray-300 dark:bg-primary-800', {
2023-02-03 00:03:22 +00:00
'h-2.5': size === 'md',
'h-[6px]': size === 'sm',
})}
>
<Motion defaultStyle={{ width: 0 }} style={{ width: spring(progress * 100) }}>
{({ width }) => (
<div
className='h-full bg-secondary-500'
style={{ width: `${width}%` }}
/>
)}
</Motion>
2022-05-02 16:57:14 +00:00
</div>
);
export default ProgressBar;