UNPKG

antd

Version:

An enterprise-class UI design language and React components implementation

151 lines (122 loc) 5.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var React = _interopRequireWildcard(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _configProvider = require("../config-provider"); var _icon = _interopRequireDefault(require("../icon")); var _breadcrumb = _interopRequireDefault(require("../breadcrumb")); var _avatar = _interopRequireDefault(require("../avatar")); var _transButton = _interopRequireDefault(require("../_util/transButton")); var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver")); var _warning = _interopRequireDefault(require("../_util/warning")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } } var renderBack = function renderBack(prefixCls, backIcon, onBack) { if (!backIcon || !onBack) { return null; } return React.createElement(_LocaleReceiver["default"], { componentName: "PageHeader" }, function (_ref) { var back = _ref.back; return React.createElement("div", { className: "".concat(prefixCls, "-back") }, React.createElement(_transButton["default"], { onClick: function onClick(e) { if (onBack) { onBack(e); } }, className: "".concat(prefixCls, "-back-button"), "aria-label": back }, backIcon)); }); }; var renderBreadcrumb = function renderBreadcrumb(breadcrumb) { return React.createElement(_breadcrumb["default"], breadcrumb); }; var renderHeader = function renderHeader(breadcrumb, _ref2) { var backIcon = _ref2.backIcon, onBack = _ref2.onBack; // by design,Bread crumbs and back icon can only have one if (backIcon && onBack) { if (breadcrumb && breadcrumb.routes) { (0, _warning["default"])(false, 'page-header', 'breadcrumbs and back icon can only have one'); } return null; } if (breadcrumb && breadcrumb.routes) { return renderBreadcrumb(breadcrumb); } return null; }; var renderTitle = function renderTitle(prefixCls, props) { var title = props.title, avatar = props.avatar, subTitle = props.subTitle, tags = props.tags, extra = props.extra, backIcon = props.backIcon, onBack = props.onBack; var headingPrefixCls = "".concat(prefixCls, "-heading"); if (title || subTitle || tags || extra) { var backIconDom = renderBack(prefixCls, backIcon, onBack); return React.createElement("div", { className: headingPrefixCls }, backIconDom, avatar && React.createElement(_avatar["default"], avatar), title && React.createElement("span", { className: "".concat(headingPrefixCls, "-title") }, title), subTitle && React.createElement("span", { className: "".concat(headingPrefixCls, "-sub-title") }, subTitle), tags && React.createElement("span", { className: "".concat(headingPrefixCls, "-tags") }, tags), extra && React.createElement("span", { className: "".concat(headingPrefixCls, "-extra") }, extra)); } return null; }; var renderFooter = function renderFooter(prefixCls, footer) { if (footer) { return React.createElement("div", { className: "".concat(prefixCls, "-footer") }, footer); } return null; }; var renderChildren = function renderChildren(prefixCls, children) { return React.createElement("div", { className: "".concat(prefixCls, "-content") }, children); }; var PageHeader = function PageHeader(props) { return React.createElement(_configProvider.ConfigConsumer, null, function (_ref3) { var getPrefixCls = _ref3.getPrefixCls; var customizePrefixCls = props.prefixCls, style = props.style, footer = props.footer, children = props.children, breadcrumb = props.breadcrumb, customizeClassName = props.className; var prefixCls = getPrefixCls('page-header', customizePrefixCls); var breadcrumbDom = renderHeader(breadcrumb, props); var className = (0, _classnames["default"])(prefixCls, customizeClassName, { 'has-breadcrumb': breadcrumbDom, 'has-footer': footer }); return React.createElement("div", { className: className, style: style }, breadcrumbDom, renderTitle(prefixCls, props), children && renderChildren(prefixCls, children), renderFooter(prefixCls, footer)); }); }; PageHeader.defaultProps = { backIcon: React.createElement(_icon["default"], { type: "arrow-left" }) }; var _default = PageHeader; exports["default"] = _default; //# sourceMappingURL=index.js.map