Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 0a7e909

Browse files
authored
Add TypeScript declarations to iron-input. (#125)
* Generate minimal package.json from bower.json * Update and/or configure type declarations.
1 parent 4928981 commit 0a7e909

File tree

5 files changed

+1158
-0
lines changed

5 files changed

+1158
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bower_components*
22
bower-*.json
3+
node_modules

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ sudo: required
33
before_script:
44
- npm install -g polymer-cli
55
- polymer install --variants
6+
- >-
7+
npm run update-types && git diff --exit-code || (echo -e
8+
'\n\033[31mERROR:\033[0m Typings are stale. Please run "npm run
9+
update-types".' && false)
610
env:
711
global:
812
- secure: >-

iron-input.d.ts

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/**
2+
* DO NOT EDIT
3+
*
4+
* This file was automatically generated by
5+
* https://github.com/Polymer/gen-typescript-declarations
6+
*
7+
* To modify these typings, edit the source file(s):
8+
* iron-input.html
9+
*/
10+
11+
/// <reference path="../polymer/types/polymer.d.ts" />
12+
/// <reference path="../iron-a11y-announcer/iron-a11y-announcer.d.ts" />
13+
/// <reference path="../iron-validatable-behavior/iron-validatable-behavior.d.ts" />
14+
15+
/**
16+
* `<iron-input>` is a wrapper to a native `<input>` element, that adds two-way binding
17+
* and prevention of invalid input. To use it, you must distribute a native `<input>`
18+
* yourself. You can continue to use the native `input` as you would normally:
19+
*
20+
* <iron-input>
21+
* <input>
22+
* </iron-input>
23+
*
24+
* <iron-input>
25+
* <input type="email" disabled>
26+
* </iron-input>
27+
*
28+
* ### Two-way binding
29+
*
30+
* By default you can only get notified of changes to a native `<input>`'s `value`
31+
* due to user input:
32+
*
33+
* <input value="{{myValue::input}}">
34+
*
35+
* This means that if you imperatively set the value (i.e. `someNativeInput.value = 'foo'`),
36+
* no events will be fired and this change cannot be observed.
37+
*
38+
* `iron-input` adds the `bind-value` property that mirrors the native `input`'s '`value` property; this
39+
* property can be used for two-way data binding.
40+
* `bind-value` will notify if it is changed either by user input or by script.
41+
*
42+
* <iron-input bind-value="{{myValue}}">
43+
* <input>
44+
* </iron-input>
45+
*
46+
* Note: this means that if you want to imperatively set the native `input`'s, you _must_
47+
* set `bind-value` instead, so that the wrapper `iron-input` can be notified.
48+
*
49+
* ### Validation
50+
*
51+
* `iron-input` uses the native `input`'s validation. For simplicity, `iron-input`
52+
* has a `validate()` method (which internally just checks the distributed `input`'s
53+
* validity), which sets an `invalid` attribute that can also be used for styling.
54+
*
55+
* To validate automatically as you type, you can use the `auto-validate` attribute.
56+
*
57+
* `iron-input` also fires an `iron-input-validate` event after `validate()` is
58+
* called. You can use it to implement a custom validator:
59+
*
60+
* var CatsOnlyValidator = {
61+
* validate: function(ironInput) {
62+
* var valid = !ironInput.bindValue || ironInput.bindValue === 'cat';
63+
* ironInput.invalid = !valid;
64+
* return valid;
65+
* }
66+
* }
67+
* ironInput.addEventListener('iron-input-validate', function() {
68+
* CatsOnly.validate(input2);
69+
* });
70+
*
71+
* You can also use an element implementing an [`IronValidatorBehavior`](/element/PolymerElements/iron-validatable-behavior).
72+
* This example can also be found in the demo for this element:
73+
*
74+
* <iron-input validator="cats-only">
75+
* <input>
76+
* </iron-input>
77+
*
78+
* ### Preventing invalid input
79+
*
80+
* It may be desirable to only allow users to enter certain characters. You can use the
81+
* `allowed-pattern` attribute to accomplish this. This feature
82+
* is separate from validation, and `allowed-pattern` does not affect how the input is validated.
83+
*
84+
* // Only allow typing digits, but a valid input has exactly 5 digits.
85+
* <iron-input allowed-pattern="[0-9]">
86+
* <input pattern="\d{5}">
87+
* </iron-input>
88+
*/
89+
interface IronInputElement extends Polymer.Element, Polymer.IronValidatableBehavior {
90+
91+
/**
92+
* Use this property instead of `value` for two-way data binding, or to
93+
* set a default value for the input. **Do not** use the distributed
94+
* input's `value` property to set a default value.
95+
*/
96+
bindValue: string|null|undefined;
97+
98+
/**
99+
* Computed property that echoes `bindValue` (mostly used for Polymer 1.0
100+
* backcompatibility, if you were one-way binding to the Polymer 1.0
101+
* `input is="iron-input"` value attribute).
102+
*/
103+
readonly value: string|null|undefined;
104+
105+
/**
106+
* Regex-like list of characters allowed as input; all characters not in the list
107+
* will be rejected. The recommended format should be a list of allowed characters,
108+
* for example, `[a-zA-Z0-9.+-!;:]`.
109+
*
110+
* This pattern represents the allowed characters for the field; as the user inputs text,
111+
* each individual character will be checked against the pattern (rather than checking
112+
* the entire value as a whole). If a character is not a match, it will be rejected.
113+
*
114+
* Pasted input will have each character checked individually; if any character
115+
* doesn't match `allowedPattern`, the entire pasted string will be rejected.
116+
*
117+
* Note: if you were using `iron-input` in 1.0, you were also required to
118+
* set `prevent-invalid-input`. This is no longer needed as of Polymer 2.0,
119+
* and will be set automatically for you if an `allowedPattern` is provided.
120+
*/
121+
allowedPattern: string|null|undefined;
122+
123+
/**
124+
* Set to true to auto-validate the input value as you type.
125+
*/
126+
autoValidate: boolean|null|undefined;
127+
128+
/**
129+
* The native input element.
130+
*/
131+
_inputElement: object|null|undefined;
132+
133+
/**
134+
* Returns the distributed <input> element.
135+
*
136+
*/
137+
readonly inputElement: any;
138+
readonly _patternRegExp: any;
139+
140+
/**
141+
* Returns true if `value` is valid. The validator provided in `validator` will be used first,
142+
* then any constraints.
143+
*
144+
* @returns True if the value is valid.
145+
*/
146+
validate(): boolean;
147+
created(): void;
148+
attached(): void;
149+
detached(): void;
150+
_initSlottedInput(): void;
151+
_bindValueChanged(bindValue: any, inputElement: any): void;
152+
_onInput(): void;
153+
_isPrintable(event: any): any;
154+
_onKeypress(event: any): void;
155+
_checkPatternValidity(): any;
156+
_announceInvalidCharacter(message: any): void;
157+
_computeValue(bindValue: any): any;
158+
}
159+
160+
interface HTMLElementTagNameMap {
161+
"iron-input": IronInputElement;
162+
}

0 commit comments

Comments
 (0)