feat(webui): add a compact composer workspace toolbar (#6256)

* feat(webui): add a compact composer workspace toolbar

* refactor(webui): simplify composer workspace access control

* feat(webui): add a draggable workspace access capsule

* refactor(webui): simplify composer permission controls

* fix(webui): align mobile workspace permissions and stabilize CI test
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-23 21:09:21 +08:00
1 parent 0254bf1217
commit cf0a0276a7
34 files changed
+528 -267

No files matched your search

+2 -2
View File
@@ -77,11 +77,11 @@ export function StartupSkeleton({
<div className="startup-composer-surface">
<div className="startup-composer-input"><Block /></div>
<div className="startup-composer-footer">
<div className="startup-composer-primary"><Block className="startup-attach" /><Block className="startup-workspace" /><Block className="startup-access" /><Block className="startup-mobile-model" /></div>
<div className="startup-composer-primary"><Block className="startup-attach" /><Block className="startup-access" /></div>
<div className="startup-composer-actions"><Block className="startup-model" /><Block className="startup-send" /></div>
</div>
<div className="startup-workspace-row"><Block /><Block /></div>
</div>
<div className="startup-workspace-row"><Block className="startup-workspace" /></div>
</div>
<div className="startup-chat-spacer" />
</div>
+1 -1
View File
@@ -37,7 +37,7 @@ export const SendIcon = productIcon("send", <><path d="m4 5 17 7-17 7 3-7-3-7Z"
export const VoiceIcon = productIcon("voice", <><rect x="9" y="3" width="6" height="12" rx="3" /><path d="M6 11v1a6 6 0 0 0 12 0v-1M12 18v3m-3 0h6" /></>);
export const StopIcon = productIcon("stop", <rect x="5" y="5" width="14" height="14" rx="2.5" />);
export const RestrictedAccessIcon = productIcon("restricted-access", <><rect x="5" y="10" width="14" height="11" rx="2.5" /><path d="M8 10V7a4 4 0 0 1 8 0v3m-4 5v2" /></>);
export const FullAccessIcon = productIcon("full-access", <><rect x="5" y="10" width="14" height="11" rx="2.5" /><path d="M8 10V7a4 4 0 0 1 7.5-2M9 16h6m-2.5-2.5L15 16l-2.5 2.5" /></>);
export const FullAccessIcon = productIcon("full-access", <><rect x="5" y="10" width="14" height="11" rx="2.5" /><path d="M8 10V7a4 4 0 0 1 7.5-2m-3.5 10v2" /></>);
export const WorkspaceIcon = productIcon("workspace", <><path d="M3 7a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z" /><path d="M8 13h8m-8 4h5" /></>);
export const PromptNavigationIcon = productIcon("prompt-navigation", <><path d="M5 5v14m4-14h11M9 12h11M9 19h7" /><circle cx="5" cy="5" r="1.5" fill="currentColor" stroke="none" /><circle cx="5" cy="12" r="1.5" fill="currentColor" stroke="none" /><circle cx="5" cy="19" r="1.5" fill="currentColor" stroke="none" /></>);
export const TemporaryChatIcon = productIcon("temporary-chat", <><path d="M7 4h10a4 4 0 0 1 4 4v7a4 4 0 0 1-4 4H8l-5 3V8a4 4 0 0 1 4-4Z" strokeDasharray="3 3" /><path d="M8 10h8m-8 4h4" /></>);
+10 -8
View File
@@ -102,7 +102,7 @@ html.dark .startup-shell { --startup-fill: hsl(0 0% 72% / .2); --startup-surface
.startup-welcome { display: flex; min-height: 0; align-items: center; justify-content: center; }
.startup-welcome-line { display: flex; width: 100%; max-width: 704px; height: 36.72px; align-items: center; justify-content: center; }
.startup-welcome-line .startup-block { width: 60%; height: 24px; }
.startup-composer { container: startup-composer / inline-size; width: 100%; max-width: 928px; margin: 0 auto; }
.startup-composer { container: startup-composer / inline-size; width: 100%; max-width: 928px; margin: 0 auto; --composer-footer-inset: 0.75rem; --composer-action-size: 2rem; --composer-action-margin: 0px; }
.startup-composer-surface { overflow: hidden; border-radius: 28px; background: hsl(0 0% 96.1% / .8); }
html.dark .startup-composer-surface { background: hsl(0 0% 22%); }
.startup-composer-input { display: flex; align-items: start; height: 78px; padding: 27px 16px 8px; }
@@ -115,7 +115,11 @@ html.dark .startup-composer-surface { background: hsl(0 0% 22%); }
.startup-workspace { width: 112px; }
.startup-access { width: 88px; }
.startup-model { width: 88px; }
.startup-mobile-model, .startup-workspace-row { display: none; }
.startup-workspace-row { display: flex; align-items: center; height: 28px; margin-top: 4px; padding: 0 8px; padding-inline-start: calc(var(--composer-footer-inset) + var(--composer-action-margin) + (var(--composer-action-size) - 0.875rem) / 2 - 0.5rem); }
@media (pointer: coarse) {
.startup-composer { --composer-action-size: 2.75rem; }
.startup-workspace-row { height: 44px; }
}
.startup-chat-spacer { min-height: 0; }
@container startup-chat (width > 1152px) { .startup-chat-header { position: absolute; inset: 0 0 auto; height: 44px; } }
.startup-shell[data-existing-chat="true"] .startup-header-title { display: block; width: 96px; height: 12px; }
@@ -128,8 +132,10 @@ html.dark .startup-composer-surface { background: hsl(0 0% 22%); }
.startup-welcome { align-items: end; padding-bottom: 32px; }
.startup-welcome-line { height: 60px; }
.startup-welcome-line .startup-block { height: 36px; }
.startup-composer { --composer-footer-inset: 1rem; }
.startup-composer-input { padding-inline: 20px; }
.startup-composer-footer { padding-inline: 16px; }
.startup-workspace-row { padding-inline-end: 12px; }
.startup-page { max-width: 824px; padding: 32px 16px; }
.startup-title { height: 35px; }
.startup-toolbar { flex-direction: row; align-items: center; }
@@ -164,14 +170,10 @@ html.dark .startup-composer-surface { background: hsl(0 0% 22%); }
.startup-shell[data-startup-surface="apps"] .startup-catalog { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; }
}
@container startup-composer (max-width: 512px) {
.startup-workspace-row { --composer-footer-inset: 0.5rem; --composer-action-size: 2.25rem; --composer-action-margin: 0.25rem; }
.startup-composer-input { height: 52px; padding: 12px 16px 8px; }
.startup-composer-footer { gap: 4px; padding: 0 8px 8px; }
.startup-composer-primary, .startup-composer-actions { gap: 4px; height: 44px; }
.startup-attach, .startup-send { flex-basis: 36px; height: 36px; margin: 4px; }
.startup-workspace, .startup-access, .startup-model { display: none; }
.startup-mobile-model { display: block; width: 80px; }
.startup-workspace-row { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 6px 12px; background: hsl(0 0% 96.1% / .45); }
.startup-workspace-row .startup-block { width: 112px; }
.startup-workspace-row .startup-block + .startup-block { width: 88px; }
html.dark .startup-workspace-row { background: hsl(0 0% 100% / .045); }
.startup-access { flex: 0 1 88px; }
}
+31 -43
View File
@@ -82,7 +82,7 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip";
import {
WorkspaceAccessToggle,
WorkspaceAccessMenu,
WorkspaceProjectPicker,
} from "@/components/thread/WorkspaceControls";
import {
@@ -257,6 +257,7 @@ interface ThreadComposerProps {
workspaceDefaultScope?: WorkspaceScopePayload | null;
workspaceControls?: WorkspacesPayload["controls"] | null;
workspaceScopeDisabled?: boolean;
workspaceProjectLocked?: boolean;
workspaceError?: string | null;
onFavoriteWorkspaceProject?: (path: string, pinned: boolean) => Promise<ProjectDirectory[]>;
onResolveWorkspaceProject?: (path: string) => Promise<ProjectDirectory>;
@@ -1114,6 +1115,7 @@ export function ThreadComposer({
workspaceDefaultScope = null,
workspaceControls = null,
workspaceScopeDisabled = false,
workspaceProjectLocked = false,
workspaceError = null,
onLoadWorkspaceProjects,
onResolveWorkspaceProject,
@@ -1174,6 +1176,7 @@ export function ThreadComposer({
// Coarser than hasTouchPrimaryPointer on purpose: tablets with a physical
// keyboard still get the newline-on-Enter behavior.
const hasCoarsePointer = useMediaQuery("(pointer: coarse)");
const mobileWorkspaceControls = useMediaQuery("(max-width: 639px)");
const { readingTextSize } = useLocalPreferences();
const textareaRef = useRef<HTMLTextAreaElement>(null);
const mentionOverlayRef = useRef<HTMLDivElement>(null);
@@ -1213,7 +1216,7 @@ export function ThreadComposer({
const isHero = variant === "hero";
const voiceShortcutLabel = useMemo(getVoiceShortcutLabel, []);
const projectPickerAvailable =
isHero
!workspaceProjectLocked
&& !!workspaceDefaultScope
&& !!onWorkspaceScopeChange
&& !!onLoadWorkspaceProjects
@@ -1236,9 +1239,7 @@ export function ThreadComposer({
));
}, [activeTurnId, isStreaming, pendingQueueKey, setQueuedPrompt]);
const resolvedPlaceholder = isStreaming
? t("thread.composer.placeholderStreaming")
: placeholder ?? t("thread.composer.placeholderThread");
const resolvedPlaceholder = placeholder ?? t("thread.composer.placeholderThread");
const maxAttachments = ingressLimits?.attachments.max_count
?? MAX_ATTACHMENTS_PER_MESSAGE;
@@ -2526,17 +2527,15 @@ export function ThreadComposer({
return () => observer?.disconnect();
}, [compactControls, compactWhenIdle, modelLabel, voiceRecorder.isRecording, workspaceScope]);
const accessControl = workspaceScope && !workspaceControlsHidden ? (
<WorkspaceAccessToggle
<WorkspaceAccessMenu
scope={workspaceScope}
disabled={interactionDisabled || workspaceScopeDisabled}
isHero={isHero}
onChange={onWorkspaceScopeChange}
/>
) : null;
const workspaceControl = showProjectPicker ? (
<WorkspaceProjectPicker
layoutAnchor={workspacePickerLayoutAnchor}
isHero={isHero}
disabled={interactionDisabled || workspaceScopeDisabled}
scope={workspaceScope}
defaultScope={workspaceDefaultScope}
@@ -2566,7 +2565,7 @@ export function ThreadComposer({
onClick={modelNeedsSetup ? onModelBadgeClick : undefined}
/>
) : null;
const usageControl = !voiceRecorder.isRecording ? (
const usageControl = !voiceRecorder.isRecording && (contextUsage || recentRoundUsage.length) ? (
<ComposerUsagePopover context={contextUsage} rounds={recentRoundUsage} showLabel={compactControls} bottomSheet={compactControls} />
) : null;
const inputTextClasses = cn(
@@ -2626,8 +2625,10 @@ export function ThreadComposer({
if (!handleSessionDrop(event)) onDrop(event);
}}
className={cn(
"relative w-full",
isHero ? "px-0" : "px-1 pb-1.5 pt-1 sm:px-0",
"thread-composer-form relative w-full [--composer-action-margin:0px]",
isHero
? "px-0 [--composer-action-size:2rem] [--composer-footer-inset:0.75rem] sm:[--composer-footer-inset:1rem]"
: "px-1 pb-1.5 pt-1 [--composer-action-size:2.25rem] [--composer-footer-inset:0.625rem] sm:px-0 sm:[--composer-footer-inset:0.75rem]",
compactWhenIdle && "thread-composer-collapsible-layout",
paletteBeside && "grid grid-cols-2 items-start gap-2 p-0",
)}
@@ -2800,13 +2801,13 @@ export function ThreadComposer({
) : null}
<div
className={cn(
"thread-composer-footer flex flex-nowrap items-center motion-safe:transition-[padding-bottom] motion-safe:[transition-duration:220ms] motion-safe:ease-in-out",
"thread-composer-footer flex flex-nowrap items-center px-[var(--composer-footer-inset)] motion-safe:transition-[padding-bottom] motion-safe:[transition-duration:220ms] motion-safe:ease-in-out",
isHero
? cn(
"gap-x-1.5 px-3 sm:px-4",
"gap-x-1.5",
showProjectPicker && compactControls ? "pb-1.5" : "pb-3.5",
)
: "gap-x-2 px-2.5 pb-2 sm:px-3",
: "gap-x-2 pb-2",
)}
>
<div
@@ -2832,13 +2833,12 @@ export function ThreadComposer({
onClick={() => fileInputRef.current?.click()}
className={cn(
"thread-composer-action thread-composer-round-action touch-target shrink-0 rounded-xl text-muted-foreground hover:text-foreground",
isHero
? "h-8 w-8"
: "h-9 w-9",
"h-[var(--composer-action-size)] w-[var(--composer-action-size)]",
)}
>
<AttachIcon className="h-3.5 w-3.5" />
</Button>
{!mobileWorkspaceControls ? accessControl : null}
{voiceRecorder.isRecording ? (
<VoiceRecordingMeter
ariaLabel={voiceRecordingStatusLabel}
@@ -2847,12 +2847,7 @@ export function ThreadComposer({
isHero={isHero}
levels={voiceRecorder.levels}
/>
) : compactControls ? modelControl : (
<div className="thread-composer-workspace-group flex min-w-0 items-center gap-0.5">
{workspaceControl}
{accessControl}
</div>
)}
) : null}
</div>
<div
className={cn(
@@ -2860,7 +2855,7 @@ export function ThreadComposer({
isHero ? "gap-1.5" : "gap-2",
)}
>
{!compactControls ? modelControl : null}
{modelControl}
{!compactControls ? usageControl : null}
<TooltipProvider>
<Tooltip>
@@ -2934,26 +2929,19 @@ export function ThreadComposer({
</TooltipProvider>
</div>
</div>
{compactControls && projectPickerAvailable ? (
<div
className="inline-disclosure"
data-composer-workspace-drawer=""
data-state={showProjectPicker ? "open" : "closed"}
aria-hidden={showProjectPicker ? undefined : true}
>
<div className="inline-disclosure-clip">
<div className="inline-disclosure-content thread-composer-workspace-row flex min-w-0 items-center justify-between gap-2 rounded-b-[28px] bg-muted/45 px-3 py-1.5 dark:bg-white/[0.045] sm:px-4">
{workspaceControl}
<div className="ml-auto flex min-w-0 justify-end">{accessControl}</div>
</div>
</div>
</div>
) : null}
</div>
{compactControls && (!projectPickerAvailable || usageControl) ? (
<div className="thread-composer-meta mx-auto flex w-full max-w-[58rem] items-center justify-between gap-2 px-3">
{!projectPickerAvailable ? accessControl : null}
<div className="ml-auto">{usageControl}</div>
{workspaceControl || mobileWorkspaceControls && accessControl || compactControls && usageControl ? (
<div className={cn(
"thread-composer-meta mx-auto mt-1 flex w-full min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pr-2 sm:pr-3",
isHero ? "max-w-[58rem]" : "max-w-[49.5rem]",
paletteBeside && "col-start-1 row-start-2",
)}>
{mobileWorkspaceControls && compactControls && usageControl ? <div className="flex w-full justify-end">{usageControl}</div> : null}
<div className={cn("thread-composer-workspace-group flex min-w-0 items-center gap-1", mobileWorkspaceControls ? "flex-1" : "flex-auto max-[359px]:flex-wrap")}>
{workspaceControl}
</div>
{!mobileWorkspaceControls && compactControls && usageControl ? <div className="ml-auto shrink-0">{usageControl}</div> : null}
{mobileWorkspaceControls && accessControl ? <div className="ml-auto min-w-0 max-w-[55%] shrink">{accessControl}</div> : null}
</div>
) : null}
</form>
@@ -778,6 +778,10 @@ export function ThreadShell({
const showHeroComposer = displayMessages.length === 0 && !initialHistoryLoading;
const composerVariant = showHeroComposer ? emptyComposerVariant : "thread";
// The server owns the project lock. Old servers have no marker, so an existing
// user turn is read-only here too; the gateway remains the editing authority.
const projectLocked = session?.projectLocked === true
|| (session?.projectLocked === undefined && displayMessages.some((message) => message.role === "user" && message.deliveryStatus !== "failed"));
const wasShowingHeroComposerRef = useRef(showHeroComposer);
const sessionModelPreset = session?.modelPreset?.trim() || null;
const [localModelPreset, setLocalModelPreset] = useState<string | null>(null);
@@ -1338,6 +1342,7 @@ export function ThreadShell({
workspaceDefaultScope={workspaceDefaultScope}
workspaceControls={workspaceControls}
workspaceScopeDisabled={workspaceScopeDisabled}
workspaceProjectLocked={projectLocked}
workspaceError={workspaceError}
onWorkspaceScopeChange={onWorkspaceScopeChange}
pendingQueueKey={temporary ? null : chatId}
@@ -1395,6 +1400,7 @@ export function ThreadShell({
workspaceDefaultScope={workspaceDefaultScope}
workspaceControls={workspaceControls}
workspaceScopeDisabled={workspaceScopeDisabled}
workspaceProjectLocked={projectLocked}
workspaceError={workspaceError}
onWorkspaceScopeChange={onWorkspaceScopeChange}
transcriptionProvider={settingsSnapshot?.transcription?.provider}
@@ -1,12 +1,13 @@
import { FullAccessIcon, WorkspaceIcon, RestrictedAccessIcon } from "@/components/icons/product-icons";
import { FullAccessIcon, RestrictedAccessIcon, WorkspaceIcon } from "@/components/icons/product-icons";
import type { HTMLAttributes, ReactElement } from "react";
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { ArrowLeft, ArrowRight, Check, ChevronRight, FolderSearch, History, Search, Star } from "lucide-react";
import { ArrowLeft, ArrowRight, Check, ChevronDown, ChevronRight, FolderSearch, History, Search, Star } from "lucide-react";
import { useTranslation } from "react-i18next";
import { ToggleButton } from "@/components/ui/toggle-button";
import { Button } from "@/components/ui/button";
import { floatingItemClassName, floatingItemFocusClassName } from "@/components/ui/floating-surface";
import { HoverHint } from "@/components/ui/tooltip";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Input, SearchInput } from "@/components/ui/input";
import { Dialog, DialogContent, DialogTrigger, DialogTitle, DialogDescription } from "@/components/ui/dialog";
import { SidebarSelectionHighlight, SIDEBAR_SELECTION_ITEM_CLASS } from "@/components/SidebarSelectionHighlight";
@@ -152,9 +153,8 @@ function WorkspacePickerPath({ path }: { path: string }) {
);
}
export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope, controls, error, onLoadProjects, onResolveProject, onFavoriteProject, onBrowseDirectories, layoutAnchor, onChange }: {
export function WorkspaceProjectPicker({ disabled, scope, defaultScope, controls, error, onLoadProjects, onResolveProject, onFavoriteProject, onBrowseDirectories, layoutAnchor, onChange }: {
layoutAnchor?: HTMLElement | null;
isHero: boolean;
disabled?: boolean;
scope: WorkspaceScopePayload | null;
defaultScope: WorkspaceScopePayload | null;
@@ -217,7 +217,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
const currentProjectScope = selectedProjectScope(scope, defaultScope);
const displayedScope = scope ?? defaultScope;
const projectLabel = displayedScope ? displayedScope.project_name || projectNameFromPath(displayedScope.project_path) : "";
const visible = isHero && !!defaultScope && !!onChange && controls?.can_change_project !== false;
const visible = !!defaultScope && !!onChange && controls?.can_change_project !== false;
const canBrowse = controls?.can_browse_directories === true && !!onBrowseDirectories;
const directoryCache = useMemo(() => onBrowseDirectories ? createWorkspaceDirectoryCache(onBrowseDirectories) : null, [onBrowseDirectories]);
const previousColumns = useMemo<PickerColumn[]>(() => currentVisit.ancestors.map(ancestor => {
@@ -551,13 +551,14 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
if (!visible || !defaultScope || !onChange) return null;
return (
<div className="inline-flex min-w-0 max-w-[11rem] shrink items-center">
<div className="inline-flex min-w-0 max-w-[17.5rem] shrink items-center">
<Dialog open={open} onOpenChange={setOpen}>
<HoverHint content={`${t("workspace.picker.switchDirectory")}\n${displayedScope?.project_path ?? ""}`}>
<DialogTrigger asChild>
<button ref={triggerRef} onClick={event => { openedWithKeyboard.current = event.detail === 0; }} onPointerDown={() => setKeyboardInteraction(false)} onKeyDown={() => setKeyboardInteraction(true)} type="button" disabled={disabled} aria-label={t("workspace.picker.switchDirectory")} className="thread-composer-workspace touch-target inline-flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-control px-2 text-[12px] font-medium text-muted-foreground outline-none transition-colors hover:bg-foreground/[0.055] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55">
<WorkspaceIcon className="h-3.5 w-3.5 shrink-0" />
<button ref={triggerRef} onClick={event => { openedWithKeyboard.current = event.detail === 0; }} onPointerDown={() => setKeyboardInteraction(false)} onKeyDown={() => setKeyboardInteraction(true)} type="button" disabled={disabled} aria-label={t("workspace.picker.switchDirectory")} className="settings-hover thread-composer-workspace touch-target inline-flex h-7 min-w-0 max-w-full items-center gap-1.5 rounded-md px-2 text-[12px] font-medium text-muted-foreground outline-none transition-colors motion-reduce:transition-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55">
<WorkspaceIcon className="h-3 w-3 shrink-0" />
<span className="min-w-0 truncate">{projectLabel}</span>
<ChevronDown className="h-3 w-3 shrink-0" aria-hidden />
</button>
</DialogTrigger>
</HoverHint>
@@ -679,58 +680,67 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
);
}
export function WorkspaceAccessToggle({
export function WorkspaceAccessMenu({
scope,
disabled,
isHero,
onChange,
}: {
scope: WorkspaceScopePayload;
disabled?: boolean;
isHero: boolean;
onChange?: (scope: WorkspaceScopePayload) => void;
}) {
const { t } = useTranslation();
const mode = scope.access_mode;
const isFull = mode === "full";
const accessLabel = t(
isFull ? "thread.composer.workspace.full" : "thread.composer.workspace.default",
);
const shortAccessLabel = t(
isFull ? "thread.composer.workspace.fullShort" : "thread.composer.workspace.defaultShort",
);
const accessAriaLabel = `${t("thread.composer.workspace.accessAria")}: ${accessLabel}`;
const coarsePointer = useMediaQuery("(pointer: coarse)");
const [open, setOpen] = useState(false);
const restoreTriggerFocus = useRef(true);
const descriptionId = useId();
const isFull = scope.access_mode === "full";
const label = t(isFull ? "thread.composer.workspace.full" : "thread.composer.workspace.default");
const description = t(isFull ? "thread.composer.workspace.fullDescription" : "thread.composer.workspace.defaultDescription");
const accessAriaLabel = `${t("thread.composer.workspace.accessAria")}: ${label}`;
const AccessIcon = isFull ? FullAccessIcon : RestrictedAccessIcon;
useEffect(() => { if (disabled || !onChange) setOpen(false); }, [disabled, onChange]);
return (
<HoverHint side="top" contentClassName="w-max max-w-[calc(100vw-2rem)] text-left leading-relaxed"
content={t(isFull ? "thread.composer.workspace.fullDescription" : "thread.composer.workspace.defaultDescription")}>
<Button
type="button"
variant={null}
aria-label={accessAriaLabel}
aria-pressed={isFull}
disabled={disabled || !onChange}
onClick={() => onChange?.(scopeWithAccessMode(scope, isFull ? "restricted" : "full"))}
<DropdownMenu open={open} onOpenChange={setOpen}>
<HoverHint enabled={!open && !coarsePointer} content={description}>
<DropdownMenuTrigger asChild disabled={disabled || !onChange}>
<button type="button" aria-label={accessAriaLabel} aria-describedby={descriptionId}
onPointerDown={() => { restoreTriggerFocus.current = false; }}
onKeyDown={() => { restoreTriggerFocus.current = true; }}
className={cn(
"settings-hover thread-composer-access touch-target min-w-0 max-w-[min(12.5rem,42vw)] whitespace-nowrap rounded-control border border-transparent font-semibold shadow-none",
isHero ? "h-8 px-2.5 text-[12px]" : "h-9 px-3 text-[12.5px]",
isFull
? "bg-transparent text-orange-600 hover:text-orange-600 dark:text-orange-300 dark:hover:text-orange-300"
: "bg-transparent text-muted-foreground hover:text-foreground",
)}
>
{isFull ? (
<FullAccessIcon className={cn("thread-composer-access-icon mr-1.5 shrink-0", isHero ? "h-3.5 w-3.5" : "h-3.5 w-3.5")} />
) : (
<RestrictedAccessIcon className={cn("thread-composer-access-icon mr-1.5 shrink-0", isHero ? "h-3.5 w-3.5" : "h-3.5 w-3.5")} />
)}
<span aria-hidden className="thread-composer-access-label-full min-w-0 truncate">
{accessLabel}
"thread-composer-access touch-target inline-flex h-8 min-w-0 max-w-full shrink items-center gap-1.5 rounded-md px-2 text-[12px] font-medium outline-none transition-colors motion-reduce:transition-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55",
isFull ? "text-orange-600 hover:text-orange-700 dark:text-orange-300 dark:hover:text-orange-200" : "text-muted-foreground hover:text-foreground",
)}>
<AccessIcon className="h-3.5 w-3.5 shrink-0" />
<span className="min-w-0 truncate">{label}</span>
<ChevronDown className="h-3 w-3 shrink-0" aria-hidden />
<span id={descriptionId} className="sr-only">{description}</span>
</button>
</DropdownMenuTrigger>
</HoverHint>
<DropdownMenuContent side="top" align="start" sideOffset={8} aria-label={t("thread.composer.workspace.accessAria")}
onPointerDownCapture={() => { restoreTriggerFocus.current = false; }}
onKeyDownCapture={() => { restoreTriggerFocus.current = true; }}
onPointerDownOutside={() => { restoreTriggerFocus.current = false; }}
onCloseAutoFocus={event => { if (!restoreTriggerFocus.current) event.preventDefault(); }}
className="w-max min-w-[13rem] max-w-[calc(100vw-2rem)]">
{(["restricted", "full"] as const).map(mode => {
const full = mode === "full";
const optionLabel = t(full ? "thread.composer.workspace.full" : "thread.composer.workspace.default");
const OptionIcon = full ? FullAccessIcon : RestrictedAccessIcon;
return <DropdownMenuItem key={mode} role="menuitemradio" aria-checked={scope.access_mode === mode} aria-label={optionLabel}
className="touch-target gap-2.5"
onSelect={() => { if (!disabled && scope.access_mode !== mode) onChange?.(scopeWithAccessMode(scope, mode)); }}>
<OptionIcon className={full ? "text-orange-600 dark:text-orange-300" : undefined} />
<span className="min-w-0 flex-1">{optionLabel}</span>
<span aria-hidden className="flex h-3.5 w-3.5 shrink-0 items-center justify-center">
{scope.access_mode === mode && <Check className={cn("h-3.5 w-3.5", full && "text-orange-600 dark:text-orange-300")} />}
</span>
<span aria-hidden className="thread-composer-access-label-short hidden min-w-0 truncate">
{shortAccessLabel}
</span>
</Button>
</HoverHint>
</DropdownMenuItem>;
})}
</DropdownMenuContent>
</DropdownMenu>
);
}
+1
View File
@@ -13,6 +13,7 @@ export function HoverHint({ content, children, enabled = true, side = "top", ali
contentClassName?: string;
}) {
const [open, setOpen] = React.useState(false);
React.useEffect(() => { if (!enabled) setOpen(false); }, [enabled]);
return (
<TooltipProvider>
<Tooltip open={enabled && open} onOpenChange={(next) => setOpen(enabled && next)}>