@24i/bigscreen-sdk 1.0.22-alpha.2374 → 1.0.22-alpha.2377
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
|
@@ -144,12 +144,16 @@ extends SharedProps<any, any> = SharedProps<any, any>>
|
|
|
144
144
|
if (backward) {
|
|
145
145
|
nextScrollIndex = this.scrollPixelsToIndex(scrollValuePx, backward);
|
|
146
146
|
if (this.lastScrollIndex !== nextScrollIndex) {
|
|
147
|
-
this.
|
|
147
|
+
for (let i = this.lastScrollIndex - 1; i >= nextScrollIndex; i--) {
|
|
148
|
+
this.adjustItemsOffsetsBackward(i);
|
|
149
|
+
}
|
|
148
150
|
}
|
|
149
151
|
} else {
|
|
150
152
|
nextScrollIndex = this.scrollPixelsToIndex(scrollValuePx, backward);
|
|
151
153
|
if (this.lastScrollIndex !== nextScrollIndex) {
|
|
152
|
-
this.
|
|
154
|
+
for (let i = this.lastScrollIndex + 1; i <= nextScrollIndex; i++) {
|
|
155
|
+
this.adjustItemsOffsetsForward(i);
|
|
156
|
+
}
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
159
|
this.lastScrollIndex = nextScrollIndex;
|
|
@@ -9,7 +9,10 @@ sidebar_label: Modal Service
|
|
|
9
9
|
A component which helps managing modal windows. Handles rendering and focus management.
|
|
10
10
|
|
|
11
11
|
## Props
|
|
12
|
-
- ref - the reference to the modal service instance
|
|
12
|
+
- ```ref``` - the reference to the modal service instance
|
|
13
|
+
- ```className``` - custom class name for modal service div
|
|
14
|
+
- ```isFocusable``` - whether is modal focusable or not
|
|
15
|
+
- ```onCloseLastModal``` - function called when the last modal is closed
|
|
13
16
|
|
|
14
17
|
## Provided functionality
|
|
15
18
|
- exports interface which needs to be implemented by the modal component
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Component, createRef, Reference, clearNode } from '@24i/bigscreen-sdk/jsx';
|
|
1
|
+
import { Component, createRef, Reference, clearNode, DeclareProps } from '@24i/bigscreen-sdk/jsx';
|
|
2
2
|
import {
|
|
3
3
|
setActiveElementAsFocusCandidate, focusCandidate, refocusAfterHashChange,
|
|
4
4
|
} from '@24i/bigscreen-sdk/focus';
|
|
5
|
+
import { noop } from '@24i/bigscreen-sdk/utils';
|
|
5
6
|
import { IModal } from './IModal';
|
|
6
7
|
import './ModalService.styles';
|
|
7
8
|
|
|
8
9
|
type Props = {
|
|
9
10
|
className?: string;
|
|
10
11
|
isFocusable?: boolean;
|
|
12
|
+
onCloseLastModal?: Function,
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
type RenderFunction = (ref:Reference) => JSX.Element;
|
|
@@ -24,8 +26,11 @@ export class ModalService extends Component<Props> {
|
|
|
24
26
|
static defaultProps = {
|
|
25
27
|
className: '',
|
|
26
28
|
isFocusable: true,
|
|
29
|
+
onCloseLastModal: noop,
|
|
27
30
|
};
|
|
28
31
|
|
|
32
|
+
declare props: DeclareProps<Props, typeof ModalService.defaultProps>;
|
|
33
|
+
|
|
29
34
|
componentDidMount() {
|
|
30
35
|
window.addEventListener('hashchange', this.onHashChange);
|
|
31
36
|
}
|
|
@@ -41,7 +46,7 @@ export class ModalService extends Component<Props> {
|
|
|
41
46
|
};
|
|
42
47
|
|
|
43
48
|
getMountedComponent() {
|
|
44
|
-
return this.modalRef
|
|
49
|
+
return this.modalRef as Reference<IModal>;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
private enqueueModal(modal: RenderFunction) {
|
|
@@ -70,7 +75,7 @@ export class ModalService extends Component<Props> {
|
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
close(ignoreQueue = false) {
|
|
73
|
-
const { isFocusable } = this.props;
|
|
78
|
+
const { isFocusable, onCloseLastModal } = this.props;
|
|
74
79
|
this.openState = false;
|
|
75
80
|
clearNode(this.rootRef);
|
|
76
81
|
if (isFocusable) {
|
|
@@ -78,6 +83,7 @@ export class ModalService extends Component<Props> {
|
|
|
78
83
|
}
|
|
79
84
|
const modalFromQueue = this.dequeueModal();
|
|
80
85
|
if (modalFromQueue && !ignoreQueue) this.open(modalFromQueue);
|
|
86
|
+
if (!this.modalQueue.length) onCloseLastModal();
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
isOpen() {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@24i/bigscreen-sdk/jsx';
|
|
9
9
|
import { filter, forEach } from '@24i/bigscreen-sdk/perf-utils/array';
|
|
10
10
|
import { addClass, removeClass } from '@24i/bigscreen-sdk/utils';
|
|
11
|
+
import { ModalService } from '@24i/bigscreen-sdk/modal-service';
|
|
11
12
|
import { menuService } from '@24i/bigscreen-sdk/menu';
|
|
12
13
|
import { getCurrentHash } from './utils';
|
|
13
14
|
import { IRoute, RouteParams } from './types';
|
|
@@ -31,6 +32,10 @@ export class Route extends Component<Props> {
|
|
|
31
32
|
|
|
32
33
|
component = createRef<IRoute | null>();
|
|
33
34
|
|
|
35
|
+
modalService = createRef<ModalService>();
|
|
36
|
+
|
|
37
|
+
shouldCallReactivateOnCloseModal = false;
|
|
38
|
+
|
|
34
39
|
getParams(): RouteParams {
|
|
35
40
|
const { regexpPath, paramNames } = this.props;
|
|
36
41
|
if (!paramNames || !regexpPath) return {};
|
|
@@ -54,11 +59,34 @@ export class Route extends Component<Props> {
|
|
|
54
59
|
}
|
|
55
60
|
};
|
|
56
61
|
|
|
62
|
+
onCloseModalService = () => {
|
|
63
|
+
if (this.shouldCallReactivateOnCloseModal) {
|
|
64
|
+
this.component.current?.reactivate(this.getParams());
|
|
65
|
+
}
|
|
66
|
+
this.shouldCallReactivateOnCloseModal = false;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
getModalService() {
|
|
70
|
+
if (!this.modalService.current) {
|
|
71
|
+
this.appendMount(
|
|
72
|
+
<ModalService
|
|
73
|
+
ref={this.modalService}
|
|
74
|
+
onCloseLastModal={this.onCloseModalService}
|
|
75
|
+
/>,
|
|
76
|
+
this.domRef,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return this.modalService;
|
|
80
|
+
}
|
|
81
|
+
|
|
57
82
|
show() {
|
|
58
83
|
menuService.addEventListener('visibilitychange', this.onMenuVisibilityChange);
|
|
59
84
|
if (!this.wasCreated) {
|
|
60
85
|
this.mountRoute();
|
|
61
86
|
this.component.current?.activate(this.getParams());
|
|
87
|
+
} else if (this.modalService.current?.isOpen()) {
|
|
88
|
+
this.focusModal();
|
|
89
|
+
this.shouldCallReactivateOnCloseModal = true;
|
|
62
90
|
} else {
|
|
63
91
|
this.component.current?.reactivate(this.getParams());
|
|
64
92
|
}
|
|
@@ -98,9 +126,18 @@ export class Route extends Component<Props> {
|
|
|
98
126
|
}
|
|
99
127
|
}
|
|
100
128
|
|
|
129
|
+
private focusModal() {
|
|
130
|
+
const mountedComponent = this.modalService.current!.getMountedComponent();
|
|
131
|
+
mountedComponent.current?.focus();
|
|
132
|
+
}
|
|
133
|
+
|
|
101
134
|
focus() {
|
|
102
135
|
if (this.wasCreated) {
|
|
103
|
-
this.
|
|
136
|
+
if (this.modalService.current?.isOpen()) {
|
|
137
|
+
this.focusModal();
|
|
138
|
+
} else {
|
|
139
|
+
this.component.current?.focus();
|
|
140
|
+
}
|
|
104
141
|
}
|
|
105
142
|
}
|
|
106
143
|
|