Skip to content

Commit

Permalink
Merge pull request #23110 from storybookjs/fix/theme-fontCode-mdx
Browse files Browse the repository at this point in the history
Mdx : Theme `fontCode` not applied consistently when writing MDX
  • Loading branch information
ndelangen authored Nov 27, 2023
2 parents 20600b3 + 8fec73b commit ed656b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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>
);
};

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

0 comments on commit ed656b8

Please sign in to comment.