@ray-js/lamp-style-slider 0.0.2 → 0.0.3-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.
@@ -33,59 +33,16 @@ export interface SjsSliderProps {
33
33
  * @default false
34
34
  */
35
35
  disable?: boolean;
36
- /**
37
- * @description.en closed
38
- * @description.zh closed
39
- * @default false
40
- */
41
- closed?: boolean;
42
- /**
43
- * @description.en left value
44
- * @description.zh 左滑块初始值
45
- * @default 0
46
- */
47
- start?: number;
48
- /**
49
- * @description.en watch value and change
50
- * @description.zh 监听值,并随之变化
51
- */
52
- watchStart?: number;
53
- /**
54
- * @description.en left value min
55
- * @description.zh 左滑块最小值限制
56
- */
57
- startMin?: number;
58
- /**
59
- * @description.en left value max
60
- * @description.zh 左滑块最大值限制
61
- */
62
- startMax?: number;
63
36
  /**
64
37
  * @description.en Right slider initial value/one-way slider initial value
65
38
  * @description.zh 右滑块初始值/单向滑条初始值
66
39
  * @default 30
67
40
  */
68
41
  end?: number;
69
- /**
70
- * @description.en watch value and change
71
- * @description.zh 监听值,并随之变化
72
- */
73
- watchEnd?: number;
74
- /**
75
- * @description.en Right slider min/one-way slider min
76
- * @description.zh 右滑块最小值/单向滑条最小值
77
- */
78
- endMin?: number;
79
- /**
80
- * @description.en Right slider Max/one-way slider Max
81
- * @description.zh 右滑块最大值/单向滑条最大值
82
- */
83
- endMax?: number;
84
42
  /**
85
43
  * @description.en min
86
44
  * @description.zh 最小值, 建议用 endMin 代替
87
45
  * @default 0
88
- * @deprecated
89
46
  */
90
47
  min?: number;
91
48
  /**
@@ -109,12 +66,7 @@ export interface SjsSliderProps {
109
66
  * @description.en thumbStyle
110
67
  * @description.zh 滑块样式
111
68
  */
112
- thumbStartStyle?: React.CSSProperties;
113
- /**
114
- * @description.en thumbStyle
115
- * @description.zh 滑块样式
116
- */
117
- thumbEndStyle?: React.CSSProperties;
69
+ thumbStyle?: React.CSSProperties;
118
70
  /**
119
71
  * @description.en trackStyle
120
72
  * @description.zh 轨道样式
@@ -135,23 +87,6 @@ export interface SjsSliderProps {
135
87
  * @description.zh bar step样式
136
88
  */
137
89
  activeStepStyle?: React.CSSProperties;
138
- /**
139
- * @description.en mode
140
- * @description.zh 单向还是双向
141
- * @default normal
142
- */
143
- mode?: 'range' | 'normal';
144
- /**
145
- * @description.en barPad
146
- * @description.zh 控制滑动bar的偏移量,用于样式微调
147
- */
148
- barPad?: number;
149
- /**
150
- * @description.en maxRangeOffset
151
- * @description.zh 按钮对齐偏移
152
- * @default null
153
- */
154
- maxRangeOffset?: number;
155
90
  /**
156
91
  * @description.en hideThumb
157
92
  * @description.zh 隐藏滑块
@@ -174,17 +109,17 @@ export interface SjsSliderProps {
174
109
  * @description.en callback
175
110
  * @description.zh 回调
176
111
  */
177
- bindmove?: (event: EventType<'move'>) => void;
112
+ 'bind:onChange'?: (event: EventType<'onChange'>) => void;
178
113
  /**
179
114
  * @description.en callback
180
115
  * @description.zh 回调
181
116
  */
182
- bindend?: (event: EventType<'end'>) => void;
117
+ 'bind:onEnd'?: (event: EventType<'onEnd'>) => void;
183
118
  /**
184
119
  * @description.en callback
185
120
  * @description.zh 回调
186
121
  */
187
- bindstart?: (event: EventType<'start'>) => void;
122
+ 'bind:onStart'?: (event: EventType<'onStart'>) => void;
188
123
  /**
189
124
  * @description.en reverse
190
125
  * @description.zh 是否反转
@@ -224,6 +159,16 @@ export interface SjsSliderProps {
224
159
  * @description.zh 动态计算thumb样式,如 { background: "rgba(0,0,0, {{text /100 }})" }
225
160
  */
226
161
  thumbStyleCalc?: Partial<Record<keyof React.CSSProperties, string>>;
162
+ /**
163
+ * @description.en hideBarOnFirstRender
164
+ * @description.zh 首次渲染时隐藏bar
165
+ */
166
+ hideBarOnFirstRender?: boolean;
167
+ /**
168
+ * @description.en hotAreaStyle
169
+ * @description.zh 点击热区样式
170
+ */
171
+ hotAreaStyle?: React.CSSProperties;
227
172
  }
228
173
 
229
174
  const SjsSlider: React.FC<SjsSliderProps>;
@@ -5,15 +5,6 @@ import "core-js/modules/es.array.concat.js";
5
5
  import "core-js/modules/es.array.map.js";
6
6
  import "core-js/modules/es.array.fill.js";
7
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
8
  // eslint-disable-next-line no-undef
