Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation theme changes #1216

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.

This file was deleted.

182 changes: 64 additions & 118 deletions deepfence_frontend/apps/dashboard/src/components/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,136 +1,52 @@
import classNames from 'classnames';
import { IconContext } from 'react-icons';
import {
HiChevronLeft,
HiLogout,
HiMenu,
HiOutlineDesktopComputer,
HiOutlineMoon,
HiOutlineSun,
} from 'react-icons/hi';
import { useFetcher } from 'react-router-dom';
import {
Avatar,
Dropdown,
DropdownItem,
DropdownSeparator,
DropdownSubMenu,
IconButton,
} from 'ui-components';
import { useFetcher, useRouteLoaderData } from 'react-router-dom';
import { Dropdown, DropdownItem } from 'ui-components';

import { DFLink } from '@/components/DFLink';
import { AutoRefresh } from '@/components/header/AutoRefresh';
import { useTheme } from '@/theme/ThemeContext';
import { CaretDown } from '@/components/icons/common/caret-down';
import { UserLine } from '@/components/icons/common/user-line';

export interface DashboardHeaderProps {
sideNavExpanded: boolean;
onSideNavExpandedChange: (expanded: boolean) => void;
}

const themeSelectedDropdownClassname = 'text-blue-500 dark:text-blue-300';
const themeDropdownClassname = 'text-gray-700 dark:text-gray-400';

export function AppHeader({
sideNavExpanded,
onSideNavExpandedChange,
}: DashboardHeaderProps) {
const { setMode, userSelectedMode } = useTheme();
export function AppHeader() {
const fetcher = useFetcher();
const { email } = useRouteLoaderData('root') as { email: string };
return (
<header
className={classNames(
'fixed z-10 top-0 px-2 bg-white dark:bg-gray-800 h-[64px] w-full border-b border-gray-200 dark:border-gray-700',
'fixed z-10 top-0 bg-white dark:bg-bg-left-nav h-[56px] w-full border-b border-gray-200 dark:border-bg-top-header',
)}
>
<div className="h-full flex items-center">
<div
className={classNames('mr-auto pl-2 flex gap-4 transition-[margin-left]', {
['ml-[64px]']: !sideNavExpanded,
['ml-[240px]']: sideNavExpanded,
})}
>
<IconButton
className="rounded-md p-1 bg-transparent"
onClick={() => {
onSideNavExpandedChange(!sideNavExpanded);
<div className={classNames('mr-auto ml-3')}>
<DFLink
to="/"
style={{
all: 'unset',
cursor: 'pointer',
display: 'flex',
height: '100%',
alignItems: 'center',
gap: '12px',
}}
icon={
<IconContext.Provider
value={{
className: 'w-8 h-8 text-gray-500 dark:text-gray-400',
}}
>
<HiMenu />
</IconContext.Provider>
}
size="xs"
/>
>
<div className="h-9 w-9">
<DeepfenceLogo />
</div>
<div className="dark:text-text-text-and-icon text-[18px] leading-9">
deepfence
</div>
</DFLink>
</div>
<div className="flex items-center gap-4">
<div className="flex items-center gap-[18px] mr-6">
<AutoRefresh />

<div className="h-[16px] w-[1px] dark:bg-bg-grid-border" />

<Dropdown
triggerAsChild
align="end"
content={
<>
<DropdownSubMenu
triggerAsChild
content={
<>
<DropdownItem
onClick={() => {
setMode('light');
}}
className={
userSelectedMode === 'light'
? themeSelectedDropdownClassname
: themeDropdownClassname
}
>
<HiOutlineSun />
Light
</DropdownItem>
<DropdownItem
onClick={() => {
setMode('dark');
}}
className={
userSelectedMode === 'dark'
? themeSelectedDropdownClassname
: themeDropdownClassname
}
>
<HiOutlineMoon />
Dark
</DropdownItem>
<DropdownItem
onClick={() => {
setMode(undefined);
}}
className={
!userSelectedMode
? themeSelectedDropdownClassname
: themeDropdownClassname
}
>
<HiOutlineDesktopComputer />
Device Theme
</DropdownItem>
</>
}
>
<DropdownItem onClick={(e) => e.preventDefault()}>
<IconContext.Provider
value={{
className: 'w-4 h-4',
}}
>
<HiChevronLeft />
</IconContext.Provider>
<span className="text-gray-700 dark:text-gray-400">Theme</span>
</DropdownItem>
</DropdownSubMenu>

<DropdownSeparator />
<DropdownItem
onClick={() => {
fetcher.submit(null, {
Expand All @@ -140,18 +56,48 @@ export function AppHeader({
}}
className="text-red-700 dark:text-red-500"
>
<HiLogout />
Logout
</DropdownItem>
</>
}
>
<div>
<Avatar />
</div>
<button className="dark:text-text-text-and-icon flex gap-[6px] items-center">
<div className="h-[18px] w-[18px]">
<UserLine />
</div>
<div>{email}</div>
<div className="h-3 w-3">
<CaretDown />
</div>
</button>
</Dropdown>
</div>
</div>
</header>
);
}

const DeepfenceLogo = () => {
return (
<svg
width="100%"
height="100%"
viewBox="0 0 36 36"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M21.1188 23.2243L16.099 17.2116L13.9307 14.59L12.9505 13.4216L10.7822 10.8H6.23763H4.54456H0L3 14.59H7.54456H9.23763L10.2178 15.7298L11.5842 17.2116L18.8614 25.9314L18 26.9572L9.86139 17.2116L8.49505 15.7298H3.9802L5.34654 17.2116L15.7426 29.6929L18 32.4L20.2574 29.6929L21.1188 28.667L23.3762 25.9314L21.1188 23.2243Z"
fill="#2742E7"
/>
<path
d="M27.297 21.2581L30.6535 17.2117L31.8416 15.7869H22.6931L27.297 21.2581Z"
fill="#2742E7"
/>
<path
d="M20.1683 14.6185H21.7129H32.8218L32.8515 14.59L33.802 13.4216L36 10.8H31.4554H16.9901H12.4752L14.6733 13.4216L15.6237 14.59L17.8218 17.2116L21.9802 22.1984L24.2376 24.9055L26.495 22.1984L26.5247 22.1699L21.1485 15.7868L20.1683 14.6185Z"
fill="#2742E7"
/>
</svg>
);
};
Loading