elseware-ui 2.20.5 → 2.20.6
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,84 @@ 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
|
+
// ----------------------
|
|
141630
|
+
// Utils
|
|
141631
|
+
// ----------------------
|
|
141632
|
+
var matchRoute = function (routePath, currentPath) {
|
|
141633
|
+
var routeParts = routePath.split("/").filter(Boolean);
|
|
141634
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141635
|
+
if (routeParts.length !== pathParts.length)
|
|
141636
|
+
return false;
|
|
141637
|
+
return routeParts.every(function (part, index) {
|
|
141638
|
+
return part.startsWith(":") || part === pathParts[index];
|
|
141639
|
+
});
|
|
141640
|
+
};
|
|
141641
|
+
var buildFromRoutes = function (routes, currentPath) {
|
|
141642
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141643
|
+
var items = [];
|
|
141644
|
+
var _loop_1 = function (i) {
|
|
141645
|
+
var subPath = "/" + pathParts.slice(0, i).join("/");
|
|
141646
|
+
var matched = routes.find(function (r) { return matchRoute(r.path, subPath); });
|
|
141647
|
+
if (matched) {
|
|
141648
|
+
items.push({
|
|
141649
|
+
title: matched.name,
|
|
141650
|
+
href: subPath || "/",
|
|
141651
|
+
});
|
|
141652
|
+
}
|
|
141653
|
+
};
|
|
141654
|
+
for (var i = 0; i <= pathParts.length; i++) {
|
|
141655
|
+
_loop_1(i);
|
|
141656
|
+
}
|
|
141657
|
+
return items;
|
|
141658
|
+
};
|
|
141659
|
+
// ----------------------
|
|
141660
|
+
// Component
|
|
141661
|
+
// ----------------------
|
|
141629
141662
|
var Breadcrumb = function (_a) {
|
|
141630
141663
|
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
|
|
141664
|
+
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;
|
|
141665
|
+
var pathname = currentPath ||
|
|
141666
|
+
(typeof window !== "undefined" ? window.location.pathname : "/");
|
|
141667
|
+
// 🔥 Decide source of truth
|
|
141668
|
+
var resolvedData = useMemo$1(function () {
|
|
141669
|
+
if (routes && routes.length > 0) {
|
|
141670
|
+
return buildFromRoutes(routes, pathname);
|
|
141671
|
+
}
|
|
141672
|
+
return data;
|
|
141673
|
+
}, [routes, data, pathname]);
|
|
141633
141674
|
var childrenContent;
|
|
141634
|
-
if (
|
|
141635
|
-
var items =
|
|
141675
|
+
if (resolvedData.length > 0) {
|
|
141676
|
+
var items = resolvedData.map(function (item, index) {
|
|
141636
141677
|
var _a;
|
|
141637
|
-
|
|
141678
|
+
var isLast = index === resolvedData.length - 1;
|
|
141679
|
+
var handleClick = function (e) {
|
|
141680
|
+
if (isLast)
|
|
141681
|
+
return;
|
|
141682
|
+
if (navigate) {
|
|
141683
|
+
e.preventDefault();
|
|
141684
|
+
navigate(item.href);
|
|
141685
|
+
}
|
|
141686
|
+
};
|
|
141687
|
+
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
141688
|
"text-lg font-semibold text-gray-500": true
|
|
141639
141689
|
},
|
|
141640
141690
|
_a["px-".concat(gap)] = gap,
|
|
141641
141691
|
_a)) }, { children: seperator })))] }, index));
|
|
141642
141692
|
});
|
|
141643
|
-
childrenContent = jsx("div", { children: items });
|
|
141693
|
+
childrenContent = jsx("div", __assign$1({ className: "flex items-center" }, { children: items }));
|
|
141644
141694
|
}
|
|
141645
141695
|
return (jsx("div", __assign$1({ className: classnames((_b = {
|
|
141646
|
-
"inline-flex
|
|
141696
|
+
"inline-flex": true
|
|
141647
141697
|
},
|
|
141648
141698
|
_b["".concat(styles)] = styles,
|
|
141649
141699
|
_b)) }, { children: childrenContent })));
|
package/build/index.js
CHANGED
|
@@ -141643,34 +141643,84 @@ 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
|
+
// ----------------------
|
|
141657
|
+
// Utils
|
|
141658
|
+
// ----------------------
|
|
141659
|
+
var matchRoute = function (routePath, currentPath) {
|
|
141660
|
+
var routeParts = routePath.split("/").filter(Boolean);
|
|
141661
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141662
|
+
if (routeParts.length !== pathParts.length)
|
|
141663
|
+
return false;
|
|
141664
|
+
return routeParts.every(function (part, index) {
|
|
141665
|
+
return part.startsWith(":") || part === pathParts[index];
|
|
141666
|
+
});
|
|
141667
|
+
};
|
|
141668
|
+
var buildFromRoutes = function (routes, currentPath) {
|
|
141669
|
+
var pathParts = currentPath.split("/").filter(Boolean);
|
|
141670
|
+
var items = [];
|
|
141671
|
+
var _loop_1 = function (i) {
|
|
141672
|
+
var subPath = "/" + pathParts.slice(0, i).join("/");
|
|
141673
|
+
var matched = routes.find(function (r) { return matchRoute(r.path, subPath); });
|
|
141674
|
+
if (matched) {
|
|
141675
|
+
items.push({
|
|
141676
|
+
title: matched.name,
|
|
141677
|
+
href: subPath || "/",
|
|
141678
|
+
});
|
|
141679
|
+
}
|
|
141680
|
+
};
|
|
141681
|
+
for (var i = 0; i <= pathParts.length; i++) {
|
|
141682
|
+
_loop_1(i);
|
|
141683
|
+
}
|
|
141684
|
+
return items;
|
|
141685
|
+
};
|
|
141686
|
+
// ----------------------
|
|
141687
|
+
// Component
|
|
141688
|
+
// ----------------------
|
|
141656
141689
|
var Breadcrumb = function (_a) {
|
|
141657
141690
|
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
|
|
141691
|
+
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;
|
|
141692
|
+
var pathname = currentPath ||
|
|
141693
|
+
(typeof window !== "undefined" ? window.location.pathname : "/");
|
|
141694
|
+
// 🔥 Decide source of truth
|
|
141695
|
+
var resolvedData = React.useMemo(function () {
|
|
141696
|
+
if (routes && routes.length > 0) {
|
|
141697
|
+
return buildFromRoutes(routes, pathname);
|
|
141698
|
+
}
|
|
141699
|
+
return data;
|
|
141700
|
+
}, [routes, data, pathname]);
|
|
141660
141701
|
var childrenContent;
|
|
141661
|
-
if (
|
|
141662
|
-
var items =
|
|
141702
|
+
if (resolvedData.length > 0) {
|
|
141703
|
+
var items = resolvedData.map(function (item, index) {
|
|
141663
141704
|
var _a;
|
|
141664
|
-
|
|
141705
|
+
var isLast = index === resolvedData.length - 1;
|
|
141706
|
+
var handleClick = function (e) {
|
|
141707
|
+
if (isLast)
|
|
141708
|
+
return;
|
|
141709
|
+
if (navigate) {
|
|
141710
|
+
e.preventDefault();
|
|
141711
|
+
navigate(item.href);
|
|
141712
|
+
}
|
|
141713
|
+
};
|
|
141714
|
+
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
141715
|
"text-lg font-semibold text-gray-500": true
|
|
141666
141716
|
},
|
|
141667
141717
|
_a["px-".concat(gap)] = gap,
|
|
141668
141718
|
_a)) }, { children: seperator })))] }, index));
|
|
141669
141719
|
});
|
|
141670
|
-
childrenContent = jsxRuntime.jsx("div", { children: items });
|
|
141720
|
+
childrenContent = jsxRuntime.jsx("div", __assign$1({ className: "flex items-center" }, { children: items }));
|
|
141671
141721
|
}
|
|
141672
141722
|
return (jsxRuntime.jsx("div", __assign$1({ className: classnames((_b = {
|
|
141673
|
-
"inline-flex
|
|
141723
|
+
"inline-flex": true
|
|
141674
141724
|
},
|
|
141675
141725
|
_b["".concat(styles)] = styles,
|
|
141676
141726
|
_b)) }, { children: childrenContent })));
|