c3-components 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/CONTRIBUTING.md +80 -0
  2. package/bun.lockb +0 -0
  3. package/ng-package.json +19 -0
  4. package/package.json +5 -15
  5. package/{_index.scss → src/_index.scss} +1 -3
  6. package/src/lib/c3-auto-animate/C3AutoAnimate.directive.ts +18 -0
  7. package/src/lib/c3-dialog/c3-dialog.module.ts +30 -0
  8. package/src/lib/c3-dialog/components/c3-dialog-confirm.component.ts +44 -0
  9. package/src/lib/c3-dialog/components/c3-dialog-embed-child.component.ts +40 -0
  10. package/src/lib/c3-dialog/components/c3-dialog-prompt.component.ts +81 -0
  11. package/src/lib/c3-dialog/services/c3-dialog.service.ts +87 -0
  12. package/src/lib/c3-dropdown/c3-dropdown.module.ts +12 -0
  13. package/src/lib/c3-dropdown/components/c3-dropdown.component.spec.ts +22 -0
  14. package/src/lib/c3-dropdown/components/c3-dropdown.component.ts +39 -0
  15. package/src/lib/c3-dropdown/directives/c3-dropdown.trigger.ts +161 -0
  16. package/src/lib/c3-expansion/c3-expansion.module.ts +24 -0
  17. package/src/lib/c3-expansion/components/c3-expansion/c3-expansion.component.html +9 -0
  18. package/src/lib/c3-expansion/components/c3-expansion/c3-expansion.component.ts +33 -0
  19. package/src/lib/c3-expansion/components/c3-expansion-header/c3-expansion-header.component.html +12 -0
  20. package/src/lib/c3-expansion/components/c3-expansion-header/c3-expansion-header.component.ts +21 -0
  21. package/src/lib/c3-expansion/styles/_c3-expansion.scss +39 -0
  22. package/src/lib/c3-file/c3-download/c3-download.module.ts +7 -0
  23. package/src/lib/c3-file/c3-download/c3-download.service.ts +16 -0
  24. package/src/lib/c3-file/c3-input-file/c3-input-file.module.ts +30 -0
  25. package/src/lib/c3-file/c3-input-file/class/c3-input-file.ts +62 -0
  26. package/src/lib/c3-file/c3-input-file/components/c3-input-file/c3-input-file.component.html +7 -0
  27. package/src/lib/c3-file/c3-input-file/components/c3-input-file/c3-input-file.component.ts +96 -0
  28. package/src/lib/c3-file/c3-input-file/components/c3-input-file-container/c3-input-file-container.component.ts +53 -0
  29. package/src/lib/c3-file/c3-input-file/components/c3-input-file-displayer/c3-input-file-displayer.component.ts +107 -0
  30. package/src/lib/c3-file/c3-input-file/components/c3-input-file-trigger/c3-input-file-trigger.component.ts +22 -0
  31. package/src/lib/c3-file/c3-input-file/directives/c3-input-file-trigger.directive.ts +27 -0
  32. package/src/lib/c3-file-upload/c3-file-upload.module.ts +8 -0
  33. package/src/lib/c3-file-viewer/c3-file-viewer.module.ts +30 -0
  34. package/src/lib/c3-file-viewer/components/c3-file-viewer-actions/c3-file-viewer-actions.component.html +185 -0
  35. package/src/lib/c3-file-viewer/components/c3-file-viewer-actions/c3-file-viewer-actions.component.spec.ts +23 -0
  36. package/src/lib/c3-file-viewer/components/c3-file-viewer-actions/c3-file-viewer-actions.component.ts +15 -0
  37. package/src/lib/c3-file-viewer/components/c3-file-viewer-image/c3-file-viewer-image.component.html +7 -0
  38. package/src/lib/c3-file-viewer/components/c3-file-viewer-image/c3-file-viewer-image.component.spec.ts +23 -0
  39. package/src/lib/c3-file-viewer/components/c3-file-viewer-image/c3-file-viewer-image.component.ts +14 -0
  40. package/src/lib/c3-file-viewer/components/c3-file-viewer-pdf/c3-file-viewer-pdf.component.html +7 -0
  41. package/src/lib/c3-file-viewer/components/c3-file-viewer-pdf/c3-file-viewer-pdf.component.spec.ts +23 -0
  42. package/src/lib/c3-file-viewer/components/c3-file-viewer-pdf/c3-file-viewer-pdf.component.ts +25 -0
  43. package/src/lib/c3-file-viewer/components/c3-file-viewer-video/c3-file-viewer-video.component.css +0 -0
  44. package/src/lib/c3-file-viewer/components/c3-file-viewer-video/c3-file-viewer-video.component.html +1 -0
  45. package/src/lib/c3-file-viewer/components/c3-file-viewer-video/c3-file-viewer-video.component.spec.ts +23 -0
  46. package/src/lib/c3-file-viewer/components/c3-file-viewer-video/c3-file-viewer-video.component.ts +35 -0
  47. package/src/lib/c3-file-viewer/components/public/c3-file-viewer/c3-file-viewer.component.html +32 -0
  48. package/src/lib/c3-file-viewer/components/public/c3-file-viewer/c3-file-viewer.component.spec.ts +23 -0
  49. package/src/lib/c3-file-viewer/components/public/c3-file-viewer/c3-file-viewer.component.ts +93 -0
  50. package/src/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.component.spec.ts +23 -0
  51. package/src/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.component.ts +37 -0
  52. package/src/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.spec.ts +22 -0
  53. package/src/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.ts +12 -0
  54. package/src/lib/c3-file-viewer/consts/default.config.ts +41 -0
  55. package/src/lib/c3-file-viewer/directives/full-screen.directive.spec.ts +11 -0
  56. package/src/lib/c3-file-viewer/directives/full-screen.directive.ts +68 -0
  57. package/src/lib/c3-file-viewer/models/custom-file-event.model.ts +9 -0
  58. package/src/lib/c3-file-viewer/models/file-metadata.ts +13 -0
  59. package/src/lib/c3-file-viewer/models/file-viewer-config.model.ts +53 -0
  60. package/src/lib/c3-file-viewer/models/file-viewer.ts +259 -0
  61. package/src/lib/c3-file-viewer/models/http.client.ts +23 -0
  62. package/{lib → src/lib}/c3-file-viewer/styles/_c3-file-viewer.sass +2 -20
  63. package/src/lib/c3-highlight-text/c3-highlight-text.module.ts +12 -0
  64. package/src/lib/c3-menu/c3-menu.module.ts +12 -0
  65. package/src/lib/c3-modal/c3-modal.module.ts +12 -0
  66. package/src/lib/c3-navbar/c3-navbar.module.ts +12 -0
  67. package/src/lib/c3-pdf-dialog/c3-pdf-dialog.module.ts +12 -0
  68. package/src/lib/c3-rounded-title/c3-rounded-title.module.ts +12 -0
  69. package/src/lib/c3-safe-url/pipes/c3-safe-url.pipe.spec.ts +8 -0
  70. package/src/lib/c3-safe-url/pipes/c3-safe-url.pipe.ts +13 -0
  71. package/{lib → src/lib}/c3-styles/_c3-core.sass +4 -2
  72. package/src/lib/c3-tabs/c3-tabs.module.ts +12 -0
  73. package/{public-api.d.ts → src/public-api.ts} +20 -0
  74. package/tsconfig.lib.json +14 -0
  75. package/tsconfig.lib.prod.json +10 -0
  76. package/tsconfig.spec.json +14 -0
  77. package/esm2022/c3-components.mjs +0 -5
  78. package/esm2022/lib/c3-dialog/c3-dialog.module.mjs +0 -52
  79. package/esm2022/lib/c3-dialog/components/c3-dialog-confirm.component.mjs +0 -51
  80. package/esm2022/lib/c3-dialog/components/c3-dialog-embed-child.component.mjs +0 -32
  81. package/esm2022/lib/c3-dialog/components/c3-dialog-prompt.component.mjs +0 -95
  82. package/esm2022/lib/c3-dialog/services/c3-dialog.service.mjs +0 -79
  83. package/esm2022/lib/c3-dropdown/c3-dropdown.module.mjs +0 -20
  84. package/esm2022/lib/c3-dropdown/components/c3-dropdown.component.mjs +0 -45
  85. package/esm2022/lib/c3-dropdown/directives/c3-dropdown.trigger.mjs +0 -128
  86. package/esm2022/lib/c3-file-viewer/c3-file-viewer.module.mjs +0 -47
  87. package/esm2022/lib/c3-file-viewer/components/c3-file-viewer-actions/c3-file-viewer-actions.component.mjs +0 -17
  88. package/esm2022/lib/c3-file-viewer/components/c3-file-viewer-image/c3-file-viewer-image.component.mjs +0 -20
  89. package/esm2022/lib/c3-file-viewer/components/c3-file-viewer-pdf/c3-file-viewer-pdf.component.mjs +0 -23
  90. package/esm2022/lib/c3-file-viewer/components/c3-file-viewer-video/c3-file-viewer-video.component.mjs +0 -32
  91. package/esm2022/lib/c3-file-viewer/components/public/c3-file-viewer/c3-file-viewer.component.mjs +0 -86
  92. package/esm2022/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.component.mjs +0 -40
  93. package/esm2022/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.mjs +0 -26
  94. package/esm2022/lib/c3-file-viewer/consts/default.config.mjs +0 -40
  95. package/esm2022/lib/c3-file-viewer/directives/full-screen.directive.mjs +0 -66
  96. package/esm2022/lib/c3-file-viewer/models/custom-file-event.model.mjs +0 -7
  97. package/esm2022/lib/c3-file-viewer/models/file-metadata.mjs +0 -2
  98. package/esm2022/lib/c3-file-viewer/models/file-viewer-config.model.mjs +0 -2
  99. package/esm2022/lib/c3-file-viewer/models/file-viewer.mjs +0 -206
  100. package/esm2022/lib/c3-file-viewer/models/http.client.mjs +0 -2
  101. package/esm2022/lib/c3-safe-url/pipes/c3-safe-url.pipe.mjs +0 -21
  102. package/esm2022/public-api.mjs +0 -35
  103. package/fesm2022/c3-components.mjs +0 -1056
  104. package/fesm2022/c3-components.mjs.map +0 -1
  105. package/index.d.ts +0 -5
  106. package/lib/c3-dialog/c3-dialog.module.d.ts +0 -15
  107. package/lib/c3-dialog/components/c3-dialog-confirm.component.d.ts +0 -23
  108. package/lib/c3-dialog/components/c3-dialog-embed-child.component.d.ts +0 -18
  109. package/lib/c3-dialog/components/c3-dialog-prompt.component.d.ts +0 -31
  110. package/lib/c3-dialog/services/c3-dialog.service.d.ts +0 -19
  111. package/lib/c3-dropdown/c3-dropdown.module.d.ts +0 -10
  112. package/lib/c3-dropdown/components/c3-dropdown.component.d.ts +0 -15
  113. package/lib/c3-dropdown/directives/c3-dropdown.trigger.d.ts +0 -45
  114. package/lib/c3-file-viewer/c3-file-viewer.module.d.ts +0 -17
  115. package/lib/c3-file-viewer/components/c3-file-viewer-actions/c3-file-viewer-actions.component.d.ts +0 -8
  116. package/lib/c3-file-viewer/components/c3-file-viewer-image/c3-file-viewer-image.component.d.ts +0 -9
  117. package/lib/c3-file-viewer/components/c3-file-viewer-pdf/c3-file-viewer-pdf.component.d.ts +0 -9
  118. package/lib/c3-file-viewer/components/c3-file-viewer-video/c3-file-viewer-video.component.d.ts +0 -12
  119. package/lib/c3-file-viewer/components/public/c3-file-viewer/c3-file-viewer.component.d.ts +0 -25
  120. package/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.component.d.ts +0 -12
  121. package/lib/c3-file-viewer/components/public/c3-file-viewer-dialog/c3-file-viewer-dialog.d.ts +0 -8
  122. package/lib/c3-file-viewer/consts/default.config.d.ts +0 -2
  123. package/lib/c3-file-viewer/directives/full-screen.directive.d.ts +0 -12
  124. package/lib/c3-file-viewer/models/custom-file-event.model.d.ts +0 -5
  125. package/lib/c3-file-viewer/models/file-metadata.d.ts +0 -12
  126. package/lib/c3-file-viewer/models/file-viewer-config.model.d.ts +0 -48
  127. package/lib/c3-file-viewer/models/file-viewer.d.ts +0 -65
  128. package/lib/c3-file-viewer/models/http.client.d.ts +0 -14
  129. package/lib/c3-safe-url/pipes/c3-safe-url.pipe.d.ts +0 -10
  130. /package/{lib → src/lib}/c3-dropdown/styles/_c3-dropdown.sass +0 -0
  131. /package/{lib → src/lib}/c3-styles/_c3-root-variables.sass +0 -0
  132. /package/{lib → src/lib}/c3-styles/_utils.sass +0 -0
