Skip to main content

Social Editor

The <SocialEditor> provides a state of the art editor with mention and tag support.

import { SocialEditor } from '@remirror/react-editors/social';
Source code
import React, { useCallback } from 'react';
import { useHelpers, useRemirrorContext } from '@remirror/react';
import { SocialEditor } from '@remirror/react-editors/social';

const ALL_USERS = [
{ id: 'joe', label: 'Joe' },
{ id: 'sue', label: 'Sue' },
{ id: 'pat', label: 'Pat' },
{ id: 'tom', label: 'Tom' },
{ id: 'jim', label: 'Jim' },
];

const TAGS = ['editor', 'remirror', 'opensource', 'prosemirror'];

const SAMPLE_DOC = {
type: 'doc',
content: [
{
type: 'paragraph',
attrs: { dir: null, ignoreBidiAutoUpdate: null },
content: [{ type: 'text', text: 'Loaded content' }],
},
],
};

function LoadButton() {
const { setContent } = useRemirrorContext();
const handleClick = useCallback(() => setContent(SAMPLE_DOC), [setContent]);

return (
<button onMouseDown={(event) => event.preventDefault()} onClick={handleClick}>
Load
</button>
);
}

function SaveButton() {
const { getJSON } = useHelpers();
const handleClick = useCallback(() => alert(JSON.stringify(getJSON())), [getJSON]);

return (
<button onMouseDown={(event) => event.preventDefault()} onClick={handleClick}>
Save
</button>
);
}

const Basic: React.FC = () => (
<SocialEditor placeholder='Mention @joe or add #remirror' users={ALL_USERS} tags={TAGS}>
<LoadButton />
<SaveButton />
</SocialEditor>
);

export default Basic;

Find many more examples on Storybook.

note

Want to customize the behavior? Simply copy the <SocialEditor> code and change the extensions. That's what Remirror was built for.