Skip to content

feat: Add custom actions for conversations #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a69af05
docs: Contributing fix
kimteayon Mar 7, 2025
9693b91
ci: update snap
kimteayon Mar 8, 2025
1eb7336
test: where is wrong of happy-dom xmlnsXlink
kimteayon Mar 8, 2025
a3a28f9
📝 Change codesandbox link
kimteayon Mar 8, 2025
6171192
Merge branch 'main' into fix
kimteayon Mar 9, 2025
b5b45b9
✅ Chore: updaye happy-dom -m 更新 happy-dom
kimteayon Mar 9, 2025
efa76a1
Merge branch 'fix' of https://github.com/kimteayon/x into fix
kimteayon Mar 9, 2025
917ccb5
✅ Chore: updaye happy-dom -m 更新 happy-dom
kimteayon Mar 9, 2025
d82c887
test: update snap
kimteayon Mar 9, 2025
660b484
delete:bun.lockb
kimteayon Mar 10, 2025
977a8ff
test: 更新snap
kimteayon Mar 10, 2025
1213e34
chore: delete bun.lock
kimteayon Mar 10, 2025
b2595f3
chore: delete bun.lock
kimteayon Mar 10, 2025
7a5273b
Merge branch 'main' into fix
kimteayon Mar 10, 2025
a78614f
Update package.json
afc163 Mar 10, 2025
f34570c
Update .gitignore
afc163 Mar 10, 2025
4d27533
Update package.json
afc163 Mar 10, 2025
23991f9
📝docs: changelog of 1.0.6
kimteayon Mar 14, 2025
eb613a1
Merge branch 'main' into fix
kimteayon Mar 14, 2025
46a46cd
📝docs: changelog of 1.0.6
kimteayon Mar 14, 2025
7e4396a
📝docs: changelog of 1.0.6
kimteayon Mar 14, 2025
bd29000
📝docs: changelog of 1.0.6
kimteayon Mar 14, 2025
8a6f144
Merge branch 'main' of https://github.com/kimteayon/x into fix
kimteayon Mar 17, 2025
025e1f6
📝 Docs: 更新Attachments文档
kimteayon Mar 17, 2025
b6423c3
Merge branch 'main' into fix
kimteayon Mar 18, 2025
e914c2c
feat: Add custom actions for conversations
kimteayon Mar 18, 2025
fe30404
Merge branch 'fix' of https://github.com/kimteayon/x into fix
kimteayon Mar 18, 2025
611281f
test: Add custom actions for conversations
kimteayon Mar 18, 2025
29c8cc9
fix: Add custom actions for conversations
kimteayon Mar 18, 2025
cbddd24
docs:fix attachments docs error
kimteayon Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/attachments/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ interface PlaceholderType {
### Attachments.FileCard Props

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| --- | --- | --- | --- | --- | --- |
| prefixCls | The prefix of the style class name | string | - | - |
| className | Style class name | string | - | - |
| style | Style Object | React.CSSProperties | - | - |
| item | Attachment, same as Upload `UploadFile` | Attachment | - | - |
| onRemove | Callback function when attachment is removed | (item: Attachment) => void | - | - |
| onRemove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when the return value is false or a Promise which resolve(false) or reject | (item: Attachment) => boolean | Promise | - | - |
| imageProps | Image config, same as [Image](https://ant.design/components/image) | ImageProps | - | - |

## Semantic DOM
Expand Down
4 changes: 2 additions & 2 deletions components/attachments/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ interface PlaceholderType {
### Attachments.FileCard Props

| 属性 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| --- | --- | --- | --- | --- | --- |
| prefixCls | 样式类名的前缀 | string | - | - |
| className | 样式类名 | string | - | - |
| style | 样式对象 | React.CSSProperties | - | - |
| item | 附件,同 Upload `UploadFile` | Attachment | - | - |
| onRemove | 附件移除时的回调函数 | (item: Attachment) => void | - | - |
| onRemove | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除 | (item: Attachment) => boolean | Promise | - | - |
| imageProps | 图片属性,同 antd [Image](https://ant.design/components/image) 属性 | ImageProps | - | - |

## Semantic DOM
Expand Down
62 changes: 44 additions & 18 deletions components/conversations/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { EllipsisOutlined } from '@ant-design/icons';
import { Dropdown, Tooltip, Typography } from 'antd';
import classnames from 'classnames';
import React from 'react';
import React, { useEffect } from 'react';

import type { MenuProps } from 'antd';
import type { DirectionType } from 'antd/es/config-provider';
import pickAttrs from 'rc-util/lib/pickAttrs';
import type { Conversation } from './interface';
import type { ActionsRender, Conversation } from './interface';

export interface ConversationsItemProps
extends Omit<React.HTMLAttributes<HTMLLIElement>, 'onClick'> {
info: Conversation;
prefixCls?: string;
direction?: DirectionType;
menu?: MenuProps;
actions?: React.ReactNode | ActionsRender;
active?: boolean;
onClick?: (info: Conversation) => void;
}
Expand All @@ -23,7 +24,8 @@
};

const ConversationsItem: React.FC<ConversationsItemProps> = (props) => {
const { prefixCls, info, className, direction, onClick, active, menu, ...restProps } = props;
const { prefixCls, info, className, direction, onClick, active, menu, actions, ...restProps } =
props;

const domProps = pickAttrs(restProps, {
aria: true,
Expand Down Expand Up @@ -61,6 +63,43 @@
}
};

// ============================ Menu ============================
const menuNode = (
<Dropdown
menu={menu}
placement={direction === 'rtl' ? 'bottomLeft' : 'bottomRight'}
trigger={['click']}
disabled={disabled}
onOpenChange={onOpenChange}
>
<EllipsisOutlined
onClick={stopPropagation}
disabled={disabled}
className={`${prefixCls}-menu-icon`}
/>
</Dropdown>
);

// ============================ Actions ============================
let actionNode: React.ReactNode = <></>;

if (typeof actions === 'function') {
actionNode = actions(menuNode, {
components: {
menuNode,
},
value: info,
});
} else if (actions) {
actionNode = actions;

Check warning on line 94 in components/conversations/Item.tsx

View check run for this annotation

Codecov / codecov/patch

components/conversations/Item.tsx#L94

Added line #L94 was not covered by tests
}

useEffect(() => {
if (!React.isValidElement(actionNode)) {
console.error('Action is Valid Element : %s', actionNode);

Check warning on line 99 in components/conversations/Item.tsx

View check run for this annotation

Codecov / codecov/patch

components/conversations/Item.tsx#L99

Added line #L99 was not covered by tests
}
}, [actionNode]);

// ============================ Render ============================
return (
<Tooltip
Expand All @@ -79,21 +118,8 @@
>
{info.label}
</Typography.Text>
{menu && !disabled && (
<Dropdown
menu={menu}
placement={direction === 'rtl' ? 'bottomLeft' : 'bottomRight'}
trigger={['click']}
disabled={disabled}
onOpenChange={onOpenChange}
>
<EllipsisOutlined
onClick={stopPropagation}
disabled={disabled}
className={`${prefixCls}-menu-icon`}
/>
</Dropdown>
)}
{actions && !disabled && React.isValidElement(actionNode) && actionNode}
{menu && !actions && !disabled && menuNode}
</li>
</Tooltip>
);
Expand Down
Loading