-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfullscreen-icon-button.html
151 lines (124 loc) · 3.9 KB
/
fullscreen-icon-button.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="fullscreen-icons.html">
<link rel="import" href="fullscreen-behavior.html">
<!--
A simple Polymer based `paper-icon-button` Web Component that wraps the HTML5 full screen API.
It lets you define which element to display in full screen mode
(via the `target` attribute) and toggle normal/full screen
mode by calling the `toggleFullscreen()` method.
Note that this method MUST be triggered directly by user interaction
(typically in a native `onclick` or Polymer's `on-click` handler).
If no `target` is set, the whole page (more specifically
`document.documentElement`) will be displayed full screen.
The element also provides 2 read-only flags as attribute:
- `fullscreenAvailable`: set to `true` if the browser supports
HTML5's full screen API (Safari on iOS does not).
- `fullscreen`: set to `true` if an element is currently displayed in
full screen mode.
Usage :
<fullscreen-icon-button></fullscreen-icon-button>
With custom icons (presuming the icon-set is correctly imported):
<fullscreen-icon-button icon="icons:thumb-up" icon-exit="icons:thumb-down"></fullscreen-icon-button>
With styling (red background, white icon and ripple) :
<style is="custom-style">
fullscreen-icon-button {
color: white;
--paper-icon-button-ink-color: white;
background-color: red;
border-radius: 50%;
}
</style>
<fullscreen-icon-button></fullscreen-icon-button>
### Styling
You can also use any of the `paper-icon-button`
style mixins and custom properties to style this button.
@element fullscreen-api
@blurb A simple Polymer based Web Component wrapper for the HTML5 full screen API.
@homepage https://github.com/vguillou/fullscreen-api
@demo demo/index.html
@element fullscreen-icon-button
@demo demo/index.html
-->
<dom-module id="fullscreen-icon-button">
<style>
:host {
display: block;
width: 40px;
height: 40px;
}
:host(:not([fullscreen-available])) {
display: none;
}
paper-icon-button {
width: 100%;
height: 100%;
@apply(--)
}
</style>
<template>
<paper-icon-button id="pib" icon="[[_icon]]" alt$="[[alt]]" disabled$="[[disabled]]" noink="[[noink]]" toggles on-tap="toggleFullscreen"></paper-icon-button>
</template>
<script>
Polymer({
is: 'fullscreen-icon-button',
behaviors: [
Polymer.FullscreenBehavior
],
observers: [
'_updateIcon(fullscreen)'
],
properties: {
/**
* Icon prompting the user to go to full screen mode.
* Specifies the icon name or index in the set of icons available in
* the icon's icon set.
*/
icon: {
type: String,
value: undefined,
observer: '_updateIcon'
},
/**
* Icon prompting the user to exit full screen mode.
* Specifies the icon name or index in the set of icons available in
* the icon's icon set.
*/
iconExit: {
type: String,
value: undefined,
observer: '_updateIcon'
},
/**
* Specifies the alternate text for the button, for accessibility.
*/
alt: {
type: String,
observer: "_altChanged"
},
/**
* If true, the user cannot interact with this element.
*/
disabled: {
type: Boolean,
value: false,
notify: true
},
/**
* If true, the element will not produce a ripple effect when
* interacted with via the pointer.
*/
noink: {
type: Boolean
}
},
_updateIcon: function() {
this._icon = this.fullscreen ? this.iconExit || 'fullscreen:fullscreen-exit' :
this.icon || 'fullscreen:fullscreen';
},
_altChanged: function(newValue, oldValue) {
this.$.pib._altChanged(newValue, oldValue);
}
});
</script>
</dom-module>