pixuireactcomponents 1.1.0 → 1.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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Tabs } from "./ui/components/tab/Tabs";
2
2
  export { Tab } from "./ui/components/tab/Tab";
3
+ export { Slider } from "./ui/components/slider/Slider";
3
4
  export { Progress } from "./ui/components/progress/Progress";
4
5
  export { DropdownOptionUI } from "./ui/components/dropdown/DropdownOptionUI";
5
6
  export { DropdownSpreadMainUI } from "./ui/components/dropdown/DropdownSpreadMainUI";
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Tabs } from "./ui/components/tab/Tabs";
2
2
  export { Tab } from "./ui/components/tab/Tab";
3
+ export { Slider } from "./ui/components/slider/Slider";
3
4
  export { Progress } from "./ui/components/progress/Progress";
4
5
  export { Dropdown } from "./ui/components/dropdown/Dropdown";
5
6
  export { DropdownOptionUI } from "./ui/components/dropdown/DropdownOptionUI";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,6 +14,16 @@ 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
+ };
17
27
  var Dropdown = /** @class */ (function (_super) {
18
28
  __extends(Dropdown, _super);
19
29
  function Dropdown(props) {
@@ -75,7 +85,7 @@ var Dropdown = /** @class */ (function (_super) {
75
85
  return (h("div", null,
76
86
  h("div", { style: this.props.config.spreadStyle },
77
87
  this.props.spreadMainUI,
78
- _optionsUI)));
88
+ h("div", { style: optionsDivStyle }, _optionsUI))));
79
89
  };
80
90
  return Dropdown;
81
91
  }(Component));
@@ -1,6 +1,7 @@
1
1
  import { Component } from "preact";
2
2
  /**
3
3
  * dropdown 打开时options列表的单个Item UI
4
+ * 如果要使用滚动条,在创建改该组件时最外层div样式里面需添加flex-shrink : 0
4
5
  */
