Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Image extraProps #682

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/blocks/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export const TabsBlock = ({

if (activeTabData.caption && imageProps) {
Object.assign(imageProps, {
'aria-describedby': captionId,
extraProps: {
'aria-describedby': captionId,
},
});
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/FullscreenImage/FullscreenImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import i18n from './i18n';

import './FullscreenImage.scss';

export interface FullscreenImageProps extends ImageProps {
export interface FullscreenImageProps extends Omit<ImageProps, 'extraProps'> {
imageClassName?: string;
modalImageClass?: string;
imageStyle?: CSSProperties;
Expand All @@ -22,7 +22,8 @@ const FULL_SCREEN_ICON_SIZE = 18;
const CLOSE_ICON_SIZE = 30;

const FullscreenImage = (props: FullscreenImageProps) => {
const {imageClassName, modalImageClass, imageStyle, alt = i18n('img-alt'), extraProps} = props;
const {imageClassName, modalImageClass, imageStyle, alt = i18n('img-alt')} = props;
const {extraProps, ...imageProps} = props;
const [isOpened, setIsOpened] = useState(false);

const openModal = () => setIsOpened(true);
Expand All @@ -32,7 +33,7 @@ const FullscreenImage = (props: FullscreenImageProps) => {
<div className={b()} {...extraProps}>
<div className={b('image-wrapper')}>
<Image
{...props}
{...imageProps}
alt={alt}
className={b('image', imageClassName)}
onClick={openModal}
Expand Down Expand Up @@ -62,7 +63,7 @@ const FullscreenImage = (props: FullscreenImageProps) => {
className={b('icon', {hover: true})}
/>
</button>
<Image {...props} className={b('modal-image', modalImageClass)} />
<Image {...imageProps} className={b('modal-image', modalImageClass)} />
</div>
</Modal>
)}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {
CSSProperties,
Fragment,
HTMLProps,
MouseEventHandler,
ReactEventHandler,
useContext,
Expand All @@ -12,14 +13,15 @@ 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;
onLoad?: ReactEventHandler<HTMLDivElement>;
containerClassName?: string;
extraProps?: Omit<HTMLProps<HTMLImageElement>, keyof ImageBaseProps>;
}

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

Expand Down Expand Up @@ -123,6 +126,7 @@ const Image = (props: ImageProps) => {
onClick={onClick}
onError={() => setImgLoadingError(true)}
onLoad={onLoad}
{...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
Loading