@dloizides/ui-nav 1.11.0 → 1.13.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.d.mts CHANGED
@@ -898,6 +898,116 @@ interface NavExpandableItemProps {
898
898
  }
899
899
  declare const NavExpandableItem: ({ item, pathname, onNavigate, navigateHint, expandHint, collapseHint, renderChevron, depth, }: NavExpandableItemProps) => React.ReactElement;
900
900
 
901
+ /**
902
+ * Pure matching logic for the {@link CommandPalette}. Kept framework-free so the
903
+ * ranking/filtering is unit-testable without rendering: a command matches when
904
+ * every whitespace-separated token of the query appears (case-insensitively) in
905
+ * its haystack (label + hint + keywords). Requiring ALL tokens lets an operator
906
+ * narrow with "pay dash" the way a fuzzy launcher would, without a fuzzy lib.
907
+ */
908
+
909
+ /** One actionable destination/command shown in the palette. */
910
+ interface CommandItem {
911
+ /** Stable key + default testID. */
912
+ key: string;
913
+ /** Optional testID override (defaults to `key`). */
914
+ testID?: string;
915
+ /** Localized display label (what the operator reads). */
916
+ label: string;
917
+ /** Optional localized secondary line (e.g. the module it lives in). */
918
+ hint?: string;
919
+ /** Optional extra search terms not shown but matched (synonyms, route words). */
920
+ keywords?: readonly string[];
921
+ /** Invoked when the item is chosen (the consumer navigates / runs the action). */
922
+ onSelect: () => void;
923
+ /** Optional leading icon slot, same contract as `NavItem.renderIcon`. */
924
+ renderIcon?: (color: string, size: number) => React.ReactNode;
925
+ }
926
+ /**
927
+ * Filter `items` to those matching `query`. An empty/whitespace query returns
928
+ * the list unchanged (the palette opens showing everything). Order is preserved
929
+ * — the caller supplies items in a meaningful order (nav order).
930
+ */
931
+ declare function filterCommands(items: readonly CommandItem[], query: string): CommandItem[];
932
+
933
+ /**
934
+ * CommandPalette — the shared ⌘K launcher for `@dloizides/ui-nav`. An overlay
935
+ * (scrim + centred panel) with a search input over a keyboard-navigable list of
936
+ * {@link CommandItem}s — jump to any nav destination (or run any action) without
937
+ * hunting the rail. Web-first (RN-web), but degrades safely: when `open` is
938
+ * false it renders nothing.
939
+ *
940
+ * Package discipline (as the rest of ui-nav): NO FM / router / store / icon-set
941
+ * imports. Labels are pre-localized strings; icons are render slots; every colour
942
+ * comes from the `@dloizides/ui-feedback` UiProvider theme. The consumer owns the
943
+ * `open` state (pair with {@link useCommandPaletteHotkey}) and each item's
944
+ * `onSelect` (navigate / run) — the palette just closes after a choice.
945
+ */
946
+
947
+ /** Pre-localized labels for the palette chrome. */
948
+ interface CommandPaletteLabels {
949
+ /** Search input placeholder. */
950
+ placeholder: string;
951
+ /** Accessible name of the scrim (tap to close). */
952
+ closeLabel: string;
953
+ /** Accessible hint of the scrim (tap to close). */
954
+ closeHint: string;
955
+ /** Shown when the query matches nothing. */
956
+ emptyText: string;
957
+ /** Accessible label for the palette dialog landmark. */
958
+ regionLabel: string;
959
+ }
960
+ interface CommandPaletteProps {
961
+ /** Whether the palette overlay is shown. */
962
+ open: boolean;
963
+ /** The commands to search over, in a meaningful (nav) order. */
964
+ items: readonly CommandItem[];
965
+ /** Close the palette (scrim tap / Escape / after a selection). */
966
+ onClose: () => void;
967
+ /** Pre-localized chrome labels. */
968
+ labels: CommandPaletteLabels;
969
+ /** testID for the panel (defaults to `command-palette`). */
970
+ testID?: string;
971
+ }
972
+ /** The overlay palette. Renders null when closed. */
973
+ declare const CommandPalette: ({ open, items, onClose, labels, testID }: CommandPaletteProps) => React.ReactElement | null;
974
+
975
+ /**
976
+ * CommandPaletteTrigger — the VISIBLE, discoverable affordance that opens the
977
+ * {@link CommandPalette}. A ⌘K shortcut alone is invisible; a docs-style search
978
+ * pill (muted placeholder on the left, a keyboard-shortcut badge on the right)
979
+ * tells operators the palette exists and is one click away. Place it in a shell
980
+ * header / sidebar; wire `onPress` to the same open handler as the ⌘K hotkey.
981
+ *
982
+ * Self-contained on purpose: the shared icon set has no magnifier, so this uses
983
+ * text + a shortcut badge (the recognizable "Search … ⌘K" pattern) rather than a
984
+ * render-slot icon — one less thing every consumer must supply. Colours come from
985
+ * the `@dloizides/ui-feedback` UiProvider theme; the label/shortcut are
986
+ * pre-localized strings (package discipline: no FM/router imports).
987
+ */
988
+
989
+ interface CommandPaletteTriggerProps {
990
+ /** Placeholder-style label, e.g. "Search". */
991
+ label: string;
992
+ /** a11y hint describing what activating it does. */
993
+ hint: string;
994
+ /** The shortcut badge text, e.g. "⌘K" (already chosen per-platform by the caller). */
995
+ shortcut: string;
996
+ /** Open the palette (same handler as the ⌘K hotkey). */
997
+ onPress: () => void;
998
+ /** testID for the trigger. */
999
+ testID: string;
1000
+ }
1001
+ /** The visible "Search … ⌘K" pill that opens the command palette. */
1002
+ declare const CommandPaletteTrigger: ({ label, hint, shortcut, onPress, testID, }: CommandPaletteTriggerProps) => React.ReactElement;
1003
+
1004
+ /**
1005
+ * Call `onOpen` when the operator presses ⌘K (macOS) or Ctrl-K (Windows/Linux),
1006
+ * anywhere in the document. `enabled=false` unbinds (e.g. when the shell has no
1007
+ * palette configured), so the shortcut never fires without a handler behind it.
1008
+ */
1009
+ declare function useCommandPaletteHotkey(onOpen: () => void, enabled?: boolean): void;
1010
+
901
1011
  /**
902
1012
  * Role-gated nav helpers — build a `NavItem[]` from a user's roles, reusing the
903
1013
  * existing `resolveAccessibleRoutes` from `@dloizides/auth-web` (the same helper
@@ -1101,6 +1211,8 @@ declare const expandableStyles: {
1101
1211
  flexDirection: "row";
1102
1212
  alignItems: "center";
1103
1213
  paddingVertical: number;
1214
+ borderLeftWidth: number;
1215
+ borderLeftColor: string;
1104
1216
  };
1105
1217
  childItemText: {
1106
1218
  fontSize: number;
@@ -1114,6 +1226,7 @@ declare const expandableStyles: {
1114
1226
  };
1115
1227
  childrenContainer: {
1116
1228
  overflow: "hidden";
1229
+ marginBottom: number;
1117
1230
  };
1118
1231
  header: {
1119
1232
  borderRadius: number;
@@ -1121,11 +1234,21 @@ declare const expandableStyles: {
1121
1234
  alignItems: "center";
1122
1235
  paddingVertical: number;
1123
1236
  };
1237
+ sectionHeader: {
1238
+ marginTop: number;
1239
+ };
1124
1240
  headerText: {
1125
1241
  fontSize: number;
1126
1242
  fontWeight: "600";
1127
1243
  marginLeft: number;
1128
1244
  };
1245
+ sectionHeaderText: {
1246
+ fontSize: number;
1247
+ fontWeight: "700";
1248
+ marginLeft: number;
1249
+ textTransform: "uppercase";
1250
+ letterSpacing: number;
1251
+ };
1129
1252
  iconWrapper: {
1130
1253
  width: number;
1131
1254
  alignItems: "center";
@@ -1138,4 +1261,4 @@ declare const NAV_ICON_SIZE = 14;
1138
1261
  /** Chevron icon size for expandable sections. */
