@yuntijs/ui
Version:
☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps
56 lines (55 loc) • 2.88 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["to", "Link", "children"];
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; }
import React, { useCallback, useContext, useEffect } from 'react';
import { Breadcrumb } from "../../Breadcrumb";
import { PageContext } from "../PageContext";
import { jsx as _jsx } from "react/jsx-runtime";
var BreadcrumbLink = function BreadcrumbLink(props) {
var to = props.to,
Link = props.Link,
children = props.children,
otherProps = _objectWithoutProperties(props, _excluded);
if (Link) {
return /*#__PURE__*/_jsx(Link, _objectSpread(_objectSpread({
to: to
}, otherProps), {}, {
children: children
}));
}
return /*#__PURE__*/_jsx("a", _objectSpread(_objectSpread({
href: "#".concat(to)
}, otherProps), {}, {
children: children
}));
};
export var PageBreadcrumb = function PageBreadcrumb(props) {
var _useContext = useContext(PageContext),
Link = _useContext.Link,
breadcrumb = _useContext.breadcrumb;
useEffect(function () {
var _breadcrumb$setItems;
breadcrumb === null || breadcrumb === void 0 || (_breadcrumb$setItems = breadcrumb.setItems) === null || _breadcrumb$setItems === void 0 || _breadcrumb$setItems.call(breadcrumb, props.items);
}, [breadcrumb, props.items]);
// @ts-ignore
var itemRender = useCallback(function (currentRoute, params, items, paths) {
var _items$at, _items$at2;
var isLast = currentRoute.href ? currentRoute.href === ((_items$at = items.at(-1)) === null || _items$at === void 0 ? void 0 : _items$at.href) : currentRoute.path === ((_items$at2 = items.at(-1)) === null || _items$at2 === void 0 ? void 0 : _items$at2.path);
if (isLast) {
return /*#__PURE__*/_jsx("span", {
children: currentRoute.title
});
}
var to = currentRoute.href ? currentRoute.href : "/".concat(paths.join('/'));
return /*#__PURE__*/_jsx(BreadcrumbLink, {
Link: Link,
to: to,
children: currentRoute.title
});
}, [Link]);
return /*#__PURE__*/_jsx(Breadcrumb, _objectSpread({
itemRender: itemRender
}, props));
};