/
avatar-group.js
75 lines (70 loc) · 2.03 KB
/
avatar-group.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
65
66
67
68
69
70
71
72
73
74
75
import { defineComponent } from '../../vue'
import { NAME_AVATAR_GROUP } from '../../constants/components'
import {
PROP_TYPE_BOOLEAN,
PROP_TYPE_BOOLEAN_STRING,
PROP_TYPE_NUMBER_STRING,
PROP_TYPE_STRING
} from '../../constants/props'
import { mathMax, mathMin } from '../../utils/math'
import { toFloat } from '../../utils/number'
import { makeProp, makePropsConfigurable } from '../../utils/props'
import { normalizeSlotMixin } from '../../mixins/normalize-slot'
import { computeSize } from './avatar'
// --- Props ---
export const props = makePropsConfigurable(
{
overlap: makeProp(PROP_TYPE_NUMBER_STRING, 0.3),
// Child avatars will prefer this prop (if set) over their own
rounded: makeProp(PROP_TYPE_BOOLEAN_STRING, false),
// Child avatars will always use this over their own size
size: makeProp(PROP_TYPE_STRING),
// Child avatars will prefer this prop (if set) over their own
square: makeProp(PROP_TYPE_BOOLEAN, false),
tag: makeProp(PROP_TYPE_STRING, 'div'),
// Child avatars will prefer this variant over their own
variant: makeProp(PROP_TYPE_STRING)
},
NAME_AVATAR_GROUP
)
// --- Main component ---
// @vue/component
export const BAvatarGroup = /*#__PURE__*/ defineComponent({
name: NAME_AVATAR_GROUP,
mixins: [normalizeSlotMixin],
provide() {
return { getBvAvatarGroup: () => this }
},
props,
computed: {
computedSize() {
return computeSize(this.size)
},
overlapScale() {
return mathMin(mathMax(toFloat(this.overlap, 0), 0), 1) / 2
},
paddingStyle() {
let value = this.computedSize
value = value ? `calc(${value} * ${this.overlapScale})` : null
return value ? { paddingLeft: value, paddingRight: value } : {}
}
},
render(h) {
const $inner = h(
'div',
{
staticClass: 'b-avatar-group-inner',
style: this.paddingStyle
},
this.normalizeSlot()
)
return h(
this.tag,
{
staticClass: 'b-avatar-group',
attrs: { role: 'group' }
},
[$inner]
)
}
})