UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

63 lines (60 loc) 1.65 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import { PureComponent } from 'react'; import PropTypes from 'prop-types'; import Event from '@shopgate/pwa-core/classes/Event'; import { EVENT_KEYBOARD_WILL_CHANGE } from '@shopgate/pwa-core/constants/AppEvents'; /** * Keyboard state consumer. */ let KeyboardConsumer = /*#__PURE__*/function (_PureComponent) { /** * Initializes the component state. * @param {Object} props The components props. */ function KeyboardConsumer(props) { var _this; _this = _PureComponent.call(this, props) || this; /** * Stores current keyboard state. */ _this.handleKeyboardChange = ({ open, overlap, duration }) => { _this.setState({ open, overlap, duration }); }; _this.state = { open: false, overlap: 0, duration: 0 }; return _this; } /** * Listen to keyboard changes as soon as the component mounts. */ _inheritsLoose(KeyboardConsumer, _PureComponent); var _proto = KeyboardConsumer.prototype; _proto.componentDidMount = function componentDidMount() { Event.addCallback(EVENT_KEYBOARD_WILL_CHANGE, this.handleKeyboardChange); } /** * Remove listener when component will unmount. */; _proto.componentWillUnmount = function componentWillUnmount() { Event.removeCallback(EVENT_KEYBOARD_WILL_CHANGE, this.handleKeyboardChange); }; /** * @returns {JSX} */ _proto.render = function render() { return this.props.children(this.state); }; return KeyboardConsumer; }(PureComponent); export default KeyboardConsumer;