generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use blob url instead of data url for svg, create specal classes for s…
…troke
- Loading branch information
Showing
3 changed files
with
68 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,46 @@ | ||
import { ThemedSvg } from "./ThemedSvg"; | ||
import { ThemedSvg, useThemedSvgAsBlobUrl } from "./ThemedSvg"; | ||
import { | ||
type ThemedAssetUrl, | ||
useResolveThemedAssetUrl, | ||
} from "./lib/ThemedAssetUrl"; | ||
import { getSafeUrl } from "./tools/getSafeUrl"; | ||
|
||
type Props = { | ||
className?: string; | ||
url: ThemedAssetUrl; | ||
alt?: string; | ||
}; | ||
|
||
function getIsSvg(url: string) { | ||
return url.split("?")[0].endsWith(".svg"); | ||
} | ||
|
||
export function ThemedImage(props: Props) { | ||
const { className, alt = "" } = props; | ||
|
||
const { resolveThemedAssetUrl } = useResolveThemedAssetUrl(); | ||
|
||
const url = resolveThemedAssetUrl(props.url); | ||
|
||
return url.split("?")[0].endsWith(".svg") ? ( | ||
return getIsSvg(url) ? ( | ||
<ThemedSvg svgUrl={url} className={className} /> | ||
) : ( | ||
<img src={getSafeUrl(url)} alt={alt} className={className} /> | ||
<img src={url} alt={alt} className={className} /> | ||
); | ||
} | ||
|
||
export function useThemedImageUrl( | ||
themedAssetUrl: ThemedAssetUrl | undefined, | ||
): string | undefined { | ||
const { resolveThemedAssetUrl } = useResolveThemedAssetUrl(); | ||
|
||
const url = | ||
themedAssetUrl === undefined | ||
? undefined | ||
: resolveThemedAssetUrl(themedAssetUrl); | ||
|
||
const svgDataUrl = useThemedSvgAsBlobUrl( | ||
url === undefined ? undefined : getIsSvg(url) ? url : undefined, | ||
); | ||
|
||
return url === undefined ? undefined : getIsSvg(url) ? svgDataUrl : url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters