UNPKG

@yuntijs/ui

Version:

☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps

202 lines 9.57 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["className", "classNames", "icon", "title", "titleRender", "subTitle", "status", "descriptions", "descriptionsRender", "extraContent", "extraContentRender", "bordered", "divider"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } import { Flex, Skeleton, Tooltip } from 'antd'; import React, { useContext, useMemo } from 'react'; import { ButtonGroup } from "../../ButtonGroup"; import Divider from "../../Divider"; import { Status } from "../../Status"; import Typography from "../../Typography"; import { PageContext } from "../PageContext"; import { HeaderIcon, getIconSize } from "./Icon"; import { useStyles } from "./style"; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var Paragraph = Typography.Paragraph; export var PageHeader = function PageHeader(props) { var className = props.className, classNames = props.classNames, icon = props.icon, title = props.title, titleRender = props.titleRender, subTitle = props.subTitle, status = props.status, _props$descriptions = props.descriptions, descriptions = _props$descriptions === void 0 ? [] : _props$descriptions, descriptionsRender = props.descriptionsRender, _props$extraContent = props.extraContent, extraContent = _props$extraContent === void 0 ? {} : _props$extraContent, extraContentRender = props.extraContentRender, bordered = props.bordered, divider = props.divider, otherProps = _objectWithoutProperties(props, _excluded); var _useStyles = useStyles({ bordered: bordered, divider: divider }), styles = _useStyles.styles, cx = _useStyles.cx; var iconProps = useMemo(function () { if (!icon || typeof icon === 'string') { return { src: icon, size: subTitle ? 'large' : 'default' }; } if (subTitle && icon.size === undefined) { icon.size = 'large'; } return icon; }, [icon, subTitle]); var TitleNode = useMemo(function () { var titleElement = /*#__PURE__*/_jsx("span", { className: cx(styles.title, classNames === null || classNames === void 0 ? void 0 : classNames.title), children: title }); if (titleRender) { return titleRender(titleElement); } return titleElement; }, [classNames === null || classNames === void 0 ? void 0 : classNames.title, cx, styles.title, title, titleRender]); var DescriptionsNode = useMemo(function () { var descriptionsElement = []; var _iterator = _createForOfIteratorHelper(descriptions.filter(function (d) { return !!d; }).entries()), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _step$value = _slicedToArray(_step.value, 2), index = _step$value[0], desc = _step$value[1]; var descIcon = desc.icon, text = desc.text; if (status || index >= 1) { descriptionsElement.push( /*#__PURE__*/_jsx(Divider, { dashed: false, type: "vertical" }, "divider-".concat(index))); } descriptionsElement.push( /*#__PURE__*/_jsxs(Flex, { align: "center", gap: 4, children: [descIcon && /*#__PURE__*/_jsx(Tooltip, { title: descIcon.tooltip, children: descIcon.content }), /*#__PURE__*/_jsx("span", { children: text })] }, "desc-".concat(index))); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } if (descriptionsRender) { return descriptionsRender(descriptionsElement); } return descriptionsElement; }, [descriptions, descriptionsRender, status]); var ExtraContentNode = useMemo(function () { if (!extraContent && !extraContentRender) { return null; } var buttons = /*#__PURE__*/_jsx(ButtonGroup, _objectSpread({ className: styles.rightButtons }, extraContent)); if (extraContentRender) { return extraContentRender(buttons); } return buttons; }, [extraContent, extraContentRender, styles.rightButtons]); var _useContext = useContext(PageContext), loading = _useContext.loading, pageStatus = _useContext.status; if (loading) { return /*#__PURE__*/_jsxs(Flex, { className: cx(styles.root, className), gap: 20, children: [/*#__PURE__*/_jsx(Flex, { children: /*#__PURE__*/_jsx(Skeleton.Avatar, { active: true, className: styles.icon, shape: iconProps === null || iconProps === void 0 ? void 0 : iconProps.shape, size: getIconSize(iconProps === null || iconProps === void 0 ? void 0 : iconProps.size) }) }), /*#__PURE__*/_jsxs(Flex, { flex: "2", justify: "space-between", vertical: true, children: [/*#__PURE__*/_jsxs("div", { className: styles.titleBox, children: [/*#__PURE__*/_jsx(Skeleton.Input, { active: true, size: 25 }), subTitle && /*#__PURE__*/_jsx("div", { className: cx(styles.subTitle, className), children: /*#__PURE__*/_jsx(Skeleton.Input, { active: true, size: 18 }) })] }), /*#__PURE__*/_jsx(Skeleton.Input, { active: true, size: 18 })] }), /*#__PURE__*/_jsx(Flex, { align: "center", flex: "0 0 140px", justify: "flex-end", children: /*#__PURE__*/_jsx(Skeleton.Button, { active: true }) })] }); } if (pageStatus) { return null; } return /*#__PURE__*/_jsxs(Flex, _objectSpread(_objectSpread({ className: cx(styles.root, className), gap: 20 }, otherProps), {}, { children: [iconProps && /*#__PURE__*/_jsx(Flex, { children: /*#__PURE__*/_jsx(HeaderIcon, _objectSpread({ className: styles.icon }, iconProps)) }), /*#__PURE__*/_jsxs(Flex, { flex: "2", justify: "space-between", vertical: true, children: [/*#__PURE__*/_jsxs(Flex, { className: cx(styles.titleBox, classNames === null || classNames === void 0 ? void 0 : classNames.titleWrapper), vertical: true, children: [TitleNode, subTitle && /*#__PURE__*/_jsx(Paragraph, { className: cx(styles.subTitle, classNames === null || classNames === void 0 ? void 0 : classNames.subTitle), ellipsis: { rows: 2 }, children: subTitle })] }), /*#__PURE__*/_jsxs(Flex, { align: "center", className: cx(styles.descriptions, classNames === null || classNames === void 0 ? void 0 : classNames.descriptions), gap: 4, children: [status && /*#__PURE__*/_jsx(Status, _objectSpread({}, status)), DescriptionsNode] })] }), /*#__PURE__*/_jsx(Flex, { align: "center", className: classNames === null || classNames === void 0 ? void 0 : classNames.extraContent, flex: "1", justify: "flex-end", children: ExtraContentNode })] })); };