-
Notifications
You must be signed in to change notification settings - Fork 186
chore: support theme-editor #664
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a9edb10
docs(site): add theme editor
jeasonstudio 92d972a
feat: use previewer
jeasonstudio 2797c1f
Merge branch 'main' into feat-support-theme-editor
jeasonstudio 4b1d385
chore: update lock file
jeasonstudio aa1b6cf
Merge branch 'main' into feat-support-theme-editor
jeasonstudio 853d44c
chore: fix review comments
jeasonstudio 5897533
chore(docs): remove antd components
jeasonstudio 050a946
Merge branch 'main' into feat-support-theme-editor
jeasonstudio b195856
chore: use special demos
jeasonstudio 2a8e0cb
chore: add footer link
jeasonstudio 05928dc
chore: rm useless locale
jeasonstudio 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 @@ | ||
| --- | ||
| sidebar: false | ||
| --- | ||
|
|
||
| <ThemeEditorPage></ThemeEditorPage> |
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 @@ | ||
| --- | ||
| sidebar: false | ||
| --- | ||
|
|
||
| <ThemeEditorPage></ThemeEditorPage> |
31 changes: 31 additions & 0 deletions
31
.dumi/theme/builtins/ThemeEditorPage/demos/connect-button.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,31 @@ | ||
| import React from 'react'; | ||
| import { ConnectButton, type Chain } from '@ant-design/web3'; | ||
| import { Mainnet, Polygon } from '@ant-design/web3-assets'; | ||
| import { Space } from 'antd'; | ||
| import type { ComponentDemo } from 'antd-token-previewer-web3'; | ||
|
|
||
| const Demo = () => { | ||
| const [chain, setChain] = React.useState<Chain>(Polygon); | ||
|
|
||
| return ( | ||
| <Space> | ||
| <ConnectButton account={{ address: '3ea2cfd153b8d8505097b81c87c11f5d05097c18' }} tooltip /> | ||
| <ConnectButton | ||
| chain={chain} | ||
| availableChains={[Mainnet, Polygon]} | ||
| account={{ address: '3ea2cfd153b8d8505097b81c87c11f5d05097c18' }} | ||
| onSwitchChain={async (c) => { | ||
| setChain(c); | ||
| }} | ||
| /> | ||
| </Space> | ||
| ); | ||
| }; | ||
|
|
||
| const componentDemo: ComponentDemo = { | ||
| demo: <Demo />, | ||
| tokens: ['blue'], | ||
| key: 'Connect Button', | ||
| }; | ||
|
|
||
| export default componentDemo; |
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,7 @@ | ||
| import { ComponentDemo } from 'antd-token-previewer-web3'; | ||
|
|
||
| import ConnectButton from './connect-button'; | ||
|
|
||
| const previewerDemo: ComponentDemo[] = [ConnectButton]; | ||
|
|
||
| export default previewerDemo; |
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,8 @@ | ||
| .container { | ||
| width: 100%; | ||
| overflow: hidden; | ||
|
|
||
| :global(.previewer-layout) { | ||
| height: 100%; | ||
| } | ||
| } |
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,59 @@ | ||
| import React from 'react'; | ||
| import { ConfigProvider, message } from 'antd'; | ||
| import { | ||
| defaultAntdComponents, | ||
| parsePlainConfig, | ||
| parseThemeConfig, | ||
| Previewer, | ||
| } from 'antd-token-previewer-web3'; | ||
| import { useLocale } from 'dumi'; | ||
|
|
||
| import Connector from './demos'; | ||
|
|
||
| import 'antd/es/style/reset.css'; | ||
|
|
||
| import { useTheme } from 'antd-style'; | ||
| import antdEnUS from 'antd/locale/en_US'; | ||
| import antdZhCN from 'antd/locale/zh_CN'; | ||
|
|
||
| import styles from './index.module.less'; | ||
|
|
||
| const ANT_DESIGN_WEB3_CUSTOM_THEME = 'ant-design-web3-custom-theme'; | ||
|
|
||
| const ThemeEditorPage: React.FC = () => { | ||
| const [messageApi, contextHolder] = message.useMessage(); | ||
| const initialThemeConfigRef = React.useRef( | ||
| parseThemeConfig(JSON.parse(localStorage.getItem(ANT_DESIGN_WEB3_CUSTOM_THEME) || '{}')), | ||
| ); | ||
| const locale = useLocale(); | ||
| const token = useTheme(); | ||
|
|
||
| return ( | ||
| <React.StrictMode> | ||
| {contextHolder} | ||
| <div className={styles.container} style={{ height: `calc(100vh - ${token.headerHeight}px)` }}> | ||
| <ConfigProvider | ||
| locale={locale.id === 'zh-CN' ? antdZhCN : antdEnUS} | ||
| theme={{ hashed: true }} | ||
| > | ||
| <Previewer | ||
| showTheme | ||
| initialThemeConfig={initialThemeConfigRef.current} | ||
| components={{ Web3: ['Connector'], ...defaultAntdComponents }} | ||
| demos={{ Connector }} | ||
| onSave={(newConfig) => { | ||
| localStorage.setItem( | ||
| ANT_DESIGN_WEB3_CUSTOM_THEME, | ||
| JSON.stringify(parsePlainConfig(newConfig)), | ||
| ); | ||
| navigator.clipboard.writeText(JSON.stringify(newConfig, null, 2)); | ||
| messageApi.success('🎉 保存成功,可粘贴到项目中使用!'); | ||
jeasonstudio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }} | ||
| /> | ||
| </ConfigProvider> | ||
| </div> | ||
| </React.StrictMode> | ||
| ); | ||
| }; | ||
|
|
||
| export default ThemeEditorPage; | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Uh oh!
There was an error while loading. Please reload this page.