@vnejs/plugins.view.coralina.confirm 0.1.0 → 0.1.1
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 +11 -0
- package/index.js +3 -1
- package/modules/controller.js +1 -3
- package/modules/view.js +6 -4
- package/package.json +1 -1
- package/view/index.jsx +24 -69
package/const/params.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const TRANSITION = 500;
|
|
2
|
+
export const ZINDEX = 9000;
|
|
3
|
+
|
|
4
|
+
export const VIEW_PROPS = {
|
|
5
|
+
screen: { withBackgroundBlur: true, withBackgroundDark: 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]);
|
package/modules/controller.js
CHANGED
|
@@ -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
|
|
3
|
+
import { render } from "../view";
|
|
4
4
|
|
|
5
5
|
export class ConfirmView extends ModuleView {
|
|
6
6
|
name = "confirm.view";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
animationTime = this.PARAMS.CONFIRM_VIEW.TRANSITION;
|
|
9
9
|
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
renderFunc = render;
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
11
13
|
}
|
package/package.json
CHANGED
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
10
|
+
useEffect(() => store.subscribe(setState), []);
|
|
11
|
+
useEffect(() => void onMount(), []);
|
|
11
12
|
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
onDecline = () => this.props.emit(this.props.EVENTS.CONFIRM.DECLINE);
|
|
17
|
+
const propsView = props.PARAMS.CONFIRM_VIEW.VIEW_PROPS;
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
36
|
+
export const render = (props, root) => ReactDOM.render(<ConfirmView {...props} />, root);
|