projects/isy-angular-widgets/src/lib/input-char/components/input-char/input-char.component.ts
| selector | isy-input-char |
| standalone | true |
| imports |
ButtonModule
|
| styleUrls | ./input-char.component.scss |
| templateUrl | ./input-char.component.html |
Properties |
Methods |
Inputs |
Outputs |
| closable | |
Type : boolean
|
|
Default value : true
|
|
|
Determines whether the char picker can be closed |
|
| closeOnEscape | |
Type : boolean
|
|
Default value : true
|
|
|
Determines whether the picker closes when pressing the ESC key |
|
| closePickerAriaLabel | |
Type : string
|
|
|
Aria label for the close picker button. Defaults to translation from WidgetsConfigService if not provided. |
|
| datentyp | |
Type : Datentyp
|
|
Default value : Datentyp.DATENTYP_C
|
|
|
Determines which set of characters (datatype) according to DIN 91379 to show |
|
| dismissableMask | |
Type : boolean
|
|
Default value : false
|
|
|
Determines whether the picker closes when clicking outside of it |
|
| draggable | |
Type : boolean
|
|
Default value : true
|
|
|
Determines whether the char picker can be repositioned manually |
|
| header | |
Type : string
|
|
|
A title to show |
|
| height | |
Type : string
|
|
Default value : '460px'
|
|
|
The height of the dialog. |
|
| isInputDisabled | |
Type : boolean
|
|
Default value : false
|
|
|
Determines whether the input is displayed |
|
| modal | |
Type : boolean
|
|
Default value : true
|
|
|
Determines whether the picker is displayed as a modal. Enabled by default so PrimeNG's dialog provides the focus trap (keyboard accessibility). |
|
| outlinedInputCharButton | |
Type : boolean
|
|
Default value : false
|
|
|
Determines whether the button is outlined |
|
| resizable | |
Type : boolean
|
|
Default value : false
|
|
|
Determines whether the char picker can be resized manually |
|
| togglePickerAriaLabel | |
Type : string
|
|
|
Aria label for the open picker button. Defaults to translation from WidgetsConfigService if not provided. |
|
| width | |
Type : string
|
|
Default value : '740px'
|
|
|
The width of the dialog. |
|
| insertCharacter | |
Type : EventEmitter
|
|
|
The current value |
|
| ngOnDestroy |
ngOnDestroy()
|
|
Returns :
void
|
| toggleCharPicker |
toggleCharPicker()
|
|
Returns :
void
|
| configService |
Type : unknown
|
Default value : inject(WidgetsConfigService)
|
|
A service used to translate labels within the widgets library. |
| openDialogButton |
Type : ElementRef<HTMLButtonElement>
|
Decorators :
@ViewChild('openDialogButton')
|
import {
Component,
ElementRef,
ErrorHandler,
EventEmitter,
inject,
Input,
OnDestroy,
Output,
ViewChild
} from '@angular/core';
import {Datentyp} from '../../model/datentyp';
import {WidgetsConfigService} from '../../../i18n/widgets-config.service';
import {ButtonModule} from 'primeng/button';
import {InputCharPickerService} from '../../services/input-char-picker.service';
@Component({
standalone: true,
selector: 'isy-input-char',
templateUrl: './input-char.component.html',
styleUrls: ['./input-char.component.scss'],
imports: [ButtonModule]
})
export class InputCharComponent implements OnDestroy {
/**
* The width of the dialog.
*/
@Input() width = '740px';
/**
* The height of the dialog.
*/
@Input() height = '460px';
/**
* The current value
*/
@Output() insertCharacter = new EventEmitter<string>();
/**
* Determines which set of characters (datatype) according to DIN 91379 to show
*/
@Input() datentyp: Datentyp = Datentyp.DATENTYP_C;
/**
* A title to show
*/
@Input() header?: string;
/**
* Determines whether the button is outlined
*/
@Input() outlinedInputCharButton: boolean = false;
/**
* Determines whether the char picker can be closed
*/
@Input() closable: boolean = true;
/**
* Determines whether the char picker can be repositioned manually
*/
@Input() draggable: boolean = true;
/**
* Determines whether the char picker can be resized manually
*/
@Input() resizable: boolean = false;
/**
* Determines whether the picker closes when clicking outside of it
*/
@Input() dismissableMask: boolean = false;
/**
* Determines whether the picker closes when pressing the ESC key
*/
@Input() closeOnEscape: boolean = true;
/**
* Determines whether the picker is displayed as a modal.
* Enabled by default so PrimeNG's dialog provides the focus trap (keyboard accessibility).
*/
@Input() modal: boolean = true;
/**
* Determines whether the input is displayed
*/
@Input() isInputDisabled: boolean = false;
/**
* Aria label for the open picker button.
* Defaults to translation from WidgetsConfigService if not provided.
*/
@Input() togglePickerAriaLabel?: string;
/**
* Aria label for the close picker button.
* Defaults to translation from WidgetsConfigService if not provided.
*/
@Input() closePickerAriaLabel?: string;
@ViewChild('openDialogButton') openDialogButton!: ElementRef<HTMLButtonElement>;
/**
* A service used to translate labels within the widgets library.
*/
configService = inject(WidgetsConfigService);
private readonly pickerService = inject(InputCharPickerService);
private readonly errorHandler = inject(ErrorHandler);
ngOnDestroy(): void {
const button = this.openDialogButton?.nativeElement;
if (!button) {
return;
}
this.pickerService.closeFor(button);
}
toggleCharPicker(): void {
const button = this.openDialogButton?.nativeElement;
if (!button) {
return;
}
if (this.pickerService.isOpenFor(button)) {
this.pickerService.close();
return;
}
void this.openCharPicker(button);
}
private async openCharPicker(button: HTMLButtonElement): Promise<void> {
try {
await this.pickerService.open({
datentyp: this.datentyp,
triggerElement: button,
width: this.width,
height: this.height,
header: this.header,
closable: this.closable,
draggable: this.draggable,
resizable: this.resizable,
dismissableMask: this.dismissableMask,
closeOnEscape: this.closeOnEscape,
modal: this.modal,
togglePickerAriaLabel: this.togglePickerAriaLabel,
closePickerAriaLabel: this.closePickerAriaLabel,
onInsert: (zeichen) => this.insertCharacter.emit(zeichen)
});
} catch (error: unknown) {
this.errorHandler.handleError(error);
}
}
}
<button
#openDialogButton
[attr.aria-label]="togglePickerAriaLabel ?? configService.getTranslation('inputChar.aria.togglePicker')"
class="input-char-button"
[class.p-button-outlined]="outlinedInputCharButton"
type="button"
pRipple
pButton
icon="pi pi-language"
[outlined]="outlinedInputCharButton"
[disabled]="isInputDisabled"
(click)="toggleCharPicker()"
></button>
./input-char.component.scss
.input-char-button {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
padding-block: var(--isyfact-button-padding-block);
}