Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com

The theme toggle should show the monitor icon when the `system` theme is selected #45

Openfukowants to merge 0 commits intomain fromfix-theme-selector-dropdown-toggleopened View on GitHub

fukocommented

Summary by CodeRabbit

  • Style
    • Theme toggle icon now dynamically reflects the currently active theme.
    • Theme selection interface improved with enhanced visual feedback for active theme selection.
✏️ Tip: You can customize this high-level summary in your review settings.
    1. Walkthrough

      The ModeToggle component is refactored to introduce an optional getTheme prop, implement a new ThemeIcon component for dynamic icon rendering, and replace static dropdown menu items with a DropdownMenuRadioGroup for theme selection. The trigger icon now reflects the currently active theme.

      Changes

      Cohort / File(s)Change Summary
      Theme Toggle Component Refactoring
      src/components/mode-toggle.tsx
      Adds optional getTheme prop to ModeToggle with theme provider fallback; introduces ThemeIcon component for dynamic icon rendering; replaces three static DropdownMenuItems with DropdownMenuRadioGroup for theme selection; updates trigger to display active theme icon.

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      🚥 Pre-merge checks | ✅ 2 | ❌ 1
      ❌ Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (2 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title accurately describes the main change: updating the theme toggle to display the monitor icon when 'system' theme is selected, which aligns with the primary objective of the changeset.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing touches
      • 📝 Generate docstrings

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. 🚀 Preview Deployment

      Status: ✅ Ready!

      Preview URL: Open Preview

      Commit: d9eba574be03dd7a918a4b20b1bf694b4a480d0f

      Built and deployed successfully

    3. Actionable comments posted: 1

      🤖 Fix all issues with AI agents
      In `@src/components/mode-toggle.tsx`:
      - Around line 12-14: Remove the unused getTheme prop from ThemeToggleProps and
      the component's props list: delete the getTheme?: () => UserTheme declaration
      and any references to getTheme in the mode-toggle component so the component
      relies solely on the internal/user-selection state; update the ThemeToggleProps
      type and the component signature (e.g., ThemeToggleProps,
      ThemeToggle/ModeToggle) to reflect the removed prop and run type checks to
      ensure no callers pass getTheme anymore.
      🧹 Nitpick comments (1)
      src/components/mode-toggle.tsx (1)

      45-55: Consider harmonizing icon sizing/spacing in the radio items.

      The trigger uses a fixed icon size, while the menu items currently render icons without sizing or spacing classes. Consistent sizing avoids visual jumps.

      ♻️ Suggested tweak
      -          <DropdownMenuRadioItem value="light">
      -            <SunIcon />
      +          <DropdownMenuRadioItem value="light">
      +            <SunIcon className="mr-2 h-4 w-4" />
                   Light
                 </DropdownMenuRadioItem>
      -          <DropdownMenuRadioItem value="dark">
      -            <MoonIcon />
      +          <DropdownMenuRadioItem value="dark">
      +            <MoonIcon className="mr-2 h-4 w-4" />
                   Dark
                 </DropdownMenuRadioItem>
      -          <DropdownMenuRadioItem value="system">
      -            <MonitorIcon />
      +          <DropdownMenuRadioItem value="system">
      +            <MonitorIcon className="mr-2 h-4 w-4" />
                   System
                 </DropdownMenuRadioItem>
      src/components/mode-toggle.tsx lines 12 to 14
      @@ -1,12 +1,14 @@
      11 import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
      2-import { useTheme } from "@/components/theme-provider";
      32 import { Button } from "@/components/ui/button";
      43 import {
      54 DropdownMenu,
      65 DropdownMenuContent,
      7- DropdownMenuItem,
      6+ DropdownMenuRadioGroup,
      7+ DropdownMenuRadioItem,
      88 DropdownMenuTrigger,
      99 } from "@/components/ui/dropdown-menu";
      10+import { type UserTheme, useTheme } from "./theme-provider";
      1011
      11-export function ModeToggle() {
      12- const { setTheme } = useTheme();
      12+type ThemeToggleProps = {
      13+ getTheme?: () => UserTheme;
      14+};

      ⚠️ Potential issue | 🟡 Minor

      🧩 Analysis chain

      🏁 Script executed:

      # First, let's examine the mode-toggle.tsx file to understand the context
      cd src/components && wc -l mode-toggle.tsx

      Repository: fulopkovacs/trytanstackdb.com

      Length of output: 91


      🏁 Script executed:

      # Read the mode-toggle.tsx file to understand the implementation
      cat -n src/components/mode-toggle.tsx

      Repository: fulopkovacs/trytanstackdb.com

      Length of output: 2259


      🏁 Script executed:

      # Find all ModeToggle usages
      rg -n -C3 '<ModeToggle'

      Repository: fulopkovacs/trytanstackdb.com

      Length of output: 450


      🏁 Script executed:

      # Find getTheme prop assignments
      rg -n -C3 'getTheme\s*='

      Repository: fulopkovacs/trytanstackdb.com

      Length of output: 55


      🏁 Script executed:

      # Find UserTheme type definition in theme-provider
      rg -n "type UserTheme|interface UserTheme" src/components/

      Repository: fulopkovacs/trytanstackdb.com

      Length of output: 261


      🏁 Script executed:

      # Get more context around UserTheme definition
      cat -n src/components/theme-provider.tsx | head -50

      Repository: fulopkovacs/trytanstackdb.com

      Length of output: 2144


      Document or remove the unused getTheme prop, and clarify its contract.

      The optional getTheme parameter is never used in the codebase but could easily be misused if provided. If a caller passes a function returning a resolved theme (light/dark) instead of the user's selection (which could be "system"), the icon and radio group will display incorrect state. Either add inline documentation specifying that getTheme() must return the user-selected theme including "system", or remove the parameter if it's not needed.

      🤖 Prompt for AI Agents
      In `@src/components/mode-toggle.tsx` around lines 12 - 14, Remove the unused
      getTheme prop from ThemeToggleProps and the component's props list: delete the
      getTheme?: () => UserTheme declaration and any references to getTheme in the
      mode-toggle component so the component relies solely on the
      internal/user-selection state; update the ThemeToggleProps type and the
      component signature (e.g., ThemeToggleProps, ThemeToggle/ModeToggle) to reflect
      the removed prop and run type checks to ensure no callers pass getTheme anymore.

Sign in to join this conversation.