Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(desktop/overlay): replace native select with @base-ui/react primitives (#15266)

Innei347e2eec0c2a
diff --git a/apps/desktop/src/overlay/ChatPanel.tsx b/apps/desktop/src/overlay/ChatPanel.tsx
index d2775f8ed8e..55a718ce7e1 100644
--- a/apps/desktop/src/overlay/ChatPanel.tsx
+++ b/apps/desktop/src/overlay/ChatPanel.tsx
@@ -1,3 +1,4 @@
+import { Select } from '@base-ui/react/select';
import type {
OverlayCaptureUploadStatus,
ScreenCaptureAgentOption,
@@ -5,9 +6,8 @@ import type {
ScreenCaptureOverlayTheme,
} from '@lobechat/electron-client-ipc';
import { ModelIcon } from '@lobehub/icons';
-import { AlertCircleIcon, ChevronDownIcon, Loader2Icon, XIcon } from 'lucide-react';
+import { AlertCircleIcon, CheckIcon, ChevronDownIcon, Loader2Icon, XIcon } from 'lucide-react';
import type {
- ChangeEvent as ReactChangeEvent,
CSSProperties,
KeyboardEvent as ReactKeyboardEvent,
MouseEvent as ReactMouseEvent,
@@ -248,7 +248,7 @@ const ChatPanel = memo<ChatPanelProps>(
};
}, [activeSelection, dock]);
- const themeStyle = useMemo<CSSProperties | undefined>(() => {
+ const themeVars = useMemo<Record<string, string> | undefined>(() => {
if (!theme) return undefined;
return {
@@ -268,9 +268,24 @@ const ChatPanel = memo<ChatPanelProps>(
'--lobe-overlay-text-quaternary': theme.colorTextQuaternary,
'--lobe-overlay-text-secondary': theme.colorTextSecondary,
'--lobe-overlay-text-tertiary': theme.colorTextTertiary,
- } as CSSProperties;
+ };
}, [theme]);
+ const themeStyle = themeVars as CSSProperties | undefined;
+
+ useEffect(() => {
+ if (!themeVars) return;
+ const root = document.documentElement;
+ for (const [key, value] of Object.entries(themeVars)) {
+ root.style.setProperty(key, value);
+ }
+ return () => {
+ for (const key of Object.keys(themeVars)) {
+ root.style.removeProperty(key);
+ }
+ };
+ }, [themeVars]);
+
useLayoutEffect(() => {
if (!hidden && textareaRef.current) {
textareaRef.current.focus();
@@ -332,12 +347,12 @@ const ChatPanel = memo<ChatPanelProps>(
const canSend = selected && prompt.trim().length > 0 && allUploadsReady;
- const handleAgentChange = useCallback((e: ReactChangeEvent<HTMLSelectElement>) => {
- setAgentId(e.target.value || undefined);
+ const handleAgentChange = useCallback((value: string) => {
+ setAgentId(value || undefined);
}, []);
- const handleModelChange = useCallback((e: ReactChangeEvent<HTMLSelectElement>) => {
- setModelId(e.target.value || undefined);
+ const handleModelChange = useCallback((value: string) => {
+ setModelId(value || undefined);
}, []);
const hasAgents = !!agents && agents.length > 0;
@@ -467,71 +482,95 @@ const ChatPanel = memo<ChatPanelProps>(
<div className={styles.actionBar}>
<div className={styles.actionBarLeft}>
- <label
- aria-label={OVERLAY_COPY.agentSelectLabel}
- className={cn(styles.selectChip, !hasAgents && styles.selectChipDisabled)}
+ <Select.Root
+ disabled={!hasAgents}
+ value={agentId ?? ''}
+ onValueChange={handleAgentChange}
>
- <OverlayAvatar
- avatar={currentAgent?.avatar}
- background={currentAgent?.backgroundColor}
- size={18}
- title={currentAgent?.title}
- />
- <span className={styles.chipLabel}>
- {currentAgent?.title ?? OVERLAY_COPY.agentSelectPlaceholder}
- </span>
- <ChevronDownIcon className={styles.chevron} size={12} strokeWidth={2} />
- <select
+ <Select.Trigger
aria-label={OVERLAY_COPY.agentSelectLabel}
- className={styles.nativeSelect}
- disabled={!hasAgents}
- value={agentId ?? ''}
- onChange={handleAgentChange}
+ className={cn(styles.selectChip, !hasAgents && styles.selectChipDisabled)}
>
- {!hasAgents && <option value="">{OVERLAY_COPY.agentSelectPlaceholder}</option>}
- {agents?.map((item) => (
- <option key={item.id} value={item.id}>
- {item.avatar && typeof item.avatar === 'string' && item.avatar.length <= 4
- ? `${item.avatar} ${item.title}`
- : item.title}
- </option>
- ))}
- </select>
- </label>
+ <OverlayAvatar
+ avatar={currentAgent?.avatar}
+ background={currentAgent?.backgroundColor}
+ size={18}
+ title={currentAgent?.title}
+ />
+ <Select.Value className={styles.chipLabel}>
+ {currentAgent?.title ?? OVERLAY_COPY.agentSelectPlaceholder}
+ </Select.Value>
+ <ChevronDownIcon className={styles.chevron} size={12} strokeWidth={2} />
+ </Select.Trigger>
+ <Select.Portal>
+ <Select.Positioner
+ align="start"
+ className={styles.popupPositioner}
+ sideOffset={6}
+ >
+ <Select.Popup className={styles.popup}>
+ {agents?.map((item) => (
+ <Select.Item className={styles.popupItem} key={item.id} value={item.id}>
+ <Select.ItemIndicator className={styles.popupItemIndicator}>
+ <CheckIcon size={12} strokeWidth={2.4} />
+ </Select.ItemIndicator>
+ <Select.ItemText>
+ {item.avatar &&
+ typeof item.avatar === 'string' &&
+ item.avatar.length <= 4
+ ? `${item.avatar} ${item.title}`
+ : item.title}
+ </Select.ItemText>
+ </Select.Item>
+ ))}
+ </Select.Popup>
+ </Select.Positioner>
+ </Select.Portal>
+ </Select.Root>
{showModelSelector && (
- <label
- aria-label={OVERLAY_COPY.modelSelectLabel}
- className={cn(styles.selectChip, !hasModels && styles.selectChipDisabled)}
+ <Select.Root
+ disabled={!hasModels}
+ value={modelId ?? ''}
+ onValueChange={handleModelChange}
>
- {currentModel ? (
- <span className={styles.modelIconBox}>
- <ModelIcon model={currentModel.id} size={16} />
- </span>
- ) : (
- <span className={styles.modelIconBoxFallback} />
- )}
- <span className={styles.chipLabel}>
- {currentModel?.displayName ??
- currentModel?.id ??
- OVERLAY_COPY.modelSelectPlaceholder}
- </span>
- <ChevronDownIcon className={styles.chevron} size={12} strokeWidth={2} />
- <select
+ <Select.Trigger
aria-label={OVERLAY_COPY.modelSelectLabel}
- className={styles.nativeSelect}
- disabled={!hasModels}
- value={modelId ?? ''}
- onChange={handleModelChange}
+ className={cn(styles.selectChip, !hasModels && styles.selectChipDisabled)}
>
- {!hasModels && <option value="">{OVERLAY_COPY.modelSelectPlaceholder}</option>}
- {models?.map((item) => (
- <option key={item.id} value={item.id}>
- {item.displayName ?? item.id}
- </option>
- ))}
- </select>
- </label>
+ {currentModel ? (
+ <span className={styles.modelIconBox}>
+ <ModelIcon model={currentModel.id} size={16} />
+ </span>
+ ) : (
+ <span className={styles.modelIconBoxFallback} />
+ )}
+ <Select.Value className={styles.chipLabel}>
+ {currentModel?.displayName ??
+ currentModel?.id ??
+ OVERLAY_COPY.modelSelectPlaceholder}
+ </Select.Value>
+ <ChevronDownIcon className={styles.chevron} size={12} strokeWidth={2} />
+ </Select.Trigger>
+ <Select.Portal>
+ <Select.Positioner
+ align="start"
+ className={styles.popupPositioner}
+ sideOffset={6}
+ >
+ <Select.Popup className={styles.popup}>
+ {models?.map((item) => (
+ <Select.Item className={styles.popupItem} key={item.id} value={item.id}>
+ <Select.ItemIndicator className={styles.popupItemIndicator}>
+ <CheckIcon size={12} strokeWidth={2.4} />
+ </Select.ItemIndicator>
+ <Select.ItemText>{item.displayName ?? item.id}</Select.ItemText>
+ </Select.Item>
+ ))}
+ </Select.Popup>
+ </Select.Positioner>
+ </Select.Portal>
+ </Select.Root>
)}
</div>
diff --git a/apps/desktop/src/overlay/chatPanel.css.ts b/apps/desktop/src/overlay/chatPanel.css.ts
index 4d03363048e..6ed77908cf9 100644
--- a/apps/desktop/src/overlay/chatPanel.css.ts
+++ b/apps/desktop/src/overlay/chatPanel.css.ts
@@ -534,3 +534,57 @@ globalStyle(`.${multiSelectionRail}::-webkit-scrollbar`, {
globalStyle(`.${textarea}::selection`, {
background: 'color-mix(in srgb, var(--lobe-overlay-primary) 22%, transparent)',
});
+
+export const popupPositioner = style({
+ outline: 'none',
+ zIndex: 114_514,
+});
+
+export const popup = style({
+ background: v(vars.colorBgElevated),
+ border: `1px solid ${v(vars.colorBorderSecondary)}`,
+ borderRadius: 10,
+ boxShadow: v(vars.panelShadow),
+ color: v(vars.colorText),
+ fontSize: 12,
+ maxHeight: 240,
+ minWidth: 180,
+ outline: 'none',
+ overflowY: 'auto',
+ padding: 4,
+});
+
+export const popupItem = style({
+ alignItems: 'center',
+ borderRadius: 6,
+ color: v(vars.colorText),
+ cursor: 'pointer',
+ display: 'flex',
+ gap: 6,
+ outline: 'none',
+ padding: '6px 8px 6px 24px',
+ position: 'relative',
+ userSelect: 'none',
+ selectors: {
+ '&[data-highlighted]': {
+ background: v(vars.colorFillTertiary),
+ },
+ '&[data-disabled]': {
+ cursor: 'not-allowed',
+ opacity: 0.45,
+ },
+ },
+});
+
+export const popupItemIndicator = style({
+ alignItems: 'center',
+ color: v(vars.colorPrimary),
+ display: 'inline-flex',
+ height: 12,
+ justifyContent: 'center',
+ left: 6,
+ position: 'absolute',
+ top: '50%',
+ transform: 'translateY(-50%)',
+ width: 12,
+});