@cashub/ui 0.11.3 → 0.12.1

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.
@@ -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: false,
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, {
@@ -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 maxFiles = _ref.maxFiles,
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
 
@@ -129,28 +136,33 @@ var ImageDropzone = function ImageDropzone(_ref) {
129
136
  };
130
137
 
131
138
  var handleAddFiles = (0, _react.useCallback)(function (newFiles) {
132
- if (files.length + newFiles.length > maxFiles) {
133
- newFiles.splice(maxFiles - files.length);
134
- }
139
+ setFiles(function (previous) {
140
+ if (previous.length + newFiles.length > maxFiles) {
141
+ newFiles.splice(maxFiles - previous.length);
142
+ }
143
+
144
+ return [].concat(_toConsumableArray(previous), _toConsumableArray(newFiles));
145
+ });
135
146
 
136
147
  for (var index = 0; index < newFiles.length; index += 1) {
137
148
  newFiles[index].url = URL.createObjectURL(newFiles[index]);
138
149
  }
139
150
 
140
- setFiles([].concat(_toConsumableArray(files), _toConsumableArray(newFiles)));
141
151
  setAddedFiles(newFiles);
142
- }, [files, maxFiles]);
152
+ }, [maxFiles]);
143
153
  var handleRemoveFile = (0, _react.useCallback)(function (event, index) {
144
154
  if (event) {
145
155
  event.stopPropagation();
146
156
  }
147
157
 
148
- var newFiles = _toConsumableArray(files);
158
+ setFiles(function (previous) {
159
+ var newFiles = _toConsumableArray(previous);
149
160
 
150
- newFiles.splice(index, 1);
151
- setFiles(newFiles);
161
+ newFiles.splice(index, 1);
162
+ return newFiles;
163
+ });
152
164
  if (onRemovedFile) onRemovedFile(index);
153
- }, [files, onRemovedFile]);
165
+ }, [onRemovedFile]);
154
166
  var handleChangeFile = (0, _react.useCallback)(function (event) {
155
167
  var files = event.target.files;
156
168
  var newFiles = [];
@@ -168,8 +180,9 @@ var ImageDropzone = function ImageDropzone(_ref) {
168
180
  cropper.handler({
169
181
  file: file,
170
182
  src: file.url,
171
- width: 180,
172
- height: 320,
183
+ width: width,
184
+ height: height,
185
+ cropBoxResizable: cropper.cropBoxResizable ? cropper.cropBoxResizable : false,
173
186
  onCrop: function onCrop(croppedSrc) {
174
187
  var croppedImageFile = (0, _utils.dataURLtoFile)(croppedSrc, file.name);
175
188
  croppedImageFile.url = croppedSrc;
@@ -182,15 +195,18 @@ var ImageDropzone = function ImageDropzone(_ref) {
182
195
  });
183
196
  }
184
197
  });
185
- }, [cropper]);
198
+ }, [width, height, cropper]);
186
199
 
187
200
  var previewItem = function previewItem() {
188
201
  return files.map(function (file, index) {
189
202
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Image, {
203
+ width: width,
204
+ height: height,
205
+ fixedSize: fixedSize,
190
206
  onClick: function onClick(event) {
191
207
  event.stopPropagation();
192
208
  },
193
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(ButtonGroup, {
209
+ children: [!disabled && /*#__PURE__*/(0, _jsxRuntime.jsxs)(ButtonGroup, {
194
210
  children: [cropper && /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
195
211
  title: "Crop",
196
212
  onClick: function onClick(event) {
@@ -258,6 +274,7 @@ var ImageDropzone = function ImageDropzone(_ref) {
258
274
  });
259
275
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
260
276
  tabIndex: "-1",
277
+ disabled: disabled,
261
278
  dragging: dragging,
262
279
  onClick: handleClick,
263
280
  onDragEnter: handleDragEnter,
@@ -270,6 +287,7 @@ var ImageDropzone = function ImageDropzone(_ref) {
270
287
  setFocus(true);
271
288
  },
272
289
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_HiddenFileInput.default, {
290
+ disabled: disabled,
273
291
  multiple: true,
274
292
  ref: inputRef,
275
293
  accept: accept,
@@ -278,15 +296,34 @@ var ImageDropzone = function ImageDropzone(_ref) {
278
296
  });
279
297
  };
280
298
 
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) {
299
+ 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
300
  var reachedLimit = _ref2.reachedLimit;
283
- return reachedLimit ? 'default' : 'pointer';
301
+ return reachedLimit && 'cursor:default;';
284
302
  }, function (_ref3) {
285
- var dragging = _ref3.dragging;
303
+ var disabled = _ref3.disabled;
304
+ return disabled && 'cursor:not-allowed; opacity: 0.5;';
305
+ }, function (_ref4) {
306
+ var dragging = _ref4.dragging;
286
307
  return dragging && 'border-color: var(--color-primary);';
287
308
  });
288
309
 
289
- var Image = _styledComponents.default.figure(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: 180px;\n height: 320px;\n position: relative;\n margin: var(--spacing-xs);\n\n > img {\n width: 100%;\n height: 100%;\n border-radius: var(--border-radius);\n }\n"])));
310
+ 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) {
311
+ var width = _ref5.width,
312
+ height = _ref5.height,
313
+ fixedSize = _ref5.fixedSize;
314
+
315
+ if (fixedSize) {
316
+ return "\n width: ".concat(width, "px;\n height: ").concat(height, "px;\n ");
317
+ }
318
+
319
+ if (width < height) {
320
+ return "\n width: ".concat(width, "px;\n max-width: ").concat(width, "px;\n max-height: ").concat(height, "px;\n ");
321
+ }
322
+
323
+ if (height < width) {
324
+ return "\n height: ".concat(height, "px;\n max-width: ").concat(width, "px;\n max-height: ").concat(height, "px;\n ");
325
+ }
326
+ });
290
327
 
291
328
  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
329
 
@@ -294,8 +331,8 @@ var Button = _styledComponents.default.div.attrs(function () {
294
331
  return {
295
332
  role: 'button'
296
333
  };
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 (_ref4) {
298
- var danger = _ref4.danger;
334
+ })(_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) {
335
+ var danger = _ref6.danger;
299
336
  return danger && 'background: var(--color-danger);';
300
337
  });
301
338
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.11.3",
3
+ "version": "0.12.1",
4
4
  "private": false,
5
5
  "author": "CASHUB Team",
6
6
  "description": "CASHUB UI components library",