Skip to content

Commit

Permalink
Add example cards for HTML and Markdown Rendering
Browse files Browse the repository at this point in the history
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
saahithjanapati committed Jul 17, 2023
1 parent b5d7b7d commit 9948c6e
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 46 deletions.
74 changes: 36 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/search-ui-react",
"version": "1.3.0",
"version": "1.3.0-beta.1",
"description": "A library of React Components for powering Yext Search integrations",
"author": "slapshot@yext.com",
"license": "BSD-3-Clause",
Expand Down Expand Up @@ -76,7 +76,7 @@
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@yext/eslint-config-slapshot": "^0.5.0",
"@yext/search-headless-react": "2.3.0",
"@yext/search-headless-react": "^2.2.0",
"axe-playwright": "^1.1.11",
"babel-jest": "^27.0.6",
"eslint": "^8.11.0",
Expand All @@ -93,9 +93,9 @@
"typescript": "~4.5.5"
},
"peerDependencies": {
"@yext/search-headless-react": "2.3.0",
"react": "^16.14 || ^17",
"react-dom": "^16.14 || ^17"
"@yext/search-headless-react": "^2.2.0",
"react": "^16.14 || ^17 || ^18",
"react-dom": "^16.14 || ^17 || ^18"
},
"jest": {
"bail": 0,
Expand Down Expand Up @@ -141,12 +141,12 @@
"@reach/auto-id": "^0.18.0",
"@restart/ui": "^1.0.1",
"@tailwindcss/forms": "^0.5.0",
"@yext/analytics": "^0.5.0",
"@yext/analytics": "^0.2.0-beta.3",
"classnames": "^2.3.1",
"lodash": "^4.17.21",
"mapbox-gl": "^2.9.2",
"prop-types": "^15.8.1",
"react-collapsed": "3.6.0",
"react-collapsed": "~3.6.0",
"recent-searches": "^1.0.5",
"tailwind-merge": "^1.3.0",
"use-isomorphic-layout-effect": "^1.1.2"
Expand Down
2 changes: 2 additions & 0 deletions test-site/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"eslint-config-react-app": "file:../node_modules/eslint-config-react-app",
"@types/mapbox-gl": "^2.7.6",
"@types/node": "^16.11.26",
"@types/react": "^17.0.42",
"@types/react-dom": "^17.0.14",
"@types/uuid": "^8.3.4",
"autoprefixer": "^10.4.4",
"eslint-config-react-app": "file:../node_modules/eslint-config-react-app",
"postcss": "^8.4.12",
"react-scripts": "5.0.0",
"tailwindcss": "^3.0.23",
Expand Down
43 changes: 43 additions & 0 deletions test-site/src/components/HTMLExampleCard.tsx
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>
);
}
42 changes: 42 additions & 0 deletions test-site/src/components/MarkdownRenderCard.tsx
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>
);
}
4 changes: 4 additions & 0 deletions test-site/src/styles/resetStyles.css
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;
}

0 comments on commit 9948c6e

Please sign in to comment.