@ray-js/lamp-saturation-slider 0.0.2-beta-1 → 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/README.md CHANGED
@@ -2,61 +2,99 @@ English | [简体中文](./README-zh_CN.md)
2
2
 
3
3
  # @ray-js/lamp-saturation-slider
4
4
 
5
- [![latest](https://img.shields.io/npm/v/@ray-js/lamp-saturation-slider/latest.svg)](https://www.npmjs.com/package/@ray-js/lamp-saturation-slider) [![download](https://img.shields.io/npm/dt/@ray-js/lamp-saturation-slider.svg)](https://www.npmjs.com/package/@ray-js/lamp-saturation-slider)
5
+ [![latest](https://img.shields.io/npm/v/@ray/lamp-saturation-slider/latest.svg)](https://www.npmjs.com/package/@ray/lamp-saturation-slider) [![download](https://img.shields.io/npm/dt/@ray/lamp-saturation-slider.svg)](https://www.npmjs.com/package/@ray/lamp-saturation-slider)
6
6
 
7
- > 照明饱和度 Slider
7
+ > 照明彩光 Slider
8
8
 
9
9
  ## Installation
10
10
 
11
11
  ```sh
12
- $ npm install @ray-js/lamp-saturation-slider
12
+ $ npm install @ray-js/components-ty-lamp
13
13
  # or
14
- $ yarn add @ray-js/lamp-saturation-slider
14
+ $ yarn add @ray-js/components-ty-lamp
15
15
  ```
16
16
 
17
17
  ## Usage
18
18
 
19
19
  ```ts
20
- // 滑动条拖动时持续触发
21
- onChange?: (value: RGB) => void;
22
- // 滑动条拖动后,松手触发
23
- onAfterChange?: (value: RGB) => void;
24
- // 滑动条值
20
+ // 属性
21
+ export interface IProps {
22
+ /**
23
+ * @description.zh 禁止滑动
24
+ * @description.en Ban sliding
25
+ * @default false
26
+ */
27
+ disable?: boolean;
28
+ /**
29
+ * @description.zh slider方向
30
+ * @description.en slider direction
31
+ * @default horizontal
32
+ */
33
+ direction?: 'horizontal' | 'vertical';
34
+ /**
35
+ * @description.zh 滑动槽样式
36
+ * @description.en
37
+ * @default {}
38
+ */
39
+ trackStyle?: React.CSSProperties;
40
+ /**
41
+ * @description.zh slider值
42
+ * @description.en slider value
43
+ * @default 0
44
+ */
25
45
  value: number;
26
- // 滑动条默认RGB值
27
- defaultColor: RGB;
46
+ /**
47
+ * @description.zh slider 手指点击时触发
48
+ * @description.en slider Value changes
49
+ * @default () => {}
50
+ */
51
+ onTouchStart?: (value: number) => void;
52
+ /**
53
+ * @description.zh slider 手指拖动时触发
54
+ * @description.en slider Value changes
55
+ * @default () => {}
56
+ */
57
+ onTouchMove?: (value: number) => void;
58
+ /**
59
+ * @description.zh slider 手指离开时触发
60
+ * @description.en Values change after the trigger
61
+ * @default () => {}
62
+ */
63
+ onTouchEnd?: (value: number) => void;
64
+ }
65
+
66
+ export const defaultProps: IProps = {
67
+ value: 0,
68
+ onTouchStart: () => null,
69
+ onTouchMove: () => null,
70
+ onTouchEnd: () => null,
71
+ };
28
72
  ```
29
73
 
30
74
  ```tsx
31
- import LampSaturationSlider from '@ray-js/lamp-saturation-slider';
75
+ import LampSaturationSlider from '@ray-js/components-ty-lamp';
76
+
32
77
  export default () => {
33
- const value = 0;
34
- const [rgbSaturationValue, setRgbSaturationValue] = useState({
35
- r: 255,
36
- g: 0,
37
- b: 0,
38
- });
39
- const [rgbValue, setRgbValue] = useState({
40
- r: 255,
41
- g: 0,
42
- b: 0,
43
- });
78
+ const [hue, setHue] = useState(100);
79
+
80
+ useEffect(() => {
81
+ // 模拟dp上报
82
+ setTimeout(() => {
83
+ setHue(321);
84
+ }, 3000);
85
+ }, []);
86
+
44
87
  return (
45
- <View className={styles.view}>
46
- <DemoBlock title="基础用法">
47
- <Text className={styles.demoBlockTitleText}>
48
- RGB:{`${rgbSaturationValue.r},${rgbSaturationValue.g},${rgbSaturationValue.b}`}
49
- </Text>
50
-
51
- <LampSaturationSlider
52
- value={value}
53
- defaultColor={rgbValue}
54
- onChange={val => {
55
- setRgbSaturationValue(val);
56
- }}
57
- />
58
- </DemoBlock>
59
- </View>
88
+ <LampSaturationSlider
89
+ value={hue}
90
+ disable
91
+ onTouchMove={val => {
92
+ setHue(val);
93
+ }}
94
+ onTouchEnd={val => {
95
+ setHue(val);
96
+ }}
97
+ />
60
98
  );
61
99
  };
62
100
  ```
@@ -0,0 +1,230 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React from 'react';
3
+
4
+ export interface EventType<T> {
5
+ type: T;
6
+ timeStamp: number;
7
+ target: any;
8
+ currentTarget: any;
9
+ detail: SjsSliderEventData;
10
+ }
11
+
12
+ export interface SjsSliderEventData {
13
+ start: number;
14
+ end: number;
15
+ range: number;
16
+ position: 'start' | 'end';
17
+ }
18
+
19
+ export interface SjsSliderProps {
20
+ /**
21
+ * @description.en hue值
22
+ * @description.zh hue value
23
+ */
24
+ hue: number;
25
+ /**
26
+ * @description.en instanceId
27
+ * @description.zh 唯一ID
28
+ */
29
+ instanceId: string;
30
+ /**
31
+ * @description.en className
32
+ * @description.zh 样式
33
+ */
34
+ className?: string;
35
+ /**
36
+ * @description.en disable
37
+ * @description.zh disable
38
+ * @default false
39
+ */
40
+ disable?: boolean;
41
+ /**
42
+ * @description.en left value
43
+ * @description.zh 左滑块初始值
44
+ * @default 0
45
+ */
46
+ start?: number;
47
+ /**
48
+ * @description.en watch value and change
49
+ * @description.zh 监听值,并随之变化
50
+ */
51
+ watchStart?: number;
52
+ /**
53
+ * @description.en left value min
54
+ * @description.zh 左滑块最小值限制
55
+ */
56
+ startMin?: number;
57
+ /**
58
+ * @description.en left value max
59
+ * @description.zh 左滑块最大值限制
60
+ */
61
+ startMax?: number;
62
+ /**
63
+ * @description.en Right slider initial value/one-way slider initial value
64
+ * @description.zh 右滑块初始值/单向滑条初始值
65
+ * @default 30
66
+ */
67
+ end?: number;
68
+ /**
69
+ * @description.en watch value and change
70
+ * @description.zh 监听值,并随之变化
71
+ */
72
+ watchEnd?: number;
73
+ /**
74
+ * @description.en Right slider min/one-way slider min
75
+ * @description.zh 右滑块最小值/单向滑条最小值
76
+ */
77
+ endMin?: number;
78
+ /**
79
+ * @description.en Right slider Max/one-way slider Max
80
+ * @description.zh 右滑块最大值/单向滑条最大值
81
+ */
82
+ endMax?: number;
83
+ /**
84
+ * @description.en min
85
+ * @description.zh 最小值, 建议用 endMin 代替
86
+ * @default 0
87
+ * @deprecated
88
+ */
89
+ min?: number;
90
+ /**
91
+ * @description.en max
92
+ * @description.zh 最大值
93
+ * @default 100
94
+ */
95
+ max?: number;
96
+ /**
97
+ * @description.en step
98
+ * @description.zh 阶段值
99
+ * @default 1
100
+ */
101
+ step?: number;
102
+ /**
103
+ * @description.en step
104
+ * @description.zh 阶段值
105
+ */
106
+ forceStep?: number;
107
+ /**
108
+ * @description.en thumbStyle
109
+ * @description.zh 滑块样式
110
+ */
111
+ thumbStartStyle?: React.CSSProperties;
112
+ /**
113
+ * @description.en thumbStyle
114
+ * @description.zh 滑块样式
115
+ */
116
+ thumbEndStyle?: React.CSSProperties;
117
+ /**
118
+ * @description.en trackStyle
119
+ * @description.zh 轨道样式
120
+ */
121
+ trackStyle?: React.CSSProperties;
122
+ /**
123
+ * @description.en barStyle
124
+ * @description.zh 滑条样式
125
+ */
126
+ barStyle?: React.CSSProperties;
127
+ /**
128
+ * @description.en stepStyle
129
+ * @description.zh step样式
130
+ */
131
+ stepStyle?: React.CSSProperties;
132
+ /**
133
+ * @description.en bar stepStyle
134
+ * @description.zh bar step样式
135
+ */
136
+ activeStepStyle?: React.CSSProperties;
137
+ /**
138
+ * @description.en mode
139
+ * @description.zh 单向还是双向
140
+ * @default normal
141
+ */
142
+ mode?: 'range' | 'normal';
143
+ /**
144
+ * @description.en barPad
145
+ * @description.zh 控制滑动bar的偏移量,用于样式微调
146
+ */
147
+ barPad?: number;
148
+ /**
149
+ * @description.en maxRangeOffset
150
+ * @description.zh 按钮对齐偏移
151
+ * @default null
152
+ */
153
+ maxRangeOffset?: number;
154
+ /**
155
+ * @description.en hideThumb
156
+ * @description.zh 隐藏滑块
157
+ * @default false
158
+ */
159
+ hideThumb?: boolean;
160
+ /**
161
+ * @description.en showSteps
162
+ * @description.zh 显示阶段提示
163
+ * @default false
164
+ */
165
+ showSteps?: boolean;
166
+ /**
167
+ * @description.en direction
168
+ * @description.zh 方向
169
+ * @default horizontal
170
+ */
171
+ direction?: 'horizontal' | 'vertical';
172
+ /**
173
+ * @description.en callback
174
+ * @description.zh 回调
175
+ */
176
+ bindmove?: (event: EventType<'move'>) => void;
177
+ /**
178
+ * @description.en callback
179
+ * @description.zh 回调
180
+ */
181
+ bindend?: (event: EventType<'end'>) => void;
182
+ /**
183
+ * @description.en callback
184
+ * @description.zh 回调
185
+ */
186
+ bindstart?: (event: EventType<'start'>) => void;
187
+ /**
188
+ * @description.en reverse
189
+ * @description.zh 是否反转
190
+ * @default false
191
+ */
192
+ reverse?: boolean;
193
+ /**
194
+ * @description.en enableTouch
195
+ * @description.zh 使用触摸跳跃
196
+ * @default false
197
+ */
198
+ enableTouch?: boolean;
199
+ /**
200
+ * @description.en enableTouchBar
201
+ * @description.zh 使用触摸bar增加偏移
202
+ * @default false
203
+ */
204
+ enableTouchBar?: boolean;
205
+ /**
206
+ * @description.en showText
207
+ * @description.zh 在bar上显示文本
208
+ * @default false
209
+ */
210
+ showText?: boolean;
211
+ /**
212
+ * @description.en textStyle
213
+ * @description.zh bar文本样式
214
+ */
215
+ textStyle?: React.CSSProperties;
216
+ /**
217
+ * @description.en textTemplate
218
+ * @description.zh 文本格式化,例如 textTemplate="比率 {{text}} %"
219
+ */
220
+ textTemplate?: string;
221
+ /**
222
+ * @description.en calc style, such as { background: "rgba(0,0,0, {{text / 100 }}" }
223
+ * @description.zh 动态计算thumb样式,如 { background: "rgba(0,0,0, {{text /100 }})" }
224
+ */
225
+ thumbStyleCalc?: Partial<Record<keyof React.CSSProperties, string>>;
226
+ }
227
+
228
+ const SjsSlider: React.FC<SjsSliderProps>;
229
+
230
+ export default SjsSlider;
@@ -0,0 +1,211 @@
1
+ import "core-js/modules/es.number.constructor.js";
2
+ import "core-js/modules/es.regexp.exec.js";
3
+ import "core-js/modules/es.regexp.test.js";
4
+ import "core-js/modules/es.array.concat.js";
5
+ import "core-js/modules/es.array.map.js";
6
+ import "core-js/modules/es.array.fill.js";
7
+ import "core-js/modules/es.parse-int.js";
8
+ /* eslint-disable func-names */
9
+ /* eslint-disable vars-on-top */
10
+ import 'core-js/modules/es.number.constructor.js';
11
+ import 'core-js/modules/es.regexp.exec.js';
12
+ import 'core-js/modules/es.regexp.test.js';
13
+ import 'core-js/modules/es.array.concat.js';
14
+ import 'core-js/modules/es.array.map.js';
15
+ import 'core-js/modules/es.array.fill.js';
16
+ import 'core-js/modules/es.parse-int.js';
17
+ // eslint-disable-next-line no-undef
18
+ Component({
19
+ options: {
20
+ addGlobalClass: true
21
+ },
22
+ properties: {
23
+ className: {
24
+ type: String,
25
+ value: ''
26
+ },
27
+ hue: {
28
+ type: Number,
29
+ value: 0
30
+ },
31
+ disable: {
32
+ type: Boolean,
33
+ value: false
34
+ },
35
+ // 左滑块初始值
36
+ start: {
37
+ type: Number,
38
+ value: 0
39
+ },
40
+ // 左滑块最小值限制
41
+ startMin: {
42
+ type: Number
43
+ },
44
+ // 左滑块最大值限制
45
+ startMax: {
46
+ type: Number
47
+ },
48
+ // 右滑块初始值/单向滑条初始值
49
+ end: {
50
+ type: Number,
51
+ value: 30
52
+ },
53
+ watchStart: {
54
+ type: Number
55
+ },
56
+ watchEnd: {
57
+ type: Number
58
+ },
59
+ // 右滑块最小值/单向滑条最小值
60
+ endMin: {
61
+ type: Number
62
+ },
63
+ // 右滑块最大值/单向滑条最大值
64
+ endMax: {
65
+ type: Number
66
+ },
67
+ // 最小值
68
+ min: {
69
+ type: Number,
70
+ value: 0
71
+ },
72
+ // 最大值
73
+ max: {
74
+ type: Number,
75
+ value: 1000
76
+ },
77
+ // 阶段值
78
+ step: {
79
+ type: Number,
80
+ value: 1
81
+ },
82
+ // 阶段值
83
+ forceStep: {
84
+ type: Number
85
+ },
86
+ // 滑块样式
87
+ thumbStartStyle: {
88
+ type: String
89
+ },
90
+ // 滑块样式
91
+ thumbEndStyle: {
92
+ type: String
93
+ },
94
+ // 轨道样式
95
+ trackStyle: {
96
+ type: String
97
+ },
98
+ // 滑条样式
99
+ barStyle: {
100
+ type: String
101
+ },
102
+ // step样式
103
+ stepStyle: {
104
+ type: String
105
+ },
106
+ // step样式
107
+ activeStepStyle: {
108
+ type: String
109
+ },
110
+ // 单向还是双向 range: 双向,normal: 单向
111
+ mode: {
112
+ type: String
113
+ },
114
+ // 方向 "horizontal" | "vertical"
115
+ direction: {
116
+ type: String
117
+ },
118
+ // 控制滑动bar的偏移量,用于样式微调
119
+ barPad: {
120
+ type: Number
121
+ },
122
+ // 隐藏滑块
123
+ hideThumb: {
124
+ type: Boolean,
125
+ value: false
126
+ },
127
+ // 显示阶段提示
128
+ showSteps: {
129
+ type: Boolean,
130
+ value: false
131
+ },
132
+ // 反转
133
+ reverse: {
134
+ type: Boolean,
135
+ value: false
136
+ },
137
+ // 使用触摸跳跃
138
+ enableTouch: {
139
+ type: Boolean,
140
+ value: false
141
+ },
142
+ // 使用触摸bar增加偏移
143
+ enableTouchBar: {
144
+ type: Boolean,
145
+ value: false
146
+ },
147
+ // 使用触摸跳跃
148
+ maxRangeOffset: {
149
+ type: Number,
150
+ value: 0
151
+ },
152
+ // 唯一ID
153
+ instanceId: {
154
+ type: String
155
+ },
156
+ // 在bar上显示文本
157
+ showText: {
158
+ type: Boolean
159
+ },
160
+ // bar文本样式
161
+ textStyle: {
162
+ type: String
163
+ },
164
+ // 文本格式化,例如 textTemplate="比率 {{text}} %"
165
+ textTemplate: {
166
+ type: String
167
+ },
168
+ // 动态计算thumb样式,如 { background: "rgba(0,0,0, {{text}}/100)" }
169
+ thumbStyleCalc: {
170
+ type: Object
171
+ }
172
+ },
173
+ data: {
174
+ steps: [],
175
+ text: ''
176
+ },
177
+ lifetimes: {
178
+ /**
179
+ * 组件的方法列表
180
+ */
181
+ ready: function () {
182
+ var isNumber = function (n) {
183
+ return /\d+/.test(n);
184
+ };
185
+ var getNumber = function (n, def) {
186
+ return isNumber(n) ? n : def;
187
+ };
188
+ if (!this.data.showSteps) return;
189
+ var stepCount = this.data.step || this.data.forceStep;
190
+ var max = getNumber(this.data.max, 100);
191
+ var min = getNumber(this.data.min, 0);
192
+ var steps = new Array(parseInt(String((max - min) / stepCount), 10)).fill(0).map(function (_, i) {
193
+ return i;
194
+ }).concat(-1);
195
+ this.setData({
196
+ steps: steps
197
+ });
198
+ }
199
+ },
200
+ methods: {
201
+ setText: function (_ref) {
202
+ var instanceId = _ref.instanceId;
203
+ var content = _ref.content;
204
+ if (!this.data.showText) return;
205
+ if (instanceId !== this.data.instanceId) return;
206
+ this.setData({
207
+ text: content
208
+ });
209
+ }
210
+ }
211
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }