Skip to content

Commit 8894a77

Browse files
committed
feat(react): support open-in functionality with react components router
1 parent 7877e59 commit 8894a77

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/react/shared/components-router.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint no-underscore-dangle: "off" */
22
import { f7events, f7routers } from './f7';
33
import { extend, getComponentId } from './utils';
4+
import { routerOpenIn } from './router-open-in';
45

56
const getChildrenArray = (el) => {
67
const arr = [];
@@ -18,6 +19,9 @@ const hasSameChildren = (childrenBefore, childrenAfter) => {
1819

1920
export default {
2021
proto: {
22+
openIn(router, navigateUrl, options) {
23+
return routerOpenIn(router, navigateUrl, options);
24+
},
2125
pageComponentLoader({ routerEl, component, options, resolve, reject }) {
2226
const router = this;
2327
const routerId = router.id;

src/react/shared/router-open-in.jsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from 'react';
2+
import Popup from '../components/popup';
3+
import View from '../components/view';
4+
import LoginScreen from '../components/login-screen';
5+
import Sheet from '../components/sheet';
6+
import Popover from '../components/popover';
7+
import Panel from '../components/panel';
8+
9+
export const routerOpenIn = (router, url, options) => {
10+
const navigateOptions = {
11+
url,
12+
route: {
13+
path: url,
14+
options: {
15+
...options,
16+
openIn: undefined,
17+
},
18+
},
19+
};
20+
const params = {
21+
...options,
22+
};
23+
24+
if (options.openIn === 'popup') {
25+
params.component = function DynamicPopup() {
26+
return (
27+
<Popup className="popup-router-open-in" data-url={url}>
28+
<View linksView={router.view.selector} url={url} ignoreOpenIn />
29+
</Popup>
30+
);
31+
};
32+
navigateOptions.route.popup = params;
33+
}
34+
if (options.openIn === 'loginScreen') {
35+
params.component = function DynamicPopover() {
36+
return (
37+
<LoginScreen className="login-screen-router-open-in" data-url={url}>
38+
<View linksView={router.view.selector} url={url} ignoreOpenIn />
39+
</LoginScreen>
40+
);
41+
};
42+
navigateOptions.route.loginScreen = params;
43+
}
44+
if (options.openIn === 'sheet') {
45+
params.component = function DynamicSheet() {
46+
return (
47+
<Sheet className="sheet-modal-router-open-in" data-url={url}>
48+
<View linksView={router.view.selector} url={url} ignoreOpenIn />
49+
</Sheet>
50+
);
51+
};
52+
navigateOptions.route.sheet = params;
53+
}
54+
if (options.openIn === 'popover') {
55+
params.targetEl = options.clickedEl || options.targetEl;
56+
params.component = function DynamicPopover() {
57+
return (
58+
<Popover
59+
className="popover-router-open-in"
60+
targetEl={options.clickedEl || options.targetEl}
61+
data-url={url}
62+
>
63+
<View linksView={router.view.selector} url={url} ignoreOpenIn />
64+
</Popover>
65+
);
66+
};
67+
navigateOptions.route.popover = params;
68+
}
69+
if (options.openIn.indexOf('panel') >= 0) {
70+
const parts = options.openIn.split(':');
71+
const side = parts[1] || 'left';
72+
const effect = parts[2] || 'cover';
73+
params.targetEl = options.clickedEl || options.targetEl;
74+
params.component = function DynamicPanel() {
75+
return (
76+
<Panel side={side} effect={effect} className="panel-router-open-in" data-url={url}>
77+
<View linksView={router.view.selector} url={url} ignoreOpenIn />
78+
</Panel>
79+
);
80+
};
81+
navigateOptions.route.panel = params;
82+
}
83+
return router.navigate(navigateOptions);
84+
};

0 commit comments

Comments
 (0)