Skip to content

Commit

Permalink
chore: created part1 and part2
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Dolgikh committed Jan 4, 2024
1 parent c12f6cf commit 4b797dc
Show file tree
Hide file tree
Showing 32 changed files with 301 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"error",
{
"type": "attribute",
"prefix": "agnularPreferReduceMotion",
"prefix": "angularPreferReduceMotion",
"style": "camelCase"
}
],
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"printWidth": 80
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AgnularPreferReduceMotion
# angularPreferReduceMotion

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>

Expand All @@ -7,7 +7,7 @@

## Start the app

To start the development server run `nx serve agnular-prefer-reduce-motion`. Open your browser and navigate to http://localhost:4200/. Happy coding!
To start the development server run `nx serve angular-prefer-reduce-motion`. Open your browser and navigate to http://localhost:4200/. Happy coding!


## Generate code
Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default defineConfig({
},
/* Run your local dev server before starting the tests */
webServer: {
command: 'npx nx serve agnular-prefer-reduce-motion',
command: 'npx nx serve angular-prefer-reduce-motion',
url: 'http://localhost:4200',
reuseExistingServer: !process.env.CI,
cwd: workspaceRoot,
Expand Down
2 changes: 1 addition & 1 deletion e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"outputs": ["{options.outputFile}"]
}
},
"implicitDependencies": ["agnular-prefer-reduce-motion"]
"implicitDependencies": ["angular-prefer-reduce-motion"]
}
2 changes: 1 addition & 1 deletion e2e/src/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
test('has title', async ({ page }): Promise<void> => {
await page.goto('/');

// Expect h1 to contain a substring.
Expand Down
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable */
export default {
displayName: 'agnular-prefer-reduce-motion',
displayName: 'angular-prefer-reduce-motion',
preset: './jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: './coverage/agnular-prefer-reduce-motion',
coverageDirectory: './coverage/angular-prefer-reduce-motion',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
"style": "scss"
}
},
"defaultProject": "agnular-prefer-reduce-motion"
"defaultProject": "angular-prefer-reduce-motion"
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@agnular-prefer-reduce-motion/source",
"name": "@angular-prefer-reduce-motion/source",
"version": "0.0.0",
"license": "MIT",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions project.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "agnular-prefer-reduce-motion",
"name": "angular-prefer-reduce-motion",
"$schema": "node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "agnular-prefer-reduce-motion",
"prefix": "angular-prefer-reduce-motion",
"sourceRoot": "./src",
"tags": [],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/agnular-prefer-reduce-motion",
"outputPath": "dist/angular-prefer-reduce-motion",
"index": "./src/index.html",
"browser": "./src/main.ts",
"polyfills": ["zone.js"],
Expand Down Expand Up @@ -48,18 +48,18 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "agnular-prefer-reduce-motion:build:production"
"buildTarget": "angular-prefer-reduce-motion:build:production"
},
"development": {
"buildTarget": "agnular-prefer-reduce-motion:build:development"
"buildTarget": "angular-prefer-reduce-motion:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "agnular-prefer-reduce-motion:build"
"buildTarget": "angular-prefer-reduce-motion:build"
}
},
"lint": {
Expand Down
20 changes: 0 additions & 20 deletions src/app/animations/collapse.ts

This file was deleted.

21 changes: 2 additions & 19 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
<button (click)="show = !show" style="width: 100px;">
{{ show ? 'Hide' : 'Show'}}
</button>

<div style="display: flex; gap: 8px">
<app-item *ngIf="show"
[@collapse]="options"
(@collapse.start)="onAnimationEvent($event)"
(@collapse.done)="onAnimationEvent($event)"
>
Angular animation item
</app-item>

<app-item
class="css-animation"
[ngClass]="show ? 'show' : 'hide'">
Css animation item
</app-item>
</div>
<!--<app-reusable-animations></app-reusable-animations> Part 1-->
<app-disable-animations></app-disable-animations>

17 changes: 0 additions & 17 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
:host {
display: flex;
flex-direction: column;
gap: 8px;

.show {
opacity: 1;
}

.hide {
opacity: 0;
}

.css-animation {
transition: all 300ms linear;
}
}
38 changes: 4 additions & 34 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
import { AnimationOptions, AnimationEvent } from '@angular/animations';
import { NgClass, NgIf } from '@angular/common';
import { Component } from '@angular/core';
import { AN_COLLAPSE } from './animations/collapse';
import { ItemComponent } from './components/angular-animation/item.component';
import { ReusableAnimationsComponent } from './part-1/reusable-animations.component';
import { DisableAnimationsComponent } from './part-2/disable-animations.component';

@Component({
standalone: true,
imports: [ItemComponent, NgIf, NgClass],
imports: [ReusableAnimationsComponent, DisableAnimationsComponent],
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
animations: [
AN_COLLAPSE
]
})
export class AppComponent {
show = true

options: AnimationOptions & { value: boolean } = {
value: true,
params: {
duration: 400
}
};

onAnimationEvent(event: AnimationEvent ) {
switch (event.phaseName) {
case 'start': {
console.time('animation');
break
}
case 'done': {
console.timeEnd('animation');
break;
}
default: {
break
}
}
}
}
export class AppComponent {}
30 changes: 30 additions & 0 deletions src/app/part-1/animations/collapse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
animate,
animation,
AnimationOptions,
style,
transition,
trigger,
} from '@angular/animations';

