Skip to content

Commit 6a124cb

Browse files
committed
chore: Update react-image-crop and related dependencies
- Upgrade react-image-crop from 11.0.5 to 11.0.7 - Remove @types/react-image-crop dependency - Modify ImageCrop component to support undefined aspect ratio - Add new CoverImage story demonstrating flexible image cropping
1 parent 1738f36 commit 6a124cb

File tree

4 files changed

+80
-23
lines changed

4 files changed

+80
-23
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@
144144
"@tiptap/extension-youtube": "2.2.4",
145145
"@tiptap/react": "2.2.4",
146146
"@tiptap/suggestion": "2.2.4",
147-
"@types/react-image-crop": "8.1.6",
148147
"boring-avatars": "1.10.1",
149148
"classnames": "2.5.1",
150149
"prosemirror-state": "1.4.3",
151150
"react-colorful": "5.6.1",
152151
"react-copy-to-clipboard": "5.1.0",
153152
"react-datepicker": "7.5.0",
154-
"react-image-crop": "11.0.5",
153+
"react-image-crop": "11.0.7",
155154
"react-select": "5.8.0",
156155
"react-select-async-paginate": "0.7.3",
157156
"react-step-wizard": "5.3.11",

pnpm-lock.yaml

Lines changed: 10 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/ImageCrop/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ImageCrop: FC<IImageCropProps> = ({
2020
setCrop,
2121
circularCrop,
2222
locked,
23-
aspect = 1,
23+
aspect = undefined,
2424
imgCropWrapperClassName,
2525
imgCropClassName
2626
}) => {
@@ -41,6 +41,7 @@ const ImageCrop: FC<IImageCropProps> = ({
4141
centerCrop(
4242
makeAspectCrop(
4343
{
44+
height: crop.height,
4445
unit: crop.unit as PixelCrop["unit"],
4546
width: crop.width
4647
},

src/Components/Inputs/ImageInput/ImageInput.stories.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,71 @@ export const WithImageCrop = () => {
115115
);
116116
};
117117

118+
export const CoverImage = () => {
119+
const [image, setImage] = useState<string>("");
120+
const [croppedImage, setCroppedImage] = useState<string>("");
121+
const [error, setError] = useState<string>("");
122+
const [crop, setCrop] = useState<Crop>({
123+
unit: "px",
124+
width: 1024,
125+
height: 612,
126+
x: 0,
127+
y: 0
128+
});
129+
130+
const args = {
131+
accept: "image/*",
132+
className: "",
133+
maxFileSize: 5000000,
134+
allowedMimeTypes: ["image/jpeg", "image/png"],
135+
compression: { enabled: true },
136+
label: "Select an image",
137+
onFileLoaded: (file: IOnFileLoadedArgs) => {
138+
setImage(file.base64);
139+
}
140+
};
141+
142+
const handleCropComplete = async (croppedImage: Blob) => {
143+
const compressedImage = (await ImageUtils.compress(croppedImage as File, {
144+
maxWidth: 1024,
145+
quality: 0.7
146+
})) as string;
147+
148+
setCroppedImage(compressedImage);
149+
};
150+
151+
return (
152+
<div>
153+
<div className='yl-flex yl-flex-col yl-items-start yl-gap-2'>
154+
{image && (
155+
<ImageCrop
156+
setCrop={setCrop}
157+
crop={crop}
158+
src={image}
159+
onComplete={handleCropComplete}
160+
locked={false}
161+
aspect={undefined}
162+
imgCropWrapperClassName='yl-w-[1024px] yl-h-[612px]'
163+
/>
164+
)}
165+
<br />
166+
{croppedImage && (
167+
<div className='yl-relative yl-h-[192px] yl-w-[1024px]'>
168+
<img
169+
className='yl-absolute yl-h-full yl-w-full bg-yl-left-top object-cover'
170+
src={croppedImage}
171+
/>
172+
</div>
173+
)}
174+
</div>
175+
176+
<ImageInput
177+
{...args}
178+
onValidationError={({ message }) => setError(message)}
179+
error={error}
180+
/>
181+
</div>
182+
);
183+
};
184+
118185
export default ImageInputStories;

0 commit comments

Comments
 (0)