UNPKG

@atlaskit/drawer

Version:

A drawer is a panel that slides in from the left side of the screen.

76 lines (73 loc) • 3.86 kB
/* drawer-content.tsx generated by @compiled/babel-plugin v3.0.2 */ "use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.DrawerContent = void 0; require("./drawer-content.compiled.css"); var _react = _interopRequireWildcard(require("react")); var React = _react; var _runtime = require("@compiled/react/runtime"); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _reactScrolllock = _interopRequireDefault(require("react-scrolllock")); var _useCallbackRef = require("use-callback-ref"); var _fg = require("@atlaskit/platform-feature-flags/fg"); var _useEnsureIsInsideDrawer = require("../use-ensure-is-inside-drawer"); var _usePreventProgrammaticScroll = _interopRequireDefault(require("./hooks/use-prevent-programmatic-scroll")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var styles = { default: "_16jlkb7n _1o9zkb7n _i0dlf1ug _1reo1wug _18m91wug _19pk1ejb" }; var DrawerContentBase = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, scrollableRef) { var children = _ref.children, _ref$scrollContentLab = _ref.scrollContentLabel, scrollContentLabel = _ref$scrollContentLab === void 0 ? 'Scrollable content' : _ref$scrollContentLab, xcss = _ref.xcss; var _useState = (0, _react.useState)(false), _useState2 = (0, _slicedToArray2.default)(_useState, 2), showContentFocus = _useState2[0], setContentFocus = _useState2[1]; var ref = (0, _react.useRef)(null); (0, _react.useEffect)(function () { var setLazyContentFocus = function setLazyContentFocus() { var target = ref.current; target && setContentFocus(target.scrollHeight > target.clientHeight); }; setLazyContentFocus(); }, []); return /*#__PURE__*/React.createElement("div", { className: (0, _runtime.ax)([styles.default, xcss]), ref: (0, _useCallbackRef.mergeRefs)([ref, scrollableRef]) // tabindex is allowed here so that keyboard users can scroll content , tabIndex: showContentFocus ? 0 : undefined, role: showContentFocus ? 'region' : undefined, "aria-label": showContentFocus ? scrollContentLabel : undefined, "data-testid": "drawer-contents" }, children); }); /** * __Drawer content__ * * The main content section of the drawer panel. */ var DrawerContent = exports.DrawerContent = function DrawerContent(_ref2) { var children = _ref2.children, scrollContentLabel = _ref2.scrollContentLabel, xcss = _ref2.xcss; (0, _useEnsureIsInsideDrawer.useEnsureIsInsideDrawer)(); (0, _usePreventProgrammaticScroll.default)(); var content = /*#__PURE__*/React.createElement(DrawerContentBase, { scrollContentLabel: scrollContentLabel, xcss: xcss }, children); // Under the top-layer flag, background scroll is handled by `DialogScrollLock` // (rendered by `DrawerTopLayer`), so we skip `react-scrolllock` here to avoid // double-locking the body. See the top-layer migration scroll decision. if ((0, _fg.fg)('platform-dst-top-layer')) { return content; } return /*#__PURE__*/React.createElement(_reactScrolllock.default, null, content); };