This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
js-max-number-error.js
140 lines (125 loc) · 3.68 KB
/
js-max-number-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
Copyright 2016 The Advanced REST client authors <[email protected]>
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 { LitElement, html, css } from 'lit-element';
import '@anypoint-web-components/awc/anypoint-collapse.js';
import { info } from '@advanced-rest-client/arc-icons/ArcIcons.js';
/* eslint-disable max-len */
class JsMaxNumberError extends LitElement {
get styles() {
return css`:host {
display: inline-block;
vertical-align: text-bottom;
}
.parsed-value ::slot > * {
color: #D32F2F;
font-weight: 500;
}
.content {
display: flex;
flex-direction: row;
align-items: center;
color: #D32F2F;
font-weight: 500;
cursor: pointer;
}
.icon {
height: 18px;
width: 18px;
margin-right: 8px;
display: inline-block;
fill: currentColor;
}
#collapse {
white-space: initial;
font-size: var(--arc-font-body2-font-size);
font-weight: var(--arc-font-body2-font-weight);
line-height: var(--arc-font-body2-line-height);
color: rgba(0, 0, 0, 0.74);
}
p {
margin: 0;
}
.message {
padding: 12px;
background-color: #FFECB3;
margin: 12px 24px;
}
.expected {
font-weight: 700;
}`;
}
render() {
return html`<style>${this.styles}</style>
<div
class="content"
@click="${this.toggle}"
>
<span class="icon">${info}</span>
<div class="parsed-value">
<slot></slot>
</div>
</div>
<anypoint-collapse>
<div class="message">
<p>The number used in the response is unsafe in JavaScript environment and therefore as a JSON value.</p>
<p>Original value for the number (represented as string) is <span class="expected">"${this.expectedNumber}"</span></p>
<p>This number will not work in web environment and should be passed as a string, not a number.</p>
</div>
</anypoint-collapse>`;
}
static get properties() {
return {
// A number that is expected to be true.
expectedNumber: { type: String }
};
}
constructor() {
super();
this.expectedNumber = '[unknown]';
this._keyDown = this._keyDown.bind(this);
}
connectedCallback() {
if (super.connectedCallback) {
super.connectedCallback();
}
this.setAttribute('role', 'button');
this.setAttribute('tabindex', '0');
this.setAttribute('aria-expanded', 'false');
this.setAttribute('aria-label', 'Activate to see warning details');
this.addEventListener('keydown', this._keyDown);
}
disconnectedCallback() {
if (super.disconnectedCallback) {
super.disconnectedCallback();
}
this.removeEventListener('keydown', this._keyDown);
}
// Toggles the collapse element.
toggle() {
const node = this.shadowRoot.querySelector('anypoint-collapse');
node.toggle();
if (node.opened) {
this.setAttribute('aria-expanded', 'true');
} else {
this.setAttribute('aria-expanded', 'false');
}
}
_keyDown(e) {
if (e.code === 'Enter' || e.code === 'NumpadEnter' || e.code === 'Space') {
e.preventDefault();
this.toggle();
}
}
}
window.customElements.define('js-max-number-error', JsMaxNumberError);