@primer/doctocat-nextjs 0.0.2-rc.ac6ab68 → 0.0.2-rc.de031ea

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
@@ -12,4 +12,6 @@
12
12
 
13
13
  - Added anchor links to headings to match current functionality on primer.style
14
14
 
15
+ - [`b49f218`](https://github.com/primer/doctocat-nextjs/commit/b49f218e9bbc2de720476e21888956bee6081967) Thanks [@rezrah](https://github.com/rezrah)! - Removed sidebar links and added skip to main content a11y link
16
+
15
17
  - [#2](https://github.com/primer/doctocat-nextjs/pull/2) [`2742b32`](https://github.com/primer/doctocat-nextjs/commit/2742b3214e7a53416d23f0459dc389f7c22cf5a1) Thanks [@rezrah](https://github.com/rezrah)! - Remove code blocks stylesheet, now merged into global.css
@@ -4,7 +4,7 @@ import {Heading, Stack, Text} from '@primer/react-brand'
4
4
  import clsx from 'clsx'
5
5
  import {MdxFile, PageMapItem} from 'nextra'
6
6
  import type {PageItem} from 'nextra/normalize-pages'
7
- import React, {useEffect, useMemo} from 'react'
7
+ import React, {useCallback, useEffect, useMemo} from 'react'
8
8
  import {debounce} from 'lodash'
9
9
 
10
10
  import Link from 'next/link'
@@ -37,6 +37,12 @@ export function Header({pageMap, docsDirectories, siteTitle}: HeaderProps) {
37
37
  const [searchTerm, setSearchTerm] = React.useState<string | undefined>('')
38
38
  const [activeDescendant] = React.useState<number>(-1)
39
39
 
40
+ useEffect(() => {
41
+ if (isSearchOpen && inputRef.current) {
42
+ inputRef.current.focus()
43
+ }
44
+ }, [isSearchOpen])
45
+
40
46
  useEffect(() => {
41
47
  const handleKeyDown = (event: KeyboardEvent) => {
42
48
  if (event.key === 'Escape') {
@@ -152,6 +158,10 @@ export function Header({pageMap, docsDirectories, siteTitle}: HeaderProps) {
152
158
  alert(`Name: ${inputRef.current.value}`)
153
159
  }
154
160
 
161
+ const handleSearchButtonOpenClick = useCallback(() => {
162
+ setIsSearchOpen(true)
163
+ }, [])
164
+
155
165
  return (
156
166
  <nav className={clsx(styles.Header, isSearchOpen && styles['Header--searchAreaOpen'])}>
157
167
  <Link href="/" className={styles.Header__siteTitle}>
@@ -292,7 +302,7 @@ export function Header({pageMap, docsDirectories, siteTitle}: HeaderProps) {
292
302
  variant="invisible"
293
303
  aria-label={`Open search`}
294
304
  sx={{display: ['flex', null, 'none']}}
295
- onClick={() => setIsSearchOpen(true)}
305
+ onClick={handleSearchButtonOpenClick}
296
306
  />
297
307
  <Box sx={{display: ['flex', null, 'none']}}>
298
308
  <IconButton
@@ -35,6 +35,7 @@ import bodyStyles from '../../../css/prose.module.css'
35
35
  import {IndexCards} from '../index-cards/IndexCards'
36
36
  import {useColorMode} from '../../context/color-modes/useColorMode'
37
37
  import {getComponents} from '../../mdx-components/mdx-components'
38
+ import {SkipToMainContent} from '../skip-to-main-content/SkipToMainContent'
38
39
 
39
40
  const {publicRuntimeConfig} = getConfig()
40
41
 
@@ -81,6 +82,7 @@ export function Theme({children, pageOpts}: NextraThemeLayoutProps) {
81
82
  zIndex: 99,
82
83
  }}
83
84
  >
85
+ <SkipToMainContent href="#main">Skip to main content</SkipToMainContent>
84
86
  <Header
85
87
  pageMap={pageMap}
86
88
  docsDirectories={docsDirectories}
@@ -90,7 +92,7 @@ export function Theme({children, pageOpts}: NextraThemeLayoutProps) {
90
92
  </PRCBox>
91
93
  <PageLayout rowGap="none" columnGap="none" padding="none" containerWidth="full">
92
94
  <PageLayout.Content padding="normal">
93
- <main>
95
+ <main id="main">
94
96
  <PRCBox sx={!isHomePage && {display: 'flex', maxWidth: 1600, margin: '0 auto'}}>
95
97
  <PRCBox sx={!isHomePage && {maxWidth: 800, width: '100%', margin: '0 auto'}}>
96
98
  <Stack direction="vertical" padding="none" gap="spacious">
@@ -6,17 +6,7 @@ import {useRouter} from 'next/router'
6
6
  import getConfig from 'next/config'
7
7
 
8
8
  import styles from './Sidebar.module.css'
9
- import {
10
- BookmarkIcon,
11
- BrowserIcon,
12
- Icon,
13
- ImageIcon,
14
- LinkExternalIcon,
15
- OrganizationIcon,
16
- RepoIcon,
17
- StackIcon,
18
- StarIcon,
19
- } from '@primer/octicons-react'
9
+ import {LinkExternalIcon} from '@primer/octicons-react'
20
10
  import type {ThemeConfig} from '../../../index'
21
11
 
22
12
  type SidebarProps = {
@@ -36,29 +26,6 @@ type DocsItem = (MdxFile | FolderWithoutChildren) & {
36
26
 
37
27
  const {publicRuntimeConfig} = getConfig()
38
28
 
39
- function getOcticonForType(type?: string): Icon | undefined {
40
- if (!type) return undefined
41
-
42
- switch (type) {
43
- case 'repo':
44
- return RepoIcon
45
- case 'org':
46
- return OrganizationIcon
47
- case 'bookmark':
48
- return BookmarkIcon
49
- case 'star':
50
- return StarIcon
51
- case 'browser':
52
- return BrowserIcon
53
- case 'stack':
54
- return StackIcon
55
- case 'img':
56
- return ImageIcon
57
- default:
58
- return StarIcon
59
- }
60
- }
61
-
62
29
  export function Sidebar({pageMap}: SidebarProps) {
63
30
  const router = useRouter()
64
31
 
@@ -167,9 +134,7 @@ export function Sidebar({pageMap}: SidebarProps) {
167
134
  {sidebarLinks && sidebarLinks.length > 0 && (
168
135
  <NavList.Group title="" sx={{mb: 24}}>
169
136
  {sidebarLinks.map(link => {
170
- const {leadingIcon} = link
171
137
  const isExternalUrl = link.href.startsWith('http')
172
- const LeadingIcon = getOcticonForType(leadingIcon)
173
138
 
174
139
  return (
175
140
  <NavList.Item
@@ -178,7 +143,6 @@ export function Sidebar({pageMap}: SidebarProps) {
178
143
  href={link.href}
179
144
  target={isExternalUrl ? '_blank' : undefined}
180
145
  >
181
- <NavList.LeadingVisual>{LeadingIcon && <LeadingIcon />}</NavList.LeadingVisual>
182
146
  {link.title}
183
147
  {isExternalUrl && (
184
148
  <NavList.TrailingVisual>
@@ -0,0 +1,17 @@
1
+ .SkipToMainContent {
2
+ position: absolute;
3
+ top: 0;
4
+ left: 0;
5
+ z-index: 999;
6
+ padding: var(--base-size-16);
7
+ background-color: var(--base-color-scale-blue-5);
8
+ color: var(--base-color-scale-white-0);
9
+ }
10
+ .SkipToMainContent:not(:focus) {
11
+ clip: rect(1px, 1px, 1px, 1px);
12
+ clip-path: inset(50%);
13
+ height: 1px;
14
+ width: 1px;
15
+ margin: -1px;
16
+ padding: 0px;
17
+ }
@@ -0,0 +1,14 @@
1
+ import React, {HTMLAttributes, PropsWithChildren} from 'react'
2
+ import styles from './SkipToMainContent.module.css'
3
+
4
+ type SkipToMainContentProps = {
5
+ href: string
6
+ } & HTMLAttributes<HTMLAnchorElement>
7
+
8
+ export function SkipToMainContent({children, href, ...rest}: PropsWithChildren<SkipToMainContentProps>) {
9
+ return (
10
+ <a href={href} className={styles.SkipToMainContent} {...rest}>
11
+ {children}
12
+ </a>
13
+ )
14
+ }
@@ -1,4 +1,4 @@
1
- import React, {useEffect} from 'react'
1
+ import React, {useEffect, useMemo} from 'react'
2
2
  import {NavList} from '@primer/react'
3
3
  import {Text} from '@primer/react-brand'
4
4
  import {Heading as HeadingType} from 'nextra'
@@ -10,6 +10,8 @@ type TableOfContentsProps = {
10
10
  }
11
11
 
12
12
  export function TableOfContents({headings}: TableOfContentsProps) {
13
+ const depth2Headings = useMemo(() => headings.filter(heading => heading.depth === 2), [headings])
14
+
13
15
  useEffect(() => {
14
16
  const observer = new IntersectionObserver(
15
17
  entries => {
@@ -40,7 +42,7 @@ export function TableOfContents({headings}: TableOfContentsProps) {
40
42
  },
41
43
  )
42
44
 
43
- for (const heading of headings) {
45
+ for (const heading of depth2Headings) {
44
46
  const el = document.getElementById(heading.id)
45
47
  if (el) {
46
48
  observer.observe(el)
@@ -50,7 +52,7 @@ export function TableOfContents({headings}: TableOfContentsProps) {
50
52
  return () => {
51
53
  observer.disconnect()
52
54
  }
53
- }, [headings])
55
+ }, [depth2Headings])
54
56
 
55
57
  return (
56
58
  <aside className={styles.wrapper}>
@@ -58,7 +60,7 @@ export function TableOfContents({headings}: TableOfContentsProps) {
58
60
  On this page
59
61
  </Text>
60
62
  <NavList>
61
- {headings.map(heading => (
63
+ {depth2Headings.map(heading => (
62
64
  <NavList.Item
63
65
  className={styles.item}
64
66
  key={heading.id}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/doctocat-nextjs",
3
- "version": "0.0.2-rc.ac6ab68",
3
+ "version": "0.0.2-rc.de031ea",
4
4
  "description": "A Next.js theme for building Primer documentation sites",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/types.ts CHANGED
@@ -3,6 +3,5 @@ export type ThemeConfig = {
3
3
  sidebarLinks?: {
4
4
  title: string
5
5
  href: string
6
- leadingIcon?: 'repo' | 'org' | 'bookmark' | 'star' | 'img' | 'browser' | 'stack'
7
6
  }[]
8
7
  }