This commit is contained in:
seb
2026-10-10 03:08:05 +02:00
parent 454b802943
commit f778b2d104

View File

@@ -4,6 +4,7 @@ import ThumbHashImage from '../article/ThumbHashImage';
import { import {
SHADOW_THUMB_RING, SHADOW_THUMB_RING,
TINT_ROW_HOVER, TINT_ROW_HOVER,
WHITE,
} from '../../colors'; } from '../../colors';
export default class BrandThumb extends PureComponent { export default class BrandThumb extends PureComponent {
@@ -11,6 +12,7 @@ export default class BrandThumb extends PureComponent {
const { const {
brand, brand,
size = 40, size = 40,
padding = 4,
fallback = null, fallback = null,
sx, sx,
} = this.props; } = this.props;
@@ -20,18 +22,21 @@ export default class BrandThumb extends PureComponent {
return fallback; return fallback;
} }
// Inner content area after padding (40px outer - 2 * 4px = 32x32 content).
const content = Math.max(1, size - padding * 2);
const { thumbHash, fullHash, thumbW, thumbH } = pic; const { thumbHash, fullHash, thumbW, thumbH } = pic;
const ratio = thumbW && thumbH ? thumbW / thumbH : 1; const ratio = thumbW && thumbH ? thumbW / thumbH : 1;
// Contain-fit inside a square `size x size` box, preserving aspect ratio. // Contain-fit inside a square `content x content` box, preserving aspect ratio.
let innerW = size; let innerW = content;
let innerH = size; let innerH = content;
if (Number.isFinite(ratio) && ratio > 0) { if (Number.isFinite(ratio) && ratio > 0) {
if (ratio >= 1) { if (ratio >= 1) {
innerW = size; innerW = content;
innerH = Math.max(1, Math.round(size / ratio)); innerH = Math.max(1, Math.round(content / ratio));
} else { } else {
innerH = size; innerH = content;
innerW = Math.max(1, Math.round(size * ratio)); innerW = Math.max(1, Math.round(content * ratio));
} }
} }
@@ -46,11 +51,16 @@ export default class BrandThumb extends PureComponent {
width: size, width: size,
minWidth: size, minWidth: size,
maxWidth: size, maxWidth: size,
p: `${padding}px`,
flexShrink: 0, flexShrink: 0,
verticalAlign: 'middle', verticalAlign: 'middle',
lineHeight: 0, lineHeight: 0,
my: 0, my: 0,
boxSizing: 'border-box', boxSizing: 'border-box',
borderRadius: size >= 24 ? '6px' : '4px',
overflow: 'hidden',
bgcolor: WHITE,
boxShadow: SHADOW_THUMB_RING,
...sx, ...sx,
}} }}
> >
@@ -61,13 +71,12 @@ export default class BrandThumb extends PureComponent {
position: 'relative', position: 'relative',
width: innerW, width: innerW,
height: innerH, height: innerH,
borderRadius: size >= 24 ? '4px' : '3px', borderRadius: size >= 24 ? '3px' : '2px',
overflow: 'hidden', overflow: 'hidden',
flexShrink: 0, flexShrink: 0,
lineHeight: 0, lineHeight: 0,
boxSizing: 'border-box', boxSizing: 'border-box',
bgcolor: TINT_ROW_HOVER, bgcolor: TINT_ROW_HOVER,
boxShadow: SHADOW_THUMB_RING,
}} }}
> >
{thumbHash ? ( {thumbHash ? (