forked from PolymerElements/paper-card
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper-card.html
343 lines (288 loc) · 10 KB
/
paper-card.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!--
@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
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-image/iron-image.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../paper-styles/default-theme.html">
<!--
Material design: [Cards](https://www.google.com/design/spec/components/cards.html)
`paper-card` is a container with a drop shadow.
Example:
<paper-card heading="Card Title">
<div class="card-content">Some content</div>
<div class="card-actions">
<paper-button>Some action</paper-button>
</div>
</paper-card>
Example - top card image:
<paper-card heading="Card Title" image="/path/to/image.png">
...
</paper-card>
### Accessibility
By default, the `aria-label` will be set to the value of the `heading` attribute.
### Styling
The following custom properties and mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--paper-card-background-color` | The background color of the card | `--primary-background-color`
`--paper-card-header-color` | The color of the header text | `#000`
`--paper-card-header` | Mixin applied to the card header section | `{}`
`--paper-card-header-text` | Mixin applied to the title in the card header section | `{}`
`--paper-card-header-image` | Mixin applied to the image in the card header section | `{}`
`--paper-card-header-image-text` | Mixin applied to the text overlapping the image in the card header section | `{}`
`--paper-card-content` | Mixin applied to the card content section| `{}`
`--paper-card-actions` | Mixin applied to the card action section | `{}`
`--paper-card` | Mixin applied to the card | `{}`
@group Paper Elements
@element paper-card
@demo demo/index.html
-->
<dom-module id="paper-card">
<template>
<style include="paper-material">
:host {
display: inline-block;
position: relative;
box-sizing: border-box;
background-color: var(--paper-card-background-color, --primary-background-color);
border-radius: 2px;
@apply(--paper-font-common-base);
@apply(--paper-card);
}
/* IE 10 support for HTML5 hidden attr */
[hidden] {
display: none !important;
}
.header {
position: relative;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
overflow: hidden;
@apply(--paper-card-header);
}
.header iron-image {
width: 100%;
--iron-image-width: 100%;
pointer-events: none;
@apply(--paper-card-header-image);
}
.header .title-text {
padding: 16px;
font-size: 24px;
font-weight: 400;
color: var(--paper-card-header-color, #000);
@apply(--paper-card-header-text);
}
.header .title-text.over-image {
position: absolute;
bottom: 0px;
@apply(--paper-card-header-image-text);
}
:host ::content .card-header {
position: relative;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
overflow: hidden;
@apply(--paper-card-header);
}
:host ::content .card-content {
padding: 16px;
position:relative;
@apply(--paper-card-content);
}
:host ::content .card-actions {
border-top: 1px solid #e8e8e8;
padding: 5px 16px;
position:relative;
@apply(--paper-card-actions);
}
.aspect-ratio iron-image {
position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
/* padding: 0 24px; Optional padding for content area */
}
.image-box-wrapper {
position: relative;
width: 100%; /* <-- just a default, can be anything. */
}
.seven-by-one.aspect-ratio {
padding-bottom: 14.2857%;
}
.sixteen-by-nine.aspect-ratio {
padding-bottom: 56.25%
}
.three-by-two.aspect-ratio {
padding-bottom: 66.666%
}
.four-by-three.aspect-ratio {
padding-bottom: 75%
}
.custom.aspect-ratio {
padding-bottom: var(--paper-card-image-aspect-ratio, 100%);
}
</style>
<template is="dom-if" if="[[advanced]]" restamp="true">
<content select=".card-header"></content>
<div hidden$="[[!image]]" class="image-box-wrapper">
<div class$="[[imageAspectRatio]] aspect-ratio">
<iron-image id="advancedImage" hidden$="[[!image]]" src="[[image]]" preload$="[[preloadImage]]"
fade$="[[fadeImage]]" sizing="[[imageSizing]]" position="[[imagePosition]]" width="[[imageWidth]]"
height="[[imageHeight]]"></iron-image>
</div>
</div>
<content select=".card-content"></content>
<content select=".card-actions"></content>
</template>
<template is="dom-if" if="[[!advanced]]" restamp="true">
<div class$="header [[imageAspectRatio]] aspect-ratio">
<iron-image hidden$="[[!image]]" src="[[image]]" preload$="[[preloadImage]]" fade$="[[fadeImage]]"
sizing="[[imageSizing]]" position="[[imagePosition]]" width="[[imageWidth]]"
height="[[imageHeight]]"></iron-image>
<div hidden$="[[!heading]]" class$="[[_computeHeadingClass(image)]]">[[heading]]</div>
</div>
<content></content>
</template>
</template>
<script>
Polymer({
is: 'paper-card',
properties: {
/**
* Informs element to treat content as separate header and body areas, instead of default header behaviour,
* with property set it is possible to override header as complex as required. Card image related properties
* 'image', 'fadeImage' and 'preloadImage' are ignored if advanced mode is set.
*/
advanced: {
type: Boolean,
value: false
},
/**
* The title of the card.
*/
heading: {
type: String,
value: '',
observer: '_headingChanged'
},
/**
* The url of the title image of the card.
*/
image: {
type: String,
value: ''
},
/**
* `iron-image`, sizing option, applies to both advanced media area and header image
* From `iron-image` documentation:
* Valid values are `contain` (full aspect ratio of the image is contained within the element and
* letterboxed) or `cover` (image is cropped in order to fully cover the
* bounds of the element), or `null` (default: image takes natural size).
*/
imageSizing: {
type: String,
value: 'null'
},
/**
* `iron-image`, `position` property
* From `iron-image` documentation:
* When a `imageSizing` option is used (`cover` or `contain`), this determines
* how the image is aligned within the element bounds (default: `center`)
*/
imagePosition: {
type: String,
value: 'center'
},
/**
* In `advanced` mode only, `iron-image` will be limited by this aspect ratio depending on the card width
* Supported values are `sixteen-by-nine`, `three-by-two`, `four-by-three` or `seven-by-one`, finally if
* `--paper-card-image-aspect-ratio` variable is set you can use `custom` value
*/
imageAspectRatio: {
type: String,
value: 'sixteen-by-nine',
observer: '_switchImageRatio'
},
/**
* `iron-image`, `width` property
*/
imageWidth: {
type: Number,
value: null
},
/**
* `iron-image`, `height` property
*/
imageHeight: {
type: Number,
value: null
},
/**
* When `true`, any change to the image url property will cause the
* `placeholder` image to be shown until the image is fully rendered.
*/
preloadImage: {
type: Boolean,
value: false
},
/**
* When `preloadImage` is true, setting `fadeImage` to true will cause the
* image to fade into place.
*/
fadeImage: {
type: Boolean,
value: false
},
/**
* The z-depth of the card, from 0-5.
*/
elevation: {
type: Number,
value: 1,
reflectToAttribute: true
},
/**
* Set this to true to animate the card shadow when setting a new
* `z` value.
*/
animatedShadow: {
type: Boolean,
value: false
},
/**
* Read-only property used to pass down the `animatedShadow` value to
* the underlying paper-material style (since they have different names).
*/
animated: {
type: Boolean,
reflectToAttribute: true,
readOnly: true,
computed: '_computeAnimated(animatedShadow)'
}
},
_switchImageRatio: function(newAR, oldAR) {
this.updateStyles();
},
_headingChanged: function(heading) {
var label = this.getAttribute('aria-label');
this.setAttribute('aria-label', heading);
},
_computeHeadingClass: function(image) {
var cls = 'title-text';
if (image)
cls += ' over-image';
return cls;
},
_computeAnimated: function(animatedShadow) {
return animatedShadow;
}
});
</script>
</dom-module>