Skip to content

Commit

Permalink
Merge pull request #93 from inkonchain/feat/sticky-layout
Browse files Browse the repository at this point in the history
feat: make the side bar sticky by default
  • Loading branch information
fran-ink authored Feb 7, 2025
2 parents 9a16c44 + dfc3e18 commit 321bf3d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/layout/InkLayout/InkLayout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,24 @@ export const SideNavWithCustomButtons: Story = {
),
},
};

/**
* The side nav can be a custom component for routing, for instance, if you want to use NextJS' own {`<Link />`} component.
*/
export const StickySideNav: Story = {
args: {
children: (
<InkPageLayout>
<InkPanel className="ink:h-[2000px]">
<div className="ink:flex ink:flex-col ink:flex-1">
<div className="ink:flex-grow">
If the main content is bigger than the screen, the side nav will
be sticky.
</div>
<div className="ink:flex ink:flex-0">Bottom</div>
</div>
</InkPanel>
</InkPageLayout>
),
},
};
17 changes: 13 additions & 4 deletions src/layout/InkLayout/InkLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const InkLayout: React.FC<InkLayoutProps> = ({
<>
<div
className={classNames(
"ink:flex ink:flex-col ink:h-full ink:pb-5 ink:min-w-[320px] ink:font-default ink:text-text-default ink:gap-5 ink:box-border ink:w-full",
"ink:flex ink:flex-col ink:min-h-full ink:min-w-[320px] ink:font-default ink:text-text-default ink:gap-5 ink:box-border ink:w-full",
className
)}
>
Expand Down Expand Up @@ -73,21 +73,30 @@ export const InkLayout: React.FC<InkLayoutProps> = ({
</div>
<div
className={classNames(
"ink:flex ink:flex-1 ink:box-border ink:shrink-0 ink:w-full",
"ink:flex ink:flex-1 ink:box-border ink:shrink-0 ink:w-full ink:relative",
!snug && "ink:px-3 ink:sm:px-5",
sideNavigation && "ink:lg:pl-0"
)}
>
{sideNavigation && (
<div
style={
{
/** Header height + header top padding + header-content gap */
"--ink-side-nav-height":
"calc(var(--ink-spacing-6) + var(--ink-spacing-5) + var(--ink-spacing-4))",
} as React.CSSProperties
}
className={classNames(
"ink:w-[244px] ink:px-4 ink:hidden ink:lg:block ink:shrink-0 ink:box-border"
"ink:w-[244px] ink:px-4 ink:hidden ink:lg:block ink:shrink-0 ink:box-border ink:sticky ink:z-10 ink:bottom-0 ink:top-(--ink-side-nav-height) ink:max-h-[calc(100vh-var(--ink-side-nav-height))]"
)}
>
{sideNavigation}
</div>
)}
{children}
<div className="ink:flex-grow ink:flex ink:box-border ink:pb-5">
{children}
</div>
</div>
</div>
{isMobileNavOpen && (
Expand Down
2 changes: 1 addition & 1 deletion src/layout/InkParts/InkPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const InkPageLayout: React.FC<InkPageLayoutProps> = ({
return (
<div
className={classNames(
"ink:grid ink:gap-1 ink:*:h-full ink:auto-rows-min ink:md:auto-rows-auto ink:flex-1",
"ink:grid ink:gap-1 ink:*:min-h-full ink:auto-rows-min ink:md:auto-rows-auto ink:flex-1",
variantClassNames(columns, {
1: "ink:grid-cols-1",
2: "ink:md:grid-cols-[minmax(240px,1fr)_360px]",
Expand Down

0 comments on commit 321bf3d

Please sign in to comment.