@king-design/intact 2.0.17-beta.0 → 2.1.1
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/components/cascader/index.md +18 -0
- package/components/cascader/index.spec.ts +56 -0
- package/components/cascader/index.ts +35 -12
- package/components/cascader/index.vdt +9 -8
- package/components/cascader/useFields.ts +22 -0
- package/components/cascader/useFilterable.ts +23 -8
- package/components/cascader/useLabel.ts +7 -4
- package/components/cascader/useLoad.ts +4 -2
- package/components/code/demos/basic.md +1 -1
- package/components/colorpicker/index.md +16 -0
- package/components/colorpicker/index.ts +4 -0
- package/components/colorpicker/index.vdt +3 -2
- package/components/datepicker/index.md +11 -0
- package/components/dialog/index.spec.ts +2 -2
- package/components/dropdown/dropdown.ts +34 -71
- package/components/dropdown/index.spec.ts +53 -4
- package/components/dropdown/item.ts +18 -7
- package/components/dropdown/menu.ts +3 -3
- package/components/dropdown/usePosition.ts +12 -1
- package/components/editable/index.ts +17 -3
- package/components/editable/index.vdt +1 -0
- package/components/input/demos/autoRows.md +44 -0
- package/components/input/demos/password.md +12 -0
- package/components/input/demos/textarea.md +2 -2
- package/components/input/index.md +1 -0
- package/components/input/index.spec.ts +97 -1
- package/components/input/index.ts +17 -3
- package/components/input/index.vdt +29 -6
- package/components/input/styles.ts +18 -1
- package/components/input/useAutoRows.ts +65 -0
- package/components/input/useAutoWidth.ts +12 -3
- package/components/input/useShowPassword.ts +27 -0
- package/components/menu/demos/collapse.md +1 -1
- package/components/menu/index.spec.ts +9 -1
- package/components/menu/item.ts +7 -0
- package/components/pagination/index.spec.ts +24 -1
- package/components/pagination/index.ts +2 -1
- package/components/portal.ts +4 -4
- package/components/position.ts +5 -1
- package/components/select/base.ts +3 -1
- package/components/select/base.vdt +2 -0
- package/components/select/index.md +11 -1
- package/components/table/cell.ts +4 -5
- package/components/table/demos/hideHeader.md +33 -0
- package/components/table/demos/pagination.md +53 -0
- package/components/table/index.md +22 -0
- package/components/table/index.spec.ts +73 -1
- package/components/table/row.ts +3 -3
- package/components/table/styles.ts +5 -0
- package/components/table/table.ts +29 -4
- package/components/table/table.vdt +21 -3
- package/components/table/useChecked.ts +21 -6
- package/components/table/useDisableRow.ts +3 -2
- package/components/table/useDraggable.ts +11 -8
- package/components/table/useGroup.ts +2 -0
- package/components/table/useMerge.ts +6 -3
- package/components/table/usePagination.ts +71 -0
- package/components/table/useRestRowStatus.ts +4 -1
- package/components/table/useTree.ts +4 -3
- package/components/timepicker/index.md +11 -0
- package/components/tooltip/content.ts +15 -1
- package/components/tooltip/content.vdt +6 -1
- package/components/tooltip/demos/trigger.md +1 -1
- package/components/tooltip/index.md +1 -1
- package/components/tooltip/index.spec.ts +65 -6
- package/components/tooltip/styles.ts +1 -1
- package/components/tooltip/tooltip.ts +8 -0
- package/components/treeSelect/index.md +9 -0
- package/components/virtual.ts +98 -0
- package/es/components/cascader/index.d.ts +22 -11
- package/es/components/cascader/index.js +9 -12
- package/es/components/cascader/index.spec.js +81 -0
- package/es/components/cascader/index.vdt.js +10 -8
- package/es/components/cascader/useFields.d.ts +2 -0
- package/es/components/cascader/useFields.js +18 -0
- package/es/components/cascader/useFilterable.d.ts +2 -1
- package/es/components/cascader/useFilterable.js +17 -6
- package/es/components/cascader/useLabel.d.ts +2 -1
- package/es/components/cascader/useLabel.js +4 -4
- package/es/components/cascader/useLoad.d.ts +2 -1
- package/es/components/cascader/useLoad.js +9 -7
- package/es/components/colorpicker/index.d.ts +2 -0
- package/es/components/colorpicker/index.js +7 -2
- package/es/components/colorpicker/index.vdt.js +3 -6
- package/es/components/dialog/index.spec.js +2 -2
- package/es/components/dropdown/dropdown.d.ts +6 -5
- package/es/components/dropdown/dropdown.js +40 -69
- package/es/components/dropdown/index.spec.js +96 -17
- package/es/components/dropdown/item.d.ts +1 -1
- package/es/components/dropdown/item.js +19 -7
- package/es/components/dropdown/usePosition.js +11 -2
- package/es/components/editable/index.d.ts +1 -0
- package/es/components/editable/index.js +20 -6
- package/es/components/editable/index.vdt.js +2 -1
- package/es/components/input/index.d.ts +10 -2
- package/es/components/input/index.js +10 -3
- package/es/components/input/index.spec.js +169 -1
- package/es/components/input/index.vdt.js +26 -7
- package/es/components/input/styles.js +8 -3
- package/es/components/input/useAutoRows.d.ts +2 -0
- package/es/components/input/useAutoRows.js +79 -0
- package/es/components/input/useAutoWidth.js +13 -3
- package/es/components/input/useShowPassword.d.ts +7 -0
- package/es/components/input/useShowPassword.js +31 -0
- package/es/components/menu/index.spec.js +26 -15
- package/es/components/menu/item.d.ts +2 -0
- package/es/components/menu/item.js +5 -0
- package/es/components/pagination/index.js +2 -1
- package/es/components/pagination/index.spec.js +51 -4
- package/es/components/portal.d.ts +6 -2
- package/es/components/portal.js +4 -3
- package/es/components/position.js +2 -1
- package/es/components/select/base.d.ts +2 -1
- package/es/components/select/base.js +3 -1
- package/es/components/select/base.vdt.js +3 -1
- package/es/components/table/cell.js +1 -6
- package/es/components/table/index.spec.js +130 -19
- package/es/components/table/row.d.ts +1 -1
- package/es/components/table/row.js +2 -1
- package/es/components/table/styles.js +1 -1
- package/es/components/table/table.d.ts +15 -0
- package/es/components/table/table.js +16 -7
- package/es/components/table/table.vdt.js +20 -6
- package/es/components/table/useChecked.d.ts +3 -2
- package/es/components/table/useChecked.js +23 -12
- package/es/components/table/useDisableRow.d.ts +2 -1
- package/es/components/table/useDisableRow.js +4 -4
- package/es/components/table/useDraggable.d.ts +3 -2
- package/es/components/table/useDraggable.js +11 -8
- package/es/components/table/useGroup.js +3 -0
- package/es/components/table/useMerge.d.ts +2 -1
- package/es/components/table/useMerge.js +5 -4
- package/es/components/table/usePagination.d.ts +8 -0
- package/es/components/table/usePagination.js +81 -0
- package/es/components/table/useTree.d.ts +2 -1
- package/es/components/table/useTree.js +3 -4
- package/es/components/tooltip/content.d.ts +1 -0
- package/es/components/tooltip/content.js +18 -1
- package/es/components/tooltip/content.vdt.js +3 -1
- package/es/components/tooltip/index.spec.js +117 -10
- package/es/components/tooltip/styles.d.ts +22 -0
- package/es/components/tooltip/styles.js +1 -1
- package/es/components/tooltip/tooltip.d.ts +1 -0
- package/es/components/tooltip/tooltip.js +11 -0
- package/es/components/virtual.d.ts +8 -0
- package/es/components/virtual.js +126 -0
- package/es/index.d.ts +3 -3
- package/es/index.js +3 -3
- package/es/packages/kpc-react/__tests__/components/cascader.spec.d.ts +1 -0
- package/es/packages/kpc-react/__tests__/components/cascader.spec.js +79 -0
- package/es/site/data/components/input/demos/autoRows/index.d.ts +9 -0
- package/es/site/data/components/input/demos/autoRows/index.js +24 -0
- package/es/site/data/components/input/demos/autoRows/react.d.ts +8 -0
- package/es/site/data/components/input/demos/autoRows/react.js +62 -0
- package/es/site/data/components/input/demos/password/index.d.ts +5 -0
- package/es/site/data/components/input/demos/password/index.js +17 -0
- package/es/site/data/components/input/demos/password/react.d.ts +5 -0
- package/es/site/data/components/input/demos/password/react.js +41 -0
- package/es/site/data/components/input/demos/textarea/react.js +4 -2
- package/es/site/data/components/menu/demos/collapse/index.js +1 -1
- package/es/site/data/components/menu/demos/collapse/react.js +1 -1
- package/es/site/data/components/table/demos/hideHeader/index.d.ts +12 -0
- package/es/site/data/components/table/demos/hideHeader/index.js +30 -0
- package/es/site/data/components/table/demos/hideHeader/react.d.ts +11 -0
- package/es/site/data/components/table/demos/hideHeader/react.js +60 -0
- package/es/site/data/components/table/demos/pagination/index.d.ts +12 -0
- package/es/site/data/components/table/demos/pagination/index.js +35 -0
- package/es/site/data/components/table/demos/pagination/react.d.ts +16 -0
- package/es/site/data/components/table/demos/pagination/react.js +65 -0
- package/es/styles/fonts/ionicons.js +1 -1
- package/index.ts +3 -3
- package/package.json +5 -4
- package/styles/fonts/ionicons.ts +0 -1
|
@@ -2,7 +2,7 @@ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slic
|
|
|
2
2
|
import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/splice";
|
|
3
3
|
import { useInstance, nextTick } from 'intact';
|
|
4
4
|
import { useState } from '../../hooks/useState';
|
|
5
|
-
export function useDraggable() {
|
|
5
|
+
export function useDraggable(data) {
|
|
6
6
|
var instance = useInstance();
|
|
7
7
|
var draggingKey = useState(null);
|
|
8
8
|
var originIndex;
|
|
@@ -13,7 +13,7 @@ export function useDraggable() {
|
|
|
13
13
|
draggingIndex = originIndex = tableRow.get('index');
|
|
14
14
|
var key = tableRow.get('key');
|
|
15
15
|
draggingKey.set(key);
|
|
16
|
-
originData =
|
|
16
|
+
originData = data.value;
|
|
17
17
|
instance.trigger('dragstart', {
|
|
18
18
|
key: key,
|
|
19
19
|
from: draggingIndex
|
|
@@ -28,20 +28,23 @@ export function useDraggable() {
|
|
|
28
28
|
var newIndex = tableRow.get('index');
|
|
29
29
|
if (newIndex === draggingIndex) return; // swap data
|
|
30
30
|
|
|
31
|
-
var
|
|
31
|
+
var newData = _sliceInstanceProperty(_context = data.value).call(_context);
|
|
32
32
|
|
|
33
|
-
var item = _spliceInstanceProperty(
|
|
33
|
+
var item = _spliceInstanceProperty(newData).call(newData, draggingIndex, 1)[0];
|
|
34
34
|
|
|
35
|
-
_spliceInstanceProperty(
|
|
35
|
+
_spliceInstanceProperty(newData).call(newData, newIndex, 0, item);
|
|
36
36
|
|
|
37
37
|
draggingIndex = newIndex;
|
|
38
|
-
|
|
38
|
+
data.set(newData);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function onRowDragEnd(e, tableRow) {
|
|
42
|
-
e.preventDefault();
|
|
43
|
-
|
|
42
|
+
e.preventDefault(); // revert to origin data, then set to new data to trigger animation
|
|
43
|
+
|
|
44
|
+
var newData = data.value;
|
|
45
|
+
data.set(originData);
|
|
44
46
|
nextTick(function () {
|
|
47
|
+
data.set(newData);
|
|
45
48
|
draggingKey.set(null);
|
|
46
49
|
instance.trigger('dragend', {
|
|
47
50
|
key: tableRow.get('key'),
|
|
@@ -12,6 +12,9 @@ export function useGroup() {
|
|
|
12
12
|
var instance = useInstance();
|
|
13
13
|
var keywords = useState('');
|
|
14
14
|
var filteredGroup = useState(instance.get('group'));
|
|
15
|
+
instance.on('$receive:group', function (group) {
|
|
16
|
+
return filteredGroup.set(group);
|
|
17
|
+
});
|
|
15
18
|
|
|
16
19
|
function onSelect(value, groupValue, onChange) {
|
|
17
20
|
var _instance$get = instance.get(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Props } from 'intact';
|
|
2
2
|
import type { TableColumnProps } from './column';
|
|
3
|
+
import { State } from '../../hooks/useState';
|
|
3
4
|
export declare type TableMerge<T = any, CheckType = 'checkbox'> = (row: T, column: CheckType extends 'none' ? Props<TableColumnProps> : Props<TableColumnProps> | null, rowIndex: number, columnIndex: number) => TableMergeConfig | undefined;
|
|
4
5
|
export declare type TableMergeConfig = {
|
|
5
6
|
colspan?: number;
|
|
@@ -10,6 +11,6 @@ export declare type TableGridItem = {
|
|
|
10
11
|
spans: TableMergeConfig | undefined;
|
|
11
12
|
};
|
|
12
13
|
export declare type TableGrid = TableGridItem[][];
|
|
13
|
-
export declare function useMerge(getCols: () => Props<TableColumnProps>[]): {
|
|
14
|
+
export declare function useMerge(getCols: () => Props<TableColumnProps>[], data: State<unknown[] | undefined>): {
|
|
14
15
|
getGrid: () => TableGrid;
|
|
15
16
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useInstance } from 'intact';
|
|
2
|
-
|
|
2
|
+
import { watchState } from '../../hooks/useState';
|
|
3
|
+
export function useMerge(getCols, data) {
|
|
3
4
|
var instance = useInstance();
|
|
4
5
|
var grid = [];
|
|
5
6
|
|
|
@@ -8,12 +9,11 @@ export function useMerge(getCols) {
|
|
|
8
9
|
|
|
9
10
|
var _instance$get = instance.get(),
|
|
10
11
|
merge = _instance$get.merge,
|
|
11
|
-
data = _instance$get.data,
|
|
12
12
|
checkType = _instance$get.checkType;
|
|
13
13
|
|
|
14
|
-
if (!data || !data.length || !merge) return;
|
|
14
|
+
if (!data.value || !data.value.length || !merge) return;
|
|
15
15
|
var cols = getCols();
|
|
16
|
-
data.forEach(function (data, rowIndex) {
|
|
16
|
+
data.value.forEach(function (data, rowIndex) {
|
|
17
17
|
var currentRow = [];
|
|
18
18
|
grid.push(currentRow);
|
|
19
19
|
var columnIndexOffset = 0;
|
|
@@ -71,6 +71,7 @@ export function useMerge(getCols) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
instance.on('$receive:children', handleSpans);
|
|
74
|
+
watchState(data, handleSpans);
|
|
74
75
|
return {
|
|
75
76
|
getGrid: getGrid
|
|
76
77
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Pagination, PaginationChangeData } from '../pagination';
|
|
2
|
+
export declare function usePagination(): {
|
|
3
|
+
data: import("../../hooks/useState").State<any[] | undefined>;
|
|
4
|
+
value: import("../../hooks/useState").State<number>;
|
|
5
|
+
limit: import("../../hooks/useState").State<number>;
|
|
6
|
+
onChange: (data: PaginationChangeData) => void;
|
|
7
|
+
paginationRef: import("intact").RefObject<Pagination>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
|
|
3
|
+
import { useInstance, createRef } from 'intact';
|
|
4
|
+
import { useState } from '../../hooks/useState';
|
|
5
|
+
import { Pagination } from '../pagination';
|
|
6
|
+
import { isObject } from 'intact-shared';
|
|
7
|
+
import { useReceive } from '../../hooks/useReceive';
|
|
8
|
+
var defaultPagination = Pagination.defaults();
|
|
9
|
+
export function usePagination() {
|
|
10
|
+
var instance = useInstance();
|
|
11
|
+
var data = useState(instance.get('data'));
|
|
12
|
+
var value = useState(defaultPagination.value);
|
|
13
|
+
var limit = useState(defaultPagination.limit);
|
|
14
|
+
var paginationRef = createRef(); // for unit test
|
|
15
|
+
|
|
16
|
+
useReceive(['data', 'pagination'], function () {
|
|
17
|
+
handleData();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function handleData() {
|
|
21
|
+
var _instance$get = instance.get(),
|
|
22
|
+
_data = _instance$get.data,
|
|
23
|
+
pagination = _instance$get.pagination;
|
|
24
|
+
|
|
25
|
+
if (!_data) {
|
|
26
|
+
data.set(undefined);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!pagination) {
|
|
31
|
+
data.set(_data);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (isObject(pagination)) {
|
|
36
|
+
if (pagination.value) {
|
|
37
|
+
value.set(pagination.value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (pagination.limit) {
|
|
41
|
+
limit.set(pagination.limit);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
updateDataByPage();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function updateDataByPage() {
|
|
49
|
+
var _instance$get2 = instance.get(),
|
|
50
|
+
_data = _instance$get2.data;
|
|
51
|
+
|
|
52
|
+
var index = (value.value - 1) * limit.value;
|
|
53
|
+
data.set(_sliceInstanceProperty(_data).call(_data, index, index + limit.value));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function onChange(data) {
|
|
57
|
+
var _instance$get3 = instance.get(),
|
|
58
|
+
pagination = _instance$get3.pagination;
|
|
59
|
+
|
|
60
|
+
value.set(data.value);
|
|
61
|
+
limit.set(data.limit);
|
|
62
|
+
updateDataByPage();
|
|
63
|
+
|
|
64
|
+
if (isObject(pagination)) {
|
|
65
|
+
instance.set('pagination', _extends({}, pagination, {
|
|
66
|
+
value: value.value,
|
|
67
|
+
limit: limit.value
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
instance.trigger('changePage', data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
data: data,
|
|
76
|
+
value: value,
|
|
77
|
+
limit: limit,
|
|
78
|
+
onChange: onChange,
|
|
79
|
+
paginationRef: paginationRef
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TableRowKey } from './table';
|
|
2
|
-
|
|
2
|
+
import { State } from '../../hooks/useState';
|
|
3
|
+
export declare function useTree(data: State<any[] | undefined>): {
|
|
3
4
|
isSpreaded: (key: TableRowKey) => boolean;
|
|
4
5
|
toggleSpreadRow: (key: TableRowKey) => void;
|
|
5
6
|
loopData: <T>(cb: (value: any, index: number, level: number, meta: T | null) => T, shouldBreak?: boolean) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useInstance } from 'intact';
|
|
2
2
|
import { inArray } from './useChecked';
|
|
3
3
|
import { toggleArray } from '../utils';
|
|
4
|
-
export function useTree() {
|
|
4
|
+
export function useTree(data) {
|
|
5
5
|
var instance = useInstance();
|
|
6
6
|
|
|
7
7
|
function isSpreaded(key) {
|
|
@@ -18,10 +18,9 @@ export function useTree() {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
var _instance$get = instance.get(),
|
|
21
|
-
childrenKey = _instance$get.childrenKey
|
|
22
|
-
data = _instance$get.data;
|
|
21
|
+
childrenKey = _instance$get.childrenKey;
|
|
23
22
|
|
|
24
|
-
loopDataWithChildrenKey(data, childrenKey, cb, shouldBreak);
|
|
23
|
+
loopDataWithChildrenKey(data.value, childrenKey, cb, shouldBreak);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
return {
|
|
@@ -5,6 +5,7 @@ import { DropdownMenu } from '../dropdown/menu';
|
|
|
5
5
|
import template from './content.vdt';
|
|
6
6
|
import { bind } from '../utils';
|
|
7
7
|
import { useArrow } from './useArrow';
|
|
8
|
+
import { tooltip as tooltipTheme } from './styles';
|
|
8
9
|
export var TooltipContent = /*#__PURE__*/function (_DropdownMenu) {
|
|
9
10
|
_inheritsLoose(TooltipContent, _DropdownMenu);
|
|
10
11
|
|
|
@@ -35,10 +36,24 @@ export var TooltipContent = /*#__PURE__*/function (_DropdownMenu) {
|
|
|
35
36
|
});
|
|
36
37
|
};
|
|
37
38
|
|
|
38
|
-
_proto.onEnter = function onEnter() {
|
|
39
|
+
_proto.onEnter = function onEnter(elem) {
|
|
40
|
+
// fix the width, https://github.com/ksc-fe/kpc/issues/873
|
|
41
|
+
var maxWidth = parseInt(tooltipTheme.maxWidth);
|
|
42
|
+
var width = elem.offsetWidth;
|
|
43
|
+
|
|
44
|
+
if (width === maxWidth) {
|
|
45
|
+
elem.style.width = width + "px";
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
this.dropdown.position();
|
|
40
49
|
};
|
|
41
50
|
|
|
51
|
+
_proto.onAfterLeave = function onAfterLeave(elem) {
|
|
52
|
+
// remove the position after leave, https://github.com/ksc-fe/kpc/issues/873
|
|
53
|
+
var style = elem.style;
|
|
54
|
+
style.left = style.top = style.width = '';
|
|
55
|
+
};
|
|
56
|
+
|
|
42
57
|
_proto.onMouseEnter = function onMouseEnter(e) {
|
|
43
58
|
var dropdown = this.dropdown;
|
|
44
59
|
|
|
@@ -67,6 +82,8 @@ TooltipContent.template = template;
|
|
|
67
82
|
|
|
68
83
|
__decorate([bind], TooltipContent.prototype, "onEnter", null);
|
|
69
84
|
|
|
85
|
+
__decorate([bind], TooltipContent.prototype, "onAfterLeave", null);
|
|
86
|
+
|
|
70
87
|
__decorate([bind], TooltipContent.prototype, "onMouseEnter", null);
|
|
71
88
|
|
|
72
89
|
__decorate([bind], TooltipContent.prototype, "ok", null);
|
|
@@ -38,7 +38,9 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
38
38
|
'value': !!value && !this.isEmptyChildren,
|
|
39
39
|
'transition': {
|
|
40
40
|
name: 'k-fade',
|
|
41
|
-
onEnter: this.onEnter
|
|
41
|
+
onEnter: this.onEnter,
|
|
42
|
+
onAfterLeave: this.onAfterLeave,
|
|
43
|
+
onLeaveCancelled: this.onAfterLeave
|
|
42
44
|
},
|
|
43
45
|
'className': _$cn(classNameObj)
|
|
44
46
|
}, function ($blocks) {
|
|
@@ -12,7 +12,9 @@ import ContentDemo from '~/components/tooltip/demos/content';
|
|
|
12
12
|
import ConfirmDemo from '~/components/tooltip/demos/confirm';
|
|
13
13
|
import AlwaysDemo from '~/components/tooltip/demos/always';
|
|
14
14
|
import { Tooltip } from './';
|
|
15
|
+
import { Dialog } from '../dialog';
|
|
15
16
|
import { mount, unmount, dispatchEvent, getElement, wait } from '../../test/utils';
|
|
17
|
+
import { tooltip as tooltipTheme } from './styles';
|
|
16
18
|
describe('Tooltip', function () {
|
|
17
19
|
afterEach(function (done) {
|
|
18
20
|
unmount();
|
|
@@ -540,8 +542,10 @@ describe('Tooltip', function () {
|
|
|
540
542
|
|
|
541
543
|
_proto.mounted = function mounted() {
|
|
542
544
|
var element = findDomFromVNode(this.$lastInput, true);
|
|
543
|
-
var
|
|
544
|
-
|
|
545
|
+
var style = element.style;
|
|
546
|
+
style.position = 'fixed';
|
|
547
|
+
style.top = '-200px'; // const windowHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
548
|
+
// (element.parentNode as HTMLElement).style.height = `${windowHeight * 2}px`;
|
|
545
549
|
};
|
|
546
550
|
|
|
547
551
|
return Demo;
|
|
@@ -555,27 +559,130 @@ describe('Tooltip', function () {
|
|
|
555
559
|
};
|
|
556
560
|
};
|
|
557
561
|
|
|
558
|
-
_mount9 = mount(Demo), i = _mount9[0];
|
|
559
|
-
|
|
560
|
-
return wait(500);
|
|
562
|
+
_mount9 = mount(Demo), i = _mount9[0]; // await wait(500);
|
|
563
|
+
// window.scrollTo(0, 10000);
|
|
561
564
|
|
|
562
|
-
case 6:
|
|
563
|
-
window.scrollTo(0, 10000);
|
|
564
565
|
i.set('show', true);
|
|
565
|
-
_context11.next =
|
|
566
|
+
_context11.next = 7;
|
|
566
567
|
return wait(500);
|
|
567
568
|
|
|
568
|
-
case
|
|
569
|
+
case 7:
|
|
569
570
|
content = getElement('.k-tooltip-content');
|
|
570
571
|
console.log(content.outerHTML);
|
|
571
572
|
console.log(_JSON$stringify(content.getBoundingClientRect()));
|
|
572
573
|
expect(content.getBoundingClientRect().top < 0).to.be.true;
|
|
573
574
|
|
|
574
|
-
case
|
|
575
|
+
case 11:
|
|
575
576
|
case "end":
|
|
576
577
|
return _context11.stop();
|
|
577
578
|
}
|
|
578
579
|
}
|
|
579
580
|
}, _callee9);
|
|
580
581
|
})));
|
|
582
|
+
it('should add className', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
583
|
+
var Demo, _mount10, instance, element, trigger, dropdown;
|
|
584
|
+
|
|
585
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context13) {
|
|
586
|
+
while (1) {
|
|
587
|
+
switch (_context13.prev = _context13.next) {
|
|
588
|
+
case 0:
|
|
589
|
+
Demo = /*#__PURE__*/function (_Component3) {
|
|
590
|
+
_inheritsLoose(Demo, _Component3);
|
|
591
|
+
|
|
592
|
+
function Demo() {
|
|
593
|
+
var _context12;
|
|
594
|
+
|
|
595
|
+
var _this3;
|
|
596
|
+
|
|
597
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
598
|
+
args[_key3] = arguments[_key3];
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
_this3 = _Component3.call.apply(_Component3, _concatInstanceProperty(_context12 = [this]).call(_context12, args)) || this;
|
|
602
|
+
_this3.Tooltip = Tooltip;
|
|
603
|
+
return _this3;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return Demo;
|
|
607
|
+
}(Component);
|
|
608
|
+
|
|
609
|
+
Demo.template = "\n const Tooltip = this.Tooltip;\n <div>\n <Tooltip content=\"hello\" class=\"a\">\n <div ref=\"test\" class=\"b\">test</div>\n </Tooltip>\n </div>\n ";
|
|
610
|
+
_mount10 = mount(Demo), instance = _mount10[0], element = _mount10[1];
|
|
611
|
+
trigger = instance.refs.test;
|
|
612
|
+
expect(trigger.className).to.eql('b a');
|
|
613
|
+
dispatchEvent(trigger, 'mouseenter');
|
|
614
|
+
_context13.next = 8;
|
|
615
|
+
return wait();
|
|
616
|
+
|
|
617
|
+
case 8:
|
|
618
|
+
dropdown = getElement('.k-tooltip-content');
|
|
619
|
+
expect(dropdown.classList.contains('a')).to.be.true;
|
|
620
|
+
|
|
621
|
+
case 10:
|
|
622
|
+
case "end":
|
|
623
|
+
return _context13.stop();
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}, _callee10);
|
|
627
|
+
})));
|
|
628
|
+
it('should fix the width in small container', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
|
|
629
|
+
var Demo, _mount11, instance, element, trigger, expecedWidth, content, width, newWidth;
|
|
630
|
+
|
|
631
|
+
return _regeneratorRuntime.wrap(function _callee11$(_context15) {
|
|
632
|
+
while (1) {
|
|
633
|
+
switch (_context15.prev = _context15.next) {
|
|
634
|
+
case 0:
|
|
635
|
+
Demo = /*#__PURE__*/function (_Component4) {
|
|
636
|
+
_inheritsLoose(Demo, _Component4);
|
|
637
|
+
|
|
638
|
+
function Demo() {
|
|
639
|
+
var _context14;
|
|
640
|
+
|
|
641
|
+
var _this4;
|
|
642
|
+
|
|
643
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
644
|
+
args[_key4] = arguments[_key4];
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
_this4 = _Component4.call.apply(_Component4, _concatInstanceProperty(_context14 = [this]).call(_context14, args)) || this;
|
|
648
|
+
_this4.Tooltip = Tooltip;
|
|
649
|
+
_this4.Dialog = Dialog;
|
|
650
|
+
return _this4;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return Demo;
|
|
654
|
+
}(Component);
|
|
655
|
+
|
|
656
|
+
Demo.template = "\n const {Tooltip, Dialog} = this;\n <div style=\"text-align: right; position: relative; width: 300px;\">\n <Tooltip content=\"\u8FD9\u662F\u4E00\u6BB5\u5F88\u957F\u7684\u63CF\u8FF0\u6587\u5B57\uFF0C\u8FD9\u662F\u4E00\u6BB5\u5F88\u957F\u7684\u63CF\u8FF0\u6587\u5B57\" container={dom => dom}>\n <span class=\"trigger\">test</span>\n </Tooltip>\n </div>\n ";
|
|
657
|
+
_mount11 = mount(Demo), instance = _mount11[0], element = _mount11[1];
|
|
658
|
+
trigger = element.querySelector('.trigger');
|
|
659
|
+
expecedWidth = parseInt(tooltipTheme.maxWidth);
|
|
660
|
+
dispatchEvent(trigger, 'mouseenter');
|
|
661
|
+
_context15.next = 8;
|
|
662
|
+
return wait();
|
|
663
|
+
|
|
664
|
+
case 8:
|
|
665
|
+
content = getElement('.k-tooltip-content');
|
|
666
|
+
width = content.offsetWidth;
|
|
667
|
+
expect(width).to.eql(expecedWidth);
|
|
668
|
+
dispatchEvent(trigger, 'mouseleave');
|
|
669
|
+
_context15.next = 14;
|
|
670
|
+
return wait();
|
|
671
|
+
|
|
672
|
+
case 14:
|
|
673
|
+
dispatchEvent(trigger, 'mouseenter');
|
|
674
|
+
_context15.next = 17;
|
|
675
|
+
return wait();
|
|
676
|
+
|
|
677
|
+
case 17:
|
|
678
|
+
newWidth = content.offsetWidth;
|
|
679
|
+
expect(newWidth).to.eql(width);
|
|
680
|
+
|
|
681
|
+
case 19:
|
|
682
|
+
case "end":
|
|
683
|
+
return _context15.stop();
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}, _callee11);
|
|
687
|
+
})));
|
|
581
688
|
});
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import '../../styles/global';
|
|
2
|
+
declare const defaults: {
|
|
3
|
+
padding: string;
|
|
4
|
+
readonly color: string;
|
|
5
|
+
bgColor: string;
|
|
6
|
+
lineHeight: number;
|
|
7
|
+
maxWidth: string;
|
|
8
|
+
arrow: {
|
|
9
|
+
borderColor: string;
|
|
10
|
+
width: string;
|
|
11
|
+
};
|
|
12
|
+
confirm: {
|
|
13
|
+
gaps: string;
|
|
14
|
+
};
|
|
15
|
+
dark: {
|
|
16
|
+
readonly bgColor: string;
|
|
17
|
+
color: string;
|
|
18
|
+
readonly arrowBorderColor: string;
|
|
19
|
+
};
|
|
20
|
+
smallPadding: string;
|
|
21
|
+
};
|
|
22
|
+
export declare let tooltip: typeof defaults;
|
|
2
23
|
export declare type Theme = 'dark' | 'light';
|
|
3
24
|
export declare const themes: Theme[];
|
|
4
25
|
export default function makeStyles(): string;
|
|
26
|
+
export {};
|
|
@@ -23,5 +23,6 @@ export declare class Tooltip<T extends TooltipProps = TooltipProps, E extends To
|
|
|
23
23
|
static typeDefs: Required<TypeDefs<TooltipProps>>;
|
|
24
24
|
static defaults: () => Partial<TooltipProps>;
|
|
25
25
|
static events: Events<TooltipEvents>;
|
|
26
|
+
show(shouldFocus?: boolean): void;
|
|
26
27
|
hide(immediately: boolean): void;
|
|
27
28
|
}
|
|
@@ -25,6 +25,7 @@ var defaults = function defaults() {
|
|
|
25
25
|
at: 'center top',
|
|
26
26
|
collision: 'flipfit'
|
|
27
27
|
},
|
|
28
|
+
collison: 'flipfit',
|
|
28
29
|
hoverable: false,
|
|
29
30
|
always: false,
|
|
30
31
|
confirm: false,
|
|
@@ -48,6 +49,16 @@ export var Tooltip = /*#__PURE__*/function (_Dropdown) {
|
|
|
48
49
|
|
|
49
50
|
var _proto = Tooltip.prototype;
|
|
50
51
|
|
|
52
|
+
_proto.show = function show(shouldFocus) {
|
|
53
|
+
if (shouldFocus === void 0) {
|
|
54
|
+
shouldFocus = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.get('disabled')) return;
|
|
58
|
+
clearTimeout(this.timer);
|
|
59
|
+
this.set('value', true);
|
|
60
|
+
};
|
|
61
|
+
|
|
51
62
|
_proto.hide = function hide(immediately) {
|
|
52
63
|
if (this.get('always')) return;
|
|
53
64
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
4
|
+
var _excluded = ["children"];
|
|
5
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
6
|
+
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js/instance/starts-with";
|
|
7
|
+
import { Component, directClone, createVNode } from 'intact';
|
|
8
|
+
import { isTextChildren } from './utils';
|
|
9
|
+
import { EMPTY_OBJ, isFunction, hasOwn } from 'intact-shared';
|
|
10
|
+
import { cx } from '@emotion/css';
|
|
11
|
+
var reactEventReg = /on[A-Z]/;
|
|
12
|
+
export var Virtual = /*#__PURE__*/function (_Component) {
|
|
13
|
+
_inheritsLoose(Virtual, _Component);
|
|
14
|
+
|
|
15
|
+
function Virtual() {
|
|
16
|
+
var _context;
|
|
17
|
+
|
|
18
|
+
var _this;
|
|
19
|
+
|
|
20
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
21
|
+
args[_key] = arguments[_key];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
25
|
+
_this.vNodeProps = null;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Virtual.template = function template() {
|
|
30
|
+
var _cx;
|
|
31
|
+
|
|
32
|
+
var _this$get = this.get(),
|
|
33
|
+
children = _this$get.children,
|
|
34
|
+
props = _objectWithoutPropertiesLoose(_this$get, _excluded);
|
|
35
|
+
|
|
36
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
37
|
+
if (!children || Array.isArray(children) && children.length !== 1) {
|
|
38
|
+
throw new Error('Component must receive one children');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var vNode = Array.isArray(children) ? children[0] : children;
|
|
43
|
+
var clonedVNode = isTextChildren(vNode) ? createVNode('span', null, vNode) : directClone(vNode);
|
|
44
|
+
var vNodeProps = this.vNodeProps = this.getVNodeProps(clonedVNode.props || EMPTY_OBJ);
|
|
45
|
+
var eventProps = this.getEventProps(); // merge className
|
|
46
|
+
|
|
47
|
+
var className = clonedVNode.className || vNodeProps.className;
|
|
48
|
+
className = cx((_cx = {}, _cx[className] = !!className, _cx[props.className] = !!props.className, _cx));
|
|
49
|
+
clonedVNode.props = _extends({}, props, vNodeProps, eventProps, {
|
|
50
|
+
className: className
|
|
51
|
+
});
|
|
52
|
+
clonedVNode.className = className;
|
|
53
|
+
return clonedVNode;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
var _proto = Virtual.prototype;
|
|
57
|
+
|
|
58
|
+
_proto.getVNodeProps = function getVNodeProps(props) {
|
|
59
|
+
var vnode = props.vnode;
|
|
60
|
+
if (!vnode) return props; // maybe we render the intact component in react slot property, in this case
|
|
61
|
+
// the $isReact is false. so use the vnode $$typeof field as gauge
|
|
62
|
+
|
|
63
|
+
if (vnode.$$typeof || vnode.__v_isVNode
|
|
64
|
+
/* vue3 vnode */
|
|
65
|
+
) {
|
|
66
|
+
var _props = vnode.props;
|
|
67
|
+
if (!_props) return props;
|
|
68
|
+
var events = {};
|
|
69
|
+
|
|
70
|
+
for (var key in _props) {
|
|
71
|
+
if (reactEventReg.test(key)) {
|
|
72
|
+
events["ev-" + key.substring(2).toLowerCase()] = _props[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return _extends({}, props, events, {
|
|
77
|
+
className: _props.className || _props.class
|
|
78
|
+
/* vue-next */
|
|
79
|
+
|
|
80
|
+
});
|
|
81
|
+
} else if (hasOwn.call(vnode, 'componentOptions')
|
|
82
|
+
/* vue2 vnode */
|
|
83
|
+
) {
|
|
84
|
+
var data = vnode.data;
|
|
85
|
+
var on = data && data.on || EMPTY_OBJ;
|
|
86
|
+
var _events = {};
|
|
87
|
+
|
|
88
|
+
for (var _key2 in on) {
|
|
89
|
+
_events["ev-" + _key2] = on[_key2];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return _extends({}, props, _events);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return props;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
_proto.getEventProps = function getEventProps() {
|
|
99
|
+
var _this2 = this;
|
|
100
|
+
|
|
101
|
+
var props = {};
|
|
102
|
+
|
|
103
|
+
var _loop = function _loop(prop) {
|
|
104
|
+
if (_startsWithInstanceProperty(prop).call(prop, 'ev-')) {
|
|
105
|
+
props[prop] = function (e) {
|
|
106
|
+
return _this2.callEvent(prop, e);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
for (var prop in this.get()) {
|
|
112
|
+
_loop(prop);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return props;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
_proto.callEvent = function callEvent(name, e) {
|
|
119
|
+
var callback = this.vNodeProps[name];
|
|
120
|
+
var callbackOnVirtual = this.get(name);
|
|
121
|
+
if (isFunction(callback)) callback(e);
|
|
122
|
+
if (isFunction(callbackOnVirtual)) callbackOnVirtual(e);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return Virtual;
|
|
126
|
+
}(Component);
|