-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorph-radio.js
84 lines (74 loc) · 2.42 KB
/
morph-radio.js
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
import { html } from 'lit-element';
import { Radio } from '@material/mwc-radio/mwc-radio.js';
// import { style } from '@material/mwc-radio/mwc-radio-css.js';
import { ripple } from '@material/mwc-ripple/ripple-directive.js';
import { morphRadioAndroidStyle } from './morph-radio-android-css.js';
import { morphRadioIosStyle } from './morph-radio-ios-css.js';
import { getPlatform } from '@moduware/lit-utils';
/**
* `morph-radio`
* A radio button that looks native on IOS or Android platform and devices
*
* @customElement
* @polymer
* @extends HTMLElement
* @demo demo/index.html
*/
class MorphRadio extends Radio {
/**
* Instance of the element is created/upgraded. Useful for initializing
* state, set up event listeners, create shadow dom.
* @constructor
*/
constructor() {
super();
this.platform = getPlatform();
}
renderMorphRadioAndroidStyle() {
return morphRadioAndroidStyle;
}
renderIosMorphStyle() {
return morphRadioIosStyle;
}
renderMorphRadioAndroid() {
const morphRadioAndroid = html`
${this.renderMorphRadioAndroidStyle()}
<div class="mdc-radio" .ripple="${ripple()}">
<input class="mdc-radio__native-control" type="radio" name="${this.name}" .checked="${this.checked}" .value="${this.value}"
@change="${this._changeHandler}" @focus="${this._focusHandler}" @click="${this._clickHandler}">
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
`;
return morphRadioAndroid;
}
renderMorphRadioIos() {
const morphRadioIos = html`
${this.renderIosMorphStyle()}
<span class="mdc-radio">
<label class="radio">
<input class="mdc-radio__native-control" type="radio" name="${this.name}" .checked="${this.checked}" .value="${this.value}"
@change="${this._changeHandler}" @focus="${this._focusHandler}" @click="${this._clickHandler}">
<span class="icon"></span>
</label>
</span>
`;
return morphRadioIos;
}
render() {
return html`
<!-- this will render 2 different template either IOS or Android -->
${this.platform == 'android' ? this.renderMorphRadioAndroid() : this.renderMorphRadioIos()}
`;
}
static get properties() {
return {
name: String,
value: String,
platform: String
};
}
}
window.customElements.define('morph-radio', MorphRadio);