@docusaurus/theme-classic 0.0.0-5093 → 0.0.0-5094
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme/Admonition/index.js +56 -15
- package/package.json +14 -14
- package/src/theme/Admonition/index.tsx +62 -17
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
|
+
import {ThemeClassNames} from '@docusaurus/theme-common';
|
|
10
|
+
import Translate from '@docusaurus/Translate';
|
|
9
11
|
import styles from './styles.module.css';
|
|
10
12
|
function NoteIcon() {
|
|
11
13
|
return (
|
|
@@ -57,38 +59,75 @@ function CautionIcon() {
|
|
|
57
59
|
</svg>
|
|
58
60
|
);
|
|
59
61
|
}
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
|
|
60
63
|
const AdmonitionConfigs = {
|
|
61
64
|
note: {
|
|
62
65
|
infimaClassName: 'secondary',
|
|
63
66
|
iconComponent: NoteIcon,
|
|
67
|
+
label: (
|
|
68
|
+
<Translate
|
|
69
|
+
id="theme.admonition.note"
|
|
70
|
+
description="The default label used for the Note admonition (:::note)">
|
|
71
|
+
note
|
|
72
|
+
</Translate>
|
|
73
|
+
),
|
|
64
74
|
},
|
|
65
75
|
tip: {
|
|
66
76
|
infimaClassName: 'success',
|
|
67
77
|
iconComponent: TipIcon,
|
|
78
|
+
label: (
|
|
79
|
+
<Translate
|
|
80
|
+
id="theme.admonition.tip"
|
|
81
|
+
description="The default label used for the Tip admonition (:::tip)">
|
|
82
|
+
tip
|
|
83
|
+
</Translate>
|
|
84
|
+
),
|
|
68
85
|
},
|
|
69
86
|
danger: {
|
|
70
87
|
infimaClassName: 'danger',
|
|
71
88
|
iconComponent: DangerIcon,
|
|
89
|
+
label: (
|
|
90
|
+
<Translate
|
|
91
|
+
id="theme.admonition.danger"
|
|
92
|
+
description="The default label used for the Danger admonition (:::danger)">
|
|
93
|
+
danger
|
|
94
|
+
</Translate>
|
|
95
|
+
),
|
|
72
96
|
},
|
|
73
97
|
info: {
|
|
74
98
|
infimaClassName: 'info',
|
|
75
99
|
iconComponent: InfoIcon,
|
|
100
|
+
label: (
|
|
101
|
+
<Translate
|
|
102
|
+
id="theme.admonition.info"
|
|
103
|
+
description="The default label used for the Info admonition (:::info)">
|
|
104
|
+
info
|
|
105
|
+
</Translate>
|
|
106
|
+
),
|
|
76
107
|
},
|
|
77
108
|
caution: {
|
|
78
109
|
infimaClassName: 'warning',
|
|
79
110
|
iconComponent: CautionIcon,
|
|
111
|
+
label: (
|
|
112
|
+
<Translate
|
|
113
|
+
id="theme.admonition.caution"
|
|
114
|
+
description="The default label used for the Caution admonition (:::caution)">
|
|
115
|
+
caution
|
|
116
|
+
</Translate>
|
|
117
|
+
),
|
|
80
118
|
},
|
|
119
|
+
};
|
|
120
|
+
// Legacy aliases, undocumented but kept for retro-compatibility
|
|
121
|
+
const aliases = {
|
|
81
122
|
secondary: 'note',
|
|
82
123
|
important: 'info',
|
|
83
124
|
success: 'tip',
|
|
84
125
|
warning: 'danger',
|
|
85
126
|
};
|
|
86
|
-
function getAdmonitionConfig(
|
|
127
|
+
function getAdmonitionConfig(unsafeType) {
|
|
128
|
+
const type = aliases[unsafeType] ?? unsafeType;
|
|
87
129
|
const config = AdmonitionConfigs[type];
|
|
88
130
|
if (config) {
|
|
89
|
-
if (typeof config === 'string') {
|
|
90
|
-
return AdmonitionConfigs[config];
|
|
91
|
-
}
|
|
92
131
|
return config;
|
|
93
132
|
}
|
|
94
133
|
console.warn(
|
|
@@ -115,26 +154,28 @@ function processAdmonitionProps(props) {
|
|
|
115
154
|
const {mdxAdmonitionTitle, rest} = extractMDXAdmonitionTitle(props.children);
|
|
116
155
|
return {
|
|
117
156
|
...props,
|
|
118
|
-
title: props.title ?? mdxAdmonitionTitle
|
|
157
|
+
title: props.title ?? mdxAdmonitionTitle,
|
|
119
158
|
children: rest,
|
|
120
159
|
};
|
|
121
160
|
}
|
|
122
161
|
export default function Admonition(props) {
|
|
123
|
-
const {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
icon: iconProp,
|
|
128
|
-
} = processAdmonitionProps(props);
|
|
129
|
-
const config = getAdmonitionConfig(type);
|
|
130
|
-
const {infimaClassName, iconComponent: IconComponent} = config;
|
|
162
|
+
const {children, type, title, icon: iconProp} = processAdmonitionProps(props);
|
|
163
|
+
const typeConfig = getAdmonitionConfig(type);
|
|
164
|
+
const titleLabel = title ?? typeConfig.label;
|
|
165
|
+
const {iconComponent: IconComponent} = typeConfig;
|
|
131
166
|
const icon = iconProp ?? <IconComponent />;
|
|
132
167
|
return (
|
|
133
168
|
<div
|
|
134
|
-
className={clsx(
|
|
169
|
+
className={clsx(
|
|
170
|
+
ThemeClassNames.common.admonition,
|
|
171
|
+
ThemeClassNames.common.admonitionType(props.type),
|
|
172
|
+
'alert',
|
|
173
|
+
`alert--${typeConfig.infimaClassName}`,
|
|
174
|
+
styles.admonition,
|
|
175
|
+
)}>
|
|
135
176
|
<div className={styles.admonitionHeading}>
|
|
136
177
|
<span className={styles.admonitionIcon}>{icon}</span>
|
|
137
|
-
{
|
|
178
|
+
{titleLabel}
|
|
138
179
|
</div>
|
|
139
180
|
<div className={styles.admonitionContent}>{children}</div>
|
|
140
181
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5094",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@docusaurus/core": "0.0.0-
|
|
24
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
25
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
28
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
30
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
31
|
-
"@docusaurus/types": "0.0.0-
|
|
32
|
-
"@docusaurus/utils": "0.0.0-
|
|
33
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
34
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
23
|
+
"@docusaurus/core": "0.0.0-5094",
|
|
24
|
+
"@docusaurus/mdx-loader": "0.0.0-5094",
|
|
25
|
+
"@docusaurus/module-type-aliases": "0.0.0-5094",
|
|
26
|
+
"@docusaurus/plugin-content-blog": "0.0.0-5094",
|
|
27
|
+
"@docusaurus/plugin-content-docs": "0.0.0-5094",
|
|
28
|
+
"@docusaurus/plugin-content-pages": "0.0.0-5094",
|
|
29
|
+
"@docusaurus/theme-common": "0.0.0-5094",
|
|
30
|
+
"@docusaurus/theme-translations": "0.0.0-5094",
|
|
31
|
+
"@docusaurus/types": "0.0.0-5094",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-5094",
|
|
33
|
+
"@docusaurus/utils-common": "0.0.0-5094",
|
|
34
|
+
"@docusaurus/utils-validation": "0.0.0-5094",
|
|
35
35
|
"@mdx-js/react": "^1.6.22",
|
|
36
36
|
"clsx": "^1.1.1",
|
|
37
37
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=16.14"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "5ed0ed8f0a5918441c8b83093fd1975bfe7e0cfd"
|
|
68
68
|
}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import React, {type ReactNode} from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
|
+
import {ThemeClassNames} from '@docusaurus/theme-common';
|
|
11
|
+
import Translate from '@docusaurus/Translate';
|
|
10
12
|
import type {Props} from '@theme/Admonition';
|
|
11
13
|
|
|
12
14
|
import styles from './styles.module.css';
|
|
@@ -69,41 +71,82 @@ function CautionIcon() {
|
|
|
69
71
|
type AdmonitionConfig = {
|
|
70
72
|
iconComponent: React.ComponentType;
|
|
71
73
|
infimaClassName: string;
|
|
74
|
+
label: ReactNode;
|
|
72
75
|
};
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
|
|
78
|
+
const AdmonitionConfigs: Record<Props['type'], AdmonitionConfig> = {
|
|
75
79
|
note: {
|
|
76
80
|
infimaClassName: 'secondary',
|
|
77
81
|
iconComponent: NoteIcon,
|
|
82
|
+
label: (
|
|
83
|
+
<Translate
|
|
84
|
+
id="theme.admonition.note"
|
|
85
|
+
description="The default label used for the Note admonition (:::note)">
|
|
86
|
+
note
|
|
87
|
+
</Translate>
|
|
88
|
+
),
|
|
78
89
|
},
|
|
79
90
|
tip: {
|
|
80
91
|
infimaClassName: 'success',
|
|
81
92
|
iconComponent: TipIcon,
|
|
93
|
+
label: (
|
|
94
|
+
<Translate
|
|
95
|
+
id="theme.admonition.tip"
|
|
96
|
+
description="The default label used for the Tip admonition (:::tip)">
|
|
97
|
+
tip
|
|
98
|
+
</Translate>
|
|
99
|
+
),
|
|
82
100
|
},
|
|
83
101
|
danger: {
|
|
84
102
|
infimaClassName: 'danger',
|
|
85
103
|
iconComponent: DangerIcon,
|
|
104
|
+
label: (
|
|
105
|
+
<Translate
|
|
106
|
+
id="theme.admonition.danger"
|
|
107
|
+
description="The default label used for the Danger admonition (:::danger)">
|
|
108
|
+
danger
|
|
109
|
+
</Translate>
|
|
110
|
+
),
|
|
86
111
|
},
|
|
87
112
|
info: {
|
|
88
113
|
infimaClassName: 'info',
|
|
89
114
|
iconComponent: InfoIcon,
|
|
115
|
+
label: (
|
|
116
|
+
<Translate
|
|
117
|
+
id="theme.admonition.info"
|
|
118
|
+
description="The default label used for the Info admonition (:::info)">
|
|
119
|
+
info
|
|
120
|
+
</Translate>
|
|
121
|
+
),
|
|
90
122
|
},
|
|
91
123
|
caution: {
|
|
92
124
|
infimaClassName: 'warning',
|
|
93
125
|
iconComponent: CautionIcon,
|
|
126
|
+
label: (
|
|
127
|
+
<Translate
|
|
128
|
+
id="theme.admonition.caution"
|
|
129
|
+
description="The default label used for the Caution admonition (:::caution)">
|
|
130
|
+
caution
|
|
131
|
+
</Translate>
|
|
132
|
+
),
|
|
94
133
|
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// Legacy aliases, undocumented but kept for retro-compatibility
|
|
137
|
+
const aliases = {
|
|
95
138
|
secondary: 'note',
|
|
96
139
|
important: 'info',
|
|
97
140
|
success: 'tip',
|
|
98
141
|
warning: 'danger',
|
|
99
|
-
};
|
|
142
|
+
} as const;
|
|
100
143
|
|
|
101
|
-
function getAdmonitionConfig(
|
|
144
|
+
function getAdmonitionConfig(
|
|
145
|
+
unsafeType: Props['type'] | keyof typeof aliases,
|
|
146
|
+
): AdmonitionConfig {
|
|
147
|
+
const type = aliases[unsafeType as keyof typeof aliases] ?? unsafeType;
|
|
102
148
|
const config = AdmonitionConfigs[type];
|
|
103
149
|
if (config) {
|
|
104
|
-
if (typeof config === 'string') {
|
|
105
|
-
return AdmonitionConfigs[config] as AdmonitionConfig;
|
|
106
|
-
}
|
|
107
150
|
return config;
|
|
108
151
|
}
|
|
109
152
|
console.warn(
|
|
@@ -136,28 +179,30 @@ function processAdmonitionProps(props: Props): Props {
|
|
|
136
179
|
const {mdxAdmonitionTitle, rest} = extractMDXAdmonitionTitle(props.children);
|
|
137
180
|
return {
|
|
138
181
|
...props,
|
|
139
|
-
title: props.title ?? mdxAdmonitionTitle
|
|
182
|
+
title: props.title ?? mdxAdmonitionTitle,
|
|
140
183
|
children: rest,
|
|
141
184
|
};
|
|
142
185
|
}
|
|
143
186
|
|
|
144
187
|
export default function Admonition(props: Props): JSX.Element {
|
|
145
|
-
const {
|
|
146
|
-
children,
|
|
147
|
-
type,
|
|
148
|
-
title = type,
|
|
149
|
-
icon: iconProp,
|
|
150
|
-
} = processAdmonitionProps(props);
|
|
188
|
+
const {children, type, title, icon: iconProp} = processAdmonitionProps(props);
|
|
151
189
|
|
|
152
|
-
const
|
|
153
|
-
const
|
|
190
|
+
const typeConfig = getAdmonitionConfig(type);
|
|
191
|
+
const titleLabel = title ?? typeConfig.label;
|
|
192
|
+
const {iconComponent: IconComponent} = typeConfig;
|
|
154
193
|
const icon = iconProp ?? <IconComponent />;
|
|
155
194
|
return (
|
|
156
195
|
<div
|
|
157
|
-
className={clsx(
|
|
196
|
+
className={clsx(
|
|
197
|
+
ThemeClassNames.common.admonition,
|
|
198
|
+
ThemeClassNames.common.admonitionType(props.type),
|
|
199
|
+
'alert',
|
|
200
|
+
`alert--${typeConfig.infimaClassName}`,
|
|
201
|
+
styles.admonition,
|
|
202
|
+
)}>
|
|
158
203
|
<div className={styles.admonitionHeading}>
|
|
159
204
|
<span className={styles.admonitionIcon}>{icon}</span>
|
|
160
|
-
{
|
|
205
|
+
{titleLabel}
|
|
161
206
|
</div>
|
|
162
207
|
<div className={styles.admonitionContent}>{children}</div>
|
|
163
208
|
</div>
|