@idds/react 1.4.0 → 1.4.3

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/dist/index.es.js CHANGED
@@ -2839,13 +2839,13 @@ function FileUpload({
2839
2839
  uploadedFile.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--uploading", children: /* @__PURE__ */ jsx(
2840
2840
  IconLoader2,
2841
2841
  {
2842
- size: 16,
2842
+ size: 20,
2843
2843
  className: "ina-file-upload__file-icon--spinning"
2844
2844
  }
2845
2845
  ) }),
2846
- uploadedFile.status === "success" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--success", children: /* @__PURE__ */ jsx(IconCircleCheck, { size: 16, stroke: "2" }) }),
2847
- uploadedFile.status === "error" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--error", children: /* @__PURE__ */ jsx(IconCircleX, { size: 16, stroke: "2" }) }),
2848
- uploadedFile.status === "idle" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--success", children: /* @__PURE__ */ jsx(IconCircleCheck, { size: 16, stroke: "2" }) })
2846
+ uploadedFile.status === "success" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--success", children: /* @__PURE__ */ jsx(IconCircleCheck, { size: 20, stroke: "2" }) }),
2847
+ uploadedFile.status === "error" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--error", children: /* @__PURE__ */ jsx(IconCircleX, { size: 20, stroke: "2" }) }),
2848
+ uploadedFile.status === "idle" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--success", children: /* @__PURE__ */ jsx(IconCircleCheck, { size: 20, stroke: "2" }) })
2849
2849
  ] }),
2850
2850
  /* @__PURE__ */ jsxs("div", { className: "ina-file-upload__file-info", children: [
2851
2851
  /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-name", children: sanitizeFileName(uploadedFile.file.name) }),
@@ -2863,7 +2863,7 @@ function FileUpload({
2863
2863
  updateFileStatus(originalIndex, "idle");
2864
2864
  },
2865
2865
  title: "Coba lagi",
2866
- children: /* @__PURE__ */ jsx(IconRotateClockwise, { size: 16 })
2866
+ children: /* @__PURE__ */ jsx(IconRotateClockwise, { size: 20 })
2867
2867
  }
2868
2868
  ),
2869
2869
  /* @__PURE__ */ jsx(
@@ -2873,7 +2873,7 @@ function FileUpload({
2873
2873
  className: "ina-file-upload__file-remove",
2874
2874
  onClick: () => removeFile(originalIndex),
2875
2875
  title: "Hapus file",
2876
- children: /* @__PURE__ */ jsx(IconTrash, { size: 16 })
2876
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
2877
2877
  }
2878
2878
  )
2879
2879
  ] }),
@@ -2884,7 +2884,7 @@ function FileUpload({
2884
2884
  className: "ina-file-upload__file-remove",
2885
2885
  onClick: () => removeFile(originalIndex),
2886
2886
  title: "Batalkan upload",
2887
- children: /* @__PURE__ */ jsx(IconX, { size: 16 })
2887
+ children: /* @__PURE__ */ jsx(IconX, { size: 20 })
2888
2888
  }
2889
2889
  ),
2890
2890
  uploadedFile.status === "success" && /* @__PURE__ */ jsx(
@@ -2894,7 +2894,7 @@ function FileUpload({
2894
2894
  className: "ina-file-upload__file-remove",
2895
2895
  onClick: () => removeFile(originalIndex),
2896
2896
  title: "Hapus file",
2897
- children: /* @__PURE__ */ jsx(IconTrash, { size: 16 })
2897
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
2898
2898
  }
2899
2899
  ),
2900
2900
  uploadedFile.status === "idle" && /* @__PURE__ */ jsx(
@@ -2904,7 +2904,7 @@ function FileUpload({
2904
2904
  className: "ina-file-upload__file-remove",
2905
2905
  onClick: () => removeFile(originalIndex),
2906
2906
  title: "Hapus file",
2907
- children: /* @__PURE__ */ jsx(IconTrash, { size: 16 })
2907
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
2908
2908
  }
2909
2909
  )
2910
2910
  ] })
@@ -3261,7 +3261,7 @@ function SingleFileUpload({
3261
3261
  handleRemove();
3262
3262
  },
3263
3263
  "aria-label": "Remove file",
3264
- children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
3264
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 18 })
3265
3265
  }
3266
3266
  )
3267
3267
  ] })
