-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add docs for prefer-ideal-image rule
Signed-off-by: Devansu <devansuyadav@gmail.com>
- Loading branch information
1 parent
b28b8fd
commit 6016b36
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
website/docs/api/misc/eslint-plugin/prefer-ideal-image.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
slug: /api/misc/@docusaurus/eslint-plugin/prefer-ideal-image | ||
--- | ||
|
||
# prefer-ideal-image | ||
|
||
Ensure that the `<IdealImage />` component provided by [`@theme/IdealImage`](../../plugins/plugin-ideal-image.mdx) Docusaurus plugin is used instead of `<img>` tags. | ||
|
||
The `@theme/IdealImage` Docusaurus plugin generates an almost ideal image (responsive, lazy-loading, and low quality placeholder). | ||
|
||
## Rule Details {#details} | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```html | ||
<img src="./path/to/img.png" alt="some alt text" /> | ||
|
||
<img src={require('./path/to/img.png')} alt='some alt text' /> | ||
|
||
<img | ||
src="./path/to/img.png" | ||
srcset="./path/to/img-480w.jpg 480w, ./path/to/img-800w.png 800w" | ||
sizes="(max-width: 600px) 480px, 800px" | ||
alt="some alt text" /> | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```javascript | ||
import Image from '@theme/IdealImage'; | ||
|
||
<IdealImage img='./path/to/img.png' /> | ||
|
||
<IdealImage img={require('./path/to/img.png')} /> | ||
|
||
<IdealImage | ||
img={{ | ||
src: { | ||
src: './path/to/img.png', | ||
preSrc: '', | ||
images: [{ width: 100 }] | ||
}, | ||
preSrc: './path/to/placeholder.png' | ||
}} | ||
/> | ||
``` |