ui-svelte 0.2.20 → 0.2.22
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/control/css/btn.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { Avatar } from '../index.js';
|
|
2
3
|
import { cn } from '../utils/class-names.js';
|
|
3
|
-
import Avatar from './Avatar.svelte';
|
|
4
4
|
|
|
5
5
|
type AvatarItem = {
|
|
6
6
|
src?: string;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
variant?: 'solid' | 'soft';
|
|
18
18
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
19
19
|
max?: number;
|
|
20
|
+
autoFit?: boolean;
|
|
20
21
|
isInline?: boolean;
|
|
21
22
|
isBordered?: boolean;
|
|
22
23
|
classRoot?: string;
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
color = 'primary',
|
|
31
32
|
size = 'md',
|
|
32
33
|
max,
|
|
34
|
+
autoFit = false,
|
|
33
35
|
isInline,
|
|
34
36
|
isBordered,
|
|
35
37
|
classRoot,
|
|
@@ -37,11 +39,83 @@
|
|
|
37
39
|
classCounter
|
|
38
40
|
}: Props = $props();
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
+
const avatarSizes: Record<string, number> = {
|
|
43
|
+
xs: 24,
|
|
44
|
+
sm: 32,
|
|
45
|
+
md: 40,
|
|
46
|
+
xl: 64
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const counterSizes: Record<string, number> = {
|
|
50
|
+
xs: 20,
|
|
51
|
+
sm: 24,
|
|
52
|
+
md: 28,
|
|
53
|
+
lg: 40,
|
|
54
|
+
xl: 56
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const OVERLAP = 12;
|
|
58
|
+
const GAP_INLINE = 8;
|
|
59
|
+
|
|
60
|
+
let containerRef: HTMLDivElement | null = $state(null);
|
|
61
|
+
let autoFitMax: number | null = $state(null);
|
|
62
|
+
|
|
63
|
+
function calculateFitCount(containerWidth: number): number {
|
|
64
|
+
const avatarSize = avatarSizes[size];
|
|
65
|
+
const counterSize = counterSizes[size];
|
|
66
|
+
|
|
67
|
+
if (isInline) {
|
|
68
|
+
const gap = GAP_INLINE;
|
|
69
|
+
const reservedForCounter = counterSize + gap;
|
|
70
|
+
const availableWidth = containerWidth - reservedForCounter;
|
|
71
|
+
|
|
72
|
+
if (availableWidth < avatarSize) return 1;
|
|
73
|
+
|
|
74
|
+
const firstAvatar = avatarSize;
|
|
75
|
+
const subsequentAvatar = avatarSize + gap;
|
|
76
|
+
|
|
77
|
+
const count = 1 + Math.floor((availableWidth - firstAvatar) / subsequentAvatar);
|
|
78
|
+
return Math.max(1, count);
|
|
79
|
+
} else {
|
|
80
|
+
const reservedForCounter = counterSize - OVERLAP;
|
|
81
|
+
const availableWidth = containerWidth - reservedForCounter;
|
|
82
|
+
|
|
83
|
+
if (availableWidth < avatarSize) return 1;
|
|
84
|
+
|
|
85
|
+
const firstAvatar = avatarSize;
|
|
86
|
+
const subsequentAvatar = avatarSize - OVERLAP;
|
|
87
|
+
|
|
88
|
+
const count = 1 + Math.floor((availableWidth - firstAvatar) / subsequentAvatar);
|
|
89
|
+
return Math.max(1, count);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
$effect(() => {
|
|
94
|
+
if (!autoFit || !containerRef) return;
|
|
95
|
+
|
|
96
|
+
const observer = new ResizeObserver((entries) => {
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
const width = entry.contentRect.width;
|
|
99
|
+
const fitCount = calculateFitCount(width);
|
|
100
|
+
autoFitMax = fitCount < items.length ? fitCount : null;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
observer.observe(containerRef);
|
|
105
|
+
|
|
106
|
+
return () => observer.disconnect();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const effectiveMax = $derived(autoFit && autoFitMax !== null ? autoFitMax : max);
|
|
110
|
+
const visibleItems = $derived(
|
|
111
|
+
effectiveMax && effectiveMax < items.length ? items.slice(0, effectiveMax) : items
|
|
112
|
+
);
|
|
113
|
+
const remainingCount = $derived(
|
|
114
|
+
effectiveMax && effectiveMax < items.length ? items.length - effectiveMax : 0
|
|
115
|
+
);
|
|
42
116
|
</script>
|
|
43
117
|
|
|
44
|
-
<div class={cn('avatar-group', !isInline && 'is-stacked', classRoot)}>
|
|
118
|
+
<div bind:this={containerRef} class={cn('avatar-group', !isInline && 'is-stacked', classRoot)}>
|
|
45
119
|
{#each visibleItems as item, i}
|
|
46
120
|
<Avatar
|
|
47
121
|
src={item.src}
|