-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV-1546]: render blocks content (#773)
* feat(DEV-1546): render blocks content on the FE * chore: add changeset * feat(DEV-1546): add missing code * feat(DEV-1546): add subheadColor * feat(DEV-1546): add subheadColor * feat(DEV-1546): add missing subheadColor * Update apps/nextjs-website/src/components/molecules/BlocksRendererClient/BlocksRendererClient.tsx --------- Co-authored-by: Marco Ponchia <[email protected]>
- Loading branch information
1 parent
c0c2a65
commit b842990
Showing
10 changed files
with
462 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": patch | ||
--- | ||
|
||
Add BlocksRendererClient component to render the blocks content coming from Strapi |
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
3 changes: 3 additions & 0 deletions
3
apps/nextjs-website/src/components/atoms/CtaSlide/CtaSlide.tsx
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
47 changes: 47 additions & 0 deletions
47
apps/nextjs-website/src/components/molecules/BlocksRendererClient/BlocksRendererClient.tsx
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,47 @@ | ||
'use client'; | ||
|
||
import { Typography, useTheme } from '@mui/material'; | ||
import { BlocksContent, BlocksRenderer } from '@strapi/blocks-react-renderer'; | ||
import Image from 'next/image'; | ||
|
||
const BlocksRendererClient = ({ | ||
content, | ||
color, | ||
}: { | ||
readonly content?: BlocksContent; | ||
color?: 'contrastText' | 'main' | 'light' | 'dark'; | ||
}) => { | ||
const { palette } = useTheme(); | ||
|
||
if (!content) return null; | ||
|
||
const textColor = color ? palette.primary[color] : palette.text.primary; | ||
|
||
return ( | ||
<BlocksRenderer | ||
content={content} | ||
blocks={{ | ||
image: ({ image }) => ( | ||
<Image | ||
src={image.url} | ||
width={image.width} | ||
height={image.height} | ||
alt={image.alternativeText || ''} | ||
/> | ||
), | ||
paragraph: ({ children }) => ( | ||
<Typography variant='body1' color={textColor}> | ||
{children} | ||
</Typography> | ||
), | ||
heading: ({ children, level }) => ( | ||
<Typography variant={`h${level}`} color={textColor}> | ||
{children} | ||
</Typography> | ||
), | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default BlocksRendererClient; |
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
Oops, something went wrong.