@esic-lab/data-core-ui 0.0.46 → 0.0.47

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.css CHANGED
@@ -29,6 +29,7 @@
29
29
  --color-red-600: #ee443f;
30
30
  --color-red-700: #a9302d;
31
31
  --color-yellow-400: #ffbb33;
32
+ --color-yellow-500: #ffaa00;
32
33
  --color-green-400: #69c57d;
33
34
  --color-green-500: #43b75d;
34
35
  --color-green-600: #3da755;
@@ -339,8 +340,8 @@
339
340
  .mt-4 {
340
341
  margin-top: calc(var(--spacing) * 4);
341
342
  }
342
- .mt-7 {
343
- margin-top: calc(var(--spacing) * 7);
343
+ .mt-8 {
344
+ margin-top: calc(var(--spacing) * 8);
344
345
  }
345
346
  .mt-\[-12px\] {
346
347
  margin-top: -12px;
@@ -751,6 +752,13 @@
751
752
  margin-block-end: calc(calc(var(--spacing) * 1) * calc(1 - var(--tw-space-y-reverse)));
752
753
  }
753
754
  }
755
+ .space-y-2 {
756
+ :where(& > :not(:last-child)) {
757
+ --tw-space-y-reverse: 0;
758
+ margin-block-start: calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));
759
+ margin-block-end: calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)));
760
+ }
761
+ }
754
762
  .space-y-4 {
755
763
  :where(& > :not(:last-child)) {
756
764
  --tw-space-y-reverse: 0;
@@ -1140,6 +1148,9 @@
1140
1148
  .text-white {
1141
1149
  color: var(--color-white);
1142
1150
  }
1151
+ .text-yellow-500 {
1152
+ color: var(--color-yellow-500);
1153
+ }
1143
1154
  .uppercase {
1144
1155
  text-transform: uppercase;
1145
1156
  }
package/dist/index.d.mts CHANGED
@@ -523,16 +523,22 @@ interface IndicatorProps {
523
523
  }[];
524
524
  type: "OUTPUT" | "OUTCOME";
525
525
  arrayData: IndicatorArray[];
526
+ canEdit?: boolean;
526
527
  setArrayData: (data: IndicatorArray[]) => void;
528
+ onDeleteClick?: (payload: {
529
+ index: number;
530
+ item: IndicatorArray;
531
+ confirm: () => void;
532
+ }) => void;
527
533
  }
528
534
  interface IndicatorArray {
529
535
  indicatorType: "OUTPUT" | "OUTCOME";
530
536
  inputType: "TEXT" | "NUMBER";
531
537
  textValue: string;
532
- numberValue?: string;
538
+ numberValue?: number;
533
539
  unit?: string;
534
540
  }
535
- declare function Indicator({ option, type, arrayData, setArrayData, }: IndicatorProps): react_jsx_runtime.JSX.Element;
541
+ declare function Indicator({ option, type, arrayData, setArrayData, canEdit, onDeleteClick, }: IndicatorProps): react_jsx_runtime.JSX.Element;
536
542
 
537
543
  interface optionSelect {
538
544
  value: string;
package/dist/index.d.ts CHANGED
@@ -523,16 +523,22 @@ interface IndicatorProps {
523
523
  }[];
524
524
  type: "OUTPUT" | "OUTCOME";
525
525
  arrayData: IndicatorArray[];
526
+ canEdit?: boolean;
526
527
  setArrayData: (data: IndicatorArray[]) => void;
528
+ onDeleteClick?: (payload: {
529
+ index: number;
530
+ item: IndicatorArray;
531
+ confirm: () => void;
532
+ }) => void;
527
533
  }
528
534
  interface IndicatorArray {
529
535
  indicatorType: "OUTPUT" | "OUTCOME";
530
536
  inputType: "TEXT" | "NUMBER";
531
537
  textValue: string;
532
- numberValue?: string;
538
+ numberValue?: number;
533
539
  unit?: string;
534
540
  }
535
- declare function Indicator({ option, type, arrayData, setArrayData, }: IndicatorProps): react_jsx_runtime.JSX.Element;
541
+ declare function Indicator({ option, type, arrayData, setArrayData, canEdit, onDeleteClick, }: IndicatorProps): react_jsx_runtime.JSX.Element;
536
542
 
537
543
  interface optionSelect {
538
544
  value: string;
package/dist/index.js CHANGED
@@ -3753,41 +3753,66 @@ function Indicator({
3753
3753
  ],
3754
3754
  type,
3755
3755
  arrayData,
3756
- setArrayData
3756
+ setArrayData,
3757
+ canEdit,
3758
+ onDeleteClick
3757
3759
  }) {
3758
3760
  const [valueSwitch, setValueSwitch] = (0, import_react17.useState)("TEXT");
3759
3761
  const [cacheData, setCacheData] = (0, import_react17.useState)({
3760
3762
  indicatorType: type,
3761
3763
  inputType: valueSwitch,
3762
3764
  textValue: "",
3763
- numberValue: "",
3765
+ numberValue: 0,
3764
3766
  unit: ""
3765
3767
  });
3766
3768
  const [cacheEditData, setCacheEditData] = (0, import_react17.useState)({
3767
3769
  indicatorType: type,
3768
3770
  inputType: valueSwitch,
3769
3771
  textValue: "",
3770
- numberValue: "",
3772
+ numberValue: 0,
3771
3773
  unit: ""
3772
3774
  });
3773
3775
  const [editIndex, setEditIndex] = (0, import_react17.useState)(null);
3776
+ const [addError, setAddError] = (0, import_react17.useState)({});
3777
+ const [editError, setEditError] = (0, import_react17.useState)({});
3774
3778
  const handleAddIndicator = () => {
3775
- if (cacheData.textValue.trim() === "") return;
3776
- setArrayData([
3777
- ...arrayData,
3778
- valueSwitch === "TEXT" ? {
3779
- indicatorType: type,
3780
- inputType: "TEXT",
3781
- textValue: cacheData.textValue
3782
- } : cacheData
3783
- ]);
3779
+ const nextErr = {};
3780
+ const textValue = (cacheData.textValue ?? "").trim();
3781
+ const unit = (cacheData.unit ?? "").trim();
3782
+ if (textValue === "") {
3783
+ nextErr.textValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14";
3784
+ }
3785
+ if (valueSwitch === "NUMBER") {
3786
+ const num = cacheData.numberValue;
3787
+ if (num === void 0 || num === null || Number(num) <= 0) {
3788
+ nextErr.numberValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02";
3789
+ }
3790
+ if (unit === "") {
3791
+ nextErr.unit = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E2B\u0E19\u0E48\u0E27\u0E22";
3792
+ }
3793
+ }
3794
+ setAddError(nextErr);
3795
+ if (Object.keys(nextErr).length > 0) return;
3796
+ const newItem = valueSwitch === "TEXT" ? {
3797
+ indicatorType: type,
3798
+ inputType: "TEXT",
3799
+ textValue
3800
+ } : {
3801
+ indicatorType: type,
3802
+ inputType: "NUMBER",
3803
+ textValue,
3804
+ numberValue: Number(cacheData.numberValue),
3805
+ unit
3806
+ };
3807
+ setArrayData([...arrayData, newItem]);
3784
3808
  setCacheData({
3785
3809
  indicatorType: type,
3786
3810
  inputType: valueSwitch,
3787
3811
  textValue: "",
3788
- numberValue: "",
3812
+ numberValue: 0,
3789
3813
  unit: ""
3790
3814
  });
3815
+ setAddError({});
3791
3816
  };
3792
3817
  const handleChangeCashData = (key, value) => {
3793
3818
  setCacheData((prev) => ({
@@ -3813,11 +3838,32 @@ function Indicator({
3813
3838
  setEditIndex(null);
3814
3839
  };
3815
3840
  const handleConfirmEditIndicator = (index) => {
3816
- if (cacheEditData.textValue.trim() === "") return;
3841
+ const nextErr = {};
3842
+ const textValue = (cacheEditData.textValue ?? "").trim();
3843
+ const unit = (cacheEditData.unit ?? "").trim();
3844
+ const num = cacheEditData.numberValue;
3845
+ if (textValue === "") {
3846
+ nextErr.textValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14";
3847
+ }
3848
+ if (cacheEditData.inputType === "NUMBER") {
3849
+ if (num === void 0 || num === null || Number(num) <= 0) {
3850
+ nextErr.numberValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02";
3851
+ }
3852
+ if (unit === "") {
3853
+ nextErr.unit = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E2B\u0E19\u0E48\u0E27\u0E22";
3854
+ }
3855
+ }
3856
+ setEditError(nextErr);
3857
+ if (Object.keys(nextErr).length > 0) return;
3817
3858
  const newData = [...arrayData];
3818
- newData[index] = cacheEditData;
3859
+ newData[index] = {
3860
+ ...cacheEditData,
3861
+ textValue,
3862
+ ...cacheEditData.inputType === "NUMBER" ? { numberValue: Number(num), unit } : { numberValue: void 0, unit: void 0 }
3863
+ };
3819
3864
  setArrayData(newData);
3820
3865
  setEditIndex(null);
3866
+ setEditError({});
3821
3867
  };
3822
3868
  const handleChangeEditCashData = (e) => {
3823
3869
  const { name, value } = e.target;
@@ -3833,16 +3879,29 @@ function Indicator({
3833
3879
  {
3834
3880
  className: `space-x-2 grid ${valueSwitch === "TEXT" ? `grid-cols-[140px_1fr_50px]` : `grid-cols-[140px_1fr_200px_200px_50px]`} items-start`,
3835
3881
  children: [
3836
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(SwitchSelect, { option, onClick: handleClick, value: valueSwitch, label: "\u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17", required: true }),
3882
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3883
+ SwitchSelect,
3884
+ {
3885
+ option,
3886
+ onClick: handleClick,
3887
+ value: valueSwitch,
3888
+ label: "\u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17",
3889
+ required: true
3890
+ }
3891
+ ),
3837
3892
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3838
3893
  InputField,
3839
3894
  {
3840
3895
  label: `\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3841
3896
  value: cacheData.textValue,
3842
3897
  className: "h-[32px]",
3843
- onChange: (e) => handleChangeCashData("textValue", String(e)),
3898
+ onChange: (val) => {
3899
+ handleChangeCashData("textValue", val ?? "");
3900
+ setAddError((p) => ({ ...p, textValue: void 0 }));
3901
+ },
3844
3902
  placeholder: `\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3845
- required: true
3903
+ required: true,
3904
+ error: addError.textValue
3846
3905
  }
3847
3906
  ),
3848
3907
  valueSwitch === "NUMBER" && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
@@ -3850,11 +3909,16 @@ function Indicator({
3850
3909
  InputFieldNumber,
3851
3910
  {
3852
3911
  label: `\u0E04\u0E48\u0E32\u0E40\u0E1B\u0E49\u0E32\u0E2B\u0E21\u0E32\u0E22${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3853
- value: cacheData.numberValue ?? "",
3912
+ value: cacheData.numberValue ?? 0,
3854
3913
  className: "h-[32px]",
3855
- onChange: (e) => handleChangeCashData("numberValue", String(e)),
3914
+ onChange: (val) => {
3915
+ handleChangeCashData("numberValue", val ?? 0);
3916
+ setAddError((p) => ({ ...p, numberValue: void 0 }));
3917
+ },
3918
+ min: 0,
3856
3919
  placeholder: `\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32\u0E40\u0E1B\u0E49\u0E32\u0E2B\u0E21\u0E32\u0E22${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3857
- required: true
3920
+ required: true,
3921
+ error: addError.numberValue
3858
3922
  }
3859
3923
  ),
3860
3924
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
@@ -3863,53 +3927,83 @@ function Indicator({
3863
3927
  label: `\u0E2B\u0E19\u0E48\u0E27\u0E22`,
3864
3928
  value: cacheData.unit ?? "",
3865
3929
  className: "h-[32px]",
3866
- onChange: (e) => handleChangeCashData("unit", String(e)),
3930
+ onChange: (val) => {
3931
+ handleChangeCashData("unit", val ?? "");
3932
+ setAddError((p) => ({ ...p, unit: void 0 }));
3933
+ },
3867
3934
  placeholder: "\u0E23\u0E30\u0E1A\u0E38\u0E2B\u0E19\u0E48\u0E27\u0E22",
3868
- required: true
3935
+ required: true,
3936
+ error: addError.unit
3869
3937
  }
3870
3938
  )
3871
3939
  ] }),
3872
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_icons_react12.IconCirclePlus, { onClick: handleAddIndicator, className: "mt-7 cursor-pointer", size: 32 })
3940
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3941
+ import_icons_react12.IconCirclePlus,
3942
+ {
3943
+ onClick: handleAddIndicator,
3944
+ className: "mt-8 cursor-pointer",
3945
+ size: 32
3946
+ }
3947
+ )
3873
3948
  ]
3874
3949
  }
3875
3950
  ),
3876
3951
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_jsx_runtime40.Fragment, { children: arrayData.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
3877
3952
  "div",
3878
3953
  {
3879
- className: `space-y-4 grid ${item.inputType === "TEXT" ? `grid-cols-[140px_1fr_50px_50px]` : `grid-cols-[140px_1fr_200px_150px_50px_50px]`} items-start`,
3954
+ className: `space-y-2 grid ${item.inputType === "TEXT" ? `grid-cols-[140px_1fr_50px_50px]` : `grid-cols-[140px_1fr_200px_150px_50px_50px]`} items-start`,
3880
3955
  children: [
3881
3956
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.inputType === "TEXT" ? "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21" : "\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02" }),
3882
- index === editIndex ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3883
- import_antd20.Input,
3884
- {
3885
- className: "body-1 mt-2",
3886
- variant: "underlined",
3887
- value: cacheEditData.textValue,
3888
- name: "textValue",
3889
- onChange: (e) => handleChangeEditCashData(e)
3890
- }
3891
- ) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.textValue }),
3892
- item.inputType === "NUMBER" && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
3893
- index === editIndex ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3894
- import_antd20.Input,
3895
- {
3896
- className: "body-1 mt-2",
3897
- variant: "underlined",
3898
- value: cacheEditData.numberValue,
3899
- name: "numberValue",
3900
- onChange: (e) => handleChangeEditCashData(e)
3901
- }
3902
- ) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.numberValue }),
3903
- index === editIndex ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3957
+ index === editIndex ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-col gap-[8px]", children: [
3958
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3904
3959
  import_antd20.Input,
