@operato/input 1.13.9 → 1.13.12

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.
@@ -5,7 +5,8 @@
5
5
  import './ox-input-code'
6
6
 
7
7
  import { css, html, PropertyValues } from 'lit'
8
- import { customElement } from 'lit/decorators.js'
8
+ import { customElement, state } from 'lit/decorators.js'
9
+ import { live } from 'lit/directives/live.js'
9
10
 
10
11
  import { OxFormField } from './ox-form-field.js'
11
12
  import { OxInputCode } from './ox-input-code.js'
@@ -49,34 +50,43 @@ export class OxInputData extends OxFormField {
49
50
  ]
50
51
 
51
52
  render() {
53
+ const valueType = typeof this.value
54
+
52
55
  return html`
53
56
  <div datatype>
54
57
  <input
58
+ id="string"
55
59
  type="radio"
56
60
  name="data-type"
57
61
  data-value="string"
58
- .checked=${typeof this.value == 'string'}
62
+ .checked=${live(valueType == 'string')}
59
63
  @click=${() => this._setDataType('string')}
60
64
  ?disabled=${this.disabled}
61
- />string
65
+ />
66
+ <label for="string">string</label>
62
67
 
63
68
  <input
69
+ id="number"
64
70
  type="radio"
65
71
  name="data-type"
66
72
  data-value="number"
67
- .checked=${typeof this.value == 'number'}
73
+ .checked=${live(valueType == 'number')}
68
74
  @click=${() => this._setDataType('number')}
69
75
  ?disabled=${this.disabled}
70
- />number
76
+ />
77
+ <label for="number">number</label>
71
78
 
72
79
  <input
80
+ id="object"
73
81
  type="radio"
74
82
  name="data-type"
75
83
  data-value="object"
76
- .checked=${typeof this.value == 'object'}
84
+ .checked=${live(valueType == 'object')}
77
85
  @click=${() => this._setDataType('object')}
78
86
  ?disabled=${this.disabled}
79
- />object
87
+ />
88
+ <label for="object">object</label>
89
+
80
90
  <mwc-icon @click=${() => this._clearData()} title="delete">delete_forever</mwc-icon>
81
91
  </div>
82
92
 
@@ -98,12 +108,6 @@ export class OxInputData extends OxFormField {
98
108
  })
99
109
  }
100
110
 
101
- udpated(changes: PropertyValues<this>) {
102
- if (changes.has('value')) {
103
- this.value = this._getData(this.value)
104
- }
105
- }
106
-
107
111
  _setDataType(type: string | undefined | null) {
108
112
  if (typeof this.value !== type) {
109
113
  var value = this.value
@@ -111,7 +115,7 @@ export class OxInputData extends OxFormField {
111
115
  try {
112
116
  switch (type) {
113
117
  case 'string':
114
- this.value = String(value || '')
118
+ this.value = this._getData(value)
115
119
  break
116
120
  case 'number':
117
121
  if (!isNaN(value)) {
@@ -127,6 +131,7 @@ export class OxInputData extends OxFormField {
127
131
  }
128
132
  }
129
133
 
134
+ this.requestUpdate()
130
135
  this._onAfterValueChange()
131
136
  }
132
137
 
@@ -139,7 +144,7 @@ export class OxInputData extends OxFormField {
139
144
  return typeof data !== 'object' ? data || '' : JSON.stringify(data, null, 1)
140
145
  }
141
146
 
142
- _onAfterValueChange() {
147
+ async _onAfterValueChange() {
143
148
  this.dispatchEvent(
144
149
  new CustomEvent('change', {
145
150
  bubbles: true,
@@ -131,11 +131,16 @@ export class OxInputMassFraction extends OxFormField {
131
131
  display: block;
132
132
  text-align: center;
133
133
  }
134
+
135
+ [right-end] {
136
+ margin-left: auto;
137
+ }
134
138
  `
135
139
  ]
136
140
 
137
141
  @property({ type: Object }) defaultValue: MassFraction = {}
138
142
  @property({ type: Object }) value: MassFraction = {}
143
+ @property({ type: Boolean, attribute: true }) composable: boolean = false
139
144
 
140
145
  @queryAll('[data-record]') records!: NodeListOf<HTMLElement>
141
146
 
