@primer/gatsby-theme-doctocat 4.0.0 → 4.0.1

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,14 @@
1
1
  # @primer/gatsby-theme-doctocat
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1e22900`](https://github.com/primer/doctocat/commit/1e229008d374b8b56d19ce33f315256c4301efb4) [#434](https://github.com/primer/doctocat/pull/434) Thanks [@rezrah](https://github.com/rezrah)! - - Updated external links in frontmatter to open in new tab
8
+ - Added support for Figma links in frontmatter
9
+
10
+ * [`9585e40`](https://github.com/primer/doctocat/commit/9585e40d62b0bfcb8aff6d98cdd490b5058f6748) [#475](https://github.com/primer/doctocat/pull/475) Thanks [@JoshBowdenConcepts](https://github.com/JoshBowdenConcepts)! - Adding Primer Brand link to the main navigation
11
+
3
12
  ## 4.0.0
4
13
 
5
14
  ### Major Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/gatsby-theme-doctocat",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -6,12 +6,14 @@ import Prism from '../prism'
6
6
  import ClipboardCopy from './clipboard-copy'
7
7
  import LiveCode from './live-code'
8
8
 
9
- function Code({className, children, live, noinline, metastring}) {
9
+ function Code({className, children, live, highlight, noinline, metastring}) {
10
10
  const language = className ? className.replace(/language-/, '') : ''
11
11
  const code = children.trim()
12
12
 
13
13
  if (live) {
14
- return <LiveCode code={code} language={language} noinline={noinline} metastring={metastring} />
14
+ return (
15
+ <LiveCode code={code} highlight={highlight} language={language} noinline={noinline} metastring={metastring} />
16
+ )
15
17
  }
16
18
 
17
19
  return (
@@ -1,4 +1,4 @@
1
- import {Box, StyledOcticon, Text} from '@primer/react'
1
+ import {Box, Text} from '@primer/react'
2
2
  import React from 'react'
3
3
 
4
4
  export function DoDontContainer({stacked, children}) {
@@ -0,0 +1,32 @@
1
+ import {Link, Text} from '@primer/react'
2
+ import React from 'react'
3
+
4
+ function SourceLink({href}) {
5
+ return (
6
+ <Link href={href} target="_blank">
7
+ <FigmaLogo />
8
+ <Text sx={{ml: 2, display: 'inline-block'}}>View Figma</Text>
9
+ </Link>
10
+ )
11
+ }
12
+
13
+ function FigmaLogo() {
14
+ return (
15
+ <svg
16
+ width={16}
17
+ height={16}
18
+ aria-hidden="true"
19
+ style={{verticalAlign: 'text-bottom'}}
20
+ fill="none"
21
+ xmlns="http://www.w3.org/2000/svg"
22
+ viewBox="0 0 172 247"
23
+ >
24
+ <g stroke="currentColor" strokeWidth="15.081">
25
+ <path d="M164 46.5c0 21.263-17.237 38.5-38.5 38.5H86V8h39.5C146.763 8 164 25.237 164 46.5ZM8 46.5C8 67.763 25.237 85 46.5 85H86V8H46.5C25.237 8 8 25.237 8 46.5ZM8 123.501c0 21.263 17.237 38.5 38.5 38.5H86v-77H46.5c-21.263 0-38.5 17.237-38.5 38.5Z" />
26
+ <path d="M8 200.5C8 221.763 25.485 239 46.748 239 68.288 239 86 221.539 86 200v-38H46.5C25.237 162 8 179.237 8 200.5ZM86 123.501c0 21.263 17.237 38.5 38.5 38.5h1c21.263 0 38.5-17.237 38.5-38.5s-17.237-38.5-38.5-38.5h-1c-21.263 0-38.5 17.237-38.5 38.5Z" />
27
+ </g>
28
+ </svg>
29
+ )
30
+ }
31
+
32
+ export default SourceLink
@@ -8,10 +8,12 @@ import Sidebar from './sidebar'
8
8
  import SourceLink from './source-link'
9
9
  import StatusLabel from './status-label'
10
10
  import StorybookLink from './storybook-link'
11
+ import FigmaLink from './figma-link'
11
12
  import TableOfContents from './table-of-contents'
12
13
 
13
14
  function Layout({children, pageContext}) {
14
- let {title, description, status, source, storybook, additionalContributors, componentId} = pageContext.frontmatter
15
+ let {title, description, figma, status, source, storybook, additionalContributors, componentId} =
16
+ pageContext.frontmatter
15
17
 
16
18
  if (!additionalContributors) {
17
19
  additionalContributors = []
@@ -84,6 +86,7 @@ function Layout({children, pageContext}) {
84
86
  >
85
87
  {source ? <SourceLink href={source} /> : null}
86
88
  {storybook ? <StorybookLink href={storybook} /> : null}
89
+ {figma ? <FigmaLink href={figma} /> : null}
87
90
  </Box>
88
91
  ) : null}
89
92
  </Box>
@@ -8,6 +8,8 @@ import {ThemeContext} from 'styled-components'
8
8
  import scope from '../live-code-scope'
9
9
  import ClipboardCopy from './clipboard-copy'
10
10
  import LivePreviewWrapper from './live-preview-wrapper'
11
+ import styled from 'styled-components'
12
+ import themeGet from '@styled-system/theme-get'
11
13
 
12
14
  const languageTransformers = {
13
15
  html: html => htmlToJsx(html),
@@ -39,10 +41,43 @@ const getResolvedScope = metastring => {
39
41
  return scope
40
42
  }
41
43
 
42
- function LiveCode({code, language, noinline, metastring}) {
44
+ function parseHighlightRange(highlight) {
45
+ // Captures numbers separated by a dash: 2-3, 34-5, 2-101
46
+ const numbersWithDash = new RegExp('([0-9]+)-([0-9]+)')
47
+
48
+ const match = numbersWithDash.exec(highlight)
49
+ if (!match) return null
50
+
51
+ return {firstLine: match[1], lastLine: match[2]}
52
+ }
53
+
54
+ const LineWrapper = styled.div`
55
+ // Using negative and positive nth-child values to select the children.
56
+ pre .token-line:nth-child(n + ${props => props.range.firstLine}):nth-child(-n + ${props => props.range.lastLine}) {
57
+ // 16px is the padding of the react-live <pre> element that wraps the .token-line elements.
58
+ // The margin/padding combo extends the token-line elements so the background color reaches the border.
59
+ margin: 0px -16px;
60
+ padding: 0px 16px;
61
+ background-color: ${themeGet('colors.accent.subtle')};
62
+ // We use box-shadow instead of a border to avoid flickering when toggling the highlighting on/off.
63
+ box-shadow: inset 3px 0px 0px 0px ${themeGet('colors.accent.fg')};
64
+ }
65
+ `
66
+
67
+ function LineHighlighter({enabled, range, children}) {
68
+ if (!enabled || !range) return children
69
+
70
+ return <LineWrapper range={range}>{children}</LineWrapper>
71
+ }
72
+
73
+ function LiveCode({code, language, highlight, noinline, metastring}) {
43
74
  const theme = React.useContext(ThemeContext)
44
75
  const [liveCode, setLiveCode] = useState(code)
45
- const handleChange = updatedLiveCode => setLiveCode(updatedLiveCode)
76
+ const [pristine, setPristine] = useState(true)
77
+ const handleChange = updatedLiveCode => {
78
+ setLiveCode(updatedLiveCode)
79
+ setPristine(false)
80
+ }
46
81
 
47
82
  return (
48
83
  <Box sx={{flexDirection: 'column', mb: 3, display: 'flex'}}>
@@ -66,21 +101,23 @@ function LiveCode({code, language, noinline, metastring}) {
66
101
  </LivePreviewWrapper>
67
102
  </Box>
68
103
  <Box sx={{position: 'relative'}}>
69
- <LiveEditor
70
- onChange={handleChange}
71
- theme={githubTheme}
72
- ignoreTabKey={true}
73
- padding={theme.space[3]}
74
- style={{
75
- fontFamily: theme.fonts.mono,
76
- fontSize: '85%',
77
- borderBottomLeftRadius: theme.radii[2],
78
- borderBottomRightRadius: theme.radii[2],
79
- border: '1px solid',
80
- borderTop: 0,
81
- borderColor: theme.colors.border.default
82
- }}
83
- />
104
+ <LineHighlighter range={parseHighlightRange(highlight)} enabled={pristine}>
105
+ <LiveEditor
106
+ onChange={handleChange}
107
+ theme={githubTheme}
108
+ ignoreTabKey={true}
109
+ padding={theme.space[3]}
110
+ style={{
111
+ fontFamily: theme.fonts.mono,
112
+ fontSize: '85%',
113
+ borderBottomLeftRadius: theme.radii[2],
114
+ borderBottomRightRadius: theme.radii[2],
115
+ border: '1px solid',
116
+ borderTop: 0,
117
+ borderColor: theme.colors.border.default
118
+ }}
119
+ />
120
+ </LineHighlighter>
84
121
  <Box sx={{top: 0, right: 0, p: 2, position: 'absolute'}}>
85
122
  <ClipboardCopy value={liveCode} />
86
123
  </Box>
@@ -21,7 +21,7 @@ export function useNavDrawerState(breakpoint) {
21
21
  if (window.innerWidth >= breakpoint) {
22
22
  setOpen(false)
23
23
  }
24
- }, [setOpen])
24
+ }, [setOpen, breakpoint])
25
25
 
26
26
  const debouncedOnResize = React.useCallback(debounce(onResize, 250), [onResize])
27
27
 
@@ -1,11 +1,9 @@
1
1
  import {LinkExternalIcon} from '@primer/octicons-react'
2
- import {Link, themeGet} from '@primer/react'
3
2
  import {NavList} from '@primer/react/drafts'
4
3
  import {useLocation} from '@reach/router'
5
4
  import {Link as GatsbyLink, withPrefix} from 'gatsby'
6
5
  import preval from 'preval.macro'
7
6
  import React from 'react'
8
- import styled from 'styled-components'
9
7
 
10
8
  // This code needs to run at build-time so it can access the file system.
11
9
  const repositoryUrl = preval`
