@esvndev/es-react-config-setting 1.0.53 → 1.0.55

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.js CHANGED
@@ -18848,14 +18848,19 @@ const SettingApp = (props) => {
18848
18848
  const handleFormClosed = () => {
18849
18849
  };
18850
18850
  //Sự kiện giá trị thay đổi
18851
- const _eventChange = (obj, data) => {
18852
- if (data.target) {
18851
+ const _eventChange = (obj, e) => {
18852
+ const value = e.target.type === "checkbox" ? e.target.checked : e.target.value;
18853
+ setFormState(prev => ({
18854
+ ...prev,
18855
+ [obj.id]: value
18856
+ }));
18857
+ if (e.target) {
18853
18858
  var _value = "";
18854
18859
  if (obj.type === 'checkbox') {
18855
- _value = data.target.checked ? 'true' : 'false';
18860
+ _value = e.target.checked ? 'true' : 'false';
18856
18861
  }
18857
18862
  else {
18858
- _value = data.target.value;
18863
+ _value = e.target.value;
18859
18864
  }
18860
18865
  UpdateSettingConfig({
18861
18866
  Items: [{
@@ -18876,6 +18881,7 @@ const SettingApp = (props) => {
18876
18881
  //#endregion
18877
18882
  const [settingData, setSettingData] = React.useState({});
18878
18883
  const [dataSettingGroup, setDataSettingGroup] = React.useState([]);
18884
+ const [formState, setFormState] = React.useState({});
18879
18885
  //Load data of group config and setting by group
18880
18886
  React.useEffect(() => {
18881
18887
  if (isOpen) {
@@ -18903,6 +18909,16 @@ const SettingApp = (props) => {
18903
18909
  }
18904
18910
  });
18905
18911
  };
18912
+ //Cài đặt lại giá trị cho cấu hình
18913
+ React.useEffect(() => {
18914
+ const initialState = {};
18915
+ if (settingData && settingData.data) {
18916
+ settingData.data.forEach((item) => {
18917
+ initialState[item.id] = item.value;
18918
+ });
18919
+ }
18920
+ setFormState(initialState);
18921
+ }, [settingData]);
18906
18922
  //Sự kiện chọn nhóm cài đặt
18907
18923
  const switchSettingTab = (data) => {
18908
18924
  const updated = dataSettingGroup.map((item) => ({
@@ -18915,34 +18931,29 @@ const SettingApp = (props) => {
18915
18931
  //Hàm sử dụng tạo theo loại giá trị
18916
18932
  const _renderInput = (root, data) => {
18917
18933
  console.log(data);
18934
+ const value = formState[data.id] ?? data.value ?? "";
18918
18935
  switch (data.type) {
18919
18936
  case "switch":
18920
18937
  case "checkbox":
18921
- return (jsxRuntime.jsx("div", { className: "checkbox", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "checkbox", className: "", onChange: (e) => _eventChange(data, e), value: data.value }) }, data.id));
18938
+ return (jsxRuntime.jsx("div", { className: "checkbox", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "checkbox", checked: !!value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18922
18939
  case "radio":
18923
- return (jsxRuntime.jsx("div", { className: "radio-group", title: data.description, children: data.option?.map((opt, index) => (jsxRuntime.jsxs("label", { children: [jsxRuntime.jsx(Input$1, { type: "radio", name: data.name, value: opt.value, onChange: (e) => _eventChange(data, e) }), opt.name] }, index))) }, data.id));
18940
+ return (jsxRuntime.jsx("div", { className: "radio-group", title: data.description, children: data.option?.map((opt, index) => (jsxRuntime.jsxs("label", { children: [jsxRuntime.jsx(Input$1, { type: "radio", name: data.name, value: opt.value, checked: value === opt.value, onChange: (e) => _eventChange(data, e) }), opt.name] }, index))) }, data.id));
18924
18941
  case "combobox":
18925
- return (jsxRuntime.jsx("div", { className: "combobox", title: data.description, children: jsxRuntime.jsxs(Input$1, { type: "select", className: "input-custom", name: data.name, value: data.value, id: data.name, onChange: (e) => _eventChange(data, e), children: [jsxRuntime.jsx("option", { value: "", children: "Ch\u1ECDn m\u1ED9t gi\u00E1 tr\u1ECB" }), data.option?.map((opt, index) => (jsxRuntime.jsx("option", { value: opt.value, children: opt.name }, index)))] }) }, data.id));
18942
+ return (jsxRuntime.jsx("div", { className: "combobox", title: data.description, children: jsxRuntime.jsxs(Input$1, { type: "select", className: "input-custom", name: data.name, value: value, onChange: (e) => _eventChange(data, e), children: [jsxRuntime.jsx("option", { value: "", children: "Ch\u1ECDn m\u1ED9t gi\u00E1 tr\u1ECB" }), data.option?.map((opt, index) => (jsxRuntime.jsx("option", { value: opt.value, children: opt.name }, index)))] }) }, data.id));
18926
18943
  case "slider":
18927
18944
  case "text":
18928
- return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "text", className: "input-custom", value: data.value, placeholder: data.name, onChange: (e) => _eventChange(data, e) }) }, data.id));
18929
18945
  case "password":
18930
- return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "password", className: "input-custom", value: data.value, placeholder: data.name, onChange: (e) => _eventChange(data, e) }) }, data.id));
18931
18946
  case "number":
18932
- return (jsxRuntime.jsx("div", { className: "number-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "number", className: "t-right input-custom", value: data.value, placeholder: data.name, onChange: (e) => _eventChange(data, e) }) }, data.id));
18933
18947
  case "date":
18934
- return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "date", className: "t-right input-custom", value: data.value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18935
18948
  case "time":
18936
- return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "time", className: "t-right input-custom", value: data.value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18937
18949
  case "datetime":
18938
- return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "datetime", className: "t-right input-custom", value: data.value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18950
+ case "color":
18951
+ return (jsxRuntime.jsx("div", { className: `${data.type}-input`, title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type, className: "input-custom", value: value, placeholder: data.name, onChange: (e) => _eventChange(data, e) }) }, data.id));
18939
18952
  case "image":
18940
18953
  case "file":
18941
- return (jsxRuntime.jsx("div", { className: "file-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "file", className: "input-custom", value: data.value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18942
- case "color":
18943
- return (jsxRuntime.jsx("div", { className: "color-picker t-right", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "color", className: "form-color input-custom", value: data.value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18954
+ return (jsxRuntime.jsx("div", { className: "file-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "file", className: "input-custom", onChange: (e) => _eventChange(data, e) }) }, data.id));
18944
18955
  default:
18945
- return (jsxRuntime.jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type ?? '', value: data.value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18956
+ return (jsxRuntime.jsx("div", { className: `${data.type ?? 'normal'}-input`, title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type ?? "text", value: value, onChange: (e) => _eventChange(data, e) }) }, data.id));
18946
18957
  }
18947
18958
  };
18948
18959
  //hàm tạo các thông số cấu hình và cài đặt