1 |
|
2 |
|
3 |
|
4 | This README is automatically generated from the comments in these files:
|
5 | demo-snippet.html url-bar.html
|
6 |
|
7 | Edit those files, and our readme bot will duplicate them over here!
|
8 | Edit this file, and the bot will squash your changes :)
|
9 |
|
10 | The bot does some handling of markdown. Please file a bug if it does the wrong
|
11 | thing! https://github.com/PolymerLabs/tedium/issues
|
12 |
|
13 | -->
|
14 |
|
15 | [](https://www.npmjs.com/package/@polymer/iron-demo-helpers)
|
16 | [](https://travis-ci.org/PolymerElements/iron-demo-helpers)
|
17 | [](https://webcomponents.org/element/@polymer/iron-demo-helpers)
|
18 |
|
19 | ## <demo-snippet>
|
20 |
|
21 | `demo-snippet` is a helper element that displays the source of a code snippet and
|
22 | its rendered demo. It can be used for both native elements and
|
23 | Polymer elements.
|
24 |
|
25 | See: [Documentation](https://www.webcomponents.org/element/@polymer/iron-demo-helpers),
|
26 | [Demo](https://www.webcomponents.org/element/@polymer/iron-demo-helpers/demo/demo/index.html).
|
27 |
|
28 | ## Usage
|
29 |
|
30 | ### Installation
|
31 | ```
|
32 | npm install --save @polymer/iron-demo-helpers
|
33 | ```
|
34 |
|
35 | ### In an html file
|
36 | ```html
|
37 | <html>
|
38 | <head>
|
39 | <script type="module">
|
40 | import '@polymer/iron-demo-helpers/demo-snippet.js';
|
41 | import '@polymer/paper-checkbox/paper-checkbox.js';
|
42 | </script>
|
43 | </head>
|
44 | <body>
|
45 | <demo-snippet>
|
46 | <template>
|
47 | <input type="date">
|
48 | <paper-checkbox>Checkbox</paper-checkbox>
|
49 | </template>
|
50 | </demo-snippet>
|
51 | </body>
|
52 | </html>
|
53 | ```
|
54 |
|
55 | ### In a Polymer 3 element
|
56 | ```js
|
57 | import {PolymerElement, html} from '@polymer/polymer';
|
58 | import '@polymer/iron-demo-helpers/demo-snippet.js';
|
59 | import '@polymer/paper-checkbox/paper-checkbox.js';
|
60 |
|
61 | class SampleElement extends PolymerElement {
|
62 | static get template() {
|
63 | return html`
|
64 | <demo-snippet>
|
65 | <template>
|
66 | <input type="date">
|
67 | <paper-checkbox>Checkbox</paper-checkbox>
|
68 | </template>
|
69 | </demo-snippet>
|
70 | `;
|
71 | }
|
72 | }
|
73 | customElements.define('sample-element', SampleElement);
|
74 | ```
|
75 |
|
76 | ## <url-bar>
|
77 |
|
78 | `url-bar` is a helper element that displays a simple read-only URL bar if
|
79 | and only if the page is in an iframe. In this way we can demo elements that
|
80 | deal with the URL in our iframe-based demo environments.
|
81 |
|
82 | If the page is not in an iframe, the url-bar element is not displayed.
|
83 |
|
84 | ## Contributing
|
85 | If you want to send a PR to this element, here are
|
86 | the instructions for running the tests and demo locally:
|
87 |
|
88 | ### Installation
|
89 | ```sh
|
90 | git clone https://github.com/PolymerElements/iron-demo-helpers
|
91 | cd iron-demo-helpers
|
92 | npm install
|
93 | npm install -g polymer-cli
|
94 | ```
|
95 |
|
96 | ### Running the demo locally
|
97 | ```sh
|
98 | polymer serve --npm
|
99 | open http://127.0.0.1:<port>/demo/
|
100 | ```
|
101 |
|
102 | ### Running the tests
|
103 | ```sh
|
104 | polymer test --npm
|
105 | ```
|
106 |
|
107 | ## Known Issues
|
108 | If you add a `script type="module"` inside a `demo-snippet`, the demo will
|
109 | not be functional on non-module browsers (like IE11). If you need to
|
110 | use a `script type="module"` and want to display its code in the `demo-snippet`,
|
111 | a possible workaround is to duplicate the contents of the script outside of the
|
112 | `demo-snippet` -- that way `polymer serve` (or whatever solution you're using to
|
113 | ES5-ify the code) will convert the main document `module` to UMD, but will leave the
|
114 | displayed code untouched. Here is an example:
|
115 |
|
116 | ```html
|
117 | <body>
|
118 | <demo-snippet>
|
119 | <template>
|
120 | ...
|
121 | <script type="module">
|
122 | import {SomeExport} from '../foo.js';
|
123 | SomeExport.aFunction();
|
124 | </script>
|
125 | </template>
|
126 | </demo-snippet>
|
127 |
|
128 | <!-- Hack: on non-module browsers the demo-snippet script doesn't
|
129 | do anything, so add the content here again to make sure the demo works -->
|
130 | <script type="module">
|
131 | import {SomeExport} from '../foo.js';
|
132 | SomeExport.aFunction();
|
133 | </script>
|
134 | </body>
|
135 | ```
|