'use client'; import type { ComponentProps, CSSProperties, FC } from 'react'; import { EVENT_CAPTURE_PARAMS, useEventListener } from './internal-hooks'; import { useReactCompareSliderContext } from './provider'; import { ReactCompareSliderCssVars } from '../consts'; export type HandleRootProps = ComponentProps<'div'>; /** Container to control the handle's position. */ export const HandleRoot: FC = ({ style, ...props }) => { const { disabled, portrait, position, handleRootRef, onHandleRootClick, onHandleRootKeyDown } = useReactCompareSliderContext(); const appliedStyle: CSSProperties = { WebkitAppearance: 'none', MozAppearance: 'none', WebkitTapHighlightColor: 'transparent', boxSizing: 'border-box', position: 'absolute', display: 'flex', flexDirection: portrait ? 'row' : 'column', placeItems: 'center', contain: 'layout', top: portrait ? '-50%' : undefined, left: portrait ? undefined : `-50%`, width: '100%', height: '100%', background: 'none', border: 0, padding: 0, pointerEvents: 'none', appearance: 'none', outline: 0, zIndex: 1, translate: portrait ? `0 var(${ReactCompareSliderCssVars.currentPosition}) 0` : `var(${ReactCompareSliderCssVars.currentPosition}) 0 0`, backfaceVisibility: 'hidden', willChange: 'translate', ...style, }; useEventListener('keydown', onHandleRootKeyDown, handleRootRef.current, EVENT_CAPTURE_PARAMS); useEventListener('click', onHandleRootClick, handleRootRef.current, EVENT_CAPTURE_PARAMS); return (
); };