pixuireactcomponents 1.0.8 → 1.1.0

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,6 +1,5 @@
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";
4
3
  export { Progress } from "./ui/components/progress/Progress";
5
4
  export { DropdownOptionUI } from "./ui/components/dropdown/DropdownOptionUI";
6
5
  export { DropdownSpreadMainUI } from "./ui/components/dropdown/DropdownSpreadMainUI";
package/index.js CHANGED
@@ -1,6 +1,5 @@
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";
4
3
  export { Progress } from "./ui/components/progress/Progress";
5
4
  export { Dropdown } from "./ui/components/dropdown/Dropdown";
6
5
  export { DropdownOptionUI } from "./ui/components/dropdown/DropdownOptionUI";
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
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": "nepdai",
9
+ "author": "hardenzheng",
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("".concat(name, " = "));
51
+ lines.push(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("".concat(name, " = "));
95
+ lines.push(name + " = ");
96
96
  getTreeStyleHierarchyLines(object, 1, lines);
97
97
  console.warn(lines.join("\n"));
98
98
  };
@@ -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(".concat(_this.props.outerBg, ")"),
89
+ backgroundImage: "url(" + _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(".concat(_this.props.innerBg, ")"),
98
+ backgroundImage: "url(" + _this.props.innerBg + ")",
99
99
  backgroundSize: '100% 100%'
100
100
  };
101
101
  };
