pixuireactcomponents 1.3.25 → 1.3.27

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,12 +1,11 @@
1
1
  export { Carousel } from "./src/components/react/app/carousel/Carousel";
2
2
  export { Button } from "./src/components/react/app/button/Button";
3
- export { Checkbox } from "./src/components/react/app/checkBox/CheckBox";
4
3
  export { Dropdown } from "./src/components/react/app/dropdown/Dropdown";
5
4
  export { ImageViewer } from "./src/components/react/app/imageViewer/imageViewer";
6
- export { Slider } from "./src/components/react/app/slider/Slider";
7
5
  export { ToggleGroup } from "./src/components/react/app/togglegroup/ToggleGroup";
8
6
  export { GradientText } from "./src/components/react/base/gradient/GradientText";
9
7
  export { PVideo } from "./src/components/react/base/pixVideo/PixVideo";
10
8
  export { OutlineText } from "./src/components/react/base/outlinetext/OutlineText";
11
9
  export { ImgPreLoader } from "./src/components/tools/ImgPreLoader";
12
10
  export { Logger } from "./src/components/tools/Logger";
11
+ export { Slider, SliderProps } from "./src/components/react/app/slider/Slider";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.25",
3
+ "version": "1.3.27",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,6 +6,8 @@ interface ButtonProps {
6
6
  hoverStyle: JCSSProperties;
7
7
  pressStyle: JCSSProperties;
8
8
  clickEvent: Function;
9
+ id: string;
10
+ className: string;
9
11
  }
10
12
  export declare let Button: (props: ButtonProps) => h.JSX.Element;
11
13
  export {};
