From 20c9585708ced16d4285fe75923b219b62a24de3 Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Mon, 25 Sep 2023 12:32:57 +0300 Subject: [PATCH] refactor: code refactoring --- src/ProgressBar/index.jsx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/ProgressBar/index.jsx b/src/ProgressBar/index.jsx index 276df819a1..606f06f032 100644 --- a/src/ProgressBar/index.jsx +++ b/src/ProgressBar/index.jsx @@ -20,7 +20,7 @@ function ProgressBar(props) { return ; } -const ProgressBarAnnotated = React.forwardRef(({ +function ProgressBarAnnotated({ now, label, variant, @@ -30,24 +30,15 @@ const ProgressBarAnnotated = React.forwardRef(({ progressHint, thresholdHint, ...props -}, ref) => { - const [direction, setDirection] = React.useState('ltr'); +}) { const progressInfoRef = React.useRef(); const thresholdInfoRef = React.useRef(); - const progressAnnotatedRef = React.useRef(); - const resolvedRef = ref || progressAnnotatedRef; const thresholdPercent = (threshold || 0) - (now || 0); const isProgressHintAfter = now < HINT_SWAP_PERCENT; const isThresholdHintAfter = threshold < HINT_SWAP_PERCENT; const progressColor = VARIANTS.includes(variant) ? variant : PROGRESS_DEFAULT_VARIANT; const thresholdColor = VARIANTS.includes(thresholdVariant) ? thresholdVariant : THRESHOLD_DEFAULT_VARIANT; - - useEffect(() => { - if (resolvedRef.current) { - const pageDirection = window.getComputedStyle(resolvedRef.current).getPropertyValue('direction'); - setDirection(pageDirection); - } - }, [resolvedRef]); + const direction = window.getComputedStyle(document.body).getPropertyValue('direction'); const positionAnnotations = useCallback(() => { placeInfoAtZero(progressInfoRef, direction, isProgressHintAfter, ANNOTATION_CLASS); @@ -71,7 +62,7 @@ const ProgressBarAnnotated = React.forwardRef(({ ); return ( -
+
{!!label && (
); -}); +} ProgressBarAnnotated.propTypes = { /** Current value of progress. */