diff --git a/site/docs/components/App.tsx b/site/docs/components/App.tsx index 98788e6536..962bf8a8cc 100644 --- a/site/docs/components/App.tsx +++ b/site/docs/components/App.tsx @@ -1,6 +1,6 @@ 'use client'; -import { OnchainKitProvider } from '@coinbase/onchainkit'; -// import { OnchainKitProvider } from '../pages/src/OnchainKitProvider'; +// import { OnchainKitProvider } from '@coinbase/onchainkit'; +import { OnchainKitProvider } from '../pages/src/OnchainKitProvider'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import type { ReactNode } from 'react'; import { http, WagmiProvider, createConfig } from 'wagmi'; diff --git a/site/docs/pages/wallet/wallet.mdx b/site/docs/pages/wallet/wallet.mdx index 0c0d49db6b..452542667b 100644 --- a/site/docs/pages/wallet/wallet.mdx +++ b/site/docs/pages/wallet/wallet.mdx @@ -9,7 +9,7 @@ import { WalletDropdown, WalletDropdownLink, WalletDropdownDisconnect, -} from '@coinbase/onchainkit/wallet'; +} from '../src/wallet'; import { Address, Avatar, @@ -17,7 +17,7 @@ import { Badge, Identity, EthBalance, -} from '@coinbase/onchainkit/identity'; +} from '../src/identity'; import { color } from '@coinbase/onchainkit/theme'; import AppWithRK from '../../components/AppWithRK'; import WalletComponents from '../../components/WalletComponents'; diff --git a/src/wallet/components/Wallet.tsx b/src/wallet/components/Wallet.tsx index 160a7436df..27829db84a 100644 --- a/src/wallet/components/Wallet.tsx +++ b/src/wallet/components/Wallet.tsx @@ -1,26 +1,46 @@ -import { Children, useMemo } from 'react'; +import { Children, useMemo, useRef, useEffect } from 'react'; import type { WalletReact } from '../types'; import { ConnectWallet } from './ConnectWallet'; import { WalletDropdown } from './WalletDropdown'; -import { WalletProvider } from './WalletProvider'; +import { WalletProvider, useWalletContext } from './WalletProvider'; + +function WalletContent({ children }: WalletReact) { + const { isOpen, setIsOpen } = useWalletContext(); + const containerRef = useRef(null); -export function Wallet({ children }: WalletReact) { const { connect, dropdown } = useMemo(() => { const childrenArray = Children.toArray(children); return { - // @ts-ignore connect: childrenArray.filter(({ type }) => type === ConnectWallet), - // @ts-ignore dropdown: childrenArray.filter(({ type }) => type === WalletDropdown), }; }, [children]); + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (containerRef.current && !containerRef.current.contains(event.target as Node) && isOpen) { + setIsOpen(false); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, [isOpen, setIsOpen]); + + return ( +
+ {connect} + {isOpen && dropdown} +
+ ); +} + +export function Wallet({ children }: WalletReact) { return ( -
- {connect} - {dropdown} -
+ {children}
); -} +} \ No newline at end of file