Skip to content

Commit

Permalink
feat(gatsby-theme-docz): add some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 1, 2019
1 parent 28e6f89 commit 03d9fec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/gatsby-theme-docz/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './src/index.css'
15 changes: 8 additions & 7 deletions core/gatsby-theme-docz/src/components/Code/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @jsx jsx */
import { jsx, useColorMode } from 'theme-ui'
import { useConfig } from 'docz'
import { get } from 'lodash/fp'
import AceEditor from 'react-ace'

import 'brace/theme/dracula'
Expand All @@ -10,26 +12,22 @@ import 'brace/ext/searchbox'

import * as styles from './styles'

const languages = [
const LANGUAGES = [
'javascript',
'java',
'python',
'xml',
'ruby',
'sass',
'markdown',
'mysql',
'json',
'html',
'handlebars',
'golang',
'csharp',
'elixir',
'typescript',
'css',
]

languages.forEach(lang => {
LANGUAGES.forEach(lang => {
require(`brace/mode/${lang}`)
require(`brace/snippets/${lang}`)
})
Expand Down Expand Up @@ -61,7 +59,10 @@ export const Code = ({
onChange,
}) => {
const [colorMode] = useColorMode()
const config = useConfig()
const lang = getLanguage(language)
const theme = get('themeConfig.editorTheme', config)

return (
<AceEditor
className={className}
Expand All @@ -71,7 +72,7 @@ export const Code = ({
readOnly={readOnly}
onChange={onChange}
highlightActiveLine={false}
theme={themes[colorMode]}
theme={theme || themes[colorMode]}
name="code-editor"
fontSize={16}
style={{
Expand Down
8 changes: 7 additions & 1 deletion core/gatsby-theme-docz/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ const Theme = ({ children }) => {
)
}

export const enhance = theme(defaultTheme)
export const enhance = theme(defaultTheme, ({ mode = 'light', ...config }) => {
return {
...config,
initialColorMode: mode,
}
})

export default enhance(Theme)

0 comments on commit 03d9fec

Please sign in to comment.