@vnejs/plugins.view.coralina.confirm 0.1.0 → 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.
@@ -0,0 +1,11 @@
1
+ export const TRANSITION = 500;
2
+ export const ZINDEX = 9000;
3
+
4
+ export const VIEW_PROPS = {
5
+ screen: { withBlur: true, withDark: true, zIndex: ZINDEX, transition: TRANSITION },
6
+ position: { isCentered: true },
7
+ flex: { direction: "column", gap: 60 },
8
+ flexTitles: { direction: "column", gap: 12 },
9
+ controls: { wrapWidth: 3120, flexGap: 0, flexJustify: "center", textSize: 72, textWidth: 780, textAlign: "center" },
10
+ text: { size: 96, width: 3120, align: "center" },
11
+ };
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
2
 
3
+ import * as params from "./const/params";
4
+
3
5
  import { ConfirmController } from "./modules/controller";
4
6
  import { ConfirmView } from "./modules/view";
5
7
 
6
- regPlugin("CONFIRM_VIEW", {}, [ConfirmController, ConfirmView]);
8
+ regPlugin("CONFIRM_VIEW", { params }, [ConfirmController, ConfirmView]);
@@ -1,7 +1,5 @@
1
1
  import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- import { ZINDEX } from "../view";
4
-
5
3
  export class ConfirmController extends ModuleController {
6
4
  name = "confirm.controller";
7
5
 
@@ -15,7 +13,7 @@ export class ConfirmController extends ModuleController {
15
13
  [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: this.decCurrentItem,
16
14
  [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: this.incCurrentItem,
17
15
  };
18
- controlsIndex = ZINDEX;
16
+ controlsIndex = this.PARAMS.CONFIRM_VIEW.ZINDEX;
19
17
 
20
18
  subscribe = () => {
21
19
  this.on(this.EVENTS.CONFIRM.SHOW, this.onShow);
package/modules/view.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { ModuleView } from "@vnejs/module.components";
2
2
 
3
- import { render, TRANSITION } from "../view";
3
+ import { render } from "../view";
4
4
 
5
5
  export class ConfirmView extends ModuleView {
6
6
  name = "confirm.view";
7
- animationTime = TRANSITION;
8
- renderFunc = render;
7
+
8
+ animationTime = this.PARAMS.CONFIRM_VIEW.TRANSITION;
9
9
  updateEvent = this.EVENTS.CONFIRM.UPDATE;
10
- updateHandler = this.onUpdateReactComponent;
10
+
11
+ renderFunc = render;
12
+ updateHandler = this.onUpdateStoreComponent;
11
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.confirm",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/view/index.jsx CHANGED
@@ -1,81 +1,36 @@
1
- import React from "react";
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
4
  import { Flex, PositionBox, Screen, Text, TextControls } from "@vnejs/uis.base";
5
5
 
6
- export const TRANSITION = 500;
7
- export const ZINDEX = 9000;
6
+ const ConfirmView = ({ store, onMount, ...props } = {}) => {
7
+ const [{ isShow = false, text = "", textAccept = "", textDecline = "", currentItem: selectedIndex = null }, setState] = useState({});
8
+ const [texts, setTexts] = useState([]);
8
9
 
9
- class ConfirmView extends React.Component {
10
- state = { isShow: false, text: "", textAccept: "", textDecline: "", currentItem: null, textsArray: [] };
10
+ useEffect(() => store.subscribe(setState), []);
11
+ useEffect(() => void onMount(), []);
11
12
 
12
- componentDidUpdate(props, state) {
13
- const { textAccept = "", textDecline = "", text = "" } = this.state;
13
+ useEffect(() => void setTexts([textAccept, textDecline].map((text, i) => ({ text, value: i === 0 }))), [textAccept, textDecline]);
14
14
 
15
- if (state.textAccept !== textAccept || state.textDecline !== textDecline || state.text !== text)
16
- this.setState({
17
- textsArray: [
18
- { text: textAccept, value: true },
19
- { text: textDecline, value: false },
20
- ],
21
- });
22
- }
15
+ const onClick = useCallback((isAccept) => props.emit(isAccept ? props.EVENTS.CONFIRM.ACCEPT : props.EVENTS.CONFIRM.DECLINE), []);
23
16
 
24
- onAccept = () => this.props.emit(this.props.EVENTS.CONFIRM.ACCEPT);
25
- onDecline = () => this.props.emit(this.props.EVENTS.CONFIRM.DECLINE);
17
+ const propsView = props.PARAMS.CONFIRM_VIEW.VIEW_PROPS;
26
18
 
27
- renderOneTitle = (text = "", i) => (
28
- <Text
29
- key={i}
30
- text={text}
31
- size={96}
32
- width={3120}
33
- align={Text.ALIGNS.CENTER}
34
- />
35
- );
36
-
37
- onClick = (isAccept) => (isAccept ? this.onAccept() : this.onDecline());
19
+ const propsScreen = useMemo(() => ({ ...propsView.screen, isShow }), [isShow]);
20
+ const propsControls = useMemo(() => ({ ...propsView.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
38
21
 
39
- render() {
40
- const { isShow = false, text = "", textsArray = [], currentItem = null } = this.state;
22
+ const renderedTitle = useMemo(() => (text || "").split("\n").map((text = "", i) => <Text {...{ ...propsView.text, key: i, text }} />), [text]);
41
23
 
42
- const titles = (text || "").split("\n");
43
-
44
- return (
45
- <Screen
46
- zIndex={ZINDEX}
47
- isShow={isShow}
48
- withBlur={true}
49
- withDark={true}
50
- transition={TRANSITION}
51
- >
52
- <PositionBox isCentered={true}>
53
- <Flex
54
- direction={Flex.DIRECTION.COLUMN}
55
- gap={60}
56
- >
57
- <Flex
58
- direction={Flex.DIRECTION.COLUMN}
59
- gap={12}
60
- >
61
- {titles.map(this.renderOneTitle)}
62
- </Flex>
63
- <TextControls
64
- selectedIndex={currentItem}
65
- wrapWidth={3120}
66
- flexGap={0}
67
- flexJustify={Flex.JUSTIFY.CENTER}
68
- textSize={72}
69
- textWidth={780}
70
- textAlign={Text.ALIGNS.CENTER}
71
- texts={textsArray}
72
- onClick={this.onClick}
73
- />
74
- </Flex>
75
- </PositionBox>
76
- </Screen>
77
- );
78
- }
79
- }
24
+ return (
25
+ <Screen {...propsScreen}>
26
+ <PositionBox {...propsView.position}>
27
+ <Flex {...propsView.flex}>
28
+ <Flex {...propsView.flexTitles}>{renderedTitle}</Flex>
29
+ <TextControls {...propsControls} />
30
+ </Flex>
31
+ </PositionBox>
32
+ </Screen>
33
+ );
34
+ };
80
35
 
81
- export const render = (props, root, resolve) => ReactDOM.render(<ConfirmView {...props} />, root, resolve);
36
+ export const render = (props, root) => ReactDOM.render(<ConfirmView {...props} />, root);