Skip to content

Commit

Permalink
💄 style: Add objectFit props to images
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 1, 2023
1 parent c5d3b57 commit 7e29b7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ImageProps extends AntImageProps {
alwaysShowActions?: boolean;
isLoading?: boolean;
minSize?: number | string;
objectFit?: 'cover' | 'contain';
size?: number | string;
}

Expand All @@ -26,9 +27,10 @@ const Image = memo<ImageProps>(
size = '100%',
actions,
alwaysShowActions,
objectFit = 'cover',
...rest
}) => {
const { styles, cx, theme } = useStyles({ alwaysShowActions, minSize, size });
const { styles, cx, theme } = useStyles({ alwaysShowActions, minSize, objectFit, size });
const mergePreivew = usePreview(preview);

if (isLoading)
Expand Down
10 changes: 8 additions & 2 deletions src/Image/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export const useStyles = createStyles(
minSize,
size,
alwaysShowActions,
}: { alwaysShowActions?: boolean; minSize?: number | string; size?: number | string } = {},
objectFit,
}: {
alwaysShowActions?: boolean;
minSize?: number | string;
objectFit?: string;
size?: number | string;
} = {},
) => {
const SIZE = typeof size === 'number' ? `${size}px` : size;
const MIN_SIZE = typeof minSize === 'number' ? `${minSize}px` : minSize;
Expand Down Expand Up @@ -38,7 +44,7 @@ export const useStyles = createStyles(
height: ${SIZE} !important;
min-height: ${MIN_SIZE} !important;
object-fit: contain;
object-fit: ${objectFit || 'cover'};
}
`,
imageOff: isDarkMode
Expand Down

0 comments on commit 7e29b7d

Please sign in to comment.