diff --git a/README.md b/README.md index 5d0855d87..16d761582 100644 --- a/README.md +++ b/README.md @@ -123,4 +123,4 @@ If you would like to test out the current functionality of V2 in a small browser - Checkout the V2 feature branch: `git checkout v2-web3-onboard` - Install the dependencies: `yarn` (if running a M1 mac - `yarn install-m1-mac`) - Run all packages in dev mode: `yarn dev` -- [View demo app in the browser](http://localhost:8080) +- To view the demo app in the browser after running the above steps navigate to [http://localhost:8080](http://localhost:8080) diff --git a/docs/src/lib/components/ThemeCustomizer.svelte b/docs/src/lib/components/ThemeCustomizer.svelte index 23e7c052e..7bbfa90ee 100644 --- a/docs/src/lib/components/ThemeCustomizer.svelte +++ b/docs/src/lib/components/ThemeCustomizer.svelte @@ -18,15 +18,44 @@ rpcUrl: `https://mainnet.infura.io/v3/${INFURA_ID}` }, { - id: '0x3', - token: 'tROP', - label: 'Ethereum Ropsten Testnet', - rpcUrl: `https://ropsten.infura.io/v3/${INFURA_ID}` + id: '0x5', + token: 'ETH', + label: 'Ethereum Goerli Testnet', + rpcUrl: `https://goerli.infura.io/v3/${INFURA_ID}` + }, + { + id: '0x13881', + token: 'MATIC', + label: 'Polygon - Mumbai', + rpcUrl: 'https://matic-mumbai.chainstacklabs.com ' + }, + { + id: '0x38', + token: 'BNB', + label: 'Binance', + rpcUrl: 'https://bsc-dataseed.binance.org/' + }, + { + id: 137, + token: 'MATIC', + label: 'Polygon', + rpcUrl: 'https://matic-mainnet.chainstacklabs.com' + }, + { + id: 10, + token: 'OETH', + label: 'Optimism', + rpcUrl: 'https://mainnet.optimism.io' + }, + { + id: 42161, + token: 'ARB-ETH', + label: 'Arbitrum', + rpcUrl: 'https://rpc.ankr.com/arbitrum' } ], appMetadata: { name: 'Documentation', - icon: '', description: 'Example showcasing how to connect a wallet.', recommendedInjectedWallets: [ { name: 'MetaMask', url: 'https://metamask.io' }, @@ -34,11 +63,15 @@ ] }, accountCenter: { - desktop: { enabled: false }, - mobile: { enabled: false } - } + desktop: { enabled: true }, + mobile: { enabled: true } + }, + theme: 'system' }) + const themes = ['system', 'default', 'light', 'dark', 'custom'] + let selectedTheme = 'system' + // Subscribe to wallet updates const wallets$ = onboard.state.select('wallets').pipe(share()) @@ -73,8 +106,9 @@ uploaded_image = undefined webURL = '' resetTheme() - const onboardCloseBtnVisible = - document?.querySelector('body > onboard-v2')?.shadowRoot?.querySelector('.close-button') + const onboardCloseBtnVisible = document + ?.querySelector('body > onboard-v2') + ?.shadowRoot?.querySelector('.close-button') if (onboardCloseBtnVisible) onboardCloseBtnVisible?.click() } @@ -84,34 +118,43 @@ : onboard.connectWallet() } - const baseStyles = { - '--background-color': '#ffffff', - '--text-color': '#1a1d26', - '--border-color': '#ebebed', - '--accent-background': '#ebebed', - '--accent-color': '#929bed', - '--accent-color-hover': '#eff1fc', - '--secondary-text-color': '#707481' - } - - let defaultStyling = {...baseStyles} - - const baseStyling = `--onboard-connect-sidebar-background: var(--accent-background); - --onboard-close-button-background: var(--accent-background); - --onboard-connect-sidebar-color: var(--text-color); - --onboard-connect-sidebar-progress-background: var(--secondary-text-color); - --onboard-connect-sidebar-progress-color: var(--accent-color); - --onboard-connect-header-background: var(--background-color); - --onboard-connect-header-color: var(--text-color); - --onboard-main-scroll-container-background: var(--background-color); - --onboard-link-color: var(--accent-color); - --onboard-wallet-button-background: var(--background-color); - --onboard-wallet-button-background-hover: var(--accent-color-hover); - --onboard-wallet-button-border-color: var(--border-color); - --onboard-wallet-app-icon-border-color: var(--border-color);` + const themingObjects = { + default: { + '--w3o-background-color': 'unset', + '--w3o-foreground-color': 'unset', + '--w3o-text-color': 'unset', + '--w3o-border-color': 'unset', + '--w3o-action-color': 'unset', + '--w3o-border-radius': 'unset' + }, + custom: { + '--w3o-background-color': 'unset', + '--w3o-foreground-color': 'unset', + '--w3o-text-color': 'unset', + '--w3o-border-color': 'unset', + '--w3o-action-color': 'unset', + '--w3o-border-radius': 'unset' + }, + light: { + '--w3o-background-color': '#ffffff', + '--w3o-foreground-color': '#EFF1FC', + '--w3o-text-color': '#1a1d26', + '--w3o-border-color': '#d0d4f7', + '--w3o-action-color': '#6370E5', + '--w3o-border-radius': '16px' + }, + dark: { + '--w3o-background-color': '#1A1D26', + '--w3o-foreground-color': '#242835', + '--w3o-text-color': '#EFF1FC', + '--w3o-border-color': '#33394B', + '--w3o-action-color': '#929bed', + '--w3o-border-radius': '16px' + } + } const styleToString = (style) => { - return Object.keys(style).reduce((acc, key) => acc + key + ': ' + style[key] + '; \n ', '') + return Object.keys(style).reduce((acc, key) => acc + `"${key}": "${style[key]}", \n`, '') } async function copyStylingConfig() { @@ -123,18 +166,28 @@ } } - let copyableStyles = `:root {\n ${styleToString(defaultStyling)}${baseStyling}\n}` + let copyableStyles = + selectedTheme !== 'custom' ? '' : `{\n ${styleToString(themingObjects[selectedTheme])}}` + + const updateTheme = () => { + selectedTheme !== 'custom' + ? onboard.state.actions.updateTheme(selectedTheme) + : onboard.state.actions.updateTheme('default') + copyableStyles = + selectedTheme !== 'custom' ? '' : `{\n ${styleToString(themingObjects[selectedTheme])}}` + } - const updateTheme = (e, targetStyle) => { + const updateThemeEl = (e, targetStyle) => { + if (selectedTheme !== 'custom') return document.documentElement.style.setProperty(targetStyle, e.target.value) - copyableStyles = `:root {\n ${styleToString(defaultStyling)}${baseStyling}\n}` + copyableStyles = `{\n ${styleToString(themingObjects[selectedTheme])}}` } const resetTheme = () => { - defaultStyling = {...baseStyles} - Object.keys(defaultStyling).forEach(style => { - document.documentElement.style.setProperty(style, defaultStyling[style]) + selectedTheme = 'custom' + Object.keys(themingObjects['custom']).forEach((style) => { + document.documentElement.style.setProperty(style, themingObjects['custom'][style]) }) } @@ -187,28 +240,66 @@
- -
-
- {#each Object.keys(defaultStyling) as target} -
-
- updateTheme(e, target)} - /> -
- {target} : {defaultStyling[target]} -
+ +