This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
e106ffb
commit 550ae09
Showing
8 changed files
with
219 additions
and
99 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { css } from '@emotion/core'; | ||
import tokens from '@ruids/tokens'; | ||
import { Navbar } from './Navigation/Navbar'; | ||
import { ContentItem } from '@/lib/api'; | ||
import { Sidenav } from './Navigation/Sidenav'; | ||
|
||
const layout = { | ||
navigation: css({ | ||
position: 'sticky', | ||
top: '4rem', | ||
zIndex: 1000, | ||
height: 'calc(100vh - 4rem)', | ||
backgroundColor: tokens.colorNeutral20, | ||
borderRight: `1px solid ${tokens.colorNeutral30}`, | ||
}), | ||
}; | ||
|
||
interface LayoutProps { | ||
navigation: ContentItem[]; | ||
} | ||
|
||
export const Layout: React.FC<LayoutProps> = ({ navigation, children }) => { | ||
return ( | ||
<div> | ||
<Navbar items={navigation} /> | ||
<div className="w-full px-4 mx-auto" style={{ boxSizing: 'border-box' }}> | ||
<div className="grid grid-flow-col grid-cols-12 -mx-4"> | ||
<div className="col-span-2 px-4" css={layout.navigation}> | ||
<Sidenav items={navigation} /> | ||
</div> | ||
<main className="col-span-10 py-8 px-16">{children}</main> | ||
</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,99 @@ | ||
import React, { useMemo } from 'react'; | ||
import { css } from '@emotion/core'; | ||
import tokens from '@ruids/tokens'; | ||
import Link from 'next/link'; | ||
import { ContentItem } from '@/lib/api'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const styles = { | ||
primary: css({ | ||
boxSizing: 'border-box', | ||
display: 'flex', | ||
alignItems: 'center', | ||
padding: `${tokens.spacing4} ${tokens.spacing2}`, | ||
flexFlow: 'row nowrap', | ||
justifyContent: 'flex-start', | ||
height: '4rem', | ||
position: 'sticky', | ||
top: 0, | ||
zIndex: 1040, | ||
backgroundColor: tokens.colorNeutral800, | ||
}), | ||
left: css({ | ||
marginLeft: 'auto', | ||
color: tokens.colorNeutral0, | ||
}), | ||
listItem: css({ | ||
boxSizing: 'border-box', | ||
height: '4rem', | ||
justifyContent: 'center', | ||
flexDirection: 'column', | ||
display: 'flex', | ||
margin: 0, | ||
paddingLeft: tokens.spacing4, | ||
}), | ||
link: (active: boolean) => | ||
css({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
height: '100%', | ||
transition: 'color 0.1s ease-in-out 0s', | ||
position: 'relative', | ||
cursor: 'pointer', | ||
textDecoration: 'none', | ||
padding: `0 ${tokens.spacing4}`, | ||
color: tokens.colorNeutral0, | ||
backgroundColor: active ? tokens.colorNeutral900 : 'transparent', | ||
fontSize: tokens.textSm, | ||
':hover': { | ||
backgroundColor: tokens.colorNeutral600, | ||
}, | ||
}), | ||
}; | ||
|
||
export const NavLink: React.FC<{ | ||
item: ContentItem; | ||
}> = ({ item }) => { | ||
const router = useRouter(); | ||
|
||
const active = useMemo(() => { | ||
if (router.asPath === item.to) { | ||
return true; | ||
} | ||
return false; | ||
}, [item.to]); | ||
|
||
return ( | ||
<Link href={item.to}> | ||
<li css={styles.listItem}> | ||
<a css={styles.link(active)}>{item.title}</a> | ||
</li> | ||
</Link> | ||
); | ||
}; | ||
|
||
interface NavbarProps { | ||
items: ContentItem[]; | ||
} | ||
|
||
export const Navbar: React.FC<NavbarProps> = ({ items }) => { | ||
return ( | ||
<header role="banner" css={styles.primary}> | ||
<ul | ||
id="top" | ||
role="navigation" | ||
className="flex flex-row p-0 m-0" | ||
css={css({ | ||
listStyle: 'none', | ||
})} | ||
> | ||
{items.map((item, index) => ( | ||
<NavLink key={`navbar-${item.title}-${index}`} item={item} /> | ||
))} | ||
</ul> | ||
<div className="pr-5" css={styles.left}> | ||
side | ||
</div> | ||
</header> | ||
); | ||
}; |
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,73 @@ | ||
import React, { useMemo } from 'react'; | ||
import { ContentItem } from '@/lib/api'; | ||
import { css } from '@emotion/core'; | ||
import tokens from '@ruids/tokens'; | ||
import Link from 'next/link'; | ||
|
||
const styles = { | ||
wrapper: css({ | ||
boxSizing: 'border-box', | ||
borderTop: `1px solid ${tokens.colorNeutral30}`, | ||
overflow: 'hidden', | ||
display: 'block', | ||
height: '100%', | ||
}), | ||
nav: css({ | ||
height: '100%', | ||
overflow: 'auto', | ||
marginRight: '-40px', | ||
paddingRight: 'calc(40px + 1rem)', | ||
}), | ||
link: (children: boolean) => | ||
css({ | ||
color: tokens.colorTextDark, | ||
cursor: 'pointer', | ||
fontWeight: children ? tokens.fontBold : tokens.fontNormal, | ||
':hover': { | ||
color: tokens.colorTextLightest, | ||
}, | ||
}), | ||
childBox: css({ | ||
marginTop: tokens.spacing1, | ||
marginBottom: tokens.spacing4, | ||
}), | ||
}; | ||
|
||
const NavItem: React.FC<{ | ||
item: ContentItem; | ||
}> = ({ item }) => { | ||
const { children } = item; | ||
return ( | ||
<div data-children={!!children?.length}> | ||
<Link href={item.to}> | ||
<a css={styles.link(!!children.length)}>{item.title}</a> | ||
</Link> | ||
{!!children.length && ( | ||
<div css={styles.childBox}> | ||
{children.map((c, i) => ( | ||
<Link href={c.to}> | ||
<a css={styles.link(false)}>{c.title}</a> | ||
</Link> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export const Sidenav: React.FC<{ | ||
items: ContentItem[]; | ||
}> = ({ items }) => { | ||
return ( | ||
<React.Fragment> | ||
<div css={styles.wrapper}> | ||
<nav role="complementary" css={styles.nav} className="pt-2 pb-4"> | ||
{items.map((item, index) => ( | ||
<NavItem key={`sidenav-${item.title}-${index}`} item={item} /> | ||
))} | ||
</nav> | ||
sidenav | ||
</div> | ||
</React.Fragment> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
export { AppContext } from './AppContext/AppContext'; | ||
export { Head } from './Head'; | ||
export { Navigation } from './Navigation'; | ||
export { Frame, PageContent, Page } from './Page'; | ||
export { Layout } from './Layout'; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.