@vnejs/plugins.view.coralina.mainmenu 0.1.1 → 0.1.2
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/modules/view.js +1 -1
- package/package.json +1 -1
- package/view/index.jsx +51 -63
package/modules/view.js
CHANGED
package/package.json
CHANGED
package/view/index.jsx
CHANGED
|
@@ -1,67 +1,55 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
|
|
4
4
|
import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
items={items}
|
|
57
|
-
realItems={realItems}
|
|
58
|
-
currentItem={currentItem}
|
|
59
|
-
locs={locs}
|
|
60
|
-
/>
|
|
61
|
-
</PositionBox>
|
|
62
|
-
</Screen>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const render = (props, root, resolve) => ReactDOM.render(<MainMenu {...props} />, root, resolve);
|
|
6
|
+
const MainMenuControls = (props) => {
|
|
7
|
+
const [texts, setTexts] = useState([]);
|
|
8
|
+
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
9
|
+
|
|
10
|
+
const mapItems = useCallback(({ locKey, isDisabled, isHide }, i) => ({ text: props.locs[locKey], isDisabled, isNotRender: isHide, value: i }), [props.locs]);
|
|
11
|
+
const findSelectedIndex = useCallback((value) => props.realItems[props.currentItem]?.locKey === value?.locKey, [props.realItems, props.currentItem]);
|
|
12
|
+
const onClick = useCallback((index) => props.emit(props.EVENTS.MAINMENU_VIEW.CLICK, { index }), []);
|
|
13
|
+
|
|
14
|
+
useEffect(() => void setTexts(props.items.map(mapItems)), [props.items, mapItems]);
|
|
15
|
+
useEffect(() => void setSelectedIndex(props.items.findIndex(findSelectedIndex)), [props.items, findSelectedIndex]);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<TextControls
|
|
19
|
+
texts={texts}
|
|
20
|
+
onClick={onClick}
|
|
21
|
+
selectedIndex={selectedIndex}
|
|
22
|
+
{...props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.props}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const MainMenu = ({ store, onMount, ...props } = {}) => {
|
|
28
|
+
const [{ isShow = false, items = [], bgSrc = "", currentItem = null, realItems = [], locs = {} }, setState] = useState({});
|
|
29
|
+
|
|
30
|
+
useEffect(() => store.subscribe(setState), []);
|
|
31
|
+
useEffect(() => void onMount(), []);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Screen
|
|
35
|
+
bgSrc={bgSrc}
|
|
36
|
+
isShow={isShow}
|
|
37
|
+
zIndex={props.PARAMS.MAINMENU_VIEW.ZINDEX}
|
|
38
|
+
transition={props.PARAMS.MAINMENU_VIEW.TRANSITION}
|
|
39
|
+
withBackgroundDark={props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.background.withDark}
|
|
40
|
+
withBackgroundBlur={props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.background.withBlur}
|
|
41
|
+
>
|
|
42
|
+
<PositionBox {...props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.position}>
|
|
43
|
+
<MainMenuControls
|
|
44
|
+
{...props}
|
|
45
|
+
items={items}
|
|
46
|
+
realItems={realItems}
|
|
47
|
+
currentItem={currentItem}
|
|
48
|
+
locs={locs}
|
|
49
|
+
/>
|
|
50
|
+
</PositionBox>
|
|
51
|
+
</Screen>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const render = (props, root) => ReactDOM.render(<MainMenu {...props} />, root);
|