Files
ISA-Frontend/libs/shell/common/src/lib/navigation.service.ts
Lorenz Hilpert 5bebd3de4d feat(shell): add logging and JSDoc documentation across shell components
- Add @isa/core/logging to services and components with actions
- Add comprehensive JSDoc documentation with @example blocks
- Fix typo: TabsCollabsedService → TabsCollapsedService
- Add error handling with try/catch for async operations
- Add tap operator for logging in NetworkStatusService
2025-12-10 20:36:58 +01:00

48 lines
1.4 KiB
TypeScript

import { Injectable, signal } from '@angular/core';
import { logger } from '@isa/core/logging';
/**
* Service for managing the navigation sidebar visibility state.
*
* Controls whether the sidebar navigation panel is open or closed,
* primarily used for responsive mobile/tablet layouts where the
* navigation can be toggled via a hamburger menu.
*
* @example
* ```typescript
* readonly navigationService = inject(NavigationService);
*
* // Check if navigation is open
* const isOpen = this.navigationService.get();
*
* // Toggle navigation
* this.navigationService.toggle();
*
* // Explicitly set state
* this.navigationService.set(false); // Close navigation
* ```
*/
@Injectable({ providedIn: 'root' })
export class NavigationService {
#logger = logger({ service: 'NavigationService' });
#state = signal<boolean>(false);
/** Readonly signal exposing the current navigation open/closed state. */
readonly get = this.#state.asReadonly();
/** Toggles the navigation state between open and closed. */
toggle(): void {
this.#state.update((state) => !state);
this.#logger.debug('Navigation toggled', () => ({ isOpen: this.#state() }));
}
/**
* Sets the navigation visibility state.
* @param state - True to open navigation, false to close
*/
set(state: boolean): void {
this.#logger.debug('Navigation state set', () => ({ state }));
this.#state.set(state);
}
}