Skip to content

Commit

Permalink
docs: ✏️ Add examples page
Browse files Browse the repository at this point in the history
  • Loading branch information
dc7290 committed May 21, 2022
1 parent dfd1bdf commit 2472113
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions docs/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,47 @@ description: This page is to introduce examples of use.

## Set the `deviceSizes`

In progress 🏗
```js title="next.config.js"
module.exports = withExportImages({
images: {
deviceSizes: [640, 960, 1280, 1600, 1920],
},
})
```

## Set the `placeholder`

In progress 🏗
```jsx
<Image src="/img.png" width={1280} height={640} alt="" placeholder="blur" />
```

## Use next/image separately from image components to be optimized at build time

In progress 🏗
```tsx title="CMSImage.tsx"
import { ImageLoaderProps, ImageProps } from 'next/image'
import { FC } from 'react'

type Props = ImageProps

const CMSLoader = ({ src, width, quality }: ImageLoaderProps) => {
// Demo: https://static.imgix.net/daisy.png?auto=format&fit=max&w=300
const url = new URL(`${config.path}${normalizeSrc(src)}`)
const params = url.searchParams

params.set('auto', params.get('auto') || 'format')
params.set('fit', params.get('fit') || 'max')
params.set('w', params.get('w') || width.toString())

if (quality) {
params.set('q', quality.toString())
}

return url.href
}

const CMSImage: FC<Props> = (props) => {
return <Image loader={CMSLoader} {...props} />
}

export default CMSImage
```

1 comment on commit 2472113

@vercel
Copy link

@vercel vercel bot commented on 2472113 May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.