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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
// 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 { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
import * as React from "react";
import { MenuTickIcon } from "@/lib/tick-icon";
import { MenuChevronRightIcon } from "@/lib/chevron-icons";
import { useIsMobile } from "@/hooks/use-mobile";
import { snapRowInsets, useSnappedPaddingRef } from "@/lib/snap-padding";
import { useWindowChromeCollisionPadding } from "@/lib/window-chrome";
import { useDropdownGlow } from "@/components/ui/dropdown-glow";
import { cn } from "@/lib/utils";
import { HugeiconsIcon } from "@hugeicons/react";
function DropdownMenu({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
}
function DropdownMenuPortal({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
return (
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
);
}
function DropdownMenuTrigger({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
return (
<DropdownMenuPrimitive.Trigger
data-slot="dropdown-menu-trigger"
{...props}
/>
);
}
function DropdownMenuContent({
className,
align = "start",
sideOffset = 0,
collisionPadding,
children,
ref,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
const snappedRef = useSnappedPaddingRef(ref);
return (
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Content
ref={snappedRef}
data-slot="dropdown-menu-content"
data-dropdown-glow={useDropdownGlow()}
sideOffset={sideOffset}
collisionPadding={useWindowChromeCollisionPadding(collisionPadding)}
align={align}
className={cn(
// Whole-pixel width (Firefox offsets hover pills otherwise). The 3px nudge must be margin, not
// translate: a transform here would clip every position:fixed submenu.
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 bg-popover text-popover-foreground min-w-48 max-w-[calc(100vw-32px)] rounded-lg p-1 duration-100 z-50 max-h-(--radix-dropdown-menu-content-available-height) w-[round(calc(var(--radix-dropdown-menu-trigger-width)_+_6px*var(--ui-space-scale,1)),1px)] data-[align=start]:-ml-[calc(3px*var(--ui-space-scale,1))] data-[align=end]:ml-[calc(3px*var(--ui-space-scale,1))] origin-(--radix-dropdown-menu-content-transform-origin) flex flex-col overflow-hidden",
className,
)}
{...props}
>
{/* Scroll an inner viewport: a scrollbar on the rounded surface squares its corners in WebKit. */}
<div
data-slot="dropdown-menu-viewport"
className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto"
>
{children}
</div>
</DropdownMenuPrimitive.Content>
</DropdownMenuPrimitive.Portal>
);
}
function DropdownMenuGroup({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
return (
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
);
}
function DropdownMenuItem({
className,
inset,
variant = "default",
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean;
variant?: "default" | "destructive";
}) {
return (
<DropdownMenuPrimitive.Item
data-slot="dropdown-menu-item"
data-inset={inset}
data-variant={variant}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground gap-2.5 rounded-md px-3 min-h-menu-row py-2 text-sm [&_svg:not([class*='size-'])]:size-4 group/dropdown-menu-item relative flex cursor-pointer items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0",
className,
)}
{...props}
/>
);
}
function DropdownMenuCheckboxItem({
className,
children,
checked,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
return (
<DropdownMenuPrimitive.CheckboxItem
data-slot="dropdown-menu-checkbox-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-2.5 rounded-md min-h-menu-row py-2 pr-9 pl-3 text-sm [&_svg:not([class*='size-'])]:size-4 relative flex cursor-pointer items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
className,
)}
checked={checked}
{...props}
>
<span
className="pointer-events-none absolute right-3 flex items-center justify-center"
data-slot="dropdown-menu-checkbox-item-indicator"
>
<DropdownMenuPrimitive.ItemIndicator>
<HugeiconsIcon icon={MenuTickIcon} strokeWidth={2} />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.CheckboxItem>
);
}
function DropdownMenuRadioGroup({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
return (
<DropdownMenuPrimitive.RadioGroup
data-slot="dropdown-menu-radio-group"
{...props}
/>
);
}
function DropdownMenuRadioItem({
className,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
return (
<DropdownMenuPrimitive.RadioItem
data-slot="dropdown-menu-radio-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-2.5 rounded-md min-h-menu-row py-2 pr-9 pl-3 text-sm [&_svg:not([class*='size-'])]:size-4 relative flex cursor-pointer items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
className,
)}
{...props}
>
<span
className="pointer-events-none absolute right-3 flex items-center justify-center"
data-slot="dropdown-menu-radio-item-indicator"
>
<DropdownMenuPrimitive.ItemIndicator>
<HugeiconsIcon icon={MenuTickIcon} strokeWidth={2} />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.RadioItem>
);
}
function DropdownMenuLabel({
className,
inset,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
inset?: boolean;
}) {
return (
<DropdownMenuPrimitive.Label
data-slot="dropdown-menu-label"
data-inset={inset}
className={cn(
"text-muted-foreground px-3 py-2.5 text-xs data-[inset]:pl-8",
className,
)}
{...props}
/>
);
}
function DropdownMenuSeparator({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
return (
<DropdownMenuPrimitive.Separator
data-slot="dropdown-menu-separator"
className={cn("bg-border/50 mx-1 my-1 h-px", className)}
{...props}
/>
);
}
function DropdownMenuShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
data-slot="dropdown-menu-shortcut"
className={cn(
"text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground ml-auto -mr-[0.1em] text-xs tracking-widest",
className,
)}
{...props}
/>
);
}
function assignRef<T>(ref: React.Ref<T> | undefined, value: T | null) {
if (typeof ref === "function") {
ref(value);
} else if (ref) {
ref.current = value;
}
}
function DropdownMenuSub({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
}
function DropdownMenuSubTrigger({
className,
inset,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean;
}) {
return (
<DropdownMenuPrimitive.SubTrigger
data-slot="dropdown-menu-sub-trigger"
data-inset={inset}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground gap-2 rounded-md px-3 min-h-menu-row py-2 text-sm [&_svg:not([class*='size-'])]:size-4 flex cursor-pointer items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0",
className,
)}
{...props}
>
{children}
<HugeiconsIcon
icon={MenuChevronRightIcon}
strokeWidth={1.5}
className="ml-auto size-[calc(12px*var(--ui-space-scale,1))]"
/>
</DropdownMenuPrimitive.SubTrigger>
);
}
function DropdownMenuSubContent({
className,
sideOffset,
alignOffset,
alignEnd,
collisionPadding,
style,
children,
ref,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent> & {
/** Grow upward so the last item lines up with the trigger. */
alignEnd?: boolean;
}) {
const isMobile = useIsMobile();
const [contentWidth, setContentWidth] = React.useState(0);
const [endShift, setEndShift] = React.useState<number | null>(null);
const resizeObserverRef = React.useRef<ResizeObserver | null>(null);
const composedRef = React.useCallback(
(
element: React.ComponentRef<
typeof DropdownMenuPrimitive.SubContent
> | null,
) => {
resizeObserverRef.current?.disconnect();
resizeObserverRef.current = null;
assignRef(ref, element);
if (!element) return;
snapRowInsets(element);
const updateContentSize = () => {
setContentWidth(element.offsetWidth);
const anchorHeight = Number.parseFloat(
getComputedStyle(element).getPropertyValue(
"--radix-popper-anchor-height",
),
);
if (Number.isFinite(anchorHeight)) {
setEndShift(anchorHeight - element.offsetHeight);
}
};
updateContentSize();
if (typeof ResizeObserver !== "undefined") {
resizeObserverRef.current = new ResizeObserver(updateContentSize);
resizeObserverRef.current.observe(element);
}
},
[ref],
);
React.useEffect(
() => () => {
resizeObserverRef.current?.disconnect();
},
[],
);
const compactSideOffset =
isMobile && contentWidth > 0 ? -contentWidth : sideOffset;
const endAligned = alignEnd && !isMobile;
// With alignEnd, alignOffset applies from the bottom edge.
const resolvedAlignOffset =
endAligned && endShift !== null ? endShift - (alignOffset ?? 0) : alignOffset;
// Transparent, not hidden, while measuring: hidden content misses Radix's keyboard autofocus.
const measuring = endAligned && endShift === null;
return (
// Portaled: inline, a transform in the parent menu's scroll container clips the submenu.
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.SubContent
ref={composedRef}
data-slot="dropdown-menu-sub-content"
data-dropdown-glow={useDropdownGlow()}
sideOffset={compactSideOffset}
alignOffset={resolvedAlignOffset}
collisionPadding={useWindowChromeCollisionPadding(collisionPadding)}
style={{
...style,
visibility:
isMobile && contentWidth === 0 ? "hidden" : style?.visibility,
}}
className={cn(
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 bg-popover text-popover-foreground min-w-36 max-w-[calc(100vw-32px)] max-h-(--radix-dropdown-menu-content-available-height) rounded-lg p-1 duration-100 z-50 origin-(--radix-dropdown-menu-content-transform-origin) flex flex-col overflow-hidden",
// !important so the fade-in animation cannot reveal it early.
measuring && "opacity-0!",
className,
)}
{...props}
>
{/* Capped and scrolled like DropdownMenuContent, so a long list stays reachable. */}
<div
data-slot="dropdown-menu-viewport"
className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto"
>
{children}
</div>
</DropdownMenuPrimitive.SubContent>
</DropdownMenuPrimitive.Portal>
);
}
export {
DropdownMenu,
DropdownMenuPortal,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
};