OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:html'; | |
6 import 'dart:async'; | |
7 import 'package:observatory/src/elements/helpers/tag.dart'; | |
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
9 | |
10 class NavMenuElement extends HtmlElement implements Renderable { | |
11 static final StyleElement _style = () { | |
12 var style = new StyleElement(); | |
13 style.text = '''li.nav-menu_label, li.nav-menu_spacer { | |
14 float: left; | |
15 } | |
16 li.nav-menu_label > a, li.nav-menu_spacer { | |
17 display: block; | |
18 padding: 12px 8px; | |
19 color: White; | |
20 text-decoration: none; | |
21 } | |
22 li.nav-menu_label:hover { | |
23 background: #455; | |
24 } | |
25 li.nav-menu_label > ul { | |
26 display: none; | |
27 position: absolute; | |
28 top: 98%; | |
29 list-style: none; | |
30 margin: 0; | |
31 padding: 0; | |
32 width: auto; | |
33 z-index: 1000; | |
34 font: 400 16px \'Montserrat\', sans-serif; | |
35 color: white; | |
36 background: #567; | |
37 } | |
38 li.nav-menu_label > ul:after { | |
39 content: ""; clear: both; display: block; | |
40 } | |
41 li.nav-menu_label:hover > ul { | |
42 display: block; | |
43 }'''; | |
44 return style; | |
45 }(); | |
46 | |
47 static const tag = const Tag<NavMenuElement>('nav-menu-wrapped'); | |
48 | |
49 RenderingScheduler _r; | |
50 | |
51 Stream<RenderedEvent<NavMenuElement>> get onRendered => _r.onRendered; | |
52 | |
53 String _label; | |
54 String _link; | |
55 bool _last; | |
56 | |
57 String get label => _label; | |
58 String get link => _link; | |
59 bool get last => _last; | |
60 | |
61 set label(String value) => _label = _r.checkAndReact(_label, value); | |
62 set link(String value) => _link = _r.checkAndReact(_link, value); | |
63 set last(bool value) => _last = _r.checkAndReact(_link, value); | |
64 | |
65 factory NavMenuElement(String label, {String link, bool last: false, | |
66 RenderingQueue queue}) { | |
67 assert(label != null); | |
68 assert(last != null); | |
69 NavMenuElement e = document.createElement(tag.name); | |
70 e._r = new RenderingScheduler(e, queue: queue); | |
71 e._label = label; | |
72 e._link = link; | |
73 e._last = last; | |
74 return e; | |
75 } | |
76 | |
77 NavMenuElement.created() : super.created() { createShadowRoot(); } | |
78 | |
79 @override | |
80 void attached() { | |
81 super.attached(); | |
82 _r.enable(); | |
83 } | |
84 | |
85 @override | |
86 void detached() { | |
87 super.detached(); | |
88 _r.disable(notify: true); | |
89 shadowRoot.children = []; | |
90 } | |
91 | |
92 void render() { | |
93 List<Element> children = [ | |
94 _style.clone(true), | |
95 new LIElement() | |
96 ..classes = ['nav-menu_label'] | |
97 ..children = [ | |
98 new AnchorElement(href: link) | |
99 ..text = label, | |
100 new UListElement() | |
101 ..children = [ | |
102 new ContentElement() | |
103 ] | |
104 ] | |
105 ]; | |
106 if (!last) { | |
107 children.add( | |
108 new LIElement() | |
109 ..classes = ['nav-menu_spacer'] | |
110 ..innerHtml = '>' | |
111 ); | |
112 } | |
113 shadowRoot.children = children; | |
114 } | |
115 } | |
OLD | NEW |