-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
refactor(theme): split admonitions, make swizzle easier, better retrocompatibility #7945
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
93c1547
stable admonition refactor
slorber 15b04c9
stable admonition refactor
slorber 176de1d
stable admonition refactor
slorber 9b190b6
Merge branch 'main' into slorber/admonitions-refactor-retrocompat
slorber a5b7181
stable admonition refactor
slorber 5bb9b47
add documentation for custom admonitions + appendKeywords=true by def…
slorber fa2ea15
admonitionsSchema validation
slorber 6c2d9c4
fix mdx admonition options
slorber fd3dc54
add admonition swizzle config as safe
slorber b8680a4
temporarily fix swizzle test for intermediate folders
slorber f064123
fix swizzle tests
slorber 8c70574
Merge branch 'main' into slorber/admonitions-refactor-retrocompat
slorber 0567320
Update website/docs/guides/markdown-features/markdown-features-admoni…
slorber 3c147a4
Update website/docs/guides/markdown-features/markdown-features-admoni…
slorber 0ddfefa
Update website/docs/guides/markdown-features/markdown-features-admoni…
slorber 0577d69
docs: fix typo in swizzling.md (#8025)
amm98d b15e846
chore(deps): bump github/codeql-action from 2.1.20 to 2.1.21 (#8020)
dependabot[bot] a29e6f0
chore(deps): bump actions/github-script from 6.1.1 to 6.2.0 (#8019)
dependabot[bot] b7ac025
docs(showcase): add 74 new showcase sites (#8010)
slorber 8a73b39
chore(ci): GitHub Workflows security hardening (#8030)
sashashura 749c6ac
fix(preset-classic): broken link in "unrecognized keys" error message…
mdubus c5aed50
docs(showcase): fix daily.dev site name (#8031)
FrancescoXX 5669851
fix(create-docusaurus): tutorial and init template improvements (#8032)
slorber 4bec3a3
docs: create Docusaurus v2.1.0 release docs + changelog + release blo…
slorber 2b1b1b7
chore: Update examples after release of Docusaurus v2.1.0 (#8041)
slorber 354a75a
fix(website): fix blog post social card (#8042)
slorber cef94a3
refactor(core): detect if codegen should quote property without using…
Josh-Cena 6961f46
docs: delete extra semicolon in MDX and React page (#8046)
mrazauskas 88de830
docs: improve alt messages (#8047)
Josh-Cena 07b56b8
chore(deps): bump github/codeql-action from 2.1.21 to 2.1.22 (#8051)
dependabot[bot] abf52e3
docs: document usage of docs `frontMatter.custom_edit_url: null` (#8053)
homotechsual 915ab7c
docs(content-docs): updates typo in lifecycle-apis.md (#8055)
GalexyN 78b706a
docs: fix broken image (#8054)
debs-obrien c080a52
defaultProps
slorber ac13f1e
review: const componentNames
slorber 15fb104
appendKeywords => extendDefaults
slorber 4f34062
Merge branch 'main' into slorber/admonitions-refactor-retrocompat
slorber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/docusaurus-theme-classic/src/theme/Admonition/Icon/Caution.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * 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 type {Props} from '@theme/Admonition/Icon/Caution'; | ||
|
|
||
| export default function AdmonitionIconCaution(props: Props): JSX.Element { | ||
| return ( | ||
| <svg viewBox="0 0 16 16" {...props}> | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/docusaurus-theme-classic/src/theme/Admonition/Icon/Danger.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * 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 type {Props} from '@theme/Admonition/Icon/Danger'; | ||
|
|
||
| export default function AdmonitionIconDanger(props: Props): JSX.Element { | ||
| return ( | ||
| <svg viewBox="0 0 12 16" {...props}> | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M5.05.31c.81 2.17.41 3.38-.52 4.31C3.55 5.67 1.98 6.45.9 7.98c-1.45 2.05-1.7 6.53 3.53 7.7-2.2-1.16-2.67-4.52-.3-6.61-.61 2.03.53 3.33 1.94 2.86 1.39-.47 2.3.53 2.27 1.67-.02.78-.31 1.44-1.13 1.81 3.42-.59 4.78-3.42 4.78-5.56 0-2.84-2.53-3.22-1.25-5.61-1.52.13-2.03 1.13-1.89 2.75.09 1.08-1.02 1.8-1.86 1.33-.67-.41-.66-1.19-.06-1.78C8.18 5.31 8.68 2.45 5.05.32L5.03.3l.02.01z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/docusaurus-theme-classic/src/theme/Admonition/Icon/Info.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * 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 type {Props} from '@theme/Admonition/Icon/Info'; | ||
|
|
||
| export default function AdmonitionIconInfo(props: Props): JSX.Element { | ||
| return ( | ||
| <svg viewBox="0 0 14 16" {...props}> | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/docusaurus-theme-classic/src/theme/Admonition/Icon/Note.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * 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 type {Props} from '@theme/Admonition/Icon/Note'; | ||
|
|
||
| export default function AdmonitionIconNote(props: Props): JSX.Element { | ||
| return ( | ||
| <svg viewBox="0 0 14 16" {...props}> | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/docusaurus-theme-classic/src/theme/Admonition/Icon/Tip.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * 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 type {Props} from '@theme/Admonition/Icon/Tip'; | ||
|
|
||
| export default function AdmonitionIconTip(props: Props): JSX.Element { | ||
| return ( | ||
| <svg viewBox="0 0 12 16" {...props}> | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
55 changes: 55 additions & 0 deletions
55
packages/docusaurus-theme-classic/src/theme/Admonition/Layout/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * 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, {type ReactNode} from 'react'; | ||
| import clsx from 'clsx'; | ||
| import {ThemeClassNames} from '@docusaurus/theme-common'; | ||
|
|
||
| import type {Props} from '@theme/Admonition/Layout'; | ||
|
|
||
| import styles from './styles.module.css'; | ||
|
|
||
| function AdmonitionContainer({ | ||
| type, | ||
| className, | ||
| children, | ||
| }: Pick<Props, 'type' | 'className'> & {children: ReactNode}) { | ||
| return ( | ||
| <div | ||
| className={clsx( | ||
| ThemeClassNames.common.admonition, | ||
| ThemeClassNames.common.admonitionType(type), | ||
| styles.admonition, | ||
| className, | ||
| )}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function AdmonitionHeading({icon, title}: Pick<Props, 'icon' | 'title'>) { | ||
| return ( | ||
| <div className={styles.admonitionHeading}> | ||
| <span className={styles.admonitionIcon}>{icon}</span> | ||
| {title} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function AdmonitionContent({children}: Pick<Props, 'children'>) { | ||
| return <div className={styles.admonitionContent}>{children}</div>; | ||
| } | ||
|
|
||
| export default function AdmonitionLayout(props: Props): JSX.Element { | ||
| const {type, icon, title, children, className} = props; | ||
| return ( | ||
| <AdmonitionContainer type={type} className={className}> | ||
| <AdmonitionHeading title={title} icon={icon} /> | ||
| <AdmonitionContent>{children}</AdmonitionContent> | ||
| </AdmonitionContainer> | ||
| ); | ||
| } |
File renamed without changes.
105 changes: 105 additions & 0 deletions
105
packages/docusaurus-theme-classic/src/theme/Admonition/Types.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * 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 Translate from '@docusaurus/Translate'; | ||
| import type {Props} from '@theme/Admonition'; | ||
| import IconNote from '@theme/Admonition/Icon/Note'; | ||
| import IconTip from '@theme/Admonition/Icon/Tip'; | ||
| import IconInfo from '@theme/Admonition/Icon/Info'; | ||
| import IconCaution from '@theme/Admonition/Icon/Caution'; | ||
| import IconDanger from '@theme/Admonition/Icon/Danger'; | ||
| import type {AdmonitionTypeConfig} from '@theme/Admonition/Types'; | ||
|
|
||
| function getInfimaClassName(suffix: string) { | ||
| return `alert alert--${suffix}`; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style | ||
| const admonitionTypes: Record<Props['type'], AdmonitionTypeConfig> = { | ||
| note: { | ||
| className: getInfimaClassName('secondary'), | ||
| iconComponent: IconNote, | ||
| label: ( | ||
| <Translate | ||
| id="theme.admonition.note" | ||
| description="The default label used for the Note admonition (:::note)"> | ||
| note | ||
| </Translate> | ||
| ), | ||
| }, | ||
| tip: { | ||
| className: getInfimaClassName('success'), | ||
| iconComponent: IconTip, | ||
| label: ( | ||
| <Translate | ||
| id="theme.admonition.tip" | ||
| description="The default label used for the Tip admonition (:::tip)"> | ||
| tip | ||
| </Translate> | ||
| ), | ||
| }, | ||
| danger: { | ||
| className: getInfimaClassName('danger'), | ||
| iconComponent: IconDanger, | ||
| label: ( | ||
| <Translate | ||
| id="theme.admonition.danger" | ||
| description="The default label used for the Danger admonition (:::danger)"> | ||
| danger | ||
| </Translate> | ||
| ), | ||
| }, | ||
| info: { | ||
| className: getInfimaClassName('info'), | ||
| iconComponent: IconInfo, | ||
| label: ( | ||
| <Translate | ||
| id="theme.admonition.info" | ||
| description="The default label used for the Info admonition (:::info)"> | ||
| info | ||
| </Translate> | ||
| ), | ||
| }, | ||
| caution: { | ||
| className: getInfimaClassName('warning'), | ||
| iconComponent: IconCaution, | ||
| label: ( | ||
| <Translate | ||
| id="theme.admonition.caution" | ||
| description="The default label used for the Caution admonition (:::caution)"> | ||
| caution | ||
| </Translate> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| function createLegacyAlias( | ||
| alias: string, | ||
| config: AdmonitionTypeConfig, | ||
| ): AdmonitionTypeConfig { | ||
| return { | ||
| ...config, | ||
| // An alias "important" should display "Important", not "Info" | ||
| // Not translated on purpose: legacy, to remove later | ||
| label: alias, | ||
| }; | ||
| } | ||
|
|
||
| // Legacy admonition type aliases, undocumented but kept for retro-compatibility | ||
| const aliases: {[key: string]: AdmonitionTypeConfig} = { | ||
| secondary: createLegacyAlias('secondary', admonitionTypes.note), | ||
| important: createLegacyAlias('important', admonitionTypes.info), | ||
| success: createLegacyAlias('success', admonitionTypes.tip), | ||
| // TODO bad legacy mapping, warning is usually yellow, not red... | ||
| warning: createLegacyAlias('warning', admonitionTypes.danger), | ||
| } as const; | ||
|
|
||
| export default { | ||
| ...admonitionTypes, | ||
| ...aliases, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.