packageDocumentation module import * as React from "react" ; public export interface WithIsPressedProps { /** initial value for pressed status */ isPressed ? : boolean ; /** callback function for [isPressed] change */ onIsPressedChange ? : ( isPressed : boolean ) => void ; } public export const withIsPressed = < ComponentProps extends { } > ( Component ) => { return class WithIsPressed extends React . PureComponent < ComponentProps & WithIsPressedProps > { public handleOnPointerDown = ( ) => { this . changeIsPressed ( true ) ; } ; public handleOnPointerUp = ( ) => { this . changeIsPressed ( false ) ; } ; public handleOnMouseLeave = ( ) => { this . changeIsPressed ( false ) ; } ; public changeIsPressed = ( isPressed ) => { if ( this . props . isPressed === isPressed ) return ; this . props . onIsPressedChange && this . props . onIsPressedChange ( isPressed ) ; } ; public override render ( ) { const { isPressed , onIsPressedChange , ... props } = this . props ; return ( < div className = "withispressed-wrapper" onMouseDown = { this . handleOnPointerDown } onMouseUp = { this . handleOnPointerUp } onTouchStart = { this . handleOnPointerDown } onTouchEnd = { this . handleOnPointerUp } onMouseLeave = { this . handleOnMouseLeave } > < Component { ... props as ComponentProps } { ... this . state } /> < /div>); } } ; } ;