This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhax-context-item-menu.html
155 lines (148 loc) · 4.64 KB
/
hax-context-item-menu.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
152
153
154
155
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-tooltip/paper-tooltip.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../neon-animation/web-animations.html">
<link rel="import" href="hax-toolbar-menu.html">
<!--
`hax-context-item-menu`
An icon / button that has support for multiple options via drop down.
@demo demo/index.html
@microcopy - the mental model for this element
- panel - the flyout from left or right side that has elements that can be placed
- button - an item that expresses what interaction you will have with the content.
-->
<dom-module id="hax-context-item-menu">
<template>
<style>
:host {
display: inline-flex;
height: 32px;
box-sizing: border-box;
}
:host ::slotted(*):hover {
background-color: #cccccc;
};
:host ::slotted(*) {
height: 32px;
};
</style>
<hax-toolbar-menu corner="[[corner]]" id="menu" icon="[[icon]]" tooltip="[[label]]" tooltip-direction="[[direction]]" selected="{{selectedValue}}" reset-on-select="[[resetOnSelect]]">
<slot id="items"></slot>
</hax-toolbar-menu>
</template>
<script>
Polymer({
is: 'hax-context-item-menu',
properties: {
/**
* corner
*/
corner: {
type: String,
value: '',
},
/**
* Internal flag to allow blocking the event firing if machine selects tag.
*/
_blockEvent: {
type: Boolean,
value: false,
},
/**
* Should we reset the selection after it is made
*/
resetOnSelect: {
type: Boolean,
value: false,
},
/**
* Value.
*/
selectedValue: {
type: Number,
reflectToAttribute: true,
notify: true,
value: 0,
observer: '_selectedUpdated',
},
/**
* Direction for the tooltip
*/
direction: {
type: String,
value: 'top',
},
/**
* Icon for the button.
*/
icon: {
type: String,
value: "editor:text-fields",
reflectToAttribute: true,
},
/**
* Icon for the button.
*/
iconClass: {
type: String,
value: "black-text",
reflectToAttribute: true,
},
/**
* Label for the button.
*/
label: {
type: String,
value: "editor:text-fields",
reflectToAttribute: true,
},
/**
* Name of the event to bubble up as being tapped.
* This can be used to tell other elements what was
* clicked so it can take action appropriately.
*/
eventName: {
type: String,
value: "button",
reflectToAttribute: true,
}
},
/**
* Notice the selected value has changed.
*/
_selectedUpdated: function (newValue, oldValue) {
if (typeof newValue !== typeof null && typeof oldValue !== typeof undefined && typeof oldValue !== typeof null) {
let children = Polymer.dom(this.$.items).getDistributedNodes();
var item = new Object();
var j = 0;
// check for tag match since we have to filter out text nodes
for (var i = 0, len = children.length; i < len; i++) {
if (children[i].tagName === 'PAPER-ITEM') {
if (j === newValue) {
item = children[i];
len = i;
continue;
}
j++;
}
}
// ensure we have a value; if so, this becomes the event to look for
// also use our flag to ensure machine setting the tag default doesn't
// equate to firing off a selected event.
if (!this._blockEvent && typeof item.attributes !== typeof undefined && typeof item.attributes.value !== typeof undefined && typeof item.attributes.value.value !== typeof undefined) {
// weird but this makes the menu close when we fire up an event
// that indicates something higher should do something. This
// avoids an annoying UX error where the menu stays open for
// no reason.
this.$.menu.hideMenu();
this.fire('hax-context-item-selected', { target: item, eventName: item.attributes.value.value });
}
// we only block 1 time if it's available
if (this._blockEvent) {
this._blockEvent = false;
}
}
},
});
</script>
</dom-module>