@idds/react 1.4.0 → 1.4.4

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
@@ -535,7 +535,9 @@ function clsx() {
535
535
  for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
536
536
  return n;
537
537
  }
538
- const AccordionGroupContext = createContext(null);
538
+ const AccordionGroupContext = createContext(
539
+ null
540
+ );
539
541
  function useAccordionGroup() {
540
542
  const context = useContext(AccordionGroupContext);
541
543
  return context;
@@ -557,19 +559,29 @@ function AccordionGroup(props) {
557
559
  const [version, setVersion] = useState(0);
558
560
  const openIndexesRef = useRef(openIndexes);
559
561
  openIndexesRef.current = openIndexes;
560
- const registerItem = useCallback((itemId, defaultOpen) => {
561
- const index = itemsRef.current.size;
562
- itemsRef.current.set(itemId, index);
563
- if (!allowMultiple && defaultOpen) {
564
- setOpenIndexes((prev) => {
565
- if (prev.length === 0) {
566
- return [index];
567
- }
568
- return prev;
569
- });
570
- }
571
- return index;
572
- }, [allowMultiple]);
562
+ const registerItem = useCallback(
563
+ (itemId, defaultOpen) => {
564
+ const index = itemsRef.current.size;
565
+ itemsRef.current.set(itemId, index);
566
+ if (defaultOpen) {
567
+ setOpenIndexes((prev) => {
568
+ if (allowMultiple) {
569
+ if (!prev.includes(index)) {
570
+ return [...prev, index];
571
+ }
572
+ return prev;
573
+ } else {
574
+ if (prev.length === 0) {
575
+ return [index];
576
+ }
577
+ return prev;
578
+ }
579
+ });
580
+ }
581
+ return index;
582
+ },
583
+ [allowMultiple]
584
+ );
573
585
  const unregisterItem = useCallback((itemId) => {
574
586
  const index = itemsRef.current.get(itemId);
575
587
  if (index !== void 0) {
@@ -629,7 +641,14 @@ function AccordionGroup(props) {
629
641
  version
630
642
  // Include version untuk trigger re-render
631
643
  }),
632
- [allowMultiple, registerItem, unregisterItem, handleItemToggle, isItemOpen, version]
644
+ [
645
+ allowMultiple,
646
+ registerItem,
647
+ unregisterItem,
648
+ handleItemToggle,
649
+ isItemOpen,
650
+ version
651
+ ]
633
652
  );
634
653
  return /* @__PURE__ */ jsx(AccordionGroupContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx("div", { className: clsx("ina-accordion-group", className), children }) });
635
654
  }
@@ -2839,13 +2858,13 @@ function FileUpload({
2839
2858
  uploadedFile.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-icon-wrapper ina-file-upload__file-icon-wrapper--uploading", children: /* @__PURE__ */ jsx(
2840
2859
  IconLoader2,
2841
2860
  {
2842
- size: 16,
2861
+ size: 20,
2843
2862
  className: "ina-file-upload__file-icon--spinning"
2844
2863
  }
2845
2864
  ) }),
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" }) })
2865
+ 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" }) }),
2866
+ 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" }) }),
2867
+ 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
2868
  ] }),
2850
2869
  /* @__PURE__ */ jsxs("div", { className: "ina-file-upload__file-info", children: [
2851
2870
  /* @__PURE__ */ jsx("div", { className: "ina-file-upload__file-name", children: sanitizeFileName(uploadedFile.file.name) }),
@@ -2863,7 +2882,7 @@ function FileUpload({
2863
2882
  updateFileStatus(originalIndex, "idle");
2864
2883
  },
2865
2884
  title: "Coba lagi",
2866
- children: /* @__PURE__ */ jsx(IconRotateClockwise, { size: 16 })
2885
+ children: /* @__PURE__ */ jsx(IconRotateClockwise, { size: 20 })
2867
2886
  }
2868
2887
  ),
2869
2888
  /* @__PURE__ */ jsx(
@@ -2873,7 +2892,7 @@ function FileUpload({
2873
2892
  className: "ina-file-upload__file-remove",
2874
2893
  onClick: () => removeFile(originalIndex),
2875
2894
  title: "Hapus file",
2876
- children: /* @__PURE__ */ jsx(IconTrash, { size: 16 })
2895
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
2877
2896
  }
2878
2897
  )
2879
2898
  ] }),
