@hi-ui/hiui 2.15.11 → 2.15.12
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/es/_util/SwitchVersion.js +40 -0
- package/es/_util/depreactedPropsCompat.js +58 -0
- package/es/_util/index.js +31 -0
- package/es/_util/warning.js +2 -2
- package/es/alert/Alert.js +126 -0
- package/es/alert/__tests__/index.test.js +84 -0
- package/es/alert/index.js +6 -147
- package/es/alert/style/index.css +1 -1
- package/es/badge/Badge.js +82 -0
- package/es/badge/__tests__/index.test.js +82 -0
- package/es/badge/index.js +9 -87
- package/es/badge/style/index.css +1 -1
- package/es/badge/style/index.js +0 -0
- package/es/breadcrumb/__tests__/index.test.js +61 -0
- package/es/breadcrumb/index.js +85 -0
- package/es/breadcrumb/style/index.css +1 -0
- package/es/button/Button.js +62 -60
- package/es/button/ButtonGroup.js +24 -40
- package/es/button/IconLoading.js +6 -6
- package/es/button/__tests__/index.test.js +221 -0
- package/es/button/index.js +3 -2
- package/es/button/style/index.css +1 -1
- package/es/card/__tests__/index.test.js +179 -0
- package/es/card/index.js +61 -57
- package/es/card/style/index.css +1 -1
- package/es/carousel/__tests__/index.test.js +104 -0
- package/es/carousel/index.js +219 -0
- package/es/carousel/style/index.css +1 -0
- package/es/carousel/style/index.js +3 -0
- package/es/cascader/Cascader.js +190 -133
- package/es/cascader/Menu.js +168 -0
- package/es/cascader/__tests__/index.test.js +392 -0
- package/es/cascader/index.js +5 -2
- package/es/cascader/style/cascader.css +1 -1
- package/es/cascader/style/menu.css +1 -1
- package/es/checkbox/Checkbox.js +136 -0
- package/es/checkbox/Group.js +194 -0
- package/es/checkbox/__tests__/index.test.js +226 -0
- package/es/checkbox/checkbox-legacy/Base.js +212 -0
- package/es/checkbox/checkbox-legacy/CheckBox.js +157 -0
- package/es/checkbox/checkbox-legacy/index.js +15 -0
- package/es/checkbox/checkbox-legacy/style/index.css +1 -0
- package/es/checkbox/checkbox-legacy/style/index.js +3 -0
- package/es/checkbox/index.js +13 -4
- package/es/checkbox/style/index.css +1 -1
- package/es/collapse/__tests__/index.test.js +111 -0
- package/es/collapse/index.js +88 -110
- package/es/collapse/style/index.css +1 -1
- package/es/confirm/index.js +39 -60
- package/es/context/index.js +45 -51
- package/es/counter/Counter.js +339 -0
- package/es/counter/__tests__/index.test.js +134 -0
- package/es/counter/counter-legacy/index.js +267 -0
- package/es/counter/index.js +6 -270
- package/es/counter/style/index.css +1 -1
- package/es/date-picker/BasePicker.js +380 -302
- package/es/date-picker/Calender.js +326 -98
- package/es/date-picker/DatePanel.js +194 -213
- package/es/date-picker/DatePicker.js +143 -47
- package/es/date-picker/DateRangePanel.js +272 -208
- package/es/date-picker/Modal.js +18 -32
- package/es/date-picker/Time.js +231 -345
- package/es/date-picker/TimeList.js +246 -0
- package/es/date-picker/TimePanel.js +28 -41
- package/es/date-picker/TimePeriodPanel.js +27 -46
- package/es/date-picker/TimePicker.js +44 -46
- package/es/date-picker/TimeRangePanel.js +33 -51
- package/es/date-picker/Type.js +5 -1
- package/es/date-picker/WeekRangePanel.js +254 -175
- package/es/date-picker/YMRangePanel.js +364 -0
- package/es/date-picker/__tests__/index.test.js +956 -0
- package/es/date-picker/constants.js +14 -28
- package/es/date-picker/dateUtil.js +221 -52
- package/es/date-picker/datepicker-legacy/BasePicker.js +511 -0
- package/es/date-picker/datepicker-legacy/Calender.js +422 -0
- package/es/date-picker/datepicker-legacy/DatePanel.js +455 -0
- package/es/date-picker/datepicker-legacy/DatePicker.js +103 -0
- package/es/date-picker/datepicker-legacy/DateRangePanel.js +488 -0
- package/es/date-picker/datepicker-legacy/Modal.js +67 -0
- package/es/date-picker/datepicker-legacy/Time.js +405 -0
- package/es/date-picker/datepicker-legacy/TimePanel.js +85 -0
- package/es/date-picker/datepicker-legacy/TimePeriodPanel.js +118 -0
- package/es/date-picker/datepicker-legacy/TimePicker.js +78 -0
- package/es/date-picker/datepicker-legacy/TimeRangePanel.js +90 -0
- package/es/date-picker/datepicker-legacy/Type.js +31 -0
- package/es/date-picker/datepicker-legacy/WeekRangePanel.js +337 -0
- package/es/date-picker/datepicker-legacy/constants.js +79 -0
- package/es/date-picker/datepicker-legacy/dateUtil.js +258 -0
- package/es/date-picker/datepicker-legacy/index.js +15 -0
- package/es/date-picker/datepicker-legacy/local.js +11 -0
- package/es/date-picker/datepicker-legacy/style/index.css +1 -0
- package/es/date-picker/datepicker-legacy/style/index.js +3 -0
- package/es/date-picker/datepicker-legacy/style/timepicker.css +1 -0
- package/es/date-picker/datepicker-legacy/util.js +60 -0
- package/es/date-picker/index.js +5 -2
- package/es/date-picker/style/index.css +1 -1
- package/es/date-picker/toLunar.js +172 -0
- package/es/date-picker/util.js +101 -8
- package/es/dropdown/Dropdown.js +191 -203
- package/es/dropdown/DropdownButton.js +102 -0
- package/es/dropdown/DropdownMenu.js +107 -0
- package/es/dropdown/DropdownMenuItem.js +172 -0
- package/es/dropdown/__tests__/index.test.js +313 -0
- package/es/dropdown/index.js +69 -4
- package/es/dropdown/style/index.css +1 -1
- package/es/dropdown/style/index.js +0 -2
- package/es/dropdown/{__test__ → tests}/index.test.js +7 -7
- package/es/dropdown/utils.js +35 -0
- package/es/ficon/index.js +16 -30
- package/es/form/Form.js +176 -0
- package/es/form/{item.js → Item.js} +52 -60
- package/es/form/__tests__/index.test.js +571 -0
- package/es/form/index.js +6 -171
- package/es/form/style/index.css +1 -1
- package/es/grid/__tests__/index.test.js +100 -0
- package/es/grid/index.js +36 -56
- package/es/icon/index.js +23 -38
- package/es/index.js +61 -9
- package/es/input/Input.js +400 -0
- package/es/input/__tests__/index.test.js +376 -0
- package/es/input/index.js +26 -347
- package/es/input/input-legacy/index.js +341 -0
- package/es/input/input-legacy/util.js +176 -0
- package/es/input/style/index.css +1 -1
- package/es/input/util.js +26 -18
- package/es/lib/withDragDropContext.js +2 -2
- package/es/loading/Loading.js +173 -0
- package/es/loading/__tests__/index.test.js +110 -0
- package/es/loading/index.js +5 -129
- package/es/loading/style/index.css +0 -0
- package/es/loading/style/index.js +0 -0
- package/es/locales/en-US.js +45 -9
- package/es/locales/index.js +16 -2
- package/es/locales/zh-CN.js +46 -10
- package/es/locales/zh-Hant-HK.js +123 -0
- package/es/locales/zh-Hant-TW.js +125 -0
- package/es/menu/Item.js +34 -51
- package/es/menu/Menu.js +414 -0
- package/es/menu/SubMenu.js +63 -90
- package/es/menu/Title.js +37 -51
- package/es/menu/__tests__/index.test.js +274 -0
- package/es/menu/index.js +12 -419
- package/es/menu/style/index.css +1 -1
- package/es/message/__tests__/index.test.js +71 -0
- package/es/message/index.js +58 -0
- package/es/message/style/index.css +1 -0
- package/es/message/style/index.js +5 -0
- package/es/modal/__tests__/index.test.js +178 -0
- package/es/modal/index.js +85 -77
- package/es/modal/style/index.css +1 -1
- package/es/nav-menu/NavMenu.js +44 -61
- package/es/nav-menu/__test__/index.test.js +8 -8
- package/es/nav-menu/__tests__/index.test.js +23 -0
- package/es/nav-menu/index.js +2 -2
- package/es/notice/Notice.js +136 -0
- package/es/notice/NoticeContainer.js +107 -0
- package/es/notice/__tests__/index.test.js +174 -0
- package/es/notice/index.js +66 -0
- package/es/notice/style/index.css +1 -0
- package/es/notice/style/index.js +5 -0
- package/es/notification/HandleNotification/index.js +216 -0
- package/es/notification/HandleNotification/style/index.css +1 -0
- package/es/notification/HandleNotification/style/index.js +5 -0
- package/es/notification/__tests__/index.test.js +114 -0
- package/es/notification/index.js +68 -231
- package/es/notification/style/index.css +1 -1
- package/es/notification/style/index.js +0 -0
- package/es/pagination/Pager.js +7 -9
- package/es/pagination/Pagination.js +134 -133
- package/es/pagination/__tests__/index.test.js +244 -0
- package/es/pagination/index.js +9 -8
- package/es/pagination/style/index.css +1 -1
- package/es/panel/index.js +28 -46
- package/es/popover/__test__/index.test.js +10 -10
- package/es/popover/__tests__/index.test.js +152 -0
- package/es/popover/index.js +77 -83
- package/es/popper/index.js +68 -64
- package/es/popper/style/index.css +1 -1
- package/es/preview/index.js +529 -0
- package/es/preview/style/index.css +1 -0
- package/es/preview/style/index.js +3 -0
- package/es/progress/BarProgress.js +107 -43
- package/es/progress/CircleProgress.js +13 -14
- package/es/progress/DashboardProgress.js +11 -13
- package/es/progress/Progress.js +102 -0
- package/es/progress/__tests__/index.test.js +131 -0
- package/es/progress/index.js +8 -100
- package/es/progress/style/index.css +1 -1
- package/es/radio/Group.js +199 -0
- package/es/radio/Radio.js +147 -0
- package/es/radio/__tests__/index.test.js +127 -0
- package/es/radio/index.js +10 -216
- package/es/radio/{__test__ → radio-legacy/__test__}/index.test.js +13 -13
- package/es/radio/radio-legacy/index.js +214 -0
- package/es/radio/radio-legacy/style/index.css +1 -0
- package/es/radio/radio-legacy/style/index.js +3 -0
- package/es/radio/style/index.css +1 -1
- package/es/rate/Icons.js +70 -70
- package/es/rate/Rate.js +75 -108
- package/es/rate/__tests__/index.test.js +124 -0
- package/es/rate/index.js +5 -2
- package/es/rate/style/index.css +1 -1
- package/es/select/Select.js +330 -265
- package/es/select/SelectDropdown.js +223 -79
- package/es/select/SelectInput.js +120 -91
- package/es/select/__tests__/index.test.js +505 -0
- package/es/select/index.js +6 -4
- package/es/select/select-legacy/Option.js +78 -0
- package/es/select/select-legacy/Select.js +702 -0
- package/es/select/select-legacy/SelectDropdown.js +157 -0
- package/es/select/select-legacy/SelectInput.js +308 -0
- package/es/select/select-legacy/common.js +19 -0
- package/es/select/select-legacy/index.js +16 -0
- package/es/select/style/select-dropdown.css +1 -1
- package/es/select/style/select-input.css +1 -1
- package/es/stepper/Stepper.js +147 -0
- package/es/stepper/__tests__/index.test.js +161 -0
- package/es/stepper/index.js +21 -127
- package/es/stepper/style/index.css +1 -1
- package/es/style/icon/diyIcon.css +1 -1
- package/es/style/icon/index.css +1 -1
- package/es/switch/__tests__/index.test.js +68 -0
- package/es/switch/index.js +26 -46
- package/es/switch/style/index.css +1 -1
- package/es/table/Body.js +294 -0
- package/es/table/ClickOuterside.js +95 -0
- package/es/table/Footer.js +171 -0
- package/es/table/Header.js +320 -0
- package/es/table/TableContent.js +101 -0
- package/es/table/__tests__/index.test.js +129 -0
- package/es/table/checkbox/index.js +36 -47
- package/es/table/checkbox/style/index.css +1 -0
- package/es/table/checkbox/style/index.js +3 -0
- package/es/table/index.js +269 -314
- package/es/table/menu/index.js +34 -44
- package/es/table/prefix.js +2 -2
- package/es/table/style/Table.css +1 -1
- package/es/table/style/index.css +1 -1
- package/es/tabs/ItemDropdown.js +45 -65
- package/es/tabs/TabPane.js +26 -44
- package/es/tabs/Tabs.js +110 -111
- package/es/tabs/__tests__/index.test.js +329 -0
- package/es/tabs/index.js +9 -3
- package/es/tabs/style/index.css +1 -1
- package/es/tabs/tabs-legacy/ItemDropdown.js +162 -0
- package/es/tabs/tabs-legacy/TabPane.js +70 -0
- package/es/tabs/tabs-legacy/Tabs.js +291 -0
- package/es/tabs/tabs-legacy/index.js +18 -0
- package/es/tabs/tabs-legacy/style/index.css +1 -0
- package/es/tabs/tabs-legacy/style/index.js +3 -0
- package/es/tag/__tests__/index.test.js +46 -0
- package/es/tag/index.js +86 -0
- package/es/tag/style/index.css +1 -0
- package/es/tag/style/index.js +3 -0
- package/es/timeline/__tests__/index.test.js +198 -0
- package/es/timeline/index.js +206 -136
- package/es/timeline/style/index.css +1 -1
- package/es/tooltip/__tests__/index.test.js +166 -0
- package/es/tooltip/index.js +93 -52
- package/es/tooltip/style/index.css +1 -1
- package/es/transfer/Item.js +73 -71
- package/es/transfer/Transfer.js +558 -0
- package/es/transfer/__tests__/index.test.js +210 -0
- package/es/transfer/index.js +4 -443
- package/es/transfer/style/index.css +1 -1
- package/es/tree/IconLoading.js +38 -0
- package/es/tree/Tree.js +94 -111
- package/es/tree/TreeDivider.js +6 -6
- package/es/tree/TreeItem.js +217 -123
- package/es/tree/TreeNode.js +472 -333
- package/es/tree/__tests__/index.test.js +599 -0
- package/es/tree/index.js +9 -2
- package/es/tree/style/index.css +1 -1
- package/es/tree/tree-legacy/Tree.js +330 -0
- package/es/tree/tree-legacy/TreeDivider.js +25 -0
- package/es/tree/tree-legacy/TreeItem.js +326 -0
- package/es/tree/tree-legacy/TreeNode.js +711 -0
- package/es/tree/tree-legacy/index.js +13 -0
- package/es/tree/tree-legacy/style/index.css +1 -0
- package/es/tree/tree-legacy/style/index.js +3 -0
- package/es/tree/tree-legacy/util.js +434 -0
- package/es/tree/util.js +8 -256
- package/es/upload/Upload.js +292 -200
- package/es/upload/UploadAvatar.js +61 -79
- package/es/upload/UploadClick.js +62 -60
- package/es/upload/UploadDrag.js +63 -66
- package/es/upload/UploadPhoto.js +86 -75
- package/es/upload/UploadPictureCard.js +53 -60
- package/es/upload/__tests__/index.test.js +760 -0
- package/es/upload/index.js +8 -71
- package/es/upload/main.js +83 -0
- package/es/upload/style/index.css +1 -1
- package/es/upload/tool.js +0 -1
- package/es/upload/{Preview.js → upload-legacy/Preview.js} +48 -62
- package/es/upload/upload-legacy/Upload.js +431 -0
- package/es/upload/upload-legacy/UploadAvatar.js +318 -0
- package/es/upload/upload-legacy/UploadClick.js +121 -0
- package/es/upload/upload-legacy/UploadDrag.js +176 -0
- package/es/upload/upload-legacy/UploadPhoto.js +179 -0
- package/es/upload/upload-legacy/UploadPictureCard.js +122 -0
- package/es/upload/upload-legacy/index.js +67 -0
- package/es/upload/upload-legacy/style/index.css +1 -0
- package/es/upload/upload-legacy/style/index.js +5 -0
- package/es/upload/upload-legacy/tool.js +84 -0
- package/es/watermark/index.js +97 -0
- package/es/watermark/watermark.js +263 -0
- package/package.json +1 -1
- package/es/alert/__test__/index.test.js +0 -67
- package/es/button/__test__/index.test.js +0 -29
- package/es/cascader/__test__/index.test.js +0 -283
- package/es/cascader/menu.js +0 -155
- package/es/checkbox/Base.js +0 -205
- package/es/checkbox/CheckBox.js +0 -185
- package/es/collapse/__test__/index.test.js +0 -58
- package/es/counter/__test__/index.test.js +0 -52
- package/es/menu/ItemGroup.js +0 -81
- package/es/modal/__test__/index.test.js +0 -123
- package/es/notification/__test__/index.test.js +0 -56
- package/es/pagination/__test__/index.test.js +0 -140
- package/es/rate/__test__/index.test.js +0 -54
- package/es/select/Option.js +0 -93
- package/es/select/__test__/index.test.js +0 -429
- package/es/style/color/colors.css +0 -0
- package/es/style/index.css +0 -0
- package/es/style/mixins/colors.css +0 -0
- package/es/style/mixins/index.css +0 -0
- package/es/style/theme/dark.css +0 -0
- package/es/style/theme/default.css +0 -0
- package/es/switch/__test__/index.test.js +0 -39
- package/es/table/__test__/index.test.js +0 -73
- package/es/table/body.js +0 -318
- package/es/table/clickOuterside.js +0 -115
- package/es/table/footer.js +0 -196
- package/es/table/header.js +0 -337
- package/es/table/pover.js +0 -154
- package/es/table/tableContent.js +0 -120
- package/es/timeline/__test__/index.test.js +0 -49
- package/es/timeline/foldingItem.js +0 -82
- package/es/tooltip/__test__/index.test.js +0 -67
- package/es/transfer/__test__/index.test.js +0 -11
- /package/es/{style → breadcrumb/style}/index.js +0 -0
- /package/es/checkbox/{common.js → checkbox-legacy/common.js} +0 -0
- /package/es/upload/{style → upload-legacy/style}/preview.css +0 -0
- /package/es/upload/{style → upload-legacy/style}/preview.js +0 -0
package/es/context/index.js
CHANGED
|
@@ -1,84 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
3
7
|
Object.defineProperty(exports, "__esModule", {
|
|
4
8
|
value: true
|
|
5
9
|
});
|
|
6
10
|
exports["default"] = exports.LocaleContext = exports.ThemeContext = void 0;
|
|
7
11
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _locales = _interopRequireDefault(require("../locales"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
15
|
-
|
|
16
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
19
|
-
|
|
20
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
21
13
|
|
|
22
|
-
|
|
14
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
25
17
|
|
|
26
|
-
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
39
|
-
|
|
40
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
|
-
|
|
42
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
28
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
43
29
|
|
|
44
|
-
|
|
30
|
+
var _locales = _interopRequireDefault(require("../locales"));
|
|
45
31
|
|
|
46
|
-
var ThemeContext =
|
|
32
|
+
var ThemeContext = _react["default"].createContext('hiui-blue');
|
|
47
33
|
|
|
48
34
|
exports.ThemeContext = ThemeContext;
|
|
49
35
|
|
|
50
|
-
var LocaleContext =
|
|
36
|
+
var LocaleContext = _react["default"].createContext('zh-Hans');
|
|
37
|
+
/**
|
|
38
|
+
* 临时解决 notice组件获取不到theme的问题
|
|
39
|
+
*/
|
|
40
|
+
|
|
51
41
|
|
|
52
42
|
exports.LocaleContext = LocaleContext;
|
|
43
|
+
var noticeTheme = '';
|
|
44
|
+
var confirmLocale = '';
|
|
53
45
|
|
|
54
46
|
var _default = function _default(WrappedComponent) {
|
|
55
|
-
var WrapperComponent =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
var WrapperComponent =
|
|
48
|
+
/*#__PURE__*/
|
|
49
|
+
function (_Component) {
|
|
50
|
+
(0, _inherits2["default"])(WrapperComponent, _Component);
|
|
59
51
|
|
|
60
52
|
function WrapperComponent() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return _super.apply(this, arguments);
|
|
53
|
+
(0, _classCallCheck2["default"])(this, WrapperComponent);
|
|
54
|
+
return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(WrapperComponent).apply(this, arguments));
|
|
64
55
|
}
|
|
65
56
|
|
|
66
|
-
|
|
57
|
+
(0, _createClass2["default"])(WrapperComponent, [{
|
|
67
58
|
key: "render",
|
|
68
59
|
value: function render() {
|
|
69
60
|
var _this$props = this.props,
|
|
70
61
|
theme = _this$props.theme,
|
|
71
62
|
locale = _this$props.locale,
|
|
72
63
|
innerRef = _this$props.innerRef,
|
|
73
|
-
restProps =
|
|
74
|
-
|
|
75
|
-
var ConsumerComponent =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
restProps = (0, _objectWithoutProperties2["default"])(_this$props, ["theme", "locale", "innerRef"]);
|
|
65
|
+
|
|
66
|
+
var ConsumerComponent = _react["default"].createElement(ThemeContext.Consumer, null, function (contextTheme) {
|
|
67
|
+
noticeTheme = noticeTheme || contextTheme;
|
|
68
|
+
return _react["default"].createElement(LocaleContext.Consumer, null, function (contextLocale) {
|
|
69
|
+
confirmLocale = confirmLocale || contextLocale;
|
|
70
|
+
return _react["default"].createElement(WrappedComponent, (0, _extends2["default"])({
|
|
71
|
+
theme: WrappedComponent.IS_HIUI_NOTICE ? noticeTheme : contextTheme,
|
|
72
|
+
locale: WrappedComponent.IS_HIUI_CONFIRM ? confirmLocale : contextLocale,
|
|
73
|
+
localeDatas: WrappedComponent.IS_HIUI_CONFIRM ? _locales["default"][confirmLocale] : _locales["default"][contextLocale],
|
|
74
|
+
ref: innerRef,
|
|
75
|
+
innerRef: innerRef
|
|
82
76
|
}, restProps));
|
|
83
77
|
});
|
|
84
78
|
});
|
|
@@ -86,12 +80,12 @@ var _default = function _default(WrappedComponent) {
|
|
|
86
80
|
return wrapProvider(theme, ThemeContext)(locale, LocaleContext)(ConsumerComponent);
|
|
87
81
|
}
|
|
88
82
|
}]);
|
|
89
|
-
|
|
90
83
|
return WrapperComponent;
|
|
91
84
|
}(_react.Component);
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
(0, _defineProperty2["default"])(WrapperComponent, "displayName", WrappedComponent.name);
|
|
87
|
+
return (0, _react.forwardRef)(function (props, ref) {
|
|
88
|
+
return _react["default"].createElement(WrapperComponent, (0, _extends2["default"])({}, props, {
|
|
95
89
|
innerRef: ref
|
|
96
90
|
}));
|
|
97
91
|
});
|
|
@@ -112,7 +106,7 @@ function wrapProvider(value, context) {
|
|
|
112
106
|
if (!context) {
|
|
113
107
|
var component = value;
|
|
114
108
|
wrapProvider.Providers.reverse().map(function (obj) {
|
|
115
|
-
component =
|
|
109
|
+
component = _react["default"].createElement(obj.context.Provider, {
|
|
116
110
|
value: obj.value
|
|
117
111
|
}, component);
|
|
118
112
|
});
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
+
|
|
16
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
+
|
|
18
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
+
|
|
20
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
+
|
|
22
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
|
+
|
|
24
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
+
|
|
26
|
+
var _react = _interopRequireDefault(require("react"));
|
|
27
|
+
|
|
28
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
29
|
+
|
|
30
|
+
var _util = require("../input/util");
|
|
31
|
+
|
|
32
|
+
var _decimal = require("decimal.js");
|
|
33
|
+
|
|
34
|
+
var _context = _interopRequireDefault(require("../context"));
|
|
35
|
+
|
|
36
|
+
var _icon = _interopRequireDefault(require("../icon"));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 加减器
|
|
40
|
+
*/
|
|
41
|
+
var Counter =
|
|
42
|
+
/*#__PURE__*/
|
|
43
|
+
function (_React$Component) {
|
|
44
|
+
(0, _inherits2["default"])(Counter, _React$Component);
|
|
45
|
+
|
|
46
|
+
function Counter(props) {
|
|
47
|
+
var _this;
|
|
48
|
+
|
|
49
|
+
(0, _classCallCheck2["default"])(this, Counter);
|
|
50
|
+
_this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(Counter).call(this, props));
|
|
51
|
+
var oldProps = Object.assign({}, _this.props);
|
|
52
|
+
_this.attrs = _this.getAttrs(oldProps);
|
|
53
|
+
var _this$props = _this.props,
|
|
54
|
+
value = _this$props.value,
|
|
55
|
+
defaultValue = _this$props.defaultValue,
|
|
56
|
+
_this$props$min = _this$props.min,
|
|
57
|
+
min = _this$props$min === void 0 ? -1 * Infinity : _this$props$min,
|
|
58
|
+
_this$props$max = _this$props.max,
|
|
59
|
+
max = _this$props$max === void 0 ? Infinity : _this$props$max;
|
|
60
|
+
var finalValue = Math.min(Math.max(Number(value === undefined ? defaultValue : value), Number(min)), Number(max));
|
|
61
|
+
_this.state = {
|
|
62
|
+
value: _this.format(finalValue),
|
|
63
|
+
valueTrue: _this.formatValue(finalValue)
|
|
64
|
+
};
|
|
65
|
+
return _this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
(0, _createClass2["default"])(Counter, [{
|
|
69
|
+
key: "componentWillReceiveProps",
|
|
70
|
+
value: function componentWillReceiveProps(nextProps) {
|
|
71
|
+
if (this.props.hasOwnProperty('value')) {
|
|
72
|
+
this.setState({
|
|
73
|
+
value: this.format(nextProps.value),
|
|
74
|
+
valueTrue: this.formatValue(nextProps.value)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 提取非函数属性
|
|
80
|
+
* @param {object} oldProps 原始props
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
}, {
|
|
84
|
+
key: "getAttrs",
|
|
85
|
+
value: function getAttrs(oldProps) {
|
|
86
|
+
var attrs = {};
|
|
87
|
+
var noNeed = ['value', 'className', 'class', 'id', 'style', 'type', 'placeholder', 'disabled'];
|
|
88
|
+
|
|
89
|
+
for (var i in oldProps) {
|
|
90
|
+
if (!(oldProps[i] instanceof Function)) {
|
|
91
|
+
if (noNeed.indexOf(i) === -1) {
|
|
92
|
+
attrs[i] = oldProps[i];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return attrs;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 净化数据
|
|
101
|
+
* @param {string} val 值
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
}, {
|
|
105
|
+
key: "formatValue",
|
|
106
|
+
value: function formatValue(value) {
|
|
107
|
+
return isNaN(Number(value)) ? value.toString().replace(/[^-\d]/g, '') : value;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 格式化数据
|
|
111
|
+
* 88,888
|
|
112
|
+
* @param {string} val 值
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
}, {
|
|
116
|
+
key: "format",
|
|
117
|
+
value: function format(val) {
|
|
118
|
+
return val;
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "render",
|
|
122
|
+
value: function render() {
|
|
123
|
+
var _this2 = this;
|
|
124
|
+
|
|
125
|
+
var _this$props2 = this.props,
|
|
126
|
+
className = _this$props2.className,
|
|
127
|
+
id = _this$props2.id,
|
|
128
|
+
disabled = _this$props2.disabled;
|
|
129
|
+
var _this$props3 = this.props,
|
|
130
|
+
_this$props3$min = _this$props3.min,
|
|
131
|
+
min = _this$props3$min === void 0 ? -1 * Infinity : _this$props3$min,
|
|
132
|
+
_this$props3$max = _this$props3.max,
|
|
133
|
+
max = _this$props3$max === void 0 ? Infinity : _this$props3$max,
|
|
134
|
+
step = _this$props3.step,
|
|
135
|
+
theme = _this$props3.theme;
|
|
136
|
+
var valueTrue = this.state.valueTrue;
|
|
137
|
+
var _this$attrs = this.attrs,
|
|
138
|
+
defaultValue = _this$attrs.defaultValue,
|
|
139
|
+
attrs = (0, _objectWithoutProperties2["default"])(_this$attrs, ["defaultValue"]);
|
|
140
|
+
var filterAttrs = (0, _util.filterObjProps)(attrs, ['locale', 'theme', 'localeDatas', 'localedatas', 'innerRef']);
|
|
141
|
+
var isAddDisabled = false;
|
|
142
|
+
var isMinusDisabled = false;
|
|
143
|
+
|
|
144
|
+
if (step > 0) {
|
|
145
|
+
isMinusDisabled = this.hasReachedMin || disabled;
|
|
146
|
+
isAddDisabled = this.hasReachedMax || disabled;
|
|
147
|
+
} else {
|
|
148
|
+
isMinusDisabled = this.hasReachedMax || disabled;
|
|
149
|
+
isAddDisabled = this.hasReachedMin || disabled;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return _react["default"].createElement("div", {
|
|
153
|
+
className: "hi-counter theme__".concat(theme, " ").concat(className || ''),
|
|
154
|
+
id: id
|
|
155
|
+
}, _react["default"].createElement("div", {
|
|
156
|
+
className: "hi-counter-outer"
|
|
157
|
+
}, _react["default"].createElement("span", {
|
|
158
|
+
className: "hi-counter-minus hi-counter-sign ".concat(isMinusDisabled ? 'disabled' : ''),
|
|
159
|
+
onClick: function onClick(e) {
|
|
160
|
+
var value = new _decimal.Decimal(_this2.getInputNumber()).minus(step).valueOf();
|
|
161
|
+
|
|
162
|
+
if (isMinusDisabled) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (step > 0) {
|
|
167
|
+
if (_this2.willReachMin) {
|
|
168
|
+
value = min;
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
if (_this2.willReachMax) {
|
|
172
|
+
value = max;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_this2.update(value);
|
|
177
|
+
}
|
|
178
|
+
}, _react["default"].createElement(_icon["default"], {
|
|
179
|
+
name: "minus"
|
|
180
|
+
})), _react["default"].createElement("input", (0, _extends2["default"])({
|
|
181
|
+
id: id ? "".concat(id, "_value") : '',
|
|
182
|
+
ref: function ref(arg) {
|
|
183
|
+
_this2._Input = arg;
|
|
184
|
+
},
|
|
185
|
+
value: this.state.value,
|
|
186
|
+
disabled: disabled,
|
|
187
|
+
"data-value": this.state.valueTrue
|
|
188
|
+
}, filterAttrs, {
|
|
189
|
+
onChange: function onChange(e) {
|
|
190
|
+
e.persist();
|
|
191
|
+
var value = e.target.value;
|
|
192
|
+
|
|
193
|
+
_this2.setState({
|
|
194
|
+
value: _this2.format(value),
|
|
195
|
+
valueTrue: _this2.formatValue(value)
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
onBlur: function onBlur(e) {
|
|
199
|
+
var value = _this2.getInputNumber();
|
|
200
|
+
|
|
201
|
+
_this2.update(value);
|
|
202
|
+
}
|
|
203
|
+
})), _react["default"].createElement("span", {
|
|
204
|
+
className: "hi-counter-plus hi-counter-sign ".concat(isAddDisabled ? 'disabled' : ''),
|
|
205
|
+
onClick: function onClick(e) {
|
|
206
|
+
var value = new _decimal.Decimal(valueTrue).plus(step).valueOf();
|
|
207
|
+
|
|
208
|
+
if (isAddDisabled) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (step > 0) {
|
|
213
|
+
if (_this2.willReachMax) {
|
|
214
|
+
value = max;
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
if (_this2.willReachMin) {
|
|
218
|
+
value = min;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
_this2.update(value);
|
|
223
|
+
}
|
|
224
|
+
}, _react["default"].createElement(_icon["default"], {
|
|
225
|
+
name: "plus"
|
|
226
|
+
}))));
|
|
227
|
+
}
|
|
228
|
+
}, {
|
|
229
|
+
key: "update",
|
|
230
|
+
value: function update(value) {
|
|
231
|
+
var _this3 = this;
|
|
232
|
+
|
|
233
|
+
var onChange = this.props.onChange;
|
|
234
|
+
|
|
235
|
+
if (this.isControlledComponent) {
|
|
236
|
+
this.setState({
|
|
237
|
+
value: this.format(this.props.value),
|
|
238
|
+
valueTrue: this.formatValue(this.props.value)
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (this.isUncontrolledComponent) {
|
|
243
|
+
this.setState({
|
|
244
|
+
value: this.format(value),
|
|
245
|
+
valueTrue: this.formatValue(value)
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
setTimeout(function () {
|
|
250
|
+
onChange && onChange({
|
|
251
|
+
target: _this3._Input
|
|
252
|
+
}, value);
|
|
253
|
+
}, 0);
|
|
254
|
+
}
|
|
255
|
+
}, {
|
|
256
|
+
key: "getInputNumber",
|
|
257
|
+
value: function getInputNumber() {
|
|
258
|
+
var _this$props4 = this.props,
|
|
259
|
+
max = _this$props4.max,
|
|
260
|
+
min = _this$props4.min;
|
|
261
|
+
var value = this.valueTrue;
|
|
262
|
+
|
|
263
|
+
if (isNaN(value)) {
|
|
264
|
+
value = 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
value = max && value - max >= 0 ? max : value;
|
|
268
|
+
value = min && value - min <= 0 ? min : value;
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
}, {
|
|
272
|
+
key: "isControlledComponent",
|
|
273
|
+
get: function get() {
|
|
274
|
+
return this.props.hasOwnProperty('value');
|
|
275
|
+
}
|
|
276
|
+
}, {
|
|
277
|
+
key: "isUncontrolledComponent",
|
|
278
|
+
get: function get() {
|
|
279
|
+
return !this.isControlledComponent;
|
|
280
|
+
}
|
|
281
|
+
}, {
|
|
282
|
+
key: "valueTrue",
|
|
283
|
+
get: function get() {
|
|
284
|
+
return parseFloat(this.state.value.toString().replace(/[^0-9|.|\-(e+)]+/, ''));
|
|
285
|
+
}
|
|
286
|
+
}, {
|
|
287
|
+
key: "willReachMax",
|
|
288
|
+
get: function get() {
|
|
289
|
+
var _this$props5 = this.props,
|
|
290
|
+
_this$props5$max = _this$props5.max,
|
|
291
|
+
max = _this$props5$max === void 0 ? Infinity : _this$props5$max,
|
|
292
|
+
step = _this$props5.step;
|
|
293
|
+
var num = new _decimal.Decimal(this.valueTrue).plus(step > 0 ? step : -step).valueOf() * 1;
|
|
294
|
+
return max <= num;
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
key: "willReachMin",
|
|
298
|
+
get: function get() {
|
|
299
|
+
var _this$props6 = this.props,
|
|
300
|
+
_this$props6$min = _this$props6.min,
|
|
301
|
+
min = _this$props6$min === void 0 ? -1 * Infinity : _this$props6$min,
|
|
302
|
+
step = _this$props6.step;
|
|
303
|
+
var num = new _decimal.Decimal(this.valueTrue).minus(step > 0 ? step : -step).valueOf() * 1;
|
|
304
|
+
return min >= num;
|
|
305
|
+
}
|
|
306
|
+
}, {
|
|
307
|
+
key: "hasReachedMax",
|
|
308
|
+
get: function get() {
|
|
309
|
+
var _this$props$max2 = this.props.max,
|
|
310
|
+
max = _this$props$max2 === void 0 ? Infinity : _this$props$max2;
|
|
311
|
+
return max <= this.valueTrue * 1;
|
|
312
|
+
}
|
|
313
|
+
}, {
|
|
314
|
+
key: "hasReachedMin",
|
|
315
|
+
get: function get() {
|
|
316
|
+
var _this$props$min2 = this.props.min,
|
|
317
|
+
min = _this$props$min2 === void 0 ? -1 * Infinity : _this$props$min2;
|
|
318
|
+
return min >= this.valueTrue * 1;
|
|
319
|
+
}
|
|
320
|
+
}]);
|
|
321
|
+
return Counter;
|
|
322
|
+
}(_react["default"].Component);
|
|
323
|
+
|
|
324
|
+
(0, _defineProperty2["default"])(Counter, "_Input", '');
|
|
325
|
+
(0, _defineProperty2["default"])(Counter, "propTypes", {
|
|
326
|
+
value: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
327
|
+
step: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
328
|
+
min: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
329
|
+
max: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
330
|
+
onChange: _propTypes["default"].func
|
|
331
|
+
});
|
|
332
|
+
(0, _defineProperty2["default"])(Counter, "defaultProps", {
|
|
333
|
+
defaultValue: 0,
|
|
334
|
+
step: 1
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
var _default = (0, _context["default"])(Counter);
|
|
338
|
+
|
|
339
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
|
|
7
|
+
var _enzyme = require("enzyme");
|
|
8
|
+
|
|
9
|
+
var _index = _interopRequireDefault(require("../index"));
|
|
10
|
+
|
|
11
|
+
/* eslint-env jest */
|
|
12
|
+
describe('Counter', function () {
|
|
13
|
+
beforeAll(function () {
|
|
14
|
+
jest.useFakeTimers();
|
|
15
|
+
});
|
|
16
|
+
afterAll(function () {
|
|
17
|
+
jest.useRealTimers();
|
|
18
|
+
});
|
|
19
|
+
it('should init with defaultValue', function () {
|
|
20
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
21
|
+
defaultValue: 10
|
|
22
|
+
}));
|
|
23
|
+
expect(wrapper.find('input').prop('value')).toEqual(10);
|
|
24
|
+
wrapper.unmount();
|
|
25
|
+
});
|
|
26
|
+
it('should controlled by value', function () {
|
|
27
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
28
|
+
defaultValue: 10,
|
|
29
|
+
value: 5,
|
|
30
|
+
step: 5
|
|
31
|
+
}));
|
|
32
|
+
expect(wrapper.find('input').prop('value')).toEqual(5);
|
|
33
|
+
wrapper.setProps({
|
|
34
|
+
value: 10
|
|
35
|
+
});
|
|
36
|
+
expect(wrapper.find('input').prop('value')).toEqual(10);
|
|
37
|
+
wrapper.find(".hi-counter-plus").simulate('click');
|
|
38
|
+
expect(wrapper.find('input').prop('value')).toEqual(10);
|
|
39
|
+
wrapper.unmount();
|
|
40
|
+
});
|
|
41
|
+
it('should change by step', function () {
|
|
42
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
43
|
+
defaultValue: 10,
|
|
44
|
+
step: 2
|
|
45
|
+
}));
|
|
46
|
+
wrapper.find(".hi-counter-minus").simulate('click');
|
|
47
|
+
expect(wrapper.find('input').prop('value')).toEqual('8');
|
|
48
|
+
wrapper.find(".hi-counter-plus").simulate('click');
|
|
49
|
+
expect(wrapper.find('input').prop('value')).toEqual('10');
|
|
50
|
+
wrapper.setProps({
|
|
51
|
+
step: -2
|
|
52
|
+
});
|
|
53
|
+
wrapper.find(".hi-counter-minus").simulate('click');
|
|
54
|
+
expect(wrapper.find('input').prop('value')).toEqual('12');
|
|
55
|
+
wrapper.find(".hi-counter-plus").simulate('click');
|
|
56
|
+
expect(wrapper.find('input').prop('value')).toEqual('10');
|
|
57
|
+
wrapper.unmount();
|
|
58
|
+
});
|
|
59
|
+
it('should show in boundary', function () {
|
|
60
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
61
|
+
defaultValue: 4,
|
|
62
|
+
step: 5,
|
|
63
|
+
max: 8,
|
|
64
|
+
min: 3
|
|
65
|
+
}));
|
|
66
|
+
wrapper.find(".hi-counter-minus").simulate('click');
|
|
67
|
+
expect(wrapper.find('input').prop('value')).toEqual(3);
|
|
68
|
+
wrapper.find(".hi-counter-minus").simulate('click');
|
|
69
|
+
expect(wrapper.find('input').prop('value')).toEqual(3);
|
|
70
|
+
wrapper.setProps({
|
|
71
|
+
step: 6
|
|
72
|
+
});
|
|
73
|
+
wrapper.find(".hi-counter-plus").simulate('click');
|
|
74
|
+
expect(wrapper.find('input').prop('value')).toEqual(8);
|
|
75
|
+
wrapper.find(".hi-counter-plus").simulate('click');
|
|
76
|
+
expect(wrapper.find('input').prop('value')).toEqual(8);
|
|
77
|
+
wrapper.setProps({
|
|
78
|
+
step: -12
|
|
79
|
+
});
|
|
80
|
+
wrapper.find(".hi-counter-plus").simulate('click');
|
|
81
|
+
expect(wrapper.find('input').prop('value')).toEqual(3);
|
|
82
|
+
wrapper.find(".hi-counter-minus").simulate('click');
|
|
83
|
+
expect(wrapper.find('input').prop('value')).toEqual(8);
|
|
84
|
+
wrapper.unmount();
|
|
85
|
+
});
|
|
86
|
+
it('should handle input change and blur', function () {
|
|
87
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
88
|
+
defaultValue: 4,
|
|
89
|
+
step: 5,
|
|
90
|
+
max: 8,
|
|
91
|
+
min: 3
|
|
92
|
+
}));
|
|
93
|
+
wrapper.find('input').simulate('change', {
|
|
94
|
+
target: {
|
|
95
|
+
value: 12
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
expect(wrapper.find('input').prop('value')).toEqual(12);
|
|
99
|
+
wrapper.find('input').simulate('blur');
|
|
100
|
+
expect(wrapper.find('input').prop('value')).toEqual(8);
|
|
101
|
+
wrapper.unmount();
|
|
102
|
+
});
|
|
103
|
+
it('should handle NaN', function () {
|
|
104
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
105
|
+
defaultValue: NaN,
|
|
106
|
+
step: 5,
|
|
107
|
+
max: 8,
|
|
108
|
+
min: 3
|
|
109
|
+
}));
|
|
110
|
+
wrapper.find('input').simulate('change', {
|
|
111
|
+
target: {
|
|
112
|
+
value: 'null'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
expect(wrapper.find('input').prop('value')).toEqual('null');
|
|
116
|
+
wrapper.find('input').simulate('blur');
|
|
117
|
+
expect(wrapper.find('input').prop('value')).toEqual(3);
|
|
118
|
+
wrapper.unmount();
|
|
119
|
+
});
|
|
120
|
+
it('should invoke counter onChange', function () {
|
|
121
|
+
var cb = jest.fn();
|
|
122
|
+
var wrapper = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
|
|
123
|
+
defaultValue: 4,
|
|
124
|
+
step: 1,
|
|
125
|
+
max: 8,
|
|
126
|
+
min: 3,
|
|
127
|
+
onChange: cb
|
|
128
|
+
}));
|
|
129
|
+
wrapper.find(".hi-counter-minus").simulate('click');
|
|
130
|
+
jest.runAllTimers();
|
|
131
|
+
expect(cb).toHaveBeenCalled();
|
|
132
|
+
wrapper.unmount();
|
|
133
|
+
});
|
|
134
|
+
});
|