mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
chore(): begin adding ionic components to mono-repo.
This commit is contained in:
70
packages/ionic-angular/src/components/option/option.ts
Normal file
70
packages/ionic-angular/src/components/option/option.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { Directive, ElementRef, EventEmitter, Input, Output } from '@angular/core';
|
||||
|
||||
import { isPresent, isTrueProperty } from '../../util/util';
|
||||
|
||||
/**
|
||||
* @name Option
|
||||
* @description
|
||||
* `ion-option` is a child component of `ion-select`. Similar to the native option element, `ion-option` can take a value and a selected property.
|
||||
*
|
||||
* @demo /docs/demos/src/select/
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'ion-option'
|
||||
})
|
||||
export class Option {
|
||||
|
||||
_selected: boolean = false;
|
||||
_disabled: boolean = false;
|
||||
_value: any;
|
||||
|
||||
/**
|
||||
* @input {boolean} If true, the user cannot interact with this element.
|
||||
*/
|
||||
@Input()
|
||||
get disabled(): boolean {
|
||||
return this._disabled;
|
||||
}
|
||||
set disabled(val: boolean) {
|
||||
this._disabled = isTrueProperty(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @input {boolean} If true, the element is selected.
|
||||
*/
|
||||
@Input()
|
||||
get selected(): boolean {
|
||||
return this._selected;
|
||||
}
|
||||
set selected(val: boolean) {
|
||||
this._selected = isTrueProperty(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @input {any} The value of the option.
|
||||
*/
|
||||
@Input()
|
||||
get value() {
|
||||
if (isPresent(this._value)) {
|
||||
return this._value;
|
||||
}
|
||||
return this.text;
|
||||
}
|
||||
set value(val: any) {
|
||||
this._value = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @output {any} Event to evaluate when option is selected.
|
||||
*/
|
||||
@Output() ionSelect: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
constructor(private _elementRef: ElementRef) {}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
get text() {
|
||||
return this._elementRef.nativeElement.textContent;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user