-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example cards for HTML and Markdown Rendering
Added two example cards that render HTML and Markdown in search results J=BACK-2395 TEST=manual Ran the test-site with both the example cards and searched for entities with RichTextv2 and Markdown data
- Loading branch information
1 parent
b5d7b7d
commit 9948c6e
Showing
7 changed files
with
135 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { CardProps, useCardAnalyticsCallback, useCardFeedbackCallback } from '@yext/search-ui-react'; | ||
import { useCallback } from 'react'; | ||
import '../styles/resetStyles.css' | ||
|
||
const builtInCssClasses = { | ||
container: 'flex flex-col justify-between border border-gray-200 rounded-lg mb-4 p-4 shadow-sm', | ||
header: 'flex text-neutral-dark', | ||
title: 'text-lg font-medium', | ||
thumbsFeedbackContainer: 'flex justify-end mt-4 text-sm text-gray-500 font-medium', | ||
}; | ||
|
||
// change to the field name that contains html string | ||
const htmlFieldName = "c_richTextV2Data"; | ||
interface CustomRawDataType { | ||
name: string, | ||
description: string | ||
[htmlFieldName]: any | ||
} | ||
|
||
function renderRichTextDescription(richTextHTML: string | undefined) { | ||
if ( richTextHTML ) | ||
{ | ||
return <div className={"reset-style"} dangerouslySetInnerHTML={{ __html: richTextHTML }} />; | ||
} | ||
return null; | ||
} | ||
|
||
export function HTMLExampleCard(props: CardProps<CustomRawDataType>): JSX.Element { | ||
const { result } = props; | ||
const onClickTitle = useCardAnalyticsCallback(result, 'TITLE_CLICK'); | ||
const cardFeedbackCallback = useCardFeedbackCallback(result); | ||
const onClick = useCallback(() => { | ||
cardFeedbackCallback('THUMBS_UP'); | ||
}, [cardFeedbackCallback]); | ||
return ( | ||
<div className={builtInCssClasses.container}> | ||
<p className={builtInCssClasses.header}>HTML Card</p> | ||
<button onClick={onClickTitle} className={builtInCssClasses.title}>{result.rawData.name}</button> | ||
{renderRichTextDescription(result.rawData?.[htmlFieldName]?.html)} | ||
<button onClick={onClick} className={builtInCssClasses.thumbsFeedbackContainer}>Feedback</button> | ||
</div> | ||
); | ||
} |
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,42 @@ | ||
import { CardProps, useCardAnalyticsCallback, useCardFeedbackCallback } from '@yext/search-ui-react'; | ||
import { useCallback } from 'react'; | ||
import '../styles/resetStyles.css' | ||
import MDEditor from "@uiw/react-md-editor"; | ||
|
||
|
||
|
||
const builtInCssClasses = { | ||
container: 'flex flex-col justify-between border border-gray-200 rounded-lg mb-4 p-4 shadow-sm', | ||
header: 'flex text-neutral-dark', | ||
title: 'text-lg font-medium', | ||
thumbsFeedbackContainer: 'flex justify-end mt-4 text-sm text-gray-500 font-medium', | ||
}; | ||
|
||
|
||
const markdownFieldName = "c_markdownData"; | ||
|
||
interface CustomRawDataType { | ||
name: string, | ||
description: string, | ||
[markdownFieldName]: any | ||
} | ||
|
||
export function MarkdownExampleCard(props: CardProps<CustomRawDataType>): JSX.Element { | ||
const { result } = props; | ||
const onClickTitle = useCardAnalyticsCallback(result, 'TITLE_CLICK'); | ||
const cardFeedbackCallback = useCardFeedbackCallback(result); | ||
const onClick = useCallback(() => { | ||
cardFeedbackCallback('THUMBS_UP'); | ||
}, [cardFeedbackCallback]); | ||
|
||
return ( | ||
<div className={`${builtInCssClasses.container} `}> | ||
<p className={builtInCssClasses.header}>Markdown Render Card</p> | ||
<button onClick={onClickTitle} className={builtInCssClasses.title}>{result.rawData.name}</button> | ||
<div className="container reset-style" data-color-mode="light"> | ||
<MDEditor.Markdown source={result.rawData?.[markdownFieldName]?.markdown} /> | ||
</div> | ||
<button onClick={onClick} className={builtInCssClasses.thumbsFeedbackContainer}>Feedback</button> | ||
</div> | ||
); | ||
} |
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,4 @@ | ||
/* Revert CSS style of target element and its children */ | ||
.reset-style, .reset-style * { | ||
all: revert; | ||
} |