@sunggang/ui-lib 0.3.58 → 0.3.59

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/index.esm.css CHANGED
@@ -1587,6 +1587,10 @@ video {
1587
1587
  --tw-bg-opacity: 1;
1588
1588
  background-color: rgb(209 213 219 / var(--tw-bg-opacity, 1));
1589
1589
  }
1590
+ .bg-gray-50 {
1591
+ --tw-bg-opacity: 1;
1592
+ background-color: rgb(249 250 251 / var(--tw-bg-opacity, 1));
1593
+ }
1590
1594
  .bg-gray-500 {
1591
1595
  --tw-bg-opacity: 1;
1592
1596
  background-color: rgb(107 114 128 / var(--tw-bg-opacity, 1));
@@ -1717,6 +1721,9 @@ video {
1717
1721
  .p-6 {
1718
1722
  padding: 1.5rem;
1719
1723
  }
1724
+ .p-8 {
1725
+ padding: 2rem;
1726
+ }
1720
1727
  .p-\[30px\] {
1721
1728
  padding: 30px;
1722
1729
  }
@@ -1997,6 +2004,10 @@ video {
1997
2004
  --tw-text-opacity: 1;
1998
2005
  color: rgb(119 119 119 / var(--tw-text-opacity, 1));
1999
2006
  }
2007
+ .text-\[\#999999\] {
2008
+ --tw-text-opacity: 1;
2009
+ color: rgb(153 153 153 / var(--tw-text-opacity, 1));
2010
+ }
2000
2011
  .text-\[\#B0B0B0\] {
2001
2012
  --tw-text-opacity: 1;
2002
2013
  color: rgb(176 176 176 / var(--tw-text-opacity, 1));
package/index.esm2.js CHANGED
@@ -18033,7 +18033,7 @@ function _unsupported_iterable_to_array$o(o, minLen) {
18033
18033
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$o(o, minLen);
18034
18034
  }
18035
18035
  var DropImage = function(param) {
18036
- var _param_preview = param.preview, preview = _param_preview === void 0 ? true : _param_preview, setFiles = param.setFiles, imageUrls = param.imageUrls, setImageUrls = param.setImageUrls, _param_imageStyleType = param.imageStyleType, imageStyleType = _param_imageStyleType === void 0 ? "base" : _param_imageStyleType, _param_limitSize = param.limitSize, limitSize = _param_limitSize === void 0 ? 0 : _param_limitSize;
18036
+ var _param_preview = param.preview, preview = _param_preview === void 0 ? true : _param_preview, setFiles = param.setFiles, imageUrls = param.imageUrls, setImageUrls = param.setImageUrls, _param_imageStyleType = param.imageStyleType, imageStyleType = _param_imageStyleType === void 0 ? "base" : _param_imageStyleType, _param_limitSize = param.limitSize, limitSize = _param_limitSize === void 0 ? 0 : _param_limitSize, _param_maxFiles = param.maxFiles, maxFiles = _param_maxFiles === void 0 ? 10 : _param_maxFiles, _param_maxTotalImages = param.maxTotalImages, maxTotalImages = _param_maxTotalImages === void 0 ? 10 : _param_maxTotalImages;
18037
18037
  var _useState = _sliced_to_array$l(useState([]), 2), previewFiles = _useState[0], setPreviewFiles = _useState[1];
18038
18038
  var _useState1 = _sliced_to_array$l(useState(null), 2), uploadError = _useState1[0], setUploadError = _useState1[1];
18039
18039
  useEffect(function() {
@@ -18043,6 +18043,12 @@ var DropImage = function(param) {
18043
18043
  ]);
18044
18044
  var MAX_SIZE_5MB = 5 * 1024 * 1024;
18045
18045
  var DEFAULT_IMAGE_SIZE_LIMIT_IN_BYTES = limitSize || MAX_SIZE_5MB;
18046
+ // 計算目前還能上傳多少張圖片
18047
+ var currentImageCount = (previewFiles === null || previewFiles === void 0 ? void 0 : previewFiles.length) || 0;
18048
+ var remainingSlots = maxTotalImages - currentImageCount;
18049
+ var canUploadMore = remainingSlots > 0;
18050
+ // 動態調整 maxFiles,不能超過剩餘空間
18051
+ var dynamicMaxFiles = Math.min(maxFiles, remainingSlots);
18046
18052
  var _useDropzone = useDropzone({
18047
18053
  accept: {
18048
18054
  "image/png": [
@@ -18053,10 +18059,66 @@ var DropImage = function(param) {
18053
18059
  ".jpeg"
18054
18060
  ]
18055
18061
  },
18056
- maxFiles: 10,
18062
+ maxFiles: dynamicMaxFiles,
18057
18063
  maxSize: DEFAULT_IMAGE_SIZE_LIMIT_IN_BYTES,
18064
+ disabled: !canUploadMore,
18058
18065
  onDrop: function(dropFiles) {
18059
- var newFiles = [];
18066
+ if (!canUploadMore) {
18067
+ setUploadError(/*#__PURE__*/ jsx(ErrorContent, {
18068
+ setModal: function() {
18069
+ return setUploadError(null);
18070
+ },
18071
+ errmsg: /*#__PURE__*/ jsxs("div", {
18072
+ className: "text-center text-lg text-gray-500",
18073
+ children: [
18074
+ "已達到最大圖片數量限制:",
18075
+ maxTotalImages,
18076
+ " 張"
18077
+ ]
18078
+ })
18079
+ }));
18080
+ return;
18081
+ }
18082
+ // 檢查是否會超過總數限制
18083
+ var totalAfterUpload = currentImageCount + dropFiles.length;
18084
+ if (totalAfterUpload > maxTotalImages) {
18085
+ var allowedFiles = dropFiles.slice(0, remainingSlots);
18086
+ setUploadError(/*#__PURE__*/ jsx(ErrorContent, {
18087
+ setModal: function() {
18088
+ return setUploadError(null);
18089
+ },
18090
+ errmsg: /*#__PURE__*/ jsxs("div", {
18091
+ className: "text-center text-lg text-gray-500",
18092
+ children: [
18093
+ "最多只能上傳 ",
18094
+ remainingSlots,
18095
+ " 張圖片,已自動限制為前",
18096
+ " ",
18097
+ allowedFiles.length,
18098
+ " 張"
18099
+ ]
18100
+ })
18101
+ }));
18102
+ // 只處理允許的檔案數量
18103
+ var newFiles = [];
18104
+ setFiles(function(prevFiles) {
18105
+ return _to_consumable_array$8(prevFiles).concat(_to_consumable_array$8(allowedFiles));
18106
+ });
18107
+ allowedFiles.forEach(function(dropFile, index) {
18108
+ Object.assign(dropFile, {
18109
+ preview: URL.createObjectURL(dropFile),
18110
+ id: v4(),
18111
+ index: (previewFiles === null || previewFiles === void 0 ? void 0 : previewFiles.length) + index + 1
18112
+ });
18113
+ newFiles.push(dropFile);
18114
+ });
18115
+ setPreviewFiles(function(prev) {
18116
+ return _to_consumable_array$8(prev).concat(_to_consumable_array$8(newFiles));
18117
+ });
18118
+ return;
18119
+ }
18120
+ // 正常處理
18121
+ var newFiles1 = [];
18060
18122
  setFiles(function(prevFiles) {
18061
18123
  return _to_consumable_array$8(prevFiles).concat(_to_consumable_array$8(dropFiles));
18062
18124
  });
@@ -18066,10 +18128,10 @@ var DropImage = function(param) {
18066
18128
  id: v4(),
18067
18129
  index: (previewFiles === null || previewFiles === void 0 ? void 0 : previewFiles.length) + index + 1
18068
18130
  });
18069
- newFiles.push(dropFile);
18131
+ newFiles1.push(dropFile);
18070
18132
  });
18071
18133
  setPreviewFiles(function(prev) {
18072
- return _to_consumable_array$8(prev).concat(_to_consumable_array$8(newFiles));
18134
+ return _to_consumable_array$8(prev).concat(_to_consumable_array$8(newFiles1));
18073
18135
  });
18074
18136
  },
18075
18137
  onDropRejected: function(rejectedFiles) {
@@ -18133,7 +18195,32 @@ var DropImage = function(param) {
18133
18195
  /*#__PURE__*/ jsxs(DragDropContext, {
18134
18196
  onDragEnd: onDragEnd,
18135
18197
  children: [
18136
- /*#__PURE__*/ jsxs("div", _object_spread_props$k(_object_spread$p({}, getRootProps({
18198
+ !canUploadMore ? /*#__PURE__*/ jsx("div", {
18199
+ className: "w-full mb-4",
18200
+ children: /*#__PURE__*/ jsxs("div", {
18201
+ className: "border-2 border-dashed border-gray-300 rounded-lg bg-gray-50 p-8 text-center",
18202
+ children: [
18203
+ /*#__PURE__*/ jsx(Icon, {
18204
+ icon: "material-symbols:block",
18205
+ width: "2.5rem",
18206
+ height: "2.5rem",
18207
+ className: "mx-auto mb-2 text-gray-400"
18208
+ }),
18209
+ /*#__PURE__*/ jsxs("p", {
18210
+ className: "text-gray-500",
18211
+ children: [
18212
+ "已達到最大圖片數量限制:",
18213
+ maxTotalImages,
18214
+ " 張"
18215
+ ]
18216
+ }),
18217
+ /*#__PURE__*/ jsx("p", {
18218
+ className: "text-sm text-gray-400",
18219
+ children: "請刪除部分圖片後再上傳新的圖片"
18220
+ })
18221
+ ]
18222
+ })
18223
+ }) : /*#__PURE__*/ jsxs("div", _object_spread_props$k(_object_spread$p({}, getRootProps({
18137
18224
  className: "dropzone"
18138
18225
  })), {
18139
18226
  children: [
@@ -18188,6 +18275,17 @@ var DropImage = function(param) {
18188
18275
  /*#__PURE__*/ jsx("h5", {
18189
18276
  className: "mb-2 text-xl font-bold tracking-tight text-gray-700 pb-4",
18190
18277
  children: "拖曳圖片至此"
18278
+ }),
18279
+ /*#__PURE__*/ jsxs("p", {
18280
+ className: "font-normal text-xs text-[#999999] pb-4",
18281
+ children: [
18282
+ "還可上傳 ",
18283
+ remainingSlots,
18284
+ " 張圖片 (總限制:",
18285
+ " ",
18286
+ maxTotalImages,
18287
+ " 張)"
18288
+ ]
18191
18289
  })
18192
18290
  ]
18193
18291
  })
@@ -50195,11 +50293,11 @@ var FlatpickrInput = /*#__PURE__*/ forwardRef(function(param, ref) {
50195
50293
  className: "absolute right-3 top-1/2 transform -translate-y-1/2 pointer-events-none",
50196
50294
  children: /*#__PURE__*/ jsx("span", {
50197
50295
  className: "w-5 h-5 text-[#B4B4B4]",
50198
- children: typeof item.icon === "string" ? /*#__PURE__*/ jsx("img", {
50199
- src: "/assets/images/".concat(item.icon),
50200
- alt: "",
50201
- className: "w-full h-full"
50202
- }) : item.icon
50296
+ children: /*#__PURE__*/ jsx(Icon, {
50297
+ icon: item.icon || "solar:calendar-linear",
50298
+ width: "1.5rem",
50299
+ height: "1.5rem"
50300
+ })
50203
50301
  })
50204
50302
  })
50205
50303
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.3.58",
3
+ "version": "0.3.59",
4
4
  "dependencies": {
5
5
  "@emotion/react": "^11.14.0",
6
6
  "@emotion/styled": "^11.14.0",
@@ -8,6 +8,8 @@ export interface ImageItem {
8
8
  export interface DropImageProps {
9
9
  preview: boolean;
10
10
  limitSize?: number;
11
+ maxFiles?: number;
12
+ maxTotalImages?: number;
11
13
  imageUrls?: ImageItem[] | undefined;
12
14
  setImageUrls?: any;
13
15
  setFiles: React.Dispatch<React.SetStateAction<File[]>>;
@@ -18,3 +20,4 @@ export default _default;
18
20
  export declare const Base: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, DropImageProps>;
19
21
  export declare const Custom: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, DropImageProps>;
20
22
  export declare const Primary: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, DropImageProps>;
23
+ export declare const SingleImageOnly: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, DropImageProps>;
@@ -16,6 +16,7 @@ export declare const config: (getValues: (name: string) => unknown) => (FormItem
16
16
  validateOption: {
17
17
  required: string;
18
18
  };
19
+ icon: string;
19
20
  flatpickrOptions: {
20
21
  mode: string;
21
22
  time_24hr: boolean;
@@ -44,6 +45,7 @@ export declare const config: (getValues: (name: string) => unknown) => (FormItem
44
45
  hoverClass: string;
45
46
  selectedClass: string;
46
47
  };
48
+ icon?: undefined;
47
49
  flatpickrOptions?: undefined;
48
50
  })[] | {
49
51
  type: string;
@@ -30,6 +30,37 @@ interface Checkbox {
30
30
  color?: 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | 'default';
31
31
  };
32
32
  }
33
+ interface FlatpickrOptions {
34
+ mode?: 'single' | 'multiple' | 'range';
35
+ enableTime?: boolean;
36
+ time_24hr?: boolean;
37
+ dateFormat?: string;
38
+ defaultDate?: Date | Date[] | string;
39
+ inline?: boolean;
40
+ noCalendar?: boolean;
41
+ allowInput?: boolean;
42
+ clickOpens?: boolean;
43
+ weekNumbers?: boolean;
44
+ minDate?: Date | string;
45
+ maxDate?: Date | string;
46
+ disable?: Array<Date | string | {
47
+ from: Date | string;
48
+ to: Date | string;
49
+ }>;
50
+ enable?: Array<Date | string | {
51
+ from: Date | string;
52
+ to: Date | string;
53
+ }>;
54
+ locale?: string;
55
+ position?: 'auto' | 'above' | 'below';
56
+ static?: boolean;
57
+ monthSelectorType?: 'dropdown' | 'static';
58
+ onChange?: (selectedDates: Date[], dateStr: string, instance: any) => void;
59
+ onClose?: (selectedDates: Date[], dateStr: string, instance: any) => void;
60
+ onOpen?: (selectedDates: Date[], dateStr: string, instance: any) => void;
61
+ onReady?: (selectedDates: Date[], dateStr: string, instance: any) => void;
62
+ [key: string]: any;
63
+ }
33
64
  export interface FormItem {
34
65
  type: string;
35
66
  name: string;
@@ -91,6 +122,7 @@ export interface FormItem {
91
122
  hoverClass?: string;
92
123
  selectedClass?: string;
93
124
  };
125
+ flatpickrOptions?: FlatpickrOptions;
94
126
  }
95
127
  export interface FormType {
96
128
  item: FormItem;