2020-06-26 14:02:36 +01:00
|
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
|
Copyright 2020-2022 The Matrix.org Foundation C.I.C.
|
2020-06-26 14:02:36 +01:00
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-06-26 14:02:36 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
2022-07-29 13:43:29 +02:00
|
|
|
|
import { useSmoothAnimation } from "../../../hooks/useSmoothAnimation";
|
|
|
|
|
|
|
2020-06-26 14:02:36 +01:00
|
|
|
|
interface IProps {
|
|
|
|
|
|
value: number;
|
|
|
|
|
|
max: number;
|
2022-07-29 13:43:29 +02:00
|
|
|
|
animated?: boolean;
|
2020-06-26 14:02:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-29 13:43:29 +02:00
|
|
|
|
const PROGRESS_BAR_ANIMATION_DURATION = 300;
|
2022-08-25 16:39:00 +01:00
|
|
|
|
const ProgressBar: React.FC<IProps> = ({ value, max, animated = true }) => {
|
2022-07-29 13:43:29 +02:00
|
|
|
|
// Animating progress bars via CSS transition isn’t possible in all of our supported browsers yet.
|
|
|
|
|
|
// As workaround, we’re using animations through JS requestAnimationFrame
|
2022-08-25 16:39:00 +01:00
|
|
|
|
const currentValue = useSmoothAnimation(0, value, animated ? PROGRESS_BAR_ANIMATION_DURATION : 0);
|
2022-07-29 13:43:29 +02:00
|
|
|
|
return <progress className="mx_ProgressBar" max={max} value={currentValue} />;
|
2020-06-26 14:02:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default ProgressBar;
|