rsuite 4.10.0 → 4.10.4

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.
Files changed (140) hide show
  1. package/CHANGELOG.md +51 -5
  2. package/dist/rsuite.js +65 -172
  3. package/dist/rsuite.min.js +2 -2
  4. package/dist/rsuite.min.js.map +1 -1
  5. package/es/AutoComplete/AutoComplete.js +1 -1
  6. package/es/Avatar/Avatar.js +1 -2
  7. package/es/Breadcrumb/Breadcrumb.js +1 -2
  8. package/es/Button/Button.js +1 -2
  9. package/es/ButtonGroup/ButtonGroup.js +1 -2
  10. package/es/Calendar/TimeDropdown.js +3 -3
  11. package/es/Cascader/Cascader.js +23 -6
  12. package/es/CheckTreePicker/CheckTreePicker.js +8 -7
  13. package/es/Drawer/index.js +1 -2
  14. package/es/Dropdown/Dropdown.js +1 -2
  15. package/es/FlexboxGrid/FlexboxGrid.js +1 -2
  16. package/es/FormGroup/FormGroup.js +1 -2
  17. package/es/Input/Input.js +1 -2
  18. package/es/InputGroup/InputGroup.js +1 -2
  19. package/es/IntlProvider/withLocale.js +1 -1
  20. package/es/List/List.js +1 -2
  21. package/es/List/ListItem.js +1 -2
  22. package/es/Loader/Loader.js +1 -2
  23. package/es/Modal/Modal.js +1 -2
  24. package/es/Modal/ModalDialog.js +1 -2
  25. package/es/MultiCascader/MultiCascader.js +14 -1
  26. package/es/Nav/Nav.js +1 -2
  27. package/es/Navbar/Navbar.js +1 -2
  28. package/es/Overlay/OverlayTrigger.d.ts +1 -1
  29. package/es/Overlay/OverlayTrigger.js +12 -1
  30. package/es/Pagination/Pagination.js +1 -2
  31. package/es/Rate/Rate.js +1 -2
  32. package/es/Sidenav/Sidenav.js +1 -2
  33. package/es/Slider/Slider.d.ts +4 -11
  34. package/es/Steps/Steps.js +1 -2
  35. package/es/Table/Table.js +1 -2
  36. package/es/Table/TablePagination.js +1 -2
  37. package/es/Tag/Tag.js +1 -2
  38. package/es/TagPicker/index.js +1 -2
  39. package/es/Timeline/Timeline.js +1 -2
  40. package/es/Timeline/TimelineItem.js +1 -2
  41. package/es/Toggle/Toggle.js +1 -2
  42. package/es/Uploader/Uploader.js +1 -2
  43. package/es/utils/defaultProps.js +1 -1
  44. package/es/utils/index.js +1 -0
  45. package/es/utils/recompose.js +42 -0
  46. package/es/utils/treeUtils.js +5 -1
  47. package/es/utils/withStyleProps.js +1 -1
  48. package/lib/AutoComplete/AutoComplete.js +2 -4
  49. package/lib/Avatar/Avatar.js +1 -3
  50. package/lib/Breadcrumb/Breadcrumb.js +1 -3
  51. package/lib/Button/Button.js +1 -3
  52. package/lib/ButtonGroup/ButtonGroup.js +1 -3
  53. package/lib/Calendar/TimeDropdown.js +3 -3
  54. package/lib/Cascader/Cascader.js +23 -6
  55. package/lib/CheckTreePicker/CheckTreePicker.js +8 -7
  56. package/lib/Drawer/index.js +4 -6
  57. package/lib/Dropdown/Dropdown.js +2 -4
  58. package/lib/FlexboxGrid/FlexboxGrid.js +1 -3
  59. package/lib/FormGroup/FormGroup.js +1 -3
  60. package/lib/Input/Input.js +1 -3
  61. package/lib/InputGroup/InputGroup.js +3 -5
  62. package/lib/IntlProvider/withLocale.js +3 -3
  63. package/lib/List/List.js +1 -3
  64. package/lib/List/ListItem.js +1 -3
  65. package/lib/Loader/Loader.js +1 -3
  66. package/lib/Modal/Modal.js +5 -7
  67. package/lib/Modal/ModalDialog.js +1 -3
  68. package/lib/MultiCascader/MultiCascader.js +14 -1
  69. package/lib/Nav/Nav.js +1 -3
  70. package/lib/Navbar/Navbar.js +2 -4
  71. package/lib/Overlay/OverlayTrigger.d.ts +1 -1
  72. package/lib/Overlay/OverlayTrigger.js +12 -1
  73. package/lib/Pagination/Pagination.js +1 -3
  74. package/lib/Rate/Rate.js +1 -3
  75. package/lib/Sidenav/Sidenav.js +3 -5
  76. package/lib/Slider/Slider.d.ts +4 -11
  77. package/lib/Steps/Steps.js +1 -3
  78. package/lib/Table/Table.js +6 -8
  79. package/lib/Table/TablePagination.js +1 -3
  80. package/lib/Tag/Tag.js +1 -3
  81. package/lib/TagPicker/index.js +1 -3
  82. package/lib/Timeline/Timeline.js +1 -3
  83. package/lib/Timeline/TimelineItem.js +1 -3
  84. package/lib/Toggle/Toggle.js +1 -3
  85. package/lib/Uploader/Uploader.js +1 -3
  86. package/lib/utils/defaultProps.js +1 -1
  87. package/lib/utils/index.js +8 -0
  88. package/lib/utils/recompose.js +57 -0
  89. package/lib/utils/treeUtils.js +5 -1
  90. package/lib/utils/withStyleProps.js +1 -1
  91. package/package.json +5 -6
  92. package/src/AutoComplete/AutoComplete.tsx +1 -1
  93. package/src/Avatar/Avatar.tsx +1 -2
  94. package/src/Breadcrumb/Breadcrumb.tsx +1 -2
  95. package/src/Button/Button.tsx +8 -2
  96. package/src/ButtonGroup/ButtonGroup.tsx +1 -2
  97. package/src/Calendar/TimeDropdown.tsx +2 -3
  98. package/src/Cascader/Cascader.tsx +24 -5
  99. package/src/Cascader/test/CascaderSpec.js +56 -1
  100. package/src/CheckTreePicker/CheckTreePicker.tsx +15 -7
  101. package/src/CheckTreePicker/test/CheckTreePickerSpec.js +184 -1
  102. package/src/DatePicker/test/DatePickerSpec.js +20 -0
  103. package/src/Drawer/index.tsx +1 -3
  104. package/src/Dropdown/Dropdown.tsx +1 -1
  105. package/src/FlexboxGrid/FlexboxGrid.tsx +1 -2
  106. package/src/FormGroup/FormGroup.tsx +1 -2
  107. package/src/Input/Input.tsx +1 -1
  108. package/src/InputGroup/InputGroup.tsx +1 -2
  109. package/src/IntlProvider/withLocale.tsx +1 -1
  110. package/src/List/List.tsx +1 -2
  111. package/src/List/ListItem.tsx +1 -2
  112. package/src/Loader/Loader.tsx +1 -2
  113. package/src/Modal/Modal.tsx +1 -2
  114. package/src/Modal/ModalDialog.tsx +1 -2
  115. package/src/MultiCascader/MultiCascader.tsx +17 -1
  116. package/src/Nav/Nav.tsx +1 -1
  117. package/src/Navbar/Navbar.tsx +1 -2
  118. package/src/Overlay/OverlayTrigger.d.ts +1 -1
  119. package/src/Overlay/OverlayTrigger.tsx +22 -1
  120. package/src/Overlay/test/OverlayTriggerSpec.js +155 -0
  121. package/src/Pagination/Pagination.tsx +1 -2
  122. package/src/Rate/Rate.tsx +1 -2
  123. package/src/Sidenav/Sidenav.tsx +1 -2
  124. package/src/Slider/Slider.d.ts +4 -11
  125. package/src/Steps/Steps.tsx +1 -2
  126. package/src/Table/Table.tsx +1 -2
  127. package/src/Table/TablePagination.tsx +1 -2
  128. package/src/Tag/Tag.tsx +1 -2
  129. package/src/TagPicker/index.tsx +1 -3
  130. package/src/Timeline/Timeline.tsx +1 -2
  131. package/src/Timeline/TimelineItem.tsx +1 -2
  132. package/src/Toggle/Toggle.tsx +1 -2
  133. package/src/TreePicker/test/TreePickerSpec.js +43 -15
  134. package/src/Uploader/Uploader.tsx +1 -2
  135. package/src/utils/defaultProps.ts +1 -1
  136. package/src/utils/index.ts +1 -0
  137. package/src/utils/recompose.ts +52 -0
  138. package/src/utils/test/recomposeSpec.js +107 -0
  139. package/src/utils/treeUtils.ts +4 -1
  140. package/src/utils/withStyleProps.tsx +1 -1
