@douyinfe/semi-foundation 2.14.0 → 2.15.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/cascader/cascader.scss +20 -0
- package/cascader/foundation.ts +21 -0
- package/cascader/variables.scss +2 -0
- package/checkbox/checkbox.scss +9 -9
- package/checkbox/checkboxFoundation.ts +1 -0
- package/datePicker/foundation.ts +32 -8
- package/datePicker/monthsGridFoundation.ts +1 -2
- package/dropdown/dropdown.scss +4 -0
- package/dropdown/foundation.ts +38 -1
- package/dropdown/menuFoundation.ts +77 -0
- package/lib/cjs/cascader/cascader.css +15 -0
- package/lib/cjs/cascader/cascader.scss +20 -0
- package/lib/cjs/cascader/foundation.d.ts +6 -0
- package/lib/cjs/cascader/foundation.js +23 -0
- package/lib/cjs/cascader/variables.scss +2 -0
- package/lib/cjs/checkbox/checkbox.css +5 -5
- package/lib/cjs/checkbox/checkbox.scss +9 -9
- package/lib/cjs/checkbox/checkboxFoundation.d.ts +1 -0
- package/lib/cjs/datePicker/foundation.d.ts +7 -0
- package/lib/cjs/datePicker/foundation.js +38 -7
- package/lib/cjs/datePicker/monthsGridFoundation.js +1 -4
- package/lib/cjs/dropdown/dropdown.css +4 -0
- package/lib/cjs/dropdown/dropdown.scss +4 -0
- package/lib/cjs/dropdown/foundation.d.ts +4 -0
- package/lib/cjs/dropdown/foundation.js +48 -0
- package/lib/cjs/dropdown/menuFoundation.d.ts +9 -0
- package/lib/cjs/dropdown/menuFoundation.js +119 -0
- package/lib/cjs/list/list.css +1 -1
- package/lib/cjs/list/list.scss +1 -1
- package/lib/cjs/list/variables.scss +2 -1
- package/lib/cjs/modal/modalFoundation.d.ts +1 -0
- package/lib/cjs/rating/foundation.d.ts +13 -0
- package/lib/cjs/rating/foundation.js +123 -35
- package/lib/cjs/rating/rating.css +14 -5
- package/lib/cjs/rating/rating.scss +21 -8
- package/lib/cjs/rating/variables.scss +4 -0
- package/lib/cjs/tabs/foundation.js +28 -6
- package/lib/cjs/tooltip/foundation.js +39 -9
- package/lib/cjs/tree/foundation.d.ts +1 -0
- package/lib/cjs/treeSelect/foundation.js +9 -1
- package/lib/cjs/utils/FocusHandle.d.ts +1 -0
- package/lib/cjs/utils/FocusHandle.js +6 -1
- package/lib/cjs/utils/a11y.d.ts +9 -0
- package/lib/cjs/utils/a11y.js +123 -0
- package/lib/es/cascader/cascader.css +15 -0
- package/lib/es/cascader/cascader.scss +20 -0
- package/lib/es/cascader/foundation.d.ts +6 -0
- package/lib/es/cascader/foundation.js +23 -0
- package/lib/es/cascader/variables.scss +2 -0
- package/lib/es/checkbox/checkbox.css +5 -5
- package/lib/es/checkbox/checkbox.scss +9 -9
- package/lib/es/checkbox/checkboxFoundation.d.ts +1 -0
- package/lib/es/datePicker/foundation.d.ts +7 -0
- package/lib/es/datePicker/foundation.js +37 -7
- package/lib/es/datePicker/monthsGridFoundation.js +1 -3
- package/lib/es/dropdown/dropdown.css +4 -0
- package/lib/es/dropdown/dropdown.scss +4 -0
- package/lib/es/dropdown/foundation.d.ts +4 -0
- package/lib/es/dropdown/foundation.js +45 -0
- package/lib/es/dropdown/menuFoundation.d.ts +9 -0
- package/lib/es/dropdown/menuFoundation.js +99 -0
- package/lib/es/list/list.css +1 -1
- package/lib/es/list/list.scss +1 -1
- package/lib/es/list/variables.scss +2 -1
- package/lib/es/modal/modalFoundation.d.ts +1 -0
- package/lib/es/rating/foundation.d.ts +13 -0
- package/lib/es/rating/foundation.js +116 -32
- package/lib/es/rating/rating.css +14 -5
- package/lib/es/rating/rating.scss +21 -8
- package/lib/es/rating/variables.scss +4 -0
- package/lib/es/tabs/foundation.js +30 -6
- package/lib/es/tooltip/foundation.js +38 -9
- package/lib/es/tree/foundation.d.ts +1 -0
- package/lib/es/treeSelect/foundation.js +9 -1
- package/lib/es/utils/FocusHandle.d.ts +1 -0
- package/lib/es/utils/FocusHandle.js +6 -1
- package/lib/es/utils/a11y.d.ts +9 -0
- package/lib/es/utils/a11y.js +101 -0
- package/list/list.scss +1 -1
- package/list/variables.scss +2 -1
- package/modal/modalFoundation.ts +1 -0
- package/package.json +2 -2
- package/rating/foundation.ts +90 -31
- package/rating/rating.scss +21 -8
- package/rating/variables.scss +4 -0
- package/tabs/foundation.ts +9 -6
- package/tooltip/foundation.ts +16 -8
- package/tree/foundation.ts +1 -0
- package/treeSelect/foundation.ts +5 -1
- package/utils/FocusHandle.ts +3 -1
- package/utils/a11y.ts +105 -0
|
@@ -40,6 +40,8 @@ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable
|
|
|
40
40
|
|
|
41
41
|
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
42
42
|
|
|
43
|
+
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
|
|
44
|
+
|
|
43
45
|
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
44
46
|
|
|
45
47
|
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
@@ -176,6 +178,27 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
176
178
|
this._adapter.updateValue(result);
|
|
177
179
|
|
|
178
180
|
this.resetCachedSelectedValue(result);
|
|
181
|
+
this.initRangeInputFocus(result);
|
|
182
|
+
|
|
183
|
+
if (this._adapter.needConfirm()) {
|
|
184
|
+
this._adapter.updateCachedSelectedValue(result);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 如果用户传了一个空的 value,需要把 range input focus 设置为 rangeStart,这样用户可以清除完之后继续从开始选择
|
|
189
|
+
*
|
|
190
|
+
* If the user passes an empty value, you need to set the range input focus to rangeStart, so that the user can continue to select from the beginning after clearing
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
initRangeInputFocus(result) {
|
|
195
|
+
const {
|
|
196
|
+
triggerRender
|
|
197
|
+
} = this.getProps();
|
|
198
|
+
|
|
199
|
+
if (this._isRangeType() && (0, _isFunction2.default)(triggerRender) && result.length === 0) {
|
|
200
|
+
this._adapter.setRangeInputFocus('rangeStart');
|
|
201
|
+
}
|
|
179
202
|
}
|
|
180
203
|
|
|
181
204
|
parseWithTimezone(value, timeZone, prevTimeZone) {
|
|
@@ -1424,7 +1447,8 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
1424
1447
|
|
|
1425
1448
|
handleTriggerWrapperClick(e) {
|
|
1426
1449
|
const {
|
|
1427
|
-
disabled
|
|
1450
|
+
disabled,
|
|
1451
|
+
triggerRender
|
|
1428
1452
|
} = this._adapter.getProps();
|
|
1429
1453
|
|
|
1430
1454
|
const {
|
|
@@ -1443,12 +1467,19 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
1443
1467
|
*/
|
|
1444
1468
|
|
|
1445
1469
|
|
|
1446
|
-
if (this._isRangeType() && !rangeInputFocus
|
|
1447
|
-
(
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1470
|
+
if (this._isRangeType() && !rangeInputFocus) {
|
|
1471
|
+
if (this._adapter.isEventTarget(e)) {
|
|
1472
|
+
(0, _setTimeout2.default)(() => {
|
|
1473
|
+
// using setTimeout get correct state value 'rangeInputFocus'
|
|
1474
|
+
this.handleInputFocus(e, 'rangeStart');
|
|
1475
|
+
}, 0);
|
|
1476
|
+
} else if ((0, _isFunction2.default)(triggerRender)) {
|
|
1477
|
+
// 如果是 triggerRender 场景,因为没有 input,因此打开面板时默认 focus 在 rangeStart
|
|
1478
|
+
// If it is a triggerRender scene, because there is no input, the default focus is rangeStart when the panel is opened
|
|
1479
|
+
this._adapter.setRangeInputFocus('rangeStart');
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
this.openPanel();
|
|
1452
1483
|
} else {
|
|
1453
1484
|
this.openPanel();
|
|
1454
1485
|
}
|
|
@@ -28,8 +28,6 @@ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
|
|
|
28
28
|
|
|
29
29
|
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
30
30
|
|
|
31
|
-
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
|
|
32
|
-
|
|
33
31
|
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
34
32
|
|
|
35
33
|
var _isSet2 = _interopRequireDefault(require("lodash/isSet"));
|
|
@@ -828,11 +826,10 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
828
826
|
/**
|
|
829
827
|
* no need to check focus then
|
|
830
828
|
* - dateRange and isDateRangeAndHasOffset
|
|
831
|
-
* - dateRange and triggerRender
|
|
832
829
|
*/
|
|
833
830
|
|
|
834
831
|
|
|
835
|
-
const needCheckFocusRecord = !(type === 'dateRange' &&
|
|
832
|
+
const needCheckFocusRecord = !(type === 'dateRange' && isDateRangeAndHasOffset);
|
|
836
833
|
|
|
837
834
|
this._adapter.notifySelectedChange(date, {
|
|
838
835
|
needCheckFocusRecord
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
.semi-dropdown-item:not(.semi-dropdown-item-active):active {
|
|
54
54
|
background-color: var(--semi-color-fill-1);
|
|
55
55
|
}
|
|
56
|
+
.semi-dropdown-item:focus-visible {
|
|
57
|
+
background-color: var(--semi-color-fill-0);
|
|
58
|
+
outline: 0;
|
|
59
|
+
}
|
|
56
60
|
.semi-dropdown-item-icon {
|
|
57
61
|
display: inline-flex;
|
|
58
62
|
align-items: center;
|
|
@@ -50,6 +50,10 @@ $module: #{$prefix}-dropdown;
|
|
|
50
50
|
&:not(.#{$module}-item-active):active {
|
|
51
51
|
background-color: $color-dropdown_item-bg-active;
|
|
52
52
|
}
|
|
53
|
+
&:focus-visible {
|
|
54
|
+
background-color: $color-dropdown_item-bg-hover;
|
|
55
|
+
outline: 0;
|
|
56
|
+
}
|
|
53
57
|
&-icon {
|
|
54
58
|
display: inline-flex;
|
|
55
59
|
align-items: center;
|
|
@@ -5,4 +5,8 @@ export interface DropdownAdapter extends Partial<DefaultAdapter> {
|
|
|
5
5
|
}
|
|
6
6
|
export default class DropdownFoundation extends BaseFoundation<DropdownAdapter> {
|
|
7
7
|
handleVisibleChange(visible: boolean): void;
|
|
8
|
+
getMenuItemNodes(target: any): HTMLElement[];
|
|
9
|
+
setFocusToFirstMenuItem(target: any): void;
|
|
10
|
+
setFocusToLastMenuItem(target: any): void;
|
|
11
|
+
handleKeyDown(event: any): void;
|
|
8
12
|
}
|
|
@@ -10,8 +10,14 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
10
10
|
|
|
11
11
|
exports.default = void 0;
|
|
12
12
|
|
|
13
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
14
|
+
|
|
15
|
+
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
|
|
16
|
+
|
|
13
17
|
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
14
18
|
|
|
19
|
+
var _a11y = require("../utils/a11y");
|
|
20
|
+
|
|
15
21
|
class DropdownFoundation extends _foundation.default {
|
|
16
22
|
handleVisibleChange(visible) {
|
|
17
23
|
this._adapter.setPopVisible(visible);
|
|
@@ -19,6 +25,48 @@ class DropdownFoundation extends _foundation.default {
|
|
|
19
25
|
this._adapter.notifyVisibleChange(visible);
|
|
20
26
|
}
|
|
21
27
|
|
|
28
|
+
getMenuItemNodes(target) {
|
|
29
|
+
var _context;
|
|
30
|
+
|
|
31
|
+
const id = target.attributes['data-popupid'].value;
|
|
32
|
+
const menuWrapper = document.getElementById(id); // if has dropdown item, the item must wrapped by li
|
|
33
|
+
|
|
34
|
+
return menuWrapper ? (0, _filter.default)(_context = (0, _from.default)(menuWrapper.getElementsByTagName('li'))).call(_context, item => item.ariaDisabled === "false") : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
setFocusToFirstMenuItem(target) {
|
|
38
|
+
const menuItemNodes = this.getMenuItemNodes(target);
|
|
39
|
+
menuItemNodes && (0, _a11y.setFocusToFirstItem)(menuItemNodes);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setFocusToLastMenuItem(target) {
|
|
43
|
+
const menuItemNodes = this.getMenuItemNodes(target);
|
|
44
|
+
menuItemNodes && (0, _a11y.setFocusToLastItem)(menuItemNodes);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
handleKeyDown(event) {
|
|
48
|
+
switch (event.key) {
|
|
49
|
+
case ' ':
|
|
50
|
+
case 'Enter':
|
|
51
|
+
event.target.click();
|
|
52
|
+
(0, _a11y.handlePrevent)(event);
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case 'ArrowDown':
|
|
56
|
+
this.setFocusToFirstMenuItem(event.target);
|
|
57
|
+
(0, _a11y.handlePrevent)(event);
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case 'ArrowUp':
|
|
61
|
+
this.setFocusToLastMenuItem(event.target);
|
|
62
|
+
(0, _a11y.handlePrevent)(event);
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
22
70
|
}
|
|
23
71
|
|
|
24
72
|
exports.default = DropdownFoundation;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
2
|
+
export default class DropdownMenuFoundation extends BaseFoundation<Partial<DefaultAdapter>> {
|
|
3
|
+
menuItemNodes: HTMLElement[];
|
|
4
|
+
firstChars: string[];
|
|
5
|
+
autoFocus(ulElement: any): void;
|
|
6
|
+
handleEscape(menu: Element): void;
|
|
7
|
+
setFocusByFirstCharacter(curItem: any, char: string): void;
|
|
8
|
+
onMenuKeydown(event: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
exports.default = void 0;
|
|
12
|
+
|
|
13
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
14
|
+
|
|
15
|
+
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
16
|
+
|
|
17
|
+
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
18
|
+
|
|
19
|
+
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
20
|
+
|
|
21
|
+
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
22
|
+
|
|
23
|
+
var _a11y = require("../utils/a11y");
|
|
24
|
+
|
|
25
|
+
class DropdownMenuFoundation extends _foundation.default {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.menuItemNodes = null;
|
|
29
|
+
this.firstChars = [];
|
|
30
|
+
} // if trigger is click, auto focus to the first menu item
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
autoFocus(ulElement) {
|
|
34
|
+
const trigger = this._adapter.getContext('trigger');
|
|
35
|
+
|
|
36
|
+
if (trigger === 'click') {
|
|
37
|
+
var _context;
|
|
38
|
+
|
|
39
|
+
// find all non-disabled li under this menu and set focus to the first menu
|
|
40
|
+
this.menuItemNodes = (0, _filter.default)(_context = [...ulElement.getElementsByTagName('li')]).call(_context, item => item.ariaDisabled !== "true");
|
|
41
|
+
(0, _a11y.setFocusToFirstItem)(this.menuItemNodes);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
handleEscape(menu) {
|
|
46
|
+
const trigger = this._adapter.getContext('trigger');
|
|
47
|
+
|
|
48
|
+
if (trigger === 'custom') {
|
|
49
|
+
const menuButton = menu && (0, _a11y.getMenuButton)(document.querySelectorAll("[data-popupid]"), menu.id);
|
|
50
|
+
menuButton.focus();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setFocusByFirstCharacter(curItem, char) {
|
|
55
|
+
const index = (0, _a11y.findIndexByCharacter)(this.menuItemNodes, curItem, this.firstChars, char);
|
|
56
|
+
|
|
57
|
+
if (index >= 0) {
|
|
58
|
+
(0, _a11y.setFocusToItem)(this.menuItemNodes, this.menuItemNodes[index]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onMenuKeydown(event) {
|
|
63
|
+
var _context5;
|
|
64
|
+
|
|
65
|
+
const menu = (0, _a11y.getAncestorNodeByRole)(event.target, 'tooltip');
|
|
66
|
+
|
|
67
|
+
if (!this.menuItemNodes) {
|
|
68
|
+
var _context2;
|
|
69
|
+
|
|
70
|
+
this.menuItemNodes = (0, _filter.default)(_context2 = [...event.target.parentNode.getElementsByTagName('li')]).call(_context2, item => item.ariaDisabled !== "true");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.firstChars.length === 0) {
|
|
74
|
+
var _context3;
|
|
75
|
+
|
|
76
|
+
(0, _forEach.default)(_context3 = this.menuItemNodes).call(_context3, item => {
|
|
77
|
+
var _context4;
|
|
78
|
+
|
|
79
|
+
this.firstChars.push((0, _trim.default)(_context4 = item.textContent).call(_context4)[0].toLowerCase());
|
|
80
|
+
});
|
|
81
|
+
} // get the currently focused menu item
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const curItem = (0, _find.default)(_context5 = this.menuItemNodes).call(_context5, item => item.tabIndex === 0);
|
|
85
|
+
|
|
86
|
+
switch (event.key) {
|
|
87
|
+
case ' ':
|
|
88
|
+
case 'Enter':
|
|
89
|
+
event.target.click();
|
|
90
|
+
(0, _a11y.handlePrevent)(event);
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case 'Escape':
|
|
94
|
+
this.handleEscape(menu);
|
|
95
|
+
break;
|
|
96
|
+
|
|
97
|
+
case 'ArrowUp':
|
|
98
|
+
(0, _a11y.setFocusToPreviousMenuItem)(this.menuItemNodes, curItem);
|
|
99
|
+
(0, _a11y.handlePrevent)(event);
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case 'ArrowDown':
|
|
103
|
+
(0, _a11y.setFocusToNextMenuitem)(this.menuItemNodes, curItem);
|
|
104
|
+
(0, _a11y.handlePrevent)(event);
|
|
105
|
+
break;
|
|
106
|
+
|
|
107
|
+
default:
|
|
108
|
+
if ((0, _a11y.isPrintableCharacter)(event.key)) {
|
|
109
|
+
this.setFocusByFirstCharacter(curItem, event.key);
|
|
110
|
+
(0, _a11y.handlePrevent)(event);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
exports.default = DropdownMenuFoundation;
|
package/lib/cjs/list/list.css
CHANGED
package/lib/cjs/list/list.scss
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
$color-list_default-border-default: var(--semi-color-border); // 列表描边颜色
|
|
2
2
|
$color-list_empty-text-default: var(--semi-color-text-2); // 空状态下列表文字颜色
|
|
3
3
|
|
|
4
|
-
$spacing-list_empty-
|
|
4
|
+
$spacing-list_empty-paddingX: 0px; // 空状态列表水平内边距
|
|
5
|
+
$spacing-list_empty-paddingY: $spacing-base-tight; // 空状态列表垂直内边距
|
|
5
6
|
$spacing-list_footer-paddingX: $spacing-base-tight; // 列表 footer 水平内边距
|
|
6
7
|
$spacing-list_footer-paddingY: $spacing-loose; // 列表 footer 垂直内边距
|
|
7
8
|
$spacing-list_item-paddingX: $spacing-base-tight; // 列表 item 水平内边距 - 默认尺寸
|
|
@@ -8,6 +8,7 @@ export interface RatingAdapter<P = Record<string, any>, S = Record<string, any>>
|
|
|
8
8
|
notifyFocus: (e: any) => void;
|
|
9
9
|
notifyBlur: (e: any) => void;
|
|
10
10
|
notifyKeyDown: (e: any) => void;
|
|
11
|
+
setEmptyStarFocusVisible: (focusVisible: boolean) => void;
|
|
11
12
|
}
|
|
12
13
|
export default class RatingFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<RatingAdapter<P, S>, P, S> {
|
|
13
14
|
constructor(adapter: RatingAdapter<P, S>);
|
|
@@ -25,4 +26,16 @@ export default class RatingFoundation<P = Record<string, any>, S = Record<string
|
|
|
25
26
|
handleFocus(e: any): void;
|
|
26
27
|
handleBlur(e: any): void;
|
|
27
28
|
handleKeyDown(event: any, value: number): void;
|
|
29
|
+
changeFocusStar(value: number, event: any): void;
|
|
30
|
+
handleStarFocusVisible: (event: any) => void;
|
|
31
|
+
handleStarBlur: (event: React.FocusEvent) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface RatingItemAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
34
|
+
setFirstStarFocus: (value: boolean) => void;
|
|
35
|
+
setSecondStarFocus: (value: boolean) => void;
|
|
36
|
+
}
|
|
37
|
+
export declare class RatingItemFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<RatingItemAdapter<P, S>, P, S> {
|
|
38
|
+
constructor(adapter: RatingItemAdapter<P, S>);
|
|
39
|
+
handleFocusVisible: (event: any, star: string) => void;
|
|
40
|
+
handleBlur: (event: React.FocusEvent, star: string) => void;
|
|
28
41
|
}
|
|
@@ -8,21 +8,49 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
exports.default = void 0;
|
|
11
|
+
exports.default = exports.RatingItemFoundation = void 0;
|
|
12
12
|
|
|
13
13
|
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
14
14
|
|
|
15
|
+
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
16
|
+
|
|
17
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
18
|
+
|
|
15
19
|
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
const KeyCode = {
|
|
19
|
-
LEFT: 37,
|
|
20
|
-
RIGHT: 39
|
|
21
|
-
};
|
|
21
|
+
var _warning = _interopRequireDefault(require("../utils/warning"));
|
|
22
22
|
|
|
23
|
+
/* eslint-disable no-param-reassign */
|
|
23
24
|
class RatingFoundation extends _foundation.default {
|
|
24
25
|
constructor(adapter) {
|
|
25
26
|
super((0, _assign.default)((0, _assign.default)({}, RatingFoundation.defaultAdapter), adapter));
|
|
27
|
+
|
|
28
|
+
this.handleStarFocusVisible = event => {
|
|
29
|
+
const {
|
|
30
|
+
target
|
|
31
|
+
} = event;
|
|
32
|
+
const {
|
|
33
|
+
count
|
|
34
|
+
} = this.getProps(); // when rating 0 is focus visible
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
if (target.matches(':focus-visible')) {
|
|
38
|
+
this._adapter.setEmptyStarFocusVisible(true);
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
(0, _warning.default)(true, 'Warning: [Semi Rating] The current browser does not support the focus-visible');
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
this.handleStarBlur = event => {
|
|
46
|
+
const {
|
|
47
|
+
emptyStarFocusVisible
|
|
48
|
+
} = this.getStates();
|
|
49
|
+
|
|
50
|
+
if (emptyStarFocusVisible) {
|
|
51
|
+
this._adapter.setEmptyStarFocusVisible(false);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
26
54
|
}
|
|
27
55
|
|
|
28
56
|
init() {
|
|
@@ -152,8 +180,10 @@ class RatingFoundation extends _foundation.default {
|
|
|
152
180
|
}
|
|
153
181
|
|
|
154
182
|
handleKeyDown(event, value) {
|
|
183
|
+
var _context;
|
|
184
|
+
|
|
155
185
|
const {
|
|
156
|
-
|
|
186
|
+
key
|
|
157
187
|
} = event;
|
|
158
188
|
const {
|
|
159
189
|
count,
|
|
@@ -163,40 +193,98 @@ class RatingFoundation extends _foundation.default {
|
|
|
163
193
|
const direction = this._adapter.getContext('direction');
|
|
164
194
|
|
|
165
195
|
const reverse = direction === 'rtl';
|
|
196
|
+
const step = allowHalf ? 0.5 : 1;
|
|
197
|
+
let tempValue;
|
|
198
|
+
let newValue;
|
|
199
|
+
|
|
200
|
+
if (key === 'ArrowRight' || key === 'ArrowUp') {
|
|
201
|
+
tempValue = value + (reverse ? -step : step);
|
|
202
|
+
} else if (key === 'ArrowLeft' || key === 'ArrowDown') {
|
|
203
|
+
tempValue = value + (reverse ? step : -step);
|
|
204
|
+
}
|
|
166
205
|
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} else if (keyCode === KeyCode.LEFT && value > 0 && !reverse) {
|
|
174
|
-
if (allowHalf) {
|
|
175
|
-
value -= 0.5;
|
|
176
|
-
} else {
|
|
177
|
-
value -= 1;
|
|
178
|
-
}
|
|
179
|
-
} else if (keyCode === KeyCode.RIGHT && value > 0 && reverse) {
|
|
180
|
-
if (allowHalf) {
|
|
181
|
-
value -= 0.5;
|
|
182
|
-
} else {
|
|
183
|
-
value -= 1;
|
|
184
|
-
}
|
|
185
|
-
} else if (keyCode === KeyCode.LEFT && value < count && reverse) {
|
|
186
|
-
if (allowHalf) {
|
|
187
|
-
value += 0.5;
|
|
188
|
-
} else {
|
|
189
|
-
value += 1;
|
|
190
|
-
}
|
|
206
|
+
if (tempValue > count) {
|
|
207
|
+
newValue = 0;
|
|
208
|
+
} else if (tempValue < 0) {
|
|
209
|
+
newValue = count;
|
|
210
|
+
} else {
|
|
211
|
+
newValue = tempValue;
|
|
191
212
|
}
|
|
192
213
|
|
|
193
|
-
|
|
214
|
+
if ((0, _includes.default)(_context = ['ArrowRight', 'ArrowUp', 'ArrowLeft', 'ArrowDown']).call(_context, key)) {
|
|
215
|
+
this._adapter.notifyKeyDown(event);
|
|
194
216
|
|
|
195
|
-
|
|
217
|
+
this._adapter.updateValue(newValue);
|
|
196
218
|
|
|
197
|
-
|
|
219
|
+
this.changeFocusStar(newValue, event);
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
|
|
222
|
+
this._adapter.notifyHoverChange(undefined, null);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
changeFocusStar(value, event) {
|
|
227
|
+
var _context2;
|
|
228
|
+
|
|
229
|
+
const {
|
|
230
|
+
count,
|
|
231
|
+
allowHalf,
|
|
232
|
+
preventScroll
|
|
233
|
+
} = this.getProps();
|
|
234
|
+
const index = Math.ceil(value) - 1;
|
|
235
|
+
const starElement = (0, _map.default)(_context2 = [...event.currentTarget.childNodes]).call(_context2, item => item.childNodes[0].childNodes);
|
|
236
|
+
|
|
237
|
+
if (index < 0) {
|
|
238
|
+
starElement[count][0].focus({
|
|
239
|
+
preventScroll
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
starElement[index][allowHalf ? value * 10 % 10 === 5 ? 0 : 1 : 0].focus({
|
|
243
|
+
preventScroll
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
exports.default = RatingFoundation;
|
|
251
|
+
|
|
252
|
+
class RatingItemFoundation extends _foundation.default {
|
|
253
|
+
constructor(adapter) {
|
|
254
|
+
super((0, _assign.default)((0, _assign.default)({}, RatingItemFoundation.defaultAdapter), adapter));
|
|
255
|
+
|
|
256
|
+
this.handleFocusVisible = (event, star) => {
|
|
257
|
+
const {
|
|
258
|
+
target
|
|
259
|
+
} = event; // when rating 0 is focus visible
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
if (target.matches(':focus-visible')) {
|
|
263
|
+
if (star === 'first') {
|
|
264
|
+
this._adapter.setFirstStarFocus(true);
|
|
265
|
+
} else {
|
|
266
|
+
this._adapter.setSecondStarFocus(true);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
(0, _warning.default)(true, 'Warning: [Semi Rating] The current browser does not support the focus-visible');
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
this.handleBlur = (event, star) => {
|
|
275
|
+
const {
|
|
276
|
+
firstStarFocus,
|
|
277
|
+
secondStarFocus
|
|
278
|
+
} = this.getStates();
|
|
279
|
+
|
|
280
|
+
if (star === 'first') {
|
|
281
|
+
firstStarFocus && this._adapter.setFirstStarFocus(false);
|
|
282
|
+
} else {
|
|
283
|
+
secondStarFocus && this._adapter.setSecondStarFocus(false);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
198
286
|
}
|
|
199
287
|
|
|
200
288
|
}
|
|
201
289
|
|
|
202
|
-
exports.
|
|
290
|
+
exports.RatingItemFoundation = RatingItemFoundation;
|
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
margin: 0px;
|
|
7
7
|
padding: 0px;
|
|
8
8
|
color: rgba(var(--semi-yellow-5), 1);
|
|
9
|
-
font-size: 20px;
|
|
10
|
-
line-height: unset;
|
|
11
9
|
list-style: none;
|
|
12
10
|
outline: none;
|
|
11
|
+
border-radius: 3px;
|
|
12
|
+
}
|
|
13
|
+
.semi-rating-focus {
|
|
14
|
+
outline: 2px solid var(--semi-color-primary-light-active);
|
|
15
|
+
}
|
|
16
|
+
.semi-rating-no-focus {
|
|
17
|
+
outline: none;
|
|
13
18
|
}
|
|
14
19
|
.semi-rating-disabled .semi-rating-star {
|
|
15
20
|
cursor: default;
|
|
@@ -29,12 +34,12 @@
|
|
|
29
34
|
.semi-rating-star:not(:last-child) {
|
|
30
35
|
margin-right: 6px;
|
|
31
36
|
}
|
|
32
|
-
.semi-rating-star > div:focus {
|
|
33
|
-
outline: 0;
|
|
34
|
-
}
|
|
35
37
|
.semi-rating-star > div:hover, .semi-rating-star > div:focus {
|
|
36
38
|
transform: scale(1.1);
|
|
37
39
|
}
|
|
40
|
+
.semi-rating-star > div.semi-rating-star-disabled {
|
|
41
|
+
transform: none;
|
|
42
|
+
}
|
|
38
43
|
.semi-rating-star-small {
|
|
39
44
|
width: 16px;
|
|
40
45
|
height: 16px;
|
|
@@ -47,6 +52,10 @@
|
|
|
47
52
|
}
|
|
48
53
|
.semi-rating-star-wrapper {
|
|
49
54
|
position: relative;
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
border-radius: 3px;
|
|
57
|
+
width: 100%;
|
|
58
|
+
height: 100%;
|
|
50
59
|
}
|
|
51
60
|
.semi-rating-star-first, .semi-rating-star-second {
|
|
52
61
|
color: var(--semi-color-fill-0);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@import
|
|
1
|
+
@import './variables.scss';
|
|
2
2
|
|
|
3
3
|
$module: #{$prefix}-rating;
|
|
4
4
|
|
|
@@ -7,10 +7,19 @@ $module: #{$prefix}-rating;
|
|
|
7
7
|
margin: $spacing-rating-margin;
|
|
8
8
|
padding: $spacing-rating-padding;
|
|
9
9
|
color: $color-rating-icon-default;
|
|
10
|
-
font-size: $font-rating-fontSize;
|
|
11
|
-
line-height: unset;
|
|
10
|
+
// font-size: $font-rating-fontSize;
|
|
11
|
+
// line-height: unset;
|
|
12
12
|
list-style: none;
|
|
13
13
|
outline: none;
|
|
14
|
+
border-radius: 3px;
|
|
15
|
+
|
|
16
|
+
&-focus {
|
|
17
|
+
outline: $width-rating-outline-focus solid $color-rating-outline-focus;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&-no-focus {
|
|
21
|
+
outline: none;
|
|
22
|
+
}
|
|
14
23
|
|
|
15
24
|
&-disabled &-star {
|
|
16
25
|
cursor: default;
|
|
@@ -34,14 +43,14 @@ $module: #{$prefix}-rating;
|
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
& > div {
|
|
37
|
-
&:focus {
|
|
38
|
-
outline: 0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
46
|
&:hover,
|
|
42
47
|
&:focus {
|
|
43
48
|
transform: scale(1.1);
|
|
44
49
|
}
|
|
50
|
+
|
|
51
|
+
&.#{$module}-star-disabled {
|
|
52
|
+
transform: none;
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
&-small {
|
|
@@ -58,6 +67,10 @@ $module: #{$prefix}-rating;
|
|
|
58
67
|
|
|
59
68
|
&-wrapper {
|
|
60
69
|
position: relative;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
border-radius: 3px;
|
|
72
|
+
width: 100%;
|
|
73
|
+
height: 100%;
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
&-first,
|
|
@@ -88,4 +101,4 @@ $module: #{$prefix}-rating;
|
|
|
88
101
|
}
|
|
89
102
|
}
|
|
90
103
|
|
|
91
|
-
@import
|
|
104
|
+
@import './rtl.scss';
|