@@ -4162,13 +4162,15 @@ function SelectDropdown({
4162
4162
  onSearchChange,
4163
4163
  disabled = false,
4164
4164
  showPreviewValue = true,
4165
- searchable = true
4165
+ searchable = true,
4166
+ onSelectedRawChange
4166
4167
  }) {
4167
4168
  const [isOpen, setIsOpen] = useState(false);
4168
4169
  const [internalSearchTerm, setInternalSearchTerm] = useState("");
4169
4170
  const containerRef = useRef(null);
4170
4171
  const scrollContainerRef = useRef(null);
4171
4172
  const searchTimeoutRef = useRef(null);
4173
+ const selectedLabelsCacheRef = useRef(/* @__PURE__ */ new Map());
4172
4174
  const isSearchControlled = searchValue !== void 0;
4173
4175
  const searchTerm = isSearchControlled ? searchValue : internalSearchTerm;
4174
4176
  useEffect(() => {
@@ -4226,16 +4228,88 @@ function SelectDropdown({
4226
4228
  const isArraySelected = multiple && Array.isArray(selected);
4227
4229
  const selectedArray = isArraySelected ? selected : [];
4228
4230
  const singleSelected = !multiple ? selected : null;
4231
+ const getLabelForValue = (value) => {
4232
+ if (selectedLabelsCacheRef.current.has(value)) {
4233
+ return selectedLabelsCacheRef.current.get(value) || null;
4234
+ }
4235
+ const found = options.find((o) => o.value === value);
4236
+ if (found) {
4237
+ selectedLabelsCacheRef.current.set(value, found.label);
4238
+ return found.label;
4239
+ }
4240
+ return null;
4241
+ };
4242
+ const getOptionForValue = (value) => {
4243
+ const label = getLabelForValue(value);
4244
+ if (label !== null) {
4245
+ return { label, value };
4246
+ }
4247
+ const found = options.find((o) => o.value === value);
4248
+ return found || null;
4249
+ };
4250
+ useEffect(() => {
4251
+ if (onSelectedRawChange) {
4252
+ let selectedRaw = null;
4253
+ if (multiple) {
4254
+ if (selectedArray.length > 0) {
4255
+ const rawOptions = selectedArray.map((val) => getOptionForValue(val)).filter((opt) => opt !== null);
4256
+ selectedRaw = rawOptions.length > 0 ? rawOptions : null;
4257
+ }
4258
+ } else {
4259
+ if (singleSelected !== null && singleSelected !== void 0 && singleSelected !== "") {
4260
+ selectedRaw = getOptionForValue(singleSelected);
4261
+ }
4262
+ }
4263
+ onSelectedRawChange(selectedRaw);
4264
+ }
4265
+ }, [selected, multiple, options]);
4266
+ useEffect(() => {
4267
+ const cache = selectedLabelsCacheRef.current;
4268
+ options.forEach((option) => {
4269
+ if (cache.has(option.value)) {
4270
+ cache.set(option.value, option.label);
4271
+ }
4272
+ });
4273
+ }, [options]);
4274
+ useEffect(() => {
4275
+ const cache = selectedLabelsCacheRef.current;
4276
+ if (multiple && Array.isArray(selected)) {
4277
+ selected.forEach((value) => {
4278
+ if (!cache.has(value)) {
4279
+ const found = options.find((o) => o.value === value);
4280
+ if (found) {
4281
+ cache.set(value, found.label);
4282
+ }
4283
+ }
4284
+ });
4285
+ cache.forEach((_, value) => {
4286
+ if (!selected.includes(value)) {
4287
+ cache.delete(value);
4288
+ }
4289
+ });
4290
+ } else if (selected !== null && selected !== void 0 && selected !== "") {
4291
+ if (!cache.has(selected)) {
4292
+ const found = options.find((o) => o.value === selected);
4293
+ if (found) {
4294
+ cache.set(selected, found.label);
4295
+ }
4296
+ }
4297
+ } else {
4298
+ cache.clear();
4299
+ }
4300
+ }, [selected, multiple, options]);
4229
4301
  let triggerLabel;
4230
4302
  if (multiple) {
4231
4303
  if (!selectedArray.length) triggerLabel = placeholder;
4232
4304
  else if (selectedArray.length > 3)
4233
4305
  triggerLabel = `${selectedArray.length} data terpilih`;
4234
- else
4235
- triggerLabel = options.filter((o) => selectedArray.includes(o.value)).map((o) => o.label).join(", ");
4306
+ else {
4307
+ const labels = selectedArray.map((val) => getLabelForValue(val)).filter((label) => label !== null);
4308
+ triggerLabel = labels.length > 0 ? labels.join(", ") : placeholder;
4309
+ }
4236
4310
  } else {
4237
- const found = options.find((o) => o.value === singleSelected);
4238
- triggerLabel = found ? found.label : placeholder;
4311
+ const label = getLabelForValue(singleSelected);
4312
+ triggerLabel = label || placeholder;
4239
4313
  }
4240
4314
  const filteredOptions = onSearch ? options : !searchable ? options : options.filter(
4241
4315
  (o) => o.label.toLowerCase().includes(searchTerm.toLowerCase())
@@ -4249,6 +4323,7 @@ function SelectDropdown({
4249
4323
  }
4250
4324
  };
4251
4325
  const handleRemoveSelected = (value) => {
4326
+ selectedLabelsCacheRef.current.delete(value);
4252
4327
  if (onRemoveSelected) {
4253
4328
  onRemoveSelected(value);
4254
4329
  } else {
@@ -4268,13 +4343,14 @@ function SelectDropdown({
4268
4343
  if (multiple && selectedArray.length > 0) {
4269
4344
  return /* @__PURE__ */ jsxs("div", { className: "ina-select-dropdown__preview-content", children: [
4270
4345
  selectedArray.slice(0, 3).map((value, index) => {
4271
- const option = options.find((o) => o.value === value);
4346
+ const label = getLabelForValue(value);
4347
+ const displayLabel = label || value;
4272
4348
  return /* @__PURE__ */ jsxs(
4273
4349
  "div",
4274
4350
  {
4275
4351
  className: "ina-select-dropdown__preview-item ina-select-dropdown__preview-item--multiple",
4276
4352
  children: [
4277
- /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: (option == null ? void 0 : option.label) || value }),
4353
+ /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: displayLabel }),
4278
4354
  !disabled && /* @__PURE__ */ jsx(
4279
4355
  "button",
4280
4356
  {
@@ -4284,7 +4360,7 @@ function SelectDropdown({
4284
4360
  handleRemoveSelected(value);
4285
4361
  },
4286
4362
  className: "ina-select-dropdown__preview-remove ina-select-dropdown__preview-remove--multiple",
4287
- "aria-label": `Remove ${(option == null ? void 0 : option.label) || value}`,
4363
+ "aria-label": `Remove ${displayLabel}`,
4288
4364
  disabled,
4289
4365
  children: /* @__PURE__ */ jsx(IconX, { size: 12 })
4290
4366
  }
@@ -4302,9 +4378,10 @@ function SelectDropdown({
4302
4378
  ] });
4303
4379
  }
4304
4380
  if (!multiple && singleSelected !== null && singleSelected !== void 0 && singleSelected !== "") {
4305
- const option = options.find((o) => o.value === singleSelected);
4381
+ const label = getLabelForValue(singleSelected);
4382
+ const displayLabel = label || singleSelected;
4306
4383
  return /* @__PURE__ */ jsx("div", { className: "ina-select-dropdown__preview-content", children: /* @__PURE__ */ jsxs("div", { className: "ina-select-dropdown__preview-item ina-select-dropdown__preview-item--single", children: [
4307
- /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: (option == null ? void 0 : option.label) || singleSelected }),
4384
+ /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: displayLabel }),
4308
4385
  !disabled && /* @__PURE__ */ jsx(
4309
4386
  "button",
4310
4387
  {
@@ -4314,7 +4391,7 @@ function SelectDropdown({
4314
4391
  handleRemoveSelected(singleSelected);
4315
4392
  },
4316
4393
  className: "ina-select-dropdown__preview-remove ina-select-dropdown__preview-remove--single",
4317
- "aria-label": `Remove ${(option == null ? void 0 : option.label) || singleSelected}`,
4394
+ "aria-label": `Remove ${displayLabel}`,
4318
4395
  disabled,
4319
4396
  children: /* @__PURE__ */ jsx(IconX, { size: 12 })
4320
4397
  }
@@ -4448,11 +4525,27 @@ function SelectDropdown({
4448
4525
  if (disabled) return;
4449
4526
  if (multiple) {
4450
4527
  const prev = Array.isArray(selected) ? [...selected] : [];
4451
- onSelect(
4452
- prev.includes(option.value) ? prev.filter((v) => v !== option.value) : [...prev, option.value]
4453
- );
4528
+ const newSelected = prev.includes(option.value) ? prev.filter((v) => v !== option.value) : [...prev, option.value];
4529
+ if (prev.includes(option.value)) {
4530
+ selectedLabelsCacheRef.current.delete(option.value);
4531
+ } else {
4532
+ selectedLabelsCacheRef.current.set(
4533
+ option.value,
4534
+ option.label
4535
+ );
4536
+ }
4537
+ onSelect(newSelected);
4454
4538
  } else {
4455
- onSelect(isSelected ? null : option.value, option);
4539
+ if (isSelected) {
4540
+ selectedLabelsCacheRef.current.delete(option.value);
4541
+ onSelect(null, option);
4542
+ } else {
4543
+ selectedLabelsCacheRef.current.set(
4544
+ option.value,
4545
+ option.label
4546
+ );
4547
+ onSelect(option.value, option);
4548
+ }
4456
4549
  setIsOpen(false);
4457
4550
  if (isSearchControlled) {
4458
4551
  onSearchChange == null ? void 0 : onSearchChange("");