@operato/input 2.0.0-beta.2 → 2.0.0-beta.20

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-beta.2",
5
+ "version": "2.0.0-beta.20",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "license": "MIT",
@@ -54,7 +54,8 @@
54
54
  "./ox-input-hashtags.js": "./dist/src/ox-input-hashtags.js",
55
55
  "./ox-input-mass-fraction.js": "./dist/src/ox-input-mass-fraction.js",
56
56
  "./ox-input-textarea.js": "./dist/src/ox-input-textarea.js",
57
- "./ox-input-direction.js": "./dist/src/ox-input-direction.js"
57
+ "./ox-input-direction.js": "./dist/src/ox-input-direction.js",
58
+ "./ox-input-table-column-config.js": "./dist/src/ox-input-table-column-config.js"
58
59
  },
59
60
  "typesVersions": {
60
61
  "*": {
@@ -171,6 +172,9 @@
171
172
  ],
172
173
  "./ox-input-direction.js": [
173
174
  "./dist/src/ox-input-direction.d.ts"
175
+ ],
176
+ "./ox-input-table-column-config.js": [
177
+ "./dist/src/ox-input-table-column-config.d.ts"
174
178
  ]
175
179
  }
176
180
  },
@@ -200,10 +204,10 @@
200
204
  "@lit/localize": "^0.12.1",
201
205
  "@material/web": "^1.4.0",
202
206
  "@operato/color-picker": "^2.0.0-beta.0",
203
- "@operato/i18n": "^2.0.0-beta.0",
204
- "@operato/popup": "^2.0.0-beta.0",
205
- "@operato/styles": "^2.0.0-beta.0",
206
- "@operato/utils": "^2.0.0-beta.0",
207
+ "@operato/i18n": "^2.0.0-beta.16",
208
+ "@operato/popup": "^2.0.0-beta.14",
209
+ "@operato/styles": "^2.0.0-beta.13",
210
+ "@operato/utils": "^2.0.0-beta.13",
207
211
  "@polymer/paper-dropdown-menu": "^3.2.0",
208
212
  "@polymer/paper-item": "^3.0.1",
209
213
  "@thebespokepixel/es-tinycolor": "^3.1.0",
@@ -247,5 +251,5 @@
247
251
  "prettier --write"
248
252
  ]
249
253
  },
250
- "gitHead": "df3ca9940501549fe8b59f294425d50962895965"
254
+ "gitHead": "b17cf676ccdd3d005ae2cba046bb8fb51379a2ba"
251
255
  }
package/src/index.ts CHANGED
@@ -29,3 +29,4 @@ export * from './ox-input-quantifier.js'
29
29
  export * from './ox-input-select-buttons.js'
30
30
  export * from './ox-input-textarea.js'
31
31
  export * from './ox-input-direction.js'
32
+ export * from './ox-input-table-column-config.js'
@@ -39,12 +39,8 @@ export class OxCheckbox extends OxFormField {
39
39
  justify-content: center;
40
40
  }
41
41
 
42
- :host([indeterminate]) .checkbox {
43
- background-color: var(--ox-checkbox-unchecked-background-color, var(--md-ref-palette-primary80));
44
- }
45
-
46
42
  :host([checked]) .checkbox {
47
- background-color: var(--ox-checkbox-checked-background-color, var(--md-ref-palette-primary60));
43
+ background-color: var(--ox-checkbox-checked-background-color, var(--md-sys-color-primary));
48
44
  }
49
45
 
