feat(webui): simplify automation management and unify disclosure motion
Replace the dense automation workspace with a calm list and on-demand details, show current linked-chat titles, and remember manual system-task expansion preferences. Reuse disclosure transitions across expandable controls, preserve drafts and focus through closing, and release large diffs after their exit animation. Refs NAN-116
This commit is contained in:
1 parent
90b889394f
commit
1640784d45
37 files changed
+1746
-721
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useId,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
Wrench,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
|
||||
import { AttachmentTile } from "@/components/AttachmentTile";
|
||||
import { SessionHandleLabel } from "@/components/SessionHandleLabel";
|
||||
@@ -934,6 +936,7 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
const lines = message.traces ?? [message.content];
|
||||
const count = lines.length;
|
||||
const [open, setOpen] = useState(false);
|
||||
const contentId = useId();
|
||||
return (
|
||||
<div className="w-full">
|
||||
<button
|
||||
@@ -944,6 +947,7 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
"text-xs text-muted-foreground transition-colors hover:bg-muted/45",
|
||||
)}
|
||||
aria-expanded={open}
|
||||
aria-controls={contentId}
|
||||
>
|
||||
<Wrench className="h-3.5 w-3.5" aria-hidden />
|
||||
<span className="font-medium">
|
||||
@@ -954,17 +958,14 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
<ChevronRight
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"ml-auto h-3.5 w-3.5 transition-transform duration-200",
|
||||
"ml-auto h-3.5 w-3.5 transition-transform duration-200 motion-reduce:transition-none",
|
||||
open && "rotate-90",
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
{open && (
|
||||
<DisclosureContent id={contentId} open={open}>
|
||||
<ul
|
||||
className={cn(
|
||||
"mt-1 space-y-0.5 border-l border-muted-foreground/20 pl-3",
|
||||
"animate-in fade-in-0 slide-in-from-top-1 duration-200",
|
||||
)}
|
||||
className="mt-1 space-y-0.5 border-l border-muted-foreground/20 pl-3"
|
||||
>
|
||||
{lines.map((line, i) => (
|
||||
<li
|
||||
@@ -975,7 +976,7 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</DisclosureContent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -51,6 +51,7 @@ interface SettingsPageProps {
|
||||
onToggleTheme: () => void;
|
||||
onBackToChat: () => void;
|
||||
skills: SkillSummary[];
|
||||
titleOverrides?: Record<string, string>;
|
||||
onLogout?: () => void;
|
||||
isRestarting: boolean;
|
||||
hostChromeInset: boolean;
|
||||
@@ -64,6 +65,7 @@ export function SettingsPage({
|
||||
onToggleTheme,
|
||||
onBackToChat,
|
||||
skills,
|
||||
titleOverrides,
|
||||
onLogout,
|
||||
isRestarting,
|
||||
hostChromeInset,
|
||||
@@ -562,6 +564,7 @@ export function SettingsPage({
|
||||
<div className="settings-stack">
|
||||
<AutomationsSettings
|
||||
payload={automations}
|
||||
titleOverrides={titleOverrides}
|
||||
loading={automationsLoading}
|
||||
query={automationsQuery}
|
||||
filter={automationsFilter}
|
||||
@@ -574,7 +577,6 @@ export function SettingsPage({
|
||||
onAction={handleAutomationAction}
|
||||
onRequestEdit={setAutomationPendingEdit}
|
||||
onRequestDelete={setAutomationPendingDelete}
|
||||
onBackToChat={onBackToChat}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -730,7 +732,7 @@ export function SettingsPage({
|
||||
)}
|
||||
>
|
||||
{!showSidebar ? (
|
||||
<div className="mb-7">
|
||||
<div className={activeSection === "automations" ? "lg:hidden" : "mb-7"}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={backToChat}
|
||||
@@ -739,11 +741,11 @@ export function SettingsPage({
|
||||
<ChevronLeft className="h-3.5 w-3.5" aria-hidden />
|
||||
{t("settings.backToChat")}
|
||||
</button>
|
||||
<h1 className="text-[24px] font-normal leading-tight tracking-normal text-foreground sm:text-[28px]">
|
||||
{activeSection !== "automations" ? <h1 className="text-[24px] font-normal leading-tight tracking-normal text-foreground sm:text-[28px]">
|
||||
{t(`settings.nav.${activeSection}`, {
|
||||
defaultValue: standaloneSectionTitle(activeSection),
|
||||
})}
|
||||
</h1>
|
||||
</h1> : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ interface SettingsViewProps {
|
||||
onModelNameChange: (modelName: string | null) => void;
|
||||
onSettingsChange?: (payload: SettingsPayload) => void;
|
||||
skills?: SkillSummary[];
|
||||
titleOverrides?: Record<string, string>;
|
||||
onSectionChange?: (section: SettingsSectionKey) => void;
|
||||
onLogout?: () => void;
|
||||
onRestart?: () => void;
|
||||
@@ -35,6 +36,7 @@ export function SettingsView({
|
||||
onModelNameChange,
|
||||
onSettingsChange,
|
||||
skills = [],
|
||||
titleOverrides,
|
||||
onSectionChange,
|
||||
onLogout,
|
||||
onRestart,
|
||||
@@ -61,6 +63,7 @@ export function SettingsView({
|
||||
onToggleTheme={onToggleTheme}
|
||||
onBackToChat={onBackToChat}
|
||||
skills={skills}
|
||||
titleOverrides={titleOverrides}
|
||||
onLogout={onLogout}
|
||||
isRestarting={isRestarting}
|
||||
hostChromeInset={hostChromeInset}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { useEffect, useId, useState, type ReactNode } from "react";
|
||||
import type { TFunction } from "i18next";
|
||||
import {
|
||||
Check,
|
||||
@@ -25,6 +25,8 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Disclosure } from "@/components/ui/disclosure";
|
||||
import { ExpandableText } from "@/components/ui/expandable-text";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { Sheet, SheetContent, SheetDescription, SheetTitle } from "@/components/ui/sheet";
|
||||
@@ -279,6 +281,7 @@ function SkillDetailSheet({
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
const [descriptionExpanded, setDescriptionExpanded] = useState(false);
|
||||
const descriptionId = useId();
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !skill) return;
|
||||
@@ -407,18 +410,21 @@ function SkillDetailSheet({
|
||||
{statusLabel}
|
||||
</Pill>
|
||||
</div>
|
||||
<p
|
||||
className={cn(
|
||||
"mt-3 text-[13px] leading-5 text-muted-foreground",
|
||||
descriptionExpandable && !descriptionExpanded && "line-clamp-5",
|
||||
)}
|
||||
>
|
||||
{activeSkill.description}
|
||||
</p>
|
||||
<div className="mt-3">
|
||||
<ExpandableText
|
||||
id={descriptionId}
|
||||
expanded={descriptionExpanded || !descriptionExpandable}
|
||||
lines={5}
|
||||
className="text-[13px] leading-5 text-muted-foreground"
|
||||
>
|
||||
{activeSkill.description}
|
||||
</ExpandableText>
|
||||
</div>
|
||||
{descriptionExpandable ? (
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={descriptionExpanded}
|
||||
aria-controls={descriptionId}
|
||||
onClick={() => setDescriptionExpanded((value) => !value)}
|
||||
className="mt-1.5 min-h-8 rounded-full text-[12px] font-medium text-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
@@ -574,15 +580,18 @@ function RawInstructionsBlock({ markdown }: { markdown: string }) {
|
||||
});
|
||||
|
||||
return (
|
||||
<details className="group rounded-floating border border-border/45 bg-muted/20 px-3 py-3">
|
||||
<summary className="flex min-h-11 cursor-pointer select-none items-center justify-between gap-3 text-[13px] font-medium text-foreground/90 transition-colors hover:text-foreground">
|
||||
<Disclosure
|
||||
className="rounded-floating border border-border/45 bg-muted/20 px-3 py-3"
|
||||
summaryClassName="flex min-h-11 cursor-pointer items-center justify-between gap-3 rounded-sm text-[13px] font-medium text-foreground/90 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
summary={<>
|
||||
<span>
|
||||
{t("settings.skills.instructionsTitle", { defaultValue: "Skill instructions" })}
|
||||
</span>
|
||||
<code className="font-mono text-[10px] font-normal text-muted-foreground">
|
||||
SKILL.md
|
||||
</code>
|
||||
</summary>
|
||||
</>}
|
||||
>
|
||||
<div className="mt-3 overflow-hidden rounded-control border border-border/35 bg-background/70">
|
||||
<pre
|
||||
className={cn(
|
||||
@@ -596,7 +605,7 @@ function RawInstructionsBlock({ markdown }: { markdown: string }) {
|
||||
{content}
|
||||
</pre>
|
||||
</div>
|
||||
</details>
|
||||
</Disclosure>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ProviderIcon } from "@/components/settings/models/ProviderSettings";
|
||||
import { useAutoSave } from "@/components/settings/shared/useAutoSave";
|
||||
import { useEffect, useRef, useState, type Dispatch, type SetStateAction } from "react";
|
||||
import { useEffect, useId, useRef, useState, type Dispatch, type SetStateAction } from "react";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
import {
|
||||
ChevronDown,
|
||||
GripVertical,
|
||||
@@ -237,6 +238,7 @@ export function ModelsSettings({
|
||||
const suggestedPresetNameRef = useRef<string | null>(null);
|
||||
const [editorRowKey, setEditorRowKey] = useState<string | null>(null);
|
||||
const [advancedOpen, setAdvancedOpen] = useState(false);
|
||||
const advancedId = useId();
|
||||
const [draggedCallOrderIndex, setDraggedCallOrderIndex] = useState<number | null>(null);
|
||||
const [dragOverCallOrderIndex, setDragOverCallOrderIndex] = useState<number | null>(null);
|
||||
const [draggedRowHeight, setDraggedRowHeight] = useState(0);
|
||||
@@ -499,6 +501,7 @@ export function ModelsSettings({
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={advancedOpen}
|
||||
aria-controls={advancedId}
|
||||
onClick={() => setAdvancedOpen((value) => !value)}
|
||||
className="flex min-h-[62px] w-full items-center justify-between gap-4 px-4 py-3.5 text-left transition-colors settings-hover sm:px-5"
|
||||
>
|
||||
@@ -519,13 +522,13 @@ export function ModelsSettings({
|
||||
</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform",
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200 motion-reduce:transition-none",
|
||||
advancedOpen && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
{advancedOpen ? (
|
||||
<DisclosureContent id={advancedId} open={advancedOpen}>
|
||||
<div className="bg-muted/12 px-4 py-4 sm:px-5">
|
||||
<ModelAdvancedFields
|
||||
maxTokens={form.maxTokens}
|
||||
@@ -535,7 +538,7 @@ export function ModelsSettings({
|
||||
onChange={(value) => setForm((prev) => ({ ...prev, ...value }))}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</DisclosureContent>
|
||||
<div className="flex min-h-[58px] flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:px-5">
|
||||
{creating ? (
|
||||
<Button
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useState, type ReactNode } from "react";
|
||||
import { useId, useMemo, useState, type ReactNode } from "react";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
import {
|
||||
ChevronDown,
|
||||
Clipboard,
|
||||
@@ -431,6 +432,7 @@ function ProviderAdvancedOptions({
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const enabled = new Set(fields);
|
||||
const contentId = useId();
|
||||
if (enabled.size === 0) return null;
|
||||
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
@@ -446,6 +448,7 @@ function ProviderAdvancedOptions({
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={open}
|
||||
aria-controls={contentId}
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
className="flex min-h-[48px] w-full items-center justify-between gap-4 px-1 py-2.5 text-left transition-colors hover:text-foreground"
|
||||
>
|
||||
@@ -454,13 +457,13 @@ function ProviderAdvancedOptions({
|
||||
</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform",
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200 motion-reduce:transition-none",
|
||||
open && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
{open ? (
|
||||
<DisclosureContent id={contentId} open={open}>
|
||||
<div className="py-3">
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{enabled.has("api_type") ? (
|
||||
@@ -622,7 +625,7 @@ function ProviderAdvancedOptions({
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</DisclosureContent>
|
||||
{footer ? (
|
||||
<div className="flex items-center justify-end gap-2 py-3">
|
||||
{footer}
|
||||
|
||||
@@ -4,17 +4,20 @@ import { useTranslation } from "react-i18next";
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
import { SettingsGroup, SettingsRow } from "@/components/settings/shared/SettingsControls";
|
||||
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { Disclosure } from "@/components/ui/disclosure";
|
||||
|
||||
export function SettingsAdvancedOptions({ children }: { children: ReactNode }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<details className="group/advanced [&>summary]:select-none">
|
||||
<summary className="settings-list-inset flex min-h-12 cursor-pointer list-none items-center justify-between gap-4 rounded-xl text-[13px] leading-5 text-muted-foreground settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&::-webkit-details-marker]:hidden">
|
||||
<Disclosure
|
||||
summaryClassName="settings-list-inset flex min-h-12 cursor-pointer items-center justify-between gap-4 rounded-xl text-[13px] leading-5 text-muted-foreground settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
summary={<>
|
||||
{t("settings.runtimeConfig.advancedOptions")}
|
||||
<ChevronDown aria-hidden className="h-3.5 w-3.5 shrink-0 group-open/advanced:rotate-180" />
|
||||
</summary>
|
||||
<ChevronDown aria-hidden className="h-3.5 w-3.5 shrink-0 transition-transform duration-200 group-data-[state=open]/disclosure:rotate-180 motion-reduce:transition-none" />
|
||||
</>}
|
||||
>
|
||||
<div className="space-y-1">{children}</div>
|
||||
</details>
|
||||
</Disclosure>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -2562,13 +2562,13 @@ export function ThreadComposer({
|
||||
</div>
|
||||
{projectPickerAvailable ? (
|
||||
<div
|
||||
className="composer-workspace-drawer"
|
||||
className="inline-disclosure"
|
||||
data-composer-workspace-drawer=""
|
||||
data-state={showProjectPicker ? "open" : "closed"}
|
||||
aria-hidden={showProjectPicker ? undefined : true}
|
||||
>
|
||||
<div className="composer-workspace-drawer-clip">
|
||||
<div className="composer-workspace-drawer-content">
|
||||
<div className="inline-disclosure-clip">
|
||||
<div className="inline-disclosure-content">
|
||||
<WorkspaceProjectPicker
|
||||
isHero={isHero}
|
||||
disabled={interactionDisabled || workspaceScopeDisabled || !showProjectPicker}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useId, useMemo, useState } from "react";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
@@ -166,13 +167,15 @@ function FileUnifiedDiff({
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const [open, setOpen] = useState(false);
|
||||
const [hasOpened, setHasOpened] = useState(false);
|
||||
const contentId = useId();
|
||||
const [expandedLines, setExpandedLines] = useState(false);
|
||||
const renderableDiff = useMemo(() => parseRenderableFileDiff(diff), [diff]);
|
||||
const language = useMemo(() => codeLanguageFromPath(previewPath), [previewPath]);
|
||||
const totalLineCount = useMemo(() => countDiffLines(renderableDiff), [renderableDiff]);
|
||||
const shouldAutoCollapse = totalLineCount > AUTO_COLLAPSE_DIFF_LINES || !!diff.truncated;
|
||||
const startsCollapsed = collapsed || shouldAutoCollapse;
|
||||
const shouldRenderBody = !startsCollapsed || open;
|
||||
const shouldRenderBody = !startsCollapsed || hasOpened;
|
||||
const shouldLimitLines = totalLineCount > INITIAL_VISIBLE_DIFF_LINES;
|
||||
const lineLimit = expandedLines || !shouldLimitLines
|
||||
? totalLineCount
|
||||
@@ -193,13 +196,21 @@ function FileUnifiedDiff({
|
||||
|
||||
useEffect(() => {
|
||||
setOpen(false);
|
||||
setHasOpened(false);
|
||||
setExpandedLines(false);
|
||||
}, [diff]);
|
||||
|
||||
const handleToggleOpen = () => {
|
||||
if (open) setExpandedLines(false);
|
||||
if (!open) {
|
||||
setHasOpened(true);
|
||||
setExpandedLines(false);
|
||||
}
|
||||
setOpen(!open);
|
||||
};
|
||||
const releaseBody = useCallback(() => {
|
||||
setHasOpened(false);
|
||||
setExpandedLines(false);
|
||||
}, []);
|
||||
|
||||
if (totalLineCount === 0) return null;
|
||||
|
||||
@@ -287,6 +298,7 @@ function FileUnifiedDiff({
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={open}
|
||||
aria-controls={contentId}
|
||||
data-testid="file-edit-diff-toggle"
|
||||
onClick={handleToggleOpen}
|
||||
className={cn(
|
||||
@@ -295,13 +307,15 @@ function FileUnifiedDiff({
|
||||
)}
|
||||
>
|
||||
<ChevronRight
|
||||
className={cn("h-3 w-3 shrink-0 transition-transform", open && "rotate-90")}
|
||||
className={cn("h-3 w-3 shrink-0 transition-transform duration-200 motion-reduce:transition-none", open && "rotate-90")}
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="min-w-0 flex-1">{viewDiffLabel}</span>
|
||||
<span className="shrink-0 text-muted-foreground/65">{lineCountLabel}</span>
|
||||
</button>
|
||||
{open ? renderBody() : null}
|
||||
<DisclosureContent id={contentId} open={open} onExitComplete={releaseBody}>
|
||||
{shouldRenderBody ? renderBody() : null}
|
||||
</DisclosureContent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ const DialogOverlay = React.forwardRef<
|
||||
ref={ref}
|
||||
className={cn(
|
||||
modalOverlayClassName,
|
||||
"motion-reduce:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -31,15 +32,30 @@ const DialogOverlay = React.forwardRef<
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
// The portal's presence ref must reach the animated content, not the plain
|
||||
// positioning wrapper; otherwise the wrapper unmounts before the exit finishes.
|
||||
const DialogPositionedContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
|
||||
positionerStyle?: React.CSSProperties;
|
||||
}
|
||||
>(({ positionerStyle, ...props }, ref) => (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" style={positionerStyle}>
|
||||
<DialogPrimitive.Content ref={ref} {...props} />
|
||||
</div>
|
||||
));
|
||||
DialogPositionedContent.displayName = "DialogPositionedContent";
|
||||
|
||||
interface DialogContentProps
|
||||
extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
|
||||
showCloseButton?: boolean;
|
||||
overlayClassName?: string;
|
||||
}
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
DialogContentProps
|
||||
>(({ className, children, showCloseButton = true, onOpenAutoFocus, ...props }, ref) => {
|
||||
>(({ className, children, showCloseButton = true, overlayClassName, onOpenAutoFocus, ...props }, ref) => {
|
||||
const { t } = useTranslation();
|
||||
const [container, setContainer] = React.useState<HTMLDivElement | null>(null);
|
||||
const contentNode = React.useRef<HTMLDivElement | null>(null);
|
||||
@@ -74,9 +90,9 @@ const DialogContent = React.forwardRef<
|
||||
}, [ref]);
|
||||
return (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" style={layout}>
|
||||
<DialogPrimitive.Content
|
||||
<DialogOverlay className={overlayClassName} />
|
||||
<DialogPositionedContent
|
||||
positionerStyle={layout}
|
||||
ref={contentRef}
|
||||
onOpenAutoFocus={(event) => {
|
||||
if (onOpenAutoFocus) onOpenAutoFocus(event);
|
||||
@@ -87,7 +103,7 @@ const DialogContent = React.forwardRef<
|
||||
}}
|
||||
className={cn(
|
||||
modalSurfaceClassName,
|
||||
"relative grid w-full max-w-lg origin-center gap-4 rounded-modal p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
||||
"relative grid w-full max-w-lg origin-center gap-4 rounded-modal p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 motion-reduce:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -101,8 +117,7 @@ const DialogContent = React.forwardRef<
|
||||
<span className="sr-only">{t("common.close")}</span>
|
||||
</DialogPrimitive.Close>
|
||||
) : null}
|
||||
</DialogPrimitive.Content>
|
||||
</div>
|
||||
</DialogPositionedContent>
|
||||
</DialogPortal>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { useEffect, useId, useRef, useState, type KeyboardEventHandler, type ReactNode } from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Keep the content mounted so both directions animate and form drafts survive closing. */
|
||||
export function DisclosureContent({
|
||||
open, children, id, className, onKeyDown, onExitComplete,
|
||||
}: {
|
||||
open: boolean;
|
||||
children: ReactNode;
|
||||
id?: string;
|
||||
className?: string;
|
||||
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
||||
onExitComplete?: () => void;
|
||||
}) {
|
||||
const node = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (open || !onExitComplete) return;
|
||||
// Read the actual CSS transitions, including a reversal in progress. With
|
||||
// reduced motion (or no transition), there is nothing to wait for.
|
||||
const animations = node.current?.getAnimations?.() ?? [];
|
||||
if (!animations.length) {
|
||||
onExitComplete();
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
void Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {
|
||||
if (!cancelled) onExitComplete();
|
||||
});
|
||||
return () => { cancelled = true; };
|
||||
}, [open, onExitComplete]);
|
||||
return (
|
||||
<div
|
||||
ref={node}
|
||||
id={id}
|
||||
className="inline-disclosure"
|
||||
data-state={open ? "open" : "closed"}
|
||||
aria-hidden={open ? undefined : true}
|
||||
onKeyDown={onKeyDown}
|
||||
{...(!open ? { inert: "" } : {})}
|
||||
>
|
||||
<div className="inline-disclosure-clip">
|
||||
<div className={cn("inline-disclosure-content", className)}>{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Disclosure({
|
||||
summary, children, className, summaryClassName, contentClassName,
|
||||
}: {
|
||||
summary: ReactNode;
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
summaryClassName?: string;
|
||||
contentClassName?: string;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={className}>
|
||||
<button
|
||||
type="button"
|
||||
className={cn("group/disclosure w-full select-none text-start", summaryClassName)}
|
||||
data-state={open ? "open" : "closed"}
|
||||
aria-expanded={open}
|
||||
aria-controls={id}
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
>
|
||||
{summary}
|
||||
</button>
|
||||
<DisclosureContent id={id} open={open} className={contentClassName}>
|
||||
{children}
|
||||
</DisclosureContent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useLayoutEffect, useRef, useState } from "react";
|
||||
|
||||
/** Animate a line-limited preview without swapping or duplicating its text. */
|
||||
export function ExpandableText({
|
||||
children, expanded, lines, className, id,
|
||||
}: {
|
||||
children: string;
|
||||
expanded: boolean;
|
||||
lines: number;
|
||||
className?: string;
|
||||
id?: string;
|
||||
}) {
|
||||
const content = useRef<HTMLParagraphElement>(null);
|
||||
const [size, setSize] = useState<{ full: number; preview: number }>();
|
||||
useLayoutEffect(() => {
|
||||
const node = content.current;
|
||||
if (!node) return;
|
||||
const measure = () => {
|
||||
const full = node.scrollHeight;
|
||||
const lineHeight = parseFloat(getComputedStyle(node).lineHeight);
|
||||
if (!full || !Number.isFinite(lineHeight)) return;
|
||||
const preview = Math.min(full, lineHeight * lines);
|
||||
setSize((current) => current?.full === full && current.preview === preview
|
||||
? current : { full, preview });
|
||||
};
|
||||
measure();
|
||||
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
|
||||
observer?.observe(node);
|
||||
window.addEventListener("resize", measure);
|
||||
return () => {
|
||||
observer?.disconnect();
|
||||
window.removeEventListener("resize", measure);
|
||||
};
|
||||
}, [children, lines, className]);
|
||||
|
||||
return (
|
||||
<div
|
||||
id={id}
|
||||
className="expandable-text flow-root overflow-hidden"
|
||||
data-state={expanded ? "open" : "closed"}
|
||||
style={{ height: size ? expanded ? size.full : size.preview : undefined }}
|
||||
>
|
||||
<p ref={content} className={className}>{children}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user