@operato/input 1.0.0-beta.7 → 1.0.0

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 (183) hide show
  1. package/.storybook/main.js +2 -2
  2. package/.storybook/server.mjs +4 -4
  3. package/CHANGELOG.md +417 -0
  4. package/demo/index-multiple-colors.html +4 -1
  5. package/demo/index-partition-keys.html +2 -5
  6. package/demo/index-select.html +1 -1
  7. package/demo/index.html +4 -0
  8. package/dist/src/index.d.ts +4 -2
  9. package/dist/src/index.js +4 -2
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/locales/en.d.ts +8 -0
  12. package/dist/src/locales/en.js +8 -0
  13. package/dist/src/locales/en.js.map +1 -1
  14. package/dist/src/locales/ko.d.ts +8 -0
  15. package/dist/src/locales/ko.js +8 -0
  16. package/dist/src/locales/ko.js.map +1 -1
  17. package/dist/src/locales/ms.d.ts +8 -0
  18. package/dist/src/locales/ms.js +8 -0
  19. package/dist/src/locales/ms.js.map +1 -1
  20. package/dist/src/locales/zh.d.ts +8 -0
  21. package/dist/src/locales/zh.js +8 -0
  22. package/dist/src/locales/zh.js.map +1 -1
  23. package/dist/src/ox-input-3dish.js +24 -8
  24. package/dist/src/ox-input-3dish.js.map +1 -1
  25. package/dist/src/ox-input-barcode.d.ts +5 -2
  26. package/dist/src/ox-input-barcode.js +61 -31
  27. package/dist/src/ox-input-barcode.js.map +1 -1
  28. package/dist/src/ox-input-color.js +16 -11
  29. package/dist/src/ox-input-color.js.map +1 -1
  30. package/dist/src/ox-input-crontab.js +28 -10
  31. package/dist/src/ox-input-crontab.js.map +1 -1
  32. package/dist/src/ox-input-data.js +1 -1
  33. package/dist/src/ox-input-data.js.map +1 -1
  34. package/dist/src/ox-input-duration.d.ts +13 -0
  35. package/dist/src/ox-input-duration.js +163 -0
  36. package/dist/src/ox-input-duration.js.map +1 -0
  37. package/dist/src/ox-input-file.js +5 -3
  38. package/dist/src/ox-input-file.js.map +1 -1
  39. package/dist/src/ox-input-key-values.d.ts +41 -0
  40. package/dist/src/ox-input-key-values.js +233 -0
  41. package/dist/src/ox-input-key-values.js.map +1 -0
  42. package/dist/src/ox-input-multiple-colors.d.ts +1 -0
  43. package/dist/src/ox-input-multiple-colors.js +29 -21
  44. package/dist/src/ox-input-multiple-colors.js.map +1 -1
  45. package/dist/src/ox-input-options.d.ts +1 -0
  46. package/dist/src/ox-input-options.js +55 -14
  47. package/dist/src/ox-input-options.js.map +1 -1
  48. package/dist/src/ox-input-partition-keys.d.ts +1 -0
  49. package/dist/src/ox-input-partition-keys.js +51 -23
  50. package/dist/src/ox-input-partition-keys.js.map +1 -1
  51. package/dist/src/ox-input-quantifier.d.ts +11 -0
  52. package/dist/src/ox-input-quantifier.js +67 -0
  53. package/dist/src/ox-input-quantifier.js.map +1 -0
  54. package/dist/src/ox-input-range.js +35 -38
  55. package/dist/src/ox-input-range.js.map +1 -1
  56. package/dist/src/ox-input-search.d.ts +1 -0
  57. package/dist/src/ox-input-search.js +27 -5
  58. package/dist/src/ox-input-search.js.map +1 -1
  59. package/dist/src/ox-input-unit.d.ts +17 -0
  60. package/dist/src/ox-input-unit.js +122 -0
  61. package/dist/src/ox-input-unit.js.map +1 -0
  62. package/dist/src/ox-input-value-map.d.ts +2 -2
  63. package/dist/src/ox-input-value-map.js +51 -15
  64. package/dist/src/ox-input-value-map.js.map +1 -1
  65. package/dist/src/ox-input-value-ranges.d.ts +2 -2
  66. package/dist/src/ox-input-value-ranges.js +50 -23
  67. package/dist/src/ox-input-value-ranges.js.map +1 -1
  68. package/dist/src/ox-input-work-shift.js +79 -44
  69. package/dist/src/ox-input-work-shift.js.map +1 -1
  70. package/dist/src/ox-select.js +12 -3
  71. package/dist/src/ox-select.js.map +1 -1
  72. package/dist/stories/ox-checkbox.stories.d.ts +39 -0
  73. package/dist/stories/ox-checkbox.stories.js +44 -0
  74. package/dist/stories/ox-checkbox.stories.js.map +1 -0
  75. package/dist/stories/ox-input-3dish.stories.d.ts +26 -0
  76. package/dist/stories/ox-input-3dish.stories.js +59 -0
  77. package/dist/stories/ox-input-3dish.stories.js.map +1 -0
  78. package/dist/stories/ox-input-barcode.stories.d.ts +43 -0
  79. package/dist/stories/ox-input-barcode.stories.js +59 -0
  80. package/dist/stories/ox-input-barcode.stories.js.map +1 -0
  81. package/dist/stories/ox-input-crontab.stories.d.ts +25 -0
  82. package/dist/stories/ox-input-crontab.stories.js +35 -0
  83. package/dist/stories/ox-input-crontab.stories.js.map +1 -0
  84. package/dist/stories/ox-input-duration.stories.d.ts +26 -0
  85. package/dist/stories/ox-input-duration.stories.js +37 -0
  86. package/dist/stories/ox-input-duration.stories.js.map +1 -0
  87. package/dist/stories/ox-input-file.stories.d.ts +49 -0
  88. package/dist/stories/ox-input-file.stories.js +48 -0
  89. package/dist/stories/ox-input-file.stories.js.map +1 -0
  90. package/dist/stories/{index.stories.d.ts → ox-input-key-values.stories.d.ts} +7 -11
  91. package/dist/stories/ox-input-key-values.stories.js +49 -0
  92. package/dist/stories/ox-input-key-values.stories.js.map +1 -0
  93. package/dist/stories/ox-input-multiple-colors.stories.d.ts +20 -0
  94. package/dist/stories/ox-input-multiple-colors.stories.js +167 -0
  95. package/dist/stories/ox-input-multiple-colors.stories.js.map +1 -0
  96. package/dist/stories/ox-input-options.stories.d.ts +25 -0
  97. package/dist/stories/ox-input-options.stories.js +33 -0
  98. package/dist/stories/ox-input-options.stories.js.map +1 -0
  99. package/dist/stories/ox-input-partition-keys.stories.d.ts +25 -0
  100. package/dist/stories/ox-input-partition-keys.stories.js +37 -0
  101. package/dist/stories/ox-input-partition-keys.stories.js.map +1 -0
  102. package/dist/stories/ox-input-quantifier.stories.d.ts +25 -0
  103. package/dist/stories/ox-input-quantifier.stories.js +27 -0
  104. package/dist/stories/ox-input-quantifier.stories.js.map +1 -0
  105. package/dist/stories/ox-input-range.stories.d.ts +37 -0
  106. package/dist/stories/ox-input-range.stories.js +28 -0
  107. package/dist/stories/ox-input-range.stories.js.map +1 -0
  108. package/dist/stories/ox-input-search.stories.d.ts +33 -0
  109. package/dist/stories/ox-input-search.stories.js +35 -0
  110. package/dist/stories/ox-input-search.stories.js.map +1 -0
  111. package/dist/stories/ox-input-unit.stories.d.ts +40 -0
  112. package/dist/stories/ox-input-unit.stories.js +42 -0
  113. package/dist/stories/ox-input-unit.stories.js.map +1 -0
  114. package/dist/stories/ox-input-value-map.stories.d.ts +35 -0
  115. package/dist/stories/ox-input-value-map.stories.js +37 -0
  116. package/dist/stories/ox-input-value-map.stories.js.map +1 -0
  117. package/dist/stories/ox-input-value-ranges.stories.d.ts +35 -0
  118. package/dist/stories/ox-input-value-ranges.stories.js +37 -0
  119. package/dist/stories/ox-input-value-ranges.stories.js.map +1 -0
  120. package/dist/stories/ox-input-work-shift.stories.d.ts +26 -0
  121. package/dist/stories/ox-input-work-shift.stories.js +59 -0
  122. package/dist/stories/ox-input-work-shift.stories.js.map +1 -0
  123. package/dist/stories/ox-select.stories.d.ts +30 -0
  124. package/dist/stories/ox-select.stories.js +83 -0
  125. package/dist/stories/ox-select.stories.js.map +1 -0
  126. package/dist/tsconfig.tsbuildinfo +1 -1
  127. package/package.json +16 -13
  128. package/src/index.ts +4 -2
  129. package/src/locales/en.ts +8 -0
  130. package/src/locales/ko.ts +8 -0
  131. package/src/locales/ms.ts +8 -0
  132. package/src/locales/zh.ts +8 -0
  133. package/src/ox-input-3dish.ts +24 -8
  134. package/src/ox-input-barcode.ts +67 -34
  135. package/src/ox-input-color.ts +17 -11
  136. package/src/ox-input-crontab.ts +30 -10
  137. package/src/ox-input-data.ts +2 -2
  138. package/src/ox-input-duration.ts +168 -0
  139. package/src/ox-input-file.ts +7 -6
  140. package/src/ox-input-key-values.ts +270 -0
  141. package/src/ox-input-multiple-colors.ts +29 -21
  142. package/src/ox-input-options.ts +54 -13
  143. package/src/ox-input-partition-keys.ts +51 -22
  144. package/src/ox-input-quantifier.ts +62 -0
  145. package/src/ox-input-range.ts +35 -38
  146. package/src/ox-input-search.ts +29 -5
  147. package/src/ox-input-unit.ts +123 -0
  148. package/src/ox-input-value-map.ts +52 -16
  149. package/src/ox-input-value-ranges.ts +52 -25
  150. package/src/ox-input-work-shift.ts +81 -44
  151. package/src/ox-select.ts +19 -5
  152. package/stories/ox-checkbox.stories.ts +69 -0
  153. package/stories/ox-input-3dish.stories.ts +73 -0
  154. package/stories/ox-input-barcode.stories.ts +85 -0
  155. package/stories/ox-input-code.stories.ts_ +51 -0
  156. package/stories/ox-input-crontab.stories.ts +49 -0
  157. package/stories/ox-input-duration.stories.ts +51 -0
  158. package/stories/ox-input-file.stories.ts +77 -0
  159. package/stories/ox-input-key-values.stories.ts +64 -0
  160. package/stories/ox-input-multiple-colors.stories.ts +178 -0
  161. package/stories/ox-input-options.stories.ts +47 -0
  162. package/stories/ox-input-partition-keys.stories.ts +51 -0
  163. package/stories/ox-input-quantifier.stories.ts +43 -0
  164. package/stories/ox-input-range.stories.ts +45 -0
  165. package/stories/ox-input-search.stories.ts +56 -0
  166. package/stories/ox-input-unit.stories.ts +66 -0
  167. package/stories/ox-input-value-map.stories.ts +58 -0
  168. package/stories/ox-input-value-ranges.stories.ts +58 -0
  169. package/stories/ox-input-work-shift.stories.ts +73 -0
  170. package/stories/ox-select.stories.ts +101 -0
  171. package/themes/app-theme.css +142 -0
  172. package/themes/input-theme.css +19 -0
  173. package/translations/en.json +45 -1
  174. package/translations/ko.json +43 -1
  175. package/translations/ms.json +43 -1
  176. package/translations/zh.json +43 -1
  177. package/xliff/en.xlf +24 -0
  178. package/xliff/ko.xlf +32 -0
  179. package/xliff/ms.xlf +24 -0
  180. package/xliff/zh.xlf +24 -0
  181. package/dist/stories/index.stories.js +0 -33
  182. package/dist/stories/index.stories.js.map +0 -1
  183. package/stories/index.stories.ts +0 -52
