@dloizides/ui-nav 1.23.2 → 1.24.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,61 @@ 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
+ }) => {
1883
+ const { theme } = useUi();
1884
+ const primaryColor = theme.palette.primary["500"];
1885
+ const options = useMemo(() => items.map((item) => ({ label: item.label, value: item.route })), [items]);
1886
+ const activeRoute = resolveActiveRoute(items, pathname) ?? NO_ACTIVE_ROUTE2;
1887
+ const label = resolvePillMenuLabel(items, pathname, regionLabel);
1888
+ const optionTestID = useMemo(() => {
1889
+ const byRoute = new Map(items.map((item) => [item.route, item.testID ?? item.key]));
1890
+ return (route) => byRoute.get(route) ?? `${testID}-option-${route}`;
1891
+ }, [items, testID]);
1892
+ return /* @__PURE__ */ jsx(
1893
+ ModalDropdown,
1894
+ {
1895
+ accessibilityHint: hint,
1896
+ accessibilityLabel: label,
1897
+ menuMinWidth: PILL_MENU_MIN_WIDTH,
1898
+ optionTestID,
1899
+ options,
1900
+ testID,
1901
+ value: activeRoute,
1902
+ variant: dropdownVariant,
1903
+ onChange: onNavigate,
1904
+ renderTrigger: ({ isOpen }) => /* @__PURE__ */ jsxs(View, { style: [pillNavStyles.pill, { backgroundColor: primaryColor }], children: [
1905
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [pillNavStyles.pillText, pillNavStyles.menuTriggerText, { color: TEXT_ON_PRIMARY4 }], children: label }),
1906
+ /* @__PURE__ */ jsx(Text, { style: [pillNavStyles.pillText, { color: TEXT_ON_PRIMARY4 }], children: isOpen ? "\u25B4" : "\u25BE" })
1907
+ ] })
1908
+ }
1909
+ );
1910
+ };
1911
+
1912
+ // src/PillNavVariant.ts
1913
+ var PillNavVariant = /* @__PURE__ */ ((PillNavVariant2) => {
1914
+ PillNavVariant2["Pills"] = "pills";
1915
+ PillNavVariant2["Menu"] = "menu";
1916
+ return PillNavVariant2;
1917
+ })(PillNavVariant || {});
1918
+ var TEXT_ON_PRIMARY5 = "#ffffff";
1857
1919
  var DEFAULT_MIN_ITEMS = 1;
1858
1920
  var PillNav = ({
1859
1921
  items,
@@ -1862,12 +1924,29 @@ var PillNav = ({
1862
1924
  regionLabel,
1863
1925
  navigateHint = (label) => label,
1864
1926
  minItems = DEFAULT_MIN_ITEMS,
1927
+ variant = "pills" /* Pills */,
1928
+ menuHint,
1929
+ menuTestID,
1930
+ dropdownVariant,
1865
1931
  containerStyle
1866
1932
  }) => {
1867
1933
  const { theme } = useUi();
1868
1934
  const colors = theme.colors;
1869
1935
  const primaryColor = theme.palette.primary["500"];
1870
1936
  if (items.length < minItems) return null;
1937
+ if (variant === "menu" /* Menu */)
1938
+ return /* @__PURE__ */ jsx(View, { accessibilityRole: "none", "aria-label": regionLabel, role: "navigation", style: containerStyle, children: /* @__PURE__ */ jsx(
1939
+ PillNavMenu,
1940
+ {
1941
+ dropdownVariant,
1942
+ hint: menuHint ?? regionLabel,
1943
+ items,
1944
+ pathname,
1945
+ regionLabel,
1946
+ testID: menuTestID,
1947
+ onNavigate
1948
+ }
1949
+ ) });
1871
1950
  const activeRoute = resolveActiveRoute(items, pathname);
1872
1951
  return /* @__PURE__ */ jsx(
1873
1952
  View,
@@ -1878,7 +1957,7 @@ var PillNav = ({
1878
1957
  style: [pillNavStyles.container, containerStyle],
1879
1958
  children: items.map((item) => {
1880
1959
  const active = item.route === activeRoute;
1881
- const textColor = active ? TEXT_ON_PRIMARY4 : colors.textSecondary;
1960
+ const textColor = active ? TEXT_ON_PRIMARY5 : colors.textSecondary;
1882
1961
  const pillStyle = active ? { backgroundColor: primaryColor } : { backgroundColor: colors.surfaceElevated };
1883
1962
  return /* @__PURE__ */ jsxs(
1884
1963
  FocusableTouchable,
@@ -1901,7 +1980,7 @@ var PillNav = ({
1901
1980
  }
1902
1981
  );
1903
1982
  };
1904
- var TEXT_ON_PRIMARY5 = "#ffffff";
1983
+ var TEXT_ON_PRIMARY6 = "#ffffff";
1905
1984
  var DARK_MODE_ICON_SIZE = 16;
1906
1985
  var DarkModeControl = ({
1907
1986
  value,
@@ -1950,7 +2029,7 @@ var DarkModeControl = ({
1950
2029
  style: [darkModeStyles.segmentRow, { borderColor: colors.border }, containerStyle],
1951
2030
  children: options.map((option) => {
1952
2031
  const active = option.value === value;
1953
- const textColor = active ? TEXT_ON_PRIMARY5 : colors.textSecondary;
2032
+ const textColor = active ? TEXT_ON_PRIMARY6 : colors.textSecondary;
1954
2033
  return /* @__PURE__ */ jsxs(
1955
2034
  FocusableTouchable,
1956
2035
  {
@@ -2135,6 +2214,6 @@ function accessibleNavItems(user, table, translate) {
2135
2214
  return roleRoutesToNavItems(resolveAccessibleRoutes(user, table), translate);
2136
2215
  }
2137
2216
 
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 };
2217
+ 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
2218
  //# sourceMappingURL=index.mjs.map
2140
2219
  //# sourceMappingURL=index.mjs.map