UNPKG

@grafana/ui

Version:
66 lines (65 loc) 2.88 kB
import React from 'react'; export type SidebarPosition = 'left' | 'right'; export interface SidebarContextValue { isDocked: boolean; position: SidebarPosition; compact: boolean; hasOpenPane?: boolean; tabsMode?: boolean; outerWrapperProps: React.HTMLAttributes<HTMLDivElement>; paneWidth: number; bottomMargin: number; edgeMargin: number; contentMargin: number; isHidden: boolean; isHiddenPreference: boolean; canGoBack?: boolean; onToggleDock?: () => void; onResize: (diff: number) => void; /** Called when pane is closed or clicked outside of (in undocked mode) */ onClosePane?: () => void; /** Open previous pane */ onGoBack?: () => void; onToggleIsHidden: () => void; setIsHidden: (value: boolean) => void; } export declare const SidebarContext: React.Context<SidebarContextValue | undefined>; export declare const useSidebarContext: () => SidebarContextValue | undefined; export interface UseSideBarOptions { hasOpenPane?: boolean; position?: SidebarPosition; tabsMode?: boolean; /** Initial state for compact mode */ defaultToCompact?: boolean; /** Initial state for docked mode */ defaultToDocked?: boolean; /** defaults to 2 grid units (16px) */ bottomMargin?: number; /** defaults to 2 grid units (16px) */ edgeMargin?: number; /** defaults to 2 grid units (16px) */ contentMargin?: number; /** Called when pane is closed or clicked outside of (in undocked mode) */ onClosePane?: () => void; /** Disables go back button */ canGoBack?: boolean; /** Open previous pane */ onGoBack?: () => void; /** * Optional key to use for persisting sidebar state (docked / compact / size) * Can only be app name as the final local storag key will be `grafana.ui.sidebar.{persistenceKey}.{docked|compact|size}` */ persistenceKey?: string; /** Whether the sidebar is hidden by default */ defaultIsHidden?: boolean; /** * Optional override for the persistance key used to store the hidden state. * Allows the hidden preference to be shared across consumers that otherwise use different * persistenceKeys (e.g. dashboard view vs edit mode share a single hide preference). */ hiddenPersistenceKey?: string; } export declare const SIDE_BAR_WIDTH_ICON_ONLY = 5; export declare const SIDE_BAR_WIDTH_WITH_TEXT = 8; export declare function useSidebar({ hasOpenPane, position, tabsMode, defaultToCompact, defaultToDocked, bottomMargin, edgeMargin, contentMargin, persistenceKey, onClosePane, onGoBack, canGoBack, defaultIsHidden, hiddenPersistenceKey, }: UseSideBarOptions): SidebarContextValue; export declare function useSidebarSavedState<T = number | boolean>(persistenceKey: string | undefined, subKey: string, defaultValue: T): readonly [T, (cb: (prevState: T) => T) => void];