Skip to content

Commit

Permalink
[docs-infra] Cleanup code on demo code block expansion (#38522)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli authored Aug 17, 2023
1 parent d9a12c8 commit a2ef8a6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 48 deletions.
14 changes: 1 addition & 13 deletions docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() => ({
Expand Down Expand Up @@ -513,13 +508,7 @@ export default function Demo(props) {
return (
<Root>
<AnchorLink id={demoName} />
<DemoRoot
hideToolbar={demoOptions.hideToolbar}
bg={demoOptions.bg}
id={demoId}
onMouseEnter={handleDemoHover}
onMouseLeave={handleDemoHover}
>
<DemoRoot hideToolbar={demoOptions.hideToolbar} bg={demoOptions.bg} id={demoId}>
<Wrapper {...(demoData.productId === 'joy-ui' && { mode })}>
<InitialFocus
aria-label={t('initialFocusLabel')}
Expand Down Expand Up @@ -558,7 +547,6 @@ export default function Demo(props) {
hasNonSystemDemos={hasNonSystemDemos}
demo={demo}
demoData={demoData}
demoHovered={demoHovered}
demoId={demoId}
demoName={demoName}
demoOptions={demoOptions}
Expand Down
36 changes: 1 addition & 35 deletions docs/src/modules/components/DemoToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import copy from 'clipboard-copy';
import { useTheme, styled, alpha } from '@mui/material/styles';
import IconButton from '@mui/material/IconButton';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import useMediaQuery from '@mui/material/useMediaQuery';
import CheckIcon from '@mui/icons-material/Check';
import Fade from '@mui/material/Fade';
import MDButton from '@mui/material/Button';
Expand All @@ -22,7 +21,6 @@ import RefreshRoundedIcon from '@mui/icons-material/RefreshRounded';
import ResetFocusIcon from '@mui/icons-material/CenterFocusWeak';
import ContentCopyRoundedIcon from '@mui/icons-material/ContentCopyRounded';
import { useRouter } from 'next/router';
import { getCookie } from 'docs/src/modules/utils/helpers';
import { CODE_VARIANTS, CODE_STYLING } from 'docs/src/modules/constants';
import { useSetCodeVariant } from 'docs/src/modules/utils/codeVariant';
import { useSetCodeStyling, useCodeStyling } from 'docs/src/modules/utils/codeStylingSolution';
Expand Down Expand Up @@ -65,24 +63,6 @@ function DemoTooltip(props) {
);
}

function ToggleCodeTooltip(props) {
const { showSourceHint, ...other } = props;
const atLeastSmallViewport = useMediaQuery((theme) => theme.breakpoints.up('sm'));
const [open, setOpen] = React.useState(false);

return (
<DemoTooltip
{...other}
onClose={() => setOpen(false)}
onOpen={() => setOpen(true)}
open={showSourceHint && atLeastSmallViewport ? true : open}
/>
);
}
ToggleCodeTooltip.propTypes = {
showSourceHint: PropTypes.bool,
};

const alwaysTrue = () => true;

const ToggleButtonGroup = styled(MDToggleButtonGroup)(({ theme }) => [
Expand Down Expand Up @@ -297,7 +277,6 @@ export default function DemoToolbar(props) {
demo,
demoData,
demoId,
demoHovered,
demoName,
demoOptions,
demoSourceId,
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a2ef8a6

Please sign in to comment.