Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sometimes slate does not proper update
also introdces a language switch example that sometimes showed the issue when the lang was changed "outside"
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState } from 'react'; | ||
import type { Options, Value } from '@react-page/editor'; | ||
import Editor from '@react-page/editor'; | ||
import slate from '@react-page/plugins-slate'; | ||
import image from '@react-page/plugins-image'; | ||
import { ExampleCustomBottomToolbar } from '../../components/ExampleCustomBottomToolbar'; | ||
import { Button } from '@mui/material'; | ||
import customContentPlugin from '../../plugins/customContentPlugin'; | ||
|
||
const cellPlugins = [slate(), image, customContentPlugin]; | ||
|
||
const LANGUAGES = [ | ||
{ | ||
lang: 'en', | ||
label: 'English', | ||
}, | ||
{ | ||
lang: 'de', | ||
label: 'Deutsch', | ||
}, | ||
]; | ||
|
||
// Custom bottom toolbar example with collapse/restore functionality. | ||
const languageSwitchExample = () => { | ||
const [lang, setLang] = React.useState<string>('en'); | ||
const [value, setValue] = useState<Value>(); | ||
|
||
return ( | ||
<> | ||
<select value={lang} onChange={(v) => setLang(v.target.value)}> | ||
{LANGUAGES.map((l) => ( | ||
<option key={l.lang} value={l.lang}> | ||
{l.label} | ||
</option> | ||
))} | ||
</select> | ||
<Editor | ||
languages={LANGUAGES} | ||
cellPlugins={cellPlugins} | ||
value={value} | ||
onChange={setValue} | ||
lang={lang} | ||
onChangeLang={(l) => { | ||
setLang(l); | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default languageSwitchExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters