From fe6eebbf8b2faafd7d7491143fb24d7d7a067675 Mon Sep 17 00:00:00 2001 From: Oleg Chendighelean Date: Thu, 29 Aug 2024 17:29:19 +0100 Subject: [PATCH] Add account tile to mobile header --- .../components/AccountCard/AccountCard.tsx | 1 + .../AccountSelectorModal.tsx | 1 + .../AccountSelectorPopover.tsx | 1 + .../components/AccountTile/AccountTile.tsx | 37 ++++++++++++----- apps/web/src/components/Header/Header.tsx | 41 ++++++++++++++++++- .../Menu/AddressBookMenu/AddressBookMenu.tsx | 7 +++- .../web/src/components/beacon/BeaconPeers.tsx | 1 + apps/web/src/setupTests.ts | 11 +++++ 8 files changed, 87 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/AccountCard/AccountCard.tsx b/apps/web/src/components/AccountCard/AccountCard.tsx index 7ec2882a3f..f7830e2db9 100644 --- a/apps/web/src/components/AccountCard/AccountCard.tsx +++ b/apps/web/src/components/AccountCard/AccountCard.tsx @@ -25,6 +25,7 @@ export const AccountCard = () => { openWith()} > { aria-label="actions" icon={} size="xs" + variant="ghost" /> {accounts.map(account => { diff --git a/apps/web/src/components/AccountSelectorModal/AccountSelectorPopover.tsx b/apps/web/src/components/AccountSelectorModal/AccountSelectorPopover.tsx index 4664120565..72869f1d60 100644 --- a/apps/web/src/components/AccountSelectorModal/AccountSelectorPopover.tsx +++ b/apps/web/src/components/AccountSelectorModal/AccountSelectorPopover.tsx @@ -99,6 +99,7 @@ export const AccountSelectorPopover = ({ account }: AccountSelectorPopoverProps) icon={} onClick={event => event.stopPropagation()} size="xs" + variant="ghost" /> ); diff --git a/apps/web/src/components/AccountTile/AccountTile.tsx b/apps/web/src/components/AccountTile/AccountTile.tsx index 31f6d9b989..7d65bdc973 100644 --- a/apps/web/src/components/AccountTile/AccountTile.tsx +++ b/apps/web/src/components/AccountTile/AccountTile.tsx @@ -10,32 +10,47 @@ import { CopyAddressButton } from "../CopyAddressButton"; export const AccountTile = ({ account, children, + size = "sm", ...props -}: PropsWithChildren<{ account: ImplicitAccount }> & FlexProps) => { +}: PropsWithChildren<{ account: ImplicitAccount; size?: "xs" | "sm" }> & FlexProps) => { const color = useColor(); const address = account.address.pkh; + const sizes = { + xs: 20, + sm: 30, + }; + + const isSmall = size === "xs"; + const copyButtonStyles = isSmall + ? { + padding: 0, + left: 0, + } + : {}; + return ( - - + + - + - - {account.label} - - + {!isSmall && ( + + {account.label} + + )} + {children} diff --git a/apps/web/src/components/Header/Header.tsx b/apps/web/src/components/Header/Header.tsx index e21ae398be..ccda161ead 100644 --- a/apps/web/src/components/Header/Header.tsx +++ b/apps/web/src/components/Header/Header.tsx @@ -1,11 +1,23 @@ -import { Card, Icon, useBreakpointValue, useColorMode } from "@chakra-ui/react"; +import { Card, Icon, SlideFade, useBreakpointValue, useColorMode } from "@chakra-ui/react"; import { mode } from "@chakra-ui/theme-tools"; +import { useDynamicModalContext } from "@umami/components"; +import { useCurrentAccount } from "@umami/state"; +import { useEffect, useState } from "react"; import { Actions } from "./Actions"; import { LogoDarkIcon, LogoLightIcon } from "../../assets/icons"; +import { useColor } from "../../styles/useColor"; +import { AccountSelectorModal } from "../AccountSelectorModal"; +import { AccountTile } from "../AccountTile"; export const Header = () => { + const color = useColor(); const colorMode = useColorMode(); + const currentAccount = useCurrentAccount()!; + const { openWith } = useDynamicModalContext(); + + const [isVisible, setIsVisible] = useState(false); + const size = useBreakpointValue({ base: { width: "42px", @@ -17,6 +29,25 @@ export const Header = () => { }, }); + useEffect(() => { + const accountTile = document.getElementById("account-tile")!; + + const observer = new IntersectionObserver( + ([entry]) => { + setIsVisible(!entry.isIntersecting); + }, + { + threshold: 1, + } + ); + + observer.observe(accountTile); + + return () => { + observer.unobserve(accountTile); + }; + }, []); + return ( { }} > {mode(, )(colorMode)} + + openWith()} + size="xs" + /> + ); diff --git a/apps/web/src/components/Menu/AddressBookMenu/AddressBookMenu.tsx b/apps/web/src/components/Menu/AddressBookMenu/AddressBookMenu.tsx index b2e3203282..498b999dc7 100644 --- a/apps/web/src/components/Menu/AddressBookMenu/AddressBookMenu.tsx +++ b/apps/web/src/components/Menu/AddressBookMenu/AddressBookMenu.tsx @@ -80,7 +80,12 @@ const ContactItem = ({ contact }: ContactItemProps) => { - } /> + } + variant="iconButtonSolid" + /> ); diff --git a/apps/web/src/components/beacon/BeaconPeers.tsx b/apps/web/src/components/beacon/BeaconPeers.tsx index fc31ea998b..192e551e49 100644 --- a/apps/web/src/components/beacon/BeaconPeers.tsx +++ b/apps/web/src/components/beacon/BeaconPeers.tsx @@ -83,6 +83,7 @@ const PeerRow = ({ peerInfo }: { peerInfo: ExtendedPeerInfo }) => { aria-label="Remove Peer" icon={} onClick={() => removePeer(peerInfo)} + variant="iconButtonSolid" /> ); diff --git a/apps/web/src/setupTests.ts b/apps/web/src/setupTests.ts index 98b403bbc6..603385b734 100644 --- a/apps/web/src/setupTests.ts +++ b/apps/web/src/setupTests.ts @@ -5,6 +5,17 @@ import { TextDecoder, TextEncoder } from "util"; import { mockToast } from "@umami/state"; import { setupJestCanvasMock } from "jest-canvas-mock"; +const intersectionObserverMock = () => ({ + observe: jest.fn(), + unobserve: jest.fn(), +}); + +Object.defineProperty(global, "IntersectionObserver", { + writable: true, + configurable: true, + value: intersectionObserverMock, +}); + const localStorageMock = () => { const store: { [key: string]: string } = {};