Skip to content

build: add animations toggle to the dev app #22669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dev-app/dev-app/dev-app-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ <h1>Angular Material Demos</h1>
<button mat-icon-button (click)="toggleFullscreen()" title="Toggle fullscreen">
<mat-icon>fullscreen</mat-icon>
</button>
<button mat-button (click)="toggleAnimations()">
{{animationsDisabled ? 'Enable' : 'Disable'}} animations
</button>
<button mat-button (click)="isDark = !isDark">
{{isDark ? 'Light' : 'Dark'}} theme
</button>
Expand Down
9 changes: 9 additions & 0 deletions src/dev-app/dev-app/dev-app-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {DOCUMENT} from '@angular/common';

const isDarkThemeKey = 'ANGULAR_COMPONENTS_DEV_APP_DARK_THEME';

export const ANIMATIONS_STORAGE_KEY = 'ANGULAR_COMPONENTS_ANIMATIONS_DISABLED';

/** Root component for the dev-app demos. */
@Component({
selector: 'dev-app-layout',
Expand Down Expand Up @@ -111,6 +113,9 @@ export class DevAppLayout {
/** List of possible global density scale values. */
densityScales = [0, -1, -2, 'minimum', 'maximum'];

/** Whether animations are disabled. */
animationsDisabled = localStorage.getItem(ANIMATIONS_STORAGE_KEY) === 'true';

constructor(
private _element: ElementRef<HTMLElement>, public rippleOptions: DevAppRippleOptions,
@Inject(Directionality) public dir: DevAppDirectionality, cdr: ChangeDetectorRef,
Expand Down Expand Up @@ -181,6 +186,10 @@ export class DevAppLayout {
}
}

toggleAnimations() {
localStorage.setItem(ANIMATIONS_STORAGE_KEY, (!this.animationsDisabled) + '');
location.reload();
}

/** Gets the index of the next density scale that can be selected. */
getNextDensityIndex() {
Expand Down
7 changes: 6 additions & 1 deletion src/dev-app/main-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ import {DevAppDirectionality} from './dev-app/dev-app-directionality';
import {DevAppModule} from './dev-app/dev-app-module';
import {DEV_APP_ROUTES} from './dev-app/routes';
import {DevAppRippleOptions} from './dev-app/ripple-options';
import {ANIMATIONS_STORAGE_KEY} from './dev-app/dev-app-layout';

@NgModule({
imports: [
BrowserAnimationsModule,
BrowserAnimationsModule.withConfig({
// Note that this doesn't seem to work on ViewEngine, but it's
// not a compilation error either so we can live with it.
disableAnimations: localStorage.getItem(ANIMATIONS_STORAGE_KEY) === 'true'
}),
BrowserModule,
DevAppModule,
HttpClientModule,
Expand Down