@@ -2884,7 +2903,7 @@ function FileUpload({
2884
2903
  className: "ina-file-upload__file-remove",
2885
2904
  onClick: () => removeFile(originalIndex),
2886
2905
  title: "Batalkan upload",
2887
- children: /* @__PURE__ */ jsx(IconX, { size: 16 })
2906
+ children: /* @__PURE__ */ jsx(IconX, { size: 20 })
2888
2907
  }
2889
2908
  ),
2890
2909
  uploadedFile.status === "success" && /* @__PURE__ */ jsx(
@@ -2894,7 +2913,7 @@ function FileUpload({
2894
2913
  className: "ina-file-upload__file-remove",
2895
2914
  onClick: () => removeFile(originalIndex),
2896
2915
  title: "Hapus file",
2897
- children: /* @__PURE__ */ jsx(IconTrash, { size: 16 })
2916
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
2898
2917
  }
2899
2918
  ),
2900
2919
  uploadedFile.status === "idle" && /* @__PURE__ */ jsx(
@@ -2904,7 +2923,7 @@ function FileUpload({
2904
2923
  className: "ina-file-upload__file-remove",
2905
2924
  onClick: () => removeFile(originalIndex),
2906
2925
  title: "Hapus file",
2907
- children: /* @__PURE__ */ jsx(IconTrash, { size: 16 })
2926
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
2908
2927
  }
2909
2928
  )
2910
2929
  ] })
@@ -3261,7 +3280,7 @@ function SingleFileUpload({
3261
3280
  handleRemove();
3262
3281
  },
3263
3282
  "aria-label": "Remove file",
3264
- children: /* @__PURE__ */ jsx(IconTrash, { size: 20 })
3283
+ children: /* @__PURE__ */ jsx(IconTrash, { size: 18 })
3265
3284
  }
3266
3285
  )
3267
3286
  ] })
