Skip to content

Commit

Permalink
Added PrismJs line number option to JsonInlineLink (#72)
Browse files Browse the repository at this point in the history
* added option for line numbers in prismjs codeblocks

* moved PrismJS line number conditional out of inline markup

* added lineNumbers propType to Code.js and removed inline boolean value from JsonLinkInlineExamples.js to remove lint warnings

* moved line numbers examples from JsonLinkInline to Code component where it belongs

* update line number example in Code Examples

* added lineNumbers prop to JsonLinkInline.js

* added proptype validation
  • Loading branch information
kennylam authored and jzhang300 committed Jan 12, 2018
1 parent ba1b420 commit cfe3a3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example/src/components/JsonLinkInlineExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class JsonLinkInlineExamples extends React.Component {
this.state = {
json: initialJson,
showJson: false,
lineNumbers: true,
};
this.onExit = this.onExit.bind(this);
this.onShow = this.onShow.bind(this);
Expand Down Expand Up @@ -58,6 +59,7 @@ export default class JsonLinkInlineExamples extends React.Component {
onExit={this.onExit}
onShow={this.onShow}
description={<p>This is a description for the JsonLinkInline component.</p>}
lineNumbers={this.state.lineNumbers}
/>
<Code type="jsx" lineNumbers>
{`<JsonLinkInline
Expand All @@ -66,6 +68,7 @@ export default class JsonLinkInlineExamples extends React.Component {
onExit={ callback function for when exit button is clicked }
onShow={ callback function for when json link is clicked }
description={<p>This is a description for the JsonLinkInline component.</p>}
lineNumbers={ boolean to toggle line numbers }
/>`}
</Code>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/components/JsonLinkInline.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function JsonLinkInline(props) {
{ 'json-link-inline--overlay_show': props.showJson }
)}
>
<Code language="json">
<Code language="json" lineNumbers={props.lineNumbers}>
{JSON.stringify(normalizeJson(props.json), null, 1)}
</Code>
<button
Expand Down Expand Up @@ -71,6 +71,7 @@ JsonLinkInline.propTypes = {
onExit: PropTypes.func,
onShow: PropTypes.func, // eslint-disable-line
description: PropTypes.element,
lineNumbers: PropTypes.bool,
};

JsonLinkInline.defaultProps = {
Expand All @@ -79,4 +80,5 @@ JsonLinkInline.defaultProps = {
description: <div />,
onExit: () => {},
onShow: () => {},
lineNumbers: false,
};

0 comments on commit cfe3a3a

Please sign in to comment.