@primer/gatsby-theme-doctocat 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @primer/gatsby-theme-doctocat
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`1022d1c`](https://github.com/primer/doctocat/commit/1022d1c92588f1e4fed4bdacec30fd5d11256412) [#362](https://github.com/primer/doctocat/pull/362) Thanks [@siddharthkp](https://github.com/siddharthkp)! - Drop support for node 12
8
+
9
+ * [`5f4426c`](https://github.com/primer/doctocat/commit/5f4426cc0cec6201600241bc753e5c7c9bf188a6) [#427](https://github.com/primer/doctocat/pull/427) Thanks [@colebemis](https://github.com/colebemis)! - Items in [`nav.yml`](https://primer.style/doctocat/usage/customization#side-navigation) that contain `children` no longer render as links, meaning the `url` property will be ignored.
10
+
11
+ ```diff
12
+ # nav.yml
13
+ – title: Components
14
+ - url: /components
15
+ children:
16
+ — title: Avatar
17
+ url: /Avatar
18
+ ```
19
+
20
+ ### Patch Changes
21
+
22
+ - [`facde5a`](https://github.com/primer/doctocat/commit/facde5a56119b160f98b8b01302e3508392c2146) [#330](https://github.com/primer/doctocat/pull/330) Thanks [@siddharthkp](https://github.com/siddharthkp)! - Vertically-center align images in table
23
+
3
24
  ## 3.3.0
4
25
 
5
26
  ### Minor Changes
package/gatsby-node.js CHANGED
@@ -30,7 +30,7 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
30
30
  }
31
31
  `)
32
32
 
33
- if (!process.env.GITHUB_TOKEN && !process.env.NOW_GITHUB_DEPLOYMENT && !process.env.VERCEL_GITHUB_DEPLOYMENT) {
33
+ if (!process.env.GITHUB_TOKEN) {
34
34
  console.error(`Non-deploy build and no GITHUB_TOKEN environment variable set; skipping GitHub API calls`)
35
35
  }
36
36
 
@@ -48,7 +48,7 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
48
48
  const editUrl = getEditUrl(repo, fileRelativePath, defaultBranch)
49
49
 
50
50
  let contributors = []
51
- if (process.env.GITHUB_TOKEN || process.env.NOW_GITHUB_DEPLOYMENT || process.env.VERCEL_GITHUB_DEPLOYMENT) {
51
+ if (process.env.GITHUB_TOKEN) {
52
52
  contributors = await fetchContributors(repo, fileRelativePath, process.env.GITHUB_TOKEN)
53
53
  }
54
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/gatsby-theme-doctocat",
3
- "version": "3.3.0",
3
+ "version": "4.0.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -33,8 +33,8 @@
33
33
  "@mdx-js/mdx": "^1.0.21",
34
34
  "@mdx-js/react": "^1.0.21",
35
35
  "@primer/component-metadata": "^0.4.0",
36
- "@primer/react": "^34.5.0",
37
36
  "@primer/octicons-react": "^16.3.1",
37
+ "@primer/react": "^35.2.2",
38
38
  "@styled-system/theme-get": "^5.0.12",
39
39
  "@testing-library/jest-dom": "^5.16.2",
40
40
  "@testing-library/react": "^9.1.3",
package/setup-tests.js CHANGED
@@ -1 +1,10 @@
1
1
  import '@testing-library/jest-dom/extend-expect'
2
+
3
+ // JSDOM doesn't mock ResizeObserver
4
+ // Copied from https://github.com/primer/react/blob/3fdae477d8067c5131d316548ce5b08aa1017355/src/utils/test-helpers.tsx
5
+ global.ResizeObserver = jest.fn().mockImplementation(() => {
6
+ return {
7
+ observe: jest.fn(),
8
+ disconnect: jest.fn()
9
+ }
10
+ })
@@ -56,8 +56,10 @@ function Layout({children, pageContext}) {
56
56
  }}
57
57
  css={{gridArea: 'table-of-contents', overflow: 'auto'}}
58
58
  >
59
- <Text sx={{display: 'inline-block', fontWeight: 'bold', mb: 1}}>On this page</Text>
60
- <TableOfContents items={pageContext.tableOfContents.items} />
59
+ <Text sx={{display: 'inline-block', fontWeight: 'bold', pl: 3}} id="toc-heading">
60
+ On this page
61
+ </Text>
62
+ <TableOfContents aria-labelledby="toc-heading" items={pageContext.tableOfContents.items} />
61
63
  </Box>
62
64
  ) : null}
63
65
  <Box sx={{width: '100%', maxWidth: '960px'}}>
@@ -97,14 +99,14 @@ function Layout({children, pageContext}) {
97
99
  borderRadius: 2
98
100
  }}
99
101
  >
100
- <Box sx={{p: 3}}>
102
+ <Box sx={{px: 3, py: 2}}>
101
103
  <Box
102
104
  sx={{flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', display: 'flex'}}
103
105
  >
104
106
  <Text sx={{fontWeight: 'bold'}}>On this page</Text>
105
107
  </Box>
106
108
  </Box>
107
- <Box sx={{p: 3, borderTop: '1px solid', borderColor: 'border.muted'}}>
109
+ <Box sx={{borderTop: '1px solid', borderColor: 'border.muted'}}>
108
110
  <TableOfContents items={pageContext.tableOfContents.items} />
109
111
  </Box>
110
112
  </Box>
@@ -86,11 +86,13 @@ function NavDrawer({isOpen, onDismiss}) {
86
86
  <Link
87
87
  as={GatsbyLink}
88
88
  to="/"
89
- sx={{display: 'inline-block', color: 'inherit', fontFamily: 'mono', mx: 4, my: 4}}
89
+ sx={{display: 'inline-block', color: 'inherit', fontFamily: 'mono', mx: 4, mt: 4}}
90
90
  >
91
91
  {siteMetadata.title}
92
92
  </Link>
93
- <NavItems items={navItems} />
93
+ <Box sx={{px: 2}}>
94
+ <NavItems items={navItems} />
95
+ </Box>
94
96
  </Box>
95
97
  </ThemeProvider>
96
98
  ) : null}
@@ -1,6 +1,8 @@
1
- import {Box, Link, StyledOcticon, themeGet} from '@primer/react'
2
1
  import {LinkExternalIcon} from '@primer/octicons-react'
3
- import {Link as GatsbyLink} from 'gatsby'
2
+ import {Link, themeGet} from '@primer/react'
3
+ import {NavList} from '@primer/react/drafts'
4
+ import {useLocation} from '@reach/router'
5
+ import {Link as GatsbyLink, withPrefix} from 'gatsby'
4
6
  import preval from 'preval.macro'
5
7
  import React from 'react'
6
8
  import styled from 'styled-components'
@@ -17,81 +19,46 @@ const repositoryUrl = preval`
17
19
  }
18
20
  `
19
21
 
20
- const NavLink = styled(Link)`
21
- &.active {
22
- font-weight: ${themeGet('fontWeights.bold')};
23
- color: ${themeGet('colors.fg.default')};
24
- }
25
- `
22
+ function NavItem({href, children}) {
23
+ const location = useLocation()
24
+ const isCurrent = withPrefix(href) === location.pathname
25
+ return (
26
+ <NavList.Item as={GatsbyLink} to={href} aria-current={isCurrent ? 'page' : null}>
27
+ {children}
28
+ </NavList.Item>
29
+ )
30
+ }
26
31
 
27
32
  function NavItems({items}) {
28
33
  return (
29
- <>
34
+ <NavList>
30
35
  {items.map(item => (
31
- <Box
32
- key={item.title}
33
- sx={{
34
- borderWidth: 0,
35
- borderRadius: 0,
36
- borderTopWidth: 1,
37
- borderStyle: 'solid',
38
- borderColor: 'border.muted',
39
- p: 4
40
- }}
41
- >
42
- <Box sx={{display: 'flex', flexDirection: 'column'}}>
43
- <NavLink
44
- as={GatsbyLink}
45
- to={item.url}
46
- activeClassName="active"
47
- partiallyActive={true}
48
- sx={{color: 'inherit'}}
49
- >
50
- {item.title}
51
- </NavLink>
52
- {item.children ? (
53
- <Box sx={{display: 'flex', flexDirection: 'column', mt: 2}}>
54
- {item.children.map(child => (
55
- <NavLink
56
- key={child.title}
57
- as={GatsbyLink}
58
- to={child.url}
59
- activeClassName="active"
60
- sx={{
61
- display: 'block',
62
- py: 1,
63
- mt: 2,
64
- fontSize: 1
65
- }}
66
- >
67
- {child.title}
68
- </NavLink>
69
- ))}
70
- </Box>
71
- ) : null}
72
- </Box>
73
- </Box>
36
+ <React.Fragment key={item.title}>
37
+ {item.children ? (
38
+ <NavList.Group title={item.title}>
39
+ {item.children.map(child => (
40
+ <NavItem key={child.title} href={child.url}>
41
+ {child.title}
42
+ </NavItem>
43
+ ))}
44
+ </NavList.Group>
45
+ ) : (
46
+ <NavItem href={item.url}>{item.title}</NavItem>
47
+ )}
48
+ </React.Fragment>
74
49
  ))}
75
50
  {repositoryUrl ? (
76
- <Box
77
- sx={{
78
- borderWidth: 0,
79
- borderTopWidth: 1,
80
- borderRadius: 0,
81
- borderStyle: 'solid',
82
- borderColor: 'border.default',
83
- p: 4
84
- }}
85
- >
86
- <Link href={repositoryUrl} sx={{color: 'inherit'}}>
87
- <Box sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>
88
- GitHub
89
- <StyledOcticon icon={LinkExternalIcon} sx={{color: 'fg.muted'}} />
90
- </Box>
91
- </Link>
92
- </Box>
51
+ <>
52
+ <NavList.Divider />
53
+ <NavList.Item href={repositoryUrl}>
54
+ GitHub
55
+ <NavList.TrailingVisual>
56
+ <LinkExternalIcon />
57
+ </NavList.TrailingVisual>
58
+ </NavList.Item>
59
+ </>
93
60
  ) : null}
94
- </>
61
+ </NavList>
95
62
  )
96
63
  }
97
64
 
@@ -37,8 +37,7 @@ function Sidebar() {
37
37
  position: 'sticky',
38
38
  top: HEADER_HEIGHT,
39
39
  height: `calc(100vh - ${HEADER_HEIGHT}px)`,
40
- minWidth: 260,
41
- bg: 'canvas.subtle'
40
+ minWidth: 260
42
41
  }}
43
42
  >
44
43
  <Box
@@ -50,7 +49,8 @@ function Sidebar() {
50
49
  borderRadius: 0,
51
50
  height: '100%',
52
51
  borderStyle: 'solid',
53
- borderColor: 'border.default'
52
+ borderColor: 'border.subtle',
53
+ px: 2
54
54
  }}
55
55
  >
56
56
  <Box sx={{flexDirection: 'column', display: 'flex'}}>
@@ -1,28 +1,16 @@
1
1
  import {Box, Link} from '@primer/react'
2
2
  import React from 'react'
3
+ import {NavList} from '@primer/react/drafts'
3
4
 
4
- function TableOfContents({items, depth}) {
5
+ function TableOfContents({'aria-labelledby': ariaLabelledBy, items, depth}) {
5
6
  return (
6
- <Box as="ul" sx={{m: 0, p: 0, listStyle: 'none'}}>
7
+ <NavList aria-labelledby={ariaLabelledBy}>
7
8
  {items.map(item => (
8
- <Box as="li" key={item.url} sx={{pl: depth > 0 ? 3 : 0}}>
9
- {item.title ? (
10
- <Link
11
- href={item.url}
12
- sx={{
13
- display: 'inline-block',
14
- py: 1,
15
- fontSize: [2, null, 1],
16
- color: 'fg.muted'
17
- }}
18
- >
19
- {item.title}
20
- </Link>
21
- ) : null}
22
- {item.items ? <TableOfContents items={item.items} depth={depth + 1} /> : null}
23
- </Box>
9
+ <NavList.Item key={item.title} href={item.url}>
10
+ {item.title}
11
+ </NavList.Item>
24
12
  ))}
25
- </Box>
13
+ </NavList>
26
14
  )
27
15
  }
28
16
 
@@ -28,6 +28,7 @@ const Table = styled.table`
28
28
 
29
29
  img {
30
30
  background-color: transparent;
31
+ vertical-align: middle;
31
32
  }
32
33
  `
33
34