mediacube-ui 0.1.57 → 0.1.59
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/package.json
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="mc-stack" ref="stack">
|
|
3
|
+
<div class="mc-stack__body" ref="body">
|
|
4
|
+
<slot />
|
|
5
|
+
</div>
|
|
6
|
+
<div v-if="more" class="mc-stack__counter" ref="counter">
|
|
7
|
+
{{ counterText }}
|
|
8
|
+
</div>
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
1
12
|
<script>
|
|
2
13
|
export default {
|
|
3
14
|
name: 'McStack',
|
|
4
|
-
functional: true,
|
|
5
15
|
/**
|
|
6
16
|
* Количество отрисованных
|
|
7
17
|
* единиц списка
|
|
18
|
+
* или число для макс. лимита
|
|
19
|
+
* или строка "auto" для расчета по доступной ширине
|
|
8
20
|
*/
|
|
9
21
|
props: {
|
|
10
22
|
limit: {
|
|
11
|
-
type: Number,
|
|
23
|
+
type: [Number, String],
|
|
12
24
|
default: null,
|
|
13
25
|
},
|
|
14
26
|
collapsed: {
|
|
@@ -16,59 +28,74 @@ export default {
|
|
|
16
28
|
default: false,
|
|
17
29
|
},
|
|
18
30
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
data: () => ({
|
|
32
|
+
children: null,
|
|
33
|
+
more: 0,
|
|
34
|
+
custom_limit: 0,
|
|
35
|
+
}),
|
|
36
|
+
computed: {
|
|
37
|
+
classes() {
|
|
38
|
+
return {
|
|
39
|
+
'mc-stack': true,
|
|
40
|
+
'mc-stack--collapsed': this.collapsed,
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
isAutoLimit() {
|
|
44
|
+
return this.limit === 'auto'
|
|
45
|
+
},
|
|
46
|
+
counterText() {
|
|
47
|
+
return `+${this.more}`
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
mounted() {
|
|
51
|
+
this.init()
|
|
52
|
+
},
|
|
53
|
+
beforeDestroy() {
|
|
54
|
+
if (this.isAutoLimit) window.removeEventListener('resize', this.calcLimit)
|
|
55
|
+
},
|
|
56
|
+
methods: {
|
|
57
|
+
init() {
|
|
58
|
+
if (this.isAutoLimit) {
|
|
59
|
+
this.calcLimit()
|
|
60
|
+
window.addEventListener('resize', this.calcLimit)
|
|
61
|
+
} else {
|
|
62
|
+
this.toggleChilds(true, this.limit)
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
calcLimit() {
|
|
66
|
+
this.toggleChilds()
|
|
67
|
+
this.custom_limit = Infinity
|
|
68
|
+
let childWidth = 0
|
|
69
|
+
// ширина родителя без учета счетчика
|
|
70
|
+
const parentWidth = +this.$refs.stack?.clientWidth - (+this.$refs.counter?.clientWidth || 0)
|
|
71
|
+
for (let i = 0; i < this.children?.length; i++) {
|
|
72
|
+
const elemStyle = window.getComputedStyle(this.children[i])
|
|
73
|
+
childWidth += (+this.children[i]?.clientWidth + +parseInt(elemStyle.marginRight))
|
|
74
|
+
// считаем занимаемую дочерними элементами ширину, если превышает родительскую, то выходим из цикла и ставим лимит
|
|
75
|
+
if (childWidth > parentWidth) {
|
|
76
|
+
this.custom_limit = i
|
|
77
|
+
break
|
|
36
78
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
style =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
items,
|
|
59
|
-
),
|
|
60
|
-
more > 0
|
|
61
|
-
? h(
|
|
62
|
-
'div',
|
|
63
|
-
{
|
|
64
|
-
ref: 'counter',
|
|
65
|
-
class: 'mc-stack__counter',
|
|
66
|
-
},
|
|
67
|
-
[`+${more}`],
|
|
68
|
-
)
|
|
69
|
-
: null,
|
|
70
|
-
],
|
|
71
|
-
)
|
|
79
|
+
}
|
|
80
|
+
this.toggleChilds(true, this.custom_limit)
|
|
81
|
+
},
|
|
82
|
+
setStyles(elem, opacity = 1, visibility = 'visible', position = 'initial') {
|
|
83
|
+
elem.style.opacity = opacity
|
|
84
|
+
elem.style.visibility = visibility
|
|
85
|
+
elem.style.position = position
|
|
86
|
+
},
|
|
87
|
+
toggleChilds(hide, limit = 0) {
|
|
88
|
+
this.more = 0
|
|
89
|
+
this.children = this.$refs.body.children
|
|
90
|
+
let elementsLimit = hide ? (limit - 1) : this.children.length
|
|
91
|
+
for (let i = 0; i < this.children?.length; i++) {
|
|
92
|
+
this.setStyles(this.children[i])
|
|
93
|
+
if (i > elementsLimit) {
|
|
94
|
+
this.setStyles(this.children[i], 0, 'hidden', 'absolute')
|
|
95
|
+
this.more++
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
72
99
|
},
|
|
73
100
|
}
|
|
74
101
|
</script>
|
|
@@ -105,14 +132,16 @@ export default {
|
|
|
105
132
|
}
|
|
106
133
|
|
|
107
134
|
&__counter {
|
|
135
|
+
width: auto;
|
|
108
136
|
position: sticky;
|
|
109
137
|
right: 0;
|
|
110
138
|
margin-left: $space-50;
|
|
111
139
|
flex: 0 0 auto;
|
|
112
|
-
color: $color-gray;
|
|
113
|
-
font-family: $font-family-main;
|
|
114
140
|
font-size: $font-size-200;
|
|
115
141
|
line-height: $line-height-200;
|
|
142
|
+
color: $color-gray;
|
|
143
|
+
font-weight: $font-weight-semi-bold;
|
|
144
|
+
font-family: $font-family-main;
|
|
116
145
|
}
|
|
117
146
|
}
|
|
118
147
|
</style>
|