const closedStyle = style({ height: 0 });
const openStyle = style({ height: '*' });
const animateTimings = '{{duration}}ms linear';
const defaultOptions: AnimationOptions = { params: { duration: 300 } };

export const collapse = trigger('collapse', [
transition(
':enter',
animation([closedStyle, animate(animateTimings, openStyle)]),
defaultOptions
),
transition(
':leave',
animation([openStyle, animate(animateTimings, closedStyle)]),
defaultOptions
),
]);

export interface ReusableAnimationOptions<State> extends AnimationOptions {
value?: State;
}
1 change: 1 addition & 0 deletions src/app/part-1/components/bonus/bonus.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ng-content></ng-content>
8 changes: 8 additions & 0 deletions src/app/part-1/components/bonus/bonus.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:host {
display: flex;
flex-direction: column;
gap: 8px;
align-items: center;
background: #f3dfdf;
width: 100px;
}
28 changes: 28 additions & 0 deletions src/app/part-1/components/bonus/bonus.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, Input, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { collapse, ReusableAnimationOptions } from '../../animations/collapse';

@Component({
selector: 'app-bonus',
standalone: true,
imports: [CommonModule],
templateUrl: './bonus.component.html',
styleUrl: './bonus.component.scss',
animations: [collapse],
host: {
'[@collapse]': 'animationOptions',
},
})
export class BonusComponent implements OnInit {
@Input()
public collapseDuration: number = 300;

public animationOptions!: ReusableAnimationOptions<string>

public ngOnInit(): void {
this.animationOptions = {
value: '_',
params: { duration: this.collapseDuration },
};
}
}
22 changes: 22 additions & 0 deletions src/app/part-1/reusable-animations.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="flex">
<button (click)="state = !state">{{
state ? 'close' : 'open'
}}</button>
</div>

<div class="flex">
<div *ngIf="state" class="example-block" [@collapse]="slowAnimation">
<div class="block">Slow</div>
</div>
<div *ngIf="state" class="example-block" [@collapse]="fastAnimation">
<div class="block">Fast</div>
</div>
</div>

<div class="flex">
<ng-container *ngFor="let duration of durations">
<app-bonus *ngIf="state" [collapseDuration]="duration">
<div class="block">Duration {{duration}} ms</div>
</app-bonus>
</ng-container>
</div>
11 changes: 11 additions & 0 deletions src/app/part-1/reusable-animations.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:host {
.example-block {
background: #b59e9e;
width: 100px;
}

.block {
width: 100px;
height: 100px;
}
}
30 changes: 30 additions & 0 deletions src/app/part-1/reusable-animations.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { collapse, ReusableAnimationOptions } from './animations/collapse';
import { BonusComponent } from './components/bonus/bonus.component';

@Component({
selector: 'app-reusable-animations',
standalone: true,
imports: [CommonModule, BonusComponent],
templateUrl: './reusable-animations.component.html',
styleUrl: './reusable-animations.component.scss',
animations: [collapse],
host: {
'[class.flex]': 'true',
'[class.flex-column]': 'true',
},
})
export class ReusableAnimationsComponent {
public state: boolean = false;
public slowAnimation: ReusableAnimationOptions<string> = {
value: '_',
params: { duration: 800 },
};
public fastAnimation: ReusableAnimationOptions<string> = {
value: '_',
params: { duration: 200 },
};

public durations = [1000, 800, 600, 400, 200, 0]
}
Loading

0 comments on commit 4b797dc

Please sign in to comment.