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

Mdx : Theme fontCode not applied consistently when writing MDX #23110

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions code/ui/blocks/src/components/Source.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { ComponentProps, FunctionComponent } from 'react';
import React from 'react';
import { styled, ThemeProvider, convert, themes, ignoreSsrWarning } from '@storybook/theming';
import {
styled,
ThemeProvider,
convert,
themes,
ignoreSsrWarning,
useTheme,
} from '@storybook/theming';
import { SyntaxHighlighter } from '@storybook/components';

import { EmptyBlock } from './EmptyBlock';
Expand Down Expand Up @@ -95,6 +102,7 @@ const Source: FunctionComponent<SourceProps> = ({
format,
...rest
}) => {
const { typography } = useTheme();
if (isLoading) {
return <SourceSkeleton />;
}
Expand All @@ -118,7 +126,17 @@ const Source: FunctionComponent<SourceProps> = ({
return syntaxHighlighter;
}
const overrideTheme = dark ? themes.dark : themes.light;
return <ThemeProvider theme={convert(overrideTheme)}>{syntaxHighlighter}</ThemeProvider>;
return (
<ThemeProvider
theme={convert({
...overrideTheme,
fontCode: typography.fonts.mono,
fontBase: typography.fonts.base,
})}
>
{syntaxHighlighter}
</ThemeProvider>
);
};
Comment on lines +128 to 139
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why this is required? I'd assume the fix code/ui/components/src/syntaxhighlighter/syntaxhighlighter.tsx would be enough on it's own?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @ndelangen for the review. We have passed the content of code from here
Screen Shot 2023-06-23 at 00 00 52

which is not actually the Code defined over here

Screen Shot 2023-06-23 at 00 05 30

So fix over code/ui/components/src/syntaxhighlighter/syntaxhighlighter.tsx is not enough.


Source.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const Code = styled.div(({ theme }) => ({
paddingLeft: 2, // TODO: To match theming/global.ts for now
paddingRight: theme.layoutMargin,
opacity: 1,
fontFamily: theme.typography.fonts.mono,
}));

const processLineNumber = (row: any) => {
Expand Down