UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

118 lines 7.39 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Drawer = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); /** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ const react_1 = require("@floating-ui/react"); const classnames_1 = __importDefault(require("classnames")); const re_resizable_1 = require("re-resizable"); const react_2 = require("react"); const clean_icon_button_1 = require("../clean-icon-button"); const conditional_wrap_1 = require("../conditional-wrap"); const icons_1 = require("../icons"); const typography_1 = require("../typography"); const DrawerComponent = function DrawerComponent(_a) { var { children, className = '', isExpanded, onExpandedChange, position = 'left', type = 'overlay', isResizeable = false, resizeableProps, isCloseable = true, isPortaled = false, portalProps = {}, htmlAttributes, style, ref, as } = _a, restProps = __rest(_a, ["children", "className", "isExpanded", "onExpandedChange", "position", "type", "isResizeable", "resizeableProps", "isCloseable", "isPortaled", "portalProps", "htmlAttributes", "style", "ref", "as"]); const setOnExpandedChange = (0, react_2.useCallback)(() => { if (onExpandedChange) { onExpandedChange(!isExpanded); } }, [isExpanded, onExpandedChange]); const classes = (0, classnames_1.default)('ndl-drawer', className, { 'ndl-drawer-expanded': isExpanded, 'ndl-drawer-left': position === 'left', 'ndl-drawer-overlay': type === 'overlay', 'ndl-drawer-push': type === 'push', 'ndl-drawer-right': position === 'right', }); const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative'; const shouldRenderInPortal = isPortaled && type === 'overlay'; const Component = as !== null && as !== void 0 ? as : 'div'; const Close = () => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isCloseable && ((0, jsx_runtime_1.jsx)(clean_icon_button_1.CleanIconButton, { className: "ndl-drawer-close-button", onClick: setOnExpandedChange, description: "Close", size: "medium", htmlAttributes: { title: 'Close drawer', }, children: (0, jsx_runtime_1.jsx)(icons_1.XMarkIconOutline, {}) })) })); if (isResizeable) { return ((0, jsx_runtime_1.jsx)(conditional_wrap_1.ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, Object.assign({ as: Component, defaultSize: { height: '100%', width: 'auto', } }, resizeableProps, { className: classes, style: Object.assign(Object.assign({ position: resizableStylePosition }, style), resizeableProps === null || resizeableProps === void 0 ? void 0 : resizeableProps.style), boundsByDirection: true, bounds: "parent", handleStyles: { /* * adding a small offset to the handle to make it easier to click * if the content of the drawer is scrollable, most noticeable if not using * a mouse on mac or chrome on windows with the fluent scrollbars */ right: { right: '-8px', }, }, enable: { bottom: false, bottomLeft: false, bottomRight: false, left: position === 'right', right: position === 'left', top: false, topLeft: false, topRight: false, }, ref: ref }, restProps, htmlAttributes, { children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) })); } return ((0, jsx_runtime_1.jsx)(conditional_wrap_1.ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: (0, jsx_runtime_1.jsxs)(Component, Object.assign({ className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) })); }; DrawerComponent.displayName = 'Drawer'; const DrawerHeader = (_a) => { var { children, className = '', htmlAttributes } = _a, restProps = __rest(_a, ["children", "className", "htmlAttributes"]); const classes = (0, classnames_1.default)('ndl-drawer-header', className); if (typeof children === 'string' || typeof children === 'number') { return ((0, jsx_runtime_1.jsx)(typography_1.Typography, Object.assign({ className: classes, variant: "title-3" }, restProps, htmlAttributes, { children: children }))); } return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes }, restProps, htmlAttributes, { children: children }))); }; const DrawerActions = (_a) => { var { children, className = '', htmlAttributes } = _a, restProps = __rest(_a, ["children", "className", "htmlAttributes"]); const classes = (0, classnames_1.default)('ndl-drawer-actions', className); return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes }, restProps, htmlAttributes, { children: children }))); }; const DrawerBody = (_a) => { var { children, className = '', htmlAttributes } = _a, restProps = __rest(_a, ["children", "className", "htmlAttributes"]); const classes = (0, classnames_1.default)('ndl-drawer-body', className); return ((0, jsx_runtime_1.jsx)("div", { className: "ndl-drawer-body-wrapper", children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes }, restProps, htmlAttributes, { children: children })) })); }; const Drawer = Object.assign(DrawerComponent, { Actions: DrawerActions, Body: DrawerBody, Header: DrawerHeader, }); exports.Drawer = Drawer; //# sourceMappingURL=Drawer.js.map