@dloizides/ui-nav 1.23.2 → 1.25.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/dist/index.mjs CHANGED
@@ -65,6 +65,7 @@ var navStyles = StyleSheet.create({
65
65
  justifyContent: "space-between"
66
66
  },
67
67
  topbarLeft: { flex: 1 },
68
+ topbarCenter: { flexShrink: 1, minWidth: 0, flexDirection: "row", alignItems: "center", marginHorizontal: 8 },
68
69
  topbarRight: { flexDirection: "row", alignItems: "center" },
69
70
  topbarRowItem: {
70
71
  marginHorizontal: 8,
@@ -218,7 +219,8 @@ var pillNavStyles = StyleSheet.create({
218
219
  columnGap: 6,
219
220
  justifyContent: "center"
220
221
  },
221
- pillText: { fontSize: 14, fontWeight: "600" }
222
+ pillText: { fontSize: 14, fontWeight: "600" },
223
+ menuTriggerText: { flexShrink: 1 }
222
224
  });
223
225
  var darkModeStyles = StyleSheet.create({
224
226
  // Segmented Light / Dark / System control.
@@ -875,7 +877,11 @@ var NAV_TEST_IDS = {
875
877
  /** links container in the horizontal NavBar. */
876
878
  navBarLinks: "navbar-links",
877
879
  /** the "More ▾" priority+ overflow trigger in the horizontal NavBar (shown when items spill). */
878
- navBarOverflow: "navbar-overflow"
880
+ navBarOverflow: "navbar-overflow",
881
+ /** the compact "Current ▾" trigger of `PillNav` with `variant={PillNavVariant.Menu}`. */
882
+ pillNavMenu: "pill-nav-menu",
883
+ /** the optional middle slot of `Topbar` (rendered only when `center` is passed). */
884
+ topbarCenter: "topbar-center"
879
885
  };
880
886
  var APP_SHELL_SUFFIX = {
881
887
  content: "-content",
@@ -935,6 +941,7 @@ function planToneColor(theme, tone) {
935
941
  }
936
942
  var Topbar = ({
937
943
  left,
944
+ center,
938
945
  language,
939
946
  notificationSlot,
940
947
  user,
@@ -958,6 +965,7 @@ var Topbar = ({
958
965
  ],
959
966
  children: [
960
967
  /* @__PURE__ */ jsx(View, { style: navStyles.topbarLeft, children: renderTextSlot(left, { color: colors.text }) }),
968
+ center !== void 0 && center !== null ? /* @__PURE__ */ jsx(View, { style: navStyles.topbarCenter, testID: NAV_TEST_IDS.topbarCenter, children: renderTextSlot(center, { color: colors.text }) }) : null,
961
969
  /* @__PURE__ */ jsxs(View, { style: navStyles.topbarRight, children: [
962
970
  language ? /* @__PURE__ */ jsx(
963
971
  FocusableTouchable,
@@ -1853,7 +1861,63 @@ var NavShell = ({
1853
1861
  }
1854
1862
  );
1855
1863
  };
1864
+
1865
+ // src/pillMenuLabel.ts
1866
+ function resolvePillMenuLabel(items, pathname, fallback) {
1867
+ const activeRoute = resolveActiveRoute(items, pathname);
1868
+ const active = items.find((item) => item.route === activeRoute);
1869
+ return active?.label ?? fallback;
1870
+ }
1856
1871
  var TEXT_ON_PRIMARY4 = "#ffffff";
1872
+ var NO_ACTIVE_ROUTE2 = "";
1873
+ var PILL_MENU_MIN_WIDTH = 200;
1874
+ var PillNavMenu = ({
1875
+ items,
1876
+ pathname,
1877
+ onNavigate,
1878
+ regionLabel,
1879
+ hint,
1880
+ testID = NAV_TEST_IDS.pillNavMenu,
1881
+ dropdownVariant,
1882
+ menuHeading
1883
+ }) => {
1884
+ const { theme } = useUi();
1885
+ const primaryColor = theme.palette.primary["500"];
1886
+ const options = useMemo(() => items.map((item) => ({ label: item.label, value: item.route })), [items]);
1887
+ const activeRoute = resolveActiveRoute(items, pathname) ?? NO_ACTIVE_ROUTE2;
1888
+ const label = resolvePillMenuLabel(items, pathname, regionLabel);
1889
+ const optionTestID = useMemo(() => {
1890
+ const byRoute = new Map(items.map((item) => [item.route, item.testID ?? item.key]));
1891
+ return (route) => byRoute.get(route) ?? `${testID}-option-${route}`;
1892
+ }, [items, testID]);
1893
+ return /* @__PURE__ */ jsx(
1894
+ ModalDropdown,
1895
+ {
1896
+ accessibilityHint: hint,
1897
+ accessibilityLabel: label,
1898
+ menuHeading,
1899
+ menuMinWidth: PILL_MENU_MIN_WIDTH,
1900
+ optionTestID,
1901
+ options,
1902
+ testID,
1903
+ value: activeRoute,
1904
+ variant: dropdownVariant,
1905
+ onChange: onNavigate,
1906
+ renderTrigger: ({ isOpen }) => /* @__PURE__ */ jsxs(View, { style: [pillNavStyles.pill, { backgroundColor: primaryColor }], children: [
1907
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [pillNavStyles.pillText, pillNavStyles.menuTriggerText, { color: TEXT_ON_PRIMARY4 }], children: label }),
1908
+ /* @__PURE__ */ jsx(Text, { style: [pillNavStyles.pillText, { color: TEXT_ON_PRIMARY4 }], children: isOpen ? "\u25B4" : "\u25BE" })
1909
+ ] })
1910
+ }
1911
+ );
1912
+ };
1913
+
1914
+ // src/PillNavVariant.ts
1915
+ var PillNavVariant = /* @__PURE__ */ ((PillNavVariant2) => {
1916
+ PillNavVariant2["Pills"] = "pills";
1917
+ PillNavVariant2["Menu"] = "menu";
1918
+ return PillNavVariant2;
1919
+ })(PillNavVariant || {});
1920
+ var TEXT_ON_PRIMARY5 = "#ffffff";
1857
1921
  var DEFAULT_MIN_ITEMS = 1;
1858
1922
  var PillNav = ({
1859
1923
  items,
@@ -1862,12 +1926,31 @@ var PillNav = ({
1862
1926
  regionLabel,
1863
1927
  navigateHint = (label) => label,
1864
1928
  minItems = DEFAULT_MIN_ITEMS,
1929
+ variant = "pills" /* Pills */,
1930
+ menuHint,
1931
+ menuHeading,
1932
+ menuTestID,
1933
+ dropdownVariant,
1865
1934
  containerStyle
1866
1935
  }) => {
1867
1936
  const { theme } = useUi();
1868
1937
  const colors = theme.colors;
1869
1938
  const primaryColor = theme.palette.primary["500"];
1870
1939
  if (items.length < minItems) return null;
1940
+ if (variant === "menu" /* Menu */)
1941
+ return /* @__PURE__ */ jsx(View, { accessibilityRole: "none", "aria-label": regionLabel, role: "navigation", style: containerStyle, children: /* @__PURE__ */ jsx(
1942
+ PillNavMenu,
1943
+ {
1944
+ dropdownVariant,
1945
+ hint: menuHint ?? regionLabel,
1946
+ items,
1947
+ menuHeading,
1948
+ pathname,
1949
+ regionLabel,
1950
+ testID: menuTestID,
1951
+ onNavigate
1952
+ }
1953
+ ) });
1871
1954
  const activeRoute = resolveActiveRoute(items, pathname);
1872
1955
  return /* @__PURE__ */ jsx(
1873
1956
  View,
@@ -1878,7 +1961,7 @@ var PillNav = ({
1878
1961
  style: [pillNavStyles.container, containerStyle],
1879
1962
  children: items.map((item) => {
1880
1963
  const active = item.route === activeRoute;
1881
- const textColor = active ? TEXT_ON_PRIMARY4 : colors.textSecondary;
1964
+ const textColor = active ? TEXT_ON_PRIMARY5 : colors.textSecondary;
1882
1965
  const pillStyle = active ? { backgroundColor: primaryColor } : { backgroundColor: colors.surfaceElevated };
1883
1966
  return /* @__PURE__ */ jsxs(
1884
1967
  FocusableTouchable,
@@ -1901,7 +1984,7 @@ var PillNav = ({
1901
1984
  }
1902
1985
  );
1903
1986
  };
1904
- var TEXT_ON_PRIMARY5 = "#ffffff";
1987
+ var TEXT_ON_PRIMARY6 = "#ffffff";
1905
1988
  var DARK_MODE_ICON_SIZE = 16;
1906
1989
  var DarkModeControl = ({
1907
1990
  value,
@@ -1950,7 +2033,7 @@ var DarkModeControl = ({
1950
2033
  style: [darkModeStyles.segmentRow, { borderColor: colors.border }, containerStyle],
1951
2034
  children: options.map((option) => {
1952
2035
  const active = option.value === value;
1953
- const textColor = active ? TEXT_ON_PRIMARY5 : colors.textSecondary;
2036
+ const textColor = active ? TEXT_ON_PRIMARY6 : colors.textSecondary;
1954
2037
  return /* @__PURE__ */ jsxs(
1955
2038
  FocusableTouchable,
1956
2039
  {
@@ -2135,6 +2218,6 @@ function accessibleNavItems(user, table, translate) {
2135
2218
  return roleRoutesToNavItems(resolveAccessibleRoutes(user, table), translate);
2136
2219
  }
2137
2220
 
2138
- 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 };
2221
+ 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, PillNavVariant, RAIL_FULL_BREAKPOINT, Sidebar, SidebarChevron, SidebarSearch, Topbar, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, filterCommands, filterNavItems, isFilterActive, isRouteActive, navStyles, pillNavStyles, resolveActiveRoute, resolveContentMaxWidth, resolvePillMenuLabel, resolveRailMode, resolveSearchAffordance, roleRoutesToNavItems, searchTokens, useCommandPaletteHotkey, useContentMaxWidth };
2139
2222
  //# sourceMappingURL=index.mjs.map
2140
2223
  //# sourceMappingURL=index.mjs.map