pixuireactcomponents 1.1.2 → 1.1.3
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/README.md +3 -0
- package/package.json +2 -2
- package/tools/Logger.js +2 -2
- package/tools/tools.md +22 -0
- package/ui/components/dropdown/Dropdown.js +1 -11
- package/ui/components/dropdown/DropdownOptionUI.d.ts +0 -1
- package/ui/components/dropdown/DropdownOptionUI.js +0 -1
- package/ui/components/progress/Progress.js +2 -2
- package/ui/components/slider/Slider.d.ts +3 -0
- package/ui/components/slider/Slider.js +20 -4
- package/ui/ui.md +2 -0
- package/images//344/273/243/347/240/201/344/275/215/347/275/256.png +0 -0
- package/images//345/211/215/350/250/200.png +0 -0
- package/images//346/200/235/350/267/257/346/213/206/350/247/243.png +0 -0
- package/images//350/256/276/350/256/241/346/200/235/350/267/257/345/217/212/347/224/250/346/263/225.png +0 -0
- package/images//350/256/276/350/256/241/346/200/235/350/267/257/345/217/212/347/224/250/346/263/2252.png +0 -0
- package/ui/components//344/270/213/346/213/211/351/200/211/344/270/255/346/241/206Dropdown.md +0 -53
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixuireactcomponents",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "pixui react components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
-
"author": "
|
|
9
|
+
"author": "nepdai",
|
|
10
10
|
"license": "ISC"
|
|
11
11
|
}
|
package/tools/Logger.js
CHANGED
|
@@ -48,7 +48,7 @@ var regexForLine = new RegExp(",$");
|
|
|
48
48
|
*/
|
|
49
49
|
Logger.ObjectPrinter2 = function (object, name) {
|
|
50
50
|
var lines = [];
|
|
51
|
-
lines.push(name
|
|
51
|
+
lines.push("".concat(name, " = "));
|
|
52
52
|
getTreeStyleLines(object, 1, lines);
|
|
53
53
|
console.warn(lines.join("\n"));
|
|
54
54
|
};
|
|
@@ -92,7 +92,7 @@ function getSeparation2(level) {
|
|
|
92
92
|
*/
|
|
93
93
|
Logger.HierarchyPrinter = function (object, name) {
|
|
94
94
|
var lines = [];
|
|
95
|
-
lines.push(name
|
|
95
|
+
lines.push("".concat(name, " = "));
|
|
96
96
|
getTreeStyleHierarchyLines(object, 1, lines);
|
|
97
97
|
console.warn(lines.join("\n"));
|
|
98
98
|
};
|
package/tools/tools.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# 工具类组件
|
|
2
|
+
### 1. EventDispatcherJs.tsx
|
|
3
|
+
React里可供使用的事件派发器,类似Pandora Lua里的EventDispatcher。
|
|
4
|
+
|
|
5
|
+
用法主要就3个接口:
|
|
6
|
+
|
|
7
|
+
* AddEventListener: 添加监听事件
|
|
8
|
+
* DispatchEvent: 分发监听事件
|
|
9
|
+
* RemoveEventListener: 移除监听事件
|
|
10
|
+
|
|
11
|
+
### 2. Logger.tsx
|
|
12
|
+
React里可供使用的对象(数组)打印器。
|
|
13
|
+
|
|
14
|
+
直接console.log一个对象时,在游戏引擎中,无法打印出这个对象里的东西。而实际开发时,前后端联调时,需要方便的确认各种对象里的细节。
|
|
15
|
+
|
|
16
|
+
用法一共3个接口,打印粒度有差异。
|
|
17
|
+
|
|
18
|
+
* ObjectPrinter: 打印一个对象的内部细节,效果如下
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+
* ObjectPrinter2:比上一个打印的信息更多
|
|
22
|
+
* HierarchyPrinter: 采样打印,对数组进行采样,能打印最多的信息
|
|
@@ -14,16 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
};
|
|
15
15
|
})();
|
|
16
16
|
import { Component, h } from "preact";
|
|
17
|
-
var optionsDivStyle = {
|
|
18
|
-
marginTop: 3,
|
|
19
|
-
display: 'flex',
|
|
20
|
-
flexDirection: 'column',
|
|
21
|
-
justifyContent: 'flex-start',
|
|
22
|
-
alignItems: 'center',
|
|
23
|
-
height: 'auto',
|
|
24
|
-
overflow: 'scroll',
|
|
25
|
-
overflowStyle: 'none',
|
|
26
|
-
};
|
|
27
17
|
var Dropdown = /** @class */ (function (_super) {
|
|
28
18
|
__extends(Dropdown, _super);
|
|
29
19
|
function Dropdown(props) {
|
|
@@ -85,7 +75,7 @@ var Dropdown = /** @class */ (function (_super) {
|
|
|
85
75
|
return (h("div", null,
|
|
86
76
|
h("div", { style: this.props.config.spreadStyle },
|
|
87
77
|
this.props.spreadMainUI,
|
|
88
|
-
|
|
78
|
+
_optionsUI)));
|
|
89
79
|
};
|
|
90
80
|
return Dropdown;
|
|
91
81
|
}(Component));
|
|
@@ -16,7 +16,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
import { Component } from "preact";
|
|
17
17
|
/**
|
|
18
18
|
* dropdown 打开时options列表的单个Item UI
|
|
19
|
-
* 如果要使用滚动条,在创建改该组件时最外层div样式里面需添加flex-shrink : 0
|
|
20
19
|
*/
|
|
21
20
|
var DropdownOptionUI = /** @class */ (function (_super) {
|
|
22
21
|
__extends(DropdownOptionUI, _super);
|
|
@@ -86,7 +86,7 @@ var Progress = /** @class */ (function (_super) {
|
|
|
86
86
|
outerStyle = {
|
|
87
87
|
width: '100%',
|
|
88
88
|
height: _this.props.height + "px",
|
|
89
|
-
backgroundImage: "url("
|
|
89
|
+
backgroundImage: "url(".concat(_this.props.outerBg, ")"),
|
|
90
90
|
backgroundSize: '100% 100%'
|
|
91
91
|
};
|
|
92
92
|
};
|
|
@@ -95,7 +95,7 @@ var Progress = /** @class */ (function (_super) {
|
|
|
95
95
|
innerStyle = {
|
|
96
96
|
width: _width,
|
|
97
97
|
height: '100%',
|
|
98
|
-
backgroundImage: "url("
|
|
98
|
+
backgroundImage: "url(".concat(_this.props.innerBg, ")"),
|
|
99
99
|
backgroundSize: '100% 100%'
|
|
100
100
|
};
|
|
101
101
|
};
|
|
@@ -27,6 +27,9 @@ export interface SliderProps {
|
|
|
27
27
|
overallWidth?: number;
|
|
28
28
|
onIncClick?: Function | null;
|
|
29
29
|
onDecClick?: Function | null;
|
|
30
|
+
rangeControl?: Boolean;
|
|
31
|
+
startRange?: number;
|
|
32
|
+
endRange?: number;
|
|
30
33
|
}
|
|
31
34
|
export declare class Slider extends Component<SliderProps, {
|
|
32
35
|
percent: number;
|
|
@@ -80,6 +80,12 @@ var Slider = /** @class */ (function (_super) {
|
|
|
80
80
|
// this.setState({
|
|
81
81
|
// discrete: Math.round(newPercent),
|
|
82
82
|
// })
|
|
83
|
+
if (_this.props.rangeControl) {
|
|
84
|
+
if (_this.props.endRange != null)
|
|
85
|
+
_this.discrete = Math.min(_this.discrete, _this.props.endRange);
|
|
86
|
+
if (_this.props.startRange != null)
|
|
87
|
+
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
88
|
+
}
|
|
83
89
|
newPercent = _this.discrete * (100 / _this.props.maxDiscrete);
|
|
84
90
|
}
|
|
85
91
|
_this.setState({
|
|
@@ -112,10 +118,14 @@ var Slider = /** @class */ (function (_super) {
|
|
|
112
118
|
}
|
|
113
119
|
};
|
|
114
120
|
_this.onDecClick = function () {
|
|
121
|
+
//离散的情况
|
|
115
122
|
if (_this.props.isDiscrete && _this.props.maxDiscrete) {
|
|
116
123
|
if (_this.discrete >= 1) {
|
|
117
|
-
var newPercent = (_this.discrete - 1) * (100 / _this.props.maxDiscrete);
|
|
118
124
|
_this.discrete -= 1;
|
|
125
|
+
if (_this.props.rangeControl && _this.props.startRange != null) {
|
|
126
|
+
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
127
|
+
}
|
|
128
|
+
var newPercent = _this.discrete * (100 / _this.props.maxDiscrete);
|
|
119
129
|
_this.setState({
|
|
120
130
|
//discrete: this.state.discrete - 1,
|
|
121
131
|
percent: newPercent
|
|
@@ -126,6 +136,7 @@ var Slider = /** @class */ (function (_super) {
|
|
|
126
136
|
});
|
|
127
137
|
}
|
|
128
138
|
}
|
|
139
|
+
//连续的情况
|
|
129
140
|
else {
|
|
130
141
|
if (_this.state.percent > 0) {
|
|
131
142
|
_this.setState({
|
|
@@ -139,10 +150,14 @@ var Slider = /** @class */ (function (_super) {
|
|
|
139
150
|
}
|
|
140
151
|
};
|
|
141
152
|
_this.onIncClick = function () {
|
|
153
|
+
//离散的情况
|
|
142
154
|
if (_this.props.isDiscrete && _this.props.maxDiscrete) {
|
|
143
155
|
if (_this.discrete < _this.props.maxDiscrete) {
|
|
144
|
-
var newPercent = (_this.discrete + 1) * (100 / _this.props.maxDiscrete);
|
|
145
156
|
_this.discrete += 1;
|
|
157
|
+
if (_this.props.rangeControl && _this.props.startRange != null) {
|
|
158
|
+
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
159
|
+
}
|
|
160
|
+
var newPercent = _this.discrete * (100 / _this.props.maxDiscrete);
|
|
146
161
|
_this.setState({
|
|
147
162
|
// discrete: this.state.discrete + 1,
|
|
148
163
|
percent: newPercent
|
|
@@ -153,6 +168,7 @@ var Slider = /** @class */ (function (_super) {
|
|
|
153
168
|
});
|
|
154
169
|
}
|
|
155
170
|
}
|
|
171
|
+
//连续的情况
|
|
156
172
|
else {
|
|
157
173
|
if (_this.state.percent < 100) {
|
|
158
174
|
_this.setState({
|
|
@@ -172,7 +188,7 @@ var Slider = /** @class */ (function (_super) {
|
|
|
172
188
|
outerStyle = {
|
|
173
189
|
width: '100%',
|
|
174
190
|
height: _this.props.height + "px",
|
|
175
|
-
backgroundImage: "url("
|
|
191
|
+
backgroundImage: "url(".concat(_this.props.outerBg, ")"),
|
|
176
192
|
backgroundSize: '100% 100%',
|
|
177
193
|
display: 'flex',
|
|
178
194
|
flexDirection: 'row',
|
|
@@ -185,7 +201,7 @@ var Slider = /** @class */ (function (_super) {
|
|
|
185
201
|
innerStyle = {
|
|
186
202
|
width: _width,
|
|
187
203
|
height: '100%',
|
|
188
|
-
backgroundImage: "url("
|
|
204
|
+
backgroundImage: "url(".concat(_this.props.innerBg, ")"),
|
|
189
205
|
backgroundSize: '100% 100%',
|
|
190
206
|
display: 'flex',
|
|
191
207
|
flexDirection: 'row',
|
package/ui/ui.md
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/ui/components//344/270/213/346/213/211/351/200/211/344/270/255/346/241/206Dropdown.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
下拉选中框Dropdown
|
|
3
|
-
===
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
前言
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
<img src="../../images/前言.png" />
|
|
10
|
-
下拉选中框Dropdown,其实也是一种N选1的UI组件。不过跟Tabs(另一篇介绍了)这种N选1相比,有所差别:
|
|
11
|
-
Tabs这种N选1场景,N个选项都是直接展示在外的。Dropdown这种N选1,有两种状态:展开态和收缩态。展开态展示所有选项,收缩态只展示选中的1。也是很常用的功能。
|
|
12
|
-
开发过程遇到这种需求时,抽象沉淀了一个Dropdown组件。方便后续快速实现一个健壮的下拉列表需求。
|
|
13
|
-
组件和示例的git地址:[https://git.woa.com/pixui_plugin/PixUIReactComponents.git。](https://git.woa.com/pixui_plugin/PixUIReactComponents.git)
|
|
14
|
-
具体代码位置:
|
|
15
|
-
<img src="../../images/代码位置.png" />
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
设计思路及用法
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
<img src="../../images/设计思路及用法.png" />
|
|
22
|
-
<img src="../../images/设计思路及用法2.png" />
|
|
23
|
-
看一下源码,基本的拆解思路是:
|
|
24
|
-
|
|
25
|
-
1. 首先是有2个状态,收缩态 和 展开态
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
2. 收缩态 需要传入一个DropdownUnspreadMainUI的实例(对应当前选中Item),直接展示
|
|
29
|
-
|
|
30
|
-
3.展开态 时,依次展示DropdownSpreadMainUI的实例(对应当前选中Item)和 N - 1个DropdownOptionUI的实例(对应N - 1 个为选中Item)
|
|
31
|
-
|
|
32
|
-
4.考虑到单个Item对应的数据类型不定,每个Item的样式也千变万化。所以上述3种实例对应的类均基于泛型实现,方便扩展。
|
|
33
|
-
|
|
34
|
-
5.如果需要使用滚动条,在创建DropdownOptionUI(每项item)时,需要在最外层的div添加样式: ***flex-shrink : 0***
|
|
35
|
-
|
|
36
|
-
<img src="../../images/思路拆解.png" />
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
结合Demo看下用法:
|
|
41
|
-
|
|
42
|
-
- 使用Dropdown组件时,定义好数据类型 和 3种状态的Item类型
|
|
43
|
-
|
|
44
|
-
- 传入3种状态的Item对应的实例对象
|
|
45
|
-
|
|
46
|
-
- 传入一个DropdownConfig,里面包括了下拉列表的数据 和 展开态的整体Style
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|