Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example cards for HTML and Markdown Rendering #384

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,571 changes: 9,780 additions & 791 deletions THIRD-PARTY-NOTICES

Large diffs are not rendered by default.

6,319 changes: 6,257 additions & 62 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"@reach/auto-id": "^0.18.0",
"@restart/ui": "^1.0.1",
"@tailwindcss/forms": "^0.5.0",
"@uiw/react-md-editor": "^3.23.3",
"@yext/analytics": "^0.5.0",
"classnames": "^2.3.1",
"lodash": "^4.17.21",
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'

Check warning on line 3 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Missing semicolon

const builtInCssClasses = {
container: 'flex flex-col justify-between border border-gray-200 rounded-lg mb-4 p-4 shadow-sm',

Check warning on line 6 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4
header: 'flex text-neutral-dark',

Check warning on line 7 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4
title: 'text-lg font-medium',

Check warning on line 8 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4
thumbsFeedbackContainer: 'flex justify-end mt-4 text-sm text-gray-500 font-medium',

Check warning on line 9 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4
};

// change to the field name that contains html string
const htmlFieldName = "c_richTextV2Data";

Check warning on line 13 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Strings must use singlequote
interface CustomRawDataType {
name: string,

Check warning on line 15 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4
description: string

Check warning on line 16 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4

Check warning on line 16 in test-site/src/components/HTMLExampleCard.tsx

View workflow job for this annotation

GitHub Actions / linting / linting

Expected a comma
[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;
}
Loading