├── .editorconfig ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── tasks.json ├── README.md ├── angular.json ├── package-lock.json ├── package.json ├── src ├── app │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.ts │ ├── app.config.ts │ └── ui-components │ │ ├── banner │ │ ├── banner.component.scss │ │ └── banner.component.ts │ │ ├── button │ │ ├── button.component.scss │ │ └── button.component.ts │ │ └── chip │ │ ├── chip.component.scss │ │ └── chip.component.ts ├── assets │ └── .gitkeep ├── favicon.ico ├── index.html ├── main.ts └── styles.scss ├── tsconfig.app.json ├── tsconfig.json └── tsconfig.spec.json /.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 | -------------------------------------------------------------------------------- /.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 | /bazel-out 8 | 9 | # Node 10 | /node_modules 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | # IDEs and editors 15 | .idea/ 16 | .project 17 | .classpath 18 | .c9/ 19 | *.launch 20 | .settings/ 21 | *.sublime-workspace 22 | 23 | # Visual Studio Code 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | .history/* 30 | 31 | # Miscellaneous 32 | /.angular/cache 33 | .sass-cache/ 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | testem.log 38 | /typings 39 | 40 | # System files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 3 | "recommendations": ["angular.ng-template"] 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "ng serve", 7 | "type": "chrome", 8 | "request": "launch", 9 | "preLaunchTask": "npm: start", 10 | "url": "http://localhost:4200/" 11 | }, 12 | { 13 | "name": "ng test", 14 | "type": "chrome", 15 | "request": "launch", 16 | "preLaunchTask": "npm: test", 17 | "url": "http://localhost:9876/debug.html" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 3 | "version": "2.0.0", 4 | "tasks": [ 5 | { 6 | "type": "npm", 7 | "script": "start", 8 | "isBackground": true, 9 | "problemMatcher": { 10 | "owner": "typescript", 11 | "pattern": "$tsc", 12 | "background": { 13 | "activeOnStart": true, 14 | "beginsPattern": { 15 | "regexp": "(.*?)" 16 | }, 17 | "endsPattern": { 18 | "regexp": "bundle generation complete" 19 | } 20 | } 21 | } 22 | }, 23 | { 24 | "type": "npm", 25 | "script": "test", 26 | "isBackground": true, 27 | "problemMatcher": { 28 | "owner": "typescript", 29 | "pattern": "$tsc", 30 | "background": { 31 | "activeOnStart": true, 32 | "beginsPattern": { 33 | "regexp": "(.*?)" 34 | }, 35 | "endsPattern": { 36 | "regexp": "bundle generation complete" 37 | } 38 | } 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AngularDirectiveCompositionApiDemo 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 16.1.5. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-directive-composition-api-demo": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss", 11 | "standalone": true 12 | }, 13 | "@schematics/angular:directive": { 14 | "standalone": true 15 | }, 16 | "@schematics/angular:pipe": { 17 | "standalone": true 18 | } 19 | }, 20 | "root": "", 21 | "sourceRoot": "src", 22 | "prefix": "app", 23 | "architect": { 24 | "build": { 25 | "builder": "@angular-devkit/build-angular:browser", 26 | "options": { 27 | "outputPath": "dist/angular-directive-composition-api-demo", 28 | "index": "src/index.html", 29 | "main": "src/main.ts", 30 | "polyfills": [ 31 | "zone.js" 32 | ], 33 | "tsConfig": "tsconfig.app.json", 34 | "inlineStyleLanguage": "scss", 35 | "assets": [ 36 | "src/favicon.ico", 37 | "src/assets" 38 | ], 39 | "styles": [ 40 | "src/styles.scss" 41 | ], 42 | "scripts": [] 43 | }, 44 | "configurations": { 45 | "production": { 46 | "budgets": [ 47 | { 48 | "type": "initial", 49 | "maximumWarning": "500kb", 50 | "maximumError": "1mb" 51 | }, 52 | { 53 | "type": "anyComponentStyle", 54 | "maximumWarning": "2kb", 55 | "maximumError": "4kb" 56 | } 57 | ], 58 | "outputHashing": "all" 59 | }, 60 | "development": { 61 | "buildOptimizer": false, 62 | "optimization": false, 63 | "vendorChunk": true, 64 | "extractLicenses": false, 65 | "sourceMap": true, 66 | "namedChunks": true 67 | } 68 | }, 69 | "defaultConfiguration": "production" 70 | }, 71 | "serve": { 72 | "builder": "@angular-devkit/build-angular:dev-server", 73 | "configurations": { 74 | "production": { 75 | "browserTarget": "angular-directive-composition-api-demo:build:production" 76 | }, 77 | "development": { 78 | "browserTarget": "angular-directive-composition-api-demo:build:development" 79 | } 80 | }, 81 | "defaultConfiguration": "development" 82 | }, 83 | "extract-i18n": { 84 | "builder": "@angular-devkit/build-angular:extract-i18n", 85 | "options": { 86 | "browserTarget": "angular-directive-composition-api-demo:build" 87 | } 88 | }, 89 | "test": { 90 | "builder": "@angular-devkit/build-angular:karma", 91 | "options": { 92 | "polyfills": [ 93 | "zone.js", 94 | "zone.js/testing" 95 | ], 96 | "tsConfig": "tsconfig.spec.json", 97 | "inlineStyleLanguage": "scss", 98 | "assets": [ 99 | "src/favicon.ico", 100 | "src/assets" 101 | ], 102 | "styles": [ 103 | "src/styles.scss" 104 | ], 105 | "scripts": [] 106 | } 107 | } 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-directive-composition-api-demo", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "watch": "ng build --watch --configuration development", 9 | "test": "ng test" 10 | }, 11 | "private": true, 12 | "dependencies": { 13 | "@angular/animations": "^16.1.0", 14 | "@angular/common": "^16.1.0", 15 | "@angular/compiler": "^16.1.0", 16 | "@angular/core": "^16.1.0", 17 | "@angular/forms": "^16.1.0", 18 | "@angular/platform-browser": "^16.1.0", 19 | "@angular/platform-browser-dynamic": "^16.1.0", 20 | "@angular/router": "^16.1.0", 21 | "rxjs": "~7.8.0", 22 | "tslib": "^2.3.0", 23 | "zone.js": "~0.13.0" 24 | }, 25 | "devDependencies": { 26 | "@angular-devkit/build-angular": "^16.1.5", 27 | "@angular/cli": "~16.1.5", 28 | "@angular/compiler-cli": "^16.1.0", 29 | "@types/jasmine": "~4.3.0", 30 | "jasmine-core": "~4.6.0", 31 | "karma": "~6.4.0", 32 | "karma-chrome-launcher": "~3.2.0", 33 | "karma-coverage": "~2.2.0", 34 | "karma-jasmine": "~5.1.0", 35 | "karma-jasmine-html-reporter": "~2.1.0", 36 | "typescript": "~5.1.3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Button

