Skip to content

Commit

Permalink
[@mantine/core] Image: Fix incorrect placeholder size calculation whe…
Browse files Browse the repository at this point in the history
…n width/height is not set (#2675)

* [docs] Fix typo (#2604)

* [@mantine/core] Image: Add div around placeholder

Co-authored-by: Alf <62615304+Alf-Melmac@users.noreply.github.com>
  • Loading branch information
MrOnosa and Alf-Melmac committed Oct 18, 2022
1 parent 6aa574a commit 5ffaf87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/mantine-core/src/Image/Image.story.tsx
@@ -1,8 +1,10 @@
import React, { useEffect, useState } from 'react';
import { storiesOf } from '@storybook/react';
import { useInterval } from '@mantine/hooks';
import { MantineProvider } from '@mantine/styles';
import { Container } from '../Container';
import { Image } from './Image';
import { AspectRatio } from '../AspectRatio';

const images = [
'https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3748&q=80',
Expand Down Expand Up @@ -36,4 +38,18 @@ storiesOf('Image', module)
<Container size={60}>
<Image radius="sm" src={null} withPlaceholder width={50} height={50} />
</Container>
))
.add('Responsive Image with AspectRatio', () => (
<MantineProvider withGlobalStyles withNormalizeCSS>
<div style={{ width: 400, padding: 20, backgroundColor: '#fdf' }}>
<p>Responsive Image with AspectRatio</p>
<AspectRatio ratio={2}>
<Image src="https://picsum.photos/600/600" withPlaceholder />
</AspectRatio>
<p>Responsive Placeholder with AspectRatio</p>
<AspectRatio ratio={2}>
<Image withPlaceholder />
</AspectRatio>
</div>
</MantineProvider>
));
6 changes: 5 additions & 1 deletion src/mantine-core/src/Image/Image.tsx
Expand Up @@ -115,7 +115,11 @@ export const Image = forwardRef<HTMLDivElement, ImageProps>((props: ImageProps,

{isPlaceholder && (
<div className={classes.placeholder} title={alt}>
{placeholder || <ImageIcon style={{ width: 40, height: 40 }} />}
{placeholder || (
<div>
<ImageIcon style={{ width: 40, height: 40 }} />
</div>
)}
</div>
)}
</div>
Expand Down

0 comments on commit 5ffaf87

Please sign in to comment.