ui icon indicating copy to clipboard operation
ui copied to clipboard

Icon does not change to reflect theme setting

Open kariemoorman opened this issue 2 years ago • 4 comments

When transitioning from light to dark mode the associated icon stays fixed as sun, instead of switching to moon icon (to reflect the current theme setting).

kariemoorman avatar Jan 26 '23 23:01 kariemoorman

https://github.com/shadcn/ui/pull/4

Zebeqo avatar Jan 27 '23 03:01 Zebeqo

Hello @kariemoorman. I would like to work on this.

kuldeepswnkumar avatar Jan 29 '23 07:01 kuldeepswnkumar

This is my implementation in tauri-ui-boilerplate.

export function ThemeToggle() {
  const { setTheme, theme, systemTheme } = useTheme()
  const [currentTheme, setCurrentTheme] = useState("")

  useEffect(() => {
    setCurrentTheme(
      theme === "system"
        ? systemTheme === "light"
          ? "light"
          : "dark"
        : theme === "light"
        ? "light"
        : "dark"
    )
  }, [theme, systemTheme])

  const ThemeIcon = Icons[currentTheme === "light" ? "sun" : "moon"]

  return (
    <DropdownMenu>
      <DropdownMenuTrigger asChild>
        <Button variant="ghost" size="sm">
          <ThemeIcon className="hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-100" />
...

https://github.com/agmmnn/tauri-ui-boilerplate/blob/master/src/components/theme-toggle.tsx

agmmnn avatar Feb 02 '23 16:02 agmmnn

I found a solution to this. Its due to hydration mismatch for. Refer to this doc https://github.com/pacocoursey/next-themes#avoid-hydration-mismatch

ahosny752 avatar Apr 25 '24 03:04 ahosny752

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jul 10 '24 23:07 shadcn