@cashub/ui 0.11.2 → 0.12.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/cropper/Cropper.js
CHANGED
|
@@ -21,6 +21,8 @@ var CropperWrapper = function CropperWrapper(_ref) {
|
|
|
21
21
|
alt = _ref$alt === void 0 ? 'picture' : _ref$alt,
|
|
22
22
|
width = _ref.width,
|
|
23
23
|
height = _ref.height,
|
|
24
|
+
_ref$cropBoxResizable = _ref.cropBoxResizable,
|
|
25
|
+
cropBoxResizable = _ref$cropBoxResizable === void 0 ? false : _ref$cropBoxResizable,
|
|
24
26
|
onInitialized = _ref.onInitialized,
|
|
25
27
|
_ref$dragMode = _ref.dragMode,
|
|
26
28
|
dragMode = _ref$dragMode === void 0 ? 'move' : _ref$dragMode;
|
|
@@ -34,7 +36,7 @@ var CropperWrapper = function CropperWrapper(_ref) {
|
|
|
34
36
|
viewMode: 1,
|
|
35
37
|
initialAspectRatio: 9 / 16,
|
|
36
38
|
background: true,
|
|
37
|
-
cropBoxResizable:
|
|
39
|
+
cropBoxResizable: cropBoxResizable,
|
|
38
40
|
data: {
|
|
39
41
|
width: width,
|
|
40
42
|
height: height
|
|
@@ -18,6 +18,8 @@ var CropperModalHandler = function CropperModalHandler(_ref) {
|
|
|
18
18
|
file = _ref.file,
|
|
19
19
|
width = _ref.width,
|
|
20
20
|
height = _ref.height,
|
|
21
|
+
_ref$cropBoxResizable = _ref.cropBoxResizable,
|
|
22
|
+
cropBoxResizable = _ref$cropBoxResizable === void 0 ? false : _ref$cropBoxResizable,
|
|
21
23
|
onCrop = _ref.onCrop,
|
|
22
24
|
_onClose = _ref.onClose;
|
|
23
25
|
(0, _TitleModal.default)({
|
|
@@ -29,6 +31,7 @@ var CropperModalHandler = function CropperModalHandler(_ref) {
|
|
|
29
31
|
file: file,
|
|
30
32
|
width: width,
|
|
31
33
|
height: height,
|
|
34
|
+
cropBoxResizable: cropBoxResizable,
|
|
32
35
|
onCrop: onCrop,
|
|
33
36
|
onClose: _onClose
|
|
34
37
|
}),
|
|
@@ -41,6 +41,8 @@ var CropImageModal = function CropImageModal(_ref) {
|
|
|
41
41
|
alt = _ref.alt,
|
|
42
42
|
width = _ref.width,
|
|
43
43
|
height = _ref.height,
|
|
44
|
+
_ref$cropBoxResizable = _ref.cropBoxResizable,
|
|
45
|
+
cropBoxResizable = _ref$cropBoxResizable === void 0 ? false : _ref$cropBoxResizable,
|
|
44
46
|
onCrop = _ref.onCrop,
|
|
45
47
|
onClose = _ref.onClose,
|
|
46
48
|
close = _ref.close;
|
|
@@ -89,6 +91,7 @@ var CropImageModal = function CropImageModal(_ref) {
|
|
|
89
91
|
alt: alt,
|
|
90
92
|
width: width,
|
|
91
93
|
height: height,
|
|
94
|
+
cropBoxResizable: cropBoxResizable,
|
|
92
95
|
onInitialized: handleInitialized
|
|
93
96
|
})
|
|
94
97
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TitleModal.default.Footer, {
|
|
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils = require("@cashub/utils");
|
|
11
11
|
|
|
12
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
13
|
|
|
@@ -23,7 +23,7 @@ var useChangeNumber = function useChangeNumber(min, max, setState, name) {
|
|
|
23
23
|
|
|
24
24
|
if (value.length > 0) {
|
|
25
25
|
// if value is not a integer, then remove last char
|
|
26
|
-
if (!(0,
|
|
26
|
+
if (!(0, _utils.isInteger)(value)) {
|
|
27
27
|
value = value.substring(0, value.length - 1);
|
|
28
28
|
} // use min value instead when exceed minimum
|
|
29
29
|
|
|
@@ -50,9 +50,16 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
50
50
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
51
51
|
|
|
52
52
|
var ImageDropzone = function ImageDropzone(_ref) {
|
|
53
|
-
var
|
|
53
|
+
var _ref$width = _ref.width,
|
|
54
|
+
width = _ref$width === void 0 ? 180 : _ref$width,
|
|
55
|
+
_ref$height = _ref.height,
|
|
56
|
+
height = _ref$height === void 0 ? 320 : _ref$height,
|
|
57
|
+
_ref$fixedSize = _ref.fixedSize,
|
|
58
|
+
fixedSize = _ref$fixedSize === void 0 ? true : _ref$fixedSize,
|
|
59
|
+
maxFiles = _ref.maxFiles,
|
|
54
60
|
message = _ref.message,
|
|
55
61
|
accept = _ref.accept,
|
|
62
|
+
disabled = _ref.disabled,
|
|
56
63
|
onAddedFile = _ref.onAddedFile,
|
|
57
64
|
onRemovedFile = _ref.onRemovedFile,
|
|
58
65
|
setDropzoneFunc = _ref.setDropzoneFunc,
|
|
@@ -81,7 +88,7 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
81
88
|
setFocus = _useState8[1];
|
|
82
89
|
|
|
83
90
|
var handleClick = function handleClick() {
|
|
84
|
-
if (files.length >= maxFiles) return;
|
|
91
|
+
if (disabled || files.length >= maxFiles) return;
|
|
85
92
|
setFocus(false);
|
|
86
93
|
inputRef.current.click();
|
|
87
94
|
};
|
|
@@ -89,13 +96,13 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
89
96
|
var handleDragEnter = function handleDragEnter(event) {
|
|
90
97
|
event.preventDefault();
|
|
91
98
|
event.stopPropagation();
|
|
92
|
-
if (files.length < maxFiles) setDragging(true);
|
|
99
|
+
if (!disabled && files.length < maxFiles) setDragging(true);
|
|
93
100
|
};
|
|
94
101
|
|
|
95
102
|
var handleDragOver = function handleDragOver(event) {
|
|
96
103
|
event.preventDefault();
|
|
97
104
|
event.stopPropagation();
|
|
98
|
-
if (files.length < maxFiles) setDragging(true);
|
|
105
|
+
if (!disabled && files.length < maxFiles) setDragging(true);
|
|
99
106
|
};
|
|
100
107
|
|
|
101
108
|
var handleDragLeave = function handleDragLeave(event) {
|
|
@@ -108,7 +115,7 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
108
115
|
event.preventDefault();
|
|
109
116
|
event.stopPropagation();
|
|
110
117
|
|
|
111
|
-
if (files.length < maxFiles) {
|
|
118
|
+
if (!disabled && files.length < maxFiles) {
|
|
112
119
|
setDragging(false);
|
|
113
120
|
var dataTransfer = event.dataTransfer;
|
|
114
121
|
|
|
@@ -168,8 +175,9 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
168
175
|
cropper.handler({
|
|
169
176
|
file: file,
|
|
170
177
|
src: file.url,
|
|
171
|
-
width:
|
|
172
|
-
height:
|
|
178
|
+
width: width,
|
|
179
|
+
height: height,
|
|
180
|
+
cropBoxResizable: cropper.cropBoxResizable ? cropper.cropBoxResizable : false,
|
|
173
181
|
onCrop: function onCrop(croppedSrc) {
|
|
174
182
|
var croppedImageFile = (0, _utils.dataURLtoFile)(croppedSrc, file.name);
|
|
175
183
|
croppedImageFile.url = croppedSrc;
|
|
@@ -187,10 +195,13 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
187
195
|
var previewItem = function previewItem() {
|
|
188
196
|
return files.map(function (file, index) {
|
|
189
197
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Image, {
|
|
198
|
+
width: width,
|
|
199
|
+
height: height,
|
|
200
|
+
fixedSize: fixedSize,
|
|
190
201
|
onClick: function onClick(event) {
|
|
191
202
|
event.stopPropagation();
|
|
192
203
|
},
|
|
193
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(ButtonGroup, {
|
|
204
|
+
children: [!disabled && /*#__PURE__*/(0, _jsxRuntime.jsxs)(ButtonGroup, {
|
|
194
205
|
children: [cropper && /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
|
|
195
206
|
title: "Crop",
|
|
196
207
|
onClick: function onClick(event) {
|
|
@@ -258,6 +269,7 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
258
269
|
});
|
|
259
270
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
|
|
260
271
|
tabIndex: "-1",
|
|
272
|
+
disabled: disabled,
|
|
261
273
|
dragging: dragging,
|
|
262
274
|
onClick: handleClick,
|
|
263
275
|
onDragEnter: handleDragEnter,
|
|
@@ -270,6 +282,7 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
270
282
|
setFocus(true);
|
|
271
283
|
},
|
|
272
284
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_HiddenFileInput.default, {
|
|
285
|
+
disabled: disabled,
|
|
273
286
|
multiple: true,
|
|
274
287
|
ref: inputRef,
|
|
275
288
|
accept: accept,
|
|
@@ -278,15 +291,34 @@ var ImageDropzone = function ImageDropzone(_ref) {
|
|
|
278
291
|
});
|
|
279
292
|
};
|
|
280
293
|
|
|
281
|
-
var Wrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n min-height: 200px;\n border: 4px dashed var(--border-color);\n border-radius: var(--border-radius-l);\n color: var(--font-on-primary);\n display: flex;\n flex-wrap: wrap;\n justify-content: center;\n align-items: center;\n padding: var(--spacing-xs);\n cursor: ", ";\n\n ", ";\n\n &:focus {\n border-color: var(--color-primary);\n }\n"])), function (_ref2) {
|
|
294
|
+
var Wrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n min-height: 200px;\n border: 4px dashed var(--border-color);\n border-radius: var(--border-radius-l);\n color: var(--font-on-primary);\n display: flex;\n flex-wrap: wrap;\n justify-content: center;\n align-items: center;\n padding: var(--spacing-xs);\n cursor: pointer;\n\n ", ";\n\n ", ";\n\n ", ";\n\n &:focus {\n border-color: var(--color-primary);\n }\n"])), function (_ref2) {
|
|
282
295
|
var reachedLimit = _ref2.reachedLimit;
|
|
283
|
-
return reachedLimit
|
|
296
|
+
return reachedLimit && 'cursor:default;';
|
|
284
297
|
}, function (_ref3) {
|
|
285
|
-
var
|
|
298
|
+
var disabled = _ref3.disabled;
|
|
299
|
+
return disabled && 'cursor:not-allowed; opacity: 0.5;';
|
|
300
|
+
}, function (_ref4) {
|
|
301
|
+
var dragging = _ref4.dragging;
|
|
286
302
|
return dragging && 'border-color: var(--color-primary);';
|
|
287
303
|
});
|
|
288
304
|
|
|
289
|
-
var Image = _styledComponents.default.figure(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n
|
|
305
|
+
var Image = _styledComponents.default.figure(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n margin: var(--spacing-xs);\n\n ", "\n\n > img {\n width: 100%;\n height: 100%;\n border-radius: var(--border-radius);\n }\n"])), function (_ref5) {
|
|
306
|
+
var width = _ref5.width,
|
|
307
|
+
height = _ref5.height,
|
|
308
|
+
fixedSize = _ref5.fixedSize;
|
|
309
|
+
|
|
310
|
+
if (fixedSize) {
|
|
311
|
+
return "\n width: ".concat(width, "px;\n height: ").concat(height, "px;\n ");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (width < height) {
|
|
315
|
+
return "\n width: ".concat(width, "px;\n max-width: ").concat(width, "px;\n max-height: ").concat(height, "px;\n ");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (height < width) {
|
|
319
|
+
return "\n height: ".concat(height, "px;\n max-width: ").concat(width, "px;\n max-height: ").concat(height, "px;\n ");
|
|
320
|
+
}
|
|
321
|
+
});
|
|
290
322
|
|
|
291
323
|
var ButtonGroup = _styledComponents.default.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: absolute;\n right: calc(var(--spacing-xs) * -1);\n top: calc(var(--spacing-xs) * -1);\n"])));
|
|
292
324
|
|
|
@@ -294,8 +326,8 @@ var Button = _styledComponents.default.div.attrs(function () {
|
|
|
294
326
|
return {
|
|
295
327
|
role: 'button'
|
|
296
328
|
};
|
|
297
|
-
})(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: inline-block;\n width: 32px;\n height: 32px;\n color: var(--color-white);\n background: var(--color-primary);\n border-radius: var(--border-radius-round);\n cursor: pointer;\n\n > svg {\n color: var(--color-white);\n margin: 0 auto;\n position: relative;\n top: 50%;\n transform: translateY(-50%);\n margin: 0 auto;\n display: block;\n }\n\n &:not(:first-child) {\n margin-left: var(--spacing-xs);\n }\n\n ", "\n"])), function (
|
|
298
|
-
var danger =
|
|
329
|
+
})(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: inline-block;\n width: 32px;\n height: 32px;\n color: var(--color-white);\n background: var(--color-primary);\n border-radius: var(--border-radius-round);\n cursor: pointer;\n\n > svg {\n color: var(--color-white);\n margin: 0 auto;\n position: relative;\n top: 50%;\n transform: translateY(-50%);\n margin: 0 auto;\n display: block;\n }\n\n &:not(:first-child) {\n margin-left: var(--spacing-xs);\n }\n\n ", "\n"])), function (_ref6) {
|
|
330
|
+
var danger = _ref6.danger;
|
|
299
331
|
return danger && 'background: var(--color-danger);';
|
|
300
332
|
});
|
|
301
333
|
|