Skip to content

Commit 812731d

Browse files
authored
Merge pull request #4062 from appirio-tech/feature/fix_link_formatting_for_contentful_text
fixed issue with link type text's formatting.
2 parents ad51085 + 45413bc commit 812731d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/components/FAQ/FAQItem.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cn from 'classnames'
33
import { documentToReactComponents } from '@contentful/rich-text-react-renderer'
44
import IconX from ' ../../assets/icons/ui-x-mark.svg'
55
import IconCarretDown from '../../assets/icons/arrow-6px-carret-down-normal.svg'
6+
import { CONTENTFUL_NODE_TYPES } from '../../config/constants'
67
import './FAQItem.scss'
78

89

@@ -25,6 +26,13 @@ class FAQItem extends Component {
2526
render() {
2627
const {item} = this.props
2728
const {isOpen} = this.state
29+
30+
const FormattedHyperLink = ({ value, url }) => <a href={url} target="_blank" className="hyperlink-style">{value}</a>
31+
const options = {
32+
renderNode: {/* eslint-disable no-unused-vars*/
33+
[CONTENTFUL_NODE_TYPES.HYPERLINK]: (node, children) => <FormattedHyperLink value={node.content[0].value} url={node.data.uri}/>
34+
}
35+
}
2836
return (
2937
<div styleName={cn('accordion', { 'is-open': isOpen })}>
3038
<div styleName="header" onClick={this.toggle}>
@@ -33,7 +41,7 @@ class FAQItem extends Component {
3341
{isOpen ? <IconX styleName="toggle-icon" /> : <IconCarretDown styleName="toggle-icon" />}
3442
</div>
3543
</div>
36-
<div styleName="content">{documentToReactComponents(item.fields.answer)}</div>
44+
<div styleName="content">{documentToReactComponents(item.fields.answer, options)}</div>
3745
</div>
3846
)
3947
}

src/components/FAQ/FAQItem.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
line-height: 20px;
6363
text-align: left;
6464
margin-bottom: 2 * $base-unit;
65+
66+
a {
67+
cursor: pointer;
68+
color: $tc-dark-blue;
69+
&:hover {
70+
text-decoration: underline;
71+
}
72+
}
6573
}
6674

6775
.accordion.is-open .content {

src/config/constants.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,4 +992,12 @@ export const REPORT_SESSION_LENGTH = 25 * 60 // 25 minutes (5 minutes less than
992992
*/
993993
export const DASHBOARD_FAQ_CONTENT_ID = process.env.DASHBOARD_FAQ_CONTENT_ID
994994
export const CONTENTFUL_DELIVERY_KEY = process.env.CONTENTFUL_DELIVERY_KEY
995-
export const CONTENTFUL_SPACE_ID = process.env.CONTENTFUL_SPACE_ID
995+
export const CONTENTFUL_SPACE_ID = process.env.CONTENTFUL_SPACE_ID
996+
997+
998+
/**
999+
* Contentful node types
1000+
*/
1001+
export const CONTENTFUL_NODE_TYPES = {
1002+
HYPERLINK : 'hyperlink',
1003+
}

0 commit comments

Comments
 (0)