@ngxmc/file-input
Version:
Angular Material File Input
119 lines (112 loc) • 5.58 kB
TypeScript
import * as i0 from '@angular/core';
import { OnDestroy, DoCheck, ElementRef, ChangeDetectorRef } from '@angular/core';
import { Platform } from '@angular/cdk/platform';
import { NgForm, FormGroupDirective, NgControl, ControlValueAccessor, ValidatorFn } from '@angular/forms';
import { ErrorStateMatcher, ThemePalette } from '@angular/material/core';
import { MatFormFieldControl } from '@angular/material/form-field';
import { Subject } from 'rxjs';
type FileOrArrayFile = File | Array<File> | File[];
declare class NgxMatInputMixinBase {
_defaultErrorStateMatcher: ErrorStateMatcher;
_parentForm: NgForm;
_parentFormGroup: FormGroupDirective;
/** @docs-private */
ngControl: NgControl;
readonly stateChanges: Subject<void>;
constructor(_defaultErrorStateMatcher: ErrorStateMatcher, _parentForm: NgForm, _parentFormGroup: FormGroupDirective,
/** @docs-private */
ngControl: NgControl);
}
declare class NgxMatFileInputIcon {
static ɵfac: i0.ɵɵFactoryDeclaration<NgxMatFileInputIcon, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NgxMatFileInputIcon, "[ngxMatFileInputIcon]", never, {}, {}, never, never, true, never>;
}
declare class NgxMatFileInputComponent extends NgxMatInputMixinBase implements MatFormFieldControl<FileOrArrayFile>, OnDestroy, DoCheck, ControlValueAccessor {
protected _elementRef: ElementRef<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>;
protected _platform: Platform;
private _cd;
ngControl: NgControl;
private _inputFileRef;
private _inputValueRef;
readonly color: i0.InputSignal<ThemePalette>;
fileNames: string;
protected _uid: string;
protected _previousNativeValue: any;
_ariaDescribedby: string;
readonly stateChanges: Subject<void>;
focused: boolean;
errorState: boolean;
controlType: string;
autofilled: boolean;
/** Function when touched */
_onTouched: () => void;
/** Function when changed */
_onChange: (value: FileOrArrayFile) => void;
get disabled(): boolean;
set disabled(value: boolean);
protected _disabled: boolean;
get id(): string;
set id(value: string);
protected _id: string;
get multiple(): boolean;
set multiple(value: boolean);
protected _multiple: boolean;
placeholder: string;
separator: i0.InputSignal<string>;
get required(): boolean;
set required(value: boolean);
protected _required: boolean;
errorStateMatcher: ErrorStateMatcher;
get value(): FileOrArrayFile;
set value(value: FileOrArrayFile);
protected _value: FileOrArrayFile;
get readonly(): boolean;
set readonly(value: boolean);
private _readonly;
/**
* Limiting accepted file types
* Example: accept="image/png, image/jpeg" or accept=".png, .jpg, .jpeg" — Accept PNG or JPEG files.
*/
get accept(): string;
set accept(value: string);
private _accept;
constructor(_elementRef: ElementRef<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>, _platform: Platform, _cd: ChangeDetectorRef, ngControl: NgControl, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, _defaultErrorStateMatcher: ErrorStateMatcher);
ngOnChanges(): void;
ngOnDestroy(): void;
ngDoCheck(): void;
updateErrorState(): void;
writeValue(value: FileOrArrayFile): void;
registerOnChange(fn: (value: any) => void): void;
registerOnTouched(fn: () => void): void;
setDisabledState(isDisabled: boolean): void;
/** Focuses the input. */
focus(options?: FocusOptions): void;
_focusChanged(isFocused: boolean): void;
/** Mark the field as touched */
_markAsTouched(): void;
protected _isBadInput(): boolean;
get empty(): boolean;
get shouldLabelFloat(): boolean;
setDescribedByIds(ids: string[]): void;
openFilePicker(event?: MouseEvent): void;
handleFiles(filelist: FileList): void;
/** Handles a click on the control's container. */
onContainerClick(event: MouseEvent): void;
private _resetInputFile;
private _updateInputValue;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxMatFileInputComponent, [null, null, null, { optional: true; self: true; }, { optional: true; }, { optional: true; }, null]>;
static ɵcmp: i0.ɵɵComponentDeclaration<NgxMatFileInputComponent, "ngx-mat-file-input", ["ngx-mat-file-input"], { "color": { "alias": "color"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; }; "id": { "alias": "id"; "required": false; }; "multiple": { "alias": "multiple"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "separator": { "alias": "separator"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; }; "errorStateMatcher": { "alias": "errorStateMatcher"; "required": false; }; "value": { "alias": "value"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "accept": { "alias": "accept"; "required": false; }; }, {}, never, ["[ngxMatFileInputIcon]"], true, never>;
}
declare function calculFileSize(number: number): string;
/**
* Validator for size of file
* @param max Max of size of file (in bytes)
*/
declare function MaxSizeValidator(max: number): ValidatorFn;
/**
* Validator for input file accept
* @param accept Allowable type of file
*/
declare function AcceptValidator(accept: string): ValidatorFn;
export { AcceptValidator, MaxSizeValidator, NgxMatFileInputComponent, NgxMatFileInputIcon, calculFileSize };
export type { FileOrArrayFile };