mirror of
https://github.com/Polymer/polymer.git
synced 2026-08-19 01:14:44 -05:00
111 lines
3.3 KiB
HTML
111 lines
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
Copyright 2013 The Toolkitchen Authors. All rights reserved.
|
|
Use of this source code is governed by a BSD-style
|
|
license that can be found in the LICENSE file.
|
|
-->
|
|
<html>
|
|
<head>
|
|
<meta name="viewport" content="initial-scale=1.0">
|
|
<title>Using @host styling</title>
|
|
<script src="../../../toolkit.js"></script>
|
|
<script src="../../../tools/test/htmltest.js"></script>
|
|
<script src="../../../node_modules/chai/chai.js"></script>
|
|
</head>
|
|
<body>
|
|
<h4>Expected: red background</h4>
|
|
<x-foo></x-foo>
|
|
|
|
<h4>Expected: red background with white text</h4>
|
|
<x-bar></x-bar>
|
|
|
|
<h4>Expected: red background with black text and orange border</h4>
|
|
<x-zot></x-zot>
|
|
|
|
<h4>Expected: red background with black text and orange border and 20px padding</h4>
|
|
<x-zim></x-zim>
|
|
|
|
<script>
|
|
document.addEventListener('WebComponentsReady', function() {
|
|
var foo = document.querySelector('x-foo');
|
|
chai.assert.equal(getComputedStyle(foo).backgroundColor, 'rgb(255, 0, 0)',
|
|
'@host styles are applied');
|
|
|
|
var bar = document.querySelector('x-bar');
|
|
var barStyle = getComputedStyle(bar);
|
|
chai.assert.equal(barStyle.backgroundColor, 'rgb(255, 0, 0)',
|
|
'@host styles are inherited');
|
|
chai.assert.equal(barStyle.color, 'rgb(255, 255, 255)',
|
|
'@host styles are combined with inherited @host styles');
|
|
|
|
var zot = document.querySelector('x-zot');
|
|
var zotStyle = getComputedStyle(zot);
|
|
chai.assert.equal(zotStyle.backgroundColor, 'rgb(255, 0, 0)',
|
|
'@host styles are inherited');
|
|
chai.assert.equal(zotStyle.borderColor, 'rgb(255, 165, 0)',
|
|
'@host styles are combined with inherited @host styles');
|
|
chai.assert.equal(zotStyle.color, 'rgb(0, 0, 0)',
|
|
'@host styles are applied to given selector');
|
|
|
|
var zim = document.querySelector('x-zim');
|
|
var zimStyle = getComputedStyle(zim);
|
|
chai.assert.equal(zimStyle.backgroundColor, 'rgb(255, 0, 0)',
|
|
'@host styles are inherited');
|
|
chai.assert.equal(zimStyle.borderColor, 'rgb(255, 165, 0)',
|
|
'@host styles are combined with inherited @host styles');
|
|
chai.assert.equal(zimStyle.color, 'rgb(0, 0, 0)',
|
|
'@host styles are applied to given selector');
|
|
chai.assert.equal(zimStyle.padding, '20px',
|
|
'@host styles are loaded via external sheet in import');
|
|
done();
|
|
});
|
|
</script>
|
|
|
|
<element name="x-foo">
|
|
<template>
|
|
<style>
|
|
@host {
|
|
* {
|
|
display: block;
|
|
background: red;
|
|
}
|
|
}
|
|
</style>
|
|
<div>red background</div>
|
|
</template>
|
|
<script>Toolkit.register(this)</script>
|
|
</element>
|
|
|
|
<element name="x-bar" extends="x-foo">
|
|
<template>
|
|
<style>
|
|
@host {
|
|
x-bar {
|
|
color: white;
|
|
}
|
|
}
|
|
</style>
|
|
<shadow></shadow>
|
|
<div>white text</div>
|
|
</template>
|
|
<script>Toolkit.register(this)</script>
|
|
</element>
|
|
|
|
<element name="x-zot" extends="x-bar">
|
|
<template>
|
|
<style>
|
|
@host {
|
|
* {
|
|
border: 5px solid orange;
|
|
}
|
|
}
|
|
</style>
|
|
<shadow></shadow>
|
|
<div>orange border & gray background</div>
|
|
</template>
|
|
<script>Toolkit.register(this)</script>
|
|
</element>
|
|
<link rel="import" href="zim.html">
|
|
</body>
|
|
</html>
|