Skip to content

Commit ca95dc1

Browse files
authored
feat: add custom button (#1506)
* feat: add custom button * chore: add changeset
1 parent 64d8356 commit ca95dc1

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

.changeset/cool-ghosts-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ant-design/web3': minor
3+
---
4+
5+
feat: add custom connect button

packages/web3/src/connect-button/connect-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const ConnectButton: React.FC<ConnectButtonProps> = (props) => {
4747
addressPrefix: addressPrefixProp,
4848
sign,
4949
signBtnTextRender,
50+
children,
5051
...restProps
5152
} = props;
5253
const intl = useIntl('ConnectButton', locale);
@@ -60,7 +61,7 @@ export const ConnectButton: React.FC<ConnectButtonProps> = (props) => {
6061

6162
const { coverAddress = true } = typeof balance !== 'object' ? { coverAddress: true } : balance;
6263
const needSign = !!(sign?.signIn && account?.status === ConnectStatus.Connected && account);
63-
let buttonText: React.ReactNode = intl.getMessage(intl.messages.connect);
64+
let buttonText: React.ReactNode = children || intl.getMessage(intl.messages.connect);
6465
if (account) {
6566
buttonText = (
6667
<>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ArrowRightOutlined } from '@ant-design/icons';
2+
import { ConnectButton } from '@ant-design/web3';
3+
import { EthereumCircleColorful } from '@ant-design/web3-icons';
4+
import { Flex, Space } from 'antd';
5+
6+
const App: React.FC = () => {
7+
return (
8+
<ConnectButton
9+
style={{
10+
height: 60,
11+
borderRadius: 12,
12+
}}
13+
>
14+
<Flex justify="space-between">
15+
<Space size={8}>
16+
<EthereumCircleColorful />
17+
<Flex vertical gap={4} align="start" style={{ width: 200 }}>
18+
<div>Ethereum</div>
19+
<div style={{ opacity: 0.25 }}>Connect to this network</div>
20+
</Flex>
21+
</Space>
22+
<ArrowRightOutlined style={{ opacity: 0.25 }} />
23+
</Flex>
24+
</ConnectButton>
25+
);
26+
};
27+
28+
export default App;

packages/web3/src/connect-button/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ After configuring the `quickConnect` property, the installed wallets and univers
5757

5858
<code src="./demos/balance.tsx"></code>
5959

60+
## Custom Button
61+
62+
<code src="./demos/customButton.tsx"></code>
63+
6064
## API
6165

6266
| Property | Description | Type | Default | Version |

packages/web3/src/connect-button/index.zh-CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ coverDark: https://mdn.alipayobjects.com/huamei_mutawc/afts/img/A*S4cyQ7OCxDUAAA
5858

5959
<code src="./demos/balance.tsx"></code>
6060

61+
## 自定义按钮内容
62+
63+
<code src="./demos/customButton.tsx"></code>
64+
6165
## API
6266

6367
| 属性 | 描述 | 类型 | 默认值 | 版本 |

0 commit comments

Comments
 (0)