Fix FontAwesome 7 icon overflows (#3885)

This commit is contained in:
Zeno Kapitein
2026-01-05 13:56:08 +01:00
committed by GitHub
parent 695e99f466
commit 360b525b4b
4 changed files with 34 additions and 14 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"gitbook": patch
"@gitbook/icons": patch
---
Switch icon masking method to fix visual cutoffs in FA7
+1 -1
View File
@@ -1291,7 +1291,7 @@ const testCases: TestsCase[] = [
name: 'Redirect to Quickstart page',
url: 'sections-2/redirect-test',
run: async (page) => {
await expect(page.locator('h1')).toHaveText('Quickstart');
await expect(page.locator('h1')).toContainText('Quickstart');
},
screenshot: false,
},
+6 -5
View File
@@ -417,14 +417,15 @@ export async function waitForIcons(page: Page) {
return true;
}
// url("https://ka-p.fontawesome.com/releases/v6.6.0/svgs/light/moon.svg?v=2&token=a463935e93")
const maskImage = window.getComputedStyle(icon).getPropertyValue('mask-image');
const urlMatch = maskImage.match(/url\("([^"]+)"\)/);
const url = urlMatch?.[1];
const maskImage = icon.querySelector('[data-testid="mask-image"]');
if (!maskImage) {
throw new Error('No mask-image element');
}
const url = maskImage.getAttribute('href');
// If URL is invalid we throw an error.
if (!url) {
throw new Error('No mask-image');
throw new Error('No mask-image url');
}
// If the URL is already queued for loading, we return the state.
+21 -8
View File
@@ -51,23 +51,36 @@ export const Icon = React.forwardRef(function Icon(
const [iconStyle, icon] = getIconStyle(propIconStyle, propIcon);
const url = getIconAssetURL(context, iconStyle, icon);
const maskId = React.useId();
return (
<svg
ref={ref}
{...rest}
style={{
maskImage: `url(${url})`,
WebkitMaskImage: `url(${url})`,
maskRepeat: 'no-repeat',
WebkitMaskRepeat: 'no-repeat',
maskPosition: 'center',
WebkitMaskPosition: 'center',
backgroundColor: 'currentColor',
...(size ? { width: size, height: size } : {}),
...rest.style,
}}
className={`gb-icon ${className}`}
/>
>
<title>{icon}</title>
<defs>
<mask
id={maskId}
style={{
maskType: 'alpha',
}}
>
<image
data-testid="mask-image"
href={url}
width="100%"
height="100%"
preserveAspectRatio="xMidYMid meet"
/>
</mask>
</defs>
<rect width="100%" height="100%" fill="currentColor" mask={`url(#${maskId})`} />
</svg>
);
});