@@ -0,0 +1,51 @@
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
+ <img src="../../images/思路拆解.png" />
35
+
36
+
37
+
38
+ 结合Demo看下用法:
39
+
40
+ - 使用Dropdown组件时,定义好数据类型 和 3种状态的Item类型
41
+
42
+ - 传入3种状态的Item对应的实例对象 
43
+
44
+ - 传入一个DropdownConfig,里面包括了下拉列表的数据 和 展开态的整体Style
45
+
46
+
47
+
48
+
49
+
50
+
51
+
@@ -1,53 +0,0 @@
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
- discrete: number;
34
- }> {
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
- }
@@ -1,254 +0,0 @@
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.refWrapper = createRef();
56
- _this.onDragStart = function (event) {
57
- console.log("【Slider】DragStart event.clientX--" + event.clientX + "-----percent----" + _this.state.percent + "-----currentX----" + (_this.state.percent / 100 * _this.props.wrapperWidth));
58
- lastX = event.clentX;
59
- count = _this.state.percent / 100 * _this.props.wrapperWidth;
60
- if (_this.props.onDragStart) {
61
- _this.props.onDragStart();
62
- }
63
- };
64
- _this.onDrag = function (event) {
65
- if (event.clientX < rect.left || event.clientX > rect.right)
66
- return;
67
- if (lastX == undefined) {
68
- lastX = event.clientX;
69
- return;
70
- }
71
- var move = Number(event.clientX) - Number(lastX);
72
- count += move;
73
- count = Math.min(_this.props.wrapperWidth, count);
74
- count = Math.max(0, count);
75
- var newPercent = count / _this.props.wrapperWidth * 100;
76
- if (_this.props.isDiscrete == true && _this.props.maxDiscrete != null) {
77
- newPercent = count / _this.props.wrapperWidth * _this.props.maxDiscrete;
78
- _this.setState({
79
- discrete: Math.round(newPercent),
80
- });
81
- newPercent = _this.state.discrete * (100 / _this.props.maxDiscrete);
82
- }
83
- _this.setState({
84
- percent: newPercent
85
- }, function () {
86
- if (_this.props.onDrag)
87
- _this.props.onDrag(_this.props.isDiscrete ? _this.state.discrete : newPercent);
88
- });
89
- lastX = event.clientX;
90
- };
91
- _this.onDragEnd = function (event) {
92
- lastX = undefined;
93
- console.log("【Slider】DragEnd event.clientX--" + event.clientX + "-----percent----" + _this.state.percent + "-----currentX----" + (_this.state.percent / 100 * _this.props.wrapperWidth));
94
- if (_this.props.onDragEnd) {
95
- _this.props.onDragEnd(_this.props.isDiscrete ? _this.state.discrete : _this.state.percent);
96
- }
97
- };
98
- _this.onDecClick = function () {
99
- if (_this.props.isDiscrete && _this.props.maxDiscrete) {
100
- if (_this.state.discrete >= 1) {
101
- var newPercent = (_this.state.discrete - 1) * (100 / _this.props.maxDiscrete);
102
- _this.setState({
103
- discrete: _this.state.discrete - 1,
104
- percent: newPercent
105
- }, function () {
106
- if (_this.props.onDecClick) {
107
- _this.props.onDecClick(_this.state.discrete);
108
- }
109
- });
110
- }
111
- }
112
- else {
113
- if (_this.state.percent > 0) {
114
- _this.setState({
115
- percent: _this.state.percent - 1
116
- }, function () {
117
- if (_this.props.onIncClick) {
118
- _this.props.onIncClick(_this.state.percent);
119
- }
120
- });
121
- }
122
- }
123
- };
124
- _this.onIncClick = function () {
125
- if (_this.props.isDiscrete && _this.props.maxDiscrete) {
126
- if (_this.state.discrete < _this.props.maxDiscrete) {
127
- var newPercent = (_this.state.discrete + 1) * (100 / _this.props.maxDiscrete);
128
- _this.setState({
129
- discrete: _this.state.discrete + 1,
130
- percent: newPercent
131
- }, function () {
132
- if (_this.props.onIncClick) {
133
- _this.props.onIncClick(_this.state.discrete);
134
- }
135
- });
136
- }
137
- }
138
- else {
139
- if (_this.state.percent < 100) {
140
- _this.setState({
141
- percent: _this.state.percent + 1
142
- }, function () {
143
- if (_this.props.onIncClick) {
144
- _this.props.onIncClick(_this.state.percent);
145
- }
146
- });
147
- }
148
- }
149
- };
150
- _this.computeWrapperStyle = function () {
151
- wrapperStyle = __assign({ width: _this.props.wrapperWidth + "px", height: _this.props.wrapperHeight + "px" }, row_center_center);
152
- };
153
- _this.computeOuterStyle = function () {
154
- outerStyle = {
155
- width: '100%',
156
- height: _this.props.height + "px",
157
- backgroundImage: "url(".concat(_this.props.outerBg, ")"),
158
- backgroundSize: '100% 100%',
159
- display: 'flex',
160
- flexDirection: 'row',
161
- justifyContent: 'start',
162
- alignItems: 'center'
163
- };
164
- };
165
- _this.computeInnerStyle = function () {
166
- var _width = Math.floor(_this.state.percent) + "%";
167
- innerStyle = {
168
- width: _width,
169
- height: '100%',
170
- backgroundImage: "url(".concat(_this.props.innerBg, ")"),
171
- backgroundSize: '100% 100%',
172
- display: 'flex',
173
- flexDirection: 'row',
174
- justifyContent: 'start',
175
- alignItems: 'center'
176
- };
177
- };
178
- _this.computeDotWrapperStyle = function () {
179
- dotWrapperStyle = __assign({ position: 'absolute', width: _this.props.dotWrapperWidth + "px", height: _this.props.dotWrapperHeight + "px",
180
- //marginTop: (this.props.height - this.props.dotWrapperHeight) / 2 + "px",
181
- marginLeft: (_this.props.wrapperWidth * _this.state.percent / 100 - _this.props.dotWrapperWidth / 2) + "px" }, row_center_center
182
- // backgroundColor: '#FF000066'
183
- );
184
- };
185
- _this.computeDotStyle = function () {
186
- dotStyle = {
187
- width: _this.props.dotWidth + "px",
188
- height: _this.props.dotHeight + "px",
189
- };
190
- };
191
- _this.computeIncButtonStyle = function () {
192
- incButtonStyle = {
193
- width: _this.props.incButtonWidth + "px",
194
- height: _this.props.incButtonHeight + "px",
195
- //marginLeft:this.props.incButtonLeft+"px",
196
- //backgroundImage: `url(${this.props.incButtonBg})`,
197
- };
198
- };
199
- _this.computeDecButtonStyle = function () {
200
- decButtonStyle = {
201
- width: _this.props.decButtonWidth + "px",
202
- height: _this.props.decButtonHeight + "px",
203
- //marginRight:this.props.decButtonRight+"px",
204
- //backgroundImage: `url(${this.props.decButtonBg})`,
205
- };
206
- };
207
- _this.computeWithButtonStyle = function () {
208
- withButtonStyle = __assign({ minWidth: _this.props.overallWidth + "px" }, row_between_center);
209
- };
210
- _this.state = {
211
- percent: (props.discrete != null && _this.props.maxDiscrete != null && _this.props.discrete != null) ? _this.props.discrete * (100 / _this.props.maxDiscrete) : Math.floor(_this.props.percent),
212
- discrete: Math.round(_this.props.discrete == null ? 0 : _this.props.discrete)
213
- };
214
- _this.computeWrapperStyle();
215
- _this.computeOuterStyle();
216
- return _this;
217
- }
218
- Slider.prototype.componentDidMount = function () {
219
- rect = this.refWrapper.current.getBoundingClientRect();
220
- };
221
- Slider.prototype.componentWillReceiveProps = function (nextProps) {
222
- if (nextProps.percent == this.props.percent && nextProps.discrete == this.props.discrete)
223
- return;
224
- if (this.props.isDiscrete == true && this.props.maxDiscrete != null) {
225
- this.setState({
226
- discrete: nextProps.discrete,
227
- percent: this.state.discrete * (100 / this.props.maxDiscrete)
228
- });
229
- }
230
- else {
231
- this.setState({
232
- percent: nextProps.percent,
233
- });
234
- }
235
- };
236
- Slider.prototype.render = function () {
237
- this.computeInnerStyle();
238
- this.computeDotWrapperStyle();
239
- this.computeDotStyle();
240
- this.computeIncButtonStyle();
241
- this.computeDecButtonStyle();
242
- this.computeWithButtonStyle();
243
- return (h("div", { style: this.props.hasIncDecButton ? withButtonStyle : {} },
244
- this.props.hasIncDecButton && h("img", { src: this.props.decButtonBg, style: decButtonStyle, onClick: this.onDecClick }),
245
- h("div", { ref: this.refWrapper, style: wrapperStyle },
246
- h("div", { style: outerStyle },
247
- h("div", { style: innerStyle },
248
- h("div", { style: dotWrapperStyle, draggable: true, onDragStart: this.onDragStart, onDrag: this.onDrag, onDragEnd: this.onDragEnd },
249
- h("img", { src: this.props.dotBg, style: dotStyle }))))),
250
- this.props.hasIncDecButton && h("img", { src: this.props.incButtonBg, style: incButtonStyle, onClick: this.onIncClick })));
251
- };
252
- return Slider;
253
- }(Component));
254
- export { Slider };