Skip to content

Commit 06ca98c

Browse files
committed
[DEV-13006] Implement renderer for Callout node
1 parent 3f5003c commit 06ca98c

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

src/Renderer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AttachmentNode,
44
BookmarkNode,
55
ButtonBlockNode,
6+
CalloutNode,
67
ContactNode,
78
DividerNode,
89
DocumentNode,
@@ -69,6 +70,7 @@ export function Renderer<N extends Node | Node[]>({
6970
component={Elements.ButtonBlock}
7071
/>
7172
<Component match={BookmarkNode.isBookmarkNode} component={Elements.Bookmark} />
73+
<Component match={CalloutNode.isCalloutNode} component={Elements.Callout} />
7274
<Component match={ContactNode.isContactNode} component={Elements.Contact} />
7375
<Component match={DividerNode.isDividerNode} component={Elements.Divider} />
7476
<Component match={DocumentNode.isDocumentNode} component={Elements.Document} />

src/elements/Callout/Callout.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@import "styles/variables";
2+
3+
.prezly-slate-callout {
4+
display: flex;
5+
flex-direction: row;
6+
7+
padding: $spacing-3;
8+
gap: $spacing-1-5;
9+
10+
background: rgba($color-link, 0.08);
11+
border: 1px solid rgba($color-link, 0.60);
12+
border-radius: $spacing-half;
13+
14+
&[data-icon]::before {
15+
content: attr(data-icon);
16+
display: block;
17+
}
18+
19+
&--align-left {
20+
text-align: left;
21+
flex-direction: row;
22+
}
23+
24+
&--align-center {
25+
text-align: center;
26+
flex-direction: column;
27+
}
28+
29+
&--align-right {
30+
text-align: right;
31+
flex-direction: row-reverse;
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { Meta, Story } from '@storybook/react';
2+
3+
import { StoryNameDecorator } from '../../dev/StoryNameDecorator';
4+
import { Renderer } from '../../Renderer';
5+
6+
export default {
7+
title: 'Elements/Quote',
8+
decorators: [StoryNameDecorator],
9+
} as Meta;
10+
11+
export const BlockQuote: Story = () => (
12+
<Renderer
13+
nodes={[
14+
{
15+
type: 'block-quote',
16+
children: [
17+
{
18+
text: 'I love how Prezly has been created by people who really understand the needs of PR professionals. Its features and functionality are just right for our business.',
19+
},
20+
],
21+
},
22+
]}
23+
/>
24+
);
25+
26+
export const Alignment: Story = () => (
27+
<Renderer
28+
nodes={[
29+
{
30+
type: 'block-quote',
31+
align: 'center',
32+
children: [
33+
{
34+
text: 'Same goes for blockquotes',
35+
},
36+
],
37+
},
38+
]}
39+
/>
40+
);

src/elements/Callout/Callout.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { CalloutNode } from '@prezly/story-content-format';
2+
import classNames from 'classnames';
3+
import type { HTMLAttributes } from 'react';
4+
5+
import { stringifyNode } from '../../lib';
6+
7+
import './Callout.scss';
8+
9+
interface Props extends HTMLAttributes<HTMLDivElement> {
10+
node: CalloutNode;
11+
}
12+
13+
export function Callout({ children, className, node, ...props }: Props) {
14+
const isEmpty = stringifyNode(node).trim() === '';
15+
16+
if (isEmpty) {
17+
return null;
18+
}
19+
20+
return (
21+
<div
22+
className={classNames('prezly-slate-callout', className, {
23+
'prezly-slate-callout--align-inherit': node.align === undefined,
24+
'prezly-slate-callout--align-left': node.align === CalloutNode.Alignment.LEFT,
25+
'prezly-slate-callout--align-center': node.align === CalloutNode.Alignment.CENTER,
26+
'prezly-slate-callout--align-right': node.align === CalloutNode.Alignment.RIGHT,
27+
})}
28+
data-icon={node.icon || undefined}
29+
{...props}
30+
>
31+
<p>{children}</p>
32+
</div>
33+
);
34+
}

src/elements/Callout/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Callout } from './Callout';

src/elements/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { Passthru } from './Passthru';
66
export { Attachment } from './Attachment';
77
export { Bookmark } from './Bookmark';
88
export { ButtonBlock } from './ButtonBlock';
9+
export { Callout } from './Callout';
910
export { Contact } from './Contact';
1011
export { Divider } from './Divider';
1112
export { Embed } from './Embed';

0 commit comments

Comments
 (0)