-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
183 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { InkIcon } from "../.."; | ||
import { InkLayoutLink } from "../InkLayout/InkNavLink"; | ||
|
||
export const EXAMPLE_LINKS: InkLayoutLink[] = [ | ||
{ | ||
children: "Home", | ||
href: "#home", | ||
icon: <InkIcon.Home />, | ||
target: "_self", | ||
}, | ||
{ | ||
children: "Settings", | ||
href: "#settings", | ||
icon: <InkIcon.Settings />, | ||
target: "_self", | ||
}, | ||
]; |
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,11 @@ | ||
import { EXAMPLE_LINKS } from "./ExampleLayoutLinks"; | ||
import { | ||
InkLayoutMobileNav, | ||
InkLayoutMobileNavProps, | ||
} from "../InkLayout/MobileNav"; | ||
|
||
export const ExampleMobileNav = ( | ||
props: Omit<InkLayoutMobileNavProps, "links"> | ||
) => { | ||
return <InkLayoutMobileNav links={EXAMPLE_LINKS} {...props} />; | ||
}; |
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,23 +1,6 @@ | ||
import { InkIcon } from "../.."; | ||
import { InkLayoutSideNav } from "../InkLayout"; | ||
import { EXAMPLE_LINKS } from "./ExampleLayoutLinks"; | ||
|
||
export const ExampleSideNav = () => { | ||
return ( | ||
<InkLayoutSideNav | ||
links={[ | ||
{ | ||
children: "Home", | ||
href: "#home", | ||
icon: <InkIcon.Home />, | ||
target: "_self", | ||
}, | ||
{ | ||
children: "Settings", | ||
href: "#settings", | ||
icon: <InkIcon.Settings />, | ||
target: "_self", | ||
}, | ||
]} | ||
/> | ||
); | ||
return <InkLayoutSideNav links={EXAMPLE_LINKS} />; | ||
}; |
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,44 +1,109 @@ | ||
import { PropsWithChildren } from "react"; | ||
import { PropsWithChildren, useState } from "react"; | ||
import { DefaultAppIcon } from "../../icons"; | ||
import { classNames } from "../../util/classes"; | ||
import { Button, InkIcon } from "../.."; | ||
|
||
export interface InkLayoutProps extends PropsWithChildren { | ||
mainIcon?: React.ReactNode; | ||
headerContent?: React.ReactNode; | ||
sideNavigation?: React.ReactNode; | ||
topNavigation?: React.ReactNode; | ||
mobileNavigation?: ({ | ||
closeMobileNavigation, | ||
}: { | ||
closeMobileNavigation: () => void; | ||
}) => React.ReactNode; | ||
} | ||
|
||
export const InkLayout: React.FC<InkLayoutProps> = ({ | ||
mainIcon = <DefaultAppIcon className="ink:size-6" />, | ||
headerContent, | ||
sideNavigation, | ||
topNavigation, | ||
mobileNavigation, | ||
children, | ||
}) => { | ||
const [isMobileNavOpen, setIsMobileNavOpen] = useState(false); | ||
const hasSomethingInHeader = !!headerContent || !!mobileNavigation; | ||
return ( | ||
<div | ||
className={classNames( | ||
"ink:flex ink:flex-col ink:min-h-full ink:pb-5 ink:min-w-[320px] ink:font-default ink:text-text-default ink:gap-5 ink:box-border" | ||
)} | ||
> | ||
<div className="ink:w-full ink:flex ink:justify-between ink:items-center ink:gap-3 ink:px-5 ink:pt-4 ink:box-border"> | ||
<div className="ink:flex ink:items-center ink:justify-start ink:size-6 ink:gap-2"> | ||
{mainIcon} | ||
</div> | ||
{topNavigation && <div>{topNavigation}</div>} | ||
{headerContent ? ( | ||
<div className="ink:flex ink:items-center">{headerContent}</div> | ||
) : null} | ||
</div> | ||
<div className="ink:flex ink:flex-1 ink:mr-5 ink:box-border"> | ||
{sideNavigation && ( | ||
<div className={classNames("ink:w-[260px] ink:px-4")}> | ||
{sideNavigation} | ||
</div> | ||
<> | ||
<div | ||
className={classNames( | ||
"ink:flex ink:flex-col ink:min-h-full ink:pb-5 ink:min-w-[320px] ink:font-default ink:text-text-default ink:gap-5 ink:box-border" | ||
)} | ||
{children} | ||
> | ||
<div className="ink:w-full ink:flex ink:justify-between ink:items-center ink:gap-3 ink:px-5 ink:pt-4 ink:box-border"> | ||
<div className="ink:flex ink:items-center ink:justify-start ink:size-6 ink:gap-2"> | ||
{mainIcon} | ||
</div> | ||
<div className="ink:flex ink:flex-1 ink:justify-center ink:items-center"> | ||
{isMobileNavOpen && ( | ||
<div className="ink:text-h3 ink:transition-default-animation ink:opacity-100 ink:starting:opacity-0"> | ||
Menu | ||
</div> | ||
)} | ||
{topNavigation && ( | ||
<div className="ink:hidden ink:lg:block">{topNavigation}</div> | ||
)} | ||
</div> | ||
{hasSomethingInHeader && ( | ||
<div className="ink:flex ink:gap-1 ink:justify-end ink:items-center"> | ||
{!isMobileNavOpen && headerContent && ( | ||
<div className="ink:flex ink:items-center">{headerContent}</div> | ||
)} | ||
{mobileNavigation && ( | ||
<Button | ||
variant="wallet" | ||
size="md" | ||
rounded="full" | ||
className="ink:lg:hidden" | ||
onClick={() => setIsMobileNavOpen(!isMobileNavOpen)} | ||
> | ||
{isMobileNavOpen ? <InkIcon.Close /> : <InkIcon.Menu />} | ||
</Button> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
<div | ||
className={classNames( | ||
"ink:flex ink:flex-1 ink:mx-5 ink:box-border", | ||
sideNavigation && "ink:lg:ml-0" | ||
)} | ||
> | ||
{sideNavigation && ( | ||
<div | ||
className={classNames( | ||
"ink:w-[260px] ink:px-4 ink:hidden ink:lg:block" | ||
)} | ||
> | ||
{sideNavigation} | ||
</div> | ||
)} | ||
{children} | ||
</div> | ||
</div> | ||
</div> | ||
{isMobileNavOpen && ( | ||
<div | ||
style={ | ||
{ | ||
/** 48px components height + 32px top spacing + 32px spacing between header and content */ | ||
"--ink-mobile-nav-height": | ||
"calc(var(--ink-spacing-6) + var(--ink-spacing-4) + var(--ink-spacing-4))", | ||
} as React.CSSProperties | ||
} | ||
className={classNames( | ||
"ink:fixed ink:lg:hidden ink:lg:pointer-events-none ink:inset-0 ink:top-[var(--ink-mobile-nav-height)] ink:z-50", | ||
"ink:bg-background-light/20 ink:backdrop-blur-xl", | ||
"ink:transition-default-animation ink:opacity-100 ink:starting:opacity-0" | ||
)} | ||
> | ||
{mobileNavigation && | ||
mobileNavigation({ | ||
closeMobileNavigation: () => setIsMobileNavOpen(false), | ||
})} | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; |
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
33 changes: 33 additions & 0 deletions
33
src/layout/InkLayout/MobileNav/InkLayoutMobileNav.stories.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,33 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { | ||
InkLayoutMobileNav, | ||
InkLayoutMobileNavProps, | ||
} from "./InkLayoutMobileNav"; | ||
import { EXAMPLE_LINKS } from "../../ForStories/ExampleLayoutLinks"; | ||
|
||
const meta: Meta<InkLayoutMobileNavProps> = { | ||
decorators: [ | ||
(Story) => ( | ||
<> | ||
<div className="ink:w-full ink:h-full ink:box-border" /> | ||
<Story /> | ||
</> | ||
), | ||
], | ||
title: "Layouts/InkLayoutMobileNav", | ||
component: InkLayoutMobileNav, | ||
parameters: { | ||
layout: "fullscreen", | ||
}, | ||
tags: ["autodocs"], | ||
args: { | ||
links: EXAMPLE_LINKS, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Simple: Story = { | ||
args: {}, | ||
}; |
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,22 @@ | ||
import React from "react"; | ||
import { InkLayoutLink, InkNavLink } from "../InkNavLink"; | ||
|
||
export interface InkLayoutMobileNavProps { | ||
links: InkLayoutLink[]; | ||
onLinkClick?: React.MouseEventHandler<HTMLElement>; | ||
} | ||
|
||
export const InkLayoutMobileNav: React.FC<InkLayoutMobileNavProps> = ({ | ||
links, | ||
onLinkClick, | ||
}) => { | ||
return ( | ||
<nav className="ink:h-full ink:w-full ink:p-3 ink:box-border ink:font-default ink:text-text-default"> | ||
<div className="ink:flex ink:flex-col ink:gap-1"> | ||
{links.map((link) => { | ||
return <InkNavLink {...link} key={link.href} onClick={onLinkClick} />; | ||
})} | ||
</div> | ||
</nav> | ||
); | ||
}; |
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 "./InkLayoutMobileNav"; |