pixuireactcomponents 1.3.25 → 1.3.26
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
|
@@ -3,10 +3,10 @@ export { Button } from "./src/components/react/app/button/Button";
|
|
|
3
3
|
export { Checkbox } from "./src/components/react/app/checkBox/CheckBox";
|
|
4
4
|
export { Dropdown } from "./src/components/react/app/dropdown/Dropdown";
|
|
5
5
|
export { ImageViewer } from "./src/components/react/app/imageViewer/imageViewer";
|
|
6
|
-
export { Slider } from "./src/components/react/app/slider/Slider";
|
|
7
6
|
export { ToggleGroup } from "./src/components/react/app/togglegroup/ToggleGroup";
|
|
8
7
|
export { GradientText } from "./src/components/react/base/gradient/GradientText";
|
|
9
8
|
export { PVideo } from "./src/components/react/base/pixVideo/PixVideo";
|
|
10
9
|
export { OutlineText } from "./src/components/react/base/outlinetext/OutlineText";
|
|
11
10
|
export { ImgPreLoader } from "./src/components/tools/ImgPreLoader";
|
|
12
11
|
export { Logger } from "./src/components/tools/Logger";
|
|
12
|
+
export { Slider, SliderProps } from "./src/components/react/app/slider/Slider";
|
package/package.json
CHANGED
|
@@ -101,7 +101,7 @@ export function Carousel(props) {
|
|
|
101
101
|
//组件展示内容长度改变的时候改回到第一个元素,刷新autoplay判断
|
|
102
102
|
useEffect(function () {
|
|
103
103
|
setNextInterval();
|
|
104
|
-
setShowIndex(
|
|
104
|
+
setShowIndex(defaultIndex);
|
|
105
105
|
}, [children]);
|
|
106
106
|
useEffect(function () {
|
|
107
107
|
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
@@ -233,19 +233,7 @@ export function Carousel(props) {
|
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
return (h("div", { style: { flexDirection: 'column' } },
|
|
236
|
-
h("div", { style: __assign(__assign({
|
|
237
|
-
h("div", { style: {
|
|
238
|
-
display: 'flex',
|
|
239
|
-
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
240
|
-
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
241
|
-
transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
|
|
242
|
-
transform: isVertical
|
|
243
|
-
? "translate(0px, ".concat(offset + gesteroffset[1], "px)")
|
|
244
|
-
: "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
|
|
245
|
-
flexDirection: isVertical ? 'column' : 'row',
|
|
246
|
-
flexShrink: 0,
|
|
247
|
-
}, class: "wrapper", onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))),
|
|
248
|
-
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function () {
|
|
236
|
+
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function (ev) {
|
|
249
237
|
gestureClick(props);
|
|
250
238
|
}, class: 'GestureComp', onDragStart: function (e) {
|
|
251
239
|
if (children.length > 1) {
|
|
@@ -259,21 +247,17 @@ export function Carousel(props) {
|
|
|
259
247
|
if (children.length > 1) {
|
|
260
248
|
gestureUp();
|
|
261
249
|
}
|
|
262
|
-
} }
|
|
250
|
+
} },
|
|
251
|
+
h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
|
|
252
|
+
h("div", { style: {
|
|
253
|
+
display: 'flex',
|
|
254
|
+
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
255
|
+
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
256
|
+
transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
|
|
257
|
+
transform: isVertical
|
|
258
|
+
? "translate(0px, ".concat(offset + gesteroffset[1], "px)")
|
|
259
|
+
: "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
|
|
260
|
+
flexDirection: isVertical ? 'column' : 'row',
|
|
261
|
+
flexShrink: 0,
|
|
262
|
+
}, class: "wrapper", onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))))));
|
|
263
263
|
}
|
|
264
|
-
// Carousel.Item = (props) => {
|
|
265
|
-
// return (
|
|
266
|
-
// <div
|
|
267
|
-
// style={
|
|
268
|
-
// {
|
|
269
|
-
// // width: '100%',
|
|
270
|
-
// // height: '100%',
|
|
271
|
-
// // flexShrink: 0,
|
|
272
|
-
// }
|
|
273
|
-
// }
|
|
274
|
-
// >
|
|
275
|
-
// {' '}
|
|
276
|
-
// {props.children}
|
|
277
|
-
// </div>
|
|
278
|
-
// );
|
|
279
|
-
// }
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Component, h } from 'preact';
|
|
1
|
+
import { Component, CSSProperties, h } from 'preact';
|
|
2
2
|
export interface SliderProps {
|
|
3
|
-
percent
|
|
4
|
-
wrapperWidth
|
|
5
|
-
wrapperHeight
|
|
6
|
-
height
|
|
3
|
+
percent?: number;
|
|
4
|
+
wrapperWidth?: number;
|
|
5
|
+
wrapperHeight?: number;
|
|
6
|
+
height?: number;
|
|
7
7
|
innerHeight?: number;
|
|
8
|
-
dotWidth
|
|
9
|
-
dotHeight
|
|
10
|
-
dotWrapperWidth
|
|
11
|
-
dotWrapperHeight
|
|
8
|
+
dotWidth?: number;
|
|
9
|
+
dotHeight?: number;
|
|
10
|
+
dotWrapperWidth?: number;
|
|
11
|
+
dotWrapperHeight?: number;
|
|
12
12
|
outerBg: string;
|
|
13
13
|
innerBg: string;
|
|
14
14
|
dotBg: string;
|
|
@@ -18,7 +18,7 @@ export interface SliderProps {
|
|
|
18
18
|
isDiscrete: boolean | null;
|
|
19
19
|
discrete?: number;
|
|
20
20
|
maxDiscrete?: number;
|
|
21
|
-
hasIncDecButton
|
|
21
|
+
hasIncDecButton?: boolean | null;
|
|
22
22
|
incButtonWidth?: number;
|
|
23
23
|
incButtonHeight?: number;
|
|
24
24
|
decButtonWidth?: number;
|
|
@@ -33,10 +33,43 @@ export interface SliderProps {
|
|
|
33
33
|
endRange?: number;
|
|
34
34
|
hasDot?: boolean;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
interface SliderState {
|
|
37
37
|
percent: number;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
onDraging: boolean;
|
|
39
|
+
wrapperStyle: CSSProperties;
|
|
40
|
+
outerStyle: CSSProperties;
|
|
41
|
+
innerStyle: CSSProperties;
|
|
42
|
+
dotStyle: CSSProperties;
|
|
43
|
+
dotWrapperStyle: CSSProperties;
|
|
44
|
+
incButtonStyle: CSSProperties;
|
|
45
|
+
decButtonStyle: CSSProperties;
|
|
46
|
+
withButtonStyle: CSSProperties;
|
|
47
|
+
}
|
|
48
|
+
export declare class Slider extends Component<SliderProps, SliderState> {
|
|
49
|
+
static defaultProps: {
|
|
50
|
+
percent: number;
|
|
51
|
+
wrapperHeight: number;
|
|
52
|
+
wrapperWidth: number;
|
|
53
|
+
height: number;
|
|
54
|
+
dotWidth: number;
|
|
55
|
+
dotHeight: number;
|
|
56
|
+
dotWrapperWidth: number;
|
|
57
|
+
dotWrapperHeight: number;
|
|
58
|
+
onDragStart: null;
|
|
59
|
+
onDrag: null;
|
|
60
|
+
onDragEnd: null;
|
|
61
|
+
isDiscrete: boolean;
|
|
62
|
+
discrete: number;
|
|
63
|
+
maxDiscrete: number;
|
|
64
|
+
hasIncDecButton: boolean;
|
|
65
|
+
overallWidth: number;
|
|
66
|
+
rangeControl: boolean;
|
|
67
|
+
hasDot: boolean;
|
|
68
|
+
};
|
|
69
|
+
private lastX;
|
|
70
|
+
private count;
|
|
71
|
+
private rect;
|
|
72
|
+
private discrete;
|
|
40
73
|
private refWrapper;
|
|
41
74
|
constructor(props: any);
|
|
42
75
|
componentDidMount(): void;
|
|
@@ -46,13 +79,14 @@ export declare class Slider extends Component<SliderProps, {
|
|
|
46
79
|
onDragEnd: (event: any) => void;
|
|
47
80
|
onDecClick: () => void;
|
|
48
81
|
onIncClick: () => void;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
82
|
+
wrapperStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
83
|
+
outerStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
84
|
+
innerStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
85
|
+
dotWrapperStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
86
|
+
dotStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
87
|
+
incButtonStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
88
|
+
decButtonStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
89
|
+
withButtonStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
|
|
57
90
|
render(): h.JSX.Element;
|
|
58
91
|
}
|
|
92
|
+
export {};
|
|
@@ -24,6 +24,17 @@ var __assign = (this && this.__assign) || function () {
|
|
|
24
24
|
};
|
|
25
25
|
return __assign.apply(this, arguments);
|
|
26
26
|
};
|
|
27
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
};
|
|
27
38
|
import { Component, createRef, h } from 'preact';
|
|
28
39
|
var rowCenterCenter = {
|
|
29
40
|
display: 'flex',
|
|
@@ -37,54 +48,46 @@ var rowBetweenCenter = {
|
|
|
37
48
|
justifyContent: 'space-between',
|
|
38
49
|
alignItems: 'center'
|
|
39
50
|
};
|
|
40
|
-
var
|
|
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) {
|
|
51
|
+
export var Slider = /** @class */ (function (_super) {
|
|
52
52
|
__extends(Slider, _super);
|
|
53
53
|
function Slider(props) {
|
|
54
54
|
var _this = _super.call(this, props) || this;
|
|
55
|
+
_this.lastX = undefined; // 上一次位置的横坐标
|
|
56
|
+
_this.count = 0; // 拖动条距离最左端的位置 [0, this.props.wrapperWidth]
|
|
57
|
+
_this.rect = undefined; // 滑动区域
|
|
55
58
|
_this.discrete = Math.round(_this.props.discrete == null ? 0 : _this.props.discrete);
|
|
56
59
|
_this.refWrapper = createRef();
|
|
60
|
+
//====================================================================================================
|
|
61
|
+
//事件相关
|
|
57
62
|
_this.onDragStart = function (event) {
|
|
58
63
|
console.log('【Slider】DragStart event.clientX--' + event.clientX + '-----percent----' + _this.state.percent + '-----currentX----' + (_this.state.percent / 10000 * _this.props.wrapperWidth));
|
|
59
|
-
lastX = event.clentX;
|
|
60
|
-
count = _this.state.percent / 10000 * _this.props.wrapperWidth;
|
|
64
|
+
_this.lastX = event.clentX;
|
|
65
|
+
_this.count = _this.state.percent / 10000 * _this.props.wrapperWidth;
|
|
66
|
+
_this.setState({
|
|
67
|
+
onDraging: true,
|
|
68
|
+
});
|
|
61
69
|
if (_this.props.onDragStart) {
|
|
62
70
|
_this.props.onDragStart();
|
|
63
71
|
}
|
|
64
72
|
};
|
|
65
73
|
_this.onDrag = function (event) {
|
|
66
|
-
if (event.clientX < rect.left - 50 || event.clientX > rect.right + 50)
|
|
74
|
+
if (event.clientX < _this.rect.left - 50 || event.clientX > _this.rect.right + 50)
|
|
67
75
|
return;
|
|
68
|
-
if (lastX == undefined) {
|
|
69
|
-
lastX = event.clientX;
|
|
76
|
+
if (_this.lastX == undefined) {
|
|
77
|
+
_this.lastX = event.clientX;
|
|
70
78
|
return;
|
|
71
79
|
}
|
|
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 * 10000;
|
|
77
|
-
if (_this.props.isDiscrete == true
|
|
78
|
-
newPercent = count / _this.props.wrapperWidth * _this.props.maxDiscrete;
|
|
80
|
+
var move = Number(event.clientX) - Number(_this.lastX);
|
|
81
|
+
_this.count += move;
|
|
82
|
+
_this.count = Math.min(_this.props.wrapperWidth, _this.count);
|
|
83
|
+
_this.count = Math.max(0, _this.count);
|
|
84
|
+
var newPercent = _this.count / _this.props.wrapperWidth * 10000;
|
|
85
|
+
if (_this.props.isDiscrete == true) {
|
|
86
|
+
newPercent = _this.count / _this.props.wrapperWidth * _this.props.maxDiscrete;
|
|
79
87
|
_this.discrete = Math.round(newPercent);
|
|
80
|
-
// this.setState({
|
|
81
|
-
// discrete: Math.round(newPercent),
|
|
82
|
-
// })
|
|
83
88
|
if (_this.props.rangeControl) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (_this.props.startRange != null)
|
|
87
|
-
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
89
|
+
_this.discrete = Math.min(_this.discrete, _this.props.endRange);
|
|
90
|
+
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
88
91
|
}
|
|
89
92
|
newPercent = _this.discrete * (10000 / _this.props.maxDiscrete);
|
|
90
93
|
}
|
|
@@ -95,14 +98,15 @@ var Slider = /** @class */ (function (_super) {
|
|
|
95
98
|
if (_this.props.onDrag)
|
|
96
99
|
_this.props.onDrag(_this.props.isDiscrete ? _this.discrete : newPercent);
|
|
97
100
|
});
|
|
98
|
-
lastX = event.clientX;
|
|
101
|
+
_this.lastX = event.clientX;
|
|
99
102
|
};
|
|
100
103
|
_this.onDragEnd = function (event) {
|
|
101
|
-
lastX = undefined;
|
|
102
|
-
if (_this.props.isDiscrete == true
|
|
104
|
+
_this.lastX = undefined;
|
|
105
|
+
if (_this.props.isDiscrete == true) {
|
|
103
106
|
//console.log("OnDragEnd -----discrete----"+this.state.discrete)
|
|
104
107
|
_this.setState({
|
|
105
108
|
percent: _this.discrete * (10000 / _this.props.maxDiscrete),
|
|
109
|
+
onDraging: false
|
|
106
110
|
}, function () {
|
|
107
111
|
console.log('【Slider】DragEnd event.clientX--' + event.clientX + '-----percent----' + _this.state.percent + '-----discrete----' + _this.discrete + '-----currentX----' + (_this.state.percent / 10000 * _this.props.wrapperWidth));
|
|
108
112
|
if (_this.props.onDragEnd) {
|
|
@@ -112,22 +116,26 @@ var Slider = /** @class */ (function (_super) {
|
|
|
112
116
|
}
|
|
113
117
|
else {
|
|
114
118
|
console.log('【Slider】DragEnd event.clientX--' + event.clientX + '-----percent----' + _this.state.percent + '-----currentX----' + (_this.state.percent / 10000 * _this.props.wrapperWidth));
|
|
115
|
-
|
|
116
|
-
_this.
|
|
117
|
-
|
|
119
|
+
_this.setState({
|
|
120
|
+
percent: _this.count / _this.props.wrapperWidth * 10000,
|
|
121
|
+
onDraging: false
|
|
122
|
+
}, function () {
|
|
123
|
+
if (_this.props.onDragEnd) {
|
|
124
|
+
_this.props.onDragEnd(_this.props.isDiscrete ? _this.discrete : _this.state.percent);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
118
127
|
}
|
|
119
128
|
};
|
|
120
129
|
_this.onDecClick = function () {
|
|
121
130
|
//离散的情况
|
|
122
|
-
if (_this.props.isDiscrete
|
|
131
|
+
if (_this.props.isDiscrete) {
|
|
123
132
|
if (_this.discrete >= 1) {
|
|
124
133
|
_this.discrete -= 1;
|
|
125
|
-
if (_this.props.rangeControl
|
|
134
|
+
if (_this.props.rangeControl) {
|
|
126
135
|
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
127
136
|
}
|
|
128
137
|
var newPercent = _this.discrete * (10000 / _this.props.maxDiscrete);
|
|
129
138
|
_this.setState({
|
|
130
|
-
//discrete: this.state.discrete - 1,
|
|
131
139
|
percent: newPercent
|
|
132
140
|
}, function () {
|
|
133
141
|
if (_this.props.onDecClick) {
|
|
@@ -151,10 +159,10 @@ var Slider = /** @class */ (function (_super) {
|
|
|
151
159
|
};
|
|
152
160
|
_this.onIncClick = function () {
|
|
153
161
|
//离散的情况
|
|
154
|
-
if (_this.props.isDiscrete
|
|
162
|
+
if (_this.props.isDiscrete) {
|
|
155
163
|
if (_this.discrete < _this.props.maxDiscrete) {
|
|
156
164
|
_this.discrete += 1;
|
|
157
|
-
if (_this.props.rangeControl
|
|
165
|
+
if (_this.props.rangeControl) {
|
|
158
166
|
_this.discrete = Math.max(_this.discrete, _this.props.startRange);
|
|
159
167
|
}
|
|
160
168
|
var newPercent = _this.discrete * (10000 / _this.props.maxDiscrete);
|
|
@@ -181,11 +189,14 @@ var Slider = /** @class */ (function (_super) {
|
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
};
|
|
184
|
-
|
|
185
|
-
|
|
192
|
+
//====================================================================================================
|
|
193
|
+
//样式相关
|
|
194
|
+
_this.wrapperStyle = function () {
|
|
195
|
+
var wrapperStyle = __assign({ width: _this.props.wrapperWidth + 'px', height: _this.props.wrapperHeight + 'px' }, rowCenterCenter);
|
|
196
|
+
return wrapperStyle;
|
|
186
197
|
};
|
|
187
|
-
_this.
|
|
188
|
-
outerStyle = {
|
|
198
|
+
_this.outerStyle = function () {
|
|
199
|
+
var outerStyle = {
|
|
189
200
|
width: '100%',
|
|
190
201
|
height: _this.props.height + 'px',
|
|
191
202
|
backgroundImage: "url(".concat(_this.props.outerBg, ")"),
|
|
@@ -195,11 +206,11 @@ var Slider = /** @class */ (function (_super) {
|
|
|
195
206
|
justifyContent: 'start',
|
|
196
207
|
alignItems: 'center'
|
|
197
208
|
};
|
|
209
|
+
return outerStyle;
|
|
198
210
|
};
|
|
199
|
-
_this.
|
|
200
|
-
var
|
|
201
|
-
|
|
202
|
-
width: innerWidth,
|
|
211
|
+
_this.innerStyle = function () {
|
|
212
|
+
var innerStyle = {
|
|
213
|
+
// width: innerWidth,
|
|
203
214
|
height: (_this.props.innerHeight != null) ? _this.props.innerHeight + 'px' : '100%',
|
|
204
215
|
backgroundImage: "url(".concat(_this.props.innerBg, ")"),
|
|
205
216
|
backgroundSize: '100% 100%',
|
|
@@ -208,82 +219,133 @@ var Slider = /** @class */ (function (_super) {
|
|
|
208
219
|
justifyContent: 'start',
|
|
209
220
|
alignItems: 'center'
|
|
210
221
|
};
|
|
222
|
+
return innerStyle;
|
|
211
223
|
};
|
|
212
|
-
_this.
|
|
213
|
-
dotWrapperStyle = __assign({ position: 'absolute', width: _this.props.dotWrapperWidth + 'px', height: _this.props.dotWrapperHeight + 'px',
|
|
214
|
-
//marginTop: (this.props.height - this.props.dotWrapperHeight) / 2 + "px",
|
|
215
|
-
marginLeft: (_this.props.wrapperWidth * _this.state.percent / 10000 - _this.props.dotWrapperWidth / 2) + 'px' }, rowCenterCenter
|
|
224
|
+
_this.dotWrapperStyle = function () {
|
|
225
|
+
var dotWrapperStyle = __assign({ position: 'absolute', width: _this.props.dotWrapperWidth + 'px', height: _this.props.dotWrapperHeight + 'px' }, rowCenterCenter
|
|
216
226
|
// backgroundColor: '#FF000066'
|
|
217
227
|
);
|
|
228
|
+
return dotWrapperStyle;
|
|
218
229
|
};
|
|
219
|
-
_this.
|
|
220
|
-
dotStyle = {
|
|
230
|
+
_this.dotStyle = function () {
|
|
231
|
+
var dotStyle = {
|
|
221
232
|
width: _this.props.dotWidth + 'px',
|
|
222
233
|
height: _this.props.dotHeight + 'px',
|
|
223
234
|
};
|
|
235
|
+
return dotStyle;
|
|
224
236
|
};
|
|
225
|
-
_this.
|
|
226
|
-
incButtonStyle = {
|
|
237
|
+
_this.incButtonStyle = function () {
|
|
238
|
+
var incButtonStyle = {
|
|
227
239
|
width: _this.props.incButtonWidth + 'px',
|
|
228
240
|
height: _this.props.incButtonHeight + 'px',
|
|
229
241
|
//marginLeft:this.props.incButtonLeft+"px",
|
|
230
242
|
//backgroundImage: `url(${this.props.incButtonBg})`,
|
|
231
243
|
};
|
|
244
|
+
return incButtonStyle;
|
|
232
245
|
};
|
|
233
|
-
_this.
|
|
234
|
-
decButtonStyle = {
|
|
246
|
+
_this.decButtonStyle = function () {
|
|
247
|
+
var decButtonStyle = {
|
|
235
248
|
width: _this.props.decButtonWidth + 'px',
|
|
236
249
|
height: _this.props.decButtonHeight + 'px',
|
|
237
250
|
//marginRight:this.props.decButtonRight+"px",
|
|
238
251
|
//backgroundImage: `url(${this.props.decButtonBg})`,
|
|
239
252
|
};
|
|
253
|
+
return decButtonStyle;
|
|
240
254
|
};
|
|
241
|
-
_this.
|
|
242
|
-
withButtonStyle = __assign({ minWidth: _this.props.overallWidth + 'px' }, rowBetweenCenter);
|
|
255
|
+
_this.withButtonStyle = function () {
|
|
256
|
+
var withButtonStyle = __assign({ minWidth: _this.props.overallWidth + 'px' }, rowBetweenCenter);
|
|
257
|
+
return withButtonStyle;
|
|
243
258
|
};
|
|
244
259
|
_this.state = {
|
|
245
|
-
percent:
|
|
246
|
-
|
|
260
|
+
percent: props.isDiscrete ? _this.props.discrete * (10000 / _this.props.maxDiscrete) : Math.floor(_this.props.percent),
|
|
261
|
+
onDraging: false,
|
|
262
|
+
wrapperStyle: _this.wrapperStyle(),
|
|
263
|
+
outerStyle: _this.outerStyle(),
|
|
264
|
+
innerStyle: _this.innerStyle(),
|
|
265
|
+
dotStyle: _this.dotStyle(),
|
|
266
|
+
dotWrapperStyle: _this.dotWrapperStyle(),
|
|
267
|
+
incButtonStyle: _this.incButtonStyle(),
|
|
268
|
+
decButtonStyle: _this.decButtonStyle(),
|
|
269
|
+
withButtonStyle: _this.withButtonStyle(),
|
|
247
270
|
};
|
|
248
|
-
_this.computeWrapperStyle();
|
|
249
|
-
_this.computeOuterStyle();
|
|
250
271
|
return _this;
|
|
251
272
|
}
|
|
273
|
+
//====================================================================================================
|
|
274
|
+
//生命周期相关
|
|
252
275
|
Slider.prototype.componentDidMount = function () {
|
|
253
|
-
rect = this.refWrapper.current.getBoundingClientRect();
|
|
276
|
+
this.rect = this.refWrapper.current.getBoundingClientRect();
|
|
254
277
|
};
|
|
255
278
|
Slider.prototype.componentWillReceiveProps = function (nextProps) {
|
|
256
|
-
if (
|
|
279
|
+
if (JSON.stringify(this.props) === JSON.stringify(nextProps))
|
|
257
280
|
return;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
281
|
+
//用于标识位置的props和其他样式相关的props分开比较
|
|
282
|
+
var _a = this.props, percent = _a.percent, discrete = _a.discrete, styleProps = __rest(_a, ["percent", "discrete"]);
|
|
283
|
+
var nextPercent = nextProps.percent, nextDiscrete = nextProps.discrete, nextstyleProps = __rest(nextProps, ["percent", "discrete"]);
|
|
284
|
+
//拖动状态时,忽略外部传入的percent值,优先用户拖动
|
|
285
|
+
var shouldUpdatePercent = !(this.state.onDraging) &&
|
|
286
|
+
!(percent == nextPercent && discrete == nextDiscrete);
|
|
287
|
+
console.log('检查shouldUpdatePercent', shouldUpdatePercent);
|
|
288
|
+
if (shouldUpdatePercent) {
|
|
289
|
+
//如果从外部传入percent/discrete,则组件可根据新props来更新滑动条位置
|
|
290
|
+
//离散情况
|
|
291
|
+
if (this.props.isDiscrete == true) {
|
|
292
|
+
this.discrete = nextProps.discrete;
|
|
293
|
+
this.setState({
|
|
294
|
+
percent: this.discrete * (10000 / this.props.maxDiscrete)
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
//连续情况
|
|
298
|
+
else {
|
|
299
|
+
this.setState({
|
|
300
|
+
percent: nextProps.percent,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
264
303
|
}
|
|
265
|
-
|
|
304
|
+
//如果slider传入样式相关props有更改
|
|
305
|
+
if (JSON.stringify(styleProps) !== JSON.stringify(nextstyleProps)) {
|
|
266
306
|
this.setState({
|
|
267
|
-
|
|
307
|
+
wrapperStyle: this.wrapperStyle(),
|
|
308
|
+
outerStyle: this.outerStyle(),
|
|
309
|
+
innerStyle: this.innerStyle(),
|
|
310
|
+
dotStyle: this.dotStyle(),
|
|
311
|
+
dotWrapperStyle: this.dotWrapperStyle(),
|
|
312
|
+
incButtonStyle: this.incButtonStyle(),
|
|
313
|
+
decButtonStyle: this.decButtonStyle(),
|
|
314
|
+
withButtonStyle: this.withButtonStyle(),
|
|
268
315
|
});
|
|
269
316
|
}
|
|
270
317
|
};
|
|
271
318
|
Slider.prototype.render = function () {
|
|
272
|
-
this.computeInnerStyle();
|
|
273
|
-
this.computeDotWrapperStyle();
|
|
274
|
-
this.computeDotStyle();
|
|
275
|
-
this.computeIncButtonStyle();
|
|
276
|
-
this.computeDecButtonStyle();
|
|
277
|
-
this.computeWithButtonStyle();
|
|
278
319
|
var hasDot = this.props.hasDot === undefined || this.props.hasDot === true;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
320
|
+
var innerWidth = Math.floor(this.state.percent / 100) + '%';
|
|
321
|
+
var dotWrapperMarginLeft = (this.props.wrapperWidth * this.state.percent / 10000 - this.props.dotWrapperWidth / 2) + 'px';
|
|
322
|
+
return (h("div", { style: this.props.hasIncDecButton ? this.state.withButtonStyle : {} },
|
|
323
|
+
this.props.hasIncDecButton && h("img", { src: this.props.decButtonBg, style: this.state.decButtonStyle, onClick: this.onDecClick }),
|
|
324
|
+
h("div", { ref: this.refWrapper, style: this.state.wrapperStyle },
|
|
325
|
+
h("div", { style: this.state.outerStyle },
|
|
326
|
+
h("div", { style: __assign(__assign({}, this.state.innerStyle), { width: innerWidth }) },
|
|
327
|
+
h("div", { style: __assign(__assign({}, this.state.dotWrapperStyle), { marginLeft: dotWrapperMarginLeft }), draggable: true, onDragStart: this.onDragStart, onDrag: this.onDrag, onDragEnd: this.onDragEnd }, hasDot && h("img", { src: this.props.dotBg, style: this.state.dotStyle }))))),
|
|
328
|
+
this.props.hasIncDecButton && h("img", { src: this.props.incButtonBg, style: this.state.incButtonStyle, onClick: this.onIncClick })));
|
|
329
|
+
};
|
|
330
|
+
Slider.defaultProps = {
|
|
331
|
+
percent: 0,
|
|
332
|
+
wrapperHeight: 34,
|
|
333
|
+
wrapperWidth: 376,
|
|
334
|
+
height: 5,
|
|
335
|
+
dotWidth: 26,
|
|
336
|
+
dotHeight: 27,
|
|
337
|
+
dotWrapperWidth: 56,
|
|
338
|
+
dotWrapperHeight: 57,
|
|
339
|
+
onDragStart: null,
|
|
340
|
+
onDrag: null,
|
|
341
|
+
onDragEnd: null,
|
|
342
|
+
isDiscrete: true,
|
|
343
|
+
discrete: 0,
|
|
344
|
+
maxDiscrete: 100,
|
|
345
|
+
hasIncDecButton: false,
|
|
346
|
+
overallWidth: 500,
|
|
347
|
+
rangeControl: false,
|
|
348
|
+
hasDot: true,
|
|
286
349
|
};
|
|
287
350
|
return Slider;
|
|
288
351
|
}(Component));
|
|
289
|
-
export { Slider };
|