Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

4.8 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

import { BrushCleaningIcon } from "@/lib/brush-cleaning-icon";
import {
  CloudIcon,
  CursorInfo02Icon,
  DragDropVerticalIcon,
  HelpCircleIcon,
  Logout05Icon,
  Moon02Icon,
  PowerIcon,
  UserCircleIcon,
  ApiIcon,
} from "@hugeicons/core-free-icons";
import { ChipIcon, MessageCircleIcon, Settings01Icon } from "@/lib/hugeicons-derived";
import { HugeiconsIcon } from "@hugeicons/react";
import { Reorder, useDragControls } from "motion/react";
import { Switch } from "@/components/ui/switch";
import { useT } from "@/i18n";
import type { TranslationKey } from "@/i18n";
import type { IconSvgElement } from "@hugeicons/react";
import type { SidebarMenuItemPref } from "../stores/appearance-custom-store";
import { useAppearanceCustomStore } from "../stores/appearance-custom-store";

const ITEM_META: Record<
  SidebarMenuItemPref["id"],
  { icon: IconSvgElement; labelKey: TranslationKey }
> = {
  api: { icon: ApiIcon, labelKey: "settings.tabs.apiKeys" },
  darkMode: { icon: Moon02Icon, labelKey: "settings.appearance.sidebarMenu.darkModeToggle" },
  guidedTour: { icon: CursorInfo02Icon, labelKey: "shell.navigation.guidedTour" },
  profile: { icon: UserCircleIcon, labelKey: "settings.tabs.profile" },
  appearance: { icon: BrushCleaningIcon, labelKey: "settings.tabs.appearance" },
  resources: { icon: ChipIcon, labelKey: "settings.tabs.resources" },
  chat: { icon: MessageCircleIcon, labelKey: "settings.tabs.chat" },
  connections: { icon: CloudIcon, labelKey: "settings.tabs.connections" },
};

function FixedRow({ icon, label }: { icon: IconSvgElement; label: string }) {
  return (
    <div className="flex h-9 items-center gap-2.5 rounded-md px-2 text-muted-foreground/70">
      {/* Spacer where the drag handle sits on movable rows. */}
      <span className="size-4" aria-hidden="true" />
      <HugeiconsIcon icon={icon} strokeWidth={1.75} className="size-4" />
      <span className="text-ui-13">{label}</span>
    </div>
  );
}

function MovableRow({ item }: { item: SidebarMenuItemPref }) {
  const t = useT();
  const controls = useDragControls();
  const patch = useAppearanceCustomStore((s) => s.patch);
  const sidebarMenu = useAppearanceCustomStore(
    (s) => s.customization.sidebarMenu,
  );
  const meta = ITEM_META[item.id];
  return (
    <Reorder.Item
      value={item.id}
      dragListener={false}
      dragControls={controls}
      layout="position"
      whileDrag={{
        backgroundColor: "var(--popover)",
        boxShadow: "0 4px 16px rgb(0 0 0 / 0.18)",
        zIndex: 10,
      }}
      className="relative flex h-9 items-center gap-2.5 rounded-md px-2"
    >
      <button
        type="button"
        aria-label={t("settings.appearance.sidebarMenu.dragToReorder")}
        onPointerDown={(e) => {
          e.preventDefault();
          controls.start(e);
        }}
        className="flex size-4 shrink-0 cursor-grab touch-none items-center justify-center text-muted-foreground active:cursor-grabbing"
      >
        <HugeiconsIcon
          icon={DragDropVerticalIcon}
          strokeWidth={1.75}
          className="size-4"
        />
      </button>
      <HugeiconsIcon
        icon={meta.icon}
        strokeWidth={1.75}
        className="size-4 text-foreground/80"
      />
      <span className="text-ui-13 text-foreground">{t(meta.labelKey)}</span>
      <Switch
        className="ml-auto"
        checked={item.visible}
        onCheckedChange={(visible) =>
          patch({
            sidebarMenu: sidebarMenu.map((entry) =>
              entry.id === item.id ? { ...entry, visible } : entry,
            ),
          })
        }
      />
    </Reorder.Item>
  );
}

export function SidebarMenuCustomizer() {
  const t = useT();
  const sidebarMenu = useAppearanceCustomStore(
    (s) => s.customization.sidebarMenu,
  );
  const patch = useAppearanceCustomStore((s) => s.patch);
  return (
    <div className="flex flex-col rounded-lg border border-border/70 p-1">
      <FixedRow icon={Settings01Icon} label={t("shell.navigation.settings")} />
      <Reorder.Group
        axis="y"
        values={sidebarMenu.map((item) => item.id)}
        onReorder={(ids: SidebarMenuItemPref["id"][]) =>
          patch({
            sidebarMenu: ids.flatMap(
              (id) => sidebarMenu.find((entry) => entry.id === id) ?? [],
            ),
          })
        }
        className="flex flex-col"
      >
        {sidebarMenu.map((item) => (
          <MovableRow key={item.id} item={item} />
        ))}
      </Reorder.Group>
      <div className="mx-2 my-1 border-t border-border/70" />
      <FixedRow icon={HelpCircleIcon} label={t("common.help")} />
      <FixedRow icon={Logout05Icon} label={t("shell.navigation.logOut")} />
      <FixedRow icon={PowerIcon} label={t("common.shutdown")} />
    </div>
  );
}