@operato/input 2.0.0-beta.3 → 2.0.0-beta.31
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 +187 -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-checkbox.js +4 -8
- package/dist/src/ox-checkbox.js.map +1 -1
- package/dist/src/ox-input-multiple-colors.d.ts +1 -1
- package/dist/src/ox-input-multiple-colors.js +22 -13
- package/dist/src/ox-input-multiple-colors.js.map +1 -1
- package/dist/src/ox-input-select-buttons.d.ts +1 -1
- package/dist/src/ox-input-select-buttons.js +2 -2
- package/dist/src/ox-input-select-buttons.js.map +1 -1
- package/dist/src/ox-input-table-column-config.d.ts +21 -0
- package/dist/src/ox-input-table-column-config.js +202 -0
- package/dist/src/ox-input-table-column-config.js.map +1 -0
- package/dist/src/ox-input-unit-number.d.ts +0 -2
- package/dist/src/ox-input-unit-number.js +3 -5
- package/dist/src/ox-input-unit-number.js.map +1 -1
- package/dist/src/ox-select.js +1 -12
- package/dist/src/ox-select.js.map +1 -1
- 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 +16 -9
- package/src/index.ts +1 -0
- package/src/ox-checkbox.ts +4 -8
- package/src/ox-input-multiple-colors.ts +23 -13
- package/src/ox-input-select-buttons.ts +2 -2
- package/src/ox-input-table-column-config.ts +211 -0
- package/src/ox-input-unit-number.ts +5 -6
- package/src/ox-select.ts +1 -14
- package/stories/ox-input-table-column-config.stories.ts +120 -0
- package/themes/grist-theme.css +4 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
import { __decorate } from "tslib";
|
2
|
+
import { css, html } from 'lit';
|
3
|
+
import { customElement, property } from 'lit/decorators.js';
|
4
|
+
import { OxFormField } from './ox-form-field';
|
5
|
+
import '@material/web/icon/icon.js';
|
6
|
+
let OxInputTableColumnConfig = class OxInputTableColumnConfig extends OxFormField {
|
7
|
+
constructor() {
|
8
|
+
super(...arguments);
|
9
|
+
this.value = [];
|
10
|
+
}
|
11
|
+
static { this.styles = [
|
12
|
+
css `
|
13
|
+
:host {
|
14
|
+
display: block;
|
15
|
+
padding: 4px;
|
16
|
+
border: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
|
17
|
+
background-color: var(--ox-input-table-column-config-background-color, var(--md-sys-color-surface));
|
18
|
+
color: var(--ox-input-table-column-config-color, var(--md-sys-color-on-surface));
|
19
|
+
}
|
20
|
+
|
21
|
+
table {
|
22
|
+
width: auto;
|
23
|
+
border-collapse: collapse;
|
24
|
+
font-size: 12px;
|
25
|
+
border: 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
tr {
|
29
|
+
border-bottom: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));
|
30
|
+
}
|
31
|
+
|
32
|
+
th,
|
33
|
+
td {
|
34
|
+
padding: 0 var(--spacing-small, 2px);
|
35
|
+
text-align: left;
|
36
|
+
}
|
37
|
+
|
38
|
+
th {
|
39
|
+
text-transform: capitalize;
|
40
|
+
text-align: center;
|
41
|
+
background-color: var(
|
42
|
+
--ox-input-table-column-config-header-background-color,
|
43
|
+
var(--md-sys-color-secondary-container)
|
44
|
+
);
|
45
|
+
color: var(--ox-input-table-column-config-header-background-color, var(--md-sys-color-on-secondary-container));
|
46
|
+
white-space: nowrap;
|
47
|
+
}
|
48
|
+
|
49
|
+
th *,
|
50
|
+
td * {
|
51
|
+
vertical-align: middle;
|
52
|
+
}
|
53
|
+
|
54
|
+
td[width] {
|
55
|
+
width: 60px;
|
56
|
+
text-align: right;
|
57
|
+
}
|
58
|
+
|
59
|
+
input {
|
60
|
+
font-size: 12px;
|
61
|
+
padding: 0;
|
62
|
+
margin: 0;
|
63
|
+
border: none;
|
64
|
+
width: 100%;
|
65
|
+
box-sizing: border-box;
|
66
|
+
outline: none;
|
67
|
+
background-color: var(--ox-input-table-column-config-input-background-color, var(--md-sys-color-surface));
|
68
|
+
color: var(--ox-input-table-column-config-input-color, var(--md-sys-color-on-surface));
|
69
|
+
}
|
70
|
+
|
71
|
+
input[type='number'] {
|
72
|
+
text-align: right;
|
73
|
+
}
|
74
|
+
|
75
|
+
md-icon {
|
76
|
+
cursor: pointer;
|
77
|
+
padding: 0;
|
78
|
+
margin: 0;
|
79
|
+
border: none;
|
80
|
+
background: none;
|
81
|
+
|
82
|
+
--md-icon-size: 16px;
|
83
|
+
}
|
84
|
+
|
85
|
+
md-icon[disabled] {
|
86
|
+
cursor: not-allowed;
|
87
|
+
color: var(--ox-input-table-column-config-disabled-color, var(--md-sys-color-surface-variant, #ccc));
|
88
|
+
}
|
89
|
+
`
|
90
|
+
]; }
|
91
|
+
render() {
|
92
|
+
console.log('this.value', this.value);
|
93
|
+
return html `
|
94
|
+
<table>
|
95
|
+
<thead>
|
96
|
+
<tr>
|
97
|
+
<th></th>
|
98
|
+
<th>name</th>
|
99
|
+
<th>label</th>
|
100
|
+
<th>width</th>
|
101
|
+
<th></th>
|
102
|
+
</tr>
|
103
|
+
</thead>
|
104
|
+
<tbody>
|
105
|
+
${(this.value || []).map((col, index) => html `
|
106
|
+
<tr name=${col.name}>
|
107
|
+
<td>
|
108
|
+
<input
|
109
|
+
type="checkbox"
|
110
|
+
.checked=${col.visible}
|
111
|
+
@change=${(e) => this._updateVisibility(e, index)}
|
112
|
+
/>
|
113
|
+
</td>
|
114
|
+
<td name>${col.name}</td>
|
115
|
+
<td>
|
116
|
+
<input type="text" .value=${col.label} @input=${(e) => this._updateLabel(e, index)} />
|
117
|
+
</td>
|
118
|
+
<td width>
|
119
|
+
<input
|
120
|
+
type="number"
|
121
|
+
.value=${String(col.width)}
|
122
|
+
@input=${(e) => this._updateWidth(e, index)}
|
123
|
+
/>
|
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
|
+
</tbody>
|
140
|
+
</table>
|
141
|
+
`;
|
142
|
+
}
|
143
|
+
_updateVisibility(event, index) {
|
144
|
+
const target = event.target;
|
145
|
+
this.value[index].visible = target.checked;
|
146
|
+
this.requestUpdate();
|
147
|
+
this._notifyChange();
|
148
|
+
}
|
149
|
+
_updateLabel(event, index) {
|
150
|
+
const target = event.target;
|
151
|
+
this.value[index].label = target.value;
|
152
|
+
this.requestUpdate();
|
153
|
+
this._notifyChange();
|
154
|
+
}
|
155
|
+
_updateWidth(event, index) {
|
156
|
+
const target = event.target;
|
157
|
+
this.value[index].width = target.valueAsNumber;
|
158
|
+
this.requestUpdate();
|
159
|
+
this._notifyChange();
|
160
|
+
}
|
161
|
+
_moveUp(index) {
|
162
|
+
if (index === 0)
|
163
|
+
return;
|
164
|
+
const temp = this.value[index];
|
165
|
+
this.value[index] = this.value[index - 1];
|
166
|
+
this.value[index - 1] = temp;
|
167
|
+
this._updateOrder();
|
168
|
+
this.requestUpdate();
|
169
|
+
this._notifyChange();
|
170
|
+
}
|
171
|
+
_moveDown(index) {
|
172
|
+
if (index === this.value.length - 1)
|
173
|
+
return;
|
174
|
+
const temp = this.value[index];
|
175
|
+
this.value[index] = this.value[index + 1];
|
176
|
+
this.value[index + 1] = temp;
|
177
|
+
this._updateOrder();
|
178
|
+
this.requestUpdate();
|
179
|
+
this._notifyChange();
|
180
|
+
}
|
181
|
+
_updateOrder() {
|
182
|
+
this.value = this.value.map((col, index) => ({
|
183
|
+
...col,
|
184
|
+
order: index + 1
|
185
|
+
}));
|
186
|
+
}
|
187
|
+
_notifyChange() {
|
188
|
+
this.dispatchEvent(new CustomEvent('change', {
|
189
|
+
detail: this.value,
|
190
|
+
bubbles: true,
|
191
|
+
composed: true
|
192
|
+
}));
|
193
|
+
}
|
194
|
+
};
|
195
|
+
__decorate([
|
196
|
+
property({ type: Array })
|
197
|
+
], OxInputTableColumnConfig.prototype, "value", void 0);
|
198
|
+
OxInputTableColumnConfig = __decorate([
|
199
|
+
customElement('ox-input-table-column-config')
|
200
|
+
], OxInputTableColumnConfig);
|
201
|
+
export { OxInputTableColumnConfig };
|
202
|
+
//# sourceMappingURL=ox-input-table-column-config.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ox-input-table-column-config.js","sourceRoot":"","sources":["../../src/ox-input-table-column-config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,4BAA4B,CAAA;AAW5B,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,WAAW;IAAlD;;QAkFsB,UAAK,GAAmB,EAAE,CAAA;IAkHvD,CAAC;aAnMQ,WAAM,GAAG;QACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6EF;KACF,AA/EY,CA+EZ;IAID,MAAM;QACJ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QACrC,OAAO,IAAI,CAAA;;;;;;;;;;;;YAYH,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CACtB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC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,EAAE,EAAE,CAAC,CAAC;YAC3C,GAAG,GAAG;YACN,KAAK,EAAE,KAAK,GAAG,CAAC;SACjB,CAAC,CAAC,CAAA;IACL,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE;YACxB,MAAM,EAAE,IAAI,CAAC,KAAK;YAClB,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CACH,CAAA;IACH,CAAC;;AAjH0B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;uDAA2B;AAlF1C,wBAAwB;IADpC,aAAa,CAAC,8BAA8B,CAAC;GACjC,wBAAwB,CAoMpC","sourcesContent":["import { css, html } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { OxFormField } from './ox-form-field'\nimport '@material/web/icon/icon.js'\n\nexport interface ColumnConfig {\n name: string\n label: string\n visible: boolean\n width: number\n order: number\n}\n\n@customElement('ox-input-table-column-config')\nexport class OxInputTableColumnConfig extends OxFormField {\n static styles = [\n css`\n :host {\n display: block;\n padding: 4px;\n border: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));\n background-color: var(--ox-input-table-column-config-background-color, var(--md-sys-color-surface));\n color: var(--ox-input-table-column-config-color, var(--md-sys-color-on-surface));\n }\n\n table {\n width: auto;\n border-collapse: collapse;\n font-size: 12px;\n border: 0;\n }\n\n tr {\n border-bottom: 1px solid var(--ox-input-table-column-config-border-color, var(--md-sys-color-on-surface));\n }\n\n th,\n td {\n padding: 0 var(--spacing-small, 2px);\n text-align: left;\n }\n\n th {\n text-transform: capitalize;\n text-align: center;\n background-color: var(\n --ox-input-table-column-config-header-background-color,\n var(--md-sys-color-secondary-container)\n );\n color: var(--ox-input-table-column-config-header-background-color, var(--md-sys-color-on-secondary-container));\n white-space: nowrap;\n }\n\n th *,\n td * {\n vertical-align: middle;\n }\n\n td[width] {\n width: 60px;\n text-align: right;\n }\n\n input {\n font-size: 12px;\n padding: 0;\n margin: 0;\n border: none;\n width: 100%;\n box-sizing: border-box;\n outline: none;\n background-color: var(--ox-input-table-column-config-input-background-color, var(--md-sys-color-surface));\n color: var(--ox-input-table-column-config-input-color, var(--md-sys-color-on-surface));\n }\n\n input[type='number'] {\n text-align: right;\n }\n\n md-icon {\n cursor: pointer;\n padding: 0;\n margin: 0;\n border: none;\n background: none;\n\n --md-icon-size: 16px;\n }\n\n md-icon[disabled] {\n cursor: not-allowed;\n color: var(--ox-input-table-column-config-disabled-color, var(--md-sys-color-surface-variant, #ccc));\n }\n `\n ]\n\n @property({ type: Array }) value: ColumnConfig[] = []\n\n render() {\n console.log('this.value', this.value)\n return html`\n <table>\n <thead>\n <tr>\n <th></th>\n <th>name</th>\n <th>label</th>\n <th>width</th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n ${(this.value || []).map(\n (col, index) => html`\n <tr name=${col.name}>\n <td>\n <input\n type=\"checkbox\"\n .checked=${col.visible}\n @change=${(e: Event) => this._updateVisibility(e, index)}\n />\n </td>\n <td name>${col.name}</td>\n <td>\n <input type=\"text\" .value=${col.label} @input=${(e: Event) => this._updateLabel(e, index)} />\n </td>\n <td width>\n <input\n type=\"number\"\n .value=${String(col.width)}\n @input=${(e: Event) => this._updateWidth(e, index)}\n />\n </td>\n <td buttons>\n <md-icon class=\"icon-button\" @click=${() => this._moveUp(index)} ?disabled=${index === 0}>\n arrow_upward\n </md-icon>\n <md-icon\n class=\"icon-button\"\n @click=${() => this._moveDown(index)}\n ?disabled=${index === this.value.length - 1}\n >\n arrow_downward\n </md-icon>\n </td>\n </tr>\n `\n )}\n </tbody>\n </table>\n `\n }\n\n private _updateVisibility(event: Event, index: number) {\n const target = event.target as HTMLInputElement\n this.value[index].visible = target.checked\n this.requestUpdate()\n this._notifyChange()\n }\n\n private _updateLabel(event: Event, index: number) {\n const target = event.target as HTMLInputElement\n this.value[index].label = target.value\n this.requestUpdate()\n this._notifyChange()\n }\n\n private _updateWidth(event: Event, index: number) {\n const target = event.target as HTMLInputElement\n this.value[index].width = target.valueAsNumber\n this.requestUpdate()\n this._notifyChange()\n }\n\n private _moveUp(index: number) {\n if (index === 0) return\n const temp = this.value[index]\n this.value[index] = this.value[index - 1]\n this.value[index - 1] = temp\n this._updateOrder()\n this.requestUpdate()\n this._notifyChange()\n }\n\n private _moveDown(index: number) {\n if (index === this.value.length - 1) return\n const temp = this.value[index]\n this.value[index] = this.value[index + 1]\n this.value[index + 1] = temp\n this._updateOrder()\n this.requestUpdate()\n this._notifyChange()\n }\n\n private _updateOrder() {\n this.value = this.value.map((col, index) => ({\n ...col,\n order: index + 1\n }))\n }\n\n private _notifyChange() {\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: this.value,\n bubbles: true,\n composed: true\n })\n )\n }\n}\n"]}
|
@@ -2,7 +2,6 @@
|
|
2
2
|
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
3
|
*/
|
4
4
|
import '@material/web/icon/icon.js';
|
5
|
-
import { PropertyValues } from 'lit';
|
6
5
|
import { OxPopupList } from '@operato/popup';
|
7
6
|
import { OxFormField } from './ox-form-field';
|
8
7
|
export declare class OxInputUnitNumber extends OxFormField {
|
@@ -13,7 +12,6 @@ export declare class OxInputUnitNumber extends OxFormField {
|
|
13
12
|
input: HTMLInputElement;
|
14
13
|
popup: OxPopupList;
|
15
14
|
render(): import("lit-html").TemplateResult<1>;
|
16
|
-
updated(changes: PropertyValues<this>): void;
|
17
15
|
_onChangeValue(e: Event): void;
|
18
16
|
_toUserUnit(stdValue: string | number | undefined): number | undefined;
|
19
17
|
_toUserUnitByRate(stdValue: string | number | undefined, converterRate: number): number;
|
@@ -251,6 +251,9 @@ let OxInputUnitNumber = class OxInputUnitNumber extends OxFormField {
|
|
251
251
|
.value=${userUnit}
|
252
252
|
@select=${(e) => {
|
253
253
|
this.userUnit = e.detail;
|
254
|
+
this.dispatchEvent(new CustomEvent('user-unit-change', {
|
255
|
+
detail: this.userUnit
|
256
|
+
}));
|
254
257
|
}}
|
255
258
|
>
|
256
259
|
<div option value=${this.stdUnit}>${this.stdUnit}</div>
|
@@ -260,11 +263,6 @@ let OxInputUnitNumber = class OxInputUnitNumber extends OxFormField {
|
|
260
263
|
</div>
|
261
264
|
`;
|
262
265
|
}
|
263
|
-
updated(changes) {
|
264
|
-
// if (changes.has('stdUnit')) {
|
265
|
-
// this.userUnit = this.userUnit || this.stdUnit
|
266
|
-
// }
|
267
|
-
}
|
268
266
|
_onChangeValue(e) {
|
269
267
|
this.value = this._toStdUnit(this.input.value);
|
270
268
|
this.dispatchEvent(new CustomEvent('change', {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ox-input-unit-number.js","sourceRoot":"","sources":["../../src/ox-input-unit-number.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,4BAA4B,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAIxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,YAAY,GAA+E;IAC/F,EAAE,EAAE;QACF,EAAE,EAAE,OAAO;QACX,CAAC,EAAE,IAAI;QACP,GAAG,EAAE,KAAK;KACX;IACD,GAAG,EAAE;QACH,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC,EAAE;KACtB;IACD,GAAG,EAAE;QACH,IAAI,EAAE,IAAI;QACV,GAAG,EAAE,CAAC,GAAG,EAAE;QACX,EAAE,EAAE,CAAC,GAAG,IAAI;QACZ,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;QACpB,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC;KAC5B;IACD,CAAC,EAAE;Q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AAM,cAAc,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAEhE,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,IAAI,CAAC,CAAC,CAAA;QAC9D,CAAC,CAAC,wCAAwC;aAAM,CAAC;YAC/C,OAAO,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,cAA2C,CAAC,CAAA;QAC1F,CAAC;IACH,CAAC;IAED,gBAAgB,CAAC,SAAsC,EAAE,aAAqB;QAC5E,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,aAAa,CAAA;IACjF,CAAC;IAED,oBAAoB,CAAC,SAAsC,EAAE,kBAA6C;QACxG,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;IACjD,CAAC;;AAzH2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAqB;AACG;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;kDAAiB;AACf;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;mDAAkB;AAErD;IAAf,KAAK,CAAC,OAAO,CAAC;gDAAyB;AAChB;IAAvB,KAAK,CAAC,eAAe,CAAC;gDAAoB;AAhEhC,iBAAiB;IAD7B,aAAa,CAAC,sBAAsB,CAAC;GACzB,iBAAiB,CAqL7B","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport '@material/web/icon/icon.js'\n\nimport { css, html, PropertyValues } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { ifDefined } from 'lit/directives/if-defined.js'\n\nimport { OxPopupList } from '@operato/popup'\n\nimport { OxFormField } from './ox-form-field'\n\nconst UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number | ((v: number) => number)[] } } = {\n kg: {\n mg: 1000000,\n g: 1000,\n ton: 0.001\n },\n rad: {\n degree: 180 / Math.PI\n },\n sec: {\n msec: 1000,\n min: 1 / 60,\n hr: 1 / 3600,\n day: 1 / (3600 * 24),\n year: 1 / (3600 * 24 * 365)\n },\n m: {\n mm: 1000,\n cm: 100,\n inch: 39.37008\n },\n 'g/mol': {\n 'kg/kmol': 1,\n 'g/kmol': 1000\n },\n m2: {\n mm2: 1000000,\n cm2: 1000\n },\n m3: {\n cm3: 1000000,\n L: 1000,\n mL: 1000000\n },\n 'kg/m3': {\n 'g/m3': 1000,\n 'g/L': 1,\n 'g/cm3': 0.001,\n 'kg/L': 0.001,\n 'g/mL': 0.001\n },\n 'm/sec': {\n 'm/min': 60,\n 'm/hr': 3600,\n 'cm/sec': 100,\n 'cm/min': 6000,\n 'cm/hr': 360000\n },\n N: {\n kN: 0.001,\n kgf: 0.101971621\n },\n Pa: {\n atm: 1 / 101325,\n bar: 1 / 100000,\n 'kgf/cm2': 1 / 9.80665 / 10000,\n MPa: 1 / 1000000,\n kPa: 1 / 1000,\n psi: 1 / 6894.76,\n mmH2O: 1 / 9.80665,\n mmHg: 1 / 133.32\n },\n 'kg/sec': {\n 'kg/min': 60,\n 'kg/hr': 3600,\n 'ton/hr': 3.6,\n 'ton/year': (60 * 60 * 24 * 365) / 1000\n },\n 'kg/m2/sec': {\n 'kg/m2/min': 60,\n 'kg/m2/hr': 3600\n },\n 'mol/sec': {\n 'kmol/sec': 1 / 1000\n },\n 'mol/m2/sec': {\n 'kmol/m2/sec': 1 / 1000\n },\n 'Sm3/sec': {\n 'Sm3/hr': 3600,\n 'Sm3/min': 60,\n 'SL/min': 60000,\n 'SL/sec': 1000,\n 'Scm3/min': 60000000,\n 'Scm3/sec': 1000000\n },\n 'Nm3/sec': {\n 'Nm3/hr': 3600,\n 'Nm3/min': 60,\n 'NL/min': 60000,\n 'NL/sec': 1000,\n 'Ncm3/min': 60000000,\n 'Ncm3/sec': 1000000\n },\n 'Am3/sec': {\n 'Am3/hr': 3600,\n 'Am3/min': 60,\n 'AL/min': 60000,\n 'AL/sec': 1000,\n 'Acm3/min': 60000000,\n 'Acm3/sec': 1000000\n },\n J: {\n kJ: 1 / 1000,\n MJ: 1 / 1000000,\n cal: 1 / 4.184,\n kcal: 1 / 4.184 / 1000\n },\n W: {\n kW: 1 / 1000,\n MW: 1 / 1000000,\n 'kcal/hr': 859.85 / 1000,\n hp: 1 / 745.7\n },\n 'W/m2': {\n 'kW/m2': 1 / 1000,\n 'W/cm2': 1 / 10000,\n 'kW/cm2': 1 / 10000000\n },\n 'J/kg': {\n 'kJ/kg': 1 / 1000,\n 'cal/g': 1 / 4.184 / 1000,\n 'cal/kg': 1 / 4.184,\n 'kcal/kg': 1 / 4.184 / 1000\n },\n 'J/kg/K': {\n 'kJ/kg/K': 1 / 1000,\n 'cal/kg/K': 1 / 4.184,\n 'kcal/kg/K': 1 / 4.184 / 1000,\n 'cal/g/K': 1 / 4.184 / 1000\n },\n 'W/m/K': {\n 'kW/m/K': 1 / 1000,\n 'W/cm/K': 1 / 100,\n 'kW/cm/K': 1 / 100 / 1000\n },\n 'W/m2/K': {\n 'kW/m2/K': 1 / 1000,\n 'kcal/hr/m2/oC': 1 / 1.163\n },\n 'N sec/m2': {\n 'Pa sec': 1,\n 'mPa sec': 1000,\n 'kg/m/sec': 1,\n 'g/cm/sec': 10,\n P: 10,\n cP: 1000\n },\n 'm2 oC/W': {\n 'm2 oC/kW': 1000\n },\n '%': {},\n ppm: {},\n K: {\n '°C': [(v: number) => v - 273.15, (v: number) => v + 273.15]\n }\n}\n\n@customElement('ox-input-unit-number')\nexport class OxInputUnitNumber extends OxFormField {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: row;\n align-items: center;\n\n --md-icon-size: var(--fontsize-default, 14px);\n }\n\n input {\n flex: 1;\n border: 0;\n border-bottom: 1px solid rgba(0, 0, 0, 0.15);\n padding: var(--spacing-tiny);\n font: var(--input-font);\n color: var(--md-sys-color-on-primary-container);\n min-width: 40px;\n }\n\n input:focus {\n outline: none;\n border-bottom: 1px solid var(--md-sys-color-on-primary-container);\n }\n\n input::-webkit-outer-spin-button,\n input::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n\n input[type='number'] {\n text-align: right;\n -moz-appearance: textfield;\n }\n\n #unit {\n flex: 1;\n display: flex;\n align-items: center;\n position: relative;\n margin-left: var(--margin-narrow);\n font: var(--label-font);\n color: var(--label-color, var(--md-sys-color-on-surface));\n min-width: 24px;\n }\n\n md-icon {\n color: var(--md-sys-color-on-primary-container, #3c3938);\n margin-left: auto;\n }\n\n ox-popup-list {\n right: 0;\n }\n `\n ]\n\n @property({ type: String }) placeholder?: string\n @property({ type: String, attribute: 'std-unit' }) stdUnit!: string\n @property({ type: String, attribute: 'user-unit' }) userUnit?: string\n\n @query('input') input!: HTMLInputElement\n @query('ox-popup-list') popup!: OxPopupList\n\n render() {\n const userUnit = this.userUnit || this.stdUnit\n const units = (UNIT_SYSTEMS[this.stdUnit] && Object.keys(UNIT_SYSTEMS[this.stdUnit])) || []\n\n return html`\n <input\n type=\"number\"\n .value=${this._toUserUnit(this.value)}\n placeholder=${ifDefined(this.placeholder)}\n @change=${(e: Event) => this._onChangeValue(e)}\n ?disabled=${this.disabled}\n />\n <div\n id=\"unit\"\n @click=${(e: Event) => {\n if (this.disabled) {\n return\n }\n\n const target = e.currentTarget as HTMLElement\n this.popup.open({\n right: 0,\n top: target.clientTop + target.offsetHeight\n })\n }}\n >\n ${userUnit}\n <ox-popup-list\n .value=${userUnit}\n @select=${(e: CustomEvent) => {\n this.userUnit = e.detail\n }}\n >\n <div option value=${this.stdUnit}>${this.stdUnit}</div>\n ${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}\n </ox-popup-list>\n <md-icon>expand_more</md-icon>\n </div>\n `\n }\n\n updated(changes: PropertyValues<this>) {\n // if (changes.has('stdUnit')) {\n // this.userUnit = this.userUnit || this.stdUnit\n // }\n }\n\n _onChangeValue(e: Event) {\n this.value = this._toStdUnit(this.input.value)\n\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n }\n\n _toUserUnit(stdValue: string | number | undefined) {\n if (!this.userUnit) {\n return\n }\n\n if (this.userUnit === this.stdUnit) {\n return Number(stdValue)\n }\n\n const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]\n\n if (!converterValue) {\n delete this.userUnit\n return\n }\n\n if (typeof converterValue === 'number') {\n return this._toUserUnitByRate(stdValue, converterValue || 1)\n } /* should be converter function array */ else {\n return this._toUserUnitByFunction(stdValue, converterValue as ((v: number) => number)[])\n }\n }\n\n _toUserUnitByRate(stdValue: string | number | undefined, converterRate: number) {\n return Number(stdValue) * converterRate\n }\n\n _toUserUnitByFunction(stdValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {\n return converterFunctions[0](Number(stdValue))\n }\n\n _toStdUnit(userValue: string | number | undefined) {\n if (!this.userUnit) {\n return\n }\n\n if (this.userUnit === this.stdUnit) {\n return Number(userValue)\n }\n\n const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]\n\n if (typeof converterValue === 'number') {\n return this._toStdUnitByRate(userValue, converterValue || 1)\n } /* should be converter function array */ else {\n return this._toStdUnitByFunction(userValue, converterValue as ((v: number) => number)[])\n }\n }\n\n _toStdUnitByRate(userValue: string | number | undefined, converterRate: number) {\n return isNaN(Number(userValue)) ? undefined : Number(userValue) / converterRate\n }\n\n _toStdUnitByFunction(userValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {\n return converterFunctions[1](Number(userValue))\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"ox-input-unit-number.js","sourceRoot":"","sources":["../../src/ox-input-unit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,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,aAAa,CAAA;IACjF,CAAC;IAED,oBAAoB,CAAC,SAAsC,EAAE,kBAA6C;QACxG,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;IACjD,CAAC;;AAxH2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAqB;AACG;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;kDAAiB;AACf;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;mDAAkB;AAErD;IAAf,KAAK,CAAC,OAAO,CAAC;gDAAyB;AAChB;IAAvB,KAAK,CAAC,eAAe,CAAC;gDAAoB;AAhEhC,iBAAiB;IAD7B,aAAa,CAAC,sBAAsB,CAAC;GACzB,iBAAiB,CAoL7B","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport '@material/web/icon/icon.js'\n\nimport { css, html, PropertyValues } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { ifDefined } from 'lit/directives/if-defined.js'\n\nimport { OxPopupList } from '@operato/popup'\n\nimport { OxFormField } from './ox-form-field'\n\nconst UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number | ((v: number) => number)[] } } = {\n kg: {\n mg: 1000000,\n g: 1000,\n ton: 0.001\n },\n rad: {\n degree: 180 / Math.PI\n },\n sec: {\n msec: 1000,\n min: 1 / 60,\n hr: 1 / 3600,\n day: 1 / (3600 * 24),\n year: 1 / (3600 * 24 * 365)\n },\n m: {\n mm: 1000,\n cm: 100,\n inch: 39.37008\n },\n 'g/mol': {\n 'kg/kmol': 1,\n 'g/kmol': 1000\n },\n m2: {\n mm2: 1000000,\n cm2: 1000\n },\n m3: {\n cm3: 1000000,\n L: 1000,\n mL: 1000000\n },\n 'kg/m3': {\n 'g/m3': 1000,\n 'g/L': 1,\n 'g/cm3': 0.001,\n 'kg/L': 0.001,\n 'g/mL': 0.001\n },\n 'm/sec': {\n 'm/min': 60,\n 'm/hr': 3600,\n 'cm/sec': 100,\n 'cm/min': 6000,\n 'cm/hr': 360000\n },\n N: {\n kN: 0.001,\n kgf: 0.101971621\n },\n Pa: {\n atm: 1 / 101325,\n bar: 1 / 100000,\n 'kgf/cm2': 1 / 9.80665 / 10000,\n MPa: 1 / 1000000,\n kPa: 1 / 1000,\n psi: 1 / 6894.76,\n mmH2O: 1 / 9.80665,\n mmHg: 1 / 133.32\n },\n 'kg/sec': {\n 'kg/min': 60,\n 'kg/hr': 3600,\n 'ton/hr': 3.6,\n 'ton/year': (60 * 60 * 24 * 365) / 1000\n },\n 'kg/m2/sec': {\n 'kg/m2/min': 60,\n 'kg/m2/hr': 3600\n },\n 'mol/sec': {\n 'kmol/sec': 1 / 1000\n },\n 'mol/m2/sec': {\n 'kmol/m2/sec': 1 / 1000\n },\n 'Sm3/sec': {\n 'Sm3/hr': 3600,\n 'Sm3/min': 60,\n 'SL/min': 60000,\n 'SL/sec': 1000,\n 'Scm3/min': 60000000,\n 'Scm3/sec': 1000000\n },\n 'Nm3/sec': {\n 'Nm3/hr': 3600,\n 'Nm3/min': 60,\n 'NL/min': 60000,\n 'NL/sec': 1000,\n 'Ncm3/min': 60000000,\n 'Ncm3/sec': 1000000\n },\n 'Am3/sec': {\n 'Am3/hr': 3600,\n 'Am3/min': 60,\n 'AL/min': 60000,\n 'AL/sec': 1000,\n 'Acm3/min': 60000000,\n 'Acm3/sec': 1000000\n },\n J: {\n kJ: 1 / 1000,\n MJ: 1 / 1000000,\n cal: 1 / 4.184,\n kcal: 1 / 4.184 / 1000\n },\n W: {\n kW: 1 / 1000,\n MW: 1 / 1000000,\n 'kcal/hr': 859.85 / 1000,\n hp: 1 / 745.7\n },\n 'W/m2': {\n 'kW/m2': 1 / 1000,\n 'W/cm2': 1 / 10000,\n 'kW/cm2': 1 / 10000000\n },\n 'J/kg': {\n 'kJ/kg': 1 / 1000,\n 'cal/g': 1 / 4.184 / 1000,\n 'cal/kg': 1 / 4.184,\n 'kcal/kg': 1 / 4.184 / 1000\n },\n 'J/kg/K': {\n 'kJ/kg/K': 1 / 1000,\n 'cal/kg/K': 1 / 4.184,\n 'kcal/kg/K': 1 / 4.184 / 1000,\n 'cal/g/K': 1 / 4.184 / 1000\n },\n 'W/m/K': {\n 'kW/m/K': 1 / 1000,\n 'W/cm/K': 1 / 100,\n 'kW/cm/K': 1 / 100 / 1000\n },\n 'W/m2/K': {\n 'kW/m2/K': 1 / 1000,\n 'kcal/hr/m2/oC': 1 / 1.163\n },\n 'N sec/m2': {\n 'Pa sec': 1,\n 'mPa sec': 1000,\n 'kg/m/sec': 1,\n 'g/cm/sec': 10,\n P: 10,\n cP: 1000\n },\n 'm2 oC/W': {\n 'm2 oC/kW': 1000\n },\n '%': {},\n ppm: {},\n K: {\n '°C': [(v: number) => v - 273.15, (v: number) => v + 273.15]\n }\n}\n\n@customElement('ox-input-unit-number')\nexport class OxInputUnitNumber extends OxFormField {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: row;\n align-items: center;\n\n --md-icon-size: var(--fontsize-default, 14px);\n }\n\n input {\n flex: 1;\n border: 0;\n border-bottom: 1px solid rgba(0, 0, 0, 0.15);\n padding: var(--spacing-tiny);\n font: var(--input-font);\n color: var(--md-sys-color-on-primary-container);\n min-width: 40px;\n }\n\n input:focus {\n outline: none;\n border-bottom: 1px solid var(--md-sys-color-on-primary-container);\n }\n\n input::-webkit-outer-spin-button,\n input::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n\n input[type='number'] {\n text-align: right;\n -moz-appearance: textfield;\n }\n\n #unit {\n flex: 1;\n display: flex;\n align-items: center;\n position: relative;\n margin-left: var(--margin-narrow);\n font: var(--label-font);\n color: var(--label-color, var(--md-sys-color-on-surface));\n min-width: 24px;\n }\n\n md-icon {\n color: var(--md-sys-color-on-primary-container, #3c3938);\n margin-left: auto;\n }\n\n ox-popup-list {\n right: 0;\n }\n `\n ]\n\n @property({ type: String }) placeholder?: string\n @property({ type: String, attribute: 'std-unit' }) stdUnit!: string\n @property({ type: String, attribute: 'user-unit' }) userUnit?: string\n\n @query('input') input!: HTMLInputElement\n @query('ox-popup-list') popup!: OxPopupList\n\n render() {\n const userUnit = this.userUnit || this.stdUnit\n const units = (UNIT_SYSTEMS[this.stdUnit] && Object.keys(UNIT_SYSTEMS[this.stdUnit])) || []\n\n return html`\n <input\n type=\"number\"\n .value=${this._toUserUnit(this.value)}\n placeholder=${ifDefined(this.placeholder)}\n @change=${(e: Event) => this._onChangeValue(e)}\n ?disabled=${this.disabled}\n />\n <div\n id=\"unit\"\n @click=${(e: Event) => {\n if (this.disabled) {\n return\n }\n\n const target = e.currentTarget as HTMLElement\n this.popup.open({\n right: 0,\n top: target.clientTop + target.offsetHeight\n })\n }}\n >\n ${userUnit}\n <ox-popup-list\n .value=${userUnit}\n @select=${(e: CustomEvent) => {\n this.userUnit = e.detail\n this.dispatchEvent(\n new CustomEvent('user-unit-change', {\n detail: this.userUnit\n })\n )\n }}\n >\n <div option value=${this.stdUnit}>${this.stdUnit}</div>\n ${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}\n </ox-popup-list>\n <md-icon>expand_more</md-icon>\n </div>\n `\n }\n\n _onChangeValue(e: Event) {\n this.value = this._toStdUnit(this.input.value)\n\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n }\n\n _toUserUnit(stdValue: string | number | undefined) {\n if (!this.userUnit) {\n return\n }\n\n if (this.userUnit === this.stdUnit) {\n return Number(stdValue)\n }\n\n const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]\n\n if (!converterValue) {\n delete this.userUnit\n return\n }\n\n if (typeof converterValue === 'number') {\n return this._toUserUnitByRate(stdValue, converterValue || 1)\n } /* should be converter function array */ else {\n return this._toUserUnitByFunction(stdValue, converterValue as ((v: number) => number)[])\n }\n }\n\n _toUserUnitByRate(stdValue: string | number | undefined, converterRate: number) {\n return Number(stdValue) * converterRate\n }\n\n _toUserUnitByFunction(stdValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {\n return converterFunctions[0](Number(stdValue))\n }\n\n _toStdUnit(userValue: string | number | undefined) {\n if (!this.userUnit) {\n return\n }\n\n if (this.userUnit === this.stdUnit) {\n return Number(userValue)\n }\n\n const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]\n\n if (typeof converterValue === 'number') {\n return this._toStdUnitByRate(userValue, converterValue || 1)\n } /* should be converter function array */ else {\n return this._toStdUnitByFunction(userValue, converterValue as ((v: number) => number)[])\n }\n }\n\n _toStdUnitByRate(userValue: string | number | undefined, converterRate: number) {\n return isNaN(Number(userValue)) ? undefined : Number(userValue) / converterRate\n }\n\n _toStdUnitByFunction(userValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {\n return converterFunctions[1](Number(userValue))\n }\n}\n"]}
|
package/dist/src/ox-select.js
CHANGED
@@ -8,18 +8,7 @@ import './ox-checkbox.js';
|
|
8
8
|
import { css, html, render } from 'lit';
|
9
9
|
import { customElement, property, state } from 'lit/decorators.js';
|
10
10
|
import { TooltipStyles } from '@operato/styles';
|
11
|
-
import { detectOverflow } from '@operato/utils';
|
12
11
|
import { OxFormField } from './ox-form-field.js';
|
13
|
-
function onmouseover(e) {
|
14
|
-
const element = e.target;
|
15
|
-
if (detectOverflow(element)) {
|
16
|
-
element.setAttribute('data-tooltip', element.textContent);
|
17
|
-
}
|
18
|
-
}
|
19
|
-
function onmouseout(e) {
|
20
|
-
const element = e.target;
|
21
|
-
element.removeAttribute('data-tooltip');
|
22
|
-
}
|
23
12
|
let OxSelect = class OxSelect extends OxFormField {
|
24
13
|
constructor() {
|
25
14
|
super(...arguments);
|
@@ -88,7 +77,7 @@ let OxSelect = class OxSelect extends OxFormField {
|
|
88
77
|
'';
|
89
78
|
return html `
|
90
79
|
<div @click=${this.expand}>
|
91
|
-
<span
|
80
|
+
<span data-reactive-tooltip>${label}</span>
|
92
81
|
<md-icon>expand_more</md-icon>
|
93
82
|
</div>
|
94
83
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ox-select.js","sourceRoot":"","sources":["../../src/ox-select.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,4BAA4B,CAAA;AACnC,OAAO,iCAAiC,CAAA;AACxC,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAA2B,MAAM,KAAK,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGzE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,SAAS,WAAW,CAAC,CAAQ;IAC3B,MAAM,OAAO,GAAG,CAAC,CAAC,MAAyB,CAAA;IAC3C,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,WAAY,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,CAAQ;IAC1B,MAAM,OAAO,GAAG,CAAC,CAAC,MAAyB,CAAA;IAC3C,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,CAAA;AACzC,CAAC;AAGM,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,WAAW;IAAlC;;QAwDuB,SAAI,GAAW,EAAE,CAAA;QACjB,gBAAW,GAAW,EAAE,CAAA;QAE3C,UAAK,GAAsB,EAAE,CAAA;IA4HxC,CAA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AK,GAAG,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAA;YAErE,MAAM,KAAK,GAAG;gBACZ,GAAG,EAAE,IAAI,CAAC,YAAY;gBACtB,CAAC,KAAK,CAAC,EAAE,CAAC;aACX,CAAA;YAED,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;;AA9H2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAAkB;AACjB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAAyB;AAE3C;IAAR,KAAK,EAAE;uCAA8B;AA3D3B,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CAuLpB","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport '@material/web/icon/icon.js'\nimport '@operato/popup/ox-popup-list.js'\nimport './ox-checkbox.js'\n\nimport { css, html, render, PropertyValues, nothing } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { OxPopupList } from '@operato/popup'\nimport { TooltipStyles } from '@operato/styles'\nimport { detectOverflow } from '@operato/utils'\n\nimport { OxFormField } from './ox-form-field.js'\n\nfunction onmouseover(e: Event) {\n const element = e.target as HTMLSpanElement\n if (detectOverflow(element)) {\n element.setAttribute('data-tooltip', element.textContent!)\n }\n}\n\nfunction onmouseout(e: Event) {\n const element = e.target as HTMLSpanElement\n element.removeAttribute('data-tooltip')\n}\n\n@customElement('ox-select')\nexport class OxSelect extends OxFormField {\n static styles = [\n TooltipStyles,\n css`\n :host {\n display: block;\n position: relative;\n border-bottom: 1px solid rgba(0, 0, 0, 0.15);\n\n --ox-select-padding: var(--spacing-tiny);\n --ox-select-font: var(--input-font);\n --ox-select-color: var(--input-color, var(--md-sys-color-on-surface-variant));\n --ox-select-icon-color: var(--theme-primary-text-color, var(--md-sys-color-on-surface-variant));\n --ox-select-icon-hover-color: var(--md-sys-color-on-primary-container, #3c3938);\n }\n\n div {\n width: 100%;\n box-sizing: border-box;\n\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n padding: var(--ox-select-padding);\n font: var(--ox-select-font);\n color: var(--ox-select-color);\n }\n\n span {\n flex: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n gap: 4px;\n }\n\n md-icon {\n --md-icon-size: 16px;\n display: block;\n text-align: right;\n color: var(--ox-select-icon-color);\n opacity: 0.7;\n }\n\n div:hover md-icon {\n color: var(--md-sys-color-on-primary-container);\n }\n\n ::slotted(ox-popup-list) {\n width: 100%;\n }\n `\n ]\n\n @property({ type: String }) name: string = ''\n @property({ type: String }) placeholder: string = ''\n\n @state() label: string | string[] = ''\n\n render() {\n const label =\n (this.label instanceof Array ? this.label.join(', ') : this.label?.trim()) ||\n (this.value instanceof Array ? this.value.join(', ') : this.value?.trim()) ||\n this.placeholder ||\n ''\n\n return html`\n <div @click=${this.expand}>\n <span @mouseover=${onmouseover} @mouseout=${onmouseout}>${label}</span>\n <md-icon>expand_more</md-icon>\n </div>\n\n <slot></slot>\n `\n }\n\n connectedCallback() {\n super.connectedCallback()\n\n this.setAttribute('tabindex', '0')\n\n this.addEventListener('select', (e: Event) => {\n this.value = (e as CustomEvent).detail\n })\n\n this.addEventListener('close', e => {\n /* popup이 close될 때 change 이벤트를 발생시킨다. */\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n })\n\n this.addEventListener('keydown', (e: KeyboardEvent) => {\n e.preventDefault()\n\n if (e.key === ' ' || e.key === 'Spacebar' || e.key === 'ArrowDown') {\n this.expand()\n }\n })\n }\n\n async updated(changes: PropertyValues<this>) {\n if (changes.has('value')) {\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n if (popupList) {\n popupList.value = this.value\n await this.requestUpdate()\n\n this.label = popupList.getSelectedLabels()\n }\n }\n }\n\n setOptions(\n options: string[] | { display: string; value: string }[],\n opt: { multiple?: boolean; withSearch?: boolean } = {}\n ) {\n const objOptions = options.map(option => {\n return typeof option == 'string' ? { display: option, value: option } : option\n })\n\n const { multiple, withSearch } = opt || {}\n\n const template = html`\n <ox-popup-list\n align-left\n nowrap\n ?multiple=${multiple}\n attr-selected=${multiple ? 'checked' : ''}\n ?with-search=${withSearch}\n >\n ${multiple\n ? html`<ox-checkbox\n @change=${(e: Event) => {\n const target = e.target as HTMLInputElement\n const options = Array.from(target.parentElement!.querySelectorAll('[option]')).filter(\n option => !option.hasAttribute('hidden')\n )\n options.forEach(option => ((option as HTMLInputElement).checked = target.checked))\n\n this.value = options\n .map(option =>\n (option as HTMLInputElement).checked ? (option as HTMLInputElement).value : undefined\n )\n .filter(Boolean)\n }}\n >set all</ox-checkbox\n >\n ${objOptions.map(\n option => html` <ox-checkbox option value=${option.value}>${option.display}</ox-checkbox> `\n )} `\n : html`${objOptions.map(option => html` <div option value=${option.value}>${option.display}</div> `)}`}\n </ox-popup-list>\n `\n\n render(template, this)\n }\n\n expand() {\n if (this.disabled) {\n return\n }\n\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n\n if (popupList) {\n popupList.style.width = `${this.offsetWidth}px`\n const align = popupList.hasAttribute('align-left') ? 'left' : 'right'\n\n const props = {\n top: this.offsetHeight,\n [align]: 0\n }\n\n popupList.open(props)\n }\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"ox-select.js","sourceRoot":"","sources":["../../src/ox-select.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,4BAA4B,CAAA;AACnC,OAAO,iCAAiC,CAAA;AACxC,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAA2B,MAAM,KAAK,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGzE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I,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAM;QACR,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAgB,CAAA;QAEpE,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,CAAA;YAC/C,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAA;YAErE,MAAM,KAAK,GAAG;gBACZ,GAAG,EAAE,IAAI,CAAC,YAAY;gBACtB,CAAC,KAAK,CAAC,EAAE,CAAC;aACX,CAAA;YAED,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;;AA9H2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAAkB;AACjB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAAyB;AAE3C;IAAR,KAAK,EAAE;uCAA8B;AA3D3B,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CAuLpB","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport '@material/web/icon/icon.js'\nimport '@operato/popup/ox-popup-list.js'\nimport './ox-checkbox.js'\n\nimport { css, html, render, PropertyValues, nothing } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { OxPopupList } from '@operato/popup'\nimport { TooltipStyles } from '@operato/styles'\n\nimport { OxFormField } from './ox-form-field.js'\n\n@customElement('ox-select')\nexport class OxSelect extends OxFormField {\n static styles = [\n TooltipStyles,\n css`\n :host {\n display: block;\n position: relative;\n border-bottom: 1px solid rgba(0, 0, 0, 0.15);\n\n --ox-select-padding: var(--spacing-tiny);\n --ox-select-font: var(--input-font);\n --ox-select-color: var(--input-color, var(--md-sys-color-on-surface-variant));\n --ox-select-icon-color: var(--theme-primary-text-color, var(--md-sys-color-on-surface-variant));\n --ox-select-icon-hover-color: var(--md-sys-color-on-primary-container, #3c3938);\n }\n\n div {\n width: 100%;\n box-sizing: border-box;\n\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n padding: var(--ox-select-padding);\n font: var(--ox-select-font);\n color: var(--ox-select-color);\n }\n\n span {\n flex: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n gap: 4px;\n }\n\n md-icon {\n --md-icon-size: 16px;\n display: block;\n text-align: right;\n color: var(--ox-select-icon-color);\n opacity: 0.7;\n }\n\n div:hover md-icon {\n color: var(--md-sys-color-on-primary-container);\n }\n\n ::slotted(ox-popup-list) {\n width: 100%;\n }\n `\n ]\n\n @property({ type: String }) name: string = ''\n @property({ type: String }) placeholder: string = ''\n\n @state() label: string | string[] = ''\n\n render() {\n const label =\n (this.label instanceof Array ? this.label.join(', ') : this.label?.trim()) ||\n (this.value instanceof Array ? this.value.join(', ') : this.value?.trim()) ||\n this.placeholder ||\n ''\n\n return html`\n <div @click=${this.expand}>\n <span data-reactive-tooltip>${label}</span>\n <md-icon>expand_more</md-icon>\n </div>\n\n <slot></slot>\n `\n }\n\n connectedCallback() {\n super.connectedCallback()\n\n this.setAttribute('tabindex', '0')\n\n this.addEventListener('select', (e: Event) => {\n this.value = (e as CustomEvent).detail\n })\n\n this.addEventListener('close', e => {\n /* popup이 close될 때 change 이벤트를 발생시킨다. */\n this.dispatchEvent(\n new CustomEvent('change', {\n bubbles: true,\n composed: true,\n detail: this.value\n })\n )\n })\n\n this.addEventListener('keydown', (e: KeyboardEvent) => {\n e.preventDefault()\n\n if (e.key === ' ' || e.key === 'Spacebar' || e.key === 'ArrowDown') {\n this.expand()\n }\n })\n }\n\n async updated(changes: PropertyValues<this>) {\n if (changes.has('value')) {\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n if (popupList) {\n popupList.value = this.value\n await this.requestUpdate()\n\n this.label = popupList.getSelectedLabels()\n }\n }\n }\n\n setOptions(\n options: string[] | { display: string; value: string }[],\n opt: { multiple?: boolean; withSearch?: boolean } = {}\n ) {\n const objOptions = options.map(option => {\n return typeof option == 'string' ? { display: option, value: option } : option\n })\n\n const { multiple, withSearch } = opt || {}\n\n const template = html`\n <ox-popup-list\n align-left\n nowrap\n ?multiple=${multiple}\n attr-selected=${multiple ? 'checked' : ''}\n ?with-search=${withSearch}\n >\n ${multiple\n ? html`<ox-checkbox\n @change=${(e: Event) => {\n const target = e.target as HTMLInputElement\n const options = Array.from(target.parentElement!.querySelectorAll('[option]')).filter(\n option => !option.hasAttribute('hidden')\n )\n options.forEach(option => ((option as HTMLInputElement).checked = target.checked))\n\n this.value = options\n .map(option =>\n (option as HTMLInputElement).checked ? (option as HTMLInputElement).value : undefined\n )\n .filter(Boolean)\n }}\n >set all</ox-checkbox\n >\n ${objOptions.map(\n option => html` <ox-checkbox option value=${option.value}>${option.display}</ox-checkbox> `\n )} `\n : html`${objOptions.map(option => html` <div option value=${option.value}>${option.display}</div> `)}`}\n </ox-popup-list>\n `\n\n render(template, this)\n }\n\n expand() {\n if (this.disabled) {\n return\n }\n\n const popupList = this.querySelector('ox-popup-list') as OxPopupList\n\n if (popupList) {\n popupList.style.width = `${this.offsetWidth}px`\n const align = popupList.hasAttribute('align-left') ? 'left' : 'right'\n\n const props = {\n top: this.offsetHeight,\n [align]: 0\n }\n\n popupList.open(props)\n }\n }\n}\n"]}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import '../src/ox-input-table-column-config.js';
|
2
|
+
import { TemplateResult } from 'lit';
|
3
|
+
declare const _default: {
|
4
|
+
title: string;
|
5
|
+
component: string;
|
6
|
+
argTypes: {
|
7
|
+
name: {
|
8
|
+
control: string;
|
9
|
+
};
|
10
|
+
value: {
|
11
|
+
control: string;
|
12
|
+
};
|
13
|
+
disabled: {
|
14
|
+
control: string;
|
15
|
+
};
|
16
|
+
theme: {
|
17
|
+
control: string;
|
18
|
+
options: string[];
|
19
|
+
};
|
20
|
+
};
|
21
|
+
};
|
22
|
+
export default _default;
|
23
|
+
interface Story<T> {
|
24
|
+
(args: T): TemplateResult;
|
25
|
+
args?: Partial<T>;
|
26
|
+
argTypes?: Record<string, unknown>;
|
27
|
+
}
|
28
|
+
interface ArgTypes {
|
29
|
+
name?: string;
|
30
|
+
value?: object;
|
31
|
+
disabled?: boolean;
|
32
|
+
theme?: string;
|
33
|
+
}
|
34
|
+
export declare const Regular: Story<ArgTypes>;
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import '../src/ox-input-table-column-config.js';
|
2
|
+
import { html } from 'lit';
|
3
|
+
import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles';
|
4
|
+
export default {
|
5
|
+
title: 'ox-input-table-column-config',
|
6
|
+
component: 'ox-input-table-column-config',
|
7
|
+
argTypes: {
|
8
|
+
name: { control: 'text' },
|
9
|
+
value: { control: 'object' },
|
10
|
+
disabled: { control: 'boolean' },
|
11
|
+
theme: { control: 'select', options: ['light', 'dark'] }
|
12
|
+
}
|
13
|
+
};
|
14
|
+
const Template = ({ name = 'table-column-config', value = {}, disabled, theme = 'light' }) => html `
|
15
|
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
|
16
|
+
|
17
|
+
<link href="/themes/light.css" rel="stylesheet" />
|
18
|
+
<link href="/themes/dark.css" rel="stylesheet" />
|
19
|
+
<link href="/themes/spacing.css" rel="stylesheet" />
|
20
|
+
|
21
|
+
<link
|
22
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
|
23
|
+
rel="stylesheet"
|
24
|
+
/>
|
25
|
+
<link
|
26
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
|
27
|
+
rel="stylesheet"
|
28
|
+
/>
|
29
|
+
<link
|
30
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
|
31
|
+
rel="stylesheet"
|
32
|
+
/>
|
33
|
+
|
34
|
+
<style>
|
35
|
+
${MDTypeScaleStyles.cssText}
|
36
|
+
</style>
|
37
|
+
|
38
|
+
<style>
|
39
|
+
.container {
|
40
|
+
height: 500px;
|
41
|
+
text-align: center;
|
42
|
+
padding: 20px;
|
43
|
+
|
44
|
+
background-color: var(--md-sys-color-primary-container);
|
45
|
+
color: var(--md-sys-color-on-primary-container);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
|
49
|
+
<script>
|
50
|
+
document.body.classList.add('${theme}')
|
51
|
+
</script>
|
52
|
+
|
53
|
+
<div class="container md-typescale-body-large-prominent">
|
54
|
+
<ox-input-table-column-config
|
55
|
+
@change=${(e) => {
|
56
|
+
console.log(e.target.value);
|
57
|
+
}}
|
58
|
+
name=${name}
|
59
|
+
.value=${value}
|
60
|
+
?disabled=${disabled}
|
61
|
+
>
|
62
|
+
</ox-input-table-column-config>
|
63
|
+
</div>
|
64
|
+
`;
|
65
|
+
export const Regular = Template.bind({});
|
66
|
+
Regular.args = {
|
67
|
+
name: 'table-column-config',
|
68
|
+
value: [
|
69
|
+
{
|
70
|
+
name: 'section',
|
71
|
+
label: 'Section',
|
72
|
+
visible: true,
|
73
|
+
width: 100,
|
74
|
+
order: 1
|
75
|
+
},
|
76
|
+
{
|
77
|
+
name: 'title',
|
78
|
+
label: 'Title',
|
79
|
+
visible: true,
|
80
|
+
width: 110,
|
81
|
+
order: 2
|
82
|
+
},
|
83
|
+
{
|
84
|
+
name: 'startDate',
|
85
|
+
label: 'Start Date',
|
86
|
+
visible: true,
|
87
|
+
width: 150,
|
88
|
+
order: 3
|
89
|
+
},
|
90
|
+
{
|
91
|
+
name: 'endDate',
|
92
|
+
label: 'End Date',
|
93
|
+
visible: true,
|
94
|
+
width: 200,
|
95
|
+
order: 4
|
96
|
+
}
|
97
|
+
]
|
98
|
+
};
|
99
|
+
//# sourceMappingURL=ox-input-table-column-config.stories.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ox-input-table-column-config.stories.js","sourceRoot":"","sources":["../../stories/ox-input-table-column-config.stories.ts"],"names":[],"mappings":"AAAA,OAAO,wCAAwC,CAAA;AAE/C,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC1C,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,8CAA8C,CAAA;AAE1F,eAAe;IACb,KAAK,EAAE,8BAA8B;IACrC,SAAS,EAAE,8BAA8B;IACzC,QAAQ,EAAE;QACR,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QACzB,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;QAC5B,QAAQ,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;QAChC,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;KACzD;CACF,CAAA;AAeD,MAAM,QAAQ,GAAoB,CAAC,EACjC,IAAI,GAAG,qBAAqB,EAC5B,KAAK,GAAG,EAAE,EACV,QAAQ,EACR,KAAK,GAAG,OAAO,EACN,EAAE,EAAE,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;MAqBd,iBAAiB,CAAC,OAAO;;;;;;;;;;;;;;;mCAeI,KAAK;;;;;gBAKxB,CAAC,CAAQ,EAAE,EAAE;IACrB,OAAO,CAAC,GAAG,CAAE,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC;aACM,IAAI;eACF,KAAK;kBACF,QAAQ;;;;CAIzB,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACxC,OAAO,CAAC,IAAI,GAAG;IACb,IAAI,EAAE,qBAAqB;IAC3B,KAAK,EAAE;QACL;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,GAAG;YACV,KAAK,EAAE,CAAC;SACT;QACD;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,GAAG;YACV,KAAK,EAAE,CAAC;SACT;QACD;YACE,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,GAAG;YACV,KAAK,EAAE,CAAC;SACT;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,GAAG;YACV,KAAK,EAAE,CAAC;SACT;KACF;CACF,CAAA","sourcesContent":["import '../src/ox-input-table-column-config.js'\n\nimport { html, TemplateResult } from 'lit'\nimport { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'\n\nexport default {\n title: 'ox-input-table-column-config',\n component: 'ox-input-table-column-config',\n argTypes: {\n name: { control: 'text' },\n value: { control: 'object' },\n disabled: { control: 'boolean' },\n theme: { control: 'select', options: ['light', 'dark'] }\n }\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {\n name?: string\n value?: object\n disabled?: boolean\n theme?: string\n}\n\nconst Template: Story<ArgTypes> = ({\n name = 'table-column-config',\n value = {},\n disabled,\n theme = 'light'\n}: ArgTypes) => html`\n <link href=\"https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap\" rel=\"stylesheet\" />\n\n <link href=\"/themes/light.css\" rel=\"stylesheet\" />\n <link href=\"/themes/dark.css\" rel=\"stylesheet\" />\n <link href=\"/themes/spacing.css\" rel=\"stylesheet\" />\n\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n\n <style>\n ${MDTypeScaleStyles.cssText}\n </style>\n\n <style>\n .container {\n height: 500px;\n text-align: center;\n padding: 20px;\n\n background-color: var(--md-sys-color-primary-container);\n color: var(--md-sys-color-on-primary-container);\n }\n </style>\n\n <script>\n document.body.classList.add('${theme}')\n </script>\n\n <div class=\"container md-typescale-body-large-prominent\">\n <ox-input-table-column-config\n @change=${(e: Event) => {\n console.log((e.target as HTMLInputElement).value)\n }}\n name=${name}\n .value=${value}\n ?disabled=${disabled}\n >\n </ox-input-table-column-config>\n </div>\n`\n\nexport const Regular = Template.bind({})\nRegular.args = {\n name: 'table-column-config',\n value: [\n {\n name: 'section',\n label: 'Section',\n visible: true,\n width: 100,\n order: 1\n },\n {\n name: 'title',\n label: 'Title',\n visible: true,\n width: 110,\n order: 2\n },\n {\n name: 'startDate',\n label: 'Start Date',\n visible: true,\n width: 150,\n order: 3\n },\n {\n name: 'endDate',\n label: 'End Date',\n visible: true,\n width: 200,\n order: 4\n }\n ]\n}\n"]}
|