@operato/input 1.13.11 → 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,
@@ -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
+ }