diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index e2b95689a6..b680d9d931 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -11,6 +11,18 @@ declare module '@docusaurus/theme-classic' { }; } +declare module '@theme/Admonition' { + import type {ReactNode} from 'react'; + + export interface Props { + readonly children: ReactNode; + readonly type: 'note' | 'tip' | 'danger' | 'info' | 'caution'; + readonly icon?: ReactNode; + readonly title?: string; + } + export default function Admonition(props: Props): JSX.Element; +} + declare module '@theme/AnnouncementBar' { const AnnouncementBar: () => JSX.Element | null; export default AnnouncementBar; diff --git a/packages/docusaurus-theme-classic/src/theme/Admonition/index.tsx b/packages/docusaurus-theme-classic/src/theme/Admonition/index.tsx new file mode 100644 index 0000000000..137e03574e --- /dev/null +++ b/packages/docusaurus-theme-classic/src/theme/Admonition/index.tsx @@ -0,0 +1,106 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; +import clsx from 'clsx'; +import {Props} from '@theme/Admonition'; + +const icons = { + note: ( + + ), + tip: ( + + ), + danger: ( + + ), + info: ( + + ), + caution: ( + + ), +}; + +const ifmClassNames = { + note: 'secondary', + tip: 'success', + danger: 'danger', + info: 'info', + caution: 'warning', +}; + +export default function Admonition({ + children, + type, + title = type, + icon = icons[type], +}: Props): JSX.Element { + return ( +
Some information
++ Use plugins to introduce shorter syntax for the most commonly used JSX + elements in your project. +
+Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
+