Skip to content

Commit

Permalink
feat(ui): add sidebar component (#2620)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Oct 31, 2024
1 parent 959ce16 commit 7cefeb1
Show file tree
Hide file tree
Showing 41 changed files with 2,280 additions and 192 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-bats-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/kode-ui': minor
---

add SideBar Component
1 change: 1 addition & 0 deletions packages/apps/dev-wallet/src/App/BetaHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const BetaHeader = () => {
return (
<>
<Stack
width="100%"
as="header"
alignItems="center"
flexDirection="row"
Expand Down
84 changes: 84 additions & 0 deletions packages/apps/dev-wallet/src/App/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {
MonoKey,
MonoLightMode,
MonoWifiTethering,
MonoWorkspaces,
} from '@kadena/kode-icons/system';

import { NetworkSelector } from '@/Components/NetworkSelector/NetworkSelector';
import { BreadCrumbs } from '@/pages/BreadCrumbs/BreadCrumbs';
import { Themes, useTheme } from '@kadena/kode-ui';
import {
SideBarFooter,
SideBarFooterItem,
SideBarLayout,
useSideBar,
} from '@kadena/kode-ui/patterns';
import { FC, useEffect } from 'react';
import { Link, Outlet, useLocation } from 'react-router-dom';
import { BetaHeader } from './../BetaHeader';
import { SideBar } from './SideBar';

export const Layout: FC = () => {
const { theme, setTheme } = useTheme();
const { breadCrumbs, setBreadCrumbs, setAppContext } = useSideBar();
const location = useLocation();

useEffect(() => {
if (
breadCrumbs.length > 0 &&
location.pathname !== breadCrumbs[breadCrumbs.length - 1].url
) {
setBreadCrumbs([]);
setAppContext();
}
}, [location]);

const toggleTheme = (): void => {
const newTheme = theme === Themes.dark ? Themes.light : Themes.dark;
setTheme(newTheme);
};
return (
<>
<SideBarLayout
topBanner={<BetaHeader />}
breadcrumbs={<BreadCrumbs />}
activeUrl={location.pathname}
sidebar={<SideBar />}
footer={
<SideBarFooter>
<SideBarFooterItem
href="/"
component={Link}
visual={<MonoWifiTethering />}
label="Profile"
/>

<SideBarFooterItem
href="/key-management/keys"
component={Link}
visual={<MonoKey />}
label="Keys"
/>

<SideBarFooterItem
visual={<MonoWorkspaces />}
label="Select network"
>
<NetworkSelector variant="transparent" showLabel={false} />
</SideBarFooterItem>
<SideBarFooterItem
visual={<MonoLightMode />}
label="Change theme"
onPress={toggleTheme}
/>
</SideBarFooter>
}
>
<Outlet />
</SideBarLayout>

<div id="modalportal"></div>
</>
);
};
157 changes: 157 additions & 0 deletions packages/apps/dev-wallet/src/App/Layout/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import {
MonoContacts,
MonoContrast,
MonoDashboardCustomize,
MonoDataThresholding,
MonoLogout,
MonoNetworkCheck,
MonoSwapHoriz,
MonoTableRows,
MonoWallet,
} from '@kadena/kode-icons/system';

import { NetworkSelector } from '@/Components/NetworkSelector/NetworkSelector';
import { useWallet } from '@/modules/wallet/wallet.hook';
import {
Button,
ContextMenu,
ContextMenuItem,
Themes,
useTheme,
} from '@kadena/kode-ui';
import {
SideBarItem,
SideBarItemsInline,
SideBarTree,
SideBarTreeItem,
SideBar as SideBarUI,
useSideBar,
} from '@kadena/kode-ui/patterns';
import { FC } from 'react';
import { Link, useNavigate } from 'react-router-dom';

export const SideBar: FC = () => {
const { theme, setTheme } = useTheme();
const { isExpanded } = useSideBar();
const navigate = useNavigate();
const { lockProfile } = useWallet();

const toggleTheme = (): void => {
const newTheme = theme === Themes.dark ? Themes.light : Themes.dark;
setTheme(newTheme);
};

const handleLogout = () => {
lockProfile();
};
return (
<SideBarUI
appContext={
<SideBarItem visual={<MonoNetworkCheck />} label="Select network">
<NetworkSelector
showLabel={isExpanded}
variant="outlined"
isCompact={!isExpanded}
/>
</SideBarItem>
}
navigation={
<>
<SideBarItem
visual={<MonoDataThresholding />}
label="Dashboard"
component={Link}
href="/"
/>

<SideBarTree visual={<MonoWallet />} label="My Wallets">
<SideBarTreeItem
label="Keys"
component={Link}
href="/key-management/keys"
/>
</SideBarTree>
<SideBarTree visual={<MonoTableRows />} label="Transactions">
<SideBarTreeItem
label="History"
component={Link}
href="/transactions"
/>
</SideBarTree>
<SideBarTree visual={<MonoDashboardCustomize />} label="Utilities">
<SideBarTreeItem
label="Sig Builder"
component={Link}
href="/sig-builder"
/>
<SideBarTreeItem
label="Dev Console"
component={Link}
href="/terminal"
/>
<SideBarTreeItem
label="Backup"
component={Link}
href="/backup-recovery-phrase/write-down"
/>
</SideBarTree>

<SideBarItem
visual={<MonoSwapHoriz />}
label="Transfer"
component={Link}
href="/transfer"
/>

<SideBarItem
visual={<MonoContacts />}
label="Contacts"
component={Link}
href="/contacts"
/>
</>
}
context={
<>
<SideBarItemsInline>
<SideBarItem visual={<MonoContacts />} label="Profile">
<ContextMenu
trigger={
<Button
isCompact={!isExpanded}
variant="outlined"
endVisual={<MonoContacts />}
>
{isExpanded ? 'Profile' : undefined}
</Button>
}
>
<ContextMenuItem
onClick={() => navigate('/profile')}
label="Profile"
/>
<ContextMenuItem
endVisual={<MonoLogout />}
label="Logout"
onClick={handleLogout}
/>
</ContextMenu>
</SideBarItem>
<SideBarItem
visual={<MonoContrast />}
onPress={toggleTheme}
label="Change theme"
>
<Button
variant={isExpanded ? 'transparent' : 'outlined'}
onPress={() => toggleTheme()}
startVisual={<MonoContrast />}
isCompact={!isExpanded}
/>
</SideBarItem>
</SideBarItemsInline>
</>
}
></SideBarUI>
);
};
9 changes: 5 additions & 4 deletions packages/apps/dev-wallet/src/App/app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DatabaseProvider } from '@/modules/db/db.provider';
import { WalletProvider } from '@/modules/wallet/wallet.provider';
import { MediaContextProvider } from '@kadena/kode-ui';
import { SideBarProvider } from '@kadena/kode-ui/patterns';
import { useEffect } from 'react';
import { PromptProvider } from '../Components/PromptProvider/Prompt';
import { BetaHeader } from './BetaHeader';
import { Routes } from './routes';
import { SessionProvider } from './session';

Expand All @@ -19,8 +19,10 @@ function Providers({ children }: { children: React.ReactNode }) {
<PromptProvider>
<DatabaseProvider>
<WalletProvider>
{/* TODO: fixed the issue with prompt and remove this one in favor of the one above */}
<PromptProvider>{children}</PromptProvider>
<SideBarProvider>
{/* TODO: fixed the issue with prompt and remove this one in favor of the one above */}
<PromptProvider>{children}</PromptProvider>
</SideBarProvider>
</WalletProvider>
</DatabaseProvider>
</PromptProvider>
Expand All @@ -31,7 +33,6 @@ function Providers({ children }: { children: React.ReactNode }) {

export const App = () => (
<Providers>
<BetaHeader />
<Routes />
</Providers>
);
14 changes: 0 additions & 14 deletions packages/apps/dev-wallet/src/App/layout-mini.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ export const headerStyle = style({
minHeight: minHeaderHeight,
});

export const mainStyle = style([
atoms({
width: '100%',
color: 'text.base.default',
display: 'flex',
alignItems: 'center',
}),
{
minHeight: `calc(100vh - ${minHeaderHeight})`,
background: 'transparent', // fallback in case radial-gradient is not working
backgroundRepeat: 'no-repeat',
},
]);

export const containerStyle = style([
atoms({
padding: 'sm',
Expand Down
10 changes: 4 additions & 6 deletions packages/apps/dev-wallet/src/App/layout-mini.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { MainHeader } from '@/Components/MainHeader/MainHeader';

import { SideBarLayout } from '@kadena/kode-ui/patterns';
import { FC } from 'react';
import { Outlet } from 'react-router-dom';
import { containerStyle, mainStyle } from './layout-mini.css';
import { containerStyle } from './layout-mini.css';

export const LayoutMini: FC = () => {
return (
<>
<MainHeader />
<main className={mainStyle}>
<SideBarLayout variant="full">
<div className={containerStyle}>
<Outlet />
</div>
</main>
</SideBarLayout>
<div id="modalportal"></div>
</>
);
Expand Down
33 changes: 0 additions & 33 deletions packages/apps/dev-wallet/src/App/layout.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/apps/dev-wallet/src/App/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { HomePage } from '../pages/home/home-page';
import { SelectProfile } from '../pages/select-profile/select-profile';
import { UnlockProfile } from '../pages/unlock-profile/unlock-profile';
import { getScriptType } from '../utils/window';
import { Layout } from './layout';
import { Layout } from './Layout/Layout';
import { LayoutMini } from './layout-mini';

const Redirect: FC<
Expand Down
Loading

0 comments on commit 7cefeb1

Please sign in to comment.