# All files / src/components/layout/navigation NavigationSidebar.tsx

70.44% Statements 112/159
100% Branches 1/1
33.33% Functions 1/3
70.44% Lines 112/159

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    1601x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x

    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
    6x
     'use client';

    import { motion, AnimatePresence } from 'framer-motion';
    import Link from 'next/link';
    import { usePathname } from 'next/navigation';
    import { X } from '@phosphor-icons/react';
    import { cn } from '@/lib/utils';
    import { navigationItems } from './navigation-items';
    import { useNavigation } from './useNavigation';

    /**
     * Material Design 3 Navigation Drawer
     *
     * Android-style modal navigation drawer with:
     * - Scrim overlay
     * - Slide-in animation
     * - Active indicator pill
     * - MD3 typography and spacing
     */
    export function NavigationSidebar() {
      const { menuOpen, setMenuOpen } = useNavigation();
      const pathname = usePathname();

      return (
        <AnimatePresence>
          {menuOpen && (
            <>
              {/* Scrim/Overlay */}
              <motion.div
                initial={{ opacity: 0 }}
                animate={{ opacity: 1 }}
                exit={{ opacity: 0 }}
                transition={{ duration: 0.2 }}
                className="fixed inset-0 z-40 bg-black/32"
                onClick={() => setMenuOpen(false)}
                aria-hidden="true"
                data-testid="navigation-sidebar-overlay"
              />

              {/* Navigation Drawer */}
              <motion.aside
                initial={{ x: -320 }}
                animate={{ x: 0 }}
                exit={{ x: -320 }}
                transition={{
                  type: 'spring',
                  damping: 30,
                  stiffness: 300,
                  mass: 0.8
                }}
                className={cn(
                  "fixed left-0 top-0 h-screen w-80 z-50",
                  "bg-[hsl(var(--card))]",
                  "flex flex-col",
                  "shadow-xl"
                )}
                data-testid="navigation-sidebar"
                id="navigation-sidebar"
                role="navigation"
                aria-label="Main navigation menu"
              >
                {/* Header */}
                <div className="flex items-center justify-between h-16 px-4 border-b border-border/50">
                  <span className="text-base font-medium text-foreground pl-3">
                    CodeSnippet
                  </span>
                  <button
                    onClick={() => setMenuOpen(false)}
                    className={cn(
                      "flex items-center justify-center",
                      "size-10 rounded-full",
                      "text-muted-foreground",
                      "hover:bg-foreground/[0.08]",
                      "active:bg-foreground/[0.12]",
                      "transition-colors duration-200",
                      "outline-none focus-visible:ring-2 focus-visible:ring-primary"
                    )}
                    aria-label="Close navigation"
                    data-testid="navigation-sidebar-close-btn"
                  >
                    <X weight="bold" className="size-5" aria-hidden="true" />
                  </button>
                </div>

                {/* Navigation Items */}
                <nav
                  role="navigation"
                  className="flex-1 overflow-y-auto py-2 px-3"
                  data-testid="navigation-items"
                >
                  <ul className="space-y-0.5">
                    {navigationItems.map((item) => {
                      const Icon = item.icon;
                      const isActive = pathname === item.path;

                      return (
                        <li key={item.path}>
                          <Link
                            href={item.path}
                            onClick={() => setMenuOpen(false)}
                            className={cn(
                              "relative flex items-center gap-3",
                              "h-14 px-4 rounded-full",
                              "text-sm font-medium",
                              "transition-all duration-200",
                              "outline-none",
                              // State layer
                              "before:absolute before:inset-0 before:rounded-full",
                              "before:bg-current before:opacity-0 before:transition-opacity",
                              "hover:before:opacity-[0.08]",
                              "focus-visible:before:opacity-[0.12]",
                              "active:before:opacity-[0.12]",
                              // Active state
                              isActive
                                ? "bg-secondary text-secondary-foreground"
                                : "text-muted-foreground hover:text-foreground"
                            )}
                            data-testid={`nav-link-${item.path.replace(/\//g, '-')}`}
                            aria-current={isActive ? "page" : undefined}
                          >
                            <Icon
                              weight={isActive ? "fill" : "regular"}
                              className="size-6 relative z-10 shrink-0"
                              aria-hidden="true"
                            />
                            <span className="relative z-10">{item.label}</span>

                            {/* Active indicator line */}
                            {isActive && (
                              <motion.div
                                layoutId="nav-indicator"
                                className="absolute right-3 w-1 h-4 bg-primary rounded-full"
                                transition={{ type: 'spring', damping: 30, stiffness: 500 }}
                              />
                            )}
                          </Link>
                        </li>
                      );
                    })}
                  </ul>
                </nav>

                {/* Footer */}
                <div className="p-4 border-t border-border/50">
                  <p className="text-xs text-muted-foreground text-center">
                    Material Design 3
                  </p>
                </div>

                {/* Android gesture bar indicator */}
                <div className="h-5 flex items-center justify-center pb-2">
                  <div className="w-[134px] h-[5px] bg-muted-foreground/40 rounded-full" />
                </div>
              </motion.aside>
            </>
          )}
        </AnimatePresence>
      );
    }