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

(feat) Make the label in FormField optional to support Markdown content #411

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
"lodash-es": "^4.17.21",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.52.0",
"react-markdown": "^7.1.2",
"react-markdown": "^9.0.1",
"react-waypoint": "^10.3.0",
"react-webcam": "^7.2.0"
"react-webcam": "^7.2.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0"
Copy link
Contributor

@NethmiRodrigo NethmiRodrigo Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these three libraries?

},
"peerDependencies": {
"@openmrs/esm-framework": "5.x",
Expand Down
23 changes: 22 additions & 1 deletion src/components/inputs/markdown/markdown-wrapper.component.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import React from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';

Check failure on line 3 in src/components/inputs/markdown/markdown-wrapper.component.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'remark-gfm' or its corresponding type declarations.
import rehypeRaw from 'rehype-raw';

Check failure on line 4 in src/components/inputs/markdown/markdown-wrapper.component.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'rehype-raw' or its corresponding type declarations.

const MarkdownWrapper: React.FC<{ markdown: string | string[] }> = ({ markdown }) => {
return (
<ReactMarkdown
children={Array.isArray(markdown) ? markdown.join('\n') : markdown}
unwrapDisallowed={true}
allowedElements={['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'strong', 'em']}
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeRaw]}
allowedElements={[
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'p',
'strong',
'em',
'ul',
'ol',
'li',
'input',
'sup',
'sub',
'del',
]}
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface FormSection {
}

export interface FormField {
label: string;
label?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelmale this was changed to be optional because markdown type inputs don't have a label. Does this seem okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me.

type: string;
questionOptions: FormQuestionOptions;
datePickerFormat?: 'both' | 'calendar' | 'timer';
Expand Down
Loading