@@ -80,6 +80,8 @@ class MultiCascader extends React.Component<MultiCascaderProps, MultiCascaderSta
80
80
  menuContainerRef: React.RefObject<any>;
81
81
  positionRef: React.RefObject<any>;
82
82
  triggerRef: React.RefObject<any>;
83
+ toggleRef: React.RefObject<any>;
84
+
83
85
  constructor(props) {
84
86
  super(props);
85
87
 
@@ -115,6 +117,7 @@ class MultiCascader extends React.Component<MultiCascaderProps, MultiCascaderSta
115
117
  this.menuContainerRef = React.createRef();
116
118
  this.positionRef = React.createRef();
117
119
  this.triggerRef = React.createRef();
120
+ this.toggleRef = React.createRef();
118
121
  }
119
122
 
120
123
  static getCascadeState(nextProps: MultiCascaderProps, flattenData: any[], nextValue?: any[]) {
@@ -321,6 +324,13 @@ class MultiCascader extends React.Component<MultiCascaderProps, MultiCascaderSta
321
324
  }
322
325
  return items;
323
326
  }
327
+ getPositionInstance = () => {
328
+ return this.positionRef.current;
329
+ };
330
+
331
+ getToggleInstance = () => {
332
+ return this.toggleRef.current;
333
+ };
324
334
 
