From 5651fddead674584bd3204ddafb32f95d184291b Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Mon, 29 Apr 2024 08:49:16 -0300 Subject: [PATCH] [wesbite] Remove duplicate MarkdownElement component (#42028) --- docs/src/components/action/Frame.tsx | 4 +- docs/src/components/home/AdvancedShowcase.tsx | 8 +-- docs/src/components/home/CoreShowcase.tsx | 8 +-- .../components/markdown/MarkdownElement.tsx | 54 ------------------- .../productBaseUI/BaseUIComponents.tsx | 8 ++- .../productBaseUI/BaseUICustomization.tsx | 16 ++---- .../productMaterial/MaterialComponents.tsx | 10 +--- .../productMaterial/MaterialStyling.tsx | 16 ++---- .../productMaterial/MaterialTheming.tsx | 8 +-- docs/src/components/productX/XChartsDemo.tsx | 3 +- docs/src/components/productX/XDataGrid.tsx | 8 +-- .../components/productX/XDateRangeDemo.tsx | 3 +- .../src/components/productX/XTreeViewDemo.tsx | 3 +- .../src/HighlightedCode/HighlightedCode.tsx | 33 ++++++++++-- 14 files changed, 48 insertions(+), 134 deletions(-) delete mode 100644 docs/src/components/markdown/MarkdownElement.tsx diff --git a/docs/src/components/action/Frame.tsx b/docs/src/components/action/Frame.tsx index 64ecab7c500248..f2cf33e9e97e71 100644 --- a/docs/src/components/action/Frame.tsx +++ b/docs/src/components/action/Frame.tsx @@ -36,9 +36,7 @@ const FrameInfo = React.forwardRef(function FrameInfo( borderColor: 'primaryDark.700', borderTop: 0, colorScheme: 'dark', - '* pre, code': { - bgcolor: 'common.black', - }, + overflow: 'clip', ...props.sx, }} /> diff --git a/docs/src/components/home/AdvancedShowcase.tsx b/docs/src/components/home/AdvancedShowcase.tsx index 8ada3b7c591b62..56f4fea7edefe9 100644 --- a/docs/src/components/home/AdvancedShowcase.tsx +++ b/docs/src/components/home/AdvancedShowcase.tsx @@ -6,7 +6,6 @@ import Typography from '@mui/material/Typography'; import Divider from '@mui/material/Divider'; import ShowcaseContainer from 'docs/src/components/home/ShowcaseContainer'; import { HighlightedCode } from '@mui/docs/HighlightedCode'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; import XGridGlobalStyles from 'docs/src/components/home/XGridGlobalStyles'; import ProgressBar from 'docs/src/components/x-grid/ProgressBar'; import EditProgress from 'docs/src/components/x-grid/EditProgress'; @@ -1728,12 +1727,7 @@ export default function DataTable() { }, }} > - + } /> diff --git a/docs/src/components/home/CoreShowcase.tsx b/docs/src/components/home/CoreShowcase.tsx index a2be6591894a1a..c3a84ee1346896 100644 --- a/docs/src/components/home/CoreShowcase.tsx +++ b/docs/src/components/home/CoreShowcase.tsx @@ -5,7 +5,6 @@ import Button, { buttonClasses } from '@mui/material/Button'; import { HighlightedCode } from '@mui/docs/HighlightedCode'; import MaterialDesignDemo, { componentCode } from 'docs/src/components/home/MaterialDesignDemo'; import ShowcaseContainer from 'docs/src/components/home/ShowcaseContainer'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; import PointerContainer, { Data } from 'docs/src/components/home/ElementPointer'; import StylingInfo from 'docs/src/components/action/StylingInfo'; import FlashCode from 'docs/src/components/animation/FlashCode'; @@ -184,12 +183,7 @@ export default function CoreShowcase() { > {startLine !== undefined && } - + diff --git a/docs/src/components/markdown/MarkdownElement.tsx b/docs/src/components/markdown/MarkdownElement.tsx deleted file mode 100644 index 0fa3ed548afea2..00000000000000 --- a/docs/src/components/markdown/MarkdownElement.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import * as React from 'react'; -import clsx from 'clsx'; -import { - // alpha, - // darken, - styled, -} from '@mui/material/styles'; - -const Root = styled('div')(({ theme }) => ({ - ...theme.typography.caption, - color: (theme.vars || theme).palette.text.primary, - '& pre': { - backgroundColor: 'hsl(210, 35%, 9%)', // a special, one-off, color tailored for the code blocks using MUI's branding theme blue palette as the starting point. It has a less saturaded color but still maintaining a bit of the blue tint. - color: '#f8f8f2', // fallback color until Prism's theme is loaded - overflow: 'auto', - margin: 0, - WebkitOverflowScrolling: 'touch', // iOS momentum scrolling. - maxWidth: 'calc(100vw - 32px)', - [theme.breakpoints.up('md')]: { - maxWidth: 'calc(100vw - 32px - 16px)', - }, - }, - '& code': { - // Avoid layout jump after hydration (style injected by prism) - ...theme.typography.caption, - fontFamily: theme.typography.fontFamilyCode, - fontWeight: 400, - WebkitFontSmoothing: 'subpixel-antialiased', - // Reset for Safari - // https://github.com/necolas/normalize.css/blob/master/normalize.css#L102 - fontSize: '1em', - }, -})); - -type MarkdownElementProps = { - renderedMarkdown: string; -} & Omit; - -const MarkdownElement = React.forwardRef( - function MarkdownElement(props, ref) { - const { className, renderedMarkdown, ...other } = props; - const more: Record = {}; - - if (typeof renderedMarkdown === 'string') { - // workaround for https://github.com/facebook/react/issues/17170 - // otherwise we could just set `dangerouslySetInnerHTML={undefined}` - more.dangerouslySetInnerHTML = { __html: renderedMarkdown }; - } - - return ; - }, -); - -export default MarkdownElement; diff --git a/docs/src/components/productBaseUI/BaseUIComponents.tsx b/docs/src/components/productBaseUI/BaseUIComponents.tsx index f95e4bb54910e4..6766fe7b76acea 100644 --- a/docs/src/components/productBaseUI/BaseUIComponents.tsx +++ b/docs/src/components/productBaseUI/BaseUIComponents.tsx @@ -17,7 +17,6 @@ import Section from 'docs/src/layouts/Section'; import SectionHeadline from 'docs/src/components/typography/SectionHeadline'; import More from 'docs/src/components/action/More'; import Frame from 'docs/src/components/action/Frame'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; import ROUTES from 'docs/src/route'; // Switcher icons @@ -163,11 +162,10 @@ export default function BaseUIComponents() { { const result = CODES[demo]; if (typeof result === 'function') { diff --git a/docs/src/components/productBaseUI/BaseUICustomization.tsx b/docs/src/components/productBaseUI/BaseUICustomization.tsx index 5d016a8e378752..48ba71e113daad 100644 --- a/docs/src/components/productBaseUI/BaseUICustomization.tsx +++ b/docs/src/components/productBaseUI/BaseUICustomization.tsx @@ -3,7 +3,6 @@ import { styled } from '@mui/system'; import clsx from 'clsx'; import { Switch as SwitchUnstyled } from '@mui/base/Switch'; import { useSwitch, UseSwitchParameters } from '@mui/base/useSwitch'; -import Box from '@mui/material/Box'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import { HighlightedCode } from '@mui/docs/HighlightedCode'; @@ -15,7 +14,6 @@ import GradientText from 'docs/src/components/typography/GradientText'; import SectionHeadline from 'docs/src/components/typography/SectionHeadline'; import FlashCode from 'docs/src/components/animation/FlashCode'; import Frame from 'docs/src/components/action/Frame'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; const code = ` import clsx from 'clsx'; @@ -302,20 +300,12 @@ export default function BaseUICustomization() { ref={infoRef} sx={{ maxHeight: 450, + position: 'relative', overflow: 'auto', }} > - - - - - - + + diff --git a/docs/src/components/productMaterial/MaterialComponents.tsx b/docs/src/components/productMaterial/MaterialComponents.tsx index 2eeaa9e4918471..08dd1449262faf 100644 --- a/docs/src/components/productMaterial/MaterialComponents.tsx +++ b/docs/src/components/productMaterial/MaterialComponents.tsx @@ -30,7 +30,7 @@ import More from 'docs/src/components/action/More'; import Frame from 'docs/src/components/action/Frame'; import { customTheme } from 'docs/src/components/home/MaterialDesignComponents'; import { HighlightedCode } from '@mui/docs/HighlightedCode'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; + import StylingInfo from 'docs/src/components/action/StylingInfo'; import ROUTES from 'docs/src/route'; @@ -290,7 +290,6 @@ export default function MaterialComponents() { minHeight: 220, maxHeight: demo === 'Table' ? 260 : 'none', position: 'relative', - overflow: 'hidden', p: 0, pt: 5, }} @@ -305,12 +304,7 @@ export default function MaterialComponents() { height: '100%', }} > - + ({ diff --git a/docs/src/components/productMaterial/MaterialStyling.tsx b/docs/src/components/productMaterial/MaterialStyling.tsx index 30153e196f5d35..4fb48f665fc909 100644 --- a/docs/src/components/productMaterial/MaterialStyling.tsx +++ b/docs/src/components/productMaterial/MaterialStyling.tsx @@ -14,7 +14,7 @@ import Item, { Group } from 'docs/src/components/action/Item'; import Highlighter from 'docs/src/components/action/Highlighter'; import Frame from 'docs/src/components/action/Frame'; import RealEstateCard from 'docs/src/components/showcase/RealEstateCard'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; + import FlashCode from 'docs/src/components/animation/FlashCode'; const code = ` @@ -311,19 +311,11 @@ export default function MaterialStyling() { sx={{ maxHeight: index === 2 ? 282 : 400, overflow: 'auto', + position: 'relative', }} > - - - - - - + + diff --git a/docs/src/components/productMaterial/MaterialTheming.tsx b/docs/src/components/productMaterial/MaterialTheming.tsx index 683654fd05b927..a0c3560bbaebf1 100644 --- a/docs/src/components/productMaterial/MaterialTheming.tsx +++ b/docs/src/components/productMaterial/MaterialTheming.tsx @@ -12,7 +12,6 @@ import Highlighter from 'docs/src/components/action/Highlighter'; import SvgMaterialDesign from 'docs/src/icons/SvgMaterialDesign'; import Frame from 'docs/src/components/action/Frame'; import PlayerCard from 'docs/src/components/showcase/PlayerCard'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; const code = ` - + diff --git a/docs/src/components/productX/XChartsDemo.tsx b/docs/src/components/productX/XChartsDemo.tsx index 9dd5c593f51420..5cfef0e88a108b 100644 --- a/docs/src/components/productX/XChartsDemo.tsx +++ b/docs/src/components/productX/XChartsDemo.tsx @@ -4,7 +4,6 @@ import { BarChart } from '@mui/x-charts/BarChart'; import { blueberryTwilightPaletteLight } from '@mui/x-charts'; import { HighlightedCode } from '@mui/docs/HighlightedCode'; import Frame from 'docs/src/components/action/Frame'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; const code = ` - + ); diff --git a/docs/src/components/productX/XDataGrid.tsx b/docs/src/components/productX/XDataGrid.tsx index a9b63174ea61e8..2630440dddac9b 100644 --- a/docs/src/components/productX/XDataGrid.tsx +++ b/docs/src/components/productX/XDataGrid.tsx @@ -19,7 +19,6 @@ import Item, { Group } from 'docs/src/components/action/Item'; import Highlighter from 'docs/src/components/action/Highlighter'; import More from 'docs/src/components/action/More'; import Frame from 'docs/src/components/action/Frame'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; import FlashCode from 'docs/src/components/animation/FlashCode'; import XGridGlobalStyles from 'docs/src/components/home/XGridGlobalStyles'; import StylingInfo from 'docs/src/components/action/StylingInfo'; @@ -211,12 +210,7 @@ export default function XDataGrid() { > - + {demo && } - + ); diff --git a/docs/src/components/productX/XTreeViewDemo.tsx b/docs/src/components/productX/XTreeViewDemo.tsx index 7c87ea44fd4635..7cf620c9935071 100644 --- a/docs/src/components/productX/XTreeViewDemo.tsx +++ b/docs/src/components/productX/XTreeViewDemo.tsx @@ -19,7 +19,6 @@ import VideocamOutlined from '@mui/icons-material/VideocamOutlined'; import FourKOutlined from '@mui/icons-material/FourKOutlined'; import { HighlightedCode } from '@mui/docs/HighlightedCode'; import Frame from 'docs/src/components/action/Frame'; -import MarkdownElement from 'docs/src/components/markdown/MarkdownElement'; const CustomContent = React.forwardRef(function CustomContent( props: TreeItemContentProps & { lastNestedChild?: boolean }, @@ -330,7 +329,7 @@ export default function XDateRangeDemo() { - + ); diff --git a/packages/mui-docs/src/HighlightedCode/HighlightedCode.tsx b/packages/mui-docs/src/HighlightedCode/HighlightedCode.tsx index dd2d43fd020849..2f88f0d09476b5 100644 --- a/packages/mui-docs/src/HighlightedCode/HighlightedCode.tsx +++ b/packages/mui-docs/src/HighlightedCode/HighlightedCode.tsx @@ -2,16 +2,37 @@ import * as React from 'react'; import prism from '@mui/internal-markdown/prism'; import { NoSsr } from '@mui/base/NoSsr'; import { ButtonProps } from '@mui/material/Button'; -import { SxProps } from '@mui/material/styles'; +import { SxProps, styled } from '@mui/material/styles'; import { useCodeCopy, CodeCopyButton } from '../CodeCopy'; import { MarkdownElement } from '../MarkdownElement'; +const Pre = styled('pre')(({ theme }) => ({ + margin: 0, + color: 'hsl(60deg 30% 96.08%)', // fallback color until Prism's theme is loaded + WebkitOverflowScrolling: 'touch', // iOS momentum scrolling. + maxWidth: 'calc(100vw - 32px)', + [theme.breakpoints.up('md')]: { + maxWidth: 'calc(100vw - 32px - 16px)', + }, + '& code': { + // Avoid layout jump after hydration (style injected by Prism) + ...theme.typography.caption, + fontFamily: theme.typography.fontFamilyCode, + fontWeight: 400, + WebkitFontSmoothing: 'subpixel-antialiased', + // Reset for Safari + // https://github.com/necolas/normalize.css/blob/master/normalize.css#L102 + }, +})); + export interface HighlightedCodeProps { code: string; - component?: React.ElementType; copyButtonHidden?: boolean; copyButtonProps?: ButtonProps; language: string; + parentComponent?: React.ElementType; + preComponent?: React.ElementType; + plainStyle?: boolean; sx?: SxProps; } @@ -22,7 +43,9 @@ export const HighlightedCode = React.forwardRef { @@ -38,13 +61,13 @@ export const HighlightedCode = React.forwardRef )} -
+          
             
-          
+ );