mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 02:35:23 -04:00
Fix Splitter issues (#1343)
Fix Splitter issues * Replace code with hook useAdjustedRelativeSplitValue * Add e2e tests for splitter Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
015a5cf496
commit
6cfcc37b1c
4 changed files with 94 additions and 6 deletions
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react'
|
||||
|
||||
/**
|
||||
* Calculates the adjusted relative split value.
|
||||
*
|
||||
* @param showLeft Defines if the left split pane should be shown
|
||||
* @param showRight Defines if the right split pane should be shown
|
||||
* @param relativeSplitValue The relative size ratio of the split
|
||||
* @return the limited (0% to 100%) relative split value. If only the left or right pane should be shown then the return value will be always 100 or 0
|
||||
*/
|
||||
export const useAdjustedRelativeSplitValue = (
|
||||
showLeft: boolean,
|
||||
showRight: boolean,
|
||||
relativeSplitValue: number
|
||||
): number =>
|
||||
useMemo(() => {
|
||||
let splitValue: number
|
||||
if (!showLeft && showRight) {
|
||||
splitValue = 0
|
||||
} else if (showLeft && !showRight) {
|
||||
splitValue = 100
|
||||
} else {
|
||||
splitValue = relativeSplitValue
|
||||
}
|
||||
|
||||
return Math.min(100, Math.max(0, splitValue))
|
||||
}, [relativeSplitValue, showLeft, showRight])
|
Loading…
Add table
Add a link
Reference in a new issue