mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-07 06:07:42 +02:00
refactor(v2): add missing theme-classic types (#4385)
This commit is contained in:
parent
fa1d681abc
commit
a39c62f644
17 changed files with 90 additions and 46 deletions
|
@ -9,8 +9,9 @@ import React from 'react';
|
||||||
import Layout from '@theme/Layout';
|
import Layout from '@theme/Layout';
|
||||||
import {MDXProvider} from '@mdx-js/react';
|
import {MDXProvider} from '@mdx-js/react';
|
||||||
import MDXComponents from '@theme/MDXComponents';
|
import MDXComponents from '@theme/MDXComponents';
|
||||||
|
import type {Props} from '@theme/MDXPage';
|
||||||
|
|
||||||
function MDXPage(props) {
|
function MDXPage(props: Props): JSX.Element {
|
||||||
const {content: MDXPageContent} = props;
|
const {content: MDXPageContent} = props;
|
||||||
const {frontMatter, metadata} = MDXPageContent;
|
const {frontMatter, metadata} = MDXPageContent;
|
||||||
const {title, description} = frontMatter;
|
const {title, description} = frontMatter;
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
import Translate, {translate} from '@docusaurus/Translate';
|
import Translate, {translate} from '@docusaurus/Translate';
|
||||||
import type {Metadata} from '@theme/BlogListPage';
|
import type {Props} from '@theme/BlogListPaginator';
|
||||||
|
|
||||||
function BlogListPaginator(props: {readonly metadata: Metadata}): JSX.Element {
|
function BlogListPaginator(props: Props): JSX.Element {
|
||||||
const {metadata} = props;
|
const {metadata} = props;
|
||||||
const {previousPage, nextPage} = metadata;
|
const {previousPage, nextPage} = metadata;
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ function DocSidebarItemLink({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DocSidebarItem(props) {
|
function DocSidebarItem(props): JSX.Element {
|
||||||
switch (props.item.type) {
|
switch (props.item.type) {
|
||||||
case 'category':
|
case 'category':
|
||||||
return <DocSidebarItemCategory {...props} />;
|
return <DocSidebarItemCategory {...props} />;
|
||||||
|
|
|
@ -12,7 +12,7 @@ import Link from '@docusaurus/Link';
|
||||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
import ThemedImage from '@theme/ThemedImage';
|
import ThemedImage, {Props as ThemedImageProps} from '@theme/ThemedImage';
|
||||||
|
|
||||||
function FooterLink({to, href, label, prependBaseUrlToHref, ...props}: any) {
|
function FooterLink({to, href, label, prependBaseUrlToHref, ...props}: any) {
|
||||||
const toUrl = useBaseUrl(to);
|
const toUrl = useBaseUrl(to);
|
||||||
|
@ -34,7 +34,10 @@ function FooterLink({to, href, label, prependBaseUrlToHref, ...props}: any) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const FooterLogo = ({sources, alt}) => (
|
const FooterLogo = ({
|
||||||
|
sources,
|
||||||
|
alt,
|
||||||
|
}: Pick<ThemedImageProps, 'sources' | 'alt'>) => (
|
||||||
<ThemedImage className="footer__logo" alt={alt} sources={sources} />
|
<ThemedImage className="footer__logo" alt={alt} sources={sources} />
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Props} from '@theme/IconArrow';
|
import type {Props} from '@theme/IconArrow';
|
||||||
|
|
||||||
const IconArrow = (props: Props): JSX.Element => {
|
const IconArrow = (props: Props): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
||||||
import {Props} from '@theme/IconEdit';
|
import type {Props} from '@theme/IconEdit';
|
||||||
|
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Props} from '@theme/IconLanguage';
|
import type {Props} from '@theme/IconLanguage';
|
||||||
|
|
||||||
const IconLanguage = ({
|
const IconLanguage = ({
|
||||||
width = 20,
|
width = 20,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Props} from '@theme/IconMenu';
|
import type {Props} from '@theme/IconMenu';
|
||||||
|
|
||||||
const IconMenu = ({
|
const IconMenu = ({
|
||||||
width = 30,
|
width = 30,
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
import Translate from '@docusaurus/Translate';
|
import Translate from '@docusaurus/Translate';
|
||||||
|
import type {Props} from '@theme/LastUpdated';
|
||||||
|
|
||||||
function LastUpdatedAtDate({
|
function LastUpdatedAtDate({
|
||||||
lastUpdatedAt,
|
lastUpdatedAt,
|
||||||
|
@ -15,7 +16,7 @@ function LastUpdatedAtDate({
|
||||||
}: {
|
}: {
|
||||||
lastUpdatedAt: number;
|
lastUpdatedAt: number;
|
||||||
formattedLastUpdatedAt: string;
|
formattedLastUpdatedAt: string;
|
||||||
}) {
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Translate
|
<Translate
|
||||||
id="theme.lastUpdated.atDate"
|
id="theme.lastUpdated.atDate"
|
||||||
|
@ -34,7 +35,11 @@ function LastUpdatedAtDate({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function LastUpdatedByUser({lastUpdatedBy}: {lastUpdatedBy: string}) {
|
function LastUpdatedByUser({
|
||||||
|
lastUpdatedBy,
|
||||||
|
}: {
|
||||||
|
lastUpdatedBy: string;
|
||||||
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Translate
|
<Translate
|
||||||
id="theme.lastUpdated.byUser"
|
id="theme.lastUpdated.byUser"
|
||||||
|
@ -51,11 +56,7 @@ export default function LastUpdated({
|
||||||
lastUpdatedAt,
|
lastUpdatedAt,
|
||||||
formattedLastUpdatedAt,
|
formattedLastUpdatedAt,
|
||||||
lastUpdatedBy,
|
lastUpdatedBy,
|
||||||
}: {
|
}: Props): JSX.Element {
|
||||||
lastUpdatedAt: number | undefined;
|
|
||||||
formattedLastUpdatedAt: string | undefined;
|
|
||||||
lastUpdatedBy: string | undefined;
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<div className="col text--right">
|
<div className="col text--right">
|
||||||
<em>
|
<em>
|
||||||
|
|
|
@ -9,7 +9,7 @@ import React from 'react';
|
||||||
import ThemeProvider from '@theme/ThemeProvider';
|
import ThemeProvider from '@theme/ThemeProvider';
|
||||||
import UserPreferencesProvider from '@theme/UserPreferencesProvider';
|
import UserPreferencesProvider from '@theme/UserPreferencesProvider';
|
||||||
import {DocsPreferredVersionContextProvider} from '@docusaurus/theme-common';
|
import {DocsPreferredVersionContextProvider} from '@docusaurus/theme-common';
|
||||||
import {Props} from '@theme/LayoutProviders';
|
import type {Props} from '@theme/LayoutProviders';
|
||||||
|
|
||||||
export default function LayoutProviders({children}: Props): JSX.Element {
|
export default function LayoutProviders({children}: Props): JSX.Element {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -8,12 +8,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import Head from '@docusaurus/Head';
|
import Head from '@docusaurus/Head';
|
||||||
|
import type {Props} from '@theme/SearchMetadatas';
|
||||||
type SearchTagMetaProps = {
|
|
||||||
locale?: string;
|
|
||||||
version?: string;
|
|
||||||
tag?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Note: we don't couple this to Algolia/DocSearch on purpose
|
// Note: we don't couple this to Algolia/DocSearch on purpose
|
||||||
// We may want to support other search engine plugins too
|
// We may want to support other search engine plugins too
|
||||||
|
@ -22,7 +17,7 @@ export default function SearchMetadatas({
|
||||||
locale,
|
locale,
|
||||||
version,
|
version,
|
||||||
tag,
|
tag,
|
||||||
}: SearchTagMetaProps): JSX.Element {
|
}: Props): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Head>
|
<Head>
|
||||||
{locale && <meta name="docusaurus_locale" content={`${locale}`} />}
|
{locale && <meta name="docusaurus_locale" content={`${locale}`} />}
|
||||||
|
|
|
@ -10,20 +10,20 @@ import Translate from '@docusaurus/Translate';
|
||||||
import {useLocation} from '@docusaurus/router';
|
import {useLocation} from '@docusaurus/router';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
function programmaticFocus(el) {
|
function programmaticFocus(el: HTMLElement) {
|
||||||
el.setAttribute('tabindex', '-1');
|
el.setAttribute('tabindex', '-1');
|
||||||
el.focus();
|
el.focus();
|
||||||
el.removeAttribute('tabindex');
|
el.removeAttribute('tabindex');
|
||||||
}
|
}
|
||||||
|
|
||||||
function SkipToContent(): JSX.Element {
|
function SkipToContent(): JSX.Element {
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const handleSkip = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
const handleSkip = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const targetElement =
|
const targetElement: HTMLElement | null =
|
||||||
document.querySelector('main:first-of-type') ||
|
document.querySelector('main:first-of-type') ||
|
||||||
document.querySelector('.main-wrapper');
|
document.querySelector('.main-wrapper');
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ function SkipToContent(): JSX.Element {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!location.hash) {
|
if (!location.hash) {
|
||||||
programmaticFocus(containerRef.current);
|
programmaticFocus(containerRef.current!);
|
||||||
}
|
}
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import type {TOCProps} from '@theme/TOC';
|
import type {TOCInlineProps} from '@theme/TOCInline';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
import {TOCItem} from '@docusaurus/types';
|
import {TOCItem} from '@docusaurus/types';
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ function HeadingsInline({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TOCInline({toc}: TOCProps): JSX.Element {
|
function TOCInline({toc}: TOCInlineProps): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className={clsx(styles.tableOfContentsInline)}>
|
<div className={clsx(styles.tableOfContentsInline)}>
|
||||||
<HeadingsInline toc={toc} />
|
<HeadingsInline toc={toc} />
|
||||||
|
|
|
@ -14,7 +14,7 @@ import clsx from 'clsx';
|
||||||
|
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
function isInViewport(element: HTMLElement) {
|
function isInViewport(element: HTMLElement): boolean {
|
||||||
const {top, left, bottom, right} = element.getBoundingClientRect();
|
const {top, left, bottom, right} = element.getBoundingClientRect();
|
||||||
const {innerHeight, innerWidth} = window;
|
const {innerHeight, innerWidth} = window;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ function isInViewport(element: HTMLElement) {
|
||||||
const keys = {
|
const keys = {
|
||||||
left: 37,
|
left: 37,
|
||||||
right: 39,
|
right: 39,
|
||||||
};
|
} as const;
|
||||||
|
|
||||||
function Tabs(props: Props): JSX.Element {
|
function Tabs(props: Props): JSX.Element {
|
||||||
const {lazy, block, defaultValue, values, groupId, className} = props;
|
const {lazy, block, defaultValue, values, groupId, className} = props;
|
||||||
|
@ -79,14 +79,16 @@ function Tabs(props: Props): JSX.Element {
|
||||||
let focusElement;
|
let focusElement;
|
||||||
|
|
||||||
switch (event.keyCode) {
|
switch (event.keyCode) {
|
||||||
case keys.right:
|
case keys.right: {
|
||||||
const nextTab = tabRefs.indexOf(event.target) + 1;
|
const nextTab = tabRefs.indexOf(event.target) + 1;
|
||||||
focusElement = tabRefs[nextTab] || tabRefs[0];
|
focusElement = tabRefs[nextTab] || tabRefs[0];
|
||||||
break;
|
break;
|
||||||
case keys.left:
|
}
|
||||||
|
case keys.left: {
|
||||||
const prevTab = tabRefs.indexOf(event.target) - 1;
|
const prevTab = tabRefs.indexOf(event.target) - 1;
|
||||||
focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
|
focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,26 +5,32 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {ComponentProps} from 'react';
|
import React, {CSSProperties} from 'react';
|
||||||
import Toggle from 'react-toggle';
|
import Toggle from 'react-toggle';
|
||||||
|
import type {Props} from '@theme/Toggle';
|
||||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
const Dark = ({icon, style}) => (
|
interface IconProps {
|
||||||
|
icon: string;
|
||||||
|
style: CSSProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Dark = ({icon, style}: IconProps): JSX.Element => (
|
||||||
<span className={clsx(styles.toggle, styles.dark)} style={style}>
|
<span className={clsx(styles.toggle, styles.dark)} style={style}>
|
||||||
{icon}
|
{icon}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
const Light = ({icon, style}) => (
|
const Light = ({icon, style}: IconProps): JSX.Element => (
|
||||||
<span className={clsx(styles.toggle, styles.light)} style={style}>
|
<span className={clsx(styles.toggle, styles.light)} style={style}>
|
||||||
{icon}
|
{icon}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
export default function (props: ComponentProps<typeof Toggle>): JSX.Element {
|
export default function (props: Props): JSX.Element {
|
||||||
const {
|
const {
|
||||||
colorMode: {
|
colorMode: {
|
||||||
switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
|
switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
|
||||||
|
|
46
packages/docusaurus-theme-classic/src/types.d.ts
vendored
46
packages/docusaurus-theme-classic/src/types.d.ts
vendored
|
@ -258,9 +258,43 @@ declare module '@theme/Layout' {
|
||||||
export default Layout;
|
export default Layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '@theme/LayoutHead' {
|
||||||
|
import type {Props} from '@theme/Layout';
|
||||||
|
|
||||||
|
const LayoutHead: (props: Props) => JSX.Element;
|
||||||
|
export default LayoutHead;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '@theme/SearchMetadatas' {
|
||||||
|
export type Props = {
|
||||||
|
locale?: string;
|
||||||
|
version?: string;
|
||||||
|
tag?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SearchMetadatas: (props: Props) => JSX.Element;
|
||||||
|
export default SearchMetadatas;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '@theme/LastUpdated' {
|
||||||
|
export type Props = {
|
||||||
|
lastUpdatedAt?: number;
|
||||||
|
formattedLastUpdatedAt?: string;
|
||||||
|
lastUpdatedBy?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LastUpdated: (props: Props) => JSX.Element;
|
||||||
|
export default LastUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '@theme/SkipToContent' {
|
||||||
|
const SkipToContent: () => JSX.Element;
|
||||||
|
export default SkipToContent;
|
||||||
|
}
|
||||||
|
|
||||||
declare module '@theme/MDXComponents' {
|
declare module '@theme/MDXComponents' {
|
||||||
import {ComponentProps} from 'react';
|
import type {ComponentProps} from 'react';
|
||||||
import CodeBlock from '@theme/CodeBlock';
|
import type CodeBlock from '@theme/CodeBlock';
|
||||||
|
|
||||||
export type MDXComponentsObject = {
|
export type MDXComponentsObject = {
|
||||||
readonly code: typeof CodeBlock;
|
readonly code: typeof CodeBlock;
|
||||||
|
@ -465,10 +499,12 @@ declare module '@theme/TOCInline' {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@theme/Toggle' {
|
declare module '@theme/Toggle' {
|
||||||
import {ComponentProps} from 'react';
|
import type {ComponentProps} from 'react';
|
||||||
import ReactToggle from 'react-toggle';
|
import type ReactToggle from 'react-toggle';
|
||||||
|
|
||||||
const Toggle: (props: ComponentProps<typeof ReactToggle>) => JSX.Element;
|
export type Props = ComponentProps<typeof ReactToggle>;
|
||||||
|
|
||||||
|
const Toggle: (props: Props) => JSX.Element;
|
||||||
export default Toggle;
|
export default Toggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ export function DocsPreferredVersionContextProvider({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) {
|
}): JSX.Element {
|
||||||
if (isDocsPluginEnabled) {
|
if (isDocsPluginEnabled) {
|
||||||
return (
|
return (
|
||||||
<DocsPreferredVersionContextProviderUnsafe>
|
<DocsPreferredVersionContextProviderUnsafe>
|
||||||
|
@ -149,7 +149,7 @@ function DocsPreferredVersionContextProviderUnsafe({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) {
|
}): JSX.Element {
|
||||||
const contextValue = useContextValue();
|
const contextValue = useContextValue();
|
||||||
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue