From 425bad872dcdd56b8f6b4dcf23627ca58e402a05 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 11 Oct 2023 13:59:22 +0200 Subject: [PATCH] feat(material/snack-bar): convert to standalone (#27926) Converts the snack bar module to standalone. --- src/dev-app/snack-bar/snack-bar-demo.ts | 7 +++--- src/material/snack-bar/module.ts | 23 ++++++++----------- src/material/snack-bar/simple-snack-bar.ts | 5 ++++ src/material/snack-bar/snack-bar-container.ts | 3 +++ src/material/snack-bar/snack-bar-content.ts | 3 +++ src/material/snack-bar/snack-bar.ts | 3 +-- tools/public_api_guard/material/snack-bar.md | 21 ++++++++--------- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/dev-app/snack-bar/snack-bar-demo.ts b/src/dev-app/snack-bar/snack-bar-demo.ts index de5991a4d609..d846ec160c39 100644 --- a/src/dev-app/snack-bar/snack-bar-demo.ts +++ b/src/dev-app/snack-bar/snack-bar-demo.ts @@ -13,7 +13,6 @@ import { MatSnackBarConfig, MatSnackBarHorizontalPosition, MatSnackBarVerticalPosition, - MatSnackBarModule, } from '@angular/material/snack-bar'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; @@ -29,7 +28,6 @@ import {MatSelectModule} from '@angular/material/select'; encapsulation: ViewEncapsulation.None, standalone: true, imports: [ - MatSnackBarModule, CommonModule, FormsModule, MatButtonModule, @@ -49,7 +47,10 @@ export class SnackBarDemo { horizontalPosition: MatSnackBarHorizontalPosition = 'center'; verticalPosition: MatSnackBarVerticalPosition = 'bottom'; - constructor(public snackBar: MatSnackBar, private _dir: Directionality) {} + constructor( + public snackBar: MatSnackBar, + private _dir: Directionality, + ) {} open() { const config = this._createConfig(); diff --git a/src/material/snack-bar/module.ts b/src/material/snack-bar/module.ts index d557fdd0b594..b2d7c58f17f5 100644 --- a/src/material/snack-bar/module.ts +++ b/src/material/snack-bar/module.ts @@ -8,7 +8,6 @@ import {OverlayModule} from '@angular/cdk/overlay'; import {PortalModule} from '@angular/cdk/portal'; -import {CommonModule} from '@angular/common'; import {NgModule} from '@angular/core'; import {MatButtonModule} from '@angular/material/button'; import {MatCommonModule} from '@angular/material/core'; @@ -16,22 +15,20 @@ import {MatCommonModule} from '@angular/material/core'; import {SimpleSnackBar} from './simple-snack-bar'; import {MatSnackBarContainer} from './snack-bar-container'; import {MatSnackBarAction, MatSnackBarActions, MatSnackBarLabel} from './snack-bar-content'; +import {MatSnackBar} from './snack-bar'; + +const DIRECTIVES = [MatSnackBarContainer, MatSnackBarLabel, MatSnackBarActions, MatSnackBarAction]; @NgModule({ - imports: [OverlayModule, PortalModule, CommonModule, MatButtonModule, MatCommonModule], - exports: [ + imports: [ + OverlayModule, + PortalModule, + MatButtonModule, MatCommonModule, - MatSnackBarContainer, - MatSnackBarLabel, - MatSnackBarActions, - MatSnackBarAction, - ], - declarations: [ SimpleSnackBar, - MatSnackBarContainer, - MatSnackBarLabel, - MatSnackBarActions, - MatSnackBarAction, + ...DIRECTIVES, ], + exports: [MatCommonModule, ...DIRECTIVES], + providers: [MatSnackBar], }) export class MatSnackBarModule {} diff --git a/src/material/snack-bar/simple-snack-bar.ts b/src/material/snack-bar/simple-snack-bar.ts index ed12f3b3d901..1e333c2964e9 100644 --- a/src/material/snack-bar/simple-snack-bar.ts +++ b/src/material/snack-bar/simple-snack-bar.ts @@ -7,8 +7,11 @@ */ import {ChangeDetectionStrategy, Component, Inject, ViewEncapsulation} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {MatButtonModule} from '@angular/material/button'; import {MatSnackBarRef} from './snack-bar-ref'; import {MAT_SNACK_BAR_DATA} from './snack-bar-config'; +import {MatSnackBarAction, MatSnackBarActions, MatSnackBarLabel} from './snack-bar-content'; /** * Interface for a simple snack bar component that has a message and a single action. @@ -27,6 +30,8 @@ export interface TextOnlySnackBar { exportAs: 'matSnackBar', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, + imports: [MatButtonModule, MatSnackBarLabel, MatSnackBarActions, MatSnackBarAction, CommonModule], + standalone: true, host: { 'class': 'mat-mdc-simple-snack-bar', }, diff --git a/src/material/snack-bar/snack-bar-container.ts b/src/material/snack-bar/snack-bar-container.ts index 6beabf79b072..458e3db4833a 100644 --- a/src/material/snack-bar/snack-bar-container.ts +++ b/src/material/snack-bar/snack-bar-container.ts @@ -26,6 +26,7 @@ import { CdkPortalOutlet, ComponentPortal, DomPortal, + PortalModule, TemplatePortal, } from '@angular/cdk/portal'; import {Observable, Subject} from 'rxjs'; @@ -52,6 +53,8 @@ let uniqueId = 0; changeDetection: ChangeDetectionStrategy.Default, encapsulation: ViewEncapsulation.None, animations: [matSnackBarAnimations.snackBarState], + standalone: true, + imports: [PortalModule], host: { 'class': 'mdc-snackbar mat-mdc-snack-bar-container mdc-snackbar--open', '[@state]': '_animationState', diff --git a/src/material/snack-bar/snack-bar-content.ts b/src/material/snack-bar/snack-bar-content.ts index 7604fec19e43..4d9b977df28d 100644 --- a/src/material/snack-bar/snack-bar-content.ts +++ b/src/material/snack-bar/snack-bar-content.ts @@ -11,6 +11,7 @@ import {Directive} from '@angular/core'; /** Directive that should be applied to the text element to be rendered in the snack bar. */ @Directive({ selector: `[matSnackBarLabel]`, + standalone: true, host: { 'class': 'mat-mdc-snack-bar-label mdc-snackbar__label', }, @@ -20,6 +21,7 @@ export class MatSnackBarLabel {} /** Directive that should be applied to the element containing the snack bar's action buttons. */ @Directive({ selector: `[matSnackBarActions]`, + standalone: true, host: { 'class': 'mat-mdc-snack-bar-actions mdc-snackbar__actions', }, @@ -29,6 +31,7 @@ export class MatSnackBarActions {} /** Directive that should be applied to each of the snack bar's action buttons. */ @Directive({ selector: `[matSnackBarAction]`, + standalone: true, host: { 'class': 'mat-mdc-snack-bar-action mdc-snackbar__action', }, diff --git a/src/material/snack-bar/snack-bar.ts b/src/material/snack-bar/snack-bar.ts index b4e9a29cc968..2cd1632357dd 100644 --- a/src/material/snack-bar/snack-bar.ts +++ b/src/material/snack-bar/snack-bar.ts @@ -21,7 +21,6 @@ import { SkipSelf, TemplateRef, } from '@angular/core'; -import {MatSnackBarModule} from './module'; import {SimpleSnackBar, TextOnlySnackBar} from './simple-snack-bar'; import {MatSnackBarContainer} from './snack-bar-container'; import {MAT_SNACK_BAR_DATA, MatSnackBarConfig} from './snack-bar-config'; @@ -46,7 +45,7 @@ export const MAT_SNACK_BAR_DEFAULT_OPTIONS = new InjectionToken; + static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; } @@ -78,7 +77,7 @@ export class MatSnackBarAction { // @public export class MatSnackBarActions { // (undocumented) - static ɵdir: i0.ɵɵDirectiveDeclaration; + static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; } @@ -124,7 +123,7 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy _role?: 'status' | 'alert'; snackBarConfig: MatSnackBarConfig; // (undocumented) - static ɵcmp: i0.ɵɵComponentDeclaration; + static ɵcmp: i0.ɵɵComponentDeclaration; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; } @@ -140,7 +139,7 @@ export type MatSnackBarHorizontalPosition = 'start' | 'center' | 'end' | 'left' // @public export class MatSnackBarLabel { // (undocumented) - static ɵdir: i0.ɵɵDirectiveDeclaration; + static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; } @@ -152,7 +151,7 @@ export class MatSnackBarModule { // (undocumented) static ɵinj: i0.ɵɵInjectorDeclaration; // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public @@ -190,7 +189,7 @@ export class SimpleSnackBar implements TextOnlySnackBar { // (undocumented) snackBarRef: MatSnackBarRef; // (undocumented) - static ɵcmp: i0.ɵɵComponentDeclaration; + static ɵcmp: i0.ɵɵComponentDeclaration; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; }