@tdcerhverv/richtext v1.0.5
RichText
Render Rich Text from Contentful as HTML
This module uses @contentful/rich-text-react-renderer to take RichText from Contentful and render it as Material-UI components for use with TDC Erhverv's material-ui theme.
In the case of Headings, the semantic html and styles do not necessarily map directly. The following table gives an overview of the mapping of headings:
Component | HTML | Style | Notes |
---|---|---|---|
heading-1 | - | - | This component does not support h1 - there should only be one per page in the Hero Component |
heading-2 | <h2> | h5 | - |
heading-3 | <h3> | subtitle-1 | - |
heading-4 | <p> | body-1 | Heading level currently not supported, replaced with a paragraph |
heading-5 | <p> | body-1 | Heading level currently not supported, replaced with a paragraph |
heading-6 | <p> | body-1 | Heading level currently not supported, replaced with a paragraph |
Usage
The RichText
module is imported and used as follows
import RichText, { IRichText } from '@tdcerhverv/RichText'
This module takes props of type IRichText
, with the following implementation:
export interface IRichText {
raw: string
resources?: IRichTextResource[]
}
interface IRichTextResource {
title: string
description?: string
file?: IRichTextFileResource
}
interface IRichTextFileResource {
contentType: string
url: string
filename: string
}
It is important to note that the raw
prop must be able to be parsed to JSON for the componenet to work. The contents of this component should be provided via contentful, in which case it will be parsed with the correct structure. If for some reason you are using this module without data from Contentful (protip: don't use this module without data from Contentful) then this string, when parsed as JSON, should follow the structure outlined in Contentful's Rich Text documentation.