sprint-asia-custom-component 0.1.145 → 0.1.146

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,7 +1,7 @@
1
1
  {
2
2
  "name": "sprint-asia-custom-component",
3
3
  "main": "dist/index.js",
4
- "version": "0.1.145",
4
+ "version": "0.1.146",
5
5
  "private": false,
6
6
  "dependencies": {
7
7
  "@headlessui/react": "^1.7.18",
@@ -12,9 +12,54 @@ const DropzoneUploadPhoto = ({
12
12
  error = "",
13
13
  disabled,
14
14
  layout = "box",
15
+ validateResolution = false, // Enable/Disable resolution validation
16
+ minResolution = { width: 300, height: 300 }, // Minimum resolution
17
+ maxResolution = { width: 5000, height: 5000 }, // Maximum resolution
15
18
  }) => {
16
19
  const [errorMessage, setErrorMessage] = useState("");
17
20
 
21
+ const validateImageResolution = (file) => {
22
+ return new Promise((resolve, reject) => {
23
+ const img = new Image();
24
+ img.src = URL.createObjectURL(file);
25
+ img.onload = () => {
26
+ if (
27
+ img.naturalWidth < minResolution.width ||
28
+ img.naturalHeight < minResolution.height ||
29
+ img.naturalWidth > maxResolution.width ||
30
+ img.naturalHeight > maxResolution.height
31
+ ) {
32
+ reject(
33
+ `Invalid image resolution.\nAllowed: ${minResolution.width}x${minResolution.height} px to ${maxResolution.width}x${maxResolution.height} px.`
34
+ );
35
+ } else {
36
+ resolve();
37
+ }
38
+ };
39
+ img.onerror = () => reject("Error loading image.");
40
+ });
41
+ };
42
+
43
+ const handleDrop = async (acceptedFiles) => {
44
+ setErrorMessage(""); // Clear previous error messages
45
+ const validFiles = [];
46
+
47
+ for (const file of acceptedFiles) {
48
+ try {
49
+ if (validateResolution) {
50
+ await validateImageResolution(file);
51
+ }
52
+ validFiles.push(file);
53
+ } catch (err) {
54
+ setErrorMessage(err);
55
+ }
56
+ }
57
+
58
+ if (validFiles.length > 0 && onDrop) {
59
+ onDrop(validFiles);
60
+ }
61
+ };
62
+
18
63
  const onDropRejected = (rejectedFiles) => {
19
64
  const file = rejectedFiles[0];
20
65
  if (file.errors[0]?.code === "file-too-large") {
@@ -25,7 +70,7 @@ const DropzoneUploadPhoto = ({
25
70
  };
26
71
 
27
72
  const { getRootProps, getInputProps } = useDropzone({
28
- onDrop,
73
+ onDrop: handleDrop,
29
74
  maxFiles,
30
75
  accept: {
31
76
  "image/jpeg": [".jpeg", ".jpg"],
@@ -61,7 +106,7 @@ const DropzoneUploadPhoto = ({
61
106
  <PiPlus size={24} className="text-neutral300" />
62
107
  <p className="text-sm text-neutral300">Upload Photo</p>
63
108
  {errorMessage && (
64
- <p className="text-danger500 mt-1" style={{ fontSize: 10 }}>
109
+ <p className="text-danger500 mt-1 whitespace-pre-line" style={{ fontSize: 10 }}>
65
110
  {errorMessage}
66
111
  </p>
67
112
  )}
@@ -863,9 +863,9 @@ const Templates = () => {
863
863
  titleRightButton="Submit"
864
864
  isActiveLeftButton
865
865
  isActiveRightButton
866
- onClickLeftButton={() => { }}
867
- onClickRightButton={() => { }}
868
- additionalButton={<PrimaryButton title={"Additional"} onClick={() => { }} isActive={true} />}
866
+ onClickLeftButton={() => {}}
867
+ onClickRightButton={() => {}}
868
+ additionalButton={<PrimaryButton title={"Additional"} onClick={() => {}} isActive={true} />}
869
869
  />
870
870
  </div>
871
871
 
@@ -1097,22 +1097,20 @@ const Templates = () => {
1097
1097
 
1098
1098
  <div className="m-9"></div>
1099
1099
  <p className="text-black font-bold text-2xl text-center py-2">Dropdown Button</p>
1100
- <DropdownButton
1101
- defaultType="Voucher Type"
1102
- />
1100
+ <DropdownButton defaultType="Voucher Type" />
1103
1101
 
1104
1102
  <div className="m-9"></div>
1105
1103
  <p className="text-black font-bold text-2xl text-center py-2">Description</p>
1106
1104
  <Description
1107
1105
  title="Sample Title"
1108
1106
  value={"This is a sample description.\n HHEHEEH \n LOh"}
1109
- // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1107
+ // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1110
1108
  />
1111
1109
  <Description
1112
1110
  title="Sample Title"
1113
1111
  value={"This is a sample description.\n HHEHEEH \n LOh"}
1114
1112
  icon={<PiCalendarBlank size={20} />}
1115
- // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1113
+ // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1116
1114
  />
1117
1115
 
1118
1116
  <div className="m-9"></div>
@@ -1159,6 +1157,9 @@ const Templates = () => {
1159
1157
  title="Upload a photos with minimum resolution 300 x 300 px and maximum 5000 x 5000 px."
1160
1158
  subtitle="Format File PNG, JPEG, or JPG, Maximal File 5 MB"
1161
1159
  required={true}
1160
+ validateResolution={true}
1161
+ minResolution={{ height: 300, width: 300 }}
1162
+ maxResolution={{ height: 5000, width: 5000 }}
1162
1163
  />
1163
1164
 
1164
1165
  <div className="m-9"></div>
@@ -1185,11 +1186,11 @@ const Templates = () => {
1185
1186
  options={[
1186
1187
  {
1187
1188
  option: "Option1",
1188
- value: "value 1"
1189
+ value: "value 1",
1189
1190
  },
1190
1191
  {
1191
1192
  option: "Option2",
1192
- value: "value 2"
1193
+ value: "value 2",
1193
1194
  },
1194
1195
  ]}
1195
1196
  buttonText="Division"
@@ -1197,9 +1198,7 @@ const Templates = () => {
1197
1198
  onSelect={setValueSelectFilter}
1198
1199
  />
1199
1200
 
1200
- {
1201
- console.log("ini value select", valueSelectFilter)
1202
- }
1201
+ {console.log("ini value select", valueSelectFilter)}
1203
1202
 
1204
1203
  <div className="m-9"></div>
1205
1204
  <FilterDropdown