Skip to content

Commit

Permalink
chore: fallback if unable to format code
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 3, 2020
1 parent 2c2068c commit 481db7b
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/components/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@ import styles from './ComponentExample.module.scss';

const TRAILING_SEMI = /;\s*$/;

const ComponentExample = ({ className, example }) => (
<div className={cx(styles.container, className)}>
<h3 className={styles.title}>{example.label}</h3>
<LiveProvider
scope={window.__NR1_SDK__.default}
code={formatCode(example.sourceCode).replace(TRAILING_SEMI, '')}
theme={github}
>
<LivePreview className={styles.preview} />
<LiveEditor style={{ fontSize: '0.75rem' }} />
<LiveError className={styles.error} />
</LiveProvider>
</div>
);
const ComponentExample = ({ className, example }) => {
let formattedCode;

try {
formattedCode = formatCode(example.sourceCode).replace(TRAILING_SEMI, '');
} catch (e) {
formattedCode = example.sourceCode;
}

return (
<div className={cx(styles.container, className)}>
<h3 className={styles.title}>{example.label}</h3>
<LiveProvider
scope={{
...window.__NR1_SDK__.default,
navigation: {
// eslint-disable-next-line no-empty-function
getOpenLauncherLocation() {},
},
}}
code={formattedCode}
theme={github}
>
<LivePreview className={styles.preview} />
<LiveEditor style={{ fontSize: '0.75rem' }} />
<LiveError className={styles.error} />
</LiveProvider>
</div>
);
};

ComponentExample.propTypes = {
className: PropTypes.string,
Expand Down

0 comments on commit 481db7b

Please sign in to comment.