File tree Expand file tree Collapse file tree 5 files changed +45
-33
lines changed Expand file tree Collapse file tree 5 files changed +45
-33
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @programmer_network/yail" ,
3
- "version" : " 1.0.29 " ,
3
+ "version" : " 1.0.30 " ,
4
4
"description" : " Programmer Network's official UI library for React" ,
5
5
"author" : " Aleksandar Grbic - (https://programmer.network)" ,
6
6
"publishConfig" : {
Original file line number Diff line number Diff line change 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" ;
2
4
3
5
import image from "../../../assets/images/image-crop.png" ;
4
6
import ImageCrop from "./" ;
5
- import { IImageCropProps } from "./types" ;
6
7
7
8
export default {
8
9
title : "Components/ImageCrop" ,
9
10
component : ImageCrop
10
11
} as Meta ;
11
12
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 > ( {
18
15
width : 150 ,
19
16
height : 150 ,
20
17
unit : "px" ,
21
18
x : 0 ,
22
19
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
+ ) ;
36
31
} ;
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ const ImageCrop: FC<IImageCropProps> = ({
21
21
circularCrop,
22
22
locked,
23
23
aspect = 1 ,
24
- cropAreaClassName
24
+ imgCropWrapperClassName,
25
+ imgCropClassName
25
26
} ) => {
26
27
const previewCanvasRef = useRef ( null ) ;
27
28
const imgRef = useRef ( null ) ;
@@ -116,13 +117,22 @@ const ImageCrop: FC<IImageCropProps> = ({
116
117
keepSelection
117
118
circularCrop = { circularCrop }
118
119
>
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 >
126
136
</ ReactCrop >
127
137
) }
128
138
</ div >
Original file line number Diff line number Diff line change @@ -9,5 +9,6 @@ export interface IImageCropProps {
9
9
locked ?: boolean ;
10
10
circularCrop ?: boolean ;
11
11
aspect ?: number ;
12
- cropAreaClassName ?: string ;
12
+ imgCropWrapperClassName ?: string ;
13
+ imgCropClassName ?: string ;
13
14
}
Original file line number Diff line number Diff line change @@ -90,15 +90,21 @@ export const WithImageCrop = () => {
90
90
< div className = 'flex items-start gap-2' >
91
91
{ image && (
92
92
< ImageCrop
93
- cropAreaClassName = 'max-w-[600px] max-h-[600px] min-w-[600px]'
94
93
setCrop = { setCrop }
95
94
crop = { crop }
96
95
src = { image }
97
96
onComplete = { handleCropComplete }
98
97
locked = { false }
99
98
/>
100
99
) }
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
+ ) }
102
108
</ div >
103
109
104
110
< ImageInput
You can’t perform that action at this time.
0 commit comments