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 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
24 changes: 21 additions & 3 deletions code/ui/blocks/src/components/Source.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { ComponentProps, FunctionComponent } from 'react';
import { ThemeProvider, convert, ignoreSsrWarning, styled, themes } from '@storybook/theming';

import React from 'react';
import {
styled,
ThemeProvider,
convert,
themes,
ignoreSsrWarning,
useTheme,
} from '@storybook/theming';

import { SyntaxHighlighter } from '@storybook/components';
import type { SyntaxHighlighterProps } from '@storybook/components';
import { EmptyBlock } from './EmptyBlock';
Expand Down Expand Up @@ -94,6 +101,7 @@ const Source: FunctionComponent<SourceProps> = ({
format,
...rest
}) => {
const { typography } = useTheme();
if (isLoading) {
return <SourceSkeleton />;
}
Expand All @@ -117,7 +125,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

@gitstart-storybook gitstart-storybook Jun 22, 2023

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 @@ -132,6 +132,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