@operato/input 1.17.2 → 1.17.7

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/input",
3
3
  "description": "Webcomponents for input following open-wc recommendations",
4
4
  "author": "heartyoh@hatiolab.com",
5
- "version": "1.17.2",
5
+ "version": "1.17.7",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "license": "MIT",
@@ -46,6 +46,7 @@
46
46
  "./ox-input-search.js": "./dist/src/ox-input-search.js",
47
47
  "./ox-input-value-map.js": "./dist/src/ox-input-value-map.js",
48
48
  "./ox-input-value-ranges.js": "./dist/src/ox-input-value-ranges.js",
49
+ "./ox-input-i18n-label.js": "./dist/src/ox-input-i18n-label.js",
49
50
  "./ox-input-partition-keys.js": "./dist/src/ox-input-partition-keys.js",
50
51
  "./ox-input-table.js": "./dist/src/ox-input-table.js",
51
52
  "./ox-input-scene-component-id.js": "./dist/src/ox-input-scene-component-id.js",
@@ -143,6 +144,9 @@
143
144
  "./ox-input-value-ranges.js": [
144
145
  "./dist/src/ox-input-value-ranges.d.ts"
145
146
  ],
147
+ "./ox-input-i18n-label.js": [
148
+ "./dist/src/ox-input-i18n-label.d.ts"
149
+ ],
146
150
  "./ox-input-partition-keys.js": [
147
151
  "./dist/src/ox-input-partition-keys.d.ts"
148
152
  ],
@@ -193,8 +197,8 @@
193
197
  "@material/mwc-icon": "^0.27.0",
194
198
  "@operato/color-picker": "^1.4.64",
195
199
  "@operato/i18n": "^1.5.14",
196
- "@operato/popup": "^1.17.2",
197
- "@operato/styles": "^1.12.3",
200
+ "@operato/popup": "^1.17.7",
201
+ "@operato/styles": "^1.17.7",
198
202
  "@operato/utils": "^1.13.9",
199
203
  "@polymer/paper-dropdown-menu": "^3.2.0",
200
204
  "@polymer/paper-item": "^3.0.1",
@@ -239,5 +243,5 @@
239
243
  "prettier --write"
240
244
  ]
241
245
  },
242
- "gitHead": "953573e87b156ac2ce143009555fb2ec4f1162ee"
246
+ "gitHead": "4634d814f460d11dc5dcf5b765664e1c68db38ca"
243
247
  }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@material/mwc-icon'
