@dloizides/ui-nav 1.23.1 → 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,11 +65,24 @@ 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
- topbarRowItem: { marginHorizontal: 8, alignItems: "center" },
70
+ topbarRowItem: {
71
+ marginHorizontal: 8,
72
+ alignItems: "center",
73
+ justifyContent: "center",
74
+ minHeight: MIN_TOUCH_TARGET,
75
+ minWidth: MIN_TOUCH_TARGET
76
+ },
70
77
  topbarLabel: { fontSize: 14 },
71
78
  userBlock: { marginHorizontal: 12, alignItems: "flex-end" },
72
79
  userName: { fontWeight: "600" },
80
+ accountNameBtn: {
81
+ minHeight: MIN_TOUCH_TARGET,
82
+ minWidth: MIN_TOUCH_TARGET,
83
+ justifyContent: "center",
84
+ alignItems: "flex-end"
85
+ },
73
86
  userEmail: { fontSize: 12 },
74
87
  accountBtn: {
75
88
  marginLeft: 8,
@@ -206,7 +219,8 @@ var pillNavStyles = StyleSheet.create({
206
219
  columnGap: 6,
207
220
  justifyContent: "center"
208
221
  },
209
- pillText: { fontSize: 14, fontWeight: "600" }
222
+ pillText: { fontSize: 14, fontWeight: "600" },
223
+ menuTriggerText: { flexShrink: 1 }
210
224
  });
211
225
  var darkModeStyles = StyleSheet.create({
212
226
  // Segmented Light / Dark / System control.
@@ -863,7 +877,11 @@ var NAV_TEST_IDS = {
863
877
  /** links container in the horizontal NavBar. */
864
878
  navBarLinks: "navbar-links",
865
879
  /** the "More ▾" priority+ overflow trigger in the horizontal NavBar (shown when items spill). */
866
- 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"
867
885
  };
868
886
  var APP_SHELL_SUFFIX = {
869
887
  content: "-content",
@@ -923,6 +941,7 @@ function planToneColor(theme, tone) {
923
941
  }
924
942
  var Topbar = ({
925
943
  left,
944
+ center,
926
945
  language,
927
946
  notificationSlot,
928
947
  user,
@@ -946,6 +965,7 @@ var Topbar = ({
946
965
  ],
947
966
  children: [
948
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,
949
969
  /* @__PURE__ */ jsxs(View, { style: navStyles.topbarRight, children: [
950
970
  language ? /* @__PURE__ */ jsx(
951
971
  FocusableTouchable,
@@ -971,6 +991,7 @@ var Topbar = ({
971
991
  accessibilityHint: richAccount.accountHint ?? richAccount.displayName,
972
992
  accessibilityLabel: richAccount.displayName,
973
993
  ringColor: primaryColor,
994
+ style: navStyles.accountNameBtn,
974
995
  testID: richAccount.accountTestID ?? NAV_TEST_IDS.accountName,
975
996
  onPress: richAccount.onAccount,
976
997
  children: /* @__PURE__ */ jsx(Text, { style: [navStyles.userName, { color: colors.text }], children: richAccount.displayName })
@@ -1840,7 +1861,61 @@ var NavShell = ({
1840
1861
  }
1841
1862
  );
1842
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
+ }
1843
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";
1844
1919
  var DEFAULT_MIN_ITEMS = 1;
1845
1920
  var PillNav = ({
1846
1921
  items,
@@ -1849,12 +1924,29 @@ var PillNav = ({
1849
1924
  regionLabel,
1850
1925
  navigateHint = (label) => label,
1851
1926
  minItems = DEFAULT_MIN_ITEMS,
1927
+ variant = "pills" /* Pills */,
1928
+ menuHint,
1929
+ menuTestID,
1930
+ dropdownVariant,
1852
1931
  containerStyle
1853
1932
  }) => {
1854
1933
  const { theme } = useUi();
1855
1934
  const colors = theme.colors;
1856
1935
  const primaryColor = theme.palette.primary["500"];
1857
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
+ ) });
1858
1950
  const activeRoute = resolveActiveRoute(items, pathname);
1859
1951
  return /* @__PURE__ */ jsx(
1860
1952
  View,
@@ -1865,7 +1957,7 @@ var PillNav = ({
1865
1957
  style: [pillNavStyles.container, containerStyle],
1866
1958
  children: items.map((item) => {
1867
1959
  const active = item.route === activeRoute;
1868
- const textColor = active ? TEXT_ON_PRIMARY4 : colors.textSecondary;
1960
+ const textColor = active ? TEXT_ON_PRIMARY5 : colors.textSecondary;
1869
1961
  const pillStyle = active ? { backgroundColor: primaryColor } : { backgroundColor: colors.surfaceElevated };
1870
1962
  return /* @__PURE__ */ jsxs(
1871
1963
  FocusableTouchable,
@@ -1888,7 +1980,7 @@ var PillNav = ({
1888
1980
  }
1889
1981
  );
1890
1982
  };
1891
- var TEXT_ON_PRIMARY5 = "#ffffff";
1983
+ var TEXT_ON_PRIMARY6 = "#ffffff";
1892
1984
  var DARK_MODE_ICON_SIZE = 16;
1893
1985
  var DarkModeControl = ({
1894
1986
  value,
@@ -1937,7 +2029,7 @@ var DarkModeControl = ({
1937
2029
  style: [darkModeStyles.segmentRow, { borderColor: colors.border }, containerStyle],
1938
2030
  children: options.map((option) => {
1939
2031
  const active = option.value === value;
1940
- const textColor = active ? TEXT_ON_PRIMARY5 : colors.textSecondary;
2032
+ const textColor = active ? TEXT_ON_PRIMARY6 : colors.textSecondary;
1941
2033
  return /* @__PURE__ */ jsxs(
1942
2034
  FocusableTouchable,
1943
2035
  {
@@ -2122,6 +2214,6 @@ function accessibleNavItems(user, table, translate) {
2122
2214
  return roleRoutesToNavItems(resolveAccessibleRoutes(user, table), translate);
2123
2215
  }
2124
2216
 
2125
- 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 };
2126
2218
  //# sourceMappingURL=index.mjs.map
2127
2219
  //# sourceMappingURL=index.mjs.map