Skip to content

feat(services): add ItBreakpointService with Angular Signals#690

Open
giulio-leone wants to merge 2 commits into
italia:mainfrom
giulio-leone:feat/576-breakpoint-signal
Open

feat(services): add ItBreakpointService with Angular Signals#690
giulio-leone wants to merge 2 commits into
italia:mainfrom
giulio-leone:feat/576-breakpoint-signal

Conversation

@giulio-leone

Copy link
Copy Markdown
Contributor

Closes #576

Adds ItBreakpointService — a tree-shakable, providedIn: 'root' service that exposes Angular Signals reflecting the current Bootstrap Italia viewport breakpoint.

API

import { ItBreakpointService } from 'design-angular-kit';

@Component({ ... })
export class MyComponent {
  private bp = inject(ItBreakpointService);

  // Signal<BootstrapBreakpoint> — 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
  current = this.bp.currentBreakpoint;

  // Signal<number> — min-width in px for the current breakpoint
  width = this.bp.currentMinWidth;

  // Computed Signal<boolean> — true when viewport >= lg
  isDesktop = this.bp.isAbove('lg');

  // Computed Signal<boolean> — true when viewport < md
  isMobile = this.bp.isBelow('md');
}

Implementation

  • Uses window.matchMedia for efficient listener-based detection (no polling)
  • SSR-safe: gracefully degrades when window is unavailable
  • Proper cleanup in ngOnDestroy
  • Breakpoints match Bootstrap Italia: xs(0), sm(576), md(768), lg(992), xl(1200), xxl(1400)

Testing

  • 117/117 tests passing (ChromeHeadless)
  • 0 lint errors
  • 8 new tests covering service creation, signal types, isAbove/isBelow consistency, and cleanup

⚠️ This reopens #646 which was accidentally closed due to fork deletion.

giulio-leone and others added 2 commits March 25, 2026 11:39
Expose the current Bootstrap Italia viewport breakpoint as Angular
Signals. The service uses window.matchMedia for efficient, listener-based
detection and provides:
- currentBreakpoint: Signal<BootstrapBreakpoint>
- currentMinWidth: Signal<number>
- isAbove(bp): computed Signal<boolean>
- isBelow(bp): computed Signal<boolean>

Closes italia#576

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Show ItBreakpointService usage with currentBreakpoint signal,
currentMinWidth, isAbove, and isBelow computed signals. Includes
live-updating table that reflects viewport changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vercel

vercel Bot commented Mar 25, 2026

Copy link
Copy Markdown

@giulio-leone is attempting to deploy a commit to the dip-trasformazione-digitale Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Mar 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
design-angular-kit Error Error Mar 27, 2026 3:39pm

Request Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Esporre uno o più Signal per poter reagire programmaticamente in base al breakpoint raggiunto

1 participant