3 | 4 | 5 | 6 |

Chip

7 | Solid Chip 8 | Stroked Chip 9 | 10 |

Banner

11 | 12 |

13 | This is a demo text for a banner which has SOLID appearance 14 |

15 |
16 | 17 |

18 | This is a demo text for a banner which has STROKED appearance 19 |

20 |
21 |
22 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | app-banner { 2 | margin-right: 15px; 3 | } 4 | app-chip { 5 | margin-right: 15px; 6 | } 7 | app-banner { 8 | margin-bottom: 15px; 9 | } 10 | button { 11 | margin-right: 15px; 12 | } 13 | h3 { 14 | margin-bottom: 5px; 15 | } 16 | :host { 17 | display: flex; 18 | height: 100vh; 19 | align-items: center; 20 | justify-items: center; 21 | padding: 20px; 22 | box-sizing: border-box; 23 | } 24 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { ButtonComponent } from './ui-components/button/button.component'; 3 | import { BannerComponent } from './ui-components/banner/banner.component'; 4 | import { ChipComponent } from './ui-components/chip/chip.component'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | standalone: true, 9 | imports: [ButtonComponent, BannerComponent, ChipComponent], 10 | templateUrl: './app.component.html', 11 | styleUrls: ['./app.component.scss'], 12 | }) 13 | export class AppComponent {} 14 | -------------------------------------------------------------------------------- /src/app/app.config.ts: -------------------------------------------------------------------------------- 1 | import { ApplicationConfig } from '@angular/core'; 2 | 3 | export const appConfig: ApplicationConfig = { 4 | providers: [] 5 | }; 6 | -------------------------------------------------------------------------------- /src/app/ui-components/banner/banner.component.scss: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | padding: 10px 20px; 4 | box-sizing: border-box; 5 | border-radius: 20px; 6 | background-color: var(--bg-color); 7 | color: var(--text-color); 8 | border: solid 2px; 9 | box-shadow: #00000029 0px 2px 4px 3px; 10 | 11 | h5 { 12 | margin-bottom: 5px; 13 | margin-top: 0; 14 | font-size: 20px; 15 | } 16 | 17 | &.df-solid { 18 | background-color: var(--bg-color); 19 | border-color: var(--bg-color); 20 | color: var(--text-color); 21 | } 22 | &.df-stroked { 23 | background-color: transparent; 24 | border-color: var(--bg-color); 25 | color: var(--bg-color); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/app/ui-components/banner/banner.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ChangeDetectionStrategy, 3 | Component, 4 | HostBinding, 5 | Input, 6 | } from '@angular/core'; 7 | 8 | @Component({ 9 | selector: 'app-banner', 10 | standalone: true, 11 | template: ` 12 |
Notification:
13 | 16 | `, 17 | styleUrls: ['./banner.component.scss'], 18 | changeDetection: ChangeDetectionStrategy.OnPush, 19 | }) 20 | export class BannerComponent { 21 | @Input() 22 | appearance: 'solid' | 'stroked' = 'solid'; 23 | 24 | @Input() 25 | color: 'primary' | 'secondary' = 'primary'; 26 | 27 | @HostBinding('class') 28 | protected get computedHostClasses() { 29 | return { 30 | [`df-${[this.appearance]}`]: true, 31 | [`df-${[this.color]}`]: true, 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/app/ui-components/button/button.component.scss: -------------------------------------------------------------------------------- 1 | :host { 2 | display: inline-flex; 3 | padding: 7px 13px; 4 | align-items: center; 5 | box-sizing: border-box; 6 | border: solid 2px; 7 | border-radius: 5px; 8 | font-size: 16px; 9 | transition: border-radius 0.2s ease-in-out; 10 | text-decoration: none; 11 | &:hover { 12 | opacity: 0.9; 13 | cursor: pointer; 14 | } 15 | &.df-solid { 16 | background-color: var(--bg-color); 17 | border-color: var(--bg-color); 18 | color: var(--text-color); 19 | } 20 | &.df-stroked { 21 | background-color: transparent; 22 | border-color: var(--bg-color); 23 | color: var(--bg-color); 24 | } 25 | &:disabled, 26 | &.disabled { 27 | opacity: 0.6; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/app/ui-components/button/button.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ChangeDetectionStrategy, 3 | Component, 4 | HostBinding, 5 | HostListener, 6 | Input, 7 | } from '@angular/core'; 8 | 9 | @Component({ 10 | selector: 'button[dfButton], a[dfButton]', 11 | standalone: true, 12 | template: ` 13 | 14 | 15 | 16 | `, 17 | styleUrls: ['./button.component.scss'], 18 | changeDetection: ChangeDetectionStrategy.OnPush, 19 | }) 20 | export class ButtonComponent { 21 | @Input() 22 | appearance: 'solid' | 'stroked' = 'solid'; 23 | 24 | @Input() 25 | color: 'primary' | 'secondary' = 'primary'; 26 | 27 | @HostBinding('class') 28 | protected get computedHostClasses() { 29 | return { 30 | [`df-${[this.appearance]}`]: true, 31 | [`df-${[this.color]}`]: true, 32 | }; 33 | } 34 | 35 | @Input() 36 | @HostBinding('class.disabled') 37 | disabled = false; 38 | 39 | @HostBinding('attr.disabled') 40 | protected get nativeDisabled(): '' | null { 41 | return this.disabled ? '' : null; 42 | } 43 | 44 | @HostListener('click', ['$event']) 45 | @HostListener('dblclick', ['$event']) 46 | onClick(e: Event) { 47 | if (this.disabled) { 48 | e.preventDefault(); 49 | e.stopImmediatePropagation(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/app/ui-components/chip/chip.component.scss: -------------------------------------------------------------------------------- 1 | @mixin _draw-line() { 2 | content: ""; 3 | position: absolute; 4 | width: 15px; 5 | height: 2px; 6 | background-color: currentColor; 7 | top: 6.5px; 8 | } 9 | 10 | :host { 11 | display: inline-flex; 12 | align-items: center; 13 | padding: 5px 13px; 14 | border-radius: 20px; 15 | border: solid 2px; 16 | 17 | &.df-solid { 18 | background-color: var(--bg-color); 19 | border-color: var(--bg-color); 20 | color: var(--text-color); 21 | } 22 | &.df-stroked { 23 | background-color: transparent; 24 | border-color: var(--bg-color); 25 | color: var(--bg-color); 26 | } 27 | } 28 | .chip-remove-icon { 29 | display: inline-block; 30 | color: currentColor; 31 | position: relative; 32 | margin: 0 0 0 5px; 33 | opacity: 0.5; 34 | width: 15px; 35 | height: 15px; 36 | cursor: pointer; 37 | &:hover { 38 | opacity: 1; 39 | } 40 | &:before { 41 | @include _draw-line(); 42 | transform: rotate(45deg); 43 | } 44 | &:after { 45 | @include _draw-line(); 46 | transform: rotate(-45deg); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/ui-components/chip/chip.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ChangeDetectionStrategy, 3 | Component, 4 | EventEmitter, 5 | HostBinding, 6 | HostListener, 7 | Input, 8 | Output, 9 | } from '@angular/core'; 10 | import { CommonModule, NgIf } from '@angular/common'; 11 | 12 | @Component({ 13 | selector: 'app-chip', 14 | standalone: true, 15 | imports: [NgIf], 16 | template: ` 17 | 18 | 19 | 20 | 21 | `, 22 | styleUrls: ['./chip.component.scss'], 23 | changeDetection: ChangeDetectionStrategy.OnPush, 24 | }) 25 | export class ChipComponent { 26 | @Input() 27 | appearance: 'solid' | 'stroked' = 'solid'; 28 | 29 | @Input() 30 | color: 'primary' | 'secondary' = 'primary'; 31 | 32 | @HostBinding('class') 33 | protected get computedHostClasses() { 34 | return { 35 | [`df-${[this.appearance]}`]: true, 36 | [`df-${[this.color]}`]: true, 37 | }; 38 | } 39 | 40 | @Input() 41 | @HostBinding('class.disabled') 42 | disabled = false; 43 | 44 | @HostBinding('attr.disabled') 45 | protected get nativeDisabled(): '' | null { 46 | return this.disabled ? '' : null; 47 | } 48 | 49 | @HostListener('click', ['$event']) 50 | @HostListener('dblclick', ['$event']) 51 | onClick(e: Event) { 52 | if (this.disabled) { 53 | e.preventDefault(); 54 | e.stopImmediatePropagation(); 55 | } 56 | } 57 | 58 | @Input() 59 | removable = false; 60 | 61 | @Output() 62 | removed = new EventEmitter(); 63 | 64 | onRemove() { 65 | if (this.removable) { 66 | this.removed.emit(this); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DMezhenskyi/angular-directive-composition-api-demo/0722adc47896ad41a11fa0db1d5d9c850fed246b/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DMezhenskyi/angular-directive-composition-api-demo/0722adc47896ad41a11fa0db1d5d9c850fed246b/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularDirectiveCompositionApiDemo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { bootstrapApplication } from '@angular/platform-browser'; 2 | import { appConfig } from './app/app.config'; 3 | import { AppComponent } from './app/app.component'; 4 | 5 | bootstrapApplication(AppComponent, appConfig) 6 | .catch((err) => console.error(err)); 7 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | body { 3 | font-family: 'Poppins', sans-serif; 4 | } 5 | 6 | p { 7 | margin: 0; 8 | } 9 | 10 | .df-primary { 11 | --bg-color: #4378db; 12 | --text-color: #faf0e6; 13 | } 14 | .df-secondary { 15 | --bg-color: rgb(249, 186, 11); 16 | --text-color: #333; 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitOverride": true, 10 | "noPropertyAccessFromIndexSignature": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "sourceMap": true, 14 | "declaration": false, 15 | "downlevelIteration": true, 16 | "experimentalDecorators": true, 17 | "moduleResolution": "node", 18 | "importHelpers": true, 19 | "target": "ES2022", 20 | "module": "ES2022", 21 | "useDefineForClassFields": false, 22 | "lib": [ 23 | "ES2022", 24 | "dom" 25 | ] 26 | }, 27 | "angularCompilerOptions": { 28 | "enableI18nLegacyMessageIdFormat": false, 29 | "strictInjectionParameters": true, 30 | "strictInputAccessModifiers": true, 31 | "strictTemplates": true 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "include": [ 11 | "src/**/*.spec.ts", 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | --------------------------------------------------------------------------------