From 56313ca95e30f7d97db68816112905b495c580c5 Mon Sep 17 00:00:00 2001 From: Marvin9 Date: Sat, 14 Mar 2020 10:23:50 +0530 Subject: [PATCH] Add live tab -> implement renderLive() -> render renderLive() --- .../components/guide_section/guide_section.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src-docs/src/components/guide_section/guide_section.js b/src-docs/src/components/guide_section/guide_section.js index 9c568d0053a..e8c614a213a 100644 --- a/src-docs/src/components/guide_section/guide_section.js +++ b/src-docs/src/components/guide_section/guide_section.js @@ -1,5 +1,6 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; +import { LiveProvider, LiveEditor, LivePreview, LiveError } from 'react-live'; import { EuiCode, @@ -18,6 +19,8 @@ import { EuiTextColor, EuiTitle, EuiLink, + EuiFlexGroup, + EuiFlexItem, } from '../../../../src/components'; function markup(text) { @@ -99,6 +102,13 @@ export class GuideSection extends Component { this.tabs = []; + if (props.live) { + this.tabs.push({ + name: 'live', + displayName: 'Live', + }); + } + if (props.demo) { this.tabs.push({ name: 'demo', @@ -408,6 +418,50 @@ export class GuideSection extends Component { ); } + renderLive() { + let code = '

No code defined

'; + const dependency = this.props.live.dependency; + + if (this.props.live.snippet) { + code = '<>\n'; + const snippet = this.props.live.snippet; + if (typeof snippet === 'object') { + code += snippet.join('\n'); + code += '\n'; + } else if (typeof snippet === 'string') code = snippet; + else code = '

Snippet not defined.

'; + } + + if (this.props.live.code) { + code = this.props.live.code; + } + + const scope = dependency; + + return ( + + + + + + + + + + + + + + ); + } + renderContent() { if (typeof this.state.selectedTab === 'undefined') { return; @@ -429,6 +483,10 @@ export class GuideSection extends Component { return {this.renderProps()}; } + if (this.state.selectedTab.name === 'live') { + return {this.renderLive()} ; + } + return (