Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit a025144

Browse files
SelemondevSelemondev
Selemondev
authored and
Selemondev
committedSep 10, 2023
fix(app): avatarGroup margin
1 parent 06f9e53 commit a025144

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed
 

‎packages/nuxt-ui-vue/src/App.vue

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue'
3-
4-
const isOpen = ref(false)
52
</script>
63

74
<template>
85
<div class="grid place-items-center min-h-screen w-full">
9-
<UButton label="Open" @click="isOpen = true" />
10-
<UModal v-model="isOpen" fullscreen>
11-
<!-- Content -->
12-
</UModal>
6+
<UAvatarGroup size="sm" :max="2">
7+
<UAvatar src="https://avatars.githubusercontent.com/u/739984?v=4" alt="benjamincanac" />
8+
<UAvatar src="https://avatars.githubusercontent.com/u/904724?v=4" alt="Atinux" />
9+
<UAvatar src="https://avatars.githubusercontent.com/u/7547335?v=4" alt="smarroufin" />
10+
</UAvatarGroup>
1311
</div>
1412
</template>

‎packages/nuxt-ui-vue/src/components/elements/Avatar/UAvatar.vue

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ const attrsOmitted = omit(attrs, ['class'])
152152
<script lang="ts">
153153
export default defineComponent({
154154
name: Components.UAvatar,
155-
inheritAttrs: false,
156155
})
157156
</script>
158157

‎packages/nuxt-ui-vue/src/components/elements/Avatar/UAvatarGroup.vue

+68-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script lang="ts">
1+
<!-- <script lang="ts">
22
import { cloneVNode, computed, defineComponent, h } from 'vue'
33
import type { PropType, VNode } from 'vue'
44
import classNames from 'classnames'
@@ -64,4 +64,71 @@ export default defineComponent({
6464
return () => h('div', { class: nuxtLabsTheme.UAvatarGroup.base.root }, clones.value)
6565
},
6666
})
67+
</script> -->
68+
69+
<script lang="ts">
70+
import { cloneVNode, computed, defineComponent, h } from 'vue'
71+
import type { PropType, VNode } from 'vue'
72+
import classNames from 'classnames'
73+
import nuxtLabsTheme from '../../../theme/nuxtLabsTheme'
74+
import { getSlotsFromChildren } from './Types'
75+
import UAvatar from './UAvatar.vue'
76+
import { getVariantPropsWithClassesList } from '@/utils/getVariantProps'
77+
import type { UAvatarGroup } from '@/Types/componentsTypes/components'
78+
import { Components } from '@/Types/enums/Components'
79+
80+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl'
81+
82+
export default defineComponent({
83+
name: Components.UAvatarGroup,
84+
...getVariantPropsWithClassesList<UAvatarGroup>(),
85+
86+
props: {
87+
size: {
88+
type: String as PropType<AvatarSize>,
89+
default: 'md',
90+
},
91+
max: {
92+
type: Number,
93+
default: null,
94+
},
95+
},
96+
setup(props, { slots }) {
97+
const children = computed(() => getSlotsFromChildren(slots))
98+
99+
// if max is passed as a string, we go ahead and convert it into an integer
100+
101+
const max = computed(() => typeof props.max === 'string' ? Number.parseInt(props.max) : props.max)
102+
103+
const clones = computed(() => children.value.map((node: VNode<unknown, unknown, { [key: string]: any }>, index: number) => {
104+
const vProps: Record<string, string> = {}
105+
106+
if (!props.max || (max.value && index < max.value)) {
107+
if (props.size)
108+
vProps.size = props.size
109+
110+
vProps.class = node.props?.class || ''
111+
vProps.class += `${classNames(
112+
nuxtLabsTheme.UAvatarGroup.base.avatarGroupMargin,
113+
)}`
114+
115+
return cloneVNode(node, vProps)
116+
}
117+
118+
if (max.value !== undefined && index === max.value) {
119+
return h(UAvatar, {
120+
size: props.size,
121+
text: `${children.value.length - max.value}`,
122+
name: `${children.value.length - max.value}`,
123+
})
124+
}
125+
126+
return null
127+
}).filter(Boolean).reverse())
128+
129+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
130+
// @ts-expect-error
131+
return () => h('div', { class: nuxtLabsTheme.UAvatarGroup.base.root }, clones.value)
132+
},
133+
})
67134
</script>

‎packages/nuxt-ui-vue/src/theme/nuxtLabsTheme.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ export default {
124124
},
125125
UAvatarGroup: {
126126
base: {
127-
root: 'flex flex-row-reverse',
127+
root: 'flex flex-row-reverse justify-end',
128128
avatarGroupMargin: '-mx-2.5',
129129
},
130130

131131
variants: {
132-
root: 'flex flex-row-reverse',
133-
avatarGroupMargin: 'mx-6',
132+
root: 'flex flex-row-reverse justify-end',
133+
avatarGroupMargin: '-mx-2.5',
134134
},
135135
},
136136

0 commit comments

Comments
 (0)