@bagelink/vue 0.0.1041 → 0.0.1043
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/dist/components/form/inputs/RangeInput.vue.d.ts +1 -0
- package/dist/components/form/inputs/RangeInput.vue.d.ts.map +1 -1
- package/dist/index.cjs +31 -43
- package/dist/index.mjs +31 -43
- package/dist/style.css +257 -257
- package/package.json +1 -1
- package/src/components/form/inputs/RangeInput.vue +23 -32
- package/src/styles/theme.css +258 -258
|
@@ -12,6 +12,7 @@ export interface RangeInputProps {
|
|
|
12
12
|
id?: string
|
|
13
13
|
rtl?: boolean
|
|
14
14
|
multiRange?: boolean
|
|
15
|
+
formatValue?: (value: number) => string
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const props = defineProps<RangeInputProps>()
|
|
@@ -25,51 +26,38 @@ const {
|
|
|
25
26
|
disabled,
|
|
26
27
|
id,
|
|
27
28
|
rtl,
|
|
28
|
-
multiRange
|
|
29
|
+
multiRange = false,
|
|
30
|
+
formatValue = (value: number) => value.toString()
|
|
29
31
|
} = props
|
|
30
32
|
|
|
31
|
-
let from = $ref<number>(min)
|
|
32
|
-
let to = $ref<number>(max)
|
|
33
|
-
|
|
34
|
-
let isExternalUpdate = $ref(true)
|
|
33
|
+
let from = $ref<number>(Array.isArray(props.modelValue) ? props.modelValue[0] : (props.modelValue ?? min))
|
|
34
|
+
let to = $ref<number>(Array.isArray(props.modelValue) ? props.modelValue[1] : max)
|
|
35
35
|
|
|
36
36
|
const validFrom = $computed(() => Math.min(Math.max(from, min), multiRange ? to : max))
|
|
37
37
|
const validTo = $computed(() => Math.max(Math.min(to, max), from))
|
|
38
38
|
|
|
39
|
+
const fromPercentage = $computed(() => ((validFrom - min) / (max - min)) * 100)
|
|
40
|
+
const toPercentage = $computed(() => ((validTo - min) / (max - min)) * 100)
|
|
41
|
+
|
|
39
42
|
watch(() => props.modelValue, (newVal) => {
|
|
40
|
-
|
|
41
|
-
if (multiRange && Array.isArray(newVal)) {
|
|
43
|
+
if (Array.isArray(newVal) && multiRange) {
|
|
42
44
|
from = newVal[0]
|
|
43
45
|
to = newVal[1]
|
|
44
|
-
} else if (!
|
|
46
|
+
} else if (!Array.isArray(newVal)) {
|
|
45
47
|
from = newVal ?? min
|
|
46
48
|
to = max
|
|
47
49
|
}
|
|
48
50
|
}, { immediate: true })
|
|
49
51
|
|
|
50
|
-
watch([() => validFrom, () => validTo], () => {
|
|
51
|
-
if (!isExternalUpdate) {
|
|
52
|
-
if (multiRange) {
|
|
53
|
-
emit('update:modelValue', [validFrom, validTo])
|
|
54
|
-
} else {
|
|
55
|
-
emit('update:modelValue', validFrom)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
isExternalUpdate = false
|
|
59
|
-
})
|
|
60
|
-
|
|
61
52
|
function handleInput(value: number, isFromInput: boolean) {
|
|
62
|
-
isExternalUpdate = false
|
|
63
53
|
if (isFromInput) {
|
|
64
54
|
from = value
|
|
65
55
|
} else {
|
|
66
56
|
to = value
|
|
67
57
|
}
|
|
58
|
+
emit('update:modelValue', multiRange ? [validFrom, validTo] : validFrom)
|
|
68
59
|
}
|
|
69
60
|
|
|
70
|
-
const fromPercentage = $computed(() => ((validFrom - min) / (max - min)) * 100)
|
|
71
|
-
const toPercentage = $computed(() => ((validTo - min) / (max - min)) * 100)
|
|
72
|
-
|
|
73
61
|
const rangeStyle = $computed(() => {
|
|
74
62
|
if (multiRange) {
|
|
75
63
|
return {
|
|
@@ -81,6 +69,9 @@ const rangeStyle = $computed(() => {
|
|
|
81
69
|
? { left: `${100 - fromPercentage}%`, width: `${fromPercentage}%` }
|
|
82
70
|
: { left: '0', width: `${fromPercentage}%` }
|
|
83
71
|
})
|
|
72
|
+
|
|
73
|
+
const displayFrom = $computed(() => formatValue(validFrom))
|
|
74
|
+
const displayTo = $computed(() => formatValue(validTo))
|
|
84
75
|
</script>
|
|
85
76
|
|
|
86
77
|
<template>
|
|
@@ -89,11 +80,11 @@ const rangeStyle = $computed(() => {
|
|
|
89
80
|
<div class="range-slider relative w-100" :dir="rtl ? 'rtl' : 'ltr'">
|
|
90
81
|
<input
|
|
91
82
|
:id="id"
|
|
92
|
-
|
|
83
|
+
:value="validFrom"
|
|
93
84
|
class="from"
|
|
94
85
|
type="range"
|
|
95
86
|
:min="min"
|
|
96
|
-
:max="multiRange ?
|
|
87
|
+
:max="multiRange ? validTo : max"
|
|
97
88
|
:step="step"
|
|
98
89
|
:required="required"
|
|
99
90
|
:disabled="disabled"
|
|
@@ -102,10 +93,10 @@ const rangeStyle = $computed(() => {
|
|
|
102
93
|
>
|
|
103
94
|
<input
|
|
104
95
|
v-if="multiRange"
|
|
105
|
-
|
|
96
|
+
:value="validTo"
|
|
106
97
|
class="to"
|
|
107
98
|
type="range"
|
|
108
|
-
:min="
|
|
99
|
+
:min="validFrom"
|
|
109
100
|
:max="max"
|
|
110
101
|
:step="step"
|
|
111
102
|
:required="required"
|
|
@@ -124,19 +115,19 @@ const rangeStyle = $computed(() => {
|
|
|
124
115
|
class="txt-center txt-12 range-slider-position-txt absolute line-height-1 opacity-0"
|
|
125
116
|
:style="{ '--progress': `${fromPercentage}` }"
|
|
126
117
|
>
|
|
127
|
-
{{
|
|
118
|
+
{{ displayFrom }}
|
|
128
119
|
</p>
|
|
129
120
|
<p
|
|
130
121
|
v-if="multiRange && validTo !== max"
|
|
131
122
|
class="txt-center txt-12 range-slider-position-txt opacity-0 line-height-1 absolute"
|
|
132
123
|
:style="{ '--progress': `${toPercentage}` }"
|
|
133
124
|
>
|
|
134
|
-
{{
|
|
125
|
+
{{ displayTo }}
|
|
135
126
|
</p>
|
|
136
127
|
</div>
|
|
137
|
-
<p class="txt-center txt-14 range-slider-txt flex space-between opacity-4 mx-05">
|
|
138
|
-
<span>{{ min }}</span>
|
|
139
|
-
<span>{{ max }}</span>
|
|
128
|
+
<p class="txt-center txt-14 user-select-none range-slider-txt flex space-between opacity-4 mx-05">
|
|
129
|
+
<span>{{ formatValue(min) }}</span>
|
|
130
|
+
<span>{{ formatValue(max) }}</span>
|
|
140
131
|
</p>
|
|
141
132
|
</div>
|
|
142
133
|
</template>
|