├── .editorconfig ├── .github └── workflows │ └── gh-pages.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── README.md ├── angular.json ├── browserslist ├── karma.conf.js ├── package-lock.json ├── package.json ├── screenshots └── preview.gif ├── src ├── .huskyrc ├── 404.html ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── core │ │ ├── base │ │ │ ├── base-component.ts │ │ │ └── index.ts │ │ ├── constants │ │ │ ├── icons.constants.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── models │ │ │ ├── index.ts │ │ │ └── product.model.ts │ │ └── services │ │ │ ├── cart.service.ts │ │ │ ├── data.service.ts │ │ │ ├── index.ts │ │ │ └── ui.service.ts │ ├── features │ │ └── home │ │ │ ├── home-routing.module.ts │ │ │ ├── home.component.html │ │ │ ├── home.component.ts │ │ │ └── home.module.ts │ └── shared │ │ ├── animations │ │ ├── bounce.animation.ts │ │ ├── fade.animation.ts │ │ ├── index.ts │ │ ├── scale.animation.ts │ │ └── slide.animation.ts │ │ ├── components │ │ ├── cards │ │ │ ├── cart-product-card │ │ │ │ ├── cart-product-card.component.html │ │ │ │ └── cart-product-card.component.ts │ │ │ ├── index.ts │ │ │ └── product-card │ │ │ │ ├── product-card.component.html │ │ │ │ └── product-card.component.ts │ │ ├── header │ │ │ ├── header.component.html │ │ │ └── header.component.ts │ │ ├── index.ts │ │ ├── layers │ │ │ ├── cart │ │ │ │ ├── cart.component.html │ │ │ │ └── cart.component.ts │ │ │ ├── index.ts │ │ │ ├── order-confirmation │ │ │ │ ├── order-confirmation.component.html │ │ │ │ └── order-confirmation.component.ts │ │ │ └── product-details │ │ │ │ ├── cart-button │ │ │ │ ├── cart-button.component.html │ │ │ │ └── cart-button.component.ts │ │ │ │ ├── product-details.component.html │ │ │ │ ├── product-details.component.scss │ │ │ │ └── product-details.component.ts │ │ └── menu │ │ │ ├── menu.component.html │ │ │ └── menu.component.ts │ │ ├── index.ts │ │ └── shared.module.ts ├── assets │ ├── .gitkeep │ ├── images │ │ ├── order-confirmation.svg │ │ └── potted-plant.svg │ └── local-data │ │ ├── product-types.json │ │ └── products.json ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss └── test.ts ├── tailwind.config.js ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json └── webpack.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: github pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | deploy: 10 | runs-on: ubuntu-18.04 11 | strategy: 12 | matrix: 13 | node-version: [12.x] 14 | steps: 15 | - uses: actions/checkout@master 16 | 17 | - name: Cache node modules 18 | uses: actions/cache@v1 19 | with: 20 | path: ~/.npm 21 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 22 | restore-keys: | 23 | ${{ runner.os }}-node- 24 | - name: Use Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v1 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | 29 | - name: Installing Lib Dependencies and Building 30 | run: npm install && npm run build -- --base-href /angular-animations-storefront/ 31 | 32 | - name: Deploy 33 | uses: peaceiris/actions-gh-pages@v3 34 | with: 35 | github_token: ${{ secrets.GITHUB_TOKEN }} 36 | publish_dir: ./dist/angular-animations-storefront 37 | publish_branch: gh-pages 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json 2 | package-lock.json 3 | yarn.lock 4 | dist -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": true, 3 | "semi": true, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "printWidth": 80 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular Animations Storefront 2 | 3 | > A showcase of angular animations in the context of an ecommerce site 4 | 5 | ![App Preview](screenshots/preview.gif) 6 | 7 | ## Live Demo 8 | 9 | Check out the live demo: https://auth0-blog.github.io/angular-animations-storefront/ 10 | 11 | If you prefer exploring the codebase right in the browser, you can also use [Stackblitz](https://stackblitz.com/github/auth0-blog/angular-animations-storefront/tree/starter) or [CodeSandbox](https://codesandbox.io/s/github/auth0-blog/angular-animations-storefront/tree/starter). 12 | 13 | ## Build Setup 14 | 15 | ```bash 16 | # install dependencies 17 | npm install 18 | 19 | # serve with hot reload at localhost:4200 20 | npm run start 21 | 22 | # build for production 23 | npm run build 24 | ``` 25 | 26 | ## Branches 27 | 28 | There are 2 main branches that is used in the repo: 29 | 30 | - `starter`: Without the animations 31 | - `animated`: With animations 32 | 33 | ## Notes 34 | 35 | ### Ugly relative import paths 36 | 37 | There was an issue I ran into with absolute paths or predefined paths from tsconfig when running this application on Stackblitz/CodeSandbox 38 | 39 | ### core-js dependency 40 | 41 | This was an issue on CodeSandbox where the application won't compile if it was missing this dependency and its corresponding import on `main.ts`. This shouldn't be required when doing developing outside of the CodeSandbox environment 42 | 43 | ### Tailwind import in index.html 44 | 45 | This is an issue with Stackblitz where it is not able to use `ngneat/tailwind` which is added through npm. You can remove the following line from `index.html` when developing locally. 46 | 47 | ```html 48 | 52 | ``` 53 | 54 | Because its using index.html to add Tailwind, it no longer respects the config in `tailwind.config.js`. I've duplicated the modifications I made on `tailwind.config.js` to `styles.scss` so the application looks and feels the same on both Stackblitz/CodeSandbox and locally. 55 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-animations-storefront": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-builders/custom-webpack:browser", 19 | "options": { 20 | "outputPath": "dist/angular-animations-storefront", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": true, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets", 29 | "src/404.html" 30 | ], 31 | "styles": [ 32 | "src/styles.scss" 33 | ], 34 | "scripts": [], 35 | "customWebpackConfig": { 36 | "path": "webpack.config.js" 37 | } 38 | }, 39 | "configurations": { 40 | "production": { 41 | "fileReplacements": [ 42 | { 43 | "replace": "src/environments/environment.ts", 44 | "with": "src/environments/environment.prod.ts" 45 | } 46 | ], 47 | "optimization": true, 48 | "outputHashing": "all", 49 | "sourceMap": false, 50 | "extractCss": true, 51 | "namedChunks": false, 52 | "extractLicenses": true, 53 | "vendorChunk": false, 54 | "buildOptimizer": true, 55 | "budgets": [ 56 | { 57 | "type": "initial", 58 | "maximumWarning": "2mb", 59 | "maximumError": "5mb" 60 | }, 61 | { 62 | "type": "anyComponentStyle", 63 | "maximumWarning": "6kb", 64 | "maximumError": "10kb" 65 | } 66 | ] 67 | } 68 | } 69 | }, 70 | "serve": { 71 | "builder": "@angular-builders/custom-webpack:dev-server", 72 | "options": { 73 | "browserTarget": "angular-animations-storefront:build" 74 | }, 75 | "configurations": { 76 | "production": { 77 | "browserTarget": "angular-animations-storefront:build:production" 78 | } 79 | } 80 | }, 81 | "extract-i18n": { 82 | "builder": "@angular-devkit/build-angular:extract-i18n", 83 | "options": { 84 | "browserTarget": "angular-animations-storefront:build" 85 | } 86 | }, 87 | "test": { 88 | "builder": "@angular-builders/custom-webpack:karma", 89 | "options": { 90 | "main": "src/test.ts", 91 | "polyfills": "src/polyfills.ts", 92 | "tsConfig": "tsconfig.spec.json", 93 | "karmaConfig": "karma.conf.js", 94 | "assets": [ 95 | "src/favicon.ico", 96 | "src/assets", 97 | "src/404.html" 98 | ], 99 | "styles": [ 100 | "src/styles.scss" 101 | ], 102 | "scripts": [], 103 | "customWebpackConfig": { 104 | "path": "webpack.config.js" 105 | } 106 | } 107 | }, 108 | "lint": { 109 | "builder": "@angular-devkit/build-angular:tslint", 110 | "options": { 111 | "tsConfig": [ 112 | "tsconfig.app.json", 113 | "tsconfig.spec.json", 114 | "e2e/tsconfig.json" 115 | ], 116 | "exclude": [ 117 | "**/node_modules/**" 118 | ] 119 | } 120 | }, 121 | "e2e": { 122 | "builder": "@angular-devkit/build-angular:protractor", 123 | "options": { 124 | "protractorConfig": "e2e/protractor.conf.js", 125 | "devServerTarget": "angular-animations-storefront:serve" 126 | }, 127 | "configurations": { 128 | "production": { 129 | "devServerTarget": "angular-animations-storefront:serve:production" 130 | } 131 | } 132 | } 133 | } 134 | }}, 135 | "defaultProject": "angular-animations-storefront" 136 | } 137 | -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/auth0-ecommerce'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-animations-storefront", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build --prod", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~11.0.1", 15 | "@angular/common": "~11.0.1", 16 | "@angular/compiler": "~11.0.1", 17 | "@angular/core": "~11.0.1", 18 | "@angular/fire": "^6.1.2", 19 | "@angular/forms": "~11.0.1", 20 | "@angular/platform-browser": "~11.0.1", 21 | "@angular/platform-browser-dynamic": "~11.0.1", 22 | "@angular/router": "~11.0.1", 23 | "@angular/service-worker": "~11.0.1", 24 | "@fortawesome/angular-fontawesome": "^0.8.1", 25 | "@fortawesome/fontawesome-free": "^5.15.1", 26 | "@fortawesome/fontawesome-svg-core": "^1.2.32", 27 | "@fortawesome/free-regular-svg-icons": "^5.15.1", 28 | "@fortawesome/free-solid-svg-icons": "^5.15.1", 29 | "@ngneat/tailwind": "^1.1.0", 30 | "core-js": "^3.8.3", 31 | "rxjs": "~6.6.0", 32 | "tslib": "^2.0.0", 33 | "zone.js": "~0.10.2" 34 | }, 35 | "devDependencies": { 36 | "@angular-builders/custom-webpack": "10.0.1", 37 | "@angular-devkit/build-angular": "~0.1100.2", 38 | "@angular/cli": "~11.0.2", 39 | "@angular/compiler-cli": "~11.0.1", 40 | "@types/jasmine": "~3.6.0", 41 | "@types/node": "^12.11.1", 42 | "autoprefixer": "10.0.4", 43 | "codelyzer": "^6.0.0", 44 | "jasmine-core": "~3.6.0", 45 | "jasmine-spec-reporter": "~5.0.0", 46 | "karma": "~5.1.0", 47 | "karma-chrome-launcher": "~3.1.0", 48 | "karma-coverage": "~2.0.3", 49 | "karma-jasmine": "~4.0.0", 50 | "karma-jasmine-html-reporter": "^1.5.0", 51 | "postcss": "8.1.10", 52 | "postcss-import": "13.0.0", 53 | "postcss-loader": "4.1.0", 54 | "postcss-scss": "3.0.4", 55 | "protractor": "~7.0.0", 56 | "tailwindcss": "2.0.1", 57 | "ts-node": "~8.3.0", 58 | "tslint": "~6.1.0", 59 | "typescript": "~4.0.2", 60 | "@angular-devkit/architect": ">= 0.900 < 0.1200", 61 | "karma-coverage-istanbul-reporter": "~2.1.0", 62 | "prettier": "^2.2.1", 63 | "pretty-quick": "^3.1.0" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /screenshots/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/angular-animations-storefront/99cfee0e09752edfea068718ac44a245674f6cb6/screenshots/preview.gif -------------------------------------------------------------------------------- /src/.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "pre-commit": "pretty-quick --staged && ng lint", 4 | "pre-push": "ng build --aot true" 5 | } 6 | } -------------------------------------------------------------------------------- /src/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Angular Animations Storefront 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |                                           21 | 22 | 23 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { 6 | path: '', 7 | loadChildren: () => 8 | import('./features/home/home.module').then((m) => m.HomeModule), 9 | }, 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forRoot(routes)], 14 | exports: [RouterModule], 15 | }) 16 | export class AppRoutingModule {} 17 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
4 | 8 |
9 |
10 | 11 |
12 |
13 | 14 |
15 |
16 | 17 | 18 |
19 | 20 | 21 |
22 | 23 |
24 | 25 | 26 | 27 | 28 |
29 | 30 |
34 | 35 |
36 |
37 | 38 | 39 | 43 | 44 |
45 | 46 |
50 | 51 |
52 |
53 | 54 |
56 | 57 |
58 |
59 |
60 | 61 |
62 | 63 |
64 | 65 |
66 | View Without Animations 67 | 68 | View With Animations 69 | 70 |
71 |
72 |
73 | 74 |
-------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/angular-animations-storefront/99cfee0e09752edfea068718ac44a245674f6cb6/src/app/app.component.scss -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'auth0-ecommerce'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('auth0-ecommerce'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('auth0-ecommerce app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { transition, trigger, useAnimation } from '@angular/animations'; 2 | import { Component } from '@angular/core'; 3 | import { UIService } from './core'; 4 | import { bounceIn, bounceOut, SlideRight, Fade } from './shared'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.scss'], 10 | animations: [ 11 | SlideRight, 12 | Fade, 13 | trigger('bounce', [ 14 | transition( 15 | 'void => *', 16 | useAnimation(bounceIn, { 17 | params: { timing: 0.7 }, 18 | }) 19 | ), 20 | transition( 21 | '* => void', 22 | useAnimation(bounceOut, { 23 | params: { timing: 0.6 }, 24 | }) 25 | ), 26 | ]), 27 | ], 28 | }) 29 | export class AppComponent { 30 | cartIsOpened$ = this.uiService.selectCart$(); 31 | orderConfirmationIsOpened$ = this.uiService.selectOrderConfirmation$(); 32 | productDetails$ = this.uiService.selectProductDetails$(); 33 | animated$ = this.uiService.selectAnimated$(); 34 | 35 | constructor(private uiService: UIService) {} 36 | 37 | closeAllLayers(): void { 38 | if (this.uiService.selectCartCurrentValue()) { 39 | this.uiService.toggleCart(false); 40 | } 41 | if (this.uiService.selectOrderConfirmationCurrentValue()) { 42 | this.uiService.toggleOrderConfirmation(false); 43 | } 44 | if (this.uiService.productDetailsCurrentValue()) { 45 | this.uiService.closeProductDetails(); 46 | } 47 | } 48 | 49 | setAnimated(isAnimated: boolean): void { 50 | this.uiService.setAnimated(isAnimated); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { BrowserModule } from '@angular/platform-browser'; 5 | import { HttpClientModule } from '@angular/common/http'; 6 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 7 | import { AppRoutingModule } from './app-routing.module'; 8 | import { AppComponent } from './app.component'; 9 | import { SharedModule } from './shared'; 10 | 11 | @NgModule({ 12 | declarations: [AppComponent], 13 | imports: [ 14 | BrowserModule, 15 | CommonModule, 16 | FormsModule, 17 | HttpClientModule, 18 | BrowserAnimationsModule, 19 | AppRoutingModule, 20 | SharedModule, 21 | ], 22 | providers: [], 23 | bootstrap: [AppComponent], 24 | }) 25 | export class AppModule {} 26 | -------------------------------------------------------------------------------- /src/app/core/base/base-component.ts: -------------------------------------------------------------------------------- 1 | import { Directive, OnDestroy } from '@angular/core'; 2 | import { Subject } from 'rxjs'; 3 | import { Icons } from '../constants'; 4 | 5 | @Directive() 6 | export class BaseComponent implements OnDestroy { 7 | icons = Icons; 8 | destroy$ = new Subject(); 9 | 10 | ngOnDestroy(): void { 11 | this.destroy$.next(true); 12 | this.destroy$.complete(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/app/core/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base-component'; 2 | -------------------------------------------------------------------------------- /src/app/core/constants/icons.constants.ts: -------------------------------------------------------------------------------- 1 | import { 2 | faCartPlus, 3 | faShoppingCart, 4 | faTimes, 5 | } from '@fortawesome/free-solid-svg-icons'; 6 | 7 | export const Icons = { 8 | cartPlus: faCartPlus, 9 | cart: faShoppingCart, 10 | close: faTimes, 11 | }; 12 | -------------------------------------------------------------------------------- /src/app/core/constants/index.ts: -------------------------------------------------------------------------------- 1 | export * from './icons.constants'; 2 | -------------------------------------------------------------------------------- /src/app/core/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base'; 2 | export * from './constants'; 3 | export * from './services'; 4 | export * from './models'; 5 | -------------------------------------------------------------------------------- /src/app/core/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './product.model'; 2 | -------------------------------------------------------------------------------- /src/app/core/models/product.model.ts: -------------------------------------------------------------------------------- 1 | export interface IProduct { 2 | productId: number; 3 | title: string; 4 | description: string; 5 | longDescription: string; 6 | categories: Categories[]; 7 | type: ProductType; 8 | price: number; 9 | imageUrl: string; 10 | } 11 | 12 | export interface IProductType { 13 | displayName: string; 14 | typeKey: ProductType; 15 | } 16 | 17 | export enum ProductType { 18 | explore = 'explore', 19 | new = 'new', 20 | trending = 'trending', 21 | recommended = 'recommended', 22 | discount = 'discount', 23 | normal = 'normal', 24 | } 25 | 26 | export enum Categories { 27 | objects = 'objects', 28 | food = 'food', 29 | healthy = 'healthy', 30 | } 31 | -------------------------------------------------------------------------------- /src/app/core/services/cart.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { BehaviorSubject, Observable } from 'rxjs'; 3 | import { map } from 'rxjs/operators'; 4 | import { IProduct } from '../models'; 5 | 6 | @Injectable({ 7 | providedIn: 'root', 8 | }) 9 | export class CartService { 10 | private _stateSource$ = new BehaviorSubject({ 11 | products: [], 12 | }); 13 | state$ = this._stateSource$.asObservable(); 14 | 15 | addToCart(productToAdd: IProduct): void { 16 | const currentState = this._getCurrentState(); 17 | const productCartIndex = currentState.products.findIndex( 18 | (product) => product.productId === productToAdd.productId 19 | ); 20 | if (productCartIndex === -1) { 21 | this._stateSource$.next({ 22 | ...currentState, 23 | products: [ 24 | ...currentState.products, 25 | { 26 | ...productToAdd, 27 | count: 1, 28 | }, 29 | ], 30 | }); 31 | } else { 32 | this._stateSource$.next({ 33 | ...currentState, 34 | products: [ 35 | ...currentState.products.map((product, i) => { 36 | if (i === productCartIndex) { 37 | product.count += 1; 38 | } 39 | return product; 40 | }), 41 | ], 42 | }); 43 | } 44 | } 45 | 46 | removeFromCart(productId: number): void { 47 | const currentState = this._getCurrentState(); 48 | if ( 49 | currentState.products.find((product) => product.productId === productId) 50 | ) { 51 | const products = currentState.products; 52 | products.splice( 53 | currentState.products.findIndex( 54 | (product) => product.productId === productId 55 | ), 56 | 1 57 | ); 58 | this._stateSource$.next({ 59 | ...currentState, 60 | products: products, 61 | }); 62 | } 63 | } 64 | 65 | clearCart(): void { 66 | this._stateSource$.next({ 67 | ...this._getCurrentState(), 68 | products: [], 69 | }); 70 | } 71 | 72 | selectProducts$(): Observable { 73 | return this.state$.pipe(map((state) => state.products)); 74 | } 75 | 76 | selectTotalProductQuantity$(): Observable { 77 | return this.state$.pipe( 78 | map((state) => state.products.reduce((acc, curr) => acc + curr.count, 0)) 79 | ); 80 | } 81 | 82 | selectTotalPrice$(): Observable { 83 | return this.state$.pipe( 84 | map((state) => 85 | state.products.reduce((acc, curr) => acc + curr.price * curr.count, 0) 86 | ) 87 | ); 88 | } 89 | 90 | private _getCurrentState(): CartState { 91 | return this._stateSource$.value; 92 | } 93 | } 94 | 95 | export interface CartState { 96 | products: ICartProduct[]; 97 | } 98 | 99 | export interface ICartProduct extends IProduct { 100 | count: number; 101 | } 102 | -------------------------------------------------------------------------------- /src/app/core/services/data.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | import { map } from 'rxjs/operators'; 5 | import { environment } from '../../../environments/environment'; 6 | import { IProduct, IProductType } from '../models'; 7 | 8 | @Injectable({ 9 | providedIn: 'root', 10 | }) 11 | export class DataService { 12 | constructor(private http: HttpClient) {} 13 | 14 | getProducts$(): Observable { 15 | return this.getData$(this._getUrl('assets/local-data/products.json')).pipe( 16 | map((res) => res.products) 17 | ); 18 | } 19 | 20 | getProductTypes$(): Observable { 21 | return this.getData$( 22 | this._getUrl('assets/local-data/product-types.json') 23 | ).pipe(map((res) => res.productTypes)); 24 | } 25 | 26 | getData$(path: string): Observable { 27 | return this.http.get(path); 28 | } 29 | 30 | private _getUrl(path: string): string { 31 | return `${environment.baseUrl}/${path}`; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/app/core/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './data.service'; 2 | export * from './ui.service'; 3 | export * from './cart.service'; 4 | -------------------------------------------------------------------------------- /src/app/core/services/ui.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { BehaviorSubject, Observable } from 'rxjs'; 3 | import { map } from 'rxjs/operators'; 4 | import { IProduct, ProductType } from '../models'; 5 | 6 | @Injectable({ 7 | providedIn: 'root', 8 | }) 9 | export class UIService { 10 | private _stateSource$ = new BehaviorSubject({ 11 | // layers 12 | cartIsOpened: undefined, 13 | orderConfirmationIsOpened: undefined, 14 | productDetails: undefined, 15 | 16 | // filters 17 | searchQuery: '', 18 | productType: ProductType.explore, 19 | 20 | // animated 21 | animated: true, 22 | }); 23 | state$ = this._stateSource$.asObservable(); 24 | 25 | // Selects 26 | 27 | selectCart$(): Observable { 28 | return this.state$.pipe(map((state) => state.cartIsOpened)); 29 | } 30 | 31 | selectOrderConfirmation$(): Observable { 32 | return this.state$.pipe(map((state) => state.orderConfirmationIsOpened)); 33 | } 34 | 35 | selectProductDetails$(): Observable { 36 | return this.state$.pipe(map((state) => state.productDetails)); 37 | } 38 | 39 | selectSearchQuery$(): Observable { 40 | return this.state$.pipe(map((state) => state.searchQuery)); 41 | } 42 | 43 | selectProductType$(): Observable { 44 | return this.state$.pipe(map((state) => state.productType)); 45 | } 46 | 47 | selectAnimated$(): Observable { 48 | return this.state$.pipe(map((state) => state.animated)); 49 | } 50 | 51 | // Actions 52 | 53 | toggleCart(isOpened: boolean): void { 54 | this._stateSource$.next({ 55 | ...this._getCurrentState(), 56 | cartIsOpened: isOpened, 57 | }); 58 | } 59 | 60 | toggleOrderConfirmation(isOpened: boolean): void { 61 | this._stateSource$.next({ 62 | ...this._getCurrentState(), 63 | orderConfirmationIsOpened: isOpened, 64 | }); 65 | } 66 | 67 | setAnimated(isAnimated: boolean): void { 68 | this._stateSource$.next({ 69 | ...this._getCurrentState(), 70 | animated: isAnimated, 71 | }); 72 | } 73 | 74 | viewProductDetails(product: IProduct): void { 75 | this._stateSource$.next({ 76 | ...this._getCurrentState(), 77 | productDetails: product, 78 | }); 79 | } 80 | 81 | closeProductDetails(): void { 82 | this._stateSource$.next({ 83 | ...this._getCurrentState(), 84 | productDetails: null, 85 | }); 86 | } 87 | 88 | search(keyword: string): void { 89 | this._stateSource$.next({ 90 | ...this._getCurrentState(), 91 | searchQuery: keyword, 92 | }); 93 | } 94 | 95 | selectProductType(productType: ProductType): void { 96 | this._stateSource$.next({ 97 | ...this._getCurrentState(), 98 | productType: productType, 99 | }); 100 | } 101 | 102 | // Current Value 103 | 104 | selectCartCurrentValue(): boolean { 105 | return this._getCurrentState().cartIsOpened; 106 | } 107 | 108 | selectOrderConfirmationCurrentValue(): boolean { 109 | return this._getCurrentState().orderConfirmationIsOpened; 110 | } 111 | 112 | productDetailsCurrentValue(): IProduct { 113 | return this._getCurrentState().productDetails; 114 | } 115 | 116 | animatedCurrentValue(): boolean { 117 | return this._getCurrentState().animated; 118 | } 119 | 120 | private _getCurrentState(): UIState { 121 | return this._stateSource$.value; 122 | } 123 | } 124 | 125 | export interface UIState { 126 | // layers 127 | cartIsOpened: boolean; 128 | orderConfirmationIsOpened: boolean; 129 | productDetails: IProduct; 130 | 131 | // filters 132 | searchQuery: string; 133 | productType: ProductType; 134 | 135 | // animated 136 | animated: boolean; 137 | } 138 | -------------------------------------------------------------------------------- /src/app/features/home/home-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { HomeComponent } from './home.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: HomeComponent, 9 | }, 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | }) 16 | export class HomeRoutingModule {} 17 | -------------------------------------------------------------------------------- /src/app/features/home/home.component.html: -------------------------------------------------------------------------------- 1 |
2 |

{{ selectedProductType$ | async | titlecase }}

3 | 4 | 5 |
6 | 7 |
13 | 14 |
15 |
16 |
17 | 18 | 19 | No results found 20 | 21 |
22 |
-------------------------------------------------------------------------------- /src/app/features/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { combineLatest } from 'rxjs'; 3 | import { 4 | delay, 5 | distinctUntilChanged, 6 | map, 7 | takeUntil, 8 | tap, 9 | } from 'rxjs/operators'; 10 | import { BaseComponent, DataService, ProductType, UIService } from '../../core'; 11 | import { ScaleFadeStagger, ScaleFade } from '../../shared'; 12 | 13 | @Component({ 14 | selector: 'app-home', 15 | templateUrl: './home.component.html', 16 | animations: [ScaleFadeStagger, ScaleFade], 17 | }) 18 | export class HomeComponent extends BaseComponent { 19 | products = null; 20 | selectedProductType$ = this.uiService.selectProductType$(); 21 | productItems$ = combineLatest([ 22 | this.dataService.getProducts$(), 23 | this.uiService.selectSearchQuery$(), 24 | this.selectedProductType$, 25 | ]).pipe( 26 | takeUntil(this.destroy$), 27 | map(([products, keyword, productType]) => { 28 | if (productType && productType !== ProductType.explore) { 29 | products = products.filter((product) => product.type === productType); 30 | } 31 | if (keyword) { 32 | products = products.filter((product) => 33 | product.title.toLowerCase().includes(keyword.toLowerCase()) 34 | ); 35 | } 36 | return products; 37 | }), 38 | distinctUntilChanged((prev, curr) => prev.length === curr.length), 39 | tap(() => (this.products = null)), 40 | delay(500), 41 | tap((products) => (this.products = products)) 42 | ); 43 | 44 | constructor(private dataService: DataService, private uiService: UIService) { 45 | super(); 46 | this.productItems$.subscribe(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/features/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { SharedModule } from '../../shared'; 6 | import { HomeRoutingModule } from './home-routing.module'; 7 | import { HomeComponent } from './home.component'; 8 | 9 | @NgModule({ 10 | imports: [CommonModule, FormsModule, SharedModule, HomeRoutingModule], 11 | declarations: [HomeComponent], 12 | }) 13 | export class HomeModule {} 14 | -------------------------------------------------------------------------------- /src/app/shared/animations/bounce.animation.ts: -------------------------------------------------------------------------------- 1 | import { animation, style, animate, keyframes } from '@angular/animations'; 2 | 3 | export const DEFAULT_TIMING = '0.5'; 4 | 5 | export const bounceIn = animation( 6 | animate( 7 | '{{ timing }}s {{ delay }}s cubic-bezier(0.17, 0.89, 0.24, 1.11)', 8 | keyframes([ 9 | style({ 10 | opacity: 0, 11 | transform: 'scale3d(0.1, 0.1, 0.1) translate3d(0, 1000px, 0)', 12 | offset: 0, 13 | }), 14 | style({ 15 | opacity: 1, 16 | transform: 'scale3d(0.475, 0.475, 0.475) translate3d(0, -60px, 0)', 17 | offset: 0.6, 18 | }), 19 | style({ 20 | opacity: 1, 21 | transform: 'scale3d(1, 1, 1) translate3d(0,0,0)', 22 | offset: 1, 23 | }), 24 | ]) 25 | ), 26 | { params: { timing: DEFAULT_TIMING, delay: 0 } } 27 | ); 28 | 29 | export const bounceOut = animation( 30 | animate( 31 | '{{ timing }}s {{ delay }}s cubic-bezier(0.6, 0.72, 0, 1)', 32 | keyframes([ 33 | style({ 34 | opacity: 1, 35 | transform: 'scale3d(0.475, 0.475, 0.475) translate3d(0, -60px, 0)', 36 | offset: 0.3, 37 | }), 38 | style({ 39 | opacity: 0, 40 | transform: 'scale3d(0.1, 0.1, 0.1) translate3d(0, 500px, 0)', 41 | offset: 1, 42 | }), 43 | ]) 44 | ), 45 | { params: { timing: DEFAULT_TIMING, delay: 0 } } 46 | ); 47 | -------------------------------------------------------------------------------- /src/app/shared/animations/fade.animation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | transition, 3 | style, 4 | animate, 5 | trigger, 6 | animation, 7 | } from '@angular/animations'; 8 | 9 | export const Fade = trigger('fade', [ 10 | transition( 11 | ':enter', 12 | animation([ 13 | style({ opacity: 0 }), 14 | animate( 15 | '0.3s cubic-bezier(0.59, 0.32, 0.38, 1.13)', 16 | style({ opacity: 1 }) 17 | ), 18 | ]) 19 | ), 20 | transition( 21 | ':leave', 22 | animation([ 23 | style({ opacity: 1 }), 24 | animate( 25 | '0.3s cubic-bezier(0.59, 0.32, 0.38, 1.13)', 26 | style({ opacity: 0 }) 27 | ), 28 | ]) 29 | ), 30 | ]); 31 | -------------------------------------------------------------------------------- /src/app/shared/animations/index.ts: -------------------------------------------------------------------------------- 1 | export * from './slide.animation'; 2 | export * from './scale.animation'; 3 | export * from './bounce.animation'; 4 | export * from './fade.animation'; 5 | -------------------------------------------------------------------------------- /src/app/shared/animations/scale.animation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | transition, 3 | style, 4 | animate, 5 | trigger, 6 | stagger, 7 | query, 8 | animation, 9 | } from '@angular/animations'; 10 | 11 | export const ScaleFade = trigger('scaleFade', [ 12 | transition( 13 | ':enter', 14 | animation([ 15 | style({ opacity: 0, transform: 'scale(0.8, 0.8)' }), 16 | animate( 17 | '0.3s ease-in-out', 18 | style({ opacity: 1, transform: 'scale(1, 1)' }) 19 | ), 20 | ]) 21 | ), 22 | transition( 23 | ':leave', 24 | animation([ 25 | animate( 26 | '0.3s ease-in-out', 27 | style({ 28 | opacity: 0, 29 | transform: 'scale(0.8, 0.8)', 30 | }) 31 | ), 32 | ]) 33 | ), 34 | ]); 35 | 36 | export const ScaleFadeStagger = trigger('scaleFadeStagger', [ 37 | transition(':enter', [ 38 | query( 39 | ':enter', 40 | [ 41 | style({ opacity: 0, transform: 'scale(0.8, 0.8)' }), 42 | stagger('50ms', [ 43 | animate( 44 | '300ms 300ms', 45 | style({ opacity: 1, transform: 'scale(1, 1)' }) 46 | ), 47 | ]), 48 | ], 49 | { optional: true } 50 | ), 51 | ]), 52 | transition(':leave', [ 53 | query( 54 | ':leave', 55 | [ 56 | stagger('50ms', [ 57 | animate('300ms', style({ opacity: 0, transform: 'scale(0.8, 0.8)' })), 58 | ]), 59 | ], 60 | { optional: true } 61 | ), 62 | ]), 63 | ]); 64 | -------------------------------------------------------------------------------- /src/app/shared/animations/slide.animation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | transition, 3 | style, 4 | animate, 5 | trigger, 6 | useAnimation, 7 | animation, 8 | } from '@angular/animations'; 9 | 10 | export const SlideEnterAnimation = animation([ 11 | style({ transform: 'translate({{ x }}, {{ y }})' }), 12 | animate( 13 | '{{ duration }} cubic-bezier(0.59, 0.32, 0.38, 1.13)', 14 | style({ transform: 'translate(0)' }) 15 | ), 16 | ]); 17 | 18 | export const SlideExitAnimation = animation([ 19 | style({ transform: 'translate(0)' }), 20 | animate( 21 | '{{ duration }} cubic-bezier(0.59, 0.32, 0.38, 1.13)', 22 | style({ transform: 'translate({{ x }}, {{ y }})' }) 23 | ), 24 | ]); 25 | 26 | // export const SlideToCart = trigger('slideToCart', [ 27 | // transition( 28 | // ':enter', 29 | // animate('300ms', style({ 30 | // transform: 'translate(' 31 | // })) 32 | // ), 33 | // // transition( 34 | // // ':leave', 35 | // // useAnimation(SlideExitAnimation, { 36 | // // params: { x: `-${window.innerWidth}px`, y: 0, duration: '0.5s' }, 37 | // // }) 38 | // // ), 39 | // ]); 40 | 41 | export const SlideLeft = trigger('slideLeft', [ 42 | transition( 43 | ':enter', 44 | useAnimation(SlideEnterAnimation, { 45 | params: { x: `-${window.innerWidth}px`, y: 0, duration: '0.5s' }, 46 | }) 47 | ), 48 | transition( 49 | ':leave', 50 | useAnimation(SlideExitAnimation, { 51 | params: { x: `-${window.innerWidth}px`, y: 0, duration: '0.5s' }, 52 | }) 53 | ), 54 | ]); 55 | 56 | export const SlideRight = trigger('slideRight', [ 57 | transition( 58 | ':enter', 59 | useAnimation(SlideEnterAnimation, { 60 | params: { x: `${window.innerWidth}px`, y: 0, duration: '0.5s' }, 61 | }) 62 | ), 63 | transition( 64 | ':leave', 65 | useAnimation(SlideExitAnimation, { 66 | params: { x: `${window.innerWidth}px`, y: 0, duration: '0.5s' }, 67 | }) 68 | ), 69 | ]); 70 | 71 | export const SlideFadeLeft = trigger('slideFadeLeft', [ 72 | transition( 73 | ':enter', 74 | animation([ 75 | style({ opacity: 0, height: 0, transform: 'translate(100px, 0)' }), 76 | animate( 77 | '0.3s cubic-bezier(0.59, 0.32, 0.38, 1.13)', 78 | style({ opacity: 1, height: '*', transform: 'translate(0, 0)' }) 79 | ), 80 | ]) 81 | ), 82 | transition( 83 | ':leave', 84 | animation([ 85 | animate( 86 | '0.3s cubic-bezier(0.59, 0.32, 0.38, 1.13)', 87 | style({ opacity: 0, height: 0, transform: 'translate(100px, 0)' }) 88 | ), 89 | ]) 90 | ), 91 | ]); 92 | -------------------------------------------------------------------------------- /src/app/shared/components/cards/cart-product-card/cart-product-card.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | {{ product?.title }} 5 | Quantity: {{ product?.count }} 6 | 9 |
10 | ${{ product?.price }} 11 |
-------------------------------------------------------------------------------- /src/app/shared/components/cards/cart-product-card/cart-product-card.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | import { CartService, ICartProduct } from '../../../../core'; 3 | 4 | @Component({ 5 | selector: 'app-cart-product-card', 6 | templateUrl: './cart-product-card.component.html', 7 | }) 8 | export class CartProductCardComponent { 9 | @Input() product: ICartProduct; 10 | 11 | constructor(private cartService: CartService) {} 12 | 13 | removeFromCart(productId: number): void { 14 | this.cartService.removeFromCart(productId); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/app/shared/components/cards/index.ts: -------------------------------------------------------------------------------- 1 | import { ProductCardComponent } from './product-card/product-card.component'; 2 | import { CartProductCardComponent } from './cart-product-card/cart-product-card.component'; 3 | export const CARD_COMPONENTS = [ProductCardComponent, CartProductCardComponent]; 4 | 5 | export * from './product-card/product-card.component'; 6 | export * from './cart-product-card/cart-product-card.component'; 7 | -------------------------------------------------------------------------------- /src/app/shared/components/cards/product-card/product-card.component.html: -------------------------------------------------------------------------------- 1 |
3 | 6 |
7 | 8 |
9 |
10 | 11 | 12 | 13 |
14 |
15 | 16 |
17 |
18 | 21 |
22 | 23 |
24 | 25 |
26 | {{ product?.title }} 27 | {{ product?.description }} 28 | ${{ product?.price }} 29 |
30 |
31 |
32 |
-------------------------------------------------------------------------------- /src/app/shared/components/cards/product-card/product-card.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, ViewChild, ElementRef } from '@angular/core'; 2 | import { 3 | BaseComponent, 4 | CartService, 5 | IProduct, 6 | UIService, 7 | } from '../../../../core'; 8 | import { SlideRight } from '../../../animations'; 9 | 10 | @Component({ 11 | selector: 'app-product-card', 12 | templateUrl: './product-card.component.html', 13 | animations: [SlideRight], 14 | }) 15 | export class ProductCardComponent extends BaseComponent { 16 | @Input() product: IProduct; 17 | @ViewChild('addToCartLayer') addToCartLayer: ElementRef; 18 | @ViewChild('displayCard') displayCard: ElementRef; 19 | 20 | animated$ = this.uiService.selectAnimated$(); 21 | private _isAdding = false; 22 | constructor(private cartService: CartService, private uiService: UIService) { 23 | super(); 24 | } 25 | 26 | addToCart(selectedProduct: IProduct): void { 27 | // if in the middle of an animation, wait until its done prior 28 | // to allowing the user to add to cart again 29 | if (this._isAdding) { 30 | return; 31 | } 32 | this.cartService.addToCart(selectedProduct); 33 | if (this.uiService.animatedCurrentValue()) { 34 | this._isAdding = true; 35 | this._animateCard(); 36 | } 37 | } 38 | 39 | viewProductDetails(selectedProduct: IProduct): void { 40 | this.uiService.viewProductDetails(selectedProduct); 41 | } 42 | 43 | private _animateCard(): void { 44 | this.addToCartLayer.nativeElement.style.visibility = 'visible'; 45 | this.addToCartLayer.nativeElement.style.opacity = 1; 46 | const DOMrect = this.displayCard.nativeElement.getBoundingClientRect(); 47 | const offsetX = 48 | (window.innerWidth || 49 | document.documentElement.clientWidth || 50 | document.body.clientWidth) - 51 | DOMrect.x - 52 | 50; 53 | const offsetY = -DOMrect.y + 50; 54 | const offsetPath = `path("m 150 140 Q ${offsetX / 2} ${ 55 | offsetY - 100 56 | } ${offsetX} ${offsetY}")`; 57 | this.addToCartLayer.nativeElement.style.offsetPath = offsetPath; 58 | const addToCartAnimation = this.addToCartLayer.nativeElement.animate( 59 | [ 60 | { 61 | offsetDistance: 0, 62 | offsetRotate: '0deg', 63 | }, 64 | { 65 | offsetDistance: '100%', 66 | transform: 'scale(0,0)', 67 | offsetRotate: '0deg', 68 | opacity: 0, 69 | }, 70 | ], 71 | { 72 | duration: 800, 73 | easing: 'ease-in-out', 74 | fill: 'none', 75 | } 76 | ); 77 | addToCartAnimation.onfinish = () => { 78 | this.addToCartLayer.nativeElement.style.visibility = 'hidden'; 79 | this.addToCartLayer.nativeElement.style.offsetDistance = 0; 80 | this._isAdding = false; 81 | }; 82 | } 83 | 84 | noop(event): void { 85 | event.stopPropagation(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/app/shared/components/header/header.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 9 |
10 | 11 |
12 | 23 |
24 |
-------------------------------------------------------------------------------- /src/app/shared/components/header/header.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ElementRef, ViewChild } from '@angular/core'; 2 | import { delay, map, tap, withLatestFrom } from 'rxjs/operators'; 3 | import { BaseComponent, CartService, UIService } from '../../../core'; 4 | 5 | @Component({ 6 | selector: 'app-header', 7 | templateUrl: './header.component.html', 8 | }) 9 | export class HeaderComponent extends BaseComponent { 10 | @ViewChild('cartButton') cartButton: ElementRef; 11 | searchQuery = ''; 12 | cartCount$ = this.cartService.selectTotalProductQuantity$().pipe( 13 | delay(600), 14 | withLatestFrom(this.uiService.selectAnimated$()), 15 | tap(([count, isAnimated]) => { 16 | if (isAnimated && count > 0 && this.cartButton?.nativeElement) { 17 | this.cartButton.nativeElement.animate( 18 | [ 19 | // keyframes 20 | { transform: 'translate3d(0, -5px, 0) scaleY(1.1)' }, 21 | { transform: 'translate3d(0, -10px, 0) scaleY(1.05)' }, 22 | { transform: 'translate3d(0, 5px, 0) scaleY(0.95)' }, 23 | { transform: 'translate3d(0, 0, 0) scaleY(1)' }, 24 | ], 25 | { 26 | // timing options 27 | duration: 200, 28 | } 29 | ); 30 | } 31 | }), 32 | map(([count, isAnimated]) => count) 33 | ); 34 | 35 | constructor(private uiService: UIService, private cartService: CartService) { 36 | super(); 37 | } 38 | 39 | openCart(): void { 40 | this.uiService.toggleCart(true); 41 | } 42 | 43 | onSearch(keyword: string): void { 44 | this.uiService.search(keyword); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/shared/components/index.ts: -------------------------------------------------------------------------------- 1 | import { from } from 'rxjs'; 2 | import { CARD_COMPONENTS } from './cards'; 3 | import { HeaderComponent } from './header/header.component'; 4 | import { LAYERS } from './layers'; 5 | import { MenuComponent } from './menu/menu.component'; 6 | 7 | export const COMPONENTS = [ 8 | HeaderComponent, 9 | MenuComponent, 10 | ...LAYERS, 11 | ...CARD_COMPONENTS, 12 | ]; 13 | 14 | export * from './header/header.component'; 15 | export * from './menu/menu.component'; 16 | export * from './cards'; 17 | export * from './layers'; 18 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/cart/cart.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

YOUR SHOPPING CART

4 | 5 | 8 |
9 | 10 | 11 |
12 | 13 |
14 | 15 |
16 |
17 |
18 | 19 | 20 |
21 |

TOTAL

22 |

${{ totalPrice }}

23 |
24 |
25 | 26 |
27 | 32 |
33 |
34 | 35 | 36 |
37 |
38 | 39 | 40 |

Your cart is Empty

41 |

Looks like you haven't added anything to your cart yet

42 |
43 |
44 |
45 |
-------------------------------------------------------------------------------- /src/app/shared/components/layers/cart/cart.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { BaseComponent, CartService, UIService } from '../../../../core'; 3 | import { SlideFadeLeft } from '../../../animations'; 4 | 5 | @Component({ 6 | selector: 'app-cart', 7 | templateUrl: './cart.component.html', 8 | animations: [SlideFadeLeft], 9 | }) 10 | export class CartComponent extends BaseComponent { 11 | products$ = this.cartService.selectProducts$(); 12 | totalPrice$ = this.cartService.selectTotalPrice$(); 13 | constructor(private uiService: UIService, private cartService: CartService) { 14 | super(); 15 | } 16 | 17 | closeCart(): void { 18 | this.uiService.toggleCart(false); 19 | } 20 | 21 | checkout(): void { 22 | this.uiService.toggleOrderConfirmation(true); 23 | this.cartService.clearCart(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/index.ts: -------------------------------------------------------------------------------- 1 | import { CartComponent } from './cart/cart.component'; 2 | import { OrderConfirmationComponent } from './order-confirmation/order-confirmation.component'; 3 | import { CartButtonComponent } from './product-details/cart-button/cart-button.component'; 4 | import { ProductDetailsComponent } from './product-details/product-details.component'; 5 | 6 | export const LAYERS = [ 7 | CartComponent, 8 | OrderConfirmationComponent, 9 | ProductDetailsComponent, 10 | CartButtonComponent, 11 | ]; 12 | 13 | export * from './cart/cart.component'; 14 | export * from './order-confirmation/order-confirmation.component'; 15 | export * from './product-details/product-details.component'; 16 | export * from './product-details/cart-button/cart-button.component'; 17 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/order-confirmation/order-confirmation.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 |
7 | 8 | 9 |

Thank you for your Order!

10 | 11 |

12 | Your random objects order has been placed successfully. You should get a confirmation email with a random tracking information. 13 |

14 |
-------------------------------------------------------------------------------- /src/app/shared/components/layers/order-confirmation/order-confirmation.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { BaseComponent, UIService } from '../../../../core'; 3 | 4 | @Component({ 5 | selector: 'app-order-confirmation', 6 | templateUrl: './order-confirmation.component.html', 7 | }) 8 | export class OrderConfirmationComponent extends BaseComponent { 9 | constructor(private uiService: UIService) { 10 | super(); 11 | } 12 | 13 | closeOrderConfirmation(): void { 14 | this.uiService.toggleOrderConfirmation(false); 15 | } 16 | 17 | noop(event) { 18 | event.stopPropagation(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/product-details/cart-button/cart-button.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/product-details/cart-button/cart-button.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | import { 3 | animate, 4 | animation, 5 | style, 6 | transition, 7 | trigger, 8 | } from '@angular/animations'; 9 | import { 10 | BaseComponent, 11 | CartService, 12 | IProduct, 13 | UIService, 14 | } from '../../../../../core'; 15 | 16 | @Component({ 17 | selector: 'app-cart-button', 18 | templateUrl: './cart-button.component.html', 19 | animations: [ 20 | trigger('addToCartText', [ 21 | transition( 22 | ':enter', 23 | animation([ 24 | style({ 25 | transform: 'translate(200px,0)', 26 | }), 27 | animate( 28 | '0.3s cubic-bezier(0.59, 0.32, 0.38, 1.13)', 29 | style({ 30 | transform: 'translate(0)', 31 | }) 32 | ), 33 | ]) 34 | ), 35 | transition( 36 | ':leave', 37 | animation([ 38 | style({ transform: 'translate(0)' }), 39 | animate( 40 | '0.3s cubic-bezier(0.59, 0.32, 0.38, 1.13)', 41 | style({ 42 | transform: 'translate(-200px,0)', 43 | }) 44 | ), 45 | ]) 46 | ), 47 | ]), 48 | ], 49 | }) 50 | export class CartButtonComponent extends BaseComponent { 51 | @Input() product: IProduct; 52 | addState: 'DEFAULT' | 'ADDED' = 'DEFAULT'; 53 | animated$ = this.uiService.selectAnimated$(); 54 | 55 | constructor(private uiService: UIService, private cartService: CartService) { 56 | super(); 57 | } 58 | 59 | addToCart(): void { 60 | if (this.addState === 'ADDED') { 61 | return; 62 | } 63 | this.addState = 'ADDED'; 64 | this.cartService.addToCart(this.product); 65 | 66 | // reset to default state 67 | // some delay here to simulate some processing time 68 | // when user clicks on add to cart 69 | setTimeout(() => { 70 | this.addState = 'DEFAULT'; 71 | }, 2000); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/product-details/product-details.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 |
7 |
8 | 9 | 10 | 11 |
12 | 13 |
14 | 15 |
16 |

{{ product.title }}

17 | ${{ product?.price }} 18 |

19 | {{ product.description }} 20 |

21 | 22 |

23 | {{ product.longDescription }} 24 |

25 | 26 | 27 |

Categories

28 |
29 |
30 | {{ category }} 31 |
32 |
33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 |
41 |
-------------------------------------------------------------------------------- /src/app/shared/components/layers/product-details/product-details.component.scss: -------------------------------------------------------------------------------- 1 | .product-details-container { 2 | max-height: 80vh; 3 | overflow-y: hidden; 4 | } 5 | -------------------------------------------------------------------------------- /src/app/shared/components/layers/product-details/product-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | import { BaseComponent, IProduct, UIService } from '../../../../core'; 3 | 4 | @Component({ 5 | selector: 'app-product-details', 6 | templateUrl: './product-details.component.html', 7 | styleUrls: ['./product-details.component.scss'], 8 | }) 9 | export class ProductDetailsComponent extends BaseComponent { 10 | @Input() product: IProduct; 11 | 12 | constructor(private uiService: UIService) { 13 | super(); 14 | } 15 | 16 | closeProductDetails(): void { 17 | this.uiService.closeProductDetails(); 18 | } 19 | 20 | noop(event) { 21 | event.stopPropagation(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/shared/components/menu/menu.component.html: -------------------------------------------------------------------------------- 1 |
2 |
    3 | 4 | 5 | 6 |
  • 7 | 15 |
  • 16 |
    17 |
    18 |
    19 |
20 |
-------------------------------------------------------------------------------- /src/app/shared/components/menu/menu.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { 3 | animate, 4 | animation, 5 | style, 6 | state, 7 | transition, 8 | trigger, 9 | } from '@angular/animations'; 10 | import { 11 | BaseComponent, 12 | DataService, 13 | ProductType, 14 | UIService, 15 | } from '../../../core'; 16 | 17 | @Component({ 18 | selector: 'app-menu', 19 | templateUrl: './menu.component.html', 20 | animations: [ 21 | trigger('menuOptionsBackground', [ 22 | state('DEFAULT', style({ backgroundColor: 'transparent' })), 23 | state('ACTIVE', style({ backgroundColor: '#93C5FE' })), 24 | transition('* => *', animate('0.3s ease-in-out')), 25 | ]), 26 | ], 27 | }) 28 | export class MenuComponent extends BaseComponent { 29 | productTypes$ = this.dataService.getProductTypes$(); 30 | selectedProductType$ = this.uiService.selectProductType$(); 31 | animated$ = this.uiService.selectAnimated$(); 32 | constructor(private dataService: DataService, private uiService: UIService) { 33 | super(); 34 | } 35 | 36 | selectMenuItem(productType: ProductType): void { 37 | this.uiService.selectProductType(productType); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/app/shared/index.ts: -------------------------------------------------------------------------------- 1 | export * from './components'; 2 | export * from './animations'; 3 | export * from './shared.module'; 4 | -------------------------------------------------------------------------------- /src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; 5 | import { COMPONENTS } from './components'; 6 | 7 | @NgModule({ 8 | imports: [CommonModule, FormsModule, FontAwesomeModule], 9 | declarations: [...COMPONENTS], 10 | exports: [...COMPONENTS], 11 | }) 12 | export class SharedModule {} 13 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/angular-animations-storefront/99cfee0e09752edfea068718ac44a245674f6cb6/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/images/order-confirmation.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/assets/images/potted-plant.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/assets/local-data/product-types.json: -------------------------------------------------------------------------------- 1 | { 2 | "productTypes": [ 3 | { 4 | "displayName": "Explore", 5 | "typeKey": "explore" 6 | }, 7 | { 8 | "displayName": "New", 9 | "typeKey": "new" 10 | }, 11 | { 12 | "displayName": "Trending", 13 | "typeKey": "trending" 14 | }, 15 | { 16 | "displayName": "For you", 17 | "typeKey": "recommended" 18 | }, 19 | { 20 | "displayName": "Random", 21 | "typeKey": "random" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /src/assets/local-data/products.json: -------------------------------------------------------------------------------- 1 | { 2 | "products": [ 3 | { 4 | "productId": 1, 5 | "title": "Sunshine Telephone", 6 | "description": "Take a call from the sun", 7 | "longDescription": "This phone lets you get a tan whenever you want! Just pick up the phone and feel the sun rays warm your skin.", 8 | "catagories": ["objects"], 9 | "type": "new", 10 | "price": 15, 11 | "imageUrl": "https://source.unsplash.com/-haAxbjiHds/700x700" 12 | }, 13 | { 14 | "productId": 2, 15 | "title": "Just the Cone", 16 | "description": "Sugar-free ice-cream", 17 | "catagories": ["objects"], 18 | "type": "recommended", 19 | "price": 5, 20 | "imageUrl": "https://source.unsplash.com/Rz5o0osnN6Q/700x700" 21 | }, 22 | { 23 | "productId": 3, 24 | "title": "Pink Grapes", 25 | "description": "Tastes like strawberry", 26 | "catagories": ["objects"], 27 | "type": "new", 28 | "price": 7, 29 | "imageUrl": "https://source.unsplash.com/pz_hAv6ER7c/700x700" 30 | }, 31 | { 32 | "productId": 4, 33 | "title": "Lobster", 34 | "description": "Yum, seafood", 35 | "catagories": ["objects"], 36 | "type": "trending", 37 | "price": 30, 38 | "imageUrl": "https://source.unsplash.com/YeOMRwgvPv4/700x700" 39 | }, 40 | { 41 | "productId": 5, 42 | "title": "Cherries", 43 | "description": "Cherrific!!", 44 | "catagories": ["objects"], 45 | "type": "trending", 46 | "price": 15, 47 | "imageUrl": "https://source.unsplash.com/vbAEHCrvXZ0/700x700" 48 | }, 49 | { 50 | "productId": 6, 51 | "title": "Playstation Controller", 52 | "description": "Break time", 53 | "catagories": ["objects"], 54 | "type": "trending", 55 | "price": 20, 56 | "imageUrl": "https://source.unsplash.com/IJyXoyGmiZY/700x700" 57 | }, 58 | { 59 | "productId": 7, 60 | "title": "Brussel Sprouts", 61 | "description": "Baby cabbage", 62 | "catagories": ["objects"], 63 | "type": "trending", 64 | "price": 2, 65 | "imageUrl": "https://source.unsplash.com/g733A40xl3Q/700x700" 66 | }, 67 | { 68 | "productId": 8, 69 | "title": "Pink Pineapple", 70 | "description": "Is this even edible?", 71 | "catagories": ["objects"], 72 | "type": "new", 73 | "price": 20, 74 | "imageUrl": "https://source.unsplash.com/9f55wJpnCwY/700x700" 75 | }, 76 | { 77 | "productId": 9, 78 | "title": "Donuts", 79 | "description": "Coffee's best friend", 80 | "catagories": ["objects"], 81 | "type": "trending", 82 | "price": 10, 83 | "imageUrl": "https://source.unsplash.com/PFzy4N0_R3M/700x700" 84 | }, 85 | { 86 | "productId": 10, 87 | "title": "Retro Gaming System", 88 | "description": "Before gaming was cool", 89 | "catagories": ["objects"], 90 | "type": "new", 91 | "price": 25, 92 | "imageUrl": "https://source.unsplash.com/v8XaVfyo41Q/700x700" 93 | }, 94 | { 95 | "productId": 11, 96 | "title": "Stool", 97 | "description": "People gotta sit", 98 | "catagories": ["objects"], 99 | "type": "new", 100 | "price": "20", 101 | "imageUrl": "https://source.unsplash.com/4kTbAMRAHtQ/700x700" 102 | }, 103 | { 104 | "productId": 12, 105 | "title": "Icecream", 106 | "description": "Always room for dessert", 107 | "catagories": ["objects"], 108 | "type": "new", 109 | "price": 10, 110 | "imageUrl": "https://source.unsplash.com/TLD6iCOlyb0/700x700" 111 | }, 112 | { 113 | "productId": 13, 114 | "title": "Tennis Court", 115 | "description": "Nothing too big that we can't sell", 116 | "catagories": ["objects"], 117 | "type": "recommended", 118 | "price": 50, 119 | "imageUrl": "https://source.unsplash.com/aG6ByqGXiXg/700x700" 120 | }, 121 | { 122 | "productId": 14, 123 | "title": "Cake", 124 | "description": "Everything is cake", 125 | "catagories": ["objects"], 126 | "type": "trending", 127 | "price": 5, 128 | "imageUrl": "https://source.unsplash.com/1Hh57OhkdCc/700x700" 129 | }, 130 | { 131 | "productId": 15, 132 | "title": "Avocado", 133 | "description": "What's up Guac?", 134 | "catagories": ["objects"], 135 | "type": "trending", 136 | "price": 10, 137 | "imageUrl": "https://source.unsplash.com/9aOswReDKPo/700x700" 138 | } 139 | ] 140 | } 141 | 142 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | baseUrl: '/angular-animations-storefront', 4 | }; 5 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | baseUrl: './', 8 | }; 9 | 10 | /* 11 | * For easier debugging in development mode, you can import the following file 12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 13 | * 14 | * This import should be commented out in production mode because it will have a negative impact 15 | * on performance if an error is thrown. 16 | */ 17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 18 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/angular-animations-storefront/99cfee0e09752edfea068718ac44a245674f6cb6/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular Animations Storefront 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | // for code sandbox 5 | import 'core-js/proposals/reflect-metadata'; 6 | 7 | import { AppModule } from './app/app.module'; 8 | import { environment } from './environments/environment'; 9 | 10 | if (environment.production) { 11 | enableProdMode(); 12 | } 13 | 14 | platformBrowserDynamic() 15 | .bootstrapModule(AppModule) 16 | .catch((err) => console.error(err)); 17 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | // [STACKBLITZ]: this import doesn't work in stackblitz, see index.html 2 | // @import 'tailwindcss/base'; 3 | // @import 'tailwindcss/components'; 4 | // @import 'tailwindcss/utilities'; 5 | /* You can add global styles to this file, and also import other style files */ 6 | 7 | .hover-shadow { 8 | transform: scale(1, 1); 9 | transition: transform 0.2s ease-in-out; 10 | 11 | /* Pre-render the bigger shadow, but hide it */ 12 | &:hover { 13 | transform: scale(1.03, 1.03); 14 | transition: transform 0.2s ease-in-out; 15 | } 16 | &::after { 17 | box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 18 | 0 10px 10px -5px rgba(0, 0, 0, 0.04); 19 | opacity: 0; 20 | display: inline-block; 21 | content: ''; 22 | position: absolute; 23 | z-index: -1; 24 | top: 0; 25 | left: 0; 26 | width: 100%; 27 | height: 100%; 28 | border-radius: 0.75rem; 29 | transition: opacity 0.2s ease-in-out; 30 | } 31 | /* Transition to showing the bigger shadow on hover */ 32 | &:hover::after { 33 | opacity: 1; 34 | } 35 | } 36 | 37 | .hover-dim { 38 | opacity: 1; 39 | transition: opacity 0.2s ease-in-out; 40 | &:hover { 41 | opacity: 0.5; 42 | } 43 | } 44 | 45 | .hover-bounce { 46 | -webkit-animation-duration: 1s; 47 | animation-duration: 1s; 48 | -webkit-animation-fill-mode: both; 49 | animation-fill-mode: both; 50 | -webkit-animation-timing-function: ease-in-out; 51 | animation-timing-function: ease-in-out; 52 | animation-iteration-count: infinite; 53 | -webkit-animation-iteration-count: infinite; 54 | &:hover { 55 | animation-name: bounce; 56 | -moz-animation-name: bounce; 57 | } 58 | } 59 | 60 | @keyframes bounce { 61 | 0%, 62 | 100%, 63 | 20%, 64 | 50%, 65 | 80% { 66 | -webkit-transform: translateY(0); 67 | -ms-transform: translateY(0); 68 | transform: translateY(0); 69 | } 70 | 40% { 71 | -webkit-transform: translateY(-15px); 72 | -ms-transform: translateY(-15px); 73 | transform: translateY(-15px); 74 | } 75 | 60% { 76 | -webkit-transform: translateY(-7px); 77 | -ms-transform: translateY(-7px); 78 | transform: translateY(-7px); 79 | } 80 | } 81 | 82 | .hover-softbounce-once { 83 | -webkit-animation-duration: 1s; 84 | animation-duration: 1s; 85 | -webkit-animation-fill-mode: both; 86 | animation-fill-mode: both; 87 | -webkit-animation-timing-function: ease-in-out; 88 | animation-timing-function: ease-in-out; 89 | animation-iteration-count: 1; 90 | -webkit-animation-iteration-count: 1; 91 | &:hover { 92 | animation-name: softbounce; 93 | -moz-animation-name: softbounce; 94 | } 95 | } 96 | 97 | @keyframes softbounce { 98 | 0%, 99 | 100%, 100 | 20%, 101 | 50%, 102 | 80% { 103 | -webkit-transform: translateY(0); 104 | -ms-transform: translateY(0); 105 | transform: translateY(0); 106 | } 107 | 40% { 108 | -webkit-transform: translateY(-5px); 109 | -ms-transform: translateY(-5px); 110 | transform: translateY(-5px); 111 | } 112 | 60% { 113 | -webkit-transform: translateY(-3px); 114 | -ms-transform: translateY(-3px); 115 | transform: translateY(-3px); 116 | } 117 | } 118 | 119 | .blur { 120 | backdrop-filter: blur(1px); 121 | } 122 | 123 | img { 124 | object-fit: cover; 125 | } 126 | 127 | // [STACKBLITZ]: this is to replace the masonry layout in tailwind.config.js 128 | .masonry { 129 | grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); 130 | } 131 | .auto-rows-5 { 132 | grid-auto-rows: 5rem; 133 | } 134 | 135 | /*kill the transitions on any descendant elements of .notransition*/ 136 | .noanimation * { 137 | -webkit-transition: none !important; 138 | -moz-transition: none !important; 139 | -o-transition: none !important; 140 | -ms-transition: none !important; 141 | transition: none !important; 142 | -webkit-animation: none !important; 143 | -moz-animation: none !important; 144 | -o-animation: none !important; 145 | -ms-animation: none !important; 146 | animation: none !important; 147 | } 148 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = (isProd) => ({ 2 | prefix: '', 3 | purge: { 4 | enabled: isProd, 5 | content: [ 6 | '**/*.html', 7 | '**/*.ts', 8 | ] 9 | }, 10 | darkMode: false, // or 'media' or 'class' 11 | theme: { 12 | fontFamily: { 13 | 'body': ['Dosis', 'Open Sans'], 14 | }, 15 | extend: { 16 | gridTemplateColumns: { 17 | 'auto-fill': 'repeat(auto-fill, minmax(250px, 1fr))', 18 | }, 19 | gridAutoRows: { 20 | '3': '3rem', 21 | '5': '5rem' 22 | } 23 | }, 24 | }, 25 | variants: { 26 | extend: {}, 27 | }, 28 | plugins: [], 29 | }); 30 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "paths": { 20 | "@app/core/*": ["src/app/core/*"], 21 | "@app/core": ["src/app/core/index.ts"], 22 | "@app/shared/*": ["src/app/shared/*"], 23 | "@app/shared": ["src/app/shared/index.ts"] 24 | }, 25 | "angularCompilerOptions": { 26 | "fullTemplateTypeCheck": true, 27 | "strictInjectionParameters": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef-whitespace": { 98 | "options": [ 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | }, 106 | { 107 | "call-signature": "onespace", 108 | "index-signature": "onespace", 109 | "parameter": "onespace", 110 | "property-declaration": "onespace", 111 | "variable-declaration": "onespace" 112 | } 113 | ] 114 | }, 115 | "variable-name": { 116 | "options": [ 117 | "ban-keywords", 118 | "check-format", 119 | "allow-pascal-case" 120 | ] 121 | }, 122 | "whitespace": { 123 | "options": [ 124 | "check-branch", 125 | "check-decl", 126 | "check-operator", 127 | "check-separator", 128 | "check-type", 129 | "check-typecast" 130 | ] 131 | }, 132 | "no-conflicting-lifecycle": true, 133 | "no-host-metadata-property": true, 134 | "no-input-rename": true, 135 | "no-inputs-metadata-property": true, 136 | "no-output-native": true, 137 | "no-output-on-prefix": true, 138 | "no-output-rename": true, 139 | "no-outputs-metadata-property": true, 140 | "template-banana-in-box": true, 141 | "template-no-negated-async": true, 142 | "use-lifecycle-interface": true, 143 | "use-pipe-transform-interface": true 144 | }, 145 | "rulesDirectory": [ 146 | "codelyzer" 147 | ] 148 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpackMerge = require('webpack-merge'); 2 | 3 | module.exports = (config) => { 4 | const merge = webpackMerge && webpackMerge.merge ? webpackMerge.merge : webpackMerge; 5 | const isProd = config.mode === "production"; 6 | const tailwindConfig = require("./tailwind.config.js")(isProd); 7 | 8 | return merge(config, { 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.scss$/, 13 | loader: 'postcss-loader', 14 | options: { 15 | postcssOptions: { 16 | ident: 'postcss', 17 | syntax: 'postcss-scss', 18 | plugins: [ 19 | require('postcss-import'), 20 | require('tailwindcss')(tailwindConfig), 21 | require('autoprefixer'), 22 | ] 23 | } 24 | } 25 | } 26 | ] 27 | } 28 | }); 29 | }; 30 | --------------------------------------------------------------------------------