UNPKG

@s-ui/react-ad-blocker-extension-detector

Version:

> This component has only the logic of show content (i.e banner or message) through children when user has adblock. If you are using adblock just right now you should see a placeholder sentence like: <<"If you see this message you are using adblock extens

44 lines 1.67 kB
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; import { Component, createRef } from 'react'; import PropTypes from 'prop-types'; import { jsx as _jsx } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var AdBlockerExtensionDetector = /*#__PURE__*/function (_Component) { _inheritsLoose(AdBlockerExtensionDetector, _Component); function AdBlockerExtensionDetector(props) { var _this; _this = _Component.call(this, props) || this; _this._detectIfAdBlockerIsEnabled = function () { var blockDetector = _this.blockDetector.current; var isBlockerAdviseActive = blockDetector.offsetHeight === 0; _this.setState({ displayBanner: isBlockerAdviseActive, showBlockDetector: false }); }; _this.blockDetector = /*#__PURE__*/createRef(); _this.state = { displayBanner: false, showBlockDetector: true }; return _this; } var _proto = AdBlockerExtensionDetector.prototype; _proto.componentDidMount = function componentDidMount() { this._detectIfAdBlockerIsEnabled(); }; _proto.render = function render() { var children = this.props.children; return /*#__PURE__*/_jsxs(_Fragment, { children: [this.state.displayBanner && children, this.state.showBlockDetector && /*#__PURE__*/_jsx("div", { ref: this.blockDetector, className: "adsbox", children: "\xA0" })] }); }; return AdBlockerExtensionDetector; }(Component); AdBlockerExtensionDetector.displayName = 'AdBlockerExtensionDetector'; export default AdBlockerExtensionDetector;