Files
supabase/apps/studio/components/ui/ProviderIcon.tsx
Alaister YoungandAlaister Young 87b9d0562e [FE-5111] refactor(studio): replace next/image shims with plain img (#54011)
Replaces all remaining `next/image` and `next/legacy/image` imports in
`apps/studio` with plain `<img>` elements and deletes both compat shims
and their Vite aliases (following #53906, which removed the last
`next/image` import from `packages/ui-patterns`).

**Changed:**

- Replaced 26 `next/image` and 3 `next/legacy/image` call sites across
`apps/studio` with plain `<img>` elements (every local `src` already
prepends `BASE_PATH` / `router.basePath`, and none used `loader`,
`priority`, `placeholder`, `quality`, or `onLoadingComplete`)
- Converted `fill` / `layout="fill"` usages in `IntegrationCard`,
`MarketplaceFeaturedHeroGrid`, `Integrations.constants`,
`useAvailableIntegrations`, and `IntegrationPanels` to Tailwind sizing
classes, and dropped no-op `layout="fixed"` props in `FormContents` and
`HookList`
- Replaced invalid `layout="fill" objectFit="cover"` props passed to
`next/image` in `HelpPanel` with `absolute inset-0 h-full w-full
object-cover`
- Cleaned up image accessibility across the touched call sites (accurate
alt text on feature preview screenshots and `HookList`, `alt=""` +
`aria-hidden="true"` on decorative icons/illustrations next to visible
labels)

**Removed:**

- `apps/studio/compat/next/image.tsx`
- `apps/studio/compat/next/legacy/image.tsx`
- `'next/image'` and `'next/legacy/image'` aliases from
`apps/studio/vite.config.ts`

## To test

- Confirm `git grep -E "next/(legacy/)?image" apps/studio/` has no
remaining imports
- Check images render as expected across the updated surfaces:
- **Integrations marketplace** (`/project/_/integrations`): featured
hero covers (`MarketplaceFeaturedHeroGrid`), integration icons in cards,
sidebar, and wrapper rows (`Integrations.constants`,
`useAvailableIntegrations`)
  - **Help panel**: Discord card background illustration
- **Account & settings**: Account Connections GitHub icon, Add-ons cards
(IPv4 / PITR / Custom Domain), Spend Cap card & side panel, user profile
avatars (`ProfileImage`), and Feature Previews modal images
- **Database Webhooks** (`FormContents`, `HookList`) and Third-Party
Auth provider dropdown/cards

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-26 16:23:41 +08:00

58 lines
1.7 KiB
TypeScript

import { cn } from 'ui'
import type { IdentityProviderDisplay } from '@/lib/external-identity-providers'
/**
* Renders a monochrome identity-provider mark as a CSS mask so it inherits the current theme's
* foreground color. The provider SVGs use `currentColor`, which a plain `<img>` would
* not respect (it would render the icon's literal fill and need a `dark:invert` hack). Masking tints
* any provider mark correctly in every theme, regardless of how its SVG is colored.
*
* Size via `size` (pixels) or `className` (e.g. `size-7`, `size-[30px]`).
*/
export const ProviderIcon = ({
src,
alt,
size,
className,
}: {
src: string
alt: string
size?: number
className?: string
}) => (
<span
role="img"
aria-label={alt}
className={cn('inline-block shrink-0 bg-foreground', className)}
style={{
...(size !== undefined ? { width: size, height: size } : undefined),
maskImage: `url(${src})`,
maskRepeat: 'no-repeat',
maskPosition: 'center',
maskSize: 'contain',
WebkitMaskImage: `url(${src})`,
WebkitMaskRepeat: 'no-repeat',
WebkitMaskPosition: 'center',
WebkitMaskSize: 'contain',
}}
/>
)
/**
* Renders the icon for a provider's display metadata (see `getProviderDisplay`): monochrome marks
* are tinted to the theme via {@link ProviderIcon}, colored icons render as-is.
*/
export const IdentityProviderIcon = ({
display,
size = 20,
}: {
display: IdentityProviderDisplay
size?: number
}) =>
display.hasMonochromeIcon ? (
<ProviderIcon src={display.iconPath} alt={`${display.displayName} icon`} size={size} />
) : (
<img src={display.iconPath} width={size} height={size} alt={`${display.displayName} icon`} />
)