1
- import { iconComponentFor$ , viewMode$ } from '../../core'
1
+ import { iconComponentFor$ , ViewMode , viewMode$ } from '../../core'
2
2
import { useCellValues , usePublisher } from '@mdxeditor/gurx'
3
3
import React from 'react'
4
4
import styles from '../../../styles/ui.module.css'
@@ -20,10 +20,29 @@ import { SingleChoiceToggleGroup } from '.././primitives/toolbar'
20
20
*
21
21
* @group Toolbar Components
22
22
*/
23
- export const DiffSourceToggleWrapper : React . FC < { children : React . ReactNode } > = ( { children } ) => {
23
+ export const DiffSourceToggleWrapper : React . FC < { children : React . ReactNode ; options ?: ViewMode [ ] } > = ( {
24
+ children,
25
+ options = [ 'rich-text' , 'diff' , 'source' ]
26
+ } ) => {
24
27
const [ viewMode , iconComponentFor ] = useCellValues ( viewMode$ , iconComponentFor$ )
25
28
const changeViewMode = usePublisher ( viewMode$ )
26
29
30
+ const toggleGroupItems : {
31
+ title : string
32
+ contents : React . ReactNode
33
+ value : ViewMode
34
+ } [ ] = [ ]
35
+
36
+ if ( options . includes ( 'rich-text' ) ) {
37
+ toggleGroupItems . push ( { title : 'Rich text' , contents : iconComponentFor ( 'rich_text' ) , value : 'rich-text' } )
38
+ }
39
+ if ( options . includes ( 'diff' ) ) {
40
+ toggleGroupItems . push ( { title : 'Diff mode' , contents : iconComponentFor ( 'difference' ) , value : 'diff' } )
41
+ }
42
+ if ( options . includes ( 'source' ) ) {
43
+ toggleGroupItems . push ( { title : 'Source' , contents : iconComponentFor ( 'markdown' ) , value : 'source' } )
44
+ }
45
+
27
46
return (
28
47
< >
29
48
{ viewMode === 'rich-text' ? (
@@ -38,11 +57,7 @@ export const DiffSourceToggleWrapper: React.FC<{ children: React.ReactNode }> =
38
57
< SingleChoiceToggleGroup
39
58
className = { styles . diffSourceToggle }
40
59
value = { viewMode }
41
- items = { [
42
- { title : 'Rich text' , contents : iconComponentFor ( 'rich_text' ) , value : 'rich-text' } ,
43
- { title : 'Diff mode' , contents : iconComponentFor ( 'difference' ) , value : 'diff' } ,
44
- { title : 'Source' , contents : iconComponentFor ( 'markdown' ) , value : 'source' }
45
- ] }
60
+ items = { toggleGroupItems }
46
61
onChange = { ( value ) => changeViewMode ( value || 'rich-text' ) }
47
62
/>
48
63
</ div >
0 commit comments