-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add compound layout component (#1363)
* feat: add compound layout component * chore: add PageBoundary * test: add Layout to storybook * refactor: finalize compound layout * feat: add background to banner * test: update stories * move PageContainer into Layout * refactor: move header out, fix storybook * fix storybook * feat(Banner): add className prop * chore: add classname as optional --------- Co-authored-by: valid <[email protected]>
- Loading branch information
1 parent
7470a91
commit 3cc3cdc
Showing
5 changed files
with
143 additions
and
4 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
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 type { Meta, StoryFn } from "@storybook/react" | ||
import { Layout } from "." | ||
|
||
const meta: Meta = { | ||
title: "Design system/Layout", | ||
parameters: { | ||
layout: "fullscreen", | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
export const Static: StoryFn = () => ( | ||
<Layout.Root> | ||
<Layout.Hero> | ||
<Layout.Banner /> | ||
<Layout.Headline title="Layout title" /> | ||
</Layout.Hero> | ||
<Layout.Main>Page contents</Layout.Main> | ||
<Layout.Footer /> | ||
</Layout.Root> | ||
) |
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,108 @@ | ||
import { cn } from "@/lib/utils" | ||
import { Slot } from "@radix-ui/react-slot" | ||
import clsx from "clsx" | ||
import { PropsWithChildren, ReactNode, forwardRef } from "react" | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Root | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
const Root = ({ children }: PropsWithChildren) => ( | ||
<div className="flex min-h-screen flex-col">{children}</div> | ||
) | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* PageContainer | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
export interface PageContainerProps extends React.HTMLAttributes<HTMLDivElement> { | ||
asChild?: boolean | ||
} | ||
|
||
const PageContainer = forwardRef<HTMLDivElement, PageContainerProps>( | ||
({ children, className, asChild = false }, ref) => { | ||
const Comp = asChild ? Slot : "div" | ||
return ( | ||
<Comp | ||
className={clsx("mx-auto max-w-screen-lg px-4 sm:px-8 md:px-10", className)} | ||
ref={ref} | ||
> | ||
{children} | ||
</Comp> | ||
) | ||
} | ||
) | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Hero | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
const Hero = ({ children }: PropsWithChildren) => ( | ||
<div className="relative">{children}</div> | ||
) | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Headline | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
interface HeadlineProps { | ||
title: ReactNode | ||
} | ||
|
||
const Headline = ({ title }: HeadlineProps) => ( | ||
<PageContainer> | ||
<h1 className="pt-9 pb-14 font-bold font-display text-4xl text-white tracking-tight sm:text-5xl"> | ||
{title} | ||
</h1> | ||
</PageContainer> | ||
) | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Banner | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
interface BannerProps extends PropsWithChildren { | ||
offset?: number | ||
className?: string | ||
} | ||
|
||
const Banner = ({ children, offset = 112, className }: BannerProps) => ( | ||
<div | ||
className={cn( | ||
"-z-10 absolute inset-0 overflow-hidden", | ||
`-bottom-[${Math.abs(offset)}px]` | ||
)} | ||
> | ||
<div | ||
className={cn( | ||
"absolute inset-0 bg-[hsl(240_4%_16%)] data-[theme='dark']:bg-[hsl(240_3%_22%)]", | ||
className | ||
)} | ||
/> | ||
{children} | ||
</div> | ||
) | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Main | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
const Main = ({ children }: PropsWithChildren) => ( | ||
<main> | ||
<PageContainer>{children}</PageContainer> | ||
</main> | ||
) | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Footer | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
const Footer = ({ children }: PropsWithChildren) => ( | ||
<footer className="mt-auto"> | ||
<PageContainer>{children}</PageContainer> | ||
</footer> | ||
) | ||
|
||
/* -----------------------------------------------------------------------------------------------*/ | ||
|
||
export { Banner, Footer, Headline, Hero, Main, PageContainer, Root } |
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,4 @@ | ||
import { Header } from "@/components/Header" | ||
import { Banner, Footer, Headline, Hero, Main, Root } from "./Layout" | ||
|
||
export const Layout = { Root, Headline, Banner, Hero, Footer, Main, Header } |