-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV-13006] Implement renderer for Callout node
- Loading branch information
Showing
6 changed files
with
111 additions
and
0 deletions.
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
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,33 @@ | ||
@import "styles/variables"; | ||
|
||
.prezly-slate-callout { | ||
display: flex; | ||
flex-direction: row; | ||
|
||
padding: $spacing-3; | ||
gap: $spacing-1-5; | ||
|
||
background: rgba($color-link, 0.08); | ||
border: 1px solid rgba($color-link, 0.60); | ||
border-radius: $spacing-half; | ||
|
||
&[data-icon]::before { | ||
content: attr(data-icon); | ||
display: block; | ||
} | ||
|
||
&--align-left { | ||
text-align: left; | ||
flex-direction: row; | ||
} | ||
|
||
&--align-center { | ||
text-align: center; | ||
flex-direction: column; | ||
} | ||
|
||
&--align-right { | ||
text-align: right; | ||
flex-direction: row-reverse; | ||
} | ||
} |
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,40 @@ | ||
import type { Meta, Story } from '@storybook/react'; | ||
|
||
import { StoryNameDecorator } from '../../dev/StoryNameDecorator'; | ||
import { Renderer } from '../../Renderer'; | ||
|
||
export default { | ||
title: 'Elements/Quote', | ||
decorators: [StoryNameDecorator], | ||
} as Meta; | ||
|
||
export const BlockQuote: Story = () => ( | ||
<Renderer | ||
nodes={[ | ||
{ | ||
type: 'block-quote', | ||
children: [ | ||
{ | ||
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.', | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
); | ||
|
||
export const Alignment: Story = () => ( | ||
<Renderer | ||
nodes={[ | ||
{ | ||
type: 'block-quote', | ||
align: 'center', | ||
children: [ | ||
{ | ||
text: 'Same goes for blockquotes', | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
); |
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,34 @@ | ||
import { CalloutNode } from '@prezly/story-content-format'; | ||
import classNames from 'classnames'; | ||
import type { HTMLAttributes } from 'react'; | ||
|
||
import { stringifyNode } from '../../lib'; | ||
|
||
import './Callout.scss'; | ||
|
||
interface Props extends HTMLAttributes<HTMLDivElement> { | ||
node: CalloutNode; | ||
} | ||
|
||
export function Callout({ children, className, node, ...props }: Props) { | ||
const isEmpty = stringifyNode(node).trim() === ''; | ||
|
||
if (isEmpty) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className={classNames('prezly-slate-callout', className, { | ||
'prezly-slate-callout--align-inherit': node.align === undefined, | ||
'prezly-slate-callout--align-left': node.align === CalloutNode.Alignment.LEFT, | ||
'prezly-slate-callout--align-center': node.align === CalloutNode.Alignment.CENTER, | ||
'prezly-slate-callout--align-right': node.align === CalloutNode.Alignment.RIGHT, | ||
})} | ||
data-icon={node.icon || undefined} | ||
{...props} | ||
> | ||
<p>{children}</p> | ||
</div> | ||
); | ||
} |
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 @@ | ||
export { Callout } from './Callout'; |
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