@king-design/react 3.6.0 → 3.6.2-beta.0
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/__tests__/__snapshots__/React Demos.md +117 -61
- package/components/copy/index.spec.js +14 -31
- package/components/datepicker/index.spec.js +646 -608
- package/components/datepicker/useValueBase.js +5 -2
- package/components/dropdown/constants.d.ts +22 -0
- package/components/dropdown/constants.js +7 -0
- package/components/dropdown/item.js +1 -1
- package/components/dropdown/menu.js +1 -1
- package/components/dropdown/useItemKeyboard.d.ts +6 -0
- package/components/dropdown/useItemKeyboard.js +32 -0
- package/components/dropdown/useMenuKeyboard.d.ts +2 -0
- package/components/dropdown/{useKeyboard.js → useMenuKeyboard.js} +3 -38
- package/components/form/form.d.ts +1 -0
- package/components/form/form.js +7 -0
- package/components/form/index.spec.js +10 -8
- package/components/menu/index.spec.js +28 -0
- package/components/menu/styles.js +2 -2
- package/components/select/index.spec.js +231 -177
- package/components/select/menu.js +1 -1
- package/components/select/useCard.d.ts +4 -3
- package/components/select/useCard.js +15 -4
- package/components/spinner/index.spec.js +82 -44
- package/components/spinner/useValue.js +2 -1
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +2 -2
- package/yarn-error.log +528 -0
- package/components/dropdown/useKeyboard.d.ts +0 -23
|
@@ -189,8 +189,11 @@ export function useValueBase(_ref, _ref2, panel, shouldUpdateValue, updateValueO
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
var valueStr = convertToValueString(_value);
|
|
192
|
-
|
|
193
|
-
instance.
|
|
192
|
+
// only trigger change event once
|
|
193
|
+
if (!isEqualArray(valueStr, instance.get('value'))) {
|
|
194
|
+
instance.set('value', valueStr);
|
|
195
|
+
instance.resetKeywords();
|
|
196
|
+
}
|
|
194
197
|
}
|
|
195
198
|
// TODO
|
|
196
199
|
function setMoment() {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Component } from 'intact-react';
|
|
2
|
+
import type { DropdownItem } from './item';
|
|
3
|
+
export interface ItemEvents {
|
|
4
|
+
onFocusin: () => void;
|
|
5
|
+
onFocusout: () => void;
|
|
6
|
+
onShowMenu: () => void;
|
|
7
|
+
onHideMenu: () => void;
|
|
8
|
+
onSelect: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare enum Direction {
|
|
11
|
+
Up = 0,
|
|
12
|
+
Down = 1
|
|
13
|
+
}
|
|
14
|
+
export type MenuKeyboardMethods = {
|
|
15
|
+
reset: () => void;
|
|
16
|
+
focus: (item: DropdownItem) => void;
|
|
17
|
+
};
|
|
18
|
+
export type ItemComponent = Component<{
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
export declare const ITEM_EVENTS = "ItemEvents";
|
|
22
|
+
export declare const MENU_KEYBOARD = "MenuKeyboard";
|
|
@@ -4,7 +4,7 @@ import { __decorate } from "tslib";
|
|
|
4
4
|
import { Component, inject } from 'intact-react';
|
|
5
5
|
import template from './item.vdt';
|
|
6
6
|
import { bind } from '../utils';
|
|
7
|
-
import { useItemKeyboard } from './
|
|
7
|
+
import { useItemKeyboard } from './useItemKeyboard';
|
|
8
8
|
import { DROPDOWN } from './dropdown';
|
|
9
9
|
import { DROPDOWN_MENU } from './menu';
|
|
10
10
|
import { Dropdown as ExportDropdown, DropdownMenu as ExportDropdownMenu } from '.';
|
|
@@ -6,7 +6,7 @@ import template from './menu.vdt';
|
|
|
6
6
|
import { bind } from '../utils';
|
|
7
7
|
import { DROPDOWN } from './dropdown';
|
|
8
8
|
import { useTransition } from './useTransition';
|
|
9
|
-
import { useMenuKeyboard } from './
|
|
9
|
+
import { useMenuKeyboard } from './useMenuKeyboard';
|
|
10
10
|
import { useMouseOutsidable } from '../../hooks/useMouseOutsidable';
|
|
11
11
|
import { useConfigContext } from '../config';
|
|
12
12
|
import { usePositionForDropdownMenu } from './usePosition';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ItemEvents } from './constants';
|
|
2
|
+
export declare function useItemKeyboard(itemEvents: Omit<ItemEvents, 'onFocusin' | 'onFocusout'>): {
|
|
3
|
+
onMouseEnter(e: MouseEvent): void;
|
|
4
|
+
onMouseLeave(e: MouseEvent): void;
|
|
5
|
+
isFocus: import("../../hooks/useState").State<boolean>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import { useInstance, inject } from 'intact-react';
|
|
3
|
+
import { useRecordItem } from '../../hooks/useRecordComponent';
|
|
4
|
+
import { useState } from '../../hooks/useState';
|
|
5
|
+
import { MENU_KEYBOARD, ITEM_EVENTS } from './constants';
|
|
6
|
+
export function useItemKeyboard(itemEvents) {
|
|
7
|
+
var isFocus = useState(false);
|
|
8
|
+
var keyboard = inject(MENU_KEYBOARD);
|
|
9
|
+
var instance = useInstance();
|
|
10
|
+
useRecordItem(ITEM_EVENTS, instance, _extends({}, itemEvents, {
|
|
11
|
+
onFocusin: function onFocusin() {
|
|
12
|
+
isFocus.set(true);
|
|
13
|
+
},
|
|
14
|
+
onFocusout: function onFocusout() {
|
|
15
|
+
isFocus.set(false);
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
return {
|
|
19
|
+
onMouseEnter: function onMouseEnter(e) {
|
|
20
|
+
instance.trigger('mouseenter', e);
|
|
21
|
+
if (instance.get('disabled')) return;
|
|
22
|
+
keyboard.focus(instance);
|
|
23
|
+
},
|
|
24
|
+
onMouseLeave: function onMouseLeave(e) {
|
|
25
|
+
instance.trigger('mouseleave', e);
|
|
26
|
+
keyboard.reset();
|
|
27
|
+
// If it is a virtual item, it needs to be reset manually because the DOM is reused.
|
|
28
|
+
isFocus.set(false);
|
|
29
|
+
},
|
|
30
|
+
isFocus: isFocus
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { useRecordParent, useRecordItem } from '../../hooks/useRecordComponent';
|
|
1
|
+
import { onBeforeUpdate, onMounted, onUpdated, useInstance, findDomFromVNode, provide, isComponentClass, isComponentFunction, hasVNodeChildren, hasMultipleChildren } from 'intact-react';
|
|
2
|
+
import { useRecordParent } from '../../hooks/useRecordComponent';
|
|
4
3
|
import { useKeyboard } from '../../hooks/useKeyboard';
|
|
5
|
-
import { useState } from '../../hooks/useState';
|
|
6
4
|
import { isComponentVNode } from '../utils';
|
|
7
5
|
import { DropdownItem } from './item';
|
|
8
6
|
// can not import DropdownMenu from index.ts, otherwise it will cause circle reference
|
|
9
7
|
// import {DropdownMenu} from './';
|
|
10
8
|
import { DropdownMenu } from './menu';
|
|
11
|
-
|
|
12
|
-
(function (Direction) {
|
|
13
|
-
Direction[Direction["Up"] = 0] = "Up";
|
|
14
|
-
Direction[Direction["Down"] = 1] = "Down";
|
|
15
|
-
})(Direction || (Direction = {}));
|
|
16
|
-
var ITEM_EVENTS = 'ItemEvents';
|
|
17
|
-
var MENU_KEYBOARD = 'MenuKeyboard';
|
|
9
|
+
import { ITEM_EVENTS, Direction, MENU_KEYBOARD } from './constants';
|
|
18
10
|
export function useMenuKeyboard() {
|
|
19
11
|
var items = [];
|
|
20
12
|
var itemEvents = useRecordParent(ITEM_EVENTS, true);
|
|
@@ -121,33 +113,6 @@ export function useMenuKeyboard() {
|
|
|
121
113
|
enter: makeEventCall('onSelect')
|
|
122
114
|
}), focusByIndex, reset];
|
|
123
115
|
}
|
|
124
|
-
export function useItemKeyboard(itemEvents) {
|
|
125
|
-
var isFocus = useState(false);
|
|
126
|
-
var keyboard = inject(MENU_KEYBOARD);
|
|
127
|
-
var instance = useInstance();
|
|
128
|
-
useRecordItem(ITEM_EVENTS, instance, _extends({}, itemEvents, {
|
|
129
|
-
onFocusin: function onFocusin() {
|
|
130
|
-
isFocus.set(true);
|
|
131
|
-
},
|
|
132
|
-
onFocusout: function onFocusout() {
|
|
133
|
-
isFocus.set(false);
|
|
134
|
-
}
|
|
135
|
-
}));
|
|
136
|
-
return {
|
|
137
|
-
onMouseEnter: function onMouseEnter(e) {
|
|
138
|
-
instance.trigger('mouseenter', e);
|
|
139
|
-
if (instance.get('disabled')) return;
|
|
140
|
-
keyboard.focus(instance);
|
|
141
|
-
},
|
|
142
|
-
onMouseLeave: function onMouseLeave(e) {
|
|
143
|
-
instance.trigger('mouseleave', e);
|
|
144
|
-
keyboard.reset();
|
|
145
|
-
// If it is a virtual item, it needs to be reset manually because the DOM is reused.
|
|
146
|
-
isFocus.set(false);
|
|
147
|
-
},
|
|
148
|
-
isFocus: isFocus
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
116
|
function fixIndex(index, max) {
|
|
152
117
|
if (index > max) {
|
|
153
118
|
index = 0;
|
|
@@ -32,6 +32,7 @@ export declare class Form extends Component<FormProps, FormEvents> {
|
|
|
32
32
|
init(): void;
|
|
33
33
|
validate(): Promise<boolean>;
|
|
34
34
|
getFirstInvalidFormItem(): FormItem | undefined;
|
|
35
|
+
getAllInvalidFormItems(): FormItem[];
|
|
35
36
|
submit(e: Event): void;
|
|
36
37
|
reset(): void;
|
|
37
38
|
private onSubmit;
|
package/components/form/form.js
CHANGED
|
@@ -3,6 +3,7 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/con
|
|
|
3
3
|
import _Promise from "@babel/runtime-corejs3/core-js/promise";
|
|
4
4
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
5
5
|
import _findInstanceProperty from "@babel/runtime-corejs3/core-js/instance/find";
|
|
6
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js/instance/filter";
|
|
6
7
|
import { __decorate } from "tslib";
|
|
7
8
|
import { Component, provide } from 'intact-react';
|
|
8
9
|
import template from './form.vdt';
|
|
@@ -59,6 +60,12 @@ export var Form = /*#__PURE__*/function (_Component) {
|
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
};
|
|
63
|
+
_proto.getAllInvalidFormItems = function getAllInvalidFormItems() {
|
|
64
|
+
var _context4;
|
|
65
|
+
return _filterInstanceProperty(_context4 = this.items).call(_context4, function (item) {
|
|
66
|
+
return !item.isValid();
|
|
67
|
+
});
|
|
68
|
+
};
|
|
62
69
|
_proto.submit = function submit(e) {
|
|
63
70
|
var _this2 = this;
|
|
64
71
|
this.validate().then(function (valid) {
|
|
@@ -32,7 +32,7 @@ describe('Form', function () {
|
|
|
32
32
|
return unmount();
|
|
33
33
|
});
|
|
34
34
|
it('validate', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
35
|
-
var _mount, instance, element, form, item, input;
|
|
35
|
+
var _mount, instance, element, form, item, items, input;
|
|
36
36
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
37
37
|
while (1) switch (_context.prev = _context.next) {
|
|
38
38
|
case 0:
|
|
@@ -44,24 +44,26 @@ describe('Form', function () {
|
|
|
44
44
|
expect(element.innerHTML).to.matchSnapshot();
|
|
45
45
|
item = form.getFirstInvalidFormItem();
|
|
46
46
|
expect(item.get('label')).to.eql('Input');
|
|
47
|
+
items = form.getAllInvalidFormItems();
|
|
48
|
+
expect(items.length).to.eql(10);
|
|
47
49
|
instance.reset();
|
|
48
|
-
_context.next =
|
|
50
|
+
_context.next = 12;
|
|
49
51
|
return wait();
|
|
50
|
-
case
|
|
52
|
+
case 12:
|
|
51
53
|
expect(instance.get('model')).to.matchSnapshot();
|
|
52
54
|
// validate on focusout
|
|
53
55
|
input = element.querySelector('input');
|
|
54
56
|
dispatchEvent(input, 'focus');
|
|
55
|
-
_context.next =
|
|
57
|
+
_context.next = 17;
|
|
56
58
|
return wait();
|
|
57
|
-
case
|
|
59
|
+
case 17:
|
|
58
60
|
expect(element.innerHTML).to.matchSnapshot();
|
|
59
61
|
dispatchEvent(input, 'focusout');
|
|
60
|
-
_context.next =
|
|
62
|
+
_context.next = 21;
|
|
61
63
|
return wait();
|
|
62
|
-
case
|
|
64
|
+
case 21:
|
|
63
65
|
expect(element.innerHTML).to.matchSnapshot();
|
|
64
|
-
case
|
|
66
|
+
case 22:
|
|
65
67
|
case "end":
|
|
66
68
|
return _context.stop();
|
|
67
69
|
}
|
|
@@ -8,6 +8,7 @@ import BasicDemo from '~/components/menu/demos/basic';
|
|
|
8
8
|
import CollapseDemo from '~/components/menu/demos/collapse';
|
|
9
9
|
import AccordionDemo from '~/components/menu/demos/accordion';
|
|
10
10
|
import CollapseArrowDemo from '~/components/menu/demos/showCollapseArrow';
|
|
11
|
+
import HorizontalDemo from '~/components/menu/demos/horizontal';
|
|
11
12
|
import { mount, unmount, dispatchEvent, getElement, wait } from '../../test/utils';
|
|
12
13
|
import { Menu, MenuItem } from './';
|
|
13
14
|
describe('Menu', function () {
|
|
@@ -271,4 +272,31 @@ describe('Menu', function () {
|
|
|
271
272
|
}
|
|
272
273
|
}, _callee7);
|
|
273
274
|
})));
|
|
275
|
+
it('detecting pop-up position during rapid mouse hover over menus', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
276
|
+
var _mount8, instance, element, _element$querySelecto2, menu3, menu4, dropdownmenu1, top1, dropdownmenu2, top2;
|
|
277
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context9) {
|
|
278
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
279
|
+
case 0:
|
|
280
|
+
_mount8 = mount(HorizontalDemo), instance = _mount8[0], element = _mount8[1];
|
|
281
|
+
_element$querySelecto2 = element.querySelectorAll('.k-menu-item-title'), menu3 = _element$querySelecto2[2], menu4 = _element$querySelecto2[3];
|
|
282
|
+
dispatchEvent(menu3, 'mouseenter');
|
|
283
|
+
_context9.next = 5;
|
|
284
|
+
return wait(500);
|
|
285
|
+
case 5:
|
|
286
|
+
dropdownmenu1 = getElement('.k-dropdown-menu');
|
|
287
|
+
top1 = dropdownmenu1.getBoundingClientRect().top;
|
|
288
|
+
dispatchEvent(menu3, 'mouseleave');
|
|
289
|
+
dispatchEvent(menu4, 'mouseenter');
|
|
290
|
+
_context9.next = 11;
|
|
291
|
+
return wait(1000);
|
|
292
|
+
case 11:
|
|
293
|
+
dropdownmenu2 = getElement('.k-dropdown-menu');
|
|
294
|
+
top2 = dropdownmenu2.getBoundingClientRect().top;
|
|
295
|
+
expect(top1).to.eql(top2);
|
|
296
|
+
case 14:
|
|
297
|
+
case "end":
|
|
298
|
+
return _context9.stop();
|
|
299
|
+
}
|
|
300
|
+
}, _callee8);
|
|
301
|
+
})));
|
|
274
302
|
});
|
|
@@ -21,7 +21,7 @@ var defaults = {
|
|
|
21
21
|
item: {
|
|
22
22
|
height: '40px',
|
|
23
23
|
padding: '0 12px',
|
|
24
|
-
bodyPadding: '
|
|
24
|
+
bodyPadding: '4px',
|
|
25
25
|
color: '#aeaeb9',
|
|
26
26
|
hoverColor: '#fff',
|
|
27
27
|
disabledColor: '#53535a',
|
|
@@ -115,7 +115,7 @@ export var makeMenuStyles = cache(function makeMenuStyles(k) {
|
|
|
115
115
|
return /*#__PURE__*/css("&.", k, "-menu{width:", menu.width, ";transition:width ", menu.transition, ";background:", menu.bgColor, ";font-size:", menu.fontSize, ";position:relative;}.", k, "-icon{width:", menu.icon.width, ";margin-right:", menu.icon.gap, ";text-align:center;flex-shrink:0;}.", k, "-menu-header{height:", menu.header.height, ";padding:0 16px;color:", menu.header.color, ";font-size:", menu.header.fontSize, ";font-weight:bold;}.", k, "-menu-body{padding:", menu.item.bodyPadding, ";max-height:calc(100% - ", menu.header.height, ");overflow-y:auto;overflow-x:hidden;scrollbar-width:none;}.", k, "-menu-title{height:", menu.title.height, ";border-top:", menu.border, ";margin-top:4px;.", k, "-menu-name{transition:all ", menu.transition, ";height:", menu.title.height, ";color:", menu.title.color, ";font-weight:bold;}}.", k, "-menu-arrow-box{width:14px;height:60px;cursor:pointer;background:", menu.bgColor, ";border-radius:0 8px 8px 0;position:absolute;display:flex;align-items:center;justify-content:center;top:50%;left:calc(", menu.width, " - 2px);transition:left ", menu.transition, ";transform:translateY(-50%);border:", menu.border, ";border-left:none;.", k, "-icon{margin-right:0;}&:hover{.", k, "-menu-arrow:before{color:", menu.item.activeBgColor, ";}}}&.", k, "-light{border-right:1px solid ", theme.color.disabledBg, ";background:", menu.light.bgColor, ";.", k, "-menu-header{color:", menu.light.title.color, ";}.", k, "-menu-item{.", k, "-menu-item-title{color:", menu.light.item.color, ";&:hover{background:", menu.light.item.hoverBg, ";}}.", k, "-menu-item-arrow{color:", menu.light.item.color, ";}&.", k, "-highlighted{>.", k, "-menu-item-title{color:", menu.light.item.hoverColor, ";}}&.", k, "-disabled{>.", k, "-menu-item-title{color:", menu.light.item.disabledColor, "!important;}}}.", k, "-menu-title{border-top:", menu.light.border, ";.", k, "-menu-name{color:", menu.light.title.color, ";}}.", k, "-menu-arrow-box{background:", menu.light.bgColor, ";border:", menu.light.border, ";border-left:none;&:hover{.", k, "-menu-arrow:before{color:", menu.light.active.color, ";}}}.", k, "-menu:not(.", k, "-dropdown-menu){background:", menu.light.bgColor, ";}&.", k, "-horizontal{.", k, "-menu-header{border-right:", menu.light.border, ";}.", k, "-menu-body>.", k, "-menu-title{border-right:", menu.light.border, ";}}.", k, "-menu-item.", k, "-active{>.", k, "-menu-item-title{color:", menu.light.active.color, "!important;background:", menu.light.active.bgColor, ";}}.", k, "-sub-menu{.", k, "-menu-item-title,.", k, "-menu-item-arrow{color:", menu.light.item.subTitleColor, "!important;}}}", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
116
116
|
var styles = menu[size];
|
|
117
117
|
return /*#__PURE__*/css("&.", k, "-", size, "{width:", styles.width, ";font-size:", styles.fontSize, ";.", k, "-menu{font-size:", styles.fontSize, ";}.", k, "-menu-arrow-box{left:calc(", styles.width, " - 2px);}}");
|
|
118
|
-
}), "&.", k, "-collapsed{width:calc(", menu.icon.width, " + (", getLeft(menu.item.padding), " + ", getLeft(menu.item.bodyPadding), ") * 2);.", k, "-icon{margin-right:0;}.", k, "-menu-item-arrow{display:none;}}&.", k, "-collapsed-arrow{width:0px;border-left:none;.", k, "-menu-header{padding:0;}.", k, "-menu-body{overflow:hidden;padding:0;}.", k, "-menu-arrow-box{left:0;.", k, "-menu-arrow:before{transform:rotateY(180deg);}}}&.", k, "-dropdown-menu{width:fit-content;min-width:", menu.dropdown.minWidth, ";.", k, "-menu-item-arrow{transform:rotate(-90deg);}}&.", k, "-horizontal{width:auto;display:flex;.", k, "-menu-body{display:flex;align-items:center;.", k, "-menu-title{border-top:none;border-right:", menu.border, ";}}}");
|
|
118
|
+
}), "&.", k, "-collapsed{width:calc(", menu.icon.width, " + (", getLeft(menu.item.padding), " + ", getLeft(menu.item.bodyPadding), ") * 2);.", k, "-icon{margin-right:0;}.", k, "-menu-item-arrow{display:none;}}&.", k, "-collapsed-arrow{width:0px;border-left:none;.", k, "-menu-header{padding:0;}.", k, "-menu-body{overflow:hidden;padding:0;}.", k, "-menu-arrow-box{left:0;.", k, "-menu-arrow:before{transform:rotateY(180deg);}}}&.", k, "-dropdown-menu{width:fit-content;min-width:", menu.dropdown.minWidth, ";position:absolute;.", k, "-menu-item-arrow{transform:rotate(-90deg);}}&.", k, "-horizontal{width:auto;display:flex;.", k, "-menu-body{display:flex;align-items:center;.", k, "-menu-title{border-top:none;border-right:", menu.border, ";}}}");
|
|
119
119
|
});
|
|
120
120
|
export var makeTitleStyles = cache(function makeTitleStyles(k) {
|
|
121
121
|
var item = menu.item;
|