1139
1262
  declare const CHEVRON_ICON_SIZE = 12;
1140
1263
 
1141
- export { ACTIVE_BORDER_RADIUS, APP_SHELL_SUFFIX, type AccountPlan, type AccountState, AppShell, type AppShellProps, type AppShellWidth, BASE_INDENT, CHEVRON_ICON_SIZE, CollapsedRail, type CollapsedRailProps, type CollapsedRailRange, DEFAULT_COLLAPSED_RAIL_MAX, DarkModeControl, type DarkModeControlProps, type DarkModeOption, type DarkModeVariant, NAV_ICON_SIZE, NAV_LINK_GAP, NAV_TEST_IDS, Nav, NavBar, type NavBarProps, NavExpandableItem, type NavExpandableItemProps, type NavItem, type NavOrientation, NavOverflowMenu, type NavOverflowMenuProps, type NavProps, NavShell, type NavShellCollapsedRail, type NavShellLayout, type NavShellProps, type NavShellSideRail, type NavShellTopBar, type NavUser, PillNav, type PillNavProps, RAIL_FULL_BREAKPOINT, type RailMode, type ResolveRailModeArgs, type ShellMessage, Sidebar, type SidebarProps, Topbar, type TopbarAction, type TopbarProps, type TopbarUser, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, isRouteActive, navStyles, pillNavStyles, resolveContentMaxWidth, resolveRailMode, roleRoutesToNavItems, useContentMaxWidth };
1264
+ export { ACTIVE_BORDER_RADIUS, APP_SHELL_SUFFIX, type AccountPlan, type AccountState, AppShell, type AppShellProps, type AppShellWidth, BASE_INDENT, CHEVRON_ICON_SIZE, CollapsedRail, type CollapsedRailProps, type CollapsedRailRange, type CommandItem, CommandPalette, type CommandPaletteLabels, type CommandPaletteProps, CommandPaletteTrigger, type CommandPaletteTriggerProps, DEFAULT_COLLAPSED_RAIL_MAX, DarkModeControl, type DarkModeControlProps, type DarkModeOption, type DarkModeVariant, NAV_ICON_SIZE, NAV_LINK_GAP, NAV_TEST_IDS, Nav, NavBar, type NavBarProps, NavExpandableItem, type NavExpandableItemProps, type NavItem, type NavOrientation, NavOverflowMenu, type NavOverflowMenuProps, type NavProps, NavShell, type NavShellCollapsedRail, type NavShellLayout, type NavShellProps, type NavShellSideRail, type NavShellTopBar, type NavUser, PillNav, type PillNavProps, RAIL_FULL_BREAKPOINT, type RailMode, type ResolveRailModeArgs, type ShellMessage, Sidebar, type SidebarProps, Topbar, type TopbarAction, type TopbarProps, type TopbarUser, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, filterCommands, isRouteActive, navStyles, pillNavStyles, resolveContentMaxWidth, resolveRailMode, roleRoutesToNavItems, useCommandPaletteHotkey, useContentMaxWidth };
package/dist/index.d.ts CHANGED
@@ -898,6 +898,116 @@ interface NavExpandableItemProps {
898
898
  }
