Skip to content

Commit b4cedf0

Browse files
authored
Merge pull request #138 from assureclaims/feature/RMA-File_Input
File Input control
2 parents 654e6c7 + a66f45e commit b4cedf0

17 files changed

+1406
-1
lines changed

angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
}
331331
}
332332
},
333-
"defaultProject": "angular-dxc-site",
333+
"defaultProject": "dxc-ngx-cdk",
334334
"cli": {
335335
"analytics": false
336336
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Directive, ElementRef, Input, Inject } from '@angular/core';
2+
import { DOCUMENT } from '@angular/common';
3+
4+
@Directive({
5+
selector: '[dxcFileFormat]'
6+
})
7+
export class FileFormatDirective {
8+
9+
@Input() format;
10+
11+
constructor(private elementRef: ElementRef, @Inject(DOCUMENT) private document: any) {
12+
}
13+
14+
ngOnInit(): void {
15+
let xmlns = "http://www.w3.org/2000/svg";
16+
const commonPathChild = this.document.createElementNS(xmlns, "path");
17+
commonPathChild.setAttributeNS(null, 'd', 'M0 0h24v24H0V0z');
18+
commonPathChild.setAttributeNS(null, 'fill', 'none');
19+
const child = this.document.createElementNS(xmlns, "path");
20+
switch (this.categorizeFileFormat(this.format)) {
21+
case 'image':
22+
child.setAttributeNS(null, 'd', 'M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z');
23+
break;
24+
case 'video':
25+
child.setAttributeNS(null, 'd', 'M4 6.47L5.76 10H20v8H4V6.47M22 4h-4l2 4h-3l-2-4h-2l2 4h-3l-2-4H8l2 4H7L5 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4z');
26+
break;
27+
case 'audio':
28+
child.setAttributeNS(null, 'd', 'M21 3H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H3V5h18v14zM8 15c0-1.66 1.34-3 3-3 .35 0 .69.07 1 .18V6h5v2h-3v7.03c-.02 1.64-1.35 2.97-3 2.97-1.66 0-3-1.34-3-3z');
29+
break;
30+
default:
31+
child.setAttributeNS(null, 'd', 'M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z');
32+
break;
33+
}
34+
this.elementRef.nativeElement.append(commonPathChild);
35+
this.elementRef.nativeElement.append(child);
36+
}
37+
38+
private categorizeFileFormat(fileFormat:string){
39+
if (fileFormat.includes("image")) {
40+
return 'image';
41+
} else if (fileFormat.includes("video")) {
42+
return 'video';
43+
44+
} else if (fileFormat.includes("audio")) {
45+
return 'audio';
46+
47+
}
48+
return 'default';
49+
}
50+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<span
2+
class="errorMessage"
3+
>{{error}}</span>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.errorMessage {
2+
text-align: left;
3+
letter-spacing: 0.37px;
4+
color: var(--fileInput-errorMessageFontColor);
5+
font-family: var(--fileInput-errorMessageFontFamily);
6+
font-size: var(--fileInput-errorMessageFontSize);
7+
font-weight: var(--fileInput-errorMessageFontWeight);
8+
line-height: var(--fileInput-errorMessageLineHeight);
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ChangeDetectionStrategy, Component, HostBinding, Input, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'dxc-file-error',
5+
templateUrl: './dxc-file-error.component.html',
6+
styleUrls: ['./dxc-file-error.component.scss'],
7+
changeDetection: ChangeDetectionStrategy.OnPush,
8+
})
9+
export class DxcFileErrorComponent implements OnInit {
10+
11+
@Input()
12+
error: string;
13+
14+
constructor() { }
15+
16+
ngOnInit(): void {
17+
18+
}
19+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<label class="label" htmlFor="{{ id }}">{{ label }}</label>
2+
<span *ngIf="helperText" class="helperText">{{ helperText }}</span>
3+
<div class="fileInputContainer">
4+
<input
5+
#fileInput
6+
data-testid="input"
7+
type="file"
8+
(change)="onFileInput($event)"
9+
[accept]="accept"
10+
/>
11+
<dxc-button
12+
*ngIf="mode === 'file'"
13+
[label]="buttonLabel"
14+
mode="secondary"
15+
[disabled]="disabled"
16+
(onClick)="fileInput.click()"
17+
[tabIndexValue]="tabIndexValue"
18+
></dxc-button>
19+
<div
20+
*ngIf="mode !== 'file'"
21+
class="dragDropArea"
22+
[ngClass]="{
23+
hovering: hoveringWithFile === true
24+
}"
25+
(drop)="drop($event)"
26+
(dragleave)="dragLeave($event)"
27+
(dragover)="dragOver($event)"
28+
>
29+
<dxc-button
30+
[label]="buttonLabel"
31+
mode="secondary"
32+
[disabled]="disabled"
33+
[tabIndexValue]="tabIndexValue"
34+
(onClick)="fileInput.click()"
35+
></dxc-button>
36+
<span *ngIf="mode === 'filedrop' || mode === 'dropzone'" class="dropLabel"
37+
>or drop files</span
38+
>
39+
</div>
40+
<div class="fileContainer">
41+
<dxc-file
42+
*ngFor="let file of value"
43+
[file]="file"
44+
[showPreview]="showPreview"
45+
[multiple]="!hasSingleFile"
46+
[mode]="mode"
47+
[tabIndexValue]="tabIndexValue"
48+
[updatable]="callbackFile?.observers?.length > 0"
49+
></dxc-file>
50+
</div>
51+
</div>
52+
53+
<dxc-file-error *ngIf="hasShowError" [error]="value[0]?.error"></dxc-file-error>

0 commit comments

Comments
 (0)