1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * 'cr-settings-section' shows a paper material themed section with a header
8 * which shows its page title and icon.
12 * <cr-settings-section page-title="[[pageTitle]]" icon="[[icon]]">
13 * <!-- Insert your section controls here -->
14 * </cr-settings-section>
16 * @group Chrome Settings Elements
17 * @element cr-settings-section
20 is
: 'cr-settings-section',
23 Polymer
.NeonAnimationRunnerBehavior
,
28 * The current active route.
32 observer
: 'currentRouteChanged_',
36 * The section is expanded to a full-page view when this property matches
37 * currentRoute.section.
44 * Title for the page header and navigation menu.
49 * Name of the 'iron-icon' to show.
54 * Container that determines the sizing of expanded sections.
65 name
: 'expand-card-animation',
69 name
: 'collapse-card-animation',
81 currentRouteChanged_: function() {
82 var expanded
= this.currentRoute
.section
== this.section
;
84 if (expanded
== this.expanded_
)
87 this.expanded_
= expanded
;
88 this.playAnimation(expanded
? 'expand' : 'collapse');
93 is
: 'expand-card-animation',
96 Polymer
.NeonAnimationBehavior
99 configure: function(config
) {
100 var node
= config
.node
;
101 var containerRect
= node
.expandContainer
.getBoundingClientRect();
102 var nodeRect
= node
.getBoundingClientRect();
104 // Save section's original height.
105 node
.unexpandedHeight
= nodeRect
.height
;
107 var headerHeight
= node
.$.header
.getBoundingClientRect().height
;
108 var newTop
= containerRect
.top
- headerHeight
;
109 var newHeight
= containerRect
.height
+ headerHeight
;
111 node
.style
.position
= 'fixed';
112 node
.style
.zIndex
= '1';
114 this._effect
= new KeyframeEffect(node
, [
115 {'top': nodeRect
.top
+ 'px', 'height': nodeRect
.height
+ 'px'},
116 {'top': newTop
+ 'px', 'height': newHeight
+ 'px'},
117 ], this.timingFromConfig(config
));
121 complete: function(config
) {
122 config
.node
.style
.position
= 'absolute';
123 config
.node
.style
.top
=
124 -config
.node
.$.header
.getBoundingClientRect().height
+ 'px';
125 config
.node
.style
.bottom
= 0;
130 is
: 'collapse-card-animation',
133 Polymer
.NeonAnimationBehavior
136 configure: function(config
) {
137 var node
= config
.node
;
139 var oldRect
= node
.getBoundingClientRect();
141 // Temporarily set position to static to determine new height.
142 node
.style
.position
= '';
143 var newTop
= node
.getBoundingClientRect().top
;
145 // TODO(tommycli): This value is undefined when the user navigates to a
146 // subpage directly by URL instead of from the settings root. Find a better
147 // method than using 200 as a dummy height.
148 var newHeight
= node
.unexpandedHeight
|| 200;
150 node
.style
.position
= 'fixed';
152 this._effect
= new KeyframeEffect(node
, [
153 {'top': oldRect
.top
+ 'px', 'height': oldRect
.height
+ 'px'},
154 {'top': newTop
+ 'px', 'height': newHeight
+ 'px'},
155 ], this.timingFromConfig(config
));
159 complete: function(config
) {
160 config
.node
.style
.position
= '';
161 config
.node
.style
.zIndex
= '0';