Skip to content

Commit 07e61cc

Browse files
committed
fix(Avatar): use resolved size for image width/height
1 parent 5c667b8 commit 07e61cc

43 files changed

Lines changed: 417 additions & 411 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* fix(Error): support `status` and `statusText` properties
88
* fix(ContentSurround): handle RTL mode
99
* chore(deps): update dependency reka-ui to v2.9.0
10+
* fix(Avatar): use resolved size for image width/height
1011

1112
## [2.5.3](https://github.com/bitrix24/b24ui/compare/v2.5.2...v2.5.3) (2026-03-30)
1213

src/runtime/components/Avatar.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ const b24ui = computed(() => tv({ extend: tv(theme), ...(appConfig.b24ui?.avatar
7777
size: size.value
7878
}))
7979
80-
const sizePx = computed(() => ({
81-
'3xs': 10,
82-
'2xs': 14,
83-
'xs': 18,
84-
'sm': 22,
85-
'md': 32,
86-
'lg': 42,
87-
'xl': 48,
88-
'2xl': 60,
89-
'3xl': 94
90-
})[props.size || 'md'])
80+
const rootClass = computed(() => b24ui.value.root({ class: [uiProp.value?.root, props.class] }))
81+
82+
const sizePx = computed(() => {
83+
const sizeClass = rootClass.value.split(' ').find(c => /^size-\d+$/.test(c))
84+
if (sizeClass) {
85+
const num = Number.parseFloat(sizeClass.split('-')[1] ?? '')
86+
if (!Number.isNaN(num)) return num * 4
87+
}
88+
89+
return null
90+
})
9191
9292
const error = ref(false)
9393
@@ -108,7 +108,7 @@ function onError() {
108108
:as="as.root"
109109
v-bind="props.chip ? (typeof props.chip === 'object' ? { inset: true, ...props.chip } : { inset: true }) : {}"
110110
data-slot="root"
111-
:class="b24ui.root({ class: [uiProp?.root, props.class] })"
111+
:class="rootClass"
112112
:style="props.style"
113113
>
114114
<component

test/components/Avatar.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ describe('Avatar', () => {
2020
['with as', { props: { as: 'section' } }],
2121
['with as (object)', { props: { src: 'https://github.com/bitrix24.png', as: { root: 'section', img: 'p' } } }],
2222
['with as (partial object)', { props: { src: 'https://github.com/bitrix24.png', as: { img: 'p' } } }],
23-
['with class', { props: { class: 'bg-white' } }],
23+
['with class', { props: { class: 'bg-default' } }],
2424
['with b24ui', { props: { b24ui: { fallback: 'font-bold' } } }],
25+
['with custom size', { props: { class: 'size-100', src: 'https://github.com/bitrix24.png' } }],
2526
// Slots
2627
['with default slot', { slots: { default: '🚀' } }]
2728
])

test/components/__snapshots__/Alert-vue.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports[`Alert > renders with as correctly 1`] = `
3131
`;
3232

3333
exports[`Alert > renders with avatar correctly 1`] = `
34-
"<div data-orientation="vertical" data-slot="root" class="relative overflow-hidden w-full flex text-(--b24ui-color) bg-(--b24ui-background) border-(--b24ui-border-color) border-(length:--b24ui-border-width) rounded-(--ui-border-radius-md) style-outline py-md ps-md pe-xs gap-2.5 items-start"><span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset) shrink-0"><img src="https://github.com/bitrix24.png" width="48" height="48" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>
34+
"<div data-orientation="vertical" data-slot="root" class="relative overflow-hidden w-full flex text-(--b24ui-color) bg-(--b24ui-background) border-(--b24ui-border-color) border-(length:--b24ui-border-width) rounded-(--ui-border-radius-md) style-outline py-md ps-md pe-xs gap-2.5 items-start"><span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset) shrink-0"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>
3535
<div data-slot="wrapper" class="min-w-0 flex-1 flex flex-col font-[family-name:var(--ui-font-family-primary)]">
3636
<div data-slot="title" class="font-(--ui-font-weight-bold) text-(length:--ui-font-size-md)/(--ui-font-line-height-reset)">Alert</div>
3737
<!--v-if-->

test/components/__snapshots__/Alert.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports[`Alert > renders with as correctly 1`] = `
3131
`;
3232

3333
exports[`Alert > renders with avatar correctly 1`] = `
34-
"<div data-orientation="vertical" data-slot="root" class="relative overflow-hidden w-full flex text-(--b24ui-color) bg-(--b24ui-background) border-(--b24ui-border-color) border-(length:--b24ui-border-width) rounded-(--ui-border-radius-md) style-outline py-md ps-md pe-xs gap-2.5 items-start"><span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset) shrink-0"><img src="https://github.com/bitrix24.png" width="48" height="48" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>
34+
"<div data-orientation="vertical" data-slot="root" class="relative overflow-hidden w-full flex text-(--b24ui-color) bg-(--b24ui-background) border-(--b24ui-border-color) border-(length:--b24ui-border-width) rounded-(--ui-border-radius-md) style-outline py-md ps-md pe-xs gap-2.5 items-start"><span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset) shrink-0"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>
3535
<div data-slot="wrapper" class="min-w-0 flex-1 flex flex-col font-[family-name:var(--ui-font-family-primary)]">
3636
<div data-slot="title" class="font-(--ui-font-weight-bold) text-(length:--ui-font-size-md)/(--ui-font-line-height-reset)">Alert</div>
3737
<!--v-if-->

test/components/__snapshots__/Avatar-vue.spec.ts.snap

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ exports[`Avatar > renders with alt correctly 1`] = `"<span data-slot="root" clas
44

55
exports[`Avatar > renders with as (object) correctly 1`] = `
66
"<section data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)">
7-
<p src="https://github.com/bitrix24.png" width="32" height="32" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></p>
7+
<p src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></p>
88
</section>"
99
`;
1010

11-
exports[`Avatar > renders with as (partial object) correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><p src="https://github.com/bitrix24.png" width="32" height="32" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></p></span>"`;
11+
exports[`Avatar > renders with as (partial object) correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><p src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></p></span>"`;
1212

1313
exports[`Avatar > renders with as correctly 1`] = `"<section data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><span data-slot="fallback" class="font-(--ui-font-weight-medium) text-(--ui-color-design-plain-content-icon-secondary) truncate">&nbsp;</span></section>"`;
1414

@@ -19,30 +19,32 @@ exports[`Avatar > renders with chip correctly 1`] = `
1919
<!----></span></span>"
2020
`;
2121

22-
exports[`Avatar > renders with class correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset) bg-white"><span data-slot="fallback" class="font-(--ui-font-weight-medium) text-(--ui-color-design-plain-content-icon-secondary) truncate">&nbsp;</span></span>"`;
22+
exports[`Avatar > renders with class correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset) bg-default"><span data-slot="fallback" class="font-(--ui-font-weight-medium) text-(--ui-color-design-plain-content-icon-secondary) truncate">&nbsp;</span></span>"`;
23+
24+
exports[`Avatar > renders with custom size correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset) size-100"><img src="https://github.com/bitrix24.png" width="400" height="400" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
2325
2426
exports[`Avatar > renders with default slot correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)">🚀</span>"`;
2527
2628
exports[`Avatar > renders with icon correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" aria-hidden="true" data-slot="icon" class="text-(--ui-color-design-plain-content-icon-secondary) shrink-0 size-[28px]"><path fill="currentColor" fill-rule="evenodd" d="M14.05 15.886a6.37 6.37 0 1 1 1.836-1.837l3.311 3.311a1 1 0 0 1 0 1.414l-.422.423a1 1 0 0 1-1.414 0zm1.058-5.328a4.55 4.55 0 1 1-9.098 0 4.55 4.55 0 0 1 9.099 0" clip-rule="evenodd"></path></svg></span>"`;
2729
28-
exports[`Avatar > renders with size 2xl correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[60px] text-(length:--ui-font-size-5xl)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="60" height="60" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
30+
exports[`Avatar > renders with size 2xl correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[60px] text-(length:--ui-font-size-5xl)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
2931
30-
exports[`Avatar > renders with size 2xs correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[20px] text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)"><img src="https://github.com/bitrix24.png" width="14" height="14" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
32+
exports[`Avatar > renders with size 2xs correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[20px] text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
3133
32-
exports[`Avatar > renders with size 3xl correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[94px] text-[34px]/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="94" height="94" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
34+
exports[`Avatar > renders with size 3xl correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[94px] text-[34px]/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
3335
34-
exports[`Avatar > renders with size 3xs correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[10px] text-4xs font-(--ui-font-weight-regular)"><img src="https://github.com/bitrix24.png" width="10" height="10" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
36+
exports[`Avatar > renders with size 3xs correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[10px] text-4xs font-(--ui-font-weight-regular)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
3537
36-
exports[`Avatar > renders with size lg correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[42px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="42" height="42" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
38+
exports[`Avatar > renders with size lg correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[42px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
3739
38-
exports[`Avatar > renders with size md correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="32" height="32" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
40+
exports[`Avatar > renders with size md correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
3941
40-
exports[`Avatar > renders with size sm correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[28px] text-(length:--ui-font-size-xs)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="22" height="22" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
42+
exports[`Avatar > renders with size sm correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[28px] text-(length:--ui-font-size-xs)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
4143
42-
exports[`Avatar > renders with size xl correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="48" height="48" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
44+
exports[`Avatar > renders with size xl correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring-(--ui-color-base-7) ring-2 size-[48px] text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
4345
44-
exports[`Avatar > renders with size xs correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[24px] text-(length:--ui-font-size-3xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)"><img src="https://github.com/bitrix24.png" width="18" height="18" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
46+
exports[`Avatar > renders with size xs correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[24px] text-(length:--ui-font-size-3xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
4547
46-
exports[`Avatar > renders with src correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" width="32" height="32" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
48+
exports[`Avatar > renders with src correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><img src="https://github.com/bitrix24.png" data-slot="image" class="h-full w-full rounded-[inherit] object-cover"></span>"`;
4749
4850
exports[`Avatar > renders with text correctly 1`] = `"<span data-slot="root" class="air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) size-[32px] text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)"><span data-slot="fallback" class="font-(--ui-font-weight-medium) text-(--ui-color-design-plain-content-icon-secondary) truncate">+1</span></span>"`;

0 commit comments

Comments
 (0)