diff --git a/code/ui/manager/src/components/mobile/MobileLayoutProvider.tsx b/code/ui/manager/src/components/mobile/MobileLayoutProvider.tsx index 05c9c5219ab6..c93c14ec6cf6 100644 --- a/code/ui/manager/src/components/mobile/MobileLayoutProvider.tsx +++ b/code/ui/manager/src/components/mobile/MobileLayoutProvider.tsx @@ -2,6 +2,8 @@ import type { FC } from 'react'; import React, { createContext, useContext, useState } from 'react'; type MobileLayoutContextType = { + isMobileMenuOpen: boolean; + setMobileMenuOpen: React.Dispatch>; isMobileAboutOpen: boolean; setMobileAboutOpen: React.Dispatch>; isMobilePanelOpen: boolean; @@ -9,6 +11,8 @@ type MobileLayoutContextType = { }; const MobileLayoutContext = createContext({ + isMobileMenuOpen: false, + setMobileMenuOpen: () => {}, isMobileAboutOpen: false, setMobileAboutOpen: () => {}, isMobilePanelOpen: false, @@ -16,12 +20,20 @@ const MobileLayoutContext = createContext({ }); export const MobileLayoutProvider: FC = ({ children }) => { + const [isMobileMenuOpen, setMobileMenuOpen] = useState(false); const [isMobileAboutOpen, setMobileAboutOpen] = useState(false); const [isMobilePanelOpen, setMobilePanelOpen] = useState(false); return ( {children} diff --git a/code/ui/manager/src/components/mobile/about/MobileAbout.tsx b/code/ui/manager/src/components/mobile/about/MobileAbout.tsx index 8531e0f14cd3..a2354aa11783 100644 --- a/code/ui/manager/src/components/mobile/about/MobileAbout.tsx +++ b/code/ui/manager/src/components/mobile/about/MobileAbout.tsx @@ -72,7 +72,7 @@ const Container = styled.div<{ state: TransitionStatus; transitionDuration: numb zIndex: 11, transition: `all ${transitionDuration}ms ease-in-out`, overflow: 'scroll', - padding: '20px', + padding: '25px 10px 10px', color: theme.color.defaultText, background: theme.background.content, opacity: `${(() => { diff --git a/code/ui/manager/src/components/mobile/navigation/MobileMenuDrawer.tsx b/code/ui/manager/src/components/mobile/navigation/MobileMenuDrawer.tsx index f3f79fe790a3..1dcefed3a5d0 100644 --- a/code/ui/manager/src/components/mobile/navigation/MobileMenuDrawer.tsx +++ b/code/ui/manager/src/components/mobile/navigation/MobileMenuDrawer.tsx @@ -5,39 +5,36 @@ import { Transition } from 'react-transition-group'; import type { TransitionStatus } from 'react-transition-group/Transition'; import { MobileAbout } from '../about/MobileAbout'; import { MOBILE_TRANSITION_DURATION } from '../../../constants'; +import { useMobileLayoutContext } from '../MobileLayoutProvider'; interface MobileMenuDrawerProps { - isMenuOpen: boolean; - isAboutOpen: boolean; - setAboutOpen: (open: boolean) => void; - closeMenu: () => void; children?: React.ReactNode; } -export const MobileMenuDrawer: FC = ({ - isMenuOpen, - isAboutOpen, - setAboutOpen, - closeMenu, - children, -}) => { +export const MobileMenuDrawer: FC = ({ children }) => { const containerRef = useRef(null); const sidebarRef = useRef(null); const overlayRef = useRef(null); + const { isMobileMenuOpen, setMobileMenuOpen, isMobileAboutOpen, setMobileAboutOpen } = + useMobileLayoutContext(); return ( <> setAboutOpen(false)} + onExited={() => setMobileAboutOpen(false)} > {(state) => ( - + {(sidebarState) => ( {children} @@ -50,7 +47,7 @@ export const MobileMenuDrawer: FC = ({ = ({ setMobileMenuOpen(false)} aria-label="Close navigation menu" /> )} diff --git a/code/ui/manager/src/components/mobile/navigation/MobileNavigation.tsx b/code/ui/manager/src/components/mobile/navigation/MobileNavigation.tsx index b4615172fdd7..e402982ae612 100644 --- a/code/ui/manager/src/components/mobile/navigation/MobileNavigation.tsx +++ b/code/ui/manager/src/components/mobile/navigation/MobileNavigation.tsx @@ -1,5 +1,5 @@ import type { FC } from 'react'; -import React, { useState } from 'react'; +import React from 'react'; import { styled } from '@storybook/theming'; import { IconButton, Icons } from '@storybook/components'; import { useStorybookApi, useStorybookState } from '@storybook/manager-api'; @@ -35,22 +35,14 @@ const useFullStoryName = () => { }; export const MobileNavigation: FC = ({ menu, panel, showPanel }) => { - const [isMenuOpen, setMenuOpen] = useState(false); - const { isMobileAboutOpen, setMobileAboutOpen, setMobilePanelOpen } = useMobileLayoutContext(); + const { isMobileMenuOpen, setMobileMenuOpen, setMobilePanelOpen } = useMobileLayoutContext(); const fullStoryName = useFullStoryName(); return ( - setMenuOpen(false)} - > - {menu} - + {menu} {panel} - diff --git a/code/ui/manager/src/components/sidebar/Sidebar.tsx b/code/ui/manager/src/components/sidebar/Sidebar.tsx index a057bc69a102..068e28d42808 100644 --- a/code/ui/manager/src/components/sidebar/Sidebar.tsx +++ b/code/ui/manager/src/components/sidebar/Sidebar.tsx @@ -20,26 +20,27 @@ import { Search } from './Search'; import { SearchResults } from './SearchResults'; import type { Refs, CombinedDataset, Selection } from './types'; import { useLastViewed } from './useLastViewed'; +import { BREAKPOINT_MIN_600 } from '../../constants'; export const DEFAULT_REF_ID = 'storybook_internal'; -const Container = styled.nav( - { - position: 'absolute', - zIndex: 1, - left: 0, - top: 0, - bottom: 0, - right: 0, - width: '100%', - height: '100%', - display: 'flex', - flexDirection: 'column', - }, - ({ theme }) => ({ +const Container = styled.nav(({ theme }) => ({ + position: 'absolute', + zIndex: 1, + left: 0, + top: 0, + bottom: 0, + right: 0, + width: '100%', + height: '100%', + display: 'flex', + flexDirection: 'column', + background: theme.background.content, + + [`@media ${BREAKPOINT_MIN_600}`]: { background: theme.background.app, - }) -); + }, +})); const Top = styled(Spaced)({ padding: 20, diff --git a/code/ui/manager/src/components/sidebar/Tree.tsx b/code/ui/manager/src/components/sidebar/Tree.tsx index e329310e6b88..abc89b630bc4 100644 --- a/code/ui/manager/src/components/sidebar/Tree.tsx +++ b/code/ui/manager/src/components/sidebar/Tree.tsx @@ -36,6 +36,9 @@ import { getLink, } from '../../utils/tree'; import { statusMapping, getHighestStatus, getGroupStatus } from '../../utils/status'; +import { useMediaQuery } from '../hooks/useMedia'; +import { BREAKPOINT_MIN_600 } from '../../constants'; +import { useMobileLayoutContext } from '../mobile/MobileLayoutProvider'; export const Action = styled.button<{ height?: number; width?: number }>( ({ theme, height, width }) => ({ @@ -201,6 +204,9 @@ const Node = React.memo(function Node({ onSelectStoryId, api, }) { + const isDesktop = useMediaQuery(BREAKPOINT_MIN_600); + const { setMobileMenuOpen } = useMobileLayoutContext(); + if (!isDisplayed) { return null; } @@ -231,6 +237,7 @@ const Node = React.memo(function Node({ onClick={(event) => { event.preventDefault(); onSelectStoryId(item.id); + if (!isDesktop) setMobileMenuOpen(false); }} {...(item.type === 'docs' && { docsMode })} > @@ -329,7 +336,7 @@ const Node = React.memo(function Node({ onClick={(event) => { event.preventDefault(); setExpanded({ ids: [item.id], value: !isExpanded }); - if (item.type === 'component' && !isExpanded) onSelectStoryId(item.id); + if (item.type === 'component' && !isExpanded && isDesktop) onSelectStoryId(item.id); }} onMouseEnter={() => { if (item.isComponent) { diff --git a/code/ui/manager/src/components/upgrade/UpgradeBlock.tsx b/code/ui/manager/src/components/upgrade/UpgradeBlock.tsx index ee29b6b3d16a..feb54ff3c7e4 100644 --- a/code/ui/manager/src/components/upgrade/UpgradeBlock.tsx +++ b/code/ui/manager/src/components/upgrade/UpgradeBlock.tsx @@ -3,6 +3,7 @@ import React, { useState } from 'react'; import { styled } from '@storybook/theming'; import { useStorybookApi } from '@storybook/manager-api'; import { Link } from '@storybook/components'; +import { BREAKPOINT_MIN_600 } from '../../constants'; interface UpgradeBlockProps { onNavigateToWhatsNew?: () => void; @@ -40,10 +41,13 @@ const Container = styled.div(({ theme }) => ({ borderRadius: 5, padding: 20, marginTop: 0, - maxWidth: 400, borderColor: theme.appBorderColor, fontSize: theme.typography.size.s2, width: '100%', + + [`@media ${BREAKPOINT_MIN_600}`]: { + maxWidth: 400, + }, })); const Tabs = styled.div({