-
Notifications
You must be signed in to change notification settings - Fork 183
faet: init new component connect-panel #1482
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './index'; |
| 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} | ||
| > | ||
| <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} ></div> | ||
| </div> | ||
| ))} | ||
| </div>, | ||
| ); | ||
| }; | ||
|
|
||
| export default ConnectPanel; | ||
| 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 | |
| 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', | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议使用设计令牌而不是硬编码颜色 建议使用设计令牌中的颜色值而不是硬编码的 - background: '#fafaff',
+ background: token.colorBgLayout,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| 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', | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议使用设计令牌中的文本颜色 建议使用设计令牌中的文本颜色而不是硬编码的 - color: '#666',
+ color: token.colorTextSecondary,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| fontSize: 22, | ||||||||
| }, | ||||||||
| }, | ||||||||
| }; | ||||||||
| }; | ||||||||
|
|
||||||||
| export function useStyle(prefixCls: string): UseStyleResult { | ||||||||
| return useAntdStyle('ConnectPanel', (token) => { | ||||||||
| const panelToken: ConnectPanelToken = { | ||||||||
| ...token, | ||||||||
| componentCls: `.${prefixCls}`, | ||||||||
| }; | ||||||||
| return [genConnectPanelStyle(panelToken)]; | ||||||||
| }); | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修复无障碍访问问题
卡片元素缺少键盘事件支持,这会影响键盘导航用户的体验。根据静态分析工具的建议,需要添加键盘事件处理。
<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
🧰 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