Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add configurable nodeVersion prop #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ x.map(i => i*2);

![2](https://user-images.githubusercontent.com/1797812/48085110-042f1e00-e1bf-11e8-9a49-9fd7535fe290.gif)

### Configurable nodeVersion

You can configure the `nodeVersion` to use by passing it as a prop to the `Code` component.

````mdx
import Code from 'mdx-code';

# Regular Slide

---

<Code nodeVersion="13">

```js A playground slide!
console.log('Hello world');
```

</Code>

````

# Authors

* Pranay Prakash ([@pranaygp](https://twitter.com/pranaygp))
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import scriptLoader from "react-async-script-loader";
const Code = scriptLoader("https://embed.runkit.com")(
({ isScriptLoaded, ...rest }) =>
isScriptLoaded ? (
<Embed style={{ width: "100vw" }} nodeVersion="10" {...rest} />
<Embed style={{ width: "100vw" }} {...rest} />
) : (
<h3>Loading</h3>
)
);

export default ({ children }) => {
export default ({ nodeVersion = 10, children }) => {
const [pre, code] = React.Children.toArray(children);
let title;
let component;
Expand All @@ -20,11 +20,11 @@ export default ({ children }) => {
c => c.props.children.props.children
);
title = code.props.children.props.metastring;
component = <Code source={source} preamble={preamble} title={title} />;
component = <Code source={source} preamble={preamble} title={title} nodeVersion={nodeVersion} />;
} else {
const source = pre.props.children.props.children;
title = pre.props.children.props.metastring;
component = <Code source={source} title={title} />;
component = <Code source={source} title={title} nodeVersion={nodeVersion} />;
}
return (
<div
Expand Down