2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 The `core-style` element helps manage styling inside other elements and can
12 be used to make themes. The `core-style` element can be either a producer
13 or consumer of styling. If it has its `id` property set, it's a producer.
14 Elements that are producers should include css styling as their text content.
15 If a `core-style` has its `ref` property set, it's a consumer. A `core-style`
16 typically sets its `ref` property to the value of the `id` property of the
17 `core-style` it wants to use. This allows a single producer to be used in
18 multiple places, for example, in many different elements.
20 It's common to place `core-style` producer elements inside HTMLImports.
21 Remote stylesheets should be included this way, the @import css mechanism is
22 not currently supported.
24 Here's a basic example:
26 <polymer-element name="x-test" noscript>
28 <core-style ref="x-test"></core-style>
33 The `x-test` element above will be styled by any `core-style` elements that have
34 `id` set to `x-test`. These `core-style` producers are separate from the element
35 definition, allowing a user of the element to style it independent of the author's
38 <core-style id="x-test">
40 backgound-color: steelblue;
44 The content of the `x-test` `core-style` producer gets included inside the
45 shadowRoot of the `x-test` element. If the content of the `x-test` producer
46 `core-style` changes, all consumers of it are automatically kept in sync. This
47 allows updating styling on the fly.
49 The `core-style` element also supports bindings and it is the producer
50 `core-style` element is the model for its content. Here's an example:
52 <core-style id="x-test">
54 background-color: {{myColor}};
58 document._currentScript.ownerDocument.getElementById('x-test').myColor = 'orange';
61 Finally, to facilitate sharing data between `core-style` elements, all
62 `core-style` elements have a `g` property which is set to the global
63 `CoreStyle.g`. Here's an example:
65 <core-style id="x-test">
67 background-color: {{g.myColor}};
71 CoreStyle.g.myColor = 'tomato';
74 Finally, one `core-style` can be nested inside another. The `core-style`
75 element has a `list` property which is a map of all the `core-style` producers.
76 A `core-style` producer's content is available via its `cssText` property.
77 Putting this together:
79 <core-style id="common">
81 font-family: sans-serif;
85 <core-style id="x-test">
86 {{list.common.cssText}}
89 background-color: {{g.myColor}};
94 @group Polymer Core Elements
99 <link rel="import" href="../polymer/polymer.html">
101 <polymer-element name="core-style" hidden assetpath="">
104 <script src="core-style-extracted.js"></script>