5
6
  export declare abstract class DropdownOptionUI<T> extends Component<{
6
7
  info: T;
@@ -16,6 +16,7 @@ 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
19
20
  */
20
21
  var DropdownOptionUI = /** @class */ (function (_super) {
21
22
  __extends(DropdownOptionUI, _super);
@@ -0,0 +1,53 @@
1
+ import { Component, h } from "preact";
2
+ export interface SliderProps {
3
+ percent: number;
4
+ wrapperWidth: number;
5
+ wrapperHeight: number;
6
+ height: number;
7
+ dotWidth: number;
8
+ dotHeight: number;
9
+ dotWrapperWidth: number;
10
+ dotWrapperHeight: number;
11
+ outerBg: string;
12
+ innerBg: string;
13
+ dotBg: string;
14
+ onDragStart: Function | null;
15
+ onDrag: Function | null;
16
+ onDragEnd: Function | null;
17
+ isDiscrete: Boolean | null;
18
+ discrete?: number;
19
+ maxDiscrete?: number;
20
+ hasIncDecButton: Boolean | null;
21
+ incButtonWidth?: number;
22
+ incButtonHeight?: number;
23
+ decButtonWidth?: number;
24
+ decButtonHeight?: number;
25
+ incButtonBg?: string;
26
+ decButtonBg?: string;
27
+ overallWidth?: number;
28
+ onIncClick?: Function | null;
29
+ onDecClick?: Function | null;
30
+ }
31
+ export declare class Slider extends Component<SliderProps, {
32
+ percent: number;
33
+ }> {
34
+ discrete: number;
35
+ private refWrapper;
36
+ constructor(props: any);
37
+ componentDidMount(): void;
38
+ componentWillReceiveProps(nextProps: any): void;
39
+ onDragStart: (event: any) => void;
40
+ onDrag: (event: any) => void;
41
+ onDragEnd: (event: any) => void;
42
+ onDecClick: () => void;
43
+ onIncClick: () => void;
44
+ computeWrapperStyle: () => void;
45
+ computeOuterStyle: () => void;
46
+ computeInnerStyle: () => void;
47
+ computeDotWrapperStyle: () => void;
48
+ computeDotStyle: () => void;
49
+ computeIncButtonStyle: () => void;
50
+ computeDecButtonStyle: () => void;
51
+ computeWithButtonStyle: () => void;
52
+ render(): h.JSX.Element;
53
+ }
@@ -0,0 +1,273 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import { Component, createRef, h } from "preact";
28
+ var row_center_center = {
29
+ display: 'flex',
30
+ flexDirection: 'row',
31
+ justifyContent: 'center',
32
+ alignItems: 'center'
33
+ };
34
+ var row_between_center = {
35
+ display: 'flex',
36
+ flexDirection: 'row',
37
+ justifyContent: 'space-between',
38
+ alignItems: 'center'
39
+ };
40
+ var wrapperStyle;
41
+ var outerStyle;
42
+ var innerStyle;
43
+ var dotStyle;
44
+ var dotWrapperStyle;
45
+ var incButtonStyle;
46
+ var decButtonStyle;
47
+ var withButtonStyle;
48
+ var lastX = undefined; // 上一次位置的横坐标
49
+ var count = 0; // 拖动条距离最左端的位置 [0, this.props.wrapperWidth]
50
+ var rect = undefined; // 滑动区域
51
+ var Slider = /** @class */ (function (_super) {
52
+ __extends(Slider, _super);
53
+ function Slider(props) {
54
+ var _this = _super.call(this, props) || this;
55
+ _this.discrete = Math.round(_this.props.discrete == null ? 0 : _this.props.discrete);
56
+ _this.refWrapper = createRef();
57
+ _this.onDragStart = function (event) {
58
+ console.log("【Slider】DragStart event.clientX--" + event.clientX + "-----percent----" + _this.state.percent + "-----currentX----" + (_this.state.percent / 100 * _this.props.wrapperWidth));
59
+ lastX = event.clentX;
60
+ count = _this.state.percent / 100 * _this.props.wrapperWidth;
61
+ if (_this.props.onDragStart) {
62
+ _this.props.onDragStart();
63
+ }
64
+ };
65
+ _this.onDrag = function (event) {
66
+ if (event.clientX < rect.left || event.clientX > rect.right)
67
+ return;
68
+ if (lastX == undefined) {
69
+ lastX = event.clientX;
70
+ return;
71
+ }
72
+ var move = Number(event.clientX) - Number(lastX);
73
+ count += move;
74
+ count = Math.min(_this.props.wrapperWidth, count);
75
+ count = Math.max(0, count);
76
+ var newPercent = count / _this.props.wrapperWidth * 100;
77
+ if (_this.props.isDiscrete == true && _this.props.maxDiscrete != null) {
78
+ newPercent = count / _this.props.wrapperWidth * _this.props.maxDiscrete;
79
+ _this.discrete = Math.round(newPercent);
80
+ // this.setState({
81
+ // discrete: Math.round(newPercent),
82
+ // })
83
+ newPercent = _this.discrete * (100 / _this.props.maxDiscrete);
84
+ }
85
+ _this.setState({
86
+ percent: newPercent
87
+ }, function () {
88
+ console.log("【Slider】OnDrag event.clientX--" + event.clientX + "-----percent----" + _this.state.percent + "-----discrete----" + _this.discrete + "-----currentX----" + (_this.state.percent / 100 * _this.props.wrapperWidth));
89
+ if (_this.props.onDrag)
90
+ _this.props.onDrag(_this.props.isDiscrete ? _this.discrete : newPercent);
91
+ });
92
+ lastX = event.clientX;
93
+ };
94
+ _this.onDragEnd = function (event) {
95
+ lastX = undefined;
96
+ if (_this.props.isDiscrete == true && _this.props.maxDiscrete != null) {
97
+ //console.log("OnDragEnd -----discrete----"+this.state.discrete)
98
+ _this.setState({
99
+ percent: _this.discrete * (100 / _this.props.maxDiscrete),
100
+ }, function () {
101
+ console.log("【Slider】DragEnd event.clientX--" + event.clientX + "-----percent----" + _this.state.percent + "-----discrete----" + _this.discrete + "-----currentX----" + (_this.state.percent / 100 * _this.props.wrapperWidth));
102
+ if (_this.props.onDragEnd) {
103
+ _this.props.onDragEnd(_this.props.isDiscrete ? _this.discrete : _this.state.percent);
104
+ }
105
+ });
106
+ }
107
+ else {
108
+ console.log("【Slider】DragEnd event.clientX--" + event.clientX + "-----percent----" + _this.state.percent + "-----currentX----" + (_this.state.percent / 100 * _this.props.wrapperWidth));
109
+ if (_this.props.onDragEnd) {
110
+ _this.props.onDragEnd(_this.props.isDiscrete ? _this.discrete : _this.state.percent);
111
+ }
112
+ }
113
+ };
114
+ _this.onDecClick = function () {
115
+ if (_this.props.isDiscrete && _this.props.maxDiscrete) {
116
+ if (_this.discrete >= 1) {
117
+ var newPercent = (_this.discrete - 1) * (100 / _this.props.maxDiscrete);
118
+ _this.discrete -= 1;
119
+ _this.setState({
120
+ //discrete: this.state.discrete - 1,
121
+ percent: newPercent
122
+ }, function () {
123
+ if (_this.props.onDecClick) {
124
+ _this.props.onDecClick(_this.discrete);
125
+ }
126
+ });
127
+ }
128
+ }
129
+ else {
130
+ if (_this.state.percent > 0) {
131
+ _this.setState({
132
+ percent: _this.state.percent - 1
133
+ }, function () {
134
+ if (_this.props.onIncClick) {
135
+ _this.props.onIncClick(_this.state.percent);
136
+ }
137
+ });
138
+ }
139
+ }
140
+ };
141
+ _this.onIncClick = function () {
142
+ if (_this.props.isDiscrete && _this.props.maxDiscrete) {
143
+ if (_this.discrete < _this.props.maxDiscrete) {
144
+ var newPercent = (_this.discrete + 1) * (100 / _this.props.maxDiscrete);
145
+ _this.discrete += 1;
146
+ _this.setState({
147
+ // discrete: this.state.discrete + 1,
148
+ percent: newPercent
149
+ }, function () {
150
+ if (_this.props.onIncClick) {
151
+ _this.props.onIncClick(_this.discrete);
152
+ }
153
+ });
154
+ }
155
+ }
156
+ else {
157
+ if (_this.state.percent < 100) {
158
+ _this.setState({
159
+ percent: _this.state.percent + 1
160
+ }, function () {
161
+ if (_this.props.onIncClick) {
162
+ _this.props.onIncClick(_this.state.percent);
163
+ }
164
+ });
165
+ }
166
+ }
167
+ };
168
+ _this.computeWrapperStyle = function () {
169
+ wrapperStyle = __assign({ width: _this.props.wrapperWidth + "px", height: _this.props.wrapperHeight + "px" }, row_center_center);
170
+ };
171
+ _this.computeOuterStyle = function () {
172
+ outerStyle = {
173
+ width: '100%',
174
+ height: _this.props.height + "px",
175
+ backgroundImage: "url(" + _this.props.outerBg + ")",
176
+ backgroundSize: '100% 100%',
177
+ display: 'flex',
178
+ flexDirection: 'row',
179
+ justifyContent: 'start',
180
+ alignItems: 'center'
181
+ };
182
+ };
183
+ _this.computeInnerStyle = function () {
184
+ var _width = Math.floor(_this.state.percent) + "%";
185
+ innerStyle = {
186
+ width: _width,
187
+ height: '100%',
188
+ backgroundImage: "url(" + _this.props.innerBg + ")",
189
+ backgroundSize: '100% 100%',
190
+ display: 'flex',
191
+ flexDirection: 'row',
192
+ justifyContent: 'start',
193
+ alignItems: 'center'
194
+ };
195
+ };
196
+ _this.computeDotWrapperStyle = function () {
197
+ dotWrapperStyle = __assign({ position: 'absolute', width: _this.props.dotWrapperWidth + "px", height: _this.props.dotWrapperHeight + "px",
198
+ //marginTop: (this.props.height - this.props.dotWrapperHeight) / 2 + "px",
199
+ marginLeft: (_this.props.wrapperWidth * _this.state.percent / 100 - _this.props.dotWrapperWidth / 2) + "px" }, row_center_center
200
+ // backgroundColor: '#FF000066'
201
+ );
202
+ };
203
+ _this.computeDotStyle = function () {
204
+ dotStyle = {
205
+ width: _this.props.dotWidth + "px",
206
+ height: _this.props.dotHeight + "px",
207
+ };
208
+ };
209
+ _this.computeIncButtonStyle = function () {
210
+ incButtonStyle = {
211
+ width: _this.props.incButtonWidth + "px",
212
+ height: _this.props.incButtonHeight + "px",
213
+ //marginLeft:this.props.incButtonLeft+"px",
214
+ //backgroundImage: `url(${this.props.incButtonBg})`,
215
+ };
216
+ };
217
+ _this.computeDecButtonStyle = function () {
218
+ decButtonStyle = {
219
+ width: _this.props.decButtonWidth + "px",
220
+ height: _this.props.decButtonHeight + "px",
221
+ //marginRight:this.props.decButtonRight+"px",
222
+ //backgroundImage: `url(${this.props.decButtonBg})`,
223
+ };
224
+ };
225
+ _this.computeWithButtonStyle = function () {
226
+ withButtonStyle = __assign({ minWidth: _this.props.overallWidth + "px" }, row_between_center);
227
+ };
228
+ _this.state = {
229
+ percent: (props.discrete != null && _this.props.maxDiscrete != null && _this.props.discrete != null) ? _this.props.discrete * (100 / _this.props.maxDiscrete) : Math.floor(_this.props.percent),
230
+ //discrete: Math.round(this.props.discrete==null?0:this.props.discrete)
231
+ };
232
+ _this.computeWrapperStyle();
233
+ _this.computeOuterStyle();
234
+ return _this;
235
+ }
236
+ Slider.prototype.componentDidMount = function () {
237
+ rect = this.refWrapper.current.getBoundingClientRect();
238
+ };
239
+ Slider.prototype.componentWillReceiveProps = function (nextProps) {
240
+ if (nextProps.percent == this.props.percent && nextProps.discrete == this.props.discrete)
241
+ return;
242
+ if (this.props.isDiscrete == true && this.props.maxDiscrete != null) {
243
+ this.discrete = nextProps.discrete;
244
+ this.setState({
245
+ //discrete:nextProps.discrete,
246
+ percent: this.discrete * (100 / this.props.maxDiscrete)
247
+ });
248
+ }
249
+ else {
250
+ this.setState({
251
+ percent: nextProps.percent,
252
+ });
253
+ }
254
+ };
255
+ Slider.prototype.render = function () {
256
+ this.computeInnerStyle();
257
+ this.computeDotWrapperStyle();
258
+ this.computeDotStyle();
259
+ this.computeIncButtonStyle();
260
+ this.computeDecButtonStyle();
261
+ this.computeWithButtonStyle();
262
+ return (h("div", { style: this.props.hasIncDecButton ? withButtonStyle : {} },
263
+ this.props.hasIncDecButton && h("img", { src: this.props.decButtonBg, style: decButtonStyle, onClick: this.onDecClick }),
264
+ h("div", { ref: this.refWrapper, style: wrapperStyle },
265
+ h("div", { style: outerStyle },
266
+ h("div", { style: innerStyle },
267
+ h("div", { style: dotWrapperStyle, draggable: true, onDragStart: this.onDragStart, onDrag: this.onDrag, onDragEnd: this.onDragEnd },
268
+ h("img", { src: this.props.dotBg, style: dotStyle }))))),
269
+ this.props.hasIncDecButton && h("img", { src: this.props.incButtonBg, style: incButtonStyle, onClick: this.onIncClick })));
270
+ };
271
+ return Slider;
272
+ }(Component));
273
+ export { Slider };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # 组件库
2
- 本组件库目前分为2大类:ui组件和工具组件。分别参见目录ui/和目录tools。
3
- 具体组件说明,参见对应类别目录下的md文档
package/tools/tools.md DELETED
@@ -1,22 +0,0 @@
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
- ![](./img/logger.png)
20
-
21
- * ObjectPrinter2:比上一个打印的信息更多
22
- * HierarchyPrinter: 采样打印,对数组进行采样,能打印最多的信息
package/ui/ui.md DELETED
@@ -1,2 +0,0 @@
1
- # UI组件
2
- 组件源码,参见components目录;对应的示例Demo,参见sample目录