6
+
7
+ import { css, html } from 'lit'
8
+ import { customElement, property, queryAll } from 'lit/decorators.js'
9
+
10
+ import { OxFormField } from './ox-form-field'
11
+
12
+ type I18nLabel = { [code: string]: string }
13
+
14
+ const LANGUAGES = [
15
+ {
16
+ code: 'en',
17
+ display: 'English'
18
+ }
19
+ ]
20
+
21
+ /**
22
+ input component for i18n labels
23
+
24
+ Example:
25
+
26
+ <ox-input-i18n-label
27
+ value=${map}
28
+ languages=${languages}
29
+ </ox-input-i18n-label>
30
+ */
31
+ @customElement('ox-input-i18n-label')
32
+ export class OxInputI18nLabels extends OxFormField {
33
+ static styles = css`
34
+ :host {
35
+ display: flex;
36
+ flex-direction: column;
37
+ overflow: hidden;
38
+ }
39
+
40
+ [data-record] {
41
+ display: flex;
42
+ flex-direction: row;
43
+ gap: 10px;
44
+ }
45
+
46
+ label {
47
+ width: 80px;
48
+ align-self: center;
49
+ text-align: end;
50
+ }
51
+
52
+ input {
53
+ flex: 1;
54
+ border: 0;
55
+ border-bottom: var(--border-dark-color);
56
+ padding: var(--input-padding);
57
+ font: var(--input-font);
58
+ color: var(--primary-text-color);
59
+ min-width: 100px;
60
+ }
61
+
62
+ input:focus {
63
+ outline: none;
64
+ border-bottom: 1px solid var(--primary-color);
65
+ }
66
+
67
+ input[type='hidden'] {
68
+ flex: 0;
69
+ }
70
+ `
71
+
72
+ @property({ type: Object }) value: I18nLabel = {}
73
+ @property({ type: Array }) languages: { display: string; code: string }[] = LANGUAGES
74
+
75
+ @queryAll('[data-record]') records!: NodeListOf<HTMLElement>
76
+
77
+ private changing: boolean = false
78
+
79
+ firstUpdated() {
80
+ this.renderRoot.addEventListener('change', this.onChange.bind(this))
81
+ }
82
+
83
+ render() {
84
+ const value = !this.value || typeof this.value !== 'object' ? {} : this.value
85
+ const languages = (this.languages && this.languages.length > 0 && this.languages) || LANGUAGES
86
+
87
+ return html`
88
+ ${languages.map(
89
+ ({ display, code }) => html`
90
+ <div data-record>
91
+ <label>${display}</label>
92
+ <input type="hidden" data-code value=${code} />
93
+ <input
94
+ type="text"
95
+ data-label
96
+ placeholder="label"
97
+ .value=${value?.[code] || ''}
98
+ ?disabled=${this.disabled}
99
+ />
100
+ </div>
101
+ `
102
+ )}
103
+ `
104
+ }
105
+
106
+ private onChange(e: Event) {
107
+ e.stopPropagation()
108
+
109
+ if (this.changing) {
110
+ return
111
+ }
112
+
113
+ this.changing = true
114
+
115
+ this.build()
116
+
117
+ this.changing = false
118
+ }
119
+
120
+ private build() {
121
+ var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
122
+
123
+ var newmap: I18nLabel = {}
124
+
125
+ for (var i = 0; i < records.length; i++) {
126
+ var record = records[i]
127
+
128
+ const code = (record.querySelector('[data-code]') as HTMLInputElement).value
129
+ const label = (record.querySelector('[data-label]') as HTMLInputElement).value
130
+
131
+ if (code) {
132
+ newmap[code] = label || ''
133
+ }
134
+ }
135
+
136
+ this.value = { ...this.value, ...newmap }
137
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
138
+ }
139
+ }
@@ -0,0 +1,73 @@
1
+ import '../src/ox-input-i18n-label.js'
2
+
3
+ import { html, TemplateResult } from 'lit'
4
+
5
+ export default {
6
+ title: 'ox-input-i18n-label',
7
+ component: 'ox-input-i18n-label',
8
+ argTypes: {
9
+ name: { control: 'text' },
10
+ value: { control: 'object' },
11
+ disabled: { control: 'boolean' }
12
+ }
13
+ }
14
+
15
+ interface Story<T> {
16
+ (args: T): TemplateResult
17
+ args?: Partial<T>
18
+ argTypes?: Record<string, unknown>
19
+ }
20
+
21
+ interface ArgTypes {
22
+ name?: string
23
+ value?: object
24
+ disabled?: boolean
25
+ }
26
+
27
+ const Template: Story<ArgTypes> = ({ name = 'values', value = {}, disabled }: ArgTypes) => html`
28
+ <link href="/themes/app-theme.css" rel="stylesheet" />
29
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
30
+ <style>
31
+ body {
32
+ }
33
+ </style>
34
+
35
+ <ox-input-i18n-label
36
+ @change=${(e: Event) => {
37
+ console.log((e.target as HTMLInputElement).value)
38
+ }}
39
+ name=${name}
40
+ .value=${value}
41
+ .languages=${[
42
+ {
43
+ code: 'ko',
44
+ display: '한글'
45
+ },
46
+ {
47
+ code: 'en',
48
+ display: 'English'
49
+ },
50
+ {
51
+ code: 'zh',
52
+ display: 'Chinese'
53
+ },
54
+ {
55
+ code: 'ja',
56
+ display: 'Japanese'
57
+ }
58
+ ]}
59
+ ?disabled=${disabled}
60
+ >
61
+ </ox-input-i18n-label>
62
+ `
63
+
64
+ export const Regular = Template.bind({})
65
+ Regular.args = {
66
+ name: 'i18n labels',
67
+ value: {
68
+ ko: '한글 코드',
69
+ en: 'English code',
70
+ zh: 'Chinese code',
71
+ ja: 'Japan code'
72
+ }
73
+ }