Skip to content

Commit 1b8f337

Browse files
authored
feat: added possibility to select visible views for diff-source wrapper element (#340)
1 parent 7d37182 commit 1b8f337

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/plugins/toolbar/components/DiffSourceToggleWrapper.tsx

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { iconComponentFor$, viewMode$ } from '../../core'
1+
import { iconComponentFor$, ViewMode, viewMode$ } from '../../core'
22
import { useCellValues, usePublisher } from '@mdxeditor/gurx'
33
import React from 'react'
44
import styles from '../../../styles/ui.module.css'
@@ -20,10 +20,29 @@ import { SingleChoiceToggleGroup } from '.././primitives/toolbar'
2020
*
2121
* @group Toolbar Components
2222
*/
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+
}) => {
2427
const [viewMode, iconComponentFor] = useCellValues(viewMode$, iconComponentFor$)
2528
const changeViewMode = usePublisher(viewMode$)
2629

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+
2746
return (
2847
<>
2948
{viewMode === 'rich-text' ? (
@@ -38,11 +57,7 @@ export const DiffSourceToggleWrapper: React.FC<{ children: React.ReactNode }> =
3857
<SingleChoiceToggleGroup
3958
className={styles.diffSourceToggle}
4059
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}
4661
onChange={(value) => changeViewMode(value || 'rich-text')}
4762
/>
4863
</div>

0 commit comments

Comments
 (0)