mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-08 23:58:13 +08:00
chore(interface): init input interfaces
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
|
import { BlurEvent, BooleanInput, BooleanInputChangeEvent, FocusEvent, StyleEvent } from '../../utils/input-interfaces';
|
||||||
import { Component, CssClassMap, Event, EventEmitter, Listen, Prop, PropDidChange } from '@stencil/core';
|
import { Component, CssClassMap, Event, EventEmitter, Listen, Prop, PropDidChange } from '@stencil/core';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Checkbox
|
* @name Checkbox
|
||||||
* @module ionic
|
* @module ionic
|
||||||
@ -76,7 +76,7 @@ import { Component, CssClassMap, Event, EventEmitter, Listen, Prop, PropDidChang
|
|||||||
theme: 'checkbox'
|
theme: 'checkbox'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class Checkbox {
|
export class Checkbox implements BooleanInput {
|
||||||
private checkboxId: string;
|
private checkboxId: string;
|
||||||
private labelId: string;
|
private labelId: string;
|
||||||
private styleTmr: any;
|
private styleTmr: any;
|
||||||
@ -84,12 +84,22 @@ export class Checkbox {
|
|||||||
/**
|
/**
|
||||||
* @output {Event} Emitted when the checked property has changed.
|
* @output {Event} Emitted when the checked property has changed.
|
||||||
*/
|
*/
|
||||||
@Event() ionChange: EventEmitter;
|
@Event() ionChange: EventEmitter<BooleanInputChangeEvent>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @output {Event} Emitted when the toggle has focus.
|
||||||
|
*/
|
||||||
|
@Event() ionFocus: EventEmitter<FocusEvent>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @output {Event} Emitted when the toggle loses focus.
|
||||||
|
*/
|
||||||
|
@Event() ionBlur: EventEmitter<BlurEvent>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @output {Event} Emitted when the styles change.
|
* @output {Event} Emitted when the styles change.
|
||||||
*/
|
*/
|
||||||
@Event() ionStyle: EventEmitter;
|
@Event() ionStyle: EventEmitter<StyleEvent>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @input {string} The color to use from your Sass `$colors` map.
|
* @input {string} The color to use from your Sass `$colors` map.
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
|
import { BlurEvent, BooleanInput, BooleanInputChangeEvent, FocusEvent, StyleEvent } from '../../utils/input-interfaces';
|
||||||
import { Component, Event, EventEmitter, Listen, Method, Prop, PropDidChange, State } from '@stencil/core';
|
import { Component, Event, EventEmitter, Listen, Method, Prop, PropDidChange, State } from '@stencil/core';
|
||||||
import { BooleanInputComponent, GestureDetail } from '../../index';
|
import { GestureDetail } from '../../index';
|
||||||
import { hapticSelection } from '../../utils/haptic';
|
import { hapticSelection } from '../../utils/haptic';
|
||||||
|
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ import { hapticSelection } from '../../utils/haptic';
|
|||||||
theme: 'toggle'
|
theme: 'toggle'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class Toggle implements BooleanInputComponent {
|
export class Toggle implements BooleanInput {
|
||||||
private toggleId: string;
|
private toggleId: string;
|
||||||
private labelId: string;
|
private labelId: string;
|
||||||
private styleTmr: any;
|
private styleTmr: any;
|
||||||
@ -26,22 +27,22 @@ export class Toggle implements BooleanInputComponent {
|
|||||||
/**
|
/**
|
||||||
* @output {Event} Emitted when the value property has changed.
|
* @output {Event} Emitted when the value property has changed.
|
||||||
*/
|
*/
|
||||||
@Event() ionChange: EventEmitter;
|
@Event() ionChange: EventEmitter<BooleanInputChangeEvent>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @output {Event} Emitted when the styles change.
|
* @output {Event} Emitted when the styles change.
|
||||||
*/
|
*/
|
||||||
@Event() ionStyle: EventEmitter;
|
@Event() ionStyle: EventEmitter<StyleEvent>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @output {Event} Emitted when the toggle has focus.
|
* @output {Event} Emitted when the toggle has focus.
|
||||||
*/
|
*/
|
||||||
@Event() ionFocus: EventEmitter;
|
@Event() ionFocus: EventEmitter<FocusEvent>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @output {Event} Emitted when the toggle loses focus.
|
* @output {Event} Emitted when the toggle loses focus.
|
||||||
*/
|
*/
|
||||||
@Event() ionBlur: EventEmitter;
|
@Event() ionBlur: EventEmitter<BlurEvent>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @input {string} The color to use from your Sass `$colors` map.
|
* @input {string} The color to use from your Sass `$colors` map.
|
||||||
@ -187,8 +188,7 @@ export class Toggle implements BooleanInputComponent {
|
|||||||
protected render() {
|
protected render() {
|
||||||
return (
|
return (
|
||||||
<ion-gesture {...this.gestureConfig}
|
<ion-gesture {...this.gestureConfig}
|
||||||
enabled={!this.disabled}
|
enabled={!this.disabled}>
|
||||||
>
|
|
||||||
<div class='toggle-icon'>
|
<div class='toggle-icon'>
|
||||||
<div class='toggle-inner'></div>
|
<div class='toggle-inner'></div>
|
||||||
</div>
|
</div>
|
||||||
@ -199,8 +199,7 @@ export class Toggle implements BooleanInputComponent {
|
|||||||
aria-disabled={this.disabled ? 'true' : false}
|
aria-disabled={this.disabled ? 'true' : false}
|
||||||
aria-labelledby={this.labelId}
|
aria-labelledby={this.labelId}
|
||||||
role='checkbox'
|
role='checkbox'
|
||||||
tabIndex={0}
|
tabIndex={0}>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</ion-gesture>
|
</ion-gesture>
|
||||||
);
|
);
|
||||||
|
|||||||
6
packages/core/src/index.d.ts
vendored
6
packages/core/src/index.d.ts
vendored
@ -174,12 +174,6 @@ export interface BaseInputComponent {
|
|||||||
fireBlur: () => void;
|
fireBlur: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BooleanInputComponent extends BaseInputComponent {
|
|
||||||
checked: boolean;
|
|
||||||
toggle: (ev: UIEvent) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface StencilElement extends HTMLElement {
|
export interface StencilElement extends HTMLElement {
|
||||||
componentOnReady(): Promise<HTMLElement>;
|
componentOnReady(): Promise<HTMLElement>;
|
||||||
componentOnReady(done: (cmp?: HTMLElement) => void): void;
|
componentOnReady(done: (cmp?: HTMLElement) => void): void;
|
||||||
|
|||||||
122
packages/core/src/utils/input-interfaces.d.ts
vendored
Normal file
122
packages/core/src/utils/input-interfaces.d.ts
vendored
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
import { EventEmitter } from '@stencil/core';
|
||||||
|
|
||||||
|
|
||||||
|
export interface BaseInput {
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the user cannot interact with the control.
|
||||||
|
*/
|
||||||
|
disabled: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns / Sets the element's readonly attribute, indicating that
|
||||||
|
* the user cannot modify the value of the control. HTML5. This is
|
||||||
|
* ignored if the value of the type attribute is hidden, range, color,
|
||||||
|
* checkbox, radio, file, or a button type.
|
||||||
|
*/
|
||||||
|
readOnly?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflects the value of the form control.
|
||||||
|
*/
|
||||||
|
value: string;
|
||||||
|
|
||||||
|
|
||||||
|
// Events
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes focus from input; keystrokes will subsequently go nowhere.
|
||||||
|
*/
|
||||||
|
ionBlur: EventEmitter<BlurEvent>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Focus on the input element; keystrokes will subsequently go to this element.
|
||||||
|
*/
|
||||||
|
ionFocus: EventEmitter<FocusEvent>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the styles change. This is useful for parent
|
||||||
|
* components to know how to style themselves depending on the
|
||||||
|
* child input. For example, a disabled ion-toggle may give
|
||||||
|
* its wrapping ion-item a different style.
|
||||||
|
*/
|
||||||
|
ionStyle: EventEmitter<StyleEvent>;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface BooleanInput extends BaseInput {
|
||||||
|
/**
|
||||||
|
* Returns / Sets the current state of the element when type is checkbox or radio.
|
||||||
|
*/
|
||||||
|
checked: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The change event is fired when the value of has changed.
|
||||||
|
* This is actually more similar to the native "input" event
|
||||||
|
* https://developer.mozilla.org/en-US/docs/Web/Events/input
|
||||||
|
*/
|
||||||
|
ionChange: EventEmitter<BooleanInputChangeEvent>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface BooleanInputChangeEvent {
|
||||||
|
checked: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface SelectOptionInput extends BaseInput {
|
||||||
|
/**
|
||||||
|
* Indicates whether the option is currently selected.
|
||||||
|
*/
|
||||||
|
selected: boolean;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface SelectInput extends BaseInput {
|
||||||
|
/**
|
||||||
|
* Indicates whether the option is currently selected.
|
||||||
|
*/
|
||||||
|
selected: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A long reflecting the index of the first selected <option> element.
|
||||||
|
* The value -1 indicates no element is selected.
|
||||||
|
*/
|
||||||
|
selectedIndex: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflecting the multiple HTML attribute, which indicates
|
||||||
|
* whether multiple items can be selected.
|
||||||
|
*/
|
||||||
|
multiple: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface TextInput extends BaseInput {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface TextMultiLineInput extends TextInput {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface StyleEvent {
|
||||||
|
[styleName: string]: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface FocusEvent {}
|
||||||
|
|
||||||
|
|
||||||
|
export interface BlurEvent {}
|
||||||
|
|
||||||
Reference in New Issue
Block a user