Skip to content

Commit

Permalink
feat: optimize connect-modal theme token (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang authored Nov 25, 2023
1 parent 4f3fd45 commit 1697927
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 25 deletions.
12 changes: 3 additions & 9 deletions packages/web3/src/connect-modal/demos/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConnectModal } from '@ant-design/web3';
import { Button, ConfigProvider } from 'antd';
import { Button } from 'antd';
import React from 'react';
import type { DefaultGuide, Wallet } from '../interface';

Expand Down Expand Up @@ -194,13 +194,7 @@ const guide: DefaultGuide = {
const App: React.FC = () => {
const [open, setOpen] = React.useState(false);
return (
<ConfigProvider
theme={{
token: {
// colorPrimary: 'red'
},
}}
>
<>
<Button type="primary" onClick={() => setOpen(true)}>
Open with basic
</Button>
Expand All @@ -213,7 +207,7 @@ const App: React.FC = () => {
onOpenChange={setOpen}
guide={guide}
/>
</ConfigProvider>
</>
);
};

Expand Down
220 changes: 220 additions & 0 deletions packages/web3/src/connect-modal/demos/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import { ConnectModal } from '@ant-design/web3';
import { Button, ConfigProvider } from 'antd';
import React from 'react';
import type { DefaultGuide, Wallet } from '../interface';

const walletList: Wallet[] = [
{
icon: 'https://xsgames.co/randomusers/avatar.php?g=pixel&key=0',
name: '测试钱包',
remark: '备注',
app: {
link: 'https://test.com/xxx',
},
extensions: [
{
key: 'Chrome',
link: 'https://test.com/xxx',
browserIcon:
'https://github.com/ant-design/ant-design/assets/10286961/0d4e4ac7-8f89-4147-a06a-de72c02e85cb',
browserName: 'Chrome',
description: 'Access your wallet right from your favorite web browser.',
},
{
key: 'Firefox',
link: 'https://test.com/xxx',
browserIcon:
'https://github.com/ant-design/ant-design/assets/10286961/a6559d9b-d20a-4ac7-a263-53c04b9038a4',
browserName: 'Firefox',
description: 'Access your wallet right from your favorite web browser.',
},
],
group: 'Popular',
},
{
icon: 'https://xsgames.co/randomusers/avatar.php?g=pixel&key=1',
name: '测试钱包2',
remark: '备注2',
app: {
link: 'https://test.com/xxx',
},
extensions: [
{
key: 'Firefox',
link: 'https://test.com/xxx',
browserIcon:
'https://github.com/ant-design/ant-design/assets/10286961/a6559d9b-d20a-4ac7-a263-53c04b9038a4',
browserName: 'Firefox',
description: 'Access your wallet right from your favorite web browser.',
},
],
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://xsgames.co/randomusers/avatar.php?g=pixel&key=3',
name: '测试钱包3',
remark: '备注3',
group: 'Popular',
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,
),
);
},
},
{
name: '测试钱包4',
remark: '备注4',
extensions: [
{
key: 'Safari',
link: 'https://test.com/xxx',
browserIcon:
'https://github.com/ant-design/ant-design/assets/10286961/9d56eba7-84d7-4360-b013-bf57d419b058',
browserName: 'Safari',
description: 'Access your wallet right from your favorite web browser.',
},
],
},
{
name: '测试钱包5',
remark: '备注5',
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,
),
);
},
},
{
name: '测试钱包6',
remark: '备注6',
key: 6,
app: {
link: 'https://test.com/xxx',
},
extensions: [
{
key: 'Chrome',
link: 'https://test.com/xxx',
browserIcon:
'https://github.com/ant-design/ant-design/assets/10286961/0d4e4ac7-8f89-4147-a06a-de72c02e85cb',
browserName: 'Chrome',
description: 'Access your wallet right from your favorite web browser.',
},
],
},
{
name: '测试钱包6',
remark: '备注6',
key: 7,
app: {
link: 'https://test.com/xxx',
},
extensions: [
{
key: 'Chrome',
link: 'https://test.com/xxx',
browserIcon:
'https://github.com/ant-design/ant-design/assets/10286961/0d4e4ac7-8f89-4147-a06a-de72c02e85cb',
browserName: 'Chrome',
description: 'Access your wallet right from your favorite web browser.',
},
],
},
];
const groupOrder = (a: string, b: string) => {
if (a === 'Popular') return -1;
if (b === 'Popular') return 1;
return a.localeCompare(b);
};
const guide: DefaultGuide = {
title: 'What is a Wallet?',
infos: [
{
title: 'A Home for your Digital Assets',
description:
'Wallets are used to send, receive, store, and display digital assets like Ethereum and NFTs.',
icon: 'https://xsgames.co/randomusers/avatar.php?g=pixel&key=4',
},
{
title: 'A New Way to Log In',
description:
'Instead of creating new accounts and passwords on every website, just connect your wallet.',
icon: 'https://xsgames.co/randomusers/avatar.php?g=pixel&key=5',
},
{
title: 'A New Way to Log In2',
description:
'Instead of creating new accounts and passwords on every website, just connect your wallet.',
icon: 'https://xsgames.co/randomusers/avatar.php?g=pixel&key=5',
},
{
title: 'A New Way to Log In3',
description:
'Instead of creating new accounts and passwords on every website, just connect your wallet.',
icon: 'https://xsgames.co/randomusers/avatar.php?g=pixel&key=5',
},
],
moreLink: 'https://test.com/xxx',
};

