Skip to content

Commit

Permalink
docs: The document of ConnectModal (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang authored Oct 6, 2023
1 parent dba369e commit c789b1e
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 9 deletions.
58 changes: 57 additions & 1 deletion packages/web3/src/ConnectModal/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ group:

# ConnectModal

TODO
Connect wallet modal, used with ConnectButton to complete the wallet connection process.

## Basic Usage

Expand All @@ -18,3 +18,59 @@ TODO
## Dark Mode

<code src="./demos/dark.tsx"></code>

## API

### ConnectModalProps

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| title | The title of ConnectModal, same as Modal's title | `ModalProps['title']` | - | - |
| theme | The theme of ConnectModal | `'dark' \| 'light'` | 'light' | - |
| open | Whether the modal is visible, same as Modal's open | `ModalProps['open']` | - | - |
| onOpenChange | Callback when the modal visibility changes | `(open: boolean) => void` | - | - |
| onSelectWallet | Callback when the wallet is selected | `(wallet: Wallet) => void` | - | - |
| modalProps | Pass through the props of Modal | `ModalProps` | - | - | - |
| prefixCls | Class prefix | `string` | - | - |
| footer | Custom footer | `React.ReactNode` | - | - |
| walletList | Wallet list | `Wallet[]` | - | - |
| groupOrder | Wallet group sorting function | `(a: string, b: string) => number` | - | - |
| guide | Newbie guide panel | `false \| null` | [DefaultGuide](#defaultguide) | - |

### Wallet

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| name | Wallet name | `string` | - | - |
| icon | Wallet icon | `string \| React.ReactNode` | - | - |
| remark | Wallet description | `string` | - | - |
| key | Wallet key | `React.Key` | - | - |
| extensions | List of browser extensions supported by the wallet | `false` \| [ExtensionItem](#extensionitem)\[] | - | - |
| app | Whether the wallet supports APP calls | `false \| { link: string }` | - | - |
| group | Wallet group name | `string` | - | - |

### ExtensionItem

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| link | Link to browser extension | `string` | - | - |
| key | Browser extension key | `'Chrome' \| 'Firefox' \| 'Edge' \| 'Safari' \| (string & {})` | - | - |
| browserIcon | Browser icon | `string` | - | - |
| browserName | Browser extension name | `string` | - | - |
| description | Description of browser extension | `string` | - | - |

### DefaultGuide

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| title | Guide title | `string` | - | - |
| infos | Guide info list | [GuideInfo](#guideinfo)\[] | - | - |
| moreLink | More link | `string` | - | - |

### GuideInfoItem

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| title | The title of the information item of the newbie guide panel | `string \| React.ReactNode` | - | - |
| icon | The icon of the information item of the newbie guide panel | `string \| React.ReactNode` | - | - |
| description | The description of the information item of the newbie guide panel | `string \| React.ReactNode` | - | - |
9 changes: 5 additions & 4 deletions packages/web3/src/ConnectModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const ConnectModal: React.FC<ConnectModalProps> = (props) => {
guide,
onSelectWallet,
theme = 'light',
className,
} = props;
const { getPrefixCls } = React.useContext(ConfigContext);
const [selectedWallet, setSelectedWallet] = React.useState<Wallet>();
Expand Down Expand Up @@ -74,13 +75,13 @@ export const ConnectModal: React.FC<ConnectModalProps> = (props) => {
<Modal
{...modalProps}
width={guide ? 737 : 380}
maskClosable={false}
className={classNames(prefixCls, `${prefixCls}-${theme}`)}
rootClassName={`${prefixCls}-root`}
className={classNames(prefixCls, `${prefixCls}-${theme}`, className)}
rootClassName={classNames(`${prefixCls}-root`, modalProps?.rootClassName)}
open={open}
closeIcon={<CloseCircleFilled />}
onCancel={() => {
onCancel={(e) => {
onOpenChange?.(false);
modalProps?.onCancel?.(e);
}}
footer={null}
>
Expand Down
62 changes: 61 additions & 1 deletion packages/web3/src/ConnectModal/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ group:

# ConnectModal

TODO
连接钱包弹窗,与 ConnectButton 配合使用完成钱包的链接流程。

## 基本使用

Expand All @@ -18,3 +18,63 @@ TODO
## 暗黑模式

<code src="./demos/dark.tsx"></code>

## API

### ConnectModalProps

| 属性 | 描述 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| title | ConnectModal 的标题,与 Modal 的 title 类型相同 | `ModalProps['title']` | - | - |
| theme | ConnectModal 的主题 | `'dark' \| 'light'` | 'light' | - |
| open | 弹框是否展示,与 Modal 的 open 类型相同 | `ModalProps['open']` | - | - |
| onOpenChange | 弹框可见性改变回调 | `(open: boolean) => void` | - | - |
| onSelectWallet | 选中钱包回调 | `(wallet: Wallet) => void` | - | - |
| modalProps | 透传 Modal 的 props | `ModalProps` | - | - | - |
| prefixCls | class 前缀 | `string` | - | - |
| footer | 自定义 footer | `React.ReactNode` | - | - |
| walletList | 钱包列表 | `Wallet[]` | - | - |
| groupOrder | 钱包分组排序函数 | `(a: string, b: string) => number` | - | - |
| guide | 新手指引面板 | `false \| null` | [DefaultGuide](#defaultguide) | - |
| className | 自定义类名 | `string` | - | - |

### Wallet

| 属性 | 描述 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| name | 钱包名称 | `string` | - | - |
| icon | 钱包图标 | `string \| React.ReactNode` | - | - |
| remark | 钱包简介 | `string` | - | - |
| key | 钱包 Key | `React.Key` | - | - |
| extensions | 该钱包支持的浏览器扩展程序列表 | `false` \| [ExtensionItem](#extensionitem)\[] | - | - |
| app | 该钱包是否支持 APP 调用 | `false \| { link: string }` | - | - |
| group | 钱包所属分组名称 | `string` | - | - |


### ExtensionItem

| 属性 | 描述 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| link | 浏览器扩展程序链接 | `string` | - | - |
| key | 浏览器扩展程序 Key | `'Chrome' \| 'Firefox' \| 'Edge' \| 'Safari' \| (string & {})` | - | - |
| browserIcon | 浏览器图标 | `string` | - | - |
| browserName | 浏览器扩展程序名称 | `string` | - | - |
| description | 浏览器扩展程序的描述 | `string` | - | - |


### DefaultGuide

| 属性 | 描述 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| title | 新手指引面板的标题 | `string` | - | - |
| infos | 新手指引面板的信息列表 | [GuideInfoItem](#guideinfoitem)\[] | - | - |
| moreLink | 新手指引面板的更多链接 | `string` | - | - |

### GuideInfoItem

| 属性 | 描述 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| title | 新手指引面板的信息项标题 | `string \| React.ReactNode` | - | - |
| icon | 新手指引面板的信息项图标 | `string \| React.ReactNode` | - | - |
| description | 新手指引面板的信息项描述 | `string \| React.ReactNode` | - | - |

153 changes: 150 additions & 3 deletions packages/web3/src/ConnectModal/interface.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,203 @@
import type React from 'react';
import type { ModalProps } from 'antd';

/**
* @desc 浏览器扩展程序信息
*/
export type ExtensionItem = {
/**
* @desc 支持的浏览器的 key
* @descEn The key of the supported browser
*/
key: 'Chrome' | 'Firefox' | 'Edge' | 'Safari' | (string & {});
/**
* @desc 浏览器扩展程序的链接
* @descEn Link to browser extension
*/
link: string;
/**
* @desc 浏览器扩展程序的图标
* @descEn Icon of browser extension
*/
browserIcon: string;
/**
* @desc 浏览器扩展程序的名称
* @descEn Name of browser extension
*/
browserName: string;
/**
* @desc 浏览器扩展程序的描述
* @descEn Description of browser extension
*/
description: string;
};

/**
* @desc 钱包
* @descEn Wallet
*/
export type Wallet = {
/**
* @desc 钱包名称
* @descEn Wallet name
*/
name: string;
/**
* @desc 钱包简介
* @descEn Wallet introduction
*/
remark: string;
/**
* @desc 钱包的 key
* @descEn The key of Wallet
*/
key?: React.Key;
/**
* @desc 钱包图标
* @descEn Wallet icon
*/
icon?: string | React.ReactNode;
/**
* @desc 该钱包支持的浏览器扩展程序列表
* @descEn The list of browser extensions supported by the wallet
*/
extensions?: false | ExtensionItem[];
/**
* @desc 该钱包是否支持 APP 调用
* @descEn Whether the wallet supports APP calls
*/
app?:
| false
| {
link: string;
};
/**
* @desc 钱包所属分组名称
* @descEn The name of the group to which the wallet belongs
*/
group?: string;
};

/**
* @desc 新手指引面板的信息项
* @descEn Information items of the newbie guide panel
*/
export type GuideInfoItem = {
/**
* @desc 新手指引面板的信息项标题
* @descEn The title of the information item of the newbie guide panel
*/
title: string | React.ReactNode;
/**
* @desc 新手指引面板的信息项图标
* @descEn The icon of the information item of the newbie guide panel
*/
icon: string | React.ReactNode;
/**
* @desc 新手指引面板的信息项描述
* @descEn The description of the information item of the newbie guide panel
*/
description: string | React.ReactNode;
};

/**
* @desc 新手指引面板
* @descEn Newbie guide panel
*/
export type DefaultGuide = {
/**
* @desc 新手指引面板的标题
* @descEn The title of the newbie guide panel
*/
title: string;
/**
* @desc 新手指引面板的信息列表
* @descEn Information list of the newbie guide panel
*/
infos: GuideInfoItem[];
/**
* @desc 新手指引面板的更多链接
* @descEn More links to the newbie guide panel
*/
moreLink: string;
};

export type Theme = 'dark' | 'light';

export type ConnectModalProps = {
/**
* @desc ConnectModal 的标题,与 Modal 的 title 类型相同
* @descEn The title of ConnectModal, the same as Modal's title type
*/
title?: ModalProps['title'];
theme?: 'dark' | 'light';
/**
* @desc ConnectModal 的主题
* @descEn The theme of ConnectModal
* @default 'light'
*/
theme?: Theme;
/**
* @desc 弹框是否展示,与 Modal 的 open 类型相同
* @descEn Whether the Modal is displayed, the same as the Modal's open type
*/
open: ModalProps['open'];
/**
* @desc 弹框可见性改变回调
* @descEn Callback when the Modal visibility changes
* @param open 弹框是否展示
*/
onOpenChange?: (open: boolean) => void;
/**
* @desc 选中钱包回调
* @descEn Callback when the wallet is selected
* @param wallet 选中的钱包
* @paramEn Selected wallet
* @returns
*/
onSelectWallet?: (wallet: Wallet) => void;
/**
* @desc 透传 Modal 的 props,需要注意的是以下属性将会被内部逻辑覆盖,配置不生效。
* - title
* - open
* - onOpenChange
* @descEn Pass through the props of Modal. Note that the following attributes will be overwritten by internal logic and the configuration will not take effect.
*/
modalProps?: ModalProps;
/**
* @desc class 前缀
* @descEn Class prefix
*/
prefixCls?: string;
/**
* @desc 自定义 footer
* @descEn Custom footer
*/
footer?: React.ReactNode;
/**
* @desc 钱包列表
* @descEn Wallet list
*/
walletList?: Wallet[];
/**
* @desc 钱包分组排序函数
* @descEn Wallet group sorting function
* @param a groupName1
* @param b groupName2
* @returns
*/
groupOrder?: (a: string, b: string) => number;
/**
* @desc 新手指引面板
* @descEn Newbie guide panel
*/
guide?: false | null | DefaultGuide;
/**
* @desc 自定义类名
* @descEn Custom class name
*/
className?: string;
};

export type PanelRoute = 'guide' | 'getWallet' | 'wallet' | 'qrCode';

export type MainPanelProps = Pick<ConnectModalProps, 'guide' | 'walletList'>;

export type Theme = 'dark' | 'light';

0 comments on commit c789b1e

Please sign in to comment.