-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-theme-docz): add new Pre component
- Loading branch information
1 parent
8eb780d
commit a6be6a1
Showing
8 changed files
with
203 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @jsx jsx */ | ||
import { useConfig } from 'docz' | ||
import { jsx, Styled } from 'theme-ui' | ||
import Highlight, { defaultProps } from 'prism-react-renderer' | ||
import { get } from 'lodash/fp' | ||
|
||
export const Code = ({ codeString, language = 'jsx' }) => { | ||
const config = useConfig() | ||
const theme = get('themeConfig.prismjs', config) | ||
|
||
return ( | ||
<Highlight | ||
{...defaultProps} | ||
theme={theme} | ||
code={codeString} | ||
language={language} | ||
> | ||
{({ className, style, tokens, getLineProps, getTokenProps }) => ( | ||
<Styled.pre className={className} style={style}> | ||
{tokens.map((line, i) => { | ||
if (line.length === 1 && line[0].empty) return null | ||
return ( | ||
<div key={line} {...getLineProps({ line, key: i })}> | ||
{line.map((token, key) => ( | ||
<span key={key} {...getTokenProps({ token, key })} /> | ||
))} | ||
</div> | ||
) | ||
})} | ||
</Styled.pre> | ||
)} | ||
</Highlight> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const line = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'theme-ui' | ||
import { preToCodeBlock } from 'mdx-utils' | ||
|
||
import { Code } from '../Code' | ||
|
||
export const Pre = preProps => { | ||
const props = preToCodeBlock(preProps) | ||
if (props) { | ||
return <Code {...props} /> | ||
} else { | ||
return <pre {...preProps} /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import * as headings from './Headings' | ||
|
||
import { Pre } from './Pre' | ||
import { Layout } from './Layout' | ||
import { Props } from './Props' | ||
|
||
export const componentsMap = { | ||
...headings, | ||
pre: Pre, | ||
layout: Layout, | ||
props: Props, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
export default { | ||
plain: { | ||
color: '#393A34', | ||
backgroundColor: '#f6f8fa', | ||
}, | ||
styles: [ | ||
{ | ||
types: ['comment', 'prolog', 'doctype', 'cdata'], | ||
style: { | ||
color: '#999988', | ||
fontStyle: 'italic', | ||
}, | ||
}, | ||
{ | ||
types: ['namespace'], | ||
style: { | ||
opacity: 0.7, | ||
}, | ||
}, | ||
{ | ||
types: ['string', 'attr-value'], | ||
style: { | ||
color: '#e3116c', | ||
}, | ||
}, | ||
{ | ||
types: ['punctuation', 'operator'], | ||
style: { | ||
color: '#393A34', | ||
}, | ||
}, | ||
{ | ||
types: [ | ||
'entity', | ||
'url', | ||
'symbol', | ||
'number', | ||
'boolean', | ||
'variable', | ||
'constant', | ||
'property', | ||
'regex', | ||
'inserted', | ||
], | ||
style: { | ||
color: '#36acaa', | ||
}, | ||
}, | ||
{ | ||
types: ['atrule', 'keyword', 'attr-name', 'selector'], | ||
style: { | ||
color: '#00a4db', | ||
}, | ||
}, | ||
{ | ||
types: ['function', 'deleted', 'tag'], | ||
style: { | ||
color: '#d73a49', | ||
}, | ||
}, | ||
{ | ||
types: ['function-variable'], | ||
style: { | ||
color: '#6f42c1', | ||
}, | ||
}, | ||
{ | ||
types: ['tag', 'selector', 'keyword'], | ||
style: { | ||
color: '#00009f', | ||
}, | ||
}, | ||
], | ||
} |
Oops, something went wrong.