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
"@material-ui/core": "4.9.2", | |
"@material-ui/icons": "4.9.1", | |
"@material-ui/lab": "4.0.0-alpha.42", | |
"@types/draft-js": "0.10.38", | |
"draft-js": "0.11.4", | |
"draft-js-plugins-utils": "2.0.3", |
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
import * as React from "react"; | |
import { EditorState } from "draft-js"; | |
export const EditorContext = React.createContext<EditorState>( | |
EditorState.createEmpty() | |
); |
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
<Box onClick={focusEditor} p={4}> | |
<EditorContext.Provider value={editorState}> | |
<Editor | |
editorState={editorState} | |
onChange={setEditorState} | |
placeholder="Click here to start typing in the editor..." | |
blockRendererFn={renderBlock} | |
ref={editor} | |
/> | |
</EditorContext.Provider> |
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
import * as React from "react"; | |
import { EditorContext } from "./EditorContext"; | |
import { | |
Box, | |
Paper, | |
TextField, | |
InputAdornment, | |
IconButton | |
} from "@material-ui/core"; | |
import { ToggleButtonGroup, ToggleButton } from "@material-ui/lab"; |
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
const editor = React.useRef<Editor>(null); | |
const [editorState, setEditorState] = React.useState<EditorState>( | |
EditorState.createEmpty( | |
new CompositeDecorator([ | |
{ | |
strategy: linkStrategy, | |
component: DecoratedLink | |
} | |
]) |
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
<input | |
id="fileInput" | |
style={{ display: "none" }} | |
type="file" | |
accept="image/png,image/jpeg,image/jpg,image/gif" | |
onChange={event => { | |
const reader = new FileReader(); | |
reader.addEventListener( | |
"load", | |
function() { |
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
const renderBlock = (contentBlock: ContentBlock) => { | |
if (contentBlock.getType() === "atomic") { | |
const entityKey = contentBlock.getEntityAt(0); | |
const entityData = editorState | |
.getCurrentContent() | |
.getEntity(entityKey) | |
.getData(); | |
return { | |
component: MediaComponent, | |
editable: false, |
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
import * as React from "react"; | |
//eslint-disable-next-line | |
export const MediaComponent = ({ blockProps }: any) => { | |
const src = blockProps.src; | |
if (src.file) { | |
return ( | |
<img | |
style={{ | |
width: "100%" | |
}} |
OlderNewer