Skip to content

Commit 44760e1

Browse files
committed
Docs improvements
- Updates to latest components - Simplifies layout code - Improves menu behaviour - Separates open/close of menu from navigation - Closes panel on navigation when in temporary mode - Removes redundant commands form theme package.json
1 parent 0add3f9 commit 44760e1

File tree

8 files changed

+51
-61
lines changed

8 files changed

+51
-61
lines changed

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "example",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"main": "index.js",
55
"author": "Committed <opensource@committed.io>",
66
"license": "MIT",

package.json

+1-1
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": "2.0.0",
4+
"version": "2.1.0",
55
"main": "index.js",
66
"license": "MIT",
77
"scripts": {

theme/package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@committed/gatsby-theme-docs",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"main": "index.js",
55
"author": "Committed <opensource@committed.io>",
66
"license": "MIT",
@@ -15,9 +15,6 @@
1515
"scripts": {
1616
"format": "prettier --write '**/{*.js,*.ts,*.tsx,*.json,*.md,*.mdx}'",
1717
"format-check": "prettier --check '**/{**/*.js,*.ts,*.tsx,*.json,*.md,*.mdx}'",
18-
"build": "gatsby build",
19-
"develop": "gatsby develop",
20-
"start": "npm run develop",
2118
"deploy": "cp ../README.md . ; npm publish --access public"
2219
},
2320
"prettier": {
@@ -30,7 +27,7 @@
3027
"react-dom": "^16.13.1"
3128
},
3229
"dependencies": {
33-
"@committed/components": "^3.0.2",
30+
"@committed/components": "^3.2.0",
3431
"@committed/layout": "^2.0.1",
3532
"@gatsby-contrib/gatsby-plugin-elasticlunr-search": "^2.3.0",
3633
"@material-ui/core": "^4.9.12",

theme/src/components/Header.tsx

+2-12
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ const ThemedLogo = () => {
2828
return <Logo size={24} className={classes.color} />
2929
}
3030

31-
export const Header = ({
32-
themeChoice,
33-
toggleThemeChoice,
34-
}: {
35-
themeChoice: ThemeChoice
36-
toggleThemeChoice: () => void
37-
}) => {
31+
export const Header = () => {
3832
const {
3933
site: {
4034
siteMetadata: {
@@ -105,11 +99,7 @@ export const Header = ({
10599
</Button>
106100
</ClearLink>
107101
) : null}
108-
<ThemeSwitch
109-
themeChoice={themeChoice}
110-
toggleThemeChoice={toggleThemeChoice}
111-
variant="celestial"
112-
/>
102+
<ThemeSwitch />
113103
{helpUrl !== '' ? (
114104
<a href={helpUrl}>
115105
<Icons.Help />

theme/src/components/Layout.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
CodeStyle,
44
Container,
55
ThemeProvider,
6-
useThemeChoice,
76
fonts,
87
} from '@committed/components'
98
import { Content, Header as LayoutHeader, Nav, Root } from '@committed/layout'
@@ -43,7 +42,6 @@ export const Layout = ({
4342
...props
4443
}: LayoutProps) => {
4544
const [collapsed, setCollapsed] = useState((location && location.state) || {})
46-
const [themeChoice, toggleThemeChoice, componentMounted] = useThemeChoice()
4745

4846
useHotkeys('shift+home', () => {
4947
navigate('/')
@@ -58,7 +56,7 @@ export const Layout = ({
5856
})
5957
}
6058

61-
const component = componentMounted ? (
59+
return (
6260
<DocsContext.Provider
6361
value={{
6462
pathname: location.pathname,
@@ -68,7 +66,6 @@ export const Layout = ({
6866
}}
6967
>
7068
<ThemeProvider
71-
choice={themeChoice}
7269
createFonts={() => ({
7370
...fonts.defaultFonts,
7471
display: {
@@ -103,10 +100,7 @@ export const Layout = ({
103100
}}
104101
>
105102
<LayoutHeader>
106-
<Header
107-
themeChoice={themeChoice}
108-
toggleThemeChoice={toggleThemeChoice}
109-
/>
103+
<Header />
110104
</LayoutHeader>
111105
<Nav>
112106
<Sidebar location={location} current={id} />
@@ -128,6 +122,5 @@ export const Layout = ({
128122
</Root>
129123
</ThemeProvider>
130124
</DocsContext.Provider>
131-
) : null
132-
return component
125+
)
133126
}

theme/src/components/Sidebar.tsx

+9-14
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ import React from 'react'
22
import { Tree } from './Tree'
33
import { ClearLink } from './Link'
44
import { useStaticQuery, graphql } from 'gatsby'
5-
import {
6-
Icons,
7-
Divider,
8-
List,
9-
ListItem,
10-
ListItemText
11-
} from '@committed/components'
5+
import { Icons, Divider, List } from '@committed/components'
6+
import { NavListItem } from '@committed/layout'
127

138
export interface SidebarProps {
149
location: any
@@ -19,8 +14,8 @@ export const Sidebar = ({ location, current }: SidebarProps) => {
1914
const {
2015
menu: { data: data },
2116
site: {
22-
siteMetadata: { sidebar: sidebar }
23-
}
17+
siteMetadata: { sidebar: sidebar },
18+
},
2419
} = useStaticQuery(
2520
graphql`
2621
query MenuQuery {
@@ -52,13 +47,13 @@ export const Sidebar = ({ location, current }: SidebarProps) => {
5247
<Divider />
5348
<List>
5449
{sidebar.links
55-
.filter(link => link.link !== '' && link.text !== '')
50+
.filter((link) => link.link !== '' && link.text !== '')
5651
.map((link, key) => (
5752
<ClearLink key={key} href={link.link}>
58-
<ListItem button>
59-
<ListItemText primary={link.text} />
60-
<Icons.ExitToApp color="disabled" />
61-
</ListItem>
53+
<NavListItem
54+
text={link.text}
55+
icon={<Icons.ExitToApp color="disabled" />}
56+
/>
6257
</ClearLink>
6358
))}
6459
</List>

theme/src/components/TreeNode.tsx

+29-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import {
44
List,
55
ListItem,
66
ListItemText,
7+
ListItemSecondaryAction,
8+
IconButton,
79
Theme,
8-
useTheme
10+
useTheme,
911
} from '@committed/components'
1012
import React from 'react'
1113
import { Info, Item } from '../types'
1214
import { firstUrl } from '../util/tree'
15+
import { useLayout } from '@committed/layout'
1316

1417
export interface TreeNodeProps extends Item {
1518
isActive: (id: string) => boolean
@@ -35,38 +38,50 @@ export const TreeNode = React.memo(
3538
...rest
3639
}: TreeNodeProps) => {
3740
const theme = useTheme<Theme>()
41+
const { navVariant, setOpen } = useLayout()
3842
const url = firstUrl({ id, label, items, info })
3943
const isCollapsed = collapsed[id] || false
4044
const hasChildren = items.length !== 0
4145
const title = info ? info.title : label
4246
const active = isActive(id)
47+
48+
const handleClick = () => {
49+
if (navVariant === 'temporary') {
50+
setOpen(false)
51+
}
52+
navigate(url)
53+
}
54+
4355
return (
4456
<>
4557
<ListItem
4658
style={{
47-
paddingLeft: theme.spacing(2) * (level + 1)
59+
paddingLeft: theme.spacing(2) * (level + 1),
4860
}}
4961
selected={active}
5062
button
51-
onClick={() => {
52-
setCollapsed(id)
53-
navigate(url)
54-
}}
63+
onClick={handleClick}
5564
>
5665
<ListItemText
5766
primary={title}
5867
primaryTypographyProps={{
59-
variant: level === 0 ? 'body1' : 'caption'
68+
variant: level === 0 ? 'body1' : 'caption',
6069
}}
6170
/>
6271
{title && hasChildren ? (
63-
<>
64-
{!isCollapsed ? (
65-
<Icons.KeyboardArrowDown />
66-
) : (
67-
<Icons.KeyboardArrowRight />
68-
)}
69-
</>
72+
<ListItemSecondaryAction>
73+
<IconButton
74+
onClick={() => setCollapsed(id)}
75+
edge="end"
76+
aria-label={isCollapsed ? 'expand' : 'collapse'}
77+
>
78+
{!isCollapsed ? (
79+
<Icons.KeyboardArrowDown />
80+
) : (
81+
<Icons.KeyboardArrowRight />
82+
)}
83+
</IconButton>
84+
</ListItemSecondaryAction>
7085
) : null}
7186
</ListItem>
7287

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -939,10 +939,10 @@
939939
resolved "https://registry.yarnpkg.com/@braintree/sanitize-url/-/sanitize-url-3.1.0.tgz#8ff71d51053cd5ee4981e5a501d80a536244f7fd"
940940
integrity sha512-GcIY79elgB+azP74j8vqkiXz8xLFfIzbQJdlwOPisgbKT00tviJQuEghOXSMVxJ00HoYJbGswr4kcllUc4xCcg==
941941

942-
"@committed/components@^3.0.2":
943-
version "3.0.2"
944-
resolved "https://registry.yarnpkg.com/@committed/components/-/components-3.0.2.tgz#3e7afa360b511443c9bae054bdd75cc8374b6e83"
945-
integrity sha512-zT4XN7RwYJb05b7qin87SVneJ6Cx9fR/ci6+oCca4YlAfwxq13wmEn0056OshutZeeA6pZthTJ8e8UUY4h0kIQ==
942+
"@committed/components@^3.2.0":
943+
version "3.2.0"
944+
resolved "https://registry.yarnpkg.com/@committed/components/-/components-3.2.0.tgz#3e2db6d49390148e2bc97bc218131f59cbc12663"
945+
integrity sha512-FmMGpkHsuDO3is/kQuVjuj6As7w2VhWcSJBYnWLUHsm4nxb+n95iYvbI5Zwa3cWoV70tck7jor585/mpgjUzaA==
946946
dependencies:
947947
clsx "^1.1.0"
948948
deepmerge "^4.2.2"

0 commit comments

Comments
 (0)