UNPKG

@polymer/iron-pages

Version:

Organizes a set of pages and shows one at a time

158 lines (150 loc) 5.14 kB
<!doctype html> <!-- @license Copyright (c) 2015 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.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 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.txt --> <html> <head> <title>iron-pages demo</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> <script src="https://unpkg.com/@webcomponents/webcomponentsjs@^2.0.0/webcomponents-loader.js"></script> <script type="module"> import '@polymer/paper-styles/color.js'; import '@polymer/iron-demo-helpers/demo-snippet.js'; import '@polymer/iron-demo-helpers/demo-pages-shared-styles.js'; import '../iron-pages.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js'; const template = html` <custom-style> <style is="custom-style" include="demo-pages-shared-styles"> code { background-color: #eee; color: #222; border-radius: 2px; padding: 2px; } </style> </custom-style> `; document.body.appendChild(template.content); </script> </head> <body unresolved> <div class="vertical-section-container centered"> <h3>iron-pages shows only one of its children at a time.</h3> <demo-snippet> <template> <custom-style> <style is="custom-style"> iron-pages { width: 100%; height: 200px; font-size: 50px; color: white; text-align: center; } iron-pages div { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; } iron-pages div:nth-child(1) { background-color: var(--google-blue-500); } iron-pages div:nth-child(2) { background-color: var(--google-red-500); } iron-pages div:nth-child(3) { background-color: var(--google-green-500); } </style> </custom-style> <p>Click on a page to advance to the next one.</p> <iron-pages selected="0"> <div>One</div> <div>Two</div> <div>Three</div> </iron-pages> <script> var pages = document.querySelector('iron-pages'); pages.addEventListener('click', function(e) { pages.selectNext(); }); </script> </template> </demo-snippet> </div> <div class="vertical-section-container centered"> <h3> <code>&lt;iron-pages&gt;</code> inherits functionality (for example, <code>attr-for-selected</code>) from <code>IronSelectableBehavior</code>. </h3> <demo-snippet> <template> <custom-style> <style is="custom-style"> input { width: 100%; box-sizing: border-box; font-size: 1.5em; } iron-pages { width: 100%; height: 200px; font-size: 3em; color: white; text-align: center; } iron-pages div { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 4px; box-sizing: border-box; } iron-pages div:nth-child(1) { background-color: var(--google-blue-500); } iron-pages div:nth-child(2) { background-color: var(--google-red-500); } iron-pages div:nth-child(3) { background-color: var(--google-green-500); } [page-name=fallback] { background-color: gray; font-size: 0.5em; } </style> </custom-style> <dom-bind> <template is="dom-bind"> <input value="{{pageName::input}}" placeholder="Type a page name here."> <iron-pages selected="[[pageName]]" attr-for-selected="page-name" fallback-selection="fallback"> <div page-name="page-1">One</div> <div page-name="page-2">Two</div> <div page-name="page-3">Three</div> <div page-name="fallback"> Change pages by typing 'page-1', 'page-2', or 'page-3' in the input above. </div> </iron-pages> </template> </dom-bind> </template> </demo-snippet> </div> </body> </html>