Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to select available views for diffSourcePlugin #340

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/plugins/toolbar/components/DiffSourceToggleWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { iconComponentFor$, viewMode$ } from '../../core'
import { iconComponentFor$, ViewMode, viewMode$ } from '../../core'
import { useCellValues, usePublisher } from '@mdxeditor/gurx'
import React from 'react'
import styles from '../../../styles/ui.module.css'
Expand All @@ -20,10 +20,29 @@ import { SingleChoiceToggleGroup } from '.././primitives/toolbar'
*
* @group Toolbar Components
*/
export const DiffSourceToggleWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => {
export const DiffSourceToggleWrapper: React.FC<{ children: React.ReactNode; options?: ViewMode[] }> = ({
children,
options = ['rich-text', 'diff', 'source']
}) => {
const [viewMode, iconComponentFor] = useCellValues(viewMode$, iconComponentFor$)
const changeViewMode = usePublisher(viewMode$)

const toggleGroupItems: {
title: string
contents: React.ReactNode
value: ViewMode
}[] = []

if (options.includes('rich-text')) {
toggleGroupItems.push({ title: 'Rich text', contents: iconComponentFor('rich_text'), value: 'rich-text' })
}
if (options.includes('diff')) {
toggleGroupItems.push({ title: 'Diff mode', contents: iconComponentFor('difference'), value: 'diff' })
}
if (options.includes('source')) {
toggleGroupItems.push({ title: 'Source', contents: iconComponentFor('markdown'), value: 'source' })
}

return (
<>
{viewMode === 'rich-text' ? (
Expand All @@ -38,11 +57,7 @@ export const DiffSourceToggleWrapper: React.FC<{ children: React.ReactNode }> =
<SingleChoiceToggleGroup
className={styles.diffSourceToggle}
value={viewMode}
items={[
{ title: 'Rich text', contents: iconComponentFor('rich_text'), value: 'rich-text' },
{ title: 'Diff mode', contents: iconComponentFor('difference'), value: 'diff' },
{ title: 'Source', contents: iconComponentFor('markdown'), value: 'source' }
]}
items={toggleGroupItems}
onChange={(value) => changeViewMode(value || 'rich-text')}
/>
</div>
Expand Down