@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
114 lines • 6.91 kB
JavaScript
"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Drawer = exports.DrawerComponent = 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 re_resizable_1 = require("re-resizable");
const react_2 = require("react");
const defaultImports_1 = require("../_common/defaultImports");
const conditional_wrap_1 = require("../conditional-wrap");
const helpers_1 = require("../helpers");
const icon_button_1 = require("../icon-button");
const icons_1 = require("../icons");
exports.DrawerComponent = (0, helpers_1.forwardRef)(function DrawerComponent({ children, className = '', isExpanded, onExpandedChange, position = 'left', type = 'overlay', isResizeable = false, resizeableProps, isCloseable = true, isPortaled = false, portalProps = {}, htmlAttributes, }, ref) {
const setOnExpandedChange = (0, react_2.useCallback)(() => {
if (onExpandedChange)
onExpandedChange(!isExpanded);
}, [isExpanded, onExpandedChange]);
const classes = (0, defaultImports_1.classNames)('ndl-drawer', className, {
'ndl-drawer-expanded': isExpanded,
'ndl-drawer-left': position === 'left',
'ndl-drawer-right': position === 'right',
'ndl-drawer-overlay': type === 'overlay',
'ndl-drawer-push': type === 'push',
});
const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';
const shouldRenderInPortal = isPortaled && type === 'overlay';
const Close = () => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isCloseable && ((0, jsx_runtime_1.jsx)(icon_button_1.IconButton, { className: "ndl-drawer-close-button", onClick: setOnExpandedChange, ariaLabel: "Close drawer", size: "medium", isClean: true, htmlAttributes: {
title: 'Close drawer',
'data-testid': 'ndl-drawer-close-button',
}, 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({ defaultSize: {
width: 'auto',
height: '100%',
} }, resizeableProps, { className: classes, style: Object.assign({ position: resizableStylePosition }, 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: {
top: false,
right: position === 'left',
bottom: false,
left: position === 'right',
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
}, ref: ref, 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)("div", Object.assign({ className: classes, ref: ref }, htmlAttributes, { children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) }));
});
const DrawerHeader = (_a) => {
var { children, className = '' } = _a, restProps = __rest(_a, ["children", "className"]);
const classes = (0, defaultImports_1.classNames)('ndl-drawer-header', className);
if (typeof children === 'string' || typeof children === 'number') {
return ((0, jsx_runtime_1.jsx)("h5", Object.assign({}, restProps, { className: classes, children: children })));
}
return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, restProps, { className: classes, children: children })));
};
exports.DrawerComponent.displayName = 'Drawer';
const DrawerActions = (_a) => {
var { children, className = '' } = _a, restProps = __rest(_a, ["children", "className"]);
const classes = (0, defaultImports_1.classNames)('ndl-drawer-actions', className);
return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, restProps, { className: classes, children: children })));
};
const DrawerBody = (_a) => {
var { children, className = '' } = _a, restProps = __rest(_a, ["children", "className"]);
const classes = (0, defaultImports_1.classNames)('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({}, restProps, { className: classes, children: children })) }));
};
// Issue with TypeScript forwardRef and subcomponents: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34757#issuecomment-894053907
const Drawer = Object.assign(exports.DrawerComponent, {
Header: DrawerHeader,
Actions: DrawerActions,
Body: DrawerBody,
});
exports.Drawer = Drawer;
//# sourceMappingURL=Drawer.js.map