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,6 +1,6 @@
1
1
  {
2
2
  "name": "mediacube-ui",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "Design system for Mediacube services",
5
5
  "author": "Mediacube",
6
6
  "private": false,
@@ -51,6 +51,7 @@
51
51
  variation="black-flat"
52
52
  :href="menuAppsItem.href"
53
53
  :to="menuAppsItem.to"
54
+ :target="menuAppsItem.target"
54
55
  :is-active="menuAppsItem.isActive"
55
56
  :exact="menuAppsItem.exact"
56
57
  >
@@ -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
- render(h, { props, slots, data }) {
20
- let items = slots()['default']
21
- const renderItems = items ? items.filter(i => i.tag) : []
22
- items = props.limit === null ? renderItems : renderItems.slice(0, props.limit)
23
- const more = renderItems.length - items.length
24
-
25
- const classes = {
26
- 'mc-stack': true,
27
- 'mc-stack--collapsed': props.collapsed,
28
- ...(data.class || {}),
29
- }
30
-
31
- if (data.staticClass) {
32
- const staticClasses = data.staticClass.split(' ')
33
- staticClasses.forEach(c => {
34
- if (c) {
35
- classes[c] = true
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
- let style = {}
40
- if (data.staticStyle) {
41
- style = data.staticStyle
42
- }
43
-
44
- return h(
45
- 'div',
46
- {
47
- ref: data.ref,
48
- class: classes,
49
- style,
50
- },
51
- [
52
- h(
53
- 'div',
54
- {
55
- ref: 'body',
56
- class: 'mc-stack__body',
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>