@operato/input 2.0.0-alpha.30 → 2.0.0-alpha.32

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": "2.0.0-alpha.30",
5
+ "version": "2.0.0-alpha.32",
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
  ],
@@ -239,5 +243,5 @@
239
243
  "prettier --write"
240
244
  ]
241
245
  },
242
- "gitHead": "cbe840ad27dd2a27f0909ba32238c4b5b9ca000b"
246
+ "gitHead": "2956c5182da55334bb327bde22a677fc50fc5a5e"
243
247
  }
@@ -44,6 +44,7 @@ export class OxInputData extends OxFormField {
44
44
 
45
45
  ox-input-code {
46
46
  flex: 1;
47
+ max-width: 260px;
47
48
  overflow: auto;
48
49
  }
49
50
  `
@@ -0,0 +1,133 @@
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 = { [lng: string]: string }
13
+
14
+ const LANGUAGES = [
15
+ {
16
+ lng: '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; lng: 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, lng }) => html`
90
+ <div data-record>
91
+ <label>${display}</label>
92
+ <input type="hidden" data-lng value=${lng} />
93
+ <input type="text" data-label placeholder="label" .value=${value?.[lng] || ''} ?disabled=${this.disabled} />
94
+ </div>
95
+ `
96
+ )}
97
+ `
98
+ }
99
+
100
+ private onChange(e: Event) {
101
+ e.stopPropagation()
102
+
103
+ if (this.changing) {
104
+ return
105
+ }
106
+
107
+ this.changing = true
108
+
109
+ this.build()
110
+
111
+ this.changing = false
112
+ }
113
+
114
+ private build() {
115
+ var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
116
+
117
+ var newmap: I18nLabel = {}
118
+
119
+ for (var i = 0; i < records.length; i++) {
120
+ var record = records[i]
121
+
122
+ const lng = (record.querySelector('[data-lng]') as HTMLInputElement).value
123
+ const label = (record.querySelector('[data-label]') as HTMLInputElement).value
124
+
125
+ if (lng) {
126
+ newmap[lng] = label || ''
127
+ }
128
+ }
129
+
130
+ this.value = { ...this.value, ...newmap }
131
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
132
+ }
133
+ }
@@ -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
+ lng: 'ko',
44
+ display: '한글'
45
+ },
46
+ {
47
+ lng: 'en',
48
+ display: 'English'
49
+ },
50
+ {
51
+ lng: 'zh',
52
+ display: 'Chinese'
53
+ },
54
+ {
55
+ lng: '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
+ }