Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 43cef6c

Browse files
authored
feat(toolbar): Implement flexible and waterfall toolbar. (#448) (#499)
1 parent f8b1e81 commit 43cef6c

20 files changed

+2147
-52
lines changed

demos/images/4-3.jpg

56.9 KB
Loading
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright 2016 Google Inc. All rights reserved.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
https://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License
13+
-->
14+
<html>
15+
<head>
16+
<meta charset="utf-8">
17+
<title>MDC Toolbar Demo</title>
18+
<meta name="viewport" content="width=device-width, initial-scale=1">
19+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
20+
<style>
21+
.mdc-toolbar-demo {
22+
margin: 0px;
23+
}
24+
.mdc-toolbar__row:first-child::after {
25+
background-image: url("../images/4-3.jpg");
26+
background-size: cover;
27+
background-position: center;
28+
}
29+
.demo-paragraph {
30+
margin: 0px;
31+
padding: 20px 28px;
32+
}
33+
.material-icons {
34+
text-decoration: none;
35+
cursor: pointer;
36+
padding-right: 8px;
37+
color: white;
38+
}
39+
[dir='rtl'] .material-icons {
40+
padding-left: 8px;
41+
}
42+
@media (max-width: 599px) {
43+
.demo-paragraph {
44+
padding: 16px;
45+
}
46+
}
47+
footer {
48+
position: fixed;
49+
bottom: 20px;
50+
width: 100%;
51+
text-align: center;
52+
color: red;
53+
background-color: rgba(0, 0, 0, 0.8);
54+
}
55+
</style>
56+
<script src="../assets/material-components-web.css.js" charset="utf-8"></script>
57+
</head>
58+
<body class="mdc-typography mdc-toolbar-demo">
59+
<header class="mdc-toolbar mdc-toolbar--flexible mdc-toolbar--flexible-default-behavior">
60+
<div class="mdc-toolbar__row">
61+
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
62+
<a href="#" class="material-icons">menu</a>
63+
<span class="mdc-toolbar__title">Title</span>
64+
</section>
65+
<section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
66+
<a href="#" class="material-icons" aria-label="Download" alt="Download">file_download</a>
67+
<a href="#" class="material-icons" aria-label="Print this page" alt="Print this page">print</a>
68+
<a href="#" class="material-icons" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
69+
</section>
70+
</div>
71+
</header>
72+
<main>
73+
<p class="demo-paragraph">
74+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
75+
</p>
76+
<p class="demo-paragraph">
77+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
78+
</p>
79+
<p class="demo-paragraph">
80+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
81+
</p>
82+
</main>
83+
<footer>
84+
<span>Flexible Expansion Ratio: <span id="ratio">0</span></span>
85+
</footer>
86+
<script src="../assets/material-components-web.js" charset="utf-8"></script>
87+
<script type="text/javascript">
88+
(function() {
89+
var pollId = 0;
90+
pollId = setInterval(function() {
91+
var pos = getComputedStyle(document.querySelector('.mdc-toolbar')).position;
92+
if (pos === 'fixed' || pos === 'relative') {
93+
init();
94+
clearInterval(pollId);
95+
}
96+
}, 250);
97+
function init() {
98+
var ratioSpan = document.querySelector("#ratio");
99+
var toolbar = mdc.toolbar.MDCToolbar.attachTo(document.querySelector('.mdc-toolbar'));
100+
toolbar.listen('MDCToolbar:change', function(evt) {
101+
var flexibleExpansionRatio = evt.detail.flexibleExpansionRatio;
102+
ratioSpan.innerHTML = flexibleExpansionRatio.toFixed(2);
103+
});
104+
}
105+
})();
106+
</script>
107+
</body>
108+
</html>

demos/toolbar/default-toolbar.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
text-decoration: none;
3030
cursor: pointer;
3131
padding-right: 8px;
32+
color: white;
3233
}
3334
[dir='rtl'] .material-icons {
3435
padding-left: 8px;
@@ -45,13 +46,13 @@
4546
<header class="mdc-toolbar">
4647
<div class="mdc-toolbar__row">
4748
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
48-
<a class="material-icons">menu</a>
49+
<a href="#" class="material-icons">menu</a>
4950
<span class="mdc-toolbar__title">Title</span>
5051
</section>
5152
<section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
52-
<a class="material-icons" aria-label="Download" alt="Download">file_download</a>
53-
<a class="material-icons" aria-label="Print this page" alt="Print this page">print</a>
54-
<a class="material-icons" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
53+
<a href="#" class="material-icons" aria-label="Download" alt="Download">file_download</a>
54+
<a href="#" class="material-icons" aria-label="Print this page" alt="Print this page">print</a>
55+
<a href="#" class="material-icons" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
5556
</section>
5657
</div>
5758
</header>
@@ -62,6 +63,9 @@
6263
<p class="demo-paragraph">
6364
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
6465
</p>
66+
<p class="demo-paragraph">
67+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
68+
</p>
6569
</main>
6670
</body>
6771
</html>

demos/toolbar/fixed-top-toolbar.html renamed to demos/toolbar/fixed-toolbar.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
text-decoration: none;
3030
cursor: pointer;
3131
padding: 0px 8px 0px 0px;
32+
color: white;
3233
}
3334
[dir='rtl'] .material-icons {
3435
padding-left: 8px;
@@ -45,13 +46,13 @@
4546
<header class="mdc-toolbar mdc-toolbar--fixed">
4647
<div class="mdc-toolbar__row">
4748
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
48-
<a class="material-icons">menu</a>
49+
<a href="#" class="material-icons">menu</a>
4950
<span class="mdc-toolbar__title">Title</span>
5051
</section>
5152
<section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
52-
<a class="material-icons" aria-label="Download" alt="Download">file_download</a>
53-
<a class="material-icons" aria-label="Print this page" alt="Print this page">print</a>
54-
<a class="material-icons" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
53+
<a href="#" class="material-icons" aria-label="Download" alt="Download">file_download</a>
54+
<a href="#" class="material-icons" aria-label="Print this page" alt="Print this page">print</a>
55+
<a href="#" class="material-icons" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
5556
</section>
5657
</div>
5758
</header>
@@ -64,6 +65,9 @@
6465
<p class="demo-paragraph">
6566
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
6667
</p>
68+
<p class="demo-paragraph">
69+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
70+
</p>
6771
</div>
6872
</main>
6973
</body>

demos/toolbar/index.html

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,30 @@
3333
<h2>Normal Toolbar <button type="button" onclick="toggleRTL(0)">Toggle RTL</button></h2>
3434
<p><a href="./default-toolbar.html" target="_blank">View in separate window</a></p>
3535
<iframe class="demo-container" src="./default-toolbar.html"></iframe>
36-
<h2>Fixed Toolbar <button type="button" onclick="toggleRTL(1)">Toggle RTL</button></h2>
37-
<p><a href="./fixed-top-toolbar.html" target="_blank">View in separate window</a></p>
38-
<iframe class="demo-container" src="./fixed-top-toolbar.html"></iframe>
36+
37+
<h2>Fixed Toolbar<button type="button" onclick="toggleRTL(1)">Toggle RTL</button></h2>
38+
<p><a href="./fixed-toolbar.html" target="_blank">View in separate window</a></p>
39+
<iframe class="demo-container" src="./fixed-toolbar.html"></iframe>
40+
41+
<h2>Waterfall Toolbar<button type="button" onclick="toggleRTL(2)">Toggle RTL</button></h2>
42+
<p><a href="./waterfall-toolbar.html" target="_blank">View in separate window</a></p>
43+
<iframe class="demo-container" src="./waterfall-toolbar.html"></iframe>
44+
45+
<h2>Default Flexible Toolbar<button type="button" onclick="toggleRTL(3)">Toggle RTL</button></h2>
46+
<p><a href="./default-flexible-toolbar.html" target="_blank">View in separate window</a></p>
47+
<iframe class="demo-container" src="./default-flexible-toolbar.html"></iframe>
48+
49+
<h2>Waterfall Flexible Toolbar<button type="button" onclick="toggleRTL(4)">Toggle RTL</button></h2>
50+
<p><a href="./waterfall-flexible-toolbar.html" target="_blank">View in separate window</a></p>
51+
<iframe class="demo-container" src="./waterfall-flexible-toolbar.html"></iframe>
52+
53+
<h2>Waterfall Toolbar Fix Last Row<button type="button" onclick="toggleRTL(5)">Toggle RTL</button></h2>
54+
<p><a href="./waterfall-toolbar-fix-last-row.html" target="_blank">View in separate window</a></p>
55+
<iframe class="demo-container" src="./waterfall-toolbar-fix-last-row.html"></iframe>
56+
57+
<h2>Waterfall Flexible Toolbar with Custom Style<button type="button" onclick="toggleRTL(6)">Toggle RTL</button></h2>
58+
<p><a href="./waterfall-flexible-toolbar-custom-style.html" target="_blank">View in separate window</a></p>
59+
<iframe class="demo-container" src="./waterfall-flexible-toolbar-custom-style.html"></iframe>
3960
</main>
4061
<script>
4162
function toggleRTL(iframe_number) {
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright 2016 Google Inc. All rights reserved.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
https://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License
13+
-->
14+
<html>
15+
<head>
16+
<meta charset="utf-8">
17+
<title>MDC Toolbar Demo</title>
18+
<meta name="viewport" content="width=device-width, initial-scale=1">
19+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
20+
<style>
21+
.mdc-toolbar-demo {
22+
margin: 0px;
23+
}
24+
.demo-paragraph {
25+
margin: 0px;
26+
padding: 20px 28px;
27+
}
28+
.material-icons {
29+
text-decoration: none;
30+
cursor: pointer;
31+
padding: 0px 8px 0px 0px;
32+
color: white;
33+
}
34+
[dir='rtl'] .material-icons {
35+
padding-left: 8px;
36+
}
37+
@media (max-width: 599px) {
38+
.demo-paragraph {
39+
padding: 16px;
40+
}
41+
}
42+
footer {
43+
position: fixed;
44+
bottom: 20px;
45+
width: 100%;
46+
text-align: center;
47+
color: red;
48+
background-color: rgba(0, 0, 0, 0.8);
49+
}
50+
#my-flexible-header {
51+
--mdc-toolbar-ratio-to-extend-flexible: 2;
52+
background-color: rgb(255, 64, 129);
53+
}
54+
#my-flexible-header .mdc-toolbar__title {
55+
font-size: 5rem;
56+
transform: translateY(-30px);
57+
}
58+
</style>
59+
<script src="../assets/material-components-web.css.js" charset="utf-8"></script>
60+
</head>
61+
<body class="mdc-typography mdc-toolbar-demo">
62+
<header class="mdc-toolbar mdc-toolbar--fixed mdc-toolbar--waterfall mdc-toolbar--flexible" id="my-flexible-header">
63+
<div class="mdc-toolbar__row">
64+
<section class="mdc-toolbar__section mdc-toolbar__section--align-center">
65+
<span class="mdc-toolbar__title">Hey!</span>
66+
</section>
67+
</div>
68+
</header>
69+
<main>
70+
<div class="mdc-toolbar-fixed-adjust">
71+
<p class="demo-paragraph">
72+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
73+
</p>
74+
<p class="demo-paragraph">
75+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
76+
</p>
77+
<p class="demo-paragraph">
78+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
79+
</p>
80+
</div>
81+
</main>
82+
<footer>
83+
<span>Flexible Expansion Ratio: <span id="ratio">0</span></span>
84+
</footer>
85+
<script src="../assets/material-components-web.js" charset="utf-8"></script>
86+
<script type="text/javascript">
87+
(function() {
88+
var pollId = 0;
89+
pollId = setInterval(function() {
90+
var pos = getComputedStyle(document.querySelector('.mdc-toolbar')).position;
91+
if (pos === 'fixed' || pos === 'relative') {
92+
init();
93+
clearInterval(pollId);
94+
}
95+
}, 250);
96+
function init() {
97+
var initialR = 255;
98+
var initialG = 64;
99+
var initialB = 129;
100+
var endR = 63;
101+
var endG = 81;
102+
var endB = 181;
103+
var initialFontSize = 5;
104+
var initialTransY = -30;
105+
var endFontSize = 1.25;
106+
var endTransY = 0;
107+
var ratioSpan = document.querySelector("#ratio");
108+
var myFlexibleHeader = document.querySelector("#my-flexible-header");
109+
var myFlexibleHeaderTitle = document.querySelector("#my-flexible-header .mdc-toolbar__title");
110+
var toolbar = mdc.toolbar.MDCToolbar.attachTo(document.querySelector('.mdc-toolbar'));
111+
toolbar.listen('MDCToolbar:change', function(evt) {
112+
var flexibleExpansionRatio = evt.detail.flexibleExpansionRatio;
113+
114+
var currentR = Math.round(endR - (endR - initialR) * flexibleExpansionRatio);
115+
var currentG = Math.round(endG - (endG - initialG) * flexibleExpansionRatio);
116+
var currentB = Math.round(endB - (endB - initialB) * flexibleExpansionRatio);
117+
myFlexibleHeader.style.backgroundColor = `rgb(${currentR}, ${currentG}, ${currentB})`;
118+
119+
if (flexibleExpansionRatio > 0.5) {
120+
var currentTransY = endTransY - (endTransY - initialTransY) * (flexibleExpansionRatio - 0.5) * 2;
121+
myFlexibleHeaderTitle.style.transform = `translateY(${currentTransY}px)`;
122+
} else {
123+
var currentFontsize = endFontSize - (endFontSize - initialFontSize) * flexibleExpansionRatio * 2;
124+
myFlexibleHeaderTitle.style.fontSize = `${currentFontsize}rem`;
125+
}
126+
127+
ratioSpan.innerHTML = flexibleExpansionRatio.toFixed(2);
128+
});
129+
toolbar.fixedAdjustElement = document.querySelector('.mdc-toolbar-fixed-adjust');
130+
}
131+
})();
132+
</script>
133+
</body>
134+
</html>

0 commit comments

Comments
 (0)