All files / src/components/SplitPane StyledSplitPane.tsx

0% Statements 0/17
100% Branches 0/0
0% Functions 0/5
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                                               
import React from 'react';
 
import {cn} from '../../utils/cn';
 
import {Pane} from './Pane';
import {SplitPane} from './SplitPane';
import type {SplitPaneProps} from './SplitPane';
 
import './StyledSplitPane.scss';
 
const b = cn('styled-split-pane');
const resizerClassName = b('pane-resizer');
 
type Props = SplitPaneProps & {
    paneOneRender: () => React.ReactNode;
    paneTwoRender: () => React.ReactNode;
};
 
export const StyledSplitPane = ({paneOneRender, paneTwoRender, ...splitPaneProps}: Props) => {
    const splitPaneRef = React.useRef<SplitPane & {splitPane?: HTMLDivElement | null}>(null);
 
    React.useEffect(() => {
        const resizer =
            splitPaneRef.current?.splitPane?.getElementsByClassName(resizerClassName)[0];
        const hoveredClassName = `${resizerClassName}_hovered`;
 
        const onTouchStart = () => {
            resizer?.classList.add(hoveredClassName);
        };
 
        const onTouchEnd = () => {
            resizer?.classList.remove(hoveredClassName);
        };
 
        resizer?.addEventListener('touchstart', onTouchStart);
        resizer?.addEventListener('touchend', onTouchEnd);
 
        return function cleanup() {
            resizer?.removeEventListener('touchstart', onTouchStart);
            resizer?.removeEventListener('touchend', onTouchEnd);
        };
    }, []);
 
    return (
        <SplitPane
            {...splitPaneProps}
            ref={splitPaneRef}
            className={b()}
            resizerClassName={resizerClassName}
        >
            <Pane>{paneOneRender()}</Pane>
            <Pane>{paneTwoRender()}</Pane>
        </SplitPane>
    );
};