rsuite 4.10.1 → 4.10.5

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 (133) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/rsuite.js +52 -159
  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/Pagination/Pagination.js +1 -2
  29. package/es/Rate/Rate.js +1 -2
  30. package/es/Sidenav/Sidenav.js +1 -2
  31. package/es/Slider/Slider.d.ts +4 -11
  32. package/es/Steps/Steps.js +1 -2
  33. package/es/Table/Table.js +1 -2
  34. package/es/Table/TablePagination.js +1 -2
  35. package/es/Tag/Tag.js +1 -2
  36. package/es/TagPicker/index.js +1 -2
  37. package/es/Timeline/Timeline.js +1 -2
  38. package/es/Timeline/TimelineItem.js +1 -2
  39. package/es/Toggle/Toggle.js +1 -2
  40. package/es/Uploader/Uploader.js +2 -3
  41. package/es/utils/defaultProps.js +1 -1
  42. package/es/utils/index.js +1 -0
  43. package/es/utils/recompose.js +42 -0
  44. package/es/utils/treeUtils.js +5 -1
  45. package/es/utils/withStyleProps.js +1 -1
  46. package/lib/AutoComplete/AutoComplete.js +2 -4
  47. package/lib/Avatar/Avatar.js +1 -3
  48. package/lib/Breadcrumb/Breadcrumb.js +1 -3
  49. package/lib/Button/Button.js +1 -3
  50. package/lib/ButtonGroup/ButtonGroup.js +1 -3
  51. package/lib/Calendar/TimeDropdown.js +3 -3
  52. package/lib/Cascader/Cascader.js +23 -6
  53. package/lib/CheckTreePicker/CheckTreePicker.js +8 -7
  54. package/lib/Drawer/index.js +4 -6
  55. package/lib/Dropdown/Dropdown.js +2 -4
  56. package/lib/FlexboxGrid/FlexboxGrid.js +1 -3
  57. package/lib/FormGroup/FormGroup.js +1 -3
  58. package/lib/Input/Input.js +1 -3
  59. package/lib/InputGroup/InputGroup.js +3 -5
  60. package/lib/IntlProvider/withLocale.js +3 -3
  61. package/lib/List/List.js +1 -3
  62. package/lib/List/ListItem.js +1 -3
  63. package/lib/Loader/Loader.js +1 -3
  64. package/lib/Modal/Modal.js +5 -7
  65. package/lib/Modal/ModalDialog.js +1 -3
  66. package/lib/MultiCascader/MultiCascader.js +14 -1
  67. package/lib/Nav/Nav.js +1 -3
  68. package/lib/Navbar/Navbar.js +2 -4
  69. package/lib/Pagination/Pagination.js +1 -3
  70. package/lib/Rate/Rate.js +1 -3
  71. package/lib/Sidenav/Sidenav.js +3 -5
  72. package/lib/Slider/Slider.d.ts +4 -11
  73. package/lib/Steps/Steps.js +1 -3
  74. package/lib/Table/Table.js +6 -8
  75. package/lib/Table/TablePagination.js +1 -3
  76. package/lib/Tag/Tag.js +1 -3
  77. package/lib/TagPicker/index.js +1 -3
  78. package/lib/Timeline/Timeline.js +1 -3
  79. package/lib/Timeline/TimelineItem.js +1 -3
  80. package/lib/Toggle/Toggle.js +1 -3
  81. package/lib/Uploader/Uploader.js +2 -4
  82. package/lib/utils/defaultProps.js +1 -1
  83. package/lib/utils/index.js +8 -0
  84. package/lib/utils/recompose.js +57 -0
  85. package/lib/utils/treeUtils.js +5 -1
  86. package/lib/utils/withStyleProps.js +1 -1
  87. package/package.json +4 -5
  88. package/src/AutoComplete/AutoComplete.tsx +1 -1
  89. package/src/Avatar/Avatar.tsx +1 -2
  90. package/src/Breadcrumb/Breadcrumb.tsx +1 -2
  91. package/src/Button/Button.tsx +8 -2
  92. package/src/ButtonGroup/ButtonGroup.tsx +1 -2
  93. package/src/Calendar/TimeDropdown.tsx +2 -3
  94. package/src/Cascader/Cascader.tsx +24 -5
  95. package/src/Cascader/test/CascaderSpec.js +56 -1
  96. package/src/CheckTreePicker/CheckTreePicker.tsx +15 -7
  97. package/src/CheckTreePicker/test/CheckTreePickerSpec.js +184 -1
  98. package/src/DatePicker/test/DatePickerSpec.js +20 -0
  99. package/src/Drawer/index.tsx +1 -3
  100. package/src/Dropdown/Dropdown.tsx +1 -1
  101. package/src/FlexboxGrid/FlexboxGrid.tsx +1 -2
  102. package/src/FormGroup/FormGroup.tsx +1 -2
  103. package/src/Input/Input.tsx +1 -1
  104. package/src/InputGroup/InputGroup.tsx +1 -2
  105. package/src/IntlProvider/withLocale.tsx +1 -1
  106. package/src/List/List.tsx +1 -2
  107. package/src/List/ListItem.tsx +1 -2
  108. package/src/Loader/Loader.tsx +1 -2
  109. package/src/Modal/Modal.tsx +1 -2
  110. package/src/Modal/ModalDialog.tsx +1 -2
  111. package/src/MultiCascader/MultiCascader.tsx +17 -1
  112. package/src/Nav/Nav.tsx +1 -1
  113. package/src/Navbar/Navbar.tsx +1 -2
  114. package/src/Pagination/Pagination.tsx +1 -2
  115. package/src/Rate/Rate.tsx +1 -2
  116. package/src/Sidenav/Sidenav.tsx +1 -2
  117. package/src/Slider/Slider.d.ts +4 -11
  118. package/src/Steps/Steps.tsx +1 -2
  119. package/src/Table/Table.tsx +1 -2
  120. package/src/Table/TablePagination.tsx +1 -2
  121. package/src/Tag/Tag.tsx +1 -2
  122. package/src/TagPicker/index.tsx +1 -3
  123. package/src/Timeline/Timeline.tsx +1 -2
  124. package/src/Timeline/TimelineItem.tsx +1 -2
  125. package/src/Toggle/Toggle.tsx +1 -2
  126. package/src/TreePicker/test/TreePickerSpec.js +43 -15
  127. package/src/Uploader/Uploader.tsx +2 -3
  128. package/src/utils/defaultProps.ts +1 -1
  129. package/src/utils/index.ts +1 -0
  130. package/src/utils/recompose.ts +52 -0
  131. package/src/utils/test/recomposeSpec.js +107 -0
  132. package/src/utils/treeUtils.ts +4 -1
  133. package/src/utils/withStyleProps.tsx +1 -1
