import React, { useContext, createContext } from 'react' import { FC, ComponentType as CT } from 'react' import { Entry } from '../state' export interface PlaygroundProps { className?: string style?: any wrapper?: CT components: ComponentsMap component: JSX.Element position: number code: string scope: Record language?: string showLivePreview?: boolean useScoping?: boolean } export interface LayoutProps { doc: Entry [key: string]: any } export interface ComponentsMap { notFound?: CT layout?: CT playground?: CT [key: string]: any } const DefNotFound: FC = () => <>Not found const DefLayout: FC = ({ children }) => <>{children} const DefPlayground: FC = ({ component, code }) => (
{component}
{code}
) const defaultComponents: ComponentsMap = { layout: DefLayout, notFound: DefNotFound, playground: DefPlayground, } export interface ComponentsProviderProps { components: ComponentsMap } const ctx = createContext(defaultComponents) export const ComponentsProvider: FC = ({ components: themeComponents = {}, children, }) => ( {children} ) export const useComponents = (): ComponentsMap => { return useContext(ctx) }