-
Notifications
You must be signed in to change notification settings - Fork 338
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
19 changed files
with
285 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
dist | ||
node_modules | ||
*storybook.log | ||
|
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
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,13 +1,9 @@ | ||
import { | ||
ComponentPropsWithoutRef, | ||
ElementType, | ||
PropsWithChildren, | ||
} from "react"; | ||
import { ComponentPropsWithoutRef, ElementType } from "react"; | ||
|
||
interface PolymorphicAsProp<E extends ElementType> { | ||
export type PolymorphicDefinition<E extends ElementType> = { | ||
as?: E; | ||
} | ||
asProps?: ComponentPropsWithoutRef<E>; | ||
}; | ||
|
||
export type PolymorphicProps<E extends ElementType> = PropsWithChildren< | ||
ComponentPropsWithoutRef<E> & PolymorphicAsProp<E> | ||
>; | ||
export type PolymorphicProps<E extends ElementType> = | ||
ComponentPropsWithoutRef<E> & PolymorphicDefinition<E>; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 +1,5 @@ | ||
import "./tailwind.css"; | ||
export * from "./components"; | ||
export * from "./layout"; | ||
export * from "./hooks"; | ||
export * as InkIcon from "./icons"; |
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,90 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { InkLayout, InkLayoutProps } from "./InkLayout"; | ||
import { Button, InkIcon, SegmentedControl } from "../.."; | ||
import { InkLayoutSideNav } from "./InkLayoutSideNav"; | ||
|
||
const SideNav = () => { | ||
return ( | ||
<InkLayoutSideNav | ||
links={[ | ||
{ | ||
label: "Home", | ||
href: "/", | ||
icon: <InkIcon.Home />, | ||
}, | ||
{ | ||
label: "Settings", | ||
href: "/settings", | ||
icon: <InkIcon.Settings />, | ||
}, | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
const TopNav = () => { | ||
return ( | ||
<SegmentedControl | ||
options={[ | ||
{ label: "Home", value: "home", selectedByDefault: true }, | ||
{ label: "Settings", value: "settings" }, | ||
]} | ||
onOptionChange={() => {}} | ||
/> | ||
); | ||
}; | ||
|
||
const meta: Meta<InkLayoutProps> = { | ||
title: "Layouts/InkLayout", | ||
component: InkLayout, | ||
parameters: { | ||
layout: "fullscreen", | ||
}, | ||
tags: ["autodocs"], | ||
args: { | ||
children: <div>Some content</div>, | ||
headerContent: <div>Header content</div>, | ||
topNavigation: <TopNav />, | ||
sideNavigation: <SideNav />, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Simple: Story = { | ||
args: {}, | ||
}; | ||
|
||
// Serves as a fun example of how to use `linkAs` to customize the underlying component of `InkNavLink`. | ||
// It is necessary to allow users to pass `Link` | ||
export const SideNavWithCustomButtons: Story = { | ||
args: { | ||
sideNavigation: ( | ||
<InkLayoutSideNav | ||
linkAs={{ | ||
as: Button, | ||
asProps: { variant: "secondary", as: "a", target: "_blank" }, | ||
}} | ||
links={[ | ||
{ | ||
label: "Home", | ||
href: "/", | ||
icon: <InkIcon.Home />, | ||
}, | ||
{ | ||
label: "Settings", | ||
href: "/settings", | ||
icon: <InkIcon.Settings />, | ||
}, | ||
]} | ||
/> | ||
), | ||
children: ( | ||
<div> | ||
The side nav can be a custom component for routing, for instance, if you | ||
want to use NextJS' own {`<Link />`} component. | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { PropsWithChildren } from "react"; | ||
import { DefaultAppIcon } from "../../icons"; | ||
import { classNames, resetClasses } from "../../util/classes"; | ||
|
||
export interface InkLayoutProps extends PropsWithChildren { | ||
mainIcon?: React.ReactNode; | ||
headerContent?: React.ReactNode; | ||
sideNavigation?: React.ReactNode; | ||
topNavigation?: React.ReactNode; | ||
} | ||
|
||
export const InkLayout: React.FC<InkLayoutProps> = ({ | ||
mainIcon = <DefaultAppIcon className="ink-size-6" />, | ||
headerContent, | ||
sideNavigation, | ||
topNavigation, | ||
children, | ||
}) => { | ||
return ( | ||
<div | ||
className={classNames( | ||
resetClasses, | ||
"ink-flex ink-flex-col ink-min-h-screen ink-min-w-[320px] ink-font-default ink-gap-5" | ||
)} | ||
> | ||
<div className="ink-w-full ink-flex ink-justify-between ink-items-center ink-gap-3 ink-px-5 ink-pt-4"> | ||
<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"> | ||
{sideNavigation && ( | ||
<div className={classNames("ink-w-[260px] ink-px-4")}> | ||
{sideNavigation} | ||
</div> | ||
)} | ||
<div className="ink-flex-1 ink-bg-background-light ink-rounded-24 ink-shadow-layout ink-p-3 ink-mr-5"> | ||
{children} | ||
</div> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import { InkLayoutLink, InkNavLink } from "./InkNavLink"; | ||
import { | ||
PolymorphicDefinition, | ||
PolymorphicProps, | ||
} from "../../components/polymorphic"; | ||
import { InkIcon } from "../.."; | ||
|
||
interface InkLayoutSideNavProps<T extends React.ElementType = "a"> { | ||
links: InkLayoutLink[]; | ||
linkAs?: PolymorphicDefinition<T>; | ||
} | ||
|
||
export const InkLayoutSideNav = <T extends React.ElementType = "a">({ | ||
links, | ||
linkAs, | ||
}: InkLayoutSideNavProps<T>) => { | ||
const { as, asProps, ...rest } = linkAs ?? {}; | ||
return ( | ||
<nav className="ink-min-h-screen"> | ||
<div className="ink-flex ink-flex-col ink-gap-1"> | ||
{links.map((link) => { | ||
// @ts-expect-error | ||
const linkProps: PolymorphicProps<T> & | ||
React.ComponentPropsWithoutRef<T> = { | ||
as, | ||
asProps, | ||
...rest, | ||
}; | ||
return <InkNavLink {...link} {...linkProps} />; | ||
})} | ||
</div> | ||
</nav> | ||
); | ||
}; | ||
|
||
<InkNavLink href="" label="Home" icon={<InkIcon.Home />} />; |
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,49 @@ | ||
import React, { ElementType } from "react"; | ||
import { PolymorphicProps } from "../../components/polymorphic"; | ||
import { classNames, resetClasses } from "../../util/classes"; | ||
|
||
const DEFAULT_COMPONENT_TYPE = "a" as const; | ||
|
||
export interface InkLayoutLink { | ||
label: string; | ||
href: string; | ||
icon: React.ReactNode; | ||
} | ||
|
||
export type InkNavLinkProps< | ||
T extends ElementType = typeof DEFAULT_COMPONENT_TYPE, | ||
> = PolymorphicProps<T> & | ||
InkLayoutLink & { | ||
className?: string; | ||
}; | ||
|
||
export const InkNavLink = < | ||
T extends ElementType = typeof DEFAULT_COMPONENT_TYPE, | ||
>({ | ||
as, | ||
asProps, | ||
href, | ||
icon, | ||
label, | ||
className = "", | ||
...props | ||
}: InkNavLinkProps<T>) => { | ||
const Component = as ?? DEFAULT_COMPONENT_TYPE; | ||
|
||
return ( | ||
<Component | ||
href={href} | ||
className={classNames( | ||
resetClasses, | ||
Component === DEFAULT_COMPONENT_TYPE && | ||
"ink-flex ink-items-center ink-gap-1.5 ink-px-1.5 ink-py-1.5 ink-text-inherit ink-no-underline ink-rounded-16 ink-transition-colors ink-duration-200 hover:ink-bg-background-container", | ||
className | ||
)} | ||
{...asProps} | ||
{...props} | ||
> | ||
<div className="ink-size-3">{icon}</div> | ||
<div>{label}</div> | ||
</Component> | ||
); | ||
}; |
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,2 @@ | ||
export * from "./InkLayout"; | ||
export * from "./InkLayoutSideNav"; |
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 "./InkLayout"; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
:root { | ||
--ink-box-shadow-menu: 0px 8px 24px -8px #160f1f1a; | ||
--ink-box-shadow-modal: 0px 16px 64px -32px #160f1f1a; | ||
--ink-box-shadow-layout: 0px 16px 64px -32px #160f1f0d; | ||
} |
Oops, something went wrong.