import { Provider, teamsTheme, teamsHighContrastTheme, teamsDarkTheme } from '@fluentui/react-northstar'; import * as _ from 'lodash'; import * as React from 'react'; import { match } from 'react-router-dom'; import { KnobProvider } from '@fluentui/docs-components'; import { ExampleSource } from '../types'; import { exampleSourcesContext, exampleKebabNameToSourceFilename, parseExamplePath } from '../utils'; import PageNotFound from '../views/PageNotFound'; import { SourceRender } from './ComponentDoc/SourceRender'; import { babelConfig, importResolver } from './Playground/renderConfig'; const examplePaths = exampleSourcesContext.keys(); type ExternalExampleLayoutProps = { match: match<{ exampleName: string; rtl: string; }>; }; const themes = { teams: teamsTheme, teamsHighContrast: teamsHighContrastTheme, teamsDark: teamsDarkTheme, }; const ExternalExampleLayout: React.FC = props => { const { exampleName, rtl } = props.match.params; const [error, setError] = React.useState(null); const [renderId, setRenderId] = React.useState(0); const [themeName, setThemeName] = React.useState(); React.useLayoutEffect(() => { window.resetExternalLayout = () => setRenderId(prevNumber => prevNumber + 1); window.switchTheme = setThemeName; }, []); const exampleFilename = exampleKebabNameToSourceFilename(exampleName); const examplePath = _.find(examplePaths, path => exampleFilename === parseExamplePath(path).exampleName); if (!examplePath) return ; const exampleSource: ExampleSource = exampleSourcesContext(examplePath); const theme = (themeName && themes[themeName]) || {}; return ( {/* This block allows to see issues with examples as visual regressions. */} {error &&
{error.toString()}
}
); }; export default ExternalExampleLayout;