@@ -2,6 +2,8 @@
2
2
  * @license Copyright © HatioLab Inc. All rights reserved.
3
3
  */
4
4
 
5
+ import '@material/mwc-icon'
6
+
5
7
  import { css, html } from 'lit'
6
8
  import { customElement, property, queryAll } from 'lit/decorators.js'
7
9
 
@@ -25,38 +27,55 @@ export class OxInputPartitionKeys extends OxFormField {
25
27
  :host {
26
28
  display: flex;
27
29
  flex-direction: column;
28
- align-content: center;
29
-
30
- width: 100%;
31
30
  overflow: hidden;
32
- border: 1px solid #ccc;
31
+ margin-bottom: var(--margin-wide);
33
32
  }
34
33
 
35
34
  div {
36
35
  display: flex;
37
36
  flex-flow: row nowrap;
38
- align-items: center;
39
-
40
- border-bottom: 1px solid #c0c0c0;
37
+ gap: var(--margin-default);
38
+ margin-bottom: var(--margin-narrow);
41
39
  }
42
40
 
43
- div:last-child {
44
- border-bottom: none;
41
+ button {
42
+ border: var(--button-border);
43
+ border-radius: var(--border-radius);
44
+ background-color: var(--button-background-color);
45
+ padding: var(--padding-narrow) var(--padding-default);
46
+ line-height: 0.8;
47
+ color: var(--button-color);
48
+ cursor: pointer;
45
49
  }
46
-
47
- div > * {
48
- min-width: 0px;
49
- margin: 2px;
50
- padding: 0;
50
+ button + button {
51
+ margin-left: -5px;
51
52
  }
52
-
53
- button {
54
- width: 20px;
55
- text-align: center;
53
+ button mwc-icon {
54
+ font-size: var(--fontsize-default);
55
+ }
56
+ button:focus,
57
+ button:hover,
58
+ button:active {
59
+ border: var(--button-activ-border);
60
+ background-color: var(--button-background-focus-color);
61
+ color: var(--theme-white-color);
56
62
  }
57
63
 
58
64
  input {
59
65
  flex: 1;
66
+ border: 0;
67
+ border-bottom: var(--border-dark-color);
68
+ padding: var(--input-padding);
69
+ font: var(--input-font);
70
+ color: var(--primary-text-color);
71
+ }
72
+ input:focus {
73
+ outline: none;
74
+ border-bottom: 1px solid var(--primary-color);
75
+ }
76
+ button.hidden {
77
+ opacity: 0;
78
+ cursor: default;
60
79
  }
61
80
  `
62
81
 
@@ -77,9 +96,15 @@ export class OxInputPartitionKeys extends OxFormField {
77
96
  <div data-record>
78
97
  <input type="text" data-key placeholder="key" .value=${item.key} />
79
98
  <input type="text" data-value placeholder="value" .value=${item.value} list="value-template" />
80
- <button class="record-action" @click=${(e: MouseEvent) => this._delete(e)} tabindex="-1">-</button>
81
- <button class="record-action" @click=${(e: MouseEvent) => this._up(e)} tabindex="-1">↑</button>
82
- <button class="record-action" @click=${(e: MouseEvent) => this._down(e)} tabindex="-1">↓</button>
99
+ <button class="record-action" @click=${(e: MouseEvent) => this._delete(e)} tabindex="-1">
100
+ <mwc-icon>remove</mwc-icon>
101
+ </button>
102
+ <button class="record-action" @click=${(e: MouseEvent) => this._up(e)} tabindex="-1">
103
+ <mwc-icon>arrow_upward</mwc-icon>
104
+ </button>
105
+ <button class="record-action" @click=${(e: MouseEvent) => this._down(e)} tabindex="-1">
106
+ <mwc-icon>arrow_downward</mwc-icon>
107
+ </button>
83
108
  </div>
84
109
  `
85
110
  )}
@@ -87,7 +112,11 @@ export class OxInputPartitionKeys extends OxFormField {
87
112
  <div data-record-new>
88
113
  <input type="text" data-key placeholder="key" value="" />
89
114
  <input type="text" data-value placeholder="value" value="" list="value-template" />
90
- <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">+</button>
115
+ <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
116
+ <mwc-icon>add</mwc-icon>
117
+ </button>
118
+ <button class="hidden"><mwc-icon>add</mwc-icon></button>
119
+ <button class="hidden"><mwc-icon>add</mwc-icon></button>
91
120
  </div>
92
121
 
93
122
  <datalist id="value-template">
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import { css, html } from 'lit'
6
+ import { customElement, property, queryAll } from 'lit/decorators.js'
7
+
8
+ import { OxFormField } from './ox-form-field.js'
9
+
10
+ @customElement('ox-input-quantifier')
11
+ export class OxInputQuantifier extends OxFormField {
12
+ static styles = css`
13
+ :host {
14
+ display: flex;
15
+ gap: var(--margin-default);
16
+ align-items: center;
17
+
18
+ width: 100%;
19
+ user-select: text;
20
+ }
21
+
22
+ input[type='number'] {
23
+ width: 48px;
24
+ border: 0;
25
+ border-bottom: var(--border-dark-color);
26
+ padding: var(--input-padding);
27
+ font: var(--input-font);
28
+ color: var(--primary-text-color);
29
+ }
30
+ input[type='number']:focus {
31
+ outline: none;
32
+ border-bottom: 1px solid var(--primary-color);
33
+ }
34
+
35
+ input:focus {
36
+ outline: none;
37
+ opacity: 1;
38
+ }
39
+ `
40
+
41
+ @property({ type: Array }) value: number[] = [1, 1]
42
+
43
+ render() {
44
+ const [min = 1, max = 1] = this.value || []
45
+
46
+ return html`
47
+ <span>
48
+ <input type="number" .value=${min} @change=${(e: Event) => this.onChange(e)} />
49
+ -
50
+ <input type="number" .value=${max} @change=${(e: Event) => this.onChange(e)} />
51
+ </span>
52
+ `
53
+ }
54
+
55
+ @queryAll('input') inputs?: HTMLInputElement[]
56
+
57
+ onChange(e: Event) {
58
+ e.stopPropagation()
59
+ this.value = Array.from(this.inputs || []).map(input => input.valueAsNumber) || [1, 1]
60
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
61
+ }
62
+ }
@@ -11,10 +11,9 @@ import { OxFormField } from './ox-form-field.js'
11
11
  class OxInputRange extends OxFormField {
12
12
  static styles = css`
13
13
  :host {
14
- font-size: 16px;
15
14
  display: flex;
15
+ gap: var(--margin-default);
16
16
  align-items: center;
17
- padding: 1px 0;
18
17
 
19
18
  width: 100%;
20
19
  user-select: text;
@@ -22,15 +21,15 @@ class OxInputRange extends OxFormField {
22
21
 
23
22
  input[type='number'] {
24
23
  width: 48px;
25
- overflow: hidden;
24
+ border: 0;
25
+ border-bottom: var(--border-dark-color);
26
+ padding: var(--input-padding);
27
+ font: var(--input-font);
28
+ color: var(--primary-text-color);
26
29
  }
27
-
28
- input[type='number'] {
29
- color: black;
30
- border: none;
31
- font-weight: 300;
32
- background: white;
33
- padding: 1px 2px;
30
+ input[type='number']:focus {
31
+ outline: none;
32
+ border-bottom: 1px solid var(--primary-color);
34
33
  }
35
34
 
36
35
  input[type='range'] {
@@ -44,40 +43,40 @@ class OxInputRange extends OxFormField {
44
43
  }
45
44
  input[type='range']::-webkit-slider-runnable-track {
46
45
  width: 100%;
47
- height: 1px;
48
- background: black;
49
- border: none;
46
+ height: 7px;
47
+ background-color: rgba(0, 0, 0, 0.02);
48
+ border: 1px solid rgba(0, 0, 0, 0.05);
50
49
  border-radius: 5px;
51
50
  }
52
51
  input[type='range']::-webkit-slider-thumb {
53
52
  -webkit-appearance: none;
54
53
  border: none;
55
- height: 10px;
56
- width: 10px;
54
+ height: 16px;
55
+ width: 16px;
57
56
  border-radius: 50%;
58
- background: black;
59
- margin-top: -5px;
57
+ background: var(--primary-color);
58
+ margin-top: -6px;
59
+ box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.15);
60
60
  }
61
61
  input[type='range']:focus {
62
62
  outline: none;
63
63
  }
64
- input[type='range']:focus::-webkit-slider-runnable-track {
65
- background: black;
66
- }
67
64
 
68
65
  input[type='range']::-moz-range-track {
69
66
  width: 100%;
70
- height: 1px;
71
- background: black;
72
- border: none;
67
+ height: 7px;
68
+ background-color: rgba(0, 0, 0, 0.02);
69
+ border: 1px solid rgba(0, 0, 0, 0.05);
73
70
  border-radius: 5px;
74
71
  }
75
72
  input[type='range']::-moz-range-thumb {
76
73
  border: none;
77
- height: 10px;
78
- width: 10px;
74
+ height: 16px;
75
+ width: 16px;
79
76
  border-radius: 50%;
80
- background: black;
77
+ background: var(--primary-color);
78
+ margin-top: -6px;
79
+ box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.15);
81
80
  }
82
81
 
83
82
  input[type='range']:-moz-focusring {
@@ -87,21 +86,19 @@ class OxInputRange extends OxFormField {
87
86
 
88
87
  input[type='range']::-ms-track {
89
88
  width: 100%;
90
- height: 1px;
91
- background: black;
92
- border-radius: 10px;
93
- color: transparent;
94
- border: none;
95
- outline: none;
89
+ height: 7px;
90
+ background-color: rgba(0, 0, 0, 0.02);
91
+ border: 1px solid rgba(0, 0, 0, 0.05);
92
+ border-radius: 5px;
96
93
  }
97
94
  input[type='range']::-ms-thumb {
98
- height: 10px;
99
- width: 10px;
100
- border-radius: 50%;
101
- background: black;
102
95
  border: none;
103
- outline: none;
104
- margin-top: 2px;
96
+ height: 16px;
97
+ width: 16px;
98
+ border-radius: 50%;
99
+ background: var(--primary-color);
100
+ margin-top: -6px;
101
+ box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.15);
105
102
  }
106
103
 
107
104
  input:focus {
@@ -14,8 +14,6 @@ export class OxInputSearch extends OxFormField {
14
14
  static styles = [
15
15
  css`
16
16
  :host {
17
- flex: 1;
18
-
19
17
  display: flex;
20
18
  position: relative;
21
19
  align-items: center;
@@ -28,9 +26,14 @@ export class OxInputSearch extends OxFormField {
28
26
  background-color: transparent;
29
27
  border: 0;
30
28
  border-bottom: var(--border-dark-color);
31
- padding: var(--padding-narrow) var(--padding-narrow) 7px 25px;
32
- font-size: var(--fontsize-large);
29
+ padding: var(--input-padding);
30
+ padding-left: 25px;
31
+ font: var(--input-font);
32
+ color: var(--primary-text-color);
33
+ }
34
+ [type='text']:focus {
33
35
  outline: none;
36
+ border-bottom: 1px solid var(--primary-color);
34
37
  }
35
38
 
36
39
  mwc-icon {
@@ -41,6 +44,7 @@ export class OxInputSearch extends OxFormField {
41
44
  ]
42
45
 
43
46
  @property({ type: String }) placeholder?: string
47
+ @property({ attribute: 'select-after-change', type: Boolean }) selectAfterChange?: boolean
44
48
 
45
49
  @query('input') input!: HTMLInputElement
46
50
 
@@ -52,12 +56,26 @@ export class OxInputSearch extends OxFormField {
52
56
  .value=${this.value || ''}
53
57
  .placeholder=${this.placeholder || ''}
54
58
  @change=${(e: Event) => this._onChangeValue(e)}
59
+ @keydown=${(e: KeyboardEvent) => {
60
+ if (e.key === 'Enter') {
61
+ /* Even if the value has not changed, the enter key triggers a change event. */
62
+ e.preventDefault() /* Prevent change event from occurring twice. */
63
+
64
+ this.input.dispatchEvent(
65
+ new CustomEvent('change', {
66
+ detail: this.value
67
+ })
68
+ )
69
+ }
70
+ }}
55
71
  />
56
72
  `
57
73
  }
58
74
 
59
75
  firstUpdated() {
60
- this.renderRoot.addEventListener('change', this._onChangeValue.bind(this))
76
+ if (this.autofocus) {
77
+ this.input.focus()
78
+ }
61
79
  }
62
80
 
63
81
  _onChangeValue(e: Event) {
@@ -71,6 +89,12 @@ export class OxInputSearch extends OxFormField {
71
89
  detail: this.value
72
90
  })
73
91
  )
92
+
93
+ if (this.selectAfterChange) {
94
+ requestAnimationFrame(() => {
95
+ this.input.select()
96
+ })
97
+ }
74
98
  }
75
99
 
76
100
  _onClickSearch(e: Event) {
@@ -0,0 +1,123 @@
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 { OxPopupList } from '@operato/popup'
9
+
10
+ import { OxFormField } from './ox-form-field'
11
+
12
+ const UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number } } = {
13
+ kg: {
14
+ mg: 1000000,
15
+ g: 1000,
16
+ ton: 0.001
17
+ },
18
+ rad: {
19
+ degree: 180 / Math.PI
20
+ }
21
+ }
22
+
23
+ @customElement('ox-input-unit')
24
+ export class OxInputUnit extends OxFormField {
25
+ static styles = [
26
+ css`
27
+ input {
28
+ border: 0;
29
+ border-bottom: var(--border-dark-color);
30
+ padding: var(--input-padding);
31
+ font: var(--input-font);
32
+ color: var(--primary-text-color);
33
+ }
34
+ input:focus {
35
+ outline: none;
36
+ border-bottom: 1px solid var(--primary-color);
37
+ }
38
+
39
+ input::-webkit-outer-spin-button,
40
+ input::-webkit-inner-spin-button {
41
+ -webkit-appearance: none;
42
+ margin: 0;
43
+ }
44
+
45
+ input[type='number'] {
46
+ -moz-appearance: textfield;
47
+ }
48
+
49
+ div {
50
+ display: inline;
51
+ position: relative;
52
+ margin-left: var(--margin-narrow);
53
+ font: var(--label-font);
54
+ color: var(--label-color);
55
+ opacity: 0.7;
56
+ }
57
+ `
58
+ ]
59
+
60
+ @property({ type: String }) placeholder?: string
61
+ @property({ type: String, attribute: 'std-unit' }) stdUnit!: string
62
+ @property({ type: String, attribute: 'user-unit' }) userUnit?: string
63
+
64
+ @query('input') input!: HTMLInputElement
65
+ @query('ox-popup-list') popup!: OxPopupList
66
+
67
+ render() {
68
+ const userUnit = this.userUnit || this.stdUnit
69
+ const units = Object.keys(UNIT_SYSTEMS[this.stdUnit])
70
+ const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
71
+
72
+ return html`
73
+ <input
74
+ type="number"
75
+ .value=${this._toUserUnit(this.value)}
76
+ placeholder=${this.placeholder}
77
+ @change=${(e: Event) => this._onChangeValue(e)}
78
+ />
79
+ <div
80
+ @click=${(e: Event) => {
81
+ const target = e.currentTarget as HTMLElement
82
+ this.popup.open({
83
+ right: 0,
84
+ top: target.offsetTop + target.offsetHeight
85
+ })
86
+ }}
87
+ >
88
+ ${userUnit}
89
+ <ox-popup-list
90
+ .value=${userUnit}
91
+ @select=${(e: CustomEvent) => {
92
+ this.userUnit = e.detail
93
+ }}
94
+ >
95
+ <div option value=${this.stdUnit}>${this.stdUnit}</div>
96
+ ${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}
97
+ </ox-popup-list>
98
+ </div>
99
+ `
100
+ }
101
+
102
+ _onChangeValue(e: Event) {
103
+ this.value = this._toStdUnit(this.input.value)
104
+
105
+ this.dispatchEvent(
106
+ new CustomEvent('change', {
107
+ bubbles: true,
108
+ composed: true,
109
+ detail: this.value
110
+ })
111
+ )
112
+ }
113
+
114
+ _toUserUnit(stdValue: string | number | undefined) {
115
+ const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
116
+ return Number(stdValue) * rate
117
+ }
118
+
119
+ _toStdUnit(userValue: string | number | undefined) {
120
+ const rate = !this.userUnit || this.userUnit === this.stdUnit ? 1 : UNIT_SYSTEMS[this.stdUnit][this.userUnit] || 1
121
+ return isNaN(Number(userValue)) ? undefined : Number(userValue) / rate
122
+ }
123
+ }
@@ -29,23 +29,18 @@ export class OxInputValueMap extends OxFormField {
29
29
  :host {
30
30
  display: flex;
31
31
  flex-direction: column;
32
- align-content: center;
33
-
34
- width: 100%;
35
- overflow: hidden;
36
- border: 1px solid #ccc;
32
+ border: var(--border-dark-color);
33
+ padding: var(--padding-narrow) var(--padding-narrow) 0 var(--padding-narrow);
37
34
  }
38
35
 
39
36
  div {
40
37
  display: flex;
41
38
  flex-flow: row nowrap;
42
- align-items: center;
43
-
44
- border-bottom: 1px solid #c0c0c0;
39
+ gap: var(--padding-default);
45
40
  }
46
41
 
47
42
  div:last-child {
48
- border-bottom: none;
43
+ margin-bottom: var(--margin-narrow);
49
44
  }
50
45
 
51
46
  div > * {
@@ -55,14 +50,47 @@ export class OxInputValueMap extends OxFormField {
55
50
  }
56
51
 
57
52
  button {
58
- width: 20px;
59
- text-align: center;
53
+ border: var(--button-border);
54
+ border-radius: var(--border-radius);
55
+ background-color: var(--button-background-color);
56
+ padding: var(--padding-narrow) var(--padding-default);
57
+ line-height: 0.8;
58
+ color: var(--button-color);
59
+ cursor: pointer;
60
+ }
61
+ button + button {
62
+ margin-left: -5px;
63
+ }
64
+ button mwc-icon {
65
+ font-size: var(--fontsize-default);
66
+ }
67
+ button:focus,
68
+ button:hover,
69
+ button:active {
70
+ border: var(--button-activ-border);
71
+ background-color: var(--button-background-focus-color);
72
+ color: var(--theme-white-color);
60
73
  }
61
74
 
62
75
  input,
63
76
  ox-input-color {
64
77
  flex: 1;
65
78
  }
79
+ input {
80
+ border: 0;
81
+ border-bottom: var(--border-dark-color);
82
+ padding: var(--input-padding);
83
+ font: var(--input-font);
84
+ color: var(--primary-text-color);
85
+ }
86
+ input:focus {
87
+ outline: none;
88
+ border-bottom: 1px solid var(--primary-color);
89
+ }
90
+ button.hidden {
91
+ opacity: 0;
92
+ cursor: default;
93
+ }
66
94
 
67
95
  ox-input-color {
68
96
  --ox-input-color-input-color: {
@@ -80,8 +108,8 @@ export class OxInputValueMap extends OxFormField {
80
108
  `
81
109
 
82
110
  @property({ type: Object }) value: ValueMap = {}
83
- @property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | string = 'string'
84
- @property({ type: String }) keytype: 'string' | 'boolean' | 'color' | string = 'string'
111
+ @property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | 'number' | 'date' | string = 'string'
112
+ @property({ type: String }) keytype: 'string' | 'number' = 'number'
85
113
 
86
114
  private _changingNow: boolean = false
87
115
 
@@ -107,7 +135,10 @@ export class OxInputValueMap extends OxFormField {
107
135
  .value=${item.value}
108
136
  data-value-type=${this.valuetype}
109
137
  />
110
- `} <button class="record-action" @click=${(e: MouseEvent) => this._delete(e)} tabindex="-1">-</button>
138
+ `}
139
+ <button class="record-action" @click=${(e: MouseEvent) => this._delete(e)} tabindex="-1">
140
+ <mwc-icon>remove</mwc-icon>
141
+ </button>
111
142
  </div>
112
143
  `
113
144
  )}
@@ -118,7 +149,9 @@ export class OxInputValueMap extends OxFormField {
118
149
  : this.valuetype == 'color'
119
150
  ? html` <ox-input-color data-value value="" tabindex="-1" placeholder="value"> </ox-input-color> `
120
151
  : html` <input type="text" data-value placeholder="value" value="" data-value-type=${this.valuetype} /> `}
121
- <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">+</button>
152
+ <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
153
+ <mwc-icon>add</mwc-icon>
154
+ </button>
122
155
  </div>
123
156
 
124
157
  <div data-record>
@@ -149,7 +182,10 @@ export class OxInputValueMap extends OxFormField {
149
182
  .value=${(this.value && this.value.default) || ''}
150
183
  data-value-type=${this.valuetype}
151
184
  />
152
- `} <button class="record-action" @click=${() => this._sort()} tabindex="-1">&gt;</button>
185
+ `}
186
+ <button class="record-action" @click=${() => this._sort()} tabindex="-1">
187
+ <mwc-icon>chevron_right</mwc-icon>
188
+ </button>
153
189
  </div>
154
190
  `
155
191
  }