react-ui-basics 0.0.251 → 0.0.253
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/AutocompleteSelect.js +14 -3
- package/AutocompleteSelect.js.map +1 -1
- package/ReadyListener.d.ts +47 -13
- package/ReadyListener.js +9 -4
- package/ReadyListener.js.map +1 -1
- package/Tools.d.ts +1 -1
- package/Tools.js +1 -1
- package/Tools.js.map +1 -1
- package/bundle.css +581 -581
- package/package.json +1 -1
- package/src/AutocompleteSelect.js +14 -5
- package/src/AutocompleteSelect.test.js +103 -0
- package/src/ReadyListener.tsx +17 -7
- package/src/Tools.ts +1 -1
package/package.json
CHANGED
|
@@ -122,19 +122,28 @@ class AutocompleteSelect extends PureComponent {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
updateListPosition = () => {
|
|
125
|
-
if (__props(this).listPortal && __state(this).isActive) {
|
|
126
|
-
|
|
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.
|
|
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
|
+
});
|
package/src/ReadyListener.tsx
CHANGED
|
@@ -5,17 +5,22 @@ import {orNoop} from "./Tools";
|
|
|
5
5
|
|
|
6
6
|
export interface NotReadyIndicatorProps {
|
|
7
7
|
onChange?: (ready: boolean) => void
|
|
8
|
-
render?: (ready: boolean) => JSX.Element | ReactNode
|
|
8
|
+
render?: (ready: boolean, notReadyElements: string[]) => JSX.Element | ReactNode
|
|
9
9
|
children?: ReactNode
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export interface NotReadyProps {
|
|
13
|
+
name?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
interface NotReadyIndicatorState {
|
|
13
17
|
r: boolean
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
export const createReadyListener = () => {
|
|
17
21
|
let indicator,
|
|
18
|
-
count = 0
|
|
22
|
+
count = 0,
|
|
23
|
+
notReadyElements: string[] = [];
|
|
19
24
|
|
|
20
25
|
class NotReadyIndicator extends PureComponent<NotReadyIndicatorProps, NotReadyIndicatorState> {
|
|
21
26
|
constructor(properties) {
|
|
@@ -29,25 +34,30 @@ export const createReadyListener = () => {
|
|
|
29
34
|
ready = state(that).r;
|
|
30
35
|
|
|
31
36
|
if (renderer)
|
|
32
|
-
return renderer(ready);
|
|
37
|
+
return renderer(ready, notReadyElements);
|
|
33
38
|
else
|
|
34
39
|
return (!ready && _props[children]) || null;
|
|
35
40
|
};
|
|
36
41
|
that[componentDidMount] = that[componentDidUpdate] = () => {
|
|
37
|
-
|
|
42
|
+
// console.log('NotReadyIndicator.update.mounted', state(that).r, count)
|
|
43
|
+
orNoop(props(that).onChange)(state(that).r && count === 0);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
class NotReady extends PureComponent {
|
|
43
|
-
constructor(props) {
|
|
48
|
+
class NotReady extends PureComponent<NotReadyProps> {
|
|
49
|
+
constructor(props: NotReadyProps) {
|
|
44
50
|
super(props);
|
|
45
51
|
const that = this;
|
|
52
|
+
count++;
|
|
53
|
+
// console.log('NotReady created')
|
|
46
54
|
that[componentDidMount] = () => {
|
|
47
|
-
|
|
55
|
+
notReadyElements.push(that.props.name || 'unknown')
|
|
48
56
|
setState(indicator, {r: false});
|
|
49
57
|
};
|
|
50
58
|
that[componentWillUnmount] = () => {
|
|
59
|
+
let index = notReadyElements.indexOf(that.props.name || 'unknown')
|
|
60
|
+
notReadyElements.splice(index, 1)
|
|
51
61
|
setState(indicator, {r: --count === 0});
|
|
52
62
|
};
|
|
53
63
|
that[render] = () => null;
|
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);
|