@operato/input 8.0.0-beta.0 → 8.0.0-beta.2

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.
Files changed (121) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/package.json +7 -7
  3. package/.editorconfig +0 -29
  4. package/.storybook/main.js +0 -3
  5. package/.storybook/preview.js +0 -52
  6. package/.storybook/server.mjs +0 -8
  7. package/demo/index-3dish.html +0 -38
  8. package/demo/index-angle.html +0 -36
  9. package/demo/index-barcode.html +0 -68
  10. package/demo/index-button-radio.html +0 -42
  11. package/demo/index-checkbox.html +0 -69
  12. package/demo/index-code.html +0 -61
  13. package/demo/index-color-gradient.html +0 -35
  14. package/demo/index-color-stops.html +0 -62
  15. package/demo/index-color.html +0 -35
  16. package/demo/index-crontab.html +0 -37
  17. package/demo/index-file.html +0 -41
  18. package/demo/index-image.html +0 -40
  19. package/demo/index-multiple-colors.html +0 -52
  20. package/demo/index-options.html +0 -43
  21. package/demo/index-partition-keys.html +0 -79
  22. package/demo/index-range.html +0 -40
  23. package/demo/index-select.html +0 -136
  24. package/demo/index-stack.html +0 -33
  25. package/demo/index-table.html +0 -50
  26. package/demo/index-value-map.html +0 -80
  27. package/demo/index-value-ranges.html +0 -80
  28. package/demo/index-work-shift.html +0 -59
  29. package/demo/index.html +0 -54
  30. package/src/index.ts +0 -35
  31. package/src/locale/locale-codes.ts +0 -18
  32. package/src/locale/locale-picker.ts +0 -43
  33. package/src/locale/localization.ts +0 -15
  34. package/src/locales/en.ts +0 -30
  35. package/src/locales/ko.ts +0 -30
  36. package/src/locales/ms.ts +0 -30
  37. package/src/locales/zh.ts +0 -30
  38. package/src/ox-buttons-radio.ts +0 -140
  39. package/src/ox-checkbox.ts +0 -181
  40. package/src/ox-form-field.ts +0 -53
  41. package/src/ox-input-3axis.ts +0 -77
  42. package/src/ox-input-3dish.ts +0 -211
  43. package/src/ox-input-angle.ts +0 -73
  44. package/src/ox-input-barcode.ts +0 -318
  45. package/src/ox-input-code.ts +0 -139
  46. package/src/ox-input-color-gradient.ts +0 -349
  47. package/src/ox-input-color-stops.ts +0 -525
  48. package/src/ox-input-color.ts +0 -338
  49. package/src/ox-input-container.ts +0 -32
  50. package/src/ox-input-crontab.ts +0 -595
  51. package/src/ox-input-data.ts +0 -219
  52. package/src/ox-input-direction.ts +0 -92
  53. package/src/ox-input-duration.ts +0 -175
  54. package/src/ox-input-file.ts +0 -209
  55. package/src/ox-input-hashtags.ts +0 -185
  56. package/src/ox-input-i18n-label.ts +0 -140
  57. package/src/ox-input-image.ts +0 -168
  58. package/src/ox-input-key-values.ts +0 -301
  59. package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
  60. package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
  61. package/src/ox-input-layout/ox-input-layout.ts +0 -77
  62. package/src/ox-input-mass-fraction.ts +0 -437
  63. package/src/ox-input-multiple-colors.ts +0 -135
  64. package/src/ox-input-options.ts +0 -216
  65. package/src/ox-input-partition-keys.ts +0 -303
  66. package/src/ox-input-privilege.ts +0 -163
  67. package/src/ox-input-quantifier.ts +0 -62
  68. package/src/ox-input-range.ts +0 -146
  69. package/src/ox-input-scene-component-id.ts +0 -73
  70. package/src/ox-input-search.ts +0 -126
  71. package/src/ox-input-select-buttons.ts +0 -75
  72. package/src/ox-input-signature.ts +0 -208
  73. package/src/ox-input-stack.ts +0 -136
  74. package/src/ox-input-switch.ts +0 -117
  75. package/src/ox-input-table-column-config.ts +0 -211
  76. package/src/ox-input-table.ts +0 -404
  77. package/src/ox-input-textarea.ts +0 -86
  78. package/src/ox-input-unit-number.ts +0 -354
  79. package/src/ox-input-value-map.ts +0 -342
  80. package/src/ox-input-value-ranges.ts +0 -363
  81. package/src/ox-input-work-shift.ts +0 -290
  82. package/src/ox-select-floor.ts +0 -246
  83. package/src/ox-select.ts +0 -219
  84. package/stories/image-for-select-floor.ts +0 -2
  85. package/stories/ox-buttons-radio.stories.ts +0 -89
  86. package/stories/ox-checkbox.stories.ts +0 -111
  87. package/stories/ox-input-3axis.stories.ts +0 -77
  88. package/stories/ox-input-3dish.stories.ts +0 -106
  89. package/stories/ox-input-angle.stories.ts +0 -84
  90. package/stories/ox-input-barcode.stories.ts +0 -117
  91. package/stories/ox-input-code.stories.ts +0 -99
  92. package/stories/ox-input-crontab.stories.ts +0 -82
  93. package/stories/ox-input-data.stories.ts +0 -82
  94. package/stories/ox-input-direction.stories.ts +0 -91
  95. package/stories/ox-input-duration.stories.ts +0 -84
  96. package/stories/ox-input-file.stories.ts +0 -111
  97. package/stories/ox-input-hashtags.stories.ts +0 -82
  98. package/stories/ox-input-i18n-label.stories.ts +0 -103
  99. package/stories/ox-input-key-values.stories.ts +0 -97
  100. package/stories/ox-input-mass-fraction.stories.ts +0 -102
  101. package/stories/ox-input-multiple-colors.stories.ts +0 -72
  102. package/stories/ox-input-options.stories.ts +0 -80
  103. package/stories/ox-input-partition-keys.stories.ts +0 -84
  104. package/stories/ox-input-privilege.stories.ts +0 -108
  105. package/stories/ox-input-quantifier.stories.ts +0 -80
  106. package/stories/ox-input-range.stories.ts +0 -89
  107. package/stories/ox-input-search.stories.ts +0 -91
  108. package/stories/ox-input-select-buttons.stories.ts +0 -118
  109. package/stories/ox-input-signature.stories.ts +0 -75
  110. package/stories/ox-input-switch.stories.ts +0 -91
  111. package/stories/ox-input-table-column-config.stories.ts +0 -109
  112. package/stories/ox-input-unit.stories.ts +0 -151
  113. package/stories/ox-input-value-map.stories.ts +0 -92
  114. package/stories/ox-input-value-ranges.stories.ts +0 -92
  115. package/stories/ox-input-work-shift.stories.ts +0 -106
  116. package/stories/ox-select-floor.stories.ts +0 -197
  117. package/stories/ox-select-set-options.stories.ts +0 -208
  118. package/stories/ox-select.stories.ts +0 -181
  119. package/tsconfig.json +0 -25
  120. package/web-dev-server.config.mjs +0 -27
  121. package/web-test-runner.config.mjs +0 -41
