@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
112 lines • 6.67 kB
JavaScript
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;
};
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "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/>.
*/
import { FloatingPortal } from '@floating-ui/react';
import classNames from 'classnames';
import { Resizable } from 're-resizable';
import { useCallback } from 'react';
import { CleanIconButton } from '../clean-icon-button';
import { ConditionalWrap } from '../conditional-wrap';
import { XMarkIconOutline } from '../icons';
import { Typography } from '../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 = useCallback(() => {
if (onExpandedChange) {
onExpandedChange(!isExpanded);
}
}, [isExpanded, onExpandedChange]);
const classes = classNames('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 = () => (_jsx(_Fragment, { children: isCloseable && (_jsx(CleanIconButton, { className: "ndl-drawer-close-button", onClick: setOnExpandedChange, description: "Close", size: "medium", htmlAttributes: {
title: 'Close drawer',
}, children: _jsx(XMarkIconOutline, {}) })) }));
if (isResizeable) {
return (_jsx(ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => (_jsx(FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: _jsxs(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, _jsx(Close, {})] })) }));
}
return (_jsx(ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => (_jsx(FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: _jsxs(Component, Object.assign({ className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: [children, _jsx(Close, {})] })) }));
};
DrawerComponent.displayName = 'Drawer';
const DrawerHeader = (_a) => {
var { children, className = '', htmlAttributes } = _a, restProps = __rest(_a, ["children", "className", "htmlAttributes"]);
const classes = classNames('ndl-drawer-header', className);
if (typeof children === 'string' || typeof children === 'number') {
return (_jsx(Typography, Object.assign({ className: classes, variant: "title-3" }, restProps, htmlAttributes, { children: children })));
}
return (_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 = classNames('ndl-drawer-actions', className);
return (_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 = classNames('ndl-drawer-body', className);
return (_jsx("div", { className: "ndl-drawer-body-wrapper", children: _jsx("div", Object.assign({ className: classes }, restProps, htmlAttributes, { children: children })) }));
};
const Drawer = Object.assign(DrawerComponent, {
Actions: DrawerActions,
Body: DrawerBody,
Header: DrawerHeader,
});
export { Drawer };
//# sourceMappingURL=Drawer.js.map