3905
3960
  {
3906
3961
  className: "body-1 mt-2",
3907
3962
  variant: "underlined",
3908
- value: cacheEditData.unit,
3909
- name: "unit",
3910
- onChange: (e) => handleChangeEditCashData(e)
3963
+ value: cacheEditData.textValue,
3964
+ name: "textValue",
3965
+ onChange: (e) => {
3966
+ handleChangeEditCashData(e);
3967
+ setEditError((p) => ({ ...p, textValue: void 0 }));
3968
+ }
3911
3969
  }
3912
- ) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.unit })
3970
+ ),
3971
+ editError.textValue && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "text-red-500 caption-1", children: editError.textValue })
3972
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.textValue }),
3973
+ item.inputType === "NUMBER" && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
3974
+ index === editIndex ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-col gap-[8px]", children: [
3975
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3976
+ import_antd20.Input,
3977
+ {
3978
+ type: "number",
3979
+ className: "body-1 mt-2",
3980
+ variant: "underlined",
3981
+ value: cacheEditData.numberValue,
3982
+ name: "numberValue",
3983
+ onChange: (e) => {
3984
+ handleChangeEditCashData(e);
3985
+ setEditError((p) => ({ ...p, numberValue: void 0 }));
3986
+ }
3987
+ }
3988
+ ),
3989
+ editError.numberValue && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "text-red-500 caption-1", children: editError.numberValue })
3990
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.numberValue }),
3991
+ index === editIndex ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-col gap-[8px]", children: [
3992
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3993
+ import_antd20.Input,
3994
+ {
3995
+ className: "body-1 mt-2",
3996
+ variant: "underlined",
3997
+ value: cacheEditData.unit,
3998
+ name: "unit",
3999
+ onChange: (e) => {
4000
+ handleChangeEditCashData(e);
4001
+ setEditError((p) => ({ ...p, unit: void 0 }));
4002
+ }
4003
+ }
4004
+ ),
4005
+ editError.unit && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "text-red-500 caption-1", children: editError.unit })
4006
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2", children: item.unit })
3913
4007
  ] }),
