-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor(site): migrate <Markdown /> and <InlineMarkdown /> off MUI
#27724
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import type { Interpolation, Theme } from "@emotion/react"; | ||
| import isEqual from "lodash/isEqual"; | ||
| import { | ||
| createElement, | ||
|
|
@@ -21,7 +20,6 @@ import { | |
| TableHeader, | ||
| TableRow, | ||
| } from "#/components/Table/Table"; | ||
| import colors from "#/theme/tailwindColors"; | ||
| import { cn } from "#/utils/cn"; | ||
|
|
||
| interface MarkdownProps { | ||
|
|
@@ -43,15 +41,19 @@ export const Markdown: FC<MarkdownProps> = (props) => { | |
|
|
||
| return ( | ||
| <ReactMarkdown | ||
| css={markdownStyles} | ||
| className={className} | ||
| className={cn(markdownClassName, className)} | ||
| remarkPlugins={[gfm]} | ||
| components={{ | ||
| a: ({ href, children }) => { | ||
| const isExternal = href?.startsWith("http"); | ||
|
|
||
| return ( | ||
| <Link href={href} target={isExternal ? "_blank" : undefined}> | ||
| <Link | ||
| href={href} | ||
| target={isExternal ? "_blank" : undefined} | ||
| showExternalIcon={isExternal} | ||
| className="text-[length:inherit] p-0" | ||
| > | ||
| {children} | ||
| </Link> | ||
| ); | ||
|
|
@@ -328,60 +330,18 @@ const MarkdownGfmAlert: FC<MarkdownGfmAlertProps> = ({ | |
| ); | ||
| }; | ||
|
|
||
| const markdownStyles: Interpolation<Theme> = (theme: Theme) => ({ | ||
| fontSize: 16, | ||
| lineHeight: "24px", | ||
|
|
||
| "& h1, & h2, & h3, & h4, & h5, & h6": { | ||
| marginTop: 32, | ||
| marginBottom: 16, | ||
| lineHeight: "1.25", | ||
| }, | ||
|
|
||
| "& p": { | ||
| marginTop: 0, | ||
| marginBottom: 16, | ||
| }, | ||
|
|
||
| "& p:only-child": { | ||
| marginTop: 0, | ||
| marginBottom: 0, | ||
| }, | ||
|
|
||
| "& ul, & ol": { | ||
| display: "flex", | ||
| flexDirection: "column", | ||
| gap: 8, | ||
| marginBottom: 16, | ||
| }, | ||
|
|
||
| "& li > ul, & li > ol": { | ||
| marginTop: 16, | ||
| }, | ||
|
|
||
| "& li > p": { | ||
| marginBottom: 0, | ||
| }, | ||
|
|
||
| "& .prismjs": { | ||
| background: | ||
| theme.palette.mode === "dark" | ||
| ? colors.zinc[950] | ||
| : theme.palette.background.paper, | ||
| borderRadius: 8, | ||
| padding: "16px 24px", | ||
| overflowX: "auto", | ||
|
|
||
| "& code": { | ||
| color: theme.palette.text.secondary, | ||
| }, | ||
|
|
||
| "& .key, & .property, & .inserted, .keyword": { | ||
| color: colors.teal[300], | ||
| }, | ||
|
|
||
| "& .deleted": { | ||
| color: theme.palette.error.light, | ||
| }, | ||
| }, | ||
| }); | ||
| const markdownClassName = cn( | ||
| "text-base", | ||
| "[&_:is(h1,h2,h3,h4,h5,h6)]:mt-8", | ||
| "[&_:is(h1,h2,h3,h4,h5,h6)]:mb-4", | ||
| "[&_:is(h1,h2,h3,h4,h5,h6)]:leading-tight", | ||
| "[&_p]:mt-0 [&_p]:mb-4 [&_p:only-child]:my-0", | ||
| "[&_ul]:mb-4 [&_ul]:flex [&_ul]:flex-col [&_ul]:gap-2", | ||
| "[&_ol]:mb-4 [&_ol]:flex [&_ol]:flex-col [&_ol]:gap-2", | ||
| "[&_li>ul]:mt-4 [&_li>ol]:mt-4 [&_li>p]:mb-0", | ||
| "[&_.prismjs]:overflow-x-auto [&_.prismjs]:rounded-lg [&_.prismjs]:bg-surface-secondary [&_.prismjs]:px-6 [&_.prismjs]:py-4", | ||
| "[&_.prismjs_code]:text-content-secondary", | ||
| "[&_.prismjs_.key]:text-syntax-key [&_.prismjs_.property]:text-syntax-key", | ||
| "[&_.prismjs_.inserted]:text-syntax-key [&_.prismjs_.keyword]:text-syntax-key", | ||
| "[&_.prismjs_.deleted]:text-content-destructive", | ||
| ); | ||
|
Comment on lines
+333
to
+347
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. holy tailwind selectors. Can we inline this at usage? Non-blocking just not sure we need it to be defined here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agreedly hate this, but the alternative is to import a CSS file (gross? idk), I will come back to this post-MUI 🙏🏻 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For external links rendered through
InlineMarkdown, this now setstarget="_blank"and changes the rendered link primitive, but the existingWithLinkstory only supplies args and has noplayassertion. Add Storybook interaction coverage that locates the link semantically and verifies the external and internal target behavior, as FE1 requires user-visible behavior changes to be exercised by a story'splayfunction.AGENTS.md reference: site/AGENTS.md:L9-L10
Useful? React with 👍 / 👎.