-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2546 from bcgov/feature/DESENG-633-survey-block
[To Main] DESENG 633: Engagement Survey Block
- Loading branch information
Showing
20 changed files
with
871 additions
and
436 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,60 @@ | ||
import React from 'react'; | ||
import { ContentBlock, ContentState, Editor, EditorProps } from 'react-draft-wysiwyg'; | ||
import { Link } from '../Navigation'; | ||
import { Header2 } from '../Typography'; | ||
|
||
const LinkRenderer = ({ | ||
children, | ||
contentState, | ||
entityKey, | ||
}: { | ||
children: React.ReactNode; | ||
contentState: ContentState; | ||
entityKey: string; | ||
}) => { | ||
const { url } = contentState.getEntity(entityKey).getData(); | ||
return <Link to={url}>{children}</Link>; | ||
}; | ||
|
||
const Header2Renderer = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<Header2 decorated weight="thin"> | ||
{children} | ||
</Header2> | ||
); | ||
}; | ||
|
||
export const RichTextArea = ({ customDecorators, ...props }: EditorProps) => { | ||
return ( | ||
<Editor | ||
customDecorators={[ | ||
{ | ||
// Find all entities of type 'LINK' and render them using the Link component | ||
strategy: ( | ||
contentBlock: ContentBlock, | ||
callback: (start: number, end: number) => void, | ||
contentState: ContentState, | ||
) => { | ||
contentBlock.findEntityRanges((character) => { | ||
const entityKey = character.getEntity(); | ||
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK'; | ||
}, callback); | ||
}, | ||
component: LinkRenderer, | ||
}, | ||
{ | ||
// Find all blocks with h2 style and render them using the Header2 component | ||
strategy: (contentBlock: ContentBlock, callback: (start: number, end: number) => void) => { | ||
if (!contentBlock) return; | ||
if (contentBlock.getType() === 'header-two') { | ||
callback(contentBlock.getDepth(), contentBlock.getDepth() + contentBlock.getLength()); | ||
} | ||
}, | ||
component: Header2Renderer, | ||
}, | ||
...(customDecorators || []), | ||
]} | ||
{...props} | ||
/> | ||
); | ||
}; |
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
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
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
Oops, something went wrong.