@angulogic/ng-sidebar
Version:
angular sidebar
115 lines (114 loc) • 4.38 kB
TypeScript
import { MenuData, SidebarData, SidebarModel } from './sidebar.model';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import * as i0 from "@angular/core";
/**
* Service responsible for managing sidebar state, configurations, and behaviors.
* It handles sidebar initialization, resizing, menu interactions, and theme changes.
*
* @export
* @class NgSidebarService
*/
export declare class NgSidebarService {
router: Router;
private http;
/**
* Tracks whether auto-positioning is enabled.
* @default false
*/
autoPositionActive: boolean;
/**
* Indicates whether the sidebar is currently being resized.
* @default false
*/
isResizing: boolean;
/**
* Stores the complete sidebar configuration and data.
*/
sidebarData: SidebarModel;
/**
* MutationObserver to monitor sidebar style changes for auto-positioning.
*/
private observer;
/**
* Initializes the sidebar service and listens for route changes.
*
* @param {Router} router - Angular Router for detecting navigation events.
* @param {HttpClient} http - Angular HttpClient for loading assets (e.g., SVG icons).
*/
constructor(router: Router, http: HttpClient);
/**
* Initializes the sidebar configuration with default values if not provided.
*
* @param {Partial<SidebarModel> & { sidebarData: SidebarData[] }} data - Sidebar data with optional configurations.
* @returns {SidebarModel} - The complete SidebarModel with default values applied.
*/
initilazeSidebarData(data: Partial<SidebarModel> & {
sidebarData: SidebarData[];
}): SidebarModel;
/**
* Enables automatic positioning of the sidebar.
* It observes the sidebar's width and updates the CSS variable `--sidebar-width` dynamically.
*/
setAutoPosition(): void;
/**
* Animates the width update of the sidebar.
*
* @param {HTMLElement} divElement - The sidebar element whose width is being updated.
* @param {number} startTime - The start time of the animation.
* @param {number} duration - The duration of the width animation in milliseconds.
*/
updateWidth(divElement: HTMLElement, startTime: number, duration: number): void;
/**
* Disables automatic positioning of the sidebar.
* Stops observing style changes and resets CSS modifications.
*/
destroyAutoPosition(): void;
/**
* Handles sidebar resizing using mouse events.
*
* @param {SidebarModel} sidebarData - The sidebar configuration object.
*/
resize(sidebarData: SidebarModel): void;
/**
* Initializes menu data by assigning default values if not provided.
*
* @param {MenuData[]} menuData - The menu data array to initialize.
* @returns {MenuData[]} - The processed menu data with default values applied.
*/
private initializeMenuData;
/**
* Searches for menu items by name within the sidebar data.
*
* @param {SidebarModel} data - The sidebar configuration containing menu data.
* @param {string} searchValue - The search query entered by the user.
* @returns {MenuData[]} - An array of matching menu items.
*/
searchByName(data: SidebarModel, searchValue: string): MenuData[];
/**
* Updates the active state of menu items based on the current route.
*
* @param {MenuData[]} menuData - The menu data array to update.
* @param {string} currentRoute - The current active route.
*/
updateActiveState(menuData: MenuData[], currentRoute: string): void;
/**
* Toggles the sidebar theme between 'light' and 'dark'.
* Updates the `theme` property in `sidebarData.options`.
*/
changeTheme(): void;
/**
* Loads an SVG file from the given path.
*
* @param {string} path - The file path of the SVG to load.
* @returns {Promise<string>} - A promise resolving to the SVG content.
*/
loadSvg(path: string): Promise<string>;
/**
* Toggles the sidebar's expanded or collapsed state.
* Triggers the appropriate expand/collapse event if provided.
*/
toggleSidebar(): Promise<void>;
static ɵfac: i0.ɵɵFactoryDeclaration<NgSidebarService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<NgSidebarService>;
}