-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: header to app component, link context
- Loading branch information
1 parent
1bed424
commit 24c7476
Showing
19 changed files
with
152 additions
and
64 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
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
27 changes: 27 additions & 0 deletions
27
integrations/gatsby-theme-stories/src/components/GatsbyLink.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,27 @@ | ||
/** @jsx jsx */ | ||
import { FC } from 'react'; | ||
import { jsx, LinkProps, Theme } from 'theme-ui'; | ||
import { Link } from 'gatsby'; | ||
|
||
export const GatsbyLink: FC<LinkProps & { to?: string }> = ({ | ||
href, | ||
to, | ||
...props | ||
}) => ( | ||
//@ts-ignore | ||
<Link | ||
to={href || to || ''} | ||
{...props} | ||
activeClassName="active" | ||
sx={{ | ||
color: 'inherit', | ||
'&.active': { | ||
borderLeft: (t: Theme) => `4px solid ${t?.colors?.accent}`, | ||
color: 'white', | ||
}, | ||
':hover': { | ||
backgroundColor: 'shadow', | ||
}, | ||
}} | ||
/> | ||
); |
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
22 changes: 2 additions & 20 deletions
22
integrations/gatsby-theme-stories/src/components/Sidebar.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 |
---|---|---|
@@ -1,30 +1,12 @@ | ||
/** @jsx jsx */ | ||
import { FC } from 'react'; | ||
import { jsx, LinkProps, Theme } from 'theme-ui'; | ||
import { Link as GatsbyLink } from 'gatsby'; | ||
import { jsx } from 'theme-ui'; | ||
import { Sidebar as AppSidebar } from '@component-controls/app'; | ||
|
||
const Link: FC<LinkProps> = props => ( | ||
//@ts-ignore | ||
<GatsbyLink | ||
{...props} | ||
activeClassName="active" | ||
sx={{ | ||
color: 'inherit', | ||
'&.active': { | ||
borderLeft: (t: Theme) => `4px solid ${t?.colors?.accent}`, | ||
color: 'white', | ||
}, | ||
':hover': { | ||
backgroundColor: 'shadow', | ||
}, | ||
}} | ||
/> | ||
); | ||
export interface SidebarProps { | ||
docPath?: string; | ||
} | ||
|
||
export const Sidebar: FC<SidebarProps> = ({ docPath }) => { | ||
return <AppSidebar docPath={docPath} buttonClass={Link} />; | ||
return <AppSidebar docPath={docPath} />; | ||
}; |
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,7 @@ | ||
import React, { FC } from 'react'; | ||
import { LinkProps } from 'theme-ui'; | ||
import { useGetLinkClass } from './LinkContext'; | ||
export const Link: FC<LinkProps> = props => { | ||
const LinkClass = useGetLinkClass(); | ||
return <LinkClass {...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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React, { FC, createContext, useContext } from 'react'; | ||
import { Link, LinkProps } from 'theme-ui'; | ||
|
||
export type LinkClassType = React.FC<LinkProps>; | ||
const LinkContext = createContext<LinkClassType>(Link); | ||
|
||
export const LinkContextProvider: FC<{ | ||
linkClass: LinkClassType; | ||
}> = ({ linkClass: LinkClass, children }) => { | ||
return ( | ||
<LinkContext.Provider value={LinkClass}>{children}</LinkContext.Provider> | ||
); | ||
}; | ||
export const useGetLinkClass = () => { | ||
return useContext(LinkContext) || Link; | ||
}; |
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 './Link'; | ||
export * from './LinkContext'; |
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,5 +1,6 @@ | ||
export * from './ColorMode'; | ||
export * from './Header'; | ||
export * from './Keyboard'; | ||
export * from './Link'; | ||
export * from './Navmenu'; | ||
export * from './Sidebar'; |
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,50 @@ | ||
/** @jsx jsx */ | ||
import { FC, useContext } from 'react'; | ||
import { jsx, Flex, Text } from 'theme-ui'; | ||
import { | ||
Link, | ||
ColorMode, | ||
SidebarContext, | ||
Header as AppHeader, | ||
} from '@component-controls/app-components'; | ||
|
||
interface HeaderProps { | ||
title?: string; | ||
} | ||
export const Header: FC<HeaderProps> = () => { | ||
const { SidebarToggle, collapsed, responsive } = useContext(SidebarContext); | ||
|
||
return ( | ||
<AppHeader position="sticky"> | ||
<Flex | ||
sx={{ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
color: `secondary`, | ||
a: { | ||
color: `secondary`, | ||
':hover': { color: `accent` }, | ||
fontWeight: '700', | ||
}, | ||
}} | ||
> | ||
{collapsed && <SidebarToggle />} | ||
<Flex | ||
sx={{ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
py: 3, | ||
}} | ||
> | ||
<Link href="/"> | ||
<Text sx={{ px: 2 }}>Home</Text> | ||
</Link> | ||
<Link href="/docs/"> | ||
<Text sx={{ px: 2 }}>Docs</Text> | ||
</Link> | ||
</Flex> | ||
</Flex> | ||
{!responsive && <ColorMode />} | ||
</AppHeader> | ||
); | ||
}; |
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 './Header'; |
Oops, something went wrong.