@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,437 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
import '@material/web/icon/icon.js'
|
6
|
-
import '@operato/popup/ox-popup-list.js'
|
7
|
-
import './ox-select.js'
|
8
|
-
|
9
|
-
import { css, html, nothing } from 'lit'
|
10
|
-
import { customElement, property, queryAll } from 'lit/decorators.js'
|
11
|
-
import { live } from 'lit/directives/live.js'
|
12
|
-
|
13
|
-
import { ScrollbarStyles } from '@operato/styles'
|
14
|
-
|
15
|
-
import { OxFormField } from './ox-form-field'
|
16
|
-
|
17
|
-
const FLUIDS = ['CH4', 'C2H6', 'C3H8', 'C4H10', 'CO2', 'H2O', 'H2S', 'N2', 'N2O', 'NO2', 'O2']
|
18
|
-
|
19
|
-
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[]
|
20
|
-
? ElementType
|
21
|
-
: never
|
22
|
-
|
23
|
-
type FLUID = ArrayElement<typeof FLUIDS>
|
24
|
-
|
25
|
-
type MassFraction = { [key: FLUID]: number }
|
26
|
-
type ArrayedMassFraction = { key: FLUID; value: number }[]
|
27
|
-
|
28
|
-
/**
|
29
|
-
input component for mass-fraction map
|
30
|
-
|
31
|
-
Example:
|
32
|
-
|
33
|
-
<ox-input-mass-fraction
|
34
|
-
value=${map}
|
35
|
-
</ox-input-mass-fraction>
|
36
|
-
*/
|
37
|
-
@customElement('ox-input-mass-fraction')
|
38
|
-
export class OxInputMassFraction extends OxFormField {
|
39
|
-
static styles = [
|
40
|
-
ScrollbarStyles,
|
41
|
-
css`
|
42
|
-
:host {
|
43
|
-
display: flex;
|
44
|
-
flex-direction: column;
|
45
|
-
justify-content: space-between;
|
46
|
-
|
47
|
-
--md-icon-size: var(--fontsize-default, 14px);
|
48
|
-
}
|
49
|
-
|
50
|
-
[records] {
|
51
|
-
flex: 1;
|
52
|
-
|
53
|
-
overflow: overlay;
|
54
|
-
|
55
|
-
> div {
|
56
|
-
display: flex;
|
57
|
-
flex-flow: row nowrap;
|
58
|
-
gap: var(--mass-fraction-gap, 3px);
|
59
|
-
margin-bottom: var(--spacing-small);
|
60
|
-
}
|
61
|
-
|
62
|
-
> [nofraction] {
|
63
|
-
display: block;
|
64
|
-
text-align: center;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
[data-record-new] {
|
69
|
-
display: flex;
|
70
|
-
flex-flow: row nowrap;
|
71
|
-
gap: var(--mass-fraction-gap, 3px);
|
72
|
-
margin: var(--spacing-small) 0;
|
73
|
-
}
|
74
|
-
|
75
|
-
button {
|
76
|
-
display: inherit;
|
77
|
-
align-self: center;
|
78
|
-
border: var(--button-border);
|
79
|
-
border-radius: var(--border-radius);
|
80
|
-
background-color: var(--button-background-color);
|
81
|
-
padding: var(--mass-fraction-button-padding-vertical, 3px) var(--mass-fraction-button-padding-horizontal, 3px);
|
82
|
-
color: var(--button-color);
|
83
|
-
cursor: pointer;
|
84
|
-
|
85
|
-
&:focus,
|
86
|
-
&:hover,
|
87
|
-
&:active {
|
88
|
-
border: var(--button-active-border, 1px solid rgba(0, 0, 0, 0.2));
|
89
|
-
background-color: var(--button-background-focus-color);
|
90
|
-
color: var(--md-sys-color-primary-container);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
input,
|
95
|
-
label,
|
96
|
-
ox-select {
|
97
|
-
border: 0;
|
98
|
-
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
99
|
-
font: var(--input-font);
|
100
|
-
color: var(--md-sys-color-on-primary-container);
|
101
|
-
min-width: 50px;
|
102
|
-
}
|
103
|
-
|
104
|
-
input,
|
105
|
-
label {
|
106
|
-
padding: var(--spacing-tiny);
|
107
|
-
}
|
108
|
-
|
109
|
-
label {
|
110
|
-
text-align: center;
|
111
|
-
text-wrap: nowrap;
|
112
|
-
}
|
113
|
-
|
114
|
-
ox-select {
|
115
|
-
padding: 0;
|
116
|
-
}
|
117
|
-
|
118
|
-
[data-key] {
|
119
|
-
flex: 2;
|
120
|
-
}
|
121
|
-
|
122
|
-
[data-value] {
|
123
|
-
flex: 1;
|
124
|
-
}
|
125
|
-
|
126
|
-
input:focus {
|
127
|
-
outline: none;
|
128
|
-
border-bottom: 1px solid var(--md-sys-color-on-primary-container);
|
129
|
-
}
|
130
|
-
|
131
|
-
button.hidden {
|
132
|
-
opacity: 0;
|
133
|
-
cursor: default;
|
134
|
-
}
|
135
|
-
|
136
|
-
ox-popup-list {
|
137
|
-
max-height: 300px;
|
138
|
-
overflow: auto;
|
139
|
-
left: 0;
|
140
|
-
}
|
141
|
-
|
142
|
-
[right-end] {
|
143
|
-
margin-left: auto;
|
144
|
-
}
|
145
|
-
|
146
|
-
[hidden] {
|
147
|
-
opacity: 0;
|
148
|
-
}
|
149
|
-
`
|
150
|
-
]
|
151
|
-
|
152
|
-
@property({ type: Object }) defaultValue: MassFraction = {}
|
153
|
-
@property({ type: Object }) value: MassFraction = {}
|
154
|
-
@property({ type: Boolean, attribute: true }) composable: boolean = false
|
155
|
-
|
156
|
-
@queryAll('[data-record]') records!: NodeListOf<HTMLElement>
|
157
|
-
|
158
|
-
private options = FLUIDS.map(fluid => html`<div option value=${fluid}>${fluid}</div>`)
|
159
|
-
private changingNow: boolean = false
|
160
|
-
|
161
|
-
firstUpdated() {
|
162
|
-
this.renderRoot.addEventListener('change', this._onChange.bind(this))
|
163
|
-
}
|
164
|
-
|
165
|
-
render() {
|
166
|
-
const value = !this.value || typeof this.value !== 'object' ? {} : this.value
|
167
|
-
const arrayed = this._toArray(value)
|
168
|
-
|
169
|
-
return html`
|
170
|
-
<div records>
|
171
|
-
<div data-header>
|
172
|
-
<label data-key>성분</label>
|
173
|
-
<label data-value>체적비(몰분율)</label>
|
174
|
-
<button hidden><md-icon>remove</md-icon></button>
|
175
|
-
<button hidden><md-icon>remove</md-icon></button>
|
176
|
-
${this.composable ? html` <button hidden><md-icon>remove</md-icon></button>` : nothing}
|
177
|
-
</div>
|
178
|
-
${arrayed.length
|
179
|
-
? arrayed.map(
|
180
|
-
(item, idx) => html`
|
181
|
-
<div data-record>
|
182
|
-
<input type="text" data-key .value=${item.key} disabled />
|
183
|
-
<input
|
184
|
-
type="number"
|
185
|
-
data-value
|
186
|
-
placeholder="fraction"
|
187
|
-
min="0"
|
188
|
-
max="1"
|
189
|
-
step="0.01"
|
190
|
-
.value=${String(item.value)}
|
191
|
-
list="value-template"
|
192
|
-
?disabled=${this.disabled}
|
193
|
-
/>
|
194
|
-
${this.composable
|
195
|
-
? html`
|
196
|
-
<button
|
197
|
-
class="record-action"
|
198
|
-
@click=${(e: MouseEvent) => this._delete(e)}
|
199
|
-
tabindex="-1"
|
200
|
-
?disabled=${this.disabled}
|
201
|
-
>
|
202
|
-
<md-icon>remove</md-icon>
|
203
|
-
</button>
|
204
|
-
`
|
205
|
-
: nothing}
|
206
|
-
<button
|
207
|
-
class="record-action"
|
208
|
-
@click=${(e: MouseEvent) => this._up(e)}
|
209
|
-
tabindex="-1"
|
210
|
-
?disabled=${this.disabled || idx === 0}
|
211
|
-
>
|
212
|
-
<md-icon>arrow_upward</md-icon>
|
213
|
-
</button>
|
214
|
-
<button
|
215
|
-
class="record-action"
|
216
|
-
@click=${(e: MouseEvent) => this._down(e)}
|
217
|
-
tabindex="-1"
|
218
|
-
?disabled=${this.disabled || idx === arrayed.length - 1}
|
219
|
-
>
|
220
|
-
<md-icon>arrow_downward</md-icon>
|
221
|
-
</button>
|
222
|
-
</div>
|
223
|
-
`
|
224
|
-
)
|
225
|
-
: html`<div nofraction>No Fractions</div>`}
|
226
|
-
</div>
|
227
|
-
|
228
|
-
${this.disabled
|
229
|
-
? nothing
|
230
|
-
: html`
|
231
|
-
<div data-record-new>
|
232
|
-
${this.composable
|
233
|
-
? html`
|
234
|
-
<ox-select
|
235
|
-
data-key
|
236
|
-
placeholder="Fluid"
|
237
|
-
.value=${live('')}
|
238
|
-
@change=${(e: Event) => {
|
239
|
-
e.stopPropagation()
|
240
|
-
}}
|
241
|
-
>
|
242
|
-
<ox-popup-list with-search> ${this.options} </ox-popup-list>
|
243
|
-
</ox-select>
|
244
|
-
|
245
|
-
<input
|
246
|
-
type="number"
|
247
|
-
data-value
|
248
|
-
placeholder="proportion"
|
249
|
-
min="0"
|
250
|
-
max="1"
|
251
|
-
step="0.01"
|
252
|
-
value=""
|
253
|
-
list="value-template"
|
254
|
-
/>
|
255
|
-
<button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
|
256
|
-
<md-icon>add</md-icon>
|
257
|
-
</button>
|
258
|
-
`
|
259
|
-
: nothing}
|
260
|
-
<button
|
261
|
-
title="fill with the values suggested"
|
262
|
-
@click=${() => {
|
263
|
-
this.value = { ...this.defaultValue }
|
264
|
-
this.dispatchChangeEvent()
|
265
|
-
}}
|
266
|
-
right-end
|
267
|
-
>
|
268
|
-
<md-icon>settings_suggest</md-icon>
|
269
|
-
</button>
|
270
|
-
<button
|
271
|
-
title="normalize fraction"
|
272
|
-
@click=${() => {
|
273
|
-
this._normalize()
|
274
|
-
}}
|
275
|
-
>
|
276
|
-
<md-icon>repartition</md-icon>
|
277
|
-
</button>
|
278
|
-
</div>
|
279
|
-
`}
|
280
|
-
`
|
281
|
-
}
|
282
|
-
|
283
|
-
_onChange(e: Event) {
|
284
|
-
if (this.changingNow) {
|
285
|
-
return
|
286
|
-
}
|
287
|
-
|
288
|
-
this.changingNow = true
|
289
|
-
|
290
|
-
const input = e.target as HTMLInputElement
|
291
|
-
|
292
|
-
const record = (e.target as Element).closest('[data-record],[data-record-new]') as HTMLElement
|
293
|
-
|
294
|
-
if (record.hasAttribute('data-record')) {
|
295
|
-
this._build()
|
296
|
-
} else if (record.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
297
|
-
this._add()
|
298
|
-
}
|
299
|
-
|
300
|
-
this.changingNow = false
|
301
|
-
}
|
302
|
-
|
303
|
-
_normalize() {
|
304
|
-
const fraction: MassFraction = this.value || {}
|
305
|
-
const sum = Object.values(fraction).reduce((a, b) => a + b, 0)
|
306
|
-
this.value = Object.keys(fraction).reduce((newvalue, key) => {
|
307
|
-
newvalue[key] = fraction[key] / sum
|
308
|
-
return newvalue
|
309
|
-
}, {} as MassFraction)
|
310
|
-
|
311
|
-
this.dispatchChangeEvent()
|
312
|
-
}
|
313
|
-
|
314
|
-
_build(includeNewRecord?: boolean) {
|
315
|
-
if (includeNewRecord) {
|
316
|
-
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
|
317
|
-
} else {
|
318
|
-
var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
|
319
|
-
}
|
320
|
-
|
321
|
-
var newmap: MassFraction = {}
|
322
|
-
|
323
|
-
for (var i = 0; i < records.length; i++) {
|
324
|
-
var record = records[i]
|
325
|
-
|
326
|
-
const key = (record.querySelector('[data-key]') as HTMLInputElement).value
|
327
|
-
const inputs = record.querySelectorAll(
|
328
|
-
'[data-value]:not([style*="display: none"])'
|
329
|
-
) as NodeListOf<HTMLInputElement>
|
330
|
-
|
331
|
-
if (!inputs || inputs.length == 0) {
|
332
|
-
continue
|
333
|
-
}
|
334
|
-
|
335
|
-
var input = inputs[inputs.length - 1]
|
336
|
-
|
337
|
-
var value = input.value
|
338
|
-
|
339
|
-
if (key) {
|
340
|
-
newmap[key] = Number(value) || 0
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
|
-
this.value = newmap
|
345
|
-
|
346
|
-
this.dispatchChangeEvent()
|
347
|
-
}
|
348
|
-
|
349
|
-
/* map아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
|
350
|
-
_toArray(map: MassFraction) {
|
351
|
-
var array: ArrayedMassFraction = []
|
352
|
-
|
353
|
-
for (var key in map) {
|
354
|
-
array.push({
|
355
|
-
key: key,
|
356
|
-
value: map[key]
|
357
|
-
})
|
358
|
-
}
|
359
|
-
|
360
|
-
return array
|
361
|
-
}
|
362
|
-
|
363
|
-
_add() {
|
364
|
-
this._build(true)
|
365
|
-
|
366
|
-
const inputs = this.renderRoot.querySelectorAll(
|
367
|
-
'[data-record-new] input:not([style*="display: none"])'
|
368
|
-
) as NodeListOf<HTMLInputElement & { value: any }>
|
369
|
-
|
370
|
-
for (var i = 0; i < inputs.length; i++) {
|
371
|
-
let input = inputs[i]
|
372
|
-
|
373
|
-
if (input.type == 'checkbox') input.checked = false
|
374
|
-
else input.value = ''
|
375
|
-
}
|
376
|
-
|
377
|
-
inputs[0].focus()
|
378
|
-
}
|
379
|
-
|
380
|
-
_delete(e: MouseEvent) {
|
381
|
-
const record = (e.target as Element).closest('[data-record]') as HTMLElement
|
382
|
-
|
383
|
-
;(record!.querySelector('[data-key]') as HTMLInputElement)!.value = ''
|
384
|
-
|
385
|
-
this._build()
|
386
|
-
}
|
387
|
-
|
388
|
-
_up(e: MouseEvent) {
|
389
|
-
const record = (e.target as Element).closest('[data-record]') as HTMLElement
|
390
|
-
const array = Array.from(this.records)
|
391
|
-
const index = array.indexOf(record) - 1
|
392
|
-
|
393
|
-
if (index < 0) {
|
394
|
-
return
|
395
|
-
}
|
396
|
-
|
397
|
-
const deleted = array.splice(index, 1)
|
398
|
-
array.splice(index + 1, 0, ...deleted)
|
399
|
-
|
400
|
-
this.value = array.reduce((sum, record) => {
|
401
|
-
const key = (record.querySelector('[data-key]') as HTMLInputElement).value
|
402
|
-
const value = (record.querySelector('[data-value]') as HTMLInputElement).value
|
403
|
-
|
404
|
-
sum[key] = Number(value) || 0
|
405
|
-
return sum
|
406
|
-
}, {} as MassFraction)
|
407
|
-
|
408
|
-
this.dispatchChangeEvent()
|
409
|
-
}
|
410
|
-
|
411
|
-
_down(e: MouseEvent) {
|
412
|
-
const record = (e.target as Element).closest('[data-record]') as HTMLElement
|
413
|
-
const array = Array.from(this.records)
|
414
|
-
const index = array.indexOf(record)
|
415
|
-
|
416
|
-
if (index > array.length) {
|
417
|
-
return
|
418
|
-
}
|
419
|
-
|
420
|
-
array.splice(index, 1)
|
421
|
-
array.splice(index + 1, 0, record)
|
422
|
-
|
423
|
-
this.value = array.reduce((sum, record) => {
|
424
|
-
const key = (record.querySelector('[data-key]') as HTMLInputElement).value
|
425
|
-
const value = (record.querySelector('[data-value]') as HTMLInputElement).value
|
426
|
-
|
427
|
-
sum[key] = Number(value) || 0
|
428
|
-
return sum
|
429
|
-
}, {} as MassFraction)
|
430
|
-
|
431
|
-
this.dispatchChangeEvent()
|
432
|
-
}
|
433
|
-
|
434
|
-
dispatchChangeEvent() {
|
435
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
436
|
-
}
|
437
|
-
}
|
@@ -1,135 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
import './ox-input-color.js'
|
6
|
-
import '@material/web/icon/icon.js'
|
7
|
-
|
8
|
-
import { css, html } from 'lit'
|
9
|
-
import { customElement, property, query, queryAll } from 'lit/decorators.js'
|
10
|
-
import { random as randomColor, TinyColor } from '@ctrl/tinycolor'
|
11
|
-
|
12
|
-
import { OxFormField } from './ox-form-field.js'
|
13
|
-
import { OxInputColor } from './ox-input-color.js'
|
14
|
-
|
15
|
-
/**
|
16
|
-
색상 배열을 편집하는 컴포넌트이다.
|
17
|
-
|
18
|
-
새로운 색상을 추가하고자 할 때는 `+` 버튼을 클릭한다.<br />
|
19
|
-
색상을 제거하고자 할 때는 `-` 버튼을 클릭한다.<br />
|
20
|
-
|
21
|
-
Example:
|
22
|
-
|
23
|
-
<ox-input-multiple-colors values=${values}>
|
24
|
-
</ox-input-multiple-colors>
|
25
|
-
*/
|
26
|
-
|
27
|
-
@customElement('ox-input-multiple-colors')
|
28
|
-
export class OxInputMultipleColors extends OxFormField {
|
29
|
-
static styles = css`
|
30
|
-
:host {
|
31
|
-
display: inline-block;
|
32
|
-
|
33
|
-
--md-icon-size: var(--fontsize-default, 14px);
|
34
|
-
}
|
35
|
-
|
36
|
-
#colors-container > div {
|
37
|
-
display: grid;
|
38
|
-
grid-template-columns: 34px 1fr 34px;
|
39
|
-
grid-gap: var(--spacing-medium);
|
40
|
-
align-items: center;
|
41
|
-
justify-content: left;
|
42
|
-
margin-bottom: var(--spacing-tiny, 2px);
|
43
|
-
}
|
44
|
-
|
45
|
-
ox-input-color {
|
46
|
-
width: 100%;
|
47
|
-
}
|
48
|
-
|
49
|
-
md-icon {
|
50
|
-
pointer-events: none;
|
51
|
-
}
|
52
|
-
|
53
|
-
button {
|
54
|
-
height: 100%;
|
55
|
-
border: var(--button-border);
|
56
|
-
border-radius: 0;
|
57
|
-
background-color: transparent;
|
58
|
-
line-height: 0.8;
|
59
|
-
color: var(--md-sys-color-on-surface);
|
60
|
-
cursor: pointer;
|
61
|
-
}
|
62
|
-
|
63
|
-
button:hover,
|
64
|
-
button:active {
|
65
|
-
border: var(--button-activ-border);
|
66
|
-
background-color: var(--md-sys-color-on-primary);
|
67
|
-
color: var(--md-sys-color-primary);
|
68
|
-
}
|
69
|
-
`
|
70
|
-
|
71
|
-
@property({ type: Array }) value: string[] = []
|
72
|
-
|
73
|
-
@query('#colors-container') colorsContainer!: HTMLDivElement
|
74
|
-
@queryAll('ox-input-color') colors!: NodeListOf<OxInputColor>
|
75
|
-
|
76
|
-
firstUpdated() {
|
77
|
-
this.renderRoot.addEventListener('change', this._onValueChanged.bind(this))
|
78
|
-
}
|
79
|
-
|
80
|
-
render() {
|
81
|
-
return html`
|
82
|
-
<div id="colors-container">
|
83
|
-
${(this.value || []).map(
|
84
|
-
(item, index) => html`
|
85
|
-
<div>
|
86
|
-
<button @tap=${(e: Event) => this._appendEditorColor(e)} data-index=${index} ?disabled=${this.disabled}>
|
87
|
-
<md-icon>add</md-icon>
|
88
|
-
</button>
|
89
|
-
<ox-input-color .value=${item} ?disabled=${this.disabled}> </ox-input-color>
|
90
|
-
|
91
|
-
${(this.value || []).length > 1
|
92
|
-
? html`
|
93
|
-
<button
|
94
|
-
@tap=${(e: Event) => this._removeEditorColor(e)}
|
95
|
-
data-index=${index}
|
96
|
-
?disabled=${this.disabled}
|
97
|
-
>
|
98
|
-
<md-icon>remove</md-icon>
|
99
|
-
</button>
|
100
|
-
`
|
101
|
-
: html``}
|
102
|
-
</div>
|
103
|
-
`
|
104
|
-
)}
|
105
|
-
</div>
|
106
|
-
`
|
107
|
-
}
|
108
|
-
|
109
|
-
_onValueChanged() {
|
110
|
-
this.value = Array.from(this.colors).map(color => color.value!)
|
111
|
-
}
|
112
|
-
|
113
|
-
_appendEditorColor(e: Event) {
|
114
|
-
const idx = Number((e.target as HTMLElement).getAttribute('data-index'))
|
115
|
-
const hue = this.value[idx] || '#fff'
|
116
|
-
this.value.splice(idx + 1, 0, randomColor({ hue }).toRgbString())
|
117
|
-
this.value = [...this.value]
|
118
|
-
|
119
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
120
|
-
}
|
121
|
-
|
122
|
-
_removeEditorColor(e: Event) {
|
123
|
-
var values = []
|
124
|
-
for (var i = 0; i < this.value.length; i++) {
|
125
|
-
if (i == Number((e.target as HTMLElement).getAttribute('data-index'))) {
|
126
|
-
continue
|
127
|
-
} else {
|
128
|
-
values.push(this.value[i])
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
this.value = values
|
133
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
134
|
-
}
|
135
|
-
}
|