@engie-group/fluid-design-system-angular
Version:
Fluid Design System Angular
98 lines (80 loc) • 2.05 kB
text/typescript
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { RadioSize } from './radio.model';
export class RadioComponent {
private readonly radioClassName = 'nj-radio';
/**
* Input id
*/
inputId: string;
/**
* Input name
*/
name: string;
/**
* Whether input is required or not
*/
required?: boolean;
/**
* Whether the radio is checked or not
*/
isChecked = false;
/**
* Input value
*/
value: string;
/**
* Whether the radio is disabled or not
*/
isDisabled?: boolean;
/**
* Radio size
*/
size?: RadioSize = 'md';
/**
* Text alternative for assistive technologies
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label
*/
ariaLabel?: string;
/**
* Text alternative for assistive technologies based on visible text
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby
*/
ariaLabelledby?: string;
/**
* Output that emits checked value on change only
*/
valueChange: EventEmitter<boolean> = new EventEmitter<boolean>();
constructor(private cdr: ChangeDetectorRef) {}
/**
* @ignore
*/
onInputChange(event: Event) {
event.stopPropagation();
this.isChecked = !this.isChecked;
this.valueChange.emit(this.isChecked);
}
/**
* @ignore
*/
_markForCheck() {
this.cdr.markForCheck();
}
protected get classes() {
const classes = [this.radioClassName];
if (this.size && this.size !== 'md') {
classes.push(`${this.radioClassName}--${this.size}`);
}
return classes;
}
}