3914
4008
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2 flex", children: editIndex !== null ? editIndex === index ? /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex", children: [
3915
4009
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
@@ -3919,11 +4013,36 @@ function Indicator({
3919
4013
  onClick: () => handleConfirmEditIndicator(index)
3920
4014
  }
3921
4015
  ),
3922
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_icons_react12.IconX, { className: "cursor-pointer text-red-600", onClick: handleCancelEditIndicator })
3923
- ] }) : void 0 : /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_icons_react12.IconPencil, { className: "cursor-pointer", onClick: () => handleEditIndicator(index) }) }),
3924
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2 cursor-pointer", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_icons_react12.IconTrash, { onClick: () => handleDeleteIndicator(index) }) })
4016
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
4017
+ import_icons_react12.IconX,
4018
+ {
4019
+ className: "cursor-pointer text-red-600",
4020
+ onClick: handleCancelEditIndicator
4021
+ }
4022
+ )
4023
+ ] }) : void 0 : canEdit && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
4024
+ import_icons_react12.IconPencil,
4025
+ {
4026
+ className: "cursor-pointer",
4027
+ onClick: () => handleEditIndicator(index)
4028
+ }
4029
+ ) }),
4030
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "body-1 mt-2 cursor-pointer", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
4031
+ import_icons_react12.IconTrash,
4032
+ {
4033
+ onClick: () => {
4034
+ const confirm = () => handleDeleteIndicator(index);
4035
+ if (onDeleteClick) {
4036
+ onDeleteClick({ index, item, confirm });
4037
+ } else {
4038
+ confirm();
4039
+ }
4040
+ }
4041
+ }
4042
+ ) })
3925
4043
  ]
