Skip to content

Commit 0b02cf2

Browse files
authored
Merge pull request #3777 from VisActor/refactor/vtable-editors-unifiedStyle
Refactor/vtable editors unified style
2 parents 77a03df + 180d54c commit 0b02cf2

File tree

4 files changed

+90
-17
lines changed

4 files changed

+90
-17
lines changed

packages/vtable-editors/src/date-input-editor.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ export class DateInputEditor extends InputEditor implements IEditor {
1818
input.style.position = 'absolute';
1919
input.style.backgroundColor = '#FFFFFF';
2020

21+
input.style.borderRadius = '0px';
22+
input.style.border = '2px solid #d9d9d9';
23+
// #region 为了保证input在focus时,没有圆角
24+
input.addEventListener('focus', () => {
25+
input.style.borderColor = '#4A90E2';
26+
input.style.outline = 'none';
27+
});
28+
29+
input.addEventListener('blur', () => {
30+
input.style.borderColor = '#d9d9d9';
31+
// input.style.boxShadow = 'none';
32+
});
33+
2134
this.element = input;
2235
this.container.appendChild(input);
2336
// 测试successCallback 调用是否正确

packages/vtable-editors/src/list-editor.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class ListEditor implements IEditor {
1212
successCallback?: () => void;
1313

1414
constructor(editorConfig: ListEditorConfig) {
15-
console.log('listEditor constructor');
1615
this.editorConfig = editorConfig;
1716
}
1817

@@ -25,6 +24,21 @@ export class ListEditor implements IEditor {
2524
select.style.width = '100%';
2625
select.style.boxSizing = 'border-box';
2726
select.style.backgroundColor = '#FFFFFF';
27+
select.style.borderRadius = '0px';
28+
select.style.border = '2px solid #d9d9d9';
29+
// #region 为了保证input在focus时,没有圆角
30+
select.addEventListener('focus', () => {
31+
select.style.borderColor = '#4A90E2';
32+
select.style.outline = 'none';
33+
});
34+
35+
select.addEventListener('blur', () => {
36+
select.style.borderColor = '#d9d9d9';
37+
// input.style.boxShadow = 'none';
38+
});
39+
40+
41+
2842
this.element = select;
2943

3044
// create option tags
@@ -72,10 +86,18 @@ export class ListEditor implements IEditor {
7286
}
7387

7488
adjustPosition(rect: RectProps) {
75-
this.element.style.top = rect.top + 'px';
76-
this.element.style.left = rect.left + 'px';
77-
this.element.style.width = rect.width + 'px';
78-
this.element.style.height = rect.height + 'px';
89+
90+
//使border均分input位置rect的上下左右
91+
const borderWidth = 2;
92+
const top = rect.top - borderWidth / 2;
93+
const left = rect.left - borderWidth / 2;
94+
const width = rect.width + borderWidth;
95+
const height = rect.height + borderWidth;
96+
97+
this.element.style.top =top + 'px';
98+
this.element.style.left =left + 'px';
99+
this.element.style.width = width + 'px';
100+
this.element.style.height = height + 'px';
79101
}
80102

81103
endEditing() {

packages/vtable-editors/src/textArea-editor.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,22 @@ export class TextAreaEditor implements IEditor {
2828
input.style.boxSizing = 'border-box';
2929
input.style.backgroundColor = '#FFFFFF';
3030

31-
this.element = input;
31+
input.style.borderRadius = '0px';
32+
input.style.border = '2px solid #d9d9d9';
33+
34+
// #region 为了保证input在focus时,没有圆角
35+
input.addEventListener('focus', () => {
36+
input.style.borderColor = '#4A90E2';
37+
input.style.outline = 'none';
38+
});
39+
40+
input.addEventListener('blur', () => {
41+
input.style.borderColor = '#d9d9d9';
42+
// input.style.boxShadow = 'none';
43+
input.style.outline = 'none';
44+
});
3245

46+
this.element = input;
3347
this.container.appendChild(input);
3448

3549
// 监听键盘事件
@@ -69,10 +83,19 @@ export class TextAreaEditor implements IEditor {
6983
}
7084

7185
adjustPosition(rect: RectProps) {
72-
this.element.style.top = rect.top + 'px';
73-
this.element.style.left = rect.left + 'px';
74-
this.element.style.width = rect.width + 'px';
75-
this.element.style.height = rect.height + 'px';
86+
87+
88+
//使border均分input位置rect的上下左右
89+
const borderWidth = 2;
90+
const top = rect.top - borderWidth / 2;
91+
const left = rect.left - borderWidth / 2;
92+
const width = rect.width + borderWidth;
93+
const height = rect.height + borderWidth;
94+
95+
this.element.style.top = top + 'px';
96+
this.element.style.left = left + 'px';
97+
this.element.style.width = width + 'px';
98+
this.element.style.height = height + 'px';
7699
}
77100

78101
endEditing() {

packages/vtable-plugins/demo/highlight-header/highlight-header.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as VTable from '@visactor/vtable';
22
import { bindDebugTool } from '@visactor/vtable/es/scenegraph/debug-tool';
33
import * as VTable_editors from '@visactor/vtable-editors';
44

5+
// import * as VTable_editors from '../../../vtable-editors/src/index'; // 直接引入,省的需要在vtable-editors中rushx build。
6+
57
import { HighlightHeaderWhenSelectCellPlugin } from '../../src';
68
const CONTAINER_ID = 'vTable';
79
const generatePersons = count => {
@@ -24,11 +26,19 @@ export function createTable() {
2426
const input_editor = new VTable_editors.InputEditor();
2527
VTable.register.editor('input-editor', input_editor);
2628

29+
const textArea_editor = new VTable_editors.TextAreaEditor();
30+
VTable.register.editor('textArea-editor', textArea_editor);
31+
32+
const date_input_editor = new VTable_editors.DateInputEditor();
33+
const list_editor = new VTable_editors.ListEditor({ values: ['girl', 'boy'] });
34+
VTable.register.editor('date_input_editor', date_input_editor);
35+
VTable.register.editor('list_editor', list_editor);
36+
2737
const records = generatePersons(20);
2838
const columns: VTable.ColumnsDefine = [
2939
{
3040
field: 'id',
31-
title: 'ID',
41+
title: 'ID ( input-editor )',
3242
width: 'auto',
3343
minWidth: 50,
3444
sort: true,
@@ -37,9 +47,10 @@ export function createTable() {
3747
},
3848
{
3949
field: 'email1',
40-
title: 'email',
41-
width: 200,
50+
title: 'email ( textArea-editor )',
51+
width: 300,
4252
sort: true,
53+
editor: 'textArea-editor',
4354
style: {
4455
underline: true,
4556
underlineDash: [2, 0],
@@ -48,13 +59,15 @@ export function createTable() {
4859
},
4960
{
5061
field: 'date1',
51-
title: 'birthday',
52-
width: 200
62+
title: 'birthday ( date_input_editor )',
63+
width: 300,
64+
editor: 'date_input_editor'
5365
},
5466
{
5567
field: 'sex',
56-
title: 'sex',
57-
width: 100
68+
title: 'sex ( list_editor )',
69+
width: 300,
70+
editor: 'list_editor'
5871
}
5972
];
6073

@@ -70,6 +83,8 @@ export function createTable() {
7083
outsideClickDeselect: true,
7184
headerSelectMode: 'body'
7285
},
86+
87+
editCellTrigger: 'click',
7388
autoWrapText: true,
7489
editor: 'input-editor',
7590
menu: {

0 commit comments

Comments
 (0)