@vnejs/plugins.view.coralina.confirm 0.0.1 → 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.
@@ -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]);
@@ -1,16 +1,19 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class ConfirmController extends Module.Controller {
3
+ export class ConfirmController extends ModuleController {
4
4
  name = "confirm.controller";
5
5
 
6
+ maxCurrentItem = 1;
7
+
6
8
  updateEvent = this.EVENTS.CONFIRM.UPDATE;
7
9
  controls = {
8
- [this.CONST.CONTROLS.BUTTONS.INTERACT]: () => this.emit(this.EVENTS.CONFIRM.ACCEPT),
10
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: () => this.emit(this.maxCurrentItem === 0 ? this.EVENTS.CONFIRM.ACCEPT : this.EVENTS.CONFIRM.DECLINE),
9
11
  [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.emit(this.EVENTS.CONFIRM.ACCEPT),
10
12
  [this.CONST.CONTROLS.BUTTONS.BACK]: () => this.emit(this.EVENTS.CONFIRM.DECLINE),
11
- [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: () => this.emit(this.EVENTS.CONFIRM.DECLINE),
13
+ [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: this.decCurrentItem,
14
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: this.incCurrentItem,
12
15
  };
13
- controlsIndex = 5000;
16
+ controlsIndex = this.PARAMS.CONFIRM_VIEW.ZINDEX;
14
17
 
15
18
  subscribe = () => {
16
19
  this.on(this.EVENTS.CONFIRM.SHOW, this.onShow);
package/modules/view.js CHANGED
@@ -1,11 +1,13 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleView } from "@vnejs/module.components";
2
2
 
3
3
  import { render } from "../view";
4
4
 
5
- export class ConfirmView extends Module.View {
5
+ export class ConfirmView extends ModuleView {
6
6
  name = "confirm.view";
7
- animationTime = 300;
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,18 +1,17 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.confirm",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major:plugin": "npm run publish:major",
8
+ "publish:minor:plugin": "npm run publish:minor",
9
+ "publish:patch:plugin": "npm run publish:patch",
7
10
  "publish:major": "npm version major && npm publish --access public",
8
11
  "publish:minor": "npm version minor && npm publish --access public",
9
12
  "publish:patch": "npm version patch && npm publish --access public"
10
13
  },
11
14
  "author": "",
12
15
  "license": "ISC",
13
- "description": "",
14
- "peerDependencies": {
15
- "@vnejs/shared": "*",
16
- "@vnejs/module": "*"
17
- }
16
+ "description": ""
18
17
  }
package/view/index.jsx CHANGED
@@ -1,45 +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
- import { cn } from "@bem-react/classname";
4
+ import { Flex, PositionBox, Screen, Text, TextControls } from "@vnejs/uis.base";
5
5
 
6
- import "./index.styl";
6
+ const ConfirmView = ({ store, onMount, ...props } = {}) => {
7
+ const [{ isShow = false, text = "", textAccept = "", textDecline = "", currentItem: selectedIndex = null }, setState] = useState({});
8
+ const [texts, setTexts] = useState([]);
7
9
 
8
- const b = cn("ConfirmView");
10
+ useEffect(() => store.subscribe(setState), []);
11
+ useEffect(() => void onMount(), []);
9
12
 
10
- class ConfirmView extends React.Component {
11
- state = { isShow: false, text: "", textAccept: "", textDecline: "" };
13
+ useEffect(() => void setTexts([textAccept, textDecline].map((text, i) => ({ text, value: i === 0 }))), [textAccept, textDecline]);
12
14
 
13
- onAccept = () => this.props.emit(this.props.EVENTS.CONFIRM.ACCEPT);
14
- onDecline = () => this.props.emit(this.props.EVENTS.CONFIRM.DECLINE);
15
+ const onClick = useCallback((isAccept) => props.emit(isAccept ? props.EVENTS.CONFIRM.ACCEPT : props.EVENTS.CONFIRM.DECLINE), []);
15
16
 
16
- renderOneLine = (line = "", i) => (
17
- <div key={i} className={b("text", ["text"])}>
18
- {line}
19
- </div>
20
- );
17
+ const propsView = props.PARAMS.CONFIRM_VIEW.VIEW_PROPS;
18
+
19
+ const propsScreen = useMemo(() => ({ ...propsView.screen, isShow }), [isShow]);
20
+ const propsControls = useMemo(() => ({ ...propsView.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
21
+
22
+ const renderedTitle = useMemo(() => (text || "").split("\n").map((text = "", i) => <Text {...{ ...propsView.text, key: i, text }} />), [text]);
21
23
 
22
- renderControl = (text, onClick) => (
23
- <div className={b("control", ["text"])} onClick={onClick}>
24
- {text}
25
- </div>
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>
26
33
  );
34
+ };
27
35
 
28
- render() {
29
- const { isShow = false, text = "", textAccept = "", textDecline = "" } = this.state;
30
-
31
- return (
32
- <div className={b({ isShow })}>
33
- <div className={b("wrap")}>
34
- <div className={b("texts", ["textWrap_60"])}>{(text || "").split("\n").map(this.renderOneLine)}</div>
35
- <div className={b("controls", ["textWrap_60"])}>
36
- {this.renderControl(textAccept, this.onAccept)}
37
- {this.renderControl(textDecline, this.onDecline)}
38
- </div>
39
- </div>
40
- </div>
41
- );
42
- }
43
- }
44
-
45
- export const render = (props, root, resolve) => ReactDOM.render(<ConfirmView {...props} />, root, resolve);
36
+ export const render = (props, root) => ReactDOM.render(<ConfirmView {...props} />, root);
package/view/index.styl DELETED
@@ -1,59 +0,0 @@
1
- .ConfirmView
2
- position: absolute
3
- top: 0
4
- right: 0
5
- bottom: 0
6
- left: 0
7
- display: flex
8
- align-items: center
9
- justify-content: center
10
- z-index: 9000
11
- background: linear-gradient(0deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.25) 14.04%, rgba(0,0,0,0.45) 27.9%, rgba(0,0,0,0.55) 45.51%, rgba(0,0,0,0.7) 66.85%, rgba(0,0,0,0.85) 100%);
12
- backdrop-filter: blur(5px) brightness(0.5)
13
- font-family: Montserrat
14
- pointer-events: none
15
- opacity: 0
16
- transition: opacity 300ms
17
-
18
- &-wrap
19
- display: flex
20
- flex-direction: column
21
- align-items: center
22
- justify-content: center
23
-
24
- text-align: center
25
-
26
- height: calc(1000 / 2160 * 100%)
27
- gap: calc(50 / 1000 * 100%)
28
-
29
- &-texts
30
- display: flex;
31
- flex-direction: column
32
- justify-content: flex-end
33
- width: 100%;
34
- height: calc(450 / 1000 * 100%)
35
-
36
- &-text
37
- color: rgba(255,255,255,0.6)
38
-
39
- &-controls
40
- display: flex;
41
- justify-content: space-around;
42
- align-items: flex-start
43
- width: 100%;
44
- height: calc(450 / 1000 * 100%)
45
-
46
- &-control
47
- cursor: pointer
48
- color: rgba(255,255,255,0.6)
49
-
50
- transition: color 300ms, text-shadow 300ms, transform 300ms
51
-
52
- &:hover
53
- text-shadow: 0px 5px 25px rgba(255,255,255,0.75)
54
- transform: scale(1.5)
55
- color: white
56
-
57
- &_isShow
58
- pointer-events: all
59
- opacity: 1