Skip to content

Commit

Permalink
refactor: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Sep 25, 2023
1 parent bf9cc45 commit 2e6e2e3
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/ProgressBar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ProgressBar(props) {
return <ProgressBarBase {...props} />;
}

const ProgressBarAnnotated = React.forwardRef(({
function ProgressBarAnnotated({
now,
label,
variant,
Expand All @@ -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);
Expand All @@ -71,7 +62,7 @@ const ProgressBarAnnotated = React.forwardRef(({
);

return (
<div ref={progressAnnotatedRef} className="pgn__progress-annotated">
<div className="pgn__progress-annotated">
{!!label && (
<div
className="pgn__progress-info"
Expand Down Expand Up @@ -121,7 +112,7 @@ const ProgressBarAnnotated = React.forwardRef(({
)}
</div>
);
});
}

ProgressBarAnnotated.propTypes = {
/** Current value of progress. */
Expand Down

0 comments on commit 2e6e2e3

Please sign in to comment.