@@ -9,11 +9,7 @@ var ButtonState;
9
9
  export var Button = function (props) {
10
10
  var _a;
11
11
  var buttonState = (_a = useState(ButtonState.normal), _a[0]), setButtonState = _a[1];
12
- return (h("div", { style: buttonState == ButtonState.normal
13
- ? props.normalStyle
14
- : buttonState == ButtonState.hover
15
- ? props.hoverStyle
16
- : props.pressStyle, onMouseDown: function () {
12
+ return (h("div", { style: buttonState == ButtonState.normal ? props.normalStyle : buttonState == ButtonState.hover ? props.hoverStyle : props.pressStyle, onMouseDown: function () {
17
13
  setButtonState(ButtonState.press);
18
14
  }, onMouseUp: function () {
19
15
  setButtonState(ButtonState.hover);
@@ -22,5 +18,5 @@ export var Button = function (props) {
22
18
  setButtonState(ButtonState.hover);
23
19
  }, onMouseOut: function () {
24
20
  setButtonState(ButtonState.normal);
25
- } }, props.text));
21
+ }, id: props.id, className: props.className }, props.text));
26
22
  };
@@ -12,9 +12,11 @@ import { h } from 'preact';
12
12
  * @param isVertical - 轮播元素滚动方向
13
13
  * @param touchable - 是否允许手势切换
14
14
  * @param onSlideChange - 切换元素后的回调函数
15
- * @param onclickEvent - 点击元素的回调函数
15
+ * @param onClick - 点击元素的回调函数
16
16
  */
17
17
  export declare function Carousel(props: {
18
+ id?: string;
19
+ className?: string;
18
20
  cRef?: any;
19
21
  children?: preact.JSX.Element[] | HTMLElement[];
20
22
  defaultIndex?: number;
@@ -26,5 +28,5 @@ export declare function Carousel(props: {
26
28
  isVertical?: boolean;
27
29
  touchable?: boolean;
28
30
  onSlideChange?: Function | null;
29
- onclickEvent?: Function | null;
31
+ onClick?: Function | null;
30
32
  }): h.JSX.Element;
@@ -19,7 +19,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
19
  return to.concat(ar || Array.prototype.slice.call(from));
20
20
  };
21
21
  import { h } from 'preact';
22
- import { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../../../../../lib/preact/hooks/src';
22
+ import { useImperativeHandle, useState, useRef, useMemo, useEffect } from 'preact/hooks';
23
23
  // import { memo } from '../../../../../lib/preact/compat/src';
24
24
  //组件优化,防止组件的props没有改变但父组件刷新时导致组件刷新
25
25
  // export let Carousel = memo(Carouselinner, (prev, next) => {
@@ -58,29 +58,48 @@ import { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../..
58
58
  * @param isVertical - 轮播元素滚动方向
59
59
  * @param touchable - 是否允许手势切换
60
60
  * @param onSlideChange - 切换元素后的回调函数
61
- * @param onclickEvent - 点击元素的回调函数
61
+ * @param onClick - 点击元素的回调函数
62
62
  */
63
63
  export function Carousel(props) {
64
- var _a = props.children, children = _a === void 0 ? [] : _a, _b = props.defaultIndex, defaultIndex = _b === void 0 ? 1 : _b, _c = props.compWidth, compWidth = _c === void 0 ? 100 : _c, _d = props.compHeight, compHeight = _d === void 0 ? 100 : _d, _e = props.autoplay, autoplay = _e === void 0 ? true : _e, _f = props.switchDuration, switchDuration = _f === void 0 ? 3000 : _f, _g = props.loop, loop = _g === void 0 ? true : _g, _h = props.isVertical, isVertical = _h === void 0 ? false : _h, _j = props.touchable, touchable = _j === void 0 ? true : _j, _k = props.onSlideChange, onSlideChange = _k === void 0 ? null : _k, _l = props.onclickEvent, onclickEvent = _l === void 0 ? null : _l;
64
+ var _a = props.id, id = _a === void 0 ? '' : _a, _b = props.className, className = _b === void 0 ? '' : _b, _c = props.children, children = _c === void 0 ? [] : _c, _d = props.defaultIndex, defaultIndex = _d === void 0 ? 1 : _d, _e = props.compWidth, compWidth = _e === void 0 ? 100 : _e, _f = props.compHeight, compHeight = _f === void 0 ? 100 : _f, _g = props.autoplay, autoplay = _g === void 0 ? true : _g, _h = props.switchDuration, switchDuration = _h === void 0 ? 3000 : _h, _j = props.loop, loop = _j === void 0 ? true : _j, _k = props.isVertical, isVertical = _k === void 0 ? false : _k, _l = props.touchable, touchable = _l === void 0 ? true : _l, _m = props.onSlideChange, onSlideChange = _m === void 0 ? null : _m, _o = props.onClick, onClick = _o === void 0 ? null : _o;
65
65
  // console.log('children', children.length);
66
+ var safeNext = function () {
67
+ if (!canClickSwitch.current)
68
+ return;
69
+ canClickSwitch.current = false;
70
+ setTimeout(function () {
71
+ canClickSwitch.current = true;
72
+ }, 1000);
73
+ handleNext();
74
+ };
75
+ var safePrev = function () {
76
+ if (!canClickSwitch.current)
77
+ return;
78
+ canClickSwitch.current = false;
79
+ setTimeout(function () {
80
+ canClickSwitch.current = true;
81
+ }, 1000);
82
+ handlePrev();
83
+ };
66
84
  useImperativeHandle(props.cRef, function () { return ({
67
- handleNext: handleNext,
68
- handlePrev: handlePrev,
85
+ handleNext: safeNext,
86
+ handlePrev: safePrev,
69
87
  setShowIndex: setShowIndex,
70
88
  }); });
71
89
  var duration = switchDuration < 1000 ? 1000 : switchDuration;
72
- var _m = useState(defaultIndex), showIndex = _m[0], setShowIndex = _m[1];
90
+ var _p = useState(defaultIndex), showIndex = _p[0], setShowIndex = _p[1];
73
91
  //轮播元素正在滚动
74
92
  var isMoving = useRef(false);
75
93
  //鼠标手势信息
76
94
  var isMouseDown = useRef(false);
77
95
  var mouseDownX = useRef(0);
78
96
  var mouseDownY = useRef(0);
97
+ //pixui在 onTransitionEnd 之后马上触发 transform 会丢onTransitionEnd
98
+ var canClickSwitch = useRef(true);
79
99
  var handleNextRef = useRef(function () { });
80
100
  var nextInterval = useRef();
81
- var _o = useState(true), showTransition = _o[0], setShowTransition = _o[1];
82
- var _p = useState([0, 0]), gesteroffset = _p[0], setGesteroffset = _p[1];
83
- var _q = useState(''), logTex = _q[0], setLogTex = _q[1];
101
+ var _q = useState(true), showTransition = _q[0], setShowTransition = _q[1];
102
+ var _r = useState([0, 0]), gesteroffset = _r[0], setGesteroffset = _r[1];
84
103
  var offset = useMemo(function () { return -(isVertical ? compHeight : compWidth) * showIndex; }, [showIndex]);
85
104
  var itemBoxStyle = {
86
105
  minWidth: compWidth + 'px',
@@ -101,7 +120,7 @@ export function Carousel(props) {
101
120
  //组件展示内容长度改变的时候改回到第一个元素,刷新autoplay判断
102
121
  useEffect(function () {
103
122
  setNextInterval();
104
- setShowIndex(1);
123
+ setShowIndex(defaultIndex);
105
124
  }, [children]);
106
125
  useEffect(function () {
107
126
  //每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
@@ -136,7 +155,6 @@ export function Carousel(props) {
136
155
  }
137
156
  };
138
157
  var handleNext = function () {
139
- // console.log('nex', isMoving.current, showIndex, isVertical ? `translate(0px, ${offset}px)` : `translate(${offset}px, 0px)`)
140
158
  if (!loop && showIndex == carouselItems.length - 2)
141
159
  return;
142
160
  if (isMoving.current)
@@ -228,24 +246,12 @@ export function Carousel(props) {
228
246
  var gestureClick = function (props) {
229
247
  if (isMoving.current)
230
248
  return;
231
- if (onclickEvent) {
232
- onclickEvent(showIndex - 1);
249
+ if (onClick) {
250
+ onClick(showIndex - 1);
233
251
  }
234
252
  };
235
- return (h("div", { style: { flexDirection: 'column' } },
236
- h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
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 () {
253
+ return (h("div", { style: { flexDirection: 'column', width: compWidth, height: compHeight }, id: id, className: className },
254
+ h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function (ev) {
249
255
  gestureClick(props);
250
256
  }, class: 'GestureComp', onDragStart: function (e) {
251
257
  if (children.length > 1) {
@@ -259,21 +265,15 @@ export function Carousel(props) {
259
265
  if (children.length > 1) {
260
266
  gestureUp();
261
267
  }
262
- } })));
268
+ } },
269
+ h("div", { style: __assign(__assign({ position: 'relative' }, itemBoxStyle), { overflow: 'hidden', flexShrink: 0 }) },
270
+ h("div", { style: {
271
+ display: 'flex',
272
+ width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
273
+ height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
274
+ transition: "transform ".concat(showTransition ? '0.5s' : '0s', " ease 0s"),
275
+ transform: isVertical ? "translate(0px, ".concat(offset + gesteroffset[1], "px)") : "translate(".concat(offset + gesteroffset[0], "px, 0px)"),
276
+ flexDirection: isVertical ? 'column' : 'row',
277
+ flexShrink: 0,
278
+ }, class: "wrapper", onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))))));
263
279
  }
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,7 +1,10 @@
1
1
  import { h } from 'preact';
2
- export declare function Checkbox(props: {
3
- selectedChanged: Function | null;
4
- defauleSelected: boolean;
5
- selectedNode: any;
6
- notSelectedNode: any;
2
+ export declare function CheckBox(props: {
3
+ id?: string;
4
+ className?: string;
5
+ selectedChanged?: Function;
6
+ defauleSelected?: boolean;
7
+ selectedNode?: any;
8
+ notSelectedNode?: any;
9
+ toggleSize?: number;
7
10
  }): h.JSX.Element;
@@ -1,13 +1,12 @@
1
1
  import { h } from 'preact';
2
- import { useState } from '../../../../../lib/preact/hooks/src';
3
- export function Checkbox(props) {
4
- var _a = props.selectedChanged, selectedChanged = _a === void 0 ? null : _a, _b = props.defauleSelected, defauleSelected = _b === void 0 ? false : _b, _c = props.selectedNode, selectedNode = _c === void 0 ? null : _c, _d = props.notSelectedNode, notSelectedNode = _d === void 0 ? null : _d;
5
- var _e = useState(defauleSelected), selected = _e[0], setSelected = _e[1];
6
- var cli = function () {
7
- if (selectedChanged) {
8
- selectedChanged(!selected);
9
- }
10
- setSelected(!selected);
11
- };
12
- return h("div", { onClick: cli }, selected ? selectedNode : notSelectedNode);
2
+ import { useState } from 'preact/hooks';
3
+ export function CheckBox(props) {
4
+ var _a = props.id, id = _a === void 0 ? '' : _a, _b = props.className, className = _b === void 0 ? '' : _b, _c = props.selectedChanged, selectedChanged = _c === void 0 ? null : _c, _d = props.defauleSelected, defauleSelected = _d === void 0 ? false : _d, _e = props.toggleSize, toggleSize = _e === void 0 ? 20 : _e;
5
+ var _f = useState(defauleSelected), selected = _f[0], setSelected = _f[1];
6
+ props.selectedNode = props.selectedNode || (h("img", { src: "https://game.gtimg.cn/images/gamelet/cp/pixui-jnResources/check-box.png", style: { width: toggleSize + 'px', height: toggleSize + 'px' } }));
7
+ props.notSelectedNode = props.notSelectedNode || (h("img", { src: "https://game.gtimg.cn/images/gamelet/cp/pixui-jnResources/blank-check-box.png", style: { width: toggleSize + 'px', height: toggleSize + 'px' } }));
8
+ return (h("div", { onClick: function () {
9
+ selectedChanged && selectedChanged(!selected);
10
+ setSelected(!selected);
11
+ }, id: id, className: className }, selected ? props.selectedNode : props.notSelectedNode));
13
12
  }
@@ -1,14 +1,16 @@
1
- import { Component, h } from 'preact';
1
+ import { Component, CSSProperties, h } from 'preact';
2
2
  export interface SliderProps {
3
- percent: number;
4
- wrapperWidth: number;
5
- wrapperHeight: number;
6
- height: number;
3
+ id?: string;
4
+ className?: string;
5
+ percent?: number;
6
+ wrapperWidth?: number;
7
+ wrapperHeight?: number;
8
+ height?: number;
7
9
  innerHeight?: number;
8
- dotWidth: number;
9
- dotHeight: number;
10
- dotWrapperWidth: number;
11
- dotWrapperHeight: number;
10
+ dotWidth?: number;
11
+ dotHeight?: number;
12
+ dotWrapperWidth?: number;
13
+ dotWrapperHeight?: number;
12
14
  outerBg: string;
13
15
  innerBg: string;
14
16
  dotBg: string;
@@ -18,7 +20,7 @@ export interface SliderProps {
18
20
  isDiscrete: boolean | null;
19
21
  discrete?: number;
20
22
  maxDiscrete?: number;
21
- hasIncDecButton: boolean | null;
23
+ hasIncDecButton?: boolean | null;
22
24
  incButtonWidth?: number;
23
25
  incButtonHeight?: number;
24
26
  decButtonWidth?: number;
@@ -33,10 +35,43 @@ export interface SliderProps {
33
35
  endRange?: number;
34
36
  hasDot?: boolean;
35
37
  }
36
- export declare class Slider extends Component<SliderProps, {
38
+ interface SliderState {
37
39
  percent: number;
38
- }> {
39
- discrete: number;
40
+ onDraging: boolean;
41
+ wrapperStyle: CSSProperties;
42
+ outerStyle: CSSProperties;
43
+ innerStyle: CSSProperties;
44
+ dotStyle: CSSProperties;
45
+ dotWrapperStyle: CSSProperties;
46
+ incButtonStyle: CSSProperties;
47
+ decButtonStyle: CSSProperties;
48
+ withButtonStyle: CSSProperties;
49
+ }
50
+ export declare class Slider extends Component<SliderProps, SliderState> {
51
+ static defaultProps: {
52
+ percent: number;
53
+ wrapperHeight: number;
54
+ wrapperWidth: number;
55
+ height: number;
56
+ dotWidth: number;
57
+ dotHeight: number;
58
+ dotWrapperWidth: number;
59
+ dotWrapperHeight: number;
60
+ onDragStart: null;
61
+ onDrag: null;
62
+ onDragEnd: null;
63
+ isDiscrete: boolean;
64
+ discrete: number;
65
+ maxDiscrete: number;
66
+ hasIncDecButton: boolean;
67
+ overallWidth: number;
68
+ rangeControl: boolean;
69
+ hasDot: boolean;
70
+ };
71
+ private lastX;
72
+ private count;
73
+ private rect;
74
+ private discrete;
40
75
  private refWrapper;
41
76
  constructor(props: any);
42
77
  componentDidMount(): void;
@@ -46,13 +81,14 @@ export declare class Slider extends Component<SliderProps, {
46
81
  onDragEnd: (event: any) => void;
47
82
  onDecClick: () => void;
48
83
  onIncClick: () => void;
49
- computeWrapperStyle: () => void;
50
- computeOuterStyle: () => void;
51
- computeInnerStyle: () => void;
52
- computeDotWrapperStyle: () => void;
53
- computeDotStyle: () => void;
54
- computeIncButtonStyle: () => void;
55
- computeDecButtonStyle: () => void;
56
- computeWithButtonStyle: () => void;
84
+ wrapperStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
85
+ outerStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
86
+ innerStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
87
+ dotWrapperStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
88
+ dotStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
89
+ incButtonStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
90
+ decButtonStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
91
+ withButtonStyle: () => import("../../../../../lib/preact/src/jsx").JCSSProperties;
57
92
  render(): h.JSX.Element;
58
93
  }
94
+ export {};
@@ -24,111 +24,165 @@ 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',
30
41
  flexDirection: 'row',
31
42
  justifyContent: 'center',
32
- alignItems: 'center'
43
+ alignItems: 'center',
33
44
  };
34
45
  var rowBetweenCenter = {
35
46
  display: 'flex',
36
47
  flexDirection: 'row',
37
48
  justifyContent: 'space-between',
38
- alignItems: 'center'
49
+ alignItems: 'center',
39
50
  };
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) {
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
- 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;
63
+ console.log('【Slider】DragStart event.clientX--' +
64
+ event.clientX +
65
+ '-----percent----' +
66
+ _this.state.percent +
67
+ '-----currentX----' +
68
+ (_this.state.percent / 10000) * _this.props.wrapperWidth);
69
+ _this.lastX = event.clentX;
70
+ _this.count = (_this.state.percent / 10000) * _this.props.wrapperWidth;
71
+ _this.setState({
72
+ onDraging: true,
73
+ });
61
74
  if (_this.props.onDragStart) {
62
75
  _this.props.onDragStart();
63
76
  }
64
77
  };
65
78
  _this.onDrag = function (event) {
66
- if (event.clientX < rect.left - 50 || event.clientX > rect.right + 50)
79
+ console.log('【Slider】onDrag0 event.clientX--' +
80
+ event.clientX +
81
+ '-----percent----' +
82
+ _this.state.percent +
83
+ '-----currentX----' +
84
+ (_this.state.percent / 10000) * _this.props.wrapperWidth +
85
+ 'rect.left' +
86
+ _this.rect.left +
87
+ 'rect.right' +
88
+ _this.rect.right);
89
+ if (event.clientX < _this.rect.left - 50 || event.clientX > _this.rect.right + 50)
67
90
  return;
68
- if (lastX == undefined) {
69
- lastX = event.clientX;
91
+ console.log('【Slider】onDrag1 event.clientX--' +
92
+ event.clientX +
93
+ '-----percent----' +
94
+ _this.state.percent +
95
+ '-----currentX----' +
96
+ (_this.state.percent / 10000) * _this.props.wrapperWidth);
97
+ if (_this.lastX == undefined) {
98
+ _this.lastX = event.clientX;
70
99
  return;
71
100
  }
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 && _this.props.maxDiscrete != null) {
78
- newPercent = count / _this.props.wrapperWidth * _this.props.maxDiscrete;
101
+ console.log('【Slider】onDrag2 event.clientX--' +
102
+ event.clientX +
103
+ '-----percent----' +
104
+ _this.state.percent +
105
+ '-----currentX----' +
106
+ (_this.state.percent / 10000) * _this.props.wrapperWidth);
107
+ var move = Number(event.clientX) - Number(_this.lastX);
108
+ _this.count += move;
109
+ _this.count = Math.min(_this.props.wrapperWidth, _this.count);
110
+ _this.count = Math.max(0, _this.count);
111
+ var newPercent = (_this.count / _this.props.wrapperWidth) * 10000;
112
+ if (_this.props.isDiscrete == true) {
113
+ newPercent = (_this.count / _this.props.wrapperWidth) * _this.props.maxDiscrete;
79
114
  _this.discrete = Math.round(newPercent);
80
- // this.setState({
81
- // discrete: Math.round(newPercent),
82
- // })
83
115
  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);
116
+ _this.discrete = Math.min(_this.discrete, _this.props.endRange);
117
+ _this.discrete = Math.max(_this.discrete, _this.props.startRange);
88
118
  }
89
119
  newPercent = _this.discrete * (10000 / _this.props.maxDiscrete);
90
120
  }
91
121
  _this.setState({
92
- percent: newPercent
122
+ percent: newPercent,
93
123
  }, function () {
94
- console.log('【Slider】OnDrag event.clientX--' + event.clientX + '-----percent----' + _this.state.percent + '-----discrete----' + _this.discrete + '-----currentX----' + (_this.state.percent / 10000 * _this.props.wrapperWidth));
124
+ console.log('【Slider】OnDrag event.clientX--' +
125
+ event.clientX +
126
+ '-----percent----' +
127
+ _this.state.percent +
128
+ '-----discrete----' +
129
+ _this.discrete +
130
+ '-----currentX----' +
131
+ (_this.state.percent / 10000) * _this.props.wrapperWidth);
95
132
  if (_this.props.onDrag)
96
133
  _this.props.onDrag(_this.props.isDiscrete ? _this.discrete : newPercent);
97
134
  });
98
- lastX = event.clientX;
135
+ _this.lastX = event.clientX;
99
136
  };
100
137
  _this.onDragEnd = function (event) {
101
- lastX = undefined;
102
- if (_this.props.isDiscrete == true && _this.props.maxDiscrete != null) {
138
+ _this.lastX = undefined;
139
+ if (_this.props.isDiscrete == true) {
103
140
  //console.log("OnDragEnd -----discrete----"+this.state.discrete)
104
141
  _this.setState({
105
142
  percent: _this.discrete * (10000 / _this.props.maxDiscrete),
143
+ onDraging: false,
106
144
  }, function () {
107
- console.log('【Slider】DragEnd event.clientX--' + event.clientX + '-----percent----' + _this.state.percent + '-----discrete----' + _this.discrete + '-----currentX----' + (_this.state.percent / 10000 * _this.props.wrapperWidth));
145
+ console.log('【Slider】DragEnd event.clientX--' +
146
+ event.clientX +
147
+ '-----percent----' +
148
+ _this.state.percent +
149
+ '-----discrete----' +
150
+ _this.discrete +
151
+ '-----currentX----' +
152
+ (_this.state.percent / 10000) * _this.props.wrapperWidth);
108
153
  if (_this.props.onDragEnd) {
109
154
  _this.props.onDragEnd(_this.props.isDiscrete ? _this.discrete : _this.state.percent);
110
155
  }
111
156
  });
112
157
  }
113
158
  else {
114
- console.log('【Slider】DragEnd event.clientX--' + event.clientX + '-----percent----' + _this.state.percent + '-----currentX----' + (_this.state.percent / 10000 * _this.props.wrapperWidth));
115
- if (_this.props.onDragEnd) {
116
- _this.props.onDragEnd(_this.props.isDiscrete ? _this.discrete : _this.state.percent);
117
- }
159
+ console.log('【Slider】DragEnd event.clientX--' +
160
+ event.clientX +
161
+ '-----percent----' +
162
+ _this.state.percent +
163
+ '-----currentX----' +
164
+ (_this.state.percent / 10000) * _this.props.wrapperWidth);
165
+ _this.setState({
166
+ percent: (_this.count / _this.props.wrapperWidth) * 10000,
167
+ onDraging: false,
168
+ }, function () {
169
+ if (_this.props.onDragEnd) {
170
+ _this.props.onDragEnd(_this.props.isDiscrete ? _this.discrete : _this.state.percent);
171
+ }
172
+ });
118
173
  }
119
174
  };
120
175
  _this.onDecClick = function () {
121
176
  //离散的情况
122
- if (_this.props.isDiscrete && _this.props.maxDiscrete) {
177
+ if (_this.props.isDiscrete) {
123
178
  if (_this.discrete >= 1) {
124
179
  _this.discrete -= 1;
125
- if (_this.props.rangeControl && _this.props.startRange != null) {
180
+ if (_this.props.rangeControl) {
126
181
  _this.discrete = Math.max(_this.discrete, _this.props.startRange);
127
182
  }
128
183
  var newPercent = _this.discrete * (10000 / _this.props.maxDiscrete);
129
184
  _this.setState({
130
- //discrete: this.state.discrete - 1,
131
- percent: newPercent
185
+ percent: newPercent,
132
186
  }, function () {
133
187
  if (_this.props.onDecClick) {
134
188
  _this.props.onDecClick(_this.discrete);
@@ -140,7 +194,7 @@ var Slider = /** @class */ (function (_super) {
140
194
  else {
141
195
  if (_this.state.percent > 0) {
142
196
  _this.setState({
143
- percent: _this.state.percent - 1
197
+ percent: _this.state.percent - 1,
144
198
  }, function () {
145
199
  if (_this.props.onDecClick) {
146
200
  _this.props.onDecClick(_this.state.percent);
@@ -151,16 +205,16 @@ var Slider = /** @class */ (function (_super) {
151
205
  };
152
206
  _this.onIncClick = function () {
153
207
  //离散的情况
154
- if (_this.props.isDiscrete && _this.props.maxDiscrete) {
208
+ if (_this.props.isDiscrete) {
155
209
  if (_this.discrete < _this.props.maxDiscrete) {
156
210
  _this.discrete += 1;
157
- if (_this.props.rangeControl && _this.props.startRange != null) {
211
+ if (_this.props.rangeControl) {
158
212
  _this.discrete = Math.max(_this.discrete, _this.props.startRange);
159
213
  }
160
214
  var newPercent = _this.discrete * (10000 / _this.props.maxDiscrete);
161
215
  _this.setState({
162
216
  // discrete: this.state.discrete + 1,
163
- percent: newPercent
217
+ percent: newPercent,
164
218
  }, function () {
165
219
  if (_this.props.onIncClick) {
166
220
  _this.props.onIncClick(_this.discrete);
@@ -172,7 +226,7 @@ var Slider = /** @class */ (function (_super) {
172
226
  else {
173
227
  if (_this.state.percent < 10000) {
174
228
  _this.setState({
175
- percent: _this.state.percent + 1
229
+ percent: _this.state.percent + 1,
176
230
  }, function () {
177
231
  if (_this.props.onIncClick) {
178
232
  _this.props.onIncClick(_this.state.percent);
@@ -181,11 +235,14 @@ var Slider = /** @class */ (function (_super) {
181
235
  }
182
236
  }
183
237
  };
184
- _this.computeWrapperStyle = function () {
185
- wrapperStyle = __assign({ width: _this.props.wrapperWidth + 'px', height: _this.props.wrapperHeight + 'px' }, rowCenterCenter);
238
+ //====================================================================================================
239
+ //样式相关
240
+ _this.wrapperStyle = function () {
241
+ var wrapperStyle = __assign({ width: _this.props.wrapperWidth + 'px', height: _this.props.wrapperHeight + 'px' }, rowCenterCenter);
242
+ return wrapperStyle;
186
243
  };
187
- _this.computeOuterStyle = function () {
188
- outerStyle = {
244
+ _this.outerStyle = function () {
245
+ var outerStyle = {
189
246
  width: '100%',
190
247
  height: _this.props.height + 'px',
191
248
  backgroundImage: "url(".concat(_this.props.outerBg, ")"),
@@ -193,97 +250,145 @@ var Slider = /** @class */ (function (_super) {
193
250
  display: 'flex',
194
251
  flexDirection: 'row',
195
252
  justifyContent: 'start',
196
- alignItems: 'center'
253
+ alignItems: 'center',
197
254
  };
255
+ return outerStyle;
198
256
  };
199
- _this.computeInnerStyle = function () {
200
- var innerWidth = Math.floor(_this.state.percent / 100) + '%';
201
- innerStyle = {
202
- width: innerWidth,
203
- height: (_this.props.innerHeight != null) ? _this.props.innerHeight + 'px' : '100%',
257
+ _this.innerStyle = function () {
258
+ var innerStyle = {
259
+ // width: innerWidth,
260
+ height: _this.props.innerHeight != null ? _this.props.innerHeight + 'px' : '100%',
204
261
  backgroundImage: "url(".concat(_this.props.innerBg, ")"),
205
262
  backgroundSize: '100% 100%',
206
263
  display: 'flex',
207
264
  flexDirection: 'row',
208
265
  justifyContent: 'start',
209
- alignItems: 'center'
266
+ alignItems: 'center',
210
267
  };
268
+ return innerStyle;
211
269
  };
212
- _this.computeDotWrapperStyle = function () {
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
216
- // backgroundColor: '#FF000066'
217
- );
270
+ _this.dotWrapperStyle = function () {
271
+ var dotWrapperStyle = __assign({ position: 'absolute', width: _this.props.dotWrapperWidth + 'px', height: _this.props.dotWrapperHeight + 'px' }, rowCenterCenter);
272
+ return dotWrapperStyle;
218
273
  };
219
- _this.computeDotStyle = function () {
220
- dotStyle = {
274
+ _this.dotStyle = function () {
275
+ var dotStyle = {
221
276
  width: _this.props.dotWidth + 'px',
222
277
  height: _this.props.dotHeight + 'px',
223
278
  };
279
+ return dotStyle;
224
280
  };
225
- _this.computeIncButtonStyle = function () {
226
- incButtonStyle = {
281
+ _this.incButtonStyle = function () {
282
+ var incButtonStyle = {
227
283
  width: _this.props.incButtonWidth + 'px',
228
284
  height: _this.props.incButtonHeight + 'px',
229
285
  //marginLeft:this.props.incButtonLeft+"px",
230
286
  //backgroundImage: `url(${this.props.incButtonBg})`,
231
287
  };
288
+ return incButtonStyle;
232
289
  };
233
- _this.computeDecButtonStyle = function () {
234
- decButtonStyle = {
290
+ _this.decButtonStyle = function () {
291
+ var decButtonStyle = {
235
292
  width: _this.props.decButtonWidth + 'px',
236
293
  height: _this.props.decButtonHeight + 'px',
237
294
  //marginRight:this.props.decButtonRight+"px",
238
295
  //backgroundImage: `url(${this.props.decButtonBg})`,
239
296
  };
297
+ return decButtonStyle;
240
298
  };
241
- _this.computeWithButtonStyle = function () {
242
- withButtonStyle = __assign({ minWidth: _this.props.overallWidth + 'px' }, rowBetweenCenter);
299
+ _this.withButtonStyle = function () {
300
+ var withButtonStyle = __assign({ minWidth: _this.props.overallWidth + 'px' }, rowBetweenCenter);
301
+ return withButtonStyle;
243
302
  };
244
303
  _this.state = {
245
- percent: (props.discrete != null && _this.props.maxDiscrete != null && _this.props.discrete != null) ? _this.props.discrete * (10000 / _this.props.maxDiscrete) : Math.floor(_this.props.percent),
246
- //discrete: Math.round(this.props.discrete==null?0:this.props.discrete)
304
+ percent: props.isDiscrete ? _this.props.discrete * (10000 / _this.props.maxDiscrete) : Math.floor(_this.props.percent),
305
+ onDraging: false,
306
+ wrapperStyle: _this.wrapperStyle(),
307
+ outerStyle: _this.outerStyle(),
308
+ innerStyle: _this.innerStyle(),
309
+ dotStyle: _this.dotStyle(),
310
+ dotWrapperStyle: _this.dotWrapperStyle(),
311
+ incButtonStyle: _this.incButtonStyle(),
312
+ decButtonStyle: _this.decButtonStyle(),
313
+ withButtonStyle: _this.withButtonStyle(),
247
314
  };
248
- _this.computeWrapperStyle();
249
- _this.computeOuterStyle();
250
315
  return _this;
251
316
  }
317
+ //====================================================================================================
318
+ //生命周期相关
252
319
  Slider.prototype.componentDidMount = function () {
253
- rect = this.refWrapper.current.getBoundingClientRect();
320
+ this.rect = this.refWrapper.current.getBoundingClientRect();
254
321
  };
255
322
  Slider.prototype.componentWillReceiveProps = function (nextProps) {
256
- if (nextProps.percent == this.props.percent && nextProps.discrete == this.props.discrete)
323
+ if (JSON.stringify(this.props) === JSON.stringify(nextProps))
257
324
  return;
258
- if (this.props.isDiscrete == true && this.props.maxDiscrete != null) {
259
- this.discrete = nextProps.discrete;
260
- this.setState({
261
- //discrete:nextProps.discrete,
262
- percent: this.discrete * (10000 / this.props.maxDiscrete)
263
- });
325
+ //用于标识位置的props和其他样式相关的props分开比较
326
+ var _a = this.props, percent = _a.percent, discrete = _a.discrete, styleProps = __rest(_a, ["percent", "discrete"]);
327
+ var nextPercent = nextProps.percent, nextDiscrete = nextProps.discrete, nextstyleProps = __rest(nextProps, ["percent", "discrete"]);
328
+ //拖动状态时,忽略外部传入的percent值,优先用户拖动
329
+ var shouldUpdatePercent = !this.state.onDraging && !(percent == nextPercent && discrete == nextDiscrete);
330
+ console.log('检查shouldUpdatePercent', shouldUpdatePercent);
331
+ if (shouldUpdatePercent) {
332
+ //如果从外部传入percent/discrete,则组件可根据新props来更新滑动条位置
333
+ //离散情况
334
+ if (this.props.isDiscrete == true) {
335
+ this.discrete = nextProps.discrete;
336
+ this.setState({
337
+ percent: this.discrete * (10000 / this.props.maxDiscrete),
338
+ });
339
+ }
340
+ //连续情况
341
+ else {
342
+ this.setState({
343
+ percent: nextProps.percent,
344
+ });
345
+ }
264
346
  }
265
- else {
347
+ //如果slider传入样式相关props有更改
348
+ if (JSON.stringify(styleProps) !== JSON.stringify(nextstyleProps)) {
266
349
  this.setState({
267
- percent: nextProps.percent,
350
+ wrapperStyle: this.wrapperStyle(),
351
+ outerStyle: this.outerStyle(),
352
+ innerStyle: this.innerStyle(),
353
+ dotStyle: this.dotStyle(),
354
+ dotWrapperStyle: this.dotWrapperStyle(),
355
+ incButtonStyle: this.incButtonStyle(),
356
+ decButtonStyle: this.decButtonStyle(),
357
+ withButtonStyle: this.withButtonStyle(),
268
358
  });
269
359
  }
270
360
  };
271
361
  Slider.prototype.render = function () {
272
- this.computeInnerStyle();
273
- this.computeDotWrapperStyle();
274
- this.computeDotStyle();
275
- this.computeIncButtonStyle();
276
- this.computeDecButtonStyle();
277
- this.computeWithButtonStyle();
278
362
  var hasDot = this.props.hasDot === undefined || this.props.hasDot === true;
279
- return (h("div", { style: this.props.hasIncDecButton ? withButtonStyle : {} },
280
- this.props.hasIncDecButton && h("img", { src: this.props.decButtonBg, style: decButtonStyle, onClick: this.onDecClick }),
281
- h("div", { ref: this.refWrapper, style: wrapperStyle },
282
- h("div", { style: outerStyle },
283
- h("div", { style: innerStyle },
284
- h("div", { style: dotWrapperStyle, draggable: true, onDragStart: this.onDragStart, onDrag: this.onDrag, onDragEnd: this.onDragEnd }, hasDot && h("img", { src: this.props.dotBg, style: dotStyle }))))),
285
- this.props.hasIncDecButton && h("img", { src: this.props.incButtonBg, style: incButtonStyle, onClick: this.onIncClick })));
363
+ var innerWidth = Math.floor(this.state.percent / 100) + '%';
364
+ var dotWrapperMarginLeft = (this.props.wrapperWidth * this.state.percent) / 10000 - this.props.dotWrapperWidth / 2 + 'px';
365
+ return (h("div", { style: this.props.hasIncDecButton ? this.state.withButtonStyle : {}, id: this.props.id, className: this.props.className },
366
+ this.props.hasIncDecButton && h("img", { src: this.props.decButtonBg, style: this.state.decButtonStyle, onClick: this.onDecClick }),
367
+ h("div", { ref: this.refWrapper, style: this.state.wrapperStyle },
368
+ h("div", { style: this.state.outerStyle },
369
+ h("div", { style: __assign(__assign({}, this.state.innerStyle), { width: innerWidth }) },
370
+ 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 }))))),
371
+ this.props.hasIncDecButton && h("img", { src: this.props.incButtonBg, style: this.state.incButtonStyle, onClick: this.onIncClick })));
372
+ };
373
+ Slider.defaultProps = {
374
+ percent: 0,
375
+ wrapperHeight: 34,
376
+ wrapperWidth: 376,
377
+ height: 5,
378
+ dotWidth: 26,
379
+ dotHeight: 27,
380
+ dotWrapperWidth: 56,
381
+ dotWrapperHeight: 57,
382
+ onDragStart: null,
383
+ onDrag: null,
384
+ onDragEnd: null,
385
+ isDiscrete: true,
386
+ discrete: 0,
387
+ maxDiscrete: 100,
388
+ hasIncDecButton: false,
389
+ overallWidth: 500,
390
+ rangeControl: false,
391
+ hasDot: true,
286
392
  };
287
393
  return Slider;
288
394
  }(Component));
289
- export { Slider };