chore(pwa, sitemap, client-redirects, ideal-image): JSDoc for types (#6928)

* chore(pwa, sitemap, client-redirects, ideal-image): JSDoc for types

* fix
This commit is contained in:
Joshua Chen 2022-03-17 12:05:23 +08:00 committed by GitHub
parent 284649c7c8
commit bfe7ca6237
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 129 additions and 52 deletions

View file

@ -14,8 +14,7 @@ declare module '@docusaurus/plugin-ideal-image' {
/**
* Specify all widths you want to use; if a specified size exceeds the
* original image's width, the latter will be used (i.e. images won't be
* scaled up). You may also declare a default sizes array in the loader
* options in your webpack.config.js.
* scaled up).
*/
sizes?: number[];
/**
@ -25,16 +24,17 @@ declare module '@docusaurus/plugin-ideal-image' {
*/
size?: number;
/**
* As an alternative to manually specifying sizes, you can specify min, max
* and steps, and the sizes will be generated for you.
* As an alternative to manually specifying `sizes`, you can specify `min`,
* `max` and `steps`, and the `sizes` will be generated for you.
*/
min?: number;
/**
* See min above
* @see {@link PluginOptions.min}
*/
max?: number;
/**
* Configure the number of images generated between min and max (inclusive)
* Configure the number of images generated between `min` and `max`
* (inclusive)
*/
steps?: number;
/**
@ -42,7 +42,8 @@ declare module '@docusaurus/plugin-ideal-image' {
*/
quality?: number;
/**
* Just use regular images in dev mode
* You can test ideal image behavior in dev mode by setting this to `false`.
* Tip: use network throttling in your browser to simulate slow networks.
*/
disableInDev?: boolean;
};

View file

@ -15,7 +15,7 @@ import {translate} from '@docusaurus/Translate';
import type {Props} from '@theme/IdealImage';
// Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/helpers.js#L59-L65
const bytesToSize = (bytes: number) => {
function bytesToSize(bytes: number) {
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) {
return 'n/a';
@ -25,10 +25,10 @@ const bytesToSize = (bytes: number) => {
return `${bytes} ${sizes[scale]}`;
}
return `${(bytes / 1024 ** scale).toFixed(1)} ${sizes[scale]}`;
};
}
// Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/IdealImage/index.js#L43-L75
const getMessage = (icon: IconKey, state: State) => {
function getMessage(icon: IconKey, state: State) {
switch (icon) {
case 'noicon':
case 'loaded':
@ -78,7 +78,7 @@ const getMessage = (icon: IconKey, state: State) => {
default:
throw new Error(`Wrong icon: ${icon}`);
}
};
}
export default function IdealImage(props: Props): JSX.Element {
const {alt, className, img} = props;