Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyManetov committed Nov 14, 2023
2 parents bb937d4 + fe987f7 commit f998753
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[DataTable]: fix checkboxes, now they always pinned to the left column
[PickerInput]: Disable select all button if options are empty and it has no selection
[DataTable]: fixed missing `role=table`
[SlateEditor]: allow writing caption after image insertion

# 5.2.0 - 16.10.2023

Expand Down
64 changes: 35 additions & 29 deletions uui-editor/src/plugins/imagePlugin/ImageElement.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import {
Box,
PlateElement,
Expand Down Expand Up @@ -49,16 +49,17 @@ export function ImageElement({

useMediaState();

const [currentWidth] = useResizableStore().use.width();
const isCaptionEnabled = useMemo(() => {
let captionEnabled = false;
if (currentWidth && typeof currentWidth === 'number') {
captionEnabled = currentWidth >= MIN_CAPTION_WIDTH;
}
const imageRef = useRef(null);
const [currentWidth, setWidth] = useResizableStore().use.width();

return captionEnabled;
const isCaptionEnabled = useMemo(() => {
return typeof currentWidth === 'number' && currentWidth >= MIN_CAPTION_WIDTH;
}, [currentWidth]);

const imageUpdated = () => {
setWidth(imageRef.current.width);
};

return (
<PlateElement className={ cx(className) } { ...props }>
<figure className={ cx(css.group) } contentEditable={ false }>
Expand All @@ -68,46 +69,51 @@ export function ImageElement({
renderHandleLeft: (htmlProps) => (
<Box
{ ...htmlProps }
className={ cx(css.leftHandle, ...resizeHandleClasses) }
className={ cx(
css.leftHandle,
...resizeHandleClasses,
) }
/>
),
renderHandleRight: (htmlProps) => (
<Box
{ ...htmlProps }
className={ cx(css.rightHandle, ...resizeHandleClasses) }
className={ cx(
css.rightHandle,
...resizeHandleClasses,
) }
/>
),
align,
readOnly,
minWidth: MAX_IMG_WIDTH,
} }
>
{ }
{}
<Image
{ ...nodeProps }
className={
cx(
css.image,
focused && selected && css.selectedImage, // for mobile
nodeProps?.className,
)
}
className={ cx(
css.image,
focused && selected && css.selectedImage, // for mobile
nodeProps?.className,
) }
ref={ imageRef }
onLoad={ imageUpdated }
/>
</Resizable>

{ isCaptionEnabled
&& (
<Caption className={ cx(css.imageCaption, ...aligns) }>
<CaptionTextarea
className={ cx(css.caption) }
placeholder="Write a caption..."
readOnly={ readOnly }
/>
</Caption>
)}
{isCaptionEnabled && (
<Caption style={ { width: currentWidth } } className={ cx(css.imageCaption, ...aligns) }>
<CaptionTextarea
className={ cx(css.caption) }
placeholder="Write a caption..."
readOnly={ readOnly }
/>
</Caption>
)}
</figure>

{ children }
{children}
</PlateElement>
);
}

0 comments on commit f998753

Please sign in to comment.