react-ui-basics 0.0.250 → 0.0.252

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-ui-basics",
3
- "version": "0.0.250",
3
+ "version": "0.0.252",
4
4
  "description": "",
5
5
  "module": "index.js",
6
6
  "_main": "index.cjs.js",
@@ -122,19 +122,28 @@ class AutocompleteSelect extends PureComponent {
122
122
  }
123
123
 
124
124
  updateListPosition = () => {
125
- if (__props(this).listPortal && __state(this).isActive) {
126
- var rect = this.el.getBoundingClientRect();
125
+ if (__props(this).listPortal && __state(this).isActive && this.el) {
126
+ const rect = this.el.getBoundingClientRect();
127
+ const listPortal = __props(this).listPortal;
128
+ const portalRect = listPortal.getBoundingClientRect ? listPortal.getBoundingClientRect() : {left: 0, top: 0};
129
+ const scrollLeft = __scrollLeft(listPortal) || 0;
130
+ const scrollTop = __scrollTop(listPortal) || 0;
131
+
132
+ const list = this.list?.el?.el || this.list?.el || this.list;
133
+ const listRect = list?.getBoundingClientRect ? list.getBoundingClientRect() : null;
134
+ const listWidth = (listRect && __width(listRect)) || __width(rect);
135
+
127
136
  let listPortalPosition = __props(this).listPortalPosition;
128
137
  let listStyles = {
129
138
  position: 'absolute',
130
- top: rect.bottom + 'px',
139
+ top: (rect.bottom - __top(portalRect) + scrollTop) + 'px',
131
140
  minWidth: __width(rect) + 'px',
132
141
  maxHeight: '300px',
133
142
  };
134
143
  if (listPortalPosition === 'right')
135
- listStyles.right = (window.innerWidth - rect.right) + 'px'
144
+ listStyles.left = (rect.right - __left(portalRect) + scrollLeft - listWidth) + 'px'
136
145
  else
137
- listStyles.left = __left(rect) + 'px'
146
+ listStyles.left = (__left(rect) - __left(portalRect) + scrollLeft) + 'px'
138
147
 
139
148
  this.setState({
140
149
  listStyles: listStyles
@@ -0,0 +1,103 @@
1
+ import ReactConstants from "./../ReactConstants"; import {clientHeight as __clientHeight, clientWidth as __clientWidth, createAccessor as __createAccessor, data as __data, height as __height, left as __left, length as __length, pageX as __pageX, pageY as __pageY, props as __props, scrollLeft as __scrollLeft, scrollTop as __scrollTop, state as __state, style as __style, target as __target, top as __top, value as __value, width as __width} from "./../CommonFields"; import {toConsumableArray as __toConsumableArray} from "./../_virtual/_rollupPluginBabelHelpers"; import {extends as __extends} from "./../_virtual/_rollupPluginBabelHelpers"; import {inherits as __inherits} from "./../_virtual/_rollupPluginBabelHelpers"; import React from 'react';
2
+ import {mount} from 'enzyme';
3
+ import AutocompleteSelect from "./AutocompleteSelect";
4
+
5
+ describe('AutocompleteSelect listPortal position', () => {
6
+ it('calculates list position with listPortal and scroll when listPortalPosition is left', () => {
7
+ const portal = document.createElement('div');
8
+ portal.scrollTop = 50;
9
+ portal.scrollLeft = 20;
10
+ portal.getBoundingClientRect = () => ({
11
+ top: 100,
12
+ left: 50,
13
+ bottom: 400,
14
+ right: 350,
15
+ width: 300,
16
+ height: 300,
17
+ });
18
+
19
+ const wrapper = mount(
20
+ <AutocompleteSelect
21
+ listPortal={portal}
22
+ data={['item1', 'item2']}
23
+ />
24
+ );
25
+
26
+ const instance = wrapper.instance();
27
+ instance.el.getBoundingClientRect = () => ({
28
+ top: 150,
29
+ bottom: 186,
30
+ left: 80,
31
+ right: 280,
32
+ width: 200,
33
+ height: 36,
34
+ });
35
+
36
+ wrapper.setState({isActive: true});
37
+ instance.updateListPosition();
38
+
39
+ expect(__state(instance).listStyles).toEqual({
40
+ position: 'absolute',
41
+ top: `${186 - 100 + 50}px`, // 136px
42
+ left: `${80 - 50 + 20}px`, // 50px
43
+ minWidth: '200px',
44
+ maxHeight: '300px',
45
+ });
46
+ });
47
+
48
+ it('calculates list position with listPortal and list bounding rect when listPortalPosition is right', () => {
49
+ const portal = document.createElement('div');
50
+ portal.scrollTop = 30;
51
+ portal.scrollLeft = 10;
52
+ portal.getBoundingClientRect = () => ({
53
+ top: 100,
54
+ left: 50,
55
+ bottom: 500,
56
+ right: 450,
57
+ width: 400,
58
+ height: 400,
59
+ });
60
+
61
+ const wrapper = mount(
62
+ <AutocompleteSelect
63
+ listPortal={portal}
64
+ listPortalPosition="right"
65
+ data={['item1', 'item2']}
66
+ />
67
+ );
68
+
69
+ const instance = wrapper.instance();
70
+ instance.el.getBoundingClientRect = () => ({
71
+ top: 150,
72
+ bottom: 186,
73
+ left: 100,
74
+ right: 300,
75
+ width: 200,
76
+ height: 36,
77
+ });
78
+
79
+ // Mock list getBoundingClientRect with width 250
80
+ if (instance.list?.el?.el) {
81
+ instance.list.el.el.getBoundingClientRect = () => ({
82
+ top: 0,
83
+ left: 0,
84
+ bottom: 200,
85
+ right: 250,
86
+ width: 250,
87
+ height: 200,
88
+ });
89
+ }
90
+
91
+ wrapper.setState({isActive: true});
92
+ instance.updateListPosition();
93
+
94
+ // rect.right (300) - __left(portalRect) (50) + scrollLeft (10) - listWidth (250) = 10px
95
+ expect(__state(instance).listStyles).toEqual({
96
+ position: 'absolute',
97
+ top: `${186 - 100 + 30}px`, // 116px
98
+ left: `${300 - 50 + 10 - 250}px`, // 10px
99
+ minWidth: '200px',
100
+ maxHeight: '300px',
101
+ });
102
+ });
103
+ });
@@ -17,7 +17,7 @@ export interface FilteredListProps<T> {
17
17
  selectedProvider?: (cb: () => void) => void
18
18
  data: T[]
19
19
  labels?: Labels<T>
20
- filter?: (item: T) => boolean
20
+ filter?: (item: any, id: T) => boolean
21
21
  className?: string
22
22
  selected?: T | { [key: string]: boolean } | { [key: number]: boolean }
23
23
  inline?: boolean
@@ -99,8 +99,8 @@ class FilteredList<T extends string|number> extends PureComponent<FilteredListPr
99
99
  onMouseEnter={e => this.setState({selected: id})}
100
100
  onMouseLeave={e => id === this.state.selected && this.setState({selected: null})}
101
101
  className={classNames('child', this.state.selected === id && 'active', selected === id || (isObject(selected) && selected[id as (string | number)]) && 'selected')}
102
- classProvider={it => {
103
- const hidden = !filter(it);
102
+ classProvider={(it, id) => {
103
+ const hidden = !filter(it, id);
104
104
  this.hidden.set(id, hidden)
105
105
  return hidden && 'hidden';
106
106
  }}
@@ -191,7 +191,7 @@ interface ItemWrapperProps {
191
191
  onMouseDown?: MouseEventHandler
192
192
  onMouseEnter?: MouseEventHandler
193
193
  onMouseLeave?: MouseEventHandler
194
- classProvider?: (data) => string
194
+ classProvider?: (data, id) => string
195
195
  className?: string
196
196
  childComponent
197
197
  childProps
@@ -211,7 +211,7 @@ class ItemWrapper extends React.Component<ItemWrapperProps> {
211
211
  dataConsumer: (data) => this.data = data,
212
212
  });
213
213
 
214
- const cssClass = orNoop(classProvider)(this.data);
214
+ const cssClass = orNoop(classProvider)(this.data, id);
215
215
  return (
216
216
  <div className={classNames('ItemWrapper', cssClass, className)}
217
217
  onMouseEnter={onMouseEnter}
package/src/Tools.ts CHANGED
@@ -184,7 +184,7 @@ export class Comparators {
184
184
  static SORT_ASC: SortOrder = 'ASC';
185
185
  static SORT_DESC: SortOrder = 'DESC';
186
186
 
187
- static of = <T>(field: SortField<T> | SortField<T>[], order: SortOrder | SortOrder[], data?: T[]): Comparator<T> => {
187
+ static of = <T>(field: SortField<T> | SortField<T>[], order: SortOrder | SortOrder[] = Comparators.SORT_ASC, data?: T[]): Comparator<T> => {
188
188
  let comparator;
189
189
  if (Array.isArray(field)) {
190
190
  const isOrderArray = Array.isArray(order);