@varlet/ui 3.2.3 → 3.2.5
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 +5 -3
- package/README.zh-CN.md +5 -3
- package/es/action-sheet/style/index.mjs +1 -1
- package/es/avatar-group/AvatarGroup.mjs +1 -2
- package/es/breadcrumb/Breadcrumb.mjs +2 -1
- package/es/breadcrumbs/Breadcrumbs.mjs +3 -1
- package/es/collapse/Collapse.mjs +2 -0
- package/es/collapse-item/CollapseItem.mjs +53 -53
- package/es/collapse-item/collapseItem.css +1 -1
- package/es/date-picker/src/year-picker-panel.mjs +10 -18
- package/es/divider/Divider.mjs +2 -1
- package/es/index.bundle.mjs +1 -1
- package/es/index.mjs +1 -1
- package/es/locale/index.mjs +0 -1
- package/es/menu/usePopover.mjs +2 -3
- package/es/popup/Popup.mjs +3 -1
- package/es/progress/Progress.mjs +187 -185
- package/es/slider/Slider.mjs +19 -23
- package/es/style.css +1 -1
- package/es/swipe/Swipe.mjs +1 -0
- package/es/swipe-item/SwipeItem.mjs +18 -18
- package/es/switch/Switch.mjs +77 -80
- package/es/time-picker/clock.mjs +3 -5
- package/es/tooltip/Tooltip.mjs +2 -1
- package/es/varlet.esm.js +4176 -4177
- package/highlight/web-types.en-US.json +1 -1
- package/highlight/web-types.zh-CN.json +1 -1
- package/lib/style.css +1 -1
- package/lib/varlet.cjs.js +411 -421
- package/package.json +7 -7
- package/umd/varlet.js +6 -6
package/es/progress/Progress.mjs
CHANGED
|
@@ -1,195 +1,195 @@
|
|
|
1
1
|
import { defineComponent, computed } from "vue";
|
|
2
2
|
import { props } from "./props.mjs";
|
|
3
|
-
import { isPlainObject, toNumber } from "@varlet/shared";
|
|
3
|
+
import { isPlainObject, toNumber, clamp } from "@varlet/shared";
|
|
4
4
|
import { useId } from "@varlet/use";
|
|
5
5
|
import { toSizeUnit, toPxNum } from "../utils/elements.mjs";
|
|
6
6
|
import { createNamespace } from "../utils/components.mjs";
|
|
7
|
-
const
|
|
7
|
+
const MAX = 100;
|
|
8
|
+
const MIN = 0;
|
|
8
9
|
const RADIUS = 20;
|
|
9
10
|
const CIRCUMFERENCE = 2 * Math.PI * RADIUS;
|
|
10
11
|
const { name, n, classes } = createNamespace("progress");
|
|
11
12
|
import { normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, renderSlot as _renderSlot, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, renderList as _renderList, Fragment as _Fragment, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
|
|
12
13
|
const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
|
|
13
|
-
const _hoisted_1 = ["
|
|
14
|
-
const _hoisted_2 =
|
|
15
|
-
const _hoisted_3 =
|
|
16
|
-
const _hoisted_4 = ["
|
|
17
|
-
const _hoisted_5 = ["
|
|
18
|
-
const _hoisted_6 = ["d", "stroke-width", "stroke-dasharray"
|
|
14
|
+
const _hoisted_1 = ["aria-valuenow"];
|
|
15
|
+
const _hoisted_2 = ["viewBox"];
|
|
16
|
+
const _hoisted_3 = { key: 0 };
|
|
17
|
+
const _hoisted_4 = ["id"];
|
|
18
|
+
const _hoisted_5 = ["offset", "stop-color"];
|
|
19
|
+
const _hoisted_6 = ["d", "stroke-width", "stroke-dasharray"];
|
|
20
|
+
const _hoisted_7 = ["d", "stroke-width", "stroke-dasharray", "stroke-dashoffset"];
|
|
19
21
|
function __render__(_ctx, _cache) {
|
|
20
|
-
return _openBlock(), _createElementBlock(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
6
|
|
65
|
-
/* CLASS, STYLE */
|
|
66
|
-
)
|
|
67
|
-
],
|
|
68
|
-
2
|
|
69
|
-
/* CLASS */
|
|
70
|
-
)) : (_openBlock(), _createElementBlock(
|
|
71
|
-
"div",
|
|
72
|
-
{
|
|
73
|
-
key: 1,
|
|
74
|
-
class: _normalizeClass(_ctx.classes(_ctx.n("linear-certain"), _ctx.n(`linear--${_ctx.type}`))),
|
|
75
|
-
style: _normalizeStyle({ background: _ctx.progressColor, width: _ctx.linearProps.width })
|
|
76
|
-
},
|
|
77
|
-
null,
|
|
78
|
-
6
|
|
79
|
-
/* CLASS, STYLE */
|
|
80
|
-
))
|
|
81
|
-
],
|
|
82
|
-
6
|
|
83
|
-
/* CLASS, STYLE */
|
|
84
|
-
),
|
|
85
|
-
_ctx.label ? (_openBlock(), _createElementBlock(
|
|
86
|
-
"div",
|
|
87
|
-
{
|
|
88
|
-
key: 0,
|
|
89
|
-
class: _normalizeClass(_ctx.classes(_ctx.n("linear-label"), [_ctx.labelClass, _ctx.labelClass]))
|
|
90
|
-
},
|
|
91
|
-
[
|
|
92
|
-
_renderSlot(_ctx.$slots, "default", {}, () => [
|
|
93
|
-
_createTextVNode(
|
|
94
|
-
_toDisplayString(_ctx.linearProps.roundValue),
|
|
95
|
-
1
|
|
96
|
-
/* TEXT */
|
|
97
|
-
)
|
|
98
|
-
])
|
|
99
|
-
],
|
|
100
|
-
2
|
|
101
|
-
/* CLASS */
|
|
102
|
-
)) : _createCommentVNode("v-if", true)
|
|
103
|
-
],
|
|
104
|
-
2
|
|
105
|
-
/* CLASS */
|
|
106
|
-
)) : _createCommentVNode("v-if", true),
|
|
107
|
-
_ctx.mode === "circle" ? (_openBlock(), _createElementBlock(
|
|
108
|
-
"div",
|
|
109
|
-
{
|
|
110
|
-
key: 1,
|
|
111
|
-
class: _normalizeClass(_ctx.classes(_ctx.n("circle"), [_ctx.indeterminate, _ctx.n("circle-indeterminate")])),
|
|
112
|
-
style: _normalizeStyle({ width: _ctx.toSizeUnit(_ctx.size), height: _ctx.toSizeUnit(_ctx.size) })
|
|
113
|
-
},
|
|
114
|
-
[
|
|
115
|
-
(_openBlock(), _createElementBlock("svg", {
|
|
116
|
-
class: _normalizeClass(_ctx.n("circle-svg")),
|
|
117
|
-
viewBox: _ctx.circleProps.viewBox
|
|
118
|
-
}, [
|
|
119
|
-
_ctx.isPlainObject(_ctx.color) ? (_openBlock(), _createElementBlock("defs", _hoisted_2, [
|
|
120
|
-
_createElementVNode("linearGradient", {
|
|
121
|
-
id: _ctx.id,
|
|
122
|
-
x1: "100%",
|
|
123
|
-
y1: "0%",
|
|
124
|
-
x2: "0%",
|
|
125
|
-
y2: "0%"
|
|
126
|
-
}, [
|
|
127
|
-
(_openBlock(true), _createElementBlock(
|
|
128
|
-
_Fragment,
|
|
22
|
+
return _openBlock(), _createElementBlock("div", {
|
|
23
|
+
class: _normalizeClass(_ctx.n()),
|
|
24
|
+
role: "progressbar",
|
|
25
|
+
"aria-valuemin": "0",
|
|
26
|
+
"aria-valuemax": "100",
|
|
27
|
+
"aria-valuenow": _ctx.indeterminate ? void 0 : _ctx.mode === "linear" ? _ctx.linearProps.value : _ctx.circleProps.value
|
|
28
|
+
}, [
|
|
29
|
+
_ctx.mode === "linear" ? (_openBlock(), _createElementBlock(
|
|
30
|
+
"div",
|
|
31
|
+
{
|
|
32
|
+
key: 0,
|
|
33
|
+
class: _normalizeClass(_ctx.n("linear"))
|
|
34
|
+
},
|
|
35
|
+
[
|
|
36
|
+
_createElementVNode(
|
|
37
|
+
"div",
|
|
38
|
+
{
|
|
39
|
+
class: _normalizeClass(_ctx.classes(_ctx.n("linear-block"), [_ctx.track, _ctx.n("linear-background")])),
|
|
40
|
+
style: _normalizeStyle({ height: _ctx.toSizeUnit(_ctx.lineWidth), background: _ctx.trackColor })
|
|
41
|
+
},
|
|
42
|
+
[
|
|
43
|
+
_ctx.indeterminate ? (_openBlock(), _createElementBlock(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
key: 0,
|
|
47
|
+
class: _normalizeClass(_ctx.n("linear-indeterminate"))
|
|
48
|
+
},
|
|
49
|
+
[
|
|
50
|
+
_createElementVNode(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
class: _normalizeClass(_ctx.classes(_ctx.n(`linear--${_ctx.type}`))),
|
|
54
|
+
style: _normalizeStyle({ background: _ctx.progressColor })
|
|
55
|
+
},
|
|
56
|
+
null,
|
|
57
|
+
6
|
|
58
|
+
/* CLASS, STYLE */
|
|
59
|
+
),
|
|
60
|
+
_createElementVNode(
|
|
61
|
+
"div",
|
|
62
|
+
{
|
|
63
|
+
class: _normalizeClass(_ctx.classes(_ctx.n(`linear--${_ctx.type}`))),
|
|
64
|
+
style: _normalizeStyle({ background: _ctx.progressColor })
|
|
65
|
+
},
|
|
129
66
|
null,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
key: idx,
|
|
133
|
-
offset: progress,
|
|
134
|
-
"stop-color": _ctx.color[progress]
|
|
135
|
-
}, null, 8, _hoisted_4);
|
|
136
|
-
}),
|
|
137
|
-
128
|
|
138
|
-
/* KEYED_FRAGMENT */
|
|
139
|
-
))
|
|
140
|
-
], 8, _hoisted_3)
|
|
141
|
-
])) : _createCommentVNode("v-if", true),
|
|
142
|
-
_ctx.track ? (_openBlock(), _createElementBlock("path", {
|
|
143
|
-
key: 1,
|
|
144
|
-
class: _normalizeClass(_ctx.n("circle-background")),
|
|
145
|
-
d: _ctx.circleProps.path,
|
|
146
|
-
fill: "transparent",
|
|
147
|
-
"stroke-width": _ctx.circleProps.strokeWidth,
|
|
148
|
-
"stroke-dasharray": _ctx.CIRCUMFERENCE,
|
|
149
|
-
style: _normalizeStyle({
|
|
150
|
-
stroke: _ctx.trackColor
|
|
151
|
-
})
|
|
152
|
-
}, null, 14, _hoisted_5)) : _createCommentVNode("v-if", true),
|
|
153
|
-
_createElementVNode("path", {
|
|
154
|
-
class: _normalizeClass(_ctx.classes(_ctx.n("circle-certain"), _ctx.n(`circle--${_ctx.type}`), [_ctx.indeterminate, _ctx.n("circle-overlay")])),
|
|
155
|
-
d: _ctx.circleProps.path,
|
|
156
|
-
fill: "transparent",
|
|
157
|
-
"stroke-width": _ctx.circleProps.strokeWidth,
|
|
158
|
-
"stroke-dasharray": _ctx.CIRCUMFERENCE,
|
|
159
|
-
"stroke-dashoffset": _ctx.circleProps.strokeOffset,
|
|
160
|
-
style: _normalizeStyle({
|
|
161
|
-
stroke: _ctx.progressColor,
|
|
162
|
-
transform: `rotateZ(${_ctx.rotate}deg)`,
|
|
163
|
-
transformOrigin: "50% 50%"
|
|
164
|
-
})
|
|
165
|
-
}, null, 14, _hoisted_6)
|
|
166
|
-
], 10, _hoisted_1)),
|
|
167
|
-
_ctx.label ? (_openBlock(), _createElementBlock(
|
|
168
|
-
"div",
|
|
169
|
-
{
|
|
170
|
-
key: 0,
|
|
171
|
-
class: _normalizeClass(_ctx.classes(_ctx.n("circle-label"), [_ctx.labelClass, _ctx.labelClass]))
|
|
172
|
-
},
|
|
173
|
-
[
|
|
174
|
-
_renderSlot(_ctx.$slots, "default", {}, () => [
|
|
175
|
-
_createTextVNode(
|
|
176
|
-
_toDisplayString(_ctx.circleProps.roundValue),
|
|
177
|
-
1
|
|
178
|
-
/* TEXT */
|
|
67
|
+
6
|
|
68
|
+
/* CLASS, STYLE */
|
|
179
69
|
)
|
|
180
|
-
]
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
70
|
+
],
|
|
71
|
+
2
|
|
72
|
+
/* CLASS */
|
|
73
|
+
)) : (_openBlock(), _createElementBlock(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
key: 1,
|
|
77
|
+
class: _normalizeClass(_ctx.classes(_ctx.n("linear-certain"), _ctx.n(`linear--${_ctx.type}`))),
|
|
78
|
+
style: _normalizeStyle({ background: _ctx.progressColor, width: _ctx.linearProps.width })
|
|
79
|
+
},
|
|
80
|
+
null,
|
|
81
|
+
6
|
|
82
|
+
/* CLASS, STYLE */
|
|
83
|
+
))
|
|
84
|
+
],
|
|
85
|
+
6
|
|
86
|
+
/* CLASS, STYLE */
|
|
87
|
+
),
|
|
88
|
+
_ctx.label ? (_openBlock(), _createElementBlock(
|
|
89
|
+
"div",
|
|
90
|
+
{
|
|
91
|
+
key: 0,
|
|
92
|
+
class: _normalizeClass(_ctx.classes(_ctx.n("linear-label"), [_ctx.labelClass, _ctx.labelClass]))
|
|
93
|
+
},
|
|
94
|
+
[
|
|
95
|
+
_renderSlot(_ctx.$slots, "default", {}, () => [
|
|
96
|
+
_createTextVNode(
|
|
97
|
+
_toDisplayString(_ctx.linearProps.roundValue),
|
|
98
|
+
1
|
|
99
|
+
/* TEXT */
|
|
100
|
+
)
|
|
101
|
+
])
|
|
102
|
+
],
|
|
103
|
+
2
|
|
104
|
+
/* CLASS */
|
|
105
|
+
)) : _createCommentVNode("v-if", true)
|
|
106
|
+
],
|
|
107
|
+
2
|
|
108
|
+
/* CLASS */
|
|
109
|
+
)) : _createCommentVNode("v-if", true),
|
|
110
|
+
_ctx.mode === "circle" ? (_openBlock(), _createElementBlock(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
key: 1,
|
|
114
|
+
class: _normalizeClass(_ctx.classes(_ctx.n("circle"), [_ctx.indeterminate, _ctx.n("circle-indeterminate")])),
|
|
115
|
+
style: _normalizeStyle({ width: _ctx.toSizeUnit(_ctx.size), height: _ctx.toSizeUnit(_ctx.size) })
|
|
116
|
+
},
|
|
117
|
+
[
|
|
118
|
+
(_openBlock(), _createElementBlock("svg", {
|
|
119
|
+
class: _normalizeClass(_ctx.n("circle-svg")),
|
|
120
|
+
viewBox: _ctx.circleProps.viewBox
|
|
121
|
+
}, [
|
|
122
|
+
_ctx.isPlainObject(_ctx.color) ? (_openBlock(), _createElementBlock("defs", _hoisted_3, [
|
|
123
|
+
_createElementVNode("linearGradient", {
|
|
124
|
+
id: _ctx.id,
|
|
125
|
+
x1: "100%",
|
|
126
|
+
y1: "0%",
|
|
127
|
+
x2: "0%",
|
|
128
|
+
y2: "0%"
|
|
129
|
+
}, [
|
|
130
|
+
(_openBlock(true), _createElementBlock(
|
|
131
|
+
_Fragment,
|
|
132
|
+
null,
|
|
133
|
+
_renderList(_ctx.linearGradientProgress, (progress, idx) => {
|
|
134
|
+
return _openBlock(), _createElementBlock("stop", {
|
|
135
|
+
key: idx,
|
|
136
|
+
offset: progress,
|
|
137
|
+
"stop-color": _ctx.color[progress]
|
|
138
|
+
}, null, 8, _hoisted_5);
|
|
139
|
+
}),
|
|
140
|
+
128
|
|
141
|
+
/* KEYED_FRAGMENT */
|
|
142
|
+
))
|
|
143
|
+
], 8, _hoisted_4)
|
|
144
|
+
])) : _createCommentVNode("v-if", true),
|
|
145
|
+
_ctx.track ? (_openBlock(), _createElementBlock("path", {
|
|
146
|
+
key: 1,
|
|
147
|
+
class: _normalizeClass(_ctx.n("circle-background")),
|
|
148
|
+
d: _ctx.circleProps.path,
|
|
149
|
+
fill: "transparent",
|
|
150
|
+
"stroke-width": _ctx.circleProps.strokeWidth,
|
|
151
|
+
"stroke-dasharray": _ctx.CIRCUMFERENCE,
|
|
152
|
+
style: _normalizeStyle({
|
|
153
|
+
stroke: _ctx.trackColor
|
|
154
|
+
})
|
|
155
|
+
}, null, 14, _hoisted_6)) : _createCommentVNode("v-if", true),
|
|
156
|
+
_createElementVNode("path", {
|
|
157
|
+
class: _normalizeClass(_ctx.classes(_ctx.n("circle-certain"), _ctx.n(`circle--${_ctx.type}`), [_ctx.indeterminate, _ctx.n("circle-overlay")])),
|
|
158
|
+
d: _ctx.circleProps.path,
|
|
159
|
+
fill: "transparent",
|
|
160
|
+
"stroke-width": _ctx.circleProps.strokeWidth,
|
|
161
|
+
"stroke-dasharray": _ctx.CIRCUMFERENCE,
|
|
162
|
+
"stroke-dashoffset": _ctx.circleProps.strokeOffset,
|
|
163
|
+
style: _normalizeStyle({
|
|
164
|
+
stroke: _ctx.progressColor,
|
|
165
|
+
transform: `rotateZ(${_ctx.rotate}deg)`,
|
|
166
|
+
transformOrigin: "50% 50%"
|
|
167
|
+
})
|
|
168
|
+
}, null, 14, _hoisted_7)
|
|
169
|
+
], 10, _hoisted_2)),
|
|
170
|
+
_ctx.label ? (_openBlock(), _createElementBlock(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
key: 0,
|
|
174
|
+
class: _normalizeClass(_ctx.classes(_ctx.n("circle-label"), _ctx.labelClass))
|
|
175
|
+
},
|
|
176
|
+
[
|
|
177
|
+
_renderSlot(_ctx.$slots, "default", {}, () => [
|
|
178
|
+
_createTextVNode(
|
|
179
|
+
_toDisplayString(_ctx.circleProps.roundValue),
|
|
180
|
+
1
|
|
181
|
+
/* TEXT */
|
|
182
|
+
)
|
|
183
|
+
])
|
|
184
|
+
],
|
|
185
|
+
2
|
|
186
|
+
/* CLASS */
|
|
187
|
+
)) : _createCommentVNode("v-if", true)
|
|
188
|
+
],
|
|
189
|
+
6
|
|
190
|
+
/* CLASS, STYLE */
|
|
191
|
+
)) : _createCommentVNode("v-if", true)
|
|
192
|
+
], 10, _hoisted_1);
|
|
193
193
|
}
|
|
194
194
|
const __sfc__ = defineComponent({
|
|
195
195
|
name,
|
|
@@ -198,19 +198,20 @@ const __sfc__ = defineComponent({
|
|
|
198
198
|
const id = useId();
|
|
199
199
|
const linearProps = computed(() => {
|
|
200
200
|
const value = toNumber(props2.value);
|
|
201
|
-
const width = value
|
|
202
|
-
const roundValue =
|
|
201
|
+
const width = clamp(value, MIN, MAX);
|
|
202
|
+
const roundValue = clamp(Math.round(value), MIN, MAX);
|
|
203
203
|
return {
|
|
204
204
|
width: `${width}%`,
|
|
205
|
-
roundValue: `${roundValue}
|
|
205
|
+
roundValue: `${roundValue}%`,
|
|
206
|
+
value: width
|
|
206
207
|
};
|
|
207
208
|
});
|
|
208
209
|
const circleProps = computed(() => {
|
|
209
210
|
const { size, lineWidth, value } = props2;
|
|
210
211
|
const diameter = RADIUS / (1 - toPxNum(lineWidth) / toPxNum(size)) * 2;
|
|
211
212
|
const viewBox = `0 0 ${diameter} ${diameter}`;
|
|
212
|
-
const roundValue =
|
|
213
|
-
const strokeOffset = `${(
|
|
213
|
+
const roundValue = clamp(Math.round(toNumber(value)), MIN, MAX);
|
|
214
|
+
const strokeOffset = `${(MAX - roundValue) / MAX * CIRCUMFERENCE}`;
|
|
214
215
|
const strokeWidth = toPxNum(lineWidth) / toPxNum(size) * diameter;
|
|
215
216
|
const beginPositionX = 0;
|
|
216
217
|
const beginPositionY = -RADIUS;
|
|
@@ -223,7 +224,8 @@ const __sfc__ = defineComponent({
|
|
|
223
224
|
viewBox,
|
|
224
225
|
strokeOffset,
|
|
225
226
|
roundValue: `${roundValue}%`,
|
|
226
|
-
path
|
|
227
|
+
path,
|
|
228
|
+
value: clamp(toNumber(value), MIN, MAX)
|
|
227
229
|
};
|
|
228
230
|
});
|
|
229
231
|
const progressColor = computed(() => {
|
package/es/slider/Slider.mjs
CHANGED
|
@@ -6,13 +6,13 @@ import { useValidation, createNamespace } from "../utils/components.mjs";
|
|
|
6
6
|
import { useForm } from "../form/provide.mjs";
|
|
7
7
|
import { getLeft, toSizeUnit } from "../utils/elements.mjs";
|
|
8
8
|
import { warn } from "../utils/logger.mjs";
|
|
9
|
-
import { isArray, isNumber, toNumber, getRect, preventDefault, call, hasOwn } from "@varlet/shared";
|
|
9
|
+
import { isArray, isNumber, toNumber, getRect, preventDefault, call, hasOwn, clamp } from "@varlet/shared";
|
|
10
10
|
import { props, Thumbs } from "./props.mjs";
|
|
11
11
|
import { onSmartMounted, onWindowResize, useEventListener } from "@varlet/use";
|
|
12
12
|
const { name, n, classes } = createNamespace("slider");
|
|
13
13
|
import { normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode, renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, renderSlot as _renderSlot, resolveDirective as _resolveDirective, withDirectives as _withDirectives, resolveComponent as _resolveComponent, createVNode as _createVNode, toDisplayString as _toDisplayString, withModifiers as _withModifiers, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
|
|
14
14
|
const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
|
|
15
|
-
const _hoisted_1 = ["tabindex", "onTouchstart", "onFocusin", "onFocusout"];
|
|
15
|
+
const _hoisted_1 = ["tabindex", "aria-valuemin", "aria-valuemax", "aria-valuenow", "aria-disabled", "aria-valuetext", "onTouchstart", "onFocusin", "onFocusout"];
|
|
16
16
|
function __render__(_ctx, _cache) {
|
|
17
17
|
const _component_var_hover_overlay = _resolveComponent("var-hover-overlay");
|
|
18
18
|
const _component_var_form_details = _resolveComponent("var-form-details");
|
|
@@ -28,7 +28,7 @@ function __render__(_ctx, _cache) {
|
|
|
28
28
|
{
|
|
29
29
|
class: _normalizeClass(_ctx.classes(_ctx.n(`${_ctx.direction}-block`), [_ctx.isDisabled, _ctx.n("--disabled")], [_ctx.errorMessage, _ctx.n(`${_ctx.direction}--error`)])),
|
|
30
30
|
ref: "sliderEl",
|
|
31
|
-
onClick: _cache[0] || (_cache[0] = (...args) => _ctx.
|
|
31
|
+
onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args))
|
|
32
32
|
},
|
|
33
33
|
[
|
|
34
34
|
_createElementVNode(
|
|
@@ -74,6 +74,12 @@ function __render__(_ctx, _cache) {
|
|
|
74
74
|
key: item.enumValue,
|
|
75
75
|
style: _normalizeStyle(_ctx.thumbStyle(item)),
|
|
76
76
|
tabindex: _ctx.isDisabled ? void 0 : "0",
|
|
77
|
+
role: "slider",
|
|
78
|
+
"aria-valuemin": _ctx.min,
|
|
79
|
+
"aria-valuemax": _ctx.max,
|
|
80
|
+
"aria-valuenow": item.value,
|
|
81
|
+
"aria-disabled": _ctx.isDisabled,
|
|
82
|
+
"aria-valuetext": `${item.text}`,
|
|
77
83
|
onTouchstart: _withModifiers(($event) => _ctx.start($event, item.enumValue), ["stop"]),
|
|
78
84
|
onFocusin: ($event) => _ctx.handleFocus(item),
|
|
79
85
|
onFocusout: ($event) => _ctx.handleBlur(item)
|
|
@@ -330,13 +336,7 @@ const __sfc__ = defineComponent({
|
|
|
330
336
|
if (!isNumber(value)) {
|
|
331
337
|
return 0;
|
|
332
338
|
}
|
|
333
|
-
|
|
334
|
-
if (num < Number(props2.min)) {
|
|
335
|
-
num = Number(props2.min);
|
|
336
|
-
}
|
|
337
|
-
if (num > Number(props2.max)) {
|
|
338
|
-
num = Number(props2.max);
|
|
339
|
-
}
|
|
339
|
+
const num = clamp(value, toNumber(props2.min), toNumber(props2.max));
|
|
340
340
|
const isInteger = parseInt(`${num}`, 10) === num;
|
|
341
341
|
return isInteger ? num : toNumber(num.toPrecision(5));
|
|
342
342
|
}
|
|
@@ -435,11 +435,13 @@ const __sfc__ = defineComponent({
|
|
|
435
435
|
call(onEnd, range ? rangeValue : curValue);
|
|
436
436
|
isScroll.value = false;
|
|
437
437
|
}
|
|
438
|
-
function
|
|
439
|
-
if (isDisabled.value || isReadonly.value)
|
|
438
|
+
function handleClick(event) {
|
|
439
|
+
if (isDisabled.value || isReadonly.value) {
|
|
440
440
|
return;
|
|
441
|
-
|
|
441
|
+
}
|
|
442
|
+
if (event.target.closest(`.${n("thumb")}`)) {
|
|
442
443
|
return;
|
|
444
|
+
}
|
|
443
445
|
const offset = getOffset(event);
|
|
444
446
|
const type = getType(offset);
|
|
445
447
|
activeThumb = type;
|
|
@@ -447,13 +449,8 @@ const __sfc__ = defineComponent({
|
|
|
447
449
|
end();
|
|
448
450
|
}
|
|
449
451
|
function stepValidator() {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
warn("Slider", 'type of prop "step" should be Number');
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
if (stepNumber < 0) {
|
|
456
|
-
warn("Slider", '"step" should be > 0');
|
|
452
|
+
if (toNumber(props2.step) <= 0) {
|
|
453
|
+
warn("[Varlet] Slider", '"step" should be > 0');
|
|
457
454
|
return false;
|
|
458
455
|
}
|
|
459
456
|
return true;
|
|
@@ -500,7 +497,7 @@ const __sfc__ = defineComponent({
|
|
|
500
497
|
resetValidation();
|
|
501
498
|
}
|
|
502
499
|
function moveFocusingThumb(offset, value) {
|
|
503
|
-
const stepValue =
|
|
500
|
+
const stepValue = toNumber(props2.step);
|
|
504
501
|
if (isArray(value)) {
|
|
505
502
|
const updatedFirstValue = value[0] + (focusingFirst.value ? offset * stepValue : 0);
|
|
506
503
|
const updatedSecondValue = value[1] + (focusingSecond.value ? offset * stepValue : 0);
|
|
@@ -540,7 +537,6 @@ const __sfc__ = defineComponent({
|
|
|
540
537
|
item.handleFocusing(false);
|
|
541
538
|
}
|
|
542
539
|
return {
|
|
543
|
-
Thumbs,
|
|
544
540
|
sliderEl,
|
|
545
541
|
getFillStyle,
|
|
546
542
|
isDisabled,
|
|
@@ -560,7 +556,7 @@ const __sfc__ = defineComponent({
|
|
|
560
556
|
start,
|
|
561
557
|
move,
|
|
562
558
|
end,
|
|
563
|
-
|
|
559
|
+
handleClick
|
|
564
560
|
};
|
|
565
561
|
}
|
|
566
562
|
});
|