diff --git a/packages/dnb-design-system-portal/src/shared/inlineTags/CodeBlock.js b/packages/dnb-design-system-portal/src/shared/inlineTags/CodeBlock.js index 9970af03382..2ea377a51fd 100644 --- a/packages/dnb-design-system-portal/src/shared/inlineTags/CodeBlock.js +++ b/packages/dnb-design-system-portal/src/shared/inlineTags/CodeBlock.js @@ -3,10 +3,13 @@ * */ -import React from 'react' +import React, { PureComponent } from 'react' +import PropTypes from 'prop-types' import { css } from '@emotion/core' +import styled from '@emotion/styled' import Highlight, { defaultProps } from 'prism-react-renderer' import dnbTheme from './themes/dnb-prism-theme' +import { Button } from 'dnb-ui-lib/src' import { LiveProvider, LiveEditor, @@ -30,28 +33,7 @@ const CodeBlock = ({ } if (((props && props.scope) || isReactLive) && language === 'jsx') { - const { caption, hideCode, hideExample, ...restProps } = props - return ( - - {!hideExample && ( -
- -
- )} - {caption &&

{caption}

} - {!hideCode && } - {!hideCode && } -
- ) + return } else { return ( { + this.setState(() => ({ hideCode: !this.state.hideCode })) + } + togglePreview = () => { + this.setState(() => ({ hidePreview: !this.state.hidePreview })) + } + + render() { + const { code, caption, scope } = this.props + const { hideCode, hidePreview } = this.state + + return ( + + { + // console.log('error', e) + // }} + > + {!hidePreview && ( + <> +
+ {this.props.hideCode && ( +
+ + )} + + {!hideCode && ( + + )} + {hidePreview && ( +