Skip to content

Commit c5c80fc

Browse files
committed
chore: update
1 parent e3e28cf commit c5c80fc

File tree

6 files changed

+61
-31
lines changed

6 files changed

+61
-31
lines changed

packages/core/src/node/mdx/remarkPlugins/containerSyntax.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,40 +77,21 @@ const createContainer = (
7777
title: string | undefined,
7878
children: (BlockContent | PhrasingContent)[],
7979
): ContainerDirective => {
80-
const isDetails = type === 'details';
81-
82-
const rootHName = isDetails ? 'details' : 'div';
83-
const titleHName = isDetails ? 'summary' : 'div';
84-
8580
return {
8681
type: 'containerDirective',
87-
name: type,
82+
name: 'Callout',
83+
attributes: {
84+
type: type,
85+
title: title || getTypeName(type),
86+
},
8887
data: {
89-
hName: rootHName,
88+
hName: 'Callout',
9089
hProperties: {
91-
class: `rspress-directive ${type}`,
90+
type: type,
91+
title: title || getTypeName(type),
9292
},
9393
},
94-
children: [
95-
{
96-
type: 'paragraph',
97-
data: {
98-
hName: titleHName,
99-
hProperties: {
100-
class: 'rspress-directive-title',
101-
},
102-
},
103-
children: [{ type: 'text', value: title || getTypeName(type) }],
104-
},
105-
{
106-
type: 'paragraph',
107-
data: {
108-
hName: 'div',
109-
hProperties: { class: 'rspress-directive-content' },
110-
},
111-
children: children as PhrasingContent[],
112-
},
113-
],
94+
children: children as BlockContent[],
11495
};
11596
};
11697

packages/theme-default/src/styles/container.scss renamed to packages/theme-default/src/components/Callout/index.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@
242242
}
243243

244244
&:where(details) {
245-
margin: 16px 0;
246-
padding: 8px;
247245
font-size: normal;
248246
cursor: pointer;
249247
transition: all 0.3s;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { ReactNode } from 'react';
2+
import './index.scss';
3+
4+
export interface CalloutProps {
5+
type: 'tip' | 'note' | 'warning' | 'caution' | 'danger' | 'info' | 'details';
6+
title?: string;
7+
children: ReactNode;
8+
}
9+
10+
/**
11+
* Construct the DOM structure of the container directive.
12+
* For example:
13+
*
14+
* ::: tip {title="foo"}
15+
* This is a tip
16+
* :::
17+
*
18+
* will be transformed to:
19+
*
20+
* <div class="rspress-directive tip">
21+
* <div class="rspress-directive-title">Tip</div>
22+
* <div class="rspress-directive-content">
23+
* <p>This is a tip</p>
24+
* </div>
25+
* </div>
26+
*/
27+
export function Callout({ type, title, children }: CalloutProps) {
28+
const isDetails = type === 'details';
29+
30+
if (isDetails) {
31+
return (
32+
<details className={`rspress-directive ${type}`}>
33+
<summary className="rspress-directive-title">{title}</summary>
34+
<div className="rspress-directive-content">{children}</div>
35+
</details>
36+
);
37+
}
38+
39+
return (
40+
<div className={`rspress-directive ${type}`}>
41+
<div className="rspress-directive-title">{title}</div>
42+
<div className="rspress-directive-content">{children}</div>
43+
</div>
44+
);
45+
}
46+
47+
export default Callout;

packages/theme-default/src/components/DocContent/docComponents/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Callout } from '@theme';
12
import { A } from './a';
23
import { Code } from './codeblock/code';
34
import { PreWithCodeButtonGroup } from './codeblock/pre';
@@ -31,5 +32,8 @@ export function getCustomMDXComponent() {
3132
code: Code,
3233
pre: PreWithCodeButtonGroup,
3334
img: Img,
35+
36+
// custom components can be added here
37+
Callout,
3438
};
3539
}

packages/theme-default/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export { Aside } from './components/Aside/index';
33
export { Badge } from './components/Badge/index';
44
export { Button } from './components/Button/index';
5+
export { Callout, type CalloutProps } from './components/Callout/index';
56
export {
67
CodeBlockRuntime,
78
type CodeBlockRuntimeProps,

packages/theme-default/src/styles/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ import './tailwind.css';
1010
import './code.scss';
1111
import './scrollbar.scss';
1212
import './shiki.scss';
13-
import './container.scss';
1413
import 'nprogress/nprogress.css';

0 commit comments

Comments
 (0)