Home / Function/ ThemesSwitcher() — ui Function Reference

ThemesSwitcher() — ui Function Reference

Architecture documentation for the ThemesSwitcher() function in themes-selector.tsx from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  bba7966e_222b_d7ff_6790_97e9fea675b4["ThemesSwitcher()"]
  608507ba_d93d_7212_9b99_5f8639585ddc["themes-selector.tsx"]
  bba7966e_222b_d7ff_6790_97e9fea675b4 -->|defined in| 608507ba_d93d_7212_9b99_5f8639585ddc
  style bba7966e_222b_d7ff_6790_97e9fea675b4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

deprecated/www/components/themes-selector.tsx lines 21–124

export function ThemesSwitcher({
  themes = THEMES,
  className,
}: React.ComponentProps<"div"> & { themes?: Theme[] }) {
  const { theme: mode } = useTheme()
  const [mounted, setMounted] = React.useState(false)
  const { themesConfig, setThemesConfig } = useThemesConfig()
  const activeTheme = themesConfig.activeTheme
  const isDesktop = useMediaQuery("(min-width: 1024px)")

  React.useEffect(() => {
    setMounted(true)
  }, [])

  if (!mounted) {
    return (
      <div
        className={cn(
          "flex items-center justify-center gap-0.5 py-4 lg:flex-col lg:justify-start lg:gap-1",
          className
        )}
      >
        {themes.map((theme) => (
          <div
            key={theme.id}
            className="flex h-10 w-10 items-center justify-center rounded-lg border-2 border-transparent"
          >
            <Skeleton className="h-6 w-6 rounded-sm" />
          </div>
        ))}
      </div>
    )
  }

  return (
    <ToggleGroup
      type="single"
      value={activeTheme.name}
      onValueChange={(value) => {
        const theme = themes.find((theme) => theme.name === value)
        if (!theme) {
          return
        }

        setThemesConfig({ ...themesConfig, activeTheme: theme })
      }}
      className={cn(
        "flex items-center justify-center gap-0.5 py-4 lg:flex-col lg:justify-start lg:gap-1",
        className
      )}
    >
      {themes.map((theme) => {
        const isActive = theme.name === activeTheme.name
        const isDarkTheme = ["Midnight"].includes(theme.name)
        const cssVars =
          mounted && mode === "dark" ? theme.cssVars.dark : theme.cssVars.light

        return (
          <Tooltip key={theme.name}>
            <TooltipTrigger asChild>
              <ToggleGroupItem
                value={theme.name}
                className={cn(
                  "group flex h-10 w-10 shrink-0 items-center justify-center rounded-lg border-2 border-transparent p-0 hover:bg-transparent focus-visible:bg-transparent aria-checked:border-[--color-1]",
                  mounted && isDarkTheme && mode !== "dark" ? "invert-[1]" : ""
                )}
                style={
                  {
                    ...cssVars,
                    "--color-1": "hsl(var(--chart-1))",
                    "--color-2": "hsl(var(--chart-2))",
                    "--color-3": "hsl(var(--chart-3))",
                    "--color-4": "hsl(var(--chart-4))",
                  } as React.CSSProperties
                }
              >
                <div className="h-6 w-6 overflow-hidden rounded-sm">
                  <div
                    className={cn(
                      "grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out group-hover:rotate-45",
                      isActive ? "rotate-45 group-hover:rotate-0" : "rotate-0"

Subdomains

Frequently Asked Questions

What does ThemesSwitcher() do?
ThemesSwitcher() is a function in the ui codebase, defined in deprecated/www/components/themes-selector.tsx.
Where is ThemesSwitcher() defined?
ThemesSwitcher() is defined in deprecated/www/components/themes-selector.tsx at line 21.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free