@operato/input 1.0.6 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/src/locale/locale-picker.js.map +1 -1
- package/dist/src/ox-buttons-radio.js.map +1 -1
- package/dist/src/ox-checkbox.js.map +1 -1
- package/dist/src/ox-input-3dish.js.map +1 -1
- package/dist/src/ox-input-angle.js.map +1 -1
- package/dist/src/ox-input-barcode.js.map +1 -1
- package/dist/src/ox-input-code.js.map +1 -1
- package/dist/src/ox-input-color-gradient.js.map +1 -1
- package/dist/src/ox-input-color-stops.js.map +1 -1
- package/dist/src/ox-input-color.js.map +1 -1
- package/dist/src/ox-input-container.js.map +1 -1
- package/dist/src/ox-input-crontab.js.map +1 -1
- package/dist/src/ox-input-data.js.map +1 -1
- package/dist/src/ox-input-duration.js.map +1 -1
- package/dist/src/ox-input-file.js.map +1 -1
- package/dist/src/ox-input-image.js.map +1 -1
- package/dist/src/ox-input-key-values.js.map +1 -1
- package/dist/src/ox-input-layout/ox-input-card-layout.js.map +1 -1
- package/dist/src/ox-input-layout/ox-input-grid-layout.js.map +1 -1
- package/dist/src/ox-input-multiple-colors.js.map +1 -1
- package/dist/src/ox-input-options.js.map +1 -1
- package/dist/src/ox-input-partition-keys.js.map +1 -1
- package/dist/src/ox-input-quantifier.js.map +1 -1
- package/dist/src/ox-input-range.js.map +1 -1
- package/dist/src/ox-input-scene-component-id.js.map +1 -1
- package/dist/src/ox-input-search.js.map +1 -1
- package/dist/src/ox-input-stack.js.map +1 -1
- package/dist/src/ox-input-unit-number.d.ts +23 -0
- package/dist/src/ox-input-unit-number.js +300 -0
- package/dist/src/ox-input-unit-number.js.map +1 -0
- package/dist/src/ox-input-value-map.js.map +1 -1
- package/dist/src/ox-input-value-ranges.js.map +1 -1
- package/dist/src/ox-input-work-shift.js.map +1 -1
- package/dist/src/ox-select.js.map +1 -1
- package/dist/stories/ox-input-unit.stories.d.ts +2 -6
- package/dist/stories/ox-input-unit.stories.js +46 -13
- package/dist/stories/ox-input-unit.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/ox-input-unit-number.ts +310 -0
- package/stories/ox-input-unit.stories.ts +47 -15
- package/dist/src/ox-input-unit.d.ts +0 -17
- package/dist/src/ox-input-unit.js +0 -122
- package/dist/src/ox-input-unit.js.map +0 -1
- package/src/ox-input-unit.ts +0 -123
@@ -0,0 +1,310 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
import { css, html, PropertyValues } from 'lit'
|
6
|
+
import { customElement, property, query } from 'lit/decorators.js'
|
7
|
+
|
8
|
+
import { OxPopupList } from '@operato/popup'
|
9
|
+
|
10
|
+
import { OxFormField } from './ox-form-field'
|
11
|
+
|
12
|
+
const UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number | ((v: number) => number)[] } } = {
|
13
|
+
kg: {
|
14
|
+
mg: 1000000,
|
15
|
+
g: 1000,
|
16
|
+
ton: 0.001
|
17
|
+
},
|
18
|
+
rad: {
|
19
|
+
degree: 180 / Math.PI
|
20
|
+
},
|
21
|
+
sec: {
|
22
|
+
msec: 1000,
|
23
|
+
min: 1 / 60,
|
24
|
+
hr: 1 / 3600,
|
25
|
+
day: 1 / (3600 * 24),
|
26
|
+
year: 1 / (3600 * 24 * 365)
|
27
|
+
},
|
28
|
+
m: {
|
29
|
+
mm: 1000,
|
30
|
+
cm: 100,
|
31
|
+
inch: 39.37008
|
32
|
+
},
|
33
|
+
'g/mol': {
|
34
|
+
'kg/kmol': 1,
|
35
|
+
'g/kmol': 1000
|
36
|
+
},
|
37
|
+
m2: {
|
38
|
+
mm2: 1000000,
|
39
|
+
cm2: 1000
|
40
|
+
},
|
41
|
+
m3: {
|
42
|
+
cm3: 1000000,
|
43
|
+
L: 1000,
|
44
|
+
mL: 1000000
|
45
|
+
},
|
46
|
+
'kg/m3': {
|
47
|
+
'g/m3': 1000,
|
48
|
+
'g/L': 1,
|
49
|
+
'g/cm3': 0.001,
|
50
|
+
'kg/L': 0.001,
|
51
|
+
'g/mL': 0.001
|
52
|
+
},
|
53
|
+
'm/sec': {
|
54
|
+
'm/min': 60,
|
55
|
+
'm/hr': 3600,
|
56
|
+
'cm/sec': 100,
|
57
|
+
'cm/min': 6000,
|
58
|
+
'cm/hr': 360000
|
59
|
+
},
|
60
|
+
N: {
|
61
|
+
kN: 0.001,
|
62
|
+
kgf: 0.101971621
|
63
|
+
},
|
64
|
+
Pa: {
|
65
|
+
atm: 1 / 101325,
|
66
|
+
bar: 1 / 100000,
|
67
|
+
'kgf/cm2': 1 / 9.80665 / 10000,
|
68
|
+
MPa: 1 / 1000000,
|
69
|
+
kPa: 1 / 1000,
|
70
|
+
psi: 1 / 6894.76,
|
71
|
+
mmH2O: 1 / 9.80665,
|
72
|
+
mmHg: 1 / 133.32
|
73
|
+
},
|
74
|
+
'kg/sec': {
|
75
|
+
'kg/min': 60,
|
76
|
+
'kg/hr': 3600,
|
77
|
+
'ton/hr': 3.6,
|
78
|
+
'ton/year': (60 * 60 * 24 * 365) / 1000
|
79
|
+
},
|
80
|
+
'kg/m2/sec': {
|
81
|
+
'kg/m2/min': 60,
|
82
|
+
'kg/m2/hr': 3600
|
83
|
+
},
|
84
|
+
'mol/sec': {
|
85
|
+
'kmol/sec': 1 / 1000
|
86
|
+
},
|
87
|
+
'mol/m2/sec': {
|
88
|
+
'kmol/m2/sec': 1 / 1000
|
89
|
+
},
|
90
|
+
'Sm3/sec': {
|
91
|
+
'Sm3/hr': 3600,
|
92
|
+
'Sm3/min': 60,
|
93
|
+
'SL/min': 60000,
|
94
|
+
'SL/sec': 1000,
|
95
|
+
'Scm3/min': 60000000,
|
96
|
+
'Scm3/sec': 1000000
|
97
|
+
},
|
98
|
+
'Nm3/sec': {
|
99
|
+
'Am3/hr': 3600,
|
100
|
+
'Am3/min': 60,
|
101
|
+
'AL/min': 60000,
|
102
|
+
'AL/sec': 1000,
|
103
|
+
'Acm3/min': 60000000,
|
104
|
+
'Acm3/sec': 1000000
|
105
|
+
},
|
106
|
+
J: {
|
107
|
+
kJ: 1 / 1000,
|
108
|
+
MJ: 1 / 1000000,
|
109
|
+
cal: 1 / 4.184,
|
110
|
+
kcal: 1 / 4.184 / 1000
|
111
|
+
},
|
112
|
+
W: {
|
113
|
+
kW: 1 / 1000,
|
114
|
+
MW: 1 / 1000000,
|
115
|
+
'kcal/hr': 859.85 / 1000,
|
116
|
+
hp: 1 / 745.7
|
117
|
+
},
|
118
|
+
'W/m2': {
|
119
|
+
'kW/m2': 1 / 1000,
|
120
|
+
'W/cm2': 1 / 10000,
|
121
|
+
'kW/cm2': 1 / 10000000
|
122
|
+
},
|
123
|
+
'J/kg': {
|
124
|
+
'kJ/kg': 1 / 1000,
|
125
|
+
'cal/g': 1 / 4.184 / 1000,
|
126
|
+
'cal/kg': 1 / 4.184,
|
127
|
+
'kcal/kg': 1 / 4.184 / 1000
|
128
|
+
},
|
129
|
+
'J/kg/K': {
|
130
|
+
'kJ/kg/K': 1 / 1000,
|
131
|
+
'cal/kg/K': 1 / 4.184,
|
132
|
+
'kcal/kg/K': 1 / 4.184 / 1000,
|
133
|
+
'cal/g/K': 1 / 4.184 / 1000
|
134
|
+
},
|
135
|
+
'W/m/K': {
|
136
|
+
'kW/m/K': 1 / 1000,
|
137
|
+
'W/cm/K': 1 / 100,
|
138
|
+
'kW/cm/K': 1 / 100 / 1000
|
139
|
+
},
|
140
|
+
'W/m2/K': {
|
141
|
+
'kW/m2/K': 1 / 1000,
|
142
|
+
'kcal/hr/m2/oC': 1 / 1.163
|
143
|
+
},
|
144
|
+
'N sec/m2': {
|
145
|
+
'Pa sec': 1,
|
146
|
+
'mPa sec': 1000,
|
147
|
+
'kg/m/sec': 1,
|
148
|
+
'g/cm/sec': 10,
|
149
|
+
P: 10,
|
150
|
+
cP: 1000
|
151
|
+
},
|
152
|
+
'm2 oC/W': {
|
153
|
+
'm2 oC/kW': 1000
|
154
|
+
},
|
155
|
+
K: {
|
156
|
+
C: [
|
157
|
+
(v: number) => v - 273.15,
|
158
|
+
(v: number) => v + 273.15
|
159
|
+
]
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
@customElement('ox-input-unit-number')
|
164
|
+
export class OxInputUnit extends OxFormField {
|
165
|
+
static styles = [
|
166
|
+
css`
|
167
|
+
input {
|
168
|
+
border: 0;
|
169
|
+
border-bottom: var(--border-dark-color);
|
170
|
+
padding: var(--input-padding);
|
171
|
+
font: var(--input-font);
|
172
|
+
color: var(--primary-text-color);
|
173
|
+
}
|
174
|
+
input:focus {
|
175
|
+
outline: none;
|
176
|
+
border-bottom: 1px solid var(--primary-color);
|
177
|
+
}
|
178
|
+
|
179
|
+
input::-webkit-outer-spin-button,
|
180
|
+
input::-webkit-inner-spin-button {
|
181
|
+
-webkit-appearance: none;
|
182
|
+
margin: 0;
|
183
|
+
}
|
184
|
+
|
185
|
+
input[type='number'] {
|
186
|
+
-moz-appearance: textfield;
|
187
|
+
}
|
188
|
+
|
189
|
+
div {
|
190
|
+
display: inline;
|
191
|
+
position: relative;
|
192
|
+
margin-left: var(--margin-narrow);
|
193
|
+
font: var(--label-font);
|
194
|
+
color: var(--label-color);
|
195
|
+
}
|
196
|
+
`
|
197
|
+
]
|
198
|
+
|
199
|
+
@property({ type: String }) placeholder?: string
|
200
|
+
@property({ type: String, attribute: 'std-unit' }) stdUnit!: string
|
201
|
+
@property({ type: String, attribute: 'user-unit' }) userUnit?: string
|
202
|
+
|
203
|
+
@query('input') input!: HTMLInputElement
|
204
|
+
@query('ox-popup-list') popup!: OxPopupList
|
205
|
+
|
206
|
+
render() {
|
207
|
+
const userUnit = this.userUnit || this.stdUnit
|
208
|
+
const units = Object.keys(UNIT_SYSTEMS[this.stdUnit])
|
209
|
+
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
|
210
|
+
|
211
|
+
return html`
|
212
|
+
<input
|
213
|
+
type="number"
|
214
|
+
.value=${this._toUserUnit(this.value)}
|
215
|
+
placeholder=${this.placeholder}
|
216
|
+
@change=${(e: Event) => this._onChangeValue(e)}
|
217
|
+
/>
|
218
|
+
<div
|
219
|
+
@click=${(e: Event) => {
|
220
|
+
const target = e.currentTarget as HTMLElement
|
221
|
+
this.popup.open({
|
222
|
+
right: 0,
|
223
|
+
top: target.clientTop + target.offsetHeight
|
224
|
+
})
|
225
|
+
}}
|
226
|
+
>
|
227
|
+
${userUnit}
|
228
|
+
<ox-popup-list
|
229
|
+
.value=${userUnit}
|
230
|
+
@select=${(e: CustomEvent) => {
|
231
|
+
this.userUnit = e.detail
|
232
|
+
}}
|
233
|
+
>
|
234
|
+
<div option value=${this.stdUnit}>${this.stdUnit}</div>
|
235
|
+
${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}
|
236
|
+
</ox-popup-list>
|
237
|
+
</div>
|
238
|
+
`
|
239
|
+
}
|
240
|
+
|
241
|
+
updated(changes: PropertyValues<this>) {
|
242
|
+
if (changes.has('stdUnit')) {
|
243
|
+
this.userUnit = this.stdUnit
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
_onChangeValue(e: Event) {
|
248
|
+
this.value = this._toStdUnit(this.input.value)
|
249
|
+
|
250
|
+
this.dispatchEvent(
|
251
|
+
new CustomEvent('change', {
|
252
|
+
bubbles: true,
|
253
|
+
composed: true,
|
254
|
+
detail: this.value
|
255
|
+
})
|
256
|
+
)
|
257
|
+
}
|
258
|
+
|
259
|
+
_toUserUnit(stdValue: string | number | undefined) {
|
260
|
+
if(!this.userUnit) {
|
261
|
+
return
|
262
|
+
}
|
263
|
+
|
264
|
+
if(this.userUnit === this.stdUnit) {
|
265
|
+
return Number(stdValue)
|
266
|
+
}
|
267
|
+
|
268
|
+
const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]
|
269
|
+
|
270
|
+
if(typeof converterValue === 'number') {
|
271
|
+
return this._toUserUnitByRate(stdValue, converterValue || 1)
|
272
|
+
} else /* should be converter function array */{
|
273
|
+
return this._toUserUnitByFunction(stdValue, converterValue as ((v: number) => number)[])
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
_toUserUnitByRate(stdValue: string | number | undefined, converterRate: number) {
|
278
|
+
return Number(stdValue) * converterRate
|
279
|
+
}
|
280
|
+
|
281
|
+
_toUserUnitByFunction(stdValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {
|
282
|
+
return converterFunctions[0](Number(stdValue))
|
283
|
+
}
|
284
|
+
|
285
|
+
_toStdUnit(userValue: string | number | undefined) {
|
286
|
+
if(!this.userUnit) {
|
287
|
+
return
|
288
|
+
}
|
289
|
+
|
290
|
+
if(this.userUnit === this.stdUnit) {
|
291
|
+
return Number(userValue)
|
292
|
+
}
|
293
|
+
|
294
|
+
const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]
|
295
|
+
|
296
|
+
if(typeof converterValue === 'number') {
|
297
|
+
return this._toStdUnitByRate(userValue, converterValue || 1)
|
298
|
+
} else /* should be converter function array */{
|
299
|
+
return this._toStdUnitByFunction(userValue, converterValue as ((v: number) => number)[])
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
_toStdUnitByRate(userValue: string | number | undefined, converterRate: number) {
|
304
|
+
return isNaN(Number(userValue)) ? undefined : Number(userValue) / converterRate
|
305
|
+
}
|
306
|
+
|
307
|
+
_toStdUnitByFunction(userValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {
|
308
|
+
return converterFunctions[1](Number(userValue))
|
309
|
+
}
|
310
|
+
}
|
@@ -1,16 +1,45 @@
|
|
1
|
-
import '../src/ox-input-unit.js'
|
1
|
+
import '../src/ox-input-unit-number.js'
|
2
2
|
|
3
3
|
import { html, TemplateResult } from 'lit'
|
4
4
|
|
5
5
|
export default {
|
6
|
-
title: 'ox-input-unit',
|
7
|
-
component: 'ox-input-unit',
|
6
|
+
title: 'ox-input-unit-number',
|
7
|
+
component: 'ox-input-unit-number',
|
8
8
|
argTypes: {
|
9
9
|
placeholder: { control: 'text' },
|
10
10
|
name: { control: 'text' },
|
11
11
|
value: { control: 'number' },
|
12
|
-
stdUnit: {
|
13
|
-
|
12
|
+
stdUnit: {
|
13
|
+
control: 'select',
|
14
|
+
options: [
|
15
|
+
'kg',
|
16
|
+
'rad',
|
17
|
+
'm',
|
18
|
+
'g/mol',
|
19
|
+
'm2',
|
20
|
+
'm3',
|
21
|
+
'kg/m3',
|
22
|
+
'm/sec',
|
23
|
+
'N',
|
24
|
+
'Pa',
|
25
|
+
'kg/sec',
|
26
|
+
'kg/m2/sec',
|
27
|
+
'mol/sec',
|
28
|
+
'mol/m2/sec',
|
29
|
+
'Sm3/sec',
|
30
|
+
'Nm3/sec',
|
31
|
+
'J',
|
32
|
+
'W',
|
33
|
+
'W/m2',
|
34
|
+
'J/kg',
|
35
|
+
'J/kg/K',
|
36
|
+
'W/m/K',
|
37
|
+
'W/m2/K',
|
38
|
+
'N sec/m2',
|
39
|
+
'm2 oC/W',
|
40
|
+
'K'
|
41
|
+
]
|
42
|
+
}
|
14
43
|
}
|
15
44
|
}
|
16
45
|
|
@@ -25,26 +54,23 @@ interface ArgTypes {
|
|
25
54
|
name?: string
|
26
55
|
value?: number
|
27
56
|
stdUnit: string
|
28
|
-
userUnit?: string
|
29
57
|
}
|
30
58
|
|
31
59
|
const Template: Story<ArgTypes> = ({
|
32
60
|
placeholder = 'unit',
|
33
61
|
name = 'hello',
|
34
62
|
value = 0,
|
35
|
-
stdUnit = 'kg'
|
36
|
-
userUnit
|
63
|
+
stdUnit = 'kg'
|
37
64
|
}: ArgTypes) => html`
|
38
65
|
<link href="/themes/app-theme.css" rel="stylesheet" />
|
39
|
-
<ox-input-unit
|
66
|
+
<ox-input-unit-number
|
40
67
|
name=${name}
|
41
68
|
placeholder=${placeholder}
|
42
69
|
.value=${value}
|
43
70
|
std-unit=${stdUnit}
|
44
|
-
user-unit=${userUnit}
|
45
71
|
@change=${(e: CustomEvent) => console.log(e.detail)}
|
46
72
|
>
|
47
|
-
</ox-input-unit>
|
73
|
+
</ox-input-unit-number>
|
48
74
|
`
|
49
75
|
|
50
76
|
export const Weight = Template.bind({})
|
@@ -52,8 +78,7 @@ Weight.args = {
|
|
52
78
|
placeholder: 'weight',
|
53
79
|
name: 'weight',
|
54
80
|
value: 0,
|
55
|
-
stdUnit: 'kg'
|
56
|
-
userUnit: 'g'
|
81
|
+
stdUnit: 'kg'
|
57
82
|
}
|
58
83
|
|
59
84
|
export const Angle = Template.bind({})
|
@@ -61,6 +86,13 @@ Angle.args = {
|
|
61
86
|
placeholder: 'angle',
|
62
87
|
name: 'angle',
|
63
88
|
value: 0,
|
64
|
-
stdUnit: 'rad'
|
65
|
-
|
89
|
+
stdUnit: 'rad'
|
90
|
+
}
|
91
|
+
|
92
|
+
export const Temperature = Template.bind({})
|
93
|
+
Temperature.args = {
|
94
|
+
placeholder: 'temperature',
|
95
|
+
name: 'temperature',
|
96
|
+
value: 0,
|
97
|
+
stdUnit: 'K'
|
66
98
|
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
import { OxPopupList } from '@operato/popup';
|
5
|
-
import { OxFormField } from './ox-form-field';
|
6
|
-
export declare class OxInputUnit extends OxFormField {
|
7
|
-
static styles: import("lit").CSSResult[];
|
8
|
-
placeholder?: string;
|
9
|
-
stdUnit: string;
|
10
|
-
userUnit?: string;
|
11
|
-
input: HTMLInputElement;
|
12
|
-
popup: OxPopupList;
|
13
|
-
render(): import("lit-html").TemplateResult<1>;
|
14
|
-
_onChangeValue(e: Event): void;
|
15
|
-
_toUserUnit(stdValue: string | number | undefined): number;
|
16
|
-
_toStdUnit(userValue: string | number | undefined): number | undefined;
|
17
|
-
}
|
@@ -1,122 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
import { __decorate } from "tslib";
|
5
|
-
import { css, html } from 'lit';
|
6
|
-
import { customElement, property, query } from 'lit/decorators.js';
|
7
|
-
import { OxFormField } from './ox-form-field';
|
8
|
-
const UNIT_SYSTEMS = {
|
9
|
-
kg: {
|
10
|
-
mg: 1000000,
|
11
|
-
g: 1000,
|
12
|
-
ton: 0.001
|
13
|
-
},
|
14
|
-
rad: {
|
15
|
-
degree: 180 / Math.PI
|
16
|
-
}
|
17
|
-
};
|
18
|
-
let OxInputUnit = class OxInputUnit extends OxFormField {
|
19
|
-
static { this.styles = [
|
20
|
-
css `
|
21
|
-
input {
|
22
|
-
border: 0;
|
23
|
-
border-bottom: var(--border-dark-color);
|
24
|
-
padding: var(--input-padding);
|
25
|
-
font: var(--input-font);
|
26
|
-
color: var(--primary-text-color);
|
27
|
-
}
|
28
|
-
input:focus {
|
29
|
-
outline: none;
|
30
|
-
border-bottom: 1px solid var(--primary-color);
|
31
|
-
}
|
32
|
-
|
33
|
-
input::-webkit-outer-spin-button,
|
34
|
-
input::-webkit-inner-spin-button {
|
35
|
-
-webkit-appearance: none;
|
36
|
-
margin: 0;
|
37
|
-
}
|
38
|
-
|
39
|
-
input[type='number'] {
|
40
|
-
-moz-appearance: textfield;
|
41
|
-
}
|
42
|
-
|
43
|
-
div {
|
44
|
-
display: inline;
|
45
|
-
position: relative;
|
46
|
-
margin-left: var(--margin-narrow);
|
47
|
-
font: var(--label-font);
|
48
|
-
color: var(--label-color);
|
49
|
-
opacity: 0.7;
|
50
|
-
}
|
51
|
-
`
|
52
|
-
]; }
|
53
|
-
render() {
|
54
|
-
const userUnit = this.userUnit || this.stdUnit;
|
55
|
-
const units = Object.keys(UNIT_SYSTEMS[this.stdUnit]);
|
56
|
-
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1;
|
57
|
-
return html `
|
58
|
-
<input
|
59
|
-
type="number"
|
60
|
-
.value=${this._toUserUnit(this.value)}
|
61
|
-
placeholder=${this.placeholder}
|
62
|
-
@change=${(e) => this._onChangeValue(e)}
|
63
|
-
/>
|
64
|
-
<div
|
65
|
-
@click=${(e) => {
|
66
|
-
const target = e.currentTarget;
|
67
|
-
this.popup.open({
|
68
|
-
right: 0,
|
69
|
-
top: target.offsetTop + target.offsetHeight
|
70
|
-
});
|
71
|
-
}}
|
72
|
-
>
|
73
|
-
${userUnit}
|
74
|
-
<ox-popup-list
|
75
|
-
.value=${userUnit}
|
76
|
-
@select=${(e) => {
|
77
|
-
this.userUnit = e.detail;
|
78
|
-
}}
|
79
|
-
>
|
80
|
-
<div option value=${this.stdUnit}>${this.stdUnit}</div>
|
81
|
-
${units.map(unit => html `<div option value=${unit}>${unit}</div>`)}
|
82
|
-
</ox-popup-list>
|
83
|
-
</div>
|
84
|
-
`;
|
85
|
-
}
|
86
|
-
_onChangeValue(e) {
|
87
|
-
this.value = this._toStdUnit(this.input.value);
|
88
|
-
this.dispatchEvent(new CustomEvent('change', {
|
89
|
-
bubbles: true,
|
90
|
-
composed: true,
|
91
|
-
detail: this.value
|
92
|
-
}));
|
93
|
-
}
|
94
|
-
_toUserUnit(stdValue) {
|
95
|
-
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1;
|
96
|
-
return Number(stdValue) * rate;
|
97
|
-
}
|
98
|
-
_toStdUnit(userValue) {
|
99
|
-
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1;
|
100
|
-
return isNaN(Number(userValue)) ? undefined : Number(userValue) / rate;
|
101
|
-
}
|
102
|
-
};
|
103
|
-
__decorate([
|
104
|
-
property({ type: String })
|
105
|
-
], OxInputUnit.prototype, "placeholder", void 0);
|
106
|
-
__decorate([
|
107
|
-
property({ type: String, attribute: 'std-unit' })
|
108
|
-
], OxInputUnit.prototype, "stdUnit", void 0);
|
109
|
-
__decorate([
|
110
|
-
property({ type: String, attribute: 'user-unit' })
|
111
|
-
], OxInputUnit.prototype, "userUnit", void 0);
|
112
|
-
__decorate([
|
113
|
-
query('input')
|
114
|
-
], OxInputUnit.prototype, "input", void 0);
|
115
|
-
__decorate([
|
116
|
-
query('ox-popup-list')
|
117
|
-
], OxInputUnit.prototype, "popup", void 0);
|
118
|
-
OxInputUnit = __decorate([
|
119
|
-
customElement('ox-input-unit')
|
120
|
-
], OxInputUnit);
|
121
|
-
export { OxInputUnit };
|
122
|
-
//# sourceMappingURL=ox-input-unit.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ox-input-unit.js","sourceRoot":"","sources":["../../src/ox-input-unit.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAIlE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,YAAY,GAAmD;IACnE,EAAE,EAAE;QACF,EAAE,EAAE,OAAO;QACX,CAAC,EAAE,IAAI;QACP,GAAG,EAAE,KAAK;KACX;IACD,GAAG,EAAE;QACH,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC,EAAE;KACtB;CACF,CAAA;AAGD,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,WAAW;aACnC,WAAM,GAAG;QACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+BF;KACF,CAAA;IASD,MAAM;QACJ,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAA;QAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QACrD,MAAM,IA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import { css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\n\nimport { OxPopupList } from '@operato/popup'\n\nimport { OxFormField } from './ox-form-field'\n\nconst UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number } } = {\n kg: {\n mg: 1000000,\n g: 1000,\n ton: 0.001\n },\n rad: {\n degree: 180 / Math.PI\n }\n}\n\n@customElement('ox-input-unit')\nexport class OxInputUnit extends OxFormField {\n static styles = [\n css`\n input {\n border: 0;\n border-bottom: var(--border-dark-color);\n padding: var(--input-padding);\n font: var(--input-font);\n color: var(--primary-text-color);\n }\n input:focus {\n outline: none;\n border-bottom: 1px solid var(--primary-color);\n }\n\n input::-webkit-outer-spin-button,\n input::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n\n input[type='number'] {\n -moz-appearance: textfield;\n }\n\n div {\n display: inline;\n position: relative;\n margin-left: var(--margin-narrow);\n font: var(--label-font);\n color: var(--label-color);\n opacity: 0.7;\n }\n `\n ]\n\n @property({ type: String }) placeholder?: string\n @property({ type: String, attribute: 'std-unit' }) stdUnit!: string\n @property({ type: String, attribute: 'user-unit' }) userUnit?: string\n\n @query('input') input!: HTMLInputElement\n @query('ox-popup-list') popup!: OxPopupList\n\n render() {\n const userUnit = this.userUnit || this.stdUnit\n const units = Object.keys(UNIT_SYSTEMS[this.stdUnit])\n const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1\n\n return html`\n <input\n type=\"number\"\n .value=${this._toUserUnit(this.value)}\n placeholder=${this.placeholder}\n @change=${(e: Event) => this._onChangeValue(e)}\n />\n <div\n @click=${(e: Event) => {\n const target = e.currentTarget as HTMLElement\n this.popup.open({\n right: 0,\n top: target.offsetTop + target.offsetHeight\n })\n }}\n >\n ${userUnit}\n <ox-popup-list\n .value=${userUnit}\n @select=${(e: CustomEvent) => {\n this.userUnit = e.detail\n }}\n >\n <div option value=${this.stdUnit}>${this.stdUnit}</div>\n ${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}\n </ox-popup-list>\n </div>\n `\n }\n\n _onChangeValue(e: Event) {\n this.value = this._toStdUnit(this.input.value)\n\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n }\n\n _toUserUnit(stdValue: string | number | undefined) {\n const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1\n return Number(stdValue) * rate\n }\n\n _toStdUnit(userValue: string | number | undefined) {\n const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1\n return isNaN(Number(userValue)) ? undefined : Number(userValue) / rate\n }\n}\n"]}
|
package/src/ox-input-unit.ts
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
import { css, html } from 'lit'
|
6
|
-
import { customElement, property, query } from 'lit/decorators.js'
|
7
|
-
|
8
|
-
import { OxPopupList } from '@operato/popup'
|
9
|
-
|
10
|
-
import { OxFormField } from './ox-form-field'
|
11
|
-
|
12
|
-
const UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number } } = {
|
13
|
-
kg: {
|
14
|
-
mg: 1000000,
|
15
|
-
g: 1000,
|
16
|
-
ton: 0.001
|
17
|
-
},
|
18
|
-
rad: {
|
19
|
-
degree: 180 / Math.PI
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
@customElement('ox-input-unit')
|
24
|
-
export class OxInputUnit extends OxFormField {
|
25
|
-
static styles = [
|
26
|
-
css`
|
27
|
-
input {
|
28
|
-
border: 0;
|
29
|
-
border-bottom: var(--border-dark-color);
|
30
|
-
padding: var(--input-padding);
|
31
|
-
font: var(--input-font);
|
32
|
-
color: var(--primary-text-color);
|
33
|
-
}
|
34
|
-
input:focus {
|
35
|
-
outline: none;
|
36
|
-
border-bottom: 1px solid var(--primary-color);
|
37
|
-
}
|
38
|
-
|
39
|
-
input::-webkit-outer-spin-button,
|
40
|
-
input::-webkit-inner-spin-button {
|
41
|
-
-webkit-appearance: none;
|
42
|
-
margin: 0;
|
43
|
-
}
|
44
|
-
|
45
|
-
input[type='number'] {
|
46
|
-
-moz-appearance: textfield;
|
47
|
-
}
|
48
|
-
|
49
|
-
div {
|
50
|
-
display: inline;
|
51
|
-
position: relative;
|
52
|
-
margin-left: var(--margin-narrow);
|
53
|
-
font: var(--label-font);
|
54
|
-
color: var(--label-color);
|
55
|
-
opacity: 0.7;
|
56
|
-
}
|
57
|
-
`
|
58
|
-
]
|
59
|
-
|
60
|
-
@property({ type: String }) placeholder?: string
|
61
|
-
@property({ type: String, attribute: 'std-unit' }) stdUnit!: string
|
62
|
-
@property({ type: String, attribute: 'user-unit' }) userUnit?: string
|
63
|
-
|
64
|
-
@query('input') input!: HTMLInputElement
|
65
|
-
@query('ox-popup-list') popup!: OxPopupList
|
66
|
-
|
67
|
-
render() {
|
68
|
-
const userUnit = this.userUnit || this.stdUnit
|
69
|
-
const units = Object.keys(UNIT_SYSTEMS[this.stdUnit])
|
70
|
-
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
|
71
|
-
|
72
|
-
return html`
|
73
|
-
<input
|
74
|
-
type="number"
|
75
|
-
.value=${this._toUserUnit(this.value)}
|
76
|
-
placeholder=${this.placeholder}
|
77
|
-
@change=${(e: Event) => this._onChangeValue(e)}
|
78
|
-
/>
|
79
|
-
<div
|
80
|
-
@click=${(e: Event) => {
|
81
|
-
const target = e.currentTarget as HTMLElement
|
82
|
-
this.popup.open({
|
83
|
-
right: 0,
|
84
|
-
top: target.offsetTop + target.offsetHeight
|
85
|
-
})
|
86
|
-
}}
|
87
|
-
>
|
88
|
-
${userUnit}
|
89
|
-
<ox-popup-list
|
90
|
-
.value=${userUnit}
|
91
|
-
@select=${(e: CustomEvent) => {
|
92
|
-
this.userUnit = e.detail
|
93
|
-
}}
|
94
|
-
>
|
95
|
-
<div option value=${this.stdUnit}>${this.stdUnit}</div>
|
96
|
-
${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}
|
97
|
-
</ox-popup-list>
|
98
|
-
</div>
|
99
|
-
`
|
100
|
-
}
|
101
|
-
|
102
|
-
_onChangeValue(e: Event) {
|
103
|
-
this.value = this._toStdUnit(this.input.value)
|
104
|
-
|
105
|
-
this.dispatchEvent(
|
106
|
-
new CustomEvent('change', {
|
107
|
-
bubbles: true,
|
108
|
-
composed: true,
|
109
|
-
detail: this.value
|
110
|
-
})
|
111
|
-
)
|
112
|
-
}
|
113
|
-
|
114
|
-
_toUserUnit(stdValue: string | number | undefined) {
|
115
|
-
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
|
116
|
-
return Number(stdValue) * rate
|
117
|
-
}
|
118
|
-
|
119
|
-
_toStdUnit(userValue: string | number | undefined) {
|
120
|
-
const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
|
121
|
-
return isNaN(Number(userValue)) ? undefined : Number(userValue) / rate
|
122
|
-
}
|
123
|
-
}
|