@vnejs/plugins.view.coralina.choose 0.0.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/index.js +6 -0
- package/modules/controller.js +34 -0
- package/modules/view.js +11 -0
- package/package.json +18 -0
- package/view/index.jsx +37 -0
- package/view/index.styl +39 -0
package/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class ChooseController extends Module.Controller {
|
|
4
|
+
name = "choose.controller";
|
|
5
|
+
|
|
6
|
+
maxCurrentItem = 0;
|
|
7
|
+
updateEvent = this.EVENTS.CHOOSE.UPDATE;
|
|
8
|
+
|
|
9
|
+
emitGameMenu = () => this.emit(this.EVENTS.INTERFACE.GAMEMENU);
|
|
10
|
+
|
|
11
|
+
controls = {
|
|
12
|
+
[this.CONST.CONTROLS.BUTTONS.MENU]: this.emitGameMenu,
|
|
13
|
+
[this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
|
|
14
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => this.emit(this.EVENTS.INTERFACE.HISTORY_BACK),
|
|
15
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
|
|
16
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
|
|
17
|
+
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: () =>
|
|
18
|
+
this.currentItem !== null && this.emit(this.EVENTS.CHOOSE.OPTION, { index: this.currentItem }),
|
|
19
|
+
};
|
|
20
|
+
controlsIndex = 2000;
|
|
21
|
+
|
|
22
|
+
subscribe = () => {
|
|
23
|
+
this.on(this.EVENTS.CHOOSE.SHOW, this.onShow);
|
|
24
|
+
this.on(this.EVENTS.CHOOSE.HIDE, this.onHide);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
beforeShow = async () => {
|
|
28
|
+
this.updateState({ ...this.globalState.choose });
|
|
29
|
+
this.currentItem = null;
|
|
30
|
+
this.maxCurrentItem = this.state.options.length - 1;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
getDefaultState = () => ({ options: [], args: {} });
|
|
34
|
+
}
|
package/modules/view.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import { render } from "../view";
|
|
4
|
+
|
|
5
|
+
export class ChooseView extends Module.View {
|
|
6
|
+
name = "choose.view";
|
|
7
|
+
animationTime = 300;
|
|
8
|
+
renderFunc = render;
|
|
9
|
+
updateEvent = this.EVENTS.CHOOSE.UPDATE;
|
|
10
|
+
updateHandler = this.onUpdateReactComponent;
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.view.coralina.choose",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
8
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"description": "",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@vnejs/shared": "*",
|
|
16
|
+
"@vnejs/module": "*"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/view/index.jsx
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
|
|
4
|
+
import { cn } from "@bem-react/classname";
|
|
5
|
+
|
|
6
|
+
import "./index.styl";
|
|
7
|
+
|
|
8
|
+
const b = cn("Choose");
|
|
9
|
+
|
|
10
|
+
class Choose extends React.Component {
|
|
11
|
+
onOptionClick = (e) =>
|
|
12
|
+
this.props.emit(this.props.EVENTS.CHOOSE.OPTION, { index: Number(e.currentTarget.dataset.index) });
|
|
13
|
+
|
|
14
|
+
renderOption = ({ text, disabled, hided, isCurrent }, index) =>
|
|
15
|
+
!hided && (
|
|
16
|
+
<div
|
|
17
|
+
className={b("option", { disabled, isCurrent: index === this.state.currentItem }, ["textWrap_60"])}
|
|
18
|
+
data-index={index}
|
|
19
|
+
key={index}
|
|
20
|
+
onClick={disabled ? undefined : this.onOptionClick}
|
|
21
|
+
>
|
|
22
|
+
<span className="text"> {text}</span>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
const { isShow = false, options = [], isForce = false } = this.state || {};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className={b({ isShow, isForce })} vne-autoread-disable={isShow ? "1" : ""}>
|
|
31
|
+
<div className={b("options")}>{options.map(this.renderOption)}</div>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const render = (props, root, resolve) => ReactDOM.render(<Choose {...props} />, root, resolve);
|
package/view/index.styl
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
.Choose
|
|
2
|
+
position: absolute
|
|
3
|
+
top: 0
|
|
4
|
+
right: 0
|
|
5
|
+
bottom: 0
|
|
6
|
+
left: 0
|
|
7
|
+
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%);
|
|
8
|
+
display: flex
|
|
9
|
+
justify-content: center
|
|
10
|
+
align-items: center
|
|
11
|
+
z-index: 3000
|
|
12
|
+
opacity: 0
|
|
13
|
+
pointer-events: none
|
|
14
|
+
font-family: Montserrat
|
|
15
|
+
|
|
16
|
+
&-options
|
|
17
|
+
display: flex
|
|
18
|
+
flex-direction: column
|
|
19
|
+
justify-content: center
|
|
20
|
+
align-items: center
|
|
21
|
+
height: 100%
|
|
22
|
+
gap: calc(50 / 2160 * 100%)
|
|
23
|
+
|
|
24
|
+
&-option
|
|
25
|
+
cursor: pointer
|
|
26
|
+
color: rgba(255,255,255,0.6)
|
|
27
|
+
transition: text-shadow 300ms, transform 300ms
|
|
28
|
+
|
|
29
|
+
&:hover,
|
|
30
|
+
&_isCurrent
|
|
31
|
+
text-shadow: 0px 5px 25px rgba(255,255,255,0.75);
|
|
32
|
+
transform: scale(1.5)
|
|
33
|
+
|
|
34
|
+
&_isShow
|
|
35
|
+
opacity: 1
|
|
36
|
+
pointer-events: all
|
|
37
|
+
|
|
38
|
+
&:not(&_isForce)
|
|
39
|
+
transition: opacity 300ms
|