This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcore-submenu.html
126 lines (94 loc) · 3.39 KB
/
core-submenu.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
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->
<!--
Use to create nested menus inside of `core-menu` elements.
<core-menu selected="0">
<core-submenu icon="settings" label="Topics">
<core-item label="Topic 1"></core-item>
<core-item label="Topic 2"></core-item>
</core-submenu>
<core-submenu icon="settings" label="Favorites">
<core-item label="Favorite 1"></core-item>
<core-item label="Favorite 2"></core-item>
<core-item label="Favorite 3"></core-item>
</core-submenu>
</core-menu>
There is a margin set on the submenu to indent the items.
You can override the margin by doing:
core-submenu::shadow #submenu {
margin-left: 20px;
}
To style the item for the submenu, do something like this:
core-submenu::shadow > #submenuItem {
color: blue;
}
To style all the `core-item`s in the light DOM:
polyfill-next-selector { content: 'core-submenu > #submenu > core-item'; }
core-submenu > core-item {
color: red;
}
The above will style `Topic1` and `Topic2` to have font color red.
<core-submenu icon="settings" label="Topics">
<core-item label="Topic1"></core-item>
<core-item label="Topic2"></core-item>
</core-submenu>
@group Polymer Core Elements
@element core-submenu
@extends core-item
-->
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-collapse/core-collapse.html">
<polymer-element name="core-submenu" attributes="selected selectedItem selectedAttribute label icon src valueattr">
<template>
<link rel="stylesheet" href="core-submenu.css">
<core-item id="submenuItem" src="{{src}}" label="{{label}}" icon="{{icon}}" class="{{ {'core-selected' : active} | tokenList}}" on-tap="{{activate}}">
<content select=".item-content"></content>
</core-item>
<core-menu id="submenu" selected="{{selected}}" selectedItem="{{selectedItem}}" selectedAttribute="{{selectedAttribute}}" valueattr="{{valueattr}}">
<content></content>
</core-menu>
<core-collapse target="{{$.submenu}}" opened="{{opened}}"></core-collapse>
</template>
<script>
Polymer('core-submenu', {
publish: {
active: {value: false, reflect: true}
},
opened: false,
get items() {
return this.$.submenu.items;
},
hasItems: function() {
return !!this.items.length;
},
unselectAllItems: function() {
this.$.submenu.selected = null;
this.$.submenu.clearSelection();
},
activeChanged: function() {
if (this.hasItems()) {
this.opened = this.active;
}
if (!this.active) {
this.unselectAllItems();
}
},
toggle: function() {
this.opened = !this.opened;
},
activate: function() {
if (this.hasItems() && this.active) {
this.toggle();
this.unselectAllItems();
}
}
});
</script>
</polymer-element>