File tree Expand file tree Collapse file tree 6 files changed +61
-31
lines changed Expand file tree Collapse file tree 6 files changed +61
-31
lines changed Original file line number Diff line number Diff line change @@ -77,40 +77,21 @@ const createContainer = (
77
77
title : string | undefined ,
78
78
children : ( BlockContent | PhrasingContent ) [ ] ,
79
79
) : ContainerDirective => {
80
- const isDetails = type === 'details' ;
81
-
82
- const rootHName = isDetails ? 'details' : 'div' ;
83
- const titleHName = isDetails ? 'summary' : 'div' ;
84
-
85
80
return {
86
81
type : 'containerDirective' ,
87
- name : type ,
82
+ name : 'Callout' ,
83
+ attributes : {
84
+ type : type ,
85
+ title : title || getTypeName ( type ) ,
86
+ } ,
88
87
data : {
89
- hName : rootHName ,
88
+ hName : 'Callout' ,
90
89
hProperties : {
91
- class : `rspress-directive ${ type } ` ,
90
+ type : type ,
91
+ title : title || getTypeName ( type ) ,
92
92
} ,
93
93
} ,
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 [ ] ,
114
95
} ;
115
96
} ;
116
97
Original file line number Diff line number Diff line change 242
242
}
243
243
244
244
& :where(details ) {
245
- margin : 16px 0 ;
246
- padding : 8px ;
247
245
font-size : normal ;
248
246
cursor : pointer ;
249
247
transition : all 0.3s ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
1
+ import { Callout } from '@theme' ;
1
2
import { A } from './a' ;
2
3
import { Code } from './codeblock/code' ;
3
4
import { PreWithCodeButtonGroup } from './codeblock/pre' ;
@@ -31,5 +32,8 @@ export function getCustomMDXComponent() {
31
32
code : Code ,
32
33
pre : PreWithCodeButtonGroup ,
33
34
img : Img ,
35
+
36
+ // custom components can be added here
37
+ Callout,
34
38
} ;
35
39
}
Original file line number Diff line number Diff line change 2
2
export { Aside } from './components/Aside/index' ;
3
3
export { Badge } from './components/Badge/index' ;
4
4
export { Button } from './components/Button/index' ;
5
+ export { Callout , type CalloutProps } from './components/Callout/index' ;
5
6
export {
6
7
CodeBlockRuntime ,
7
8
type CodeBlockRuntimeProps ,
Original file line number Diff line number Diff line change @@ -10,5 +10,4 @@ import './tailwind.css';
10
10
import './code.scss' ;
11
11
import './scrollbar.scss' ;
12
12
import './shiki.scss' ;
13
- import './container.scss' ;
14
13
import 'nprogress/nprogress.css' ;
You can’t perform that action at this time.
0 commit comments