@atlaskit/blanket
Version:
A blanket covers the underlying UI for a layered component, such as a modal dialog or a tooltip.
57 lines (56 loc) • 2.13 kB
JavaScript
/* blanket.tsx generated by @compiled/babel-plugin v3.0.2 */
import "./blanket.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
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';
const packageName = "@atlaskit/blanket";
const packageVersion = "16.4.3";
const analyticsAttributes = {
componentName: 'blanket',
packageName,
packageVersion
};
const baseStyles = null;
const shouldAllowClickThroughStyles = null;
const 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)
*/
const Blanket = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Blanket({
shouldAllowClickThrough = false,
isTinted = false,
onBlanketClicked = noop,
testId,
children,
analyticsContext
}, ref) {
const mouseDownTarget = useRef(null);
const onBlanketClickedWithAnalytics = usePlatformLeafEventHandler({
fn: onBlanketClicked,
action: 'clicked',
analyticsData: analyticsContext,
...analyticsAttributes
});
const blanketClickOutsideChildren = useCallback(e => e.currentTarget === e.target && mouseDownTarget.current === e.target ? onBlanketClickedWithAnalytics(e) : undefined, [onBlanketClickedWithAnalytics]);
const onClick = shouldAllowClickThrough ? undefined : blanketClickOutsideChildren;
const onMouseDown = useCallback(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;