-
Notifications
You must be signed in to change notification settings - Fork 6
/
shibui-dropdown-menu.html
90 lines (75 loc) · 2.03 KB
/
shibui-dropdown-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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="shibui-dropdown.html">
<!--
`shibui-dropdown-menu` is a simple and modern dropdown menu inspired by the dropdown on [Heroku](https://heroku.com).
Example:
<shibui-dropdown-menu>
<button slot="trigger">Trigger</button>
<a>Account Settings</a>
<a>Notifications</a>
<a>Sign out</a>
</shibui-dropdown-menu>
@demo demo/shibui-dropdown-menu.html
-->
<dom-module id="shibui-dropdown-menu">
<template strip-whitespace>
<style>
:host {
display: inline-block;
position: relative;
}
.trigger ::slotted(*) {
cursor: pointer;
}
</style>
<div class="trigger">
<slot id="trigger" name="trigger"></slot>
</div>
<shibui-dropdown id="dropdown"
opened="{{opened}}"
alignment="[[alignment]]">
<slot></slot>
</shibui-dropdown>
</template>
<script>
Polymer({
is: 'shibui-dropdown-menu',
properties: {
/**
* Determines whether the dropdown is opened or closed
*/
opened: {
type: Boolean,
value: false,
notify: true,
reflectToAttribute: true
},
/**
* Whether to align the dropdown to the 'right' or 'left' of the trigger
*/
alignment: {
type: String,
value: 'right',
reflectToAttribute: true
}
},
attached: function() {
this._toggle = this._toggle.bind(this);
this._triggerElement.addEventListener('click', this._toggle);
},
detached: function() {
this._triggerElement.removeEventListener('click', this._toggle);
},
/**
* The trigger element provided
*/
get _triggerElement() {
return Polymer.dom(this.$.trigger).getDistributedNodes()[0];
},
_toggle: function() {
this.$.dropdown.toggle();
}
});
</script>
</dom-module>