Feat/725 network header styles (#1893)

* feat: add yellow theme for navbar, adjust dropdown and theme switcher styles

* feat: set yellow theme when network is testnet

* feat: adjust button styles to accomodate different color backgrounds
This commit is contained in:
Matthew Russell 2022-10-28 10:13:14 -05:00 committed by GitHub
parent a90970399c
commit f5ea0563b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 51 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

@ -9,13 +9,20 @@ import { ThemeSwitcher } from '@vegaprotocol/ui-toolkit';
import { Vega } from '../icons/vega'; import { Vega } from '../icons/vega';
import type { HTMLAttributeAnchorTarget } from 'react'; import type { HTMLAttributeAnchorTarget } from 'react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import testnetBg from '../../assets/green-cloud.png';
type NavbarTheme = 'inherit' | 'dark' | 'yellow';
interface NavbarProps { interface NavbarProps {
theme: 'light' | 'dark'; theme: 'light' | 'dark';
toggleTheme: () => void; toggleTheme: () => void;
navbarTheme?: NavbarTheme;
} }
export const Navbar = ({ theme, toggleTheme }: NavbarProps) => { export const Navbar = ({
theme,
toggleTheme,
navbarTheme = 'inherit',
}: NavbarProps) => {
const { VEGA_TOKEN_URL } = useEnvironment(); const { VEGA_TOKEN_URL } = useEnvironment();
const { marketId } = useGlobalStore((store) => ({ const { marketId } = useGlobalStore((store) => ({
marketId: store.marketId, marketId: store.marketId,
@ -28,9 +35,29 @@ export const Navbar = ({ theme, toggleTheme }: NavbarProps) => {
} }
}, [marketId]); }, [marketId]);
const themeWrapperClasses = classNames({
dark: navbarTheme === 'dark',
});
const isYellow = navbarTheme === 'yellow';
const navbarClasses = classNames(
'flex items-stretch border-b px-4 border-default',
{
'dark:bg-black dark:text-white': !isYellow,
'bg-vega-yellow text-black bg-right-top bg-no-repeat bg-contain':
isYellow,
}
);
return ( return (
<div className="dark px-4 flex items-stretch border-b border-default bg-black text-white"> <div className={themeWrapperClasses}>
<div className="flex gap-4 items-center h-full"> <div
className={navbarClasses}
style={{
backgroundImage: isYellow ? `url("${testnetBg.src}")` : '',
}}
>
<div className="flex gap-4 items-center">
<Link href="/" passHref={true}> <Link href="/" passHref={true}>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a> <a>
@ -40,13 +67,22 @@ export const Navbar = ({ theme, toggleTheme }: NavbarProps) => {
<NetworkSwitcher /> <NetworkSwitcher />
</div> </div>
<nav className="flex items-center flex-1 px-2"> <nav className="flex items-center flex-1 px-2">
<NavLink name={t('Trading')} path={tradingPath} /> <NavLink
<NavLink name={t('Portfolio')} path="/portfolio" /> name={t('Trading')}
path={tradingPath}
navbarTheme={navbarTheme}
/>
<NavLink
name={t('Portfolio')}
path="/portfolio"
navbarTheme={navbarTheme}
/>
<NavLink <NavLink
name={t('Governance')} name={t('Governance')}
path={`${VEGA_TOKEN_URL}/governance`} path={`${VEGA_TOKEN_URL}/governance`}
alignRight={true} alignRight={true}
target="_blank" target="_blank"
navbarTheme={navbarTheme}
/> />
</nav> </nav>
<div className="flex items-center gap-2 ml-auto"> <div className="flex items-center gap-2 ml-auto">
@ -54,12 +90,14 @@ export const Navbar = ({ theme, toggleTheme }: NavbarProps) => {
<ThemeSwitcher theme={theme} onToggle={toggleTheme} /> <ThemeSwitcher theme={theme} onToggle={toggleTheme} />
</div> </div>
</div> </div>
</div>
); );
}; };
interface NavLinkProps { interface NavLinkProps {
name: string; name: string;
path: string; path: string;
navbarTheme: NavbarTheme;
testId?: string; testId?: string;
alignRight?: boolean; alignRight?: boolean;
target?: HTMLAttributeAnchorTarget; target?: HTMLAttributeAnchorTarget;
@ -68,6 +106,7 @@ interface NavLinkProps {
const NavLink = ({ const NavLink = ({
name, name,
path, path,
navbarTheme,
alignRight, alignRight,
target, target,
testId = name, testId = name,
@ -75,18 +114,24 @@ const NavLink = ({
const router = useRouter(); const router = useRouter();
const isActive = router.asPath?.includes(path); const isActive = router.asPath?.includes(path);
const linkClasses = classNames('mx-2 py-3 self-end relative', { const linkClasses = classNames('mx-2 py-3 self-end relative', {
'text-white cursor-default': isActive, 'cursor-default': isActive,
'text-neutral-400 hover:text-neutral-300': !isActive, 'text-black dark:text-white': isActive && navbarTheme !== 'yellow',
'text-neutral-500 dark:text-neutral-400 hover:text-black dark:hover:text-neutral-300':
!isActive && navbarTheme !== 'yellow',
'ml-auto': alignRight, 'ml-auto': alignRight,
'text-black': isActive && navbarTheme === 'yellow',
'text-black/60 hover:text-black': !isActive && navbarTheme === 'yellow',
});
const borderClasses = classNames('absolute h-1 w-full bottom-[-1px] left-0', {
'bg-black dark:bg-vega-yellow': navbarTheme !== 'yellow',
'bg-black': navbarTheme === 'yellow',
}); });
return ( return (
<Link data-testid={testId} href={path} passHref={true}> <Link data-testid={testId} href={path} passHref={true}>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a className={linkClasses} target={target}> <a className={linkClasses} target={target}>
{name} {name}
{isActive && ( {isActive && <span className={borderClasses} />}
<span className="absolute h-1 w-full bg-vega-yellow bottom-0 left-0" />
)}
</a> </a>
</Link> </Link>
); );

View File

@ -6,6 +6,7 @@ import { VegaWalletProvider } from '@vegaprotocol/wallet';
import { import {
EnvironmentProvider, EnvironmentProvider,
envTriggerMapping, envTriggerMapping,
Networks,
useEnvironment, useEnvironment,
} from '@vegaprotocol/environment'; } from '@vegaprotocol/environment';
import { AppLoader } from '../components/app-loader'; import { AppLoader } from '../components/app-loader';
@ -38,6 +39,7 @@ const Title = () => {
}; };
function AppBody({ Component, pageProps }: AppProps) { function AppBody({ Component, pageProps }: AppProps) {
const { VEGA_ENV } = useEnvironment();
const [theme, toggleTheme] = useThemeSwitcher(); const [theme, toggleTheme] = useThemeSwitcher();
return ( return (
<ThemeContext.Provider value={theme}> <ThemeContext.Provider value={theme}>
@ -47,7 +49,11 @@ function AppBody({ Component, pageProps }: AppProps) {
<Title /> <Title />
<div className="h-full relative dark:bg-black dark:text-white z-0 grid grid-rows-[min-content,1fr,min-content]"> <div className="h-full relative dark:bg-black dark:text-white z-0 grid grid-rows-[min-content,1fr,min-content]">
<AppLoader> <AppLoader>
<Navbar theme={theme} toggleTheme={toggleTheme} /> <Navbar
theme={theme}
toggleTheme={toggleTheme}
navbarTheme={VEGA_ENV === Networks.TESTNET ? 'yellow' : 'dark'}
/>
<main data-testid={pageProps.page}> <main data-testid={pageProps.page}>
<Component {...pageProps} /> <Component {...pageProps} />
</main> </main>

View File

@ -18,12 +18,10 @@ const md = 'px-10 py-2 text-base';
const lg = 'px-14 py-4'; const lg = 'px-14 py-4';
const fillClasses = 'block w-full'; const fillClasses = 'block w-full';
const defaultClasses = [ const defaultClasses = [
'text-black dark:text-white', 'border-neutral-500',
'border-black dark:border-white', 'bg-transparent',
'bg-white dark:bg-black', 'enabled:hover:bg-neutral-500/20 dark:enabled:hover:bg-neutral-500/40',
'enabled:hover:bg-neutral-200 dark:enabled:hover:bg-neutral-700', 'enabled:active:bg-neutral-500/20 dark:enabled:active:bg-neutral-500/40',
'enabled:active:bg-neutral-200 dark:enabled:active:bg-neutral-700',
'enabled:active:border-neutral-400',
]; ];
const primary = [ const primary = [
'text-black', 'text-black',

View File

@ -27,9 +27,8 @@ export const DropdownMenuTrigger = forwardRef<
>(({ className, children, ...props }, forwardedRef) => { >(({ className, children, ...props }, forwardedRef) => {
const triggerClasses = classNames( const triggerClasses = classNames(
className, className,
'text-sm py-1 px-2 rounded bg-transparent border border-neutral-500', 'text-sm py-1 px-2 rounded bg-transparent border border-neutral-500 whitespace-nowrap',
'focus:border-black dark:focus:border-white whitespace-nowrap', 'hover:bg-neutral-500/20 dark:hover:bg-neutral-500/40'
'hover:bg-neutral-200 dark:hover:bg-neutral-700'
); );
return ( return (
<DropdownMenuPrimitive.Trigger <DropdownMenuPrimitive.Trigger

View File

@ -10,24 +10,15 @@ export const ThemeSwitcher = ({
onToggle: () => void; onToggle: () => void;
className?: string; className?: string;
}) => { }) => {
const classes = 'text-neutral-800 dark:text-neutral-300';
return ( return (
<button <button
type="button" type="button"
onClick={() => onToggle()} onClick={onToggle}
className={className} className={className}
data-testid="theme-switcher" data-testid="theme-switcher"
> >
{theme === 'dark' && ( {theme === 'dark' && <SunIcon />}
<span className={classes}> {theme === 'light' && <MoonIcon />}
<SunIcon />
</span>
)}
{theme === 'light' && (
<span className={classes}>
<MoonIcon />
</span>
)}
</button> </button>
); );
}; };