Skip to content

Global header: Add extension with a button to toggle sidebar pin mode #4754

Description

@christoph-jerolimov

Add a new Backstage extension (new frontend system only) to the global-header workspace that allow the user to toggle the sidebar pin mode.

What exists today

  • The "Pin Sidebar" switch on the settings page just calls useSidebarPinState(), which returns isPinned, toggleSidebarPinState and isMobile. That hook is public and usable anywhere.
  • There is also a built-in SidebarExpandButton component. It toggles open state via useSidebarOpenState(), not pin state. Clicking it opens the sidebar, but it will collapse again on mouse leave if not pinned, so it is not the same as the settings switch.

How to add it

A small component rendered as Global header extension, on the first position.

import { ButtonIcon } from '@backstage/ui';
import { useSidebarPinState } from '@backstage/core-components';
import { RiCloseLine } from '@remixicon/react';

const SidebarPinToggle = () => {
  const { isPinned, toggleSidebarPinState, isMobile } = useSidebarPinState();
  if (isMobile) return null;
  return (
    <ButtonIcon
      icon={<RiCloseLine />}
      variant="tertiary"
      size="medium"
      aria-label={isPinned ? 'Unpin sidebar' : 'Pin sidebar'}
      onClick={toggleSidebarPinState}
    />
  );
};

Ensure that the SidebarPinToggle is shown as first extension in the header, before the icon.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions