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

feat(website): updated sidebar component and layout improvements #1575

Merged
merged 29 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7ad6952
fix(website): CAN-624
nicosampler Nov 14, 2024
acb9fd8
review fixes
nicosampler Nov 14, 2024
c6ef855
fix heights
nicosampler Nov 15, 2024
5bab03c
Merge branch 'dev' into fix/CAN-624
nicosampler Nov 15, 2024
e162dc5
Merge remote-tracking branch 'origin/dev' into fix/CAN-624
nicosampler Nov 18, 2024
631e157
Merge remote-tracking branch 'origin/dev' into fix/CAN-624
nicosampler Nov 18, 2024
301702c
Merge remote-tracking branch 'origin/dev' into fix/CAN-624
nicosampler Nov 19, 2024
2035f0f
normalize sidebars
nicosampler Nov 19, 2024
3b613cd
misc fixes
nicosampler Nov 20, 2024
1bef416
fix height
nicosampler Nov 20, 2024
8bd882b
interact
nicosampler Nov 20, 2024
53f48b5
add code/interact sidebars
nicosampler Nov 21, 2024
2ebca6e
wip new layout
nicosampler Nov 28, 2024
71296d0
fixes
nicosampler Dec 4, 2024
9b102e3
lint error
nicosampler Dec 5, 2024
23466b7
fix: cannon file tab in package
nicosampler Dec 5, 2024
d796c8d
misc fixes
nicosampler Dec 5, 2024
758a5d4
more fixes
nicosampler Dec 5, 2024
077169c
mobile fixes
nicosampler Dec 11, 2024
70b7493
fix: layout packages (#1596)
nicosampler Dec 18, 2024
5a0925a
fix: layout /learn (#1597)
nicosampler Dec 18, 2024
4afc5ff
fix: interact code missing header (#1599)
nicosampler Dec 18, 2024
61c0593
Merge branch 'dev' into fix/CAN-624-b
nicosampler Dec 18, 2024
cd48d60
unused dep
nicosampler Dec 18, 2024
1c58319
misc fixes
nicosampler Dec 18, 2024
83da282
misc fixes
nicosampler Dec 20, 2024
83502fe
Merge branch 'dev' into fix/CAN-624-b
noahlitvin Dec 27, 2024
fd2889f
docs improvement
noahlitvin Dec 27, 2024
ed4c430
lint fix
noahlitvin Dec 27, 2024
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
1 change: 0 additions & 1 deletion packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
"styled-components": "^6.0.7",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"usehooks-ts": "^3.1.0",
"viem": "^2.21.15",
"wagmi": "^2.5.13",
"zod": "^3.23.8",
Expand Down
4 changes: 2 additions & 2 deletions packages/website/src/components/CodePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const EditorStyles = createGlobalStyle`
export const CodePreview: FC<ICodePreviewProps> = ({
code,
language,
height = '190px',
line,
height,
editorProps,
}) => {
const editorRef = useRef<any>(null);
Expand Down Expand Up @@ -62,7 +62,7 @@ export const CodePreview: FC<ICodePreviewProps> = ({
<>
<EditorStyles />
<Editor
height={height}
height={height || '100%'}
theme="vs-dark"
defaultLanguage={language || 'javascript'}
value={code}
Expand Down
15 changes: 15 additions & 0 deletions packages/website/src/components/MainContentLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CustomSpinner } from '@/components/CustomSpinner';

/* {
hasSubheader,
}: {
hasSubheader?: boolean;
} */

export default function MainContentLoading() {
return (
<div className={'h-screen w-screen flex justify-center items-center'}>
<CustomSpinner />
</div>
);
}
2 changes: 1 addition & 1 deletion packages/website/src/components/PageLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CustomSpinner } from '@/components/CustomSpinner';

export default function PageLoading() {
return (
<div className="flex min-h-screen w-full flex-col items-center justify-center">
<div className="h-screen w-screen flex items-center justify-center">
<CustomSpinner />
</div>
);
Expand Down
119 changes: 119 additions & 0 deletions packages/website/src/components/layouts/SidebarLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
'use client';

import { ReactNode, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Menu } from 'lucide-react';
import {
Sidebar,
SidebarContent,
SidebarProvider,
SidebarTrigger,
useSidebar,
} from '@/components/ui/sidebar';
import { useRouter } from 'next/router';

const CloseOnLeave = () => {
const { setOpenMobile } = useSidebar();
const router = useRouter();
const fullPath = router.asPath;

useEffect(() => {
const handleHashChange = () => {
setOpenMobile(false);
};

// Detect initial load and hash change
handleHashChange();

// Add listener for hash changes
window.addEventListener('hashchange', handleHashChange);

// Cleanup the listener on unmount
return () => {
window.removeEventListener('hashchange', handleHashChange);
};
}, [setOpenMobile, fullPath]);

return null;
};

interface SidebarLayoutProps {
children: ReactNode;
sidebarContent?: ReactNode;
centered?: boolean;
hasSubheader?: boolean;
fixedFooter?: boolean;
contentHeight?: string;
sidebarTop?: string;
mainContentOverflowY?: 'auto' | 'visible';
borderlessSidebar?: boolean;
}

export function SidebarLayout({
children,
sidebarContent,
centered = true,
hasSubheader = false,
fixedFooter = true,
contentHeight,
sidebarTop,
mainContentOverflowY = 'auto',
borderlessSidebar = false,
}: SidebarLayoutProps) {
const headerVar = 'var(--header-height)';
const subheaderVar = hasSubheader ? 'var(--subheader-height)' : '0px';
const footerVar = fixedFooter ? 'var(--footer-height)' : '0px';

const sidebarStyles = {
top: sidebarTop ? sidebarTop : `calc(${headerVar} + ${subheaderVar})`,
height: contentHeight
? contentHeight
: `calc(100vh - ${headerVar} - ${subheaderVar} - ${footerVar})`,
};

return (
<SidebarProvider>
<CloseOnLeave />
{/* Mobile Sidebar Trigger - Fixed to left side */}
{sidebarContent && (
<main className="fixed left-0 top-1/2 -translate-y-1/2 z-[50] md:hidden bg-black border border-border border-l-0 rounded-r-lg [&:has([data-state=open])]:hidden">
<SidebarTrigger>
<Button
size="icon"
className="h-8 w-8 rounded-r-lg rounded-l-none border-l-0"
aria-label="Toggle sidebar"
>
<Menu className="h-4 w-4" />
</Button>
</SidebarTrigger>
</main>
)}

{sidebarContent && (
<Sidebar
style={sidebarStyles}
className={`z-[100] sticky w-[280px] md:w-[280px] shrink-0 overflow-y-auto ${
borderlessSidebar ? 'border-none' : 'border-r border-border'
}`}
>
<SidebarContent
/* className={centered ? 'py-6 lg:py-8 bg-black' : 'overflow-y-auto'} */
className={centered ? 'bg-black' : ''}
>
{sidebarContent}
</SidebarContent>
</Sidebar>
)}

{/* Main content */}
<main
className={`cannon-page-main-content overflow-y-${mainContentOverflowY} flex-1 h-[${
contentHeight ? contentHeight : 'auto'
}]`}
>
{/* container p-4 md:px-6 lg:px-8 ml-0 */}
<div className="h-full w-full">{children}</div>
</main>
</SidebarProvider>
);
}
8 changes: 4 additions & 4 deletions packages/website/src/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Slot } from '@radix-ui/react-slot';
import { VariantProps, cva } from 'class-variance-authority';
import { PanelLeft } from 'lucide-react';

import { useIsMobile } from '@/hooks/use-mobile';
import { useIsMobile } from '@/hooks/useMedia';
import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
Expand Down Expand Up @@ -139,7 +139,7 @@ const SidebarProvider = React.forwardRef<
} as React.CSSProperties
}
className={cn(
'group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar',
'group/sidebar-wrapper flex w-full has-[[data-variant=inset]]:bg-sidebar',
className
)}
ref={ref}
Expand Down Expand Up @@ -222,7 +222,7 @@ const Sidebar = React.forwardRef<
{/* This is what handles the sidebar gap on desktop */}
<div
className={cn(
'duration-200 relative h-svh w-[--sidebar-width] bg-transparent transition-[width] ease-linear',
'duration-200 relative bg-transparent transition-[width] ease-linear',
'group-data-[collapsible=offcanvas]:w-0',
'group-data-[side=right]:rotate-180',
variant === 'floating' || variant === 'inset'
Expand All @@ -232,7 +232,7 @@ const Sidebar = React.forwardRef<
/>
<div
className={cn(
'duration-200 fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex',
'flex duration-200 inset-y-0 z-10 hidden w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex',
side === 'left'
? 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]'
: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]',
Expand Down
7 changes: 3 additions & 4 deletions packages/website/src/features/Deploy/WithSafe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAccount, useBytecode } from 'wagmi';
import PrepareNetwork from './PrepareNetwork';
import * as onchainStore from '../../helpers/onchain-store';
import * as multicallForwarder from '../../helpers/trusted-multicall-forwarder';
import { Loader2 } from 'lucide-react'; // for spinner
import MainContentLoading from '@/components/MainContentLoading';

export default function WithSafe({ children }: { children: ReactNode }) {
const currentSafe = useStore((s) => s.currentSafe);
Expand Down Expand Up @@ -39,9 +39,7 @@ export default function WithSafe({ children }: { children: ReactNode }) {
<div className="flex flex-col flex-1">
{currentSafe ? (
isLoadingNetworkPrepared ? (
<div className="m-auto">
<Loader2 className="h-8 w-8 animate-spin" />
</div>
<MainContentLoading />
) : isNetworkPrepared ? (
children
) : (
Expand All @@ -57,6 +55,7 @@ export default function WithSafe({ children }: { children: ReactNode }) {
rel="noopener noreferrer"
className="inline-block mx-2 text-gray-200 no-underline hover:no-underline translate-y-[3px] opacity-80"
>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
className="h-[18px] object-cover"
src="/images/safe.svg"
Expand Down
Loading
Loading