@almoamendev/ngx-md3 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almoamendev/ngx-md3",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "MD3-style Angular components & style library",
5
5
  "author": "Murtadha (Hussain) Almoamen",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import * as _angular_core from '@angular/core';
2
- import { ViewContainerRef, Injector, ElementRef, AfterViewInit, OnDestroy, OnInit, Renderer2, Signal, InputSignal, InjectionToken, Type, AfterContentInit, ComponentRef, TemplateRef } from '@angular/core';
2
+ import { ViewContainerRef, Injector, Signal, ElementRef, AfterViewInit, OnDestroy, OnInit, Renderer2, InputSignal, InjectionToken, Type, AfterContentInit, ComponentRef, TemplateRef } from '@angular/core';
3
3
  import { FlexibleConnectedPositionStrategyOrigin, ConnectedPosition, OverlayRef } from '@angular/cdk/overlay';
4
- import { Observable } from 'rxjs';
4
+ import { Observable, Subject } from 'rxjs';
5
5
  import * as i1 from '@angular/cdk/scrolling';
6
6
  import { AbstractControl } from '@angular/forms';
7
7
  import * as i1$1 from '@angular/router';
@@ -226,33 +226,79 @@ interface SideSheetContainer {
226
226
  setHidden(value: boolean): void;
227
227
  }
228
228
 
229
+ /**
230
+ * How the sheet sits in the layout. A modal sheet floats above the page in an overlay with a
231
+ * scrim; a standard sheet docks into the scaffold, reserves its collapsed height and leaves the
232
+ * rest of the page usable.
233
+ */
234
+ type BottomSheetType = 'standard' | 'modal';
235
+ /** Which of a standard sheet's two heights it is resting at. */
236
+ type BottomSheetState = 'collapsed' | 'expanded';
229
237
  interface BottomSheetConfig<D = unknown> {
230
238
  data?: D;
231
239
  bindDataToInputs?: boolean;
240
+ /** @default 'modal' */
241
+ type?: BottomSheetType;
232
242
  /** Shows the MD3 drag handle centered above the sheet's content. */
233
243
  handle?: boolean;
234
- /** Lets the sheet be dragged down, and flung, to dismiss it. */
244
+ /**
245
+ * Lets the sheet be dragged, and flung. A modal sheet is dragged down to dismiss it; a
246
+ * standard sheet is dragged between its collapsed and expanded heights.
247
+ */
235
248
  gestures?: boolean;
249
+ /** Standard only. How much of the sheet shows when it is collapsed. */
250
+ collapsedHeight?: number | string;
251
+ /** Standard only. Height the sheet grows to when it is expanded. */
252
+ expandedHeight?: number | string;
253
+ /** Standard only. Which height the sheet opens at. */
254
+ initialState?: BottomSheetState;
255
+ /** Standard only. Whether dragging below the collapsed height closes the sheet. */
256
+ dismissible?: boolean;
257
+ /** Standard only. Accessible name for the region the sheet occupies. */
258
+ label?: string;
259
+ /** Standard only. Id of the element naming the sheet, when it already has a visible title. */
260
+ labelledBy?: string;
236
261
  scheme?: 'inherit' | 'dark' | 'light';
237
262
  direction?: null | 'ltr' | 'rtl';
238
263
  viewContainerRef?: ViewContainerRef;
239
264
  injector?: Injector;
240
265
  }
241
266
  /**
242
- * What BottomSheetRef needs from the shell hosting a bottom sheet, mirroring
243
- * DialogContainer: a bottom sheet is a CDK dialog container underneath, not a
244
- * side-sheet-style outlet.
267
+ * What BottomSheetRef needs from the surface hosting a sheet, whichever shell it was created
268
+ * in. The surface reports gestures rather than acting on them, because it is created before
269
+ * the reference exists and cannot reach it through DI.
245
270
  */