@@ -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,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
 
@@ -285,7 +284,7 @@ class Uploader extends React.Component<UploaderProps, UploaderState> {
285
284
  fileList: nextFileList
286
285
  };
287
286
 
288
- if (nextFile.progress) {
287
+ if (nextFile.progress || nextFile.status === 'error') {
289
288
  const { fileMap } = this.state;
290
289
 
291
290
  fileMap[nextFile.fileKey] = {
@@ -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
+ }
@@ -0,0 +1,107 @@
1
+ // Ref: https://github.com/acdlite/recompose/tree/master/src/packages/recompose/__tests__
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import {
5
+ compose,
6
+ setStatic,
7
+ setDisplayName,
8
+ getDisplayName,
9
+ wrapDisplayName,
10
+ setPropTypes
11
+ } from '../recompose';
12
+
13
+ describe('compose', function() {
14
+ it('composes from right to left', () => {
15
+ const double = x => x * 2;
16
+ const square = x => x * x;
17
+ expect(compose(square)(5)).to.equal(25);
18
+ expect(compose(square, double)(5)).to.equal(100);
19
+ expect(compose(double, square, double)(5)).to.equal(200);
20
+ });
21
+
22
+ it('can be seeded with multiple arguments', () => {
23
+ const square = x => x * x;
24
+ const add = (x, y) => x + y;
25
+ expect(compose(square, add)(1, 2)).to.equal(9);
26
+ });
27
+
28
+ it('returns the identity function if given no arguments', () => {
29
+ expect(compose()(1, 2)).to.equal(1);
30
+ expect(compose()(3)).to.equal(3);
31
+ expect(compose()()).to.equal(undefined);
32
+ });
33
+
34
+ it('the first function if given only one', () => {
35
+ const fn = x => x * x;
36
+ expect(compose(fn)(3)).to.equal(fn(3));
37
+ });
38
+ });
39
+
40
+ describe('setStatic', () => {
41
+ it('sets a static property on the base component', () => {
42
+ const BaseComponent = () => <div />;
43
+ const NewComponent = setStatic('propTypes', { foo: PropTypes.object })(BaseComponent);
44
+
45
+ expect(NewComponent.propTypes).to.eql({
46
+ foo: PropTypes.object
47
+ });
48
+ });
49
+ });
50
+
51
+ describe('setDisplayName', () => {
52
+ it('sets a static property on the base component', () => {
53
+ const BaseComponent = () => <div />;
54
+ const NewComponent = setDisplayName('Foo')(BaseComponent);
55
+ expect(NewComponent.displayName).to.equal('Foo');
56
+ });
57
+ });
58
+
59
+ describe('getDisplayName', () => {
60
+ it('gets the display name of a React component', () => {
61
+ class SomeComponent extends React.Component {
62
+ render() {
63
+ return <div />;
64
+ }
65
+ }
66
+
67
+ class SomeOtherComponent extends React.Component {
68
+ static displayName = 'CustomDisplayName';
69
+ render() {
70
+ return <div />;
71
+ }
72
+ }
73
+
74
+ function YetAnotherComponent() {
75
+ return <div />;
76
+ }
77
+
78
+ expect(getDisplayName(SomeComponent)).to.equal('SomeComponent');
79
+ expect(getDisplayName(SomeOtherComponent)).to.equal('CustomDisplayName');
80
+ expect(getDisplayName(YetAnotherComponent)).to.equal('YetAnotherComponent');
81
+ expect(getDisplayName(() => <div />)).to.equal('Component');
82
+ expect(getDisplayName('div')).to.equal('div');
83
+ });
84
+ });
85
+
86
+ describe('wrapDisplayName', () => {
87
+ it('wraps the display name of a React component with the name of an HoC, Relay-style', () => {
88
+ class SomeComponent extends React.Component {
89
+ render() {
90
+ return <div />;
91
+ }
92
+ }
93
+
94
+ expect(wrapDisplayName(SomeComponent, 'someHoC')).to.equal('someHoC(SomeComponent)');
95
+ });
96
+ });
97
+
98
+ describe('setPropTypes', () => {
99
+ it(' sets a static property on the base component', () => {
100
+ const BaseComponent = () => <div />;
101
+ const NewComponent = setPropTypes({ foo: PropTypes.object })(BaseComponent);
102
+
103
+ expect(NewComponent.propTypes).to.eql({
104
+ foo: PropTypes.object
105
+ });
106
+ });
107
+ });
@@ -123,7 +123,10 @@ export function treeDeprecatedWarning(
123
123
  * @param b
124
124
  */
125
125
  export function compareArray(a: any[], b: any[]) {
126
- return _.isArray(a) && _.isArray(b) && !shallowEqualArray(a, b);
126
+ if (!(_.isArray(a) && _.isArray(b))) {
127
+ return a !== b;
128
+ }
129
+ return !shallowEqualArray(a, b);
127
130
  }
128
131
 
129
132
  /**
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { setDisplayName, wrapDisplayName, setPropTypes } from 'recompose';
4
+ import { setDisplayName, wrapDisplayName, setPropTypes } from './recompose';
5
5
 
6
6
  import { TypeAttributes } from '../@types/common';
7
7
  import prefix from './prefix';