/** * * The useSidebar manages the state and functionality of a sidebar component. * * [Live Demo](https://www.primereact.org/sidebar/) * * @module useSidebar * @group headless * */ import type { HeadlessInstance } from '@primereact/types/core'; import type { UseSidebarLayoutExposes } from './useSidebarLayout.types'; /** * Sidebar position. */ export type SidebarSide = 'left' | 'right'; /** * Visual variant of the sidebar. */ export type SidebarVariant = 'sidebar' | 'floating' | 'inset'; /** * Collapse behavior of the sidebar. */ export type SidebarCollapsible = 'offcanvas' | 'icon' | 'none'; /** * Event fired when the sidebar's open state changes. */ export interface UseSidebarOpenChangeEvent { /** * The original event that triggered the change, if any. */ originalEvent?: E | undefined; /** * The value of the sidebar open state. */ value: boolean | undefined; } /** * Defines valid properties in useSidebar. */ export interface UseSidebarProps { /** * Layout context for registering/notifying within a Sidebar.Layout. */ layout?: UseSidebarLayoutExposes | null | undefined; /** * Unique identifier for the sidebar, used by Trigger target. */ id?: string | undefined; /** * Sidebar position. * @default 'left' */ side?: SidebarSide | undefined; /** * Visual variant of the sidebar. * @default 'sidebar' */ variant?: SidebarVariant | undefined; /** * Collapse behavior. * @default 'icon' */ collapsible?: SidebarCollapsible | undefined; /** * Whether the sidebar overlays content instead of pushing it. * @default false */ overlay?: boolean | undefined; /** * Controls the open state of the sidebar. */ open?: boolean | undefined; /** * Initial open state. * @default true */ defaultOpen?: boolean | undefined; /** * Callback when the open state changes. */ onOpenChange?: ((event: UseSidebarOpenChangeEvent) => void) | undefined; /** * Whether the sidebar opens on hover. * @default false */ openOnHover?: boolean | undefined; /** * Delay before opening on hover (ms). * @default 50 */ hoverOpenDelay?: number | undefined; /** * Delay before closing on hover leave (ms). * @default 100 */ hoverCloseDelay?: number | undefined; /** * Whether clicking the backdrop closes the sidebar. * @default true */ dismissable?: boolean | undefined; /** * When `overlay` is true, clicking inside the `Sidebar.Main` area collapses the sidebar. * Clicks on a `Sidebar.Trigger` are excluded so opening via the trigger is not immediately undone. * @default true */ hideOnOutsideClick?: boolean | undefined; /** * When `overlay` is true, pressing Escape collapses the sidebar. * @default true */ closeOnEscape?: boolean | undefined; /** * Sidebar width when expanded. * @default '16rem' */ width?: string | undefined; /** * Sidebar width when collapsed to icon mode. * @default '3rem' */ iconWidth?: string | undefined; } /** * Defines valid state in useSidebar. */ export interface UseSidebarState { /** * Whether the sidebar is open. */ open: boolean; /** * The current display state. */ displayState: 'expanded' | 'collapsed'; } /** * Pre-built props for the sidebar root element. */ export interface UseSidebarRootProps { /** * Ref callback for the root element. */ ref: (node: HTMLElement | null) => void; /** * The sidebar id, when provided. */ id?: string; /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The configured collapsible mode. */ 'data-collapsible-mode': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; /** * Dialog role while the sidebar is a modal overlay. */ role?: 'dialog'; /** * Modal flag while the overlay is open. */ 'aria-modal'?: boolean; /** * Inline CSS custom properties for the sidebar sizing. */ style: React.CSSProperties; /** * Keydown handler (escape close + menu tree navigation). */ onKeyDown: (event: React.KeyboardEvent) => void; /** * Pointer-enter handler, present when openOnHover is enabled. */ onPointerEnter?: (event?: React.SyntheticEvent) => void; /** * Pointer-leave handler, present when openOnHover is enabled. */ onPointerLeave?: (event?: React.SyntheticEvent) => void; } /** * Pre-built props for the sidebar spacer element. */ export interface UseSidebarSpacerProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar aside element. */ export interface UseSidebarAsideProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar panel element. */ export interface UseSidebarPanelProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar content element. */ export interface UseSidebarContentProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar header element. */ export interface UseSidebarHeaderProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar footer element. */ export interface UseSidebarFooterProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar trigger element. */ export interface UseSidebarTriggerProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; /** * Whether the sidebar is currently open. */ 'aria-expanded': boolean; /** * Id of the controlled sidebar, when set. */ 'aria-controls'?: string; /** * Toggles the sidebar open state. */ onClick: (event?: React.SyntheticEvent) => void; } /** * Pre-built props for the sidebar rail element. */ export interface UseSidebarRailProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Accessible label for the rail toggle. */ 'aria-label': string; /** * Tooltip title for the rail toggle. */ title: string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; /** * Toggles the sidebar open state. */ onClick: (event?: React.SyntheticEvent) => void; } /** * Pre-built props for the sidebar main element. */ export interface UseSidebarMainProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Reflects the expanded/collapsed display state. */ 'data-state': string; /** * Active collapsible mode while collapsed, otherwise empty. */ 'data-collapsible': string | undefined; /** * The sidebar variant. */ 'data-variant': string | undefined; /** * The sidebar side. */ 'data-side': string | undefined; /** * Present while the sidebar is an overlay. */ 'data-overlay'?: string; } /** * Pre-built props for the sidebar backdrop element. */ export interface UseSidebarBackdropProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Collapses the sidebar when dismissable. */ onClick?: (event?: React.SyntheticEvent) => void; } /** * Pre-built props for the sidebar menu element. */ export interface UseSidebarMenuProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar menu item element. */ export interface UseSidebarMenuItemElementProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar menu button element. */ export interface UseSidebarMenuButtonProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Marks the button as a keyboard-navigable tree item. */ 'data-menu-item': string; /** * Present when the button represents the active item. */ 'data-active'?: boolean; } /** * Pre-built props for the sidebar menu action element. */ export interface UseSidebarMenuActionProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Present when the action is only shown on hover/focus. */ 'data-show-on-hover'?: string; } /** * Pre-built props for the sidebar menu badge element. */ export interface UseSidebarMenuBadgeProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar menu sub element. */ export interface UseSidebarMenuSubProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar menu sub item element. */ export interface UseSidebarMenuSubItemProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar menu sub button element. */ export interface UseSidebarMenuSubButtonProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Marks the button as a keyboard-navigable tree item. */ 'data-menu-item': string; /** * Present when the button represents the active item. */ 'data-active'?: boolean; /** * The sub button size. */ 'data-size': string | undefined; } /** * Pre-built props for the sidebar group element. */ export interface UseSidebarGroupProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar group label element. */ export interface UseSidebarGroupLabelProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar group content element. */ export interface UseSidebarGroupContentProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Pre-built props for the sidebar group action element. */ export interface UseSidebarGroupActionProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; } /** * Defines the methods and properties exposed by useSidebar. */ export interface UseSidebarExposes { /** * The state of the useSidebar. */ state: UseSidebarState; /** * Toggles the sidebar open state. * @param event The event that triggered the toggle. */ toggle: (event?: React.SyntheticEvent) => void; /** * Opens the sidebar. * @param event The event that triggered the change. */ expand: (event?: React.SyntheticEvent) => void; /** * Collapses the sidebar. * @param event The event that triggered the change. */ collapse: (event?: React.SyntheticEvent) => void; /** * Pre-built props for the root element. */ rootProps: UseSidebarRootProps; /** * Pre-built props for the spacer element. */ spacerProps: UseSidebarSpacerProps; /** * Pre-built props for the aside element. */ asideProps: UseSidebarAsideProps; /** * Pre-built props for the panel element. */ panelProps: UseSidebarPanelProps; /** * Pre-built props for the content element. */ contentProps: UseSidebarContentProps; /** * Pre-built props for the header element. */ headerProps: UseSidebarHeaderProps; /** * Pre-built props for the footer element. */ footerProps: UseSidebarFooterProps; /** * Pre-built props for the trigger element. */ triggerProps: UseSidebarTriggerProps; /** * Pre-built props for the rail element. */ railProps: UseSidebarRailProps; /** * Pre-built props for the main element. */ mainProps: UseSidebarMainProps; /** * Pre-built props for the backdrop element. */ backdropProps: UseSidebarBackdropProps; /** * Pre-built props for the menu element. */ menuProps: UseSidebarMenuProps; /** * Pre-built props for the menu item element. */ menuItemProps: UseSidebarMenuItemElementProps; /** * Gets the pre-built props for a menu button element. * @param isActive Whether the button represents the active item. */ getMenuButtonProps: (isActive?: boolean) => UseSidebarMenuButtonProps; /** * Gets the pre-built props for a menu action element. * @param showOnHover Whether the action is only shown on hover/focus. */ getMenuActionProps: (showOnHover?: boolean) => UseSidebarMenuActionProps; /** * Pre-built props for the menu badge element. */ menuBadgeProps: UseSidebarMenuBadgeProps; /** * Pre-built props for the menu sub element. */ menuSubProps: UseSidebarMenuSubProps; /** * Pre-built props for the menu sub item element. */ menuSubItemProps: UseSidebarMenuSubItemProps; /** * Gets the pre-built props for a menu sub button element. * @param isActive Whether the button represents the active item. * @param size The sub button size. */ getMenuSubButtonProps: (isActive?: boolean, size?: string) => UseSidebarMenuSubButtonProps; /** * Pre-built props for the group element. */ groupProps: UseSidebarGroupProps; /** * Pre-built props for the group label element. */ groupLabelProps: UseSidebarGroupLabelProps; /** * Pre-built props for the group content element. */ groupContentProps: UseSidebarGroupContentProps; /** * Pre-built props for the group action element. */ groupActionProps: UseSidebarGroupActionProps; /** * The sidebar variant. */ variant: 'sidebar' | 'floating' | 'inset' | undefined; /** * The collapse behavior. */ collapsible: 'offcanvas' | 'icon' | 'none' | undefined; /** * The sidebar side. */ side: 'left' | 'right' | undefined; /** * Whether the sidebar overlays the content. */ overlay: boolean | undefined; /** * Whether the sidebar opens on hover. */ openOnHover: boolean | undefined; } /** * Instance of useSidebar headless. */ export type UseSidebarInstance = HeadlessInstance;