From a2ef8a6d0dd52f067d0b3afa3817011454355917 Mon Sep 17 00:00:00 2001 From: Zeeshan Tamboli Date: Thu, 17 Aug 2023 19:57:55 +0530 Subject: [PATCH] [docs-infra] Cleanup code on demo code block expansion (#38522) --- docs/src/modules/components/Demo.js | 14 +-------- docs/src/modules/components/DemoToolbar.js | 36 +--------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/docs/src/modules/components/Demo.js b/docs/src/modules/components/Demo.js index 5c452730126744..f05635225ba5e6 100644 --- a/docs/src/modules/components/Demo.js +++ b/docs/src/modules/components/Demo.js @@ -412,11 +412,6 @@ export default function Demo(props) { const hasNonSystemDemos = demo.rawTailwind || demo.rawTailwindTS || demo.rawCSS || demo.rawCSSTs; - const [demoHovered, setDemoHovered] = React.useState(false); - const handleDemoHover = (event) => { - setDemoHovered(event.type === 'mouseenter'); - }; - const demoName = getDemoName(demoData.githubLocation); const demoSandboxedStyle = React.useMemo( () => ({ @@ -513,13 +508,7 @@ export default function Demo(props) { return ( - + theme.breakpoints.up('sm')); - const [open, setOpen] = React.useState(false); - - return ( - setOpen(false)} - onOpen={() => setOpen(true)} - open={showSourceHint && atLeastSmallViewport ? true : open} - /> - ); -} -ToggleCodeTooltip.propTypes = { - showSourceHint: PropTypes.bool, -}; - const alwaysTrue = () => true; const ToggleButtonGroup = styled(MDToggleButtonGroup)(({ theme }) => [ @@ -297,7 +277,6 @@ export default function DemoToolbar(props) { demo, demoData, demoId, - demoHovered, demoName, demoOptions, demoSourceId, @@ -365,21 +344,10 @@ export default function DemoToolbar(props) { } }; - const [sourceHintSeen, setSourceHintSeen] = React.useState(false); - React.useEffect(() => { - setSourceHintSeen(getCookie('sourceHintSeen')); - }, []); - const handleCodeOpenClick = () => { - document.cookie = `sourceHintSeen=true;path=/;max-age=31536000`; - onCodeOpenChange(); - setSourceHintSeen(true); - }; - const handleResetFocusClick = () => { initialFocusRef.current.focusVisible(); }; - const showSourceHint = demoHovered && !sourceHintSeen; let showCodeLabel; if (codeOpen) { showCodeLabel = showPreview ? t('hideFullSource') : t('hideSource'); @@ -561,8 +529,7 @@ export default function DemoToolbar(props) { data-ga-event-category="demo" data-ga-event-label={demo.gaLabel} data-ga-event-action="expand" - onClick={handleCodeOpenClick} - showSourceHint={showSourceHint} + onClick={onCodeOpenChange} {...getControlProps(3)} > {showCodeLabel} @@ -757,7 +724,6 @@ DemoToolbar.propTypes = { codeVariant: PropTypes.string.isRequired, demo: PropTypes.object.isRequired, demoData: PropTypes.object.isRequired, - demoHovered: PropTypes.bool.isRequired, demoId: PropTypes.string, demoName: PropTypes.string.isRequired, demoOptions: PropTypes.object.isRequired,