rsuite 5.0.0-beta.5 → 5.0.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/Animation/styles/index.less +16 -16
- package/Animation/styles/mixin.less +2 -2
- package/Button/styles/index.less +36 -1
- package/Button/styles/mixin.less +7 -1
- package/CHANGELOG.md +47 -4
- package/Calendar/styles/index.less +7 -1
- package/Checkbox/styles/index.less +18 -2
- package/DatePicker/styles/index.less +6 -2
- package/Drawer/styles/index.less +11 -2
- package/Drawer/styles/mixin.less +2 -2
- package/Dropdown/styles/index.less +4 -0
- package/Form/styles/mixin.less +6 -0
- package/InputGroup/styles/index.less +4 -0
- package/Message/styles/index.less +16 -0
- package/Modal/styles/index.less +3 -2
- package/Nav/styles/index.less +18 -2
- package/Navbar/styles/index.less +68 -34
- package/Notification/styles/index.less +9 -3
- package/Pagination/styles/index.less +12 -1
- package/Pagination/styles/mixin.less +7 -0
- package/Picker/styles/index.less +25 -3
- package/Picker/styles/mixin.less +7 -2
- package/Popover/styles/index.less +23 -30
- package/Popover/styles/mixins.less +72 -0
- package/README.md +4 -4
- package/Radio/styles/index.less +16 -0
- package/RadioGroup/styles/index.less +4 -0
- package/Rate/styles/index.less +13 -2
- package/Ripple/styles/index.less +8 -4
- package/Sidenav/styles/index.less +160 -47
- package/Table/styles/index.less +8 -0
- package/TagInput/package.json +7 -0
- package/TagInput/styles/index.less +13 -0
- package/Toggle/styles/index.less +29 -19
- package/Tooltip/styles/index.less +32 -38
- package/Tooltip/styles/mixins.less +72 -0
- package/Uploader/styles/index.less +11 -1
- package/cjs/@types/common.d.ts +2 -0
- package/cjs/Animation/Bounce.js +10 -4
- package/cjs/Animation/Collapse.d.ts +1 -48
- package/cjs/Animation/Collapse.js +60 -106
- package/cjs/Animation/Fade.js +10 -5
- package/cjs/Animation/Slide.js +8 -4
- package/cjs/Carousel/Carousel.d.ts +7 -0
- package/cjs/Carousel/Carousel.js +24 -11
- package/cjs/CheckTree/index.js +14 -5
- package/cjs/CheckTreePicker/CheckTreePicker.js +9 -5
- package/cjs/DatePicker/DatePicker.d.ts +5 -1
- package/cjs/DatePicker/DatePicker.js +2 -13
- package/cjs/DateRangePicker/Calendar.d.ts +2 -1
- package/cjs/DateRangePicker/Calendar.js +4 -3
- package/cjs/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/cjs/DateRangePicker/DateRangePicker.js +58 -43
- package/cjs/DateRangePicker/utils.d.ts +1 -1
- package/cjs/DateRangePicker/utils.js +9 -5
- package/cjs/Dropdown/Dropdown.js +31 -18
- package/cjs/Dropdown/DropdownContext.d.ts +4 -1
- package/cjs/Dropdown/DropdownItem.js +31 -4
- package/cjs/Dropdown/DropdownState.d.ts +37 -0
- package/cjs/Dropdown/DropdownState.js +66 -0
- package/cjs/Dropdown/DropdownToggle.js +3 -6
- package/cjs/InputNumber/InputNumber.js +11 -10
- package/cjs/InputPicker/InputPicker.d.ts +16 -3
- package/cjs/InputPicker/InputPicker.js +85 -44
- package/cjs/List/ListItem.d.ts +1 -1
- package/cjs/Menu/MenuItem.js +1 -1
- package/cjs/MultiCascader/MultiCascader.js +4 -3
- package/cjs/Nav/NavItem.js +11 -63
- package/cjs/Navbar/NavbarItem.d.ts +19 -0
- package/cjs/Navbar/NavbarItem.js +93 -0
- package/cjs/Pagination/Pagination.js +1 -1
- package/cjs/Picker/PickerToggle.js +2 -2
- package/cjs/Picker/utils.d.ts +1 -1
- package/cjs/Picker/utils.js +26 -22
- package/cjs/Progress/ProgressCircle.js +15 -15
- package/cjs/SelectPicker/SelectPicker.d.ts +1 -3
- package/cjs/Sidenav/SidenavDropdown.js +6 -1
- package/cjs/Sidenav/SidenavItem.js +46 -12
- package/cjs/Slider/Slider.js +2 -1
- package/cjs/TagInput/index.d.ts +13 -0
- package/cjs/TagInput/index.js +58 -0
- package/cjs/TagPicker/index.d.ts +10 -2
- package/cjs/TagPicker/index.js +25 -6
- package/cjs/Tree/Tree.d.ts +0 -2
- package/cjs/Tree/Tree.js +13 -4
- package/cjs/Tree/TreeContext.d.ts +7 -0
- package/cjs/Tree/TreeContext.js +13 -0
- package/cjs/TreePicker/TreeNode.js +10 -3
- package/cjs/TreePicker/TreePicker.js +22 -10
- package/cjs/Uploader/UploadFileItem.d.ts +5 -0
- package/cjs/Uploader/UploadFileItem.js +4 -3
- package/cjs/Uploader/Uploader.d.ts +8 -3
- package/cjs/Uploader/Uploader.js +12 -6
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -1
- package/cjs/utils/ajaxUpload.d.ts +5 -1
- package/cjs/utils/ajaxUpload.js +24 -13
- package/cjs/utils/constants.d.ts +1 -0
- package/cjs/utils/constants.js +1 -0
- package/cjs/utils/dateUtils.d.ts +1 -0
- package/cjs/utils/dateUtils.js +5 -1
- package/cjs/utils/useInternalId.d.ts +4 -0
- package/cjs/utils/useInternalId.js +24 -0
- package/cjs/utils/useUniqueId.d.ts +1 -1
- package/cjs/utils/useUniqueId.js +1 -1
- package/dist/rsuite-rtl.css +1614 -221
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +1618 -221
- package/dist/rsuite.js +288 -288
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/@types/common.d.ts +2 -0
- package/esm/Animation/Bounce.js +8 -4
- package/esm/Animation/Collapse.d.ts +1 -48
- package/esm/Animation/Collapse.js +59 -104
- package/esm/Animation/Fade.js +8 -4
- package/esm/Animation/Slide.js +6 -3
- package/esm/Carousel/Carousel.d.ts +7 -0
- package/esm/Carousel/Carousel.js +25 -12
- package/esm/CheckTree/index.js +11 -5
- package/esm/CheckTreePicker/CheckTreePicker.js +8 -6
- package/esm/DatePicker/DatePicker.d.ts +5 -1
- package/esm/DatePicker/DatePicker.js +2 -13
- package/esm/DateRangePicker/Calendar.d.ts +2 -1
- package/esm/DateRangePicker/Calendar.js +4 -3
- package/esm/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/esm/DateRangePicker/DateRangePicker.js +27 -12
- package/esm/DateRangePicker/utils.d.ts +1 -1
- package/esm/DateRangePicker/utils.js +7 -3
- package/esm/Dropdown/Dropdown.js +30 -19
- package/esm/Dropdown/DropdownContext.d.ts +4 -1
- package/esm/Dropdown/DropdownItem.js +30 -6
- package/esm/Dropdown/DropdownState.d.ts +37 -0
- package/esm/Dropdown/DropdownState.js +55 -0
- package/esm/Dropdown/DropdownToggle.js +3 -6
- package/esm/InputNumber/InputNumber.js +11 -10
- package/esm/InputPicker/InputPicker.d.ts +16 -3
- package/esm/InputPicker/InputPicker.js +84 -45
- package/esm/List/ListItem.d.ts +1 -1
- package/esm/Menu/MenuItem.js +1 -1
- package/esm/MultiCascader/MultiCascader.js +4 -3
- package/esm/Nav/NavItem.js +12 -61
- package/esm/Navbar/NavbarItem.d.ts +19 -0
- package/esm/Navbar/NavbarItem.js +73 -0
- package/esm/Pagination/Pagination.js +1 -1
- package/esm/Picker/PickerToggle.js +2 -2
- package/esm/Picker/utils.d.ts +1 -1
- package/esm/Picker/utils.js +26 -22
- package/esm/Progress/ProgressCircle.js +15 -15
- package/esm/SelectPicker/SelectPicker.d.ts +1 -3
- package/esm/Sidenav/SidenavDropdown.js +5 -1
- package/esm/Sidenav/SidenavItem.js +47 -13
- package/esm/Slider/Slider.js +2 -1
- package/esm/TagInput/index.d.ts +13 -0
- package/esm/TagInput/index.js +44 -0
- package/esm/TagPicker/index.d.ts +10 -2
- package/esm/TagPicker/index.js +23 -6
- package/esm/Tree/Tree.d.ts +0 -2
- package/esm/Tree/Tree.js +10 -4
- package/esm/Tree/TreeContext.d.ts +7 -0
- package/esm/Tree/TreeContext.js +3 -0
- package/esm/TreePicker/TreeNode.js +10 -4
- package/esm/TreePicker/TreePicker.js +23 -12
- package/esm/Uploader/UploadFileItem.d.ts +5 -0
- package/esm/Uploader/UploadFileItem.js +2 -3
- package/esm/Uploader/Uploader.d.ts +8 -3
- package/esm/Uploader/Uploader.js +12 -6
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/utils/ajaxUpload.d.ts +5 -1
- package/esm/utils/ajaxUpload.js +24 -13
- package/esm/utils/constants.d.ts +1 -0
- package/esm/utils/constants.js +1 -0
- package/esm/utils/dateUtils.d.ts +1 -0
- package/esm/utils/dateUtils.js +1 -0
- package/esm/utils/useInternalId.d.ts +4 -0
- package/esm/utils/useInternalId.js +16 -0
- package/esm/utils/useUniqueId.d.ts +1 -1
- package/esm/utils/useUniqueId.js +1 -1
- package/package.json +4 -9
- package/styles/color-modes/dark.less +28 -5
- package/styles/color-modes/high-contrast.less +317 -0
- package/styles/color-modes/light.less +24 -1
- package/styles/color-modes.less +5 -0
- package/styles/colors/high-contrast.less +105 -0
- package/styles/index.less +1 -0
- package/styles/mixins/color-modes.less +6 -0
- package/styles/mixins/listbox.less +13 -1
- package/styles/mixins/menu.less +7 -0
- package/styles/mixins/utilities.less +9 -1
- package/styles/variables.less +11 -0
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import IconCalendar from '@rsuite/icons/legacy/Calendar';
|
|
4
|
+
import isUndefined from 'lodash/isUndefined';
|
|
5
5
|
import omit from 'lodash/omit';
|
|
6
|
+
import partial from 'lodash/partial';
|
|
6
7
|
import pick from 'lodash/pick';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import * as disabledDateUtils from './disabledDateUtils';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
10
|
import { FormattedDate } from '../CustomProvider';
|
|
11
11
|
import Toolbar from '../DatePicker/Toolbar';
|
|
12
|
-
import
|
|
13
|
-
import { getCalendarDate, getMonthHoverRange, getWeekHoverRange, setTimingMargin } from './utils';
|
|
12
|
+
import { omitTriggerPropKeys, pickerDefaultProps, PickerOverlay, pickerPropTypes, PickerToggle, PickerToggleTrigger, pickTriggerPropKeys, usePickerClassName, usePublicMethods, useToggleKeyDownEvent } from '../Picker';
|
|
14
13
|
import { createChainedFunction, DATERANGE_DISABLED_TARGET, DateUtils, mergeRefs, useClassNames, useControlled, useCustom } from '../utils';
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import
|
|
14
|
+
import { addMonths, compareAsc, isSameMonth } from '../utils/dateUtils';
|
|
15
|
+
import Calendar from './Calendar';
|
|
16
|
+
import * as disabledDateUtils from './disabledDateUtils';
|
|
17
|
+
import { getCalendarDate, getMonthHoverRange, getWeekHoverRange, isSameRange, setTimingMargin } from './utils';
|
|
18
18
|
|
|
19
19
|
var defaultProps = _extends({}, pickerDefaultProps, {
|
|
20
20
|
as: 'div',
|
|
@@ -234,7 +234,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
234
234
|
var nextValue = !isUndefined(nextSelectValue) ? nextSelectValue : selectValue;
|
|
235
235
|
setSelectValue(nextValue || []);
|
|
236
236
|
|
|
237
|
-
if (!
|
|
237
|
+
if (!isSameRange(nextValue, value, formatStr)) {
|
|
238
238
|
setValue(nextValue);
|
|
239
239
|
onChange === null || onChange === void 0 ? void 0 : onChange(nextValue, event);
|
|
240
240
|
} // `closeOverlay` default value is `true`
|
|
@@ -243,7 +243,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
243
243
|
if (closeOverlay !== false) {
|
|
244
244
|
handleCloseDropdown();
|
|
245
245
|
}
|
|
246
|
-
}, [handleCloseDropdown, onChange, selectValue,
|
|
246
|
+
}, [formatStr, handleCloseDropdown, onChange, selectValue, setValue, value]);
|
|
247
247
|
/**
|
|
248
248
|
* Select the date range. If oneTap is not set, you need to click twice to select the start time and end time.
|
|
249
249
|
* The MouseMove event is called between the first click and the second click to update the selection state.
|
|
@@ -332,6 +332,20 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
332
332
|
nextCalendarDate[index] = date;
|
|
333
333
|
updateCalendarDate(nextCalendarDate);
|
|
334
334
|
}, [calendarDate, updateCalendarDate]);
|
|
335
|
+
var handleChangeCalendarTime = useCallback(function (index, date) {
|
|
336
|
+
setSelectValue(function (prev) {
|
|
337
|
+
var next = [].concat(prev);
|
|
338
|
+
var clonedDate = new Date(date.valueOf()); // if next[index] is not empty, only update the time after aligning the year, month and day
|
|
339
|
+
|
|
340
|
+
if (next[index]) {
|
|
341
|
+
clonedDate.setFullYear(next[index].getFullYear(), next[index].getMonth(), next[index].getDate());
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
next[index] = clonedDate;
|
|
345
|
+
return next;
|
|
346
|
+
});
|
|
347
|
+
handleChangeCalendarDate(index, date);
|
|
348
|
+
}, [handleChangeCalendarDate]);
|
|
335
349
|
/**
|
|
336
350
|
* Toolbar operation callback function
|
|
337
351
|
*/
|
|
@@ -496,6 +510,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
496
510
|
showWeekNumbers: showWeekNumbers,
|
|
497
511
|
value: selectValue,
|
|
498
512
|
onChangeCalendarDate: handleChangeCalendarDate,
|
|
513
|
+
onChangeCalendarTime: handleChangeCalendarTime,
|
|
499
514
|
onMouseMove: handleMouseMove,
|
|
500
515
|
onSelect: handleSelectValueChange
|
|
501
516
|
};
|
|
@@ -4,6 +4,6 @@ export declare function getCalendarDate({ value }: {
|
|
|
4
4
|
value?: ValueType;
|
|
5
5
|
}): ValueType;
|
|
6
6
|
export declare const getDefaultRanges: () => RangeType[];
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const isSameRange: (source: ValueType, dest: ValueType, format: string) => boolean;
|
|
8
8
|
export declare const getMonthHoverRange: (date: Date) => ValueType;
|
|
9
9
|
export declare const getWeekHoverRange: (isoWeek: boolean, date: Date) => ValueType;
|
|
@@ -36,10 +36,14 @@ export var getDefaultRanges = function getDefaultRanges() {
|
|
|
36
36
|
value: [setTimingMargin(DateUtils.subDays(todayDate, 6)), setTimingMargin(todayDate, 'right')]
|
|
37
37
|
}];
|
|
38
38
|
};
|
|
39
|
-
export var
|
|
40
|
-
var
|
|
39
|
+
export var isSameRange = function isSameRange(source, dest, format) {
|
|
40
|
+
var result = DateUtils.isSameDay(source === null || source === void 0 ? void 0 : source[0], dest === null || dest === void 0 ? void 0 : dest[0]) && DateUtils.isSameDay(source === null || source === void 0 ? void 0 : source[1], dest === null || dest === void 0 ? void 0 : dest[1]);
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
if (DateUtils.shouldTime(format)) {
|
|
43
|
+
result && (result = DateUtils.isSameSecond(source === null || source === void 0 ? void 0 : source[0], dest === null || dest === void 0 ? void 0 : dest[0]) && DateUtils.isSameSecond(source === null || source === void 0 ? void 0 : source[1], dest === null || dest === void 0 ? void 0 : dest[1]));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
43
47
|
};
|
|
44
48
|
export var getMonthHoverRange = function getMonthHoverRange(date) {
|
|
45
49
|
return [DateUtils.startOfMonth(date), DateUtils.endOfMonth(date)];
|
package/esm/Dropdown/Dropdown.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
import React, { useCallback, useContext, useMemo } from 'react';
|
|
3
|
+
import React, { useCallback, useContext, useMemo, useReducer } from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import omit from 'lodash/omit';
|
|
6
|
+
import pick from 'lodash/pick';
|
|
6
7
|
import DropdownMenu from './DropdownMenu';
|
|
7
8
|
import { mergeRefs, PLACEMENT_8, placementPolyfill, useClassNames } from '../utils';
|
|
8
9
|
import { SidenavContext } from '../Sidenav/Sidenav';
|
|
@@ -18,6 +19,7 @@ import { NavbarContext } from '../Navbar/Navbar';
|
|
|
18
19
|
import Disclosure from '../Disclosure/Disclosure';
|
|
19
20
|
import SidenavDropdown from '../Sidenav/SidenavDropdown';
|
|
20
21
|
import NavContext from '../Nav/NavContext';
|
|
22
|
+
import { initialState, reducer } from './DropdownState';
|
|
21
23
|
var defaultProps = {
|
|
22
24
|
as: 'div',
|
|
23
25
|
classPrefix: 'dropdown',
|
|
@@ -96,14 +98,29 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
96
98
|
}, [trigger]);
|
|
97
99
|
var parentMenu = useContext(MenuContext);
|
|
98
100
|
var sidenav = useContext(SidenavContext);
|
|
99
|
-
var navbar = useContext(NavbarContext);
|
|
101
|
+
var navbar = useContext(NavbarContext);
|
|
102
|
+
|
|
103
|
+
var _useReducer = useReducer(reducer, initialState),
|
|
104
|
+
items = _useReducer[0].items,
|
|
105
|
+
dispatch = _useReducer[1];
|
|
106
|
+
|
|
107
|
+
var hasSelectedItem = useMemo(function () {
|
|
108
|
+
return items.some(function (item) {
|
|
109
|
+
return item.props.selected;
|
|
110
|
+
});
|
|
111
|
+
}, [items]);
|
|
112
|
+
var dropdownContextValue = useMemo(function () {
|
|
113
|
+
return {
|
|
114
|
+
activeKey: activeKey,
|
|
115
|
+
onSelect: emitSelect,
|
|
116
|
+
hasSelectedItem: hasSelectedItem,
|
|
117
|
+
dispatch: dispatch
|
|
118
|
+
};
|
|
119
|
+
}, [activeKey, emitSelect, hasSelectedItem, dispatch]); // Render a disclosure when inside expanded <Sidenav>
|
|
100
120
|
|
|
101
121
|
if (sidenav !== null && sidenav !== void 0 && sidenav.expanded) {
|
|
102
122
|
return /*#__PURE__*/React.createElement(DropdownContext.Provider, {
|
|
103
|
-
value:
|
|
104
|
-
activeKey: activeKey,
|
|
105
|
-
onSelect: emitSelect
|
|
106
|
-
}
|
|
123
|
+
value: dropdownContextValue
|
|
107
124
|
}, /*#__PURE__*/React.createElement(SidenavDropdown, _extends({
|
|
108
125
|
ref: ref
|
|
109
126
|
}, rest)));
|
|
@@ -112,10 +129,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
112
129
|
|
|
113
130
|
if (navbar) {
|
|
114
131
|
return /*#__PURE__*/React.createElement(DropdownContext.Provider, {
|
|
115
|
-
value:
|
|
116
|
-
activeKey: activeKey,
|
|
117
|
-
onSelect: emitSelect
|
|
118
|
-
}
|
|
132
|
+
value: dropdownContextValue
|
|
119
133
|
}, /*#__PURE__*/React.createElement(Disclosure, {
|
|
120
134
|
hideOnClickOutside: true
|
|
121
135
|
}, function (_ref, containerRef) {
|
|
@@ -155,7 +169,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
155
169
|
className: toggleClassName,
|
|
156
170
|
placement: placement,
|
|
157
171
|
disabled: disabled
|
|
158
|
-
}, omit(menuButtonProps, ['open']), toggleProps), title);
|
|
172
|
+
}, omit(menuButtonProps, ['open']), omit(toggleProps, ['data-testid'])), title);
|
|
159
173
|
};
|
|
160
174
|
|
|
161
175
|
if (parentMenu) {
|
|
@@ -172,16 +186,13 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
172
186
|
className: mergeNavItemClassNames(toggleClassName, withNavItemClassPrefix({
|
|
173
187
|
focus: active
|
|
174
188
|
}))
|
|
175
|
-
}, menuButtonProps, omit(menuitemProps, ['onClick']), toggleProps), title);
|
|
189
|
+
}, menuButtonProps, omit(menuitemProps, ['onClick']), omit(toggleProps, 'data-testid')), title);
|
|
176
190
|
});
|
|
177
191
|
};
|
|
178
192
|
}
|
|
179
193
|
|
|
180
194
|
return /*#__PURE__*/React.createElement(DropdownContext.Provider, {
|
|
181
|
-
value:
|
|
182
|
-
activeKey: activeKey,
|
|
183
|
-
onSelect: emitSelect
|
|
184
|
-
}
|
|
195
|
+
value: dropdownContextValue
|
|
185
196
|
}, /*#__PURE__*/React.createElement(Menu, {
|
|
186
197
|
menuButtonText: title,
|
|
187
198
|
renderMenuButton: renderMenuButton,
|
|
@@ -190,7 +201,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
190
201
|
var open = _ref4.open,
|
|
191
202
|
popupProps = _objectWithoutPropertiesLoose(_ref4, ["open"]);
|
|
192
203
|
|
|
193
|
-
var menuClassName = mergeMenuClassName(className, withMenuClassPrefix()); // When inside a collapsed <Sidenav>, render a header in menu
|
|
204
|
+
var menuClassName = mergeMenuClassName(className, withMenuClassPrefix({})); // When inside a collapsed <Sidenav>, render a header in menu
|
|
194
205
|
|
|
195
206
|
var showHeader = !!sidenav;
|
|
196
207
|
return /*#__PURE__*/React.createElement("ul", _extends({
|
|
@@ -218,11 +229,11 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
218
229
|
var open = _ref5.open,
|
|
219
230
|
menuContainer = _objectWithoutPropertiesLoose(_ref5, ["open"]);
|
|
220
231
|
|
|
221
|
-
var classes = merge(className, withClassPrefix((_withClassPrefix2 = {}, _withClassPrefix2["placement-" + kebabCase(placementPolyfill(placement))] = !!placement, _withClassPrefix2.disabled = disabled, _withClassPrefix2.open = open, _withClassPrefix2.submenu = !!parentMenu, _withClassPrefix2)));
|
|
232
|
+
var classes = merge(className, withClassPrefix((_withClassPrefix2 = {}, _withClassPrefix2["placement-" + kebabCase(placementPolyfill(placement))] = !!placement, _withClassPrefix2.disabled = disabled, _withClassPrefix2.open = open, _withClassPrefix2.submenu = !!parentMenu, _withClassPrefix2['selected-within'] = hasSelectedItem, _withClassPrefix2)));
|
|
222
233
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
223
234
|
ref: mergeRefs(ref, menuContainerRef),
|
|
224
235
|
className: classes
|
|
225
|
-
}, menuContainer, {
|
|
236
|
+
}, menuContainer, pick(toggleProps, ['data-testid']), {
|
|
226
237
|
style: style
|
|
227
238
|
}));
|
|
228
239
|
}));
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { Dispatch } from 'react';
|
|
2
|
+
import { DropdownAction } from './DropdownState';
|
|
2
3
|
export interface DropdownContextProps {
|
|
3
4
|
activeKey?: string;
|
|
4
5
|
onSelect: (eventKey: string, event: React.SyntheticEvent) => void;
|
|
6
|
+
hasSelectedItem?: boolean;
|
|
7
|
+
dispatch?: Dispatch<DropdownAction>;
|
|
5
8
|
}
|
|
6
9
|
declare const DropdownContext: React.Context<DropdownContextProps>;
|
|
7
10
|
export default DropdownContext;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
import React, { useCallback, useContext } from 'react';
|
|
3
|
+
import React, { useCallback, useContext, useEffect } from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import { SidenavContext } from '../Sidenav/Sidenav';
|
|
6
6
|
import deprecatePropType from '../utils/deprecatePropType';
|
|
@@ -13,6 +13,8 @@ import SidenavDropdownItem from '../Sidenav/SidenavDropdownItem';
|
|
|
13
13
|
import DisclosureContext, { DisclosureActionTypes } from '../Disclosure/DisclosureContext';
|
|
14
14
|
import SafeAnchor from '../SafeAnchor';
|
|
15
15
|
import NavContext from '../Nav/NavContext';
|
|
16
|
+
import useInternalId from '../utils/useInternalId';
|
|
17
|
+
import { DropdownActionType } from './DropdownState';
|
|
16
18
|
var defaultProps = {
|
|
17
19
|
as: 'li',
|
|
18
20
|
classPrefix: 'dropdown-item'
|
|
@@ -32,6 +34,7 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
32
34
|
icon = props.icon,
|
|
33
35
|
rest = _objectWithoutPropertiesLoose(props, ["classPrefix", "className", "active", "eventKey", "onSelect", "icon"]);
|
|
34
36
|
|
|
37
|
+
var internalId = useInternalId('DropdownItem');
|
|
35
38
|
var nav = useContext(NavContext);
|
|
36
39
|
var dropdown = useContext(DropdownContext);
|
|
37
40
|
|
|
@@ -59,6 +62,29 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
59
62
|
});
|
|
60
63
|
handleSelectItem === null || handleSelectItem === void 0 ? void 0 : handleSelectItem(event);
|
|
61
64
|
}, [dispatchDisclosure, handleSelectItem]);
|
|
65
|
+
var selected = activeProp || !isNil(eventKey) && (shallowEqual(dropdown === null || dropdown === void 0 ? void 0 : dropdown.activeKey, eventKey) || shallowEqual(nav === null || nav === void 0 ? void 0 : nav.activeKey, eventKey));
|
|
66
|
+
var dispatch = dropdown === null || dropdown === void 0 ? void 0 : dropdown.dispatch;
|
|
67
|
+
useEffect(function () {
|
|
68
|
+
if (dispatch) {
|
|
69
|
+
dispatch({
|
|
70
|
+
type: DropdownActionType.RegisterItem,
|
|
71
|
+
payload: {
|
|
72
|
+
id: internalId,
|
|
73
|
+
props: {
|
|
74
|
+
selected: selected
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return function () {
|
|
79
|
+
dispatch({
|
|
80
|
+
type: DropdownActionType.UnregisterItem,
|
|
81
|
+
payload: {
|
|
82
|
+
id: internalId
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}, [internalId, selected, dispatch]);
|
|
62
88
|
|
|
63
89
|
if (sidenav !== null && sidenav !== void 0 && sidenav.expanded) {
|
|
64
90
|
return /*#__PURE__*/React.createElement(SidenavDropdownItem, _extends({
|
|
@@ -66,8 +92,6 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
66
92
|
}, props));
|
|
67
93
|
}
|
|
68
94
|
|
|
69
|
-
var menuitemSelected = activeProp || !isNil(eventKey) && (shallowEqual(dropdown === null || dropdown === void 0 ? void 0 : dropdown.activeKey, eventKey) || shallowEqual(nav === null || nav === void 0 ? void 0 : nav.activeKey, eventKey));
|
|
70
|
-
|
|
71
95
|
var Component = rest.as,
|
|
72
96
|
divider = rest.divider,
|
|
73
97
|
panel = rest.panel,
|
|
@@ -97,7 +121,7 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
97
121
|
disabled: disabled,
|
|
98
122
|
divider: divider,
|
|
99
123
|
panel: panel,
|
|
100
|
-
active:
|
|
124
|
+
active: selected
|
|
101
125
|
}));
|
|
102
126
|
var dataAttributes = {
|
|
103
127
|
'data-event-key': eventKey
|
|
@@ -110,7 +134,7 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
110
134
|
return /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(SafeAnchor, _extends({
|
|
111
135
|
ref: ref,
|
|
112
136
|
className: classes,
|
|
113
|
-
"aria-current":
|
|
137
|
+
"aria-current": selected || undefined
|
|
114
138
|
}, dataAttributes, restProps, {
|
|
115
139
|
onClick: createChainedFunction(handleClickNavbarDropdownItem, restProps.onClick)
|
|
116
140
|
}), icon && /*#__PURE__*/React.cloneElement(icon, {
|
|
@@ -119,7 +143,7 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
119
143
|
}
|
|
120
144
|
|
|
121
145
|
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
122
|
-
selected:
|
|
146
|
+
selected: selected,
|
|
123
147
|
disabled: disabled,
|
|
124
148
|
onActivate: handleSelectItem
|
|
125
149
|
}, function (_ref2, menuitemRef) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface DropdownItemState {
|
|
2
|
+
/**
|
|
3
|
+
* Internal ID
|
|
4
|
+
*/
|
|
5
|
+
id: string;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
props: {
|
|
10
|
+
selected: boolean;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface DropdownState {
|
|
14
|
+
items: DropdownItemState[];
|
|
15
|
+
}
|
|
16
|
+
export declare const initialState: DropdownState;
|
|
17
|
+
export declare enum DropdownActionType {
|
|
18
|
+
RegisterItem = 0,
|
|
19
|
+
UnregisterItem = 1,
|
|
20
|
+
UpdateItem = 2
|
|
21
|
+
}
|
|
22
|
+
export declare type DropdownAction = {
|
|
23
|
+
type: DropdownActionType.RegisterItem;
|
|
24
|
+
payload: {
|
|
25
|
+
id: string;
|
|
26
|
+
props: {
|
|
27
|
+
selected: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
} | {
|
|
31
|
+
type: DropdownActionType.UnregisterItem;
|
|
32
|
+
payload: {
|
|
33
|
+
id: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function reducer(state: DropdownState, action: DropdownAction): DropdownState;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
export var initialState = {
|
|
3
|
+
items: []
|
|
4
|
+
};
|
|
5
|
+
export var DropdownActionType;
|
|
6
|
+
|
|
7
|
+
(function (DropdownActionType) {
|
|
8
|
+
DropdownActionType[DropdownActionType["RegisterItem"] = 0] = "RegisterItem";
|
|
9
|
+
DropdownActionType[DropdownActionType["UnregisterItem"] = 1] = "UnregisterItem";
|
|
10
|
+
DropdownActionType[DropdownActionType["UpdateItem"] = 2] = "UpdateItem";
|
|
11
|
+
})(DropdownActionType || (DropdownActionType = {}));
|
|
12
|
+
|
|
13
|
+
export function reducer(state, action) {
|
|
14
|
+
if (state === void 0) {
|
|
15
|
+
state = initialState;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
switch (action.type) {
|
|
19
|
+
case DropdownActionType.RegisterItem:
|
|
20
|
+
if (state.items.find(function (item) {
|
|
21
|
+
return item.id === action.payload.id;
|
|
22
|
+
})) {
|
|
23
|
+
return _extends({}, state, {
|
|
24
|
+
items: state.items.map(function (item) {
|
|
25
|
+
if (item.id === action.payload.id) {
|
|
26
|
+
return _extends({}, item, {
|
|
27
|
+
props: _extends({}, item.props, {
|
|
28
|
+
selected: action.payload.props.selected
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return item;
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return _extends({}, state, {
|
|
39
|
+
items: [].concat(state.items, [{
|
|
40
|
+
id: action.payload.id,
|
|
41
|
+
props: action.payload.props
|
|
42
|
+
}])
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
case DropdownActionType.UnregisterItem:
|
|
46
|
+
return _extends({}, state, {
|
|
47
|
+
items: state.items.filter(function (item) {
|
|
48
|
+
return item.id !== action.payload.id;
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
default:
|
|
53
|
+
return state;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -34,15 +34,12 @@ var DropdownToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
34
34
|
var inSidenav = !!sidenav; // Caret icon is down by default, when Dropdown is used in Sidenav.
|
|
35
35
|
|
|
36
36
|
var Caret = useToggleCaret(inSidenav ? 'bottomStart' : placement);
|
|
37
|
-
var
|
|
38
|
-
appearance: 'subtle'
|
|
39
|
-
} : null;
|
|
40
|
-
var toggle = /*#__PURE__*/React.createElement(Component, _extends({}, buttonProps, rest, {
|
|
37
|
+
var toggle = /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
41
38
|
ref: ref,
|
|
42
39
|
className: classes
|
|
43
|
-
}), /*#__PURE__*/React.
|
|
40
|
+
}), icon && /*#__PURE__*/React.cloneElement(icon, {
|
|
44
41
|
className: prefix('icon')
|
|
45
|
-
}
|
|
42
|
+
}), children, noCaret ? null : /*#__PURE__*/React.createElement(Caret, {
|
|
46
43
|
className: prefix('caret')
|
|
47
44
|
}));
|
|
48
45
|
return renderToggle ? renderToggle(rest, ref) : toggle;
|
|
@@ -129,7 +129,7 @@ var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
129
129
|
rest = _partitionHTMLProps[1];
|
|
130
130
|
|
|
131
131
|
var inputRef = useRef();
|
|
132
|
-
var
|
|
132
|
+
var handleChangeValue = useCallback(function (currentValue, event) {
|
|
133
133
|
if (currentValue !== value) {
|
|
134
134
|
// Disable the up button when the value is greater than the maximum value.
|
|
135
135
|
setDisabledUpButton(disableMaxValue(currentValue, max)); // Disable the down button when the value is greater than the minimum value.
|
|
@@ -157,13 +157,13 @@ var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
157
157
|
var handlePlus = useCallback(function (event) {
|
|
158
158
|
var val = +(value || 0);
|
|
159
159
|
var bit = decimals(val, step);
|
|
160
|
-
|
|
161
|
-
}, [getSafeValue,
|
|
160
|
+
handleChangeValue(getSafeValue((val + step).toFixed(bit)), event);
|
|
161
|
+
}, [getSafeValue, handleChangeValue, step, value]);
|
|
162
162
|
var handleMinus = useCallback(function (event) {
|
|
163
163
|
var val = +(value || 0);
|
|
164
164
|
var bit = decimals(val, step);
|
|
165
|
-
|
|
166
|
-
}, [getSafeValue,
|
|
165
|
+
handleChangeValue(getSafeValue((val - step).toFixed(bit)), event);
|
|
166
|
+
}, [getSafeValue, handleChangeValue, step, value]);
|
|
167
167
|
var handleWheel = useCallback(function (event) {
|
|
168
168
|
if (!disabled && !readOnly && event.target === document.activeElement) {
|
|
169
169
|
event.preventDefault();
|
|
@@ -185,14 +185,14 @@ var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
}, [
|
|
188
|
+
handleChangeValue(value, event);
|
|
189
|
+
}, [handleChangeValue]);
|
|
190
190
|
var handleBlur = useCallback(function (event) {
|
|
191
191
|
var _event$target;
|
|
192
192
|
|
|
193
193
|
var targetValue = Number.parseFloat((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
|
|
194
|
-
|
|
195
|
-
}, [getSafeValue,
|
|
194
|
+
handleChangeValue(getSafeValue(targetValue), event);
|
|
195
|
+
}, [getSafeValue, handleChangeValue]);
|
|
196
196
|
useEffect(function () {
|
|
197
197
|
var wheelListener;
|
|
198
198
|
|
|
@@ -218,7 +218,8 @@ var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
218
218
|
value: isNil(value) ? '' : "" + value,
|
|
219
219
|
disabled: disabled,
|
|
220
220
|
readOnly: readOnly,
|
|
221
|
-
plaintext: plaintext
|
|
221
|
+
plaintext: plaintext,
|
|
222
|
+
ref: plaintext ? ref : undefined
|
|
222
223
|
}));
|
|
223
224
|
|
|
224
225
|
if (plaintext) {
|
|
@@ -4,17 +4,30 @@ import { PickerComponent } from '../Picker';
|
|
|
4
4
|
import { TagProps } from '../Tag';
|
|
5
5
|
import { ItemDataType, FormControlPickerProps } from '../@types/common';
|
|
6
6
|
import { SelectProps } from '../SelectPicker';
|
|
7
|
+
export declare type TriggerType = 'Enter' | 'Space' | 'Comma';
|
|
8
|
+
export interface InputPickerContextProps {
|
|
9
|
+
/** Multiple selections are allowed */
|
|
10
|
+
multi?: boolean;
|
|
11
|
+
/** Tag related props. */
|
|
12
|
+
tagProps?: TagProps;
|
|
13
|
+
/**
|
|
14
|
+
* Set the trigger for creating tags. only valid when creatable
|
|
15
|
+
*/
|
|
16
|
+
trigger?: TriggerType | TriggerType[];
|
|
17
|
+
/**
|
|
18
|
+
* No overlay provides options
|
|
19
|
+
*/
|
|
20
|
+
disabledOptions?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const InputPickerContext: React.Context<InputPickerContextProps>;
|
|
7
23
|
interface InputItemDataType extends ItemDataType {
|
|
8
24
|
create?: boolean;
|
|
9
25
|
}
|
|
10
26
|
export declare type ValueType = any;
|
|
11
27
|
export interface InputPickerProps<T = ValueType> extends FormControlPickerProps<T, InputPickerLocale, InputItemDataType>, SelectProps<T> {
|
|
12
28
|
tabIndex?: number;
|
|
13
|
-
multi?: boolean;
|
|
14
29
|
/** Settings can create new options */
|
|
15
30
|
creatable?: boolean;
|
|
16
|
-
/** Tag related props. */
|
|
17
|
-
tagProps?: TagProps;
|
|
18
31
|
/** Option to cache value when searching asynchronously */
|
|
19
32
|
cacheData?: InputItemDataType[];
|
|
20
33
|
/** The `onBlur` attribute for the `input` element. */
|