const App: React.FC = () => {
const [open, setOpen] = React.useState(false);
return (
<ConfigProvider
theme={{
token: {
colorPrimary: '#660066',
},
}}
>
<Button type="primary" onClick={() => setOpen(true)}>
Open with basic
</Button>
<ConnectModal
open={open}
title="Connect Wallet"
footer="蚂蚁链提供技术支持"
groupOrder={groupOrder}
walletList={walletList}
onOpenChange={setOpen}
guide={guide}
/>
</ConfigProvider>
);
};

export default App;
4 changes: 4 additions & 0 deletions packages/web3/src/connect-modal/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Connect wallet modal, used with ConnectButton to complete the wallet connection

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

## Custom Theme Color

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

## API

### ConnectModalProps
Expand Down
4 changes: 4 additions & 0 deletions packages/web3/src/connect-modal/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ group: 组件

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

## 自定义主题色

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

## API

### ConnectModalProps
Expand Down
40 changes: 24 additions & 16 deletions packages/web3/src/connect-modal/style/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ComponentToken {

export interface ConnectModalToken extends Web3AliasToken {
// Custom token here
selectedBg: string;
selectedColor: string;
hoverBg: string;
splitColor: string;
Expand Down Expand Up @@ -56,6 +57,7 @@ const resetStyle = (token: ConnectModalToken): CSSInterpolation => {

const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
const { web3ComponentsCls: componentCls } = token;
const isDark = isDarkTheme(token);
return [
{
[`${componentCls}`]: {
Expand Down Expand Up @@ -149,9 +151,9 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
background: token.hoverBg,
},
'&.selected': {
background: token.selectedColor,
background: token.selectedBg,
[`${componentCls}-name`]: {
color: token.colorText,
color: token.selectedColor,
},
},
},
Expand Down Expand Up @@ -230,21 +232,23 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
},
[`${componentCls}-get-btn`]: {
borderRadius: 8,
background: token.colorText,
color: token.colorBgContainer,
background: isDark
? new TinyColor(token.colorWhite).setAlpha(0.15).toRgbString()
: token.colorPrimary,
color: token.colorTextLightSolid,
opacity: 0.8,
['&:hover']: {
background: token['blue-6'],
borderColor: token['blue-6'],
color: token.colorWhite,
opacity: 1,
},
},
[`${componentCls}-more`]: {
color: token.colorText,
fontSize: token.fontSizeLG,
textAlign: 'center',
marginBlockStart: 16,
opacity: 0.8,
['&:hover']: {
color: token['blue-6'],
opacity: 1,
},
},
[`${componentCls}-get-wallet-panel`]: {
Expand Down Expand Up @@ -274,8 +278,8 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
lineHeight: 0,
fontSize: token.fontSizeLG,
['&:hover']: {
borderColor: token['blue-6'],
color: token['blue-6'],
borderColor: isDark ? token.colorWhite : token.colorPrimary,
color: isDark ? token.colorWhite : token.colorPrimary,
},
},
},
Expand All @@ -289,7 +293,7 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
textAlign: 'center',
h3: {
fontSize: token.fontSizeLG,
color: token.colorPrimary,
color: token.colorText,
marginBlockEnd: 16,
},
p: {
Expand All @@ -316,7 +320,7 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
border: `1px solid transparent`,
transition: 'border-color .3s',
'&:hover': {
borderColor: token.selectedColor,
borderColor: isDark ? token.colorWhite : token.colorPrimary,
},
[`${componentCls}-card-icon`]: {
width: 64,
Expand Down Expand Up @@ -366,8 +370,8 @@ const getThemeStyle = (token: ConnectModalToken): CSSInterpolation => {
height: 40,
lineHeight: 0,
['&:hover']: {
borderColor: token['blue-6'],
color: token['blue-6'],
borderColor: isDark ? token.colorWhite : token.colorPrimary,
color: isDark ? token.colorWhite : token.colorPrimary,
},
},
},
Expand Down Expand Up @@ -412,8 +416,12 @@ export function useStyle(prefixCls: string) {
return useAntdStyle('ConnectModal', (token) => {
const isDark = isDarkTheme(token);
const connectModalToken: ConnectModalToken = mergeToken<ConnectModalToken>(token, {
selectedColor: new TinyColor(token['blue-6']).toRgbString(),
hoverBg: new TinyColor(token.colorText).setAlpha(0.06).toRgbString(),
selectedBg: isDark ? token.colorWhite : token.colorPrimary,
selectedColor: token.colorBgContainer,
hoverBg: new TinyColor(isDark ? token.colorWhite : token.colorPrimary)
.setAlpha(0.1)
.onBackground(token.colorBgContainer)
.toRgbString(),
splitColor: new TinyColor(token.colorText).setAlpha(0.06).toRgbString(),
modalTitleStartColor: isDark ? token.colorWhite : '#1677ff',
modalTitleEndColor: new TinyColor('#000')
Expand Down

0 comments on commit 1697927

Please sign in to comment.