Skip to content

Commit

Permalink
improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Dec 18, 2024
1 parent 346890c commit 53848d3
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/web/components/folding/folding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,26 @@ const foldDelay = keyframes`
}
`;

const Div = styled.div`
const FoldableDiv = styled.div`
overflow: hidden;
transition: 0.4s;
transition: height 0.4s;
display: ${({$foldState}) =>
$foldState === FoldState.FOLDED ? 'none' : undefined};
$foldState === FoldState.FOLDED ? 'none' : 'block'};
height: ${({$foldState}) => {
if ($foldState === FoldState.FOLDED || $foldState === FoldState.FOLDING) {
return 0;
switch ($foldState) {
case FoldState.FOLDED:
case FoldState.FOLDING:
return '0px';
case FoldState.FOLDING_START:
case FoldState.UNFOLDING:
return `${Math.ceil(window.innerHeight * 1.2)}px`;

Check warning on line 45 in src/web/components/folding/folding.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/folding/folding.jsx#L45

Added line #L45 was not covered by tests
case FoldState.UNFOLDING_START:
return '1px';

Check warning on line 47 in src/web/components/folding/folding.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/folding/folding.jsx#L47

Added line #L47 was not covered by tests
default:
return 'auto';
}
if (
$foldState === FoldState.FOLDING_START ||
$foldState === FoldState.UNFOLDING
) {
const windowHeight = Math.ceil(window.innerHeight * 1.2) + 'px';
return windowHeight;
}
if ($foldState === FoldState.UNFOLDING_START) {
return '1px';
}
return undefined;
}};
animation: ${({$foldState}) =>
Expand All @@ -58,7 +56,7 @@ const Div = styled.div`
? css`
${foldDelay} 0.01s
`
: undefined};
: 'none'};
`;

const FoldStatePropType = PropTypes.oneOf([
Expand All @@ -81,13 +79,13 @@ export const withFolding = Component => {
onFoldToggle,
...props
}) => (
<Div
<FoldableDiv
$foldState={foldState}
onAnimationEnd={onFoldStepEnd}
onTransitionEnd={onFoldStepEnd}
>
<Component {...props} />
</Div>
</FoldableDiv>
);

FoldingWrapper.propTypes = {
Expand Down

0 comments on commit 53848d3

Please sign in to comment.