@@ -4162,13 +4181,15 @@ function SelectDropdown({
4162
4181
  onSearchChange,
4163
4182
  disabled = false,
4164
4183
  showPreviewValue = true,
4165
- searchable = true
4184
+ searchable = true,
4185
+ onSelectedRawChange
4166
4186
  }) {
4167
4187
  const [isOpen, setIsOpen] = useState(false);
4168
4188
  const [internalSearchTerm, setInternalSearchTerm] = useState("");
4169
4189
  const containerRef = useRef(null);
4170
4190
  const scrollContainerRef = useRef(null);
4171
4191
  const searchTimeoutRef = useRef(null);
4192
+ const selectedLabelsCacheRef = useRef(/* @__PURE__ */ new Map());
4172
4193
  const isSearchControlled = searchValue !== void 0;
4173
4194
  const searchTerm = isSearchControlled ? searchValue : internalSearchTerm;
4174
4195
  useEffect(() => {
@@ -4226,16 +4247,88 @@ function SelectDropdown({
4226
4247
  const isArraySelected = multiple && Array.isArray(selected);
4227
4248
  const selectedArray = isArraySelected ? selected : [];
4228
4249
  const singleSelected = !multiple ? selected : null;
4250
+ const getLabelForValue = (value) => {
4251
+ if (selectedLabelsCacheRef.current.has(value)) {
4252
+ return selectedLabelsCacheRef.current.get(value) || null;
4253
+ }
4254
+ const found = options.find((o) => o.value === value);
4255
+ if (found) {
4256
+ selectedLabelsCacheRef.current.set(value, found.label);
4257
+ return found.label;
4258
+ }
4259
+ return null;
4260
+ };
4261
+ const getOptionForValue = (value) => {
4262
+ const label = getLabelForValue(value);
4263
+ if (label !== null) {
4264
+ return { label, value };
4265
+ }
4266
+ const found = options.find((o) => o.value === value);
4267
+ return found || null;
4268
+ };
4269
+ useEffect(() => {
4270
+ if (onSelectedRawChange) {
4271
+ let selectedRaw = null;
4272
+ if (multiple) {
4273
+ if (selectedArray.length > 0) {
4274
+ const rawOptions = selectedArray.map((val) => getOptionForValue(val)).filter((opt) => opt !== null);
4275
+ selectedRaw = rawOptions.length > 0 ? rawOptions : null;
4276
+ }
4277
+ } else {
4278
+ if (singleSelected !== null && singleSelected !== void 0 && singleSelected !== "") {
4279
+ selectedRaw = getOptionForValue(singleSelected);
4280
+ }
4281
+ }
4282
+ onSelectedRawChange(selectedRaw);
4283
+ }
4284
+ }, [selected, multiple, options]);
4285
+ useEffect(() => {
4286
+ const cache = selectedLabelsCacheRef.current;
4287
+ options.forEach((option) => {
4288
+ if (cache.has(option.value)) {
4289
+ cache.set(option.value, option.label);
4290
+ }
4291
+ });
4292
+ }, [options]);
4293
+ useEffect(() => {
4294
+ const cache = selectedLabelsCacheRef.current;
4295
+ if (multiple && Array.isArray(selected)) {
4296
+ selected.forEach((value) => {
4297
+ if (!cache.has(value)) {
4298
+ const found = options.find((o) => o.value === value);
4299
+ if (found) {
4300
+ cache.set(value, found.label);
4301
+ }
4302
+ }
4303
+ });
4304
+ cache.forEach((_, value) => {
4305
+ if (!selected.includes(value)) {
4306
+ cache.delete(value);
4307
+ }
4308
+ });
4309
+ } else if (selected !== null && selected !== void 0 && selected !== "") {
4310
+ if (!cache.has(selected)) {
4311
+ const found = options.find((o) => o.value === selected);
4312
+ if (found) {
4313
+ cache.set(selected, found.label);
4314
+ }
4315
+ }
4316
+ } else {
4317
+ cache.clear();
4318
+ }
4319
+ }, [selected, multiple, options]);
4229
4320
  let triggerLabel;
4230
4321
  if (multiple) {
4231
4322
  if (!selectedArray.length) triggerLabel = placeholder;
4232
4323
  else if (selectedArray.length > 3)
4233
4324
  triggerLabel = `${selectedArray.length} data terpilih`;
4234
- else
4235
- triggerLabel = options.filter((o) => selectedArray.includes(o.value)).map((o) => o.label).join(", ");
4325
+ else {
4326
+ const labels = selectedArray.map((val) => getLabelForValue(val)).filter((label) => label !== null);
4327
+ triggerLabel = labels.length > 0 ? labels.join(", ") : placeholder;
4328
+ }
4236
4329
  } else {
4237
- const found = options.find((o) => o.value === singleSelected);
4238
- triggerLabel = found ? found.label : placeholder;
4330
+ const label = getLabelForValue(singleSelected);
4331
+ triggerLabel = label || placeholder;
4239
4332
  }
4240
4333
  const filteredOptions = onSearch ? options : !searchable ? options : options.filter(
4241
4334
  (o) => o.label.toLowerCase().includes(searchTerm.toLowerCase())
@@ -4249,6 +4342,7 @@ function SelectDropdown({
4249
4342
  }
4250
4343
  };
4251
4344
  const handleRemoveSelected = (value) => {
4345
+ selectedLabelsCacheRef.current.delete(value);
4252
4346
  if (onRemoveSelected) {
4253
4347
  onRemoveSelected(value);
4254
4348
  } else {
@@ -4268,13 +4362,14 @@ function SelectDropdown({
4268
4362
  if (multiple && selectedArray.length > 0) {
4269
4363
  return /* @__PURE__ */ jsxs("div", { className: "ina-select-dropdown__preview-content", children: [
4270
4364
  selectedArray.slice(0, 3).map((value, index) => {
4271
- const option = options.find((o) => o.value === value);
4365
+ const label = getLabelForValue(value);
4366
+ const displayLabel = label || value;
4272
4367
  return /* @__PURE__ */ jsxs(
4273
4368
  "div",
4274
4369
  {
4275
4370
  className: "ina-select-dropdown__preview-item ina-select-dropdown__preview-item--multiple",
4276
4371
  children: [
4277
- /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: (option == null ? void 0 : option.label) || value }),
4372
+ /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: displayLabel }),
4278
4373
  !disabled && /* @__PURE__ */ jsx(
4279
4374
  "button",
4280
4375
  {
@@ -4284,7 +4379,7 @@ function SelectDropdown({
4284
4379
  handleRemoveSelected(value);
4285
4380
  },
4286
4381
  className: "ina-select-dropdown__preview-remove ina-select-dropdown__preview-remove--multiple",
4287
- "aria-label": `Remove ${(option == null ? void 0 : option.label) || value}`,
4382
+ "aria-label": `Remove ${displayLabel}`,
4288
4383
  disabled,
4289
4384
  children: /* @__PURE__ */ jsx(IconX, { size: 12 })
4290
4385
  }
@@ -4302,9 +4397,10 @@ function SelectDropdown({
4302
4397
  ] });
4303
4398
  }
4304
4399
  if (!multiple && singleSelected !== null && singleSelected !== void 0 && singleSelected !== "") {
4305
- const option = options.find((o) => o.value === singleSelected);
4400
+ const label = getLabelForValue(singleSelected);
4401
+ const displayLabel = label || singleSelected;
4306
4402
  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 }),
4403
+ /* @__PURE__ */ jsx("span", { className: "ina-select-dropdown__preview-item-text", children: displayLabel }),
4308
4404
  !disabled && /* @__PURE__ */ jsx(
4309
4405
  "button",
4310
4406
  {
@@ -4314,7 +4410,7 @@ function SelectDropdown({
4314
4410
  handleRemoveSelected(singleSelected);
4315
4411
  },
4316
4412
  className: "ina-select-dropdown__preview-remove ina-select-dropdown__preview-remove--single",
4317
- "aria-label": `Remove ${(option == null ? void 0 : option.label) || singleSelected}`,
4413
+ "aria-label": `Remove ${displayLabel}`,
4318
4414
  disabled,
4319
4415
  children: /* @__PURE__ */ jsx(IconX, { size: 12 })
4320
4416
  }
@@ -4448,11 +4544,27 @@ function SelectDropdown({
4448
4544
  if (disabled) return;
4449
4545
  if (multiple) {
4450
4546
  const prev = Array.isArray(selected) ? [...selected] : [];
4451
- onSelect(
4452
- prev.includes(option.value) ? prev.filter((v) => v !== option.value) : [...prev, option.value]
4453
- );
4547
+ const newSelected = prev.includes(option.value) ? prev.filter((v) => v !== option.value) : [...prev, option.value];
4548
+ if (prev.includes(option.value)) {
4549
+ selectedLabelsCacheRef.current.delete(option.value);
4550
+ } else {
4551
+ selectedLabelsCacheRef.current.set(
4552
+ option.value,
4553
+ option.label
4554
+ );
4555
+ }
4556
+ onSelect(newSelected);
4454
4557
  } else {
4455
- onSelect(isSelected ? null : option.value, option);
4558
+ if (isSelected) {
4559
+ selectedLabelsCacheRef.current.delete(option.value);
4560
+ onSelect(null, option);
4561
+ } else {
4562
+ selectedLabelsCacheRef.current.set(
4563
+ option.value,
4564
+ option.label
4565
+ );
4566
+ onSelect(option.value, option);
4567
+ }
4456
4568
  setIsOpen(false);
4457
4569
  if (isSearchControlled) {
4458
4570
  onSearchChange == null ? void 0 : onSearchChange("");