Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions packages/web3/src/connect-panel/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ConnectPanel

A card-style wallet connect panel component for Web3 DApps, similar in function to ConnectButton but with a modern card UI.

## Usage

```tsx
import { ConnectPanel } from '@ant-design/web3';

<ConnectPanel
wallets={[
{
key: 'metamask',
name: 'MetaMask',
icon: <img src="/path/to/metamask.svg" width={64} height={64} />,
actionText: 'Connect',
onClick: () => {
/* connect logic */
},
},
{
key: 'okx',
name: 'OKX Wallet',
icon: <img src="/path/to/okx.svg" width={64} height={64} />,
actionText: 'Connect',
onClick: () => {
/* connect logic */
},
},
{
key: 'add',
name: 'Add Address',
icon: <img src="/path/to/edit.svg" width={64} height={64} />,
actionText: 'Enter',
onClick: () => {
/* add address logic */
},
},
]}
/>;
```

## API

| Property | Description | Type | Default |
| --------- | ----------------- | ------ | ------- |
| wallets | Wallet card list | array | [] |
| className | Custom class name | string | - |
| style | Custom style | object | - |

Each wallet item:

| Property | Description | Type |
| ---------- | ------------------ | --------------- |
| key | Unique key | string |
| name | Wallet name | string |
| icon | Wallet icon | React.ReactNode |
| actionText | Action button text | string |
| onClick | Click handler | () => void |
1 change: 1 addition & 0 deletions packages/web3/src/connect-panel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './index';
40 changes: 40 additions & 0 deletions packages/web3/src/connect-panel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import type { Wallet } from '@ant-design/web3-common';
import classNames from 'classnames';

import { useStyle } from './style';

export interface ConnectPanelProps {
wallets?: Array<{
key: string;
name: string;
icon: React.ReactNode;
actionText: string;
onClick?: () => void;
}>;
className?: string;
style?: React.CSSProperties;
}

export const ConnectPanel: React.FC<ConnectPanelProps> = ({ wallets = [], className, style }) => {
const prefixCls = 'web3-connect-panel';
const { wrapSSR, hashId } = useStyle(prefixCls);

return wrapSSR(
<div className={classNames(prefixCls, hashId, className)} style={style}>
{wallets.map((wallet) => (
<div
key={wallet.key}
className={classNames(`${prefixCls}-card`, hashId)}
onClick={wallet.onClick}
>
Comment on lines +26 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

修复无障碍访问问题

卡片元素缺少键盘事件支持,这会影响键盘导航用户的体验。根据静态分析工具的建议,需要添加键盘事件处理。

        <div
          key={wallet.key}
          className={classNames(`${prefixCls}-card`, hashId)}
          onClick={wallet.onClick}
+         onKeyDown={(e) => {
+           if ((e.key === 'Enter' || e.key === ' ') && wallet.onClick) {
+             e.preventDefault();
+             wallet.onClick();
+           }
+         }}
+         tabIndex={0}
+         role="button"
+         aria-label={`${wallet.actionText} ${wallet.name}`}
        >
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div
key={wallet.key}
className={classNames(`${prefixCls}-card`, hashId)}
onClick={wallet.onClick}
>
<div
key={wallet.key}
className={classNames(`${prefixCls}-card`, hashId)}
onClick={wallet.onClick}
onKeyDown={(e) => {
if ((e.key === 'Enter' || e.key === ' ') && wallet.onClick) {
e.preventDefault();
wallet.onClick();
}
}}
tabIndex={0}
role="button"
aria-label={`${wallet.actionText} ${wallet.name}`}
>
🧰 Tools
🪛 Biome (1.9.4)

[error] 26-30: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)

🤖 Prompt for AI Agents
In packages/web3/src/connect-panel/index.tsx around lines 26 to 30, the div
element acting as a clickable card lacks keyboard event handlers, which impairs
accessibility for keyboard users. Add appropriate keyboard event handlers such
as onKeyDown or onKeyPress to handle Enter and Space keys, enabling keyboard
navigation and activation of the card. Also, ensure the div has a tabIndex
attribute to make it focusable.

<div className={classNames(`${prefixCls}-icon`, hashId)}>{wallet.icon}</div>
<div className={classNames(`${prefixCls}-name`, hashId)}>{wallet.name}</div>
<div className={classNames(`${prefixCls}-action`, hashId)}>{wallet.actionText} &gt;</div>
</div>
))}
</div>,
);
};

