/* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ import * as React from "react"; // baseui imports import { useStyletron, createTheme, lightThemePrimitives, darkThemePrimitives, ThemeProvider, } from "baseui"; import { Card } from "baseui/card"; import { Spinner } from "baseui/spinner"; import { useView, Compiler, Error } from "react-view"; // yard (baseweb customization of react-view) import type { TProviderValue } from "./provider"; import { getProvider, getThemeFromContext } from "./provider"; import type { TCustomPropFields } from "./custom-props"; import { customProps } from "./custom-props"; import ThemeEditor from "./theme-editor"; import Overrides from "./overrides"; import OverridesDescription from "./overrides-description"; import Editor from "./editor"; import ActionButtons from "./action-buttons"; import Knobs from "./knobs"; import { YardTabs, YardTab } from "./styled-components"; import { countProps, countOverrides, countThemeValues } from "./utils"; import type { TYardProps } from "./types"; const Yard: React.FC = ({ componentName, placeholderHeight, compilerStyles, scope, props, theme, imports, initialTab, }) => { const [css, baseTheme] = useStyletron(); const componentTheme = getThemeFromContext(baseTheme, theme); const themePrimitives = baseTheme.name && baseTheme.name.startsWith("dark-theme") ? "darkThemePrimitives" : "lightThemePrimitives"; const provider = getProvider(componentTheme, themePrimitives); const params = useView({ componentName, props, scope: { ...scope, ThemeProvider, lightThemePrimitives, darkThemePrimitives, createTheme, }, imports, provider, customProps, }); const activeProps = countProps(params.knobProps.state, props); const activeOverrides = countOverrides(params.knobProps.state.overrides); const activeThemeValues = countThemeValues(params.providerValue); const showOverrides = props.overrides && props.overrides.custom && props.overrides.custom.names && props.overrides.custom.names.length > 0; const showTheme = theme.length > 0; // Bail in IE11 if ( typeof window !== "undefined" && typeof document !== "undefined" && // @ts-ignore: non standard window property !!window.MSInputMethodContext && // @ts-ignore: non standard document property !!document.documentMode ) { console.warn( "[react-live] does not work in IE11! Please use Edge or another modern browser.", ); return null; } return ( (
50 ? 50 : placeholderHeight} />
)} /> {showOverrides || showTheme ? ( 0 ? ` (${activeProps})` : ""}`}> {showOverrides && ( 0 ? ` (${activeOverrides})` : "" }`} > { params.knobProps.set(propValue, "overrides"); }} /> )} {showTheme && ( 0 ? `(${activeThemeValues})` : "" }`} > )} ) : ( )}
); }; export default Yard;