@@ -19,7 +19,7 @@ function usePersistentScroll(id) {
19
19
  if (scrollPosition && ref.current) {
20
20
  ref.current.scrollTop = scrollPosition
21
21
  }
22
- }, [])
22
+ }, [id])
23
23
 
24
24
  // Return props to spread onto the scroll container
25
25
  return {
@@ -4,7 +4,7 @@ import React from 'react'
4
4
 
5
5
  function SourceLink({href}) {
6
6
  return (
7
- <Link href={href}>
7
+ <Link href={href} target="_blank">
8
8
  <MarkGithubIcon />
9
9
  <Text sx={{ml: 2, display: 'inline-block'}}>View source</Text>
10
10
  </Link>
@@ -3,9 +3,9 @@ import React from 'react'
3
3
 
4
4
  function SourceLink({href}) {
5
5
  return (
6
- <Link href={href}>
6
+ <Link href={href} target="_blank">
7
7
  <StorybookIcon />
8
- <Text sx={{ml: 2, display: 'inline-block'}}>View storybook</Text>
8
+ <Text sx={{ml: 2, display: 'inline-block'}}>View Storybook</Text>
9
9
  </Link>
10
10
  )
11
11
  }
@@ -1,8 +1,7 @@
1
- import {Box, Link} from '@primer/react'
2
1
  import React from 'react'
3
2
  import {NavList} from '@primer/react/drafts'
4
3
 
5
- function TableOfContents({'aria-labelledby': ariaLabelledBy, items, depth}) {
4
+ function TableOfContents({'aria-labelledby': ariaLabelledBy, items}) {
6
5
  return (
7
6
  <NavList aria-labelledby={ariaLabelledBy}>
8
7
  {items.map(item => (
@@ -14,8 +13,4 @@ function TableOfContents({'aria-labelledby': ariaLabelledBy, items, depth}) {
14
13
  )
15
14
  }
16
15
 
17
- TableOfContents.defaultProps = {
18
- depth: 0
19
- }
20
-
21
16
  export default TableOfContents
@@ -20,6 +20,8 @@
20
20
  url: https://primer.style/css
21
21
  - title: React
22
22
  url: https://primer.style/react
23
+ - title: React Brand
24
+ url: https://primer.style/brand
23
25
  - title: ViewComponents
24
26
  url: https://primer.style/view-components
25
27
  - title: Contribute