@operato/input 8.0.0-beta.0 → 8.0.0-beta.1
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 +9 -0
- package/package.json +7 -7
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/preview.js +0 -52
- package/.storybook/server.mjs +0 -8
- package/src/index.ts +0 -35
- package/src/locale/locale-codes.ts +0 -18
- package/src/locale/locale-picker.ts +0 -43
- package/src/locale/localization.ts +0 -15
- package/src/locales/en.ts +0 -30
- package/src/locales/ko.ts +0 -30
- package/src/locales/ms.ts +0 -30
- package/src/locales/zh.ts +0 -30
- package/src/ox-buttons-radio.ts +0 -140
- package/src/ox-checkbox.ts +0 -181
- package/src/ox-form-field.ts +0 -53
- package/src/ox-input-3axis.ts +0 -77
- package/src/ox-input-3dish.ts +0 -211
- package/src/ox-input-angle.ts +0 -73
- package/src/ox-input-barcode.ts +0 -318
- package/src/ox-input-code.ts +0 -139
- package/src/ox-input-color-gradient.ts +0 -349
- package/src/ox-input-color-stops.ts +0 -525
- package/src/ox-input-color.ts +0 -338
- package/src/ox-input-container.ts +0 -32
- package/src/ox-input-crontab.ts +0 -595
- package/src/ox-input-data.ts +0 -219
- package/src/ox-input-direction.ts +0 -92
- package/src/ox-input-duration.ts +0 -175
- package/src/ox-input-file.ts +0 -209
- package/src/ox-input-hashtags.ts +0 -185
- package/src/ox-input-i18n-label.ts +0 -140
- package/src/ox-input-image.ts +0 -168
- package/src/ox-input-key-values.ts +0 -301
- package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
- package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
- package/src/ox-input-layout/ox-input-layout.ts +0 -77
- package/src/ox-input-mass-fraction.ts +0 -437
- package/src/ox-input-multiple-colors.ts +0 -135
- package/src/ox-input-options.ts +0 -216
- package/src/ox-input-partition-keys.ts +0 -303
- package/src/ox-input-privilege.ts +0 -163
- package/src/ox-input-quantifier.ts +0 -62
- package/src/ox-input-range.ts +0 -146
- package/src/ox-input-scene-component-id.ts +0 -73
- package/src/ox-input-search.ts +0 -126
- package/src/ox-input-select-buttons.ts +0 -75
- package/src/ox-input-signature.ts +0 -208
- package/src/ox-input-stack.ts +0 -136
- package/src/ox-input-switch.ts +0 -117
- package/src/ox-input-table-column-config.ts +0 -211
- package/src/ox-input-table.ts +0 -404
- package/src/ox-input-textarea.ts +0 -86
- package/src/ox-input-unit-number.ts +0 -354
- package/src/ox-input-value-map.ts +0 -342
- package/src/ox-input-value-ranges.ts +0 -363
- package/src/ox-input-work-shift.ts +0 -290
- package/src/ox-select-floor.ts +0 -246
- package/src/ox-select.ts +0 -219
- package/stories/image-for-select-floor.ts +0 -2
- package/stories/ox-buttons-radio.stories.ts +0 -89
- package/stories/ox-checkbox.stories.ts +0 -111
- package/stories/ox-input-3axis.stories.ts +0 -77
- package/stories/ox-input-3dish.stories.ts +0 -106
- package/stories/ox-input-angle.stories.ts +0 -84
- package/stories/ox-input-barcode.stories.ts +0 -117
- package/stories/ox-input-code.stories.ts +0 -99
- package/stories/ox-input-crontab.stories.ts +0 -82
- package/stories/ox-input-data.stories.ts +0 -82
- package/stories/ox-input-direction.stories.ts +0 -91
- package/stories/ox-input-duration.stories.ts +0 -84
- package/stories/ox-input-file.stories.ts +0 -111
- package/stories/ox-input-hashtags.stories.ts +0 -82
- package/stories/ox-input-i18n-label.stories.ts +0 -103
- package/stories/ox-input-key-values.stories.ts +0 -97
- package/stories/ox-input-mass-fraction.stories.ts +0 -102
- package/stories/ox-input-multiple-colors.stories.ts +0 -72
- package/stories/ox-input-options.stories.ts +0 -80
- package/stories/ox-input-partition-keys.stories.ts +0 -84
- package/stories/ox-input-privilege.stories.ts +0 -108
- package/stories/ox-input-quantifier.stories.ts +0 -80
- package/stories/ox-input-range.stories.ts +0 -89
- package/stories/ox-input-search.stories.ts +0 -91
- package/stories/ox-input-select-buttons.stories.ts +0 -118
- package/stories/ox-input-signature.stories.ts +0 -75
- package/stories/ox-input-switch.stories.ts +0 -91
- package/stories/ox-input-table-column-config.stories.ts +0 -109
- package/stories/ox-input-unit.stories.ts +0 -151
- package/stories/ox-input-value-map.stories.ts +0 -92
- package/stories/ox-input-value-ranges.stories.ts +0 -92
- package/stories/ox-input-work-shift.stories.ts +0 -106
- package/stories/ox-select-floor.stories.ts +0 -197
- package/stories/ox-select-set-options.stories.ts +0 -208
- package/stories/ox-select.stories.ts +0 -181
- package/tsconfig.json +0 -25
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
@@ -1,363 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
import './ox-input-color'
|
6
|
-
|
7
|
-
import { css, html, nothing } from 'lit'
|
8
|
-
import { customElement, property } from 'lit/decorators.js'
|
9
|
-
import { keyed } from 'lit/directives/keyed.js'
|
10
|
-
import { ifDefined } from 'lit/directives/if-defined.js'
|
11
|
-
|
12
|
-
import { OxFormField } from './ox-form-field.js'
|
13
|
-
|
14
|
-
type ValueRange = { default?: any; [fromto: string]: any }
|
15
|
-
type ArrayedRange = { from: any; to: any; value: any }
|
16
|
-
|
17
|
-
/**
|
18
|
-
range value editor element
|
19
|
-
|
20
|
-
Example:
|
21
|
-
|
22
|
-
<ox-input-value-ranges
|
23
|
-
.value=${range}
|
24
|
-
valuetype=${type}
|
25
|
-
</ox-input-value-ranges>
|
26
|
-
*/
|
27
|
-
|
28
|
-
@customElement('ox-input-value-ranges')
|
29
|
-
export class OxInputValueRange extends OxFormField {
|
30
|
-
static styles = css`
|
31
|
-
:host {
|
32
|
-
display: flex;
|
33
|
-
flex-direction: column;
|
34
|
-
border: 1px solid rgba(0, 0, 0, 0.15);
|
35
|
-
padding: var(--spacing-small) var(--spacing-small) 0 var(--spacing-small);
|
36
|
-
|
37
|
-
--md-icon-size: var(--fontsize-default, 14px);
|
38
|
-
}
|
39
|
-
|
40
|
-
div {
|
41
|
-
display: flex;
|
42
|
-
flex-flow: row nowrap;
|
43
|
-
gap: var(--padding-default);
|
44
|
-
}
|
45
|
-
|
46
|
-
div:last-child {
|
47
|
-
margin-bottom: var(--spacing-small);
|
48
|
-
}
|
49
|
-
|
50
|
-
div > * {
|
51
|
-
min-width: 0px;
|
52
|
-
margin: 2px;
|
53
|
-
padding: 0;
|
54
|
-
}
|
55
|
-
|
56
|
-
button {
|
57
|
-
border: var(--button-border);
|
58
|
-
border-radius: var(--border-radius);
|
59
|
-
background-color: var(--button-background-color);
|
60
|
-
padding: var(--spacing-small) var(--padding-default);
|
61
|
-
line-height: 0.8;
|
62
|
-
color: var(--button-color);
|
63
|
-
cursor: pointer;
|
64
|
-
}
|
65
|
-
button + button {
|
66
|
-
margin-left: -5px;
|
67
|
-
}
|
68
|
-
|
69
|
-
button:focus,
|
70
|
-
button:hover,
|
71
|
-
button:active {
|
72
|
-
border: var(--button-activ-border);
|
73
|
-
background-color: var(--button-background-focus-color);
|
74
|
-
color: var(--md-sys-color-primary-container);
|
75
|
-
}
|
76
|
-
|
77
|
-
[data-from],
|
78
|
-
[data-to] {
|
79
|
-
flex: 1;
|
80
|
-
}
|
81
|
-
|
82
|
-
[data-value] {
|
83
|
-
flex: 2;
|
84
|
-
}
|
85
|
-
|
86
|
-
input {
|
87
|
-
border: 0;
|
88
|
-
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
89
|
-
padding: var(--spacing-tiny);
|
90
|
-
font: var(--input-font);
|
91
|
-
color: var(--md-sys-color-on-primary-container);
|
92
|
-
}
|
93
|
-
|
94
|
-
input:focus {
|
95
|
-
outline: none;
|
96
|
-
border-bottom: 1px solid var(--md-sys-color-on-primary-container);
|
97
|
-
}
|
98
|
-
|
99
|
-
button.hidden {
|
100
|
-
opacity: 0;
|
101
|
-
cursor: default;
|
102
|
-
}
|
103
|
-
|
104
|
-
ox-input-color {
|
105
|
-
--things-editor-color-input-color: {
|
106
|
-
margin: 2px;
|
107
|
-
}
|
108
|
-
--things-editor-color-input-span: {
|
109
|
-
width: 12px;
|
110
|
-
height: 12px;
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
[placeholder='value'] {
|
115
|
-
flex: 2;
|
116
|
-
}
|
117
|
-
|
118
|
-
[filler] {
|
119
|
-
padding: var(--spacing-tiny);
|
120
|
-
flex: 1;
|
121
|
-
}
|
122
|
-
|
123
|
-
input[type='checkbox'] {
|
124
|
-
flex: none;
|
125
|
-
width: initial;
|
126
|
-
}
|
127
|
-
`
|
128
|
-
|
129
|
-
@property({ type: Object }) value: ValueRange = {}
|
130
|
-
@property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | 'number' | 'date' | string = 'string'
|
131
|
-
@property({ type: String }) rangetype: 'string' | 'number' = 'number'
|
132
|
-
@property({ type: String, attribute: 'default-value' }) defaultValue?: string
|
133
|
-
|
134
|
-
private _changingNow: boolean = false
|
135
|
-
|
136
|
-
firstUpdated() {
|
137
|
-
this.renderRoot.addEventListener('change', this._onChange.bind(this))
|
138
|
-
}
|
139
|
-
|
140
|
-
updated() {
|
141
|
-
const inputs = this.renderRoot.querySelectorAll('[data-record-new] > :not([style*="display: none"])') as NodeListOf<
|
142
|
-
HTMLInputElement & { value: any }
|
143
|
-
>
|
144
|
-
|
145
|
-
inputs[0]?.focus()
|
146
|
-
}
|
147
|
-
|
148
|
-
valueInputTemplate(value?: any) {
|
149
|
-
return this.valuetype == 'boolean'
|
150
|
-
? html`
|
151
|
-
<input
|
152
|
-
type="checkbox"
|
153
|
-
data-value
|
154
|
-
.checked=${!!value}
|
155
|
-
data-value-type=${this.valuetype}
|
156
|
-
?disabled=${this.disabled}
|
157
|
-
/>
|
158
|
-
`
|
159
|
-
: this.valuetype == 'color'
|
160
|
-
? html` <ox-input-color data-value value=${ifDefined(value)} ?disabled=${this.disabled}> </ox-input-color> `
|
161
|
-
: html`
|
162
|
-
<input
|
163
|
-
type="text"
|
164
|
-
data-value
|
165
|
-
placeholder="value"
|
166
|
-
value=${ifDefined(value)}
|
167
|
-
data-value-type=${this.valuetype}
|
168
|
-
?disabled=${this.disabled}
|
169
|
-
/>
|
170
|
-
`
|
171
|
-
}
|
172
|
-
|
173
|
-
render() {
|
174
|
-
return html`
|
175
|
-
${this._toArray(this.value).map(
|
176
|
-
item => html`
|
177
|
-
<div data-record>
|
178
|
-
<input type="text" data-from placeholder="<=" .value=${item.from} ?disabled=${this.disabled} />
|
179
|
-
<input type="text" data-to placeholder=">" .value=${item.to} ?disabled=${this.disabled} />
|
180
|
-
|
181
|
-
${this.valueInputTemplate(item.value)}
|
182
|
-
<button
|
183
|
-
class="record-action"
|
184
|
-
@click=${(e: Event) => this._delete(e)}
|
185
|
-
tabindex="-1"
|
186
|
-
?disabled=${this.disabled}
|
187
|
-
>
|
188
|
-
<md-icon>remove</md-icon>
|
189
|
-
</button>
|
190
|
-
</div>
|
191
|
-
`
|
192
|
-
)}
|
193
|
-
${this.disabled
|
194
|
-
? nothing
|
195
|
-
: keyed(
|
196
|
-
Date.now(),
|
197
|
-
html`
|
198
|
-
<div data-record-new>
|
199
|
-
<input type="text" data-from placeholder="<=" value="" />
|
200
|
-
<input type="text" data-to placeholder=">" value="" />
|
201
|
-
|
202
|
-
${this.valueInputTemplate()}
|
203
|
-
<button class="record-action" @click=${(e: Event) => this._add()} tabindex="-1">
|
204
|
-
<md-icon>add</md-icon>
|
205
|
-
</button>
|
206
|
-
</div>
|
207
|
-
`
|
208
|
-
)}
|
209
|
-
|
210
|
-
<div data-record>
|
211
|
-
<span filler></span>
|
212
|
-
<input type="text" data-from data-default="" disabled value="default" />
|
213
|
-
<input type="text" data-to placeholder=">" value="" hidden ?disabled=${this.disabled} />
|
214
|
-
|
215
|
-
${this.valueInputTemplate((this.value && this.value.default) || this._defaultValue())}
|
216
|
-
<button class="record-action" @click=${(e: Event) => this._sort()} ?disabled=${this.disabled}>
|
217
|
-
<md-icon>chevron_right</md-icon>
|
218
|
-
</button>
|
219
|
-
</div>
|
220
|
-
`
|
221
|
-
}
|
222
|
-
|
223
|
-
_defaultValue(type?: 'color' | 'boolean' | 'checkbox' | string) {
|
224
|
-
switch (type || this.valuetype) {
|
225
|
-
case 'color':
|
226
|
-
return this.defaultValue || '#000000'
|
227
|
-
case 'boolean':
|
228
|
-
case 'checkbox':
|
229
|
-
return this.defaultValue ? this.defaultValue === 'true' : false
|
230
|
-
default:
|
231
|
-
return this.defaultValue || ''
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
|
-
_onChange(e: Event) {
|
236
|
-
e.stopPropagation()
|
237
|
-
|
238
|
-
if (this._changingNow) {
|
239
|
-
return
|
240
|
-
}
|
241
|
-
|
242
|
-
this._changingNow = true
|
243
|
-
|
244
|
-
const input = e.target as HTMLInputElement
|
245
|
-
var value = input.type === 'checkbox' ? Boolean(input.checked) : input.value
|
246
|
-
|
247
|
-
const div = input.parentElement as HTMLDivElement
|
248
|
-
if (input.hasAttribute('data-value') && input.hasAttribute('data-value')) {
|
249
|
-
const dataList = div.querySelectorAll('[data-value]:not([hidden])') as NodeListOf<HTMLElement & { value: any }>
|
250
|
-
|
251
|
-
for (var i = 0; i < dataList.length; i++) {
|
252
|
-
if (dataList[i] !== input) {
|
253
|
-
dataList[i].value = value || this._defaultValue()
|
254
|
-
}
|
255
|
-
}
|
256
|
-
}
|
257
|
-
|
258
|
-
if (div.hasAttribute('data-record')) {
|
259
|
-
this._build()
|
260
|
-
} else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
261
|
-
this._add()
|
262
|
-
}
|
263
|
-
|
264
|
-
this._changingNow = false
|
265
|
-
}
|
266
|
-
|
267
|
-
_build(includeNewRecord?: boolean) {
|
268
|
-
if (includeNewRecord) {
|
269
|
-
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]')
|
270
|
-
} else {
|
271
|
-
var records = this.renderRoot.querySelectorAll('[data-record]')
|
272
|
-
}
|
273
|
-
|
274
|
-
var newrange: ValueRange = {}
|
275
|
-
for (var i = 0; i < records.length; i++) {
|
276
|
-
const record = records[i]
|
277
|
-
const from = (record.querySelector('[data-from]') as HTMLInputElement).value
|
278
|
-
const to = (record.querySelector('[data-to]') as HTMLInputElement).value
|
279
|
-
const inputs = record.querySelectorAll(
|
280
|
-
'[data-value]:not([style*="display: none"])'
|
281
|
-
) as NodeListOf<HTMLInputElement>
|
282
|
-
|
283
|
-
if (!inputs || inputs.length == 0) {
|
284
|
-
continue
|
285
|
-
}
|
286
|
-
|
287
|
-
var input = inputs[inputs.length - 1]
|
288
|
-
|
289
|
-
var value
|
290
|
-
|
291
|
-
if (input.type == 'checkbox') {
|
292
|
-
value = Boolean(input.checked)
|
293
|
-
} else {
|
294
|
-
value = input.value
|
295
|
-
}
|
296
|
-
|
297
|
-
if (from) {
|
298
|
-
if (from === 'default') newrange['default'] = value || (this.valuetype == 'color' ? '#000000' : '')
|
299
|
-
else newrange[`${from}~${to}`] = value
|
300
|
-
}
|
301
|
-
}
|
302
|
-
|
303
|
-
this.value = newrange
|
304
|
-
|
305
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
306
|
-
}
|
307
|
-
|
308
|
-
/* default를 제외한 range아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
|
309
|
-
_toArray(range: ValueRange) {
|
310
|
-
var array: ArrayedRange[] = []
|
311
|
-
|
312
|
-
for (var key in range) {
|
313
|
-
if (key == 'default') {
|
314
|
-
continue
|
315
|
-
}
|
316
|
-
|
317
|
-
const fromto = key.split('~')
|
318
|
-
|
319
|
-
array.push({
|
320
|
-
from: fromto[0],
|
321
|
-
to: fromto[1],
|
322
|
-
value: range[key]
|
323
|
-
})
|
324
|
-
}
|
325
|
-
return array
|
326
|
-
}
|
327
|
-
|
328
|
-
_sort() {
|
329
|
-
const sorter =
|
330
|
-
this.rangetype === 'number'
|
331
|
-
? function (a: ArrayedRange, b: ArrayedRange) {
|
332
|
-
return parseFloat(b.from) < parseFloat(a.from) ? 1 : -1
|
333
|
-
}
|
334
|
-
: function (a: ArrayedRange, b: ArrayedRange) {
|
335
|
-
return b.from < a.from ? 1 : -1
|
336
|
-
}
|
337
|
-
|
338
|
-
var range: ValueRange = this._toArray(this.value)
|
339
|
-
.sort(sorter)
|
340
|
-
.reduce(function (sum, i) {
|
341
|
-
sum[`${i.from}~${i.to}`] = i.value
|
342
|
-
return sum
|
343
|
-
}, {} as ValueRange)
|
344
|
-
range.default = this.value.default || this._defaultValue()
|
345
|
-
|
346
|
-
this.value = range
|
347
|
-
|
348
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
349
|
-
}
|
350
|
-
|
351
|
-
_add() {
|
352
|
-
this._build(true)
|
353
|
-
}
|
354
|
-
|
355
|
-
_delete(e: Event) {
|
356
|
-
const record = (e.target as Element).parentElement
|
357
|
-
|
358
|
-
const dataFrom = record!.querySelector('[data-from]') as HTMLInputElement
|
359
|
-
dataFrom.value = ''
|
360
|
-
|
361
|
-
this._build()
|
362
|
-
}
|
363
|
-
}
|
@@ -1,290 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
import { css, html, nothing } from 'lit'
|
6
|
-
import { customElement, property } from 'lit/decorators.js'
|
7
|
-
|
8
|
-
import { localized, msg } from '@lit/localize'
|
9
|
-
|
10
|
-
import { OxFormField } from './ox-form-field.js'
|
11
|
-
|
12
|
-
type WorkShift = { name: string; fromDate: number; fromTime: string; toDate: number; toTime: string }
|
13
|
-
|
14
|
-
/**
|
15
|
-
work-shift array value editor element
|
16
|
-
|
17
|
-
Example:
|
18
|
-
|
19
|
-
<ox-input-work-shift
|
20
|
-
.value=${value}
|
21
|
-
</ox-input-work-shift>
|
22
|
-
*/
|
23
|
-
|
24
|
-
@localized()
|
25
|
-
@customElement('ox-input-work-shift')
|
26
|
-
export class OxInputWorkShift extends OxFormField {
|
27
|
-
static styles = css`
|
28
|
-
:host {
|
29
|
-
display: flex;
|
30
|
-
flex-direction: column;
|
31
|
-
|
32
|
-
width: 100%;
|
33
|
-
overflow: hidden;
|
34
|
-
|
35
|
-
--md-icon-size: var(--fontsize-default, 14px);
|
36
|
-
}
|
37
|
-
|
38
|
-
div {
|
39
|
-
display: flex;
|
40
|
-
flex-flow: row nowrap;
|
41
|
-
gap: var(--spacing-medium);
|
42
|
-
}
|
43
|
-
|
44
|
-
empty-element {
|
45
|
-
width: 34px;
|
46
|
-
text-align: center;
|
47
|
-
}
|
48
|
-
|
49
|
-
input,
|
50
|
-
select,
|
51
|
-
span {
|
52
|
-
flex: 1;
|
53
|
-
}
|
54
|
-
[data-header] {
|
55
|
-
background-color: rgba(var(--md-sys-color-on-primary-container-rgb), 0.05);
|
56
|
-
padding: var(--spacing-small);
|
57
|
-
}
|
58
|
-
[data-header] span {
|
59
|
-
font: var(--label-font);
|
60
|
-
color: var(--label-color, var(--md-sys-color-on-surface));
|
61
|
-
text-transform: var(--label-text-transform);
|
62
|
-
text-align: center;
|
63
|
-
}
|
64
|
-
[data-record] {
|
65
|
-
margin-bottom: var(--spacing-small);
|
66
|
-
}
|
67
|
-
input,
|
68
|
-
select {
|
69
|
-
border: 0;
|
70
|
-
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
71
|
-
padding: var(--spacing-tiny);
|
72
|
-
font: var(--input-font);
|
73
|
-
color: var(--md-sys-color-on-primary-container);
|
74
|
-
|
75
|
-
max-height: 35px;
|
76
|
-
}
|
77
|
-
input:focus,
|
78
|
-
select:focus {
|
79
|
-
outline: none;
|
80
|
-
border-bottom: 1px solid var(--md-sys-color-on-primary-container);
|
81
|
-
}
|
82
|
-
|
83
|
-
input:required:invalid {
|
84
|
-
border: 1px dashed red;
|
85
|
-
}
|
86
|
-
|
87
|
-
button {
|
88
|
-
border: var(--button-border);
|
89
|
-
border-radius: var(--border-radius);
|
90
|
-
background-color: var(--button-background-color);
|
91
|
-
padding: var(--spacing-small) var(--padding-default);
|
92
|
-
line-height: 0.8;
|
93
|
-
color: var(--button-color);
|
94
|
-
cursor: pointer;
|
95
|
-
}
|
96
|
-
button:focus,
|
97
|
-
button:hover,
|
98
|
-
button:active {
|
99
|
-
border: var(--button-activ-border);
|
100
|
-
background-color: var(--button-background-focus-color);
|
101
|
-
color: var(--md-sys-color-primary-container);
|
102
|
-
}
|
103
|
-
|
104
|
-
[placeholder='value'] {
|
105
|
-
flex: 2;
|
106
|
-
}
|
107
|
-
`
|
108
|
-
|
109
|
-
@property({ type: Array }) value: WorkShift[] = []
|
110
|
-
|
111
|
-
private _changingNow: boolean = false
|
112
|
-
|
113
|
-
firstUpdated() {
|
114
|
-
this.renderRoot.addEventListener('change', this._onChange.bind(this))
|
115
|
-
}
|
116
|
-
|
117
|
-
render() {
|
118
|
-
const workshifts = this.value || []
|
119
|
-
|
120
|
-
return html`
|
121
|
-
<div data-header>
|
122
|
-
<span>${msg('name')}</span>
|
123
|
-
<span>${msg('from date')}</span>
|
124
|
-
<span>${msg('from time')}</span>
|
125
|
-
<span>${msg('to date')}</span>
|
126
|
-
<span>${msg('to time')}</span>
|
127
|
-
<empty-element></empty-element>
|
128
|
-
</div>
|
129
|
-
|
130
|
-
${workshifts.map(
|
131
|
-
item => html`
|
132
|
-
<div data-record>
|
133
|
-
<input type="text" data-name .value=${item.name} required ?disabled=${this.disabled} />
|
134
|
-
|
135
|
-
<select data-from-date .value=${String(item.fromDate || 0)} ?disabled=${this.disabled}>
|
136
|
-
<option value="-1">${msg('The day before')}</option>
|
137
|
-
<option value="0">${msg('The day')}</option>
|
138
|
-
<option value="1">${msg('The day after')}</option>
|
139
|
-
</select>
|
140
|
-
<input type="time" data-from-time .value=${item.fromTime} step="1800" required ?disabled=${this.disabled} />
|
141
|
-
|
142
|
-
<select data-to-date .value=${String(item.toDate || 0)} ?disabled=${this.disabled}>
|
143
|
-
<option value="-1">${msg('The day before')}</option>
|
144
|
-
<option value="0">${msg('The day')}</option>
|
145
|
-
<option value="1">${msg('The day after')}</option>
|
146
|
-
</select>
|
147
|
-
<input type="time" data-to-time .value=${item.toTime} step="1800" required ?disabled=${this.disabled} />
|
148
|
-
|
149
|
-
<button
|
150
|
-
class="record-action"
|
151
|
-
@click=${(e: Event) => this._delete(e)}
|
152
|
-
tabindex="-1"
|
153
|
-
?disabled=${this.disabled}
|
154
|
-
>
|
155
|
-
<md-icon>remove</md-icon>
|
156
|
-
</button>
|
157
|
-
</div>
|
158
|
-
`
|
159
|
-
)}
|
160
|
-
${this.disabled
|
161
|
-
? nothing
|
162
|
-
: html`
|
163
|
-
<div data-record-new>
|
164
|
-
<input type="text" data-name />
|
165
|
-
|
166
|
-
<select data-from-date>
|
167
|
-
<option value="-1">${msg('The day before')}</option>
|
168
|
-
<option value="0" selected>${msg('The day')}</option>
|
169
|
-
<option value="+1">${msg('The day after')}</option>
|
170
|
-
</select>
|
171
|
-
<input type="time" data-from-time step="1800" />
|
172
|
-
|
173
|
-
<select data-to-date>
|
174
|
-
<option value="-1">${msg('The day before')}</option>
|
175
|
-
<option value="0" selected>${msg('The day')}</option>
|
176
|
-
<option value="+1">${msg('The day after')}</option>
|
177
|
-
</select>
|
178
|
-
<input type="time" data-to-time step="1800" />
|
179
|
-
|
180
|
-
<button class="record-action" @click=${(e: Event) => this._add()} tabindex="-1">
|
181
|
-
<md-icon>add</md-icon>
|
182
|
-
</button>
|
183
|
-
</div>
|
184
|
-
`}
|
185
|
-
`
|
186
|
-
}
|
187
|
-
|
188
|
-
_onChange(e: Event) {
|
189
|
-
if (this._changingNow) {
|
190
|
-
return
|
191
|
-
}
|
192
|
-
|
193
|
-
this._changingNow = true
|
194
|
-
|
195
|
-
const input = e.target as HTMLInputElement
|
196
|
-
|
197
|
-
const div = input.parentElement as HTMLDivElement
|
198
|
-
|
199
|
-
if (div.hasAttribute('data-record')) {
|
200
|
-
this._build()
|
201
|
-
} else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
202
|
-
this._add()
|
203
|
-
}
|
204
|
-
|
205
|
-
this._changingNow = false
|
206
|
-
}
|
207
|
-
|
208
|
-
_build(includeNewRecord?: boolean) {
|
209
|
-
if (includeNewRecord) {
|
210
|
-
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]')
|
211
|
-
} else {
|
212
|
-
var records = this.renderRoot.querySelectorAll('[data-record]')
|
213
|
-
}
|
214
|
-
|
215
|
-
var value: WorkShift[] = []
|
216
|
-
for (var i = 0; i < records.length; i++) {
|
217
|
-
const record = records[i]
|
218
|
-
|
219
|
-
const name = (record.querySelector('[data-name]') as HTMLInputElement).value
|
220
|
-
|
221
|
-
const fromDate = (record.querySelector('[data-from-date]') as HTMLSelectElement).value
|
222
|
-
const fromTime = (record.querySelector('[data-from-time]') as HTMLInputElement).value
|
223
|
-
const toDate = (record.querySelector('[data-to-date]') as HTMLSelectElement).value
|
224
|
-
const toTime = (record.querySelector('[data-to-time]') as HTMLInputElement).value
|
225
|
-
|
226
|
-
if (!name) {
|
227
|
-
;(record.querySelector('[data-name]') as HTMLInputElement).focus()
|
228
|
-
return
|
229
|
-
}
|
230
|
-
|
231
|
-
if (!fromDate) {
|
232
|
-
;(record.querySelector('[data-from-date]') as HTMLInputElement).focus()
|
233
|
-
return
|
234
|
-
}
|
235
|
-
|
236
|
-
if (!fromTime) {
|
237
|
-
;(record.querySelector('[data-from-time]') as HTMLInputElement).focus()
|
238
|
-
return
|
239
|
-
}
|
240
|
-
|
241
|
-
if (!toDate) {
|
242
|
-
;(record.querySelector('[data-to-date]') as HTMLInputElement).focus()
|
243
|
-
return
|
244
|
-
}
|
245
|
-
|
246
|
-
if (!toTime) {
|
247
|
-
;(record.querySelector('[data-to-time]') as HTMLInputElement).focus()
|
248
|
-
return
|
249
|
-
}
|
250
|
-
|
251
|
-
if (name) {
|
252
|
-
value.push({
|
253
|
-
name,
|
254
|
-
fromDate: Number(fromDate),
|
255
|
-
fromTime,
|
256
|
-
toDate: Number(toDate),
|
257
|
-
toTime
|
258
|
-
})
|
259
|
-
}
|
260
|
-
}
|
261
|
-
|
262
|
-
this.value = value
|
263
|
-
|
264
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
265
|
-
}
|
266
|
-
|
267
|
-
_add() {
|
268
|
-
this._build(true)
|
269
|
-
|
270
|
-
const inputs = this.renderRoot.querySelectorAll(
|
271
|
-
'[data-record-new] input:not([style*="display: none"])'
|
272
|
-
) as NodeListOf<HTMLInputElement & { value: any; type: string }>
|
273
|
-
|
274
|
-
for (var i = 0; i < inputs.length; i++) {
|
275
|
-
let input = inputs[i]
|
276
|
-
input.value = ''
|
277
|
-
}
|
278
|
-
|
279
|
-
inputs[0].focus()
|
280
|
-
}
|
281
|
-
|
282
|
-
_delete(e: Event) {
|
283
|
-
const record = (e.target as Element).parentElement
|
284
|
-
|
285
|
-
const dataName = record!.querySelector('[data-name]') as HTMLInputElement
|
286
|
-
dataName.name = ''
|
287
|
-
|
288
|
-
this._build()
|
289
|
-
}
|
290
|
-
}
|