@operato/input 2.0.0-beta.16 → 2.0.0-beta.18

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.16",
5
+ "version": "2.0.0-beta.18",
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
  },
@@ -247,5 +251,5 @@
247
251
  "prettier --write"
248
252
  ]
249
253
  },
250
- "gitHead": "d39ebda0ccb386c224c25373ef3fb94465a4aba3"
254
+ "gitHead": "a0c6eb1c87ed50ce1cf5d1a0e6755418c1789ddf"
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'
@@ -0,0 +1,202 @@
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: string
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, white);
23
+ }
24
+
25
+ table {
26
+ width: auto;
27
+ border-collapse: collapse;
28
+ font-size: 12px;
29
+ border: 0;
30
+ }
31
+
32
+ tr {
33
+ border-bottom: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
34
+ }
35
+
36
+ th,
37
+ td {
38
+ padding: 0 var(--spacing-small, 2px);
39
+ text-align: left;
40
+ }
41
+
42
+ th {
43
+ text-transform: capitalize;
44
+ text-align: center;
45
+ background-color: var(
46
+ --ox-input-table-column-config-header-background-color,
47
+ var(--md-sys-color-secondary-container)
48
+ );
49
+ white-space: nowrap;
50
+ }
51
+
52
+ th *,
53
+ td * {
54
+ vertical-align: middle;
55
+ }
56
+
57
+ td[width] {
58
+ width: 60px;
59
+ text-align: right;
60
+ }
61
+
62
+ input {
63
+ font-size: 12px;
64
+ padding: 0;
65
+ margin: 0;
66
+ border: none;
67
+ width: 100%;
68
+ box-sizing: border-box;
69
+ outline: none;
70
+ }
71
+
72
+ input[type='number'] {
73
+ text-align: right;
74
+ }
75
+
76
+ md-icon {
77
+ cursor: pointer;
78
+ padding: 0;
79
+ margin: 0;
80
+ border: none;
81
+ background: none;
82
+
83
+ --md-icon-size: 16px;
84
+ }
85
+
86
+ md-icon[disabled] {
87
+ cursor: not-allowed;
88
+ color: var(--ox-input-table-column-config-disabled-color, var(--md-sys-color-surface-variant, #ccc));
89
+ }
90
+ `
91
+ ]
92
+
93
+ @property({ type: Array }) value: ColumnConfig[] = []
94
+
95
+ render() {
96
+ return html`
97
+ <table>
98
+ <thead>
99
+ <tr>
100
+ <th></th>
101
+ <th>name</th>
102
+ <th>label</th>
103
+ <th>width</th>
104
+ <th></th>
105
+ </tr>
106
+ </thead>
107
+ <tbody>
108
+ ${this.value.map(
109
+ (col, index) => html`
110
+ <tr name=${col.name}>
111
+ <td>
112
+ <input
113
+ type="checkbox"
114
+ .checked=${col.visible}
115
+ @change=${(e: Event) => this._updateVisibility(e, index)}
116
+ />
117
+ </td>
118
+ <td name>${col.name}</td>
119
+ <td>
120
+ <input type="text" .value=${col.label} @input=${(e: Event) => this._updateLabel(e, index)} />
121
+ </td>
122
+ <td width>
123
+ <input type="number" .value=${col.width} @input=${(e: Event) => this._updateWidth(e, index)} />
124
+ </td>
125
+ <td buttons>
126
+ <md-icon class="icon-button" @click=${() => this._moveUp(index)} ?disabled=${index === 0}>
127
+ arrow_upward
128
+ </md-icon>
129
+ <md-icon
130
+ class="icon-button"
131
+ @click=${() => this._moveDown(index)}
132
+ ?disabled=${index === this.value.length - 1}
133
+ >
134
+ arrow_downward
135
+ </md-icon>
136
+ </td>
137
+ </tr>
138
+ `
139
+ )}
140
+ </tbody>
141
+ </table>
142
+ `
143
+ }
144
+
145
+ private _updateVisibility(event: Event, index: number) {
146
+ const target = event.target as HTMLInputElement
147
+ this.value[index].visible = target.checked
148
+ this.requestUpdate()
149
+ this._notifyChange()
150
+ }
151
+
152
+ private _updateLabel(event: Event, index: number) {
153
+ const target = event.target as HTMLInputElement
154
+ this.value[index].label = target.value
155
+ this.requestUpdate()
156
+ this._notifyChange()
157
+ }
158
+
159
+ private _updateWidth(event: Event, index: number) {
160
+ const target = event.target as HTMLInputElement
161
+ this.value[index].width = target.value
162
+ this.requestUpdate()
163
+ this._notifyChange()
164
+ }
165
+
166
+ private _moveUp(index: number) {
167
+ if (index === 0) return
168
+ const temp = this.value[index]
169
+ this.value[index] = this.value[index - 1]
170
+ this.value[index - 1] = temp
171
+ this._updateOrder()
172
+ this.requestUpdate()
173
+ this._notifyChange()
174
+ }
175
+
176
+ private _moveDown(index: number) {
177
+ if (index === this.value.length - 1) return
178
+ const temp = this.value[index]
179
+ this.value[index] = this.value[index + 1]
180
+ this.value[index + 1] = temp
181
+ this._updateOrder()
182
+ this.requestUpdate()
183
+ this._notifyChange()
184
+ }
185
+
186
+ private _updateOrder() {
187
+ this.value = this.value.map((col, index) => ({
188
+ ...col,
189
+ order: index + 1
190
+ }))
191
+ }
192
+
193
+ private _notifyChange() {
194
+ this.dispatchEvent(
195
+ new CustomEvent('change', {
196
+ detail: this.value,
197
+ bubbles: true,
198
+ composed: true
199
+ })
200
+ )
201
+ }
202
+ }
@@ -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
+ }