UNPKG

@itwin/core-react

Version:

A react component library of iTwin.js UI general purpose components

38 lines 1.82 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Common */ import * as React from "react"; /** withIsPressed is a React higher-order component that adds pointer and mouse events. * @public * @deprecated in 4.15.0. Not used by AppUI. */ export const withIsPressed = (Component) => { return class WithIsPressed extends React.PureComponent { handleOnPointerDown = () => { this.changeIsPressed(true); }; handleOnPointerUp = () => { this.changeIsPressed(false); }; handleOnMouseLeave = () => { this.changeIsPressed(false); }; changeIsPressed = (isPressed) => { if (this.props.isPressed === isPressed) return; this.props.onIsPressedChange && this.props.onIsPressedChange(isPressed); }; render() { const { isPressed, onIsPressedChange, ...props } = this.props; // todo: better solution to rest object of intersected type return ( // eslint-disable-next-line jsx-a11y/no-static-element-interactions React.createElement("div", { className: "withispressed-wrapper", onMouseDown: this.handleOnPointerDown, onMouseUp: this.handleOnPointerUp, onTouchStart: this.handleOnPointerDown, onTouchEnd: this.handleOnPointerUp, onMouseLeave: this.handleOnMouseLeave }, React.createElement(Component, { ...props, ...this.state }))); } }; }; //# sourceMappingURL=withIsPressed.js.map