Files
nanobot/webui/src/components/ui/select.tsx
T
chengyongru 9261e731ce feat(webui): improve model and provider settings UX (#6145)
* feat(webui): improve model and provider settings UX

* refactor(webui): organize provider forms and model picker interactions

* fix(webui): separate OAuth credentials from provider configuration

* fix(webui): stabilize shared combobox navigation

* refactor(config): store provider connections as sparse entries

* fix(webui): preserve provider validation and isolate catalog tests

* refactor(config): manage explicit provider connections

* refactor(webui): decouple settings UX from provider removal

* fix(webui): select current combobox options during rapid input

* feat(webui): refine model preset and provider management

* style(webui): refine preset footer actions

* fix(webui): align model settings with responsive layout rules

* refactor(webui): finalize preset dialogs and simplify provider state

* fix(webui): keep fallback heading stable while sorting presets

Animate card dimensions without changing layout height and keep the section heading outside sortable cards. Remove proxy normalization from this PR.

* docs: update WebUI model and provider setup instructions

* docs: start model setup from new preset

* docs: remove duplicate WebUI model setup instructions
2026-10-11 04:30:43 +08:00

52 lines
2.9 KiB
TypeScript

import * as React from "react";
import * as SelectPrimitive from "@radix-ui/react-select";
import { Check, ChevronDown, ChevronUp } from "lucide-react";
import { floatingSurfaceElevationClassName, floatingItemClassName } from "@/components/ui/floating-surface";
import { useFloatingPortal } from "@/components/ui/floating-portal";
import { cn } from "@/lib/utils";
import { ControlChevron } from "@/components/ui/control-chevron";
export const Select = SelectPrimitive.Root;
export const SelectValue = SelectPrimitive.Value;
export const SelectSeparator = SelectPrimitive.Separator;
export const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Trigger ref={ref} {...props}
className={cn("control-layout justify-between rounded-control border-input bg-background text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 [&>span:first-child]:truncate", className)}>
{children}
<SelectPrimitive.Icon><ControlChevron /></SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
SelectTrigger.displayName = "SelectTrigger";
export function SelectContent({ children, ...props }: Pick<
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>,
"children" | "onPointerUpCapture" | "onPointerDownOutside" | "onKeyDownCapture" | "onEscapeKeyDown" | "onCloseAutoFocus"
>) {
const container = useFloatingPortal();
return (
<SelectPrimitive.Portal container={container ?? undefined}>
<SelectPrimitive.Content {...props} position="item-aligned" className={cn("z-50 max-h-[min(24rem,calc(100dvh-2rem))] min-w-[10rem] overflow-hidden rounded-control border border-transparent", floatingSurfaceElevationClassName)}>
<SelectPrimitive.ScrollUpButton className="flex h-6 items-center justify-center"><ChevronUp className="h-3.5 w-3.5" /></SelectPrimitive.ScrollUpButton>
<SelectPrimitive.Viewport className="p-1">
{children}
</SelectPrimitive.Viewport>
<SelectPrimitive.ScrollDownButton className="flex h-6 items-center justify-center"><ChevronDown className="h-3.5 w-3.5" /></SelectPrimitive.ScrollDownButton>
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
);
}
export function SelectItem({ children, className, ...props }: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>) {
return (
<SelectPrimitive.Item {...props} className={cn(floatingItemClassName, "h-9 py-0 pl-2 pr-8 data-[state=checked]:bg-muted data-[highlighted]:bg-muted data-[disabled]:opacity-50", className)}>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
<SelectPrimitive.ItemIndicator className="absolute right-2 flex items-center"><Check className="h-3.5 w-3.5" aria-hidden /></SelectPrimitive.ItemIndicator>
</SelectPrimitive.Item>
);
}