-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: clean up main navigation and ui
- Loading branch information
Showing
25 changed files
with
352 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,52 @@ | ||
import { ActionIcon, Group } from '@mantine/core' | ||
import { ActionIcon, Box, Group, Tooltip, UnstyledButton } from '@mantine/core' | ||
import { useDisclosure } from '@mantine/hooks' | ||
import { useAuth } from '@pubkey-link/web-auth-data-access' | ||
import { AppLogo, UiHeaderProfile } from '@pubkey-link/web-core-ui' | ||
import { UiHeader, UiHeaderLink, UiLayout, UiLoader } from '@pubkey-ui/core' | ||
import { IconBug, IconSettings } from '@tabler/icons-react' | ||
import { ReactNode, Suspense, useMemo } from 'react' | ||
import { AppLogo, AppUiHeader, AppUiThemeSwitch } from '@pubkey-link/web-core-ui' | ||
import { UiAvatar, UiLoader } from '@pubkey-ui/core' | ||
import { IconLogout, IconShield } from '@tabler/icons-react' | ||
import { ReactNode, Suspense } from 'react' | ||
import { Link } from 'react-router-dom' | ||
|
||
export function WebCoreLayout({ children }: { children: ReactNode }) { | ||
const { isAdmin, isDeveloper, user } = useAuth() | ||
const { isAdmin, user, logout } = useAuth() | ||
const [opened, { toggle }] = useDisclosure(false) | ||
const links: UiHeaderLink[] = useMemo(() => { | ||
const items: UiHeaderLink[] = [ | ||
{ link: `/u`, label: 'Profile' }, | ||
{ link: '/c', label: 'Communities' }, | ||
] | ||
if (isAdmin) { | ||
items.push({ link: '/admin', label: 'Admin' }) | ||
} | ||
return items | ||
}, [isAdmin, user]) | ||
return ( | ||
<UiLayout | ||
header={ | ||
<UiHeader | ||
logoSmall={<AppLogo height={28} />} | ||
logo={<AppLogo height={28} />} | ||
opened={opened} | ||
toggle={toggle} | ||
links={links} | ||
profile={ | ||
<Group gap="xs"> | ||
{isAdmin && isDeveloper && ( | ||
<ActionIcon component={Link} to="/admin/development" variant="light" size="lg"> | ||
<IconBug /> | ||
<Box> | ||
<AppUiHeader | ||
logoSmall={<AppLogo height={28} />} | ||
logo={<AppLogo height={28} />} | ||
opened={opened} | ||
toggle={toggle} | ||
links={[]} | ||
profile={ | ||
<Group gap="xs" wrap="nowrap"> | ||
<AppUiThemeSwitch /> | ||
{isAdmin && ( | ||
<Tooltip label={'Admin Dashboard'} withArrow position="top"> | ||
<ActionIcon component={Link} to="/admin" variant="light" size="lg"> | ||
<IconShield /> | ||
</ActionIcon> | ||
)} | ||
<ActionIcon component={Link} to="/settings" variant="light" size="lg"> | ||
<IconSettings /> | ||
</Tooltip> | ||
)} | ||
<Tooltip label={'Logout'} withArrow position="top"> | ||
<ActionIcon onClick={logout} variant="light" size="lg"> | ||
<IconLogout /> | ||
</ActionIcon> | ||
<UiHeaderProfile /> | ||
</Group> | ||
} | ||
/> | ||
} | ||
> | ||
</Tooltip> | ||
<UnstyledButton component={Link} to={user?.profileUrl ?? ''}> | ||
<UiAvatar | ||
url={user?.avatarUrl} | ||
name={`${user?.username}`} | ||
alt={user?.username ?? 'User Avatar'} | ||
radius={100} | ||
size={34} | ||
/> | ||
</UnstyledButton> | ||
</Group> | ||
} | ||
/> | ||
|
||
<Suspense fallback={<UiLoader mt="xl" size="xl" type="dots" />}>{children}</Suspense> | ||
</UiLayout> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
libs/web/core/ui/src/lib/app-ui-header/app-ui-header.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.header { | ||
height: rem(56px); | ||
/*background-color: light-dark(var(--mantine-color-white), var(--mantine-color-dark-9));*/ | ||
padding-left: var(--mantine-spacing-md); | ||
padding-right: var(--mantine-spacing-md); | ||
} | ||
|
||
.inner { | ||
height: rem(56px); | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
.link { | ||
display: block; | ||
line-height: 1; | ||
padding: rem(8px) rem(12px); | ||
border-radius: var(--mantine-radius-sm); | ||
text-decoration: none; | ||
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-dark-0)); | ||
font-size: var(--mantine-font-size-sm); | ||
font-weight: 500; | ||
|
||
@mixin hover { | ||
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-7)); | ||
} | ||
} | ||
.linkActive { | ||
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-8)); | ||
color: light-dark(var(--mantine-color-brand-6), var(--mantine-color-brand-4)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Anchor, Burger, Drawer, DrawerProps, Group, ScrollArea, Stack } from '@mantine/core' | ||
import { useDisclosure } from '@mantine/hooks' | ||
import { UiLogo, UiLogoType } from '@pubkey-ui/core' | ||
import cx from 'clsx' | ||
import { ReactNode } from 'react' | ||
import { Link, useLocation } from 'react-router-dom' | ||
|
||
import classes from './app-ui-header.module.css' | ||
|
||
export interface UiHeaderProps { | ||
base?: string | ||
drawerProps?: DrawerProps | ||
logo?: ReactNode | ||
logoSmall?: ReactNode | ||
links?: UiHeaderLink[] | ||
opened?: boolean | ||
profile?: ReactNode | ||
toggle?: () => void | ||
} | ||
export interface UiHeaderLink { | ||
link: string | ||
label: string | ||
} | ||
|
||
export function AppUiHeader(props: UiHeaderProps) { | ||
const { pathname } = useLocation() | ||
const [drawerOpened, { toggle: drawerToggle }] = useDisclosure(false) | ||
const opened = props.opened ?? drawerOpened | ||
const toggle = props.toggle ?? drawerToggle | ||
const burger = props.links?.length ? <Burger opened={opened} onClick={toggle} size="sm" hiddenFrom="md" /> : null | ||
|
||
const items = props.links?.map((link) => ( | ||
<Anchor | ||
component={Link} | ||
key={link.label} | ||
to={link.link} | ||
className={cx(classes.link, { [classes.linkActive]: pathname.startsWith(link.link) })} | ||
onClick={close} | ||
> | ||
{link.label} | ||
</Anchor> | ||
)) | ||
|
||
function close() { | ||
if (!opened || !props.toggle) return | ||
props.toggle() | ||
} | ||
|
||
return ( | ||
<header className={classes.header}> | ||
<div className={classes.inner}> | ||
<Group> | ||
<Group> | ||
{burger} | ||
<Anchor component={Link} to={props.base ?? '/'} display="flex"> | ||
<Group hiddenFrom="md">{props.logoSmall ?? <UiLogo height={28} />}</Group> | ||
<Group visibleFrom="md">{props.logo ?? <UiLogoType height={28} />}</Group> | ||
</Anchor> | ||
</Group> | ||
<Group gap={5} className={classes.links} visibleFrom="md"> | ||
{items} | ||
</Group> | ||
</Group> | ||
|
||
{props.profile ? <Group>{props.profile}</Group> : null} | ||
</div> | ||
<Drawer | ||
opened={opened} | ||
onClose={toggle} | ||
title={ | ||
<Group> | ||
<Anchor component={Link} to={props.base ?? '/'} display="flex" onClick={close}> | ||
{props.logo ?? <UiLogoType height={28} />} | ||
</Anchor> | ||
</Group> | ||
} | ||
hiddenFrom="md" | ||
scrollAreaComponent={ScrollArea} | ||
{...props.drawerProps} | ||
> | ||
<Stack gap="sm">{items}</Stack> | ||
</Drawer> | ||
</header> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './app-ui-header' |
28 changes: 28 additions & 0 deletions
28
libs/web/core/ui/src/lib/app-ui-theme-switch/app-ui-theme-switch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { rem, Switch, SwitchProps, Tooltip, useMantineTheme } from '@mantine/core' | ||
import { useUiColorScheme } from '@pubkey-ui/core' | ||
import { IconMoonStars, IconSun } from '@tabler/icons-react' | ||
|
||
export function AppUiThemeSwitch(props: SwitchProps) { | ||
const theme = useMantineTheme() | ||
const { toggleColorScheme, colorScheme } = useUiColorScheme() | ||
const isDark = colorScheme === 'dark' | ||
const sunIcon = <IconSun style={{ width: rem(16), height: rem(16) }} stroke={2.5} color={theme.colors.yellow[4]} /> | ||
|
||
const moonIcon = ( | ||
<IconMoonStars style={{ width: rem(16), height: rem(16) }} stroke={2.5} color={theme.colors['brand'][6]} /> | ||
) | ||
|
||
return ( | ||
<Tooltip label={`Select ${isDark ? 'light' : 'dark'} theme`} withArrow position="top" refProp="rootRef"> | ||
<Switch | ||
size="lg" | ||
color="dark.9" | ||
onLabel={sunIcon} | ||
offLabel={moonIcon} | ||
onChange={() => toggleColorScheme()} | ||
checked={colorScheme === 'dark'} | ||
{...props} | ||
/> | ||
</Tooltip> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './app-ui-theme-switch' |
Oops, something went wrong.