From a53032d8fe2cc75fb7ec6140c30348c3389bc019 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 3 Jun 2020 10:51:21 -0700 Subject: [PATCH] feat: Show loading text on example when styles have not loaded --- src/components/ComponentExample.js | 32 +++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/ComponentExample.js b/src/components/ComponentExample.js index b7f386e71..20e427536 100644 --- a/src/components/ComponentExample.js +++ b/src/components/ComponentExample.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import formatCode from '../utils/formatCode'; import github from 'prism-react-renderer/themes/github'; @@ -10,12 +10,21 @@ import { CSS_BUNDLE } from '../utils/sdk'; const TRAILING_SEMI = /;\s*$/; const EXAMPLE_CSS = ` +.nr1-Component-Example { + line-height: 1.36; + font-weight: 400; + background-color: #fff; + color: #000e0e; + font-size: 12px; + font-family: Open Sans,Segoe UI,Tahoma,sans-serif; +} + .nr1-Docs-prettify > * { margin-right: 0.5rem; +} - &:not(:first-child) { - margin-left: 0.5rem; - } +.nr1-Docs-prettify > *:not(:first-child) { + margin-left: 0.5rem; } .nr1-RedBox { @@ -34,6 +43,7 @@ const EXAMPLE_CSS = ` `; const ComponentExample = ({ className, example }) => { + const [stylesLoaded, setStylesLoaded] = useState(false); let formattedCode; try { @@ -58,10 +68,18 @@ const ComponentExample = ({ className, example }) => { disabled={!example.options.live} > {example.options.live && ( - - + + setStylesLoaded(true)} + /> - + {stylesLoaded ? ( + + ) : ( + 'Loading...' + )} )}