generated from lit/lit-element-starter-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsinpapeles-profile.js
243 lines (207 loc) · 4.82 KB
/
sinpapeles-profile.js
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
/**
* @license
* Copyright (c) 2019 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
*/
import {LitElement, html, css} from 'lit-element';
function parseUrl(link) {
try {
return new URL(link);
} catch (e) {
return '';
}
}
export const getLink = (link) => {
if (parseUrl(link)) {
return link;
}
if (link.includes('@')) {
return parseUrl(`mailto:${link}`);
}
// phone
if (/^[\d+ -]+$/.test(link)) {
return parseUrl(`tel:${link.replace(/[^\d+]/g, '')}`);
}
return parseUrl(`${window.location.protocol}//${link}`);
};
/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
export class Profile extends LitElement {
static get styles() {
return css`
:host {
display: block;
width: 100%;
height: 100%;
text-align: center;
overflow: auto;
}
:host .profile {
box-sizing: border-box;
margin: 0 auto;
max-width: 400px;
height: 100%;
padding: 80px 20px 0;
display: flex;
justify-content: space-between;
flex-direction: column;
}
:host .rounded-circle {
border-radius: 50% !important;
}
:host .img-thumbnail {
padding: 0.25rem;
border: 1px solid;
border-radius: 0.25rem;
max-width: 100%;
height: auto;
}
:host .img-fluid {
max-width: 100%;
height: auto;
max-height: 250px;
}
:host .bio {
margin: 0 auto;
padding: 20px;
white-space: pre-wrap;
}
:host .links {
margin: 0 auto;
}
:host .link {
margin: 10px 0;
}
:host .link a {
display: inline-block;
width: 100%;
padding: 20px 0;
border: 1px solid;
text-decoration: none;
font-size: 1.2rem;
}
:host .footer {
display: inline-block;
margin-top: 40px;
padding-bottom: 10px;
}
:host .footer .text {
font-family: sans-serif;
font-size: 0.8rem;
}
`;
}
static get properties() {
return {
data: {type: Object},
openNewPage: {type: Boolean},
};
}
constructor() {
super();
}
renderImage() {
const {image} = this.data;
if (!image.show) {
return '';
}
const styles = ['img-fluid'];
if (image.border) {
styles.push('img-thumbnail');
}
if (image.circle) {
styles.push('rounded-circle');
}
return html`
<div class="image">
<img src="${image.src}" class="${styles.join(' ')}" alt="profile" />
</div>
`;
}
renderTitle() {
const {title} = this.data;
if (!title.show) {
return '';
}
return html`
<div class="title">
<h1>${title.text}</h1>
</div>
`;
}
renderBio() {
const {bio} = this.data;
if (!bio.show) {
return '';
}
return html`<div class="bio">${bio.text}</div>`;
}
renderLink(link) {
const {color} = this.data.theme;
const target = this.openNewPage ? '_blank' : '_self';
const href = getLink(link.href);
return html`
<div class="link">
<a
href="${href}"
target="${target}"
rel="noopener noreferrer"
style="color: ${color}"
>${link.text}</a
>
</div>
`;
}
renderLinks() {
const {links} = this.data;
const content = Object.values(links)
.filter(({show}) => show)
.map((link) => this.renderLink(link));
return html` <div class="links">${content}</div> `;
}
renderFooter() {
return html`
<div class="footer">
<div class="text">
Truly decentralized.
</div>
</div>
</div>`;
}
render() {
const {theme} = this.data;
const {url} = theme.font;
return html`
<link href="${url}" rel="stylesheet" />
<style>
:host {
background: ${theme.background};
color: ${theme.color};
}
:host .profile {
font-family: '${theme.font.family}', sans-serif;
}
</style>
<div class="profile">
<div class="body">
${this.renderImage()} ${this.renderTitle()} ${this.renderBio()}
${this.renderLinks()}
</div>
${this.renderFooter()}
</div>
`;
}
}
window.customElements.define('sinpapeles-profile', Profile);