rsnext/examples/cms-dotcms/components/content-blocks.tsx
Freddy Montes 15cc88909c
chore(examples): Add dotCMS example (#38214)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order to make sure your PR is handled as smoothly as possible we
request that you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

This adds a new example under cms-dotcms/. Is a general-purpose example
that should allow developers to undestand how to use next.js with dotCMS
apis.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: Daniel Esteves <estevesd8@gmail.com>
Co-authored-by: Will Ezell <will@dotcms.com>
Co-authored-by: Arcadio Quintero A <oidacra@gmail.com>
Co-authored-by: Rafael <rjvelazco21@gmail.com>
2022-10-01 15:26:13 +02:00

90 lines
2.2 KiB
TypeScript

import {
BlockQuote,
BulletList,
CodeBlock,
DotImage,
Heading,
ListItem,
OrderedList,
Paragraph,
TextNode,
} from './blocks'
/*
dotCMS Block Editor is a new rich content editor that allows you to create your content as building blocks.
More info: https://dotcms.com/docs/latest/block-editor
*/
export const ContentBlocks = ({ content }) => {
return (
<>
{content?.map((data, index) => {
switch (data.type) {
case 'paragraph':
return (
<Paragraph key={index}>
<ContentBlocks content={data.content} />
</Paragraph>
)
case 'heading':
return (
<Heading key={index} level={data.attrs.level}>
<ContentBlocks content={data.content} />
</Heading>
)
case 'bulletList':
return (
<BulletList key={index}>
<ContentBlocks content={data.content} />
</BulletList>
)
case 'orderedList':
return (
<OrderedList key={index}>
<ContentBlocks content={data.content} />
</OrderedList>
)
case 'dotImage':
return <DotImage key={index} {...data} />
case 'horizontalRule':
return <hr key={index} />
case 'blockquote':
return (
<BlockQuote key={index}>
<ContentBlocks content={data.content} />
</BlockQuote>
)
case 'codeBlock':
return (
<CodeBlock language={data.attrs.language} key={index}>
<ContentBlocks content={data.content} />
</CodeBlock>
)
case 'hardBreak':
return <br key={index} />
case 'text':
return <TextNode key={index} {...data} />
case 'listItem':
return (
<ListItem key={index}>
<ContentBlocks content={data.content} />
</ListItem>
)
default:
return <p>Block not supported</p>
}
})}
</>
)
}