Skip to content

Commit

Permalink
fix: Export more types
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3k0 authored and 3y3 committed Jun 29, 2023
1 parent d88189d commit 6a4a84a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
44 changes: 21 additions & 23 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {ReactElement, useCallback, useEffect, useState} from 'react';
import React, { ReactElement, useCallback, useEffect, useState } from 'react';

import {
DocLeadingPage,
Expand All @@ -10,12 +10,12 @@ import {
TextSizes,
Theme,
} from '@doc-tools/components';
import {getDocSettings, updateRootClassName, withSavingSetting} from '../../utils';
import { getDocSettings, updateRootClassName, withSavingSetting } from '../../utils';

import '../../interceptors/leading-page-links';

import {useMermaid} from '@diplodoc/mermaid-extension/hooks';
import {Runtime as OpenapiSandbox} from '@diplodoc/openapi-extension/runtime';
import { useMermaid } from '@diplodoc/mermaid-extension/hooks';
import { Runtime as OpenapiSandbox } from '@diplodoc/openapi-extension/runtime';
import '@diplodoc/openapi-extension/runtime/styles';

import '@doc-tools/components/styles/themes.scss';
Expand All @@ -24,31 +24,29 @@ import '@doc-tools/components/styles/typography.scss';
import '@doc-tools/transform/dist/css/yfm.css';
import './App.scss';

export interface DocProps {
data: DocLeadingPageData | DocPageData;
}

export interface AppProps {
lang: Lang;
router: Router;
}

export type DocInnerProps =
& DocProps
export type DocInnerProps<Data = DocLeadingPageData | DocPageData> =
& { data: Data }
& AppProps;

export type { DocLeadingPageData, DocPageData };

const MOBILE_VIEW_WIDTH_BREAKPOINT = 900;

export function App(props: DocInnerProps): ReactElement {
const {data, router, lang} = props;
const { data, router, lang } = props;

const docSettings = getDocSettings();
const [isMobileView, setIsMobileView] = useState(typeof document !== 'undefined' && document.body.clientWidth <= MOBILE_VIEW_WIDTH_BREAKPOINT);
const [wideFormat, setWideFormat] = useState(docSettings.wideFormat);
const [fullScreen, setFullScreen] = useState(docSettings.fullScreen);
const [showMiniToc, setShowMiniToc] = useState(docSettings.showMiniToc);
const [theme, setTheme] = useState(docSettings.theme);
const [textSize, setTextSize] = useState(docSettings.textSize);
const [ isMobileView, setIsMobileView ] = useState(typeof document !== 'undefined' && document.body.clientWidth <= MOBILE_VIEW_WIDTH_BREAKPOINT);
const [ wideFormat, setWideFormat ] = useState(docSettings.wideFormat);
const [ fullScreen, setFullScreen ] = useState(docSettings.fullScreen);
const [ showMiniToc, setShowMiniToc ] = useState(docSettings.showMiniToc);
const [ theme, setTheme ] = useState(docSettings.theme);
const [ textSize, setTextSize ] = useState(docSettings.textSize);
const pageProps = {
router,
lang,
Expand Down Expand Up @@ -77,24 +75,24 @@ export function App(props: DocInnerProps): ReactElement {

useEffect(() => {
updateRootClassName(theme, isMobileView);
}, [theme, isMobileView]);
}, [ theme, isMobileView ]);

const renderMermaid = useMermaid();
useEffect(() => {
renderMermaid({
theme: theme === Theme.Dark ? 'dark' : 'neutral',
});
}, [theme, renderMermaid]);
}, [ theme, renderMermaid ]);

return (
// TODO(vladimirfedin): Replace Layout__content class.
<div className="App Layout__content">
{data.leading
? <DocLeadingPage {...data} {...pageProps}/>
{ data.leading
? <DocLeadingPage { ...data } { ...pageProps }/>
// @ts-ignore
: <DocPage {...data} {...pageProps}/>
: <DocPage { ...data } { ...pageProps }/>
}
<OpenapiSandbox />
<OpenapiSandbox/>
</div>
);
}
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import { hydrateRoot, createRoot } from 'react-dom/client';
import { renderToString } from 'react-dom/server';

import { App, DocInnerProps } from './components/App/App';
import { App, DocInnerProps, DocPageData, DocLeadingPageData } from './components/App/App';

export type { DocInnerProps, DocPageData, DocLeadingPageData };

declare global {
interface Window { STATIC_CONTENT: boolean; }
Expand Down

0 comments on commit 6a4a84a

Please sign in to comment.