Skip to content

Commit

Permalink
[docs] Fix code editor styles mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 12, 2022
1 parent cb278c4 commit 5a3f18b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/src/modules/components/AdCarbon.js
Expand Up @@ -123,7 +123,7 @@ export function AdCarbonInline(props) {
/>
</React.Fragment>
) : (
<div {...props} style={{ minHeight: 45 }} />
<div {...props} style={{ minHeight: 52 }} />
);
}

Expand Down
11 changes: 8 additions & 3 deletions docs/src/modules/components/Demo.js
Expand Up @@ -271,12 +271,17 @@ const DemoRootJoy = joyStyled('div', {
}),
}));

const DemoCodeViewer = styled(HighlightedCode)({
const DemoCodeViewer = styled(HighlightedCode)(({ theme }) => ({
'& pre': {
margin: '0 auto',
margin: 0,
maxHeight: 'min(68vh, 1000px)',
maxWidth: 'initial',
borderRadius: 0,
[theme.breakpoints.up('sm')]: {
borderRadius: theme.shape.borderRadius,
},
},
});
}));

const AnchorLink = styled('div')({
marginTop: -64, // height of toolbar
Expand Down
12 changes: 8 additions & 4 deletions docs/src/modules/components/DemoEditor.tsx
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import SimpleCodeEditor from 'react-simple-code-editor';
import Box from '@mui/material/Box';
import NoSsr from '@mui/base/NoSsr';
import { styled } from '@mui/material/styles';
import { styled, useTheme } from '@mui/material/styles';
import prism from '@mui/markdown/prism';
import MarkdownElement from 'docs/src/modules/components/MarkdownElement';
import CodeCopyButton from 'docs/src/modules/components/CodeCopyButton';
Expand All @@ -14,8 +14,7 @@ const StyledMarkdownElement = styled(MarkdownElement)(({ theme }) => ({
'& .scrollContainer': {
maxHeight: 'min(68vh, 1000px)',
overflow: 'auto',
backgroundColor: `${blueDark[800]} !important`,
borderRadius: theme.shape.borderRadius,
backgroundColor: blueDark[800],
colorScheme: 'dark',
'&:hover': {
boxShadow: `0 0 0 3px ${
Expand All @@ -27,6 +26,9 @@ const StyledMarkdownElement = styled(MarkdownElement)(({ theme }) => ({
theme.palette.mode === 'dark' ? theme.palette.primaryDark.main : theme.palette.primary.main
}`,
},
[theme.breakpoints.up('sm')]: {
borderRadius: theme.shape.borderRadius,
},
},
'& pre': {
// The scroll container needs to be the parent of the editor, overriding:
Expand All @@ -50,6 +52,7 @@ const StyledSimpleCodeEditor = styled(SimpleCodeEditor)(({ theme }) => ({
outline: 'none',
},
'& > textarea, & > pre': {
// Override inline-style
whiteSpace: 'pre !important',
},
}));
Expand All @@ -66,6 +69,7 @@ interface DemoEditorProps {
export default function DemoEditor(props: DemoEditorProps) {
const { language, value, onChange, copyButtonProps, children, id } = props;
const t = useTranslate();
const contextTheme = useTheme();
const wrapperRef = React.useRef<HTMLElement | null>(null);
const enterRef = React.useRef<HTMLElement | null>(null);
const handlers = useCodeCopy();
Expand Down Expand Up @@ -100,7 +104,7 @@ export default function DemoEditor(props: DemoEditorProps) {
<div className="MuiCode-root" {...handlers}>
<div className="scrollContainer">
<StyledSimpleCodeEditor
padding={20}
padding={contextTheme.spacing(2)}
highlight={(code: any) =>
`<code class="language-${language}">${prism(code, language)}</code>`
}
Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/components/ad.styles.js
Expand Up @@ -46,6 +46,7 @@ const adBodyInlineStyles = (theme) => {
...baseline,
root: {
display: 'block',
paddingTop: 8,
},
imgWrapper: {
display: 'none',
Expand Down

0 comments on commit 5a3f18b

Please sign in to comment.