Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { cn } from "cn";
import { useContext } from "react";
import { IconUrlContext } from "@/components/icon/icon-url-context";
import { getLanguageIconUrl } from "@/utils/icon-utils";

type LanguageIconProps = {
Expand All @@ -7,12 +9,15 @@ type LanguageIconProps = {
};

const LanguageIcon = ({ language, className }: LanguageIconProps) => {
const url = getLanguageIconUrl(language);
const resolveUrl = useContext(IconUrlContext);
const languageIconUrl = getLanguageIconUrl(language);

if (!url) {
if (!languageIconUrl) {
return null;
}

const url = resolveUrl(languageIconUrl);

return (
<svg
className={cn("size-3.5 shrink-0", className)}
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/components/icon/icon-url-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createContext } from "react";

type IconUrlResolver = (url: string) => string;

const IconUrlContext = createContext<IconUrlResolver>((url) => url);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Means if no one using this has said anything different, then reuse the same functionality

(that way only mint export will be updated to have this fix)


export { IconUrlContext };
export type { IconUrlResolver };
11 changes: 7 additions & 4 deletions packages/components/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** biome-ignore-all lint/complexity/noExcessiveCognitiveComplexity: TODO */

import { cn } from "cn";
import type { CSSProperties } from "react";
import { type CSSProperties, useContext } from "react";
import { MINTLIFY_ICONS_CDN_URL } from "@/constants";
import { Classes } from "@/constants/selectors";
import {
Expand All @@ -13,6 +13,7 @@ import {
type PageType,
} from "@/utils/icon-utils";
import { isAbsoluteUrl } from "@/utils/is-absolute-url";
import { IconUrlContext } from "./icon-url-context";

type IconProps = {
icon: string;
Expand Down Expand Up @@ -43,6 +44,7 @@ const Icon = ({
overrideColor,
overrideSize,
}: IconProps) => {
const resolveUrl = useContext(IconUrlContext);
const style: CSSProperties = {
...(!overrideSize && { width: size || 16, height: size || 16 }),
display: "inline-block",
Expand All @@ -67,7 +69,7 @@ const Icon = ({
className
);
const isPdf = pageType === "pdf";
const url = getIconUrl(icon.toLowerCase(), iconType, iconLibrary);
const url = resolveUrl(getIconUrl(icon.toLowerCase(), iconType, iconLibrary));

if (iconType && !ICON_TYPES.includes(iconType)) {
console.log(
Expand All @@ -84,15 +86,16 @@ const Icon = ({
icon.startsWith(MINTLIFY_ICONS_CDN_URL) ||
icon.startsWith("https://mintlify.b-cdn.net")
) {
const iconUrl = resolveUrl(icon);
return (
<svg
className={classNames}
data-component-part="icon-svg"
style={{
WebkitMaskImage: `url(${icon})`,
WebkitMaskImage: `url(${iconUrl})`,
WebkitMaskRepeat: "no-repeat",
WebkitMaskPosition: "center",
maskImage: `url(${icon})`,
maskImage: `url(${iconUrl})`,
maskRepeat: "no-repeat",
maskPosition: "center",
maskSize: "100%",
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/components/icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export type { IconProps } from "./icon";
export { Icon } from "./icon";
export type { IconUrlResolver } from "./icon-url-context";
export { IconUrlContext } from "./icon-url-context";
Loading