Skip to content

Commit

Permalink
Update component doc code snippets to handle dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 23, 2020
1 parent c5895d7 commit fcf7d1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/InlineCodeSnippet.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';
import Highlight, { defaultProps } from 'prism-react-renderer';
import github from 'prism-react-renderer/themes/github';
import lightTheme from 'prism-react-renderer/themes/github';
import darkTheme from 'prism-react-renderer/themes/nightOwl';
import styles from './InlineCodeSnippet.module.scss';
import cx from 'classnames';
import useDarkMode from 'use-dark-mode';

const InlineCodeSnippet = ({ children, language }) => {
const darkMode = useDarkMode();

return (
<Highlight
{...defaultProps}
theme={github}
theme={darkMode.value ? darkTheme : lightTheme}
code={children}
language={language}
>
Expand Down
7 changes: 5 additions & 2 deletions src/components/ReferenceExample.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import formatCode from '../utils/formatCode';
import github from 'prism-react-renderer/themes/github';
import lightTheme from 'prism-react-renderer/themes/github';
import darkTheme from 'prism-react-renderer/themes/nightOwl';
import { LiveEditor, LiveError, LiveProvider } from 'react-live';
import styles from './ReferenceExample.module.scss';
import ReferencePreview from './ReferencePreview';
import useDarkMode from 'use-dark-mode';

const platformStateContextMock = {
timeRange: {
Expand Down Expand Up @@ -32,6 +34,7 @@ const ReferenceExample = ({
} = window.__NR1_SDK__.default;
const { live } = example.options;
let formattedCode;
const darkMode = useDarkMode();

try {
formattedCode = formatCode(example.sourceCode).replace(TRAILING_SEMI, '');
Expand All @@ -56,7 +59,7 @@ const ReferenceExample = ({
[]
)}
code={formattedCode}
theme={github}
theme={darkMode.value ? darkTheme : lightTheme}
disabled={!live}
>
{live && (
Expand Down

0 comments on commit fcf7d1b

Please sign in to comment.