@ray-js/lamp-saturation-slider 1.1.8-beta-1 → 1.1.8-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-zh_CN.md +95 -0
- package/lib/index.js +5 -48
- package/package.json +6 -1
package/README-zh_CN.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[English](./README.md) | 简体中文
|
|
2
|
+
|
|
3
|
+
# @ray-js/lamp-saturation-slider
|
|
4
|
+
|
|
5
|
+
> 照明饱和度 Slider
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
$ npm install @ray-js/components-ty-lamp
|
|
11
|
+
// 或者
|
|
12
|
+
$ yarn add @ray-js/components-ty-lamp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// 属性
|
|
19
|
+
export interface IProps {
|
|
20
|
+
/**
|
|
21
|
+
* @description.zh 禁止滑动
|
|
22
|
+
* @description.en Ban sliding
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
disable?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @description.zh 滑动槽样式
|
|
28
|
+
* @description.en
|
|
29
|
+
* @default {}
|
|
30
|
+
*/
|
|
31
|
+
trackStyle?: React.CSSProperties;
|
|
32
|
+
/**
|
|
33
|
+
* @description.zh slider值
|
|
34
|
+
* @description.en slider value
|
|
35
|
+
* @default 0
|
|
36
|
+
*/
|
|
37
|
+
value: number;
|
|
38
|
+
/**
|
|
39
|
+
* @description.zh slider 展示的颜色值 对应hsv的hue
|
|
40
|
+
* @description.en slider value
|
|
41
|
+
* @default 0
|
|
42
|
+
*/
|
|
43
|
+
hue: number; // 0 - 359
|
|
44
|
+
/**
|
|
45
|
+
* @description.zh slider 手指点击时触发
|
|
46
|
+
* @description.en slider Value changes
|
|
47
|
+
* @default () => {}
|
|
48
|
+
*/
|
|
49
|
+
onTouchStart?: (value: number) => void;
|
|
50
|
+
/**
|
|
51
|
+
* @description.zh slider 手指拖动时触发
|
|
52
|
+
* @description.en slider Value changes
|
|
53
|
+
* @default () => {}
|
|
54
|
+
*/
|
|
55
|
+
onTouchMove?: (value: number) => void;
|
|
56
|
+
/**
|
|
57
|
+
* @description.zh slider 手指离开时触发
|
|
58
|
+
* @description.en Values change after the trigger
|
|
59
|
+
* @default () => {}
|
|
60
|
+
*/
|
|
61
|
+
onTouchEnd?: (value: number) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const defaultProps: IProps = {
|
|
65
|
+
value: 0,
|
|
66
|
+
onTouchStart: () => null,
|
|
67
|
+
onTouchMove: () => null,
|
|
68
|
+
onTouchEnd: () => null,
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { LampSaturationSlider } from '@ray-js/components-ty-lamp';
|
|
74
|
+
|
|
75
|
+
export default () => {
|
|
76
|
+
const [saturation, setSaturation] = useState(100);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
// 模拟dp上报
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
setSaturation(321);
|
|
82
|
+
}, 3000);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<LampSaturationSlider
|
|
87
|
+
hue={100}
|
|
88
|
+
value={saturation}
|
|
89
|
+
onTouchEnd={val => {
|
|
90
|
+
setSaturation(val);
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
```
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
import React, { useRef,
|
|
3
|
+
import React, { useRef, useMemo } from 'react';
|
|
4
4
|
import { View } from '@ray-js/components';
|
|
5
5
|
import Slider from '@ray-js/components-ty-slider/lib/SjsSlider';
|
|
6
6
|
import { toStyle } from '@ray-js/components-ty-slider';
|
|
@@ -8,10 +8,6 @@ import { hsvToRgb } from './utils';
|
|
|
8
8
|
import { defaultProps } from './props';
|
|
9
9
|
function LampSaturationSlider(props) {
|
|
10
10
|
var _trackStyle$width, _trackStyle$height;
|
|
11
|
-
const preSaturation = useRef(-1);
|
|
12
|
-
const lastSaturation = useRef(null);
|
|
13
|
-
const timer = useRef(null);
|
|
14
|
-
const timer1 = useRef(null);
|
|
15
11
|
const {
|
|
16
12
|
value: saturation,
|
|
17
13
|
hue,
|
|
@@ -26,15 +22,7 @@ function LampSaturationSlider(props) {
|
|
|
26
22
|
useCustomThumbStyle,
|
|
27
23
|
useCustomTrackStyle
|
|
28
24
|
} = props;
|
|
29
|
-
const startRefValue = useRef(-1);
|
|
30
|
-
const endRefValue = useRef(-1);
|
|
31
25
|
const instanceId = useRef(`Color_${String(+new Date()).slice(-4)}_${String(Math.random()).slice(-10)}`);
|
|
32
|
-
const [controllerSaturation, setControllerSaturation] = useState(-1);
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (preSaturation.current !== saturation) {
|
|
35
|
-
setControllerSaturation(saturation);
|
|
36
|
-
}
|
|
37
|
-
}, [saturation]);
|
|
38
26
|
const {
|
|
39
27
|
r,
|
|
40
28
|
g,
|
|
@@ -53,7 +41,7 @@ function LampSaturationSlider(props) {
|
|
|
53
41
|
min: 0,
|
|
54
42
|
max: max,
|
|
55
43
|
disable: disable,
|
|
56
|
-
end:
|
|
44
|
+
end: saturation,
|
|
57
45
|
enableTouch: enableTouch,
|
|
58
46
|
step: 1,
|
|
59
47
|
bindstart: _ref => {
|
|
@@ -63,11 +51,8 @@ function LampSaturationSlider(props) {
|
|
|
63
51
|
if (!onTouchStart || disable) {
|
|
64
52
|
return;
|
|
65
53
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
onTouchStart && onTouchStart(detail.end);
|
|
70
|
-
startRefValue.current = detail.end;
|
|
54
|
+
const value = Math.max(detail.end, 1);
|
|
55
|
+
onTouchStart && onTouchStart(value);
|
|
71
56
|
},
|
|
72
57
|
bindmove: _ref2 => {
|
|
73
58
|
let {
|
|
@@ -76,31 +61,7 @@ function LampSaturationSlider(props) {
|
|
|
76
61
|
if (!onTouchMove || disable) {
|
|
77
62
|
return;
|
|
78
63
|
}
|
|
79
|
-
|
|
80
|
-
if (detail.end === preSaturation.current) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (timer.current) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 移动更新的频率
|
|
88
|
-
|
|
89
|
-
// 移动结束后多久进行更新
|
|
90
|
-
|
|
91
|
-
timer.current = setTimeout(() => {
|
|
92
|
-
onTouchMove && onTouchMove(detail.end);
|
|
93
|
-
preSaturation.current = detail.end;
|
|
94
|
-
clearTimeout(timer.current);
|
|
95
|
-
timer.current = null;
|
|
96
|
-
clearTimeout(timer1.current);
|
|
97
|
-
timer1.current = null;
|
|
98
|
-
timer1.current = setTimeout(() => {
|
|
99
|
-
if (lastSaturation.current !== preSaturation.current) {
|
|
100
|
-
onTouchMove && onTouchMove(lastSaturation.current);
|
|
101
|
-
}
|
|
102
|
-
}, 200);
|
|
103
|
-
}, 50);
|
|
64
|
+
onTouchMove && onTouchMove(detail.end);
|
|
104
65
|
},
|
|
105
66
|
bindend: _ref3 => {
|
|
106
67
|
let {
|
|
@@ -109,11 +70,7 @@ function LampSaturationSlider(props) {
|
|
|
109
70
|
if (!onTouchEnd || disable) {
|
|
110
71
|
return;
|
|
111
72
|
}
|
|
112
|
-
if (detail.end === endRefValue.current) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
73
|
onTouchEnd && onTouchEnd(detail.end);
|
|
116
|
-
endRefValue.current = detail.end;
|
|
117
74
|
},
|
|
118
75
|
trackStyle: toStyle(_objectSpread(_objectSpread({
|
|
119
76
|
width: `${646}rpx`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/lamp-saturation-slider",
|
|
3
|
-
"version": "1.1.8-beta-
|
|
3
|
+
"version": "1.1.8-beta-2",
|
|
4
4
|
"description": "照明色温Slider",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"lint-staged": "^10.2.11",
|
|
44
44
|
"standard-version": "9.3.2"
|
|
45
45
|
},
|
|
46
|
+
"resolutions": {
|
|
47
|
+
"follow-redirects": "1.15.6",
|
|
48
|
+
"shell-quote": "1.7.3",
|
|
49
|
+
"ip": "2.0.1"
|
|
50
|
+
},
|
|
46
51
|
"husky": {
|
|
47
52
|
"hooks": {
|
|
48
53
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
|