UNPKG

@atlaskit/blanket

Version:

A blanket covers the underlying UI for a layered component, such as a modal dialog or a tooltip.

63 lines (62 loc) • 3.32 kB
/* blanket.tsx generated by @compiled/babel-plugin v3.0.2 */ import _defineProperty from "@babel/runtime/helpers/defineProperty"; import "./blanket.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { forwardRef, memo, useCallback, useRef } from 'react'; import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler'; import noop from '@atlaskit/ds-lib/noop'; import { layers } from '@atlaskit/theme/constants'; var packageName = "@atlaskit/blanket"; var packageVersion = "16.4.3"; var analyticsAttributes = { componentName: 'blanket', packageName: packageName, packageVersion: packageVersion }; var baseStyles = null; var shouldAllowClickThroughStyles = null; var invisibleStyles = null; /** * __Blanket__ * * A Blanket provides the overlay layer for components such as a modal dialog or a tooltip * * - [Examples](https://atlaskit.atlassian.com/examples/design-system/blanket/basic-usage) */ var Blanket = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Blanket(_ref, ref) { var _ref$shouldAllowClick = _ref.shouldAllowClickThrough, shouldAllowClickThrough = _ref$shouldAllowClick === void 0 ? false : _ref$shouldAllowClick, _ref$isTinted = _ref.isTinted, isTinted = _ref$isTinted === void 0 ? false : _ref$isTinted, _ref$onBlanketClicked = _ref.onBlanketClicked, onBlanketClicked = _ref$onBlanketClicked === void 0 ? noop : _ref$onBlanketClicked, testId = _ref.testId, children = _ref.children, analyticsContext = _ref.analyticsContext; var mouseDownTarget = useRef(null); var onBlanketClickedWithAnalytics = usePlatformLeafEventHandler(_objectSpread({ fn: onBlanketClicked, action: 'clicked', analyticsData: analyticsContext }, analyticsAttributes)); var blanketClickOutsideChildren = useCallback(function (e) { return e.currentTarget === e.target && mouseDownTarget.current === e.target ? onBlanketClickedWithAnalytics(e) : undefined; }, [onBlanketClickedWithAnalytics]); var onClick = shouldAllowClickThrough ? undefined : blanketClickOutsideChildren; var onMouseDown = useCallback(function (e) { mouseDownTarget.current = e.target; }, []); return /*#__PURE__*/React.createElement("div", { role: "presentation", onClick: onClick, onMouseDown: onMouseDown, "data-testid": testId, ref: ref, className: ax(["_1r04idpf _kqsw1n9t _1pbybfng _bfhk1i5c _18m91wug _lcxv1wug", shouldAllowClickThrough && "_lcxvglyw", !isTinted && "_bfhk1j28"]) }, children); })); Blanket.displayName = 'Blanket'; export default Blanket;