From 65350c0839bf5cbbdd128d645018a0f5f07ac14f Mon Sep 17 00:00:00 2001 From: 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> Date: Sat, 27 Jan 2024 01:22:54 +0900 Subject: initial commit --- src/theme/Admonition/Icon/Danger.js | 11 +++++++++ src/theme/Admonition/Icon/Info.js | 11 +++++++++ src/theme/Admonition/Icon/Note.js | 11 +++++++++ src/theme/Admonition/Icon/Tip.js | 11 +++++++++ src/theme/Admonition/Icon/Warning.js | 11 +++++++++ src/theme/Admonition/Layout/index.js | 28 +++++++++------------ src/theme/Admonition/Layout/styles.module.css | 35 +++++++++++++++++++++++++++ src/theme/Admonition/Type/Caution.js | 10 ++------ src/theme/Admonition/Type/Danger.js | 10 ++------ src/theme/Admonition/Type/Info.js | 10 ++------ src/theme/Admonition/Type/Note.js | 10 ++------ src/theme/Admonition/Type/Tip.js | 10 ++------ src/theme/Admonition/Type/Warning.js | 10 ++------ src/theme/Admonition/Types.js | 18 +++++--------- src/theme/Admonition/index.js | 8 +----- 15 files changed, 120 insertions(+), 84 deletions(-) create mode 100644 src/theme/Admonition/Icon/Danger.js create mode 100644 src/theme/Admonition/Icon/Info.js create mode 100644 src/theme/Admonition/Icon/Note.js create mode 100644 src/theme/Admonition/Icon/Tip.js create mode 100644 src/theme/Admonition/Icon/Warning.js create mode 100644 src/theme/Admonition/Layout/styles.module.css (limited to 'src/theme') diff --git a/src/theme/Admonition/Icon/Danger.js b/src/theme/Admonition/Icon/Danger.js new file mode 100644 index 00000000..3ae0f005 --- /dev/null +++ b/src/theme/Admonition/Icon/Danger.js @@ -0,0 +1,11 @@ +import React from 'react'; +export default function AdmonitionIconDanger(props) { + return ( + + + + ); +} diff --git a/src/theme/Admonition/Icon/Info.js b/src/theme/Admonition/Icon/Info.js new file mode 100644 index 00000000..6e843d2e --- /dev/null +++ b/src/theme/Admonition/Icon/Info.js @@ -0,0 +1,11 @@ +import React from 'react'; +export default function AdmonitionIconInfo(props) { + return ( + + + + ); +} diff --git a/src/theme/Admonition/Icon/Note.js b/src/theme/Admonition/Icon/Note.js new file mode 100644 index 00000000..e1cc0e4d --- /dev/null +++ b/src/theme/Admonition/Icon/Note.js @@ -0,0 +1,11 @@ +import React from 'react'; +export default function AdmonitionIconNote(props) { + return ( + + + + ); +} diff --git a/src/theme/Admonition/Icon/Tip.js b/src/theme/Admonition/Icon/Tip.js new file mode 100644 index 00000000..060d6c93 --- /dev/null +++ b/src/theme/Admonition/Icon/Tip.js @@ -0,0 +1,11 @@ +import React from 'react'; +export default function AdmonitionIconTip(props) { + return ( + + + + ); +} diff --git a/src/theme/Admonition/Icon/Warning.js b/src/theme/Admonition/Icon/Warning.js new file mode 100644 index 00000000..3cea92d8 --- /dev/null +++ b/src/theme/Admonition/Icon/Warning.js @@ -0,0 +1,11 @@ +import React from 'react'; +export default function AdmonitionIconCaution(props) { + return ( + + + + ); +} diff --git a/src/theme/Admonition/Layout/index.js b/src/theme/Admonition/Layout/index.js index 14a987b0..8d95599e 100644 --- a/src/theme/Admonition/Layout/index.js +++ b/src/theme/Admonition/Layout/index.js @@ -1,13 +1,7 @@ -/** - * 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 { ThemeClassNames } from '@docusaurus/theme-common'; -import admonitionStyles from '@docusaurus/theme-classic/lib/theme/Admonition/Layout/styles.module.css'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import styles from './styles.module.css'; import headingStyles from '@docusaurus/theme-classic/lib/theme/Heading/styles.module.css'; function AdmonitionContainer({type, className, children}) { @@ -16,33 +10,33 @@ function AdmonitionContainer({type, className, children}) { className={clsx( ThemeClassNames.common.admonition, ThemeClassNames.common.admonitionType(type), - admonitionStyles.admonition, + styles.admonition, className, - )} - > + )}> {children} ); } -function AdmonitionHeading({icon, id, title}) { +function AdmonitionHeading({icon, title, id}) { let depth = 0; - let trimmedTitle = ""; + let trimmedTitle = title; // titleにHTML等が含まれている場合は文字列ではなく配列になる if(typeof title === "string") { // 文字列冒頭の#の数を数える( depth = title.match ? (title.toString().match(/^#+/) || [''])[0].length : 0; // #を省いたタイトルを得る - trimmedTitle = depth > 0 ? title.replace(/^#+/, '').trim() : title; + trimmedTitle = depth > 0 ? title.replace(/^#+/, '').trim() : title; } else if (typeof title[0] === "string") { depth = title[0].match ? (title[0].match(/^#+/) || [''])[0].length : 0; trimmedTitle = depth > 0 ? [title[0].replace(/^#+/, '').trim(), ...title.slice(1)] : title; } + // スクロール位置調整のcss const classNames = clsx("anchor", "title", headingStyles.anchorWithStickyNavbar); // depthに応じて見出しタグをレンダー return ( -
- {icon} +
+ {icon} {(() => { if (depth == 3) { return( @@ -93,7 +87,7 @@ function AdmonitionHeading({icon, id, title}) { } function AdmonitionContent({children}) { return children ? ( -
{children}
+
{children}
) : null; } export default function AdmonitionLayout(props) { diff --git a/src/theme/Admonition/Layout/styles.module.css b/src/theme/Admonition/Layout/styles.module.css new file mode 100644 index 00000000..88df7e63 --- /dev/null +++ b/src/theme/Admonition/Layout/styles.module.css @@ -0,0 +1,35 @@ +.admonition { + margin-bottom: 1em; +} + +.admonitionHeading { + font: var(--ifm-heading-font-weight) var(--ifm-h5-font-size) / + var(--ifm-heading-line-height) var(--ifm-heading-font-family); + text-transform: uppercase; +} + +/* Heading alone without content (does not handle fragment content) */ +.admonitionHeading:not(:last-child) { + margin-bottom: 0.3rem; +} + +.admonitionHeading code { + text-transform: none; +} + +.admonitionIcon { + display: inline-block; + vertical-align: middle; + margin-right: 0.4em; +} + +.admonitionIcon svg { + display: inline-block; + height: 1.6em; + width: 1.6em; + fill: var(--ifm-alert-foreground-color); +} + +.admonitionContent > :last-child { + margin-bottom: 0; +} diff --git a/src/theme/Admonition/Type/Caution.js b/src/theme/Admonition/Type/Caution.js index a7bc5440..7890ef7c 100644 --- a/src/theme/Admonition/Type/Caution.js +++ b/src/theme/Admonition/Type/Caution.js @@ -1,14 +1,8 @@ -/** - * 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 AdmonitionLayout from '../Layout'; -import IconWarning from '@docusaurus/theme-classic/lib/theme/Admonition/Icon/Warning'; +import AdmonitionLayout from '@theme/Admonition/Layout'; +import IconWarning from '@theme/Admonition/Icon/Warning'; const infimaClassName = 'alert alert--warning'; const defaultProps = { icon: , diff --git a/src/theme/Admonition/Type/Danger.js b/src/theme/Admonition/Type/Danger.js index 39e37f69..7a8eb840 100644 --- a/src/theme/Admonition/Type/Danger.js +++ b/src/theme/Admonition/Type/Danger.js @@ -1,14 +1,8 @@ -/** - * 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 AdmonitionLayout from '../Layout'; -import IconDanger from '@docusaurus/theme-classic/lib/theme/Admonition/Icon/Danger'; +import AdmonitionLayout from '@theme/Admonition/Layout'; +import IconDanger from '@theme/Admonition/Icon/Danger'; const infimaClassName = 'alert alert--danger'; const defaultProps = { icon: , diff --git a/src/theme/Admonition/Type/Info.js b/src/theme/Admonition/Type/Info.js index 44409a44..f0e9d2b6 100644 --- a/src/theme/Admonition/Type/Info.js +++ b/src/theme/Admonition/Type/Info.js @@ -1,14 +1,8 @@ -/** - * 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 AdmonitionLayout from '../Layout'; -import IconInfo from '@docusaurus/theme-classic/lib/theme/Admonition/Icon/Info'; +import AdmonitionLayout from '@theme/Admonition/Layout'; +import IconInfo from '@theme/Admonition/Icon/Info'; const infimaClassName = 'alert alert--info'; const defaultProps = { icon: , diff --git a/src/theme/Admonition/Type/Note.js b/src/theme/Admonition/Type/Note.js index 01226d2f..5dfb6c00 100644 --- a/src/theme/Admonition/Type/Note.js +++ b/src/theme/Admonition/Type/Note.js @@ -1,14 +1,8 @@ -/** - * 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 AdmonitionLayout from '../Layout'; -import IconNote from '@docusaurus/theme-classic/lib/theme/Admonition/Icon/Note'; +import AdmonitionLayout from '@theme/Admonition/Layout'; +import IconNote from '@theme/Admonition/Icon/Note'; const infimaClassName = 'alert alert--secondary'; const defaultProps = { icon: , diff --git a/src/theme/Admonition/Type/Tip.js b/src/theme/Admonition/Type/Tip.js index bbe7de19..f31e4208 100644 --- a/src/theme/Admonition/Type/Tip.js +++ b/src/theme/Admonition/Type/Tip.js @@ -1,14 +1,8 @@ -/** - * 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 AdmonitionLayout from '../Layout'; -import IconTip from '@docusaurus/theme-classic/lib/theme/Admonition/Icon/Tip'; +import AdmonitionLayout from '@theme/Admonition/Layout'; +import IconTip from '@theme/Admonition/Icon/Tip'; const infimaClassName = 'alert alert--success'; const defaultProps = { icon: , diff --git a/src/theme/Admonition/Type/Warning.js b/src/theme/Admonition/Type/Warning.js index ac28ae39..b507d8d9 100644 --- a/src/theme/Admonition/Type/Warning.js +++ b/src/theme/Admonition/Type/Warning.js @@ -1,14 +1,8 @@ -/** - * 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 AdmonitionLayout from '../Layout'; -import IconWarning from '@docusaurus/theme-classic/lib/theme/Admonition/Icon/Warning'; +import AdmonitionLayout from '@theme/Admonition/Layout'; +import IconWarning from '@theme/Admonition/Icon/Warning'; const infimaClassName = 'alert alert--warning'; const defaultProps = { icon: , diff --git a/src/theme/Admonition/Types.js b/src/theme/Admonition/Types.js index d5f1f089..8d3197c5 100644 --- a/src/theme/Admonition/Types.js +++ b/src/theme/Admonition/Types.js @@ -1,16 +1,10 @@ -/** - * 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 AdmonitionTypeNote from './Type/Note'; -import AdmonitionTypeTip from './Type/Tip'; -import AdmonitionTypeInfo from './Type/Info'; -import AdmonitionTypeWarning from './Type/Warning'; -import AdmonitionTypeDanger from './Type/Danger'; -import AdmonitionTypeCaution from './Type/Caution'; +import AdmonitionTypeNote from '@theme/Admonition/Type/Note'; +import AdmonitionTypeTip from '@theme/Admonition/Type/Tip'; +import AdmonitionTypeInfo from '@theme/Admonition/Type/Info'; +import AdmonitionTypeWarning from '@theme/Admonition/Type/Warning'; +import AdmonitionTypeDanger from '@theme/Admonition/Type/Danger'; +import AdmonitionTypeCaution from '@theme/Admonition/Type/Caution'; const admonitionTypes = { note: AdmonitionTypeNote, tip: AdmonitionTypeTip, diff --git a/src/theme/Admonition/index.js b/src/theme/Admonition/index.js index c66baaea..a6ecab74 100644 --- a/src/theme/Admonition/index.js +++ b/src/theme/Admonition/index.js @@ -1,12 +1,6 @@ -/** - * 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 {processAdmonitionProps} from '@docusaurus/theme-common'; -import AdmonitionTypes from './Types'; +import AdmonitionTypes from '@theme/Admonition/Types'; function getAdmonitionTypeComponent(type) { const component = AdmonitionTypes[type]; if (component) { -- cgit v1.2.3-54-g00ecf