@vnejs/plugins.view.coralina.mainmenu 0.1.2 → 0.1.4

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/const/params.js CHANGED
@@ -1,14 +1,10 @@
1
1
  export const BACKGROUND = "Menu/loading";
2
2
 
3
- export const VIEW_PROPS = {
4
- background: { withDark: false, withBlur: false },
5
-
6
- controls: {
7
- position: { bottom: 240, left: 240 },
8
- props: { textSize: 96, flexGap: 60, flexDirection: "column" },
9
- },
10
- };
11
-
12
3
  export const TRANSITION = 500;
13
4
  export const ZINDEX = 3000;
14
5
  export const LOC_LABEL = "mainMenu";
6
+
7
+ export const VIEW_PROPS = {
8
+ screen: { withBackgroundDark: false, withBackgroundBlur: false, zIndex: ZINDEX, transition: TRANSITION },
9
+ controls: { position: { bottom: 240, left: 240 }, props: { textSize: 96, flexGap: 60, flexDirection: "column" } },
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.mainmenu",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/view/index.jsx CHANGED
@@ -1,55 +1,43 @@
1
- import React, { useCallback, useEffect, useState } from "react";
2
- import ReactDOM from "react-dom";
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
3
 
4
4
  import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
5
5
 
6
- const MainMenuControls = (props) => {
7
- const [texts, setTexts] = useState([]);
6
+ const EMPTY_ARRAY = [];
7
+ const EMPTY_OBJ = {};
8
+
9
+ const MainMenuControls = ({ locs = EMPTY_OBJ, currentItem = null, realItems = EMPTY_ARRAY, items = EMPTY_ARRAY, ...props } = EMPTY_OBJ) => {
10
+ const [texts, setTexts] = useState(EMPTY_ARRAY);
8
11
  const [selectedIndex, setSelectedIndex] = useState(-1);
9
12
 
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
+ const mapItems = useCallback(({ locKey, isDisabled, isHide }, i) => ({ text: locs[locKey], isDisabled, isNotRender: isHide, value: i }), [locs]);
14
+ const findSelectedIndex = useCallback((value) => realItems[currentItem]?.locKey === value?.locKey, [realItems, currentItem]);
15
+ const onClick = useCallback((index) => props.emit(props.EVENTS.MAINMENU_VIEW.CLICK, { index }), EMPTY_ARRAY);
13
16
 
14
- useEffect(() => void setTexts(props.items.map(mapItems)), [props.items, mapItems]);
15
- useEffect(() => void setSelectedIndex(props.items.findIndex(findSelectedIndex)), [props.items, findSelectedIndex]);
17
+ useEffect(() => void setTexts(items.map(mapItems)), [items, mapItems]);
18
+ useEffect(() => void setSelectedIndex(items.findIndex(findSelectedIndex)), [items, findSelectedIndex]);
16
19
 
17
- return (
18
- <TextControls
19
- texts={texts}
20
- onClick={onClick}
21
- selectedIndex={selectedIndex}
22
- {...props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.props}
23
- />
24
- );
20
+ const propsControls = useMemo(() => ({ ...props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.props, texts, onClick, selectedIndex }), [texts, selectedIndex]);
21
+
22
+ return <TextControls {...propsControls} />;
25
23
  };
26
24
 
27
- const MainMenu = ({ store, onMount, ...props } = {}) => {
28
- const [{ isShow = false, items = [], bgSrc = "", currentItem = null, realItems = [], locs = {} }, setState] = useState({});
25
+ const MainMenu = ({ store, onMount, ...props } = EMPTY_OBJ) => {
26
+ const [{ isShow = false, items = EMPTY_ARRAY, bgSrc = "", currentItem = null, realItems = EMPTY_ARRAY, locs = EMPTY_OBJ }, setState] = useState(EMPTY_OBJ);
27
+
28
+ useEffect(() => store.subscribe(setState), EMPTY_ARRAY);
29
+ useEffect(() => void onMount(), EMPTY_ARRAY);
29
30
 
30
- useEffect(() => store.subscribe(setState), []);
31
- useEffect(() => void onMount(), []);
31
+ const propsScreen = useMemo(() => ({ ...props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.screen, bgSrc, isShow }), [bgSrc, isShow]);
32
+ const propsControls = useMemo(() => ({ ...props, items, realItems, currentItem, locs }), [items, realItems, currentItem, locs]);
32
33
 
33
34
  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
- >
35
+ <Screen {...propsScreen}>
42
36
  <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
- />
37
+ <MainMenuControls {...propsControls} />
50
38
  </PositionBox>
51
39
  </Screen>
52
40
  );
53
41
  };
54
42
 
55
- export const render = (props, root) => ReactDOM.render(<MainMenu {...props} />, root);
43
+ export const render = (props, root) => createRoot(root).render(<MainMenu {...props} />);