3926
- }
4044
+ },
4045
+ index
3927
4046
  )) })
3928
4047
  ] });
3929
4048
  }
package/dist/index.mjs CHANGED
@@ -3681,7 +3681,13 @@ function AntDModal({ children, isOpen, width, onCancel }) {
3681
3681
  }
3682
3682
 
3683
3683
  // src/Indicator/Indicator/Indicator.tsx
3684
- import { IconCheck as IconCheck3, IconCirclePlus as IconCirclePlus2, IconPencil as IconPencil2, IconTrash as IconTrash4, IconX as IconX3 } from "@tabler/icons-react";
3684
+ import {
3685
+ IconCheck as IconCheck3,
3686
+ IconCirclePlus as IconCirclePlus2,
3687
+ IconPencil as IconPencil2,
3688
+ IconTrash as IconTrash4,
3689
+ IconX as IconX3
3690
+ } from "@tabler/icons-react";
3685
3691
  import { useState as useState15 } from "react";
3686
3692
  import { Input as Input4 } from "antd";
3687
3693
  import { Fragment as Fragment7, jsx as jsx40, jsxs as jsxs34 } from "react/jsx-runtime";
@@ -3692,41 +3698,66 @@ function Indicator({
3692
3698
  ],
3693
3699
  type,
3694
3700
  arrayData,
3695
- setArrayData
3701
+ setArrayData,
3702
+ canEdit,
3703
+ onDeleteClick
3696
3704
  }) {
3697
3705
  const [valueSwitch, setValueSwitch] = useState15("TEXT");
3698
3706
  const [cacheData, setCacheData] = useState15({
3699
3707
  indicatorType: type,
3700
3708
  inputType: valueSwitch,
3701
3709
  textValue: "",
3702
- numberValue: "",
3710
+ numberValue: 0,
3703
3711
  unit: ""
3704
3712
  });
3705
3713
  const [cacheEditData, setCacheEditData] = useState15({
3706
3714
  indicatorType: type,
3707
3715
  inputType: valueSwitch,
3708
3716
  textValue: "",
3709
- numberValue: "",
3717
+ numberValue: 0,
3710
3718
  unit: ""
3711
3719
  });
3712
3720
  const [editIndex, setEditIndex] = useState15(null);
3721
+ const [addError, setAddError] = useState15({});
3722
+ const [editError, setEditError] = useState15({});
3713
3723
  const handleAddIndicator = () => {
3714
- if (cacheData.textValue.trim() === "") return;
3715
- setArrayData([
3716
- ...arrayData,
3717
- valueSwitch === "TEXT" ? {
3718
- indicatorType: type,
3719
- inputType: "TEXT",
3720
- textValue: cacheData.textValue
3721
- } : cacheData
3722
- ]);
3724
+ const nextErr = {};
3725
+ const textValue = (cacheData.textValue ?? "").trim();
3726
+ const unit = (cacheData.unit ?? "").trim();
3727
+ if (textValue === "") {
3728
+ nextErr.textValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14";
3729
+ }
3730
+ if (valueSwitch === "NUMBER") {
3731
+ const num = cacheData.numberValue;
3732
+ if (num === void 0 || num === null || Number(num) <= 0) {
3733
+ nextErr.numberValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02";
3734
+ }
3735
+ if (unit === "") {
3736
+ nextErr.unit = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E2B\u0E19\u0E48\u0E27\u0E22";
3737
+ }
3738
+ }
3739
+ setAddError(nextErr);
3740
+ if (Object.keys(nextErr).length > 0) return;
3741
+ const newItem = valueSwitch === "TEXT" ? {
3742
+ indicatorType: type,
3743
+ inputType: "TEXT",
3744
+ textValue
3745
+ } : {
3746
+ indicatorType: type,
3747
+ inputType: "NUMBER",
3748
+ textValue,
3749
+ numberValue: Number(cacheData.numberValue),
3750
+ unit
3751
+ };
3752
+ setArrayData([...arrayData, newItem]);
3723
3753
  setCacheData({
3724
3754
  indicatorType: type,
3725
3755
  inputType: valueSwitch,
3726
3756
  textValue: "",
3727
- numberValue: "",
3757
+ numberValue: 0,
3728
3758
  unit: ""
3729
3759
  });
3760
+ setAddError({});
3730
3761
  };
3731
3762
  const handleChangeCashData = (key, value) => {
3732
3763
  setCacheData((prev) => ({
@@ -3752,11 +3783,32 @@ function Indicator({
3752
3783
  setEditIndex(null);
3753
3784
  };
3754
3785
  const handleConfirmEditIndicator = (index) => {
3755
- if (cacheEditData.textValue.trim() === "") return;
3786
+ const nextErr = {};
3787
+ const textValue = (cacheEditData.textValue ?? "").trim();
3788
+ const unit = (cacheEditData.unit ?? "").trim();
3789
+ const num = cacheEditData.numberValue;
3790
+ if (textValue === "") {
3791
+ nextErr.textValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14";
3792
+ }
3793
+ if (cacheEditData.inputType === "NUMBER") {
3794
+ if (num === void 0 || num === null || Number(num) <= 0) {
3795
+ nextErr.numberValue = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02";
3796
+ }
3797
+ if (unit === "") {
3798
+ nextErr.unit = "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E2B\u0E19\u0E48\u0E27\u0E22";
3799
+ }
3800
+ }
3801
+ setEditError(nextErr);
3802
+ if (Object.keys(nextErr).length > 0) return;
3756
3803
  const newData = [...arrayData];
3757
- newData[index] = cacheEditData;
3804
+ newData[index] = {
3805
+ ...cacheEditData,
3806
+ textValue,
3807
+ ...cacheEditData.inputType === "NUMBER" ? { numberValue: Number(num), unit } : { numberValue: void 0, unit: void 0 }
3808
+ };
3758
3809
  setArrayData(newData);
3759
3810
  setEditIndex(null);
3811
+ setEditError({});
3760
3812
  };
3761
3813
  const handleChangeEditCashData = (e) => {
3762
3814
  const { name, value } = e.target;
@@ -3772,16 +3824,29 @@ function Indicator({
3772
3824
  {
3773
3825
  className: `space-x-2 grid ${valueSwitch === "TEXT" ? `grid-cols-[140px_1fr_50px]` : `grid-cols-[140px_1fr_200px_200px_50px]`} items-start`,
3774
3826
  children: [
3775
- /* @__PURE__ */ jsx40(SwitchSelect, { option, onClick: handleClick, value: valueSwitch, label: "\u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17", required: true }),
3827
+ /* @__PURE__ */ jsx40(
3828
+ SwitchSelect,
3829
+ {
3830
+ option,
3831
+ onClick: handleClick,
3832
+ value: valueSwitch,
3833
+ label: "\u0E1B\u0E23\u0E30\u0E40\u0E20\u0E17",
3834
+ required: true
3835
+ }
3836
+ ),
3776
3837
  /* @__PURE__ */ jsx40(
3777
3838
  InputField,
3778
3839
  {
3779
3840
  label: `\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3780
3841
  value: cacheData.textValue,
3781
3842
  className: "h-[32px]",
3782
- onChange: (e) => handleChangeCashData("textValue", String(e)),
3843
+ onChange: (val) => {
3844
+ handleChangeCashData("textValue", val ?? "");
3845
+ setAddError((p) => ({ ...p, textValue: void 0 }));
3846
+ },
3783
3847
  placeholder: `\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E15\u0E31\u0E27\u0E0A\u0E35\u0E49\u0E27\u0E31\u0E14${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3784
- required: true
3848
+ required: true,
3849
+ error: addError.textValue
3785
3850
  }
3786
3851
  ),
3787
3852
  valueSwitch === "NUMBER" && /* @__PURE__ */ jsxs34(Fragment7, { children: [
@@ -3789,11 +3854,16 @@ function Indicator({
3789
3854
  InputFieldNumber,
3790
3855
  {
3791
3856
  label: `\u0E04\u0E48\u0E32\u0E40\u0E1B\u0E49\u0E32\u0E2B\u0E21\u0E32\u0E22${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3792
- value: cacheData.numberValue ?? "",
3857
+ value: cacheData.numberValue ?? 0,
3793
3858
  className: "h-[32px]",
3794
- onChange: (e) => handleChangeCashData("numberValue", String(e)),
3859
+ onChange: (val) => {
3860
+ handleChangeCashData("numberValue", val ?? 0);
3861
+ setAddError((p) => ({ ...p, numberValue: void 0 }));
3862
+ },
3863
+ min: 0,
3795
3864
  placeholder: `\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32\u0E40\u0E1B\u0E49\u0E32\u0E2B\u0E21\u0E32\u0E22${type === "OUTPUT" ? "\u0E1C\u0E25\u0E1C\u0E25\u0E34\u0E15" : "\u0E1C\u0E25\u0E25\u0E31\u0E1E\u0E18\u0E4C"}`,
3796
- required: true
3865
+ required: true,
3866
+ error: addError.numberValue
3797
3867
  }
3798
3868
  ),
3799
3869
  /* @__PURE__ */ jsx40(
@@ -3802,53 +3872,83 @@ function Indicator({
3802
3872
  label: `\u0E2B\u0E19\u0E48\u0E27\u0E22`,
3803
3873
  value: cacheData.unit ?? "",
3804
3874
  className: "h-[32px]",
3805
- onChange: (e) => handleChangeCashData("unit", String(e)),
3875
+ onChange: (val) => {
3876
+ handleChangeCashData("unit", val ?? "");
3877
+ setAddError((p) => ({ ...p, unit: void 0 }));
3878
+ },
3806
3879
  placeholder: "\u0E23\u0E30\u0E1A\u0E38\u0E2B\u0E19\u0E48\u0E27\u0E22",
3807
- required: true
3880
+ required: true,
3881
+ error: addError.unit
3808
3882
  }
3809
3883
  )
3810
3884
  ] }),
3811
- /* @__PURE__ */ jsx40(IconCirclePlus2, { onClick: handleAddIndicator, className: "mt-7 cursor-pointer", size: 32 })
3885
+ /* @__PURE__ */ jsx40(
3886
+ IconCirclePlus2,
3887
+ {
3888
+ onClick: handleAddIndicator,
3889
+ className: "mt-8 cursor-pointer",
3890
+ size: 32
3891
+ }
3892
+ )
3812
3893
  ]
3813
3894
  }
3814
3895
  ),
3815
3896
  /* @__PURE__ */ jsx40(Fragment7, { children: arrayData.map((item, index) => /* @__PURE__ */ jsxs34(
3816
3897
  "div",
3817
3898
  {
3818
- className: `space-y-4 grid ${item.inputType === "TEXT" ? `grid-cols-[140px_1fr_50px_50px]` : `grid-cols-[140px_1fr_200px_150px_50px_50px]`} items-start`,
3899
+ className: `space-y-2 grid ${item.inputType === "TEXT" ? `grid-cols-[140px_1fr_50px_50px]` : `grid-cols-[140px_1fr_200px_150px_50px_50px]`} items-start`,
3819
3900
  children: [
3820
3901
  /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.inputType === "TEXT" ? "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21" : "\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02" }),
3821
- index === editIndex ? /* @__PURE__ */ jsx40(
3822
- Input4,
3823
- {
3824
- className: "body-1 mt-2",
3825
- variant: "underlined",
3826
- value: cacheEditData.textValue,
3827
- name: "textValue",
3828
- onChange: (e) => handleChangeEditCashData(e)
3829
- }
3830
- ) : /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.textValue }),
3831
- item.inputType === "NUMBER" && /* @__PURE__ */ jsxs34(Fragment7, { children: [
3832
- index === editIndex ? /* @__PURE__ */ jsx40(
3833
- Input4,
3834
- {
3835
- className: "body-1 mt-2",
3836
- variant: "underlined",
3837
- value: cacheEditData.numberValue,
3838
- name: "numberValue",
3839
- onChange: (e) => handleChangeEditCashData(e)
3840
- }
3841
- ) : /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.numberValue }),
3842
- index === editIndex ? /* @__PURE__ */ jsx40(
3902
+ index === editIndex ? /* @__PURE__ */ jsxs34("div", { className: "flex flex-col gap-[8px]", children: [
3903
+ /* @__PURE__ */ jsx40(
3843
3904
  Input4,
3844
3905
  {
3845
3906
  className: "body-1 mt-2",
3846
3907
  variant: "underlined",
3847
- value: cacheEditData.unit,
3848
- name: "unit",
3849
- onChange: (e) => handleChangeEditCashData(e)
3908
+ value: cacheEditData.textValue,
3909
+ name: "textValue",
3910
+ onChange: (e) => {
3911
+ handleChangeEditCashData(e);
3912
+ setEditError((p) => ({ ...p, textValue: void 0 }));
3913
+ }
3850
3914
  }
3851
- ) : /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.unit })
3915
+ ),
3916
+ editError.textValue && /* @__PURE__ */ jsx40("p", { className: "text-red-500 caption-1", children: editError.textValue })
3917
+ ] }) : /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.textValue }),
3918
+ item.inputType === "NUMBER" && /* @__PURE__ */ jsxs34(Fragment7, { children: [
3919
+ index === editIndex ? /* @__PURE__ */ jsxs34("div", { className: "flex flex-col gap-[8px]", children: [
3920
+ /* @__PURE__ */ jsx40(
3921
+ Input4,
3922
+ {
3923
+ type: "number",
3924
+ className: "body-1 mt-2",
3925
+ variant: "underlined",
3926
+ value: cacheEditData.numberValue,
3927
+ name: "numberValue",
3928
+ onChange: (e) => {
3929
+ handleChangeEditCashData(e);
3930
+ setEditError((p) => ({ ...p, numberValue: void 0 }));
3931
+ }
3932
+ }
3933
+ ),
3934
+ editError.numberValue && /* @__PURE__ */ jsx40("p", { className: "text-red-500 caption-1", children: editError.numberValue })
3935
+ ] }) : /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.numberValue }),
3936
+ index === editIndex ? /* @__PURE__ */ jsxs34("div", { className: "flex flex-col gap-[8px]", children: [
3937
+ /* @__PURE__ */ jsx40(
3938
+ Input4,
3939
+ {
3940
+ className: "body-1 mt-2",
3941
+ variant: "underlined",
3942
+ value: cacheEditData.unit,
3943
+ name: "unit",
3944
+ onChange: (e) => {
3945
+ handleChangeEditCashData(e);
3946
+ setEditError((p) => ({ ...p, unit: void 0 }));
3947
+ }
3948
+ }
3949
+ ),
3950
+ editError.unit && /* @__PURE__ */ jsx40("p", { className: "text-red-500 caption-1", children: editError.unit })
3951
+ ] }) : /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2", children: item.unit })
3852
3952
  ] }),
3853
3953
  /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2 flex", children: editIndex !== null ? editIndex === index ? /* @__PURE__ */ jsxs34("div", { className: "flex", children: [
3854
3954
  /* @__PURE__ */ jsx40(
@@ -3858,11 +3958,36 @@ function Indicator({
3858
3958
  onClick: () => handleConfirmEditIndicator(index)
3859
3959
  }
3860
3960
  ),
3861
- /* @__PURE__ */ jsx40(IconX3, { className: "cursor-pointer text-red-600", onClick: handleCancelEditIndicator })
3862
- ] }) : void 0 : /* @__PURE__ */ jsx40(IconPencil2, { className: "cursor-pointer", onClick: () => handleEditIndicator(index) }) }),
3863
- /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2 cursor-pointer", children: /* @__PURE__ */ jsx40(IconTrash4, { onClick: () => handleDeleteIndicator(index) }) })
3961
+ /* @__PURE__ */ jsx40(
3962
+ IconX3,
3963
+ {
3964
+ className: "cursor-pointer text-red-600",
3965
+ onClick: handleCancelEditIndicator
3966
+ }
3967
+ )
3968
+ ] }) : void 0 : canEdit && /* @__PURE__ */ jsx40(
3969
+ IconPencil2,
3970
+ {
3971
+ className: "cursor-pointer",
3972
+ onClick: () => handleEditIndicator(index)
3973
+ }
3974
+ ) }),
3975
+ /* @__PURE__ */ jsx40("div", { className: "body-1 mt-2 cursor-pointer", children: /* @__PURE__ */ jsx40(
3976
+ IconTrash4,
3977
+ {
3978
+ onClick: () => {
3979
+ const confirm = () => handleDeleteIndicator(index);
3980
+ if (onDeleteClick) {
3981
+ onDeleteClick({ index, item, confirm });
3982
+ } else {
3983
+ confirm();
3984
+ }
3985
+ }
3986
+ }
3987
+ ) })
3864
3988
  ]
3865
- }
3989
+ },
3990
+ index
3866
3991
  )) })
3867
3992
  ] });
3868
3993
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esic-lab/data-core-ui",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",