-
Notifications
You must be signed in to change notification settings - Fork 168
fix: When a wireframe token is present, adapt the style of the connect-modal accordingly. #1441
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
Open
maskboys
wants to merge
3
commits into
ant-design:main
Choose a base branch
from
maskboys:fix/connect-modal-style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ant-design/web3': patch | ||
--- | ||
|
||
fix: When a wireframe token is present, adapt the style of the connect-modal accordingly. |
80 changes: 80 additions & 0 deletions
80
packages/web3/src/connect-modal/__tests__/wireframe.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { ConnectModal } from '@ant-design/web3'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { theme as antTheme, ConfigProvider } from 'antd'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { groupOrder, walletList } from './mock'; | ||
|
||
describe('ConnectModal without guide', () => { | ||
it.each(['light', 'dark'] as const)('should render in %s mode', async (theme) => { | ||
const App = () => ( | ||
<ConfigProvider | ||
theme={{ | ||
algorithm: theme === 'light' ? antTheme.defaultAlgorithm : antTheme.darkAlgorithm, | ||
token: { | ||
wireframe: true, | ||
}, | ||
}} | ||
> | ||
<ConnectModal | ||
open | ||
title="ConnectModal" | ||
footer="Powered by AntChain" | ||
group={{ | ||
groupOrder, | ||
}} | ||
walletList={walletList} | ||
/> | ||
</ConfigProvider> | ||
); | ||
const { baseElement } = render(<App />); | ||
expect(baseElement).toMatchSnapshot(); | ||
const headerStyle = window.getComputedStyle( | ||
baseElement.querySelector('.ant-web3-connect-modal-header')!, | ||
); | ||
// header have borderBlockEnd & paddingBlockEnd | ||
expect(headerStyle.borderBlockEnd).toBe('1px solid rgba(0, 0, 0, 0.06)'); | ||
expect(headerStyle.paddingBlockEnd).toBe('16px'); | ||
|
||
// should have ant-web3-connect-modal class | ||
expect(baseElement.querySelector('.ant-modal')?.className).toContain('ant-web3-connect-modal'); | ||
// should have simple class when without guide | ||
expect(baseElement.querySelector('.ant-web3-connect-modal-body')?.className).toContain( | ||
'simple', | ||
); | ||
|
||
// should have title and footer | ||
expect(baseElement.querySelector('.ant-web3-connect-modal-title')?.textContent).toBe( | ||
'ConnectModal', | ||
); | ||
expect(baseElement.querySelector('.ant-web3-connect-modal-footer')?.textContent).toBe( | ||
'Powered by AntChain', | ||
); | ||
|
||
// group order | ||
expect(baseElement.querySelectorAll('.ant-web3-connect-modal-group-title')[0].textContent).toBe( | ||
'Popular', | ||
); | ||
expect(baseElement.querySelectorAll('.ant-web3-connect-modal-group-title')[1].textContent).toBe( | ||
'More', | ||
); | ||
|
||
// wallet list items | ||
expect(baseElement.querySelectorAll('.ant-web3-connect-modal-wallet-item').length).toBe( | ||
walletList.length, | ||
); | ||
}); | ||
it('render with mode simple', async () => { | ||
const App = () => ( | ||
<ConnectModal open groupOrder={groupOrder} walletList={walletList} mode="simple" /> | ||
); | ||
const { baseElement } = render(<App />); | ||
const btn = baseElement.querySelector('.ant-web3-connect-modal-simple-guide-right'); | ||
fireEvent.click(btn!); | ||
await vi.waitFor(() => { | ||
expect(baseElement.querySelector('.ant-web3-connect-modal-simple-guide-panel')).not.toBe( | ||
null, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import type { ConnectModalProps } from '@ant-design/web3'; | ||
import { ConnectModal } from '@ant-design/web3'; | ||
import { metadata_MetaMask, metadata_WalletConnect } from '@ant-design/web3-assets'; | ||
import { Button, ConfigProvider } from 'antd'; | ||
|
||
import type { Wallet } from '../interface'; | ||
|
||
const walletList: Wallet[] = [ | ||
metadata_MetaMask, | ||
{ | ||
...metadata_WalletConnect, | ||
getQrCode: () => { | ||
return new Promise<{ | ||
uri: string; | ||
}>((resolve) => | ||
setTimeout( | ||
() => | ||
resolve({ | ||
uri: `https://ant.design/docs/react/migrate-less-variables-cn#avatar-%E5%A4%B4%E5%83%8F?timestamp=${Date.now()}&random=${Math.random()}`, | ||
}), | ||
2000, | ||
), | ||
); | ||
}, | ||
}, | ||
{ | ||
icon: 'https://mdn.alipayobjects.com/huamei_mutawc/afts/img/A*8LhqSZ_KatsAAAAAAAAAAAAAelrGAQ/fmt.webp', | ||
name: 'Test Wallet3', | ||
remark: 'remark 3', | ||
app: { | ||
link: 'https://test.com/xxx', | ||
}, | ||
getQrCode: () => { | ||
return new Promise<{ | ||
uri: string; | ||
}>((resolve) => | ||
setTimeout( | ||
() => | ||
resolve({ | ||
uri: `https://ant.design/docs/react/migrate-less-variables-cn#avatar-%E5%A4%B4%E5%83%8F?timestamp=${Date.now()}&random=${Math.random()}`, | ||
}), | ||
2000, | ||
), | ||
); | ||
}, | ||
}, | ||
]; | ||
const groupOrder = (a: string, b: string) => { | ||
if (a === 'Popular') return -1; | ||
if (b === 'Popular') return 1; | ||
return a.localeCompare(b); | ||
}; | ||
|
||
const App: React.FC<ConnectModalProps> = (props) => { | ||
const [open, setOpen] = React.useState(false); | ||
|
||
return ( | ||
<> | ||
<Button type="primary" onClick={() => setOpen(true)}> | ||
Open with simple | ||
</Button> | ||
<ConfigProvider | ||
theme={{ | ||
token: { | ||
wireframe: true, | ||
}, | ||
}} | ||
> | ||
<ConnectModal | ||
open={open} | ||
group={{ | ||
groupOrder, | ||
}} | ||
walletList={walletList} | ||
onCancel={() => setOpen(false)} | ||
mode="simple" | ||
{...props} | ||
/> | ||
</ConfigProvider> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ const resetStyle = (token: ConnectModalToken): CSSInterpolation => { | |
'.ant-modal-content': { | ||
padding: 0, | ||
}, | ||
'.ant-modal-body': { | ||
padding: 0, | ||
}, | ||
'.ant-list-split .ant-list-item': { | ||
borderBlockEnd: 'none', | ||
}, | ||
|
@@ -92,6 +95,8 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => { | |
[`${componentCls}-header`]: { | ||
paddingInline: token.paddingMD, | ||
height: 30, | ||
borderBlockEnd: token.wireframe ? '1px solid rgba(0, 0, 0, 0.06)' : 'none', | ||
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.
|
||
paddingBlockEnd: token.wireframe ? '16px' : 0, | ||
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. padding 的置也应该用 antd 的 token,看看能不能用 padding |
||
}, | ||
[`${componentCls}-list`]: { | ||
display: 'flex', | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里是不是改错了?