From d153da0e0ebe485d3e8a65e348f446faf661da2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kiner-tang=28=E6=96=87=E8=BE=89=29?= <1127031143@qq.com> Date: Sun, 19 Nov 2023 19:29:18 +0800 Subject: [PATCH 1/7] feat: Support tooltip --- .../connect-button/__tests__/index.test.tsx | 37 ++++++++++++++++ .../src/connect-button/connect-button.tsx | 42 +++++++++++++++++-- .../web3/src/connect-button/demos/tooltip.tsx | 14 +++++++ packages/web3/src/connect-button/index.md | 21 ++++++++++ .../web3/src/connect-button/index.zh-CN.md | 21 ++++++++++ packages/web3/src/connect-button/interface.ts | 2 +- packages/web3/src/connect-button/tooltip.tsx | 24 ++++++++++- 7 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 packages/web3/src/connect-button/demos/tooltip.tsx diff --git a/packages/web3/src/connect-button/__tests__/index.test.tsx b/packages/web3/src/connect-button/__tests__/index.test.tsx index e8c4dad96..f02a864d8 100644 --- a/packages/web3/src/connect-button/__tests__/index.test.tsx +++ b/packages/web3/src/connect-button/__tests__/index.test.tsx @@ -6,4 +6,41 @@ describe('ConnectButton', () => { it('mount correctly', () => { expect(() => render()).not.toThrow(); }); + it('display tooltip', () => { + const { baseElement } = render( + , + ); + expect(baseElement.querySelector('.ant-tooltip')).not.toBeNull(); + expect(baseElement.querySelector('.ant-tooltip-inner')?.textContent).toBe('0x3ea2cf...097c18'); + expect(baseElement.querySelector('.anticon-copy')).not.toBeNull(); + }); + it('disabled copyable in tooltip', () => { + const { baseElement } = render( + , + ); + expect(baseElement.querySelector('.ant-tooltip')).not.toBeNull(); + expect(baseElement.querySelector('.ant-tooltip-inner')?.textContent?.trim()).toBe( + '0x3ea2cf...097c18', + ); + expect(baseElement.querySelector('.anticon-copy')).toBeNull(); + }); + it('custom title in tooltip', () => { + const { baseElement } = render( + , + ); + expect(baseElement.querySelector('.ant-tooltip')).not.toBeNull(); + expect(baseElement.querySelector('.ant-tooltip-inner')?.textContent?.trim()).toBe( + 'aaaaaabbbbbbcccccc', + ); + }); + it('should not display tooltip when not custom title and without address in tooltip', () => { + const { baseElement } = render(); + expect(baseElement.querySelector('.ant-tooltip')).toBeNull(); + }); }); diff --git a/packages/web3/src/connect-button/connect-button.tsx b/packages/web3/src/connect-button/connect-button.tsx index 96500996e..d344c4d3d 100644 --- a/packages/web3/src/connect-button/connect-button.tsx +++ b/packages/web3/src/connect-button/connect-button.tsx @@ -1,7 +1,8 @@ import React from 'react'; import { Button, Dropdown } from 'antd'; import { Address } from '../address'; -import type { ConnectButtonProps } from './interface'; +import type { ConnectButtonProps, ConnectButtonTooltipProps } from './interface'; +import { ConnectButtonTooltip } from './tooltip'; export const ConnectButton: React.FC = (props) => { const { @@ -12,6 +13,8 @@ export const ConnectButton: React.FC = (props) => { chains, currentChain, onSwitchChain, + tooltip, + ...restProps } = props; const buttonProps = { @@ -28,11 +31,13 @@ export const ConnectButton: React.FC = (props) => { } }, children: connected ?
: 'Connect Wallet', - ...props, + ...restProps, }; + let content =