@nutui/nutui-react 1.2.1-beta.0 → 1.2.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/CHANGELOG.md +24 -0
- package/dist/esm/ConfigProvider.js +11 -0
- package/dist/esm/DatePicker.js +148 -106
- package/dist/esm/Icon.js +4 -72
- package/dist/esm/NumberKeyboard/style/index.js +2 -0
- package/dist/esm/NumberKeyboard.js +277 -0
- package/dist/esm/Picker.js +294 -195
- package/dist/esm/Progress/style/index.js +2 -0
- package/dist/esm/Progress.js +130 -0
- package/dist/esm/Range.js +186 -129
- package/dist/esm/SearchBar/style/index.js +2 -0
- package/dist/esm/SearchBar.js +247 -0
- package/dist/esm/Signature.js +3 -0
- package/dist/esm/Tabbar.js +6 -3
- package/dist/esm/TabbarItem.js +14 -5
- package/dist/esm/Tag.js +18 -9
- package/dist/esm/icon-62bd7379.js +72 -0
- package/dist/esm/nutui-react.es.js +3 -0
- package/dist/esm/useTouch-a2ea68c6.js +119 -0
- package/dist/locales/base.d.ts +11 -0
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +12 -1
- package/dist/locales/id-ID.js +12 -1
- package/dist/locales/zh-CN.js +12 -1
- package/dist/locales/zh-TW.js +12 -1
- package/dist/nutui.react.es.js +1308 -590
- package/dist/nutui.react.umd.js +15 -15
- package/dist/packages/numberkeyboard/numberkeyboard.scss +106 -0
- package/dist/packages/picker/picker.scss +35 -16
- package/dist/packages/progress/progress.scss +81 -0
- package/dist/packages/range/range.scss +141 -13
- package/dist/packages/searchbar/searchbar.scss +106 -0
- package/dist/packages/signature/signature.scss +4 -4
- package/dist/packages/tabbar/tabbar.scss +10 -3
- package/dist/packages/tabbaritem/tabbaritem.scss +26 -8
- package/dist/style.css +1 -1
- package/dist/style.es.js +1 -1
- package/dist/styles/themes/default.scss +3 -0
- package/dist/styles/variables.scss +73 -6
- package/dist/types/datepicker/__test__/datepicker.spec.d.ts +1 -0
- package/dist/types/datepicker/datepicker.d.ts +16 -5
- package/dist/types/divider/__test__/divider.spec.d.ts +1 -0
- package/dist/types/navbar/__test__/navbar.spec.d.ts +1 -0
- package/dist/types/numberkeyboard/_test_/index.spec.d.ts +1 -0
- package/dist/types/numberkeyboard/demo.d.ts +3 -0
- package/dist/types/numberkeyboard/index.d.ts +2 -0
- package/dist/types/numberkeyboard/numberkeyboard.d.ts +20 -0
- package/dist/types/nutui.react.d.ts +4 -1
- package/dist/types/picker/picker.d.ts +17 -13
- package/dist/types/picker/pickerSlot.d.ts +4 -3
- package/dist/types/progress/__tests__/progress.spec.d.ts +1 -0
- package/dist/types/progress/demo.d.ts +3 -0
- package/dist/types/progress/index.d.ts +2 -0
- package/dist/types/progress/progress.d.ts +26 -0
- package/dist/types/range/demo.d.ts +1 -0
- package/dist/types/range/range.d.ts +3 -1
- package/dist/types/searchbar/demo.d.ts +3 -0
- package/dist/types/searchbar/index.d.ts +2 -0
- package/dist/types/searchbar/searchbar.d.ts +60 -0
- package/dist/types/signature/__test__/signature.spec.d.ts +2 -0
- package/dist/types/tabbar/__tests__/tabbar.spec.d.ts +1 -0
- package/dist/types/tabbar/tabbar.d.ts +2 -2
- package/dist/types/tabbaritem/tabbaritem.d.ts +4 -1
- package/dist/types/tag/tag.d.ts +1 -1
- package/package.json +3 -2
- package/dist/packages/range/custom.scss +0 -9
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["className", "style", "isShowPercentage", "percentage", "fillColor", "strokeColor", "strokeWidth", "size", "textColor", "textWidth", "showText", "textInside", "textBackground", "textType", "status", "iconName", "iconColor", "iconSize", "rounded", "children"];
|
|
4
|
+
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
+
|
|
9
|
+
import React__default from 'react';
|
|
10
|
+
import classNames from 'classnames';
|
|
11
|
+
import { I as Icon } from './icon-62bd7379.js';
|
|
12
|
+
import { c as cn } from './bem-893ad28d.js';
|
|
13
|
+
import '@bem-react/classname';
|
|
14
|
+
var defaultProps = {
|
|
15
|
+
className: '',
|
|
16
|
+
style: {},
|
|
17
|
+
isShowPercentage: true,
|
|
18
|
+
percentage: 0,
|
|
19
|
+
fillColor: '#f3f3f3',
|
|
20
|
+
strokeColor: 'linear-gradient(135deg, #fa2c19 0%, #fa6419 100%)',
|
|
21
|
+
strokeWidth: '',
|
|
22
|
+
textColor: '',
|
|
23
|
+
textWidth: '',
|
|
24
|
+
showText: true,
|
|
25
|
+
textInside: false,
|
|
26
|
+
textBackground: 'linear-gradient(135deg, #fa2c19 0%, #fa6419 100%)',
|
|
27
|
+
textType: 'text',
|
|
28
|
+
status: false,
|
|
29
|
+
iconName: 'checked',
|
|
30
|
+
iconColor: '#439422',
|
|
31
|
+
iconSize: '16px',
|
|
32
|
+
rounded: true,
|
|
33
|
+
children: undefined
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var Progress = function Progress(props) {
|
|
37
|
+
var _classNames, _classNames2, _classNames4;
|
|
38
|
+
|
|
39
|
+
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
40
|
+
className = _defaultProps$props.className,
|
|
41
|
+
style = _defaultProps$props.style,
|
|
42
|
+
isShowPercentage = _defaultProps$props.isShowPercentage,
|
|
43
|
+
percentage = _defaultProps$props.percentage,
|
|
44
|
+
fillColor = _defaultProps$props.fillColor,
|
|
45
|
+
strokeColor = _defaultProps$props.strokeColor,
|
|
46
|
+
strokeWidth = _defaultProps$props.strokeWidth,
|
|
47
|
+
size = _defaultProps$props.size,
|
|
48
|
+
textColor = _defaultProps$props.textColor,
|
|
49
|
+
textWidth = _defaultProps$props.textWidth,
|
|
50
|
+
showText = _defaultProps$props.showText,
|
|
51
|
+
textInside = _defaultProps$props.textInside,
|
|
52
|
+
textBackground = _defaultProps$props.textBackground,
|
|
53
|
+
textType = _defaultProps$props.textType,
|
|
54
|
+
status = _defaultProps$props.status,
|
|
55
|
+
iconName = _defaultProps$props.iconName,
|
|
56
|
+
iconColor = _defaultProps$props.iconColor,
|
|
57
|
+
iconSize = _defaultProps$props.iconSize,
|
|
58
|
+
rounded = _defaultProps$props.rounded,
|
|
59
|
+
children = _defaultProps$props.children,
|
|
60
|
+
rest = _objectWithoutProperties(_defaultProps$props, _excluded);
|
|
61
|
+
|
|
62
|
+
var b = cn('progress');
|
|
63
|
+
var classes = classNames(b(''));
|
|
64
|
+
var classesOuter = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(b(''), "-outer"), true), _defineProperty(_classNames, "".concat(b(''), "-").concat(size || 'base'), true), _classNames));
|
|
65
|
+
var classesInner = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(b(''), "-inner"), true), _defineProperty(_classNames2, "".concat(b(''), "-active"), status), _classNames2));
|
|
66
|
+
var classesText = classNames(_defineProperty({}, "".concat(b(''), "-text"), true));
|
|
67
|
+
var classesInsideText = classNames((_classNames4 = {}, _defineProperty(_classNames4, "".concat(b(''), "-text"), true), _defineProperty(_classNames4, "".concat(b(''), "-insidetext"), true), _classNames4));
|
|
68
|
+
var classesTextInner = classNames(_defineProperty({}, "".concat(b(''), "-text__inner"), true));
|
|
69
|
+
var stylesOuter = {
|
|
70
|
+
height: "".concat(strokeWidth, "px"),
|
|
71
|
+
// eslint-disable-next-line no-nested-ternary
|
|
72
|
+
borderRadius: "".concat(rounded ? rounded === true ? '12px' : rounded : 0),
|
|
73
|
+
background: "".concat(fillColor)
|
|
74
|
+
};
|
|
75
|
+
var stylesInner = {
|
|
76
|
+
width: "".concat(percentage, "%"),
|
|
77
|
+
// eslint-disable-next-line no-nested-ternary
|
|
78
|
+
borderRadius: "".concat(rounded ? rounded === true ? '12px' : rounded : 0),
|
|
79
|
+
background: "".concat(strokeColor)
|
|
80
|
+
};
|
|
81
|
+
var stylesInsideText = {
|
|
82
|
+
width: "".concat(textWidth, "px"),
|
|
83
|
+
left: "".concat(percentage, "%"),
|
|
84
|
+
background: textBackground || strokeColor
|
|
85
|
+
};
|
|
86
|
+
var stylesInsideIcon = {
|
|
87
|
+
width: "".concat(textWidth, "px"),
|
|
88
|
+
left: "".concat(percentage, "%")
|
|
89
|
+
};
|
|
90
|
+
var stylesText = {
|
|
91
|
+
width: "".concat(textWidth, "px")
|
|
92
|
+
};
|
|
93
|
+
return React__default.createElement("div", _objectSpread({
|
|
94
|
+
className: "".concat(classes, " ").concat(className),
|
|
95
|
+
style: style
|
|
96
|
+
}, rest), React__default.createElement("div", {
|
|
97
|
+
className: classesOuter,
|
|
98
|
+
style: stylesOuter
|
|
99
|
+
}, React__default.createElement("div", {
|
|
100
|
+
className: classesInner,
|
|
101
|
+
style: stylesInner
|
|
102
|
+
}, showText && textInside && React__default.createElement(React__default.Fragment, null, children ? React__default.createElement("div", {
|
|
103
|
+
className: classesInsideText,
|
|
104
|
+
style: stylesInsideIcon
|
|
105
|
+
}, children) : React__default.createElement("div", {
|
|
106
|
+
className: classesInsideText,
|
|
107
|
+
style: stylesInsideText
|
|
108
|
+
}, React__default.createElement("span", {
|
|
109
|
+
className: classesTextInner,
|
|
110
|
+
style: {
|
|
111
|
+
color: textColor || '#fff'
|
|
112
|
+
}
|
|
113
|
+
}, percentage, isShowPercentage ? '%' : ''))))), showText && !textInside && React__default.createElement("div", {
|
|
114
|
+
className: classesText,
|
|
115
|
+
style: stylesText
|
|
116
|
+
}, textType === 'text' && React__default.createElement("span", {
|
|
117
|
+
className: classesTextInner,
|
|
118
|
+
style: {
|
|
119
|
+
color: textColor || '#333'
|
|
120
|
+
}
|
|
121
|
+
}, percentage, isShowPercentage ? '%' : ''), textType === 'icon' && React__default.createElement(Icon, {
|
|
122
|
+
size: iconSize,
|
|
123
|
+
name: iconName,
|
|
124
|
+
color: iconColor
|
|
125
|
+
})));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
Progress.defaultProps = defaultProps;
|
|
129
|
+
Progress.displayName = 'NutProgress';
|
|
130
|
+
export { Progress as default };
|
package/dist/esm/Range.js
CHANGED
|
@@ -1,116 +1,14 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
|
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
7
|
|
|
8
|
-
import React__default, { useState, useRef, useEffect } from 'react';
|
|
9
|
-
import {
|
|
8
|
+
import React__default, { useState, useRef, useEffect, useCallback } from 'react';
|
|
9
|
+
import { u as useTouch } from './useTouch-a2ea68c6.js';
|
|
10
10
|
import Toast from './Toast.js';
|
|
11
11
|
import { useConfig } from './ConfigProvider.js';
|
|
12
|
-
import '@bem-react/classname';
|
|
13
|
-
var MIN_DISTANCE = 10;
|
|
14
|
-
|
|
15
|
-
function getDirection(x, y) {
|
|
16
|
-
if (x > y && x > MIN_DISTANCE) {
|
|
17
|
-
return 'horizontal';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (y > x && y > MIN_DISTANCE) {
|
|
21
|
-
return 'vertical';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function useTouch() {
|
|
28
|
-
var _useState = useState(0),
|
|
29
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
-
startX = _useState2[0],
|
|
31
|
-
SetStartX = _useState2[1];
|
|
32
|
-
|
|
33
|
-
var _useState3 = useState(0),
|
|
34
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
-
startY = _useState4[0],
|
|
36
|
-
SetStartY = _useState4[1];
|
|
37
|
-
|
|
38
|
-
var _useState5 = useState(0),
|
|
39
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
40
|
-
deltaX = _useState6[0],
|
|
41
|
-
SetDeltaX = _useState6[1];
|
|
42
|
-
|
|
43
|
-
var _useState7 = useState(0),
|
|
44
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
45
|
-
deltaY = _useState8[0],
|
|
46
|
-
SetDeltaY = _useState8[1];
|
|
47
|
-
|
|
48
|
-
var _useState9 = useState(0),
|
|
49
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
50
|
-
offsetX = _useState10[0],
|
|
51
|
-
SetOffsetX = _useState10[1];
|
|
52
|
-
|
|
53
|
-
var _useState11 = useState(0),
|
|
54
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
55
|
-
offsetY = _useState12[0],
|
|
56
|
-
SetOffsetY = _useState12[1];
|
|
57
|
-
|
|
58
|
-
var _useState13 = useState(''),
|
|
59
|
-
_useState14 = _slicedToArray(_useState13, 2),
|
|
60
|
-
direction = _useState14[0],
|
|
61
|
-
SetDirection = _useState14[1];
|
|
62
|
-
|
|
63
|
-
var isVertical = function isVertical() {
|
|
64
|
-
return direction === 'vertical';
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
var isHorizontal = function isHorizontal() {
|
|
68
|
-
return direction === 'horizontal';
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
var reset = function reset() {
|
|
72
|
-
SetDeltaX(0);
|
|
73
|
-
SetDeltaY(0);
|
|
74
|
-
SetOffsetX(0);
|
|
75
|
-
SetOffsetY(0);
|
|
76
|
-
SetDirection('');
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
var start = function start(event) {
|
|
80
|
-
reset();
|
|
81
|
-
SetStartX(event.touches[0].clientX);
|
|
82
|
-
SetStartY(event.touches[0].clientY);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var move = function move(event) {
|
|
86
|
-
var touch = event.touches[0];
|
|
87
|
-
var dX = touch.clientX - startX;
|
|
88
|
-
var dY = touch.clientY - startY;
|
|
89
|
-
SetDeltaX(dX);
|
|
90
|
-
SetDeltaY(dY);
|
|
91
|
-
SetOffsetX(Math.abs(dX));
|
|
92
|
-
SetOffsetY(Math.abs(dY));
|
|
93
|
-
|
|
94
|
-
if (!direction) {
|
|
95
|
-
SetDirection(getDirection(Math.abs(dX), Math.abs(dY)));
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
move: move,
|
|
101
|
-
start: start,
|
|
102
|
-
reset: reset,
|
|
103
|
-
startX: startX,
|
|
104
|
-
startY: startY,
|
|
105
|
-
deltaX: deltaX,
|
|
106
|
-
deltaY: deltaY,
|
|
107
|
-
offsetX: offsetX,
|
|
108
|
-
offsetY: offsetY,
|
|
109
|
-
direction: direction,
|
|
110
|
-
isVertical: isVertical,
|
|
111
|
-
isHorizontal: isHorizontal
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
12
|
/**
|
|
115
13
|
获取元素的大小及其相对于视口的位置,等价于 Element.getBoundingClientRect。
|
|
116
14
|
width 宽度 number
|
|
@@ -121,12 +19,11 @@ function useTouch() {
|
|
|
121
19
|
bottom 底部与视图窗口左上角的距离 number
|
|
122
20
|
*/
|
|
123
21
|
|
|
124
|
-
|
|
125
22
|
function isWindow(val) {
|
|
126
23
|
return val === window;
|
|
127
24
|
}
|
|
128
25
|
|
|
129
|
-
var
|
|
26
|
+
var getRect = function getRect(elementRef) {
|
|
130
27
|
var element = elementRef;
|
|
131
28
|
|
|
132
29
|
if (isWindow(element)) {
|
|
@@ -163,7 +60,9 @@ var defaultProps = {
|
|
|
163
60
|
min: 0,
|
|
164
61
|
max: 100,
|
|
165
62
|
step: 1,
|
|
166
|
-
modelValue: 0
|
|
63
|
+
modelValue: 0,
|
|
64
|
+
vertical: false,
|
|
65
|
+
marks: {}
|
|
167
66
|
};
|
|
168
67
|
var startValue;
|
|
169
68
|
var currentValue;
|
|
@@ -186,28 +85,35 @@ var Range = function Range(props) {
|
|
|
186
85
|
step = _defaultProps$props.step,
|
|
187
86
|
modelValue = _defaultProps$props.modelValue,
|
|
188
87
|
button = _defaultProps$props.button,
|
|
88
|
+
vertical = _defaultProps$props.vertical,
|
|
89
|
+
marks = _defaultProps$props.marks,
|
|
189
90
|
change = _defaultProps$props.change,
|
|
190
91
|
dragStart = _defaultProps$props.dragStart,
|
|
191
92
|
dragEnd = _defaultProps$props.dragEnd;
|
|
192
93
|
|
|
193
|
-
var
|
|
194
|
-
|
|
195
|
-
buttonIndex =
|
|
196
|
-
SetButtonIndex =
|
|
94
|
+
var _useState = useState(0),
|
|
95
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
96
|
+
buttonIndex = _useState2[0],
|
|
97
|
+
SetButtonIndex = _useState2[1];
|
|
197
98
|
|
|
198
|
-
var
|
|
199
|
-
|
|
200
|
-
initValue =
|
|
201
|
-
SetInitValue =
|
|
99
|
+
var _useState3 = useState(),
|
|
100
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
101
|
+
initValue = _useState4[0],
|
|
102
|
+
SetInitValue = _useState4[1];
|
|
202
103
|
|
|
203
|
-
var
|
|
204
|
-
|
|
205
|
-
dragStatus =
|
|
206
|
-
SetDragStatus =
|
|
104
|
+
var _useState5 = useState('start'),
|
|
105
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
106
|
+
dragStatus = _useState6[0],
|
|
107
|
+
SetDragStatus = _useState6[1];
|
|
207
108
|
|
|
208
109
|
var touch = useTouch();
|
|
209
110
|
var root = useRef(null);
|
|
210
|
-
|
|
111
|
+
|
|
112
|
+
var _useState7 = useState([]),
|
|
113
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
114
|
+
marksList = _useState8[0],
|
|
115
|
+
SetMarksList = _useState8[1];
|
|
116
|
+
|
|
211
117
|
useEffect(function () {
|
|
212
118
|
if (modelValue) {
|
|
213
119
|
if (!range && (modelValue < min || modelValue > max)) {
|
|
@@ -219,11 +125,65 @@ var Range = function Range(props) {
|
|
|
219
125
|
SetInitValue(modelValue);
|
|
220
126
|
}
|
|
221
127
|
}, [modelValue]);
|
|
128
|
+
useEffect(function () {
|
|
129
|
+
if (marks) {
|
|
130
|
+
var marksKeys = Object.keys(marks);
|
|
131
|
+
var list = marksKeys.map(parseFloat).sort(function (a, b) {
|
|
132
|
+
return a - b;
|
|
133
|
+
}).filter(function (point) {
|
|
134
|
+
return point >= min && point <= max;
|
|
135
|
+
});
|
|
136
|
+
SetMarksList(list);
|
|
137
|
+
}
|
|
138
|
+
}, [marks]);
|
|
222
139
|
|
|
223
140
|
var scope = function scope() {
|
|
224
141
|
return Number(max) - Number(min);
|
|
225
142
|
};
|
|
226
143
|
|
|
144
|
+
var classes = useCallback(function () {
|
|
145
|
+
var prefixCls = 'nut-range';
|
|
146
|
+
return [prefixCls, "".concat(disabled ? "".concat(prefixCls, "-disabled") : ''), "".concat(vertical ? "".concat(prefixCls, "-vertical") : ''), "".concat(!hiddenRange ? "".concat(prefixCls, "-show-number") : '')].filter(Boolean).join(' ');
|
|
147
|
+
}, [disabled, vertical, hiddenRange]);
|
|
148
|
+
var containerClasses = useCallback(function () {
|
|
149
|
+
var prefixCls = 'nut-range-container';
|
|
150
|
+
return [prefixCls, "".concat(vertical ? "".concat(prefixCls, "-vertical") : ''), className].filter(Boolean).join(' ');
|
|
151
|
+
}, [vertical, className]);
|
|
152
|
+
var markClassName = useCallback(function (mark) {
|
|
153
|
+
var classPrefix = 'nut-range-mark';
|
|
154
|
+
var lowerBound = Number(min);
|
|
155
|
+
var upperBound = Number(max);
|
|
156
|
+
|
|
157
|
+
if (range) {
|
|
158
|
+
var _modelValue = _slicedToArray(modelValue, 2),
|
|
159
|
+
left = _modelValue[0],
|
|
160
|
+
right = _modelValue[1];
|
|
161
|
+
|
|
162
|
+
lowerBound = left;
|
|
163
|
+
upperBound = right;
|
|
164
|
+
} else {
|
|
165
|
+
upperBound = modelValue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var isActive = mark <= upperBound && mark >= lowerBound;
|
|
169
|
+
return ["".concat(classPrefix, "-text"), "".concat(isActive ? "".concat(classPrefix, "-text-active") : '')].filter(Boolean).join(' ');
|
|
170
|
+
}, [range, modelValue, min, max]);
|
|
171
|
+
|
|
172
|
+
var _useState9 = useState(classes()),
|
|
173
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
174
|
+
rangeName = _useState10[0],
|
|
175
|
+
setRangeName = _useState10[1];
|
|
176
|
+
|
|
177
|
+
var _useState11 = useState(containerClasses()),
|
|
178
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
179
|
+
containerName = _useState12[0],
|
|
180
|
+
setContainerName = _useState12[1];
|
|
181
|
+
|
|
182
|
+
useEffect(function () {
|
|
183
|
+
setRangeName(classes());
|
|
184
|
+
setContainerName(containerClasses());
|
|
185
|
+
}, [classes, containerClasses]);
|
|
186
|
+
|
|
227
187
|
var wrapperStyle = function wrapperStyle() {
|
|
228
188
|
return {
|
|
229
189
|
background: inactiveColor
|
|
@@ -261,6 +221,15 @@ var Range = function Range(props) {
|
|
|
261
221
|
};
|
|
262
222
|
|
|
263
223
|
var barStyle = function barStyle() {
|
|
224
|
+
if (vertical) {
|
|
225
|
+
return {
|
|
226
|
+
height: calcMainAxis(),
|
|
227
|
+
top: calcOffset(),
|
|
228
|
+
background: activeColor,
|
|
229
|
+
transition: dragStatus ? 'none' : undefined
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
264
233
|
return {
|
|
265
234
|
width: calcMainAxis(),
|
|
266
235
|
left: calcOffset(),
|
|
@@ -269,6 +238,40 @@ var Range = function Range(props) {
|
|
|
269
238
|
};
|
|
270
239
|
};
|
|
271
240
|
|
|
241
|
+
var marksStyle = function marksStyle(mark) {
|
|
242
|
+
var style = {
|
|
243
|
+
left: "".concat((mark - Number(min)) / scope() * 100, "%")
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
if (vertical) {
|
|
247
|
+
style = {
|
|
248
|
+
top: "".concat((mark - Number(min)) / scope() * 100, "%")
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return style;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
var tickStyle = function tickStyle(mark) {
|
|
256
|
+
var lowerBound = Number(min);
|
|
257
|
+
var upperBound = Number(max);
|
|
258
|
+
|
|
259
|
+
if (range) {
|
|
260
|
+
var _modelValue2 = _slicedToArray(modelValue, 2),
|
|
261
|
+
left = _modelValue2[0],
|
|
262
|
+
right = _modelValue2[1];
|
|
263
|
+
|
|
264
|
+
lowerBound = left;
|
|
265
|
+
upperBound = right;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var isActive = mark <= upperBound && mark >= lowerBound;
|
|
269
|
+
var style = {
|
|
270
|
+
background: !isActive ? inactiveColor : activeColor
|
|
271
|
+
};
|
|
272
|
+
return style;
|
|
273
|
+
};
|
|
274
|
+
|
|
272
275
|
var format = function format(value) {
|
|
273
276
|
value = Math.max(+min, Math.min(value, +max));
|
|
274
277
|
return Math.round(value / +step) * +step;
|
|
@@ -299,11 +302,47 @@ var Range = function Range(props) {
|
|
|
299
302
|
SetInitValue(value);
|
|
300
303
|
}
|
|
301
304
|
|
|
302
|
-
if (end && !isSameValue(value, startValue)) {
|
|
305
|
+
if ((marks || end) && !isSameValue(value, startValue)) {
|
|
303
306
|
change && change(value);
|
|
304
307
|
}
|
|
305
308
|
};
|
|
306
309
|
|
|
310
|
+
var click = function click(event) {
|
|
311
|
+
if (disabled || !root.current) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
SetDragStatus('');
|
|
316
|
+
var rect = getRect(root.current);
|
|
317
|
+
var delta = event.clientX - rect.left;
|
|
318
|
+
var total = rect.width;
|
|
319
|
+
|
|
320
|
+
if (vertical) {
|
|
321
|
+
delta = event.clientY - rect.top;
|
|
322
|
+
total = rect.height;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
var value = Number(min) + delta / total * scope();
|
|
326
|
+
currentValue = initValue || initValue === 0 ? initValue : modelValue;
|
|
327
|
+
|
|
328
|
+
if (isRange(currentValue)) {
|
|
329
|
+
var _currentValue = currentValue,
|
|
330
|
+
_currentValue2 = _slicedToArray(_currentValue, 2),
|
|
331
|
+
left = _currentValue2[0],
|
|
332
|
+
right = _currentValue2[1];
|
|
333
|
+
|
|
334
|
+
var middle = (left + right) / 2;
|
|
335
|
+
|
|
336
|
+
if (value <= middle) {
|
|
337
|
+
updateValue([value, right], true);
|
|
338
|
+
} else {
|
|
339
|
+
updateValue([left, value], true);
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
updateValue(value, true);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
307
346
|
var _onTouchStart = function onTouchStart(event) {
|
|
308
347
|
if (disabled) {
|
|
309
348
|
return;
|
|
@@ -332,11 +371,17 @@ var Range = function Range(props) {
|
|
|
332
371
|
|
|
333
372
|
touch.move(event);
|
|
334
373
|
SetDragStatus('draging');
|
|
335
|
-
var rect =
|
|
374
|
+
var rect = getRect(root.current);
|
|
336
375
|
var delta = touch.deltaX;
|
|
337
376
|
var total = rect.width;
|
|
338
377
|
var diff = delta / total * scope();
|
|
339
378
|
|
|
379
|
+
if (vertical) {
|
|
380
|
+
delta = touch.deltaY;
|
|
381
|
+
total = rect.height;
|
|
382
|
+
diff = delta / total * scope();
|
|
383
|
+
}
|
|
384
|
+
|
|
340
385
|
if (isRange(startValue)) {
|
|
341
386
|
currentValue[buttonIndex] = startValue[buttonIndex] + diff;
|
|
342
387
|
} else {
|
|
@@ -366,29 +411,41 @@ var Range = function Range(props) {
|
|
|
366
411
|
};
|
|
367
412
|
|
|
368
413
|
return React__default.createElement("div", {
|
|
369
|
-
className: "
|
|
414
|
+
className: "".concat(containerName)
|
|
370
415
|
}, !hiddenRange ? React__default.createElement("div", {
|
|
371
416
|
className: "min"
|
|
372
417
|
}, +min) : null, React__default.createElement("div", {
|
|
373
418
|
ref: root,
|
|
374
419
|
style: wrapperStyle(),
|
|
375
|
-
className: "".concat(
|
|
376
|
-
|
|
420
|
+
className: "".concat(rangeName),
|
|
421
|
+
onClick: function onClick(e) {
|
|
422
|
+
click(e);
|
|
423
|
+
}
|
|
424
|
+
}, marksList.length > 0 ? React__default.createElement("div", {
|
|
425
|
+
className: "nut-range-mark"
|
|
426
|
+
}, marksList.map(function (marks) {
|
|
427
|
+
return React__default.createElement("span", {
|
|
428
|
+
key: marks,
|
|
429
|
+
className: markClassName(marks),
|
|
430
|
+
style: marksStyle(marks)
|
|
431
|
+
}, marks, React__default.createElement("span", {
|
|
432
|
+
className: "nut-range-tick",
|
|
433
|
+
style: tickStyle(marks)
|
|
434
|
+
}));
|
|
435
|
+
})) : null, React__default.createElement("div", {
|
|
377
436
|
className: "nut-range-bar",
|
|
378
437
|
style: barStyle()
|
|
379
438
|
}, range ? [0, 1].map(function (item, index) {
|
|
380
439
|
return React__default.createElement("div", {
|
|
381
440
|
role: "slider",
|
|
382
441
|
key: index,
|
|
383
|
-
className: "".concat(index
|
|
442
|
+
className: "".concat(index === 0 ? 'nut-range-button-wrapper-left' : '', "\n ").concat(index === 1 ? 'nut-range-button-wrapper-right' : ''),
|
|
384
443
|
tabIndex: disabled ? -1 : 0,
|
|
385
444
|
"aria-valuemin": +min,
|
|
386
445
|
"aria-valuenow": curValue(index),
|
|
387
446
|
"aria-valuemax": +max,
|
|
388
447
|
"aria-orientation": "horizontal",
|
|
389
448
|
onTouchStart: function onTouchStart(e) {
|
|
390
|
-
e.preventDefault;
|
|
391
|
-
|
|
392
449
|
if (typeof index === 'number') {
|
|
393
450
|
// 实时更新当前拖动的按钮索引
|
|
394
451
|
SetButtonIndex(index);
|