Skip to content

Commit be0d44d

Browse files
committed
[css-shadow-parts-1] Add examples for part and partmap
1 parent f16f1b5 commit be0d44d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

css-shadow-parts-1/Overview.bs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,21 @@ Note: It's okay to give a part multiple names.
184184
The "part name" should be considered similar to a class,
185185
not an id or tagname.
186186

187+
<pre class="example">
188+
&lt;style&gt;
189+
c-e<b>::part(textspan)</b> { color: red; }
190+
&lt;/style&gt;
191+
192+
&lt;template id="c-e-template"&gt;
193+
&lt;span <b>part="textspan"</b>&gt;This text will be red&lt;/span&gt;
194+
&lt;/template&gt;
195+
&lt;c-e&gt;&lt;/c-e&gt;
196+
&lt;script&gt;
197+
// Add template as custom elment c-e
198+
...
199+
&lt;/script&gt;
200+
</pre>
201+
187202
Forwarding a Shadow Element: the <{html-global/partmap}> attribute {#partmap-attr}
188203
----------------------------------------------------------------------------------
189204
Any element in a shadow tree can have a <dfn element-attr for=html-global>partmap</dfn> attribute.
@@ -214,6 +229,35 @@ Issue: Decide whether we use "outer => inner" or vice-versa.
214229
Issue: Decide whether to allow "ident1 => ident2 ident3 ..."
215230
as shorthand for "ident1 => ident2, ident1 => ident3, ...".
216231

232+
<pre class="example">
233+
&lt;style&gt;
234+
c-e<b>::part(textspan)</b> { color: red; }
235+
&lt;/style&gt;
236+
237+
&lt;template id="c-e-outer-template"&gt;
238+
&lt;c-e-inner <b>partmap="innerspan textspan"</b>&gt;&lt;/c-e-inner&gt;
239+
&lt;/template&gt;
240+
241+
&lt;template id="c-e-inner-template"&gt;
242+
&lt;span <b>part="innerspan"</b>&gt;
243+
This text will be red because the containing shadow
244+
host forwards <b>innerspan</b> to the document as "textspan"
245+
and the document style matches it.
246+
&lt;/span&gt;
247+
&lt;span <b>part="textspan"</b>&gt;
248+
This text will not be red because <b>textspan</b> in the document style
249+
cannot match against the part inside the inner custom element
250+
if it is not forwarded.
251+
&lt;/span&gt;
252+
&lt;/template&gt;
253+
254+
&lt;c-e&gt;&lt;/c-e&gt;
255+
&lt;script&gt;
256+
// Add template as custom elments c-e-inner, c-e-outer
257+
...
258+
&lt;/script&gt;
259+
</pre>
260+
217261
Exposing More Widely: the <{html-global/theme}> attribute {#theme-attr}
218262
-----------------------------------------------------------------------
219263

0 commit comments

Comments
 (0)