-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathnuxeo-error.js
140 lines (121 loc) · 3.37 KB
/
nuxeo-error.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
/**
@license
(C) Copyright Nuxeo Corp. (http://nuxeo.com/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import '@nuxeo/nuxeo-elements/nuxeo-element.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
import { I18nBehavior } from './nuxeo-i18n-behavior.js';
{
/**
* An element to display errors.
*
* Example:
*
* <nuxeo-error code="404"></nuxeo-error>
*
* @appliesMixin Nuxeo.I18nBehavior
* @memberof Nuxeo
* @demo demo/nuxeo-error/index.html
*/
class Error extends mixinBehaviors([I18nBehavior], Nuxeo.Element) {
static get template() {
return html`
<style>
:host {
display: block;
padding: 24px;
background: rgba(0, 0, 0, 0.025);
border-radius: 4px;
border: 1px dashed rgba(0, 0, 0, 0.1);
}
:host([hidden]) {
display: none !important;
}
.code {
@apply --layout-flex;
text-transform: uppercase;
color: var(--nuxeo-text-default, rgba(0,0,0,0.3));
text-align: center;
font-size: 1.4rem;
font-weight: 700;
}
.description {
@apply --layout-flex;
text-transform: uppercase;
color: var(--nuxeo-text-default, rgba(0,0,0,0.3));
text-align: center;
font-size: 1.2rem;
font-weight: 500;
padding: 8px;
}
.url {
@apply --layout-flex;
color: var(--nuxeo-text-default, rgba(0,0,0,0.3));
text-align: center;
padding: 16px 0;
font-size: .8rem;
}
.message {
@apply --layout-flex;
color: var(--nuxeo-text-default, rgba(0,0,0,0.3));
text-align: center;
padding: 8px 0;
font-size: 1rem;
font-weight: 500;
}
</style>
<div class="code" hidden\$="[[!code]]">[[code]]</div>
<div class="description" hidden\$="[[!code]]">[[_label(code)]]</div>
<div class="url" hidden\$="[[!url]]">[[url]]</div>
<div class="message" hidden\$="[[!message]]">[[message]]</div>
`;
}
static get is() {
return 'nuxeo-error';
}
static get properties() {
return {
/**
* The error code. Description will rely on a label with key 'error.<code>'.
* */
code: String,
/**
* Error message to display.
* */
message: String,
url: String,
hidden: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
};
}
show(code, url, message) {
if (arguments.length) {
this.code = code;
this.url = url;
this.message = message;
}
this.hidden = false;
}
hide() {
this.hidden = true;
}
_label() {
return this.i18n(`error.${this.code}`);
}
}
customElements.define(Error.is, Error);
Nuxeo.Error = Error;
}