Skip to content

Commit

Permalink
fix: image widget contain style
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangtaofeng committed Feb 18, 2024
1 parent 44f83d3 commit d4b9bd2
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions apps/builder/src/widgetLibrary/ImageWidget/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ import {
} from "@/widgetLibrary/ImageWidget/style"
import { AutoHeightContainer } from "@/widgetLibrary/PublicSector/AutoHeightContainer"
import { TooltipWrapper } from "@/widgetLibrary/PublicSector/TooltipWrapper"
import {
DynamicHeight,
ImageWidgetProps,
ObjectFit,
WrappedImageProps,
} from "./interface"
import { DynamicHeight, ImageWidgetProps, WrappedImageProps } from "./interface"

const getHeight = (
dynamicHeight: DynamicHeight,
aspectRatio: number,
width: number,
objectFit?: ObjectFit,
) => {
if (dynamicHeight === "auto") {
if (aspectRatio && aspectRatio > 0) {
Expand All @@ -36,9 +30,7 @@ const getHeight = (
return `${width}px`
}
} else {
return dynamicHeight === "fixed" || objectFit === "contain"
? "100%"
: "auto"
return dynamicHeight === "fixed" ? "100%" : "auto"
}
}

Expand All @@ -62,19 +54,10 @@ export const WrappedImage: FC<WrappedImageProps> = (props) => {
? "100%"
: "auto"

const height = getHeight(
dynamicHeight,
aspectRatio,
imageBouds.width,
objectFit,
)
const height = getHeight(dynamicHeight, aspectRatio, imageBouds.width)

const finalObjectFit =
dynamicHeight === "auto"
? "cover"
: dynamicHeight === "fixed" && objectFit === "contain"
? undefined
: "cover"
const finalObjectFit = dynamicHeight === "auto" ? "cover" : objectFit
console.log("finalObjectFit", finalObjectFit)

return (
<Image
Expand Down

0 comments on commit d4b9bd2

Please sign in to comment.