899
899
  declare const NavExpandableItem: ({ item, pathname, onNavigate, navigateHint, expandHint, collapseHint, renderChevron, depth, }: NavExpandableItemProps) => React.ReactElement;
900
900
 
901
+ /**
902
+ * Pure matching logic for the {@link CommandPalette}. Kept framework-free so the
903
+ * ranking/filtering is unit-testable without rendering: a command matches when
904
+ * every whitespace-separated token of the query appears (case-insensitively) in
905
+ * its haystack (label + hint + keywords). Requiring ALL tokens lets an operator
906
+ * narrow with "pay dash" the way a fuzzy launcher would, without a fuzzy lib.
907
+ */
908
+
909
+ /** One actionable destination/command shown in the palette. */
910
+ interface CommandItem {
911
+ /** Stable key + default testID. */
912
+ key: string;
913
+ /** Optional testID override (defaults to `key`). */
914
+ testID?: string;
915
+ /** Localized display label (what the operator reads). */
916
+ label: string;
917
+ /** Optional localized secondary line (e.g. the module it lives in). */
918
+ hint?: string;
919
+ /** Optional extra search terms not shown but matched (synonyms, route words). */
920
+ keywords?: readonly string[];
921
+ /** Invoked when the item is chosen (the consumer navigates / runs the action). */
922
+ onSelect: () => void;
923
+ /** Optional leading icon slot, same contract as `NavItem.renderIcon`. */
924
+ renderIcon?: (color: string, size: number) => React.ReactNode;
925
+ }
926
+ /**
927
+ * Filter `items` to those matching `query`. An empty/whitespace query returns
928
+ * the list unchanged (the palette opens showing everything). Order is preserved
929
+ * — the caller supplies items in a meaningful order (nav order).
930
+ */
931
+ declare function filterCommands(items: readonly CommandItem[], query: string): CommandItem[];
932
+
933
+ /**
934
+ * CommandPalette — the shared ⌘K launcher for `@dloizides/ui-nav`. An overlay
935
+ * (scrim + centred panel) with a search input over a keyboard-navigable list of
936
+ * {@link CommandItem}s — jump to any nav destination (or run any action) without
937
+ * hunting the rail. Web-first (RN-web), but degrades safely: when `open` is
938
+ * false it renders nothing.
939
+ *
940
+ * Package discipline (as the rest of ui-nav): NO FM / router / store / icon-set
941
+ * imports. Labels are pre-localized strings; icons are render slots; every colour
942
+ * comes from the `@dloizides/ui-feedback` UiProvider theme. The consumer owns the
943
+ * `open` state (pair with {@link useCommandPaletteHotkey}) and each item's
944
+ * `onSelect` (navigate / run) — the palette just closes after a choice.
945
+ */
946
+
947
+ /** Pre-localized labels for the palette chrome. */
948
+ interface CommandPaletteLabels {
949
+ /** Search input placeholder. */
950
+ placeholder: string;
951
+ /** Accessible name of the scrim (tap to close). */
952
+ closeLabel: string;
953
+ /** Accessible hint of the scrim (tap to close). */
954
+ closeHint: string;
955
+ /** Shown when the query matches nothing. */
956
+ emptyText: string;
957
+ /** Accessible label for the palette dialog landmark. */
958
+ regionLabel: string;
959
+ }
960
+ interface CommandPaletteProps {
961
+ /** Whether the palette overlay is shown. */
962
+ open: boolean;
963
+ /** The commands to search over, in a meaningful (nav) order. */
964
+ items: readonly CommandItem[];
965
+ /** Close the palette (scrim tap / Escape / after a selection). */
966
+ onClose: () => void;
967
+ /** Pre-localized chrome labels. */
968
+ labels: CommandPaletteLabels;
969
+ /** testID for the panel (defaults to `command-palette`). */
970
+ testID?: string;
971
+ }
972
+ /** The overlay palette. Renders null when closed. */
973
+ declare const CommandPalette: ({ open, items, onClose, labels, testID }: CommandPaletteProps) => React.ReactElement | null;
974
+
975
+ /**
976
+ * CommandPaletteTrigger — the VISIBLE, discoverable affordance that opens the
977
+ * {@link CommandPalette}. A ⌘K shortcut alone is invisible; a docs-style search
978
+ * pill (muted placeholder on the left, a keyboard-shortcut badge on the right)
979
+ * tells operators the palette exists and is one click away. Place it in a shell
980
+ * header / sidebar; wire `onPress` to the same open handler as the ⌘K hotkey.
981
+ *
982
+ * Self-contained on purpose: the shared icon set has no magnifier, so this uses
983
+ * text + a shortcut badge (the recognizable "Search … ⌘K" pattern) rather than a
984
+ * render-slot icon — one less thing every consumer must supply. Colours come from
985
+ * the `@dloizides/ui-feedback` UiProvider theme; the label/shortcut are
986
+ * pre-localized strings (package discipline: no FM/router imports).
987
+ */
988
+
989
+ interface CommandPaletteTriggerProps {
990
+ /** Placeholder-style label, e.g. "Search". */
991
+ label: string;
992
+ /** a11y hint describing what activating it does. */
993
+ hint: string;
994
+ /** The shortcut badge text, e.g. "⌘K" (already chosen per-platform by the caller). */
995
+ shortcut: string;
996
+ /** Open the palette (same handler as the ⌘K hotkey). */
997
+ onPress: () => void;
998
+ /** testID for the trigger. */
999
+ testID: string;
1000
+ }
1001
+ /** The visible "Search … ⌘K" pill that opens the command palette. */
1002
+ declare const CommandPaletteTrigger: ({ label, hint, shortcut, onPress, testID, }: CommandPaletteTriggerProps) => React.ReactElement;
1003
+
1004
+ /**
1005
+ * Call `onOpen` when the operator presses ⌘K (macOS) or Ctrl-K (Windows/Linux),
1006
+ * anywhere in the document. `enabled=false` unbinds (e.g. when the shell has no
1007
+ * palette configured), so the shortcut never fires without a handler behind it.
1008
+ */
1009
+ declare function useCommandPaletteHotkey(onOpen: () => void, enabled?: boolean): void;
1010
+
901
1011
  /**
902
1012
  * Role-gated nav helpers — build a `NavItem[]` from a user's roles, reusing the
903
1013
  * existing `resolveAccessibleRoutes` from `@dloizides/auth-web` (the same helper
@@ -1101,6 +1211,8 @@ declare const expandableStyles: {
1101
1211
  flexDirection: "row";
1102
1212
  alignItems: "center";
1103
1213
  paddingVertical: number;
1214
+ borderLeftWidth: number;
1215
+ borderLeftColor: string;
1104
1216
  };
1105
1217
  childItemText: {
1106
1218
  fontSize: number;
@@ -1114,6 +1226,7 @@ declare const expandableStyles: {
1114
1226
  };
1115
1227
  childrenContainer: {
1116
1228
  overflow: "hidden";
1229
+ marginBottom: number;
1117
1230
  };
1118
1231
  header: {
1119
1232
  borderRadius: number;
@@ -1121,11 +1234,21 @@ declare const expandableStyles: {
1121
1234
  alignItems: "center";
1122
1235
  paddingVertical: number;
1123
1236
  };
1237
+ sectionHeader: {
1238
+ marginTop: number;
1239
+ };
1124
1240
  headerText: {
1125
1241
  fontSize: number;
1126
1242
  fontWeight: "600";
1127
1243
  marginLeft: number;
1128
1244
  };
1245
+ sectionHeaderText: {
1246
+ fontSize: number;
1247
+ fontWeight: "700";
1248
+ marginLeft: number;
1249
+ textTransform: "uppercase";
1250
+ letterSpacing: number;
1251
+ };
1129
1252
  iconWrapper: {
1130
1253
  width: number;
1131
1254
  alignItems: "center";
@@ -1138,4 +1261,4 @@ declare const NAV_ICON_SIZE = 14;
1138
1261
  /** Chevron icon size for expandable sections. */
