@dloizides/ui-nav 1.17.0 → 1.18.0
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.
- package/CHANGELOG.md +29 -0
- package/dist/index.d.mts +75 -37
- package/dist/index.d.ts +75 -37
- package/dist/index.js +35 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -122,10 +122,31 @@ function isFilterActive(query) {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// src/isRouteActive.ts
|
|
125
|
-
function isRouteActive(pathname, route) {
|
|
125
|
+
function isRouteActive(pathname, route, exact = false) {
|
|
126
|
+
if (exact) return pathname === route;
|
|
126
127
|
if (route === "/") return pathname === "/";
|
|
127
128
|
return pathname === route || pathname.startsWith(`${route}/`);
|
|
128
129
|
}
|
|
130
|
+
function leafRoutes(items) {
|
|
131
|
+
return items.flatMap((item) => {
|
|
132
|
+
const children = item.children ?? [];
|
|
133
|
+
const isGroup = children.length > 0;
|
|
134
|
+
return isGroup ? leafRoutes(children) : [{ route: item.route, exact: item.exact === true }];
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function resolveActiveRoute(items, pathname) {
|
|
138
|
+
let winner;
|
|
139
|
+
let winnerLength = -1;
|
|
140
|
+
for (const leaf of leafRoutes(items)) {
|
|
141
|
+
const matches = isRouteActive(pathname, leaf.route, leaf.exact);
|
|
142
|
+
const isLonger = leaf.route.length > winnerLength;
|
|
143
|
+
if (matches && isLonger) {
|
|
144
|
+
winner = leaf.route;
|
|
145
|
+
winnerLength = leaf.route.length;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return winner;
|
|
149
|
+
}
|
|
129
150
|
var ACTIVE_BORDER_RADIUS = 4;
|
|
130
151
|
var ACTIVE_ACCENT_WIDTH = 3;
|
|
131
152
|
var NAV_ROW_RADIUS = 8;
|
|
@@ -503,6 +524,7 @@ var NavExpandableItem = ({
|
|
|
503
524
|
expandHint,
|
|
504
525
|
collapseHint,
|
|
505
526
|
renderChevron,
|
|
527
|
+
activeRoute,
|
|
506
528
|
depth = 0
|
|
507
529
|
}) => {
|
|
508
530
|
const [expanded, setExpanded] = useState(() => hasActiveDescendant(item, pathname));
|
|
@@ -516,7 +538,7 @@ var NavExpandableItem = ({
|
|
|
516
538
|
const onHoverOut = useCallback(() => setHovered(false), []);
|
|
517
539
|
const indent = depth * BASE_INDENT;
|
|
518
540
|
const hasChildren = Array.isArray(item.children) && item.children.length > 0;
|
|
519
|
-
const isActive = isRouteActive(pathname, item.route);
|
|
541
|
+
const isActive = activeRoute !== void 0 ? item.route === activeRoute : isRouteActive(pathname, item.route, item.exact === true);
|
|
520
542
|
const isSectionHeader = hasChildren && depth === 0;
|
|
521
543
|
const activeAccentStyle = useMemo(
|
|
522
544
|
() => ({ borderLeftWidth: ACTIVE_ACCENT_WIDTH, borderLeftColor: primaryColor }),
|
|
@@ -604,6 +626,7 @@ var NavExpandableItem = ({
|
|
|
604
626
|
/* @__PURE__ */ jsx(Collapse, { open: expanded, children: /* @__PURE__ */ jsx(View, { style: expandableStyles.childrenContainer, children: item.children?.map((child) => /* @__PURE__ */ jsx(
|
|
605
627
|
NavExpandableItem,
|
|
606
628
|
{
|
|
629
|
+
activeRoute,
|
|
607
630
|
collapseHint,
|
|
608
631
|
depth: depth + 1,
|
|
609
632
|
expandHint,
|
|
@@ -754,6 +777,7 @@ var Sidebar = ({
|
|
|
754
777
|
const showPaletteTrigger = paletteTrigger !== void 0 && !isInlineAffordance;
|
|
755
778
|
const visibleItems = showInlineSearch ? filterNavItems(items, query) : items;
|
|
756
779
|
const showEmpty = showInlineSearch && isFilterActive(query) && visibleItems.length === 0;
|
|
780
|
+
const activeRoute = resolveActiveRoute(items, pathname);
|
|
757
781
|
return /* @__PURE__ */ jsxs(
|
|
758
782
|
View,
|
|
759
783
|
{
|
|
@@ -791,6 +815,7 @@ var Sidebar = ({
|
|
|
791
815
|
showEmpty && search !== void 0 ? /* @__PURE__ */ jsx(Text, { style: [navStyles.sidebarEmpty, { color: colors.textSecondary }], testID: "sidebar-search-empty", children: search.emptyText }) : visibleItems.map((item) => /* @__PURE__ */ jsx(
|
|
792
816
|
NavExpandableItem,
|
|
793
817
|
{
|
|
818
|
+
activeRoute,
|
|
794
819
|
collapseHint,
|
|
795
820
|
expandHint,
|
|
796
821
|
item,
|
|
@@ -1055,7 +1080,7 @@ var NavOverflowMenu = ({
|
|
|
1055
1080
|
}) => {
|
|
1056
1081
|
const options = useMemo(() => items.map((item) => ({ label: item.label, value: item.route })), [items]);
|
|
1057
1082
|
const activeRoute = useMemo(
|
|
1058
|
-
() => items
|
|
1083
|
+
() => resolveActiveRoute(items, pathname) ?? NO_ACTIVE_ROUTE,
|
|
1059
1084
|
[items, pathname]
|
|
1060
1085
|
);
|
|
1061
1086
|
const optionTestID = useMemo(() => {
|
|
@@ -1188,6 +1213,7 @@ var NavBarInner = ({
|
|
|
1188
1213
|
},
|
|
1189
1214
|
[onNavigate]
|
|
1190
1215
|
);
|
|
1216
|
+
const activeRoute = resolveActiveRoute(items, pathname);
|
|
1191
1217
|
const linkColors = useMemo(
|
|
1192
1218
|
() => ({
|
|
1193
1219
|
rest: colors.textSecondary,
|
|
@@ -1235,7 +1261,7 @@ var NavBarInner = ({
|
|
|
1235
1261
|
collapsed,
|
|
1236
1262
|
colors: linkColors,
|
|
1237
1263
|
iconSize: NAV_ICON_SIZE,
|
|
1238
|
-
isActive:
|
|
1264
|
+
isActive: item.route === activeRoute,
|
|
1239
1265
|
item,
|
|
1240
1266
|
navigateHint,
|
|
1241
1267
|
reducedMotion,
|
|
@@ -1597,6 +1623,7 @@ var CollapsedRail = ({
|
|
|
1597
1623
|
const { theme } = useUi();
|
|
1598
1624
|
const colors = theme.colors;
|
|
1599
1625
|
const primaryColor = theme.palette.primary["500"];
|
|
1626
|
+
const activeRoute = resolveActiveRoute(items, pathname);
|
|
1600
1627
|
return /* @__PURE__ */ jsxs(
|
|
1601
1628
|
View,
|
|
1602
1629
|
{
|
|
@@ -1611,7 +1638,7 @@ var CollapsedRail = ({
|
|
|
1611
1638
|
children: [
|
|
1612
1639
|
header !== void 0 ? /* @__PURE__ */ jsx(View, { style: collapsedRailStyles.slot, children: renderTextSlot(header, { color: colors.text }) }) : null,
|
|
1613
1640
|
items.map((item) => {
|
|
1614
|
-
const active =
|
|
1641
|
+
const active = item.route === activeRoute;
|
|
1615
1642
|
const iconColor = active ? primaryColor : colors.textSecondary;
|
|
1616
1643
|
return /* @__PURE__ */ jsx(
|
|
1617
1644
|
FocusableTouchable,
|
|
@@ -1739,6 +1766,7 @@ var PillNav = ({
|
|
|
1739
1766
|
const colors = theme.colors;
|
|
1740
1767
|
const primaryColor = theme.palette.primary["500"];
|
|
1741
1768
|
if (items.length < minItems) return null;
|
|
1769
|
+
const activeRoute = resolveActiveRoute(items, pathname);
|
|
1742
1770
|
return /* @__PURE__ */ jsx(
|
|
1743
1771
|
View,
|
|
1744
1772
|
{
|
|
@@ -1747,7 +1775,7 @@ var PillNav = ({
|
|
|
1747
1775
|
role: "navigation",
|
|
1748
1776
|
style: [pillNavStyles.container, containerStyle],
|
|
1749
1777
|
children: items.map((item) => {
|
|
1750
|
-
const active =
|
|
1778
|
+
const active = item.route === activeRoute;
|
|
1751
1779
|
const textColor = active ? TEXT_ON_PRIMARY4 : colors.textSecondary;
|
|
1752
1780
|
const pillStyle = active ? { backgroundColor: primaryColor } : { backgroundColor: colors.surfaceElevated };
|
|
1753
1781
|
return /* @__PURE__ */ jsxs(
|
|
@@ -2005,6 +2033,6 @@ function accessibleNavItems(user, table, translate) {
|
|
|
2005
2033
|
return roleRoutesToNavItems(resolveAccessibleRoutes(user, table), translate);
|
|
2006
2034
|
}
|
|
2007
2035
|
|
|
2008
|
-
export { ACTIVE_BORDER_RADIUS, ACTIVE_TINT_OPACITY, APP_SHELL_SUFFIX, AppShell, BASE_INDENT, CHEVRON_ICON_SIZE, CollapsedRail, CommandPalette, CommandPaletteTrigger, DEFAULT_COLLAPSED_RAIL_MAX, DEFAULT_SEARCH_BREAKPOINT, DarkModeControl, HOVER_TINT_OPACITY, NAV_ICON_SIZE, NAV_LINK_GAP, NAV_ROW_RADIUS, NAV_TEST_IDS, Nav, NavBar, NavExpandableItem, NavOverflowMenu, NavShell, PillNav, RAIL_FULL_BREAKPOINT, Sidebar, SidebarChevron, SidebarSearch, Topbar, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, filterCommands, filterNavItems, isFilterActive, isRouteActive, navStyles, pillNavStyles, resolveContentMaxWidth, resolveRailMode, resolveSearchAffordance, roleRoutesToNavItems, searchTokens, useCommandPaletteHotkey, useContentMaxWidth };
|
|
2036
|
+
export { ACTIVE_BORDER_RADIUS, ACTIVE_TINT_OPACITY, APP_SHELL_SUFFIX, AppShell, BASE_INDENT, CHEVRON_ICON_SIZE, CollapsedRail, CommandPalette, CommandPaletteTrigger, DEFAULT_COLLAPSED_RAIL_MAX, DEFAULT_SEARCH_BREAKPOINT, DarkModeControl, HOVER_TINT_OPACITY, NAV_ICON_SIZE, NAV_LINK_GAP, NAV_ROW_RADIUS, NAV_TEST_IDS, Nav, NavBar, NavExpandableItem, NavOverflowMenu, NavShell, PillNav, RAIL_FULL_BREAKPOINT, Sidebar, SidebarChevron, SidebarSearch, Topbar, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, filterCommands, filterNavItems, isFilterActive, isRouteActive, navStyles, pillNavStyles, resolveActiveRoute, resolveContentMaxWidth, resolveRailMode, resolveSearchAffordance, roleRoutesToNavItems, searchTokens, useCommandPaletteHotkey, useContentMaxWidth };
|
|
2009
2037
|
//# sourceMappingURL=index.mjs.map
|
|
2010
2038
|
//# sourceMappingURL=index.mjs.map
|