@ray-js/lamp-saturation-slider 0.0.3-beta-1 → 1.1.1-beta-1

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,94 @@ 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)
6
-
7
- > 照明饱和度 Slider
5
+ > Lamp saturation Slider
8
6
 
9
7
  ## Installation
10
8
 
11
9
  ```sh
12
- $ npm install @ray-js/lamp-saturation-slider
10
+ $ npm install @ray-js/components-ty-lamp
13
11
  # or
14
- $ yarn add @ray-js/lamp-saturation-slider
12
+ $ yarn add @ray-js/components-ty-lamp
15
13
  ```
16
14
 
17
15
  ## Usage
18
16
 
19
17
  ```ts
20
- // 滑动条拖动时持续触发
21
- onChange?: (value: RGB) => void;
22
- // 滑动条拖动后,松手触发
23
- onAfterChange?: (value: RGB) => void;
24
- // 滑动条值
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 slider方向
28
+ * @description.en slider direction
29
+ * @default horizontal
30
+ */
31
+ direction?: 'horizontal' | 'vertical';
32
+ /**
33
+ * @description.zh 滑动槽样式
34
+ * @description.en
35
+ * @default {}
36
+ */
37
+ trackStyle?: React.CSSProperties;
38
+ /**
39
+ * @description.zh slider值
40
+ * @description.en slider value
41
+ * @default 0
42
+ */
25
43
  value: number;
26
- // 滑动条默认RGB值
27
- defaultColor: RGB;
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
+ };
28
70
  ```
29
71
 
30
72
  ```tsx
31
- import LampSaturationSlider from '@ray-js/lamp-saturation-slider';
73
+ import { LampSaturationSlider } from '@ray-js/components-ty-lamp';
74
+
32
75
  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
- });
76
+ const [hue, setHue] = useState(100);
77
+
78
+ useEffect(() => {
79
+ // Simulation of dp report
80
+ setTimeout(() => {
81
+ setHue(321);
82
+ }, 3000);
83
+ }, []);
84
+
44
85
  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>
86
+ <LampSaturationSlider
87
+ value={hue}
88
+ disable
89
+ onTouchEnd={val => {
90
+ setHue(val);
91
+ }}
92
+ />
60
93
  );
61
94
  };
62
95
  ```
@@ -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
+ }