325
335
  renderSearchRow = (item: any, key: number) => {
326
336
  const { labelKey, valueKey, cascade, disabledItemValues = [] } = this.props;
@@ -422,7 +432,12 @@ class MultiCascader extends React.Component<MultiCascaderProps, MultiCascaderSta
422
432
  const menuProps = _.pick(this.props, Object.keys(dropdownMenuPropTypes));
423
433
 
424
434
  return (
425
- <MenuWrapper className={classes} style={menuStyle}>
435
+ <MenuWrapper
436
+ className={classes}
437
+ style={menuStyle}
438
+ getToggleInstance={this.getToggleInstance}
439
+ getPositionInstance={this.getPositionInstance}
440
+ >
426
441
  {searchable && (
427
442
  <SearchBar
428
443
  placeholder={locale.searchPlaceholder}
@@ -533,6 +548,7 @@ class MultiCascader extends React.Component<MultiCascaderProps, MultiCascaderSta
533
548
  >
534
549
  <PickerToggle
535
550
  {...unhandled}
551
+ ref={this.toggleRef}
536
552
  componentClass={toggleComponentClass}
537
553
  onClean={createChainedFunction(this.handleClean, onClean)}
538
554
  cleanable={cleanable && !disabled}
package/src/Nav/Nav.tsx CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { setStatic } from 'recompose';
5
4
  import shallowEqual from '../utils/shallowEqual';
6
5
 
7
6
  import NavItem from './NavItem';
8
7
  import {
8
+ setStatic,
9
9
  prefix,
10
10
  getUnhandledProps,
11
11
  defaultProps,
@@ -1,10 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { setStatic } from 'recompose';
5
4
  import NavbarBody from './NavbarBody';
6
5
  import NavbarHeader from './NavbarHeader';
7
- import { prefix, defaultProps, createContext } from '../utils';
6
+ import { setStatic, prefix, defaultProps, createContext } from '../utils';
8
7
  import { NavbarProps } from './Navbar.d';
9
8
 
10
9
  export const NavbarContext = createContext(null);
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { AnimationEventProps, StandardProps, TypeAttributes } from '../@types/common';
3
3
 
4
- export type OverlayTriggerTrigger = 'click' | 'hover' | 'focus' | 'active' | 'none';
4
+ export type OverlayTriggerTrigger = 'click' | 'contextMenu' | 'hover' | 'focus' | 'active' | 'none';
5
5
 
6
6
  export interface TriggerProps extends AnimationEventProps, StandardProps {
7
7
  /** Triggering events */
@@ -26,6 +26,7 @@ interface TriggerProps {
26
26
  onMouseOut?: React.MouseEventHandler;
27
27
  onBlur?: React.MouseEventHandler;
28
28
  onClick?: React.MouseEventHandler;
29
+ onContextMenu?: React.MouseEventHandler;
29
30
  onFocus?: React.MouseEventHandler;
30
31
  }
31
32
 
@@ -81,7 +82,11 @@ class OverlayTrigger extends React.Component<OverlayTriggerProps, OverlayTrigger
81
82
  handleSpeakerMouseLeave = () => {
82
83
  const { trigger } = this.props;
83
84
  this.mouseEnteredToSpeaker = false;
84
- if (!isOneOf('click', trigger) && !isOneOf('active', trigger)) {
85
+ if (
86
+ !isOneOf('click', trigger) &&
87
+ !isOneOf('active', trigger) &&
88
+ !isOneOf('contextMenu', trigger)
89
+ ) {
85
90
  this.hideWithCheck();
86
91
  }
87
92
  };
@@ -130,6 +135,10 @@ class OverlayTrigger extends React.Component<OverlayTriggerProps, OverlayTrigger
130
135
  }
131
136
  };
132
137
 
138
+ preventDefault = (event: React.MouseEvent<Element, MouseEvent>) => {
139
+ event.preventDefault();
140
+ };
141
+
133
142
  handleDelayedShow = () => {
134
143
  const { delayShow, enterable } = this.props;
135
144
  const delay = isNil(delayShow) ? this.props.delay : delayShow;
@@ -197,6 +206,8 @@ class OverlayTrigger extends React.Component<OverlayTriggerProps, OverlayTrigger
197
206
 
198
207
  if (isOneOf('click', trigger)) {
199
208
  overlayProps.onHide = createChainedFunction(this.hide, onHide);
209
+ } else if (isOneOf('contextMenu', trigger)) {
210
+ overlayProps.onHide = createChainedFunction(this.hide, onHide);
200
211
  } else if (isOneOf('active', trigger)) {
201
212
  overlayProps.onHide = createChainedFunction(this.hide, onHide);
202
213
  }
@@ -228,6 +239,7 @@ class OverlayTrigger extends React.Component<OverlayTriggerProps, OverlayTrigger
228
239
  children,
229
240
  speaker,
230
241
  onClick,
242
+ onContextMenu,
231
243
  trigger,
232
244
  onMouseOver,
233
245
  onMouseOut,
@@ -254,6 +266,15 @@ class OverlayTrigger extends React.Component<OverlayTriggerProps, OverlayTrigger
254
266
  props.onClick = createChainedFunction(this.toggleHideAndShow, props.onClick);
255
267
  }
256
268
 
269
+ if (isOneOf('contextMenu', trigger)) {
270
+ props.onContextMenu = createChainedFunction(
271
+ this.preventDefault,
272
+ this.toggleHideAndShow,
273
+ triggerProps.onContextMenu,
274
+ onContextMenu
275
+ );
276
+ }
277
+
257
278
  if (isOneOf('active', trigger)) {
258
279
  props.onClick = createChainedFunction(this.handleDelayedShow, props.onClick);
259
280
  }
@@ -0,0 +1,155 @@
1
+ import React from 'react';
2
+ import ReactTestUtils from 'react-dom/test-utils';
3
+ import { getDOMNode } from '@test/testUtils';
4
+
5
+ import OverlayTrigger from '../OverlayTrigger';
6
+ import Tooltip from '../../Tooltip';
7
+
8
+ describe('OverlayTrigger', () => {
9
+ it('Should create Whisper element', () => {
10
+ const instance = getDOMNode(
11
+ <OverlayTrigger speaker={<Tooltip>tooltip</Tooltip>}>
12
+ <button type="button">button</button>
13
+ </OverlayTrigger>
14
+ );
15
+ assert.equal(instance.nodeName, 'BUTTON');
16
+ });
17
+
18
+ it('Should maintain overlay classname when trigger click', () => {
19
+ const whisper = getDOMNode(
20
+ <OverlayTrigger
21
+ trigger="click"
22
+ speaker={<Tooltip className="test-whisper_click">test</Tooltip>}
23
+ >
24
+ <button>button</button>
25
+ </OverlayTrigger>
26
+ );
27
+ ReactTestUtils.Simulate.click(whisper);
28
+ assert.equal(document.getElementsByClassName('test-whisper_click').length, 1);
29
+ });
30
+
31
+ it('Should maintain overlay classname when trigger contextMenu', () => {
32
+ const whisper = getDOMNode(
33
+ <OverlayTrigger
34
+ trigger="contextMenu"
35
+ speaker={<Tooltip className="test-whisper_context-menu">test</Tooltip>}
36
+ >
37
+ <button>button</button>
38
+ </OverlayTrigger>
39
+ );
40
+ ReactTestUtils.Simulate.contextMenu(whisper);
41
+ assert.equal(document.getElementsByClassName('test-whisper_context-menu').length, 1);
42
+ });
43
+
44
+ it('Should maintain overlay classname when trigger focus', () => {
45
+ const whisper = getDOMNode(
46
+ <OverlayTrigger
47
+ trigger="focus"
48
+ speaker={<Tooltip className="test-whisper_focus">test</Tooltip>}
49
+ >
50
+ <button>button</button>
51
+ </OverlayTrigger>
52
+ );
53
+
54
+ ReactTestUtils.Simulate.focus(whisper);
55
+ assert.equal(document.getElementsByClassName('test-whisper_focus').length, 1);
56
+ });
57
+
58
+ it('Should maintain overlay classname when trigger mouseOver and setting [trigger="hover"]', () => {
59
+ const whisper = getDOMNode(
60
+ <OverlayTrigger
61
+ trigger="hover"
62
+ speaker={<Tooltip className="test-whisper_hover">test</Tooltip>}
63
+ >
64
+ <button>button</button>
65
+ </OverlayTrigger>
66
+ );
67
+
68
+ ReactTestUtils.Simulate.mouseOver(whisper);
69
+ assert.equal(document.getElementsByClassName('test-whisper_hover').length, 1);
70
+ });
71
+
72
+ it('Should maintain overlay classname when trigger click and setting [trigger="active"] ', () => {
73
+ const whisper = getDOMNode(
74
+ <OverlayTrigger
75
+ trigger="active"
76
+ speaker={<Tooltip className="test-whisper_active">test</Tooltip>}
77
+ >
78
+ <button>button</button>
79
+ </OverlayTrigger>
80
+ );
81
+
82
+ ReactTestUtils.Simulate.click(whisper);
83
+ assert.equal(document.getElementsByClassName('test-whisper_active').length, 1);
84
+ });
85
+
86
+ it('Should call onClick callback', done => {
87
+ const doneOp = () => {
88
+ done();
89
+ };
90
+
91
+ const whisper = getDOMNode(
92
+ <OverlayTrigger onClick={doneOp} trigger="click" speaker={<Tooltip />}>
93
+ <button>button</button>
94
+ </OverlayTrigger>
95
+ );
96
+
97
+ ReactTestUtils.Simulate.click(whisper);
98
+ });
99
+
100
+ it('Should call onContextMenu callback', done => {
101
+ const doneOp = () => {
102
+ done();
103
+ };
104
+
105
+ const whisper = getDOMNode(
106
+ <OverlayTrigger onContextMenu={doneOp} trigger="contextMenu" speaker={<Tooltip />}>
107
+ <button>button</button>
108
+ </OverlayTrigger>
109
+ );
110
+
111
+ ReactTestUtils.Simulate.contextMenu(whisper);
112
+ });
113
+
114
+ it('Should call onFocus callback', done => {
115
+ const doneOp = () => {
116
+ done();
117
+ };
118
+
119
+ const whisper = getDOMNode(
120
+ <OverlayTrigger onFocus={doneOp} trigger="focus" speaker={<Tooltip />}>
121
+ <button>button</button>
122
+ </OverlayTrigger>
123
+ );
124
+
125
+ ReactTestUtils.Simulate.focus(whisper);
126
+ });
127
+
128
+ it('Should call onMouseOver callback', done => {
129
+ const doneOp = () => {
130
+ done();
131
+ };
132
+
133
+ const whisper = getDOMNode(
134
+ <OverlayTrigger onMouseOver={doneOp} trigger="hover" speaker={<Tooltip />}>
135
+ <button>button</button>
136
+ </OverlayTrigger>
137
+ );
138
+
139
+ ReactTestUtils.Simulate.mouseOver(whisper);
140
+ });
141
+
142
+ it('Should call onMouseOut callback', done => {
143
+ const doneOp = () => {
144
+ done();
145
+ };
146
+
147
+ const whisper = getDOMNode(
148
+ <OverlayTrigger onMouseOut={doneOp} trigger="hover" speaker={<Tooltip />}>
149
+ <button>button</button>
150
+ </OverlayTrigger>
151
+ );
152
+
153
+ ReactTestUtils.Simulate.mouseOut(whisper);
154
+ });
155
+ });
@@ -1,12 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { compose } from 'recompose';
5
4
  import PaginationButton from './PaginationButton';
6
5
  import SafeAnchor from '../SafeAnchor';
7
6
  import Icon from '../Icon';
8
7
 
9
- import { withStyleProps, defaultProps, getUnhandledProps } from '../utils';
8
+ import { compose, withStyleProps, defaultProps, getUnhandledProps } from '../utils';
10
9
  import { PAGINATION_ICON_NAMES } from '../constants';
11
10
  import { PaginationProps } from './Pagination.d';
12
11
 
package/src/Rate/Rate.tsx CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { compose } from 'recompose';
5
4
 
6
- import { defaultProps, prefix, getUnhandledProps, withStyleProps } from '../utils';
5
+ import { compose, defaultProps, prefix, getUnhandledProps, withStyleProps } from '../utils';
7
6
  import { transformValueToCharacterMap, transformCharacterMapToValue } from './utils';
8
7
  import shallowEqualArray from '../utils/shallowEqualArray';
9
8
  import Icon from '../Icon';
@@ -1,14 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { setStatic } from 'recompose';
5
4
  import Transition from '../Animation/Transition';
6
5
  import shallowEqual from '../utils/shallowEqual';
7
6
  import _ from 'lodash';
8
7
  import SidenavBody from './SidenavBody';
9
8
  import SidenavHeader from './SidenavHeader';
10
9
  import SidenavToggle from './SidenavToggle';
11
- import { prefix, defaultProps, getUnhandledProps, createContext } from '../utils';
10
+ import { setStatic, prefix, defaultProps, getUnhandledProps, createContext } from '../utils';
12
11
  import { SidenavProps } from './Sidenav.d';
13
12
 
14
13
  export const SidenavContext = createContext(null);
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
- import { StandardProps } from '../@types/common';
2
+ import { StandardProps, FormControlBaseProps } from '../@types/common';
3
3
 
4
- export interface SliderProps<ValueType = number> extends StandardProps {
4
+ export interface SliderProps<ValueType = number>
5
+ extends StandardProps,
6
+ FormControlBaseProps<ValueType> {
5
7
  /** Minimum value of sliding range */
6
8
  min?: number;
7
9
 
@@ -11,12 +13,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
11
13
  /** Slide the value of one step */
12
14
  step?: number;
13
15
 
14
- /** Value (Controlled) */
15
- value?: ValueType;
16
-
17
- /** Default value */
18
- defaultValue?: ValueType;
19
-
20
16
  /** A css class to apply to the Handle node. */
21
17
  handleClassName?: string;
22
18
 
@@ -44,9 +40,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
44
40
  /** Vertical Slide */
45
41
  vertical?: boolean;
46
42
 
47
- /** Callback function that changes data */
48
- onChange?: (value: ValueType, event: React.MouseEvent) => void;
49
-
50
43
  /** Customize labels on the render ruler */
51
44
  renderMark?: (mark: number) => React.ReactNode;
52
45
  }
@@ -2,10 +2,9 @@ import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import _ from 'lodash';
4
4
  import classNames from 'classnames';
5
- import { setStatic } from 'recompose';
6
5
 
7
6
  import StepItem from './StepItem';
8
- import { prefix, defaultProps, ReactChildren, isIE10 } from '../utils';
7
+ import { setStatic, prefix, defaultProps, ReactChildren, isIE10 } from '../utils';
9
8
  import { StepsProps } from './Steps.d';
10
9
 
11
10
  class Steps extends React.Component<StepsProps> {
@@ -1,7 +1,6 @@
1
- import { setStatic, compose } from 'recompose';
2
1
  import { Table, Column, Cell, HeaderCell, ColumnGroup } from 'rsuite-table';
3
2
 
4
- import { defaultProps } from '../utils';
3
+ import { setStatic, compose, defaultProps } from '../utils';
5
4
  import withLocale from '../IntlProvider/withLocale';
6
5
  import TablePagination from './TablePagination';
7
6
 
@@ -1,13 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { compose } from 'recompose';
5
4
 
6
5
  import Pagination from '../Pagination';
7
6
  import SelectPicker from '../SelectPicker';
8
7
  import Divider from '../Divider';
9
8
 
10
- import { prefix, tplTransform, getUnhandledProps, defaultProps } from '../utils';
9
+ import { compose, prefix, tplTransform, getUnhandledProps, defaultProps } from '../utils';
11
10
  import withLocale from '../IntlProvider/withLocale';
12
11
  import { TablePaginationProps } from './TablePagination.d';
13
12
 
package/src/Tag/Tag.tsx CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classnames from 'classnames';
4
- import { compose } from 'recompose';
5
- import { prefix, withStyleProps, defaultProps } from '../utils';
4
+ import { compose, prefix, withStyleProps, defaultProps } from '../utils';
6
5
  import { TagProps } from './Tag.d';
7
6
 
8
7
  class Tag extends React.Component<TagProps> {
@@ -1,6 +1,4 @@
1
- import { compose } from 'recompose';
2
-
3
- import { defaultProps } from '../utils';
1
+ import { compose, defaultProps } from '../utils';
4
2
  import InputPicker from '../InputPicker/InputPicker';
5
3
  import withLocale from '../IntlProvider/withLocale';
6
4
 
@@ -2,10 +2,9 @@ import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
4
  import _ from 'lodash';
5
- import { setStatic } from 'recompose';
6
5
 
7
6
  import TimelineItem from './TimelineItem';
8
- import { defaultProps, prefix, ReactChildren } from '../utils';
7
+ import { setStatic, defaultProps, prefix, ReactChildren } from '../utils';
9
8
  import { TimelineProps } from './Timeline.d';
10
9
 
11
10
  class Timeline extends React.Component<TimelineProps> {
@@ -1,9 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { compose } from 'recompose';
5
4
 
6
- import { prefix, defaultProps, withStyleProps } from '../utils';
5
+ import { compose, prefix, defaultProps, withStyleProps } from '../utils';
7
6
  import { TimelineItemProps } from './TimelineItem.d';
8
7
 
9
8
  class TimelineItem extends React.Component<TimelineItemProps> {
@@ -1,9 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { compose } from 'recompose';
5
4
 
6
- import { prefix, withStyleProps, defaultProps, getUnhandledProps } from '../utils';
5
+ import { compose, prefix, withStyleProps, defaultProps, getUnhandledProps } from '../utils';
7
6
  import { ToggleProps } from './Toggle.d';
8
7
 
9
8
  interface ToggleState {
@@ -2,13 +2,22 @@ import React from 'react';
2
2
  import ReactTestUtils from 'react-dom/test-utils';
3
3
  import Enzyme, { mount } from 'enzyme';
4
4
  import Adapter from 'enzyme-adapter-react-16';
5
- import { findDOMNode } from 'react-dom';
5
+ import ReactDOM, { findDOMNode } from 'react-dom';
6
6
  import { getDOMNode, getInstance } from '@test/testUtils';
7
7
  import TreePicker from '../TreePicker';
8
8
 
9
9
  Enzyme.configure({ adapter: new Adapter() });
10
+ let container;
10
11
 
11
- export const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
12
+ beforeEach(() => {
13
+ container = document.createElement('div');
14
+ document.body.appendChild(container);
15
+ });
16
+
17
+ afterEach(() => {
18
+ document.body.removeChild(container);
19
+ container = null;
20
+ });
12
21
 
13
22
  const data = [
14
23
  {
@@ -157,7 +166,7 @@ describe('TreePicker', () => {
157
166
  });
158
167
 
159
168
  it('Should call `onChange` callback', done => {
160
- const doneOp = values => {
169
+ const doneOp = () => {
161
170
  done();
162
171
  };
163
172
  const instance = getDOMNode(<TreePicker inline onChange={doneOp} data={data} />);
@@ -243,7 +252,7 @@ describe('TreePicker', () => {
243
252
  });
244
253
 
245
254
  it('Should focus item by keyCode=13 ', done => {
246
- const doneOp = values => {
255
+ const doneOp = () => {
247
256
  done();
248
257
  };
249
258
  const instance = mount(<TreePicker data={data} onChange={doneOp} inline defaultExpandAll />);
@@ -271,8 +280,6 @@ describe('TreePicker', () => {
271
280
  });
272
281
 
273
282
  it('Should load data async', () => {
274
- let activeNode = null;
275
- let layer = 0;
276
283
  const data = [
277
284
  {
278
285
  label: 'Master',
@@ -293,8 +300,6 @@ describe('TreePicker', () => {
293
300
 
294
301
  let newData = [];
295
302
  const mockOnExpand = (node, l, concat) => {
296
- activeNode = node;
297
- layer = l;
298
303
  newData = concat(data, children);
299
304
  };
300
305
 
@@ -391,13 +396,36 @@ describe('TreePicker', () => {
391
396
  assert.ok(list[0].innerText, 'Louisa');
392
397
  });
393
398
 
394
- it('Should call renderValue', () => {
395
- const instance1 = getDOMNode(<TreePicker value="Test" renderValue={() => '1'} />);
396
- const instance2 = getDOMNode(<TreePicker value="Test" renderValue={() => null} />);
397
- const instance3 = getDOMNode(<TreePicker value="Test" renderValue={() => undefined} />);
399
+ it('Should controlled by expandItemValues', () => {
400
+ const TestApp = React.forwardRef((props, ref) => {
401
+ const [expandItemValues, setExpandItemValues] = React.useState();
402
+ const pickerRef = React.useRef();
403
+ React.useImperativeHandle(ref, () => ({
404
+ picker: pickerRef.current,
405
+ setExpandItemValues
406
+ }));
407
+
408
+ return <TreePicker data={data} ref={pickerRef} expandItemValues={expandItemValues} open />;
409
+ });
410
+
411
+ TestApp.displayName = 'TestCheckTreePicker';
412
+
413
+ const ref = React.createRef();
414
+ ReactTestUtils.act(() => {
415
+ ReactDOM.render(<TestApp ref={ref} />, container);
416
+ });
398
417
 
399
- assert.equal(instance1.querySelector('.rs-picker-toggle-value').innerText, '1');
400
- assert.equal(instance2.querySelector('.rs-picker-toggle-placeholder').innerText, 'Select');
401
- assert.equal(instance3.querySelector('.rs-picker-toggle-placeholder').innerText, 'Select');
418
+ assert.equal(
419
+ ref.current.picker.treeViewRef.current.querySelectorAll('.rs-tree-node-expanded').length,
420
+ 0
421
+ );
422
+
423
+ ReactTestUtils.act(() => {
424
+ ref.current.setExpandItemValues(['Master']);
425
+ });
426
+ assert.equal(
427
+ ref.current.picker.treeViewRef.current.querySelectorAll('.rs-tree-node-expanded').length,
428
+ 1
429
+ );
402
430
  });
403
431
  });
@@ -2,13 +2,12 @@ import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
4
  import _ from 'lodash';
5
- import { compose } from 'recompose';
6
5
 
7
6
  import IntlContext from '../IntlProvider/IntlContext';
8
7
  import withLocale from '../IntlProvider/withLocale';
9
8
  import FileItem from './UploadFileItem';
10
9
  import UploadTrigger from './UploadTrigger';
11
- import { prefix, ajaxUpload, defaultProps, getUnhandledProps } from '../utils';
10
+ import { compose, prefix, ajaxUpload, defaultProps, getUnhandledProps } from '../utils';
12
11
  import { getFiles, guid } from './utils';
13
12
  import { UploaderProps, FileType } from './Uploader.d';
14
13
 
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { setDisplayName, wrapDisplayName } from 'recompose';
2
+ import { setDisplayName, wrapDisplayName } from './recompose';
3
3
  import { getClassNamePrefix } from './prefix';
4
4
  import { StandardProps } from '../@types/common';
5
5
  import extendReactStatics from './extendReactStatics';
@@ -3,6 +3,7 @@ export * from './htmlPropsUtils';
3
3
 
4
4
  export { default as withStyleProps } from './withStyleProps';
5
5
 
6
+ export * from './recompose';
6
7
  export { default as prefix, defaultClassPrefix, getClassNamePrefix, globalKey } from './prefix';
7
8
  export { default as createChainedFunction } from './createChainedFunction';
8
9
  export { default as defaultProps } from './defaultProps';
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+
3
+ interface ComponentEnhancer<TInner, TOutter> {
4
+ (component: React.ComponentType<TInner>): React.ComponentClass<TOutter>;
5
+ }
6
+
7
+ export function compose<TInner, TOutter>(...funcs: Function[]): ComponentEnhancer<TInner, TOutter> {
8
+ return funcs.reduce(
9
+ (a, b) => (...args) => a(b(...args)),
10
+ arg => arg
11
+ ) as ComponentEnhancer<TInner, TOutter>;
12
+ }
13
+
14
+ export function setStatic(
15
+ key: string,
16
+ value: any
17
+ ): <T extends React.ComponentType<any>>(component: T) => T {
18
+ return BaseComponent => {
19
+ /* eslint-disable no-param-reassign */
20
+ BaseComponent[key] = value;
21
+ /* eslint-enable no-param-reassign */
22
+ return BaseComponent;
23
+ };
24
+ }
25
+
26
+ export function setDisplayName(
27
+ displayName: string
28
+ ): <T extends React.ComponentType<any>>(component: T) => T {
29
+ return setStatic('displayName', displayName);
30
+ }
31
+
32
+ export function getDisplayName(component: React.ComponentType<any>): string {
33
+ if (typeof component === 'string') {
34
+ return component;
35
+ }
36
+
37
+ if (!component) {
38
+ return undefined;
39
+ }
40
+
41
+ return component.displayName || component.name || 'Component';
42
+ }
43
+
44
+ export function wrapDisplayName(component: React.ComponentType<any>, wrapperName: string): string {
45
+ return `${wrapperName}(${getDisplayName(component)})`;
46
+ }
47
+
48
+ export function setPropTypes<P>(
49
+ propTypes: React.ValidationMap<P>
50
+ ): <T extends React.ComponentType<P>>(component: T) => T {
51
+ return setStatic('propTypes', propTypes);
52
+ }