@varlet/ui 2.0.6 → 2.1.0-alpha.1667210582672

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.
@@ -1 +1 @@
1
- .var-collapse { position: relative; width: 100%;}
1
+ .var-collapse { position: relative; width: 100%; z-index: 0;}
@@ -108,14 +108,16 @@ export function render(_ctx, _cache) {
108
108
  /* TEXT, CLASS */
109
109
  ))])) : (_openBlock(), _createElementBlock("span", _hoisted_2, _toDisplayString(_ctx.label), 1
110
110
  /* TEXT */
111
- )), _createVNode(_component_var_icon, {
111
+ )), _renderSlot(_ctx.$slots, "arrow-icon", {
112
+ focus: _ctx.isFocus
113
+ }, () => [_createVNode(_component_var_icon, {
112
114
  class: _normalizeClass(_ctx.classes(_ctx.n('arrow'), [_ctx.isFocus, _ctx.n('--arrow-rotate')])),
113
115
  "var-select-cover": "",
114
116
  name: "menu-down",
115
117
  transition: 300
116
118
  }, null, 8
117
119
  /* PROPS */
118
- , ["class"])], 6
120
+ , ["class"])])], 6
119
121
  /* CLASS, STYLE */
120
122
  ), _createElementVNode("label", {
121
123
  class: _normalizeClass(_ctx.classes(_ctx.n('placeholder'), 'var--ellipsis', [_ctx.isFocus, _ctx.n('--focus')], [_ctx.errorMessage, _ctx.n('--error')], [_ctx.formDisabled || _ctx.disabled, _ctx.n('--disabled')], _ctx.computePlaceholderState(), [!_ctx.hint, _ctx.n('--placeholder-non-hint')])),
@@ -1,5 +1,3 @@
1
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
1
  import { defineComponent, ref, onMounted, computed, reactive, nextTick, watch } from 'vue';
4
2
  import { useValidation, createNamespace, call } from '../utils/components';
5
3
  import { useForm } from '../form/provide';
@@ -30,10 +28,6 @@ export function render(_ctx, _cache) {
30
28
  class: _normalizeClass(_ctx.n())
31
29
  }, [_createElementVNode("div", {
32
30
  class: _normalizeClass(_ctx.classes(_ctx.n('block'), [_ctx.isDisabled, _ctx.n('--disabled')], [_ctx.errorMessage, _ctx.n('--error')])),
33
- style: _normalizeStyle({
34
- height: _ctx.thumbSize === undefined ? _ctx.thumbSize : _ctx.multiplySizeUnit(_ctx.thumbSize, 3),
35
- margin: _ctx.thumbSize === undefined ? _ctx.thumbSize : "0 " + _ctx.multiplySizeUnit(_ctx.thumbSize, 0.5)
36
- }),
37
31
  ref: "sliderEl",
38
32
  onClick: _cache[0] || (_cache[0] = function () {
39
33
  return _ctx.click && _ctx.click(...arguments);
@@ -68,21 +62,19 @@ export function render(_ctx, _cache) {
68
62
  onTouchend: $event => _ctx.end(item.enumValue),
69
63
  onTouchcancel: $event => _ctx.end(item.enumValue)
70
64
  }, [_renderSlot(_ctx.$slots, "button", {
71
- currentValue: item.value
65
+ currentValue: item.text
72
66
  }, () => [_createElementVNode("div", {
73
67
  class: _normalizeClass(_ctx.n('thumb-block')),
74
68
  style: _normalizeStyle({
75
- background: _ctx.thumbColor,
76
- height: _ctx.multiplySizeUnit(_ctx.thumbSize),
77
- width: _ctx.multiplySizeUnit(_ctx.thumbSize)
69
+ background: _ctx.thumbColor
78
70
  })
79
71
  }, null, 6
80
72
  /* CLASS, STYLE */
81
73
  ), _createElementVNode("div", {
82
74
  class: _normalizeClass(_ctx.classes(_ctx.n('thumb-ripple'), [_ctx.thumbsProps[item.enumValue].active, _ctx.n('thumb-ripple--active')])),
83
- style: _normalizeStyle(_extends({
75
+ style: _normalizeStyle({
84
76
  background: _ctx.thumbColor
85
- }, _ctx.getRippleSize(item)))
77
+ })
86
78
  }, null, 6
87
79
  /* CLASS, STYLE */
88
80
  ), _createElementVNode("div", {
@@ -93,7 +85,7 @@ export function render(_ctx, _cache) {
93
85
  height: _ctx.thumbSize === undefined ? _ctx.thumbSize : _ctx.multiplySizeUnit(_ctx.thumbSize, 2),
94
86
  width: _ctx.thumbSize === undefined ? _ctx.thumbSize : _ctx.multiplySizeUnit(_ctx.thumbSize, 2)
95
87
  })
96
- }, [_createElementVNode("span", null, _toDisplayString(item.value), 1
88
+ }, [_createElementVNode("span", null, _toDisplayString(item.text), 1
97
89
  /* TEXT */
98
90
  )], 6
99
91
  /* CLASS, STYLE */
@@ -102,8 +94,8 @@ export function render(_ctx, _cache) {
102
94
  , _hoisted_1);
103
95
  }), 128
104
96
  /* KEYED_FRAGMENT */
105
- ))], 6
106
- /* CLASS, STYLE */
97
+ ))], 2
98
+ /* CLASS */
107
99
  ), _createVNode(_component_var_form_details, {
108
100
  "error-message": _ctx.errorMessage,
109
101
  class: _normalizeClass(_ctx.n('form')),
@@ -152,53 +144,43 @@ export default defineComponent({
152
144
  [Thumbs.First]: getThumbProps(),
153
145
  [Thumbs.Second]: getThumbProps()
154
146
  });
155
- var unitWidth = computed(() => maxWidth.value / 100 * toNumber(props.step));
147
+ var scope = computed(() => toNumber(props.max) - toNumber(props.min));
148
+ var unitWidth = computed(() => maxWidth.value / scope.value * toNumber(props.step));
156
149
  var thumbList = computed(() => {
157
- var list = [{
158
- value: props.modelValue,
159
- enumValue: Thumbs.First
160
- }];
150
+ var {
151
+ modelValue,
152
+ range
153
+ } = props;
154
+ var list = [];
161
155
 
162
- if (props.range && isArray(props.modelValue)) {
156
+ if (range && isArray(modelValue)) {
163
157
  list = [{
164
- value: props.modelValue[0],
165
- enumValue: Thumbs.First
158
+ value: getValue(modelValue[0]),
159
+ enumValue: Thumbs.First,
160
+ text: toPrecision(modelValue[0])
166
161
  }, {
167
- value: props.modelValue[1],
168
- enumValue: Thumbs.Second
162
+ value: getValue(modelValue[1]),
163
+ enumValue: Thumbs.Second,
164
+ text: toPrecision(modelValue[1])
165
+ }];
166
+ } else if (isNumber(modelValue)) {
167
+ list = [{
168
+ value: getValue(modelValue),
169
+ enumValue: Thumbs.First,
170
+ text: toPrecision(modelValue)
169
171
  }];
170
172
  }
171
173
 
172
174
  return list;
173
175
  });
174
-
175
- var getRippleSize = item => {
176
- var size;
177
-
178
- if (props.thumbSize !== undefined) {
179
- size = thumbsProps[item.enumValue].active ? multiplySizeUnit(props.thumbSize, 3) : '0px';
180
- }
181
-
182
- return {
183
- height: size,
184
- width: size
185
- };
186
- };
187
-
188
- var showLabel = type => {
189
- if (props.labelVisible === 'always') return true;
190
- if (props.labelVisible === 'never') return false;
191
- return thumbsProps[type].active;
192
- };
193
-
194
176
  var getFillStyle = computed(() => {
195
177
  var {
196
178
  activeColor,
197
179
  range,
198
180
  modelValue
199
181
  } = props;
200
- var width = range && isArray(modelValue) ? Math.abs(modelValue[0] - modelValue[1]) : modelValue;
201
- var left = range && isArray(modelValue) ? Math.min(modelValue[0], modelValue[1]) : 0;
182
+ var left = range && isArray(modelValue) ? getValue(Math.min(modelValue[0], modelValue[1])) : 0;
183
+ var width = range && isArray(modelValue) ? getValue(Math.max(modelValue[0], modelValue[1])) - left : getValue(modelValue);
202
184
  return {
203
185
  width: width + "%",
204
186
  left: left + "%",
@@ -208,26 +190,52 @@ export default defineComponent({
208
190
  var isDisabled = computed(() => props.disabled || (form == null ? void 0 : form.disabled.value));
209
191
  var isReadonly = computed(() => props.readonly || (form == null ? void 0 : form.readonly.value));
210
192
 
193
+ var showLabel = type => {
194
+ if (props.labelVisible === 'always') return true;
195
+ if (props.labelVisible === 'never') return false;
196
+ return thumbsProps[type].active;
197
+ };
198
+
199
+ var getValue = value => {
200
+ var {
201
+ min,
202
+ max
203
+ } = props;
204
+ if (value < toNumber(min)) return 0;
205
+ if (value > toNumber(max)) return 100;
206
+ return (value - toNumber(min)) / scope.value * 100;
207
+ };
208
+
209
+ var toPrecision = value => {
210
+ if (!isNumber(value)) return 0;
211
+ var num = value;
212
+ if (num < Number(props.min)) num = Number(props.min);
213
+ if (num > Number(props.max)) num = Number(props.max);
214
+ var isInteger = parseInt("" + num, 10) === num;
215
+ return isInteger ? num : toNumber(num.toPrecision(5));
216
+ };
217
+
211
218
  var setPercent = (moveDistance, type) => {
212
219
  var rangeValue = [];
213
220
  var {
214
221
  step,
215
222
  range,
216
223
  modelValue,
217
- onChange
224
+ onChange,
225
+ min
218
226
  } = props;
219
227
  var stepNumber = toNumber(step);
220
228
  var roundDistance = Math.round(moveDistance / unitWidth.value);
221
- var curValue = roundDistance * stepNumber;
222
- var prevValue = thumbsProps[type].percentValue;
223
- thumbsProps[type].percentValue = curValue / stepNumber;
229
+ var curValue = roundDistance * stepNumber + toNumber(min);
230
+ var prevValue = thumbsProps[type].percentValue * stepNumber + toNumber(min);
231
+ thumbsProps[type].percentValue = roundDistance;
224
232
 
225
233
  if (range && isArray(modelValue)) {
226
234
  rangeValue = type === Thumbs.First ? [curValue, modelValue[1]] : [modelValue[0], curValue];
227
235
  }
228
236
 
229
237
  if (prevValue !== curValue) {
230
- var value = range ? rangeValue : curValue;
238
+ var value = range ? rangeValue.map(value => toPrecision(value)) : toPrecision(curValue);
231
239
  call(onChange, value);
232
240
  call(props['onUpdate:modelValue'], value);
233
241
  validateWithTrigger();
@@ -263,13 +271,15 @@ export default defineComponent({
263
271
  var {
264
272
  range,
265
273
  modelValue,
266
- onEnd
274
+ onEnd,
275
+ step,
276
+ min
267
277
  } = props;
268
278
  if (isDisabled.value || isReadonly.value) return;
269
279
  var rangeValue = [];
270
280
  thumbsProps[type].currentLeft = thumbsProps[type].percentValue * unitWidth.value;
271
281
  thumbsProps[type].active = false;
272
- var curValue = thumbsProps[type].percentValue;
282
+ var curValue = thumbsProps[type].percentValue * toNumber(step) + toNumber(min);
273
283
 
274
284
  if (range && isArray(modelValue)) {
275
285
  rangeValue = type === Thumbs.First ? [curValue, modelValue[1]] : [modelValue[0], curValue];
@@ -296,13 +306,8 @@ export default defineComponent({
296
306
  return false;
297
307
  }
298
308
 
299
- if (stepNumber < 1 || stepNumber > 100) {
300
- console.warn('[Varlet] Slider: "step" should be >= 0 and <= 100');
301
- return false;
302
- }
303
-
304
- if (parseInt("" + props.step, 10) !== stepNumber) {
305
- console.warn('[Varlet] Slider: "step" should be an Integer');
309
+ if (stepNumber < 0) {
310
+ console.warn('[Varlet] Slider: "step" should be > 0');
306
311
  return false;
307
312
  }
308
313
 
@@ -342,27 +347,26 @@ export default defineComponent({
342
347
  step = toNumber(props.step);
343
348
  }
344
349
 
350
+ var getPercent = value => {
351
+ var {
352
+ min,
353
+ max
354
+ } = props;
355
+ if (value < toNumber(min)) return 0;
356
+ if (value > toNumber(max)) return scope.value / step;
357
+ return (value - toNumber(min)) / step;
358
+ };
359
+
345
360
  if (props.range && isArray(modelValue)) {
346
- thumbsProps[Thumbs.First].percentValue = modelValue[0] / step;
361
+ thumbsProps[Thumbs.First].percentValue = getPercent(modelValue[0]);
347
362
  thumbsProps[Thumbs.First].currentLeft = thumbsProps[Thumbs.First].percentValue * unitWidth.value;
348
- thumbsProps[Thumbs.Second].percentValue = modelValue[1] / step;
363
+ thumbsProps[Thumbs.Second].percentValue = getPercent(modelValue[1]);
349
364
  thumbsProps[Thumbs.Second].currentLeft = thumbsProps[Thumbs.Second].percentValue * unitWidth.value;
350
365
  } else if (isNumber(modelValue)) {
351
- thumbsProps[Thumbs.First].currentLeft = modelValue / step * unitWidth.value;
366
+ thumbsProps[Thumbs.First].currentLeft = getPercent(modelValue) * unitWidth.value;
352
367
  }
353
368
  };
354
369
 
355
- watch([() => props.modelValue, () => props.step], _ref => {
356
- var [modelValue, step] = _ref;
357
- if (!stepValidator() || !valueValidator() || isScroll.value) return;
358
- setProps(modelValue, toNumber(step));
359
- });
360
- watch(maxWidth, () => setProps());
361
- onMounted(() => {
362
- if (!stepValidator() || !valueValidator()) return;
363
- maxWidth.value = sliderEl.value.offsetWidth;
364
- });
365
-
366
370
  var reset = () => {
367
371
  var resetValue = props.range ? [0, 0] : 0;
368
372
  call(props['onUpdate:modelValue'], resetValue);
@@ -375,6 +379,16 @@ export default defineComponent({
375
379
  resetValidation
376
380
  };
377
381
  call(bindForm, sliderProvider);
382
+ watch([() => props.modelValue, () => props.step], _ref => {
383
+ var [modelValue, step] = _ref;
384
+ if (!stepValidator() || !valueValidator() || isScroll.value) return;
385
+ setProps(modelValue, toNumber(step));
386
+ });
387
+ watch(maxWidth, () => setProps());
388
+ onMounted(() => {
389
+ if (!stepValidator() || !valueValidator()) return;
390
+ maxWidth.value = sliderEl.value.offsetWidth;
391
+ });
378
392
  return {
379
393
  n,
380
394
  classes,
@@ -387,7 +401,6 @@ export default defineComponent({
387
401
  thumbList,
388
402
  multiplySizeUnit,
389
403
  toNumber,
390
- getRippleSize,
391
404
  showLabel,
392
405
  start,
393
406
  move,
@@ -41,6 +41,14 @@ export var props = {
41
41
  trackHeight: {
42
42
  type: [String, Number]
43
43
  },
44
+ max: {
45
+ type: [String, Number],
46
+ default: 100
47
+ },
48
+ min: {
49
+ type: [String, Number],
50
+ default: 0
51
+ },
44
52
  thumbSize: {
45
53
  type: [String, Number]
46
54
  },
@@ -1 +1 @@
1
- :root { --slider-error-color: var(--color-danger); --slider-track-background: #bdbdbd; --slider-track-fill-background: var(--color-primary); --slider-thumb-block-background: var(--color-primary); --slider-thumb-ripple-background: var(--color-primary); --slider-thumb-label-background: var(--color-primary); --slider-thumb-label-font-size: var(--font-size-sm);}.var-slider { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 100%;}.var-slider__block { display: flex; align-items: center; position: relative; flex: 1; user-select: none; height: 36px; margin: 0 6px;}.var-slider--disabled { filter: opacity(0.6);}.var-slider__track { width: 100%; align-items: center; position: relative;}.var-slider__track-background { width: 100%; height: 2px; background: var(--slider-track-background);}.var-slider__track-fill { position: absolute; height: 100%; left: 0; top: 0; background-color: var(--slider-track-fill-background);}.var-slider__thumb { position: absolute;}.var-slider__thumb-block { position: absolute; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); background-color: var(--slider-thumb-block-background);}.var-slider__thumb-ripple { position: absolute; width: 0; z-index: -1; height: 0; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; opacity: 0.3; background: var(--slider-thumb-ripple-background); transition: 0.3s var(--cubic-bezier);}.var-slider__thumb-ripple--active { width: 36px; height: 36px;}.var-slider__thumb-label { height: 24px; width: 24px; background-color: var(--slider-thumb-label-background); display: flex; align-items: center; border: none; justify-content: center; color: #fff; border-radius: 50% 50% 0; bottom: 60%; user-select: none; position: absolute; left: 45%; transition: 0.3s var(--cubic-bezier); font-size: var(--slider-thumb-label-font-size); overflow: hidden; transform: translateY(0) translateY(0) translateX(-50%) rotate(45deg) scale(0);}.var-slider__thumb-label span { transform: rotate(-45deg);}.var-slider__thumb-label--active { transform: translateY(-50%) translateX(-50%) rotate(45deg) scale(1);}.var-slider--error .var-slider__track-background { background-color: var(--slider-error-color) !important; filter: opacity(0.5);}.var-slider--error .var-slider__track-fill { background-color: var(--slider-error-color) !important;}.var-slider--error .var-slider__thumb-block { background-color: var(--slider-error-color) !important;}.var-slider--error .var-slider__thumb-ripple { background-color: var(--slider-error-color) !important;}.var-slider--error .var-slider__thumb-label { background-color: var(--slider-error-color) !important;}.var-slider__form[var-slider-cover] { margin: 0;}
1
+ :root { --slider-error-color: var(--color-danger); --slider-track-background: #bdbdbd; --slider-track-fill-background: var(--color-primary); --slider-thumb-block-background: var(--color-primary); --slider-thumb-ripple-background: var(--color-primary); --slider-thumb-label-background: var(--color-primary); --slider-thumb-label-font-size: var(--font-size-sm);}.var-slider { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 100%;}.var-slider__block { display: flex; align-items: center; position: relative; flex: 1; user-select: none; height: 36px; margin: 0 6px;}.var-slider--disabled { filter: opacity(0.6);}.var-slider__track { width: 100%; align-items: center; position: relative;}.var-slider__track-background { width: 100%; height: 2px; background: var(--slider-track-background);}.var-slider__track-fill { position: absolute; height: 100%; left: 0; top: 0; background-color: var(--slider-track-fill-background);}.var-slider__thumb { position: absolute;}.var-slider__thumb-block { position: absolute; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); background-color: var(--slider-thumb-block-background);}.var-slider__thumb-ripple { position: absolute; width: 0; z-index: -1; height: 0; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; opacity: 0.3; background: var(--slider-thumb-ripple-background); transition: 0.3s var(--cubic-bezier);}.var-slider__thumb-ripple--active { width: 36px; height: 36px;}.var-slider__thumb-label { height: 24px; width: 24px; background-color: var(--slider-thumb-label-background); display: flex; align-items: center; border: none; justify-content: center; color: #fff; border-radius: 50% 50% 0; bottom: 60%; user-select: none; position: absolute; left: 45%; transition: 0.3s var(--cubic-bezier); font-size: var(--slider-thumb-label-font-size); overflow: hidden; transform: translateY(0) translateY(0) translateX(-50%) rotate(45deg) scale(0);}.var-slider__thumb-label span { transform: rotate(-45deg);}.var-slider__thumb-label--active { transform: translateY(-20%) translateY(-8px) translateX(-50%) rotate(45deg) scale(1);}.var-slider--error .var-slider__track-background { background-color: var(--slider-error-color) !important; filter: opacity(0.5);}.var-slider--error .var-slider__track-fill { background-color: var(--slider-error-color) !important;}.var-slider--error .var-slider__thumb-block { background-color: var(--slider-error-color) !important;}.var-slider--error .var-slider__thumb-ripple { background-color: var(--slider-error-color) !important;}.var-slider--error .var-slider__thumb-label { background-color: var(--slider-error-color) !important;}.var-slider__form[var-slider-cover] { margin: 0;}