18
9
  Component({
19
10
  options: {
@@ -28,14 +19,9 @@ Component({
28
19
  type: Boolean,
29
20
  value: false
30
21
  },
31
- closed: {
32
- type: Boolean,
33
- value: false
34
- },
35
22
  // 左滑块初始值
36
23
  start: {
37
- type: Number,
38
- value: 0
24
+ type: Number
39
25
  },
40
26
  // 左滑块最小值限制
41
27
  startMin: {
@@ -47,8 +33,7 @@ Component({
47
33
  },
48
34
  // 右滑块初始值/单向滑条初始值
49
35
  end: {
50
- type: Number,
51
- value: 30
36
+ type: Number
52
37
  },
53
38
  watchStart: {
54
39
  type: Number
@@ -72,7 +57,7 @@ Component({
72
57
  // 最大值
73
58
  max: {
74
59
  type: Number,
75
- value: 1000
60
+ value: 100
76
61
  },
77
62
  // 阶段值
78
63
  step: {
@@ -84,11 +69,7 @@ Component({
84
69
  type: Number
85
70
  },
86
71
  // 滑块样式
87
- thumbStartStyle: {
88
- type: String
89
- },
90
- // 滑块样式
91
- thumbEndStyle: {
72
+ thumbStyle: {
92
73
  type: String
93
74
  },
94
75
  // 轨道样式
@@ -107,18 +88,10 @@ Component({
107
88
  activeStepStyle: {
108
89
  type: String
109
90
  },
110
- // 单向还是双向 range: 双向,normal: 单向
111
- mode: {
112
- type: String
113
- },
114
91
  // 方向 "horizontal" | "vertical"
115
92
  direction: {
116
93
  type: String
117
94
  },
118
- // 控制滑动bar的偏移量,用于样式微调
119
- barPad: {
120
- type: Number
121
- },
122
95
  // 隐藏滑块
123
96
  hideThumb: {
124
97
  type: Boolean,
@@ -137,18 +110,13 @@ Component({
137
110
  // 使用触摸跳跃
138
111
  enableTouch: {
139
112
  type: Boolean,
140
- value: false
113
+ value: true
141
114
  },
142
115
  // 使用触摸bar增加偏移
143
116
  enableTouchBar: {
144
117
  type: Boolean,
145
118
  value: false
146
119
  },
147
- // 使用触摸跳跃
148
- maxRangeOffset: {
149
- type: Number,
150
- value: 0
151
- },
152
120
  // 唯一ID
153
121
  instanceId: {
154
122
  type: String
@@ -168,6 +136,15 @@ Component({
168
136
  // 动态计算thumb样式,如 { background: "rgba(0,0,0, {{text}}/100)" }
169
137
  thumbStyleCalc: {
170
138
  type: Object
139
+ },
140
+ // 首次渲染时隐藏bar
141
+ hideBarOnFirstRender: {
142
+ type: Boolean,
143
+ value: false
144
+ },
145
+ // 点击热区样式
146
+ hotAreaStyle: {
147
+ type: String
171
148
  }
172
149
  },
173
150
  data: {
@@ -178,7 +155,7 @@ Component({
178
155
  /**
179
156
  * 组件的方法列表
180
157
  */
181
- ready: function () {
158
+ ready: function ready() {
182
159
  var isNumber = function (n) {
183
160
  return /\d+/.test(n);
184
161
  };
@@ -198,9 +175,9 @@ Component({
198
175
  }
199
176
  },
200
177
  methods: {
201
- setText: function (_ref) {
202
- var instanceId = _ref.instanceId;
203
- var content = _ref.content;
178
+ setText: function setText(_ref) {
179
+ var instanceId = _ref.instanceId,
180
+ content = _ref.content;
204
181
  if (!this.data.showText) return;
205
182
  if (instanceId !== this.data.instanceId) return;
206
183
  this.setData({
@@ -1,34 +1,21 @@
1
1
  .rayui-slider {
2
- --slider-width: 300px;
3
2
  --slider-height: 10px;
4
- // --slider-top-position: 2.5px;
5
- --slider-top-position: 0px;
3
+ --slider-top-position: 2.5px;
6
4
  --range-width: 20px;
7
5
  --range-left-position: 20px;
8
- --thumb-height: 68rpx;
9
- --thumb-width: 68rpx;
6
+ --thumb-height: 24px;
7
+ --thumb-width: 24px;
10
8
  --thumb-left-position: 30px;
11
- --thumb-active-color: #FFFFFF;
9
+ --thumb-active-color: #ffffff;
12
10
 
13
11
  border-radius: 5px;
14
- background: #E0E0E0;
15
- width: var(--slider-width);
12
+ background: #e0e0e0;
16
13
  height: var(--slider-height);
17
14
  margin: var(--slider-top-position);
18
15
  position: relative;
19
16
  display: flex;
20
17
  align-items: center;
21
18
 
22
- .rayui-slider-mask {
23
- width: 100%;
24
- height: 100%;
25
- position: absolute;
26
- left: 0;
27
- top: 0;
28
- background: rgba(0, 0, 0, 0.3);
29
- border-radius: 16px;
30
- }
31
-
32
19
  &-steps {
33
20
  position: absolute;
34
21
  left: 0;
@@ -39,17 +26,14 @@
39
26
  display: flex;
40
27
  justify-content: space-between;
41
28
  align-items: center;
42
-
43
29
  &-dot {
44
30
  width: 4px;
45
31
  height: 4px;
46
32
  border-radius: 50%;
47
- background-color: #328EFF;
48
-
33
+ background-color: #328eff;
49
34
  &:first-child {
50
35
  opacity: 0;
51
36
  }
52
-
53
37
  &:last-child {
54
38
  opacity: 0;
55
39
  }
@@ -57,21 +41,20 @@
57
41
  }
58
42
 
59
43
  &-bar {
44
+ display: none;
60
45
  position: absolute;
61
46
  width: var(--range-width);
62
47
  height: var(--slider-height);
63
- background: transparent;
48
+ background: #328eff;
64
49
  cursor: pointer;
65
50
  border-top-left-radius: 5px;
66
51
  border-bottom-left-radius: 5px;
67
52
  flex-shrink: 0;
68
53
  will-change: width;
69
54
  overflow: hidden;
70
-
71
55
  .rayui-slider-steps-dot {
72
56
  background-color: rgba(51, 255, 241, 0.75);
73
57
  }
74
-
75
58
  &-text {
76
59
  position: absolute;
77
60
  top: 50%;
@@ -96,11 +79,12 @@
96
79
  &-thumb {
97
80
  position: absolute;
98
81
  will-change: left;
82
+ display: none;
99
83
 
100
84
  &-start {
101
85
  top: 50%;
102
86
  transform: translateY(-50%);
103
-
87
+ display: none;
104
88
  &-render {
105
89
  width: var(--thumb-width);
106
90
  height: var(--thumb-height);
@@ -110,11 +94,10 @@
110
94
  box-shadow: rgb(0 0 0 / 12%) 0px 0.5px 4px, rgb(0 0 0 / 12%) 0px 6px 13px;
111
95
  }
112
96
  }
113
-
114
97
  &-end {
115
98
  top: 50%;
116
99
  transform: translateY(-50%);
117
-
100
+ display: none;
118
101
  &-render {
119
102
  width: var(--thumb-width);
120
103
  height: var(--thumb-height);
@@ -138,8 +121,9 @@
138
121
  }
139
122
 
140
123
  &.vertical {
141
- height: var(--slider-width);
124
+ --slider-width: 300px;
142
125
  width: var(--slider-height);
126
+ height: var(--slider-width);
143
127
  align-items: flex-start;
144
128
  justify-content: center;
145
129
 
@@ -152,26 +136,22 @@
152
136
  flex-direction: column;
153
137
  align-items: center;
154
138
  }
155
-
156
139
  &-bar {
157
140
  height: var(--range-width);
158
141
  width: var(--slider-height);
159
- top: calc(var(--range-left-position) + var(--thumb-width)/2);
142
+ top: calc(var(--range-left-position) + var(--thumb-width) / 2);
160
143
  border-top-right-radius: 5px;
161
144
  border-bottom-right-radius: 5px;
162
145
  transform: translateX(-50%);
163
146
  left: 50%;
164
147
  will-change: height;
165
148
  }
166
-
167
149
  &-thumb {
168
150
  will-change: top;
169
-
170
151
  &-start {
171
152
  left: 50%;
172
153
  transform: translateX(-50%);
173
154
  }
174
-
175
155
  &-end {
176
156
  left: 50%;
177
157
  transform: translateX(-50%);
@@ -192,4 +172,13 @@
192
172
  &.disabled {
193
173
  pointer-events: none;
194
174
  }
195
- }
175
+ }
176
+
177
+ .rayui-slider_wrap {
178
+ padding: 20rpx 0;
179
+
180
+ &.vertical {
181
+ padding: 0 20rpx;
182
+ display: inline-block;
183
+ }
184
+ }
@@ -1,5 +1,3 @@
1
- // @ts-check
2
-
3
1
  // props
4
2
  const THUMBS = ['start', 'end'];
5
3
 
@@ -19,36 +17,69 @@ const setOstValue = (ownerInstance, instanceId, key, value) => {
19
17
  ost[instanceId] = state;
20
18
  };
21
19
 
20
+ const isUndefined = val => typeof val === 'undefined';
21
+ const isNull = val => val === null;
22
+ /**
23
+ * 值不存在
24
+ */
25
+ const isNullOrUndefined = val => isNull(val) || isUndefined(val);
26
+ /**
27
+ * 值存在
28
+ */
29
+ const isNotNullOrUndefined = val => !isNullOrUndefined(val);
30
+
31
+ const isValuesInited = (ownerInstance, instanceId) => {
32
+ return (
33
+ isNotNullOrUndefined(getStart(ownerInstance, instanceId)) && getEnd(ownerInstance, instanceId)
34
+ );
35
+ };
36
+
37
+ // hideBarOnFirstRender
38
+ // 判断第一次渲染和后续更新渲染
39
+
22
40
  // watch props
23
41
  const createPropObserver = prop => instanceId =>
24
42
  function (newValue, oldValue, ownerInstance) {
25
43
  const ost = getOst(ownerInstance, instanceId);
26
44
  const isUpdate = oldValue !== undefined;
27
- if (newValue === oldValue) return;
28
45
 
29
46
  if (prop === 'start') {
30
- setStart(ownerInstance, instanceId, getNumber(newValue, 0));
47
+ setStart(ownerInstance, instanceId, getNumber(newValue, null));
31
48
  }
32
49
  if (prop === 'watchstart' && isUpdate) {
33
- setStart(ownerInstance, instanceId, getNumber(newValue, 0));
50
+ setStart(ownerInstance, instanceId, getNumber(newValue, null));
34
51
  }
35
52
  if (prop === 'end') {
36
- setEnd(ownerInstance, instanceId, getNumber(newValue, 30));
37
- updateThumbBg({
38
- ownerInstance,
39
- instanceId,
40
- });
53
+ const end = convertOutValueToValue(ownerInstance, instanceId, getNumber(newValue, null));
54
+ setEnd(ownerInstance, instanceId, end);
41
55
  }
42
56
  if (prop === 'watchend' && isUpdate) {
43
- setEnd(ownerInstance, instanceId, getNumber(newValue, 30));
57
+ setEnd(
58
+ ownerInstance,
59
+ instanceId,
60
+ convertOutValueToValue(ownerInstance, instanceId, getNumber(newValue, null))
61
+ );
44
62
  }
63
+
45
64
  setOstValue(ownerInstance, instanceId, '_startValueInPixels', null);
46
65
  setOstValue(ownerInstance, instanceId, '_endValueInPixels', null);
47
66
 
48
- setOstValue(ownerInstance, instanceId, 'rendered', false);
49
67
  if (!ost.rendered) {
68
+ if (isValuesInited(ownerInstance, instanceId)) {
69
+ setOstValue(ownerInstance, instanceId, 'rendered', true);
70
+ }
71
+ }
72
+
73
+ const hideBarOnFirstRender = isHideBarOnFirstRender(ownerInstance, instanceId);
74
+
75
+ if (hideBarOnFirstRender) {
76
+ if (ost.rendered && isValuesInited(ownerInstance, instanceId)) {
77
+ updateSlider(ownerInstance, instanceId);
78
+ } else {
79
+ hideBarThumbs(ownerInstance, instanceId);
80
+ }
81
+ } else {
50
82
  updateSlider(ownerInstance, instanceId);
51
- setOstValue(ownerInstance, instanceId, 'rendered', true);
52
83
  }
53
84
  };
54
85
 
@@ -63,6 +94,31 @@ const getMax = (ownerInstance, instanceId) => {
63
94
  return min + 100;
64
95
  };
65
96
 
97
+ const getValueMin = (ownerInstance, instanceId) => {
98
+ return getNumber(getProps(ownerInstance, instanceId).valuemin, 0);
99
+ };
100
+
101
+ const convertValueToOutValue = (ownerInstance, instanceId, value) => {
102
+ const valueMin = getValueMin(ownerInstance, instanceId);
103
+ if (valueMin) {
104
+ const max = getMax(ownerInstance, instanceId);
105
+ const step = getStep(ownerInstance, instanceId);
106
+ const result = parseInt(valueMin + ((max - valueMin) / max) * value);
107
+ // 这里处理step
108
+ return Number(result / step).toFixed(0) * step;
109
+ }
110
+ return value;
111
+ };
112
+
113
+ const convertOutValueToValue = (ownerInstance, instanceId, outValue) => {
114
+ const valueMin = getValueMin(ownerInstance, instanceId);
115
+ if (valueMin) {
116
+ const max = getMax(ownerInstance, instanceId);
117
+ return parseInt((outValue - valueMin) / ((max - valueMin) / max));
118
+ }
119
+ return outValue;
120
+ };
121
+
66
122
  const getStep = (ownerInstance, instanceId) => {
67
123
  return getNumber(getProps(ownerInstance, instanceId).step, 1);
68
124
  };
@@ -109,6 +165,11 @@ const isShowSteps = (ownerInstance, instanceId) => {
109
165
  return !!props.showsteps;
110
166
  };
111
167
 
168
+ const isHideBarOnFirstRender = (ownerInstance, instanceId) => {
169
+ const props = getProps(ownerInstance, instanceId);
170
+ return !!props.hidebaronfirstrender;
171
+ };
172
+
112
173
  const isVerticalMode = (ownerInstance, instanceId) => {
113
174
  const props = getProps(ownerInstance, instanceId);
114
175
  return props.direction === 'vertical';
@@ -154,6 +215,21 @@ const getThumbWidth = (ownerInstance, instanceId, type = 'width') => {
154
215
  }
155
216
  };
156
217
 
218
+ function hideBarThumbs(ownerInstance, instanceId) {
219
+ const thumbs = queryComponentAll(ownerInstance, instanceId, '.rayui-slider-thumb');
220
+ const bar = queryComponent(ownerInstance, instanceId, '.rayui-slider-bar');
221
+
222
+ thumbs.forEach(thumb => {
223
+ thumb.setStyle({
224
+ opacity: 0,
225
+ });
226
+ });
227
+
228
+ bar.setStyle({
229
+ opacity: 0,
230
+ });
231
+ }
232
+
157
233
  function updateSlider(ownerInstance, instanceId) {
158
234
  const ost = getOst(ownerInstance, instanceId);
159
235
 
@@ -183,12 +259,6 @@ function updateSlider(ownerInstance, instanceId) {
183
259
  (isVertical
184
260
  ? ost_slider.getBoundingClientRect().height
185
261
  : ost_slider.getBoundingClientRect().width) - ost_thumbWidth;
186
- if (!isRerverse && !isRange && !isVertical) {
187
- ost_maxRange -= ost_thumbWidth;
188
- }
189
- if (isVertical && isRerverse) {
190
- ost_maxRange -= ost_thumbWidth;
191
- }
192
262
 
193
263
  ost_maxRange += getNumber(props.maxrangeoffset, 0);
194
264
  setOstValue(ownerInstance, instanceId, 'maxRange', ost_maxRange);
@@ -215,7 +285,7 @@ function updateSlider(ownerInstance, instanceId) {
215
285
  : 0;
216
286
 
217
287
  setThumb(ownerInstance, instanceId, 'start', _startValueInPixels, {
218
- display: hideThumb ? 'none' : isRange ? 'block' : 'none', // 单向隐藏左按钮
288
+ display: hideThumb ? 'none' : isRange ? 'block' : 'none', // 单向隐藏左按钮,
219
289
  });
220
290
 
221
291
  const endValue = isRerverse
@@ -227,7 +297,7 @@ function updateSlider(ownerInstance, instanceId) {
227
297
  setText(
228
298
  ownerInstance,
229
299
  instanceId,
230
- convertPixelsToValue(ownerInstance, instanceId, endValue, getStep(ownerInstance, instanceId))
300
+ convertValueToOutValue(ownerInstance, instanceId, getEnd(ownerInstance, instanceId))
231
301
  );
232
302
 
233
303
  setRange(
@@ -249,17 +319,16 @@ function updateSlider(ownerInstance, instanceId) {
249
319
  }
250
320
 
251
321
  if (hideThumb || enableTouchBar) {
252
- const trackCurrentX =
253
- ost.trackCurrentX ||
254
- convertValueToPixels(
255
- ownerInstance,
256
- instanceId,
257
- isRerverse
258
- ? getMax(ownerInstance, instanceId) -
259
- getMin(ownerInstance, instanceId) -
260
- getEnd(ownerInstance, instanceId)
261
- : getEnd(ownerInstance, instanceId)
262
- );
322
+ // 修复问题
323
+ const trackCurrentX = convertValueToPixels(
324
+ ownerInstance,
325
+ instanceId,
326
+ isRerverse
327
+ ? getMax(ownerInstance, instanceId) -
328
+ getMin(ownerInstance, instanceId) -
329
+ getEnd(ownerInstance, instanceId)
330
+ : getEnd(ownerInstance, instanceId)
331
+ );
263
332
  setOstValue(ownerInstance, instanceId, 'trackCurrentX', trackCurrentX);
264
333
  }
265
334
 
@@ -315,6 +384,7 @@ function convertPixelsToValue(ownerInstance, instanceId, value, step = 1) {
315
384
  (getMax(ownerInstance, instanceId) - getMin(ownerInstance, instanceId))
316
385
  )
317
386
  );
387
+
318
388
  // round to step value
319
389
  _value = step > 0 ? Math.round(_value / step) * step : _value;
320
390
  return parseFloat(_value.toFixed(2));
@@ -351,13 +421,15 @@ function setThumb(ownerInstance, instanceId, thumbName, valueInPixels, style) {
351
421
  if (thumb.getDataset().name === thumbName) {
352
422
  if (isVertical) {
353
423
  thumb.setStyle({
424
+ opacity: 1,
354
425
  ...(style || {}),
355
- top: `${valueInPixels - 3}px`,
426
+ top: `${valueInPixels}px`,
356
427
  });
357
428
  } else {
358
429
  thumb.setStyle({
430
+ opacity: 1,
359
431
  ...(style || {}),
360
- left: `${valueInPixels - 3}px`,
432
+ left: `${valueInPixels}px`,
361
433
  });
362
434
  }
363
435
  }
@@ -440,18 +512,16 @@ function setRange(ownerInstance, instanceId, start, end) {
440
512
 
441
513
  const props = getProps(ownerInstance, instanceId);
442
514
 
443
- const barPad = props.barpad;
444
-
445
- let rangeWidth = width + thumbWidth + barPad;
515
+ let rangeWidth = width + thumbWidth / 2;
446
516
  if (isReverse) {
447
517
  rangeWidth = ost.trackWidth - rangeWidth;
448
518
  }
449
519
 
450
520
  ost.sliderRange.setStyle({
451
- [isVertical ? (isReverse ? 'bottom' : 'top') : isReverse ? 'right' : 'left']: `${
452
- minThumb - barPad / 2
453
- }px`,
521
+ [isVertical ? (isReverse ? 'bottom' : 'top') : isReverse ? 'right' : 'left']: `${minThumb}px`,
454
522
  [isVertical ? 'height' : 'width']: `${rangeWidth}px`,
523
+ opacity: 1,
524
+ display: 'block',
455
525
  });
456
526
  }
457
527
 
@@ -476,13 +546,13 @@ const handleMouseDown = instanceId => (event, ownerInstance) => {
476
546
  if (THUMBS.includes(thumbId)) {
477
547
  setOstValue(ownerInstance, instanceId, 'currentThumbName', thumbId);
478
548
  setOstValue(ownerInstance, instanceId, 'currentThumb', target);
549
+
550
+ const ost_slider = queryComponent(ownerInstance, instanceId);
551
+ const rect = ost_slider.getBoundingClientRect();
552
+
479
553
  const startX = isVertical ? event.touches[0].pageY : event.touches[0].pageX;
480
554
 
481
- const currentThumbPositionX =
482
- startX -
483
- (isVertical
484
- ? ost.currentThumb.getBoundingClientRect().top
485
- : ost.currentThumb.getBoundingClientRect().left);
555
+ const currentThumbPositionX = startX - (isVertical ? rect.top : rect.left);
486
556
 
487
557
  setOstValue(ownerInstance, instanceId, 'currentThumbPositionX', currentThumbPositionX);
488
558
 
@@ -501,15 +571,21 @@ const handleTrackMouseDown = instanceId => (event, ownerInstance) => {
501
571
 
502
572
  const ost = getOst(ownerInstance, instanceId);
503
573
  const isVertical = isVerticalMode(ownerInstance, instanceId);
504
- const startX = isVertical ? event.touches[0].clientY : event.touches[0].pageX;
505
574
 
506
- const trackStartX =
507
- startX -
508
- (isVertical ? ost.slider.getBoundingClientRect().top : ost.slider.getBoundingClientRect().left);
575
+ const ost_slider = queryComponent(ownerInstance, instanceId);
576
+ const rect = ost_slider.getBoundingClientRect();
577
+ const startX = isVertical
578
+ ? event.touches[0].pageY - rect.top
579
+ : event.touches[0].pageX - rect.left;
580
+
581
+ // 修复touch模式触摸抖动
582
+ const trackStartX = startX;
509
583
  setOstValue(ownerInstance, instanceId, 'trackStartX', trackStartX);
510
584
 
511
585
  onStart(event, ownerInstance, instanceId);
512
- setOstValue(ownerInstance, instanceId, 'currentThumbName', 'end');
586
+ if (!isRange) {
587
+ setOstValue(ownerInstance, instanceId, 'currentThumbName', 'end');
588
+ }
513
589
 
514
590
  if (!isRange && !hideThumb && isEnableTouch(ownerInstance, instanceId) && !enableTouchBar) {
515
591
  const thumbEnd = queryComponent(ownerInstance, instanceId, '.rayui-slider-thumb-end');
@@ -517,11 +593,11 @@ const handleTrackMouseDown = instanceId => (event, ownerInstance) => {
517
593
  setOstValue(ownerInstance, instanceId, 'currentThumb', thumbEnd);
518
594
 
519
595
  const offset = isVertical
520
- ? thumbEnd.getBoundingClientRect().height / 2
521
- : thumbEnd.getBoundingClientRect().width / 2;
596
+ ? thumbEnd.getBoundingClientRect().height
597
+ : thumbEnd.getBoundingClientRect().width;
522
598
 
523
599
  if (thumbEnd) {
524
- let moveX = ost.trackStartX - offset;
600
+ let moveX = ost.trackStartX - offset / 2;
525
601
 
526
602
  let moveValue = convertPixelsToValue(
527
603
  ownerInstance,
@@ -562,7 +638,11 @@ const onMouseMove = instanceId => (event, ownerInstance) => {
562
638
  const enableTouchBar = isEnableTouchBar(ownerInstance, instanceId);
563
639
  // track mouse mouve only when toggle true
564
640
  if (ost.isMoving) {
565
- const currentX = isVertical ? event.touches[0].pageY : event.touches[0].pageX;
641
+ const ost_slider = queryComponent(ownerInstance, instanceId);
642
+ const rect = ost_slider.getBoundingClientRect();
643
+ const currentX = isVertical
644
+ ? event.touches[0].pageY - rect.top
645
+ : event.touches[0].pageX - rect.left;
566
646
  let moveX =
567
647
  currentX -
568
648
  ost.currentThumbPositionX -
@@ -634,6 +714,22 @@ const onMouseMove = instanceId => (event, ownerInstance) => {
634
714
  // lock the thumb within the bounaries
635
715
  moveValue = setBoundries(ownerInstance, instanceId, moveValue);
636
716
 
717
+ const props = getProps(ownerInstance, instanceId);
718
+ switch (ost.currentThumbName) {
719
+ case 'start':
720
+ const _endValueInPixels = ost._endValueInPixels;
721
+ // if (moveX > _endValueInPixels) return false;
722
+ if (props.startmin && moveValue < props.startmin) return false;
723
+ if (props.startmax && moveValue > props.startmax) return false;
724
+ break;
725
+ case 'end':
726
+ const _startValueInPixels = ost._startValueInPixels;
727
+ // if (moveX < _startValueInPixels) return false;
728
+ if (props.endmin && moveValue < props.endmin) return false;
729
+ if (props.endmax && moveValue > props.endmax) return false;
730
+ break;
731
+ }
732
+
637
733
  setOstValue(ownerInstance, instanceId, '_start', 0);
638
734
  setOstValue(ownerInstance, instanceId, '_end', moveValue);
639
735
 
@@ -647,20 +743,7 @@ const onMouseMove = instanceId => (event, ownerInstance) => {
647
743
  }
648
744
  };
649
745
 
650
- const limit = (number, min, max) => Math.min(max, Math.max(min, number));
651
-
652
- const updateThumbBg = ({ ownerInstance, instanceId }) => {
653
- // !!! thumb 内部颜色填充 ==== start
654
- // const { hue, closed } = getProps(ownerInstance, instanceId);
655
- const isRerverse = isReverseMode(ownerInstance, instanceId);
656
- const thumbEnd = ownerInstance.selectComponent('.rayui-slider-thumb-end-render');
657
- const reverseRange = isRerverse
658
- ? getMax(ownerInstance, instanceId) - getRangeValue(ownerInstance, instanceId)
659
- : 0;
660
- const end = isRerverse ? reverseRange : getEnd(ownerInstance, instanceId);
661
- };
662
-
663
- const onChange = (ownerInstance, instanceId, position) => {
746
+ const onChange = (ownerInstance, instanceId, position, skipDiff = false) => {
664
747
  const ost = getOst(ownerInstance, instanceId);
665
748
  const isRerverse = isReverseMode(ownerInstance, instanceId);
666
749
  const reverseRange = isRerverse
@@ -671,26 +754,31 @@ const onChange = (ownerInstance, instanceId, position) => {
671
754
  const nextEnd = isRerverse ? reverseRange : getEnd(ownerInstance, instanceId);
672
755
  const nextRange = isRerverse ? reverseRange : getRangeValue(ownerInstance, instanceId);
673
756
 
674
- // 如果start、end、range 都没变
675
- if (nextStart === ost._last_start && nextEnd === ost._last_end && nextRange === ost._last_range) {
676
- return;
757
+ if (skipDiff) {
758
+ // noop
759
+ } else {
760
+ // 如果start、end、range 都没变
761
+ if (
762
+ nextStart === ost._last_start &&
763
+ nextEnd === ost._last_end &&
764
+ nextRange === ost._last_range
765
+ ) {
766
+ return;
767
+ }
677
768
  }
678
- setText(ownerInstance, instanceId, nextEnd);
769
+
770
+ const out = convertValueToOutValue(ownerInstance, instanceId, nextEnd);
771
+ setText(ownerInstance, instanceId, out);
679
772
 
680
773
  setOstValue(ownerInstance, instanceId, '_last_start', nextStart);
681
774
  setOstValue(ownerInstance, instanceId, '_last_end', nextEnd);
682
775
  setOstValue(ownerInstance, instanceId, '_last_range', nextRange);
683
776
 
684
- updateThumbBg({
685
- ownerInstance,
686
- instanceId,
687
- });
688
-
689
777
  // publish
690
- ownerInstance.triggerEvent('move', {
778
+ ownerInstance.triggerEvent('onChange', {
691
779
  instanceId,
692
780
  start: nextStart,
693
- end: nextEnd,
781
+ end: out,
694
782
  range: nextRange,
695
783
  position,
696
784
  });
@@ -706,21 +794,19 @@ const onEnd = (event, ownerInstance, instanceId) => {
706
794
  const nextStart = getStart(ownerInstance, instanceId);
707
795
  const nextEnd = isRerverse ? reverseRange : getEnd(ownerInstance, instanceId);
708
796
  const nextRange = isRerverse ? reverseRange : getRangeValue(ownerInstance, instanceId);
709
- setText(ownerInstance, instanceId, nextEnd);
797
+
798
+ const out = convertValueToOutValue(ownerInstance, instanceId, nextEnd);
799
+ setText(ownerInstance, instanceId, out);
710
800
 
711
801
  setOstValue(ownerInstance, instanceId, '_last_start', null);
712
802
  setOstValue(ownerInstance, instanceId, '_last_end', null);
713
803
  setOstValue(ownerInstance, instanceId, '_last_range', null);
714
- updateThumbBg({
715
- ownerInstance,
716
- instanceId,
717
- });
718
804
 
719
805
  // publish
720
- ownerInstance.triggerEvent('end', {
806
+ ownerInstance.triggerEvent('onEnd', {
721
807
  instanceId,
722
808
  start: nextStart,
723
- end: nextEnd,
809
+ end: out,
724
810
  range: nextRange,
725
811
  position: target.getDataset().name || 'end',
726
812
  });
@@ -736,17 +822,14 @@ const onStart = (event, ownerInstance, instanceId) => {
736
822
  const nextEnd = isRerverse ? reverseRange : getEnd(ownerInstance, instanceId);
737
823
  const nextRange = isRerverse ? reverseRange : getRangeValue(ownerInstance, instanceId);
738
824
 
739
- setText(ownerInstance, instanceId, nextEnd);
740
- updateThumbBg({
741
- ownerInstance,
742
- instanceId,
743
- });
825
+ const out = convertValueToOutValue(ownerInstance, instanceId, nextEnd);
826
+ setText(ownerInstance, instanceId, out);
744
827
 
745
828
  // publish
746
- ownerInstance.triggerEvent('start', {
829
+ ownerInstance.triggerEvent('onStart', {
747
830
  instanceId,
748
831
  start: nextStart,
749
- end: nextEnd,
832
+ end: out,
750
833
  range: nextRange,
751
834
  position: target.getDataset().name || 'end',
752
835
  });
@@ -767,12 +850,61 @@ const onMouseUp = instanceId => (event, ownerInstance) => {
767
850
  const onTrackMouseUp = instanceId => (event, ownerInstance) => {
768
851
  const hideThumb = isHideThumb(ownerInstance, instanceId);
769
852
  const ost = getOst(ownerInstance, instanceId);
770
- setOstValue(ownerInstance, instanceId, 'trackCurrentX', ost.trackNextX);
853
+ setOstValue(
854
+ ownerInstance,
855
+ instanceId,
856
+ 'trackCurrentX',
857
+ ost.trackNextX === undefined ? ost.trackCurrentX : ost.trackNextX
858
+ );
771
859
  onEnd(event, ownerInstance, instanceId);
772
860
  setOstValue(ownerInstance, instanceId, 'isMoving', false);
861
+
773
862
  updateThumbZIndex(ownerInstance, instanceId);
774
863
  };
775
864
 
865
+ const onAdd = instanceId => (event, ownerInstance) => {
866
+ const end = getEnd(ownerInstance, instanceId);
867
+ const step = getStep(ownerInstance, instanceId);
868
+ const max = getMax(ownerInstance, instanceId);
869
+ const next = end + step;
870
+ const moveValue = getNumber(next <= max ? next : max, null);
871
+
872
+ setOstValue(ownerInstance, instanceId, '_end', moveValue);
873
+
874
+ const moveX = convertValueToPixels(ownerInstance, instanceId, moveValue);
875
+
876
+ setThumb(ownerInstance, instanceId, 'end', moveX);
877
+ setRange(ownerInstance, instanceId, 0, moveX);
878
+ onChange(ownerInstance, instanceId, 'end');
879
+
880
+ const trackCurrentX = convertValueToPixels(ownerInstance, instanceId, moveValue);
881
+ setOstValue(ownerInstance, instanceId, 'trackCurrentX', trackCurrentX);
882
+
883
+ onChange(ownerInstance, instanceId, 'end', true);
884
+ onEnd(event, ownerInstance, instanceId);
885
+ };
886
+ const onSub = instanceId => (event, ownerInstance) => {
887
+ const end = getEnd(ownerInstance, instanceId);
888
+ const step = getStep(ownerInstance, instanceId);
889
+ const min = getMin(ownerInstance, instanceId);
890
+ const next = end - step;
891
+ const moveValue = getNumber(next >= min ? next : min, null);
892
+
893
+ setOstValue(ownerInstance, instanceId, '_end', moveValue);
894
+
895
+ const moveX = convertValueToPixels(ownerInstance, instanceId, moveValue);
896
+
897
+ setThumb(ownerInstance, instanceId, 'end', moveX);
898
+ setRange(ownerInstance, instanceId, 0, moveX);
899
+ onChange(ownerInstance, instanceId, 'end');
900
+
901
+ const trackCurrentX = convertValueToPixels(ownerInstance, instanceId, moveValue);
902
+ setOstValue(ownerInstance, instanceId, 'trackCurrentX', trackCurrentX);
903
+
904
+ onChange(ownerInstance, instanceId, 'end', true);
905
+ onEnd(event, ownerInstance, instanceId);
906
+ };
907
+
776
908
  module.exports = {
777
909
  startPropObserver: createPropObserver('start'),
778
910
  endPropObserver: createPropObserver('end'),
@@ -783,4 +915,6 @@ module.exports = {
783
915
  onMouseUp,
784
916
  onTrackMouseUp,
785
917
  handleTrackMouseDown,
918
+ onAdd,
919
+ onSub,
786
920
  };
@@ -1,90 +1,90 @@
1
1
  <sjs src="./index.sjs" module="computed"></sjs>
2
2
 
3
- <view
4
- id="{{instanceId}}"
5
- class="rayui-slider {{direction === 'vertical' ? 'vertical': 'horizontal'}} {{reverse ? 'reverse': 'no-reverse'}} {{disable ? 'disabled': ''}} {{className}}"
6
- disable="{{disable}}"
7
-
8
- change:start="{{computed.startPropObserver(instanceId)}}"
9
- change:end="{{computed.endPropObserver(instanceId)}}"
10
- change:watchstart="{{computed.watchstartPropObserver(instanceId)}}"
11
- change:watchend="{{computed.watchenddPropObserver(instanceId)}}"
12
- change:hue="{{hue}}"
13
- start="{{start}}"
14
- end="{{end}}"
15
- watchstart="{{watchStart}}"
16
- watchend="{{watchEnd}}"
17
-
18
- data-hue="{{hue}}"
19
- data-min="{{min}}"
20
- data-max="{{max}}"
21
- data-closed="{{closed}}"
22
-
23
- data-step="{{step}}"
24
-
3
+ <view class="rayui-slider_wrap {{direction === 'vertical' ? 'vertical': 'horizontal'}}"
25
4
  bind:touchstart="{{computed.handleTrackMouseDown(instanceId)}}"
26
5
  bind:touchmove="{{computed.onMouseMove(instanceId)}}"
27
6
  bind:touchend="{{computed.onTrackMouseUp(instanceId)}}"
7
+ style="{{hotAreaStyle}}"
8
+ >
9
+ <view
10
+ id="{{instanceId}}"
11
+ class="rayui-slider {{direction === 'vertical' ? 'vertical': 'horizontal'}} {{reverse ? 'reverse': 'no-reverse'}} {{disable ? 'disabled': ''}} {{className}}"
12
+ disable="{{disable}}"
13
+
14
+ change:start="{{computed.startPropObserver(instanceId)}}"
15
+ change:end="{{computed.endPropObserver(instanceId)}}"
16
+ change:watchstart="{{computed.watchstartPropObserver(instanceId)}}"
17
+ change:watchend="{{computed.watchenddPropObserver(instanceId)}}"
18
+ start="{{start}}"
19
+ end="{{end}}"
20
+ watchstart="{{watchStart}}"
21
+ watchend="{{watchEnd}}"
28
22
 
29
- data-startmin="{{startMin}}"
30
- data-startmax="{{startMax}}"
31
-
32
- data-endmin="{{endMin}}"
33
- data-endmax="{{endMax}}"
23
+ data-max="{{max}}"
34
24
 
35
- data-mode="{{mode}}"
36
- data-barpad="{{barPad}}"
37
- data-hidethumb="{{hideThumb}}"
38
- data-showsteps="{{showSteps}}"
39
- data-direction="{{direction}}"
40
- data-reverse="{{reverse}}"
41
- data-enabletouch="{{enableTouch}}"
42
- data-enabletouchbar="{{enableTouchBar}}"
43
- data-maxrangeoffset="{{maxRangeOffset}}"
44
- data-texttemplate="{{textTemplate}}"
45
- data-showtext="{{showText}}"
46
- data-thumbstylecalc="{{thumbStyleCalc}}"
25
+ data-step="{{step}}"
47
26
 
48
- style="{{trackStyle}}"
49
- >
50
- <view ty:if="{{disable}}" class="rayui-slider-mask"></view>
51
- <view ty:if="{{showSteps}}" class="rayui-slider-steps">
52
- <view class="rayui-slider-steps-dot" ty:for="{{steps}}" style="{{stepStyle}}" ty:for-item="step">
53
- </view>
54
- </view>
55
- <view class="rayui-slider-bar"
56
- style="{{barStyle}}"
27
+ data-startmin="{{startMin}}"
28
+ data-startmax="{{startMax}}"
29
+ data-valuemin="{{min}}"
30
+
31
+ data-endmin="{{endMin}}"
32
+ data-endmax="{{endMax}}"
33
+
34
+ data-mode="{{mode}}"
35
+ data-barpad="{{barPad}}"
36
+ data-hidethumb="{{hideThumb}}"
37
+ data-showsteps="{{showSteps}}"
38
+ data-direction="{{direction}}"
39
+ data-reverse="{{reverse}}"
40
+ data-enabletouch="{{enableTouch}}"
41
+ data-enabletouchbar="{{enableTouchBar}}"
42
+ data-maxrangeoffset="{{maxRangeOffset}}"
43
+ data-texttemplate="{{textTemplate}}"
44
+ data-showtext="{{showText}}"
45
+ data-thumbstylecalc="{{thumbStyleCalc}}"
46
+ data-hidebaronfirstrender="{{hideBarOnFirstRender}}"
47
+
48
+ style="{{trackStyle}}"
57
49
  >
58
- <view ty:if="{{showText}}" class="rayui-slider-bar-text" style="{{textStyle}}">
59
- {{text}}
50
+ <view ty:if="{{showSteps}}" class="rayui-slider-steps">
51
+ <view class="rayui-slider-steps-dot" ty:for="{{steps}}" style="{{stepStyle}}" ty:for-item="step">
52
+ </view>
60
53
  </view>
61
- <view class="rayui-slider-bar-steps_wrap">
62
- <view ty:if="{{showSteps}}" class="rayui-slider-steps">
63
- <view class="rayui-slider-steps-dot" ty:for="{{steps}}" style="{{activeStepStyle}}" ty:for-item="step">
64
- </view>
65
- </view>
54
+ <view class="rayui-slider-bar"
55
+ style="{{barStyle}}"
56
+ >
57
+ <view ty:if="{{showText}}" class="rayui-slider-bar-text" style="{{textStyle}}">
58
+ {{text}}
59
+ </view>
60
+ <view class="rayui-slider-bar-steps_wrap">
61
+ <view ty:if="{{showSteps}}" class="rayui-slider-steps">
62
+ <view class="rayui-slider-steps-dot" ty:for="{{steps}}" style="{{activeStepStyle}}" ty:for-item="step">
63
+ </view>
64
+ </view>
65
+ </view>
66
66
  </view>
67
- </view>
68
- <view
69
- class="rayui-slider-thumb rayui-slider-thumb-start"
70
- data-name="start"
71
- bind:touchstart="{{computed.handleMouseDown(instanceId)}}"
72
- bind:touchend="{{computed.onMouseUp(instanceId)}}"
73
- >
74
- <view
67
+ <view
68
+ class="rayui-slider-thumb rayui-slider-thumb-start"
75
69
  data-name="start"
76
- class="rayui-slider-thumb-render rayui-slider-thumb-start-render" style="{{thumbStartStyle}}"
77
- ></view>
78
- </view>
79
- <view
80
- class="rayui-slider-thumb rayui-slider-thumb-end"
81
- data-name="end"
82
- bind:touchstart="{{computed.handleMouseDown(instanceId)}}"
83
- bind:touchend="{{computed.onMouseUp(instanceId)}}"
84
- >
85
- <view
70
+ bind:touchstart="{{computed.handleMouseDown(instanceId)}}"
71
+ bind:touchend="{{computed.onMouseUp(instanceId)}}"
72
+ >
73
+ <view
74
+ data-name="start"
75
+ class="rayui-slider-thumb-render rayui-slider-thumb-start-render"
76
+ ></view>
77
+ </view>
78
+ <view
79
+ class="rayui-slider-thumb rayui-slider-thumb-end"
86
80
  data-name="end"
87
- class="rayui-slider-thumb-render rayui-slider-thumb-end-render" style="{{thumbEndStyle}}"
88
- ></view>
81
+ bind:touchstart="{{computed.handleMouseDown(instanceId)}}"
82
+ bind:touchend="{{computed.onMouseUp(instanceId)}}"
83
+ >
84
+ <view
85
+ data-name="end"
86
+ class="rayui-slider-thumb-render rayui-slider-thumb-end-render" style="{{thumbStyle}}"
87
+ ></view>
88
+ </view>
89
89
  </view>
90
90
  </view>
package/lib/index.js CHANGED
@@ -5,10 +5,10 @@ import "core-js/modules/es.array.slice.js";
5
5
  /* eslint-disable @typescript-eslint/no-unused-vars */
6
6
  import React, { useRef, useState, useEffect } from 'react';
7
7
  import { View, Text } from '@ray-js/ray';
8
+ import Slider from '@ray-js/components-ty-slider/lib/slider';
8
9
  import { useDebounceFn, useThrottleFn } from 'ahooks';
9
10
  import { formatPercent } from './utils';
10
11
  import styles from './index.module.less';
11
- import Slider from './components/slider';
12
12
  import { defaultProps } from './props';
13
13
  function OpacitySlider(props) {
14
14
  var preValue = useRef(-1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lamp-style-slider",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-beta-1",
4
4
  "description": "照明样式的基础滑动条",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -8,13 +8,6 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "types": "lib/index.d.ts",
11
- "maintainers": [
12
- "tuya_npm",
13
- {
14
- "name": "tuyafe",
15
- "email": "tuyafe@tuya.com"
16
- }
17
- ],
18
11
  "scripts": {
19
12
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
20
13
  "build": "ray build --type=component",
@@ -65,5 +58,13 @@
65
58
  "git add"
66
59
  ]
67
60
  },
68
- "dependencies": {}
61
+ "dependencies": {
62
+ "@ray-js/components-ty-slider": "^0.2.36-beta-1"
63
+ },
64
+ "maintainers": [
65
+ {
66
+ "name": "tuyafe",
67
+ "email": "tuyafe@tuya.com"
68
+ }
69
+ ]
69
70
  }