Skip to content

Commit

Permalink
feat: using extraProps in Image
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmch committed Nov 8, 2023
1 parent c3c02ff commit c0ae384
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/blocks/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const TabsBlock = ({
imageProps = themedImage && getMediaImage(themedImage);
if (activeTabData.caption && imageProps) {
Object.assign(imageProps, {
'aria-describedby': captionId,
extraProps: {
'aria-describedby': captionId,
},
});
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import React, {CSSProperties, Fragment, MouseEventHandler, useContext, useState} from 'react';
import React, {
CSSProperties,
Fragment,
HTMLProps,
MouseEventHandler,
useContext,
useState,
} from 'react';

import {BREAKPOINTS} from '../../constants';
import {ProjectSettingsContext} from '../../context/projectSettingsContext';
import {ImageDeviceProps, ImageObjectProps, QAProps} from '../../models';
import {getQaAttrubutes} from '../../utils';
import {isCompressible} from '../../utils/imageCompress';
import ImageBase from '../ImageBase/ImageBase';
import ImageBase, {ImageBaseProps} from '../ImageBase/ImageBase';

export interface ImageProps extends Partial<ImageObjectProps>, Partial<ImageDeviceProps>, QAProps {
style?: CSSProperties;
className?: string;
onClick?: MouseEventHandler;
containerClassName?: string;
extraProps?: Omit<HTMLProps<HTMLImageElement>, keyof ImageBaseProps>;
}

export interface DeviceSpecificFragmentProps extends QAProps {
Expand Down Expand Up @@ -57,6 +65,7 @@ const Image = (props: ImageProps) => {
onClick,
containerClassName,
qa,
extraProps,
} = props;
const [imgLoadingError, setImgLoadingError] = useState(false);

Expand Down Expand Up @@ -113,6 +122,7 @@ const Image = (props: ImageProps) => {
style={style}
onClick={onClick}
onError={() => setImgLoadingError(true)}
{...extraProps}
/>
</picture>
);
Expand Down
2 changes: 1 addition & 1 deletion src/models/constructor-items/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ interface LoopProps {

// images

export interface ImageInfoProps extends Pick<HTMLProps<HTMLImageElement>, 'aria-describedby'> {
export interface ImageInfoProps {
alt?: string;
disableCompress?: boolean;
}
Expand Down

0 comments on commit c0ae384

Please sign in to comment.