@codeleap/web 3.16.2 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.16.2",
3
+ "version": "3.17.0",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -6,7 +6,7 @@ import {
6
6
  import { CropPickerPresets } from './styles'
7
7
  import { CropPickerProps } from './types'
8
8
  import { useCropPicker } from './useCropPicker'
9
- import { Modal, Button, FileInput, FileInputRef } from '../components'
9
+ import { Modal, Button, FileInput, FileInputRef, LoadingOverlay } from '../components'
10
10
 
11
11
  const ReactCrop: React.Component = require('react-image-crop').Component
12
12
  import 'react-image-crop/dist/ReactCrop.css'
@@ -35,6 +35,7 @@ export const _CropPicker = forwardRef<FileInputRef, CropPickerProps>(
35
35
  confirmButton = 'Confirm Crop',
36
36
  debugName,
37
37
  handle,
38
+ withLoading = false,
38
39
  ...fileInputProps
39
40
  } = allProps
40
41
 
@@ -47,6 +48,7 @@ export const _CropPicker = forwardRef<FileInputRef, CropPickerProps>(
47
48
  image,
48
49
  crop,
49
50
  setRelativeCrop,
51
+ isLoading,
50
52
  handleCropChange,
51
53
  } = handle || useCropPicker({ onFileSelect, ref, ...targetCrop })
52
54
 
@@ -98,6 +100,14 @@ export const _CropPicker = forwardRef<FileInputRef, CropPickerProps>(
98
100
  />
99
101
  </ReactCrop>
100
102
  )}
103
+ {
104
+ withLoading ? (
105
+ <LoadingOverlay
106
+ debugName='CropPicker'
107
+ visible={isLoading}
108
+ />
109
+ ) : null
110
+ }
101
111
  </Modal>
102
112
  </>
103
113
  )
@@ -19,6 +19,7 @@ export type CropPickerProps = Partial<FileInputProps> &
19
19
  debugName: string
20
20
  handle?: ReturnType<typeof useCropPicker>
21
21
  ref: AnyRef<HTMLElement>
22
+ withLoading?: boolean
22
23
  }
23
24
 
24
25
  export type ImageReading = HTMLImageElement
@@ -23,6 +23,7 @@ export function useCropPicker({
23
23
  const [image, setImage] = useState<ImageReading>(null)
24
24
  const [crop, setCrop] = useState<Crop>()
25
25
  const [relativeCrop, setRelativeCrop] = useState<Crop>()
26
+ const [isLoading, setIsLoading] = useState(false)
26
27
  const croppedPromise = usePromise<WebInputFile[]>({})
27
28
 
28
29
  const onCancel = () => croppedPromise.resolve([])
@@ -40,6 +41,7 @@ export function useCropPicker({
40
41
  }
41
42
 
42
43
  const onConfirmCrop = async () => {
44
+ setIsLoading(true)
43
45
  const [preview, croppedFile] = await cropImage(image, relativeCrop)
44
46
  onResolved([
45
47
  {
@@ -47,6 +49,7 @@ export function useCropPicker({
47
49
  preview,
48
50
  },
49
51
  ])
52
+ setIsLoading(false)
50
53
  setTimeout(() => cleanup())
51
54
  }
52
55
 
@@ -127,6 +130,7 @@ export function useCropPicker({
127
130
  setCrop,
128
131
  relativeCrop,
129
132
  setRelativeCrop,
133
+ isLoading,
130
134
  croppedPromise,
131
135
  handleCropChange,
132
136
  }