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(channel): card-style composer with a + menu (#22440)

Arvin Xu802d66555b83
diff --git a/locales/en-US/channel.json b/locales/en-US/channel.json
index 9b5c8b18e79..986632e83e1 100644
--- a/locales/en-US/channel.json
+++ b/locales/en-US/channel.json
@@ -31,6 +31,8 @@
"chooseDirectory": "Choose directory",
"closeThread": "Close thread",
"composer": "Message #{{name}}",
+ "composer.actions": "More actions",
+ "composer.mention": "Mention someone",
"conversationEmpty": "Start the conversation",
"copyId": "Copy ID",
"copyIdSuccess": "Channel ID copied",
diff --git a/locales/zh-CN/channel.json b/locales/zh-CN/channel.json
index a7c938c927a..8c1eecc424a 100644
--- a/locales/zh-CN/channel.json
+++ b/locales/zh-CN/channel.json
@@ -31,6 +31,8 @@
"chooseDirectory": "选择工作目录",
"closeThread": "关闭线程",
"composer": "发消息到 #{{name}}",
+ "composer.actions": "更多操作",
+ "composer.mention": "提及成员或 Agent",
"conversationEmpty": "开始一起讨论吧",
"copyId": "复制 ID",
"copyIdSuccess": "已复制频道 ID",
diff --git a/packages/locales/src/default/channel.ts b/packages/locales/src/default/channel.ts
index 7f547afec28..3363a62a598 100644
--- a/packages/locales/src/default/channel.ts
+++ b/packages/locales/src/default/channel.ts
@@ -98,6 +98,8 @@ export default {
'composer': 'Message #{{name}}',
'directComposer': 'Message {{name}}',
'threadComposer': 'Reply in thread',
+ 'composer.actions': 'More actions',
+ 'composer.mention': 'Mention someone',
'stopReply': 'Stop reply',
'main': 'Channel conversation',
'startThread': 'Start thread',
diff --git a/src/features/Channels/Composer.tsx b/src/features/Channels/Composer.tsx
index 48a170aa3cf..e685c843e34 100644
--- a/src/features/Channels/Composer.tsx
+++ b/src/features/Channels/Composer.tsx
@@ -8,10 +8,10 @@ import {
ReactMentionPlugin,
} from '@lobehub/editor';
import { ChatInput, Editor, SendButton, useEditor } from '@lobehub/editor/react';
-import { ActionIcon, cssVar, Flexbox, Text, Upload } from '@lobehub/ui';
+import { ActionIcon, Flexbox, Text } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
-import { $getSelection, $isRangeSelection } from 'lexical';
-import { CirclePlus, Reply, X } from 'lucide-react';
+import { $getSelection, $isRangeSelection, KEY_DOWN_COMMAND } from 'lexical';
+import { Reply, X } from 'lucide-react';
import type { ReactNode } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -31,6 +31,7 @@ import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfi
import { useUserStore } from '@/store/user';
import { userProfileSelectors } from '@/store/user/selectors';
+import { ComposerActions } from './ComposerActions';
import { MemberAvatar } from './MemberAvatar';
import { isCurrentUserMember, memberName } from './memberName';
import { getMentionGroups } from './mentionGroups';
@@ -75,13 +76,8 @@ type ComposerDelivery =
const plugins = [ReactCodePlugin, ReactListPlugin, ReactLinkHighlightPlugin, ReactMentionPlugin];
-/** A flat filled bar, like an IM message box, instead of the chat page's raised card. */
-const inputShell = {
- backgroundColor: cssVar.colorFillTertiary,
- borderColor: 'transparent',
- borderRadius: 12,
- boxShadow: 'none',
-};
+/** Keeps ChatInput's raised card (elevated background, border, soft shadow) from the chat page. */
+const inputShell = { borderRadius: 12 };
export function Composer({
activity,
@@ -121,7 +117,7 @@ export function Composer({
const [error, setError] = useState('');
const requests = useSingleton(createChannelSendRequest);
const attachments = useAttachments();
- const { allowed, reason } = usePermission('create_content');
+ const { allowed } = usePermission('create_content');
const enableUpload = useServerConfigStore((s) => featureFlagsSelectors(s).enableKnowledgeBase);
const canUpload = allowed && enableUpload;
const upload = (files: File[]) => {
@@ -135,6 +131,26 @@ export function Composer({
// Mentioning yourself notifies nobody and picks no reply.
const mentionable = members.filter((member) => !isCurrentUserMember(member, userId));
const invites = useMentionInvites(channel, members);
+ const canMention = mentionable.length > 0 || invites.enabled;
+ /** Types an @ at the caret and opens the same mention picker as typing it. */
+ const startMention = () => {
+ const lexical = editor.getLexicalEditor();
+ lexical?.focus(
+ () =>
+ lexical.update(() => {
+ // The picker ignores programmatic text until a keystroke re-arms it; doing both in
+ // one update keeps the intermediate state from closing it again.
+ lexical.dispatchCommand(
+ KEY_DOWN_COMMAND,
+ new KeyboardEvent('keydown', { key: 'Process' }),
+ );
+ if ($insertChannelMentionBoundary(new KeyboardEvent('keydown', { key: '@' }))) return;
+ const selection = $getSelection();
+ if ($isRangeSelection(selection)) selection.insertText('@');
+ }),
+ { defaultSelection: 'rootEnd' },
+ );
+ };
const send = async () => {
const value = String(editor.getDocument('markdown') || '').trim();
const fileIds = attachments.readyFileIds();
@@ -262,21 +278,15 @@ export function Composer({
}
>
<div {...stylex.props(styles.composerRow)}>
- {enableUpload && (
- <Upload
- multiple
- disabled={busy || !canUpload}
- onFiles={(files) => void upload(files)}
- >
- <ActionIcon
- aria-label={t('attachments.upload')}
- disabled={busy || !canUpload}
- icon={CirclePlus}
- size={{ blockSize: 28, size: 20 }}
- title={reason || t('attachments.upload')}
- />
- </Upload>
- )}
+ <ComposerActions
+ disabled={busy}
+ upload={
+ enableUpload
+ ? { blocked: !allowed, onFiles: (files) => void upload(files) }
+ : undefined
+ }
+ onMention={canMention ? startMention : undefined}
+ />
<div {...stylex.props(styles.composerEditor)}>
<Editor
autoFocus
diff --git a/src/features/Channels/ComposerActions.tsx b/src/features/Channels/ComposerActions.tsx
new file mode 100644
index 00000000000..b3400025f6a
--- /dev/null
+++ b/src/features/Channels/ComposerActions.tsx
@@ -0,0 +1,68 @@
+import { ActionIcon, type DropdownItem, DropdownMenu, Icon } from '@lobehub/ui';
+import { AtSign, CirclePlus, Paperclip } from 'lucide-react';
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+interface ComposerActionsProps {
+ disabled?: boolean;
+ /** Omitted when nobody can be mentioned here. */
+ onMention?: () => void;
+ /** Omitted when uploads are off for this server. */
+ upload?: {
+ /** The user lacks permission to upload here. */
+ blocked?: boolean;
+ onFiles: (files: File[]) => void;
+ };
+}
+
+/** The composer's "+" menu: everything you can add to a message besides typing. */
+export function ComposerActions({ disabled, onMention, upload }: ComposerActionsProps) {
+ const { t } = useTranslation('channel');
+ const [fileInput, setFileInput] = useState<HTMLInputElement | null>(null);
+
+ const items: DropdownItem[] = [];
+ if (upload)
+ items.push({
+ disabled: upload.blocked,
+ icon: <Icon icon={Paperclip} />,
+ key: 'upload',
+ label: t('attachments.upload'),
+ onClick: () => fileInput?.click(),
+ });
+ if (onMention)
+ items.push({
+ icon: <Icon icon={AtSign} />,
+ key: 'mention',
+ label: t('composer.mention'),
+ onClick: onMention,
+ });
+ if (items.length === 0) return null;
+
+ return (
+ <>
+ <DropdownMenu items={items} placement="topLeft">
+ <ActionIcon
+ aria-label={t('composer.actions')}
+ disabled={disabled}
+ icon={CirclePlus}
+ size={{ blockSize: 28, size: 20 }}
+ title={t('composer.actions')}
+ />
+ </DropdownMenu>
+ {upload && (
+ <input
+ hidden
+ multiple
+ ref={setFileInput}
+ type="file"
+ onChange={(event) => {
+ const files = Array.from(event.target.files ?? []);
+ // Let the same file be picked again after it is removed from the draft.
+ event.target.value = '';
+ if (files.length > 0) upload.onFiles(files);
+ }}
+ />
+ )}
+ </>
+ );
+}
diff --git a/src/features/Channels/styles.ts b/src/features/Channels/styles.ts
index 8019a58ea69..cfd642ecd94 100644
--- a/src/features/Channels/styles.ts
+++ b/src/features/Channels/styles.ts
@@ -191,7 +191,7 @@ export const styles = stylex.create({
display: 'flex',
alignItems: 'flex-end',
gap: 8,
- minHeight: 44,
+ minHeight: 48,
paddingBlock: 8,
paddingInline: 8,
},
@@ -200,7 +200,9 @@ export const styles = stylex.create({
flex: '1',
minWidth: 0,
maxHeight: 240,
- paddingBlock: 2,
+ // Buttons sit on the last line; glyphs ride high in the line box, so drop the
+ // text 2px to center it on the 28px icons beside it.
+ marginBlockEnd: -2,
},
/** Takes the composer's place while the channel or thread is archived. */
archivedNotice: {