50
46
  path {
@@ -52,7 +48,6 @@ export class OxCheckbox extends OxFormField {
52
48
  }
53
49
 
54
50
  :host([indeterminate]) line {
55
- fill: var(--ox-checkbox-intermidiate-color, var(--md-sys-color-on-surface-variant));
56
51
  stroke: var(--ox-checkbox-intermidiate-color, var(--md-sys-color-outline));
57
52
  }
58
53
 
@@ -40,7 +40,7 @@ export class OxInputSelectButtons extends OxFormField {
40
40
  data-value=${value}
41
41
  label=${display}
42
42
  ?selected=${values.includes(value)}
43
- @click=${(e: MouseEvent) => !this.disabled && this.onClick(e)}
43
+ @tap=${(e: MouseEvent | TouchEvent) => !this.disabled && this.onTap(e)}
44
44
  ></md-filter-chip>
45
45
  `
46
46
  )}
@@ -48,7 +48,7 @@ export class OxInputSelectButtons extends OxFormField {
48
48
  `
49
49
  }
50
50
 
51
- onClick(e: MouseEvent) {
51
+ onTap(e: MouseEvent | TouchEvent) {
52
52
  e.stopPropagation()
53
53
 
54
54
  const target = e.target as MdFilterChip
@@ -0,0 +1,211 @@
1
+ import { css, html } from 'lit'
2
+ import { customElement, property } from 'lit/decorators.js'
3
+ import { OxFormField } from './ox-form-field'
4
+ import '@material/web/icon/icon.js'
5
+
6
+ export interface ColumnConfig {
7
+ name: string
8
+ label: string
9
+ visible: boolean
10
+ width: number
11
+ order: number
12
+ }
13
+
14
+ @customElement('ox-input-table-column-config')
15
+ export class OxInputTableColumnConfig extends OxFormField {
16
+ static styles = [
17
+ css`
18
+ :host {
19
+ display: block;
20
+ padding: 4px;
21
+ border: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
22
+ background-color: var(--ox-input-table-column-config-background-color, var(--md-sys-color-surface));
23
+ color: var(--ox-input-table-column-config-color, var(--md-sys-color-on-surface));
24
+ }
25
+
26
+ table {
27
+ width: auto;
28
+ border-collapse: collapse;
29
+ font-size: 12px;
30
+ border: 0;
31
+ }
32
+
33
+ tr {
34
+ border-bottom: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
35
+ }
36
+
37
+ th,
38
+ td {
39
+ padding: 0 var(--spacing-small, 2px);
40
+ text-align: left;
41
+ }
42
+
43
+ th {
44
+ text-transform: capitalize;
45
+ text-align: center;
46
+ background-color: var(
47
+ --ox-input-table-column-config-header-background-color,
48
+ var(--md-sys-color-secondary-container)
49
+ );
50
+ color: var(--ox-input-table-column-config-header-background-color, var(--md-sys-color-on-secondary-container));
51
+ white-space: nowrap;
52
+ }
53
+
54
+ th *,
55
+ td * {
56
+ vertical-align: middle;
57
+ }
58
+
59
+ td[width] {
60
+ width: 60px;
61
+ text-align: right;
62
+ }
63
+
64
+ input {
65
+ font-size: 12px;
66
+ padding: 0;
67
+ margin: 0;
68
+ border: none;
69
+ width: 100%;
70
+ box-sizing: border-box;
71
+ outline: none;
72
+ background-color: var(--ox-input-table-column-config-input-background-color, var(--md-sys-color-surface));
73
+ color: var(--ox-input-table-column-config-input-color, var(--md-sys-color-on-surface));
74
+ }
75
+
76
+ input[type='number'] {
77
+ text-align: right;
78
+ }
79
+
80
+ md-icon {
81
+ cursor: pointer;
82
+ padding: 0;
83
+ margin: 0;
84
+ border: none;
85
+ background: none;
86
+
87
+ --md-icon-size: 16px;
88
+ }
89
+
90
+ md-icon[disabled] {
91
+ cursor: not-allowed;
92
+ color: var(--ox-input-table-column-config-disabled-color, var(--md-sys-color-surface-variant, #ccc));
93
+ }
94
+ `
95
+ ]
96
+
97
+ @property({ type: Array }) value: ColumnConfig[] = []
98
+
99
+ render() {
100
+ console.log('this.value', this.value)
101
+ return html`
102
+ <table>
103
+ <thead>
104
+ <tr>
105
+ <th></th>
106
+ <th>name</th>
107
+ <th>label</th>
108
+ <th>width</th>
109
+ <th></th>
110
+ </tr>
111
+ </thead>
112
+ <tbody>
113
+ ${(this.value || []).map(
114
+ (col, index) => html`
115
+ <tr name=${col.name}>
116
+ <td>
117
+ <input
118
+ type="checkbox"
119
+ .checked=${col.visible}
120
+ @change=${(e: Event) => this._updateVisibility(e, index)}
121
+ />
122
+ </td>
123
+ <td name>${col.name}</td>
124
+ <td>
125
+ <input type="text" .value=${col.label} @input=${(e: Event) => this._updateLabel(e, index)} />
126
+ </td>
127
+ <td width>
128
+ <input
129
+ type="number"
130
+ .value=${String(col.width)}
131
+ @input=${(e: Event) => this._updateWidth(e, index)}
132
+ />
133
+ </td>
134
+ <td buttons>
135
+ <md-icon class="icon-button" @click=${() => this._moveUp(index)} ?disabled=${index === 0}>
136
+ arrow_upward
137
+ </md-icon>
138
+ <md-icon
139
+ class="icon-button"
140
+ @click=${() => this._moveDown(index)}
141
+ ?disabled=${index === this.value.length - 1}
142
+ >
143
+ arrow_downward
144
+ </md-icon>
145
+ </td>
146
+ </tr>
147
+ `
148
+ )}
149
+ </tbody>
150
+ </table>
151
+ `
152
+ }
153
+
154
+ private _updateVisibility(event: Event, index: number) {
155
+ const target = event.target as HTMLInputElement
156
+ this.value[index].visible = target.checked
157
+ this.requestUpdate()
158
+ this._notifyChange()
159
+ }
160
+
161
+ private _updateLabel(event: Event, index: number) {
162
+ const target = event.target as HTMLInputElement
163
+ this.value[index].label = target.value
164
+ this.requestUpdate()
165
+ this._notifyChange()
166
+ }
167
+
168
+ private _updateWidth(event: Event, index: number) {
169
+ const target = event.target as HTMLInputElement
170
+ this.value[index].width = target.valueAsNumber
171
+ this.requestUpdate()
172
+ this._notifyChange()
173
+ }
174
+
175
+ private _moveUp(index: number) {
176
+ if (index === 0) return
177
+ const temp = this.value[index]
178
+ this.value[index] = this.value[index - 1]
179
+ this.value[index - 1] = temp
180
+ this._updateOrder()
181
+ this.requestUpdate()
182
+ this._notifyChange()
183
+ }
184
+
185
+ private _moveDown(index: number) {
186
+ if (index === this.value.length - 1) return
187
+ const temp = this.value[index]
188
+ this.value[index] = this.value[index + 1]
189
+ this.value[index + 1] = temp
190
+ this._updateOrder()
191
+ this.requestUpdate()
192
+ this._notifyChange()
193
+ }
194
+
195
+ private _updateOrder() {
196
+ this.value = this.value.map((col, index) => ({
197
+ ...col,
198
+ order: index + 1
199
+ }))
200
+ }
201
+
202
+ private _notifyChange() {
203
+ this.dispatchEvent(
204
+ new CustomEvent('change', {
205
+ detail: this.value,
206
+ bubbles: true,
207
+ composed: true
208
+ })
209
+ )
210
+ }
211
+ }
@@ -268,6 +268,11 @@ export class OxInputUnitNumber extends OxFormField {
268
268
  .value=${userUnit}
269
269
  @select=${(e: CustomEvent) => {
270
270
  this.userUnit = e.detail
271
+ this.dispatchEvent(
272
+ new CustomEvent('user-unit-change', {
273
+ detail: this.userUnit
274
+ })
275
+ )
271
276
  }}
272
277
  >
273
278
  <div option value=${this.stdUnit}>${this.stdUnit}</div>
@@ -278,12 +283,6 @@ export class OxInputUnitNumber extends OxFormField {
278
283
  `
279
284
  }
280
285
 
281
- updated(changes: PropertyValues<this>) {
282
- // if (changes.has('stdUnit')) {
283
- // this.userUnit = this.userUnit || this.stdUnit
284
- // }
285
- }
286
-
287
286
  _onChangeValue(e: Event) {
288
287
  this.value = this._toStdUnit(this.input.value)
289
288
 
package/src/ox-select.ts CHANGED
@@ -11,22 +11,9 @@ import { customElement, property, query, state } from 'lit/decorators.js'
11
11
 
12
12
  import { OxPopupList } from '@operato/popup'
13
13
  import { TooltipStyles } from '@operato/styles'
14
- import { detectOverflow } from '@operato/utils'
15
14
 
16
15
  import { OxFormField } from './ox-form-field.js'
17
16
 
18
- function onmouseover(e: Event) {
19
- const element = e.target as HTMLSpanElement
20
- if (detectOverflow(element)) {
21
- element.setAttribute('data-tooltip', element.textContent!)
22
- }
23
- }
24
-
25
- function onmouseout(e: Event) {
26
- const element = e.target as HTMLSpanElement
27
- element.removeAttribute('data-tooltip')
28
- }
29
-
30
17
  @customElement('ox-select')
31
18
  export class OxSelect extends OxFormField {
32
19
  static styles = [
@@ -98,7 +85,7 @@ export class OxSelect extends OxFormField {
98
85
 
99
86
  return html`
100
87
  <div @click=${this.expand}>
101
- <span @mouseover=${onmouseover} @mouseout=${onmouseout}>${label}</span>
88
+ <span data-reactive-tooltip>${label}</span>
102
89
  <md-icon>expand_more</md-icon>
103
90
  </div>
104
91
 
@@ -0,0 +1,120 @@
1
+ import '../src/ox-input-table-column-config.js'
2
+
3
+ import { html, TemplateResult } from 'lit'
4
+ import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
5
+
6
+ export default {
7
+ title: 'ox-input-table-column-config',
8
+ component: 'ox-input-table-column-config',
9
+ argTypes: {
10
+ name: { control: 'text' },
11
+ value: { control: 'object' },
12
+ disabled: { control: 'boolean' },
13
+ theme: { control: 'select', options: ['light', 'dark'] }
14
+ }
15
+ }
16
+
17
+ interface Story<T> {
18
+ (args: T): TemplateResult
19
+ args?: Partial<T>
20
+ argTypes?: Record<string, unknown>
21
+ }
22
+
23
+ interface ArgTypes {
24
+ name?: string
25
+ value?: object
26
+ disabled?: boolean
27
+ theme?: string
28
+ }
29
+
30
+ const Template: Story<ArgTypes> = ({
31
+ name = 'table-column-config',
32
+ value = {},
33
+ disabled,
34
+ theme = 'light'
35
+ }: ArgTypes) => html`
36
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
37
+
38
+ <link href="/themes/light.css" rel="stylesheet" />
39
+ <link href="/themes/dark.css" rel="stylesheet" />
40
+ <link href="/themes/spacing.css" rel="stylesheet" />
41
+
42
+ <link
43
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
44
+ rel="stylesheet"
45
+ />
46
+ <link
47
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
48
+ rel="stylesheet"
49
+ />
50
+ <link
51
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
52
+ rel="stylesheet"
53
+ />
54
+
55
+ <style>
56
+ ${MDTypeScaleStyles.cssText}
57
+ </style>
58
+
59
+ <style>
60
+ .container {
61
+ height: 500px;
62
+ text-align: center;
63
+ padding: 20px;
64
+
65
+ background-color: var(--md-sys-color-primary-container);
66
+ color: var(--md-sys-color-on-primary-container);
67
+ }
68
+ </style>
69
+
70
+ <script>
71
+ document.body.classList.add('${theme}')
72
+ </script>
73
+
74
+ <div class="container md-typescale-body-large-prominent">
75
+ <ox-input-table-column-config
76
+ @change=${(e: Event) => {
77
+ console.log((e.target as HTMLInputElement).value)
78
+ }}
79
+ name=${name}
80
+ .value=${value}
81
+ ?disabled=${disabled}
82
+ >
83
+ </ox-input-table-column-config>
84
+ </div>
85
+ `
86
+
87
+ export const Regular = Template.bind({})
88
+ Regular.args = {
89
+ name: 'table-column-config',
90
+ value: [
91
+ {
92
+ name: 'section',
93
+ label: 'Section',
94
+ visible: true,
95
+ width: 100,
96
+ order: 1
97
+ },
98
+ {
99
+ name: 'title',
100
+ label: 'Title',
101
+ visible: true,
102
+ width: 110,
103
+ order: 2
104
+ },
105
+ {
106
+ name: 'startDate',
107
+ label: 'Start Date',
108
+ visible: true,
109
+ width: 150,
110
+ order: 3
111
+ },
112
+ {
113
+ name: 'endDate',
114
+ label: 'End Date',
115
+ visible: true,
116
+ width: 200,
117
+ order: 4
118
+ }
119
+ ]
120
+ }
@@ -167,3 +167,7 @@ body {
167
167
  --data-card-create-form-padding: 7px;
168
168
  }
169
169
  }
170
+
171
+ body.dark {
172
+ --grid-container-border-color: 1px solid rgba(255, 255, 255, 0.09);
173
+ }