Files
start-os/frontend/projects/shared/src/directives/responsive-col/responsive-col-viewport.directive.ts
Matt Hill e867f31c31 Next (#2170)
* feat: add widgets (#2034)

* feat: add Taiga UI library (#1992)

* feat: add widgets

* update patchdb

* right resizable sidebar with widgets

* feat: add resizing directive

* chore: remove unused code

* chore: remove unnecessary dep

* feat: `ResponsiveCol` add directive for responsive grid

* feat: add widgets edit mode and dialogs

* feat: add widgets model and modal

* chore: fix import

* chore: hide mobile widgets behind flag

* chore: add dummy widgets

* chore: start working on heath widget and implement other comments

* feat: health widget

* feat: add saving widgets and sidebar params to patch

* feat: preemptive UI update for widgets

* update health widget with more accurate states and styling (#2127)

* feat: `ResponsiveCol` add directive for responsive grid

* chore: some changes after merge

Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
Co-authored-by: Lucy C <12953208+elvece@users.noreply.github.com>

* fix(shared): `ElasticContainer` fix collapsing margin (#2150)

* fix(shared): `ElasticContainer` fix collapsing margin

* fix toolbar height so titles not chopped

---------

Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>

* feat: make widgets sidebar width togglable (#2146)

* feat: make widgets sidebar width togglable

* feat: move widgets under header

* chore: fix wide layout

* fix(shared): `ResponsiveCol` fix missing grid steps (#2153)

* fix widget flag and refactor for non-persistence

* default widget flag to false

* fix(shared): fix responsive column size (#2159)

* fix(shared): fix responsive column size

* fix: add responsiveness to all pages

* fix responsiveness on more pages

* fix: comments

* revert some padding changes

---------

Co-authored-by: Lucy Cifferello <12953208+elvece@users.noreply.github.com>
Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>

* chore: add analyzer (#2165)

* fix list styling to previous default (#2173)

* fix list styling to previous default

* dont need important flag

---------

Co-authored-by: Alex Inkin <alexander@inkin.ru>
Co-authored-by: Lucy C <12953208+elvece@users.noreply.github.com>
2023-03-07 19:09:10 -07:00

69 lines
1.7 KiB
TypeScript

import {
Directive,
ElementRef,
Inject,
InjectionToken,
Input,
NgZone,
} from '@angular/core'
import { ResizeObserverService } from '@ng-web-apis/resize-observer'
import { distinctUntilChanged, Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { tuiZonefree } from '@taiga-ui/cdk'
export type Step = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
/**
* Not exported:
* https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/media.ts
*
* export const SIZE_TO_MEDIA: any = {
* xs: '(min-width: 0px)',
* sm: '(min-width: 576px)',
* md: '(min-width: 768px)',
* lg: '(min-width: 992px)',
* xl: '(min-width: 1200px)',
* };
*/
export const BREAKPOINTS = new InjectionToken<readonly [number, Step][]>(
'BREAKPOINTS',
{
factory: () => [
[1200, 'xl'],
[992, 'lg'],
[768, 'md'],
[576, 'sm'],
[0, 'xs'],
],
},
)
@Directive({
selector: '[responsiveColViewport]',
exportAs: 'viewport',
providers: [ResizeObserverService],
})
export class ResponsiveColViewportDirective extends Observable<Step> {
@Input()
responsiveColViewport: Observable<Step> | '' = ''
private readonly stream$ = this.resize$.pipe(
map(() => this.elementRef.nativeElement.clientWidth),
map(width => this.breakpoints.find(([step]) => width >= step)?.[1] || 'xs'),
distinctUntilChanged(),
tuiZonefree(this.zone),
)
constructor(
@Inject(BREAKPOINTS)
private readonly breakpoints: readonly [number, Step][],
private readonly resize$: ResizeObserverService,
private readonly elementRef: ElementRef<HTMLElement>,
private readonly zone: NgZone,
) {
super(subscriber =>
(this.responsiveColViewport || this.stream$).subscribe(subscriber),
)
}
}