export default ConnectPanel;
59 changes: 59 additions & 0 deletions packages/web3/src/connect-panel/index.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ConnectPanel

卡片式 Web3 钱包连接面板组件,功能与 ConnectButton 类似,但采用现代卡片 UI。

## 用法

```tsx
import { ConnectPanel } from '@ant-design/web3';

<ConnectPanel
wallets={[
{
key: 'metamask',
name: 'MetaMask',
icon: <img src="/path/to/metamask.svg" width={64} height={64} />,
actionText: '连接',
onClick: () => {
/* 连接逻辑 */
},
},
{
key: 'okx',
name: 'OKX Wallet',
icon: <img src="/path/to/okx.svg" width={64} height={64} />,
actionText: '连接',
onClick: () => {
/* 连接逻辑 */
},
},
{
key: 'add',
name: '添加地址',
icon: <img src="/path/to/edit.svg" width={64} height={64} />,
actionText: '输入',
onClick: () => {
/* 添加地址逻辑 */
},
},
]}
/>;
```

## API

| 属性 | 说明 | 类型 | 默认值 |
| --------- | ------------ | ------ | ------ |
| wallets | 钱包卡片列表 | array | [] |
| className | 自定义类名 | string | - |
| style | 自定义样式 | object | - |

每个钱包项:

| 属性 | 说明 | 类型 |
| ---------- | ------------ | --------------- |
| key | 唯一 key | string |
| name | 钱包名称 | string |
| icon | 钱包图标 | React.ReactNode |
| actionText | 操作按钮文案 | string |
| onClick | 点击事件 | () => void |
59 changes: 59 additions & 0 deletions packages/web3/src/connect-panel/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
useStyle as useAntdStyle,
type GenerateStyle,
type UseStyleResult,
type Web3AliasToken,
} from '../../theme/useStyle';

export interface ConnectPanelToken extends Web3AliasToken {
componentCls: string;
}

const genConnectPanelStyle: GenerateStyle<ConnectPanelToken> = (token) => {
return {
[token.componentCls]: {
display: 'flex',
gap: 32,
justifyContent: 'center',
alignItems: 'center',
[`${token.componentCls}-card`]: {
width: 240,
height: 260,
background: '#fafaff',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议使用设计令牌而不是硬编码颜色

建议使用设计令牌中的颜色值而不是硬编码的 #fafaff,以保持设计系统的一致性。

-        background: '#fafaff',
+        background: token.colorBgLayout,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
background: '#fafaff',
background: token.colorBgLayout,
🤖 Prompt for AI Agents
In packages/web3/src/connect-panel/style/index.ts at line 22, replace the
hardcoded color value '#fafaff' with the corresponding design token color from
the design system to ensure consistency. Identify the appropriate color token
that matches '#fafaff' and use it instead of the literal hex code.

borderRadius: 20,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
boxShadow: '0 2px 8px rgba(0,0,0,0.03)',
transition: 'box-shadow 0.2s',
cursor: 'pointer',
':hover': {
boxShadow: '0 4px 16px rgba(0,0,0,0.06)',
},
},
[`${token.componentCls}-icon`]: {
marginBottom: 24,
},
[`${token.componentCls}-name`]: {
fontSize: 28,
fontWeight: 500,
marginBottom: 12,
},
[`${token.componentCls}-action`]: {
color: '#666',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议使用设计令牌中的文本颜色

建议使用设计令牌中的文本颜色而不是硬编码的 #666

-        color: '#666',
+        color: token.colorTextSecondary,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
color: '#666',
- color: '#666',
+ color: token.colorTextSecondary,
🤖 Prompt for AI Agents
In packages/web3/src/connect-panel/style/index.ts at line 44, replace the
hardcoded color value '#666' with the corresponding text color from the design
tokens. Locate the appropriate design token for text color in the project's
style or theme files and use that token instead of the fixed hex code to ensure
consistency with the design system.

fontSize: 22,
},
},
};
};

export function useStyle(prefixCls: string): UseStyleResult {
return useAntdStyle('ConnectPanel', (token) => {
const panelToken: ConnectPanelToken = {
...token,
componentCls: `.${prefixCls}`,
};
return [genConnectPanelStyle(panelToken)];
});
}
1 change: 1 addition & 0 deletions packages/web3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from '@ant-design/web3-common';
// export Web3ConfigProvider in ./web3-config-provider for replace the one in @ant-design/web3-common
export { Web3ConfigProvider, type Web3ThemeConfig } from './web3-config-provider';
export * from './pay-panel';
export * from './connect-panel';
Loading