Skip to content

Commit

Permalink
fix: pick items imgCommonProps
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Jun 17, 2023
1 parent 393ed0a commit 360829a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface CompoundedComponent<P> extends React.FC<P> {

type ImageStatus = 'normal' | 'error' | 'loading';

const COMMON_PROPS: (keyof ImageElementProps)[] = [
export const COMMON_PROPS: (keyof Omit<ImageElementProps, 'src'>)[] = [
'crossOrigin',
'decoding',
'draggable',
Expand Down
23 changes: 19 additions & 4 deletions src/hooks/usePreviewItems.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as React from 'react';
import type { InternalItem, PreviewImageElementProps, RegisterImage } from '../interface';
import { COMMON_PROPS } from '..';
import type {
ImageElementProps,
InternalItem,
PreviewImageElementProps,
RegisterImage,
} from '../interface';
import type { GroupConsumerProps } from '../PreviewGroup';

export type Items = Omit<InternalItem, 'canPreview'>[];
Expand Down Expand Up @@ -31,9 +37,18 @@ export default function usePreviewItems(
// items
const mergedItems = React.useMemo<Items>(() => {
if (items) {
return items.map(item =>
typeof item === 'string' ? { data: { src: item } } : { data: item },
);
return items.map(item => {
if (typeof item === 'string') {
return { data: { src: item } };
}
const data: ImageElementProps = {};
Object.keys(items).forEach(key => {
if (['src', ...COMMON_PROPS].includes(key)) {
data[key] = items[key];
}
});
return { data };
});
}

return Object.keys(images).reduce((total: Items, id) => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "esnext",
"moduleResolution": "node",
"baseUrl": "./",
"jsx": "react",
"jsx": "preserve",
"declaration": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down

0 comments on commit 360829a

Please sign in to comment.