Skip to content

Commit

Permalink
feat: prepare for TS defs generation
Browse files Browse the repository at this point in the history
Closes #141
  • Loading branch information
pekam committed May 28, 2020
1 parent 4d3ba42 commit fc3836b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ bower.json
gulpfile.js
index.html
screenshot.png
gen-tsd.json
magi-p3-post.js
13 changes: 13 additions & 0 deletions @types/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface TimePickerTime {
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
}

export interface TimePickerI18n {
parseTime: (time: string) => TimePickerTime | undefined;
formatTime: (time: TimePickerTime) => string;
clear: string;
selector: string;
}
12 changes: 6 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
"dependencies": {
"polymer": "^2.0.0",
"iron-a11y-keys-behavior": "^2.0.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.3.2",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.3.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.6.1",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.4.1",
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.6.0",
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.3.2",
"vaadin-text-field": "vaadin/vaadin-text-field#^2.6.0-alpha4",
"vaadin-combo-box": "vaadin/vaadin-combo-box#^5.2.0-alpha1",
"vaadin-control-state-mixin": "vaadin/vaadin-control-state-mixin#^2.1.1"
"vaadin-text-field": "vaadin/vaadin-text-field#^2.7.0-alpha2",
"vaadin-combo-box": "vaadin/vaadin-combo-box#^5.3.0-alpha1",
"vaadin-control-state-mixin": "vaadin/vaadin-control-state-mixin#^2.2.2"
},
"devDependencies": {
"iron-component-page": "^3.0.0",
"iron-test-helpers": "^2.0.0",
"webcomponentsjs": "^1.0.0",
"web-component-tester": "^6.1.5",
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^3.1.0-alpha1",
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^3.1.0",
"iron-form": "^2.3.0"
}
}
16 changes: 16 additions & 0 deletions gen-tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"excludeFiles": [
"wct.conf.js",
"index.html",
"src/vaadin-time-picker-text-field.js",
"demo/**/*",
"test/**/*",
"theme/**/*"
],
"autoImport": {
"./@types/interfaces": [
"TimePickerTime",
"TimePickerI18n"
]
}
}
11 changes: 11 additions & 0 deletions magi-p3-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
files: [
'vaadin-time-picker.js'
],
from: [
/import '\.\/theme\/lumo\/vaadin-(.+)\.js';/
],
to: [
`import './theme/lumo/vaadin-$1.js';\nexport * from './src/vaadin-$1.js';`
]
};
25 changes: 21 additions & 4 deletions src/vaadin-time-picker.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<link rel="import" href="../../polymer/polymer-element.html">
<link rel="import" href="../../vaadin-themable-mixin/vaadin-themable-mixin.html">
<link rel="import" href="../../vaadin-themable-mixin/vaadin-theme-property-mixin.html">
<link rel="import" href="../../vaadin-element-mixin/vaadin-element-mixin.html">
<link rel="import" href="../../vaadin-combo-box/src/vaadin-combo-box-light.html">
<link rel="import" href="../../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
Expand Down Expand Up @@ -122,14 +121,12 @@
* @mixes Vaadin.ElementMixin
* @mixes Vaadin.ControlStateMixin
* @mixes Vaadin.ThemableMixin
* @mixes Vaadin.ThemePropertyMixin
* @demo demo/index.html
*/
class TimePickerElement extends
Vaadin.ElementMixin(
Vaadin.ControlStateMixin(
Vaadin.ThemableMixin(
Vaadin.ThemePropertyMixin(Polymer.Element)))) {
Vaadin.ThemableMixin(Polymer.Element))) {

static get is() {
return 'vaadin-time-picker';
Expand Down Expand Up @@ -172,6 +169,7 @@

/**
* Set to true to mark the input as required.
* @type {boolean}
*/
required: {
type: Boolean,
Expand All @@ -180,6 +178,7 @@

/**
* Set to true to disable this input.
* @type {boolean}
*/
disabled: {
type: Boolean,
Expand All @@ -188,6 +187,7 @@

/**
* Set to true to prevent the user from entering invalid input.
* @type {boolean}
*/
preventInvalidInput: {
type: Boolean
Expand Down Expand Up @@ -217,6 +217,7 @@

/**
* Set to true to prevent user picking a date or typing in the input.
* @type {boolean}
*/
readonly: {
type: Boolean,
Expand All @@ -226,6 +227,7 @@

/**
* Set to true if the value is invalid.
* @type {boolean}
*/
invalid: {
type: Boolean,
Expand Down Expand Up @@ -282,6 +284,7 @@

/**
* Set to true to display the clear icon which clears the input.
* @type {boolean}
*/
clearButtonVisible: {
type: Boolean,
Expand All @@ -290,6 +293,7 @@

/**
* Set true to prevent the overlay from opening automatically.
* @type {boolean}
*/
autoOpenDisabled: Boolean,

Expand Down Expand Up @@ -326,6 +330,7 @@
// Translation of the time selector clear button title.
clear: 'Clear'
}
* @type {!TimePickerI18n}
*/
i18n: {
type: Object,
Expand Down Expand Up @@ -619,6 +624,7 @@
return TimePickerElement.properties.i18n.value().parseTime(text);
}

/** @private */
_getInputElement() {
return this.shadowRoot.querySelector('vaadin-time-picker-text-field');
}
Expand All @@ -634,6 +640,8 @@

/**
* Focusable element used by vaadin-control-state-mixin
* @return {!HTMLElement}
* @protected
*/
get focusElement() {
return this.__inputElement;
Expand All @@ -648,6 +656,13 @@
return !(this.invalid = !this.checkValidity());
}

/**
* Returns true if `time` satisfies the `min` and `max` constraints (if any).
*
* @param {!TimePickerTime} time Value to check against constraints
* @return {boolean} True if `time` satisfies the constraints
* @protected
*/
_timeAllowed(time) {
const parsedMin = this.i18n.parseTime(this.min);
const parsedMax = this.i18n.parseTime(this.max);
Expand All @@ -660,6 +675,8 @@
* Returns true if the current input value satisfies all constraints (if any)
*
* You can override the `checkValidity` method for custom validations.
*
* @return {boolean} True if the value is valid
*/
checkValidity() {
return this.__inputElement.focusElement.checkValidity() &&
Expand Down

0 comments on commit fc3836b

Please sign in to comment.