fix: classname mismatch warning by setting dark class for nav (#1465)

* fix: classname mismatch warning, tidy unnecessary classes to accomodate dark nav

* chore: lint

* fix: lp test console error and fix

* fix: remove fixed bg from console-lite theme switcher
This commit is contained in:
Matthew Russell 2022-09-27 02:18:41 -04:00 committed by GitHub
parent 191e73335e
commit c4468d507b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 71 deletions

View File

@ -12,7 +12,7 @@ const Header = () => {
} = useContext(LocalContext); } = useContext(LocalContext);
return ( return (
<div <div
className="flex items-stretch pr-6 py-6 bg-black text-neutral-400" className="dark flex items-stretch pr-6 py-6 bg-black text-neutral-400"
data-testid="header" data-testid="header"
> >
<Logo /> <Logo />
@ -21,12 +21,7 @@ const Header = () => {
setConnectDialog={setConnect} setConnectDialog={setConnect}
setManageDialog={setManage} setManageDialog={setManage}
/> />
<ThemeSwitcher <ThemeSwitcher theme={theme} onToggle={toggleTheme} className="-my-4" />
theme={theme}
onToggle={toggleTheme}
className="-my-4"
fixedBg="dark"
/>
</div> </div>
</div> </div>
); );

View File

@ -12,7 +12,7 @@ export const Header = ({ title, children }: TradeMarketHeaderProps) => {
return ( return (
<header className="w-screen xl:px-4 pt-4 border-b border-default"> <header className="w-screen xl:px-4 pt-4 border-b border-default">
<div className="xl:flex xl:gap-4 items-start"> <div className="xl:flex xl:gap-4 items-start">
<div className="mb-4 xl:mb-0">{title}</div> <div className="mb-4 xl:mb-0 px-4 xl:px-0">{title}</div>
<div <div
data-testid="header-summary" data-testid="header-summary"
className="flex flex-nowrap items-start xl:flex-1 w-full overflow-x-auto text-xs " className="flex flex-nowrap items-start xl:flex-1 w-full overflow-x-auto text-xs "

View File

@ -20,7 +20,7 @@ export const Navbar = ({ theme, toggleTheme }: NavbarProps) => {
})); }));
const tradingPath = marketId ? `/markets/${marketId}` : '/markets'; const tradingPath = marketId ? `/markets/${marketId}` : '/markets';
return ( return (
<div className="px-4 flex items-stretch border-b border-default bg-black text-white"> <div className="dark px-4 flex items-stretch border-b border-default bg-black text-white">
<div className="flex gap-4 mr-4 items-center h-full"> <div className="flex gap-4 mr-4 items-center h-full">
<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 */}
@ -28,7 +28,7 @@ export const Navbar = ({ theme, toggleTheme }: NavbarProps) => {
<Vega className="w-13" /> <Vega className="w-13" />
</a> </a>
</Link> </Link>
<NetworkSwitcher theme="dark" /> <NetworkSwitcher />
</div> </div>
<nav className="flex items-center"> <nav className="flex items-center">
{[ {[
@ -43,12 +43,7 @@ export const Navbar = ({ theme, toggleTheme }: NavbarProps) => {
))} ))}
</nav> </nav>
<div className="flex items-center gap-2 ml-auto"> <div className="flex items-center gap-2 ml-auto">
<ThemeSwitcher <ThemeSwitcher theme={theme} onToggle={toggleTheme} />
theme={theme}
onToggle={toggleTheme}
sunClassName="text-white"
fixedBg="dark"
/>
<VegaWalletConnectButton <VegaWalletConnectButton
setConnectDialog={(open) => update({ connectDialog: open })} setConnectDialog={(open) => update({ connectDialog: open })}
/> />

View File

@ -9,7 +9,6 @@ import {
} from '@vegaprotocol/ui-toolkit'; } from '@vegaprotocol/ui-toolkit';
import { useEnvironment } from '../../hooks/use-environment'; import { useEnvironment } from '../../hooks/use-environment';
import { Networks } from '../../types'; import { Networks } from '../../types';
import classNames from 'classnames';
export const envNameMapping: Record<Networks, string> = { export const envNameMapping: Record<Networks, string> = {
[Networks.CUSTOM]: t('Custom'), [Networks.CUSTOM]: t('Custom'),
@ -69,7 +68,7 @@ const NetworkLabel = ({
</span> </span>
); );
export const NetworkSwitcher = ({ theme }: { theme?: 'dark' | 'light' }) => { export const NetworkSwitcher = () => {
const { VEGA_ENV, VEGA_NETWORKS } = useEnvironment(); const { VEGA_ENV, VEGA_NETWORKS } = useEnvironment();
const [isOpen, setOpen] = useState(false); const [isOpen, setOpen] = useState(false);
const [isAdvancedView, setAdvancedView] = useState(false); const [isAdvancedView, setAdvancedView] = useState(false);
@ -84,16 +83,9 @@ export const NetworkSwitcher = ({ theme }: { theme?: 'dark' | 'light' }) => {
[setOpen, setAdvancedView] [setOpen, setAdvancedView]
); );
const dropdownTriggerClasses = classNames({
'text-black hover:!bg-neutral-300': theme === 'light',
'text-white hover:!bg-neutral-700': theme === 'dark',
});
return ( return (
<DropdownMenu open={isOpen} onOpenChange={handleOpen}> <DropdownMenu open={isOpen} onOpenChange={handleOpen}>
<DropdownMenuTrigger className={dropdownTriggerClasses}> <DropdownMenuTrigger>{envTriggerMapping[VEGA_ENV]}</DropdownMenuTrigger>
{envTriggerMapping[VEGA_ENV]}
</DropdownMenuTrigger>
<DropdownMenuContent align="start"> <DropdownMenuContent align="start">
{!isAdvancedView && ( {!isAdvancedView && (
<> <>

View File

@ -1,5 +1,5 @@
import LiquidityTable from './liquidity-table'; import LiquidityTable from './liquidity-table';
import { act, render, screen, waitFor } from '@testing-library/react'; import { act, render, screen } from '@testing-library/react';
import { LiquidityProvisionStatus } from '@vegaprotocol/types'; import { LiquidityProvisionStatus } from '@vegaprotocol/types';
import type { LiquidityProvision } from './liquidity-data-provider'; import type { LiquidityProvision } from './liquidity-data-provider';
@ -27,27 +27,28 @@ describe('LiquidityTable', () => {
}); });
it('should render correct columns', async () => { it('should render correct columns', async () => {
act(async () => { await act(async () => {
render(<LiquidityTable data={singleRowData} />); render(<LiquidityTable data={singleRowData} />);
await waitFor(async () => { });
const headers = await screen.getAllByRole('columnheader'); const headers = await screen.getAllByRole('columnheader');
expect(headers).toHaveLength(9);
expect( const headerTexts = headers.map((h) =>
headers.map((h) =>
h.querySelector('[ref="eText"]')?.textContent?.trim() h.querySelector('[ref="eText"]')?.textContent?.trim()
) );
).toEqual([ const expectedHeaders = [
'Party', 'Party',
'Average entry valuation', 'Commitment ()',
'Updated',
'Created',
'Supplied (siskas)',
'Obligation (siskas)',
'Share', 'Share',
'Fee', 'Proposed fee',
'Average entry valuation',
'Obligation',
'Supplied',
'Status', 'Status',
]); 'Created',
}); 'Updated',
}); ];
expect(headers).toHaveLength(expectedHeaders.length);
expect(headerTexts).toEqual(expectedHeaders);
}); });
}); });

View File

@ -1,4 +1,3 @@
import classNames from 'classnames';
import React from 'react'; import React from 'react';
import { SunIcon, MoonIcon } from './icons'; import { SunIcon, MoonIcon } from './icons';
@ -6,28 +5,12 @@ export const ThemeSwitcher = ({
theme, theme,
onToggle, onToggle,
className, className,
sunClassName,
moonClassName,
fixedBg,
}: { }: {
theme: 'light' | 'dark'; theme: 'light' | 'dark';
onToggle: () => void; onToggle: () => void;
className?: string; className?: string;
sunClassName?: string;
moonClassName?: string;
fixedBg?: 'light' | 'dark';
}) => { }) => {
const sharedClasses = classNames({ const classes = 'text-neutral-800 dark:text-neutral-300';
'text-neutral-800 dark:text-neutral-300': !fixedBg,
'text-neutral-800': fixedBg === 'light',
'text-neutral-300': fixedBg === 'dark',
});
const sunClasses = classNames(sharedClasses, sunClassName, {
hidden: theme === 'light',
});
const moonClasses = classNames(sharedClasses, moonClassName, {
hidden: theme === 'dark',
});
return ( return (
<button <button
type="button" type="button"
@ -35,12 +18,16 @@ export const ThemeSwitcher = ({
className={className} className={className}
data-testid="theme-switcher" data-testid="theme-switcher"
> >
<span className={sunClasses}> {theme === 'dark' && (
<span className={classes}>
<SunIcon /> <SunIcon />
</span> </span>
<span className={moonClasses}> )}
{theme === 'light' && (
<span className={classes}>
<MoonIcon /> <MoonIcon />
</span> </span>
)}
</button> </button>
); );
}; };