-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidenticon-element.html
95 lines (79 loc) · 2.17 KB
/
identicon-element.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="identicon-import.html">
<!--
`<identicon-element>` is a beautiful identicon generator based on [jdenticon](https://jdenticon.com/).
Simply use it like this:
```html
<identicon-element size="100" seed="Polymer Rocks"></identicon-element>
```
### Styling
The following mixin is available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--identicon-element` | Mixin applied to the element | `{}`
@group MoleculeElements Elements
@element identicon-element
@hero hero.svg
@demo demo/index.html
-->
<dom-module id="identicon-element">
<template>
<style>
:host {
display: inline-block;
@apply --identicon-element;
}
</style>
<svg id="svg" width$="[[size]]" height$="[[size]]" data-jdenticon-hash$="[[_hash]]">
<!-- Fallback text for browsers not supporting inline svg -->
<content></content>
</svg>
</template>
<script>
(function() {
// TODO PG: add this to the config of the component
var jdenticon_config = {
lightness: {
color: [0.4, 0.8],
grayscale: [0.3, 0.9]
},
saturation: 0.5
};
Polymer({
is: 'identicon-element',
properties: {
/**
* Specifies the seed of the hash of the identicon to be rendered.
*/
seed: {
type: String,
observer: "_hashChanged"
},
/**
* Specifies the width and height of the SVG.
*/
size: {
type: Number,
value: 45
},
/**
* Specifies the hash of the identicon to be rendered.
*/
_hash: {
type: String,
computed: "_computeHash(seed)"
},
},
attached: function() {
jdenticon.update(this.$.svg, this._hash);
},
_hashChanged: function() {
jdenticon.update(this.$.svg, this._hash);
},
_computeHash: function(seed) {
return md5(seed);
}
});
}());
</script>
</dom-module>