@@ -0,0 +1,80 @@
1
+ # Contributing to c3-components
2
+
3
+ First of all, thank you for your interest in contributing to the c3-components project! We appreciate your effort and look forward to collaborating with you. This document provides guidelines and best practices for contributing to the project.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Code of Conduct](#code-of-conduct)
8
+ - [Getting Started](#getting-started)
9
+ - [Reporting Issues](#reporting-issues)
10
+ - [Submitting Pull Requests](#submitting-pull-requests)
11
+ - [Coding Style](#coding-style)
12
+ - [Testing](#testing)
13
+ - [Documentation](#documentation)
14
+ - [Additional Resources](#additional-resources)
15
+
16
+ ## Code of Conduct
17
+
18
+ By participating in this project, you are expected to uphold our [Code of Conduct](./CODE_OF_CONDUCT.md). Please take a moment to read it before contributing.
19
+
20
+ ## Getting Started
21
+
22
+ 1. Fork the repository on GitHub.
23
+ 2. Clone your fork of the repository to your local machine.
24
+ 3. Install the required dependencies with `npm install`.
25
+ 4. Create a new branch for your changes using `git checkout -b your-feature-branch`.
26
+ 5. Implement your changes, following the [coding style](#coding-style) and [testing](#testing) guidelines.
27
+ 6. Commit your changes and push them to your fork on GitHub.
28
+ 7. Create a pull request with a clear description of your changes.
29
+
30
+ ## Reporting Issues
31
+
32
+ If you encounter any issues or bugs, please report them on the [issue tracker](https://github.com/Kroenen62/c3-components/issues). When submitting an issue, make sure to:
33
+
34
+ - Use a clear and descriptive title.
35
+ - Provide a detailed description of the issue and steps to reproduce it.
36
+ - Include any relevant code snippets or screenshots.
37
+
38
+ ## Submitting Pull Requests
39
+
40
+ When submitting a pull request, please follow these guidelines:
41
+
42
+ - Use a clear and descriptive title.
43
+ - Provide a detailed description of your changes.
44
+ - Reference any related issues in the pull request description.
45
+ - Make sure your changes follow the [coding style](#coding-style) and [testing](#testing) guidelines.
46
+ - Update the documentation if necessary.
47
+
48
+ ## Coding Style
49
+
50
+ To ensure consistency and readability, please adhere to the following coding style guidelines:
51
+
52
+ - Use 2 spaces for indentation.
53
+ - Follow the [Angular style guide](https://angular.io/guide/styleguide).
54
+ - Use camelCase for variable and function names.
55
+ - Use PascalCase for class names.
56
+ - Add comments to explain complex or non-obvious code.
57
+ - Break down long functions or classes into smaller, more manageable pieces.
58
+
59
+ ## Testing
60
+
61
+ Before submitting a pull request, make sure to test your changes thoroughly. Follow these testing guidelines:
62
+
63
+ - Write unit tests for new features and bug fixes.
64
+ - Ensure all tests pass by running `ng test`.
65
+ - Test your changes in multiple browsers and screen sizes.
66
+
67
+ ## Documentation
68
+
69
+ Keep the documentation up-to-date by following these guidelines:
70
+
71
+ - Update the README.md file if you add or change any functionality.
72
+ - Document any new components or features in the [documentation website](https://c3-components.example.com/).
73
+ - Use clear and concise language, and provide examples when possible.
74
+
75
+ ## Additional Resources
76
+
77
+ - [Angular Documentation](https://angular.io/docs)
78
+ - [@angular/material Documentation](https://material.angular.io/)
79
+
80
+ Once again, thank you for your interest in contributing to the c3-components project. Your time and expertise are greatly appreciated!
package/bun.lockb ADDED
Binary file
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/c3-components",
4
+ "assets": [
5
+ {
6
+ "glob": "**/**.scss",
7
+ "input": "./src",
8
+ "output": "."
9
+ },
10
+ {
11
+ "glob": "**/**.sass",
12
+ "input": "./src",
13
+ "output": "."
14
+ }
15
+ ],
16
+ "lib": {
17
+ "entryFile": "src/public-api.ts"
18
+ }
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c3-components",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "C3 Components Library",
5
5
  "author": "Kroenen62",
6
6
  "license": "MIT",
@@ -11,8 +11,7 @@
11
11
  "@angular/cdk": ">=16.0.0",
12
12
  "@angular/material": ">=16.0.0",
13
13
  "autoprefixer": "^10.4.16",
14
- "postcss": "^8.4.31",
15
- "tailwindcss": ">=3.3.3"
14
+ "@formkit/auto-animate": "^0.8.2"
16
15
  },
17
16
  "dependencies": {
18
17
  "tslib": "^2.3.0"
@@ -20,16 +19,7 @@
20
19
  "sideEffects": false,
21
20
  "exports": {
22
21
  ".": {
23
- "sass": "./_index.scss",
24
- "types": "./index.d.ts",
25
- "esm2022": "./esm2022/c3-components.mjs",
26
- "esm": "./esm2022/c3-components.mjs",
27
- "default": "./fesm2022/c3-components.mjs"
28
- },
29
- "./package.json": {
30
- "default": "./package.json"
22
+ "sass": "./_index.scss"
31
23
  }
32
- },
33
- "module": "fesm2022/c3-components.mjs",
34
- "typings": "index.d.ts"
35
- }
24
+ }
25
+ }
@@ -1,5 +1,3 @@
1
1
  @forward "./lib/c3-dropdown/styles/c3-dropdown" show c3-material-dropdown;
2
+ @forward "./lib/c3-expansion/styles/c3-expansion" show c3-expansion;
2
3
  @forward "./lib/c3-styles/c3-core" show c3-core;
3
- @tailwind base;
4
- @tailwind components;
5
- @tailwind utilities;
@@ -0,0 +1,18 @@
1
+ import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';
2
+ import autoAnimate, {
3
+ AutoAnimateOptions,
4
+ AutoAnimationPlugin,
5
+ } from '@formkit/auto-animate';
6
+
7
+ @Directive({
8
+ selector: '[c3AutoAnimate]',
9
+ standalone: true,
10
+ })
11
+ export class C3AutoAnimateDirective implements AfterViewInit {
12
+ @Input() options?: Partial<AutoAnimateOptions> | AutoAnimationPlugin;
13
+ constructor(private el: ElementRef) {}
14
+
15
+ ngAfterViewInit(): void {
16
+ autoAnimate(this.el.nativeElement, this.options);
17
+ }
18
+ }
@@ -0,0 +1,30 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { MatButtonModule } from '@angular/material/button';
4
+ import { MatDialogModule } from '@angular/material/dialog';
5
+ import { MatFormFieldModule } from '@angular/material/form-field';
6
+ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
7
+ import { MatInputModule } from '@angular/material/input';
8
+ import { ConfirmDialogComponent } from './components/c3-dialog-confirm.component';
9
+ import { C3DialogEmbedChildComponent } from './components/c3-dialog-embed-child.component';
10
+ import { C3PromptDialogComponent } from './components/c3-dialog-prompt.component';
11
+ import { C3DialogService } from './services/c3-dialog.service';
12
+
13
+ @NgModule({
14
+ declarations: [
15
+ ConfirmDialogComponent,
16
+ C3PromptDialogComponent,
17
+ C3DialogEmbedChildComponent,
18
+ ],
19
+ imports: [
20
+ CommonModule,
21
+ MatDialogModule,
22
+ MatButtonModule,
23
+ MatFormFieldModule,
24
+ MatInputModule,
25
+ FormsModule,
26
+ ReactiveFormsModule,
27
+ ],
28
+ providers: [C3DialogService],
29
+ })
30
+ export class C3DialogModule {}
@@ -0,0 +1,44 @@
1
+ import { Component, Inject } from '@angular/core';
2
+ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
3
+
4
+ export interface ConfirmConfig {
5
+ text: string;
6
+ placeholder?: string;
7
+ reject?: {
8
+ color?: string;
9
+ text?: string;
10
+ };
11
+ accept?: {
12
+ color?: string;
13
+ text: string;
14
+ };
15
+ width?: string;
16
+ }
17
+
18
+ @Component({
19
+ selector: 'ConfirmDialogComponent',
20
+ template: `
21
+ <mat-dialog-content>
22
+ <div [innerHtml]="data.text"></div>
23
+ </mat-dialog-content>
24
+ <mat-dialog-actions class="flex flex-row justify-end items-center">
25
+ <button mat-button mat-dialog-close [color]="data.reject?.color">
26
+ {{ data.reject?.text }}
27
+ </button>
28
+ <button mat-button [color]="data.accept?.color" [mat-dialog-close]="true">
29
+ {{ data.accept?.text }}
30
+ </button>
31
+ </mat-dialog-actions>
32
+ `,
33
+ })
34
+ export class ConfirmDialogComponent {
35
+ constructor(
36
+ public dialogRef: MatDialogRef<ConfirmDialogComponent>,
37
+ @Inject(MAT_DIALOG_DATA)
38
+ public data: ConfirmConfig
39
+ ) {}
40
+
41
+ onNoClick(): void {
42
+ this.dialogRef.close();
43
+ }
44
+ }
@@ -0,0 +1,40 @@
1
+ import {
2
+ AfterViewInit,
3
+ ChangeDetectorRef,
4
+ Component,
5
+ ComponentRef,
6
+ Inject,
7
+ Type,
8
+ ViewChild,
9
+ ViewContainerRef,
10
+ } from '@angular/core';
11
+ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
12
+
13
+ @Component({
14
+ selector: 'C3DialogEmbedChildComponent',
15
+ template: `<mat-dialog-content>
16
+ <ng-template #target></ng-template>
17
+ </mat-dialog-content>`,
18
+ styles: [],
19
+ })
20
+ export class C3DialogEmbedChildComponent<ComponenyType>
21
+ implements AfterViewInit
22
+ {
23
+ @ViewChild('target', { read: ViewContainerRef }) target!: ViewContainerRef;
24
+
25
+ createdComponent?: ComponentRef<ComponenyType>;
26
+
27
+ constructor(
28
+ public dialogRef: MatDialogRef<C3DialogEmbedChildComponent<ComponenyType>>,
29
+ @Inject(MAT_DIALOG_DATA)
30
+ public data: {
31
+ component: Type<ComponenyType>;
32
+ },
33
+ private _cdr: ChangeDetectorRef
34
+ ) {}
35
+
36
+ ngAfterViewInit() {
37
+ this.createdComponent = this.target.createComponent(this.data.component);
38
+ this._cdr.detectChanges();
39
+ }
40
+ }
@@ -0,0 +1,81 @@
1
+ import { Component, Inject } from '@angular/core';
2
+ import { FormBuilder, FormControl, ValidatorFn } from '@angular/forms';
3
+ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
4
+
5
+ export interface PromptConfig {
6
+ text: string;
7
+ defaultValue?: string;
8
+ placeholder?: string;
9
+ multiline?: boolean;
10
+ validators?: ValidatorFn | ValidatorFn[];
11
+ required?: boolean;
12
+ reject?: {
13
+ color: string;
14
+ text: string;
15
+ };
16
+ accept?: {
17
+ color: string;
18
+ text: string;
19
+ };
20
+ width?: string;
21
+ maxWidth?: string;
22
+ }
23
+
24
+ @Component({
25
+ selector: 'PrompDialogComponent',
26
+ template: `
27
+ <div mat-dialog-title>{{ data.text }}</div>
28
+ <mat-dialog-content>
29
+ <mat-form-field>
30
+ <mat-label *ngIf="data.placeholder">{{ data.placeholder }}</mat-label>
31
+ <input
32
+ *ngIf="!data.multiline"
33
+ matInput
34
+ [formControl]="result"
35
+ (keydown.enter)="dialogRef.close(result.value)"
36
+ />
37
+ <textarea
38
+ *ngIf="data.multiline"
39
+ matInput
40
+ [formControl]="result"
41
+ cdkTextareaAutosize
42
+ ></textarea>
43
+ </mat-form-field>
44
+ </mat-dialog-content>
45
+ <mat-dialog-actions align="center">
46
+ <button mat-raised-button mat-dialog-close [class]="data.reject?.color">
47
+ {{ data.reject?.text }}
48
+ </button>
49
+ <button
50
+ mat-raised-button
51
+ [disabled]="result.invalid || (data.required && !result.value)"
52
+ [class]="data.accept?.color"
53
+ [mat-dialog-close]="result.value"
54
+ >
55
+ {{ data.accept?.text }}
56
+ </button>
57
+ </mat-dialog-actions>
58
+ `,
59
+ styles: [
60
+ `
61
+ mat-form-field {
62
+ width: 100%;
63
+ }
64
+ `,
65
+ ],
66
+ })
67
+ export class C3PromptDialogComponent {
68
+ result: FormControl;
69
+ constructor(
70
+ public dialogRef: MatDialogRef<C3PromptDialogComponent>,
71
+ @Inject(MAT_DIALOG_DATA)
72
+ public data: PromptConfig,
73
+ private _fb: FormBuilder
74
+ ) {
75
+ this.result = this._fb.control(data.defaultValue, data.validators);
76
+ }
77
+
78
+ onNoClick(): void {
79
+ this.dialogRef.close();
80
+ }
81
+ }
@@ -0,0 +1,87 @@
1
+ import { Injectable, Type, inject } from '@angular/core';
2
+ import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
3
+ import {
4
+ ConfirmConfig,
5
+ ConfirmDialogComponent,
6
+ } from '../components/c3-dialog-confirm.component';
7
+ import { C3DialogEmbedChildComponent } from '../components/c3-dialog-embed-child.component';
8
+ import {
9
+ PromptConfig,
10
+ C3PromptDialogComponent,
11
+ } from '../components/c3-dialog-prompt.component';
12
+
13
+ @Injectable({
14
+ providedIn: 'root',
15
+ })
16
+ export class C3DialogService {
17
+ readonly #dialog = inject(MatDialog);
18
+
19
+ public confirm(data: ConfirmConfig): Promise<boolean> {
20
+ return new Promise((resolve, reject) => {
21
+ const dialogRef = this.#dialog.open(ConfirmDialogComponent, {
22
+ width: data.width || '250px',
23
+ data: {
24
+ text: data.text,
25
+ reject: {
26
+ color:
27
+ data.reject && data.reject.color ? data.reject.color : undefined,
28
+ text: (data.reject && data.reject.text) || 'Annuler',
29
+ },
30
+ accept: {
31
+ color: (data.accept && data.accept.color) || 'primary',
32
+ text: (data.accept && data.accept.text) || 'Accepter',
33
+ },
34
+ },
35
+ });
36
+
37
+ dialogRef.afterClosed().subscribe(async (result) => {
38
+ if (result) resolve(true);
39
+ else resolve(false);
40
+ });
41
+ });
42
+ }
43
+
44
+ public prompt<T = any>(data: PromptConfig): Promise<false | T> {
45
+ return new Promise((resolve, reject) => {
46
+ const dialogRef = this.#dialog.open<C3PromptDialogComponent, any, T>(
47
+ C3PromptDialogComponent,
48
+ {
49
+ width: data.width || '250px',
50
+ maxWidth: data.maxWidth || '100vw',
51
+ data: {
52
+ text: data.text,
53
+ defaultValue: data.defaultValue,
54
+ placeholder: data.placeholder,
55
+ multiline: data.multiline,
56
+ validators: data.validators,
57
+ required: data.required,
58
+ reject: {
59
+ color:
60
+ data.reject && data.reject.color
61
+ ? data.reject.color
62
+ : undefined,
63
+ text: (data.reject && data.reject.text) || 'Annuler',
64
+ },
65
+ accept: {
66
+ color: (data.accept && data.accept.color) || 'primary',
67
+ text: (data.accept && data.accept.text) || 'Accepter',
68
+ },
69
+ },
70
+ }
71
+ );
72
+
73
+ dialogRef.afterClosed().subscribe(async (result) => {
74
+ if (result) resolve(result);
75
+ else resolve(false);
76
+ });
77
+ });
78
+ }
79
+
80
+ createDialgFromComponent<T>(
81
+ config: Partial<MatDialogConfig> & {
82
+ data: { component: Type<T> };
83
+ }
84
+ ) {
85
+ return this.#dialog.open(C3DialogEmbedChildComponent, config);
86
+ }
87
+ }
@@ -0,0 +1,12 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { C3DropdownComponent } from './components/c3-dropdown.component';
4
+ import { C3DropdownTrigger } from './directives/c3-dropdown.trigger';
5
+ import { OverlayModule } from '@angular/cdk/overlay';
6
+
7
+ @NgModule({
8
+ imports: [CommonModule, OverlayModule],
9
+ declarations: [C3DropdownComponent, C3DropdownTrigger],
10
+ exports: [C3DropdownComponent, C3DropdownTrigger],
11
+ })
12
+ export class C3DropdownModule {}
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { C3DropdownComponent } from './c3-dropdown.component';
4
+
5
+ describe('C3DropdownComponent', () => {
6
+ let component: C3DropdownComponent;
7
+ let fixture: ComponentFixture<C3DropdownComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [C3DropdownComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(C3DropdownComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,39 @@
1
+ import {
2
+ ChangeDetectorRef,
3
+ Component,
4
+ TemplateRef,
5
+ ViewChild,
6
+ Input,
7
+ OnChanges,
8
+ SimpleChanges,
9
+ } from '@angular/core';
10
+
11
+ @Component({
12
+ selector: 'c3-dropdown',
13
+ template: `
14
+ <ng-template>
15
+ <div class="c3-dropdown-panel" [ngClass]="dropdownClass">
16
+ <ng-content></ng-content>
17
+ </div>
18
+ </ng-template>
19
+ `,
20
+ })
21
+ export class C3DropdownComponent implements OnChanges {
22
+ @ViewChild(TemplateRef) template!: TemplateRef<any>;
23
+
24
+ /** Classes to be added to the container of the content. Supports the same syntax as `ngClass`. */
25
+ @Input()
26
+ dropdownClass: string | string[] | Set<string> | { [key: string]: any } = '';
27
+
28
+ constructor(private _changeDetectorRef: ChangeDetectorRef) {}
29
+
30
+ ngOnChanges(changes: SimpleChanges) {
31
+ if (changes['dropdownClass']) {
32
+ this._markForCheck();
33
+ }
34
+ }
35
+
36
+ _markForCheck(): void {
37
+ this._changeDetectorRef.markForCheck();
38
+ }
39
+ }
@@ -0,0 +1,161 @@
1
+ import {
2
+ Directive,
3
+ forwardRef,
4
+ ElementRef,
5
+ ViewContainerRef,
6
+ Input,
7
+ OnDestroy,
8
+ HostListener,
9
+ OnChanges,
10
+ SimpleChanges,
11
+ } from '@angular/core';
12
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
13
+ import {
14
+ Overlay,
15
+ OverlayRef,
16
+ OverlayConfig,
17
+ ConnectedPosition,
18
+ } from '@angular/cdk/overlay';
19
+ import { C3DropdownComponent } from '../components/c3-dropdown.component';
20
+ import { coerceBooleanProperty } from '@angular/cdk/coercion';
21
+ import { TemplatePortal } from '@angular/cdk/portal';
22
+ import { merge, Subject, Subscription, takeUntil } from 'rxjs';
23
+
24
+ export const MAT_DROPDOWN_VALUE_ACCESSOR: any = {
25
+ provide: NG_VALUE_ACCESSOR,
26
+ useExisting: forwardRef(() => C3DropdownTrigger),
27
+ multi: true,
28
+ };
29
+
30
+ /**
31
+ * @description The C3DropdownTrigger directive is used to display or hide a dropdown menu
32
+ * C3DropdownComponent when an item is clicked.
33
+ * @selector [c3Dropdown]
34
+ * @exportAs c3DropdownTrigger
35
+ * @input c3Dropdown - A reference to an instance of C3DropdownComponent.
36
+ * @input c3DropdownDisabled - A boolean indicating whether the directive should be disabled.
37
+ * @input c3DropdownClass - A string, an array of strings, a set of strings or a
38
+ * object representing the CSS classes to be applied to the dropdown menu.
39
+ */
40
+ @Directive({
41
+ selector: '[c3Dropdown]',
42
+ exportAs: 'c3DropdownTrigger',
43
+ providers: [MAT_DROPDOWN_VALUE_ACCESSOR],
44
+ })
45
+ export class C3DropdownTrigger implements OnChanges, OnDestroy {
46
+ private overlayRef?: OverlayRef | null;
47
+ private _closingActionsSubscription: Subscription = Subscription.EMPTY;
48
+ private _destroyed = new Subject<void>();
49
+
50
+ private _dropdownClass:
51
+ | string
52
+ | string[]
53
+ | Set<string>
54
+ | { [key: string]: any } = '';
55
+
56
+ private _dropdownDisabled: boolean = false;
57
+
58
+ /** The dropdown menu instance */
59
+ @Input('c3Dropdown')
60
+ dropdown?: C3DropdownComponent;
61
+
62
+ /** Whether the dropdown is disabled. */
63
+ @Input('c3DropdownDisabled')
64
+ get dropdownDisabled(): boolean {
65
+ return this._dropdownDisabled;
66
+ }
67
+ set dropdownDisabled(value: boolean) {
68
+ this._dropdownDisabled = coerceBooleanProperty(value);
69
+ }
70
+
71
+ /** Classes to be passed to the dropdown menu. Supports the same syntax as `ngClass`. */
72
+ @Input('c3DropdownClass')
73
+ dropdownClass: string | string[] | Set<string> | { [key: string]: any } = '';
74
+
75
+ constructor(
76
+ private _element: ElementRef<HTMLElement>,
77
+ private _overlay: Overlay,
78
+ private _viewContainerRef: ViewContainerRef
79
+ ) {}
80
+
81
+ @HostListener('click')
82
+ onClick() {
83
+ this.show();
84
+ }
85
+
86
+ ngOnChanges(changes: SimpleChanges) {
87
+ if (changes['dropdownClass'] && this.dropdown) {
88
+ this.dropdown.dropdownClass = this._dropdownClass;
89
+ this.dropdown._markForCheck();
90
+ }
91
+ }
92
+
93
+ ngOnDestroy() {
94
+ this._destroyed.next();
95
+ this._destroyed.complete();
96
+ this._closingActionsSubscription.unsubscribe();
97
+ this.close();
98
+ }
99
+
100
+ public show(): void {
101
+ if (!this.dropdown) return;
102
+
103
+ const overlayRef = this._overlay.create(this._getOverlayConfig());
104
+ const portal = new TemplatePortal(
105
+ this.dropdown.template,
106
+ this._viewContainerRef
107
+ );
108
+ overlayRef.attach(portal);
109
+
110
+ this.overlayRef = overlayRef;
111
+
112
+ this._closingActionsSubscription = this._menuClosingActions().subscribe(
113
+ () => this.close()
114
+ );
115
+ }
116
+
117
+ public close(): void {
118
+ if (this.overlayRef && this.overlayRef.hasAttached())
119
+ this.overlayRef.detach();
120
+ }
121
+
122
+ private _getOverlayConfig(): OverlayConfig {
123
+ const belowPosition: ConnectedPosition = {
124
+ originX: 'start',
125
+ originY: 'bottom',
126
+ overlayX: 'start',
127
+ overlayY: 'top',
128
+ };
129
+ const abovePosition: ConnectedPosition = {
130
+ originX: 'start',
131
+ originY: 'top',
132
+ overlayX: 'start',
133
+ overlayY: 'bottom',
134
+
135
+ // The overlay edge connected to the trigger should have squared corners, while
136
+ // the opposite end has rounded corners. We apply a CSS class to swap the
137
+ // border-radius based on the overlay position.
138
+ panelClass: 'mat-autocomplete-panel-above',
139
+ };
140
+
141
+ const positionStrategy = this._overlay
142
+ .position()
143
+ .flexibleConnectedTo(this._element)
144
+ .withLockedPosition()
145
+ .withPositions([belowPosition, abovePosition]);
146
+
147
+ return new OverlayConfig({
148
+ positionStrategy,
149
+ backdropClass: 'cdk-overlay-transparent-backdrop',
150
+ hasBackdrop: true,
151
+ });
152
+ }
153
+
154
+ /** Returns a stream that emits whenever an action that should close the menu occurs. */
155
+ private _menuClosingActions() {
156
+ const backdrop = this.overlayRef!.backdropClick();
157
+ const detachments = this.overlayRef!.detachments();
158
+
159
+ return merge(backdrop, detachments).pipe(takeUntil(this._destroyed));
160
+ }
161
+ }