@dmitryvim/form-builder 0.2.13 → 0.2.14

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.
@@ -902,10 +902,10 @@ function updateTextareaField(element, fieldPath, value, context) {
902
902
  }
903
903
 
904
904
  // src/components/number.ts
905
- function createNumberCounter(element, input) {
906
- const counter = document.createElement("span");
907
- counter.className = "number-counter";
908
- counter.style.cssText = `
905
+ function createNumberRangeHint(element, input) {
906
+ const hint = document.createElement("span");
907
+ hint.className = "number-range-hint";
908
+ hint.style.cssText = `
909
909
  position: absolute;
910
910
  top: 50%;
911
911
  transform: translateY(-50%);
@@ -916,38 +916,30 @@ function createNumberCounter(element, input) {
916
916
  background: var(--fb-background-color);
917
917
  padding: 0 4px;
918
918
  `;
919
- const updateCounter = () => {
919
+ const min = element.min;
920
+ const max = element.max;
921
+ let rangeText = "";
922
+ if (min != null && max != null) {
923
+ rangeText = `${min} \u2013 ${max}`;
924
+ } else if (max != null) {
925
+ rangeText = `\u2264${max}`;
926
+ } else if (min != null) {
927
+ rangeText = `\u2265${min}`;
928
+ }
929
+ hint.textContent = rangeText;
930
+ const updateColor = () => {
920
931
  const val = input.value ? parseFloat(input.value) : null;
921
- const min = element.min;
922
- const max = element.max;
923
- if (min == null && max == null) {
924
- counter.textContent = "";
925
- return;
926
- }
927
- if (val == null || min != null && val < min) {
928
- if (min != null && max != null) {
929
- counter.textContent = `${min}-${max}`;
930
- } else if (max != null) {
931
- counter.textContent = `\u2264${max}`;
932
- } else if (min != null) {
933
- counter.textContent = `\u2265${min}`;
934
- }
935
- counter.style.color = "var(--fb-text-secondary-color)";
936
- } else if (max != null && val > max) {
937
- counter.textContent = `${val}/${max}`;
938
- counter.style.color = "var(--fb-error-color)";
932
+ if (val != null) {
933
+ const belowMin = min != null && val < min;
934
+ const aboveMax = max != null && val > max;
935
+ hint.style.color = belowMin || aboveMax ? "var(--fb-error-color)" : "var(--fb-text-secondary-color)";
939
936
  } else {
940
- if (max != null) {
941
- counter.textContent = `${val}/${max}`;
942
- } else {
943
- counter.textContent = `${val}`;
944
- }
945
- counter.style.color = "var(--fb-text-secondary-color)";
937
+ hint.style.color = "var(--fb-text-secondary-color)";
946
938
  }
947
939
  };
948
- input.addEventListener("input", updateCounter);
949
- updateCounter();
950
- return counter;
940
+ input.addEventListener("input", updateColor);
941
+ updateColor();
942
+ return hint;
951
943
  }
952
944
  function renderNumberElement(element, ctx, wrapper, pathKey) {
953
945
  const state = ctx.state;
@@ -974,7 +966,7 @@ function renderNumberElement(element, ctx, wrapper, pathKey) {
974
966
  }
975
967
  inputWrapper.appendChild(numberInput);
976
968
  if (!state.config.readonly && (element.min != null || element.max != null)) {
977
- const counter = createNumberCounter(element, numberInput);
969
+ const counter = createNumberRangeHint(element, numberInput);
978
970
  inputWrapper.appendChild(counter);
979
971
  }
980
972
  wrapper.appendChild(inputWrapper);
@@ -1026,7 +1018,7 @@ function renderMultipleNumberElement(element, ctx, wrapper, pathKey) {
1026
1018
  }
1027
1019
  inputContainer.appendChild(numberInput);
1028
1020
  if (!state.config.readonly && (element.min != null || element.max != null)) {
1029
- const counter = createNumberCounter(element, numberInput);
1021
+ const counter = createNumberRangeHint(element, numberInput);
1030
1022
  inputContainer.appendChild(counter);
1031
1023
  }
1032
1024
  itemWrapper.appendChild(inputContainer);