1139
1262
  declare const CHEVRON_ICON_SIZE = 12;
1140
1263
 
1141
- export { ACTIVE_BORDER_RADIUS, APP_SHELL_SUFFIX, type AccountPlan, type AccountState, AppShell, type AppShellProps, type AppShellWidth, BASE_INDENT, CHEVRON_ICON_SIZE, CollapsedRail, type CollapsedRailProps, type CollapsedRailRange, DEFAULT_COLLAPSED_RAIL_MAX, DarkModeControl, type DarkModeControlProps, type DarkModeOption, type DarkModeVariant, NAV_ICON_SIZE, NAV_LINK_GAP, NAV_TEST_IDS, Nav, NavBar, type NavBarProps, NavExpandableItem, type NavExpandableItemProps, type NavItem, type NavOrientation, NavOverflowMenu, type NavOverflowMenuProps, type NavProps, NavShell, type NavShellCollapsedRail, type NavShellLayout, type NavShellProps, type NavShellSideRail, type NavShellTopBar, type NavUser, PillNav, type PillNavProps, RAIL_FULL_BREAKPOINT, type RailMode, type ResolveRailModeArgs, type ShellMessage, Sidebar, type SidebarProps, Topbar, type TopbarAction, type TopbarProps, type TopbarUser, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, isRouteActive, navStyles, pillNavStyles, resolveContentMaxWidth, resolveRailMode, roleRoutesToNavItems, useContentMaxWidth };
1264
+ export { ACTIVE_BORDER_RADIUS, APP_SHELL_SUFFIX, type AccountPlan, type AccountState, AppShell, type AppShellProps, type AppShellWidth, BASE_INDENT, CHEVRON_ICON_SIZE, CollapsedRail, type CollapsedRailProps, type CollapsedRailRange, type CommandItem, CommandPalette, type CommandPaletteLabels, type CommandPaletteProps, CommandPaletteTrigger, type CommandPaletteTriggerProps, DEFAULT_COLLAPSED_RAIL_MAX, DarkModeControl, type DarkModeControlProps, type DarkModeOption, type DarkModeVariant, NAV_ICON_SIZE, NAV_LINK_GAP, NAV_TEST_IDS, Nav, NavBar, type NavBarProps, NavExpandableItem, type NavExpandableItemProps, type NavItem, type NavOrientation, NavOverflowMenu, type NavOverflowMenuProps, type NavProps, NavShell, type NavShellCollapsedRail, type NavShellLayout, type NavShellProps, type NavShellSideRail, type NavShellTopBar, type NavUser, PillNav, type PillNavProps, RAIL_FULL_BREAKPOINT, type RailMode, type ResolveRailModeArgs, type ShellMessage, Sidebar, type SidebarProps, Topbar, type TopbarAction, type TopbarProps, type TopbarUser, accessibleNavItems, collapsedRailStyles, darkModeStyles, expandableStyles, filterCommands, isRouteActive, navStyles, pillNavStyles, resolveContentMaxWidth, resolveRailMode, roleRoutesToNavItems, useCommandPaletteHotkey, useContentMaxWidth };