import React, { useContext } from 'react'; import { DumiDemoGrid, FormattedMessage } from 'dumi'; import { BugFilled, BugOutlined, CodeFilled, CodeOutlined } from '@ant-design/icons'; import classNames from 'classnames'; import { Tooltip } from 'antd'; import DemoContext from '../../slots/DemoContext'; import useLayoutState from '../../../hooks/useLayoutState'; const DemoWrapper: typeof DumiDemoGrid = ({ items }) => { const { showDebug, setShowDebug } = useContext(DemoContext); const [expandAll, setExpandAll] = useLayoutState(false); const expandTriggerClass = classNames('code-box-expand-trigger', { 'code-box-expand-trigger-active': expandAll, }); const handleVisibleToggle = () => { setShowDebug?.(!showDebug); }; const handleExpandToggle = () => { setExpandAll(!expandAll); }; const demos = React.useMemo( () => items.reduce((acc, item) => { const { previewerProps } = item; const { debug } = previewerProps; if (debug && !showDebug) return acc; return acc.concat({ ...item, previewerProps: { ...previewerProps, expand: expandAll, // always override debug property, because dumi will hide debug demo in production debug: false, /** * antd extra marker for the original debug * @see https://github.com/ant-design/ant-design/pull/40130#issuecomment-1380208762 */ originDebug: debug, }, }); }, [] as typeof items), [expandAll, showDebug], ); return (
} > {expandAll ? ( ) : ( )} } > {showDebug ? ( ) : ( )} {/* FIXME: find a new way instead of `key` to trigger re-render */}
); }; export default DemoWrapper;