diff --git a/apps/web/src/components/settings/SettingsSidebarNav.items.ts b/apps/web/src/components/settings/SettingsSidebarNav.items.ts new file mode 100644 index 00000000000..4e341f97ee4 --- /dev/null +++ b/apps/web/src/components/settings/SettingsSidebarNav.items.ts @@ -0,0 +1,32 @@ +import { + ArchiveIcon, + BotIcon, + GitBranchIcon, + KeyboardIcon, + Link2Icon, + Settings2Icon, +} from "lucide-react"; +import type { ComponentType } from "react"; + +export type SettingsSectionPath = + | "/settings/general" + | "/settings/keybindings" + | "/settings/providers" + | "/settings/source-control" + | "/settings/connections" + | "/settings/archived"; + +export interface SettingsNavItem { + readonly icon: ComponentType<{ className?: string }>; + readonly label: string; + readonly to: SettingsSectionPath; +} + +export const SETTINGS_NAV_ITEMS: ReadonlyArray = [ + { label: "General", to: "/settings/general", icon: Settings2Icon }, + { label: "Keybindings", to: "/settings/keybindings", icon: KeyboardIcon }, + { label: "Providers", to: "/settings/providers", icon: BotIcon }, + { label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon }, + { label: "Connections", to: "/settings/connections", icon: Link2Icon }, + { label: "Archive", to: "/settings/archived", icon: ArchiveIcon }, +]; diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx index bec96063868..29f0d1696cb 100644 --- a/apps/web/src/components/settings/SettingsSidebarNav.tsx +++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx @@ -1,13 +1,5 @@ -import { useCallback, type ComponentType } from "react"; -import { - ArchiveIcon, - ArrowLeftIcon, - BotIcon, - GitBranchIcon, - KeyboardIcon, - Link2Icon, - Settings2Icon, -} from "lucide-react"; +import { useCallback } from "react"; +import { ArrowLeftIcon } from "lucide-react"; import { useCanGoBack, useNavigate } from "@tanstack/react-router"; import { @@ -20,27 +12,8 @@ import { SidebarSeparator, useSidebar, } from "../ui/sidebar"; - -export type SettingsSectionPath = - | "/settings/general" - | "/settings/keybindings" - | "/settings/providers" - | "/settings/source-control" - | "/settings/connections" - | "/settings/archived"; - -export const SETTINGS_NAV_ITEMS: ReadonlyArray<{ - label: string; - to: SettingsSectionPath; - icon: ComponentType<{ className?: string }>; -}> = [ - { label: "General", to: "/settings/general", icon: Settings2Icon }, - { label: "Keybindings", to: "/settings/keybindings", icon: KeyboardIcon }, - { label: "Providers", to: "/settings/providers", icon: BotIcon }, - { label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon }, - { label: "Connections", to: "/settings/connections", icon: Link2Icon }, - { label: "Archive", to: "/settings/archived", icon: ArchiveIcon }, -]; +import { SETTINGS_NAV_ITEMS, type SettingsSectionPath } from "./SettingsSidebarNav.items"; +import { SettingsSidebarNavItem } from "./SettingsSidebarNavItem"; export function SettingsSidebarNav({ pathname }: { pathname: string }) { const navigate = useNavigate(); @@ -71,33 +44,14 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { - {SETTINGS_NAV_ITEMS.map((item) => { - const Icon = item.icon; - const isActive = pathname === item.to; - return ( - - handleSectionClick(item.to)} - > - - {item.label} - - - ); - })} + {SETTINGS_NAV_ITEMS.map((item) => ( + + ))} @@ -108,7 +62,7 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { diff --git a/apps/web/src/components/settings/SettingsSidebarNavItem.tsx b/apps/web/src/components/settings/SettingsSidebarNavItem.tsx new file mode 100644 index 00000000000..920a2b79dc3 --- /dev/null +++ b/apps/web/src/components/settings/SettingsSidebarNavItem.tsx @@ -0,0 +1,45 @@ +import { memo, useCallback } from "react"; + +import { SidebarMenuButton, SidebarMenuItem } from "../ui/sidebar"; +import type { SettingsNavItem, SettingsSectionPath } from "./SettingsSidebarNav.items"; + +interface SettingsSidebarNavItemProps { + readonly isActive: boolean; + readonly item: SettingsNavItem; + readonly onSelect: (to: SettingsSectionPath) => void; +} + +export const SettingsSidebarNavItem = memo(function SettingsSidebarNavItem({ + isActive, + item, + onSelect, +}: SettingsSidebarNavItemProps) { + const Icon = item.icon; + const selectSettingsSection = useCallback(() => { + onSelect(item.to); + }, [item.to, onSelect]); + + return ( + + + + {item.label} + + + ); +}); diff --git a/docs/react-scan/settings-sidebar-nav/after-counts.json b/docs/react-scan/settings-sidebar-nav/after-counts.json new file mode 100644 index 00000000000..5c98161ad62 --- /dev/null +++ b/docs/react-scan/settings-sidebar-nav/after-counts.json @@ -0,0 +1,13 @@ +{ + "Archive": 1, + "Bot": 3, + "GitBranch": 3, + "Keyboard": 3, + "Link2": 1, + "Settings2": 4, + "SettingsSidebarNav": 6, + "SettingsSidebarNavItem": 15, + "Sidebar": 6, + "SidebarMenuButton": 16, + "SidebarMenuItem": 16 +} diff --git a/docs/react-scan/settings-sidebar-nav/after.webm b/docs/react-scan/settings-sidebar-nav/after.webm new file mode 100644 index 00000000000..ed8c688743a Binary files /dev/null and b/docs/react-scan/settings-sidebar-nav/after.webm differ diff --git a/docs/react-scan/settings-sidebar-nav/before-counts.json b/docs/react-scan/settings-sidebar-nav/before-counts.json new file mode 100644 index 00000000000..6429412ae5b --- /dev/null +++ b/docs/react-scan/settings-sidebar-nav/before-counts.json @@ -0,0 +1,12 @@ +{ + "Archive": 6, + "Bot": 6, + "GitBranch": 6, + "Keyboard": 6, + "Link2": 6, + "Settings2": 6, + "SettingsSidebarNav": 6, + "Sidebar": 6, + "SidebarMenuButton": 37, + "SidebarMenuItem": 37 +} diff --git a/docs/react-scan/settings-sidebar-nav/before.webm b/docs/react-scan/settings-sidebar-nav/before.webm new file mode 100644 index 00000000000..11312a76316 Binary files /dev/null and b/docs/react-scan/settings-sidebar-nav/before.webm differ