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(goal): fold the result follow-up into a pill and keep the report shadow under it (#21394)

LiJian9f47e73f66aa
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index f8752ba77ab..b30cc2a82a5 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -1114,6 +1114,7 @@
"goalProcess.result.deliverables.viewAll": "Review all {{count}}",
"goalProcess.result.followUp.placeholder": "Ask about this result, or what to do next…",
"goalProcess.result.followUp.send": "Send to the goal conversation",
+ "goalProcess.result.followUp.trigger": "Follow up",
"goalProcess.result.gate.error": "Could not save the decision. Try again.",
"goalProcess.result.gate.prompt": "Check which criteria were not met below, then retry or end the Goal.",
"goalProcess.result.gate.revising": "You chose to retry. The Agent is revising the result; it will be accepted again when done.",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 0a169495dba..56327e428e6 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -1114,6 +1114,7 @@
"goalProcess.result.deliverables.viewAll": "逐一查看全部 {{count}} 项",
"goalProcess.result.followUp.placeholder": "就这个结果追问,或说说下一步想做什么…",
"goalProcess.result.followUp.send": "发送到目标对话",
+ "goalProcess.result.followUp.trigger": "追问",
"goalProcess.result.gate.error": "决定没有保存成功,请重试。",
"goalProcess.result.gate.prompt": "先看下方哪些标准没有达成,再决定重试还是结束目标。",
"goalProcess.result.gate.revising": "你选择了重试,Agent 正在修改,改完后会重新验收。",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index b0ea077a1e1..9c0be01e9e3 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -2507,6 +2507,7 @@ export default {
'The coordinator is breaking the goal into executable tasks — they will appear here shortly.',
'goalProcess.result.followUp.placeholder': 'Ask about this result, or what to do next…',
'goalProcess.result.followUp.send': 'Send to the goal conversation',
+ 'goalProcess.result.followUp.trigger': 'Follow up',
'goalProcess.tag.needsDecision': 'Needs your decision',
'goalProcess.acceptance.repairing': 'Repairing',
'goalProcess.acceptance.verifying': 'Verifying',
diff --git a/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx b/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx
index 328a01b02a5..61be50d167a 100644
--- a/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx
+++ b/src/features/AgentGoals/ProcessControl/GoalFollowUpComposer.tsx
@@ -1,34 +1,81 @@
'use client';
import { ChatInput, ChatInputActionBar, SendButton, useEditor } from '@lobehub/editor/react';
-import { createStaticStyles, cssVar } from '@lobehub/ui';
+import { createStaticStyles, cssVar, Icon } from '@lobehub/ui';
import { $getRoot } from 'lexical';
+import { PlusIcon } from 'lucide-react';
+import type { FocusEvent, KeyboardEvent } from 'react';
import { memo, useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { EditorCanvas } from '@/features/EditorCanvas';
import { useEnterToSend } from '@/hooks/useEnterToSend';
+import { useFoldableComposer } from './useFoldableComposer';
+
/**
* The result page's closing move: ask the goal's agent about what was just
* delivered without hunting for the panel toggle. It owns no conversation of
* its own — the text is handed to the host, which opens the goal conversation
* beside the page and sends it there, so the reply lands where every other
* question about this goal already lives.
+ *
+ * It rests as a small pill so the result stays the page's focus, and only
+ * opens into the full input once the reader asks for it.
*/
const styles = createStaticStyles(({ css }) => ({
- // Pinned to the bottom of the page's scroll area, over a fade so the result
- // text scrolling underneath never collides with the box.
+ // Pinned to the bottom of the page's scroll area. Collapsed, only the pill
+ // takes pointer events, so the result text under the dock stays selectable.
dock: css`
+ pointer-events: none;
+
position: sticky;
z-index: 1;
inset-block-end: 0;
- padding-block: 24px 16px;
+ display: flex;
+ justify-content: center;
+ padding-block: 16px;
+ `,
+ // Open, the input sits over a fade so the result text scrolling underneath
+ // never collides with the box.
+ dockExpanded: css`
+ pointer-events: auto;
+ display: block;
+ padding-block: 24px 16px;
background: linear-gradient(to bottom, transparent, ${cssVar.colorBgLayout} 24px);
`,
+ pill: css`
+ pointer-events: auto;
+ cursor: pointer;
+
+ display: inline-flex;
+ gap: 8px;
+ align-items: center;
+
+ height: 40px;
+ padding-inline: 16px 20px;
+ border: 1px solid color-mix(in srgb, ${cssVar.colorBorderSecondary} 60%, transparent);
+ border-radius: 999px;
+
+ font-size: 14px;
+ color: ${cssVar.colorTextSecondary};
+
+ background: color-mix(in srgb, ${cssVar.colorBgElevated} 75%, transparent);
+ backdrop-filter: blur(16px) saturate(1.2);
+ box-shadow: ${cssVar.boxShadowSecondary};
+
+ transition:
+ color 0.2s,
+ background 0.2s;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ background: color-mix(in srgb, ${cssVar.colorBgElevated} 90%, transparent);
+ }
+ `,
}));
interface GoalFollowUpComposerProps {
@@ -40,6 +87,7 @@ interface GoalFollowUpComposerProps {
const GoalFollowUpComposer = memo<GoalFollowUpComposerProps>(({ hidden, onSend }) => {
const { t } = useTranslation('chat');
const editor = useEditor();
+ const { expanded, fold, open, triggerRef } = useFoldableComposer(editor);
const [hasContent, setHasContent] = useState(false);
const shouldSendOnEnter = useEnterToSend();
@@ -55,48 +103,80 @@ const GoalFollowUpComposer = memo<GoalFollowUpComposerProps>(({ hidden, onSend }
if (!message) return;
editor?.cleanDocument?.();
setHasContent(false);
+ fold();
onSend(message);
- }, [editor, onSend]);
+ }, [editor, fold, onSend]);
+
+ // Clicking away folds an empty input back into the pill; a draft keeps it
+ // open so the reader can see what is still unsent.
+ const handleBlur = useCallback(
+ (event: FocusEvent<HTMLDivElement>) => {
+ if (hasContent || event.currentTarget.contains(event.relatedTarget as Node | null)) return;
+ fold();
+ },
+ [fold, hasContent],
+ );
+
+ // Escape always folds it; the editor stays mounted, so a draft is kept.
+ // Focus goes back to the pill, so the keyboard can reopen the draft.
+ const handleKeyDown = useCallback(
+ (event: KeyboardEvent<HTMLDivElement>) => {
+ if (event.key === 'Escape') fold(true);
+ },
+ [fold],
+ );
return (
// The dock itself carries `hidden`: a wrapper would become the sticky
// element's containing block and unpin it from the page bottom.
- <div className={styles.dock} hidden={hidden}>
- <ChatInput
- maxHeight={200}
- minHeight={48}
- footer={
- <ChatInputActionBar
- // The bar spreads `left` and `right` apart; without a left slot the
- // send button would sit on the left edge.
- left={<span />}
- style={{ paddingInline: 8 }}
- right={
- <SendButton
- disabled={!hasContent}
- shape={'round'}
- title={t('goalProcess.result.followUp.send')}
- type={'primary'}
- onClick={handleSubmit}
- />
- }
+ <div
+ className={expanded ? `${styles.dock} ${styles.dockExpanded}` : styles.dock}
+ hidden={hidden}
+ >
+ {!expanded && (
+ <button className={styles.pill} ref={triggerRef} type={'button'} onClick={open}>
+ <Icon icon={PlusIcon} size={16} />
+ {t('goalProcess.result.followUp.trigger')}
+ </button>
+ )}
+ {/* Kept mounted while folded, so Escape never throws a draft away. */}
+ <div hidden={!expanded} onBlur={handleBlur} onKeyDown={handleKeyDown}>
+ <ChatInput
+ maxHeight={200}
+ minHeight={48}
+ footer={
+ <ChatInputActionBar
+ // The bar spreads `left` and `right` apart; without a left slot the
+ // send button would sit on the left edge.
+ left={<span />}
+ style={{ paddingInline: 8 }}
+ right={
+ <SendButton
+ disabled={!hasContent}
+ shape={'round'}
+ title={t('goalProcess.result.followUp.send')}
+ type={'primary'}
+ onClick={handleSubmit}
+ />
+ }
+ />
+ }
+ >
+ <EditorCanvas
+ editor={editor}
+ floatingToolbar={false}
+ placeholder={t('goalProcess.result.followUp.placeholder')}
+ style={{ paddingBlock: 0 }}
+ onContentChange={handleContentChange}
+ onPressEnter={({ event }) => {
+ if (shouldSendOnEnter(event)) {
+ handleSubmit();
+ return true;
+ }
+ }}
/>
- }
- >
- <EditorCanvas
- editor={editor}
- floatingToolbar={false}
- placeholder={t('goalProcess.result.followUp.placeholder')}
- style={{ paddingBlock: 0 }}
- onContentChange={handleContentChange}
- onPressEnter={({ event }) => {
- if (shouldSendOnEnter(event)) {
- handleSubmit();
- return true;
- }
- }}
- />
- </ChatInput>
+ </ChatInput>
+ </div>
</div>
);
});
diff --git a/src/features/AgentGoals/ProcessControl/GoalReportPage.tsx b/src/features/AgentGoals/ProcessControl/GoalReportPage.tsx
index 69e1d6a515b..7b68ba80868 100644
--- a/src/features/AgentGoals/ProcessControl/GoalReportPage.tsx
+++ b/src/features/AgentGoals/ProcessControl/GoalReportPage.tsx
@@ -15,7 +15,10 @@ import GoalReportFullscreen from './GoalReportFullscreen';
const PREVIEW_MAX_HEIGHT = 480;
const styles = createStaticStyles(({ css }) => ({
+ // `isolation` keeps the shadow and hit layers' z-index inside the card, so
+ // the result page's sticky follow-up dock still covers them on scroll.
card: css`
+ isolation: isolate;
position: relative;
overflow: hidden;
diff --git a/src/features/AgentGoals/ProcessControl/useFoldableComposer.test.ts b/src/features/AgentGoals/ProcessControl/useFoldableComposer.test.ts
new file mode 100644
index 00000000000..edabd2e621e
--- /dev/null
+++ b/src/features/AgentGoals/ProcessControl/useFoldableComposer.test.ts
@@ -0,0 +1,71 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { act, renderHook } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { useFoldableComposer } from './useFoldableComposer';
+
+const setup = () => {
+ const input = { focus: vi.fn() };
+ const trigger = document.createElement('button');
+ document.body.append(trigger);
+ const hook = renderHook(() => useFoldableComposer(input));
+ hook.result.current.triggerRef.current = trigger;
+ return { hook, input, trigger };
+};
+
+describe('useFoldableComposer', () => {
+ afterEach(() => {
+ document.body.innerHTML = '';
+ });
+
+ it('starts folded without focusing anything', () => {
+ const { hook, input, trigger } = setup();
+
+ expect(hook.result.current.expanded).toBe(false);
+ expect(input.focus).not.toHaveBeenCalled();
+ expect(document.activeElement).not.toBe(trigger);
+ });
+
+ it('focuses the input once opened', () => {
+ const { hook, input } = setup();
+
+ act(() => hook.result.current.open());
+
+ expect(hook.result.current.expanded).toBe(true);
+ expect(input.focus).toHaveBeenCalledTimes(1);
+ });
+
+ it('hands focus back to the trigger when folded from the keyboard', () => {
+ const { hook, trigger } = setup();
+ act(() => hook.result.current.open());
+
+ act(() => hook.result.current.fold(true));
+
+ expect(hook.result.current.expanded).toBe(false);
+ expect(document.activeElement).toBe(trigger);
+ });
+
+ it('keeps the hand-back when the hidden input blurs and folds again', () => {
+ const { hook, trigger } = setup();
+ act(() => hook.result.current.open());
+
+ act(() => {
+ hook.result.current.fold(true);
+ hook.result.current.fold();
+ });
+
+ expect(document.activeElement).toBe(trigger);
+ });
+
+ it('leaves focus alone when folded by clicking away', () => {
+ const { hook, trigger } = setup();
+ act(() => hook.result.current.open());
+
+ act(() => hook.result.current.fold());
+
+ expect(hook.result.current.expanded).toBe(false);
+ expect(document.activeElement).not.toBe(trigger);
+ });
+});
diff --git a/src/features/AgentGoals/ProcessControl/useFoldableComposer.ts b/src/features/AgentGoals/ProcessControl/useFoldableComposer.ts
new file mode 100644
index 00000000000..e332a323151
--- /dev/null
+++ b/src/features/AgentGoals/ProcessControl/useFoldableComposer.ts
@@ -0,0 +1,40 @@
+import { useCallback, useEffect, useRef, useState } from 'react';
+
+interface FocusableInput {
+ focus: () => void;
+}
+
+/**
+ * Open/folded state for an input that rests behind a trigger. Opening focuses
+ * the input; folding from the keyboard hands focus back to the trigger, since
+ * the input it was in has just been hidden.
+ */
+export const useFoldableComposer = (input: FocusableInput | undefined) => {
+ const [expanded, setExpanded] = useState(false);
+ const triggerRef = useRef<HTMLButtonElement>(null);
+ const returnFocusRef = useRef(false);
+
+ // Both targets are only visible after the commit that swaps them, so focus
+ // waits for that render instead of moving inside the handler.
+ useEffect(() => {
+ if (expanded) {
+ input?.focus();
+ return;
+ }
+ if (!returnFocusRef.current) return;
+ returnFocusRef.current = false;
+ triggerRef.current?.focus();
+ }, [input, expanded]);
+
+ const open = useCallback(() => setExpanded(true), []);
+
+ /** `returnFocus` when the input still holds focus, e.g. folding on Escape. */
+ const fold = useCallback((returnFocus = false) => {
+ // Hiding the focused input can blur it, folding a second time; that call
+ // must not cancel the hand-back the first one asked for.
+ if (returnFocus) returnFocusRef.current = true;
+ setExpanded(false);
+ }, []);
+
+ return { expanded, fold, open, triggerRef };
+};