@operato/input 2.0.0-beta.15 → 2.0.0-beta.17
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/CHANGELOG.md +17 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-input-table-column-config.d.ts +22 -0
- package/dist/src/ox-input-table-column-config.js +174 -0
- package/dist/src/ox-input-table-column-config.js.map +1 -0
- package/dist/stories/ox-input-table-column-config.stories.d.ts +34 -0
- package/dist/stories/ox-input-table-column-config.stories.js +99 -0
- package/dist/stories/ox-input-table-column-config.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -4
- package/src/index.ts +1 -0
- package/src/ox-input-table-column-config.ts +183 -0
- package/stories/ox-input-table-column-config.stories.ts +120 -0
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.
|
5
|
+
"version": "2.0.0-beta.17",
|
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,7 +204,7 @@
|
|
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.
|
207
|
+
"@operato/i18n": "^2.0.0-beta.16",
|
204
208
|
"@operato/popup": "^2.0.0-beta.14",
|
205
209
|
"@operato/styles": "^2.0.0-beta.13",
|
206
210
|
"@operato/utils": "^2.0.0-beta.13",
|
@@ -247,5 +251,5 @@
|
|
247
251
|
"prettier --write"
|
248
252
|
]
|
249
253
|
},
|
250
|
-
"gitHead": "
|
254
|
+
"gitHead": "13e26c12f590b683fd6d9dc6c69526c869854780"
|
251
255
|
}
|
package/src/index.ts
CHANGED
@@ -0,0 +1,183 @@
|
|
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/checkbox/checkbox.js'
|
5
|
+
import '@material/web/icon/icon.js'
|
6
|
+
|
7
|
+
export interface ColumnConfig {
|
8
|
+
name: string
|
9
|
+
label: string
|
10
|
+
visible: boolean
|
11
|
+
width: string
|
12
|
+
order: number
|
13
|
+
}
|
14
|
+
|
15
|
+
@customElement('ox-input-table-column-config')
|
16
|
+
export class OxInputTableColumnConfig extends OxFormField {
|
17
|
+
static styles = [
|
18
|
+
css`
|
19
|
+
:host {
|
20
|
+
display: block;
|
21
|
+
padding: 4px;
|
22
|
+
border: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
|
23
|
+
background-color: var(--ox-input-table-column-config-background-color, white);
|
24
|
+
}
|
25
|
+
|
26
|
+
table {
|
27
|
+
width: auto;
|
28
|
+
border-collapse: collapse;
|
29
|
+
font-size: 12px;
|
30
|
+
}
|
31
|
+
|
32
|
+
th,
|
33
|
+
td {
|
34
|
+
border: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
|
35
|
+
padding: 0;
|
36
|
+
text-align: left;
|
37
|
+
}
|
38
|
+
|
39
|
+
th {
|
40
|
+
background-color: var(
|
41
|
+
--ox-input-table-column-config-header-background-color,
|
42
|
+
var(--md-sys-color-secondary-container)
|
43
|
+
);
|
44
|
+
white-space: nowrap;
|
45
|
+
}
|
46
|
+
|
47
|
+
input {
|
48
|
+
font-size: 12px;
|
49
|
+
padding: 0;
|
50
|
+
margin: 0;
|
51
|
+
border: none;
|
52
|
+
width: 100%;
|
53
|
+
box-sizing: border-box;
|
54
|
+
}
|
55
|
+
|
56
|
+
.icon-button {
|
57
|
+
cursor: pointer;
|
58
|
+
display: inline-flex;
|
59
|
+
align-items: center;
|
60
|
+
justify-content: center;
|
61
|
+
padding: 0;
|
62
|
+
margin: 0;
|
63
|
+
border: none;
|
64
|
+
background: none;
|
65
|
+
font-size: 16px;
|
66
|
+
width: 24px;
|
67
|
+
height: 24px;
|
68
|
+
box-sizing: border-box;
|
69
|
+
}
|
70
|
+
|
71
|
+
.icon-button[disabled] {
|
72
|
+
cursor: not-allowed;
|
73
|
+
}
|
74
|
+
`
|
75
|
+
]
|
76
|
+
|
77
|
+
@property({ type: Array }) value: ColumnConfig[] = []
|
78
|
+
|
79
|
+
render() {
|
80
|
+
return html`
|
81
|
+
<table>
|
82
|
+
<thead>
|
83
|
+
<tr>
|
84
|
+
<th></th>
|
85
|
+
<th>Name</th>
|
86
|
+
<th>Label</th>
|
87
|
+
<th>Width</th>
|
88
|
+
<th>Order</th>
|
89
|
+
</tr>
|
90
|
+
</thead>
|
91
|
+
<tbody>
|
92
|
+
${this.value.map(
|
93
|
+
(col, index) => html`
|
94
|
+
<tr name=${col.name}>
|
95
|
+
<td>
|
96
|
+
<md-checkbox .checked=${col.visible} @change=${(e: Event) => this._updateVisibility(e, index)}>
|
97
|
+
</md-checkbox>
|
98
|
+
</td>
|
99
|
+
<td>${col.name}</td>
|
100
|
+
<td>
|
101
|
+
<input type="text" .value=${col.label} @input=${(e: Event) => this._updateLabel(e, index)} />
|
102
|
+
</td>
|
103
|
+
<td>
|
104
|
+
<input type="text" .value=${col.width} @input=${(e: Event) => this._updateWidth(e, index)} />
|
105
|
+
</td>
|
106
|
+
<td>
|
107
|
+
<md-icon class="icon-button" @click=${() => this._moveUp(index)} ?disabled=${index === 0}>
|
108
|
+
arrow_upward
|
109
|
+
</md-icon>
|
110
|
+
<md-icon
|
111
|
+
class="icon-button"
|
112
|
+
@click=${() => this._moveDown(index)}
|
113
|
+
?disabled=${index === this.value.length - 1}
|
114
|
+
>
|
115
|
+
arrow_downward
|
116
|
+
</md-icon>
|
117
|
+
</td>
|
118
|
+
</tr>
|
119
|
+
`
|
120
|
+
)}
|
121
|
+
</tbody>
|
122
|
+
</table>
|
123
|
+
`
|
124
|
+
}
|
125
|
+
|
126
|
+
private _updateVisibility(event: Event, index: number) {
|
127
|
+
const target = event.target as HTMLInputElement
|
128
|
+
this.value[index].visible = target.checked
|
129
|
+
this.requestUpdate()
|
130
|
+
this._notifyChange()
|
131
|
+
}
|
132
|
+
|
133
|
+
private _updateLabel(event: Event, index: number) {
|
134
|
+
const target = event.target as HTMLInputElement
|
135
|
+
this.value[index].label = target.value
|
136
|
+
this.requestUpdate()
|
137
|
+
this._notifyChange()
|
138
|
+
}
|
139
|
+
|
140
|
+
private _updateWidth(event: Event, index: number) {
|
141
|
+
const target = event.target as HTMLInputElement
|
142
|
+
this.value[index].width = target.value
|
143
|
+
this.requestUpdate()
|
144
|
+
this._notifyChange()
|
145
|
+
}
|
146
|
+
|
147
|
+
private _moveUp(index: number) {
|
148
|
+
if (index === 0) return
|
149
|
+
const temp = this.value[index]
|
150
|
+
this.value[index] = this.value[index - 1]
|
151
|
+
this.value[index - 1] = temp
|
152
|
+
this._updateOrder()
|
153
|
+
this.requestUpdate()
|
154
|
+
this._notifyChange()
|
155
|
+
}
|
156
|
+
|
157
|
+
private _moveDown(index: number) {
|
158
|
+
if (index === this.value.length - 1) return
|
159
|
+
const temp = this.value[index]
|
160
|
+
this.value[index] = this.value[index + 1]
|
161
|
+
this.value[index + 1] = temp
|
162
|
+
this._updateOrder()
|
163
|
+
this.requestUpdate()
|
164
|
+
this._notifyChange()
|
165
|
+
}
|
166
|
+
|
167
|
+
private _updateOrder() {
|
168
|
+
this.value = this.value.map((col, index) => ({
|
169
|
+
...col,
|
170
|
+
order: index + 1
|
171
|
+
}))
|
172
|
+
}
|
173
|
+
|
174
|
+
private _notifyChange() {
|
175
|
+
this.dispatchEvent(
|
176
|
+
new CustomEvent('change', {
|
177
|
+
detail: this.value,
|
178
|
+
bubbles: true,
|
179
|
+
composed: true
|
180
|
+
})
|
181
|
+
)
|
182
|
+
}
|
183
|
+
}
|
@@ -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
|
+
}
|