@ray-js/lamp-saturation-slider 1.1.7 → 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 +10 -51
- package/lib/props.d.ts +12 -0
- package/lib/props.js +3 -1
- 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,
|
|
@@ -22,17 +18,11 @@ function LampSaturationSlider(props) {
|
|
|
22
18
|
onTouchMove,
|
|
23
19
|
onTouchEnd,
|
|
24
20
|
enableTouch = true,
|
|
25
|
-
max = 1000
|
|
21
|
+
max = 1000,
|
|
22
|
+
useCustomThumbStyle,
|
|
23
|
+
useCustomTrackStyle
|
|
26
24
|
} = props;
|
|
27
|
-
const startRefValue = useRef(-1);
|
|
28
|
-
const endRefValue = useRef(-1);
|
|
29
25
|
const instanceId = useRef(`Color_${String(+new Date()).slice(-4)}_${String(Math.random()).slice(-10)}`);
|
|
30
|
-
const [controllerSaturation, setControllerSaturation] = useState(-1);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (preSaturation.current !== saturation) {
|
|
33
|
-
setControllerSaturation(saturation);
|
|
34
|
-
}
|
|
35
|
-
}, [saturation]);
|
|
36
26
|
const {
|
|
37
27
|
r,
|
|
38
28
|
g,
|
|
@@ -51,7 +41,7 @@ function LampSaturationSlider(props) {
|
|
|
51
41
|
min: 0,
|
|
52
42
|
max: max,
|
|
53
43
|
disable: disable,
|
|
54
|
-
end:
|
|
44
|
+
end: saturation,
|
|
55
45
|
enableTouch: enableTouch,
|
|
56
46
|
step: 1,
|
|
57
47
|
bindstart: _ref => {
|
|
@@ -61,11 +51,8 @@ function LampSaturationSlider(props) {
|
|
|
61
51
|
if (!onTouchStart || disable) {
|
|
62
52
|
return;
|
|
63
53
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
onTouchStart && onTouchStart(detail.end);
|
|
68
|
-
startRefValue.current = detail.end;
|
|
54
|
+
const value = Math.max(detail.end, 1);
|
|
55
|
+
onTouchStart && onTouchStart(value);
|
|
69
56
|
},
|
|
70
57
|
bindmove: _ref2 => {
|
|
71
58
|
let {
|
|
@@ -74,31 +61,7 @@ function LampSaturationSlider(props) {
|
|
|
74
61
|
if (!onTouchMove || disable) {
|
|
75
62
|
return;
|
|
76
63
|
}
|
|
77
|
-
|
|
78
|
-
if (detail.end === preSaturation.current) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (timer.current) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 移动更新的频率
|
|
86
|
-
|
|
87
|
-
// 移动结束后多久进行更新
|
|
88
|
-
|
|
89
|
-
timer.current = setTimeout(() => {
|
|
90
|
-
onTouchMove && onTouchMove(detail.end);
|
|
91
|
-
preSaturation.current = detail.end;
|
|
92
|
-
clearTimeout(timer.current);
|
|
93
|
-
timer.current = null;
|
|
94
|
-
clearTimeout(timer1.current);
|
|
95
|
-
timer1.current = null;
|
|
96
|
-
timer1.current = setTimeout(() => {
|
|
97
|
-
if (lastSaturation.current !== preSaturation.current) {
|
|
98
|
-
onTouchMove && onTouchMove(lastSaturation.current);
|
|
99
|
-
}
|
|
100
|
-
}, 200);
|
|
101
|
-
}, 50);
|
|
64
|
+
onTouchMove && onTouchMove(detail.end);
|
|
102
65
|
},
|
|
103
66
|
bindend: _ref3 => {
|
|
104
67
|
let {
|
|
@@ -107,18 +70,14 @@ function LampSaturationSlider(props) {
|
|
|
107
70
|
if (!onTouchEnd || disable) {
|
|
108
71
|
return;
|
|
109
72
|
}
|
|
110
|
-
if (detail.end === endRefValue.current) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
73
|
onTouchEnd && onTouchEnd(detail.end);
|
|
114
|
-
endRefValue.current = detail.end;
|
|
115
74
|
},
|
|
116
75
|
trackStyle: toStyle(_objectSpread(_objectSpread({
|
|
117
76
|
width: `${646}rpx`,
|
|
118
77
|
height: `${88}rpx`,
|
|
119
78
|
borderRadius: `${28}rpx`
|
|
120
79
|
}, trackStyle), {}, {
|
|
121
|
-
background: `linear-gradient(to right, rgba(${r}, ${g}, ${b}, 0.01) 0%, rgba(${r}, ${g}, ${b}, 1) 100%)`
|
|
80
|
+
background: useCustomTrackStyle ? trackStyle === null || trackStyle === void 0 ? void 0 : trackStyle.background : `linear-gradient(to right, rgba(${r}, ${g}, ${b}, 0.01) 0%, rgba(${r}, ${g}, ${b}, 1) 100%)`
|
|
122
81
|
})),
|
|
123
82
|
barStyle: toStyle({
|
|
124
83
|
background: 'transparent'
|
|
@@ -130,7 +89,7 @@ function LampSaturationSlider(props) {
|
|
|
130
89
|
borderRadius: '28rpx',
|
|
131
90
|
background: `${disable ? '#000' : 'transparent'}`
|
|
132
91
|
}, thumbStyle)),
|
|
133
|
-
thumbStyleRenderFormatter: {
|
|
92
|
+
thumbStyleRenderFormatter: useCustomThumbStyle ? null : {
|
|
134
93
|
background: `hsl(${props.hue}deg 100% value%)`
|
|
135
94
|
},
|
|
136
95
|
thumbStyleRenderValueScale: 50 / max,
|
package/lib/props.d.ts
CHANGED
|
@@ -64,5 +64,17 @@ export interface IProps {
|
|
|
64
64
|
* @default 1000
|
|
65
65
|
*/
|
|
66
66
|
max?: 100 | 1000;
|
|
67
|
+
/**
|
|
68
|
+
* @description.en useCustomThumbStyle
|
|
69
|
+
* @description.zh 使用自定义按钮样式
|
|
70
|
+
* @default null
|
|
71
|
+
*/
|
|
72
|
+
useCustomThumbStyle?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* @description.en useCustomTrackStyle
|
|
75
|
+
* @description.zh 使用自定义滑槽样式
|
|
76
|
+
* @default null
|
|
77
|
+
*/
|
|
78
|
+
useCustomTrackStyle?: boolean;
|
|
67
79
|
}
|
|
68
80
|
export declare const defaultProps: IProps;
|
package/lib/props.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/lamp-saturation-slider",
|
|
3
|
-
"version": "1.1.
|
|
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",
|