Skip to content

Commit

Permalink
add next.js image integration
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Jun 8, 2022
1 parent 19791ff commit dbf998b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/data/joy/components/aspect-ratio/aspect-ratio.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ When the aspect ratio component is placed as a child of a flexbox `row` containe

{{"demo": "FlexRowRatio.js"}}

## Integration

### Next.js Image

The `AspectRatio` component can be used with [Next.js Image](https://nextjs.org/docs/basic-features/image-optimization) component.

```js
import Image from 'next/image';
import AspectRatio from '@mui/joy/AspectRatio';
import mountains from '../public/mountains.jpg';

function App() {
return (
<AspectRatio variant="outlined" ratio="1" objectFit="cover">
{/* only layout="fill" makes sense for using with AspectRatio */}
<Image alt="Mountains" src={mountains} layout="fill" placeholder="blur" />
</AspectRatio>
);
}
```

:::info
Always use `layout="fill"` on the image component, otherwise you don't need to use aspect ratio because the height is based on the image.
:::

## Common examples

### Mobile Carousel
Expand Down

0 comments on commit dbf998b

Please sign in to comment.