Skip to content

Commit

Permalink
markdown support for AlertView
Browse files Browse the repository at this point in the history
  • Loading branch information
imanjra committed Apr 16, 2024
1 parent 65e8982 commit 1e6e9c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
15 changes: 12 additions & 3 deletions app/packages/core/src/plugins/SchemaIO/components/AlertView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alert, AlertTitle, Typography } from "@mui/material";
import React from "react";
import { getComponentProps } from "../utils";
import Markdown from "./Markdown";

export default function AlertView(props) {
const { schema } = props;
Expand All @@ -12,15 +13,23 @@ export default function AlertView(props) {
severity={severity || viewToSeverity[name] || "info"}
{...getComponentProps(props, "container")}
>
<AlertTitle {...getComponentProps(props, "label")}>{label}</AlertTitle>
<AlertTitle {...getComponentProps(props, "label")}>
<Markdown {...getComponentProps(props, "label.markdown")}>
{label}
</Markdown>
</AlertTitle>
{description && (
<Typography {...getComponentProps(props, "description")}>
{description}
<Markdown {...getComponentProps(props, "description.markdown")}>
{description}
</Markdown>
</Typography>
)}
{caption && (
<Typography variant="body2" {...getComponentProps(props, "caption")}>
{caption}
<Markdown {...getComponentProps(props, "caption.markdown")}>
{caption}
</Markdown>
</Typography>
)}
</Alert>
Expand Down
25 changes: 17 additions & 8 deletions app/packages/core/src/plugins/SchemaIO/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Box,
Link,
Paper,
SxProps,
Table,
TableBody,
TableCell,
Expand Down Expand Up @@ -55,6 +56,8 @@ const CodeHeader = styled.div`
background: ${({ theme }) => theme.background.level2};
`;

const defaultSx: SxProps = { color: "inherit" };

const componentsMap = {
a({ children, ...props }) {
if (
Expand All @@ -68,7 +71,11 @@ const componentsMap = {
};
}

return <Link {...props}>{children}</Link>;
return (
<Link sx={defaultSx} {...props}>
{children}
</Link>
);
},
table({ children }) {
return (
Expand Down Expand Up @@ -118,34 +125,36 @@ const componentsMap = {
</InlineCode>
);
},
p: ({ children, ...props }) => <Typography>{children}</Typography>,
p: ({ children, ...props }) => (
<Typography sx={defaultSx}>{children}</Typography>
),
h1: ({ children, ...props }) => (
<Typography variant="h1" {...props}>
<Typography sx={defaultSx} variant="h1" {...props}>
{children}
</Typography>
),
h2: ({ children, ...props }) => (
<Typography variant="h2" {...props}>
<Typography sx={defaultSx} variant="h2" {...props}>
{children}
</Typography>
),
h3: ({ children, ...props }) => (
<Typography variant="h3" {...props}>
<Typography sx={defaultSx} variant="h3" {...props}>
{children}
</Typography>
),
h4: ({ children, ...props }) => (
<Typography variant="h4" {...props}>
<Typography sx={defaultSx} variant="h4" {...props}>
{children}
</Typography>
),
h5: ({ children, ...props }) => (
<Typography variant="h5" {...props}>
<Typography sx={defaultSx} variant="h5" {...props}>
{children}
</Typography>
),
h6: ({ children, ...props }) => (
<Typography variant="h6" {...props}>
<Typography sx={defaultSx} variant="h6" {...props}>
{children}
</Typography>
),
Expand Down

0 comments on commit 1e6e9c0

Please sign in to comment.