UNPKG

plasod

Version:

An enterprise-class UI design language and React components implementation

80 lines (79 loc) 4.56 kB
"use client"; import * as React from 'react'; import classNames from 'classnames'; import useClosable from '../_util/hooks/useClosable'; import { ConfigContext } from '../config-provider'; const DrawerPanel = props => { var _a, _b; const { prefixCls, title, footer, extra, closeIcon, closable, onClose, headerStyle, bodyStyle, footerStyle, children, classNames: drawerClassNames, styles: drawerStyles } = props; const { drawer: drawerContext } = React.useContext(ConfigContext); const customCloseIconRender = React.useCallback(icon => ( /*#__PURE__*/React.createElement("button", { type: "button", onClick: onClose, "aria-label": "Close", className: `${prefixCls}-close` }, icon)), [onClose]); const mergedContextCloseIcon = React.useMemo(() => { if (typeof (drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.closable) === 'object' && drawerContext.closable.closeIcon) { return drawerContext.closable.closeIcon; } return drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.closeIcon; }, [drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.closable, drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.closeIcon]); const [mergedClosable, mergedCloseIcon] = useClosable({ closable: closable !== null && closable !== void 0 ? closable : drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.closable, closeIcon: typeof closeIcon !== 'undefined' ? closeIcon : mergedContextCloseIcon, customCloseIconRender, defaultClosable: true }); const headerNode = React.useMemo(() => { var _a, _b; if (!title && !mergedClosable) { return null; } return /*#__PURE__*/React.createElement("div", { style: Object.assign(Object.assign(Object.assign({}, (_a = drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.styles) === null || _a === void 0 ? void 0 : _a.header), headerStyle), drawerStyles === null || drawerStyles === void 0 ? void 0 : drawerStyles.header), className: classNames(`${prefixCls}-header`, { [`${prefixCls}-header-close-only`]: mergedClosable && !title && !extra }, (_b = drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.classNames) === null || _b === void 0 ? void 0 : _b.header, drawerClassNames === null || drawerClassNames === void 0 ? void 0 : drawerClassNames.header) }, /*#__PURE__*/React.createElement("div", { className: `${prefixCls}-header-title` }, title && /*#__PURE__*/React.createElement("div", { className: `${prefixCls}-title` }, title), mergedCloseIcon)); }, [mergedClosable, mergedCloseIcon, extra, headerStyle, prefixCls, title]); const footerNode = React.useMemo(() => { var _a, _b; if (!footer && !extra) { return null; } return /*#__PURE__*/React.createElement("div", { className: classNames(`${prefixCls}-footer`, (_a = drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.classNames) === null || _a === void 0 ? void 0 : _a.footer, drawerClassNames === null || drawerClassNames === void 0 ? void 0 : drawerClassNames.footer), style: Object.assign(Object.assign(Object.assign({}, (_b = drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.styles) === null || _b === void 0 ? void 0 : _b.footer), footerStyle), drawerStyles === null || drawerStyles === void 0 ? void 0 : drawerStyles.footer) }, /*#__PURE__*/React.createElement("div", { className: `${prefixCls}-footer-content` }, footer), /*#__PURE__*/React.createElement("div", { className: `${prefixCls}-extra` }, extra)); }, [footer, footerStyle, prefixCls]); return /*#__PURE__*/React.createElement(React.Fragment, null, headerNode, /*#__PURE__*/React.createElement("div", { className: classNames(`${prefixCls}-body`, drawerClassNames === null || drawerClassNames === void 0 ? void 0 : drawerClassNames.body, (_a = drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.classNames) === null || _a === void 0 ? void 0 : _a.body), style: Object.assign(Object.assign(Object.assign({}, (_b = drawerContext === null || drawerContext === void 0 ? void 0 : drawerContext.styles) === null || _b === void 0 ? void 0 : _b.body), bodyStyle), drawerStyles === null || drawerStyles === void 0 ? void 0 : drawerStyles.body) }, children), footerNode); }; export default DrawerPanel;