@@ -168,14 +173,18 @@ export class OxInputMassFraction extends OxFormField {
168
173
  list="value-template"
169
174
  ?disabled=${this.disabled}
170
175
  />
171
- <button
172
- class="record-action"
173
- @click=${(e: MouseEvent) => this._delete(e)}
174
- tabindex="-1"
175
- ?disabled=${this.disabled}
176
- >
177
- <mwc-icon>remove</mwc-icon>
178
- </button>
176
+ ${this.composable
177
+ ? html`
178
+ <button
179
+ class="record-action"
180
+ @click=${(e: MouseEvent) => this._delete(e)}
181
+ tabindex="-1"
182
+ ?disabled=${this.disabled}
183
+ >
184
+ <mwc-icon>remove</mwc-icon>
185
+ </button>
186
+ `
187
+ : nothing}
179
188
  <button
180
189
  class="record-action"
181
190
  @click=${(e: MouseEvent) => this._up(e)}
@@ -202,36 +211,41 @@ export class OxInputMassFraction extends OxFormField {
202
211
  ? nothing
203
212
  : html`
204
213
  <div data-record-new>
205
- <ox-select
206
- data-key
207
- placeholder="Fluid"
208
- .value=${live('')}
209
- @change=${(e: Event) => {
210
- e.stopPropagation()
211
- }}
212
- >
213
- <ox-popup-list with-search> ${this.options} </ox-popup-list>
214
- </ox-select>
215
-
216
- <input
217
- type="number"
218
- data-value
219
- placeholder="proportion"
220
- min="0"
221
- max="1"
222
- step="0.01"
223
- value=""
224
- list="value-template"
225
- />
226
- <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
227
- <mwc-icon>add</mwc-icon>
228
- </button>
214
+ ${this.composable
215
+ ? html`
216
+ <ox-select
217
+ data-key
218
+ placeholder="Fluid"
219
+ .value=${live('')}
220
+ @change=${(e: Event) => {
221
+ e.stopPropagation()
222
+ }}
223
+ >
224
+ <ox-popup-list with-search> ${this.options} </ox-popup-list>
225
+ </ox-select>
226
+
227
+ <input
228
+ type="number"
229
+ data-value
230
+ placeholder="proportion"
231
+ min="0"
232
+ max="1"
233
+ step="0.01"
234
+ value=""
235
+ list="value-template"
236
+ />
237
+ <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
238
+ <mwc-icon>add</mwc-icon>
239
+ </button>
240
+ `
241
+ : nothing}
229
242
  <button
230
243
  title="fill with the values suggested"
231
244
  @click=${() => {
232
245
  this.value = { ...this.defaultValue }
233
246
  this.dispatchChangeEvent()
234
247
  }}
248
+ right-end
235
249
  >
236
250
  <mwc-icon>settings_suggest</mwc-icon>
237
251
  </button>
@@ -0,0 +1,55 @@
1
+ import '../src/ox-input-data.js'
2
+
3
+ import { html, TemplateResult } from 'lit'
4
+
5
+ export default {
6
+ title: 'ox-input-data',
7
+ component: 'ox-input-data',
8
+ argTypes: {
9
+ value: { control: 'text' },
10
+ name: { control: 'text' },
11
+ language: { control: 'select', options: ['javascript', 'sql', 'json'] },
12
+ disabled: { control: 'boolean' }
13
+ }
14
+ }
15
+
16
+ interface Story<T> {
17
+ (args: T): TemplateResult
18
+ args?: Partial<T>
19
+ argTypes?: Record<string, unknown>
20
+ }
21
+
22
+ interface ArgTypes {
23
+ name?: string
24
+ value?: string | number | object
25
+ disabled?: boolean
26
+ }
27
+
28
+ const Template: Story<ArgTypes> = ({ name = 'code', value = '', disabled }: ArgTypes) => html`
29
+ <link href="/themes/app-theme.css" rel="stylesheet" />
30
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
31
+ <style>
32
+ body {
33
+ }
34
+ ox-input-data {
35
+ height: 300px;
36
+ }
37
+ </style>
38
+
39
+ <ox-input-data
40
+ @change=${(e: Event) => {
41
+ const value = (e.target as HTMLInputElement).value
42
+ console.log('value : ', value, typeof value)
43
+ }}
44
+ name=${name}
45
+ .value=${value}
46
+ ?disabled=${disabled}
47
+ >
48
+ </ox-input-data>
49
+ `
50
+
51
+ export const Regular = Template.bind({})
52
+ Regular.args = {
53
+ name: 'data',
54
+ value: ''
55
+ }
@@ -9,6 +9,7 @@ export default {
9
9
  name: { control: 'text' },
10
10
  value: { control: 'object' },
11
11
  defaultValue: { control: 'object' },
12
+ composable: { control: 'boolean' },
12
13
  disabled: { control: 'boolean' }
13
14
  }
14
15
  }
@@ -23,6 +24,7 @@ interface ArgTypes {
23
24
  name?: string
24
25
  value?: object
25
26
  defaultValue?: object
27
+ composable?: boolean
26
28
  disabled?: boolean
27
29
  }
28
30
 
@@ -30,6 +32,7 @@ const Template: Story<ArgTypes> = ({
30
32
  name = 'mass-fraction',
31
33
  value = {},
32
34
  defaultValue = {},
35
+ composable = true,
33
36
  disabled
34
37
  }: ArgTypes) => html`
35
38
  <link href="/themes/app-theme.css" rel="stylesheet" />
@@ -46,6 +49,7 @@ const Template: Story<ArgTypes> = ({
46
49
  name=${name}
47
50
  .value=${value}
48
51
  .defaultValue=${defaultValue}
52
+ ?composable=${composable}
49
53
  ?disabled=${disabled}
50
54
  >
51
55
  </ox-input-mass-fraction>
@@ -54,7 +58,12 @@ const Template: Story<ArgTypes> = ({
54
58
  export const Regular = Template.bind({})
55
59
  Regular.args = {
56
60
  name: 'mass-fraction',
57
- value: {},
61
+ value: {
62
+ H2O: 0.8,
63
+ N2O: 0.1,
64
+ CO2: 0.1
65
+ },
66
+ composable: true,
58
67
  defaultValue: {
59
68
  H2O: 0.8,
60
69
  N2O: 0.1,