@@ -1,219 +0,0 @@
1
- import './ox-input-code'
2
-
3
- import { css, html } from 'lit'
4
- import { customElement } from 'lit/decorators.js'
5
- import { live } from 'lit/directives/live.js'
6
-
7
- import { OxFormField } from './ox-form-field.js'
8
- import { OxInputCode } from './ox-input-code.js'
9
- import { isEqual } from 'lodash-es'
10
- import 'ses'
11
-
12
- /**
13
- WEB Component for code-mirror based data editor.
14
-
15
- Example:
16
-
17
- <ox-input-data value=${text}>
18
- </ox-input-data>
19
- */
20
- @customElement('ox-input-data')
21
- export class OxInputData extends OxFormField {
22
- static styles = [
23
- css`
24
- :host {
25
- display: flex;
26
- flex-direction: column;
27
- position: relative;
28
- }
29
-
30
- div.datatype {
31
- display: flex;
32
- align-items: center;
33
- margin-bottom: var(--spacing-small);
34
- padding: var(--spacing-small);
35
- background-color: var(--md-sys-color-primary-container);
36
- border: 1px solid var(--md-sys-color-primary-fixed-dim);
37
- border-radius: var(--md-sys-shape-corner-small);
38
- font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
39
- color: var(--md-sys-color-on-primary-container);
40
- }
41
-
42
- div.datatype md-icon {
43
- margin-left: auto;
44
- color: var(--md-sys-color-primary);
45
- cursor: pointer;
46
- }
47
- div.datatype label {
48
- margin-right: var(--spacing-small);
49
- }
50
-
51
- ox-input-code {
52
- flex: 1;
53
- max-width: 260px;
54
- overflow: auto;
55
- }
56
- `
57
- ]
58
-
59
- render() {
60
- const valueType = typeof this.value
61
-
62
- return html`
63
- <div class="datatype">
64
- <input
65
- id="string"
66
- type="radio"
67
- name="data-type"
68
- data-value="string"
69
- .checked=${live(valueType == 'string')}
70
- @click=${() => this._setDataType('string')}
71
- ?disabled=${this.disabled}
72
- />
73
- <label for="string">string</label>
74
-
75
- <input
76
- id="number"
77
- type="radio"
78
- name="data-type"
79
- data-value="number"
80
- .checked=${live(valueType == 'number')}
81
- @click=${() => this._setDataType('number')}
82
- ?disabled=${this.disabled}
83
- />
84
- <label for="number">number</label>
85
-
86
- <input
87
- id="object"
88
- type="radio"
89
- name="data-type"
90
- data-value="object"
91
- .checked=${live(valueType == 'object')}
92
- @click=${() => this._setDataType('object')}
93
- ?disabled=${this.disabled}
94
- />
95
- <label for="object">object</label>
96
-
97
- <md-icon @click=${() => this._clearData()} title="delete">delete_forever</md-icon>
98
- </div>
99
-
100
- <ox-input-code
101
- .value=${this._getStringData(this.value)}
102
- language="text"
103
- editor
104
- ?disabled=${this.disabled}
105
- @change=${(e: CustomEvent) => {
106
- e.stopPropagation()
107
- this._setDataTypeAndValue(valueType, (e.target as any).value)
108
- }}
109
- >
110
- </ox-input-code>
111
- `
112
- }
113
-
114
- firstUpdated() {
115
- this.renderRoot.addEventListener('change', e => {
116
- e.stopPropagation()
117
-
118
- const target = e.target as OxInputCode
119
- if (target.hasAttribute('editor')) {
120
- if (this.value === undefined && target.value == '') {
121
- return
122
- }
123
- this.value = target.value
124
- }
125
- })
126
- }
127
-
128
- _setDataTypeAndValue(type: string | undefined | null, value: any) {
129
- /* value must be a string */
130
- try {
131
- switch (type) {
132
- case 'number':
133
- if (!isNaN(Number(value))) {
134
- value = Number(value)
135
- }
136
- break
137
- case 'object':
138
- const compartment = new Compartment()
139
- value = compartment.evaluate(`(${value})`)
140
- break
141
- }
142
- } catch (e) {
143
- console.error('Error parsing value:', e)
144
- }
145
-
146
- if (isEqual(this.value, value)) {
147
- return
148
- }
149
-
150
- this.value = value
151
-
152
- this.requestUpdate()
153
- this._onAfterValueChange()
154
- }
155
-
156
- _setDataType(type: string | undefined | null) {
157
- if (typeof this.value == type) {
158
- return
159
- }
160
-
161
- var value = this.value
162
-
163
- try {
164
- switch (type) {
165
- case 'string':
166
- value = this._getStringData(value)
167
- break
168
- case 'number':
169
- if (!isNaN(value)) {
170
- value = Number(value)
171
- }
172
- break
173
- case 'object':
174
- const compartment = new Compartment()
175
- value = compartment.evaluate(`(${value})`)
176
- break
177
- }
178
- } catch (e) {
179
- console.error('Error setting data type:', e)
180
- }
181
-
182
- if (isEqual(this.value, value)) {
183
- this.requestUpdate()
184
- return
185
- }
186
-
187
- this.value = value
188
-
189
- this.requestUpdate()
190
- this._onAfterValueChange()
191
- }
192
-
193
- _clearData() {
194
- this.value = undefined
195
- this._onAfterValueChange()
196
- }
197
-
198
- _getStringData(data: any) {
199
- const type = typeof data
200
-
201
- switch (type) {
202
- case 'object':
203
- return JSON.stringify(data, null, 1)
204
- case 'undefined':
205
- return ''
206
- default:
207
- return String(data) || ''
208
- }
209
- }
210
-
211
- async _onAfterValueChange() {
212
- this.dispatchEvent(
213
- new CustomEvent('change', {
214
- bubbles: true,
215
- composed: true
216
- })
217
- )
218
- }
219
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import '@material/web/icon/icon.js'
6
-
7
- import { css, html } from 'lit'
8
- import { customElement, property } from 'lit/decorators.js'
9
-
10
- import { OxFormField } from './ox-form-field'
11
-
12
- @customElement('ox-input-direction')
13
- export class OxInputDirection extends OxFormField {
14
- static styles = css`
15
- :host {
16
- --md-icon-size: 1.4em;
17
- }
18
-
19
- div {
20
- display: flex;
21
- justify-content: space-between;
22
- max-width: 140px;
23
- }
24
-
25
- md-icon {
26
- color: var(--md-sys-color-on-background);
27
- background-color: var(--md-sys-color-background);
28
- }
29
-
30
- md-icon[selected] {
31
- color: var(--md-sys-color-on-primary);
32
- background-color: var(--md-sys-color-primary);
33
- }
34
-
35
- /* 아이콘 회전 */
36
- md-icon[data-value='W'] {
37
- transform: rotate(-90deg);
38
- }
39
-
40
- md-icon[data-value='N'] {
41
- transform: rotate(0deg);
42
- }
43
-
44
- md-icon[data-value='S'] {
45
- transform: rotate(180deg);
46
- }
47
-
48
- md-icon[data-value='E'] {
49
- transform: rotate(90deg);
50
- }
51
- `
52
-
53
- @property({ type: String }) value?: string
54
- @property({ type: Boolean }) inbound?: boolean = false
55
-
56
- render() {
57
- const value = this.value
58
-
59
- return html`
60
- <div @click=${this.onClick.bind(this)}>
61
- ${this.inbound
62
- ? html`
63
- <md-icon ?selected=${value == 'W'} data-value="W">step_into</md-icon>
64
- <md-icon ?selected=${value == 'N'} data-value="N">step_into</md-icon>
65
- <md-icon ?selected=${value == 'S'} data-value="S">step_into</md-icon>
66
- <md-icon ?selected=${value == 'E'} data-value="E">step_into</md-icon>
67
- `
68
- : html`
69
- <md-icon ?selected=${value == 'W'} data-value="W">step_out</md-icon>
70
- <md-icon ?selected=${value == 'N'} data-value="N">step_out</md-icon>
71
- <md-icon ?selected=${value == 'S'} data-value="S">step_out</md-icon>
72
- <md-icon ?selected=${value == 'E'} data-value="E">step_out</md-icon>
73
- `}
74
- </div>
75
- `
76
- }
77
-
78
- onClick(e: MouseEvent) {
79
- e.stopPropagation()
80
-
81
- if (this.disabled) {
82
- return
83
- }
84
-
85
- const target = e.target as Element
86
- const value = target.getAttribute('data-value') as string
87
-
88
- this.value = this.value === value ? undefined : value
89
-
90
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
91
- }
92
- }
@@ -1,175 +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 { i18next } from '@operato/i18n'
9
-
10
- import { OxFormField } from './ox-form-field'
11
-
12
- @customElement('ox-input-duration')
13
- export class OxInputDuration extends OxFormField {
14
- static styles = css`
15
- :host {
16
- text-align: center;
17
- padding: 10px;
18
- --md-filled-icon-button-container-height: var(--form-element-height-medium);
19
- --md-filled-icon-button-container-shape: var(--md-sys-shape-corner-small);
20
- }
21
-
22
- :host * {
23
- box-sizing: border-box;
24
- }
25
-
26
- :host *:focus {
27
- outline: none;
28
- }
29
-
30
- form {
31
- display: flex;
32
- flex-direction: row;
33
-
34
- align-items: center;
35
- }
36
-
37
- [padding] {
38
- min-width: 100px;
39
- }
40
-
41
- input {
42
- box-sizing: border-box;
43
- padding: 0 var(--spacing-small);
44
- height: var(--form-element-height-medium);
45
- border: 1px solid var(--md-sys-color-outline);
46
- border-radius: var(--md-sys-shape-corner-small);
47
- max-width: 70px;
48
- font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
49
- color: var(--md-sys-color-on-primary-container);
50
- text-align: right;
51
- }
52
-
53
- input:focus {
54
- outline: none;
55
- border-color: var(--md-sys-color-secondary-fixed-dim);
56
- }
57
-
58
- input:invalid {
59
- border-bottom: 1px solid var(--md-sys-color-error);
60
- color: var(--md-sys-color-error);
61
- }
62
-
63
- label {
64
- width: 100%;
65
- margin-right: var(--spacing-medium);
66
- font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
67
- color: var(--md-sys-color-on-primary-container);
68
- }
69
- `
70
-
71
- @property({ type: Number }) value?: number
72
-
73
- render() {
74
- var d = Number(this.value || 0)
75
-
76
- const days = Math.floor(d / (3600 * 24))
77
- d -= days * 24 * 3600
78
- const hours = Math.floor(d / 3600)
79
- d -= hours * 3600
80
- const minutes = Math.floor(d / 60)
81
- const seconds = d - minutes * 60
82
-
83
- return html`
84
- <form @change=${this.onChange.bind(this)}>
85
- <div padding></div>
86
- <input id="days" type="number" .value=${String(days || 0)} pattern="\\d*" ?disabled=${this.disabled} />
87
- <label for="days">${i18next.t('label.days')}</label>
88
-
89
- <input
90
- id="hours"
91
- type="number"
92
- .value=${String(hours || 0)}
93
- pattern="[01]?\\d|2[0-3]"
94
- ?disabled=${this.disabled}
95
- />
96
- <label for="hour">${i18next.t('label.hours')}</label>
97
-
98
- <input
99
- id="minutes"
100
- type="number"
101
- .value=${String(minutes || 0)}
102
- pattern="[0-5]?\\d"
103
- ?disabled=${this.disabled}
104
- />
105
- <label for="minute">${i18next.t('label.minutes')}</label>
106
-
107
- <input
108
- id="seconds"
109
- type="number"
110
- .value=${String(seconds || 0)}
111
- pattern="[0-5]?\\d"
112
- ?disabled=${this.disabled}
113
- />
114
- <label for="second">${i18next.t('label.seconds')}</label>
115
-
116
- <md-filled-icon-button
117
- type="button"
118
- @click=${(e: Event) => {
119
- e.preventDefault()
120
- e.stopPropagation()
121
-
122
- this.value = 0
123
-
124
- this.dispatchEvent(
125
- new CustomEvent('change', {
126
- bubbles: true,
127
- composed: true,
128
- detail: this.value
129
- })
130
- )
131
- }}
132
- ?disabled=${this.disabled}
133
- >
134
- <md-icon>backspace</md-icon>
135
- </md-filled-icon-button>
136
- <div padding></div>
137
- </form>
138
- `
139
- }
140
-
141
- firstUpdated() {
142
- ;(this.renderRoot.querySelector('input') as HTMLInputElement).focus()
143
- }
144
-
145
- @query('#days') days!: HTMLInputElement
146
- @query('#hours') hours!: HTMLInputElement
147
- @query('#minutes') minutes!: HTMLInputElement
148
- @query('#seconds') seconds!: HTMLInputElement
149
-
150
- onChange(e: Event) {
151
- e.stopPropagation()
152
-
153
- var form = this.renderRoot.querySelector('form') as HTMLFormElement
154
- var valid = form.checkValidity()
155
- if (!valid) {
156
- form.reportValidity()
157
- return
158
- }
159
-
160
- const days = Number(this.days.value)
161
- const hours = Number(this.hours.value)
162
- const minutes = Number(this.minutes.value)
163
- const seconds = Number(this.seconds.value)
164
-
165
- this.value = (days || 0) * 24 * 60 * 60 + (hours || 0) * 60 * 60 + (minutes || 0) * 60 + (seconds || 0)
166
-
167
- this.dispatchEvent(
168
- new CustomEvent('change', {
169
- bubbles: true,
170
- composed: true,
171
- detail: this.value
172
- })
173
- )
174
- }
175
- }
@@ -1,209 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import '@material/web/icon/icon.js'
6
-
7
- import { css, html, PropertyValues } from 'lit'
8
- import { customElement, property, query } from 'lit/decorators.js'
9
-
10
- import { ScrollbarStyles } from '@operato/styles'
11
- import { FileDropHelper } from '@operato/utils'
12
-
13
- import { OxFormField } from './ox-form-field.js'
14
-
15
- @customElement('ox-input-file')
16
- export class OxInputFile extends OxFormField {
17
- static styles = [
18
- ScrollbarStyles,
19
- css`
20
- :host {
21
- display: flex;
22
- flex-direction: column;
23
- border-radius: var(--md-sys-shape-corner-small);
24
- align-items: center;
25
- justify-content: center;
26
- padding: var(--padding-default, 9px);
27
- min-height: 100px;
28
- text-transform: capitalize;
29
-
30
- border: 1px dashed var(--md-sys-color-outline-variant);
31
- background-color: var(--md-sys-color-surface);
32
- font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
33
- }
34
- :host > span {
35
- color: var(--md-sys-color-primary);
36
- font-weight: var(--md-sys-typescale-label-medium-weight, var(--md-ref-typeface-weight-medium, 500));
37
- }
38
-
39
- :host > md-icon {
40
- color: var(--md-sys-color-primary);
41
- --md-icon-size: var(--file-uploader-icon-size, 36px);
42
- }
43
-
44
- :host(.candrop) {
45
- background-color: var(--md-sys-color-primary-fixed);
46
- border: 1px dashed var(--md-sys-color-primary-fixed-dim);
47
- }
48
-
49
- #input-file {
50
- display: none;
51
- }
52
-
53
- label {
54
- position: relative;
55
- width: auto;
56
- border: none;
57
- text-transform: capitalize;
58
-
59
- padding: var(--file-uploader-label-padding);
60
- border-radius: var(--file-uploader-label-border-radius);
61
- font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
62
- color: var(--md-sys-color-on-surface-variant);
63
- }
64
-
65
- ul {
66
- max-width: 500px;
67
- width: 100%;
68
- list-style: none;
69
- margin: 5px 0 0 0;
70
- padding: 0;
71
- max-height: 46px;
72
- overflow: auto;
73
- background-color: var(--md-sys-color-on-primary);
74
- }
75
- li {
76
- text-align: left;
77
-
78
- padding: 3px 5px 2px 5px;
79
- border-bottom: var(--file-uploader-li-border-bottom);
80
- font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
81
- color: var(--md-sys-color-on-primary-container);
82
- display: flex;
83
- align-items: center;
84
- }
85
- li md-icon {
86
- cursor: pointer;
87
- font-size: var(--icon-size-small);
88
- margin-left: auto;
89
- }
90
- li md-icon:hover,
91
- li md-icon:active {
92
- color: var(--md-sys-color-error);
93
- }
94
- `
95
- ]
96
-
97
- @property({ type: Boolean }) multiple?: boolean
98
- @property({ type: String }) accept?: string
99
- @property({ type: String }) icon?: string = 'upload'
100
- @property({ type: String }) label?: string
101
- @property({ type: String }) description?: string = 'drop files here!'
102
- @property({ type: Boolean, reflect: true, attribute: 'hide-filelist' })
103
- hideFileList: boolean = false
104
- @property({ type: Boolean, reflect: true, attribute: 'attach-filelist' })
105
- attachFileList: boolean = false
106
-
107
- @query('#input-file') fileInput!: HTMLInputElement
108
-
109
- render() {
110
- var files: File[] = this.value || []
111
-
112
- return html`
113
- <md-icon>${this.icon || 'upload'}</md-icon>
114
-
115
- <span>${this.description || 'drop files here!'}</span>
116
-
117
- <input
118
- id="input-file"
119
- type="file"
120
- accept=${this.accept}
121
- ?multiple=${this.multiple}
122
- hidden
123
- capture="environment"
124
- @change=${(e: Event) => this._onChangeValue(e)}
125
- ?disabled=${this.disabled}
126
- />
127
-
128
- <label for="input-file">${this.label || 'select files'}</label>
129
-
130
- ${!this.hideFileList && files?.length
131
- ? html` <ul>
132
- ${files.map(
133
- file => html`
134
- <li>
135
- - ${file.name}
136
- <md-icon
137
- @click=${(e: Event) => {
138
- if (this.disabled) {
139
- return
140
- }
141
- files.splice(files.indexOf(file), 1)
142
- this.value = [...files]
143
- this._notifyChange()
144
- }}
145
- >delete_outline</md-icon
146
- >
147
- </li>
148
- `
149
- )}
150
- </ul>`
151
- : html``}
152
- `
153
- }
154
-
155
- updated(changes: PropertyValues<this>) {
156
- if (changes.has('value') && !(this.value instanceof Array)) {
157
- this.value = !this.value ? [] : [this.value]
158
- }
159
- }
160
-
161
- firstUpdated() {
162
- FileDropHelper.set(this)
163
-
164
- this.addEventListener('file-drop', (e: Event) => {
165
- if (this.disabled) {
166
- return
167
- }
168
-
169
- const detail = (e as CustomEvent).detail
170
- this.value = this.multiple ? detail : detail[0] ? [detail[0]] : []
171
-
172
- this._notifyChange()
173
- })
174
- }
175
-
176
- get files() {
177
- return this.value
178
- }
179
-
180
- reset() {
181
- this.fileInput.value = ''
182
- this.value = []
183
-
184
- this._notifyChange()
185
- }
186
-
187
- _onChangeValue(e: Event) {
188
- const fileInput = e.currentTarget as HTMLInputElement
189
- const files = this.value || []
190
-
191
- this.value = this.attachFileList
192
- ? [...files, ...Array.from(fileInput.files as FileList)]
193
- : [...Array.from(fileInput.files as FileList)]
194
-
195
- fileInput.files = null
196
-
197
- this._notifyChange()
198
- }
199
-
200
- _notifyChange() {
201
- this.dispatchEvent(
202
- new CustomEvent('change', {
203
- bubbles: true,
204
- composed: true,
205
- detail: this.value
206
- })
207
- )
208
- }
209
- }