@una-ui/nuxt 0.49.1 → 0.49.3
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/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/elements/AvatarGroup.vue +104 -11
- package/dist/runtime/components/slots/FormFieldDefault.d.ts +2 -2
- package/dist/runtime/types/avatar-group.d.ts +3 -4
- package/package.json +3 -3
- package/dist/runtime/components/slots/AvatarGroupDefault.d.ts +0 -22
- package/dist/runtime/components/slots/AvatarGroupDefault.js +0 -45
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,23 +1,116 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { NAvatarGroupProps } from '../../types'
|
|
3
|
-
import
|
|
3
|
+
import { reactiveOmit } from '@vueuse/core'
|
|
4
|
+
import { Primitive } from 'reka-ui'
|
|
5
|
+
import { computed, h } from 'vue'
|
|
6
|
+
import { cn } from '../../utils'
|
|
7
|
+
import Avatar from './avatar/Avatar.vue'
|
|
4
8
|
|
|
5
9
|
const props = withDefaults(defineProps<NAvatarGroupProps>(), {
|
|
6
10
|
max: 3,
|
|
11
|
+
as: 'div',
|
|
7
12
|
})
|
|
13
|
+
|
|
14
|
+
const slots = defineSlots()
|
|
15
|
+
|
|
16
|
+
const max = computed(() => typeof props.max === 'string' ? Number.parseInt(props.max, 10) : props.max)
|
|
17
|
+
|
|
18
|
+
const children = computed(() => {
|
|
19
|
+
let children = slots.default?.()
|
|
20
|
+
if (children?.length) {
|
|
21
|
+
children = children.flatMap((child: any) => {
|
|
22
|
+
if (typeof child.type === 'symbol') {
|
|
23
|
+
// `v-if="false"` or commented node
|
|
24
|
+
if (typeof child.children === 'string') {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return child.children
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return child
|
|
32
|
+
}).filter(Boolean)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return children || []
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Calculate visible and hidden avatars without circular dependencies
|
|
39
|
+
const maxVisibleCount = computed(() => {
|
|
40
|
+
if (!max.value || max.value <= 0) {
|
|
41
|
+
return children.value.length
|
|
42
|
+
}
|
|
43
|
+
return Math.min(max.value, children.value.length)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const hiddenCount = computed(() => {
|
|
47
|
+
if (!children.value.length) {
|
|
48
|
+
return 0
|
|
49
|
+
}
|
|
50
|
+
return Math.max(0, children.value.length - maxVisibleCount.value)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const visibleAvatars = computed(() => {
|
|
54
|
+
if (!children.value.length) {
|
|
55
|
+
return []
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Take only the visible portion without modifying the original array
|
|
59
|
+
return [...children.value].slice(0, maxVisibleCount.value).reverse()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const displayAvatars = computed(() => {
|
|
63
|
+
const result = [...visibleAvatars.value]
|
|
64
|
+
|
|
65
|
+
if (hiddenCount.value > 0) {
|
|
66
|
+
const avatarProps = children.value.length > 0
|
|
67
|
+
? reactiveOmit(children.value[0].props || {}, ['src', 'alt', 'label', 'icon'])
|
|
68
|
+
: {}
|
|
69
|
+
|
|
70
|
+
result.unshift(
|
|
71
|
+
h(Avatar, {
|
|
72
|
+
label: `+${hiddenCount.value}`,
|
|
73
|
+
class: cn(
|
|
74
|
+
props.una?.avatarGroupCount,
|
|
75
|
+
),
|
|
76
|
+
una: {
|
|
77
|
+
avatarFallback: cn(
|
|
78
|
+
'avatar-group-count',
|
|
79
|
+
props.una?.avatarGroupCount,
|
|
80
|
+
avatarProps.una?.avatarFallback,
|
|
81
|
+
),
|
|
82
|
+
...avatarProps.una,
|
|
83
|
+
},
|
|
84
|
+
...avatarProps,
|
|
85
|
+
}),
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const rootProps = reactiveOmit(props, ['max', 'as', 'asChild'])
|
|
8
93
|
</script>
|
|
9
94
|
|
|
10
95
|
<template>
|
|
11
|
-
<
|
|
12
|
-
|
|
96
|
+
<Primitive
|
|
97
|
+
:as="as"
|
|
13
98
|
:size
|
|
14
|
-
:class="
|
|
99
|
+
:class="cn(
|
|
100
|
+
'avatar-group',
|
|
101
|
+
una?.avatarGroup,
|
|
102
|
+
)"
|
|
103
|
+
:as-child
|
|
15
104
|
>
|
|
16
|
-
<
|
|
17
|
-
:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
105
|
+
<component
|
|
106
|
+
:is="avatar"
|
|
107
|
+
v-for="(avatar, count) in displayAvatars"
|
|
108
|
+
v-bind="{ ...rootProps, ...avatar.props }"
|
|
109
|
+
:key="count"
|
|
110
|
+
:class="cn(
|
|
111
|
+
'avatar-group-item',
|
|
112
|
+
props.class,
|
|
113
|
+
)"
|
|
114
|
+
/>
|
|
115
|
+
</Primitive>
|
|
23
116
|
</template>
|
|
@@ -10,7 +10,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
10
10
|
required: false;
|
|
11
11
|
};
|
|
12
12
|
modelValue: {
|
|
13
|
-
type: (NumberConstructor |
|
|
13
|
+
type: (NumberConstructor | StringConstructor | BooleanConstructor)[];
|
|
14
14
|
required: false;
|
|
15
15
|
};
|
|
16
16
|
id: {
|
|
@@ -38,7 +38,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
38
38
|
required: false;
|
|
39
39
|
};
|
|
40
40
|
modelValue: {
|
|
41
|
-
type: (NumberConstructor |
|
|
41
|
+
type: (NumberConstructor | StringConstructor | BooleanConstructor)[];
|
|
42
42
|
required: false;
|
|
43
43
|
};
|
|
44
44
|
id: {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { PrimitiveProps } from 'reka-ui';
|
|
1
2
|
import type { NAvatarProps } from './avatar.js';
|
|
2
3
|
/**
|
|
3
4
|
* This extends the `NAvatarProps` interface.
|
|
4
5
|
*
|
|
5
6
|
* @see https://github.com/una-ui/una-ui/blob/main/packages/nuxt/src/runtime/types/avatar.ts
|
|
6
7
|
*/
|
|
7
|
-
export interface NAvatarGroupProps extends Omit<NAvatarProps, 'una'
|
|
8
|
+
export interface NAvatarGroupProps extends Omit<NAvatarProps, 'src' | 'alt' | 'label' | 'una'>, PrimitiveProps {
|
|
8
9
|
/**
|
|
9
10
|
* Set the maximum number of avatars to show.
|
|
10
11
|
*
|
|
@@ -19,8 +20,6 @@ export interface NAvatarGroupProps extends Omit<NAvatarProps, 'una'> {
|
|
|
19
20
|
*/
|
|
20
21
|
una?: {
|
|
21
22
|
avatarGroup?: string;
|
|
22
|
-
|
|
23
|
-
avatarGroupMargin?: string;
|
|
24
|
-
avatarGroupLabel?: string;
|
|
23
|
+
avatarGroupCount?: string;
|
|
25
24
|
} & NAvatarProps['una'];
|
|
26
25
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@una-ui/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.49.
|
|
4
|
+
"version": "0.49.3",
|
|
5
5
|
"description": "Nuxt module for @una-ui",
|
|
6
6
|
"author": "Phojie Rengel <phojrengel@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"typescript": "5.6.3",
|
|
60
60
|
"unocss": "^66.0.0",
|
|
61
61
|
"unocss-preset-animations": "^1.1.1",
|
|
62
|
-
"@una-ui/extractor-vue-script": "^0.49.
|
|
63
|
-
"@una-ui/preset": "^0.49.
|
|
62
|
+
"@una-ui/extractor-vue-script": "^0.49.3",
|
|
63
|
+
"@una-ui/preset": "^0.49.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@iconify-json/lucide": "^1.2.34",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { PropType, VNode } from 'vue';
|
|
2
|
-
import type { NAvatarGroupProps } from '../../types/index.js';
|
|
3
|
-
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
-
max: {
|
|
5
|
-
type: NumberConstructor;
|
|
6
|
-
required: true;
|
|
7
|
-
};
|
|
8
|
-
avatar: {
|
|
9
|
-
type: PropType<NAvatarGroupProps>;
|
|
10
|
-
};
|
|
11
|
-
}>, (() => null) | (() => (VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}> | null)[]), {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
14
|
-
max: {
|
|
15
|
-
type: NumberConstructor;
|
|
16
|
-
required: true;
|
|
17
|
-
};
|
|
18
|
-
avatar: {
|
|
19
|
-
type: PropType<NAvatarGroupProps>;
|
|
20
|
-
};
|
|
21
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
22
|
-
export default _default;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { cloneVNode, computed, defineComponent, h } from "vue";
|
|
2
|
-
import Avatar from "../elements/avatar/Avatar.vue";
|
|
3
|
-
export default defineComponent({
|
|
4
|
-
props: {
|
|
5
|
-
max: {
|
|
6
|
-
type: Number,
|
|
7
|
-
required: true
|
|
8
|
-
},
|
|
9
|
-
avatar: {
|
|
10
|
-
type: Object
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
setup(props, { slots }) {
|
|
14
|
-
const children = computed(() => slots.default?.()[0].children);
|
|
15
|
-
if (!children.value)
|
|
16
|
-
return () => null;
|
|
17
|
-
const countChildren = computed(() => children.value?.length);
|
|
18
|
-
const filterChildren = computed(() => {
|
|
19
|
-
if (countChildren.value <= props.max)
|
|
20
|
-
return children.value;
|
|
21
|
-
const childrenCopy = [...children.value];
|
|
22
|
-
childrenCopy.splice(props.max, countChildren.value - props.max);
|
|
23
|
-
return childrenCopy;
|
|
24
|
-
});
|
|
25
|
-
const clones = computed(() => filterChildren.value?.map((node) => {
|
|
26
|
-
const mergeProps = { ...props.avatar, ...node.props };
|
|
27
|
-
return cloneVNode(node, { ...mergeProps, class: "avatar-group-(child margin)" });
|
|
28
|
-
}).reverse());
|
|
29
|
-
const label = computed(() => {
|
|
30
|
-
if (countChildren.value <= props.max)
|
|
31
|
-
return null;
|
|
32
|
-
return h(Avatar, {
|
|
33
|
-
// TODO: add `more` configuration
|
|
34
|
-
class: "avatar-(soft group-margin)",
|
|
35
|
-
size: props.avatar?.size,
|
|
36
|
-
label: `+${countChildren.value - props.max}`,
|
|
37
|
-
una: { avatarLabel: `${props.avatar?.una?.avatarGroupLabel ?? ""} avatar-group-label` }
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
return () => [
|
|
41
|
-
label.value,
|
|
42
|
-
...clones.value
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
});
|