246
- interface BottomSheetContainer {
271
+ interface BottomSheetSurfaceHost {
247
272
  readonly surfaceElement: HTMLElement | null;
248
273
  /** Emits when a drag gesture asks for the sheet to be dismissed. */
249
274
  readonly dismissed: Observable<void>;
250
275
  /** Emits how far a drag has taken the sheet towards being dismissed, from 0 to 1. */
251
276
  readonly dragProgress: Observable<number>;
277
+ /** Emits the height a drag settled the sheet at. Standard sheets only. */
278
+ readonly stateChanges: Observable<BottomSheetState>;
252
279
  startEnterAnimation(): void;
253
280
  setActive(value: boolean): void;
281
+ }
282
+ /**
283
+ * The modal shell, which is a CDK dialog container underneath and so has focus handling the
284
+ * standard shell deliberately does without.
285
+ */
286
+ interface BottomSheetContainer extends BottomSheetSurfaceHost {
254
287
  recaptureFocus(): void;
255
288
  }
289
+ /**
290
+ * The docked shell, which owns the two heights a standard sheet moves between. Typed as an
291
+ * interface so BottomSheetRef can drive the shell without importing the component it lives in.
292
+ */
293
+ interface StandardBottomSheetHost extends BottomSheetSurfaceHost {
294
+ readonly state: Signal<BottomSheetState>;
295
+ expand(): void;
296
+ collapse(): void;
297
+ toggle(): void;
298
+ setCollapsedHeight(value: number | string): void;
299
+ setExpandedHeight(value: number | string): void;
300
+ setDismissible(value: boolean): void;
301
+ }
256
302
 
257
303
  type SnackbarPoliteness = 'polite' | 'assertive';
258
304
  interface SnackbarConfig<D = unknown> {
@@ -576,8 +622,10 @@ declare class LayoutService {
576
622
  declare class Scaffold implements AfterViewInit, OnDestroy {
577
623
  private startOutlet;
578
624
  private endOutlet;
625
+ private bottomOutlet;
579
626
  private panesContainer;
580
627
  private sheets;
628
+ private bottomSheets;
581
629
  private layout;
582
630
  ngAfterViewInit(): void;
583
631
  ngOnDestroy(): void;
@@ -1874,58 +1922,128 @@ declare const BOTTOM_SHEET_DATA: InjectionToken<unknown>;
1874
1922
  declare const BOTTOM_SHEET_CONFIG: InjectionToken<BottomSheetConfig<unknown>>;
1875
1923
  declare const BOTTOM_SHEET_COMPONENT: InjectionToken<Type<unknown>>;
1876
1924
  /**
1877
- * A bottom sheet is a single modal overlay, not a stack like dialogs can be,
1878
- * so this is a smaller version of DialogRef: no hide/show, no full screen
1879
- * variant, closing is always the only way out.
1925
+ * What both kinds of bottom sheet have in common: closing once, animating out before the shell
1926
+ * goes away, and reporting the result. The two shells differ in what they are hosted by — a CDK
1927
+ * overlay or a scaffold outlet so each subclass owns its own exit and teardown.
1928
+ *
1929
+ * This class stays the DI token, so a component written for one kind of sheet can be opened as
1930
+ * the other without changing how it injects its reference.
1880
1931
  */
1881
- declare class BottomSheetRef<T = unknown, R = unknown> {
1882
- private readonly cdkRef;
1883
- private readonly closed;
1884
- private closeStarted;
1932
+ declare abstract class BottomSheetRef<T = unknown, R = unknown> {
1933
+ protected readonly closed: Subject<R | undefined>;
1934
+ protected closeStarted: boolean;
1885
1935
  private closeSettled;
1886
- /** Shell hosting the sheet. Filled by BottomSheetService once it is created. */
1887
- sheetInstance?: BottomSheetContainer;
1936
+ /** Surface hosting the sheet. Filled in by BottomSheetService once the shell is created. */
1937
+ sheetInstance?: BottomSheetSurfaceHost;
1888
1938
  /** Filled by BottomSheetService after the sheet component is attached. */
1889
1939
  componentInstance?: T;
1890
- /** Overlay hosting the sheet, useful to reach the panel and the scrim. */
1891
- get overlayRef(): OverlayRef;
1892
1940
  /** Whether the sheet started closing. */
1893
1941
  get isClosing(): boolean;
1894
- constructor(cdkRef: DialogRef$1<R, T>);
1942
+ /** Height the sheet is resting at. A modal sheet is only ever fully open. */
1943
+ get state(): Signal<BottomSheetState>;
1895
1944
  /** Closes the sheet. The promise resolves once the exit animation is done. */
1896
1945
  close(result?: R): Promise<void>;
1897
1946
  afterClosed(): Observable<R | undefined>;
1898
1947
  /**
1899
1948
  * Wires the shell to this reference. Called by BottomSheetService, since the shell is
1900
- * created by the CDK before this reference exists and cannot reach it through DI.
1949
+ * created before this reference exists and cannot reach it through DI.
1901
1950
  */
1902
- attachContainer(container: BottomSheetContainer): void;
1951
+ attachContainer(container: BottomSheetSurfaceHost): void;
1952
+ /** Moves a standard sheet to its expanded height. Modal sheets have only one height. */
1953
+ expand(): void;
1954
+ /** Moves a standard sheet back to its collapsed height. */
1955
+ collapse(): void;
1956
+ /** Switches a standard sheet between its two heights. */
1957
+ toggle(): void;
1958
+ setCollapsedHeight(height: number | string): void;
1959
+ setExpandedHeight(height: number | string): void;
1960
+ setDismissible(value: boolean): void;
1961
+ protected abstract startCloseAnimation(): Promise<void>;
1962
+ protected abstract finishClose(result?: R): void;
1963
+ /** Resolves when the surface finished animating, with a timeout as a safety net. */
1964
+ protected waitForSurfaceAnimation(fallback?: HTMLElement | null): Promise<void>;
1965
+ /** Emits the result once the sheet is gone. */
1966
+ protected settle(result?: R): void;
1967
+ }
1968
+ /**
1969
+ * A modal bottom sheet is a single overlay, not a stack like dialogs can be, so this is a
1970
+ * smaller version of DialogRef: no hide/show, no full screen variant, closing is always the
1971
+ * only way out.
1972
+ */
1973
+ declare class ModalBottomSheetRef<T = unknown, R = unknown> extends BottomSheetRef<T, R> {
1974
+ private readonly cdkRef;
1975
+ constructor(cdkRef: DialogRef$1<R, T>);
1976
+ /** Overlay hosting the sheet, useful to reach the panel and the scrim. */
1977
+ get overlayRef(): OverlayRef;
1978
+ attachContainer(container: BottomSheetSurfaceHost): void;
1979
+ protected startCloseAnimation(): Promise<void>;
1980
+ protected finishClose(result?: R): void;
1981
+ private connectCloseEvents;
1903
1982
  /** Fades the scrim along with the sheet being dragged, and hands it back to CSS on release. */
1904
1983
  private trackDragProgress;
1905
- private connectCloseEvents;
1906
- private startCloseAnimation;
1907
- /** Resolves when the surface finished animating, with a timeout as a safety net. */
1908
- private waitForSurfaceAnimation;
1909
- /** Emits the result once the CDK reference is closed. Focus is restored by the container. */
1910
- private settle;
1984
+ }
1985
+ /**
1986
+ * A standard bottom sheet lives in a scaffold outlet rather than an overlay, so there is no
1987
+ * scrim to fade and nothing to dispose but the component itself. In exchange it can be moved
1988
+ * between its two heights while it is open.
1989
+ */
1990
+ declare class StandardBottomSheetRef<T = unknown, R = unknown> extends BottomSheetRef<T, R> {
1991
+ private readonly onClosed;
1992
+ private sheetComponentRef?;
1993
+ private host?;
1994
+ constructor(onClosed: () => void);
1995
+ get state(): Signal<BottomSheetState>;
1996
+ /** Called by BottomSheetService once the shell has been created in the outlet. */
1997
+ attachSheet(componentRef: ComponentRef<unknown>, host: StandardBottomSheetHost): void;
1998
+ expand(): void;
1999
+ collapse(): void;
2000
+ toggle(): void;
2001
+ setCollapsedHeight(height: number | string): void;
2002
+ setExpandedHeight(height: number | string): void;
2003
+ setDismissible(value: boolean): void;
2004
+ /**
2005
+ * Tears the sheet down without an exit animation, for when the outlet holding it is going
2006
+ * away and there is nothing left to animate in.
2007
+ */
2008
+ dispose(result?: R): void;
2009
+ protected startCloseAnimation(): Promise<void>;
2010
+ protected finishClose(result?: R): void;
1911
2011
  }
1912
2012
 
1913
2013
  /**
1914
- * Opens bottom sheets as CDK dialogs anchored to the bottom of the viewport.
1915
- * A bottom sheet is always a modal overlay, the same way a regular dialog is
1916
- * always an overlay, so this mirrors DialogService rather than the side sheet
1917
- * outlet model: there is no docked variant and nothing to register from the
1918
- * scaffold.
2014
+ * Opens bottom sheets, in either of the two ways MD3 describes them.
2015
+ *
2016
+ * A modal sheet is a CDK dialog anchored to the bottom of the viewport, the same way a regular
2017
+ * dialog is always an overlay, so that path mirrors DialogService. A standard sheet is docked
2018
+ * into the scaffold instead, following the side sheet outlet model: it floats over the content
2019
+ * without a scrim, leaves the rest of the page usable, and needs an outlet to open into.
2020
+ *
2021
+ * One of each may be open at a time, and they replace only their own kind.
1919
2022
  */
1920
2023
  declare class BottomSheetService {
1921
2024
  private readonly cdkDialog;
1922
2025
  private readonly overlay;
1923
2026
  private readonly injector;
1924
- /** Only one bottom sheet is ever open at a time. */
1925
- private ref?;
2027
+ /**
2028
+ * Outlets registered from the page scaffold up to whatever took them over last. Standard
2029
+ * sheets always open in the outlet on top.
2030
+ */
2031
+ private readonly outlets;
2032
+ private modalRef?;
2033
+ private standardRef?;
2034
+ /** Registers the outlet standard bottom sheets open into. Called by Scaffold. */
2035
+ registerBottomSheetOutlet(outlet: CdkPortalOutlet): void;
2036
+ unregisterBottomSheetOutlet(outlet: CdkPortalOutlet): void;
1926
2037
  open<T, D = unknown, R = unknown>(component: Type<T>, config?: BottomSheetConfig<D>): BottomSheetRef<T, R>;
1927
- /** Closes the bottom sheet that is open, if there is one. */
2038
+ /**
2039
+ * Closes the bottom sheet that is open. A modal sheet goes first when both kinds are up,
2040
+ * since it is the one covering the page.
2041
+ */
1928
2042
  close<R = unknown>(result?: R): void;
2043
+ private openModal;
2044
+ private openStandard;
2045
+ private activeOutlet;
2046
+ private createInjector;
1929
2047
  private startOpenAnimation;
1930
2048
  private mergeConfig;
1931
2049
  private bindDataToInputs;
@@ -2029,5 +2147,5 @@ declare class SnackbarService {
2029
2147
  static ɵprov: _angular_core.ɵɵInjectableDeclaration<SnackbarService>;
2030
2148
  }
2031
2149
 
2032
- export { AppBar, AppBarLogo, Avatar, BOTTOM_SHEET_COMPONENT, BOTTOM_SHEET_CONFIG, BOTTOM_SHEET_DATA, Badge, BottomSheetRef, BottomSheetService, Button, ButtonGroup, CAROUSEL_STRATEGIES, Card, Carousel, CarouselItem, Checkbox, ChipAvatar, Chips, CircularProgressIndicator, DIALOG_COMPONENT, DIALOG_CONFIG, DIALOG_DATA, Dialog, DialogActions, DialogBody, DialogHeader, DialogRef, DialogService, Divider, FloatingActionButton, FullScreenDialog, FullScreenDialogHeader, Grid, GridItem, IconButton, IconElement, InputElement, LayoutService, LinearProgressIndicator, List, ListItem, ListItemPrimaryAction, ListLeading, ListSlot, LoadingIndicator, MENU_COMPONENT, MENU_CONFIG, MENU_DATA, MaterialIcon, Menu, MenuGroup, MenuItem, MenuRef, MenuService, NavigationBar, NavigationGroup, NavigationItem, NavigationRail, RadioButton, SIDE_SHEET_COMPONENT, SIDE_SHEET_CONFIG, SIDE_SHEET_DATA, SNACKBAR_ACTION_LABEL, SNACKBAR_CONFIG, SNACKBAR_MESSAGE, Scaffold, ScaffoldBar, ScaffoldPane, ScaffoldRail, SheetsService, SideSheetActions, SideSheetBody, SideSheetHeader, SideSheetRef, Slider, Snackbar, SnackbarRef, SnackbarService, SplitButton, StateComponent, SupportingText, Switch, TextField, TypeBody, TypeDisplay, TypeHeadline, TypeLabel, TypeTitle, buildGeometry, clampIndex, indexForScrollOffset, multiBrowseStrategy, parseCarouselAspectRatio, resolveItemGeometry, resolveState, scrollOffsetForIndex, sizeBandFor };
2033
- export type { AppBarScrollingStyle, AppBarType, BottomSheetConfig, BottomSheetContainer, ButtonGroupSelection, ButtonGroupType, ButtonSize, ButtonType, CardType, CarouselAlignment, CarouselArrangement, CarouselGeometry, CarouselItemGeometry, CarouselItemSize, CarouselKeyline, CarouselKeylineState, CarouselLayout, CarouselOrientation, CarouselStrategy, CarouselStrategyContext, ChipStyle, ChipType, DialogConfig, DialogContainer, DialogRole, FabSize, FabType, FullScreenDialogConfig, IconButtonType, IconButtonWidth, ListLeadingSize, ListLeadingType, Md3NavigationMode, MenuConfig, MenuPositionOrigin, MenuPositionX, MenuPositionY, MenuScrollStrategy, PreviousDialog, SideSheetConfig, SideSheetContainer, SideSheetSide, SideSheetType, SliderSize, SnackbarConfig, SnackbarDismiss, SnackbarDismissReason, SnackbarPoliteness, SplitButtonType, TextColor, TextSize };
2150
+ export { AppBar, AppBarLogo, Avatar, BOTTOM_SHEET_COMPONENT, BOTTOM_SHEET_CONFIG, BOTTOM_SHEET_DATA, Badge, BottomSheetRef, BottomSheetService, Button, ButtonGroup, CAROUSEL_STRATEGIES, Card, Carousel, CarouselItem, Checkbox, ChipAvatar, Chips, CircularProgressIndicator, DIALOG_COMPONENT, DIALOG_CONFIG, DIALOG_DATA, Dialog, DialogActions, DialogBody, DialogHeader, DialogRef, DialogService, Divider, FloatingActionButton, FullScreenDialog, FullScreenDialogHeader, Grid, GridItem, IconButton, IconElement, InputElement, LayoutService, LinearProgressIndicator, List, ListItem, ListItemPrimaryAction, ListLeading, ListSlot, LoadingIndicator, MENU_COMPONENT, MENU_CONFIG, MENU_DATA, MaterialIcon, Menu, MenuGroup, MenuItem, MenuRef, MenuService, ModalBottomSheetRef, NavigationBar, NavigationGroup, NavigationItem, NavigationRail, RadioButton, SIDE_SHEET_COMPONENT, SIDE_SHEET_CONFIG, SIDE_SHEET_DATA, SNACKBAR_ACTION_LABEL, SNACKBAR_CONFIG, SNACKBAR_MESSAGE, Scaffold, ScaffoldBar, ScaffoldPane, ScaffoldRail, SheetsService, SideSheetActions, SideSheetBody, SideSheetHeader, SideSheetRef, Slider, Snackbar, SnackbarRef, SnackbarService, SplitButton, StandardBottomSheetRef, StateComponent, SupportingText, Switch, TextField, TypeBody, TypeDisplay, TypeHeadline, TypeLabel, TypeTitle, buildGeometry, clampIndex, indexForScrollOffset, multiBrowseStrategy, parseCarouselAspectRatio, resolveItemGeometry, resolveState, scrollOffsetForIndex, sizeBandFor };
2151
+ export type { AppBarScrollingStyle, AppBarType, BottomSheetConfig, BottomSheetContainer, BottomSheetState, BottomSheetSurfaceHost, BottomSheetType, ButtonGroupSelection, ButtonGroupType, ButtonSize, ButtonType, CardType, CarouselAlignment, CarouselArrangement, CarouselGeometry, CarouselItemGeometry, CarouselItemSize, CarouselKeyline, CarouselKeylineState, CarouselLayout, CarouselOrientation, CarouselStrategy, CarouselStrategyContext, ChipStyle, ChipType, DialogConfig, DialogContainer, DialogRole, FabSize, FabType, FullScreenDialogConfig, IconButtonType, IconButtonWidth, ListLeadingSize, ListLeadingType, Md3NavigationMode, MenuConfig, MenuPositionOrigin, MenuPositionX, MenuPositionY, MenuScrollStrategy, PreviousDialog, SideSheetConfig, SideSheetContainer, SideSheetSide, SideSheetType, SliderSize, SnackbarConfig, SnackbarDismiss, SnackbarDismissReason, SnackbarPoliteness, SplitButtonType, StandardBottomSheetHost, TextColor, TextSize };