diff --git a/www/src/pages/extensions/basic-setup/example.tsx b/www/src/pages/extensions/basic-setup/example.tsx index ba6acb9bc..e6b611dbe 100644 --- a/www/src/pages/extensions/basic-setup/example.tsx +++ b/www/src/pages/extensions/basic-setup/example.tsx @@ -1,9 +1,10 @@ -import { FC, PropsWithChildren, useState } from 'react'; +import { FC, PropsWithChildren, useContext, useState } from 'react'; import CodeMirror, { BasicSetupOptions } from '@uiw/react-codemirror'; import { langs } from '@uiw/codemirror-extensions-langs'; import styled from 'styled-components'; import { useTheme } from '../../../utils/useTheme'; import { PageWarpper } from '..'; +import { MdContext } from '../../theme/Preview'; const Label = styled.label` user-select: none; @@ -25,17 +26,14 @@ const Warpper = styled.div` padding-bottom: 32px; `; -interface BasicSetupExampleProps { - source?: string; -} - -export const BasicSetupExample = (props: BasicSetupExampleProps) => { +export const BasicSetupExample = () => { const { theme } = useTheme(); const [basicSetup, setBasicSetup] = useState({}); + const mdData = useContext(MdContext); return ( > = ({ source }) => { +export const ClassNameExample: FC = () => { const { theme } = useTheme(); + const mdData = useContext(MdContext); const themeDemo = EditorView.baseTheme({ '&dark .first-line': { backgroundColor: 'red' }, @@ -20,7 +21,7 @@ export const ClassNameExample: FC> = ({ s return ( > = ({ source }) => { +export const EventsExample = () => { const [scrollTop, setScrollTop] = useState(0); const [eventType, setEventType] = useState(''); const { theme } = useTheme(); - + const mdData = useContext(MdContext); return ( > = ({ source }) => { +export const LineNumbersRelativeExample: FC = () => { const { theme } = useTheme(); + const mdData = useContext(MdContext); return ( > = ({ source }) => { +export const MentionsExample: FC = () => { const { theme } = useTheme(); + const mdData = useContext(MdContext); return ( > = ({ source }) => { +export const ThemesAllExample: FC = () => { const themesData: Record> = {}; Object.keys(themes) .filter((item) => typeof themes[item as keyof typeof themes] !== 'function') @@ -26,10 +26,11 @@ export const ThemesAllExample: FC> = ({ s const changeHandle = (ev: React.ChangeEvent) => { setSelectTheme(ev.target.value as keyof typeof themesData); }; + const mdData = useContext(MdContext); return ( > = ({ source }) => { +export const ZebraStripesExample: FC = () => { const { theme } = useTheme(); const [step, setStep] = useState(2); const zebra = zebraStripes({ step: step }); + const mdData = useContext(MdContext); return ( > = ( > = (props) => { const { themePkg, mode, children } = props; const { mdData } = useMdData(props.path); @@ -66,6 +70,7 @@ export const Preview: FC> = (props) => { const themeExtensionName = themePkgNmae?.replace('@uiw/codemirror-theme-', '') + (!!mode ? `-${mode}` : ''); const extension = themeData[toCamelCase(themeExtensionName) as keyof typeof themeData]; const repoName = themePkgNmae?.replace(/@uiw\//, ''); + console.log('mdData:', mdData); return ( @@ -90,7 +95,7 @@ export const Preview: FC> = (props) => { )} - {children} + {children} {mdData && (previewDoc === 'document' || !themePkg) && } {previewDoc === 'example' && themePkg && themeExtensionName && }