diff --git a/packages/app/src/components/search/SearchPage.tsx b/packages/app/src/components/search/SearchPage.tsx index 8cd1b85d2a..9a8c208103 100644 --- a/packages/app/src/components/search/SearchPage.tsx +++ b/packages/app/src/components/search/SearchPage.tsx @@ -21,7 +21,7 @@ import { Header, Lifecycle, Page, - SidebarStateContext, + SidebarPinStateContext, } from '@backstage/core-components'; import { CatalogResultListItem } from '@backstage/plugin-catalog'; import { @@ -53,7 +53,7 @@ const useStyles = makeStyles((theme: Theme) => ({ const SearchPage = () => { const classes = useStyles(); - const { isMobile } = useContext(SidebarStateContext); + const { isMobile } = useContext(SidebarPinStateContext); return ( diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index c2244e686d..f10d7102c9 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -897,7 +897,7 @@ export const SidebarContext: Context; // @public export type SidebarContextType = { isOpen: boolean; - setOpen?: (open: boolean) => void; + setOpen: (open: boolean) => void; }; // Warning: (ae-missing-release-tag) "SidebarDivider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -1244,6 +1244,16 @@ export type SidebarPageProps = { children?: React_2.ReactNode; }; +// @public +export const SidebarPinStateContext: React_2.Context; + +// @public +export type SidebarPinStateContextType = { + isPinned: boolean; + toggleSidebarPinState: () => any; + isMobile?: boolean; +}; + // @public (undocumented) export type SidebarProps = { openDelayMs?: number; @@ -2075,16 +2085,6 @@ export const SidebarSpacer: React_2.ComponentType< // @public (undocumented) export type SidebarSpacerClassKey = 'root'; -// @public -export const SidebarStateContext: React_2.Context; - -// @public -export type SidebarStateContextType = { - isPinned: boolean; - toggleSidebarPinState: () => any; - isMobile?: boolean; -}; - // @public export const SidebarSubmenu: (props: SidebarSubmenuProps) => JSX.Element; diff --git a/packages/core-components/src/layout/Sidebar/Bar.test.tsx b/packages/core-components/src/layout/Sidebar/Bar.test.tsx index 0e0a7d5aa2..89133997f9 100644 --- a/packages/core-components/src/layout/Sidebar/Bar.test.tsx +++ b/packages/core-components/src/layout/Sidebar/Bar.test.tsx @@ -27,14 +27,14 @@ import { SidebarExpandButton, SidebarItem, SidebarSearchField, - SidebarStateContext, + SidebarPinStateContext, SidebarSubmenu, SidebarSubmenuItem, } from '.'; async function renderScalableSidebar() { await renderInTestApp( - - , + , ); } diff --git a/packages/core-components/src/layout/Sidebar/Bar.tsx b/packages/core-components/src/layout/Sidebar/Bar.tsx index fe3964b745..ff907cdda3 100644 --- a/packages/core-components/src/layout/Sidebar/Bar.tsx +++ b/packages/core-components/src/layout/Sidebar/Bar.tsx @@ -20,7 +20,7 @@ import classnames from 'classnames'; import React, { useState, useContext, useRef } from 'react'; import { sidebarConfig, SidebarContext } from './config'; import { BackstageTheme } from '@backstage/theme'; -import { SidebarStateContext } from './Page'; +import { SidebarPinStateContext } from './Page'; import { MobileSidebar } from './MobileSidebar'; /** @public */ @@ -102,7 +102,9 @@ const DesktopSidebar = (props: SidebarProps) => { ); const [state, setState] = useState(State.Closed); const hoverTimerRef = useRef(); - const { isPinned, toggleSidebarPinState } = useContext(SidebarStateContext); + const { isPinned, toggleSidebarPinState } = useContext( + SidebarPinStateContext, + ); const handleOpen = () => { if (isPinned || disableExpandOnHover) { @@ -185,7 +187,7 @@ const DesktopSidebar = (props: SidebarProps) => { */ export const Sidebar = (props: SidebarProps) => { const { children, openDelayMs, closeDelayMs, disableExpandOnHover } = props; - const { isMobile } = useContext(SidebarStateContext); + const { isMobile } = useContext(SidebarPinStateContext); return isMobile ? ( {children} diff --git a/packages/core-components/src/layout/Sidebar/Items.tsx b/packages/core-components/src/layout/Sidebar/Items.tsx index ed090690f0..b16c9ad302 100644 --- a/packages/core-components/src/layout/Sidebar/Items.tsx +++ b/packages/core-components/src/layout/Sidebar/Items.tsx @@ -643,7 +643,7 @@ export const SidebarExpandButton = () => { { noSsr: true }, ); - if (isSmallScreen || !setOpen) { + if (isSmallScreen) { return null; } diff --git a/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx b/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx index 0761199c76..298c53fb8f 100644 --- a/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx +++ b/packages/core-components/src/layout/Sidebar/MobileSidebar.tsx @@ -187,7 +187,7 @@ export const MobileSidebar = (props: MobileSidebarProps) => { !sidebarGroups[selectedMenuItemIndex].props.to; return ( - + {} }}> diff --git a/packages/core-components/src/layout/Sidebar/Page.tsx b/packages/core-components/src/layout/Sidebar/Page.tsx index 9e5d897de6..f23a6fa3b6 100644 --- a/packages/core-components/src/layout/Sidebar/Page.tsx +++ b/packages/core-components/src/layout/Sidebar/Page.tsx @@ -43,11 +43,11 @@ const useStyles = makeStyles( ); /** - * Type of `SidebarStateContext` + * Type of `SidebarPinStateContext` * * @public */ -export type SidebarStateContextType = { +export type SidebarPinStateContextType = { isPinned: boolean; toggleSidebarPinState: () => any; isMobile?: boolean; @@ -67,11 +67,13 @@ export type SidebarPageProps = { * * @public */ -export const SidebarStateContext = createContext({ - isPinned: true, - toggleSidebarPinState: () => {}, - isMobile: false, -}); +export const SidebarPinStateContext = createContext( + { + isPinned: true, + toggleSidebarPinState: () => {}, + isMobile: false, + }, +); export function SidebarPage(props: SidebarPageProps) { const [isPinned, setIsPinned] = useState(() => @@ -91,7 +93,7 @@ export function SidebarPage(props: SidebarPageProps) { const classes = useStyles({ isPinned }); return ( -
{props.children}
-
+ ); } diff --git a/packages/core-components/src/layout/Sidebar/SidebarGroup.tsx b/packages/core-components/src/layout/Sidebar/SidebarGroup.tsx index fc451cd779..bc7688153a 100644 --- a/packages/core-components/src/layout/Sidebar/SidebarGroup.tsx +++ b/packages/core-components/src/layout/Sidebar/SidebarGroup.tsx @@ -22,7 +22,7 @@ import BottomNavigationAction, { import { makeStyles } from '@material-ui/core/styles'; import React, { useContext } from 'react'; import { useLocation } from 'react-router-dom'; -import { SidebarStateContext } from '.'; +import { SidebarPinStateContext } from '.'; import { Link } from '../../components'; import { sidebarConfig } from './config'; import { MobileSidebarContext } from './MobileSidebar'; @@ -120,7 +120,7 @@ const MobileSidebarGroup = (props: SidebarGroupProps) => { */ export const SidebarGroup = (props: SidebarGroupProps) => { const { children, to, label, icon, value } = props; - const { isMobile } = useContext(SidebarStateContext); + const { isMobile } = useContext(SidebarPinStateContext); return isMobile ? ( diff --git a/packages/core-components/src/layout/Sidebar/config.ts b/packages/core-components/src/layout/Sidebar/config.ts index 0ef5282997..c41db1f537 100644 --- a/packages/core-components/src/layout/Sidebar/config.ts +++ b/packages/core-components/src/layout/Sidebar/config.ts @@ -63,7 +63,7 @@ export const SIDEBAR_INTRO_LOCAL_STORAGE = */ export type SidebarContextType = { isOpen: boolean; - setOpen?: (open: boolean) => void; + setOpen: (open: boolean) => void; }; /** @@ -71,6 +71,7 @@ export type SidebarContextType = { */ export const SidebarContext = createContext({ isOpen: false, + setOpen: () => {}, }); export type SidebarItemWithSubmenuContextType = { diff --git a/packages/core-components/src/layout/Sidebar/index.ts b/packages/core-components/src/layout/Sidebar/index.ts index 61fbcd25ab..82becb667f 100644 --- a/packages/core-components/src/layout/Sidebar/index.ts +++ b/packages/core-components/src/layout/Sidebar/index.ts @@ -32,10 +32,10 @@ export type { export type { SidebarClassKey, SidebarProps } from './Bar'; export { SidebarPage, - SidebarStateContext as SidebarStateContext, + SidebarPinStateContext as SidebarPinStateContext, } from './Page'; export type { - SidebarStateContextType as SidebarStateContextType, + SidebarPinStateContextType as SidebarPinStateContextType, SidebarPageClassKey, SidebarPageProps, } from './Page'; diff --git a/plugins/techdocs/src/reader/components/Reader.tsx b/plugins/techdocs/src/reader/components/Reader.tsx index 424697f59d..57d2786af5 100644 --- a/plugins/techdocs/src/reader/components/Reader.tsx +++ b/plugins/techdocs/src/reader/components/Reader.tsx @@ -31,7 +31,7 @@ import { EntityName } from '@backstage/catalog-model'; import { useApi, configApiRef } from '@backstage/core-plugin-api'; import { scmIntegrationsApiRef } from '@backstage/integration-react'; import { BackstageTheme } from '@backstage/theme'; -import { SidebarStateContext } from '@backstage/core-components'; +import { SidebarPinStateContext } from '@backstage/core-components'; import { techdocsStorageApiRef } from '../../api'; @@ -146,7 +146,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => { const [dom, setDom] = useState(null); // sidebar pinned status to be used in computing CSS style injections - const { isPinned } = useContext(SidebarStateContext); + const { isPinned } = useContext(SidebarPinStateContext); const updateSidebarPosition = useCallback(() => { if (!dom || !sidebars) return; diff --git a/plugins/user-settings/src/components/General/UserSettingsAppearanceCard.tsx b/plugins/user-settings/src/components/General/UserSettingsAppearanceCard.tsx index 946d22a9f0..15ab93c6d0 100644 --- a/plugins/user-settings/src/components/General/UserSettingsAppearanceCard.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsAppearanceCard.tsx @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { InfoCard, SidebarStateContext } from '@backstage/core-components'; +import { InfoCard, SidebarPinStateContext } from '@backstage/core-components'; import { List } from '@material-ui/core'; import React, { useContext } from 'react'; import { UserSettingsPinToggle } from './UserSettingsPinToggle'; import { UserSettingsThemeToggle } from './UserSettingsThemeToggle'; export const UserSettingsAppearanceCard = () => { - const { isMobile } = useContext(SidebarStateContext); + const { isMobile } = useContext(SidebarPinStateContext); return ( diff --git a/plugins/user-settings/src/components/General/UserSettingsPinToggle.test.tsx b/plugins/user-settings/src/components/General/UserSettingsPinToggle.test.tsx index e2c9f23b91..b63ac85b10 100644 --- a/plugins/user-settings/src/components/General/UserSettingsPinToggle.test.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsPinToggle.test.tsx @@ -18,14 +18,14 @@ import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils'; import { fireEvent } from '@testing-library/react'; import React from 'react'; import { UserSettingsPinToggle } from './UserSettingsPinToggle'; -import { SidebarStateContext } from '@backstage/core-components'; +import { SidebarPinStateContext } from '@backstage/core-components'; describe('', () => { it('toggles the pin sidebar button', async () => { const mockToggleFn = jest.fn(); const rendered = await renderWithEffects( wrapInTestApp( - ', () => { }} > - , + , ), ); expect(rendered.getByText('Pin Sidebar')).toBeInTheDocument(); diff --git a/plugins/user-settings/src/components/General/UserSettingsPinToggle.tsx b/plugins/user-settings/src/components/General/UserSettingsPinToggle.tsx index 1cfd8b06dd..4d71df8113 100644 --- a/plugins/user-settings/src/components/General/UserSettingsPinToggle.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsPinToggle.tsx @@ -22,10 +22,12 @@ import { Switch, Tooltip, } from '@material-ui/core'; -import { SidebarStateContext } from '@backstage/core-components'; +import { SidebarPinStateContext } from '@backstage/core-components'; export const UserSettingsPinToggle = () => { - const { isPinned, toggleSidebarPinState } = useContext(SidebarStateContext); + const { isPinned, toggleSidebarPinState } = useContext( + SidebarPinStateContext, + ); return ( diff --git a/plugins/user-settings/src/components/SettingsPage.tsx b/plugins/user-settings/src/components/SettingsPage.tsx index b1bfdb5fc9..88b46fc372 100644 --- a/plugins/user-settings/src/components/SettingsPage.tsx +++ b/plugins/user-settings/src/components/SettingsPage.tsx @@ -17,7 +17,7 @@ import { Header, Page, - SidebarStateContext, + SidebarPinStateContext, TabbedLayout, } from '@backstage/core-components'; import React, { useContext } from 'react'; @@ -30,7 +30,7 @@ type Props = { }; export const SettingsPage = ({ providerSettings }: Props) => { - const { isMobile } = useContext(SidebarStateContext); + const { isMobile } = useContext(SidebarPinStateContext); return (