import { Fragment, useState, useCallback, useEffect } from 'react'; import { HashRouter, useNavigate } from 'react-router-dom'; import { Willow } from '@svar-ui/react-core'; import Router from './Router'; import Link from './Link'; import { links, flatLinks } from '../routes'; import { GitHubLogoIcon, LogoIcon } from '../assets/icons'; import './Index.css'; const MOBILE_BREAKPOINT = 767; function DemoExplorerContent({ productTag, productLink, publicName, skins, Globals, Button, Segmented, }) { const navigate = useNavigate(); const [skin, setSkin] = useState(skins[0].id); const [title, setTitle] = useState(''); const [githubLink, setGithubLink] = useState(''); const [show, setShow] = useState(true); const [innerWidth, setInnerWidth] = useState(window.innerWidth); const isMobileView = innerWidth <= MOBILE_BREAKPOINT; const baseLink = 'https://github.com/svar-widgets/react-' + productTag + '/tree/main/demos/cases/'; useEffect(() => { const handleResize = () => setInnerWidth(window.innerWidth); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); useEffect(() => { if (isMobileView && title) { setShow(false); } }, [isMobileView, title]); const handleRouteChange = useCallback( (path) => { const parts = path.split('/'); const page = parts[1]; const newSkin = parts[2]; setSkin(newSkin); const targetPage = `/${page}/:skin`; const matched = flatLinks.find((a) => a[0] === targetPage); if (matched) { setTitle(matched[1]); const name = matched[3]?.file ?? matched[1]; setGithubLink(`${baseLink}${name.replace(/\s+/g, '')}.jsx`); } }, [], ); const handleSkinChange = ({ value }) => { setSkin(value); const currentPath = window.location.hash.slice(1); const parts = currentPath.split('/'); if (parts[1]) { navigate(`/${parts[1]}/${value}`); } }; const toggleSidebar = () => { setShow(!show); }; const SkinComponent = skins.find((s) => s.id === skin).Component; return (