mediacube-ui 0.1.416 → 0.1.418
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.
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="id" class="mc-spin-digit-container" :style="containerStyles">
|
|
3
|
+
<!-- фэйк цифра, нужно что бы устанавливать нужную ширину контейнера -->
|
|
4
|
+
<span class="mc-spin-digit-container__target">{{ end }}</span>
|
|
5
|
+
<div :class="computedSpinClasses" :style="digitStyles">
|
|
6
|
+
<span v-for="n in 10" :key="`${id}-${start}-${end}-${n}`" class="mc-spin-digit__digit">
|
|
7
|
+
{{ (n - 1 + 10) % 10 }}
|
|
8
|
+
</span>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
<script>
|
|
13
|
+
export default {
|
|
14
|
+
name: 'McSpinDigit',
|
|
15
|
+
props: {
|
|
16
|
+
/**
|
|
17
|
+
* min - 0, max - 9
|
|
18
|
+
* */
|
|
19
|
+
start: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* min - 0, max - 9
|
|
25
|
+
* */
|
|
26
|
+
end: {
|
|
27
|
+
type: Number,
|
|
28
|
+
required: true,
|
|
29
|
+
},
|
|
30
|
+
duration: {
|
|
31
|
+
type: Number,
|
|
32
|
+
default: 500,
|
|
33
|
+
},
|
|
34
|
+
fontSize: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: '300',
|
|
37
|
+
validator: v => ['100', '200', '300', '400', '500', '600', '700'].includes(v),
|
|
38
|
+
},
|
|
39
|
+
weight: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: '400',
|
|
42
|
+
validator: v => ['400', '500', '600', '700'].includes(v),
|
|
43
|
+
},
|
|
44
|
+
color: {
|
|
45
|
+
type: String,
|
|
46
|
+
default: 'black',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
data() {
|
|
50
|
+
return {
|
|
51
|
+
id: String(Date.now()),
|
|
52
|
+
offset: this.start,
|
|
53
|
+
spin_active: false,
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
computed: {
|
|
57
|
+
computedSpinClasses() {
|
|
58
|
+
return {
|
|
59
|
+
'mc-spin-digit': true,
|
|
60
|
+
'mc-spin-digit--off': !this.spin_active,
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
digitStyles() {
|
|
64
|
+
return {
|
|
65
|
+
transform: `translateY(-${this.offset * 100}%)`,
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
containerStyles() {
|
|
69
|
+
return {
|
|
70
|
+
'--mc-spin-digit-font-size': `var(--font-size-${this.fontSize}, var(--font-size-300))`,
|
|
71
|
+
'--mc-spin-digit-font-color': `var(--color-${this.color}, var(--color-black))`,
|
|
72
|
+
'--mc-spin-digit-font-weight': `var(--font-weight-${this.weight}, var(--font-weight-400))`,
|
|
73
|
+
'--mc-spin-duration': `${this.duration}ms`,
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
watch: {
|
|
78
|
+
end: {
|
|
79
|
+
handler(newVal, oldVal) {
|
|
80
|
+
if (newVal !== oldVal) {
|
|
81
|
+
this.triggerSpin()
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
mounted() {
|
|
87
|
+
this.init()
|
|
88
|
+
},
|
|
89
|
+
methods: {
|
|
90
|
+
init() {
|
|
91
|
+
this.spin_active = false
|
|
92
|
+
this.offset = this.start
|
|
93
|
+
requestAnimationFrame(this.triggerSpin)
|
|
94
|
+
},
|
|
95
|
+
triggerSpin() {
|
|
96
|
+
this.$emit('spin-start', this.start)
|
|
97
|
+
this.spin_active = true
|
|
98
|
+
this.$nextTick(() => {
|
|
99
|
+
this.offset = this.end
|
|
100
|
+
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
this.spin_active = false
|
|
103
|
+
this.$emit('spin-end', this.end)
|
|
104
|
+
}, this.duration)
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
</script>
|
|
110
|
+
<style lang="scss">
|
|
111
|
+
@import '../../tokens/font-sizes';
|
|
112
|
+
@import '../../tokens/colors';
|
|
113
|
+
@import '../../tokens/font-families';
|
|
114
|
+
@import '../../tokens/font-weights';
|
|
115
|
+
|
|
116
|
+
.mc-spin-digit-container {
|
|
117
|
+
$block-name: &;
|
|
118
|
+
// генерируем css переменный из токенов
|
|
119
|
+
$token-font-weights: (
|
|
120
|
+
'400': $font-weight-normal,
|
|
121
|
+
'500': $font-weight-medium,
|
|
122
|
+
'600': $font-weight-semi-bold,
|
|
123
|
+
'700': $font-weight-bold,
|
|
124
|
+
);
|
|
125
|
+
@each $key, $value in $token-font-sizes {
|
|
126
|
+
--font-size-#{$key}: #{$value};
|
|
127
|
+
}
|
|
128
|
+
@each $key, $value in $token-colors {
|
|
129
|
+
--color-#{$key}: #{$value};
|
|
130
|
+
}
|
|
131
|
+
@each $key, $value in $token-font-weights {
|
|
132
|
+
--font-weight-#{$key}: #{$value};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
--mc-spin-digit-font-size: var(--font-size-300);
|
|
136
|
+
--mc-spin-digit-font-color: var(--color-black);
|
|
137
|
+
--mc-spin-digit-font-weight: var(--font-weight-400);
|
|
138
|
+
|
|
139
|
+
font-family: $font-family-main;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
height: var(--mc-spin-digit-font-size);
|
|
142
|
+
position: relative;
|
|
143
|
+
|
|
144
|
+
&__target {
|
|
145
|
+
font-size: var(--mc-spin-digit-font-size);
|
|
146
|
+
visibility: hidden;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.mc-spin-digit {
|
|
150
|
+
position: absolute;
|
|
151
|
+
top: 0;
|
|
152
|
+
left: 0;
|
|
153
|
+
display: flex;
|
|
154
|
+
flex-direction: column;
|
|
155
|
+
height: 100%;
|
|
156
|
+
color: var(--mc-spin-digit-font-color);
|
|
157
|
+
transition: transform var(--mc-spin-duration) cubic-bezier(0.4, 0, 0.2, 1);
|
|
158
|
+
&--off {
|
|
159
|
+
transition: none;
|
|
160
|
+
}
|
|
161
|
+
&__digit {
|
|
162
|
+
height: var(--mc-spin-digit-font-size);
|
|
163
|
+
line-height: var(--mc-spin-digit-font-size);
|
|
164
|
+
font-size: var(--mc-spin-digit-font-size);
|
|
165
|
+
font-weight: var(--mc-spin-digit-font-weight);
|
|
166
|
+
color: var(--mc-spin-digit-font-color);
|
|
167
|
+
text-align: center;
|
|
168
|
+
flex-shrink: 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
</style>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="id" class="mc-spin-number-container">
|
|
3
|
+
<div v-for="(digit, i) in currentTo" :key="`mc-spin-number-${id}-${i}-${end}`" class="mc-spin-number">
|
|
4
|
+
<template v-if="!Number.isFinite(digit)">
|
|
5
|
+
<span :style="nonDigitStyles" class="mc-spin-number__non-digit">
|
|
6
|
+
{{ currentTo[i] }}
|
|
7
|
+
</span>
|
|
8
|
+
</template>
|
|
9
|
+
<mc-spin-digit
|
|
10
|
+
v-else
|
|
11
|
+
:start="+currentFrom[i]"
|
|
12
|
+
:end="+currentTo[i]"
|
|
13
|
+
:duration="duration"
|
|
14
|
+
:font-size="fontSize"
|
|
15
|
+
:color="color"
|
|
16
|
+
class="mc-spin-number__digit"
|
|
17
|
+
@spin-end="actualizeNumbers"
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
import McSpinDigit from '../McSpinDigit/McSpinDigit'
|
|
25
|
+
export default {
|
|
26
|
+
name: 'McSpinNumber',
|
|
27
|
+
components: {
|
|
28
|
+
McSpinDigit,
|
|
29
|
+
},
|
|
30
|
+
props: {
|
|
31
|
+
start: {
|
|
32
|
+
type: [Number, String],
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
end: {
|
|
36
|
+
type: [Number, String],
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
duration: {
|
|
40
|
+
type: Number,
|
|
41
|
+
default: 500,
|
|
42
|
+
},
|
|
43
|
+
fontSize: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: '300',
|
|
46
|
+
validator: v => ['100', '200', '300', '400', '500', '600', '700'].includes(v),
|
|
47
|
+
},
|
|
48
|
+
weight: {
|
|
49
|
+
type: String,
|
|
50
|
+
default: '400',
|
|
51
|
+
validator: v => ['400', '500', '600', '700'].includes(v),
|
|
52
|
+
},
|
|
53
|
+
color: {
|
|
54
|
+
type: String,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
data() {
|
|
58
|
+
return {
|
|
59
|
+
id: String(Date.now()),
|
|
60
|
+
current_from: null,
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
computed: {
|
|
64
|
+
currentTo() {
|
|
65
|
+
return this.formatNumber(this.end)
|
|
66
|
+
},
|
|
67
|
+
currentFrom() {
|
|
68
|
+
const from = `000000000${String((this.current_from ?? this.start) || 0)}`.slice(-this.currentTo.length)
|
|
69
|
+
return this.formatNumber(from)
|
|
70
|
+
},
|
|
71
|
+
nonDigitStyles() {
|
|
72
|
+
return {
|
|
73
|
+
'--mc-spin-number-font-size': `var(--font-size-${this.fontSize}, var(--font-size-300))`,
|
|
74
|
+
'--mc-spin-number-font-color': `var(--color-${this.color}, var(--color-black))`,
|
|
75
|
+
'--mc-spin-number-font-weight': `var(--font-weight-${this.weight}, var(--font-weight-400))`,
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
methods: {
|
|
80
|
+
actualizeNumbers() {
|
|
81
|
+
this.current_from = this.end
|
|
82
|
+
},
|
|
83
|
+
formatNumber(num) {
|
|
84
|
+
return String(num)
|
|
85
|
+
.split('')
|
|
86
|
+
.map(n => (/\d/.test(n) ? +n : n))
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<style lang="scss">
|
|
93
|
+
@import '../../tokens/font-sizes';
|
|
94
|
+
@import '../../tokens/colors';
|
|
95
|
+
@import '../../tokens/font-families';
|
|
96
|
+
@import '../../tokens/font-weights';
|
|
97
|
+
|
|
98
|
+
.mc-spin-number {
|
|
99
|
+
$block-name: &;
|
|
100
|
+
$token-font-weights: (
|
|
101
|
+
'400': $font-weight-normal,
|
|
102
|
+
'500': $font-weight-medium,
|
|
103
|
+
'600': $font-weight-semi-bold,
|
|
104
|
+
'700': $font-weight-bold,
|
|
105
|
+
);
|
|
106
|
+
@each $key, $value in $token-font-sizes {
|
|
107
|
+
--font-size-#{$key}: #{$value};
|
|
108
|
+
}
|
|
109
|
+
@each $key, $value in $token-colors {
|
|
110
|
+
--color-#{$key}: #{$value};
|
|
111
|
+
}
|
|
112
|
+
@each $key, $value in $token-font-weights {
|
|
113
|
+
--font-weight-#{$key}: #{$value};
|
|
114
|
+
}
|
|
115
|
+
--mc-spin-number-font-size: var(--font-size-300);
|
|
116
|
+
--mc-spin-number-font-color: var(--color-black);
|
|
117
|
+
--mc-spin-number-font-weight: var(--font-weight-400);
|
|
118
|
+
|
|
119
|
+
display: flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
justify-content: center;
|
|
122
|
+
|
|
123
|
+
&-container {
|
|
124
|
+
display: flex;
|
|
125
|
+
}
|
|
126
|
+
&__non-digit {
|
|
127
|
+
display: inline-flex;
|
|
128
|
+
min-width: 0.32em;
|
|
129
|
+
font-size: var(--mc-spin-number-font-size);
|
|
130
|
+
font-weight: var(--mc-spin-number-font-weight);
|
|
131
|
+
color: var(--mc-spin-number-font-color);
|
|
132
|
+
line-height: 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
</style>
|