This repository was archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhydrofoil-address-bar.ts
89 lines (79 loc) · 2.46 KB
/
hydrofoil-address-bar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { computed, customElement, property } from '@polymer/decorators'
import { IronA11yKeysElement } from '@polymer/iron-a11y-keys/iron-a11y-keys'
import { html, PolymerElement } from '@polymer/polymer'
import '@polymer/iron-a11y-keys/iron-a11y-keys'
import '@polymer/iron-icon/iron-icon'
import '@polymer/iron-icons/av-icons'
import '@polymer/iron-icons/iron-icons'
import '@polymer/paper-icon-button/paper-icon-button'
import '@polymer/paper-input/paper-input'
/**
* A browser-like Material Design URL input.
*
* Comes with button to load the url typed into the input.
*
* @customElement
*/
@customElement('hydrofoil-address-bar')
export default class HydrofoilAddressBar extends PolymerElement {
/**
* The current value
*
* @type {string}
*/
@property({ type: String, notify: true })
public url: string
/**
* A flag indicating that the value is not a valid URL
*
* @type {boolean}
*/
@property({ type: Boolean })
public addressInvalid: boolean
/**
* A flag which controls if the load button is enabled
*
* @type {boolean}
*/
@computed('url', 'addressInvalid')
public get canLoad () {
return this.url && !this.addressInvalid
}
public connectedCallback () {
super.connectedCallback()
const k = (this.$.ironKeys as IronA11yKeysElement)
k.target = this.$.resource
}
private loadOnEnter (e: KeyboardEvent) {
if (e.keyCode === 13) {
this.load()
}
}
private load () {
this.dispatchEvent(new CustomEvent('resource-confirmed'))
}
public static get template () {
return html`
<style>
:host {
display: flex;
--paper-input-container-color: white;
--paper-input-container-input-color: white;
pointer-events: auto !important;
}
paper-input {
flex-grow: 1;
}
</style>
<paper-input main-title id="resource" class="middle" label="address"
pattern="^https?://.*" no-label-float auto-validate
invalid="{{addressInvalid}}"
value="{{url}}"
on-keydown="loadOnEnter">
<iron-icon slot="prefix" icon="icons:language"></iron-icon>
</paper-input>
<iron-a11y-keys id="ironKeys" target="[[urlInput]]" keys="enter" on-keys-pressed="loadOnEnter"></iron-a11y-keys>
<paper-icon-button class="middle" icon="av:play-circle-filled" disabled="[[!canLoad]]"
on-tap="load"></paper-icon-button>`
}
}