Skip to content

Commit c6c8d09

Browse files
committed
Extended ImageCrop component with additional image props
1 parent 0e0e887 commit c6c8d09

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.29",
3+
"version": "1.0.30",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {
Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
import { Meta, Story } from "@storybook/react";
1+
import { Meta } from "@storybook/react";
2+
import { useState } from "react";
3+
import { Crop } from "react-image-crop";
24

35
import image from "../../../assets/images/image-crop.png";
46
import ImageCrop from "./";
5-
import { IImageCropProps } from "./types";
67

78
export default {
89
title: "Components/ImageCrop",
910
component: ImageCrop
1011
} as Meta;
1112

12-
const Template: Story<IImageCropProps> = args => <ImageCrop {...args} />;
13-
14-
export const Default = Template.bind({});
15-
Default.args = {
16-
src: image,
17-
crop: {
13+
export const Default = () => {
14+
const [crop, setCrop] = useState<Crop>({
1815
width: 150,
1916
height: 150,
2017
unit: "px",
2118
x: 0,
2219
y: 0
23-
},
24-
circularCrop: false,
25-
aspect: 1,
26-
cropAreaClassName: "custom-crop-area-class",
27-
locked: false,
28-
setCrop: () => {}
29-
};
30-
31-
export const CircularCrop = Template.bind({});
32-
CircularCrop.args = {
33-
...Default.args,
34-
circularCrop: true,
35-
locked: false
20+
});
21+
return (
22+
<ImageCrop
23+
src={image}
24+
crop={crop}
25+
circularCrop={false}
26+
aspect={1}
27+
locked={false}
28+
setCrop={setCrop}
29+
/>
30+
);
3631
};

src/Components/ImageCrop/index.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const ImageCrop: FC<IImageCropProps> = ({
2121
circularCrop,
2222
locked,
2323
aspect = 1,
24-
cropAreaClassName
24+
imgCropWrapperClassName,
25+
imgCropClassName
2526
}) => {
2627
const previewCanvasRef = useRef(null);
2728
const imgRef = useRef(null);
@@ -116,13 +117,22 @@ const ImageCrop: FC<IImageCropProps> = ({
116117
keepSelection
117118
circularCrop={circularCrop}
118119
>
119-
<img
120-
className={classNames(cropAreaClassName)}
121-
ref={imgRef}
122-
alt='Crop me'
123-
src={src}
124-
onLoad={onImageLoad}
125-
/>
120+
<div
121+
className={classNames(imgCropWrapperClassName, {
122+
"relative h-[350px] w-[350px]": !imgCropWrapperClassName
123+
})}
124+
>
125+
<img
126+
className={classNames(imgCropClassName, {
127+
"absolute h-full w-full bg-left-top object-cover":
128+
!imgCropClassName
129+
})}
130+
ref={imgRef}
131+
alt='Crop me'
132+
src={src}
133+
onLoad={onImageLoad}
134+
/>
135+
</div>
126136
</ReactCrop>
127137
)}
128138
</div>

src/Components/ImageCrop/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export interface IImageCropProps {
99
locked?: boolean;
1010
circularCrop?: boolean;
1111
aspect?: number;
12-
cropAreaClassName?: string;
12+
imgCropWrapperClassName?: string;
13+
imgCropClassName?: string;
1314
}

src/Components/ImageInput/ImageInput.stories.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,21 @@ export const WithImageCrop = () => {
9090
<div className='flex items-start gap-2'>
9191
{image && (
9292
<ImageCrop
93-
cropAreaClassName='max-w-[600px] max-h-[600px] min-w-[600px]'
9493
setCrop={setCrop}
9594
crop={crop}
9695
src={image}
9796
onComplete={handleCropComplete}
9897
locked={false}
9998
/>
10099
)}
101-
{croppedImage && <img src={croppedImage} />}
100+
{croppedImage && (
101+
<div className='relative h-[150px] w-[150px]'>
102+
<img
103+
className='absolute h-full w-full bg-left-top object-cover'
104+
src={croppedImage}
105+
/>
106+
</div>
107+
)}
102108
</div>
103109

104110
<ImageInput

0 commit comments

Comments
 (0)