An open source design system that's fully customizable and agent ready
TypeScript
fix(core): Thumbnail remove button uses fixed overlay contrast (#4345)
Kenton Quatman3588c450b359
diff --git a/.changeset/thumbnail-remove-fixed-contrast.md b/.changeset/thumbnail-remove-fixed-contrast.mdnew file mode 100644index 0000000000..c1a2fc35bb--- /dev/null+++ b/.changeset/thumbnail-remove-fixed-contrast.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Thumbnail: the overlaid remove button now uses a fixed `--color-overlay` scrim with an `--color-on-dark` icon instead of adapting to the image's luminance, so it has reliable contrast on any image.+@kentonquatmandiff --git a/packages/core/src/Thumbnail/Thumbnail.doc.mjs b/packages/core/src/Thumbnail/Thumbnail.doc.mjsindex 850758787c..a8ca26fb28 100644--- a/packages/core/src/Thumbnail/Thumbnail.doc.mjs+++ b/packages/core/src/Thumbnail/Thumbnail.doc.mjs@@ -84,7 +84,7 @@ export const docs = {anatomy: [{name: 'Image', required: false, description: 'The preview image, displayed as a square with cover fit.'},{name: 'Placeholder', required: false, description: 'An image silhouette icon shown when no src is provided.'},- {name: 'Remove button', required: false, description: 'An overlaid close button in the top-right corner. Appears when onRemove is set. Uses APCA luminance detection to stay visible on any image.'},+ {name: 'Remove button', required: false, description: 'An overlaid close button in the top-right corner. Appears when onRemove is set. Sits on a fixed --color-overlay scrim with an --color-on-dark icon to stay visible on any image.'},{name: 'Upload overlay', required: false, description: 'A semi-transparent overlay with a spinner, shown when isLoading is true and a src preview is available.'},{name: 'Skeleton', required: false, description: 'A shimmer animation shown when isLoading is true and no src is set.'},],diff --git a/packages/core/src/Thumbnail/Thumbnail.tsx b/packages/core/src/Thumbnail/Thumbnail.tsxindex 44d8697ccb..88aba7c895 100644--- a/packages/core/src/Thumbnail/Thumbnail.tsx+++ b/packages/core/src/Thumbnail/Thumbnail.tsx@@ -4,14 +4,14 @@/*** @file Thumbnail.tsx- * @input Uses React, stylex, Button, Skeleton, Spinner, MediaTheme, useImageMode+ * @input Uses React, stylex, Button, Skeleton, Spinner* @output Exports Thumbnail component, ThumbnailProps* @position Core implementation; consumed by index.ts** Square preview card for image attachments. Shows a skeleton shimmer while* the image loads, the image on success, or a placeholder on failure.- * Uses useImageMode (APCA) to detect image luminance so the overlaid- * remove button always has sufficient contrast.+ * The overlaid remove button sits on a fixed --color-overlay scrim with an+ * --color-on-dark icon so it always has sufficient contrast against the image.** Images without `alt` are explicitly decorative (alt="" +* role="presentation" + aria-hidden, matching Avatar). A dev-time warning@@ -39,17 +39,12 @@ import {Icon} from '../Icon';import {Skeleton} from '../Skeleton';import {Spinner} from '../Spinner';import {Tooltip} from '../Tooltip/Tooltip';-import {MediaTheme} from '../theme/MediaTheme';-import {useImageMode} from '../hooks/useImageMode';import {useDevWarning} from '../hooks/useDevWarning';import type {BaseProps} from '../BaseProps';import {mergeProps} from '../utils';import {themeProps} from '../utils/themeProps';import {useTranslator} from '../i18n';-/** Sample the region behind the remove button (20px button, 4px inset, in 64px container). */-const BUTTON_REGION = {x: 0.5, y: 0.06, width: 0.44, height: 0.44};-export interface ThumbnailProps extends BaseProps<HTMLDivElement> {/** Ref forwarded to the root element */ref?: React.Ref<HTMLDivElement>;@@ -195,6 +190,11 @@ const styles = stylex.create({'--_button-radius': `calc(${radiusVars['--radius-element']} - ${spacingVars['--spacing-1']})`,height: 20,minWidth: 20,+ // Fixed colors instead of luminance-adapting theme: a translucent scrim+ // (--color-overlay) plus an --color-on-dark icon reads on any image+ // without sampling pixel brightness.+ backgroundColor: colorVars['--color-overlay'],+ color: colorVars['--color-on-dark'],},disabled: {opacity: 0.5,@@ -241,8 +241,9 @@ function ImagePlaceholder() {* a placeholder icon on failure / when no src is provided. An overlaid* remove button appears when `onRemove` is set.*- * Uses `useImageMode` (APCA) to detect image luminance and `MediaTheme`- * to ensure the remove button always has sufficient contrast against the image.+ * The remove button uses a fixed `--color-overlay` scrim with an+ * `--color-on-dark` icon so it stays legible on any image without sampling+ * the image's luminance.** @example* ```@@ -266,7 +267,6 @@ export function Thumbnail({...props}: ThumbnailProps) {const t = useTranslator();- const imageMode = useImageMode(src, {region: BUTTON_REGION, fallback: null});const hasSrc = src != null;const showSkeleton = isLoading && !hasSrc;@@ -374,11 +374,7 @@ export function Thumbnail({<Spinner size="sm" shade="onMedia" /></div>)}- {removeButtonEl != null && imageMode != null ? (- <MediaTheme mode={imageMode}>{removeButtonEl}</MediaTheme>- ) : (- removeButtonEl- )}+ {removeButtonEl}</div></div>);