Skip to content

Commit

Permalink
fix sidemenu grid
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Oct 31, 2024
1 parent 955ad3a commit 1b9260f
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 75 deletions.
1 change: 1 addition & 0 deletions packages/apps/dev-wallet/src/App/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const Layout: FC = () => {
<SideBarLayout
topBanner={<BetaHeader />}
breadcrumbs={<BreadCrumbs />}
activeUrl={location.pathname}
sidebar={<SideBar />}
footer={
<SideBarFooter>
Expand Down
4 changes: 4 additions & 0 deletions packages/libs/kode-ui/.storybook/global.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ globalStyle('pre.prismjs > div, pre.prismjs > div span, code', {
globalStyle('code', {
fontWeight: vars.fontWeights.$semiBold,
});

globalStyle('body', {
padding: '0!important',
});
68 changes: 54 additions & 14 deletions packages/libs/kode-ui/src/patterns/SideBarLayout/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,83 @@
import { MonoMenu, MonoMenuOpen } from '@kadena/kode-icons/system';
import classNames from 'classnames';
import type { FC, PropsWithChildren, ReactElement } from 'react';
import React from 'react';
import type { PressEvent } from './../../components';
import { Button, Media, Stack } from './../../components';
import { KLogo } from './components/Logo/KLogo';
import { KadenaLogo } from './components/Logo/KadenaLogo';
import { SideBarAppContext } from './components/SideBarAppContext';
import { SideBarContext } from './components/SideBarContext';
import { SideBarNavigation } from './components/SideBarNavigation';
import { useSideBar } from './components/SideBarProvider';
import {
menuBackdropClass,
menuMenuIconClass,
menuWrapperClass,
menuWrapperMobileExpandedClass,
} from './sidebar.css';

export interface ISideBarProps extends PropsWithChildren {
activeUrl?: string;
logo?: ReactElement;

appContext?: ReactElement;
navigation?: ReactElement;
context?: ReactElement;
logo?: ReactElement;
minifiedLogo?: ReactElement;
}

export const SideBar: FC<ISideBarProps> = ({
children,
appContext,
navigation,
context,
logo,
minifiedLogo,
}) => {
const { isExpanded } = useSideBar();
const { isExpanded, handleToggleExpand } = useSideBar();

const handleExpand = (e: PressEvent) => {
if (handleToggleExpand) {
handleToggleExpand(e);
}
};

const ShowLogo = () => {
if (!isExpanded) {
return minifiedLogo ? minifiedLogo : <KLogo height={40} />;
}

return logo ? logo : <KadenaLogo height={40} />;
};

return (
<aside
className={classNames(menuWrapperClass({ expanded: isExpanded }), {
[menuWrapperMobileExpandedClass]: isExpanded,
})}
>
{appContext && <SideBarAppContext>{appContext}</SideBarAppContext>}
{navigation && <SideBarNavigation>{navigation}</SideBarNavigation>}
{context && <SideBarContext>{context}</SideBarContext>}

{children}
</aside>
<>
<Stack
className={menuBackdropClass({ expanded: isExpanded })}
onClick={handleExpand}
/>
<aside
className={classNames(menuWrapperClass({ expanded: isExpanded }), {
[menuWrapperMobileExpandedClass]: isExpanded,
})}
>
<Stack className={classNames(menuMenuIconClass)}>
<Media lessThan="md">{ShowLogo()}</Media>
<Media greaterThanOrEqual="md">{ShowLogo()}</Media>

<Button
variant="transparent"
onPress={handleExpand}
startVisual={isExpanded ? <MonoMenuOpen /> : <MonoMenu />}
/>
</Stack>

{appContext && <SideBarAppContext>{appContext}</SideBarAppContext>}
{navigation && <SideBarNavigation>{navigation}</SideBarNavigation>}
{context && <SideBarContext>{context}</SideBarContext>}

{children}
</aside>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,13 @@ const InnerLayout = () => {

return (
<SideBarLayout
logo={
<a href="https://kadena.io" target="_blank" rel="noreferrer">
<KadenaLogo height={40} />
</a>
}
minifiedLogo={
<a href="https://kadena.io" target="_blank" rel="noreferrer">
<KLogo height={40} />
</a>
}
activeUrl="https://kadena.io"
topBanner={<div>topbanner</div>}
// topBanner={<div style={{ paddingBlock: '10px' }}>topbanner</div>}
breadcrumbs={
<Breadcrumbs icon={<MonoAccountTree />}>
<BreadcrumbsItem href="/accounts">He-man</BreadcrumbsItem>
Expand All @@ -90,6 +85,16 @@ const InnerLayout = () => {
}
sidebar={
<SideBar
logo={
<a href="https://kadena.io" target="_blank" rel="noreferrer">
<KadenaLogo height={40} />
</a>
}
minifiedLogo={
<a href="https://kadena.io" target="_blank" rel="noreferrer">
<KLogo height={40} />
</a>
}
appContext={
<SideBarItem
visual={<MonoWifiTethering />}
Expand Down
24 changes: 19 additions & 5 deletions packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MediaContextProvider, Stack } from './../../components';
import { SideBarHeader } from './components/SideBarHeader';
import { useSideBar } from './components/SideBarProvider';
import {
bodyWrapperClass,
layoutExpandedWrapperClass,
layoutWrapperClass,
mainClass,
Expand Down Expand Up @@ -47,14 +48,27 @@ export const SideBarLayout: FC<ISideBarLayout> = ({
width="100%"
flexDirection="column"
position="relative"
style={{ minHeight: '100dvh' }}
className={bodyWrapperClass}
>
{topBanner}
<Stack
className={classNames(layoutWrapperClass({ variant }), {
[layoutExpandedWrapperClass]: isExpanded,
})}
className={classNames(
layoutWrapperClass({ variant, hasTopBanner: !!topBanner }),
{
[layoutExpandedWrapperClass]: isExpanded,
},
)}
>
{topBanner && (
<Stack
style={{
gridArea: 'sidebarlayout-topbanner',
overflowY: 'hidden',
background: 'green',
}}
>
{topBanner}
</Stack>
)}
<SideBarHeader
breadcrumbs={breadcrumbs}
hasSidebar={!!sidebar}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@ import { Button } from './../../../components/Button';
import { Stack } from './../../../components/Layout';
import { Media } from './../../../components/Media';
import { KLogo } from './Logo/KLogo';
import { KadenaLogo } from './Logo/KadenaLogo';
import { useSideBar } from './SideBarProvider';

interface IProps extends PropsWithChildren {
logo?: ReactElement;
minifiedLogo?: ReactElement;
breadcrumbs?: ReactElement;
minifiedLogo?: ReactElement;
hasSidebar?: boolean;
}

export const SideBarHeader: FC<IProps> = ({
logo,
minifiedLogo,
breadcrumbs,
hasSidebar = true,
}) => {
export const SideBarHeader: FC<IProps> = ({ breadcrumbs, minifiedLogo }) => {
const { isExpanded, handleToggleExpand } = useSideBar();
const handleExpand = (e: PressEvent) => {
if (handleToggleExpand) {
Expand All @@ -37,11 +30,7 @@ export const SideBarHeader: FC<IProps> = ({
};

const ShowLogo = () => {
if (!isExpanded && hasSidebar) {
return minifiedLogo ? minifiedLogo : <KLogo height={40} />;
}

return logo ? logo : <KadenaLogo height={40} />;
return minifiedLogo ? minifiedLogo : <KLogo height={40} />;
};

return (
Expand All @@ -56,18 +45,17 @@ export const SideBarHeader: FC<IProps> = ({
<Stack style={{ gridArea: 'header-logo' }}>
<>
<Media lessThan="md">{ShowLogo()}</Media>
<Media greaterThanOrEqual="md">{ShowLogo()}</Media>
</>
</Stack>
{hasSidebar && (
<Media lessThan="md">
<Stack className={classNames(menuMenuIconClass)}>
<Button
variant="transparent"
onPress={handleExpand}
startVisual={isExpanded ? <MonoMenuOpen /> : <MonoMenu />}
/>
</Stack>
)}
</Media>
<Stack style={{ gridArea: 'header-crumbs' }}>{breadcrumbs}</Stack>
</Stack>
</header>
Expand Down
76 changes: 55 additions & 21 deletions packages/libs/kode-ui/src/patterns/SideBarLayout/sidebar.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,39 @@ import {
} from './../../styles';
import { minHeaderHeight } from './styles.css';

export const menuBackdropClass = recipe({
base: [
responsiveStyle({
xs: {
display: 'flex',
position: 'absolute',
inset: 0,
background: token('color.neutral.n90@alpha20'),
zIndex: token('zIndex.overlay'),
backdropFilter: 'blur(8px)',
opacity: 0,
willChange: 'transform, opacity',
transition: 'transform .4s ease, opacity 1s ease',
transform: 'translateX(-100%)',
},
md: {
display: 'none!important',
},
}),
],
variants: {
expanded: {
true: [
{
opacity: 1,
transform: 'translateX(0%)',
},
],
false: [atoms({}), {}],
},
},
});

export const menuWrapperClass = recipe({
base: [
atoms({
Expand All @@ -21,17 +54,18 @@ export const menuWrapperClass = recipe({
responsiveStyle({
xs: {
flex: 1,
maxWidth: '300px',
width: '100dvw',
display: 'flex',
willChange: 'transform',
transition: 'transform .4s ease',
transform: 'translateX(-100%)',
position: 'relative',
gridArea: 'sidebarlayout-main',
gridRow: '2/4',
gridRow: '1/5',
inset: 0,
zIndex: token('zIndex.overlay'),
backgroundColor: token('color.background.base.default'),
backgroundColor: token('color.background.layer.default'),
padding: token('spacing.lg'),
},
md: {
Expand All @@ -41,7 +75,6 @@ export const menuWrapperClass = recipe({
paddingBlockStart: '0',
paddingInline: token('spacing.xs'),
gridArea: 'sidebarlayout-sidebar',
gridRow: '2/3',
transform: 'translateX(0%)',
backgroundColor: 'transparent',
},
Expand Down Expand Up @@ -160,28 +193,28 @@ globalStyle(`${listItemClass} a`, { justifyContent: 'flex-start', flex: 1 });
export const headerWrapperClass = style([
{
display: 'flex',
position: 'absolute',
justifyContent: 'flex-start',
width: '100%',
height: minHeaderHeight,
gridArea: 'sidebarlayout-header',
},

responsiveStyle({
xs: {
gridTemplateColumns: 'auto',
gridTemplateRows: `${minHeaderHeight} auto 60px`,
gridTemplateAreas: `
"sidebarlayout-header"
"sidebarlayout-main"
"sidebarlayout-footer"
`,
},
// xs: {
// gridTemplateColumns: 'auto',
// gridTemplateRows: `${minHeaderHeight} auto 60px`,
// gridTemplateAreas: `
// "sidebarlayout-header"
// "sidebarlayout-main"
// "sidebarlayout-footer"
// `,
// },
md: {
gridTemplateColumns: `50px auto 50px`,
gridTemplateRows: 'auto',
gridTemplateAreas: `
"header-logo header-toggle header-crumbs"
`,
// gridTemplateColumns: `50px auto 50px`,
// gridTemplateRows: 'auto',
// gridTemplateAreas: `
// "header-logo header-toggle header-crumbs"
// `,
},
}),
]);
Expand All @@ -192,15 +225,16 @@ export const headerClass = style([

responsiveStyle({
xs: {
gridTemplateColumns: `50px auto 50px`,
gridTemplateColumns: `50px 1fr 50px`,
gridTemplateAreas: `
"header-logo header-crumbs header-toggle"
`,
},
md: {
gridTemplateColumns: '150px 50px auto',
gridTemplateColumns: '1fr',
gridTemplateRows: 'auto',
gridTemplateAreas: `
"header-logo header-toggle header-crumbs"
"header-crumbs"
`,
},
}),
Expand Down
Loading

0 comments on commit 1b9260f

Please sign in to comment.