Skip to content

Commit 0add3f9

Browse files
committed
Update to new layout
Adds theme switch. Fixes fonts Update version Fixes some typing issues Fixes table coloring
1 parent b8ae280 commit 0add3f9

File tree

12 files changed

+134
-60
lines changed

12 files changed

+134
-60
lines changed

example/docs/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The gatsby theme allows you to write documentation in Markdown. With support for
1717
- :tropical_fish: mermaid diagrams
1818
- :package: @committed/components
1919
- :tada: :shortcode: emoji.
20+
- :mag: search
2021

2122
This is meant for Committed's documentation site, but feel free to use it, or copy it, for your own projects.
2223

example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "example",
3-
"version": "1.0.7",
3+
"version": "2.0.0",
44
"main": "index.js",
55
"author": "Committed <[email protected]>",
66
"license": "MIT",
@@ -13,7 +13,7 @@
1313
"deploy": "gh-pages -d public -r https://[email protected]/commitd/docs.git"
1414
},
1515
"dependencies": {
16-
"@committed/gatsby-theme-docs": "^1.0.7",
16+
"@committed/gatsby-theme-docs": "^2.0.0",
1717
"gatsby": "^2.21.9",
1818
"gatsby-plugin-manifest": "^2.4.1",
1919
"react": "^16.13.1",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@committed/gatsby-theme-docs-workspace",
33
"private": true,
4-
"version": "1.0.7",
4+
"version": "2.0.0",
55
"main": "index.js",
66
"license": "MIT",
77
"scripts": {

theme/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@committed/gatsby-theme-docs",
3-
"version": "1.0.7",
3+
"version": "2.0.0",
44
"main": "index.js",
55
"author": "Committed <[email protected]>",
66
"license": "MIT",
@@ -30,13 +30,13 @@
3030
"react-dom": "^16.13.1"
3131
},
3232
"dependencies": {
33-
"@committed/components": "^3.0.0",
34-
"@committed/layout": "^1.1.0",
33+
"@committed/components": "^3.0.2",
34+
"@committed/layout": "^2.0.1",
35+
"@gatsby-contrib/gatsby-plugin-elasticlunr-search": "^2.3.0",
3536
"@material-ui/core": "^4.9.12",
3637
"@material-ui/icons": "^4.9.1",
3738
"@mdx-js/mdx": "^1.6.1",
3839
"@mdx-js/react": "^1.6.1",
39-
"@gatsby-contrib/gatsby-plugin-elasticlunr-search": "^2.3.0",
4040
"gatsby-plugin-layout": "^1.3.0",
4141
"gatsby-plugin-material-ui": "^2.1.8",
4242
"gatsby-plugin-mdx": "^1.2.4",

theme/src/components/Header.tsx

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1-
import { Box, Button, Flex, Heading, Icons, Logo } from '@committed/components'
1+
import {
2+
Box,
3+
Button,
4+
Flex,
5+
Heading,
6+
Icons,
7+
Logo,
8+
ThemeChoice,
9+
ThemeSwitch,
10+
useTheme,
11+
makeStyles,
12+
} from '@committed/components'
213
import { graphql, useStaticQuery } from 'gatsby'
314
import React from 'react'
415
import { ClearLink } from './Link'
516

6-
export const Header = () => {
17+
export const useStyles = makeStyles((theme) => ({
18+
color: {
19+
'& .commit_logo': {
20+
stroke: theme.palette.primary.contrastText,
21+
fill: theme.palette.primary.contrastText,
22+
},
23+
},
24+
}))
25+
26+
const ThemedLogo = () => {
27+
const classes = useStyles()
28+
return <Logo size={24} className={classes.color} />
29+
}
30+
31+
export const Header = ({
32+
themeChoice,
33+
toggleThemeChoice,
34+
}: {
35+
themeChoice: ThemeChoice
36+
toggleThemeChoice: () => void
37+
}) => {
738
const {
839
site: {
940
siteMetadata: {
@@ -34,20 +65,27 @@ export const Header = () => {
3465
}
3566
`
3667
)
68+
const theme = useTheme()
3769
const finalLogoLink = logo.link !== '' ? logo.link : '/'
3870
return (
3971
<>
40-
<Flex color="white" flexGrow={1}>
72+
<Flex flexGrow={1}>
4173
<ClearLink href={finalLogoLink}>
42-
<Flex color="white">
74+
<Flex color={theme.palette.type == 'light' ? 'white' : 'black'}>
4375
<Box mx={2}>
4476
{logo.image !== '' ? (
4577
<img src={logo.image} alt="logo" />
4678
) : (
47-
<Logo size={24} />
79+
<ThemedLogo />
4880
)}
4981
</Box>
50-
<Heading.h1 style={{ fontSize: '1.5rem' }}>{title}</Heading.h1>
82+
<Heading.h1
83+
style={{
84+
fontSize: '1.5rem',
85+
}}
86+
>
87+
{title}
88+
</Heading.h1>
5189
</Flex>
5290
</ClearLink>
5391
</Flex>
@@ -67,6 +105,11 @@ export const Header = () => {
67105
</Button>
68106
</ClearLink>
69107
) : null}
108+
<ThemeSwitch
109+
themeChoice={themeChoice}
110+
toggleThemeChoice={toggleThemeChoice}
111+
variant="celestial"
112+
/>
70113
{helpUrl !== '' ? (
71114
<a href={helpUrl}>
72115
<Icons.Help />

theme/src/components/Layout.tsx

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Box, CodeStyle, Container, ThemeProvider } from '@committed/components'
1+
import {
2+
Box,
3+
CodeStyle,
4+
Container,
5+
ThemeProvider,
6+
useThemeChoice,
7+
fonts,
8+
} from '@committed/components'
29
import { Content, Header as LayoutHeader, Nav, Root } from '@committed/layout'
310
import { navigate } from 'gatsby'
411
import React, { Dispatch, ReactNode, useState } from 'react'
@@ -36,16 +43,22 @@ export const Layout = ({
3643
...props
3744
}: LayoutProps) => {
3845
const [collapsed, setCollapsed] = useState((location && location.state) || {})
39-
useHotkeys('shift+home', () => navigate('/'))
40-
useHotkeys('shift+p', () => navigate('/print'))
46+
const [themeChoice, toggleThemeChoice, componentMounted] = useThemeChoice()
47+
48+
useHotkeys('shift+home', () => {
49+
navigate('/')
50+
})
51+
useHotkeys('shift+p', () => {
52+
navigate('/print')
53+
})
4154

4255
const navigateTo = (url) => {
4356
navigate(url, {
4457
state: collapsed,
4558
})
4659
}
4760

48-
return (
61+
const component = componentMounted ? (
4962
<DocsContext.Provider
5063
value={{
5164
pathname: location.pathname,
@@ -55,7 +68,9 @@ export const Layout = ({
5568
}}
5669
>
5770
<ThemeProvider
58-
fonts={{
71+
choice={themeChoice}
72+
createFonts={() => ({
73+
...fonts.defaultFonts,
5974
display: {
6075
fontFamily:
6176
'Dosis, "Helvetica Neue", "Segoe UI", Helvetica, Arial, sans-serif',
@@ -65,27 +80,35 @@ export const Layout = ({
6580
fontFamily:
6681
'Lato, -apple-system, BlinkMacSystemFont, "San Francisco", Roboto, "Segoe UI", "Helvetica Neue"',
6782
},
68-
}}
83+
})}
6984
>
7085
{pageContext.current && pageContext.current.title && (
7186
<SEO title={pageContext.current.title} {...props} />
7287
)}
7388
<Root
74-
style={{ minHeight: '100vh' }}
7589
config={{
7690
collapsible: false,
91+
navVariant: {
92+
xs: 'temporary',
93+
sm: 'permanent',
94+
},
95+
headerResponse: {
96+
xs: 'static',
97+
sm: 'squeezed',
98+
},
99+
contentResponse: {
100+
xs: 'static',
101+
sm: 'squeezed',
102+
},
77103
}}
78104
>
79105
<LayoutHeader>
80-
<Header />
106+
<Header
107+
themeChoice={themeChoice}
108+
toggleThemeChoice={toggleThemeChoice}
109+
/>
81110
</LayoutHeader>
82-
<Nav
83-
header={
84-
// you can provide fixed header inside nav
85-
// change null to some react element
86-
(ctx) => null
87-
}
88-
>
111+
<Nav>
89112
<Sidebar location={location} current={id} />
90113
</Nav>
91114
<Content>
@@ -105,5 +128,6 @@ export const Layout = ({
105128
</Root>
106129
</ThemeProvider>
107130
</DocsContext.Provider>
108-
)
131+
) : null
132+
return component
109133
}

theme/src/components/Link.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ const isExternal = (url: string) => url && url.startsWith('http')
99
const isInPage = (url: string) => url && url.startsWith('#')
1010
const isRelative = (url: string) => url && !url.startsWith('/')
1111

12-
const LocalLink: React.FC<LinkProps> = ({
13-
href,
14-
variant,
15-
...props
16-
}: LinkProps) => (
12+
const LocalLink = ({ href, variant, ...props }: LinkProps<'a'>) => (
1713
<DocsContext.Consumer>
1814
{({ pathname, navigate }) => {
1915
let base = pathname.replace(pathStartRegEx, `/`)
@@ -37,7 +33,7 @@ const LocalLink: React.FC<LinkProps> = ({
3733
</DocsContext.Consumer>
3834
)
3935

40-
export const Link: React.FC<LinkProps> = ({ href, ...props }: LinkProps) => {
36+
export const Link = ({ href, ...props }: LinkProps<'a'>) => {
4137
if (isExternal(href)) {
4238
return <RawLink variant="styled" href={href} target="_blank" {...props} />
4339
}
@@ -51,10 +47,7 @@ export const Link: React.FC<LinkProps> = ({ href, ...props }: LinkProps) => {
5147
return <LocalLink {...props} variant="styled" href={href} />
5248
}
5349

54-
export const ClearLink: React.FC<LinkProps> = ({
55-
href,
56-
...props
57-
}: LinkProps) => {
50+
export const ClearLink = ({ href, ...props }: LinkProps<'a'>) => {
5851
if (isExternal(href)) {
5952
return <RawLink variant="clear" href={href} target="_blank" {...props} />
6053
} else {

theme/src/components/Markdown.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@ import React, { FC } from 'react'
22
import { MDXProvider } from '@mdx-js/react'
33
import MDXRenderer from 'gatsby-plugin-mdx/mdx-renderer'
44
import { Link } from './Link'
5-
import { mdx } from '@committed/components'
5+
import { styled, mdx, Table, Theme } from '@committed/components'
66

77
interface MardownProps {
88
children: any
99
}
1010

11+
const StripedTable = styled(Table)(({ theme }: { theme: Theme }) => ({
12+
'& tr:nth-child(even)': {
13+
backgroundColor:
14+
theme.palette.type === 'light'
15+
? theme.palette.grey[100]
16+
: theme.palette.grey[900],
17+
},
18+
}))
19+
1120
const components = Object.assign({}, mdx.components, {
1221
a: ({ children, href, ...props }) => (
1322
<Link href={href} {...props}>
1423
{children}
1524
</Link>
1625
),
17-
...mdx.shortcodes
26+
table: (props) => <StripedTable {...props} />,
27+
...mdx.shortcodes,
1828
})
1929

2030
export const Markdown: FC = (props: MardownProps) => (

theme/src/components/Search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const Search: FC<SearchProps> = (props: SearchProps) => {
4747

4848
const r = index
4949
// Expand allows for partial matches (mer matches mermaid)
50-
.search(query, { expand: true })
50+
.search(query, JSON.parse('{ "expand": true }'))
5151
// Map over each ID and return the full document
5252
.map(({ ref }) => index.documentStore.getDoc(ref))
5353

theme/src/layout/print.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, CodeStyle, ThemeProvider } from '@committed/components'
1+
import { Box, CodeStyle, ThemeProvider, fonts } from '@committed/components'
22
import { graphql, navigate } from 'gatsby'
33
import React from 'react'
44
import { useHotkeys } from 'react-hotkeys-hook'
@@ -11,7 +11,9 @@ import '../style/mermaid.css'
1111
import '../style/print.css'
1212

1313
export default ({ pageContext, data }) => {
14-
useHotkeys('esc', () => navigate('/'))
14+
useHotkeys('esc', () => {
15+
navigate('/')
16+
})
1517

1618
const docs = data.allDocs.edges.reduce((accu, edge) => {
1719
accu[edge.node.id] = edge.node.body
@@ -20,7 +22,8 @@ export default ({ pageContext, data }) => {
2022
return (
2123
<ThemeProvider
2224
choice="light"
23-
fonts={{
25+
createFonts={() => ({
26+
...fonts.defaultFonts,
2427
display: {
2528
fontFamily:
2629
'Dosis, "Helvetica Neue", "Segoe UI", Helvetica, Arial, sans-serif',
@@ -30,7 +33,7 @@ export default ({ pageContext, data }) => {
3033
fontFamily:
3134
'Lato, -apple-system, BlinkMacSystemFont, "San Francisco", Roboto, "Segoe UI", "Helvetica Neue"',
3235
},
33-
}}
36+
})}
3437
>
3538
<Header />
3639
<Footer />

0 commit comments

Comments
 (0)