Skip to content

Commit

Permalink
fix(react-renderer): add support for emoji callouts (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
whawker committed Aug 17, 2021
1 parent f305571 commit 18c101a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-planets-perform.md
@@ -0,0 +1,5 @@
---
'@remirror/react-renderer': patch
---

Add support for callouts with emojis to the react-renderer
36 changes: 35 additions & 1 deletion packages/remirror__react-renderer/__tests__/callout.spec.tsx
Expand Up @@ -21,7 +21,41 @@ describe('Callout', () => {

expect(container.innerHTML).toMatchInlineSnapshot(`
<div data-callout-type="info">
Important
<div>
Important
</div>
</div>
`);
});

it('renders callout with an emoji to HTML', () => {
const json: RemirrorJSON = {
type: 'callout',
attrs: {
type: 'info',
emoji: 'ℹ️',
},
content: [
{
type: 'text',
text: 'Important',
},
],
};
const { container } = strictRender(<Callout node={json} markMap={{}} />);

expect(container.innerHTML).toMatchInlineSnapshot(`
<div data-callout-type="info"
data-callout-emoji="ℹ️"
>
<div class="remirror-callout-emoji-wrapper">
<span>
ℹ️
</span>
</div>
<div>
Important
</div>
</div>
`);
});
Expand Down
18 changes: 16 additions & 2 deletions packages/remirror__react-renderer/src/handlers/callout.tsx
Expand Up @@ -18,7 +18,21 @@ export const Callout: FC<{
return <RemirrorRenderer json={node} key={ii} {...props} />;
});

const calloutType = props.node.attrs?.type;
const { type, emoji } = props.node.attrs ?? {};
const dataAttrs: Record<string, unknown> = { 'data-callout-type': type };

return <div data-callout-type={calloutType}>{children}</div>;
if (emoji) {
dataAttrs['data-callout-emoji'] = emoji;
}

return (
<div {...dataAttrs}>
{emoji && (
<div className='remirror-callout-emoji-wrapper'>
<span>{emoji as string}</span>
</div>
)}
<div>{children}</div>
</div>
);
};

1 comment on commit 18c101a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://remirror.io as production
🚀 Deployed on https://611c05a052b74914e5d43a9f--remirror.netlify.app

Please sign in to comment.