Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(theme): make warning a first-class admonition, and deprecate caution admonition #9308

Merged
merged 7 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"watch": "yarn lerna run --parallel watch",
"clear": "(yarn workspace website clear || echo 'Failure while running docusaurus clear') && yarn rimraf test-website && yarn rimraf test-website-in-workspace && yarn lerna exec --ignore docusaurus yarn rimraf lib",
"test:baseUrl": "yarn build:website:baseUrl && yarn serve:website:baseUrl",
"lock:update": "npx --yes yarn-deduplicate"
"lock:update": "npx --yes yarn-deduplicate",
"update-translations": "yarn workspace @docusaurus/theme-translations update"
},
"dependencies": {
"unified": "^10.1.2"
Expand Down
22 changes: 15 additions & 7 deletions packages/docusaurus-theme-classic/src/getSwizzleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ export default function getSwizzleConfig(): SwizzleConfig {
},
description: 'The folder containing all admonition icons',
},
'Admonition/Icon/Caution': {
actions: {
eject: 'safe',
wrap: 'safe',
},
description: 'The admonition caution icon',
},
'Admonition/Icon/Danger': {
actions: {
eject: 'safe',
Expand Down Expand Up @@ -54,6 +47,13 @@ export default function getSwizzleConfig(): SwizzleConfig {
},
description: 'The admonition tip icon',
},
'Admonition/Icon/Warning': {
actions: {
eject: 'safe',
wrap: 'safe',
},
description: 'The admonition warning icon',
},
'Admonition/Layout': {
actions: {
eject: 'safe',
Expand Down Expand Up @@ -110,6 +110,14 @@ export default function getSwizzleConfig(): SwizzleConfig {
description:
'The component responsible for rendering a :::tip admonition type',
},
'Admonition/Type/Warning': {
actions: {
eject: 'safe',
wrap: 'safe',
},
description:
'The component responsible for rendering a :::warning admonition type',
},
'Admonition/Types': {
actions: {
eject: 'safe',
Expand Down
13 changes: 11 additions & 2 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,22 @@ declare module '@theme/Admonition/Type/Tip' {
export default function AdmonitionTypeTip(props: Props): JSX.Element;
}

// TODO remove before v4: Caution replaced by Warning
// see https://github.com/facebook/docusaurus/issues/7558
declare module '@theme/Admonition/Type/Caution' {
import type {Props as AdmonitionProps} from '@theme/Admonition';

export interface Props extends AdmonitionProps {}
export default function AdmonitionTypeCaution(props: Props): JSX.Element;
}

declare module '@theme/Admonition/Type/Warning' {
import type {Props as AdmonitionProps} from '@theme/Admonition';

export interface Props extends AdmonitionProps {}
export default function AdmonitionTypeWarning(props: Props): JSX.Element;
}

declare module '@theme/Admonition/Type/Danger' {
import type {Props as AdmonitionProps} from '@theme/Admonition';

Expand Down Expand Up @@ -128,12 +137,12 @@ declare module '@theme/Admonition/Icon/Tip' {
export default function AdmonitionIconTip(props: Props): JSX.Element;
}

declare module '@theme/Admonition/Icon/Caution' {
declare module '@theme/Admonition/Icon/Warning' {
import type {ComponentProps} from 'react';

export interface Props extends ComponentProps<'svg'> {}

export default function AdmonitionIconCaution(props: Props): JSX.Element;
export default function AdmonitionIconWarning(props: Props): JSX.Element;
}

declare module '@theme/Admonition/Icon/Danger' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import type {Props} from '@theme/Admonition/Icon/Caution';
import type {Props} from '@theme/Admonition/Icon/Warning';

export default function AdmonitionIconCaution(props: Props): JSX.Element {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import clsx from 'clsx';
import Translate from '@docusaurus/Translate';
import type {Props} from '@theme/Admonition/Type/Caution';
import AdmonitionLayout from '@theme/Admonition/Layout';
import IconCaution from '@theme/Admonition/Icon/Caution';
import IconWarning from '@theme/Admonition/Icon/Warning';

const infimaClassName = 'alert alert--warning';

const defaultProps = {
icon: <IconCaution />,
icon: <IconWarning />,
title: (
<Translate
id="theme.admonition.caution"
Expand All @@ -25,6 +25,8 @@ const defaultProps = {
),
};

// TODO remove before v4: Caution replaced by Warning
// see https://github.com/facebook/docusaurus/issues/7558
export default function AdmonitionTypeCaution(props: Props): JSX.Element {
return (
<AdmonitionLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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 Translate from '@docusaurus/Translate';
import type {Props} from '@theme/Admonition/Type/Warning';
import AdmonitionLayout from '@theme/Admonition/Layout';
import IconWarning from '@theme/Admonition/Icon/Warning';

const infimaClassName = 'alert alert--warning';

const defaultProps = {
icon: <IconWarning />,
title: (
<Translate
id="theme.admonition.warning"
description="The default label used for the Warning admonition (:::warning)">
warning
</Translate>
),
};

export default function AdmonitionTypeWarning(props: Props): JSX.Element {
return (
<AdmonitionLayout
{...defaultProps}
{...props}
className={clsx(infimaClassName, props.className)}>
{props.children}
</AdmonitionLayout>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import React from 'react';
import AdmonitionTypeNote from '@theme/Admonition/Type/Note';
import AdmonitionTypeTip from '@theme/Admonition/Type/Tip';
import AdmonitionTypeInfo from '@theme/Admonition/Type/Info';
import AdmonitionTypeCaution from '@theme/Admonition/Type/Caution';
import AdmonitionTypeWarning from '@theme/Admonition/Type/Warning';
import AdmonitionTypeDanger from '@theme/Admonition/Type/Danger';
import AdmonitionTypeCaution from '@theme/Admonition/Type/Caution';
import type AdmonitionTypes from '@theme/Admonition/Types';

const admonitionTypes: typeof AdmonitionTypes = {
note: AdmonitionTypeNote,
tip: AdmonitionTypeTip,
info: AdmonitionTypeInfo,
caution: AdmonitionTypeCaution,
warning: AdmonitionTypeWarning,
danger: AdmonitionTypeDanger,
};

Expand All @@ -28,8 +29,7 @@ const admonitionAliases: typeof AdmonitionTypes = {
secondary: (props) => <AdmonitionTypeNote title="secondary" {...props} />,
important: (props) => <AdmonitionTypeInfo title="important" {...props} />,
success: (props) => <AdmonitionTypeTip title="success" {...props} />,
// TODO bad legacy mapping, warning is usually yellow, not red...
warning: (props) => <AdmonitionTypeDanger title="warning" {...props} />,
caution: AdmonitionTypeCaution,
};

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "معلومات",
"theme.admonition.note": "ملاحظة",
"theme.admonition.tip": "تلميح",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "أرشيف",
"theme.blog.archive.title": "أرشيف",
"theme.blog.paginator.navAriaLabel": "التنقل في صفحة قائمة المدونة",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"theme.CodeBlock.wordWrapToggle": "Toggle word wrap",
"theme.CodeBlock.wordWrapToggle___DESCRIPTION": "The title attribute for toggle word wrapping button of code block lines",
"theme.DocSidebarItem.collapseCategoryAriaLabel": "Collapse sidebar category '{label}'",
"theme.DocSidebarItem.collapseCategoryAriaLabel___DESCRIPTION": "The ARIA label to collapse the sidebar category",
"theme.DocSidebarItem.expandCategoryAriaLabel": "Expand sidebar category '{label}'",
"theme.DocSidebarItem.toggleCollapsedCategoryAriaLabel___DESCRIPTION": "The ARIA label to toggle the collapsible sidebar category",
"theme.DocSidebarItem.expandCategoryAriaLabel___DESCRIPTION": "The ARIA label to expand the sidebar category",
"theme.ErrorPageContent.title": "This page crashed.",
"theme.ErrorPageContent.title___DESCRIPTION": "The title of the fallback page when the page crashed",
"theme.ErrorPageContent.tryAgain": "Try again",
Expand All @@ -38,6 +39,8 @@
"theme.admonition.note___DESCRIPTION": "The default label used for the Note admonition (:::note)",
"theme.admonition.tip": "tip",
"theme.admonition.tip___DESCRIPTION": "The default label used for the Tip admonition (:::tip)",
"theme.admonition.warning": "warning",
"theme.admonition.warning___DESCRIPTION": "The default label used for the Warning admonition (:::warning)",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.description___DESCRIPTION": "The page & hero description of the blog archive page",
"theme.blog.archive.title": "Archive",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "ব্লগ তালিকা পেজ নেভিগেশন",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "Stránkování článků na blogu",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "Blogoversigt navigation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archiv",
"theme.blog.archive.title": "Archiv",
"theme.blog.paginator.navAriaLabel": "Navigation der Blog-Listenseite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archivo",
"theme.blog.archive.title": "Archivo",
"theme.blog.paginator.navAriaLabel": "Navegación por la página de la lista de blogs ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "آرشیو",
"theme.blog.archive.title": "آرشیو",
"theme.blog.paginator.navAriaLabel": "کنترل لیست مطالب وبلاگ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "Nabegasyón para sa pahina na listahan ng blog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "remarque",
"theme.admonition.tip": "astuce",
"theme.admonition.warning": "attention",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "Pagination de la liste des articles du blog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "רשימת דפי הבלוג",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "ब्लॉग सूची पेज नेविगेशन",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "információ",
"theme.admonition.note": "megjegyzés",
"theme.admonition.tip": "tanács",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archívum",
"theme.blog.archive.title": "Archívum",
"theme.blog.paginator.navAriaLabel": "Bloglista oldalának navigációja",
Expand Down Expand Up @@ -67,5 +68,7 @@
"theme.navbar.mobileVersionsDropdown.label": "Verziók",
"theme.tags.tagsListLabel": "Címkék:",
"theme.tags.tagsPageLink": "Összes címke megtekintése",
"theme.tags.tagsPageTitle": "Címkék"
"theme.tags.tagsPageTitle": "Címkék",
"theme.unlistedContent.message": "This page is unlisted. Search engines will not index it, and only users having a direct link can access it.",
"theme.unlistedContent.title": "Unlisted page"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle": "Törölje ezt a keresést a kedvencekből",
"theme.SearchModal.startScreen.removeRecentSearchButtonTitle": "Törölje ezt a keresést az előzményekből",
"theme.SearchModal.startScreen.saveRecentSearchButtonTitle": "Mentsük el ezt a keresést",
"theme.SearchPage.saveRecentSearchButtonTitle": "Mentse ezt a keresést",
"theme.SearchPage.algoliaLabel": "Keresés az Algolia segítségével",
"theme.SearchPage.documentsFound.plurals": "Egy dokumentum|{count} dokumentumok",
"theme.SearchPage.emptyResultsTitle": "Keresés a webhelyen",
"theme.SearchPage.existingResultsTitle": "\"{query}\" keresési eredményei",
"theme.SearchPage.fetchingNewResults": "Új keresési eredmények betöltése...",
"theme.SearchPage.inputLabel": "Keresés",
"theme.SearchPage.inputPlaceholder": "Adja meg a keresendő kifejezést",
"theme.SearchPage.noResultsText": "Nincs találat a keresésre"
"theme.SearchPage.noResultsText": "Nincs találat a keresésre",
"theme.SearchPage.saveRecentSearchButtonTitle": "Mentse ezt a keresést"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "informazioni",
"theme.admonition.note": "note",
"theme.admonition.tip": "mancia",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archivio",
"theme.blog.archive.title": "Archivio",
"theme.blog.paginator.navAriaLabel": "Navigazione nella pagina dei post del blog ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "備考",
"theme.admonition.note": "注記",
"theme.admonition.tip": "ヒント",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "アーカイブ",
"theme.blog.archive.title": "アーカイブ",
"theme.blog.paginator.navAriaLabel": "ブログ記事一覧のナビゲーション",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "정보",
"theme.admonition.note": "노트",
"theme.admonition.tip": "팁",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "게시물 목록",
"theme.blog.archive.title": "게시물 목록",
"theme.blog.paginator.navAriaLabel": "블로그 게시물 목록 탐색",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "merknad",
"theme.admonition.tip": "tips",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Arkiv",
"theme.blog.archive.title": "Arkiv",
"theme.blog.paginator.navAriaLabel": "Navigering av bloggliste",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "notitie",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archief",
"theme.blog.archive.title": "Archief",
"theme.blog.paginator.navAriaLabel": "Paginanavigatie blog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "informacja",
"theme.admonition.note": "notatka",
"theme.admonition.tip": "wskazówka",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archiwum",
"theme.blog.archive.title": "Archiwum",
"theme.blog.paginator.navAriaLabel": "Nawigacja na stronie listy wpisów na blogu",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Arquivo",
"theme.blog.archive.title": "Arquivo",
"theme.blog.paginator.navAriaLabel": "Navegação da página de listagem do blog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"theme.admonition.info": "info",
"theme.admonition.note": "note",
"theme.admonition.tip": "tip",
"theme.admonition.warning": "warning",
"theme.blog.archive.description": "Archive",
"theme.blog.archive.title": "Archive",
"theme.blog.paginator.navAriaLabel": "Navegação da página de listagem do blog",
Expand Down
Loading
Loading