elseware-ui 2.20.5 → 2.20.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,10 +2,17 @@ export interface I_ItemType {
|
|
|
2
2
|
title: string;
|
|
3
3
|
href: string;
|
|
4
4
|
}
|
|
5
|
+
export interface RouteConfig {
|
|
6
|
+
path: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
5
9
|
export interface BreadcrumbProps {
|
|
6
10
|
gap?: number;
|
|
7
11
|
seperator?: string;
|
|
8
12
|
data?: I_ItemType[];
|
|
13
|
+
routes?: RouteConfig[];
|
|
14
|
+
currentPath?: string;
|
|
15
|
+
navigate?: (path: string) => void;
|
|
9
16
|
styles?: string;
|
|
10
17
|
}
|
|
11
|
-
export declare const Breadcrumb: ({ gap, seperator, data, styles }: BreadcrumbProps) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export declare const Breadcrumb: ({ gap, seperator, data, routes, currentPath, navigate, styles, }: BreadcrumbProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
export interface BreadcrumbItemProps {
|
|
2
3
|
title: string;
|
|
3
4
|
href: string;
|
|
4
5
|
active: boolean;
|
|
6
|
+
onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;
|
|
5
7
|
}
|
|
6
|
-
declare function BreadcrumbItem({ title, href, active }: BreadcrumbItemProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
declare function BreadcrumbItem({ title, href, active, onClick, }: BreadcrumbItemProps): import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
export default BreadcrumbItem;
|
package/build/index.es.js
CHANGED
|
@@ -141616,34 +141616,80 @@ function MarkdownViewer(_a) {
|
|
|
141616
141616
|
}
|
|
141617
141617
|
|
|
141618
141618
|
function BreadcrumbItem(_a) {
|
|
141619
|
-
var title = _a.title, _b = _a.href, href = _b === void 0 ? "#" : _b, _c = _a.active, active = _c === void 0 ? true : _c;
|
|
141620
|
-
return (jsx("a", __assign$1({ href: href, className: classnames({
|
|
141621
|
-
"text-lg font-semibold
|
|
141622
|
-
"text-gray-400 hover:text-gray-600": !active,
|
|
141619
|
+
var title = _a.title, _b = _a.href, href = _b === void 0 ? "#" : _b, _c = _a.active, active = _c === void 0 ? true : _c, onClick = _a.onClick;
|
|
141620
|
+
return (jsx("a", __assign$1({ href: href, onClick: onClick, className: classnames({
|
|
141621
|
+
"text-lg font-semibold": true,
|
|
141622
|
+
"text-gray-400 hover:text-gray-600 cursor-pointer": !active,
|
|
141623
141623
|
"text-eui-light-800": active,
|
|
141624
141624
|
"hover:underline": true,
|
|
141625
141625
|
"transition-all ease-in-out": true,
|
|
141626
141626
|
}) }, { children: title })));
|
|
141627
141627
|
}
|
|
141628
141628
|
|
|
141629
|
+
var matchRoute = function (routePath, currentPath) {
|
|
141630
|
+
var routeParts = routePath.split("/").filter(Boolean);
|
|
141631
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141632
|
+
if (routeParts.length !== pathParts.length)
|
|
141633
|
+
return false;
|
|
141634
|
+
return routeParts.every(function (part, index) {
|
|
141635
|
+
return part.startsWith(":") || part === pathParts[index];
|
|
141636
|
+
});
|
|
141637
|
+
};
|
|
141638
|
+
var buildFromRoutes = function (routes, currentPath) {
|
|
141639
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141640
|
+
var items = [];
|
|
141641
|
+
var _loop_1 = function (i) {
|
|
141642
|
+
var subPath = "/" + pathParts.slice(0, i).join("/");
|
|
141643
|
+
var matched = routes.find(function (r) { return matchRoute(r.path, subPath); });
|
|
141644
|
+
if (matched) {
|
|
141645
|
+
items.push({
|
|
141646
|
+
title: matched.name,
|
|
141647
|
+
href: subPath || "/",
|
|
141648
|
+
});
|
|
141649
|
+
}
|
|
141650
|
+
};
|
|
141651
|
+
for (var i = 0; i <= pathParts.length; i++) {
|
|
141652
|
+
_loop_1(i);
|
|
141653
|
+
}
|
|
141654
|
+
return items;
|
|
141655
|
+
};
|
|
141629
141656
|
var Breadcrumb = function (_a) {
|
|
141630
141657
|
var _b;
|
|
141631
|
-
var _c = _a.gap, gap = _c === void 0 ? 1 : _c, _d = _a.seperator, seperator = _d === void 0 ? "/" : _d, _e = _a.data, data = _e === void 0 ? [] : _e, styles = _a.styles;
|
|
141632
|
-
var
|
|
141658
|
+
var _c = _a.gap, gap = _c === void 0 ? 1 : _c, _d = _a.seperator, seperator = _d === void 0 ? "/" : _d, _e = _a.data, data = _e === void 0 ? [] : _e, routes = _a.routes, currentPath = _a.currentPath, navigate = _a.navigate, styles = _a.styles;
|
|
141659
|
+
var config = useEUIConfig().config;
|
|
141660
|
+
var pathname = currentPath ||
|
|
141661
|
+
(typeof window !== "undefined" ? window.location.pathname : "/");
|
|
141662
|
+
var resolvedRoutes = routes || (config === null || config === void 0 ? void 0 : config.routes) || [];
|
|
141663
|
+
// Decide source of truth
|
|
141664
|
+
var resolvedData = useMemo$1(function () {
|
|
141665
|
+
if (resolvedRoutes && resolvedRoutes.length > 0) {
|
|
141666
|
+
return buildFromRoutes(resolvedRoutes, pathname);
|
|
141667
|
+
}
|
|
141668
|
+
return data;
|
|
141669
|
+
}, [resolvedRoutes, data, pathname]);
|
|
141633
141670
|
var childrenContent;
|
|
141634
|
-
if (
|
|
141635
|
-
var items =
|
|
141671
|
+
if (resolvedData.length > 0) {
|
|
141672
|
+
var items = resolvedData.map(function (item, index) {
|
|
141636
141673
|
var _a;
|
|
141637
|
-
|
|
141674
|
+
var isLast = index === resolvedData.length - 1;
|
|
141675
|
+
var handleClick = function (e) {
|
|
141676
|
+
if (isLast)
|
|
141677
|
+
return;
|
|
141678
|
+
if (navigate) {
|
|
141679
|
+
e.preventDefault();
|
|
141680
|
+
navigate(item.href);
|
|
141681
|
+
}
|
|
141682
|
+
};
|
|
141683
|
+
return (jsxs(React__default.Fragment, { children: [jsx(BreadcrumbItem, { title: item.title, href: item.href, active: isLast, onClick: handleClick }), index < resolvedData.length - 1 && (jsx("span", __assign$1({ className: classnames((_a = {
|
|
141638
141684
|
"text-lg font-semibold text-gray-500": true
|
|
141639
141685
|
},
|
|
141640
141686
|
_a["px-".concat(gap)] = gap,
|
|
141641
141687
|
_a)) }, { children: seperator })))] }, index));
|
|
141642
141688
|
});
|
|
141643
|
-
childrenContent = jsx("div", { children: items });
|
|
141689
|
+
childrenContent = jsx("div", __assign$1({ className: "flex items-center" }, { children: items }));
|
|
141644
141690
|
}
|
|
141645
141691
|
return (jsx("div", __assign$1({ className: classnames((_b = {
|
|
141646
|
-
"inline-flex
|
|
141692
|
+
"inline-flex": true
|
|
141647
141693
|
},
|
|
141648
141694
|
_b["".concat(styles)] = styles,
|
|
141649
141695
|
_b)) }, { children: childrenContent })));
|
package/build/index.js
CHANGED
|
@@ -141643,34 +141643,80 @@ function MarkdownViewer(_a) {
|
|
|
141643
141643
|
}
|
|
141644
141644
|
|
|
141645
141645
|
function BreadcrumbItem(_a) {
|
|
141646
|
-
var title = _a.title, _b = _a.href, href = _b === void 0 ? "#" : _b, _c = _a.active, active = _c === void 0 ? true : _c;
|
|
141647
|
-
return (jsxRuntime.jsx("a", __assign$1({ href: href, className: classnames({
|
|
141648
|
-
"text-lg font-semibold
|
|
141649
|
-
"text-gray-400 hover:text-gray-600": !active,
|
|
141646
|
+
var title = _a.title, _b = _a.href, href = _b === void 0 ? "#" : _b, _c = _a.active, active = _c === void 0 ? true : _c, onClick = _a.onClick;
|
|
141647
|
+
return (jsxRuntime.jsx("a", __assign$1({ href: href, onClick: onClick, className: classnames({
|
|
141648
|
+
"text-lg font-semibold": true,
|
|
141649
|
+
"text-gray-400 hover:text-gray-600 cursor-pointer": !active,
|
|
141650
141650
|
"text-eui-light-800": active,
|
|
141651
141651
|
"hover:underline": true,
|
|
141652
141652
|
"transition-all ease-in-out": true,
|
|
141653
141653
|
}) }, { children: title })));
|
|
141654
141654
|
}
|
|
141655
141655
|
|
|
141656
|
+
var matchRoute = function (routePath, currentPath) {
|
|
141657
|
+
var routeParts = routePath.split("/").filter(Boolean);
|
|
141658
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141659
|
+
if (routeParts.length !== pathParts.length)
|
|
141660
|
+
return false;
|
|
141661
|
+
return routeParts.every(function (part, index) {
|
|
141662
|
+
return part.startsWith(":") || part === pathParts[index];
|
|
141663
|
+
});
|
|
141664
|
+
};
|
|
141665
|
+
var buildFromRoutes = function (routes, currentPath) {
|
|
141666
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141667
|
+
var items = [];
|
|
141668
|
+
var _loop_1 = function (i) {
|
|
141669
|
+
var subPath = "/" + pathParts.slice(0, i).join("/");
|
|
141670
|
+
var matched = routes.find(function (r) { return matchRoute(r.path, subPath); });
|
|
141671
|
+
if (matched) {
|
|
141672
|
+
items.push({
|
|
141673
|
+
title: matched.name,
|
|
141674
|
+
href: subPath || "/",
|
|
141675
|
+
});
|
|
141676
|
+
}
|
|
141677
|
+
};
|
|
141678
|
+
for (var i = 0; i <= pathParts.length; i++) {
|
|
141679
|
+
_loop_1(i);
|
|
141680
|
+
}
|
|
141681
|
+
return items;
|
|
141682
|
+
};
|
|
141656
141683
|
var Breadcrumb = function (_a) {
|
|
141657
141684
|
var _b;
|
|
141658
|
-
var _c = _a.gap, gap = _c === void 0 ? 1 : _c, _d = _a.seperator, seperator = _d === void 0 ? "/" : _d, _e = _a.data, data = _e === void 0 ? [] : _e, styles = _a.styles;
|
|
141659
|
-
var
|
|
141685
|
+
var _c = _a.gap, gap = _c === void 0 ? 1 : _c, _d = _a.seperator, seperator = _d === void 0 ? "/" : _d, _e = _a.data, data = _e === void 0 ? [] : _e, routes = _a.routes, currentPath = _a.currentPath, navigate = _a.navigate, styles = _a.styles;
|
|
141686
|
+
var config = useEUIConfig().config;
|
|
141687
|
+
var pathname = currentPath ||
|
|
141688
|
+
(typeof window !== "undefined" ? window.location.pathname : "/");
|
|
141689
|
+
var resolvedRoutes = routes || (config === null || config === void 0 ? void 0 : config.routes) || [];
|
|
141690
|
+
// Decide source of truth
|
|
141691
|
+
var resolvedData = React.useMemo(function () {
|
|
141692
|
+
if (resolvedRoutes && resolvedRoutes.length > 0) {
|
|
141693
|
+
return buildFromRoutes(resolvedRoutes, pathname);
|
|
141694
|
+
}
|
|
141695
|
+
return data;
|
|
141696
|
+
}, [resolvedRoutes, data, pathname]);
|
|
141660
141697
|
var childrenContent;
|
|
141661
|
-
if (
|
|
141662
|
-
var items =
|
|
141698
|
+
if (resolvedData.length > 0) {
|
|
141699
|
+
var items = resolvedData.map(function (item, index) {
|
|
141663
141700
|
var _a;
|
|
141664
|
-
|
|
141701
|
+
var isLast = index === resolvedData.length - 1;
|
|
141702
|
+
var handleClick = function (e) {
|
|
141703
|
+
if (isLast)
|
|
141704
|
+
return;
|
|
141705
|
+
if (navigate) {
|
|
141706
|
+
e.preventDefault();
|
|
141707
|
+
navigate(item.href);
|
|
141708
|
+
}
|
|
141709
|
+
};
|
|
141710
|
+
return (jsxRuntime.jsxs(React__default["default"].Fragment, { children: [jsxRuntime.jsx(BreadcrumbItem, { title: item.title, href: item.href, active: isLast, onClick: handleClick }), index < resolvedData.length - 1 && (jsxRuntime.jsx("span", __assign$1({ className: classnames((_a = {
|
|
141665
141711
|
"text-lg font-semibold text-gray-500": true
|
|
141666
141712
|
},
|
|
141667
141713
|
_a["px-".concat(gap)] = gap,
|
|
141668
141714
|
_a)) }, { children: seperator })))] }, index));
|
|
141669
141715
|
});
|
|
141670
|
-
childrenContent = jsxRuntime.jsx("div", { children: items });
|
|
141716
|
+
childrenContent = jsxRuntime.jsx("div", __assign$1({ className: "flex items-center" }, { children: items }));
|
|
141671
141717
|
}
|
|
141672
141718
|
return (jsxRuntime.jsx("div", __assign$1({ className: classnames((_b = {
|
|
141673
|
-
"inline-flex
|
|
141719
|
+
"inline-flex": true
|
|
141674
141720
|
},
|
|
141675
141721
|
_b["".concat(styles)] = styles,
|
|
141676
141722
|
_b)) }, { children: childrenContent })));
|